MathGroup Archive 2004

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

Search the Archive

Re: Mathematica language issues

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53011] Re: Mathematica language issues
  • From: Maxim <ab_def at prontomail.com>
  • Date: Sun, 19 Dec 2004 06:15:22 -0500 (EST)
  • References: <200412171020.FAA16185@smc.vnet.net> <cq0tm1$2m2$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Sat, 18 Dec 2004 09:36:01 +0000 (UTC), Andrzej Kozlowski  
<akoz at mimuw.edu.pl> 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/
>

I do not agree. Suppose we evaluate z*Unevaluated[1 + 1]; according to  
your explanation, after the reordering of the factors Unevaluated should  
disappear from the final result. However, the expression evaluates to  
Unevaluated[1 + 1]*z. Further, suppose we take Unevaluated[1  
+ 1]*Sin[Pi/4]: Sin[Pi/4] evaluates to 1/Sqrt[2], so in this case an  
evaluation step definitely takes place; however, the output is  
Unevaluated[1 + 1]/Sqrt[2]. Your theory simply doesn't work. But even if  
it did, there is another problem: suppose I use Sin[Pi/8] instead of  
Sin[Pi/4] -- then first you would need to know whether Mathematica has a  
built-in rule for Sin[Pi/8] to arrive at any conclusion as to how it might  
work with Unevaluated (that is, what will count as an evaluation step?).  
So to apply your explanation we would have to search through all the  
built-in rules of Mathematica.

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Re: Re: Mathematica slows down
  • Next by Date: Re: creating exact numbers, strange behavior
  • Previous by thread: Re: Re: Mathematica language issues
  • Next by thread: Re: Re: Mathematica language issues