MathGroup Archive 2011

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

Search the Archive

Re: Pattern matching

  • To: mathgroup at
  • Subject: [mg116217] Re: Pattern matching
  • From: "Mr. Wizard" <gleam at>
  • Date: Mon, 7 Feb 2011 06:04:56 -0500 (EST)

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

When fact[0] occurs in the expression, it is matched by your first 
rule, and so becomes 0 * fact[0 - 1].

In:= 0 * "some random expression"
Out= 0


  • Prev by Date: Hi
  • Next by Date: Help with Delete cases
  • Previous by thread: Pattern matching
  • Next by thread: Re: Pattern matching