Re: How does a rule get applied?
- To: mathgroup@smc.vnet.net
- Subject: [mg12485] Re: How does a rule get applied?
- From: "Allan Hayes" <hay@haystack.demon.cc.uk>
- Date: Tue, 19 May 1998 13:31:48 -0400
- References: <6jf2mg$3vl@smc.vnet.net>
Yacine Ait-Sahalia gives the following example: x^a + x^(1+a) /. x^(n_) + x^(n_+1) ->0 x^3 + x^(1+3) /. x^(n_) + x^(n_+1) ->0 x^3 /. x^(n_) ->0 Out[388]= 0 Out[389]= 3 4 x + x Out[390]= 0 And asks why the second output is not 0. Yacine: x^3 + x^(1+3) evaluates to x^3 + x^4 before replacement is tried, so there is no match. To get round this we can temporarily hold until replacement is done: Unevaluated[x^3 + x^(1+3)] /. x^(n_) + x^(n_+1) ->0 0 Allan Hayes Training and Consulting Leicester UK http://www.haystack.demon.co.uk hay@haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44(0)116 271 8642