MathGroup Archive 2011

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

Search the Archive

Re: algebraic ReplaceAll?

  • To: mathgroup at
  • Subject: [mg122288] Re: algebraic ReplaceAll?
  • From: Andrzej Kozlowski <akoz at>
  • Date: Sun, 23 Oct 2011 06:25:50 -0400 (EDT)
  • Delivered-to:
  • References: <>

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 

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}]]


Or, if you need something more powerful, perhaps look here


and lots of other similar posts on this topic.

Andrzej Kozlowski

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: strange error
  • Next by Date: Re: Ticks without labels
  • Previous by thread: algebraic ReplaceAll?
  • Next by thread: Re: algebraic ReplaceAll?