Re: When is a List not a List?
- To: mathgroup at smc.vnet.net
- Subject: [mg90956] Re: [mg90947] When is a List not a List?
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Thu, 31 Jul 2008 06:04:10 -0400 (EDT)
- References: <200807310656.CAA07700@smc.vnet.net>
There is nothing at all quirky about this. Yes, FullForm[Table[g[x, n], {n, 1, 2}]] and FullForm[{g[x, 1], g[x, 2]}] are indeed identical, but that is because FullForm evaluates its argument. But Plot has attribute: In[2]:= Attributes[Plot] Out[2]= {HoldAll, Protected} so, unlike FullForm, it does not evaluate its argument. In your first example, Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}], the first argument of Plot has an explicit List bracket, so Plot can see that it supposed to treat the argument as two different functions, without evaluating the argument. But in the second case, it does not see an explicit bracket, so it treats the entire expression as the graph of a single function (in versions of Mathematica before 6 you would not have got any plot at all in this case). If you use Evaluate in the second code you will get the same result as you get form the first: Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle -> {Red, Blue}] Finally, since you have given ample proof that, in spite of many years of using Mathematica, you have not mastered its basics (this particular issue has been raised and answered a countless number of times on this forum), why do you keep assuming that the problems that you keep coming across are Mathematica's "quirks" rather than (as is much more likely) gaps in your won understanding? What do you think of first year undergraduate students who whenever they do not understand something in their introductory lectures claim that it is wrong, or blame their textbook or their lecture rather then themselves? Andrzej Kozlowski On 31 Jul 2008, at 08:56, AES wrote: > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] > > The FullForm[]s are identical. One Plot[] has red and blue curves; > the > other has two blue curves. > > Quirky! >
- References:
- When is a List not a List?
- From: AES <siegman@stanford.edu>
- When is a List not a List?