I'm having trouble setting a pattern for simplifying a complex expression. I've distilled the question down to the simplest case where Mathematica seems to fail.
I set up a simple rule based on a pattern:
simpRule = a b v___ - c d v___ -> e v
which works on the direct case
a b - c d /. simpRule
e
but fails if I simply add a minus sign.
-a b + c d /. simpRule
-a b + c d
How do I go about writing a more robust rule? Or perhaps there's a better way to go about performing simplifications of this sort?
Thanks, Keith
Subtract[a b something, c d something]to be replaced bye*something, or do you need something more general? In any event, there is the built-in functionFactor[]which might be apropos... – J. M. ain't a mathematician Aug 05 '11 at 05:28(1/(2 r^5)) c0 (x^2 + y^2 - 2 z^2 + s2 a2 + c2 (a1 - 8 r^4 \Omega^4))– Keith Aug 05 '11 at 06:38InputForm[]to whatever output Mathematica spits back. – J. M. ain't a mathematician Aug 05 '11 at 06:46simpRule = {a b v___ - c d v___ -> e v, -a b v___ + c d v___ -> e v}gives the desired result. – Andrew Aug 05 '11 at 06:59pat = a b v___ - c d v___; simpRule = {pat -> e v, -pat -> -e v}. – Andrew Aug 05 '11 at 07:44(-4*c0*c2*r\[CapitalOmega]^2)/r^3 + (c0*x^2)/(2*r^5) + (3*c0*c2*x^2)/(2*r^5) - (2*c0*c2*r\[CapitalOmega]^2*x^2)/r^5 - (3*c0*r\[CapitalOmega]*s2*x^2)/r^5 + (6*c0*c2*r\[CapitalOmega]*x*y)/r^5 + (3*c0*s2*x*y)/r^5 - (4*c0*r\[CapitalOmega]^2*s2*x*y)/r^5 + (c0*y^2)/(2*r^5) - (3*c0*c2*y^2)/(2*r^5) + (2*c0*c2*r\[CapitalOmega]^2*y^2)/r^5 + (3*c0*r\[CapitalOmega]*s2*y^2)/r^5 - (c0*z^2)/r^5– Keith Aug 05 '11 at 07:54{3*x^2*(v___) - 4*r\[CapitalOmega]^2*x^2*(v___) + 12*r\[CapitalOmega]*x*y*(v___) - 3*y^2*(v___) + 4*r\[CapitalOmega]^2*y^2*(v___) -> a1*v, -3*x^2*(v___) + 4*r\[CapitalOmega]^2*x^2*(v___) - 12*r\[CapitalOmega]*x*y*(v___) + 3*y^2*(v___) - 4*r\[CapitalOmega]^2*y^2*(v___) -> -(a1*v)}– Keith Aug 05 '11 at 07:56expr=x^2y^2+ 3 x z^3+y+x z^4the partx^2y^2+ 3 x z^3ona1. Then one can take some pattern which appears ina1only once, for example,pp=x z^3. Substituting ina1=x^2y^2+ 3 x z^3and findingpp->a(1-x^2y^2)/3it is possible now to simplifyexprby changingexpr/.{x z^3->pp}/.pp->(a1-x^2y^2)/3– Andrew Aug 05 '11 at 09:13pat = 3*x^2 - 4*r\[CapitalOmega]^2*x^2 + 12*r\[CapitalOmega]*x*y - 3*y^2 + 4*r\[CapitalOmega]^2*y^2; pat1 = r\[CapitalOmega]*x*y; pat2 = (pat /. pat1 -> pp); pat3 = Solve[pat2 == a1, pp][[1]]; expr /. pat1 -> pp /. pat3 // Simplifywill give $$\frac{\text{c0} \left(\text{a1} \text{c2}-8 \text{c2} r^2 \text{r$\Omega $}^2-8 \text{r$\Omega $}^2 \text{s2} x y-6 \text{r$\Omega $} \text{s2} x^2+6 \text{r$\Omega $} \text{s2} y^2+6 \text{s2} x y+x^2+y^2-2 z^2\right)}{2 r^5}$$ – Andrew Aug 05 '11 at 09:15