Le lundi 11 mars 2019 19:05:04 UTC+1, Michael Beeson a écrit :
>
>  I appreciate Eric's post,  and I do use subs  sometimes,  but it makes me 
> nervous since
> it will happily substitute any old thing you tell it to,  even an 
> incorrect thing.  So,  if your idea
> is to check a computation, it is a dangerous thing. 
>

In order to minimize the error risk in the substitution, note that you can 
use the Python variable b defined as
b = sqrt(1-a^2)
in the argument of subs(), thereby avoiding any duplicate code. The whole 
code becomes then

sage: var('p,q,r,a')  # note: no b at this stage
(p, q, r, a)
sage: b = sqrt(1-a^2) 
sage: eq = (p*a+r*b+q)^2
sage: eq = eq.expand(); eq
a^2*p^2 - a^2*r^2 + 2*sqrt(-a^2 + 1)*a*p*r + 2*a*p*q + 2*sqrt(-a^2 + 1)*q*r 
+ q^2 + r^2
sage: eq.subs({b: SR.var('b')})
a^2*p^2 + 2*a*b*p*r - a^2*r^2 + 2*a*p*q + 2*b*q*r + q^2 + r^2



-- 
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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to