1
$\begingroup$

I want to replace the common part in the equation by different value. Here is my equation

    -(3/(2*θ)) - (1/2)*Sqrt[9/θ^2 - (2*(-18 + θ))/(3*θ^2) + (324 - 252*θ - 23*θ^2)/
      (3*θ^2*(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)) + 
     (-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)/(3*θ^2)] + 
  (1/2)*Sqrt[18/θ^2 - (4*(-18 + θ))/(3*θ^2) - (324 - 252*θ - 23*θ^2)/
      (3*θ^2*(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)) - 
     (-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)/(3*θ^2) - 
     (-(216/θ^3) + (24*(-18 + θ))/θ^3 - 96/θ^2)/(4*Sqrt[9/θ^2 - (2*(-18 + θ))/(3*θ^2) + (324 - 252*θ - 23*θ^2)/
          (3*θ^2*(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)) + 
         (1/(3*θ^2))*(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)])]

which looks too complicate. However, this include the common part,

(-5832 + 6804*θ - 702*θ^2 + 73*θ^3
    + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)

Thus, I replace this part by A using the command

% /. (-5832 + 6804*θ - 702*θ^2 + 73*θ^3
         + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3) -> A

However, the output shows that not all common parts are changed into A. I get the output,

-(3/(2*θ)) - (1/2)*Sqrt[9/θ^2 + A/(3*θ^2) - (2*(-18 + θ))/(3*θ^2) + (324 - 252*θ - 23*θ^2)/
      (3*θ^2*(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3))] + 
  (1/2)*Sqrt[18/θ^2 - A/(3*θ^2) - (4*(-18 + θ))/(3*θ^2) - (324 - 252*θ - 23*θ^2)/
      (3*θ^2*(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)) - 
     (-(216/θ^3) + (24*(-18 + θ))/θ^3 - 96/θ^2)/(4*Sqrt[9/θ^2 + A/(3*θ^2) - (2*(-18 + θ))/(3*θ^2) + (324 - 252*θ - 23*θ^2)/
          (3*θ^2*(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3))])]

which still has the common part,

(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 17*θ^5 + θ^6])^(1/3)

How can I chance all these common parts at the same time?

$\endgroup$
1
$\begingroup$

Part of the problem is that

1/x^1/3 // FullForm
(* Times[Rational[1, 3], Power[x, -1]] *)

That is, powers in denominators are automatically parsed as negative powers. So as noted in Cesareo's answer, you have to find the negative powers as well. I would do the following to help automate this process.

First inspect your expression for sub-expressions that might be the same:

Cases[expr, (_)^(-1/3) | (_)^(1/3), Infinity] // DeleteDuplicates
(* {1/(-5832 + 6804 θ - 702 θ^2 + 73 θ^3
         + 54 Sqrt[6] Sqrt[-324 θ^3 + 306 θ^4 + 17 θ^5 + θ^6])^(1/3),
    (-5832 + 6804 θ - 702 θ^2 + 73 θ^3
         + 54 Sqrt[6] Sqrt[-324 θ^3 + 306 θ^4 + 17 θ^5 + θ^6])^(1/3)} *)

(Here, expr is your long expression.) By inspecting just these parts, we can see that every sub-expression of the form $(\textrm{something})^{1/3}$ is the same. So, we can do a much simpler replacement rule that requires much less typing:

expr /. {a_^(1/3) -> A, a_^(-1/3) -> 1/A}
$\endgroup$
1
$\begingroup$

Try this

% /. {(-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 
        54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 
        17*θ^5 + θ^6])^(1/3) -> A, 
      (-5832 + 6804*θ - 702*θ^2 + 73*θ^3 + 
        54*Sqrt[6]*Sqrt[-324*θ^3 + 306*θ^4 + 
        17*θ^5 + θ^6])^(-1/3) -> 1/A}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.