Defining a Sage vector subspace by modifying the basis of another subspace gives unexpected results

3 weeks ago 20
ARTICLE AD BOX

I feel like I'm going crazy, so I'm fully expecting this to be a result of some horrible user error on my part. That said—

I am trying to write code to determine whether certain vector subspaces are invariant under the action of certain matrices. In particular, this requires defining subspaces, acting on those subspaces with a matrix, and checking whether the new subspace is equal to the old subspace. Unfortunately, this does not seem to be behaving the way I would expect.

Consider the following Sage code, which defines a two-dimensional vector space over the finite field GF(2) and a couple subspaces:

F = GF(2) V = VectorSpace(F,2) u = matrix(F, [[1, 1], [0, 1]]) v1 = vector(F, [0,1]) V1 = V.subspace([v1]) uV1 = V.subspace([u*v for v in V1.basis()]) print(uV1.basis(), uV1 == V1)

I expect this to print [(1,1)] False, because uV1 should be the vector subspace with basis [(1,1)]. Indeed, when I replace the last line of the above code with print([u*v for v in V1.basis()]), Sage prints [(1,1)].

However, when I execute the code as written above, Sage instead prints [(0,1)] True.

What is going on here? Why is the subspace uV1 not being defined correctly, and how can I modify the code to fix this?

(In case it is relevant, when I manually define uV1 = V.subspace([(1,1)]), then everything works as expected; in particular, uV1.basis() is [(1,1)] and uV1 == V1 is False.)

Read Entire Article