Skip to content

Commit

Permalink
Trac #20217: Remove redundant functions from pari_instance.pyx
Browse files Browse the repository at this point in the history
Many functions in `src/sage/libs/pari/pari_instance.pyx` are just manual
copies of auto-generated code. Remove those functions, but keep the
doctests in `src/sage/libs/pari/tests.py`.

URL: http://trac.sagemath.org/20217
Reported by: jdemeyer
Ticket author(s): Jeroen Demeyer
Reviewer(s): Luca De Feo
  • Loading branch information
Release Manager authored and vbraun committed Mar 22, 2016
2 parents 1fde1bd + d7d2d7d commit d77898b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 136 deletions.
143 changes: 8 additions & 135 deletions src/sage/libs/pari/pari_instance.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1302,42 +1302,6 @@ cdef class PariInstance(PariInstance_auto):
initprimetable(M)
sig_off()

##############################################
## Support for GP Scripts
##############################################

def read(self, bytes filename):
r"""
Read a script from the named filename into the interpreter. The
functions defined in the script are then available for use from
Sage/PARI. The result of the last command in ``filename`` is
returned.
EXAMPLES:
Create a gp file::
sage: import tempfile
sage: gpfile = tempfile.NamedTemporaryFile(mode="w")
sage: gpfile.file.write("mysquare(n) = {\n")
sage: gpfile.file.write(" n^2;\n")
sage: gpfile.file.write("}\n")
sage: gpfile.file.write("polcyclo(5)\n")
sage: gpfile.file.flush()
Read it in Sage, we get the result of the last line::
sage: pari.read(gpfile.name)
x^4 + x^3 + x^2 + x + 1
Call the function defined in the gp file::
sage: pari('mysquare(12)')
144
"""
sig_on()
return self.new_gen(gp_read_file(filename))

def primes(self, n=None, end=None):
"""
Return a pari vector containing the first `n` primes, the primes
Expand Down Expand Up @@ -1416,56 +1380,13 @@ cdef class PariInstance(PariInstance_auto):

nth_prime = deprecated_function_alias(20216, PariInstance_auto.prime)

def euler(self, unsigned long precision=0):
"""
Return Euler's constant to the requested real precision (in bits).
EXAMPLES::
sage: pari.euler()
0.577215664901533
sage: pari.euler(precision=100).python()
0.577215664901532860606512090082...
"""
sig_on()
return self.new_gen(mpeuler(prec_bits_to_words(precision)))

def pi(self, unsigned long precision=0):
"""
Return the value of the constant pi to the requested real precision
(in bits).
EXAMPLES::
sage: pari.pi()
3.14159265358979
sage: pari.pi(precision=100).python()
3.1415926535897932384626433832...
"""
sig_on()
return self.new_gen(mppi(prec_bits_to_words(precision)))

def pollegendre(self, long n, v=-1):
"""
pollegendre(n, v=x): Legendre polynomial of degree n (n C-integer),
in variable v.
EXAMPLES::
sage: pari.pollegendre(7)
429/16*x^7 - 693/16*x^5 + 315/16*x^3 - 35/16*x
sage: pari.pollegendre(7, 'z')
429/16*z^7 - 693/16*z^5 + 315/16*z^3 - 35/16*z
sage: pari.pollegendre(0)
1
"""
sig_on()
return self.new_gen(pollegendre(n, self.get_var(v)))
euler = PariInstance_auto.Euler
pi = PariInstance_auto.Pi

def polchebyshev(self, long n, v=-1):
def polchebyshev(self, long n, v=None):
"""
polchebyshev(n, v=x): Chebyshev polynomial of the first kind of degree
n, in variable v.
Chebyshev polynomial of the first kind of degree `n`,
in the variable `v`.
EXAMPLES::
Expand Down Expand Up @@ -1501,39 +1422,7 @@ cdef class PariInstance(PariInstance_auto):
sig_on()
return self.new_gen(mpfact(n))

def polcyclo(self, long n, v=-1):
"""
polcyclo(n, v=x): cyclotomic polynomial of degree n, in variable
v.
EXAMPLES::
sage: pari.polcyclo(8)
x^4 + 1
sage: pari.polcyclo(7, 'z')
z^6 + z^5 + z^4 + z^3 + z^2 + z + 1
sage: pari.polcyclo(1)
x - 1
"""
sig_on()
return self.new_gen(polcyclo(n, self.get_var(v)))

def polcyclo_eval(self, long n, v):
"""
polcyclo_eval(n, v): value of the nth cyclotomic polynomial at value v.
EXAMPLES::
sage: pari.polcyclo_eval(8, 2)
17
sage: cyclotomic_polynomial(8)(2)
17
"""
cdef gen t0 = self(v)
sig_on()
return self.new_gen(polcyclo_eval(n, t0.g))

def polsubcyclo(self, long n, long d, v=-1):
def polsubcyclo(self, long n, long d, v=None):
"""
polsubcyclo(n, d, v=x): return the pari list of polynomial(s)
defining the sub-abelian extensions of degree `d` of the
Expand All @@ -1558,7 +1447,8 @@ cdef class PariInstance(PariInstance_auto):
return pari.vector(1, [plist])
else:
return plist
#return self.new_gen(polsubcyclo(n, d, self.get_var(v)))

polcyclo_eval = deprecated_function_alias(20217, PariInstance_auto.polcyclo)

def setrand(self, seed):
"""
Expand Down Expand Up @@ -1595,23 +1485,6 @@ cdef class PariInstance(PariInstance_auto):
setrand(t0.g)
sig_off()

def getrand(self):
"""
Returns PARI's current random number seed.
OUTPUT:
GEN of type t_VECSMALL
EXAMPLES::
sage: a = pari.getrand()
sage: a.type()
't_INT'
"""
sig_on()
return self.new_gen(getrand())

def vector(self, long n, entries=None):
"""
vector(long n, entries=None): Create and return the length n PARI
Expand Down
60 changes: 60 additions & 0 deletions src/sage/libs/pari/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,64 @@
doctest:...: DeprecationWarning: pari.primes_up_to_n(n) is deprecated, use pari.primes(end=n) instead
See http://trac.sagemath.org/20216 for details.
[2, 3, 5, 7, 11, 13, 17, 19]
sage: pari.polcyclo_eval(8, 2)
doctest:...: DeprecationWarning: polcyclo_eval is deprecated. Please use polcyclo instead.
See http://trac.sagemath.org/20217 for details.
17
A long list of doctests which used to be part of manually written code
which is now automatically generated:
Create a gp file::
sage: import tempfile
sage: gpfile = tempfile.NamedTemporaryFile(mode="w")
sage: gpfile.file.write("mysquare(n) = {\n")
sage: gpfile.file.write(" n^2;\n")
sage: gpfile.file.write("}\n")
sage: gpfile.file.write("polcyclo(5)\n")
sage: gpfile.file.flush()
Read it in Sage, we get the result of the last line::
sage: pari.read(gpfile.name)
x^4 + x^3 + x^2 + x + 1
Call the function defined in the gp file::
sage: pari('mysquare(12)')
144
Constants::
sage: pari.euler()
0.577215664901533
sage: pari.euler(precision=100).python()
0.577215664901532860606512090082...
sage: pari.pi()
3.14159265358979
sage: pari.pi(precision=100).python()
3.1415926535897932384626433832...
Polynomial functions::
sage: pari.pollegendre(7)
429/16*x^7 - 693/16*x^5 + 315/16*x^3 - 35/16*x
sage: pari.pollegendre(7, 'z')
429/16*z^7 - 693/16*z^5 + 315/16*z^3 - 35/16*z
sage: pari.pollegendre(0)
1
sage: pari.polcyclo(8)
x^4 + 1
sage: pari.polcyclo(7, 'z')
z^6 + z^5 + z^4 + z^3 + z^2 + z + 1
sage: pari.polcyclo(1)
x - 1
Random seed::
sage: a = pari.getrand()
sage: a.type()
't_INT'
"""
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/cyclotomic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def cyclotomic_value(n, x):

P = parent_c(x)
try:
return P(pari.polcyclo_eval(n, x).sage())
return P(pari.polcyclo(n, x).sage())
except Exception:
pass
one = P(1)
Expand Down

0 comments on commit d77898b

Please sign in to comment.