Is there an "inverse" to the ToRules function? That is, a function
that converts rules to equations (expressed in == form), which could
then be used in the Solve function?
Thanks,
Mark
Two ideas:
{a->b,{c:>d}}/.r:Rule|RuleDelayed -> Equal
{a==b,{c==d}}
ToEquations[(Rule|RuleDelayed)[x_,y_]]:= x==y;
ToEquations[z_]:= z;
ToEquations//@{a->b,{c:>d}}
{a==b,{c==d}}
You might want to flatten the outputs.
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
h...@haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Mark S. Coleman" <mcol...@bondspace.com> wrote in message
news:9pjgi4$3fr$1...@smc.vnet.net...
>Is there an "inverse" to the ToRules function? That is, a function
>that converts rules to equations (expressed in == form), which could
>then be used in the Solve function?
>
{a -> b, c -> d, e -> f} /.
(x_ -> y_) :> (x == y)
{a == b, c == d, e == f}
Bob Hanlon
Chantilly, VA USA
This is easy if you understand the structure of Mathematica expressions.
Try evaluating
myrule=(a->b)
myeqn = Equal@@myrule (or Apply[Equal,myrule])
and you will have turned a rule into an equation. To understand it better,
look at
FullForm[myrule]
FullForm[myeqn]
to see that you just had to change the Head of the expression.
I hope this helps,
John Jowett
My home page: http://home.cern.ch/jowett/
Postal address: SL Division, CERN, CH-1211 Geneva 23, Switzerland
"Mark S. Coleman" <mcol...@bondspace.com> wrote in message
news:9pjgi4$3fr$1...@smc.vnet.net...
>
In[10]:=
b = Solve[x^2 - 2 == 0, x]
Out[10]=
{{x -> -Sqrt[2]}, {x -> Sqrt[2]}}
In[11]:=
ToExpression[StringReplace[ToString[b], "->" -> "=="]]
Out[11]=
{{x == -Sqrt[2]}, {x == Sqrt[2]}}
But I think it is better to stick to the solution expressed in terms of
rules. It takes a while to get used to it, but it pays. The rule has a
definite meaning which can be used in a ReplaceAll operation, whereas
something like the last output, with two "Equal" functions for the same x,
can lead to confusion.
Tomas Garza
Mexico City