Re: Pattern matching
- To: mathgroup at smc.vnet.net
 - Subject: [mg116222] Re: Pattern matching
 - From: Bob Hanlon <hanlonr at cox.net>
 - Date: Mon, 7 Feb 2011 06:05:52 -0500 (EST)
 
Because 
fact[0] -> 0 * fact[-1] -> 0 
causing the product to be zero and terminating the recursion.
In slow motion
rules = {fact[n_] :> n fact[n - 1], fact[0] -> 1};
fact[4] /. rules
4 fact[3]
% /. rules
12 fact[2]
% /. rules
24 fact[1]
% /. rules
24 fact[0]
% /. rules
0
Bob Hanlon
---- 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!