sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.23k stars 429 forks source link

Missing parentheses when typesetting coefficients of multivariate polynomials over number fields #11186

Closed johanrosenkilde closed 13 years ago

johanrosenkilde commented 13 years ago

Notice the missing parenthesis when attempting to typeset a simple multivariate polynomial:

sage: K.<z> = QQ.extension(x^2 + x + 1)
sage: PK.<v,w> = K[]
sage: (z+1)*v
(z + 1)*v
sage: latex((z+1)*v)
z + 1 v

This, of course, means that typesetting in the Notebook will also be wrong.

The error seems not to happen with univariate polynomials.

Component: user interface

Keywords: latex, multivariate polynomials, singular

Author: Johan Sebastian Rosenkilde Nielsen

Reviewer: Mariah Lenox

Merged: sage-4.7.1.alpha4

Issue created by migration from https://trac.sagemath.org/ticket/11186

johanrosenkilde commented 13 years ago
comment:1

I wrote a simple patch to fix the issue and added a doctest for it.

However, sage.libs.singular.polynomial.latex (used for typesetting Singular polynomials) is still very different from -- and seemingly more simple -- than the generic sage.rings.polynomial.polynomial_element.latex; this is perhaps a bit disconcerting and should be looked?

johanrosenkilde commented 13 years ago

Author: Johan S. R. Nielsen

johanrosenkilde commented 13 years ago

Attachment: 11186_missing_parenthesis_multi_singular.patch.gz

Patches sage.libs.singular.polynomial.pyx

johanrosenkilde commented 13 years ago
comment:2

Slightly improved my patch as I discovered that negative coefficients we typeset with a parenthesis. My fix simplifies some existing code as well.

I discovered simultaneously that in univariate polynomials, certain coefficients will get parentheses around them, even when not needed, such as sqrt{-1} (because it contains a '-' even though it's inside the squareroot). As I copied some code from there, multivariate polynomials now also have this behaviour. This broke a doctests, which I changed.

This is not optimal behaviour, but I didn't want to patch univariate polynomials here (the patch might not be simple either -- parsing TeX, eew). Also, I "introduced" the error in multivariate polynomials to this for two reasons: first of all, without a solution to this sqrt-problem, it's a side-effect of "doing the right thing most of the time"; namely in cases such as the one in the ticket description. And this error is worse than a superfluous parenthesis once in a while. Thirdly, I think that it's nice, if all polynomials render more or less the same way.

a9bc4e33-7b98-4180-affc-8dfcef89e22b commented 13 years ago
comment:3

The patch fixes the reported problem. Ran 'make testlong' and all tests passed. Positive review!

a9bc4e33-7b98-4180-affc-8dfcef89e22b commented 13 years ago

Reviewer: Mariah Lenox

jdemeyer commented 13 years ago

Merged: sage-4.7.1.alpha4

jdemeyer commented 13 years ago

Changed author from Johan S. R. Nielsen to Johan Sebastian Rosenkilde Nielsen