Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A possible solution:

W.intersection(W1.complement())

A possible solution:

W.intersection(W1.complement())

UPDATE. As explained in the comments, this does not quite work over finite fields. Here is a somewhat slower alternative:

# computes the complement of U in A
def mycomplement(U,A):
    R = A.subspace([])
    while U.dimension() < A.dimension():
        while True:
            if (v := A.random_element()) not in U:
                break
        U += span([v])
        R += span([v])
    return R

W2_ = mycomplement(W1,W)
assert W == W1 + W2_ and W1.intersection(W2_).dimension()==0