Ticket #20310: 20310_over_23331.diff

File 20310_over_23331.diff, 64.1 KB (added by roed, 2 years ago)

Diff against 23331

  • src/sage/categories/pushout.py

    diff --git a/src/sage/categories/pushout.py b/src/sage/categories/pushout.py
    index f814b797fe..141dd88477 100644
    a b class CompletionFunctor(ConstructionFunctor): 
    23712371                    raise ValueError("completion type must be one of %s"%(", ".join(self._real_types)))
    23722372            else:
    23732373                if self.type not in self._dvr_types:
    2374                     raise ValueError("completion type must be one of %s"%(", ".join(self._dvr_types)))
     2374                    raise ValueError("completion type must be one of %s"%(", ".join(self._dvr_types[1:])))
    23752375
    23762376    def _repr_(self):
    23772377        """
    class CompletionFunctor(ConstructionFunctor): 
    24732473        return not (self == other)
    24742474
    24752475    _real_types = ['Interval','Ball','MPFR','RDF','RLF']
    2476     _dvr_types = [None, 'fixed-mod','capped-abs','capped-rel','lazy']
     2476    _dvr_types = [None, 'fixed-mod','floating-point','capped-abs','capped-rel','lazy']
    24772477
    24782478    def merge(self, other):
    24792479        """
    class CompletionFunctor(ConstructionFunctor): 
    25572557                return CompletionFunctor(self.p, new_prec, {'type':new_type, 'sci_not':new_scinot, 'rnd':new_rnd})
    25582558            else:
    25592559                new_type = self._dvr_types[min(self._dvr_types.index(self.type), self._dvr_types.index(other.type))]
    2560                 if new_type == 'fixed-mod':
    2561                     if self.type != 'fixed-mod' or other.type != 'fixed-mod':
    2562                         return None # no coercion into fixed-mod
     2560                if new_type in ('fixed-mod', 'floating-point'):
     2561                    if self.type != other.type:
     2562                        return None # no coercion into fixed-mod or floating-point
    25632563                    new_prec = min(self.prec, other.prec)
    25642564                else:
    25652565                    new_prec = max(self.prec, other.prec) # since elements track their own precision, we don't want to truncate them
  • src/sage/rings/padics/factory.py

    diff --git a/src/sage/rings/padics/factory.py b/src/sage/rings/padics/factory.py
    index d5556861e2..6034161d06 100644
    a b ext_table['u', pAdicRingFloatingPoint] = UnramifiedExtensionRingFloatingPoint 
    6969ext_table['u', pAdicFieldFloatingPoint] = UnramifiedExtensionFieldFloatingPoint
    7070#ext_table['u', pAdicRingLazy] = UnramifiedExtensionRingLazy
    7171
     72def _default_show_prec(type, print_mode):
     73    """
     74    Returns the default show_prec value for a given type and printing mode.
     75
     76    INPUT:
    7277
    73 def get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_sep, print_alphabet, print_max_terms, check, valid_non_lazy_types):
     78    - ``type`` -- a string: ``'capped-rel'``, ``'capped-abs'``, ``'fixed-mod'`` or ``'floating-point'``
     79    - ``print_mode`` -- a string: ``'series'``, ``'terse'``, ``'val-unit'``, ``'digits'``, ``'bars'``
     80
     81    EXAMPLES::
     82
     83        sage: from sage.rings.padics.factory import _default_show_prec
     84        sage: _default_show_prec('floating-point', 'series')
     85        False
     86        sage: _default_show_prec('capped-rel', 'series')
     87        True
     88        sage: _default_show_prec('capped-abs', 'digits')
     89        False
     90    """
     91    if type == 'floating-point':
     92        return False
     93    elif print_mode in ('series', 'terse', 'val-unit'):
     94        return True
     95    else:
     96        return False
     97
     98def get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec, check, valid_non_lazy_types):
    7499    """
    75100    This implements create_key for Zp and Qp: moving it here prevents code duplication.
    76101
    def get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_se 
    79104    EXAMPLES::
    80105
    81106        sage: from sage.rings.padics.factory import get_key_base
    82         sage: get_key_base(11, 5, 'capped-rel', None, None, None, None, ':', None, None, True, ['capped-rel'])
    83         (11, 5, 'capped-rel', 'series', '11', True, '|', (), -1)
    84         sage: get_key_base(12, 5, 'capped-rel', 'digits', None, None, None, None, None, None, False, ['capped-rel'])
    85         (12, 5, 'capped-rel', 'digits', '12', True, '|', ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'), -1)
     107        sage: get_key_base(11, 5, 'capped-rel', None, None, None, None, ':', None, None, False, True, ['capped-rel'])
     108        (11, 5, 'capped-rel', 'series', '11', True, '|', (), -1, False)
     109        sage: get_key_base(12, 5, 'capped-rel', 'digits', None, None, None, None, None, None, True, False, ['capped-rel'])
     110        (12, 5, 'capped-rel', 'digits', '12', True, '|', ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'), -1, True)
    86111    """
     112    if prec is None:
     113        prec = DEFAULT_PREC
    87114    if check:
    88115        if not isinstance(p, Integer):
    89116            p = Integer(p)
    def get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_se 
    107134            print_max_terms = print_mode['max_ram_terms']
    108135        if 'max_terms' in print_mode:
    109136            print_max_terms = print_mode['max_terms']
     137        if 'show_prec' in print_mode:
     138            show_prec = print_mode['show_prec']
    110139        if 'mode' in print_mode:
    111140            print_mode = print_mode['mode']
    112141        else:
    def get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_se 
    154183            name = names
    155184        else:
    156185            name = str(names)
     186    if show_prec is None:
     187        show_prec = _default_show_prec(type, print_mode)
    157188    if type in valid_non_lazy_types:
    158         key = (p, prec, type, print_mode, name, print_pos, print_sep, tuple(print_alphabet), print_max_terms)
     189        key = (p, prec, type, print_mode, name, print_pos, print_sep, tuple(print_alphabet), print_max_terms, show_prec)
    159190    else:
    160191        print(type)
    161192        raise ValueError("type must be %s"%(", ".join(valid_non_lazy_types)))
    class Qp_class(UniqueFactory): 
    210241    - ``print_max_terms`` -- integer (default ``None``) The maximum number of
    211242      terms shown.  See PRINTING below.
    212243
     244    - ``show_prec`` -- bool (default ``None``) whether to show the precision
     245      for elements.  See PRINTING below.
     246
    213247    - ``check`` -- bool (default ``True``) whether to check if `p` is prime.
    214248      Non-prime input may cause seg-faults (but can also be useful for
    215249      base n expansions for example)
    class Qp_class(UniqueFactory): 
    296330        sage: U.<p> = Qp(5); p
    297331        p + O(p^21)
    298332
     333    *show_prec* determines whether the precision is printed (default ``True``)::
     334
     335        sage: Qp(5, show_prec=False)(6)
     336        1 + 5
     337
    299338    *print_sep* and *print_alphabet* have no effect in series mode.
    300339
    301340    Note that print options affect equality::
    class Qp_class(UniqueFactory): 
    321360        sage: T = Qp(5, print_mode='val-unit', names='pi'); a = T(70700); a
    322361        pi^2 * 2828 + O(pi^22)
    323362
     363    *show_prec* determines whether the precision is printed (default ``True``)::
     364
     365        sage: Qp(5, print_mode='val-unit', show_prec=False)(30)
     366        5 * 6
     367
    324368    *print_max_terms*, *print_sep* and *print_alphabet* have no effect.
    325369
    326370    Equality again depends on the printing options::
    class Qp_class(UniqueFactory): 
    358402        sage: d = T(-707/5^10); d
    359403        95367431639918/unif^10 + O(unif^10)
    360404
     405    *show_prec* determines whether the precision is printed (default ``True``)::
     406
     407        sage: Qp(5, print_mode='terse', show_prec=False)(6)
     408        6
     409
    361410    *print_max_terms*, *print_sep* and *print_alphabet* have no effect.
    362411
    363412    Equality depends on printing options::
    class Qp_class(UniqueFactory): 
    420469        sage: T = Qp(5, print_mode='digits', print_max_terms=4, print_alphabet=('1','2','3','4','5')); b = T(-70700); repr(b)
    421470        '...325311'
    422471
     472    *show_prec* determines whether the precision is printed (default ``False``)::
     473
     474        sage: repr(Zp(5, print_mode='digits', show_prec=True)(6))
     475        '...11 + O(5^20)'
     476
    423477    *print_pos*, *name* and *print_sep* have no effect.
    424478
    425479    Equality depends on printing options::
    class Qp_class(UniqueFactory): 
    464518        sage: U = Qp(5, print_mode='bars', print_sep=']['); a = U(70700); repr(a)
    465519        '...4][2][3][0][3][0][0'
    466520
     521    *show_prec* determines whether the precision is printed (default ``False``)::
     522
     523        sage: repr(Zp(5, print_mode='bars', show_prec=True)(6))
     524        '...1|1 + O(5^20)'
     525
    467526    *name* and *print_alphabet* have no effect.
    468527
    469528    Equality depends on printing options::
    class Qp_class(UniqueFactory): 
    476535        sage: K = Qp(15, check=False); a = K(999); a
    477536        9 + 6*15 + 4*15^2 + O(15^20)
    478537    """
    479     def create_key(self, p, prec = DEFAULT_PREC, type = 'capped-rel', print_mode = None,
     538    def create_key(self, p, prec = None, type = 'capped-rel', print_mode = None,
    480539                   names = None, ram_name = None, print_pos = None,
    481                    print_sep = None, print_alphabet = None, print_max_terms = None, check = True):
     540                   print_sep = None, print_alphabet = None, print_max_terms = None, show_prec=None, check = True):
    482541        """
    483542        Creates a key from input parameters for ``Qp``.
    484543
    class Qp_class(UniqueFactory): 
    487546        TESTS::
    488547
    489548            sage: Qp.create_key(5,40)
    490             (5, 40, 'capped-rel', 'series', '5', True, '|', (), -1)
     549            (5, 40, 'capped-rel', 'series', '5', True, '|', (), -1, True)
    491550        """
    492551        if isinstance(names, (int, Integer)):
    493552            # old pickle; names is what used to be halt.
    class Qp_class(UniqueFactory): 
    497556            print_alphabet = print_max_terms
    498557            print_max_terms = check
    499558            check = True
    500         return get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_sep, print_alphabet, print_max_terms, check, ['capped-rel', 'floating-point'])
     559        return get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec, check, ['capped-rel', 'floating-point'])
    501560
    502561    def create_object(self, version, key):
    503562        """
    class Qp_class(UniqueFactory): 
    513572        if version[0] < 3 or (version[0] == 3 and version[1] < 2) or (version[0] == 3 and version[1] == 2 and version[2] < 3):
    514573            p, prec, type, print_mode, name = key
    515574            print_pos, print_sep, print_alphabet, print_max_terms = None, None, None, None
    516         else:
     575        elif version[0] < 8:
    517576            p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms = key
     577            show_prec = None
     578        else:
     579            p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec = key
    518580        if isinstance(type, Integer):
    519581            # lazy
    520582            raise NotImplementedError("lazy p-adics need more work.  Sorry.")
    class Qp_class(UniqueFactory): 
    523585            # keys changed in order to reduce irrelevant duplications: e.g. two Qps with print_mode 'series'
    524586            # that are identical except for different 'print_alphabet' now return the same object.
    525587            key = get_key_base(p, prec, type, print_mode, name, None, print_pos, print_sep, print_alphabet,
    526                                print_max_terms, False, ['capped-rel', 'fixed-mod', 'capped-abs'])
     588                               print_max_terms, None, False, ['capped-rel', 'fixed-mod', 'capped-abs'])
    527589            try:
    528590                obj = self._cache[version, key]()
    529591                if obj is not None:
    530592                    return obj
    531593            except KeyError:
    532594                pass
    533             p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms = key
     595            p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec = key
    534596
    535597        if type == 'capped-rel':
    536598            if print_mode == 'terse':
    537599                return pAdicFieldCappedRelative(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    538                                                           'ram_name': name, 'max_terse_terms': print_max_terms}, name)
     600                                                          'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name)
    539601            else:
    540602                return pAdicFieldCappedRelative(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    541                                                           'ram_name': name, 'max_ram_terms': print_max_terms}, name)
     603                                                          'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
    542604        elif type == 'floating-point':
    543605            if print_mode == 'terse':
    544606                return pAdicFieldFloatingPoint(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    545                                                           'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': False}, name)
     607                                                          'ram_name': name, 'max_terse_terms': print_max_terms, 'show_prec': show_prec}, name)
    546608            else:
    547609                return pAdicFieldFloatingPoint(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    548                                                          'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': False}, name)
     610                                                         'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
    549611        else:
    550612            raise ValueError("unexpected type")
    551613
    Qp = Qp_class("Qp") 
    559621def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None,
    560622          print_mode=None, ram_name = None, res_name = None, print_pos = None,
    561623       print_sep = None, print_max_ram_terms = None,
    562        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation = 'FLINT'):
     624       print_max_unram_terms = None, print_max_terse_terms = None, show_prec=None, check = True, implementation = 'FLINT'):
    563625    """
    564626    Given a prime power `q = p^n`, return the unique unramified
    565627    extension of `\mathbb{Q}_p` of degree `n`.
    def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    615677      number of terms in the polynomial representation of an element
    616678      (using ``'terse'``).  See PRINTING below.
    617679
     680    - ``show_prec`` -- bool (default ``None``) whether to show the precision
     681      for elements.  See PRINTING below.
     682
    618683    - ``check`` -- bool (default ``True``) whether to check inputs.
    619684
    620685    OUTPUT:
    def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    784849        sage: V.<f> = Qq(128, prec = 8, print_mode='series', print_max_unram_terms = 0); repr((1+f)^9 - 1 - f^3)
    785850        '(...)*2 + (...)*2^2 + (...)*2^3 + (...)*2^4 + (...)*2^5 + (...)*2^6 + (...)*2^7 + O(2^8)'
    786851
     852    *show_prec* determines whether the precision is printed (default ``True``)::
     853
     854        sage: U.<e> = Qq(9, 2, show_prec=False); repr(-3*(1+2*e)^4)
     855        '3 + e*3^2'
     856
    787857    *print_sep* and *print_max_terse_terms* have no effect.
    788858
    789859    Note that print options affect equality::
    def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    822892        sage: b*17*(a^3-a+14)
    823893        1 + O(17^6)
    824894
     895    *show_prec* determines whether the precision is printed (default ``True``)::
     896
     897        sage: U.<e> = Qq(9, 2, print_mode='val-unit', show_prec=False); repr(-3*(1+2*e)^4)
     898        '3 * (1 + 3*e)'
     899
    825900    *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no
    826901    effect.
    827902
    def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    867942        sage: U.<a> = Qq(625, print_mode='terse', print_max_terse_terms=2); (a-1/5)^6
    868943        106251/5^6 + 49994/5^5*a + ... + O(5^14)
    869944
     945    *show_prec* determines whether the precision is printed (default ``True``)::
     946
     947        sage: U.<e> = Qq(9, 2, print_mode='terse', show_prec=False); repr(-3*(1+2*e)^4)
     948        '3 + 9*e'
     949
    870950    *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no
    871951    effect.
    872952
    def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    9551035        sage: with local_print_mode(U, {'max_unram_terms':0}): repr(b-75*a)
    9561036        '...[...][...][...][...][][...][...]'
    9571037
     1038    *show_prec* determines whether the precision is printed (default ``False``)::
     1039
     1040        sage: U.<e> = Qq(9, 2, print_mode='bars', show_prec=True); repr(-3*(1+2*e)^4)
     1041        '...[0, 1]|[1]|[] + O(3^3)'
     1042
    9581043    *ram_name* and *print_max_terse_terms* have no effect.
    9591044
    9601045    Equality depends on printing options::
    def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    10281113    if prec is not None and not isinstance(prec, Integer):
    10291114        prec = Integer(prec)
    10301115
    1031     base = Qp(p=p, prec=DEFAULT_PREC if prec is None else prec, type=type, print_mode=print_mode, names=ram_name, print_pos=print_pos,
    1032               print_sep=print_sep, print_max_terms=print_max_ram_terms, check=check)
     1116    base = Qp(p=p, prec=prec, type=type, print_mode=print_mode, names=ram_name, print_pos=print_pos,
     1117              print_sep=print_sep, print_max_terms=print_max_ram_terms, show_prec=show_prec, check=check)
    10331118
    10341119    if k == 1:
    10351120        return base
    def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    10531138                            names=names, res_name=res_name, ram_name=ram_name, print_pos=print_pos,
    10541139                            print_sep=print_sep, print_max_ram_terms=print_max_ram_terms,
    10551140                            print_max_unram_terms=print_max_unram_terms,
    1056                             print_max_terse_terms=print_max_terse_terms, check=check,
     1141                            print_max_terse_terms=print_max_terse_terms, show_prec=show_prec, check=check,
    10571142                            unram=True, implementation=implementation)
    10581143
    10591144######################################################
    10601145# Short constructor names for different types
    10611146######################################################
    10621147
    1063 def QpCR(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = None,
    1064          print_sep = None, print_alphabet = None, print_max_terms = None, check=True):
     1148def QpCR(p, prec = None, *args, **kwds):
    10651149    """
    10661150    A shortcut function to create capped relative `p`-adic fields.
    10671151
    def QpCR(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = No 
    10731157        sage: QpCR(5, 40)
    10741158        5-adic Field with capped relative precision 40
    10751159    """
    1076     return Qp(p=p, prec=prec, print_mode=print_mode, check=check, names=names,
    1077               print_pos=print_pos, print_sep=print_sep, print_alphabet=print_alphabet, print_max_terms=print_max_terms,
    1078               type = 'capped-rel')
     1160    return Qp(p, prec, 'capped-rel', *args, **kwds)
    10791161
    1080 def QpFP(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = None,
    1081          print_sep = None, print_alphabet = None, print_max_terms = None, check=True):
     1162def QpFP(p, prec = None, *args, **kwds):
    10821163    """
    10831164    A shortcut function to create floating point `p`-adic fields.
    10841165
    def QpFP(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = No 
    10901171        sage: QpFP(5, 40)
    10911172        5-adic Field with floating precision 40
    10921173    """
    1093     return Qp(p=p, prec=prec, print_mode=print_mode, check=check, names=names,
    1094               print_pos=print_pos, print_sep=print_sep, print_alphabet=print_alphabet, print_max_terms=print_max_terms,
    1095               type = 'floating-point')
    1096 
    1097 def QqCR(q, prec = None, modulus = None, names=None,
    1098           print_mode=None, ram_name = None, print_pos = None,
    1099        print_sep = None, print_alphabet = None, print_max_ram_terms = None,
    1100        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation = 'FLINT'):
     1174    return Qp(p, prec, 'floating-point', *args, **kwds)
     1175
     1176def QqCR(q, prec = None, *args, **kwds):
    11011177    """
    11021178    A shortcut function to create capped relative unramified `p`-adic
    11031179    fields.
    def QqCR(q, prec = None, modulus = None, names=None, 
    11101186        sage: R.<a> = QqCR(25, 40); R
    11111187        Unramified Extension in a defined by x^2 + 4*x + 2 with capped relative precision 40 over 5-adic Field
    11121188    """
    1113     return Qq(q, prec=prec, modulus=modulus, names=names, print_mode=print_mode,
    1114               ram_name=ram_name, print_pos=print_pos, print_max_ram_terms=print_max_ram_terms,
    1115               print_max_unram_terms=print_max_unram_terms, print_max_terse_terms=print_max_terse_terms,
    1116               check=check, implementation=implementation, type = 'capped-rel')
    1117 
    1118 def QqFP(q, prec = None, modulus = None, names=None,
    1119           print_mode=None, ram_name = None, print_pos = None,
    1120        print_sep = None, print_alphabet = None, print_max_ram_terms = None,
    1121        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation = 'FLINT'):
     1189    return Qq(q, prec, 'capped-rel', *args, **kwds)
     1190
     1191def QqFP(q, prec = None, *args, **kwds):
    11221192    """
    11231193    A shortcut function to create floating point unramified `p`-adic
    11241194    fields.
    def QqFP(q, prec = None, modulus = None, names=None, 
    11311201        sage: R.<a> = QqFP(25, 40); R
    11321202        Unramified Extension in a defined by x^2 + 4*x + 2 with floating precision 40 over 5-adic Field
    11331203    """
    1134     return Qq(q, prec=prec, modulus=modulus, names=names, print_mode=print_mode,
    1135               ram_name=ram_name, print_pos=print_pos, print_max_ram_terms=print_max_ram_terms,
    1136               print_max_unram_terms=print_max_unram_terms, print_max_terse_terms=print_max_terse_terms,
    1137               check=check, implementation=implementation, type = 'floating-point')
     1204    return Qq(q, prec, 'floating-point', *args, **kwds)
    11381205
    11391206#######################################################################################################
    11401207#
    class Zp_class(UniqueFactory): 
    11831250    - ``print_max_terms`` -- integer (default ``None``) The maximum
    11841251      number of terms shown.  See PRINTING below.
    11851252
     1253    - ``show_prec`` -- bool (default ``None``) whether to show the precision
     1254      for elements.  See PRINTING below.
     1255
    11861256    - ``check`` -- bool (default ``True``) whether to check if `p` is
    11871257      prime.  Non-prime input may cause seg-faults (but can also be
    11881258      useful for base `n` expansions for example)
    class Zp_class(UniqueFactory): 
    12981368        sage: U.<p> = Zp(5); p
    12991369        p + O(p^21)
    13001370
     1371    *show_prec* determines whether the precision is printed (default ``True``)::
     1372
     1373        sage: Zp(5, show_prec=False)(6)
     1374        1 + 5
     1375
    13011376    *print_sep* and *print_alphabet* have no effect.
    13021377
    13031378    Note that print options affect equality::
    class Zp_class(UniqueFactory): 
    13231398        sage: T = Zp(5, print_mode='val-unit', names='pi'); a = T(70700); a
    13241399        pi^2 * 2828 + O(pi^22)
    13251400
     1401    *show_prec* determines whether the precision is printed (default ``True``)::
     1402
     1403        sage: Zp(5, print_mode='val-unit', show_prec=False)(30)
     1404        5 * 6
     1405
    13261406    *print_max_terms*, *print_sep* and *print_alphabet* have no effect.
    13271407
    13281408    Equality again depends on the printing options::
    class Zp_class(UniqueFactory): 
    13481428        sage: T.<unif> = Zp(5, print_mode='terse'); c = T(-707); c
    13491429        95367431639918 + O(unif^20)
    13501430
     1431    *show_prec* determines whether the precision is printed (default ``True``)::
     1432
     1433        sage: Zp(5, print_mode='terse', show_prec=False)(30)
     1434        30
     1435
    13511436    *print_max_terms*, *print_sep* and *print_alphabet* have no effect.
    13521437
    13531438    Equality depends on printing options::
    class Zp_class(UniqueFactory): 
    13811466        sage: T = Zp(5, print_mode='digits', print_max_terms=4, print_alphabet=('1','2','3','4','5')); b = T(-70700); repr(b)
    13821467        '...325311'
    13831468
     1469    *show_prec* determines whether the precision is printed (default ``False``)::
     1470
     1471        sage: repr(Zp(5, 2, print_mode='digits', show_prec=True)(6))
     1472        '...11 + O(5^2)'
     1473
    13841474    *print_pos*, *name* and *print_sep* have no effect.
    13851475
    13861476    Equality depends on printing options::
    class Zp_class(UniqueFactory): 
    14141504        sage: U = Zp(5, print_mode='bars', print_sep=']['); a = U(70700); repr(a)
    14151505        '...4][2][3][0][3][0][0'
    14161506
     1507    *show_prec* determines whether the precision is printed (default ``False``)::
     1508
     1509        sage: repr(Zp(5, 2, print_mode='bars', show_prec=True)(6))
     1510        '1|1 + O(5^2)'
     1511
    14171512    *name* and *print_alphabet* have no effect.
    14181513
    14191514    Equality depends on printing options::
    class Zp_class(UniqueFactory): 
    14981593        sage: a + b
    14991594        1 + 5 + O(5^10)
    15001595    """
    1501     def create_key(self, p, prec = DEFAULT_PREC, type = 'capped-rel', print_mode = None,
     1596    def create_key(self, p, prec = None, type = 'capped-rel', print_mode = None,
    15021597                   names = None, ram_name = None, print_pos = None, print_sep = None, print_alphabet = None,
    1503                    print_max_terms = None, check = True):
     1598                   print_max_terms = None, show_prec = None, check = True):
    15041599        """
    15051600        Creates a key from input parameters for ``Zp``.
    15061601
    class Zp_class(UniqueFactory): 
    15091604        TESTS::
    15101605
    15111606            sage: Zp.create_key(5,40)
    1512             (5, 40, 'capped-rel', 'series', '5', True, '|', (), -1)
     1607            (5, 40, 'capped-rel', 'series', '5', True, '|', (), -1, True)
    15131608            sage: Zp.create_key(5,40,print_mode='digits')
    1514             (5, 40, 'capped-rel', 'digits', '5', True, '|', ('0', '1', '2', '3', '4'), -1)
     1609            (5, 40, 'capped-rel', 'digits', '5', True, '|', ('0', '1', '2', '3', '4'), -1, False)
    15151610        """
    15161611        if isinstance(names, (int, Integer)):
    15171612            # old pickle; names is what used to be halt.
    class Zp_class(UniqueFactory): 
    15221617            print_max_terms = check
    15231618            check = True
    15241619        return get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_sep, print_alphabet,
    1525                             print_max_terms, check, ['capped-rel', 'fixed-mod', 'capped-abs', 'floating-point'])
     1620                            print_max_terms, show_prec, check, ['capped-rel', 'fixed-mod', 'capped-abs', 'floating-point'])
    15261621
    15271622    def create_object(self, version, key):
    15281623        """
    class Zp_class(UniqueFactory): 
    15391634            (len(version) > 2 and version[0] == 3 and version[1] == 2 and version[2] < 3)):
    15401635            p, prec, type, print_mode, name = key
    15411636            print_pos, print_sep, print_alphabet, print_max_terms = None, None, None, None
    1542         else:
     1637        elif version[0] < 8:
    15431638            p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms = key
     1639            show_prec = None
     1640        else:
     1641            p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec = key
    15441642        if isinstance(type, Integer):
    15451643            # lazy
    15461644            raise NotImplementedError("lazy p-adics need more work.  Sorry.")
    class Zp_class(UniqueFactory): 
    15491647            # keys changed in order to reduce irrelevant duplications: e.g. two Zps with print_mode 'series'
    15501648            # that are identical except for different 'print_alphabet' now return the same object.
    15511649            key = get_key_base(p, prec, type, print_mode, name, None, print_pos, print_sep, print_alphabet,
    1552                                print_max_terms, False, ['capped-rel', 'fixed-mod', 'capped-abs'])
     1650                               print_max_terms, None, False, ['capped-rel', 'fixed-mod', 'capped-abs'])
    15531651            try:
    15541652                obj = self._cache[version, key]()
    15551653                if obj is not None:
    15561654                    return obj
    15571655            except KeyError:
    15581656                pass
    1559             p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms = key
     1657            p, prec, type, print_mode, name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec = key
    15601658        if type == 'capped-rel':
    15611659            return pAdicRingCappedRelative(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    1562                                                      'ram_name': name, 'max_ram_terms': print_max_terms}, name)
     1660                                                     'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
    15631661        elif type == 'fixed-mod':
    15641662            return pAdicRingFixedMod(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    1565                                                'ram_name': name, 'max_ram_terms': print_max_terms}, name)
     1663                                               'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
    15661664        elif type == 'capped-abs':
    15671665            return pAdicRingCappedAbsolute(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    1568                                                      'ram_name': name, 'max_ram_terms': print_max_terms}, name)
     1666                                                     'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
    15691667        elif type == 'floating-point':
    15701668            return pAdicRingFloatingPoint(p, prec, {'mode': print_mode, 'pos': print_pos, 'sep': print_sep, 'alphabet': print_alphabet,
    1571                                                      'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': False}, name)
     1669                                                     'ram_name': name, 'max_ram_terms': print_max_terms, 'show_prec': show_prec}, name)
    15721670        else:
    15731671            raise ValueError("unexpected type")
    15741672
    Zp = Zp_class("Zp") 
    15821680def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None,
    15831681          print_mode=None, ram_name = None, res_name = None, print_pos = None,
    15841682       print_sep = None, print_max_ram_terms = None,
    1585        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation = 'FLINT'):
     1683       print_max_unram_terms = None, print_max_terse_terms = None, show_prec = None, check = True, implementation = 'FLINT'):
    15861684    """
    15871685    Given a prime power `q = p^n`, return the unique unramified
    15881686    extension of `\mathbb{Z}_p` of degree `n`.
    def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    16381736      number of terms in the polynomial representation of an element
    16391737      (using ``'terse'``).  See PRINTING below.
    16401738
     1739    - ``show_prec`` -- bool (default ``None``) Whether to show the precision
     1740      for elements.  See PRINTING below.
     1741
    16411742    - ``check`` -- bool (default ``True``) whether to check inputs.
    16421743
    16431744    - ``implementation`` -- string (default ``FLINT``) which
    def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    18491950        sage: V.<f> = Zq(128, prec = 8, print_mode='series', print_max_unram_terms = 0); repr((1+f)^9 - 1 - f^3)
    18501951        '(...)*2 + (...)*2^2 + (...)*2^3 + (...)*2^4 + (...)*2^5 + (...)*2^6 + (...)*2^7 + O(2^8)'
    18511952
     1953    *show_prec* determines whether the precision is printed (default ``True``)::
     1954
     1955        sage: U.<e> = Zq(9, 2, show_prec=False); repr(-3*(1+2*e)^4)
     1956        '3 + e*3^2'
     1957
    18521958    *print_sep* and *print_max_terse_terms* have no effect.
    18531959
    18541960    Note that print options affect equality::
    def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    18851991        sage: U.<a> = Zq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3); b = (17*(a^3-a+14)^6); b
    18861992        17 * (12131797 + 12076378*a + 10809706*a^2 + ...) + O(17^7)
    18871993
     1994    *show_prec* determines whether the precision is printed (default ``True``)::
     1995
     1996        sage: U.<e> = Zq(9, 2, print_mode='val-unit', show_prec=False); repr(-3*(1+2*e)^4)
     1997        '3 * (1 + 3*e)'
     1998
    18881999    *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no effect.
    18892000
    18902001    Equality again depends on the printing options::
    def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    19332044        sage: U.<a> = Zq(625, print_mode='terse', print_max_terse_terms=2); (a-1/5)^6
    19342045        106251/5^6 + 49994/5^5*a + ... + O(5^14)
    19352046
     2047    *show_prec* determines whether the precision is printed (default ``True``)::
     2048
     2049        sage: U.<e> = Zq(9, 2, print_mode='terse', show_prec=False); repr(-3*(1+2*e)^4)
     2050        '3 + 9*e'
     2051
    19362052    *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no
    19372053    effect.
    19382054
    def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    20062122        sage: with local_print_mode(U, {'max_unram_terms':0}): repr(b-75*a)
    20072123        '...[...][...][...][...][][...][...]'
    20082124
     2125    *show_prec* determines whether the precision is printed (default ``False``)::
     2126
     2127        sage: U.<e> = Zq(9, 2, print_mode='bars', show_prec=True); repr(-3*(1+2*e)^4)
     2128        '[0, 1]|[1]|[] + O(3^3)'
     2129
    20092130    *ram_name* and *print_max_terse_terms* have no effect.
    20102131
    20112132    Equality depends on printing options::
    def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    20812202    else:
    20822203        F = q
    20832204        q = F[0][0]**F[0][1]
    2084     base = Zp(p=F[0][0], prec=DEFAULT_PREC if prec is None else prec, type=type, print_mode=print_mode, names=ram_name,
    2085               print_pos=print_pos, print_sep=print_sep, print_max_terms=print_max_ram_terms, check=False)
     2205    base = Zp(p=F[0][0], prec=prec, type=type, print_mode=print_mode, names=ram_name,
     2206              print_pos=print_pos, print_sep=print_sep, print_max_terms=print_max_ram_terms,
     2207              show_prec=show_prec, check=False)
    20862208    if F[0][1] == 1:
    20872209        return base
    20882210    elif names is None:
    def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 
    20982220                            names=names, res_name=res_name, ram_name=ram_name, print_pos=print_pos,
    20992221                            print_sep=print_sep, print_max_ram_terms=print_max_ram_terms,
    21002222                            print_max_unram_terms=print_max_unram_terms,
    2101                             print_max_terse_terms=print_max_terse_terms, check=check,
     2223                            print_max_terse_terms=print_max_terse_terms, show_prec=show_prec, check=check,
    21022224                            unram=True, implementation=implementation)
    21032225
    21042226######################################################
    21052227# Short constructor names for different types
    21062228######################################################
    21072229
    2108 def ZpCR(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = None,
    2109          print_sep = None, print_alphabet = None, print_max_terms = None, check=True):
     2230def ZpCR(p, prec = None, *args, **kwds):
    21102231    """
    21112232    A shortcut function to create capped relative `p`-adic rings.
    21122233
    def ZpCR(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = No 
    21182239        sage: ZpCR(5, 40)
    21192240        5-adic Ring with capped relative precision 40
    21202241    """
    2121     return Zp(p=p, prec=prec, print_mode=print_mode, check=check, names=names,
    2122               print_pos=print_pos, print_sep=print_sep, print_alphabet=print_alphabet, print_max_terms=print_max_terms,
    2123               type = 'capped-rel')
     2242    return Zp(p, prec, 'capped-rel', *args, **kwds)
    21242243
    2125 def ZpCA(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = None,
    2126          print_sep = None, print_alphabet = None, print_max_terms = None, check=True):
     2244def ZpCA(p, prec = None, *args, **kwds):
    21272245    """
    21282246    A shortcut function to create capped absolute `p`-adic rings.
    21292247
    def ZpCA(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = No 
    21342252        sage: ZpCA(5, 40)
    21352253        5-adic Ring with capped absolute precision 40
    21362254    """
    2137     return Zp(p=p, prec=prec, print_mode=print_mode, check=check, names=names,
    2138               print_pos=print_pos, print_sep=print_sep, print_alphabet=print_alphabet, print_max_terms=print_max_terms,
    2139               type = 'capped-abs')
     2255    return Zp(p, prec, 'capped-abs', *args, **kwds)
    21402256
    2141 def ZpFM(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = None,
    2142          print_sep = None, print_alphabet = None, print_max_terms = None, check=True):
     2257def ZpFM(p, prec = None, *args, **kwds):
    21432258    """
    21442259    A shortcut function to create fixed modulus `p`-adic rings.
    21452260
    def ZpFM(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = No 
    21502265        sage: ZpFM(5, 40)
    21512266        5-adic Ring of fixed modulus 5^40
    21522267    """
    2153     return Zp(p=p, prec=prec, print_mode=print_mode, check=check, names=names,
    2154               print_pos=print_pos, print_sep=print_sep, print_alphabet=print_alphabet, print_max_terms=print_max_terms,
    2155               type = 'fixed-mod')
     2268    return Zp(p, prec, 'fixed-mod', *args, **kwds)
    21562269
    2157 def ZpFP(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = None,
    2158          print_sep = None, print_alphabet = None, print_max_terms = None, check=True):
     2270def ZpFP(p, prec = None, *args, **kwds):
    21592271    """
    21602272    A shortcut function to create floating point `p`-adic rings.
    21612273
    def ZpFP(p, prec = DEFAULT_PREC, print_mode = None, names = None, print_pos = No 
    21672279        sage: ZpFP(5, 40)
    21682280        5-adic Ring with floating precision 40
    21692281    """
    2170     return Zp(p=p, prec=prec, print_mode=print_mode, check=check, names=names,
    2171               print_pos=print_pos, print_sep=print_sep, print_alphabet=print_alphabet, print_max_terms=print_max_terms,
    2172               type = 'floating-point')
    2173 
    2174 def ZqCR(q, prec = None, modulus = None, names=None,
    2175           print_mode=None, ram_name = None, print_pos = None,
    2176        print_sep = None, print_alphabet = None, print_max_ram_terms = None,
    2177        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation = 'FLINT'):
     2282    return Zp(p, prec, 'floating-point', *args, **kwds)
     2283
     2284def ZqCR(q, prec = None, *args, **kwds):
    21782285    """
    21792286    A shortcut function to create capped relative unramified `p`-adic rings.
    21802287
    def ZqCR(q, prec = None, modulus = None, names=None, 
    21862293        sage: R.<a> = ZqCR(25, 40); R
    21872294        Unramified Extension in a defined by x^2 + 4*x + 2 with capped relative precision 40 over 5-adic Ring
    21882295    """
    2189     return Zq(q, prec=prec, modulus=modulus, names=names, print_mode=print_mode,
    2190               ram_name=ram_name, print_pos=print_pos, print_max_ram_terms=print_max_ram_terms,
    2191               print_max_unram_terms=print_max_unram_terms, print_max_terse_terms=print_max_terse_terms,
    2192               check=check, implementation=implementation, type = 'capped-rel')
    2193 
    2194 def ZqCA(q, prec = None, modulus = None, names=None,
    2195           print_mode=None, ram_name = None, print_pos = None,
    2196        print_sep = None, print_alphabet = None, print_max_ram_terms = None,
    2197        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation='FLINT'):
     2296    return Zq(q, prec, 'capped-rel', *args, **kwds)
     2297
     2298def ZqCA(q, prec = None, *args, **kwds):
    21982299    """
    21992300    A shortcut function to create capped absolute unramified `p`-adic rings.
    22002301
    def ZqCA(q, prec = None, modulus = None, names=None, 
    22052306        sage: R.<a> = ZqCA(25, 40); R
    22062307        Unramified Extension in a defined by x^2 + 4*x + 2 with capped absolute precision 40 over 5-adic Ring
    22072308    """
    2208     return Zq(q, prec=prec, modulus=modulus, names=names, print_mode=print_mode,
    2209               ram_name=ram_name, print_pos=print_pos, print_max_ram_terms=print_max_ram_terms,
    2210               print_max_unram_terms=print_max_unram_terms, print_max_terse_terms=print_max_terse_terms,
    2211               check=check, implementation=implementation, type = 'capped-abs')
    2212 
    2213 def ZqFM(q, prec = None, modulus = None, names=None,
    2214           print_mode=None, ram_name = None, print_pos = None,
    2215        print_sep = None, print_alphabet = None, print_max_ram_terms = None,
    2216        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation='FLINT'):
     2309    return Zq(q, prec, 'capped-abs', *args, **kwds)
     2310
     2311def ZqFM(q, prec = None, *args, **kwds):
    22172312    """
    22182313    A shortcut function to create fixed modulus unramified `p`-adic rings.
    22192314
    def ZqFM(q, prec = None, modulus = None, names=None, 
    22242319        sage: R.<a> = ZqFM(25, 40); R
    22252320        Unramified Extension in a defined by x^2 + 4*x + 2 of fixed modulus 5^40 over 5-adic Ring
    22262321    """
    2227     return Zq(q, prec=prec, modulus=modulus, names=names, print_mode=print_mode,
    2228               ram_name=ram_name, print_pos=print_pos, print_max_ram_terms=print_max_ram_terms,
    2229               print_max_unram_terms=print_max_unram_terms, print_max_terse_terms=print_max_terse_terms,
    2230               check=check, implementation=implementation, type = 'fixed-mod')
    2231 
    2232 def ZqFP(q, prec = None, modulus = None, names=None,
    2233           print_mode=None, ram_name = None, print_pos = None,
    2234        print_sep = None, print_alphabet = None, print_max_ram_terms = None,
    2235        print_max_unram_terms = None, print_max_terse_terms = None, check = True, implementation = 'FLINT'):
     2322    return Zq(q, prec, 'fixed-mod', *args, **kwds)
     2323
     2324def ZqFP(q, prec = None, *args, **kwds):
    22362325    """
    22372326    A shortcut function to create floating point unramified `p`-adic rings.
    22382327
    def ZqFP(q, prec = None, modulus = None, names=None, 
    22442333        sage: R.<a> = ZqFP(25, 40); R
    22452334        Unramified Extension in a defined by x^2 + 4*x + 2 with floating precision 40 over 5-adic Ring
    22462335    """
    2247     return Zq(q, prec=prec, modulus=modulus, names=names, print_mode=print_mode,
    2248               ram_name=ram_name, print_pos=print_pos, print_max_ram_terms=print_max_ram_terms,
    2249               print_max_unram_terms=print_max_unram_terms, print_max_terse_terms=print_max_terse_terms,
    2250               check=check, implementation=implementation, type = 'floating-point')
     2336    return Zq(q, prec, 'floating-point', *args, **kwds)
    22512337
    22522338#######################################################################################################
    22532339#
    class pAdicExtension_class(UniqueFactory): 
    22742360                                  unram_name = None, ram_name = None, print_pos = None,
    22752361                                  print_sep = None, print_alphabet = None, print_max_ram_terms = None,
    22762362                                  print_max_unram_terms = None, print_max_terse_terms = None,
    2277                                   check = True, unram = False, implementation='FLINT'):
     2363                                  show_prec = None, check = True, unram = False, implementation='FLINT'):
    22782364        """
    22792365        Creates a key from input parameters for pAdicExtension.
    22802366
    class pAdicExtension_class(UniqueFactory): 
    22872373            sage: pAdicExtension.create_key_and_extra_args(R, x^4-15,names='w')
    22882374            (('e', 5-adic Ring with capped relative precision 3,
    22892375              x^4 - 15, ('w', None, None, 'w'),
    2290               12, 'series', True, '|', (), -1, -1, -1, 'NTL'),
     2376              12, 'series', True, '|', (), -1, -1, -1, True, 'NTL'),
    22912377             {'approx_modulus': (1 + O(5^3))*x^4 + (O(5^4))*x^3 + (O(5^4))*x^2 + (O(5^4))*x + (2*5 + 4*5^2 + 4*5^3 + O(5^4))})
    22922378
    22932379            sage: A = Qp(3,5)
    class pAdicExtension_class(UniqueFactory): 
    23202406            print_max_unram_terms = base._printer._max_unram_terms()
    23212407        if print_max_terse_terms is None:
    23222408            print_max_terse_terms = base._printer._max_terse_terms()
     2409        if show_prec is None:
     2410            show_prec = _default_show_prec(base._prec_type(), print_mode)
    23232411        from sage.symbolic.expression import is_Expression
    23242412        if check:
    23252413            if is_Expression(modulus):
    class pAdicExtension_class(UniqueFactory): 
    23952483            implementation = "NTL" # for testing - FLINT ramified extensions not implemented yet
    23962484        key = (polytype, base, exact_modulus, names, prec, print_mode, print_pos,
    23972485               print_sep, tuple(print_alphabet), print_max_ram_terms, print_max_unram_terms,
    2398                print_max_terse_terms, implementation)
     2486               print_max_terse_terms, show_prec, implementation)
    23992487        return key, {'approx_modulus': approx_modulus}
    24002488
    24012489    def create_object(self, version, key, approx_modulus=None, shift_seed=None):
    class pAdicExtension_class(UniqueFactory): 
    24232511                exact_modulus = premodulus.polynomial(base.exact_field())
    24242512            elif is_Polynomial(premodulus):
    24252513                exact_modulus = premodulus.change_ring(base.exact_field())
     2514            show_prec = None
    24262515        else:
    24272516            (polytype, base, exact_modulus, names, prec, print_mode, print_pos,
    24282517             print_sep, print_alphabet, print_max_ram_terms, print_max_unram_terms,
    2429              print_max_terse_terms, implementation) = key
     2518             print_max_terse_terms, show_prec, implementation) = key
    24302519            if polytype == 'e':
    24312520                unif = exact_modulus.base_ring()(base.uniformizer())
    24322521                shift_seed = (-exact_modulus[:exact_modulus.degree()] / unif).change_ring(base)
    24332522            if not krasner_check(exact_modulus, prec):
    24342523                raise ValueError("polynomial does not determine a unique extension.  Please specify more precision or use parameter check=False.")
    24352524
    2436         show_prec = base._printer._show_prec()
     2525        if show_prec is None:
     2526            show_prec = base._printer._show_prec()
    24372527        if polytype == 'p':
    24382528            raise NotImplementedError("Extensions by general polynomials not yet supported.  Please use an unramified or Eisenstein polynomial.")
    24392529        T = ext_table[polytype, type(base.ground_ring_of_tower()).__base__]
  • src/sage/rings/padics/local_generic.py

    diff --git a/src/sage/rings/padics/local_generic.py b/src/sage/rings/padics/local_generic.py
    index 4eb4d62d33..900a37d551 100644
    a b from __future__ import absolute_import 
    2020#                  http://www.gnu.org/licenses/
    2121#*****************************************************************************
    2222
     23from copy import copy
    2324from sage.rings.ring import CommutativeRing
    2425from sage.categories.complete_discrete_valuation import CompleteDiscreteValuationRings, CompleteDiscreteValuationFields
    2526from sage.structure.category_object import check_default_category
    2627from sage.structure.parent import Parent
    2728from sage.rings.integer import Integer
     29from sage.rings.integer_ring import ZZ
    2830
    2931class LocalGeneric(CommutativeRing):
    3032    def __init__(self, base, prec, names, element_class, category=None):
    class LocalGeneric(CommutativeRing): 
    190192        """
    191193        return self._repr_(do_latex = True)
    192194
     195    def change(self, **kwds):
     196        r"""
     197        Return a new ring with changed attributes.
     198
     199        INPUT:
     200
     201        The following arguments are applied to every ring in the tower:
     202
     203        - ``type`` -- string, the precision type
     204        - ``p`` -- the prime of the ground ring.  Defining polynomials
     205                   will be converted to the new base rings.
     206        - ``print_mode`` -- string
     207        - ``print_pos`` -- bool
     208        - ``print_sep`` -- string
     209        - ``print_alphabet`` -- dict
     210        - ``show_prec`` -- bool
     211        - ``check`` -- bool
     212
     213        The following arguments are only applied to the top ring in the tower:
     214
     215        - ``var_name`` -- string
     216        - ``res_name`` -- string
     217        - ``unram_name`` -- string
     218        - ``ram_name`` -- string
     219        - ``names`` -- string
     220        - ``modulus`` -- polynomial
     221
     222        The following arguments have special behavior:
     223
     224        - ``prec`` -- integer.  If the precision is increased on an extension ring,
     225                       the precision on the base is increased as necessary (respecting ramification).
     226                       If the precision is decreased, the precision of the base is unchanged.
     227
     228        - ``field`` -- bool.  If ``True``, switch to a tower of fields via the fraction field.
     229                        If False, switch to a tower of rings of integers.
     230
     231        - ``q`` -- prime power.  Replace the initial unramified extension of `\Q_p` or `\Z_p`
     232                    with an unramified extension of residue cardinality `q`.
     233                    If the initial extension is ramified, add in an unramified extension.
     234
     235        - ``base`` -- ring or field. Use a specific base ring instead of recursively
     236                       calling :meth:`change` down the tower.
     237
     238        See the :mod:`constructors <sage.rings.padics.factory>` for more details on the
     239        meaning of these arguments.
     240
     241        EXAMPLES:
     242
     243        We can use this method to change the precision::
     244
     245            sage: Zp(5).change(prec=40)
     246            5-adic Ring with capped relative precision 40
     247
     248        or the precision type::
     249
     250            sage: Zp(5).change(type="capped-abs")
     251            5-adic Ring with capped absolute precision 20
     252
     253        or even the prime::
     254
     255            sage: ZpCA(3).change(p=17)
     256            17-adic Ring with capped absolute precision 20
     257
     258        You can switch between the ring of integers and its fraction field::
     259
     260            sage: ZpCA(3).change(field=True)
     261            3-adic Field with capped relative precision 20
     262
     263        You can also change print modes::
     264
     265            sage: R = Zp(5).change(prec=5, print_mode='digits')
     266            sage: repr(~R(17))
     267            '...13403'
     268
     269        Changing print mode to 'digits' works for Eisenstein extensions::
     270
     271            sage: S.<x> = ZZ[]
     272            sage: W.<w> = Zp(3).extension(x^4 + 9*x^2 + 3*x - 3)
     273            sage: W.print_mode()
     274            'series'
     275            sage: W.change(print_mode='digits').print_mode()
     276            'digits'
     277
     278        You can change extensions::
     279
     280            sage: K.<a> = QqFP(125, prec=4)
     281            sage: K.change(q=64)
     282            Unramified Extension in a defined by x^6 + x^4 + x^3 + x + 1 with floating precision 4 over 2-adic Field
     283            sage: R.<x> = QQ[]
     284            sage: K.change(modulus = x^2 - x + 2, print_pos=False)
     285            Unramified Extension in a defined by x^2 - x + 2 with floating precision 4 over 5-adic Field
     286
     287        and variable names::
     288
     289            sage: K.change(names='b')
     290            Unramified Extension in b defined by x^3 + 3*x + 3 with floating precision 4 over 5-adic Field
     291
     292        and precision::
     293
     294            sage: Kup = K.change(prec=8); Kup
     295            Unramified Extension in a defined by x^3 + 3*x + 3 with floating precision 8 over 5-adic Field
     296            sage: Kup.base_ring()
     297            5-adic Field with floating precision 8
     298
     299        If you decrease the precision, the precision of the base stays the same::
     300
     301            sage: Kdown = K.change(prec=2); Kdown
     302            Unramified Extension in a defined by x^3 + 3*x + 3 with floating precision 2 over 5-adic Field
     303            sage: Kdown.precision_cap()
     304            2
     305            sage: Kdown.base_ring()
     306            5-adic Field with floating precision 4
     307
     308        Changing the prime works for extensions::
     309
     310            sage: x = polygen(ZZ)
     311            sage: R.<a> = Zp(5).extension(x^2 + 2)
     312            sage: S = R.change(p=7)
     313            sage: S.defining_polynomial(exact=True)
     314            x^2 + 2
     315            sage: A.<y> = Zp(5)[]
     316            sage: R.<a> = Zp(5).extension(y^2 + 2)
     317            sage: S = R.change(p=7)
     318            sage: S.defining_polynomial(exact=True)
     319            y^2 + 2
     320
     321        ::
     322
     323            sage: R.<a> = Zq(5^3)
     324            sage: S = R.change(prec=50)
     325            sage: S.defining_polynomial(exact=True)
     326            x^3 + 3*x + 3
     327        """
     328        # We support both print_* and * for *=mode, pos, sep, alphabet
     329        for atr in ('print_mode', 'print_pos', 'print_sep', 'print_alphabet'):
     330            if atr in kwds:
     331                kwds[atr[6:]] = kwds.pop(atr)
     332        def get_unramified_modulus(q, res_name):
     333            from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
     334            return GF(q, res_name).modulus().change_ring(ZZ)
     335        n = None
     336        q = None
     337        from .padic_base_generic import pAdicBaseGeneric
     338        if 'q' in kwds and isinstance(self.base_ring(), pAdicBaseGeneric):
     339            q = kwds.pop('q')
     340            if not isinstance(q, Integer):
     341                raise TypeError("q must be an integer")
     342            p, n = q.is_prime_power(get_data=True)
     343            if n == 0:
     344                raise ValueError("q must be a prime power")
     345            if 'p' in kwds and kwds['p'] != p:
     346                raise ValueError("q does not match p")
     347            kwds['p'] = p
     348        functor, ring = self.construction()
     349        functor = copy(functor)
     350        if 'mode' in kwds and 'show_prec' not in kwds:
     351            new_type = kwds.get('type', self._prec_type())
     352            cur_type = self._prec_type()
     353            cur_mode = self._printer._print_mode()
     354            cur_show_prec = self._printer._show_prec()
     355            from .factory import _default_show_prec
     356            if cur_show_prec == _default_show_prec(cur_type, cur_mode):
     357                kwds['show_prec'] = _default_show_prec(new_type, kwds['mode'])
     358            else:
     359                raise RuntimeError
     360        p = kwds.get('p', functor.p if hasattr(functor, 'p') else self.prime())
     361        curpstr = str(self.prime())
     362        functor_dict = getattr(functor, "extras", getattr(functor, "kwds", None))
     363        # If we are switching to 'digits', or changing p, need to ensure a large enough alphabet.
     364        if 'alphabet' not in kwds and (kwds.get('mode') == 'digits' or
     365           (functor_dict['print_mode'].get('mode') == 'digits' and p > getattr(functor, "p", p))):
     366            from .padic_printing import _printer_defaults
     367            kwds['alphabet'] = _printer_defaults.alphabet()[:p]
     368
     369        # There are two kinds of functors possible:
     370        # CompletionFunctor and AlgebraicExtensionFunctor
     371        # We distinguish them by the presence of ``prec``,
     372        if hasattr(functor, "prec"):
     373            functor.extras = copy(functor.extras)
     374            functor.extras['print_mode'] = copy(functor.extras['print_mode'])
     375            if 'type' in kwds and kwds['type'] not in functor._dvr_types:
     376                raise ValueError("completion type must be one of %s"%(", ".join(functor._dvr_types[1:])))
     377            if 'field' in kwds:
     378                field = kwds.pop('field')
     379                if field:
     380                    ring = ring.fraction_field()
     381                    if 'type' not in kwds:
     382                        if self._prec_type() == 'capped-abs':
     383                            kwds['type'] = 'capped-rel'
     384                        elif self._prec_type() == 'fixed-mod':
     385                            raise TypeError('You must specify the type explicitly')
     386                elif ring.is_field():
     387                    ring = ring.ring_of_integers()
     388            for atr in ('p', 'prec', 'type'):
     389                if atr in kwds:
     390                    setattr(functor, atr, kwds.pop(atr))
     391            if q is not None:
     392                if 'names' in kwds:
     393                    names = kwds.pop('names')
     394                elif 'unram_name' in kwds:
     395                    names = kwds.pop('unram_name')
     396                else:
     397                    raise TypeError("You must specify the name of the generator")
     398                res_name = kwds.pop('res_name', names + '0')
     399                modulus = kwds.pop('modulus', get_unramified_modulus(q, res_name))
     400                implementation = kwds.pop('implementation', 'FLINT')
     401            # We have to change the way p prints in the default case
     402            if 'names' in kwds:
     403                functor.extras['names'] = kwds.pop('names')
     404            elif functor.extras['names'][0] == curpstr:
     405                functor.extras['names'] = (str(p),)
     406            for atr in ('ram_name', 'var_name'):
     407                if atr in kwds:
     408                    functor.extras['print_mode'][atr] = kwds.pop(atr)
     409                elif functor.extras['print_mode'].get(atr) == curpstr:
     410                    functor.extras['print_mode'][atr] = str(p)
     411            if 'check' in kwds:
     412                functor.extras['check'] = kwds.pop('check')
     413            for atr in ('mode', 'pos', 'unram_name', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet', 'show_prec'):
     414                if atr in kwds:
     415                    functor.extras['print_mode'][atr] = kwds.pop(atr)
     416            if kwds:
     417                raise ValueError("Extra arguments received: %s"%(", ".join(kwds.keys())))
     418            if q is not None:
     419                # Create an unramified extension
     420                base = functor(ring)
     421                from .factory import ExtensionFactory
     422                modulus = modulus.change_ring(base)
     423                return ExtensionFactory(base=base, premodulus=modulus, names=names, res_name=res_name, unram=True, implementation=implementation)
     424        else:
     425            functor.kwds = copy(functor.kwds)
     426            functor.kwds['print_mode'] = copy(functor.kwds['print_mode'])
     427            if 'prec' in kwds:
     428                prec = kwds.pop('prec')
     429                baseprec = (prec - 1) // self.e() + 1
     430                if baseprec > self.base_ring().precision_cap():
     431                    kwds['prec'] = baseprec
     432                functor.kwds['prec'] = prec
     433            from sage.rings.padics.padic_base_generic import pAdicBaseGeneric
     434            if 'names' in kwds:
     435                functor.names = [kwds.pop('names')]
     436            modulus = None
     437            if 'modulus' in kwds:
     438                modulus = kwds.pop('modulus')
     439                if n is not None and modulus.degree() != n:
     440                    raise ValueError("modulus must have degree matching q")
     441            elif q is not None and self.f() != 1:
     442                # If q is specified, replace the modulus with one from q.
     443                modulus = get_unramified_modulus(q, functor.kwds.get('res_name', functor.names[0] + '0'))
     444            for atr in ('var_name', 'res_name', 'unram_name', 'ram_name'):
     445                if atr in kwds:
     446                    functor.kwds[atr] = kwds.pop(atr)
     447            if 'check' in kwds:
     448                functor.kwds['check'] = kwds['check']
     449            for atr in ('mode', 'pos', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet', 'show_prec'):
     450                if atr in kwds:
     451                    functor.kwds['print_mode'][atr] = kwds[atr]
     452            if 'base' in kwds:
     453                ring = kwds['base']
     454            else:
     455                if q is not None and self.f() == 1:
     456                    kwds['q'] = q
     457                ring = ring.change(**kwds)
     458            if modulus is None:
     459                if len(functor.polys) != 1:
     460                    raise RuntimeError("Unexpected number of defining polynomials")
     461                modulus = functor.polys[0]
     462            if isinstance(modulus.base_ring(), pAdicBaseGeneric):
     463                modulus.change_ring(ring)
     464            functor.polys = [modulus]
     465        return functor(ring)
     466
    193467    def precision_cap(self):
    194468        r"""
    195469        Returns the precision cap for ``self``.
  • src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx

    diff --git a/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx
    index 28d5a0ed9e..ba4bdd18a6 100644
    a b cdef class pAdicZZpXCRElement(pAdicZZpXElement): 
    859859            '5563A4105291255628.148272'
    860860            sage: repr(y*847)[3:]
    861861            '000000000000000000000003'
    862             sage: repr(W(77/3, relprec=0))[3:]
    863             '000'
     862            sage: repr(W(77/3, relprec=0))
     863            '0'
    864864            sage: c = F(11^-1 + O(11^2)); repr(c)[3:]
    865865            '011111.01A'
    866866            sage: repr(c * 11)[3:]
  • src/sage/rings/padics/padic_extension_generic.py

    diff --git a/src/sage/rings/padics/padic_extension_generic.py b/src/sage/rings/padics/padic_extension_generic.py
    index 622c90e359..6285240bcd 100644
    a b class pAdicExtensionGeneric(pAdicGeneric): 
    295295    #        xnew = x - x*delta*(1-q*delta)
    296296    #    return x
    297297
     298    def construction(self):
     299        """
     300        Returns the functorial construction of this ring, namely,
     301        the algebraic extension of the base ring defined by the given
     302        polynomial.
     303
     304        Also preserves other information that makes this ring unique
     305        (e.g. precision, rounding, print mode).
     306
     307        EXAMPLES::
     308
     309            sage: R.<a> = Zq(25, 8, print_mode='val-unit')
     310            sage: c, R0 = R.construction(); R0
     311            5-adic Ring with capped relative precision 8
     312            sage: c(R0)
     313            Unramified Extension in a defined by x^2 + 4*x + 2 with capped relative precision 8 over 5-adic Ring
     314            sage: c(R0) == R
     315            True
     316        """
     317        from sage.categories.pushout import AlgebraicExtensionFunctor as AEF
     318        print_mode = self._printer.dict()
     319        return (AEF([self.defining_polynomial(exact=True)], [self.variable_name()],
     320                    prec=self.precision_cap(), print_mode=self._printer.dict(),
     321                    implementation=self._implementation),
     322                self.base_ring())
     323
    298324    def fraction_field(self, print_mode=None):
    299325        r"""
    300326        Returns the fraction field of this extension, which is just
    class pAdicExtensionGeneric(pAdicGeneric): 
    320346        """
    321347        if self.is_field() and print_mode is None:
    322348            return self
    323         print_mode = self._modified_print_mode(print_mode)
    324         ground_mode = print_mode.copy()
    325         # We don't want to confuse the ground ring with different names.
    326         ground_mode['ram_name'] = None
    327         ground_mode['unram_name'] = None
    328         K = self.ground_ring().fraction_field(ground_mode)
    329         #we don't want to set the print options due to the ground ring since
    330         #different extension fields (with different options) can share the same ground ring.
    331         if self.is_lazy():
    332             return K.extension(self._exact_modulus, prec = self.precision_cap(), halt = self.halting_parameter(), res_name = self.residue_field().variable_name(), print_mode=print_mode, implementation=self._implementation)
     349        if print_mode is None:
     350            return self.change(field=True)
    333351        else:
    334             return K.extension(self._exact_modulus, prec = self.precision_cap(), res_name = self.residue_field().variable_name(), print_mode=print_mode, implementation=self._implementation)
     352            return self.change(field=True, **print_mode)
    335353
    336354    def integer_ring(self, print_mode=None):
    337355        r"""
    class pAdicExtensionGeneric(pAdicGeneric): 
    359377        #Currently does not support fields with non integral defining polynomials.  This should change when the padic_general_extension framework gets worked out.
    360378        if not self.is_field() and print_mode is None:
    361379            return self
    362         print_mode = self._modified_print_mode(print_mode)
    363         ground_mode = print_mode.copy()
    364         # We don't want to confuse the ground ring with different names.
    365         ground_mode['ram_name'] = None
    366         ground_mode['unram_name'] = None
    367         K = self.ground_ring().integer_ring(ground_mode)
    368         #we don't want to set the print options due to the ground ring since
    369         #different extension fields (with different options) can share the same ground ring.
    370         if self.is_lazy():
    371             return K.extension(self._exact_modulus, prec = self.precision_cap(), halt = self.halting_parameter(), res_name = self.residue_field().variable_name(), print_mode=print_mode)
     380        if print_mode is None:
     381            return self.change(field=False)
    372382        else:
    373             return K.extension(self._exact_modulus, prec = self.precision_cap(), res_name = self.residue_field().variable_name(), print_mode=print_mode)
     383            return self.change(field=False, **print_mode)
    374384
    375385    #def hasGNB(self):
    376386    #    raise NotImplementedError
  • src/sage/rings/padics/padic_generic.py

    diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py
    index 466a3d402b..c43c74e6aa 100644
    a b class pAdicGeneric(PrincipalIdealDomain, LocalGeneric): 
    108108            print_mode = {}
    109109        elif isinstance(print_mode, str):
    110110            print_mode = {'mode': print_mode}
    111         for option in ['mode', 'pos', 'ram_name', 'unram_name', 'var_name', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet']:
     111        for option in ['mode', 'pos', 'ram_name', 'unram_name', 'var_name', 'max_ram_terms', 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet', 'show_prec']:
    112112            if option not in print_mode:
    113113                print_mode[option] = self._printer.dict()[option]
    114114        return print_mode