Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fixing errors in the coercion to the fraction field for fixed-mod p-a…
Browse files Browse the repository at this point in the history
…dics
  • Loading branch information
roed314 committed Aug 3, 2017
1 parent bc95b69 commit 7e62f70
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 45 deletions.
67 changes: 30 additions & 37 deletions src/sage/rings/padics/FM_template.pxi
Expand Up @@ -1271,6 +1271,8 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism):
a
"""
cdef FMElement x = _x
if ciszero(x.value, x.prime_pow):
return self._zero
cdef FPElement ans = self._zero._new_c()
ans.ordp = cremove(ans.unit, x.value, x.prime_pow.ram_prec_cap, x.prime_pow)
return ans
Expand Down Expand Up @@ -1308,17 +1310,17 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism):
"""
cdef long aprec, rprec
cdef FMElement x = _x
if ciszero(x.value):
if ciszero(x.value, x.prime_pow):
return self._zero
cdef FPElement ans = self._zero._new_c()
cdef bint reduce = False
_process_args_and_kwds(&aprec, &rprec, args, kwds, False, ans.prime_pow)
_process_args_and_kwds(&aprec, &rprec, args, kwds, False, x.prime_pow)
ans.ordp = cremove(ans.unit, x.value, aprec, x.prime_pow)
if aprec < ans.ordp + rprec:
rprec = aprec - ans.ordp
if rprec <= 0:
return self._zero
creduce(ans.unit, ans.unit, rprec, ans.prime_pow)
creduce(ans.unit, ans.unit, rprec, x.prime_pow)
return ans

def section(self):
Expand All @@ -1331,9 +1333,13 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism):
sage: R.<a> = ZqFM(27)
sage: K = R.fraction_field()
sage: f = K.coerce_map_from(R)
sage: f(K.gen())
sage: f.section()(K.gen())
a + O(3^20)
"""
from sage.misc.constant_function import ConstantFunction
if not isinstance(self._section.domain, ConstantFunction):
import copy
self._section = copy.copy(self._section)
return self._section

cdef dict _extra_slots(self, dict _slots):
Expand Down Expand Up @@ -1361,7 +1367,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism):
"""
_slots['_zero'] = self._zero
_slots['_section'] = self._section
_slots['_section'] = self.section() # use method since it copies coercion-internal sections.
return RingHomomorphism._extra_slots(self, _slots)

cdef _update_slots(self, dict _slots):
Expand All @@ -1383,7 +1389,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism):
sage: g is f
False
sage: g(a)
a + O(3^20)
a
sage: g(a) == f(a)
True
Expand Down Expand Up @@ -1464,16 +1470,10 @@ cdef class pAdicConvert_FM_frac_field(Morphism):
"""
cdef FPElement x = _x
if x.ordp < 0: raise ValueError("negative valuation")
if x.ordp >= self._zero.prime_pow.ram_prec_cap:
return self._zero
cdef FMElement ans = self._zero._new_c()
cdef bint reduce = False
ans.absprec = x.relprec + x.ordp
if ans.absprec > ans.prime_pow.ram_prec_cap:
ans.absprec = ans.prime_pow.ram_prec_cap
reduce = True
if x.ordp >= ans.absprec:
csetzero(ans.value, ans.prime_pow)
else:
cshift(ans.value, x.unit, x.ordp, ans.absprec, ans.prime_pow, reduce)
cshift(ans.value, x.unit, x.ordp, ans.prime_pow.ram_prec_cap, ans.prime_pow, x.ordp > 0)
return ans

cpdef Element _call_with_args(self, _x, args=(), kwds={}):
Expand All @@ -1490,42 +1490,35 @@ cdef class pAdicConvert_FM_frac_field(Morphism):
sage: K = R.fraction_field()
sage: f = R.convert_map_from(K); a = K(a)
sage: f(a, 3)
a + O(3^3)
sage: b = 9*a
a + O(3^20)
sage: b = 117*a
sage: f(b, 3)
a*3^2 + O(3^3)
a*3^2 + O(3^20)
sage: f(b, 4, 1)
a*3^2 + O(3^3)
a*3^2 + O(3^20)
sage: f(b, 4, 3)
a*3^2 + O(3^4)
a*3^2 + a*3^3 + O(3^20)
sage: f(b, absprec=4)
a*3^2 + O(3^4)
a*3^2 + a*3^3 + O(3^20)
sage: f(b, relprec=3)
a*3^2 + O(3^5)
a*3^2 + a*3^3 + a*3^4 + O(3^20)
sage: f(b, absprec=1)
O(3)
O(3^20)
sage: f(K(0))
O(3^20)
"""
cdef long aprec, rprec
cdef FPElement x = _x
if x.ordp < 0: raise ValueError("negative valuation")
if x.ordp >= self._zero.prime_pow.ram_prec_cap:
return self._zero
cdef FMElement ans = self._zero._new_c()
cdef bint reduce = False
_process_args_and_kwds(&aprec, &rprec, args, kwds, True, ans.prime_pow)
if x.relprec < rprec:
rprec = x.relprec
reduce = True
ans.absprec = rprec + x.ordp
if aprec < ans.absprec:
ans.absprec = aprec
reduce = True
if x.ordp >= ans.absprec:
csetzero(ans.value, ans.prime_pow)
else:
sig_on()
cshift(ans.value, x.unit, x.ordp, ans.absprec, ans.prime_pow, reduce)
sig_off()
if rprec < aprec - x.ordp:
aprec = x.ordp + rprec
sig_on()
cshift(ans.value, x.unit, x.ordp, aprec, ans.prime_pow, x.ordp > 0)
sig_off()
return ans

cdef dict _extra_slots(self, dict _slots):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/padics/FM_template_header.pxi
Expand Up @@ -46,4 +46,4 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism):
cdef FPElement _zero
cdef Morphism _section
cdef class pAdicConvert_FM_frac_field(Morphism):
cdef FPElement _zero
cdef FMElement _zero
13 changes: 7 additions & 6 deletions src/sage/rings/padics/local_generic.py
Expand Up @@ -365,6 +365,13 @@ def get_unramified_modulus(q, res_name):
(functor_dict['print_mode'].get('mode') == 'digits' and p > getattr(functor, "p", p))):
from .padic_printing import _printer_defaults
kwds['alphabet'] = _printer_defaults.alphabet()[:p]
# For fraction fields of fixed-mod rings, we need to explicitly set show_prec = False
if 'field' in kwds and 'type' not in kwds:
if self._prec_type() == 'capped-abs':
kwds['type'] = 'capped-rel'
elif self._prec_type() == 'fixed-mod':
kwds['type'] = 'floating-point'
kwds['show_prec'] = False # This can be removed once printing of fixed mod elements is changed.

# There are two kinds of functors possible:
# CompletionFunctor and AlgebraicExtensionFunctor
Expand All @@ -378,12 +385,6 @@ def get_unramified_modulus(q, res_name):
field = kwds.pop('field')
if field:
ring = ring.fraction_field()
if 'type' not in kwds:
if self._prec_type() == 'capped-abs':
kwds['type'] = 'capped-rel'
elif self._prec_type() == 'fixed-mod':
kwds['type'] = 'floating-point'
kwds['show_prec'] = False # This can be removed once printing of fixed mod elements is changed.
elif ring.is_field():
ring = ring.ring_of_integers()
for atr in ('p', 'prec', 'type'):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/padics/padic_base_leaves.py
Expand Up @@ -701,7 +701,7 @@ def _coerce_map_from_(self, R):
sage: K.has_coerce_map_from(ZpCA(17,40))
False
"""
if isinstance(R, (pAdicRingFloatingPoint, pAdicFieldFloatingPoint)) and R.prime() == self.prime():
if isinstance(R, (pAdicRingFixedMod, pAdicRingFloatingPoint, pAdicFieldFloatingPoint)) and R.prime() == self.prime():
if R.precision_cap() > self.precision_cap():
return True
elif R.precision_cap() == self.precision_cap() and self._printer.richcmp_modes(R._printer, op_LE):
Expand Down
1 change: 1 addition & 0 deletions src/sage/rings/ring.pyx
Expand Up @@ -119,6 +119,7 @@ cdef class Ring(ParentWithGens):
running ._test_elements_neq() . . . pass
running ._test_eq() . . . pass
running ._test_euclidean_degree() . . . pass
running ._test_fraction_field() . . . pass
running ._test_gcd_vs_xgcd() . . . pass
running ._test_new() . . . pass
running ._test_not_implemented_methods() . . . pass
Expand Down
2 changes: 2 additions & 0 deletions src/sage/structure/category_object.pyx
Expand Up @@ -803,6 +803,7 @@ cdef class CategoryObject(SageObject):
running ._test_enumerated_set_iter_list() . . . pass
running ._test_eq() . . . pass
running ._test_euclidean_degree() . . . pass
running ._test_fraction_field() . . . pass
running ._test_gcd_vs_xgcd() . . . pass
running ._test_metric() . . . pass
running ._test_new() . . . pass
Expand Down Expand Up @@ -866,6 +867,7 @@ cdef class CategoryObject(SageObject):
_test_enumerated_set_iter_list
_test_eq
_test_euclidean_degree
_test_fraction_field
_test_gcd_vs_xgcd
_test_metric
_test_new
Expand Down

0 comments on commit 7e62f70

Please sign in to comment.