MathGroup Archive 2007

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

Search the Archive

Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]

  • To: mathgroup at
  • Subject: [mg84393] Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]
  • From: Jens-Peer Kuska <kuska at>
  • Date: Fri, 21 Dec 2007 03:20:22 -0500 (EST)
  • References: <fkcueh$5d9$>


may be the pattern matcher now finds out out that
f[x_] and f[y_] describe the same pattern, while the
early versions of Mathematica where not able to do that.


cebailey wrote:
> ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]
> Evaluating this line in Mathematica 5.2 or Mathematica 6 returns 16. This makes sense, because the second definition replaces the first, as we can see when ?f returns:
> Global`f
> f[y_]:=y^4
> But in _A_Physicist's_Guide_to_Mathematica_ on p.314, Patrick Tam shows an example like this returning the other answer, 4, defined in the first definition. He then demonstrates that ?f returns:
> Global`f
> f[x_] := x^2
> f[y_]:= y^4
> He says his book was developed with Mathematica 2.2 and a prerelease of Mathematica 3 and is compatible with both.
> He goes on to explain:
> "Contrary to expectation, Mathematica used the first definition. The ? operator reveals that Mathematica stores both definitions in the global rule base, giving higher priority to the first definition. (This problem cannot, perhaps, be called a bug because developers of Mathematica are well aware of this design flaw, which is quite difficult to mend....)"
> What is he talking about? Did Mathematica  2.2 and 3 treat this differently? If earlier versions worked in this surprising way, there must have been a reason - what was it? Was it changed to prevent surprises like this example? Did changing it create other unfortunate consequences? Was Tam just wrong? Or do I misunderstand?

  • Prev by Date: Re: disable "disable dynamic updating?"?
  • Next by Date: Re: checking, if a file exists
  • Previous by thread: Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]
  • Next by thread: Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]