Question: Substituting out Radicals and (a*x..........) types

I have some long expressions that would be more readable if common sections were substituted out. There are many sets of radicals often stacked inside each other.  The other one is (a*x..........) I see repeated in some other expressions. indets is good, but is there a way to use it to select  (a*x..........) types
At these eexpressions are returned from procdures would probably put them in an array/table with their substitution components. 
I dont need to substitute everything. What I have done below is reasonable for reading and seeing the structure.

What would be a good approact here?

restart

 

18*x^2+21*x*y+7*y^2-29*x-37*y-56

(1)

vals:=[a=18,b=21,c=7,d=-29,e=-37,f=-56]

[a = 18, b = 21, c = 7, d = -29, e = -37, f = -56]

(2)

vars[1]:=x:vars[2]:=y:

eqn:= 8*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^(1
                /2)+(-8*a*f+2*d^2)*c^2+(8*a^2*f-2*a*d^2+2*a*e^2+2*b^2*f-2*b*d*e)*c-2*a^2*e^2-2*
                a*b^2*f+2*a*b*d*e)^(1/2)*(a*c-1/4*b^2)/(4*a*c-b^2)^2*(vars[1]-(1/4*b*e-1/2*c*d)/(a*c-\
                1/4*b^2))-8*csgn((4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)*(Complex(1)*a+Complex(-1)*c-
                b))*(a*c-1/4*b^2)*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^
                (1/2)+(8*a*f-2*d^2)*c^2+(-8*a^2*f+2*a*d^2-2*a*e^2-2*b^2*f+2*b*d*e)*c+2*a^2*e^2+
                2*a*b^2*f-2*a*b*d*e)^(1/2)/(4*a*c-b^2)^2*(vars[2]-(-1/2*a*e+1/4*b*d)/(a*c-1/4*b^2))

8*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^(1/2)+(-8*a*f+2*d^2)*c^2+(8*a^2*f-2*a*d^2+2*a*e^2+2*b^2*f-2*b*d*e)*c-2*a^2*e^2-2*a*b^2*f+2*a*b*d*e)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a*f + 2*d^2)*c^2 + (8*a^2*f - 2*a*d^2 + 2*a*e^2 + 2*b^2*f - 2*b*d*e)*c - 2*a^2*e^2 - 2*a*b^2*f + 2*a*b*d*e=B^2,
           f*b^3 - b^2*d*e - (-(-4*c*f + e^2)*a - c*d^2)*b=C]:

eqn1:=simplify(eqn,Subs)

(-8*csgn(C+((1/2)*I)*B^2)*(-(1/4)*y*b^2-(1/4)*b*d+a*(y*c+(1/2)*e))*(-B^2+2*(A^2)^(1/2))^(1/2)+8*(B^2+2*(A^2)^(1/2))^(1/2)*(-(1/4)*b^2*x-(1/4)*b*e+c*(a*x+(1/2)*d)))/(4*a*c-b^2)^2

(7)

Subsnumeric:=eval(Subs,vals)

[74635047712 = A^2, -253528 = B^2, 242004 = C]

(8)

simplify(eval(eqn1,[(rhs=lhs)~(Subsnumeric)[],vals[] ]))

(4/567)*(9*x+53)*(-63382+5762*562^(1/2))^(1/2)+(4/1323)*(241-21*y)*(63382+5762*562^(1/2))^(1/2)

(9)
 

 

Download 2024-05-27_Q_Pick_Apart_an_Expression.mw

Please Wait...