ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 06 Feb 2018 14:02:07 +0100How to properly declare indeterminates so that they exist in the coefficient ring.https://ask.sagemath.org/question/40918/how-to-properly-declare-indeterminates-so-that-they-exist-in-the-coefficient-ring/I'm working on a project regarding generalization of symmetric polynomials.
For the sake of simplicity, I will ask my question in the context of a minimalistic (not) working example.
Let say I am working with Symmetric Functions, I'll write an erroneous code so that you get the idea of what I'm looking for
QQt = QQ['t'].fraction_field()
Sym = SymmetricFunctions(QQt); Sym.inject_shorthands()
a0 = var('a0')
expr1 = m[1,1]
expr2 = m[2] + a0*m[1,1]
eqsys = expr1.scalar_jack(expr2)
solve(eqsys, a0)
The I get the error ```unsupported operand parent(s) for *: 'Symbolic Ring' and 'Symmetric Functions over Fraction Field of Univariate Polynomial Ring in alpha over Rational Field in the monomial basis'```
OK, so I tried this instead
QQt = QQ['t,a0'].fraction_field()
t, a0 = QQt.gens()
Sym = SymmetricFunctions(QQt); Sym.inject_shorthands()
expr1 = m[1,1]
expr2 = m[2] + a0*m[1,1]
eqsys = expr1.scalar_jack(expr2)
solve(eqsys, a0)
```a0 is not a valid variable```
So then I did the following
sln = solve(SR(eqsys), SR(a0))
and it works. But the probleme is that I can't convert the solution back
QQt(sln)
```('cannot convert {!r}/{!r} to an element of {}', {a0: 2/(t + 1)}, 1, Fraction Field of Multivariate Polynomial Ring in t, a0 over Rational Field)```
And anyway this last solution does not seem very canonical. How should I proceed?
I guess that somehow what I am asking is how to declare ```a0, a1, ...``` as symbols element of QQt. Thu, 01 Feb 2018 15:48:50 +0100https://ask.sagemath.org/question/40918/how-to-properly-declare-indeterminates-so-that-they-exist-in-the-coefficient-ring/Answer by FrédéricC for <p>I'm working on a project regarding generalization of symmetric polynomials. </p>
<p>For the sake of simplicity, I will ask my question in the context of a minimalistic (not) working example. </p>
<p>Let say I am working with Symmetric Functions, I'll write an erroneous code so that you get the idea of what I'm looking for </p>
<pre><code>QQt = QQ['t'].fraction_field()
Sym = SymmetricFunctions(QQt); Sym.inject_shorthands()
a0 = var('a0')
expr1 = m[1,1]
expr2 = m[2] + a0*m[1,1]
eqsys = expr1.scalar_jack(expr2)
solve(eqsys, a0)
</code></pre>
<p>The I get the error <code>unsupported operand parent(s) for *: 'Symbolic Ring' and 'Symmetric Functions over Fraction Field of Univariate Polynomial Ring in alpha over Rational Field in the monomial basis'</code>
OK, so I tried this instead</p>
<pre><code>QQt = QQ['t,a0'].fraction_field()
t, a0 = QQt.gens()
Sym = SymmetricFunctions(QQt); Sym.inject_shorthands()
expr1 = m[1,1]
expr2 = m[2] + a0*m[1,1]
eqsys = expr1.scalar_jack(expr2)
solve(eqsys, a0)
</code></pre>
<p><code>a0 is not a valid variable</code>
So then I did the following </p>
<pre><code> sln = solve(SR(eqsys), SR(a0))
</code></pre>
<p>and it works. But the probleme is that I can't convert the solution back</p>
<pre><code>QQt(sln)
</code></pre>
<p><code>('cannot convert {!r}/{!r} to an element of {}', {a0: 2/(t + 1)}, 1, Fraction Field of Multivariate Polynomial Ring in t, a0 over Rational Field)</code></p>
<p>And anyway this last solution does not seem very canonical. How should I proceed?
I guess that somehow what I am asking is how to declare <code>a0, a1, ...</code> as symbols element of QQt. </p>
https://ask.sagemath.org/question/40918/how-to-properly-declare-indeterminates-so-that-they-exist-in-the-coefficient-ring/?answer=40922#post-id-40922Like that (avoid using var is my best advice)
sage: eqsys = a0*(t+1)-1
sage: sln = solve(SR(eqsys), SR(a0),solution_dict=True)[0]; sln
{a0: 1/(t + 1)}
sage: eqsys.subs({QQt(a): QQt(b) for a, b in sln.items()})
0
A bit heavy of course.
Then you should use subs on every coefficientThu, 01 Feb 2018 17:54:51 +0100https://ask.sagemath.org/question/40918/how-to-properly-declare-indeterminates-so-that-they-exist-in-the-coefficient-ring/?answer=40922#post-id-40922Comment by LAV for <p>Like that (avoid using var is my best advice)</p>
<pre><code>sage: eqsys = a0*(t+1)-1
sage: sln = solve(SR(eqsys), SR(a0),solution_dict=True)[0]; sln
{a0: 1/(t + 1)}
sage: eqsys.subs({QQt(a): QQt(b) for a, b in sln.items()})
0
</code></pre>
<p>A bit heavy of course.</p>
<p>Then you should use subs on every coefficient</p>
https://ask.sagemath.org/question/40918/how-to-properly-declare-indeterminates-so-that-they-exist-in-the-coefficient-ring/?comment=40996#post-id-40996In the end this worked. For future reference, in more general cases I ended up with systems of equations in QQ['alpha, 'a0', 'a1', ...].fraction_field() which produced big expressions that somehow sage was confused about (it tried to expand the fractions as power series instead of factoring and simplifying). Factoring and simplifying did not work since the gcd was not well defined. I ended up sending the system of equation to singular for simplification, then back to sage, converted to symbolic ring, solved, converted the solution back to my ring. It still looks like a crazy workaround to me though, but it does work.Tue, 06 Feb 2018 14:02:07 +0100https://ask.sagemath.org/question/40918/how-to-properly-declare-indeterminates-so-that-they-exist-in-the-coefficient-ring/?comment=40996#post-id-40996