On 27/05/15 17:38, Johan S. R. Nielsen wrote:
Hi Sage-devel

We just crashed our heads against a bug in our code due to extremely weird
semantics of Sage. Consider the following code which creates a sub-space C
of the four-dimensional vector space over the binary field, and then
modifies a *copy* of a vector from the subspace:

F = GF(2)
VS = F^4
C = VS.subspace([ (F.one(),F.one(),F.one(),F.one()) ])
w = C([F.one(),F.one(),F.one(),F.one()])
y = copy(w)
y[0] = F.zero()
print "y's parent is ", y.parent()
print "y is in C: ", y in C
print "y = ", y

The code above is going to print:

y's parent is  Vector space of degree 4 and dimension 1 over Finite Field
of size 2
Basis matrix:
[1 1 1 1]
y is in C:  True
y =  (0, 1, 1, 1)

So even though y is clearly not in our space C, Sage claims it is. The
reason is that y's parent is still this sub-space.

Sage disallows that we modify w, the original vector from C. But we are
allowed to modify the copy y (even encouraged by a warning that Sage prints
when you try to modify c).

I assume everyone agrees the above behaviour is bad? In that case, what is
the bug?

The behavior is bad but I would not call it a bug. You modified wrongly the vector.

- Is it that the copy of c is allowed to be mutated (for instance, without
first casting it into the ambient vector space)?

- Is it that the parent of y is still C immediately after copying?

- Or is it that the parent of y is still C after modification?

- Or a fourth option I didn't think of?

The parent is not modified by FreeModuleElement.__setitem__. It is of course not a problem for element of a free module. But on the other hand you can not hope to preserve the fact that you belong to a given subspace by modifying entries.

If it was me I would set the parent to be the ambient space and not the subspace itself (but it might break a lot of code).

Vincent

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to