Skip to content

Commit

Permalink
Trac #30372: Replace NumberField_generic.__latex_variable_name by ._l…
Browse files Browse the repository at this point in the history
…atex_names

as observed in #30360,
{{{
sage: K3.<a> = NumberField(x^3+x^2+1, latex_name=['alpha'])
sage: K3.latex_variable_names()
['a']
sage: K3.latex_variable_name()
'alpha'
}}}

We fix this by changing the attribute `__latex_variable_name`, only used
in `NumberField_generic`, to the widely used `_latex_names`.

We also deprecate the method `latex_variable_name`, which is also only
used in `sage.rings.number_field`, changing its uses to
`latex_variable_names`.

URL: https://trac.sagemath.org/30372
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Aug 23, 2020
2 parents be525d6 + da551dc commit 027d34e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
29 changes: 17 additions & 12 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
import sage.rings.ring
from sage.misc.latex import latex_variable_name
from sage.misc.misc import union
from sage.misc.superseded import deprecation

from .unit_group import UnitGroup
from .class_group import ClassGroup
Expand Down Expand Up @@ -890,8 +891,8 @@ def QuadraticField(D, name='a', check=True, embedding=True, latex_name='sqrt', *
\sqrt{-7}
sage: latex(1/(1+a))
-\frac{1}{8} \sqrt{-7} + \frac{1}{8}
sage: K.latex_variable_name()
'\\sqrt{-7}'
sage: list(K.latex_variable_names())
['\\sqrt{-7}']
We can provide our own name as well::
Expand Down Expand Up @@ -1370,7 +1371,7 @@ def __init__(self, polynomial, name, latex_name,
raise ValueError("defining polynomial (%s) must be irreducible"%polynomial)

self._assign_names(name)
self.__latex_variable_name = latex_name
self._latex_names = (latex_name,)
self.__polynomial = polynomial
self._pari_bnf_certified = False
self._integral_basis_dict = {}
Expand Down Expand Up @@ -3244,16 +3245,19 @@ def latex_variable_name(self, name=None):
EXAMPLES::
sage: NumberField(x^2 + 3, 'a').latex_variable_name()
doctest:...: DeprecationWarning: This method is replaced by ...
See https://trac.sagemath.org/30372 for details.
'a'
sage: NumberField(x^3 + 3, 'theta3').latex_variable_name()
'\\theta_{3}'
sage: CyclotomicField(5).latex_variable_name()
'\\zeta_{5}'
"""
deprecation(30372, 'This method is replaced by the method latex_variable_names')
if name is None:
return self.__latex_variable_name
return self._latex_names[0]
else:
self.__latex_variable_name = name
self._latex_names = (name,)

def _repr_(self):
"""
Expand Down Expand Up @@ -3294,8 +3298,9 @@ def _latex_(self):
sage: print(k._latex_())
\Bold{Q}[\theta_{25}]/(\theta_{25}^{25} + \theta_{25} + 1)
"""
return "%s[%s]/(%s)"%(latex(QQ), self.latex_variable_name(),
self.polynomial()._latex_(self.latex_variable_name()))
latex_name = self.latex_variable_names()[0]
return "%s[%s]/(%s)"%(latex(QQ), latex_name,
self.polynomial()._latex_(latex_name))

def _ideal_class_(self, n=0):
"""
Expand Down Expand Up @@ -9677,11 +9682,11 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True):
"with respect to %s"%p)
else:
if not p in self.real_places():
raise ValueError("entries of the list must be " +
raise ValueError("entries of the list must be "
"prime ideals or real places")
if p(b) > 0:
raise ValueError("%s is a square in the completion " +
"with respect to %s" %(b,p))
raise ValueError("%s is a square in the completion "
"with respect to %s" % (b, p))

# L is the list of primes that we need to consider, b must have
# nonzero valuation for each prime in L, this is the set S'
Expand Down Expand Up @@ -10309,7 +10314,7 @@ def _latex_(self):
sage: latex(f)
\left(z^{2} + z\right) s
"""
v = self.latex_variable_name()
v = self.latex_variable_names()[0]
if v.startswith('\\zeta_'):
return "%s(%s)"%(latex(QQ), v)
else:
Expand Down Expand Up @@ -11427,7 +11432,7 @@ def _latex_(self):
sage: latex(Z) # indirect doctest
\Bold{Q}[x]/(x^{2} - 7)
"""
v = self.latex_variable_name()
v = self.latex_variable_names()[0]
if v.startswith('\\sqrt'):
return "%s(%s)"%(latex(QQ), v)
else:
Expand Down
3 changes: 2 additions & 1 deletion src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ cdef class NumberFieldElement(FieldElement):
sage: latex(zeta12^4-zeta12) # indirect doctest
\zeta_{12}^{2} - \zeta_{12} - 1
"""
return self.polynomial()._latex_(name=self.number_field().latex_variable_name())
latex_name = self.number_field().latex_variable_names()[0]
return self.polynomial()._latex_(name=latex_name)

def _gap_init_(self):
"""
Expand Down
5 changes: 3 additions & 2 deletions src/sage/rings/number_field/number_field_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,9 @@ def _latex_(self):
sage: K.extension(t^2+t+a, 'b')._latex_()
'( \\Bold{Q}[a]/(a^{3} - 2) )[b]/(b^{2} + b + a)'
"""
return "( %s )[%s]/(%s)"%(latex(self.base_field()), self.latex_variable_name(),
self.relative_polynomial()._latex_(self.latex_variable_name()))
latex_name = self.latex_variable_names()[0]
return "( %s )[%s]/(%s)"%(latex(self.base_field()), latex_name,
self.relative_polynomial()._latex_(latex_name))

def _coerce_from_other_number_field(self, x):
"""
Expand Down

0 comments on commit 027d34e

Please sign in to comment.