-1
$\begingroup$

Is it possible to directly factor out some exponent to some specific form and replace by some rule? For example I have

exp1=x^4

I want to use replacement

/. x^2 ->z

where I do NOT want to change the replacement rule like

% /. x^a_->z^(a/2) 

I wanted to know whether any simple procedure is there for direct replacement i.e.

x^4 /. {x^2->z} = z^2 
$\endgroup$
  • $\begingroup$ You could try x-> Sqrt[z]. $\endgroup$ – Henrik Schumacher Feb 21 '18 at 16:25
  • $\begingroup$ This is same as using x^a_->z^(a/2). As I said I do not want to change the replacement rule. The question is stupid, also Mathematica may not work like this. I wanted to know whether there is 'Something' for Something[x^4] /. {x^2->z} = z^2 $\endgroup$ – Boogeyman Feb 21 '18 at 16:28
0
$\begingroup$

I don't know if this helps for your actual use case, but you can try using Simplify:

Simplify[x^4, x^2==z]

z^2

$\endgroup$
  • $\begingroup$ Sorry this is not what I meant. This question has obviously many answer as way out. I was thinking of putting some module which factors out x^4 to x^2 * x^2 and do the replacement. $\endgroup$ – Boogeyman Feb 21 '18 at 17:00
0
$\begingroup$

It would be helpful if you could give more examples; but it sounds like what you're trying to do is replace a composite variable (x^2), rather than just x. You can do this by holding the expression containing the composite variable in an unevaluated state, as follows:

Unevaluated[x^2] /. x^2 -> z

z

For more complicated composite variables, you might need to do something like this:

Unevaluated[x^2] /. HoldPattern@x^2 -> z

That's not needed for the above example, but it is for this:

Unevaluated[
2 Exp[-\[Beta] (Subscript[\[Epsilon], 
   R] - \[Mu])] Exp[-\[Beta] \[Epsilon]]] /. 
   HoldPattern@Exp[-\[Beta] (Subscript[\[Epsilon], R] - \[Mu])] :> x

The one limitation you'll encounter is that the composite variable to be substituted needs to appear in the exact form you use in the replacement statement. Thus this will return z^2:

Unevaluated[x^2*x^2] /. x^2 -> z 

...but this will return x^4:

Unevaluated[x^4] /. x^2 -> z
$\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.