Ask Your Question

Revision history [back]

Here is one option, which uses CombinatorialFreeModule, which lets you define a vector space with a named basis. First, define a rational vector space with basis u,v:

sage: R.<u,v> = CombinatorialFreeModule(QQ)

Now define a second vector space with basis given by the "keys" (u,7), (v,8), (u+v, 9):

sage: S = CombinatorialFreeModule(QQ, basis_keys=[(u,7), (v,8), (u+v,9)])
sage: R
Free module generated by {'u', 'v'} over Rational Field
sage: S
Free module generated by {(u, 7), (v, 8), (u + v, 9)} over Rational Field
sage: S.basis()
Finite family {(u, 7): B[(u, 7)], (v, 8): B[(v, 8)], (u + v, 9): B[(u + v, 9)]}

Now define a linear transformation from S to R, which will take the basis element indexed by the pair (w, n) to w, which is the 0th element of this tuple:

sage: f = S.module_morphism(codomain=R, on_basis=lambda i: i[0])

Now compute a basis for the kernel:

sage: f.kernel_basis()
(B[(u, 7)] - B[(u + v, 9)] + B[(v, 8)],)
sage: K = f.kernel_basis()
sage: K[0]  # 0th element, which is the only element, in this basis
B[(u, 7)] - B[(u + v, 9)] + B[(v, 8)]
sage: K[0].coefficients()
[1, -1, 1]