MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: algebraic ReplaceAll?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122275] Re: algebraic ReplaceAll?
  • From: Dushan Mitrovich <dushanm at spinn.net>
  • Date: Sun, 23 Oct 2011 06:23:26 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201110221006.GAA29609@smc.vnet.net> <07CC24DB-3CB9-4535-A3C1-3CF965438F37@mimuw.edu.pl>

Andrzej Kozlowski wrote:
> Mathematica pattern matching is syntactical and based on the FullForm of an expression. These full forms show that you are not going to get a match:
>
> In[15]:= FullForm[Hold[-x + w]]
>
> Out[15]//FullForm= Hold[Plus[Times[-1,x],w]]
>
> In[16]:= FullForm[x - w]
>
> Out[16]//FullForm= Plus[Times[-1,w],x]
>
> If you want to make algebraic replacements you have to use algebra, not pattern matching. For example:
>
> Last[PolynomialReduce[-x + w, w - x - y, {x, w, y}]]
>
> y
>
> Or, if you need something more powerful, perhaps look here
>
> http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/634a54e2e844837f/ddf3803cab4f3a5f?lnk=gst&q=replacementfunction#ddf3803cab4f3a5f
> here
> http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/1397ca25b770b9af/59f63501668f7fbe?lnk=gst&q=replacementfunction#59f63501668f7fbe
>
> and lots of other similar posts on this topic.
>
> Andrzej Kozlowski

Thanks for the links.  I hadn't appreciated the number of ways a 
particular approach can come back and bite you.

- Dushan
>
> On 22 Oct 2011, at 12:06, Dushan Mitrovich wrote:
>
>> Is there a way to get ReplaceAll to actalgebraically, so it recognizes
>> the negative of a replaced quantity as well as the positive?  For
>> example, this works
>>      In:   x-w /. x-w->y
>>      Out: y
>>
>> but these don't
>>      In:   -x+w /. x-w->y
>>            w-x  /. x-w->y
>>      Out: w-x
>>            w-x
>>
>> - Dushan
>>
>>
>>
>>
>
>




  • Prev by Date: Re: Ticks without labels
  • Next by Date: AbsoluteTime[] runs slowly?
  • Previous by thread: Re: algebraic ReplaceAll?
  • Next by thread: Re: algebraic ReplaceAll?