ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 30 Jun 2011 07:53:37 -0500How to give latex names to generators of polynomial rings?https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/Apologies if I don't use the right terminology in my question. I'm fairly new to Sage and programming.
The question is basically in the title but here are more details:
Ideally I would like to create a multivariate polynomial ring with generators indexed by multiindices. As far as I understand this is not directly supported at the moment, although I've found a useful workaround [here]( http://groups.google.com/group/sage-support/browse_thread/thread/925a4795098546e6?pli=1).
What I'm missing though is the ability to display these generators correctly in LaTex (say as a_{i,j}). I know that one can assign latex names to symbolic variables with the command
`sage: a_ij=var('a_ij', latex_name="a_{i,j}");`
`sage: latex(a_ij);`
`a_{i,j}`
And I've tried putting this before the definition of my polynomial ring. But as soon as I declare the polynomial ring the latex name I assigned seems to be forgotten:
`sage: inject_on();`
`sage: PolynomialRing(QQ,a_ij)`
`sage: latex(a_ij);`
`a_{\mbox{ij}}`
So:
>Question: How can I define a multivariate polynomial ring in Sage and assign my preferred latex names to its generators?Thu, 30 Jun 2011 05:18:10 -0500https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/Answer by Simon King for <p>Apologies if I don't use the right terminology in my question. I'm fairly new to Sage and programming.</p>
<p>The question is basically in the title but here are more details: </p>
<p>Ideally I would like to create a multivariate polynomial ring with generators indexed by multiindices. As far as I understand this is not directly supported at the moment, although I've found a useful workaround <a href="http://groups.google.com/group/sage-support/browse_thread/thread/925a4795098546e6?pli=1">here</a>. </p>
<p>What I'm missing though is the ability to display these generators correctly in LaTex (say as a_{i,j}). I know that one can assign latex names to symbolic variables with the command</p>
<p><code>sage: a_ij=var('a_ij', latex_name="a_{i,j}");</code></p>
<p><code>sage: latex(a_ij);</code></p>
<p><code>a_{i,j}</code></p>
<p>And I've tried putting this before the definition of my polynomial ring. But as soon as I declare the polynomial ring the latex name I assigned seems to be forgotten:</p>
<p><code>sage: inject_on();</code></p>
<p><code>sage: PolynomialRing(QQ,a_ij)</code></p>
<p><code>sage: latex(a_ij);</code></p>
<p><code>a_{\mbox{ij}}</code></p>
<p>So:</p>
<blockquote>
<p>Question: How can I define a multivariate polynomial ring in Sage and assign my preferred latex names to its generators?</p>
</blockquote>
https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/?answer=12478#post-id-12478First of all, when you define `a_ij=var('a_ij')` then you define symbolic variables. But when you later do (with `inject_on()`) `PolynomialRing(QQ,a_ij)`, then `a_ij` becomes a generator of a polynomial ring.
It is a very common mistake to confuse these two very different objects, and I recommend that you carefully decide whether you want to work with polynomials (i.e., you have a polynomial ring, ideals, want to compute Gröbner bases and those things) or with symbolic expressions (they may happen to look like a polynomial, but provide largely different features).
In particular, since `a_ij` has completely changed its meaning, it is no surprise that the latex name has gone.
You could do:
sage: R.<a_12,a_23> = QQ[] # you don't need inject_on()
sage: type(a_12) # It is not a symbolic variable!
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
sage: latex(a_12) # This is not how you like it
a_{12}
sage: R._latex_names # This is where the names are stored
['a_{12}', 'a_{23}']
sage: R._latex_names = ['a_{1,2}','a_{2,3}'] # Override it...
sage: latex(a_12) # ... and enjoy
a_{1,2}
I think it is a hack, and there *should* be a method, say, `R.set_latex_names()`, but unfortunately there isn't, yet.
Thu, 30 Jun 2011 06:21:47 -0500https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/?answer=12478#post-id-12478Comment by Simon King for <p>First of all, when you define <code>a_ij=var('a_ij')</code> then you define symbolic variables. But when you later do (with <code>inject_on()</code>) <code>PolynomialRing(QQ,a_ij)</code>, then <code>a_ij</code> becomes a generator of a polynomial ring.</p>
<p>It is a very common mistake to confuse these two very different objects, and I recommend that you carefully decide whether you want to work with polynomials (i.e., you have a polynomial ring, ideals, want to compute Gröbner bases and those things) or with symbolic expressions (they may happen to look like a polynomial, but provide largely different features).</p>
<p>In particular, since <code>a_ij</code> has completely changed its meaning, it is no surprise that the latex name has gone.</p>
<p>You could do:</p>
<pre><code>sage: R.<a_12,a_23> = QQ[] # you don't need inject_on()
sage: type(a_12) # It is not a symbolic variable!
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
sage: latex(a_12) # This is not how you like it
a_{12}
sage: R._latex_names # This is where the names are stored
['a_{12}', 'a_{23}']
sage: R._latex_names = ['a_{1,2}','a_{2,3}'] # Override it...
sage: latex(a_12) # ... and enjoy
a_{1,2}
</code></pre>
<p>I think it is a hack, and there <em>should</em> be a method, say, <code>R.set_latex_names()</code>, but unfortunately there isn't, yet.</p>
https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/?comment=21525#post-id-21525Yep, if you intend to use Gröbner bases then a (multivariate) polynomial ring is the right tool - symbolic variables do not offer much (or any?) functionality in that context.Thu, 30 Jun 2011 07:53:37 -0500https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/?comment=21525#post-id-21525Comment by Michael for <p>First of all, when you define <code>a_ij=var('a_ij')</code> then you define symbolic variables. But when you later do (with <code>inject_on()</code>) <code>PolynomialRing(QQ,a_ij)</code>, then <code>a_ij</code> becomes a generator of a polynomial ring.</p>
<p>It is a very common mistake to confuse these two very different objects, and I recommend that you carefully decide whether you want to work with polynomials (i.e., you have a polynomial ring, ideals, want to compute Gröbner bases and those things) or with symbolic expressions (they may happen to look like a polynomial, but provide largely different features).</p>
<p>In particular, since <code>a_ij</code> has completely changed its meaning, it is no surprise that the latex name has gone.</p>
<p>You could do:</p>
<pre><code>sage: R.<a_12,a_23> = QQ[] # you don't need inject_on()
sage: type(a_12) # It is not a symbolic variable!
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
sage: latex(a_12) # This is not how you like it
a_{12}
sage: R._latex_names # This is where the names are stored
['a_{12}', 'a_{23}']
sage: R._latex_names = ['a_{1,2}','a_{2,3}'] # Override it...
sage: latex(a_12) # ... and enjoy
a_{1,2}
</code></pre>
<p>I think it is a hack, and there <em>should</em> be a method, say, <code>R.set_latex_names()</code>, but unfortunately there isn't, yet.</p>
https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/?comment=21526#post-id-21526Thanks! That seems to work. Indeed there are several things I don't quite understand about variables and how they are handled and accessed. I knew that there was a difference between symbolic variables and generators of a polynomial ring. So in my example the symbolic variable was redefined to be a generator of a polynomial ring and got lost? Anyway I do indeed need Groebner bases so symbolic variables should not be of interest in my situation. Thu, 30 Jun 2011 06:37:34 -0500https://ask.sagemath.org/question/8202/how-to-give-latex-names-to-generators-of-polynomial-rings/?comment=21526#post-id-21526