MathGroup Archive 2004

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

Search the Archive

Re: Mathematica language issues

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52997] Re: Mathematica language issues
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Sun, 19 Dec 2004 06:14:42 -0500 (EST)
  • References: <200412171020.FAA16185@smc.vnet.net> <cq0tm1$2m2$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Andrzej Kozlowski wrote:
> On 17 Dec 2004, at 19:20, Maxim wrote:
> 
> 
>>In[5]:=
>>Unevaluated[1 + 1]*2
>>2*Unevaluated[1 + 1]
>>
>>Out[5]=
>>4
>>
>>Out[6]=
>>2*Unevaluated[1 + 1]
>>
> 
> 
> This is not a glitch but works exactly as one woudl expect.  You can 
> see the difference and the reason by looking at Trace in both cases 
> (although there is no need for that, if you understand Unevaluated you 
> can see it right away).
> 
> First:
> 2*Unevaluated[1+1]//Trace
> 
> 
> {2 (1+1),2 Unevaluated[1+1]}
> 
> 
> First Unevaluated is stipped away and Mathematica attempts ot evaluate 
> 2*(1+1). Since it knows no rule to apply and the expression has not 
> changed Unevaluated is restored and evaluation is completed with the 
> output you see.
> 
> 
> 
> Unevaluated[1+1]*2//Trace
> 
> {(1+1) 2,2 (1+1),{1+1,2},2 2,4}
> 
> As before, first Unevaluated is stripped away and Mathematica tires to 
> evaluate 2*(1+1). It now knows a rule to apply, which is given by the 
> Orderless attribute and the canonical ordering, so it converts the 
> expression into the form 2 (1+1). But now Unevaluated is not restored 
> because the expression has changed so evaluation continues with 1+1 
> evaluationg to 2 and finally you obtain 4.
> 
> Now, I have honstly considered this case only because I could see at 
> once what what was going on. I do not knwo if any of the others are 
> glitches but jusdging by my experience with the past "language 
> glitches" you have reported (unlike the more serious problems desribed 
> in your last posting) I rather doubt it. However I have no time to 
> spend on this just to prove a point (again).
> 
> 
> 
> Andrzej Kozlowski
> Chiba, Japan
> http://www.akikoz.net/~andrzej/
> http://www.mimuw.edu.pl/~akoz/
> 
To be fair to Maxim,

You have to read between the lines of the documentation a little to 
appreciate that Unevaluated should work this way - perhaps this could be 
considered a 'documentation glitch'!

David Bailey
dbaileyconsultancy.co.uk


  • Prev by Date: Re: An argument pattern problem: ranges and lists
  • Next by Date: Re: An argument pattern problem: ranges and lists
  • Previous by thread: Re: Mathematica language issues
  • Next by thread: Re: Re: Mathematica language issues