Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

latex printing of polynomials

I have a code that generates some symbolic polynomials. I would like to generate the latex code for this polynomials to present them in the form: $ a_n \ s^n + a_{n-1} \ s^{n-1} + ... + a_1 \ s + a_0 $, where the coefficients $ a_n, ..., a_0 $ can be Real or Complex. The snippet below shows how I accomplish this.

var("s")
polynomial(s) = 115109024454248/712169248941107*(8*s^4 + 8*s^2 + 1)/pi - 1406886797940560/2486758794631057*(2*s^2 + 1)/pi + 59613932955136480/18544180962144109/pi
type(polynomial(s))
type(polynomial(s).polynomial(RR))
latex(polynomial(s).polynomial(RR))
# type(polynomial(s).polynomial(CC))
# latex(polynomial(s).polynomial(CC))

polynomial2(s) = 0.411591379742810*s^4 + 0.000000000000000*s^3 + 0.0514229729855488*s^2 + 0.000000000000000*s + 0.894634727759564
type(polynomial2(s))
latex(polynomial2(s))

the code outputs

s
<type 'sage.symbolic.expression.Expression'>
<type 'sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense'>
0.411591379742810 s^{4} + 0.000000000000000 s^{3} + 0.0514229729855488 s^{2} + 0.000000000000000 s + 0.894634727759564
<type 'sage.symbolic.expression.Expression'>
0.411591379742810 \, s^{4} + 0.0514229729855488 \, s^{2} + 0.894634727759564

Now, the questions are:

1) Is printing polynomials terms with zero coefficients the intended behavior for the _latex()_ command when operating over type 'sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense' and class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class'? the _latex()_ command behaves differently when operating over symbolic polynomials.

2) Is there a way to set the displayed number of digits?

3) Is there a better way to present such symbolic polynomials in latex code in the desired format?

Cordially