Re: Sequence is funny !

• To: mathgroup at smc.vnet.net
• Subject: [mg8950] Re: [mg8852] Sequence is funny !
• From: Peder Thusgaard Ruhoff <ptr at mip.ou.dk>
• Date: Mon, 6 Oct 1997 01:59:18 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Gilles BARBIER wrote:
>      For some people who like to understand the internal mechanism
>      of Mathematica, I give them this little problem a friend sent to me:
>
>      Why Table[i,{i,Sequence[1,3]}] gives {1,2,3,4} instead of {1,2,3}!!
>
>      That's not a bug, I even have an explanation,if you are interested.
>
>      Hope it's fun,
>
>      Gilles.

============================================================================
In[1]:= Table[i,{i,Sequence[1,3]}]

Out[1]= {1, 2, 3, 4}
============================================================================

Using the built-in command Evaluate you can get the "expected" result

============================================================================
In[2]:= Table[i, Evaluate[{i, Sequence[1, 3]}]]

Out[2]= {1, 2, 3}
============================================================================

To see what is really goin on I recommen using the built-in command On

============================================================================
In[3]:= On[]

On::trace: On[] --> Null.

In[4]:= Table[i,{i,Sequence[1,3]}]

Plus::trace: Sequence[1, 3] - 1 --> 1 + 3 - 1.

Plus::trace: 1 + 3 - 1 --> -1 + 1 + 3.

Plus::trace: -1 + 1 + 3 --> 3.

Plus::trace: 1 + (Sequence[1, 3] - 1) --> 1 + 3.

Plus::trace: 1 + 3 --> 4.

Floor::trace: Floor[4] --> 4.

i::trace: i --> 1.

i::trace: i --> 2.

i::trace: i --> 3.

i::trace: i --> 4.

Table::trace: Table[i, {i, Sequence[1, 3]}] --> {1, 2, 3, 4}.

Out[4]= {1, 2, 3, 4}

In[5]:= Table[i,Evaluate[{i, Sequence[1, 3]}]]

List::trace: {i, Sequence[1, 3]} --> {i, 1, 3}.

Table::trace: Table[i, Evaluate[{i, Sequence[1, 3]}]] --> Table[i, {i, 1,3}].

Plus::trace: 3 - 1 --> 2.

Plus::trace: 1 + (3 - 1) --> 1 + 2.

Plus::trace: 1 + 2 --> 3.

Floor::trace: Floor[3] --> 3.

i::trace: i --> 1.

i::trace: i --> 2.

i::trace: i --> 3.

Table::trace: Table[i, {i, 1, 3}] --> {1, 2, 3}.

Out[5]= {1, 2, 3}
===========================================================================

Hope the above helps.

Peder

-------------------------------------+--------------------------------------
Peder Thusgaard Ruhoff, Ph.D.        | Phone:     (+45) 63 15 71 12
The Maersk Mc-Kinney Moller          | Secretary: (+45) 63 15 71 63
Institute for Production Technology  | Fax:       (+45) 65 93 23 09
Odense University                    |
Campusvej 55                         | E-mail: ptr at mip.ou.dk
DK-5230 Odense M, DENMARK            | URL:    http://www.mip.ou.dk
-------------------------------------+--------------------------------------

"It is important for him who wants to discover not to confine himself to one
chapter of science, but to keep in touch with various others" - J. Hadamard

```

• Prev by Date: Re: Piecewise functions
• Next by Date: Re: Sequence is funny !
• Previous by thread: Re: Sequence is funny !
• Next by thread: Re: Sequence is funny !