# Span Set nasty bug

84 views
Skip to first unread message

### roby

unread,
Dec 16, 2011, 6:09:30 AM12/16/11
to
Dear group & Mathematica team

I am trying to assign a non existing element member of a 2D List.
Due to the coosen Span the element should not exist respectivly not be
assigned.
when the non existing element is queried e.g. {} should be returned

please take a look on the following assignment:

In[43]:= t = Table[0, {15}, {15}];
t[[1 ;; 0, 1 ;; 1]] = 1;
t[[1 ;; 0, 1 ;; 1]]
t[[1, 1]]

Out[45]= {}

Out[46]= 0

so far so good no element gets assigned and the query works,
after changing 15 to 16 or greater the query still works but the
following happens element [[1,1]] gets a value assigned:

In[47]:= t = Table[0, {16}, {16}];
t[[1 ;; 0, 1 ;; 1]] = 1;
t[[1 ;; 0, 1 ;; 1]]
t[[1, 1]]

Out[49]= {}

Out[50]= 1

Is this a bug or is it a feature ?

### DrMajorBob

unread,
Dec 17, 2011, 2:46:34 AM12/17/11
to
Bug.

Bobby
--
DrMaj...@yahoo.com

### BernieTheJet

unread,
Dec 19, 2011, 7:20:26 AM12/19/11
to
Feature. Wolfram doesn't do bug testing before they sell stuff, that
is our job.

B

### Shizu

unread,
Dec 20, 2011, 3:07:05 AM12/20/11
to
But what do you mean by t[[1;;0,1;;1]]?
Could a Span be from 1 to 0?
I've never seen this before.
Can't find an usage/example in Mathematica documents.

This is how I use Span for a matrix:

In[]= t = {{1, 2, 3, 4}, {5, 6, 7, 8}}
Out[]= {{1, 2, 3, 4}, {5, 6, 7, 8}}

In[]= t[[1 ;; 2, 2 ;; 3]] = a
Out[]= a

In[]= t
Out[]= {{1, a, a, 4}, {5, a, a, 8}}

### roby

unread,
Dec 21, 2011, 7:00:21 AM12/21/11
to
Hi Shizu

Imagine in your example that you would like to adjust the number of
a's to be set.
If you try adjusting the number of a' you need a variable span.
Finaly imagine that you would like to adjust the span such that even
no a's at all would be set.

In my application I am generating some Raster[ ] Graphics[ ] where
some features are Set[ ] via Span[ ].
The feature size shall be variable and even zero such that the feature
vanishes.

Regards
Robert

### Oliver Ruebenkoenig

unread,
Dec 22, 2011, 4:26:44 AM12/22/11
to

On Fri, 16 Dec 2011, roby wrote:

> Dear group & Mathematica team
>
> I am trying to assign a non existing element member of a 2D List.
> Due to the coosen Span the element should not exist respectivly not be
> assigned.
> when the non existing element is queried e.g. {} should be returned
>
> please take a look on the following assignment:
>
> In[43]:= t = Table[0, {15}, {15}];
> t[[1 ;; 0, 1 ;; 1]] = 1;
> t[[1 ;; 0, 1 ;; 1]]
> t[[1, 1]]
>
> Out[45]= {}
>
> Out[46]= 0
>
> so far so good no element gets assigned and the query works,
> after changing 15 to 16 or greater the query still works but the
> following happens element [[1,1]] gets a value assigned:
>
> In[47]:= t = Table[0, {16}, {16}];
> t[[1 ;; 0, 1 ;; 1]] = 1;
> t[[1 ;; 0, 1 ;; 1]]
> t[[1, 1]]
>
> Out[49]= {}
>
> Out[50]= 1
>
> Is this a bug or is it a feature ?
>
>

Roby, are you aware that expr[[0]] gives access to the head? Why do you do
it this way?

The fact that results differ is due to the compilation in Table. You can
modify this behavior (which I do not suggest)

SetSystemOptions["CompileOptions" -> {"TableCompileLength" -> 1}]

I think if you do not want to assign, do not do it.

t[[1]]
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

t[[0]]
List

t[[1 ;; 0]]
{}

Length[t[[1 ;; 0]]]
0

(* it is somewhat unfortunate that the following does not issue a
message *)
t[[1 ;; 0, 1]]
{}

t[[1 ;; 0]][[1]]

Oliver

### roby

unread,
Dec 23, 2011, 7:15:22 AM12/23/11
to
> Roby, are you aware that expr[[0]] gives access to the head?
yes, this is clear to me.
But if you look carful at my post then you will see that I do not
access the element with the array index 0 (the Head).

> I think if you do not want to assign, do not do it.
again look carful at my post I don't want and I do not assign to
element [[1,1]], the assignment just happens by failure!

> (* it is somewhat unfortunate that the following does not issue a message *)
> t[[1 ;; 0, 1]]
... perhaps right perhaps wrong, depends on the exact definition of
Span[ ] wich in turn should depend on what is recognized as suitable.

look at my reply to shizu there I have explained a reasonable
application.
As the Mathematica behavior now is, I of course must prevent empty
Span[ ]

I would prefer a defined behavoiur similar as e.g. for Range[1,0]
which returns an empty List.

One of the principles of Mathematica is elegant functional programming which
e.g. avoids thigs like loops etc., one of the helpful features in this
connection is Span[ ].
As explained I am looking for a construct that assigns a variable
number of elements that means even 0, 1 or any other random number
provided as a variable.
This works perfekt for Matrices < 15x15, pleeeeease, pleeeease fix it
for bigger ones.

By the way I have reported this to the Wolfram support.
The first answer was that the behaviour is "unexpected" and that the
issue is forwarded to the developers.
As I had the pleasure to meet you at the Mathematica 2011 Conference in Vienna
I would not be too much surpised if the isssu would be forwarded to
you ;)

Cheers
Robert

Reply all
Reply to author
Forward
0 new messages