# Ticket #12625: 12625.patch

File 12625.patch, 3.6 KB (added by roed, 7 years ago)
• ## sage/libs/pari/gen.pyx

```# HG changeset patch
# User David Roe <roed@math.harvard.edu>
# Date 1330800771 28800
# Node ID 35f4bf3971e358e68258870f3de5564351e8bfc8
# Parent  a149a04f144a63d4d3a2fc3e96d8aab03d59b165
#12625: conversion of p-adics back from pari

diff --git a/sage/libs/pari/gen.pyx b/sage/libs/pari/gen.pyx```
 a OUTPUT: int EXAMPLES: EXAMPLES:: sage: K = Qp(11,5) sage: x = K(11^-10 + 5*11^-7 + 11^-6) sage: y = pari(x) sage: y.padicprec(11) -5 """ cdef gen _p _p = pari(p) raise TypeError, "p (=%s) must be of type t_INT, but is of type %s."%( _p, _p.type()) return padicprec(x.g, _p.g) def padicprime(gen x): """ The uniformizer of the p-adic ring this element lies in, as a t_INT. INPUT: - ``x`` - gen, of type t_PADIC OUTPUT: - ``p`` - gen, of type t_INT EXAMPLES:: sage: K = Qp(11,5) sage: x = K(11^-10 + 5*11^-7 + 11^-6) sage: y = pari(x) sage: y.padicprime() 11 """ sig_on() return P.new_gen(gel(x.g, 2)) def permtonum(gen x): """
• ## sage/libs/pari/gen_py.py

`diff --git a/sage/libs/pari/gen_py.py b/sage/libs/pari/gen_py.py`
 a Traceback (most recent call last): ... NameError: name 'x' is not defined Conversion of p-adics:: sage: K = Qp(11,5) sage: x = K(11^-10 + 5*11^-7 + 11^-6); x 11^-10 + 5*11^-7 + 11^-6 + O(11^-5) sage: y = pari(x); y 11^-10 + 5*11^-7 + 11^-6 + O(11^-5) sage: y.sage() 11^-10 + 5*11^-7 + 11^-6 + O(11^-5) sage: pari(K(11^-5)).sage() 11^-5 + O(11^0) """ t = z.type() if t == "t_REAL": elif t == "t_MAT": from sage.matrix.constructor import matrix return matrix(z.nrows(),z.ncols(),[python(z[i,j]) for i in range(z.nrows()) for j in range(z.ncols())]) elif t == "t_PADIC": from sage.rings.padics.factory import Qp Z = IntegerRing() p = z.padicprime() rprec = Z(z.padicprec(p)) - Z(z._valp()) K = Qp(Z(p), rprec) return K(z.lift()) else: return sage_eval(str(z), locals=locals)
• ## sage/rings/integer.pyx

`diff --git a/sage/rings/integer.pyx b/sage/rings/integer.pyx`
 a Traceback (most recent call last): ... TypeError: Unable to coerce PARI x to an Integer Test coercion of p-adic with negative valuation:: sage: ZZ(pari(Qp(11)(11^-7))) Traceback (most recent call last): ... TypeError: Cannot convert p-adic with negative valuation to an integer """ # TODO: All the code below should somehow be in an external # cdef'd function.  Then e.g., if a matrix or vector or x = x.floor() break elif paritype == t_PADIC: if x._valp() < 0: raise TypeError("Cannot convert p-adic with negative valuation to an integer") # Lifting a PADIC yields an integer x = x.lift() break