Re: Question regarding replacement
- To: mathgroup at smc.vnet.net
- Subject: [mg63874] Re: Question regarding replacement
- From: Peter Pein <petsie at dordos.net>
- Date: Fri, 20 Jan 2006 04:32:27 -0500 (EST)
- References: <dqn812$la9$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
michael_chang86 at hotmail.com schrieb:
> Hi,
>
> Often, when manipulating symbolic results, one might want to replace
> some symbols with "simpler" expressions, and typically, I've managed
> this with "/.". However, suppose that
>
> In[1]: a = b c/d
>
> and I know that d/(b c) = theta. Unfortunately,
>
> In[2]: params={d/(b c)->theta}; a/.params
> does *not* yield 1/theta. How can I achieve this simply *without*
> redefining params?
>
> (This (too) simple example is meant to demonstrate some difficulties
> that I typically encounter when trying to replace symbols in *much*
> more complicated expressions, where, sometimes, the symbols that I am
> trying to replace are inverted ... :( )
>
> My apologies in advance, since this seems embarassingly simple, but any
> help or suggestions would be greatly appreciated!
>
> Regards,
>
> Michael
>
Hi Michael,
a starting point might be:
In[1]:=
Clear[simp];
simp[x_ == fx_, y_ == fy_] :=
Module[{sol = Solve[{x == fx, y == fy}, x, Intersection @@
Variables /@ {fx, y - fy}]},
If[sol == {}, x == fx, x == (x /. First[sol])]]
In[3]:=
simp[a == (b*c)/d, d/(b*c) == theta]
Out[3]=
a == 1/theta
In[4]:=
simp[l1_List, l2_List] := Fold[simp[#1, #2]& , #1, l2]& /@ l1
In[5]:=
simp[{a == (b*c)/d, b == e + d*a}, {d/(b*c) == theta, e - b == g}]
Out[5]=
{a == 1/theta, b == -(g/(a*c*theta))}
In[6]:=
Solve[%, {a, b}]
Out[6]=
{{b -> -(g/c), a -> 1/theta}}