Ask Your Question

Revision history [back]

The problem may be simply that you need to give CombinatorialFreeModule a list of basis elements:

sage: P = PolynomialRing(QQ,'x')
sage: Q = PolynomialRing(QQ,'y')
sage: R = PolynomialRing(QQ,'z')
sage: C = CombinatorialFreeModule(QQ,[P,Q,R])
sage: C
Free module generated by {Univariate Polynomial Ring in x over Rational Field, Univariate Polynomial Ring in y over Rational Field, Univariate Polynomial Ring in z over Rational Field} over Rational Field
sage: B = [x for x in C.basis()]
sage: q = 3/5*B[0] + 1/2*B[1]
sage: q
3/5*B[Univariate Polynomial Ring in x over Rational Field] + 1/2*B[Univariate Polynomial Ring in y over Rational Field]
sage: q in C
True

sage: P.rename('p')
sage: Q.rename('q')
sage: R.rename('r')
sage: C = CombinatorialFreeModule(QQ,[P,Q,R])
sage: C
Free module generated by {p, q, r} over Rational Field

Is this something like what you're trying to do?

You've probably seen it already, but here's the documentation for CombinatorialFreeModule. If this still isn't doing what you want, you could try implementing addition and scalar multiplication for your class; this is described in the "How To Implement" section of the Coercion documentation.