# Replace terms in an expression by a single variable?

Posted 3 months ago
475 Views
|
3 Replies
|
4 Total Likes
|
 Hi, I have a symbolic expression, say: exp1 == (r P^(-1))/Log[S/N0] Since I know that Log[S/N0]/r is equal to something special (namely T), I want to replace that terms by T: T == Log[S/N0]/r and get something like exp2 from exp1 using that special term. I.e.: exp2 = 1/(P * T) I tried several things like: Simplify[(r P^(-1 + a))/Log[S/N0], T == Log[S/N0]/r] But I am not getting any simplification of exp1 to get exp2 knowing that 1/T is r/Log[S/N0].Does anybody know how to do this kind of thing in Mathematica? How to simplify exp1 to get exp2? Answer
3 Replies
Sort By:
Posted 3 months ago
 Rafael,Normally for simple expressions you can use Replace[] (also typed /.):For example: In:= eqn = exp1 == (r P^(-1))/Log[S/N0] Out= exp1 == r/(P Log[S/N0]) In:= eqn /. S/N0 -> xx Out= exp1 == r/(P Log[xx]) HOWEVER, this relies on the pattern matching features of Mathematica and can fail on expressions that simplify in a variety of ways (such as your case with Log[S/N0]/r -> T)This fails because In:= FullForm[eqn] OutEqual[exp1,Times[Power[P,-1],r,Power[Log[Times[Power[N0,-1],S]],-1]]] EDITED: Note that your expression has a different form than the original so you can't do a pattern match without getting a bit more clever and account for the simplified terms in the multiplication. Another approach is to use Reduce[]. Reduce is a bit more complicated to use but it does respect the mathematical relationships.In your case: In:= Reduce[{exp1 == (r P^(-1))/Log[S/N0], T == Log[S/N0]/r}, {T}] Out= P Log[S/N0] != 0 && exp1 == r/(P Log[S/N0]) && exp1 != 0 && T == 1/(exp1 P) Which gives you the answer with additional information that the denominator can't go to zero. The downside of this is that you then need to parse the result to pick out what you want.Regards,Neil Answer
Posted 3 months ago
 Thank you! This is exactly what I was looking for. Answer
Posted 3 months ago
 As to getting pattern matching to work, you can use the fullform to give you insight as to a pattern to match: In:= eqn /. Times[r, Power[Log[Times[Power[N0, -1], S]], -1]] -> T Out= exp1 == T/P Regards Answer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments