IMHO the bug here is a lack of validation. Its perfectly fine to have 
mutable elements of a vector subspace, but y.__setitem__ should then check 
that the vector really is in the subspace or raise a ValueError. Of course 
it would almost always raise, so its not a particularly useful operation.



O Wednesday, May 27, 2015 at 5:38:18 PM UTC+2, 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?
>
> - 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?
>
> Best,
> Johan
>

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