Re: Mathematica language issues

• To: mathgroup at smc.vnet.net
• Subject: [mg52970] Re: [mg52955] Mathematica language issues
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sat, 18 Dec 2004 03:59:46 -0500 (EST)
• References: <200412171020.FAA16185@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```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/

```

• Prev by Date: Re: Mathematica slows down
• Next by Date: Re: Mathematica language issues
• Previous by thread: Mathematica language issues
• Next by thread: Re: Mathematica language issues