2
$\begingroup$

After some calculations, I get some long expressions. I want to change some variables to get simple looks.

For a just small example:

enter image description here

But it doesn't work.

I convert the expression to RawInputForm in order to ask here. So, it partially works: enter image description here

CODES:

 expr=(2*Sqrt[5]*E^(I*(q*y + (5*x*(a - Sqrt[a^2 + 6*a]))/(3*\[Alpha]*y) + (7*x*(a - Sqrt[a^2 + 6*a]))/(3*\[Alpha]*t)))*Sqrt[\[Alpha]]*\[Delta])/(Sqrt[\[Beta] + 1]*(\[Eta]/E^(\[Delta]*(x + y)) + 4*(E^(\[Delta]*x))^2))

Transforms:

transforms = {(2*Sqrt[5]*Sqrt[\[Alpha]]*\[Delta])/Sqrt[\[Beta] + 1] -> Subscript[C, 1], (x*(a - Sqrt[a^2 + 6*a]))/(3*\[Alpha]) -> Subscript[C, 2]}






 expr/.transforms
$\endgroup$
0

3 Answers 3

3
$\begingroup$

Replacements acts on the full form of an expression. Look e.g. at:

enter image description here

enter image description here

And the expression in your replacement is:

(x*(a - Sqrt[a^2 + 6*a]))/(\[Alpha]) // FullForm

enter image description here

You see that Rational[7, 3] and Power[t,-1] are the reason that the 2 expressions do not match. you may at most match the term in brackets.

Further, the whole expression reads Times[...] and the first replacement changes some terms in Times[...]. MMA then thinks it is done with everything inside Times[...]. Therefore, to make the second replacement, you need to apply ReplaceAll again or simpler, use ReplaceRepeated (//.):

transforms = {(2*Sqrt[5]*Sqrt[\[Alpha]]*\[Delta])/Sqrt[\[Beta] + 1] ->
    Subscript[C, 1], (x*(a - Sqrt[a^2 + 6*a])) -> Subscript[C, 2]}

expr //. transforms  // Simplify

enter image description here

$\endgroup$
2
$\begingroup$
  1. Slightly change your second rule:

rules = {(2 Sqrt[5] Sqrt[α] δ)/Sqrt[1 + β] -> Subscript[C, 1], 
  a - Sqrt[6 a + a^2] -> 3 α Subscript[C, 2] / x}

enter image description here

  1. Apply the replacement rules sequentially using Fold:

Fold[ReplaceAll, expr, rules]

enter image description here

Alternatively, use ReplaceRepeated as in Daniel Huber's answer:

expr //. rules
same result

Note: ReplaceAll >> Details:

enter image description here

$\endgroup$
1
$\begingroup$
Clear["Global`*"]

expr = (2*Sqrt[5]*
     E^(I*(q*
           y + (5*x*(a - Sqrt[a^2 + 6*a]))/(3*α*y) + (7*
             x*(a - Sqrt[a^2 + 6*a]))/(3*α*t)))*
     Sqrt[α]*δ)/(Sqrt[β + 
       1]*(η/E^(δ*(x + y)) + 4*(E^(δ*x))^2));

transforms = {(2*Sqrt[5]*Sqrt[α]*δ)/Sqrt[β + 1] -> 
    Subscript[C, 1], (x*(a - Sqrt[a^2 + 6*a]))/(3*α) -> 
    Subscript[C, 2]};

The simpler the LHS of a rule, the easier it is to apply.

rule1 = Solve[(Equal @@ transforms[[1]]) /. (Sqrt[α] -> sqrt), 
    sqrt][[1]] /. sqrt -> Sqrt[α]

(* {Sqrt[α] -> (Sqrt[1 + β] Subscript[C, 1])/(2 Sqrt[5] δ)} )*

rule2 = Solve[(Equal @@ transforms[[2]]) /. (Sqrt[a^2 + 6*a] -> sqrt), 
    sqrt][[1]] /. sqrt -> Sqrt[a^2 + 6*a]

(* {Sqrt[6 a + a^2] -> (a x - 3 α Subscript[C, 2])/x} *)

expr2 = expr /. rule1 /. rule2 // Simplify

(* (E^(I q y + (x + y) δ + ((7 I)/t + (5 I)/y) Subscript[C, 
   2]) Subscript[C, 1])/(4 E^((3 x + y) δ) + η) *)

Verifying,

expr == expr2 /. (Reverse /@ transforms) // Simplify

(* True *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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