Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I'm not sure if the approach below is best possible, but it does the job. Essentially it lifts bases of Z1 and Z2 into Z, constructs the corresponding vector subspaces, intersects them and embeds the result back into Z.

def subm_intersect(Z1,Z2):
    Z = Z1.basis()[0].lift().parent()
    assert Z == Z2.basis()[0].lift().parent()    # Z1 and Z2 shold have the same parent module

    z = Z.basis()

    V = VectorSpace(QQ, len(z))
    V1 = V.subspace( [[b.lift().coefficient(k) for k in z.keys()] for b in Z1.basis()] )
    V2 = V.subspace( [[b.lift().coefficient(k) for k in z.keys()] for b in Z2.basis()] )
    U = V1.intersection(V2)

    return Z.submodule( [Z.linear_combination(zip(z,u)) for u in U.basis()] )