Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5808
| From | Dushan Mitrovich <dushanm@spinn.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: algebraic ReplaceAll? |
| Date | 2011-10-23 10:27 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j80q5s$acm$1@smc.vnet.net> (permalink) |
| 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
>>
>>
>>
>>
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: algebraic ReplaceAll? Dushan Mitrovich <dushanm@spinn.net> - 2011-10-23 10:27 +0000
csiph-web