Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5821

Re: algebraic ReplaceAll?

From Andrzej Kozlowski <akoz@mimuw.edu.pl>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: algebraic ReplaceAll?
Date 2011-10-23 10:33 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j80qic$afl$1@smc.vnet.net> (permalink)
References <201110221006.GAA29609@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: algebraic ReplaceAll? Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-10-23 10:33 +0000

csiph-web