factoring out complex expression
- Subject: factoring out complex expression
- From: Stavros Macrakis
- Date: Mon, 19 Dec 2011 10:51:59 -0500
Don't know if this counts as "elegant", but...
(%i1) exp: a^2*gama+b^2*gama + beta*a*c*p + beta*b*d*p - c*b*gama*p +
a*d*gama*p - beta*c*b*r + beta*a*d*r - a*c*gama*r - b*d*gama*r +
a^2*G+b^2*G;
(%o1) b^2*G+a^2*G-b*d*gama*r-a*c*gama*r+a*beta*d*r-b*beta*c*r+a*d*gama*p
-b*c*gama*p+b*beta*d*p+a*beta*c*p+b^2*gama+a^2*gama
(%i2) e1:facsum(exp,r,p,[gama,beta]);
(%o2) (b^2+a^2)*G+(beta*(a*d-b*c)-(b*d+a*c)*gama)*r
+((a*d-b*c)*gama+beta*(b*d+a*c))*p+(b^2+a^2)*gama
(%i3) e2:substpart(factor(piece),e1,[1,4]);
(%o3) (b^2+a^2)*(G+gama)+(beta*(a*d-b*c)-(b*d+a*c)*gama)*r
+((a*d-b*c)*gama+beta*(b*d+a*c))*p
2011/12/19 V?t Mach-?i?ka <vit.machzizka at gmail.com>
> exp: a^2*gama+b^2*gama + beta*a*c*p + beta*b*d*p - c*b*gama*p +
> a*d*gama*p - beta*c*b*r + beta*a*d*r - a*c*gama*r - b*d*gama*r +
> a^2*G+b^2*G;
>