Ask Your Question
1

How to give latex names to generators of polynomial rings?

asked 2011-06-30 12:18:10 +0100

Michael gravatar image

updated 2011-06-30 12:19:58 +0100

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.

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2011-06-30 13:21:47 +0100

Simon King gravatar image

First 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.

edit flag offensive delete link more

Comments

Thanks! 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.

Michael gravatar imageMichael ( 2011-06-30 13:37:34 +0100 )edit

Yep, 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.

Simon King gravatar imageSimon King ( 2011-06-30 14:53:37 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-06-30 12:18:10 +0100

Seen: 2,773 times

Last updated: Jun 30 '11