| 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()] )
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.