[Date Index]
[Thread Index]
[Author Index]
Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg84387] Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]
*From*: dh <dh at metrohm.ch>
*Date*: Thu, 20 Dec 2007 16:52:06 -0500 (EST)
*References*: <fkcueh$5d9$1@smc.vnet.net>
Hi,
with "Information[..] or ?? for short" you can see what is stored. In
version 6, as you can convince yourself, only one definition ist stored.
I do not have version 2 or 3 available so I can not tell what is going
on there.
Daniel
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:
**using Dsolve for equation: y'' + |y|^2y=ay**
Next by Date:
**Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]**
Previous by thread:
**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]**
| |