MathGroup Archive 2011

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

Search the Archive

Re: Pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116245] Re: Pattern matching
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Tue, 8 Feb 2011 05:06:07 -0500 (EST)

Leonid,

I've been caught in thousands of errors, but as far as I know, this is  
your first.

Don't let it get to be a habit!

Bobby

On Mon, 07 Feb 2011 13:11:51 -0600, Leonid Shifrin <lshifr at gmail.com>  
wrote:

> Bobby,
>
> Yes, indeed, you are right. Thanks for the correction!
>
> Regards,
> Leonid
>
> On Mon, Feb 7, 2011 at 9:39 PM, DrMajorBob <btreat1 at austin.rr.com> wrote:
>
>> No... the rule is never applied to fact[-1].
>>
>> If it were, there WOULD be an infinite loop, since fact[-1] -> -1  
>> fact[-2]
>> (not -1 times the previous zero).
>>
>> The previous zero, multiplied by fact[-1] (unevaluated) is zero, and
>> there's no rule for zero, so ReplaceRepeated stops.
>>
>> Bobby
>>
>>
>> On Mon, 07 Feb 2011 05:07:14 -0600, Leonid Shifrin <lshifr at gmail.com>
>> wrote:
>>
>>  This is not a bug.  The second rule indeed has no chance to execute.  
>> The
>>> reason that this does not iterate infinitely is that when the first  
>>> rule
>>> applies for n = 0, we get zero as a result. The next time the rule is
>>> applied for n = -1, we get zero again, since we multiply -1 and the
>>> previous
>>> zero. Since the two consecutive  results are the same, ReplaceRepeated
>>> stops.
>>>
>>> I used a similar example in my book, where  I made the same statement  
>>> that
>>> we should expect infinite iteration, which is apparently incorrect for
>>> this
>>> particular problem, as you just pointed out. Will add this to a list of
>>> things I have to correct.
>>>
>>> Regards,
>>> Leonid
>>>
>>>
>>> On Sun, Feb 6, 2011 at 1:35 PM, StatsMath <stats.math8 at gmail.com>  
>>> wrote:
>>>
>>>  Have a question regarding the applicaiton of pattern rules:
>>>>
>>>> fact[4] //. {fact[n_] :> n fact[n-1], fact[0] -> 1}
>>>>
>>>> This is a bug since fact[0] needs to be defined 1st, but I expected
>>>> the above to grind away idefnitely but it returned a a value 0,
>>>> instead of an infininte computation.
>>>>
>>>> Can you help me understand why the above returns 0?
>>>>
>>>> Thanks!
>>>>
>>>>
>>>>
>>
>> --
>> DrMajorBob at yahoo.com
>>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Pattern matching
  • Next by Date: Re: Excel XLS Import slowdown in version 8
  • Previous by thread: Re: Pattern matching
  • Next by thread: Pattern matching