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

• To: mathgroup at smc.vnet.net
• Subject: [mg84366] ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f
• From: cebailey <cbailey at wlgore.com>
• Date: Thu, 20 Dec 2007 00:10:58 -0500 (EST)

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

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: Button Question
• Next by Date: Re: Updating NumberPadding?
• Previous by thread: Re: Trouble with double factorial and an infinite product
• Next by thread: Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f