1
$\begingroup$

I have several equations with many variables, and here and there I would like to do a variable substitution. For example, in the equation:

a (b + 42 c / d)

I might want to remap variables a * b --> p and a * c / d --> q in order to get:

p + 42 q 

Can Mathematica do this? I tried to play with the With[] and Rule[] function and the like, but that doesn't seem to produce anything. I can imagine that Mathematica is not capable of doing such a thing, but I thought it would be worth asking.

And the pro question: And then very much related to this: is there a way to use With[] not to set a single variable but to set variable relations, e.g. the sum or product of two variables. So that this:

With[{a * b = 5},  a (b + 42 c / d)] (* This doesn't work*)

would reduce to:

5 + 42 a * c / d
$\endgroup$
2
$\begingroup$
rules = {a b -> p, a c / d -> q}
Expand[a (b + 42 c/d)] /. rules
(*p + 42  q*)
$\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.