MathGroup Archive 2011

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

Search the Archive

Re: algebraic ReplaceAll?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122288] Re: algebraic ReplaceAll?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 23 Oct 2011 06:25:50 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201110221006.GAA29609@smc.vnet.net>

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




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?