ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 13 May 2018 09:10:06 -0500Polynomial rings with an arbitrary infinite set of variableshttp://ask.sagemath.org/question/42325/polynomial-rings-with-an-arbitrary-infinite-set-of-variables/I have a rational function in $\mathbb{Q}(x)$ which can be computed by substitution of a polynomial in the polynomial ring with integer compositions as variables, with coefficients in $\mathbb{Q}(x)$. The compositions can have unbounded parts. For example, one monomial might be $\frac{1}{1-x}C_{[2,2]}C_{[1,3,1]}$, where $C_\lambda$ is a formal variable related to the integer composition $\lambda$.
I would be happy to have this "symbolic" representation as polynomial over the set of all integer compositions, and not just the polynomial after substituting all of the $C_\lambda$'s. I have tried the following two approaches which failed.
1. Using the `InfinitePolynomialRing` class. The setup used:
<pre><code "python">
sage: R = FractionField(QQ["x"])
sage: R.inject_variables()
Defining x
sage: RC.<c> = InfinitePolynomialRing(R)
sage: f = 1/(1-x)*c[3] + 3*c[2]
</code></pre>
But then f.subs does not work:
sage: f.subs({c[3]:5})
...[snip]
TypeError: <class 'sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialGen'> is not hashable
sage: f.subs(c[3]=5) # Expected not to work.
SyntaxError: keyword can't be an expression
There is also a method called `f.specialization` which seems to work with substitution of just one variable, but not with more than one, nor when using an element from `InfinitePolynomialRing(R, "cd")`. There is also the annoyance of using a bijection between the natural numbers and compositions.
2. Using `CombinatorialFreeModule`. I know this might seem as an abuse, but a module can also have the structure of a ring...
<pre><code "python">
sage: R = FractionField(QQ["x"])
sage: FM = FreeAbelianMonoid(Compositions())
sage: CR = Rings().Commutative()
sage: CMR = ModulesWithBasis(R)
sage: M = CombinatorialFreeModule(R, FM, category=(CR,CMR)) # Does not work also with category=None
sage: a = M.an_element(); a*a
...[snip]
TypeError: 'NotImplementedType' object is not callable
</code></pre>
I assume some magic with the `category` argument might help. Note that in my case only a free abelian semigroup indexed by compositions is needed, and not a monoid.
Any help is welcomed.Sun, 13 May 2018 09:10:06 -0500http://ask.sagemath.org/question/42325/polynomial-rings-with-an-arbitrary-infinite-set-of-variables/