[Date Index]
[Thread Index]
[Author Index]
Re: Why doesn't this rule work?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg32478] Re: Why doesn't this rule work?
*From*: "Allan Hayes" <hay at haystack.demon.co.uk>
*Date*: Wed, 23 Jan 2002 00:59:52 -0500 (EST)
*References*: <a2j7ra$717$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Andrzej,
I agree that RuleCondition is very useful, and I have queried why it is not
a regular function with full documentation..
However, Condition works as well in this case:
c - a - b /. (n1_.)*c + (n2_.)*a :> n1*b /; n1 == -n2
0
The difference between Condition and RuleCondition shows up below: Condition
replaces with 1+1; RuleCondition replaces with its value, 2.
Hold[a] /. a :> Condition[1 + 1,True]
Hold[1+1]
Hold[a] /. a :> RuleCondition[1 + 1, True]
Hold[2]
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Andrzej Kozlowski" <andrzej at tuins.ac.jp> wrote in message
news:a2j7ra$717$1 at smc.vnet.net...
> I think the best way is to use RuleCondition instead of Rule and
> Condition as you did. (Unfortunately RuleCondition, one of the most
> useful Mathematica functions in this sort of situations, is
> undocumented...)
>
> In[1]:=
> c-a-b/.n1_. c+n2_. a:>RuleCondition[n1 b,n1==-n2]
>
> Out[1]=
> 0
>
> Andrzej Kozlowski
> Toyama International University
> JAPAN
> http://platon.c.u-tokyo.ac.jp/andrzej/
>
>
>
> On Monday, January 21, 2002, at 04:54 PM, James Jennings wrote:
>
> > Suppose I want to simplify expressions linear in a, b, and c where a+b=c
> > -- something of this sort.
> >
> > In[]:= a+b /. a+b -> c
> >
> > Out[]= c
> >
> > In[]:= a+b+c /. a+b -> c
> >
> > Out[]= 2 c
> >
> > With more complicated coefficients I can use:
> >
> > In[]:= -2 a - 2 b /. n_. a+n_. b -> n c
> >
> > Out[]= -2 c
> >
> > In[]:= -a-b+c /. n_. a+n_. b -> n c
> >
> > Out[]= 0
> >
> > I also want to apply rules based on c-a=b
> >
> > In[]:= c-a /. n1_. c+n2_. a /; n1==-n2 -> n1 b
> >
> > Out[]= b
> >
> > The problem comes with I apply the above rule to longer expressions.
> >
> > In[]:= c-a-b /. n1_. c+n2_. a /; n1==-n2 -> n1 b
> >
> > Out[]= -a-b+c
> >
> > Why didn't that work? I had thought that since Plus[] is Orderless, my
> > rule ought to be applied to all pieces of my expression, but it doesn't
> > appear to be.
> >
> > ---
> >
> > Before someone suggests that I should just set c = a+b and be done with
> > it, my actual problem involved 12 objects like a, b, and c, where 16
> > distinct triplets add up like a+b=c. I'm looking for rules that will
> > keep my expressions as short as possible, even if they aren't unique.
> >
> > Thanks.
> > James
> >
> >
> >
>
>
Prev by Date:
**Re: Unstable solutions to NonlinearFit**
Next by Date:
**Mathematica for Linux font problem on SuSE7.3**
Previous by thread:
**Re: Why doesn't this rule work?**
Next by thread:
**RE: Re: Why doesn't this rule work?**
| |