mpad a écrit :
> Hello everyone,
>
> I am new to sage (thanks for it ! it looks excellent !) and have been
> trying to re-factor some long expressions.
> As an example :
>
> sage: var('x,y,a,b,c,d')
> (x, y, a, b, c, d)
> sage: T=expand((x^2+y^2)*(a*b+a^2-2*d*c+c^2-3*b^2));T
> a^2*x^2 + a^2*y^2 + a*b*x^2 + a*b*y^2 - 3*b^2*x^2 - 3*b^2*y^2 +
> c^2*x^2 + c^2*y^2 - 2*c*d*x^2 - 2*c*d*y^2
> sage: T.collect(x^2+y^2)
> a^2*x^2 + a^2*y^2 + a*b*x^2 + a*b*y^2 - 3*b^2*x^2 - 3*b^2*y^2 +
> c^2*x^2 + c^2*y^2 - 2*c*d*x^2 - 2*c*d*y^2
>
> I've played a bit and got lost in the doc... but could not find a way
> to have sage re-factor a given sub-expression out.
> (also it seems that T.coeffs(x^2+y^2) makes sage hanging...)
>
>   
collect operates over variables, and doesn't operate over subexpressions 
or polynomial as x^2+y^2.

factor(T) is right if T is a product. It's also possible to use 
T.rational_simplify()
Theses calculus are fine only because T is a product.

For theses expressions it's not so pretty to play with 
T.subs_expr(x^2+y^2==r^2) because x^2 and y^2 aren't close in the formula.

T.subs_expr(x^2==r^2-y^2) is a little better, and I find pretty the 
expand(T.subs_expr(x^2==r^2-y^2) 

You can also look at T.collect(a).collect(b).collect(c), or in the 
opposite direction T.collect(x).collect(y)






> Thanks for any help !
>
> Cheers,
>
> P.A.
>
> >
>
>
>   


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to