Skip to content

Commit

Permalink
adding the category keyword to padic rings and fields classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Jan 9, 2025
1 parent 1be0a58 commit a069568
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 40 deletions.
31 changes: 21 additions & 10 deletions src/sage/rings/padics/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
sage: R = QpLF(2)
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2007-2013 David Roe <[email protected]>
# William Stein <[email protected]>
#
Expand All @@ -26,10 +26,11 @@
# the License, or (at your option) any later version.
#
# https://www.gnu.org/licenses/
#*****************************************************************************
# ****************************************************************************

from sage.misc.superseded import experimental

from sage.categories.fields import Fields
from sage.structure.factory import UniqueFactory
from sage.rings.integer import Integer
from sage.rings.infinity import Infinity
Expand Down Expand Up @@ -783,35 +784,45 @@ def create_object(self, version, key):
pass
p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec, label = key

_Fields = Fields()

if type == 'capped-rel':
if print_mode == 'terse':
return pAdicFieldCappedRelative(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name)
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name,
category=_Fields)
else:
return pAdicFieldCappedRelative(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name,
category=_Fields)
elif type == 'floating-point':
if print_mode == 'terse':
return pAdicFieldFloatingPoint(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name)
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name,
category=_Fields)
else:
return pAdicFieldFloatingPoint(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name,
category=_Fields)
elif type == 'relaxed':
if print_mode == 'terse':
return pAdicFieldRelaxed(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name)
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name,
category=_Fields)
else:
return pAdicFieldRelaxed(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name,
category=_Fields)
elif type[:8] == 'lattice-':
subtype = type[8:]
if print_mode == 'terse':
return pAdicFieldLattice(p, prec, subtype, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name, label)
'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name, label,
category=_Fields)
else:
return pAdicFieldLattice(p, prec, subtype, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name, label)
'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name, label,
category=_Fields)
else:
raise ValueError("unexpected type")

Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/padics/generic_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class pAdicLatticeGeneric(pAdicGeneric):
sage: R._prec_type()
'lattice-float'
"""
def __init__(self, p, prec, print_mode, names, label=None):
def __init__(self, p, prec, print_mode, names, label=None, category=None):
"""
Initialization.
Expand Down Expand Up @@ -357,7 +357,7 @@ def __init__(self, p, prec, print_mode, names, label=None):
else:
raise ValueError("subtype must be either 'cap' or 'float'")
self._element_class = self.__make_element_class__(element_class)
pAdicGeneric.__init__(self, self, p, prec, print_mode, names, None)
pAdicGeneric.__init__(self, self, p, prec, print_mode, names, None, category=category)

def _prec_type(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/padics/padic_base_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class pAdicBaseGeneric(pAdicGeneric):
_implementation = 'GMP'

def __init__(self, p, prec, print_mode, names, element_class):
def __init__(self, p, prec, print_mode, names, element_class, category=None):
"""
Initialization.
Expand All @@ -47,7 +47,7 @@ def __init__(self, p, prec, print_mode, names, element_class):
self.prime_pow = PowComputer_flint(p, 1, 1, 1, self.is_field())
else:
self.prime_pow = PowComputer(p, max(min(prec - 1, 30), 1), prec, self.is_field(), self._prec_type())
pAdicGeneric.__init__(self, self, p, prec, print_mode, names, element_class)
pAdicGeneric.__init__(self, self, p, prec, print_mode, names, element_class, category=category)
if self.is_field():
if self.is_capped_relative():
coerce_list = [pAdicCoercion_ZZ_CR(self), pAdicCoercion_QQ_CR(self)]
Expand Down
52 changes: 26 additions & 26 deletions src/sage/rings/padics/padic_base_leaves.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class pAdicRingCappedRelative(pAdicRingBaseGeneric, pAdicCappedRelativeRingGener
An implementation of the `p`-adic integers with capped relative
precision.
"""
def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand Down Expand Up @@ -247,7 +247,7 @@ def __init__(self, p, prec, print_mode, names):
....: max_runs=2^5, skip='_test_log')
sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) # long time
"""
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedRelativeElement)
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedRelativeElement, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -309,7 +309,7 @@ class pAdicRingCappedAbsolute(pAdicRingBaseGeneric, pAdicCappedAbsoluteRingGener
r"""
An implementation of the `p`-adic integers with capped absolute precision.
"""
def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand Down Expand Up @@ -345,7 +345,7 @@ def __init__(self, p, prec, print_mode, names):
....: max_runs=2^5, skip='_test_log')
sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)])
"""
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedAbsoluteElement)
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedAbsoluteElement, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -410,7 +410,7 @@ class pAdicRingFloatingPoint(pAdicRingBaseGeneric, pAdicFloatingPointRingGeneric
An implementation of the `p`-adic integers with floating point
precision.
"""
def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand Down Expand Up @@ -446,7 +446,7 @@ def __init__(self, p, prec, print_mode, names):
....: max_runs=2^5, skip='_test_log')
sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)])
"""
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFloatingPointElement)
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFloatingPointElement, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -505,7 +505,7 @@ class pAdicRingFixedMod(pAdicRingBaseGeneric, pAdicFixedModRingGeneric):
r"""
An implementation of the `p`-adic integers using fixed modulus.
"""
def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand Down Expand Up @@ -550,7 +550,7 @@ def __init__(self, p, prec, print_mode, names):
sage: K(R(90))
3*5 + 3*5^2
"""
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFixedModElement)
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFixedModElement, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -618,7 +618,7 @@ class pAdicFieldCappedRelative(pAdicFieldBaseGeneric, pAdicCappedRelativeFieldGe
sage: K = Qp(101) # indirect doctest
"""

def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand Down Expand Up @@ -660,7 +660,7 @@ def __init__(self, p, prec, print_mode, names):
....: max_runs=2^5, skip='_test_log')
sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)])
"""
pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedRelativeElement)
pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedRelativeElement, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -749,7 +749,7 @@ class pAdicFieldFloatingPoint(pAdicFieldBaseGeneric, pAdicFloatingPointFieldGene
An implementation of the `p`-adic rationals with floating point
precision.
"""
def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand Down Expand Up @@ -786,7 +786,7 @@ def __init__(self, p, prec, print_mode, names):
....: max_runs=2^5, skip='_test_log')
sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)])
"""
pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFloatingPointElement)
pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFloatingPointElement, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -881,7 +881,7 @@ class pAdicRingLattice(pAdicLatticeGeneric, pAdicRingBaseGeneric):
sage: R
2-adic Ring with lattice-cap precision (label: init)
"""
def __init__(self, p, prec, subtype, print_mode, names, label=None):
def __init__(self, p, prec, subtype, print_mode, names, label=None, category=None):
"""
Initialization.
Expand All @@ -893,11 +893,11 @@ def __init__(self, p, prec, subtype, print_mode, names, label=None):
# We need to set the subtype first, so that
# pAdicRingBaseGeneric.__init__ can work
self._subtype = subtype
if isinstance(prec,tuple):
pAdicRingBaseGeneric.__init__(self, p, prec[1], print_mode, names, None)
if isinstance(prec, tuple):
pAdicRingBaseGeneric.__init__(self, p, prec[1], print_mode, names, None, category=category)
else:
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, None)
pAdicLatticeGeneric.__init__(self, p, prec, print_mode, names, label)
pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, None, category=category)
pAdicLatticeGeneric.__init__(self, p, prec, print_mode, names, label, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -1012,7 +1012,7 @@ class pAdicFieldLattice(pAdicLatticeGeneric, pAdicFieldBaseGeneric):
sage: R
2-adic Field with lattice-cap precision (label: init)
"""
def __init__(self, p, prec, subtype, print_mode, names, label=None):
def __init__(self, p, prec, subtype, print_mode, names, label=None, category=None):
"""
Initialization.
Expand All @@ -1024,11 +1024,11 @@ def __init__(self, p, prec, subtype, print_mode, names, label=None):
# We need to set the subtype first, so that
# pAdicFieldBaseGeneric.__init__ can work
self._subtype = subtype
if isinstance(prec,tuple):
pAdicFieldBaseGeneric.__init__(self, p, prec[1], print_mode, names, None)
if isinstance(prec, tuple):
pAdicFieldBaseGeneric.__init__(self, p, prec[1], print_mode, names, None, category=category)
else:
pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, None)
pAdicLatticeGeneric.__init__(self, p, prec, print_mode, names, label)
pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, None, category=category)
pAdicLatticeGeneric.__init__(self, p, prec, print_mode, names, label, category=category)

def _coerce_map_from_(self, R):
"""
Expand Down Expand Up @@ -1137,7 +1137,7 @@ class pAdicRingRelaxed(pAdicRelaxedGeneric, pAdicRingBaseGeneric):
sage: type(R) # needs sage.libs.flint
<class 'sage.rings.padics.padic_base_leaves.pAdicRingRelaxed_with_category'>
"""
def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand All @@ -1151,7 +1151,7 @@ def __init__(self, p, prec, print_mode, names):
"""
from sage.rings.padics import padic_relaxed_element
self._default_prec, self._halting_prec, self._secure = prec
pAdicRingBaseGeneric.__init__(self, p, self._default_prec, print_mode, names, padic_relaxed_element.pAdicRelaxedElement)
pAdicRingBaseGeneric.__init__(self, p, self._default_prec, print_mode, names, padic_relaxed_element.pAdicRelaxedElement, category=category)
self._element_class_module = padic_relaxed_element
self._element_class_prefix = "pAdicRelaxedElement_"

Expand All @@ -1176,7 +1176,7 @@ class pAdicFieldRelaxed(pAdicRelaxedGeneric, pAdicFieldBaseGeneric):
sage: type(R) # needs sage.libs.flint
<class 'sage.rings.padics.padic_base_leaves.pAdicFieldRelaxed_with_category'>
"""
def __init__(self, p, prec, print_mode, names):
def __init__(self, p, prec, print_mode, names, category=None):
"""
Initialization.
Expand All @@ -1190,6 +1190,6 @@ def __init__(self, p, prec, print_mode, names):
"""
from sage.rings.padics import padic_relaxed_element
self._default_prec, self._halting_prec, self._secure = prec
pAdicFieldBaseGeneric.__init__(self, p, self._default_prec, print_mode, names, padic_relaxed_element.pAdicRelaxedElement)
pAdicFieldBaseGeneric.__init__(self, p, self._default_prec, print_mode, names, padic_relaxed_element.pAdicRelaxedElement, category=category)
self._element_class_module = padic_relaxed_element
self._element_class_prefix = "pAdicRelaxedElement_"

0 comments on commit a069568

Please sign in to comment.