On Monday, September 8, 2014 6:48:44 PM UTC-7, Chris Thron wrote:
>
> This works beautifully, thanks.  
>
> I have another small issue:  I can't do substitutions in equality 
> expressions with terms in the free algebra.  For instance, Sage tells me 
> "Not iterable"
>
>
> var('c, pi, c, mu_0,epsilon_0,epsilon,mu,q,Q,e')
> F.<curl,div,grad,d_t,d_x,d_y,d_z,J,I,K,P,p,E,V,Phi,D,B,A,H,M,m,rho,sigma,C,R,Z,L>
>  
> = 
> FreeAlgebra(SR,27,'curl,div,grad,d_t,d_x,d_y,d_z,J,I,K,P,p,E,V,Phi,D,B,A,H,M,m,rho,sigma,C,R,Z,L')
>
> eqCGS =                           curl*H - (1/c)*d_t*D == 4*pi/c*K         
>                                ### CGS expression on this line ###
>

Do check what you get back. At this point, eqCGS is bound to "False", 
because you've asked sage if two elements of F are equal that are not. The 
fact that "==" on SR does not always return a boolean is a big concession 
to calculus students that makes SR fit rather poorly with the rest of 
Python. Other sage structures (including FreeAlgebra) don't follow this 
exceptional behaviour. Imagine a programming language in which "2 != 3" 
does not provide an immediate boolean ... with SR you have that:

sage: SR(2) != SR(3)
2 != 3
sage: F(2) != F(3)
True

Your options are keeping track of LHS and RHS yourself or to take the 
difference of them.

sage:  eqCGS =                           curl*H - (1/c)*d_t*D - 4*pi/c*K 


eq =eqCGS*                          (1/2)*mu_0^(-1/2)*pi^(-1/2)             
>                              ### Multiplicative factor on this line ###
>

It would be nice if this would fail as a result, but Python specifies that 
"False" is essentially equivalent to 0, so after this, eq is bound to 0.
 

> assume(mu_0>0,epsilon_0>0,pi>0,c>0,e>0)
> eq = sum(b.subs(c == mu_0^(-1/2)*epsilon_0^(-1/2))*F(a) for a,b in eq)
>

 Note that False * ( (1/2)*mu_0^(-1/2)*pi^(-1/2) ), which evaluates as 0*(  
(1/2)*mu_0^(-1/2)*pi^(-1/2) ) doesn't involve any free algebra elements, so 
you're just getting an element of SR:

sage: parent(eq)
Symbolic Ring

It doesn't necessarily have all the properties that elements of F have. As 
a work-around you could simply make sure that you have an element of F:

sage: eq = sum(b.subs(c == mu_0^(-1/2)*epsilon_0^(-1/2))*F(a) for a,b in 
F(eq))

(which results in 0 of course, due to the earlier problems)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to