# How to intersect subspaces of a combinatorial free module? Hi, I've defined a CombinatorialFreeModule over ZZ with a pretty large named basis, along with a family of subspaces using .submodule(). In the documentation, I see that the class FreeModule_generic_field has a method .intersection() to intersect these subspaces - is there a way to do this for the combinatorial free modules as well? I can think of some very ugly messy solutions by abandoning the CombinatorialFreeModule class, but I was hoping there'd be a better way.

Here's a toy example:

Z = CombinatorialFreeModule(ZZ, ['a','b','c'], prefix="z")
z = Z.basis()
Z1 = Z.submodule([z['a'],z['b']])
Z2 = Z.submodule([z['b'],z['c']])


I'd like to be able to write something like Z1.intersection(Z2) to get a submodule containing just z['b']. Of course, the real example has a very large number of submodules with much more complicated generators.

edit retag close merge delete

Sort by » oldest newest most voted 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().lift().parent()
assert Z == Z2.basis().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()] )

more