0
$\begingroup$

Suppose that we have an expression (expr in the code below) and replace a long term with a new parameter (K).

For a simple example;

expr = (5 I (Subscript[a, 1] - Sqrt[
     Subscript[a, 1] (6 + Subscript[a, 1])]) x)/(3 y \[Alpha]);
newVariables = {(Subscript[a, 1] - Sqrt[
      Subscript[a, 1] (6 + Subscript[a, 1])]) -> K};
expr //. newVariables

After some calculations, we derive a new expression (expr2 in the code below). What is the best and most reliable method for automatically back-substituion K to expr2? (instead of manually applying expr2//.K->(Subscript[a, 1] - Sqrt[Subscript[a, 1] (6 + Subscript[a, 1])]) )

expr2 = K^2 + 5 I K x
$\endgroup$
2
  • 3
    $\begingroup$ Is this what you want: expr2 /. Reverse /@ newVariables? $\endgroup$
    – Domen
    Commented Jul 3, 2022 at 19:26
  • $\begingroup$ Yes. Thank you. $\endgroup$
    – RF_1
    Commented Jul 3, 2022 at 19:44

0

Browse other questions tagged or ask your own question.