From c26cd0b047aef2446737587bd784e38851277ed4 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Sun, 15 Feb 2015 09:18:13 +0100 Subject: [PATCH 001/135] 16671: implement harmonic number function H(n,m) --- src/sage/functions/all.py | 2 +- src/sage/functions/log.py | 326 ++++++++++++++++++++++++++++++ src/sage/interfaces/maxima_lib.py | 19 +- src/sage/libs/flint/arith.pxd | 1 + src/sage/libs/flint/arith.pyx | 20 ++ 5 files changed, 366 insertions(+), 2 deletions(-) diff --git a/src/sage/functions/all.py b/src/sage/functions/all.py index 1534c6bcc19..72c52cabd8a 100644 --- a/src/sage/functions/all.py +++ b/src/sage/functions/all.py @@ -21,7 +21,7 @@ arg, real_part, real, imag_part, imag, imaginary, conjugate) -from log import (exp, log, ln, polylog, dilog, lambert_w) +from log import (exp, log, ln, polylog, dilog, lambert_w, harmonic_number) from transcendental import (zeta, zetaderiv, zeta_symmetric, hurwitz_zeta, diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 00c911628f4..8ae9ab249b1 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -15,6 +15,8 @@ from sage.rings.real_double import RDF from sage.rings.complex_double import CDF from sage.rings.integer import Integer +from sage.rings.integer_ring import ZZ +from sage.rings.rational_field import QQ class Function_exp(GinacFunction): def __init__(self): @@ -771,3 +773,327 @@ def _print_latex_(self, n, z): return r"\operatorname{W_{%s}}(%s)" % (n, z) lambert_w = Function_lambert_w() + +class Function_harmonic_number_generalized(BuiltinFunction): + r""" + Harmonic and generalized harmonic number functions, + defined by + + .. math:: + + H_{n}=H_{n,1}=\sum_{k=1}^n\frac1k,\qquad H_{n,m}=\sum_{k=1}^n\frac1{k^m} + + They are also well-defined for complex argument, through: + + .. math:: + + H_{s}=\int_0^1\frac{1-x^s}{1-x} + + H_{s,m}=\zeta(s)-\zeta(s,m-1) + + If called with a single argument, that argument is ``s`` and ``m`` is + assumed to be 1 (the normal harmonic numbers ``H_m``). + + ALGORITHM: + + Numerical evaluation is handled using the mpmath and FLINT libraries. + + REFERENCES: + + - :wikipedia:`/Harmonic_number` + + EXAMPLES: + + Evaluation of integer, rational, or complex argument:: + + sage: harmonic_number(5) + 137/60 + sage: harmonic_number(3,3) + 251/216 + sage: harmonic_number(5/2) + -2*log(2) + 46/15 + sage: harmonic_number(3,3.) + zeta(3) - 0.0400198661225573 + sage: harmonic_number(3.,3.) + 1.16203703703704 + sage: harmonic_number(3,3).n(200) + 1.16203703703703703703703... + sage: harmonic_number(1+I,5) + harmonic_number(I + 1, 5) + sage: harmonic_number(1.+I,5) + 1.57436810798989 - 1.06194728851357*I + + Solutions to certain sums are returned in terms of harmonic numbers:: + + sage: k=var('k') + sage: sum(1/k^7,k,1,x) + harmonic_number(x, 7) + + Check the defining integral. at a random integer:: + + sage: n=randint(10,100) + sage: integrate((1-x^n)/(1-x),x,0,1)==harmonic_number(n) + True + + There are several special values which are automatically simplified:: + + sage: harmonic_number(0) + 0 + sage: harmonic_number(1) + 1 + sage: harmonic_number(x,1) + harmonic_number(x) + + Arguments are swapped with respect to the same functions in + Maxima:: + + sage: maxima(harmonic_number(x,2)) # maxima expect interface + gen_harmonic_number(2,_SAGE_VAR_x) + sage: from sage.calculus.calculus import symbolic_expression_from_maxima_string as sefms + sage: sefms('gen_harmonic_number(3,x)') + harmonic_number(x, 3) + sage: from sage.interfaces.maxima_lib import maxima_lib, max_to_sr + sage: c=maxima_lib(harmonic_number(x,2)); c + gen_harmonic_number(2,_SAGE_VAR_x) + sage: max_to_sr(c.ecl()) + harmonic_number(x, 2) + """ + + def __init__(self): + r""" + EXAMPLES:: + + sage: loads(dumps(harmonic_number(x,5))) + harmonic_number(x, 5) + """ + BuiltinFunction.__init__(self, "harmonic_number", nargs=2) + + def __call__(self, *args, **kwds): + r""" + Custom call method allows the user to pass one argument or two. If + one argument is passed, we assume it is ``z`` and that ``m=1``. + + EXAMPLES:: + + sage: harmonic_number(x) + harmonic_number(x) + sage: harmonic_number(x,1) + harmonic_number(x) + sage: harmonic_number(x,2) + harmonic_number(x, 2) + """ + if len(args) == 2: + return BuiltinFunction.__call__(self, *args, **kwds) + elif len(args) == 1: + return BuiltinFunction.__call__(self, args[0], 1, **kwds) + else: + raise TypeError("harmonic_number takes either one or two arguments.") + + def _eval_(self, z, m): + """ + EXAMPLES:: + + sage: harmonic_number(x,0) + x + sage: harmonic_number(x,1) + harmonic_number(x) + sage: harmonic_number(5) + 137/60 + sage: harmonic_number(3,3) + 251/216 + sage: harmonic_number(3,3).n() # this goes from rational to float + 1.16203703703704 + sage: harmonic_number(3.,3) # the following uses zeta functions + 1.16203703703704 + sage: harmonic_number(5,0.1) + zeta(5) - 0.650300133161038 + sage: harmonic_number(5,0.1).n() + 0.386627621982332 + """ + if m == 0: + return z + elif m == 1: + return harmonic_m1._eval_(z) + elif m in ZZ and z in ZZ: + return sum(QQ(1)/(k**m) for k in range(1,z+1)) + + def _evalf_(self, z, m, parent=None, algorithm=None): + """ + EXAMPLES:: + + sage: harmonic_number(3,3.) + zeta(3) - 0.0400198661225573 + sage: harmonic_number(3.,3.) + 1.16203703703704 + sage: harmonic_number(3,3).n(200) + 1.16203703703703703703703... + sage: harmonic_number(I,5).n() + 2.36889632899995 - 3.51181956521611*I + """ + if m == 0: + return parent(z) + elif m == 1: + return harmonic_m1._evalf_(z, parent) + from sage.functions.transcendental import zeta, hurwitz_zeta + return zeta(z) - hurwitz_zeta(z,m+1) + + def _maxima_init_evaled_(self, n, z): + """ + EXAMPLES: + + sage: maxima_calculus(harmonic_number(x,2)) + gen_harmonic_number(2,_SAGE_VAR_x) + sage: maxima_calculus(harmonic_number(3,harmonic_number(x,3),hold=True)) + 1/3^gen_harmonic_number(3,_SAGE_VAR_x)+1/2^gen_harmonic_number(3,_SAGE_VAR_x)+1 + """ + if isinstance(n,str): + maxima_n=n + elif hasattr(n,'_maxima_init_'): + maxima_n=n._maxima_init_() + else: + maxima_n=str(n) + if isinstance(z,str): + maxima_z=z + elif hasattr(z,'_maxima_init_'): + maxima_z=z._maxima_init_() + else: + maxima_z=str(z) + return "gen_harmonic_number(%s,%s)" % (maxima_z, maxima_n) # swap arguments + + def _print_(self, z, m): + """ + EXAMPLES:: + + sage: harmonic_number(x) + harmonic_number(x) + sage: harmonic_number(x,2) + harmonic_number(x, 2) + """ + if m == 1: + return "harmonic_number(%s)" % z + else: + return "harmonic_number(%s, %s)" % (z, m) + + def _print_latex_(self, z, m): + """ + EXAMPLES:: + + sage: latex(harmonic_number(x)) + H_{x} + sage: latex(harmonic_number(x,2)) + H_{{x},{2}} + """ + if m == 1: + return r"H_{%s}" % z + else: + return r"H_{{%s},{%s}}" % (z, m) + +harmonic_number = Function_harmonic_number_generalized() + +def _swap_harmonic(a,b): return harmonic_number(b,a) + +from sage.symbolic.pynac import register_symbol + +register_symbol(_swap_harmonic,{'maxima':'gen_harmonic_number'}) +register_symbol(_swap_harmonic,{'maple':'harmonic'}) + +class Function_harmonic_number(BuiltinFunction): + r""" + Harmonic number function, defined by + + .. math:: + + H_{n}=H_{n,1}=\sum_{k=1}^n\frac1k + + H_{s}=\int_0^1\frac{1-x^s}{1-x} + + See the docstring for :meth:`Function_harmonic_number_generalized`. + + This class exists as callback for ``harmonic_number`` returned by Maxima. + """ + + def __init__(self): + r""" + EXAMPLES:: + + sage: k=var('k') + sage: loads(dumps(sum(1/k,k,1,x))) + harmonic_number(x) + """ + BuiltinFunction.__init__(self, "harmonic_number", nargs=1, + conversions={'mathematica':'HarmonicNumber', + 'maple':'harmonic', + 'maxima':'harmonic_number'}) + + def _eval_(self, z, **kwds): + """ + EXAMPLES:: + + sage: harmonic_number(0) + 0 + sage: harmonic_number(1) + 1 + sage: harmonic_number(20) + 55835135/15519504 + sage: harmonic_number(5/2) + -2*log(2) + 46/15 + sage: harmonic_number(2*x) + harmonic_number(2*x) + """ + if z in ZZ: + if z == 0: + return Integer(0) + elif z == 1: + return Integer(1) + elif z < 2**20: + import sage.libs.flint.arith as flint_arith + return flint_arith.harmonic_number(z) + # fall through if flint cannot handle argument + elif z in QQ: + from sage.calculus.calculus import symbolic_sum + from sage.symbolic.ring import SR + from sage.rings.infinity import infinity + x = SR('x') + return z*symbolic_sum(1/x/(z+x),x,1,infinity) + + def _evalf_(self, z, parent=None, algorithm='mpmath'): + """ + EXAMPLES:: + + sage: harmonic_number(20).n() # this goes from rational to float + 3.59773965714368 + sage: harmonic_number(20).n(200) + 3.59773965714368191148376906... + sage: harmonic_number(20.) # this computes the integral with mpmath + 3.59773965714368 + sage: harmonic_number(1.0*I) + 0.671865985524010 + 1.07667404746858*I + """ + from sage.libs.mpmath import utils as mpmath_utils + import mpmath + return mpmath_utils.call(mpmath.harmonic, z, parent=parent) + + def _derivative_(self, z, diff_param=None): + """ + The derivative of `H_x`. + + EXAMPLES:: + + sage: k=var('k') + sage: sum(1/k,k,1,x).diff(x) + 1/6*pi^2 - harmonic_number(x, 2) + """ + from sage.functions.transcendental import zeta + return zeta(2)-harmonic_number(z,2) + + def _print_latex_(self, z): + """ + EXAMPLES:: + + sage: k=var('k') + sage: latex(sum(1/k,k,1,x)) + H_{x} + """ + return r"H_{%s}" % z + +harmonic_m1 = Function_harmonic_number() diff --git a/src/sage/interfaces/maxima_lib.py b/src/sage/interfaces/maxima_lib.py index c909c14f72a..b023c30e001 100644 --- a/src/sage/interfaces/maxima_lib.py +++ b/src/sage/interfaces/maxima_lib.py @@ -1272,6 +1272,7 @@ def sage_rat(x,y): max_array = EclObject("ARRAY") mdiff = EclObject("%DERIVATIVE") max_lambert_w = sage_op_dict[sage.functions.log.lambert_w] +max_harmo = EclObject("$GEN_HARMONIC_NUMBER") def mrat_to_sage(expr): r""" @@ -1453,6 +1454,20 @@ def dummy_integrate(expr): return sage.symbolic.integration.integral.indefinite_integral(*args, hold=True) +def max_harmonic_to_sage(expr): + """ + EXAMPLES:: + + sage: from sage.interfaces.maxima_lib import maxima_lib, max_to_sr + sage: c=maxima_lib(harmonic_number(x,2)) + sage: c.ecl() + + sage: max_to_sr(c.ecl()) + harmonic_number(x, 2) + """ + return sage.functions.log.harmonic_number(max_to_sr(caddr(expr)), + max_to_sr(cadr(expr))) + ## The dictionaries special_max_to_sage={ mrat : mrat_to_sage, @@ -1460,7 +1475,8 @@ def dummy_integrate(expr): mdiff : mdiff_to_sage, EclObject("%INTEGRATE") : dummy_integrate, max_at : max_at_to_sage, - mlist : mlist_to_sage + mlist : mlist_to_sage, + max_harmo : max_harmonic_to_sage } special_sage_to_max={ @@ -1468,6 +1484,7 @@ def dummy_integrate(expr): sage.functions.other.psi1 : lambda X : [[mqapply],[[max_psi, max_array],0],X], sage.functions.other.psi2 : lambda N,X : [[mqapply],[[max_psi, max_array],N],X], sage.functions.log.lambert_w : lambda N,X : [[max_lambert_w], X] if N==EclObject(0) else [[mqapply],[[max_lambert_w, max_array],N],X], + sage.functions.log.harmonic_number : lambda N,X : [[max_harmo],X,N], sage.functions.hypergeometric.hypergeometric : lambda A, B, X : [[mqapply],[[max_hyper, max_array],lisp_length(A.cdr()),lisp_length(B.cdr())],A,B,X] } diff --git a/src/sage/libs/flint/arith.pxd b/src/sage/libs/flint/arith.pxd index 6e2736782ea..6f825973fac 100644 --- a/src/sage/libs/flint/arith.pxd +++ b/src/sage/libs/flint/arith.pxd @@ -4,3 +4,4 @@ cdef extern from "flint/arith.h": void arith_bell_number(fmpz_t b, ulong n) void arith_number_of_partitions(fmpz_t x, ulong n) void arith_dedekind_sum(fmpq_t, fmpz_t, fmpz_t) + void arith_harmonic_number(fmpq_t, unsigned long n) \ No newline at end of file diff --git a/src/sage/libs/flint/arith.pyx b/src/sage/libs/flint/arith.pyx index 7280536df08..a2287ce6175 100644 --- a/src/sage/libs/flint/arith.pyx +++ b/src/sage/libs/flint/arith.pyx @@ -14,6 +14,7 @@ from fmpz cimport * from fmpq cimport * from arith cimport * + from sage.rings.integer cimport Integer from sage.rings.rational cimport Rational @@ -148,3 +149,22 @@ def dedekind_sum(p, q): return s +def harmonic_number(unsigned long n): + """ + Returns the harmonic number ``H_n``. + + EXAMPLES:: + """ + s = Rational(0) + cdef fmpq_t s_fmpq + + fmpq_init(s_fmpq) + + arith_harmonic_number(s_fmpq, n) + + fmpq_get_mpq((s).value, s_fmpq) + + fmpq_clear(s_fmpq) + + return s + From 3ec7fbba6b2c095ef2aa38cec5ffc47c9ba0cae6 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Sun, 15 Feb 2015 14:40:35 +0100 Subject: [PATCH 002/135] 16671: add missing doctest --- src/sage/libs/flint/arith.pyx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sage/libs/flint/arith.pyx b/src/sage/libs/flint/arith.pyx index a2287ce6175..603f25f1955 100644 --- a/src/sage/libs/flint/arith.pyx +++ b/src/sage/libs/flint/arith.pyx @@ -154,6 +154,11 @@ def harmonic_number(unsigned long n): Returns the harmonic number ``H_n``. EXAMPLES:: + + sage: from sage.libs.flint.arith import harmonic_number + sage: n = 500 + randint(0,500) + sage: bool( sum(1/k for k in range(1,n+1)) == harmonic_number(n) ) + True """ s = Rational(0) cdef fmpq_t s_fmpq From fabf86397adf8c07ce9b63b64c64e5f724702d21 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Mon, 16 Feb 2015 10:10:35 +0100 Subject: [PATCH 003/135] 16671: code tightened --- src/sage/functions/log.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 8ae9ab249b1..7eecf0dcc81 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -868,7 +868,7 @@ def __init__(self): """ BuiltinFunction.__init__(self, "harmonic_number", nargs=2) - def __call__(self, *args, **kwds): + def __call__(self, z, m=1, **kwds): r""" Custom call method allows the user to pass one argument or two. If one argument is passed, we assume it is ``z`` and that ``m=1``. @@ -882,12 +882,7 @@ def __call__(self, *args, **kwds): sage: harmonic_number(x,2) harmonic_number(x, 2) """ - if len(args) == 2: - return BuiltinFunction.__call__(self, *args, **kwds) - elif len(args) == 1: - return BuiltinFunction.__call__(self, args[0], 1, **kwds) - else: - raise TypeError("harmonic_number takes either one or two arguments.") + return BuiltinFunction.__call__(self, z, m, **kwds) def _eval_(self, z, m): """ From 309660a11c0929f223087f5f208a2ea8f14e7625 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Mon, 16 Feb 2015 17:27:21 +0100 Subject: [PATCH 004/135] 16671: generalize evaluation of H(n,m); add its derivative; several fixes; document FLINT computation limit --- src/sage/functions/log.py | 60 +++++++++++++++++++++++++++++++---- src/sage/libs/flint/arith.pxd | 2 +- src/sage/libs/flint/arith.pyx | 2 ++ 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 7eecf0dcc81..808d1b789b8 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -17,6 +17,7 @@ from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ +from sage.rings.rational import Rational class Function_exp(GinacFunction): def __init__(self): @@ -832,7 +833,7 @@ class Function_harmonic_number_generalized(BuiltinFunction): Check the defining integral. at a random integer:: sage: n=randint(10,100) - sage: integrate((1-x^n)/(1-x),x,0,1)==harmonic_number(n) + sage: bool(integrate((1-x^n)/(1-x),x,0,1) == harmonic_number(n)) True There are several special values which are automatically simplified:: @@ -904,13 +905,21 @@ def _eval_(self, z, m): zeta(5) - 0.650300133161038 sage: harmonic_number(5,0.1).n() 0.386627621982332 + sage: harmonic_number(Qp(5)(10)) + 4*5^-1 + 2 + 2*5 + 4*5^2 + 3*5^3 + 5^4 + 4*5^5 + 4*5^6 + 5^7 + 4*5^8 + 3*5^9 + 5^10 + 4*5^11 + 4*5^12 + 5^13 + 4*5^14 + 3*5^15 + 5^16 + 4*5^17 + 4*5^18 + O(5^19) """ if m == 0: return z elif m == 1: return harmonic_m1._eval_(z) - elif m in ZZ and z in ZZ: - return sum(QQ(1)/(k**m) for k in range(1,z+1)) + elif isinstance(m, Integer): + from sage.misc.misc import srange + try: + _ = ZZ(z) + except TypeError: + pass + else: + return sum(1/(k**m) for k in srange(1,z+1)) def _evalf_(self, z, m, parent=None, algorithm=None): """ @@ -955,6 +964,32 @@ def _maxima_init_evaled_(self, n, z): maxima_z=str(z) return "gen_harmonic_number(%s,%s)" % (maxima_z, maxima_n) # swap arguments + def _derivative_(self, n, m, diff_param=None): + """ + The derivative of `H_{n,m}`. + + EXAMPLES:: + + sage: k,m,n = var('k,m,n') + sage: sum(1/k, k, 1, x).diff(x) + 1/6*pi^2 - harmonic_number(x, 2) + sage: harmonic_number(x, 1).diff(x) + 1/6*pi^2 - harmonic_number(x, 2) + sage: harmonic_number(n, m).diff(n) + -m*(harmonic_number(n, m + 1) - zeta(m + 1)) + sage: harmonic_number(n, m).diff(m) + Traceback (most recent call last): + ... + ValueError: cannot differentiate harmonic_number in the second parameter + """ + from sage.functions.transcendental import zeta + if diff_param == 1: + raise ValueError("cannot differentiate harmonic_number in the second parameter") + if m==1: + return harmonic_m1(n).diff() + else: + return m*(zeta(m+1) - harmonic_number(n, m+1)) + def _print_(self, z, m): """ EXAMPLES:: @@ -1002,8 +1037,19 @@ class Function_harmonic_number(BuiltinFunction): H_{s}=\int_0^1\frac{1-x^s}{1-x} + If the argument is an integer greater than `2^20` no rational + evaluation is done, in order to allow for high-precision floating + point computation using `.n()`. + + EXAMPLES:: + + sage: harmonic_number(3**20) + harmonic_number(3486784401) + sage: harmonic_number(3**20).n(200) + 22.54946143840712528804418450... + See the docstring for :meth:`Function_harmonic_number_generalized`. - + This class exists as callback for ``harmonic_number`` returned by Maxima. """ @@ -1035,7 +1081,7 @@ def _eval_(self, z, **kwds): sage: harmonic_number(2*x) harmonic_number(2*x) """ - if z in ZZ: + if isinstance(z, Integer): if z == 0: return Integer(0) elif z == 1: @@ -1044,11 +1090,11 @@ def _eval_(self, z, **kwds): import sage.libs.flint.arith as flint_arith return flint_arith.harmonic_number(z) # fall through if flint cannot handle argument - elif z in QQ: + elif isinstance(z, Rational): from sage.calculus.calculus import symbolic_sum from sage.symbolic.ring import SR from sage.rings.infinity import infinity - x = SR('x') + x = SR.var('x') return z*symbolic_sum(1/x/(z+x),x,1,infinity) def _evalf_(self, z, parent=None, algorithm='mpmath'): diff --git a/src/sage/libs/flint/arith.pxd b/src/sage/libs/flint/arith.pxd index 6f825973fac..6c44853cd8b 100644 --- a/src/sage/libs/flint/arith.pxd +++ b/src/sage/libs/flint/arith.pxd @@ -4,4 +4,4 @@ cdef extern from "flint/arith.h": void arith_bell_number(fmpz_t b, ulong n) void arith_number_of_partitions(fmpz_t x, ulong n) void arith_dedekind_sum(fmpq_t, fmpz_t, fmpz_t) - void arith_harmonic_number(fmpq_t, unsigned long n) \ No newline at end of file + void arith_harmonic_number(fmpq_t, unsigned long n) diff --git a/src/sage/libs/flint/arith.pyx b/src/sage/libs/flint/arith.pyx index 603f25f1955..bca67cafbf5 100644 --- a/src/sage/libs/flint/arith.pyx +++ b/src/sage/libs/flint/arith.pyx @@ -165,9 +165,11 @@ def harmonic_number(unsigned long n): fmpq_init(s_fmpq) + sig_on() arith_harmonic_number(s_fmpq, n) fmpq_get_mpq((s).value, s_fmpq) + sig_off() fmpq_clear(s_fmpq) From ca696281c6d2425b72d72b6408e4a787b32d637a Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Tue, 17 Feb 2015 07:22:17 +0100 Subject: [PATCH 005/135] 16671: remove restriction --- src/sage/functions/log.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 808d1b789b8..549f0d6a84a 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -1037,17 +1037,6 @@ class Function_harmonic_number(BuiltinFunction): H_{s}=\int_0^1\frac{1-x^s}{1-x} - If the argument is an integer greater than `2^20` no rational - evaluation is done, in order to allow for high-precision floating - point computation using `.n()`. - - EXAMPLES:: - - sage: harmonic_number(3**20) - harmonic_number(3486784401) - sage: harmonic_number(3**20).n(200) - 22.54946143840712528804418450... - See the docstring for :meth:`Function_harmonic_number_generalized`. This class exists as callback for ``harmonic_number`` returned by Maxima. @@ -1086,10 +1075,9 @@ def _eval_(self, z, **kwds): return Integer(0) elif z == 1: return Integer(1) - elif z < 2**20: + else: import sage.libs.flint.arith as flint_arith return flint_arith.harmonic_number(z) - # fall through if flint cannot handle argument elif isinstance(z, Rational): from sage.calculus.calculus import symbolic_sum from sage.symbolic.ring import SR From f6e21137f97771b916ceae7f16a59805af78291f Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Thu, 5 Mar 2015 16:05:00 +0100 Subject: [PATCH 006/135] 17790: add padics to the conversion workaround for symbolic function arguments --- src/sage/symbolic/function.pyx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index e4de715dea5..c22e333650f 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -389,6 +389,8 @@ cdef class Function(SageObject): TypeError: cannot coerce arguments: ... sage: exp(QQbar(I)) 0.540302305868140 + 0.841470984807897*I + sage: binomial(Qp(2)(9),5) + 126 For functions with single argument, if coercion fails we try to call a method with the name of the function on the object:: @@ -474,12 +476,14 @@ cdef class Function(SageObject): # to work around this limitation, we manually convert # elements of QQbar to symbolic expressions here from sage.rings.qqbar import QQbar, AA + from sage.rings.padics.padic_generic_element import pAdicGenericElement nargs = [None]*len(args) for i in range(len(args)): carg = args[i] - if isinstance(carg, Element) and \ - (carg)._parent is QQbar or \ - (carg)._parent is AA: + if (isinstance(carg, Element) and + ((carg)._parent is QQbar or + (carg)._parent is AA or + isinstance(carg, pAdicGenericElement))): nargs[i] = SR(carg) else: try: From d60311eda7cce822b74480550498da09b34b7a63 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Sat, 7 Mar 2015 10:05:24 +0100 Subject: [PATCH 007/135] 16671: handle more argument types; fix num. H(n,m); cosmetics --- src/sage/functions/log.py | 60 ++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 549f0d6a84a..52ffabe6de1 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -790,7 +790,7 @@ class Function_harmonic_number_generalized(BuiltinFunction): H_{s}=\int_0^1\frac{1-x^s}{1-x} - H_{s,m}=\zeta(s)-\zeta(s,m-1) + H_{s,m}=\zeta(m)-\zeta(m,s-1) If called with a single argument, that argument is ``s`` and ``m`` is assumed to be 1 (the normal harmonic numbers ``H_m``). @@ -813,7 +813,7 @@ class Function_harmonic_number_generalized(BuiltinFunction): 251/216 sage: harmonic_number(5/2) -2*log(2) + 46/15 - sage: harmonic_number(3,3.) + sage: harmonic_number(3.,3) zeta(3) - 0.0400198661225573 sage: harmonic_number(3.,3.) 1.16203703703704 @@ -821,7 +821,7 @@ class Function_harmonic_number_generalized(BuiltinFunction): 1.16203703703703703703703... sage: harmonic_number(1+I,5) harmonic_number(I + 1, 5) - sage: harmonic_number(1.+I,5) + sage: harmonic_number(5,1.+I) 1.57436810798989 - 1.06194728851357*I Solutions to certain sums are returned in terms of harmonic numbers:: @@ -830,10 +830,10 @@ class Function_harmonic_number_generalized(BuiltinFunction): sage: sum(1/k^7,k,1,x) harmonic_number(x, 7) - Check the defining integral. at a random integer:: + Check the defining integral at a random integer:: sage: n=randint(10,100) - sage: bool(integrate((1-x^n)/(1-x),x,0,1) == harmonic_number(n)) + sage: bool(SR(integrate((1-x^n)/(1-x),x,0,1)) == harmonic_number(n)) True There are several special values which are automatically simplified:: @@ -899,39 +899,51 @@ def _eval_(self, z, m): 251/216 sage: harmonic_number(3,3).n() # this goes from rational to float 1.16203703703704 - sage: harmonic_number(3.,3) # the following uses zeta functions + sage: harmonic_number(3,3.) # the following uses zeta functions 1.16203703703704 - sage: harmonic_number(5,0.1) + sage: harmonic_number(3.,3) + zeta(3) - 0.0400198661225573 + sage: harmonic_number(0.1,5) zeta(5) - 0.650300133161038 - sage: harmonic_number(5,0.1).n() + sage: harmonic_number(0.1,5).n() 0.386627621982332 - sage: harmonic_number(Qp(5)(10)) - 4*5^-1 + 2 + 2*5 + 4*5^2 + 3*5^3 + 5^4 + 4*5^5 + 4*5^6 + 5^7 + 4*5^8 + 3*5^9 + 5^10 + 4*5^11 + 4*5^12 + 5^13 + 4*5^14 + 3*5^15 + 5^16 + 4*5^17 + 4*5^18 + O(5^19) + sage: harmonic_number(3,5/2) + 1/27*sqrt(3) + 1/8*sqrt(2) + 1 + sage: harmonic_number(Qp(5)(10),1) + 4*5^-1 + 2 + 2*5 + 4*5^2 + 3*5^3 + 5^4 + ... + sage: harmonic_number(Qp(5)(10),2) + 4*5^-1 + 3 + 5 + 3*5^2 + 2*5^3 + 3*5^5 + ... """ if m == 0: return z elif m == 1: return harmonic_m1._eval_(z) - elif isinstance(m, Integer): - from sage.misc.misc import srange + from sage.symbolic.ring import SR + P = s_parent(z) + if not hasattr(z, 'operator') and not self._is_numerical(z): try: - _ = ZZ(z) + z = ZZ(z) except TypeError: pass else: - return sum(1/(k**m) for k in srange(1,z+1)) + if (isinstance(m, (Integer, int))): + if P in (ZZ, int): + P = QQ + return SR(P(sum(1/(k**m) for k in range(1,z+1)))) + elif isinstance(m, Rational): + return sum(1/(k**m) for k in range(1,z+1)) def _evalf_(self, z, m, parent=None, algorithm=None): """ EXAMPLES:: - sage: harmonic_number(3,3.) + sage: harmonic_number(3.,3) zeta(3) - 0.0400198661225573 sage: harmonic_number(3.,3.) 1.16203703703704 sage: harmonic_number(3,3).n(200) 1.16203703703703703703703... - sage: harmonic_number(I,5).n() + sage: harmonic_number(5,I).n() 2.36889632899995 - 3.51181956521611*I """ if m == 0: @@ -939,7 +951,7 @@ def _evalf_(self, z, m, parent=None, algorithm=None): elif m == 1: return harmonic_m1._evalf_(z, parent) from sage.functions.transcendental import zeta, hurwitz_zeta - return zeta(z) - hurwitz_zeta(z,m+1) + return zeta(m) - hurwitz_zeta(m,z+1) def _maxima_init_evaled_(self, n, z): """ @@ -1069,7 +1081,18 @@ def _eval_(self, z, **kwds): -2*log(2) + 46/15 sage: harmonic_number(2*x) harmonic_number(2*x) + sage: harmonic_number(Qp(5)(3)) + 1 + 5 + 4*5^2 + 4*5^4 + 4*5^6 + ... """ + from sage.symbolic.ring import SR + P = s_parent(z) + if P in (ZZ, int): + P = QQ + if not hasattr(z, 'operator') and not self._is_numerical(z): + try: + z = ZZ(QQ(z)) + except TypeError: + pass if isinstance(z, Integer): if z == 0: return Integer(0) @@ -1077,10 +1100,9 @@ def _eval_(self, z, **kwds): return Integer(1) else: import sage.libs.flint.arith as flint_arith - return flint_arith.harmonic_number(z) + return SR(P(flint_arith.harmonic_number(z))) elif isinstance(z, Rational): from sage.calculus.calculus import symbolic_sum - from sage.symbolic.ring import SR from sage.rings.infinity import infinity x = SR.var('x') return z*symbolic_sum(1/x/(z+x),x,1,infinity) From f643cb401dec648fe0bc601573a5b019d58676ea Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Tue, 16 Jun 2015 08:20:16 +0200 Subject: [PATCH 008/135] 18709: nearly general implementation of closed forms of C-finite sequences --- src/sage/rings/cfinite_sequence.py | 114 +++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/src/sage/rings/cfinite_sequence.py b/src/sage/rings/cfinite_sequence.py index b004f9931c9..e46e74130e7 100644 --- a/src/sage/rings/cfinite_sequence.py +++ b/src/sage/rings/cfinite_sequence.py @@ -756,6 +756,119 @@ def series(self, n): R = LaurentSeriesRing(QQ, 'x', default_prec=n) return R(self.ogf()) + def closed_form(self): + """ + Return a symbolic expression in ``n`` that maps ``n`` to the n-th member of the sequence. + + It is easy to show that any C-finite sequence has a closed form of the type: + + .. MATH:: + + a_n = \sum_{i=1}^d c_i \cdot r_i^(n-s), \qquad\text{$n\ge s$, $d$ the degree of the sequence}, + + with ``c_i`` constants, ``r_i`` the roots of the o.g.f. denominator, and ``s`` the offset of + the sequence (see for example :arxiv:`0704.2481`). + + EXAMPLES:: + + sage: n = var('n') + + sage: CFiniteSequence(x/(1-x)).closed_form() + 1 + sage: CFiniteSequence(x/(1-x^2)).closed_form() + -1/2*(-1)^n + 1/2 + sage: CFiniteSequence(x/(1-x^3)).closed_form() + 1/9*sqrt(3)*(sqrt(3) + 6*sin(2/3*pi*n)) + sage: CFiniteSequence(x/(1-x^4)).closed_form() + 1/2*I*(-I)^n - 1/2*I*(-1)^(1/2*n) - 1/4*(-1)^n + 1/4 + sage: CFiniteSequence(x/(1+x^3)).closed_form() + -1/9*sqrt(3)*(sqrt(3)*cos(pi*n) + I*sqrt(3)*sin(pi*n) - 6*sin(1/3*pi*n)) + sage: CFiniteSequence(x/(1+x^4)).closed_form() + -(0.1767766952966369? - 0.1767766952966369?*I)*(0.7071067811865475? + ... + + sage: CFiniteSequence(x*(x^2+4*x+1)/(1-x)^5).closed_form() + 1/4*n^4 + 1/2*n^3 + 1/4*n^2 + sage: CFiniteSequence((1+2*x-x^2)/(1-x)^4/(1+x)^2).closed_form() + 1/12*n^3 - 1/8*(-1)^n*(n + 1) + 3/4*n^2 + 43/24*n + 9/8 + sage: CFiniteSequence(1/(1-x)/(1-2*x)/(1-3*x)).closed_form() + 1/2*3^(n + 2) - 2^(n + 2) + 1/2 + sage: CFiniteSequence(1/(1-x)^3/(1-2*x)^4).closed_form() + 1/3*(n^3 - 3*n^2 + 20*n - 36)*2^(n + 2) + 1/2*n^2 + 19/2*n + 49 + + sage: CFiniteSequence((4*x+3)/(1-2*x-5*x^2)).closed_form() + 1/12*sqrt(6)*((-5/(sqrt(6) + 1))^n*(3*sqrt(6) - 7) + 3*sqrt(6)*(5/(sqrt(6) - 1))^n + 7*(5/(sqrt(6) - 1))^n) + sage: CFiniteSequence(x/(1-x-x^2)).closed_form() + -1/5*sqrt(5)*((-2/(sqrt(5) + 1))^n - (2/(sqrt(5) - 1))^n) + sage: all(_.subs(n==i).simplify_full()==fibonacci(i) for i in range(10)) + True + """ + from sage.symbolic.ring import SR + from sage.rings.arith import lcm, binomial + __, parts = (self.ogf()).partial_fraction_decomposition() + cm = lcm([part.factor().unit().denominator() for part in parts]) + expr = SR(0) + for part in parts: + denom = part.denominator() + num = part.numerator() + f = denom.factor() + assert len(f) == 1 + denom_base = f[0][0] + denom_exp = f[0][1] + cc_denom = denom.constant_coefficient() + denom = denom/cc_denom + num = num/cc_denom + cc_denom_base = denom_base.constant_coefficient() + denom_base = denom_base/cc_denom_base + dl = denom_base.list() + term = SR(0) + n = SR.var('n') + can_simplify = True + + if len(dl) == 2: + constant_factor = num + if dl[1] == -1: + term = SR(constant_factor) + else: + term = SR(constant_factor)*SR(-dl[1])**n + if denom_exp > 1: + term *= binomial(n+denom_exp-1, denom_exp-1) + elif len(dl) == 3 and denom_exp == 1: + from sage.functions.other import sqrt + a0 = self[0] + a1 = self[1] + c = -dl[1] + d = -dl[2] + r1 = 2*d/(-c+sqrt(c**2+4*d)) + r2 = 2*d/(-c-sqrt(c**2+4*d)) + term = ((a1-c*a0+a0*r1)*r1**n-(a1-c*a0+a0*r2)*r2**n)/sqrt(c**2+4*d) + elif denom_exp == 1: + from operator import add, mul + from sage.rings.qqbar import QQbar + from sage.matrix.constructor import Matrix + deg = len(dl)-1 + num_coeffs = num.coefficients(sparse=False) + num_coeffs += [0] * (deg - len(num_coeffs)) + can_simplify = False + R = PolynomialRing(QQbar, 'X') + X = R.gen() + roots = denom_base.roots(QQbar) + full_prod = reduce(mul, [X-r for (r,_) in roots], 1) + prods = [full_prod/(X-roots[i][0]) for i in range(deg)] + m = Matrix(QQbar, [[prods[j].numerator().list(X)[i] + for j in range(deg)] for i in range(deg)]) + rv = m.inverse() * Matrix(QQbar, deg, 1, num_coeffs) + for i in range(deg): + c = rv[i][0] + c.exactify() + term += SR(c/roots[i][0]) * SR(1/roots[i][0])**n + else: + return [] + expr += term + if can_simplify: + return expr.simplify_full() + else: + return expr + class CFiniteSequences_generic(CommutativeRing, UniqueRepresentation): r""" @@ -1141,6 +1254,7 @@ def guess(self, sequence, algorithm='sage'): return 0 else: return CFiniteSequence(num / den) + """ .. TODO:: From c784bce5c0a3823443b0033bf424f954d94810fa Mon Sep 17 00:00:00 2001 From: Salvatore Stella Date: Fri, 6 Nov 2015 17:13:22 +0100 Subject: [PATCH 009/135] Fix coercion for LaurentPolynomialRing --- .../rings/polynomial/laurent_polynomial.pyx | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index 091fc1a2fb0..7d8a9ca4f89 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1297,9 +1297,31 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): 4*w*z^3 + w^-1*z^-1 sage: L(1/2) 1/2 + + TESTS:: + + Check that #19538 is fixed + + sage: R = LaurentPolynomialRing(ZZ, 'x', 4) + sage: S = LaurentPolynomialRing(ZZ, 'x0,x1') + sage: S.inject_variables() + Defining x0, x1 + sage: x0 in R + True + """ if isinstance(x, LaurentPolynomial_mpair): - x = x.dict() + inject_dict = {} + for y in x.variables(): + x_index = x.parent().gens().index(y) + name = x.parent().variable_names()[x_index] + inject_dict[parent.variable_names().index(name)] = x_index + tmp_x = x.dict() + x = dict() + n = int(parent.ngens()) + for k in tmp_x.keys(): + img_k = ETuple(dict([(a,k[inject_dict[a]]) for a in inject_dict.keys()]),n) + x[img_k] = tmp_x[k] elif isinstance(x, PolyDict): x = x.dict() if isinstance(x, dict): From 76ac4339b195762106d406516400f8468de844ef Mon Sep 17 00:00:00 2001 From: Salvatore Stella Date: Fri, 6 Nov 2015 19:06:57 +0100 Subject: [PATCH 010/135] Improved doctest --- src/sage/rings/polynomial/laurent_polynomial.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index 7d8a9ca4f89..c2835be277f 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1300,7 +1300,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): TESTS:: - Check that #19538 is fixed + Check that :trac:`19538` is fixed sage: R = LaurentPolynomialRing(ZZ, 'x', 4) sage: S = LaurentPolynomialRing(ZZ, 'x0,x1') @@ -1308,7 +1308,6 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): Defining x0, x1 sage: x0 in R True - """ if isinstance(x, LaurentPolynomial_mpair): inject_dict = {} From e510540635d871837fd5de0ae47f3fdbf51f07e6 Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Tue, 5 Apr 2016 09:12:32 -0700 Subject: [PATCH 011/135] Implement wrapper for PARI hyperellcharpoly --- .../hyperelliptic_finite_field.py | 75 ++++++++++++++++--- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 94a01cecc6b..169461e0d1d 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -13,6 +13,8 @@ - Jean-Pierre Flori, Jan Tuitman (2013) +- Kiran Kedlaya (2016) + EXAMPLES:: sage: K. = GF(9, 'a') @@ -30,6 +32,7 @@ # Copyright (C) 2011 Daniel Krenn # Copyright (C) 2013 Jean-Pierre Flori , # Jan Tuitman +# Copyright (C) 2016 Kiran Kedlaya # # Distributed under the terms of the GNU General Public License (GPL) # @@ -51,7 +54,7 @@ from sage.misc.cachefunc import cached_method from sage.matrix.constructor import identity_matrix, matrix from sage.misc.functional import rank - +from sage.libs.all import pari class HyperellipticCurve_finite_field(hyperelliptic_generic.HyperellipticCurve_generic): def _frobenius_coefficient_bound_charpoly(self): @@ -417,6 +420,58 @@ def frobenius_polynomial_matrix(self, M=None, algorithm='hypellfrob'): return ZZ['x'](f) + def frobenius_polynomial_pari(self): + r""" + Compute the charpoly of frobenius, as an element of `\ZZ[x]`, + by calling the PARI function hyperellcharpoly. + + EXAMPLES:: + + sage: R. = PolynomialRing(GF(37)) + sage: H = HyperellipticCurve(t^5 + t + 2) + sage: H.frobenius_polynomial_pari() + x^4 + x^3 - 52*x^2 + 37*x + 1369 + + A quadratic twist:: + + sage: H = HyperellipticCurve(2*t^5 + 2*t + 4) + sage: H.frobenius_polynomial_pari() + x^4 - x^3 - 52*x^2 - 37*x + 1369 + + Slightly larger example:: + + sage: K = GF(2003) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^7 + 487*t^5 + 9*t + 1) + sage: H.frobenius_polynomial_pari() + x^6 - 14*x^5 + 1512*x^4 - 66290*x^3 + 3028536*x^2 - 56168126*x + 8036054027 + + Curves defined over a non-prime field are supported as well:: + + sage: K. = GF(7^2) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^5 + a*t + 1) + sage: H.frobenius_polynomial_pari() + x^4 + 4*x^3 + 84*x^2 + 196*x + 2401 + + sage: K. = GF(23**3) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^3 + z*t + 4) + sage: H.frobenius_polynomial_pari() + x^2 - 15*x + 12167 + + Over prime fields of odd characteristic, `h` may be non-zero:: + + sage: K = GF(101) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^5 + 27*t + 3, t) + sage: H.frobenius_polynomial_pari() + x^4 + 2*x^3 - 58*x^2 + 202*x + 10201 + + """ + f, h = self.hyperelliptic_polynomials() + return ZZ['x'](pari([f, h]).hyperellcharpoly()) + @cached_method def frobenius_polynomial(self): r""" @@ -443,14 +498,14 @@ def frobenius_polynomial(self): sage: H.frobenius_polynomial() x^6 - 14*x^5 + 1512*x^4 - 66290*x^3 + 3028536*x^2 - 56168126*x + 8036054027 - Curves defined over a non-prime field are supported as well, - but a naive algorithm is used; especially when `g = 1`, - fast point counting on elliptic curves should be used:: + Curves defined over a non-prime field of odd characteristic, + or an odd prime field which is too small compared to the genus, + are supported via PARI:: sage: K. = GF(23**3) sage: R. = PolynomialRing(K) sage: H = HyperellipticCurve(t^3 + z*t + 4) - sage: H.frobenius_polynomial() # long time, 4s on a Corei7 + sage: H.frobenius_polynomial() x^2 - 15*x + 12167 sage: K. = GF(3**3) @@ -459,14 +514,12 @@ def frobenius_polynomial(self): sage: H.frobenius_polynomial() x^4 - 3*x^3 + 10*x^2 - 81*x + 729 - Over prime fields of odd characteristic, when `h` is non-zero, - this naive algorithm is currently used as well, whereas we should - rather use another defining equation:: + Over prime fields of odd characteristic, `h` may be non-zero:: sage: K = GF(101) sage: R. = PolynomialRing(K) sage: H = HyperellipticCurve(t^5 + 27*t + 3, t) - sage: H.frobenius_polynomial() # long time, 3s on a Corei7 + sage: H.frobenius_polynomial() x^4 + 2*x^3 - 58*x^2 + 202*x + 10201 In even characteristic, the naive algorithm could cover all cases @@ -487,8 +540,10 @@ def frobenius_polynomial(self): g = self.genus() f, h = self.hyperelliptic_polynomials() - if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h == 0: + if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h==0: return self.frobenius_polynomial_matrix() + elif q%2 == 1: + return self.frobenius_polynomial_pari() else: return self.frobenius_polynomial_cardinalities() From 95ede4bc4354e8717bfb38143d8b5ebb168bf878 Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Tue, 5 Apr 2016 09:18:08 -0700 Subject: [PATCH 012/135] Correctly handle frobenius_matrix() for an even degree polynomial --- .../hyperelliptic_curves/hyperelliptic_finite_field.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 169461e0d1d..50b38aec229 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -522,6 +522,11 @@ def frobenius_polynomial(self): sage: H.frobenius_polynomial() x^4 + 2*x^3 - 58*x^2 + 202*x + 10201 + Over prime fields of odd characteristic, `f` may have even degree:: + sage: H = HyperellipticCurve(t^6 + 27*t + 3) + sage: H.frobenius_polynomial() + x^4 + 25*x^3 + 322*x^2 + 2525*x + 10201 + In even characteristic, the naive algorithm could cover all cases because we can easily check for squareness in quotient rings of polynomial rings over finite fields but these rings unfortunately @@ -540,7 +545,7 @@ def frobenius_polynomial(self): g = self.genus() f, h = self.hyperelliptic_polynomials() - if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h==0: + if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h==0 and f.degree() %2 == 1: return self.frobenius_polynomial_matrix() elif q%2 == 1: return self.frobenius_polynomial_pari() From 4c92503eeaed4d9cca5016ee5fec2c6082eb65d8 Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Fri, 8 Apr 2016 16:48:21 -0700 Subject: [PATCH 013/135] Fix count_points for even-degree hyperelliptics --- .../schemes/hyperelliptic_curves/hyperelliptic_finite_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 50b38aec229..8a193f86371 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -1136,7 +1136,7 @@ def count_points(self, n=1): g = self.genus() f, h = self.hyperelliptic_polynomials() - if e == 1 and h == 0: + if e == 1 and h == 0 and f.degree() % 2 == 1: N1 = self._frobenius_coefficient_bound_traces(n) N2 = self._frobenius_coefficient_bound_charpoly() if n < g and q > (2*g+1)*(2*N1-1): From 6ca4b8c808ba9a53a17ce061a96ecbabea58d595 Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Sat, 9 Apr 2016 08:04:24 -0700 Subject: [PATCH 014/135] Add doctest regarding #20391 --- .../hyperelliptic_curves/hyperelliptic_finite_field.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 8a193f86371..cf4d6e3e56c 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -1129,6 +1129,12 @@ def count_points(self, n=1): sage: H = HyperellipticCurve(x^5+a*x^2+1, x+a+1) sage: H.count_points(6) [2, 24, 74, 256, 1082, 4272] + + This example shows that ticket #20391 is resolved: + sage: x = polygen(GF(4099)) + sage: H = HyperellipticCurve(x^6 + x + 1) + sage: H.count_points(1) + [4106] """ K = self.base_ring() q = K.cardinality() From d969623fd858087879e559754631c081d7d311e8 Mon Sep 17 00:00:00 2001 From: Florent Hivert Date: Fri, 15 Apr 2016 23:04:43 +0200 Subject: [PATCH 015/135] 20449 : Tentative 1 character fix --- src/sage/parallel/map_reduce.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/parallel/map_reduce.py b/src/sage/parallel/map_reduce.py index 6275e56d334..352638b7a7f 100644 --- a/src/sage/parallel/map_reduce.py +++ b/src/sage/parallel/map_reduce.py @@ -553,7 +553,7 @@ def proc_number(max_proc = None): if max_proc is None: return max(cpu_count(), 1) else: - return min(max_proc, max(cpu_count(), 1)) + return min(max_proc, max(cpu_count(), 2)) class AbortError(Exception): From f6e4aa143f809ff4f369af1342a1e6712868d2ff Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Tue, 5 Apr 2016 09:12:32 -0700 Subject: [PATCH 016/135] Implement wrapper for PARI hyperellcharpoly --- .../hyperelliptic_finite_field.py | 75 ++++++++++++++++--- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 94a01cecc6b..169461e0d1d 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -13,6 +13,8 @@ - Jean-Pierre Flori, Jan Tuitman (2013) +- Kiran Kedlaya (2016) + EXAMPLES:: sage: K. = GF(9, 'a') @@ -30,6 +32,7 @@ # Copyright (C) 2011 Daniel Krenn # Copyright (C) 2013 Jean-Pierre Flori , # Jan Tuitman +# Copyright (C) 2016 Kiran Kedlaya # # Distributed under the terms of the GNU General Public License (GPL) # @@ -51,7 +54,7 @@ from sage.misc.cachefunc import cached_method from sage.matrix.constructor import identity_matrix, matrix from sage.misc.functional import rank - +from sage.libs.all import pari class HyperellipticCurve_finite_field(hyperelliptic_generic.HyperellipticCurve_generic): def _frobenius_coefficient_bound_charpoly(self): @@ -417,6 +420,58 @@ def frobenius_polynomial_matrix(self, M=None, algorithm='hypellfrob'): return ZZ['x'](f) + def frobenius_polynomial_pari(self): + r""" + Compute the charpoly of frobenius, as an element of `\ZZ[x]`, + by calling the PARI function hyperellcharpoly. + + EXAMPLES:: + + sage: R. = PolynomialRing(GF(37)) + sage: H = HyperellipticCurve(t^5 + t + 2) + sage: H.frobenius_polynomial_pari() + x^4 + x^3 - 52*x^2 + 37*x + 1369 + + A quadratic twist:: + + sage: H = HyperellipticCurve(2*t^5 + 2*t + 4) + sage: H.frobenius_polynomial_pari() + x^4 - x^3 - 52*x^2 - 37*x + 1369 + + Slightly larger example:: + + sage: K = GF(2003) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^7 + 487*t^5 + 9*t + 1) + sage: H.frobenius_polynomial_pari() + x^6 - 14*x^5 + 1512*x^4 - 66290*x^3 + 3028536*x^2 - 56168126*x + 8036054027 + + Curves defined over a non-prime field are supported as well:: + + sage: K. = GF(7^2) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^5 + a*t + 1) + sage: H.frobenius_polynomial_pari() + x^4 + 4*x^3 + 84*x^2 + 196*x + 2401 + + sage: K. = GF(23**3) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^3 + z*t + 4) + sage: H.frobenius_polynomial_pari() + x^2 - 15*x + 12167 + + Over prime fields of odd characteristic, `h` may be non-zero:: + + sage: K = GF(101) + sage: R. = PolynomialRing(K) + sage: H = HyperellipticCurve(t^5 + 27*t + 3, t) + sage: H.frobenius_polynomial_pari() + x^4 + 2*x^3 - 58*x^2 + 202*x + 10201 + + """ + f, h = self.hyperelliptic_polynomials() + return ZZ['x'](pari([f, h]).hyperellcharpoly()) + @cached_method def frobenius_polynomial(self): r""" @@ -443,14 +498,14 @@ def frobenius_polynomial(self): sage: H.frobenius_polynomial() x^6 - 14*x^5 + 1512*x^4 - 66290*x^3 + 3028536*x^2 - 56168126*x + 8036054027 - Curves defined over a non-prime field are supported as well, - but a naive algorithm is used; especially when `g = 1`, - fast point counting on elliptic curves should be used:: + Curves defined over a non-prime field of odd characteristic, + or an odd prime field which is too small compared to the genus, + are supported via PARI:: sage: K. = GF(23**3) sage: R. = PolynomialRing(K) sage: H = HyperellipticCurve(t^3 + z*t + 4) - sage: H.frobenius_polynomial() # long time, 4s on a Corei7 + sage: H.frobenius_polynomial() x^2 - 15*x + 12167 sage: K. = GF(3**3) @@ -459,14 +514,12 @@ def frobenius_polynomial(self): sage: H.frobenius_polynomial() x^4 - 3*x^3 + 10*x^2 - 81*x + 729 - Over prime fields of odd characteristic, when `h` is non-zero, - this naive algorithm is currently used as well, whereas we should - rather use another defining equation:: + Over prime fields of odd characteristic, `h` may be non-zero:: sage: K = GF(101) sage: R. = PolynomialRing(K) sage: H = HyperellipticCurve(t^5 + 27*t + 3, t) - sage: H.frobenius_polynomial() # long time, 3s on a Corei7 + sage: H.frobenius_polynomial() x^4 + 2*x^3 - 58*x^2 + 202*x + 10201 In even characteristic, the naive algorithm could cover all cases @@ -487,8 +540,10 @@ def frobenius_polynomial(self): g = self.genus() f, h = self.hyperelliptic_polynomials() - if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h == 0: + if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h==0: return self.frobenius_polynomial_matrix() + elif q%2 == 1: + return self.frobenius_polynomial_pari() else: return self.frobenius_polynomial_cardinalities() From 834b5c596621f1e9e96d3b7e86e27d3bd607cb96 Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Tue, 5 Apr 2016 09:18:08 -0700 Subject: [PATCH 017/135] Correctly handle frobenius_matrix() for an even degree polynomial --- .../hyperelliptic_curves/hyperelliptic_finite_field.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 169461e0d1d..50b38aec229 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -522,6 +522,11 @@ def frobenius_polynomial(self): sage: H.frobenius_polynomial() x^4 + 2*x^3 - 58*x^2 + 202*x + 10201 + Over prime fields of odd characteristic, `f` may have even degree:: + sage: H = HyperellipticCurve(t^6 + 27*t + 3) + sage: H.frobenius_polynomial() + x^4 + 25*x^3 + 322*x^2 + 2525*x + 10201 + In even characteristic, the naive algorithm could cover all cases because we can easily check for squareness in quotient rings of polynomial rings over finite fields but these rings unfortunately @@ -540,7 +545,7 @@ def frobenius_polynomial(self): g = self.genus() f, h = self.hyperelliptic_polynomials() - if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h==0: + if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h==0 and f.degree() %2 == 1: return self.frobenius_polynomial_matrix() elif q%2 == 1: return self.frobenius_polynomial_pari() From 2690f0d5df6ad0d067fa4e2927ede75423d1569a Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Fri, 8 Apr 2016 16:48:21 -0700 Subject: [PATCH 018/135] Fix count_points for even-degree hyperelliptics --- .../schemes/hyperelliptic_curves/hyperelliptic_finite_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 50b38aec229..8a193f86371 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -1136,7 +1136,7 @@ def count_points(self, n=1): g = self.genus() f, h = self.hyperelliptic_polynomials() - if e == 1 and h == 0: + if e == 1 and h == 0 and f.degree() % 2 == 1: N1 = self._frobenius_coefficient_bound_traces(n) N2 = self._frobenius_coefficient_bound_charpoly() if n < g and q > (2*g+1)*(2*N1-1): From c2bd95d68843b5eeb1b82e6df5645bb4628e7096 Mon Sep 17 00:00:00 2001 From: "Kiran S. Kedlaya" Date: Sat, 9 Apr 2016 08:04:24 -0700 Subject: [PATCH 019/135] Add doctest regarding #20391 --- .../hyperelliptic_curves/hyperelliptic_finite_field.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 8a193f86371..cf4d6e3e56c 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -1129,6 +1129,12 @@ def count_points(self, n=1): sage: H = HyperellipticCurve(x^5+a*x^2+1, x+a+1) sage: H.count_points(6) [2, 24, 74, 256, 1082, 4272] + + This example shows that ticket #20391 is resolved: + sage: x = polygen(GF(4099)) + sage: H = HyperellipticCurve(x^6 + x + 1) + sage: H.count_points(1) + [4106] """ K = self.base_ring() q = K.cardinality() From 1f90f95e7c12901dba8078c84a588d9b3cd231a7 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Tue, 10 May 2016 10:25:27 +0200 Subject: [PATCH 020/135] Upgrade PARI to latest master --- build/pkgs/pari/checksums.ini | 6 +- build/pkgs/pari/package-version.txt | 2 +- src/sage/libs/pari/paridecl.pxd | 912 ++++++++++-------- src/sage/libs/pari/parisage.h | 1 + src/sage/libs/pari/tests.py | 4 +- src/sage/libs/pari/types.pxd | 1 + .../rings/number_field/number_field_ideal.py | 5 +- .../rings/number_field/number_field_rel.py | 6 +- src/sage_setup/autogen/pari/doc.py | 1 + 9 files changed, 516 insertions(+), 422 deletions(-) diff --git a/build/pkgs/pari/checksums.ini b/build/pkgs/pari/checksums.ini index 39db207d6d2..76088f82c6c 100644 --- a/build/pkgs/pari/checksums.ini +++ b/build/pkgs/pari/checksums.ini @@ -1,4 +1,4 @@ tarball=pari-VERSION.tar.gz -sha1=0f8221f5052610c1e6826852ab29ecb1e1cddeec -md5=03b83e4af898f456cae16c9ade1e1cb5 -cksum=3725243671 +sha1=fbb6008e6075a5848c9f91d5f4130ec4c643e38e +md5=30ca69d8f61540845b90b9275a9c44ef +cksum=3562914164 diff --git a/build/pkgs/pari/package-version.txt b/build/pkgs/pari/package-version.txt index bd07947c430..deea6cfe1d2 100644 --- a/build/pkgs/pari/package-version.txt +++ b/build/pkgs/pari/package-version.txt @@ -1 +1 @@ -2.8-2341-g61b65cc.p0 +2.8-2670-g9b4a64c.p0 diff --git a/src/sage/libs/pari/paridecl.pxd b/src/sage/libs/pari/paridecl.pxd index eae6ee2a5fd..a5c24470d5d 100644 --- a/src/sage/libs/pari/paridecl.pxd +++ b/src/sage/libs/pari/paridecl.pxd @@ -22,6 +22,7 @@ AUTHORS: - Jeroen Demeyer (2014-09-19): upgrade to PARI 2.8 (#16997) """ +from __future__ import print_function from .types cimport * from libc.stdio cimport FILE @@ -119,7 +120,6 @@ cdef extern from "sage/libs/pari/parisage.h": # F2x.c - GEN F2c_to_Flc(GEN x) GEN F2c_to_ZC(GEN x) GEN F2c_to_mod(GEN x) GEN F2m_rowslice(GEN x, long a, long b) @@ -129,8 +129,10 @@ cdef extern from "sage/libs/pari/parisage.h": void F2v_add_inplace(GEN x, GEN y) ulong F2v_dotproduct(GEN x, GEN y) GEN F2v_slice(GEN x, long a, long b) + GEN F2v_to_Flv(GEN x) GEN F2x_F2xq_eval(GEN Q, GEN x, GEN T) GEN F2x_F2xqV_eval(GEN P, GEN V, GEN T) + GEN F2x_Frobenius(GEN T) GEN F2x_1_add(GEN y) GEN F2x_add(GEN x, GEN y) GEN F2x_deflate(GEN x0, long d) @@ -143,6 +145,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN F2x_gcd(GEN a, GEN b) GEN F2x_halfgcd(GEN a, GEN b) int F2x_issquare(GEN a) + GEN F2x_matFrobenius(GEN T) GEN F2x_mul(GEN x, GEN y) GEN F2x_rem(GEN x, GEN y) GEN F2x_shift(GEN y, long d) @@ -152,10 +155,19 @@ cdef extern from "sage/libs/pari/parisage.h": GEN F2x_to_Flx(GEN x) GEN F2x_to_ZX(GEN x) long F2x_valrem(GEN x, GEN *Z) + GEN F2xC_to_FlxC(GEN v) GEN F2xC_to_ZXC(GEN x) GEN F2xV_to_F2m(GEN v, long n) + GEN F2xX_F2x_mul(GEN P, GEN U) + GEN F2xX_add(GEN x, GEN y) + GEN F2xX_deriv(GEN z) + GEN F2xX_renormalize(GEN x, long lx) + GEN F2xX_to_Kronecker(GEN P, long d) + GEN F2xX_to_ZXX(GEN B) + GEN F2xY_F2xq_evalx(GEN P, GEN x, GEN T) + GEN F2xY_F2xqV_evalx(GEN P, GEN x, GEN T) + long F2xY_degreex(GEN b) GEN F2xq_Artin_Schreier(GEN a, GEN T) - GEN FlxqXQV_autsum(GEN aut, long n, GEN S, GEN T, ulong p) GEN F2xq_autpow(GEN x, long n, GEN T) GEN F2xq_conjvec(GEN x, GEN T) GEN F2xq_div(GEN x, GEN y, GEN T) @@ -173,9 +185,29 @@ cdef extern from "sage/libs/pari/parisage.h": GEN F2xq_sqrt_fast(GEN c, GEN sqx, GEN T) GEN F2xq_sqrtn(GEN a, GEN n, GEN T, GEN *zeta) ulong F2xq_trace(GEN x, GEN T) + GEN F2xqX_F2xq_mul(GEN P, GEN U, GEN T) + GEN F2xqX_F2xq_mul_to_monic(GEN P, GEN U, GEN T) + GEN F2xqX_F2xqXQ_eval(GEN Q, GEN x, GEN S, GEN T) + GEN F2xqX_F2xqXQV_eval(GEN P, GEN V, GEN S, GEN T) + GEN F2xqX_divrem(GEN x, GEN y, GEN T, GEN *pr) + GEN F2xqX_gcd(GEN a, GEN b, GEN T) + GEN F2xqX_mul(GEN x, GEN y, GEN T) + GEN F2xqX_normalize(GEN z, GEN T) + GEN F2xqX_red(GEN z, GEN T) + GEN F2xqX_rem(GEN x, GEN S, GEN T) + GEN F2xqX_sqr(GEN x, GEN T) + GEN F2xqXQ_mul(GEN x, GEN y, GEN S, GEN T) + GEN F2xqXQ_sqr(GEN x, GEN S, GEN T) + GEN F2xqXQ_pow(GEN x, GEN n, GEN S, GEN T) + GEN F2xqXQ_powers(GEN x, long l, GEN S, GEN T) + GEN F2xqXQV_autpow(GEN aut, long n, GEN S, GEN T) + GEN F2xqXQV_auttrace(GEN aut, long n, GEN S, GEN T) GEN Flm_to_F2m(GEN x) GEN Flv_to_F2v(GEN x) GEN Flx_to_F2x(GEN x) + GEN FlxC_to_F2xC(GEN x) + GEN FlxX_to_F2xX(GEN B) + GEN Kronecker_to_F2xqX(GEN z, GEN T) GEN Rg_to_F2xq(GEN x, GEN T) GEN RgM_to_F2m(GEN x) GEN RgV_to_F2v(GEN x) @@ -185,9 +217,14 @@ cdef extern from "sage/libs/pari/parisage.h": GEN ZV_to_F2v(GEN x) GEN ZX_to_F2x(GEN x) GEN ZXX_to_F2xX(GEN B, long v) + GEN const_F2v(long m) GEN gener_F2xq(GEN T, GEN *po) - bb_field *get_F2xq_field(void **E, GEN T) + const bb_field *get_F2xq_field(void **E, GEN T) + GEN monomial_F2x(long d, long vs) + GEN pol1_F2xX(long v, long sv) + GEN polx_F2xX(long v, long sv) GEN random_F2x(long d, long vs) + GEN random_F2xqX(long d1, long v, GEN T) # F2xqE.c @@ -206,7 +243,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN F2xqE_sub(GEN P, GEN Q, GEN a2, GEN T) GEN F2xqE_tatepairing(GEN t, GEN s, GEN m, GEN a2, GEN T) GEN F2xqE_weilpairing(GEN t, GEN s, GEN m, GEN a2, GEN T) - bb_group * get_F2xqE_group(void **E, GEN a2, GEN a6, GEN T) + const bb_group * get_F2xqE_group(void **E, GEN a2, GEN a6, GEN T) GEN RgE_to_F2xqE(GEN x, GEN T) GEN random_F2xqE(GEN a2, GEN a6, GEN T) @@ -251,7 +288,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN Flm_to_FlxV(GEN x, long sv) GEN Flm_to_FlxX(GEN x, long v, long w) GEN Flm_to_ZM(GEN z) - GEN Flv_FlvV_polint(GEN xa, GEN ya, ulong p, long vs) + GEN Flv_Flm_polint(GEN xa, GEN ya, ulong p, long vs) GEN Flv_inv(GEN x, ulong p) void Flv_inv_inplace(GEN x, ulong p) void Flv_inv_pre_inplace(GEN x, ulong p, ulong pi) @@ -286,6 +323,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN Flx_gcd(GEN a, GEN b, ulong p) GEN Flx_get_red(GEN T, ulong p) GEN Flx_halfgcd(GEN a, GEN b, ulong p) + GEN Flx_halve(GEN y, ulong p) GEN Flx_inflate(GEN x0, long d) GEN Flx_invBarrett(GEN T, ulong p) int Flx_is_squarefree(GEN z, ulong p) @@ -328,6 +366,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FlxX_Flx_add(GEN y, GEN x, ulong p) GEN FlxX_Flx_mul(GEN x, GEN y, ulong p) GEN FlxX_add(GEN P, GEN Q, ulong p) + GEN FlxX_deriv(GEN z, ulong p) GEN FlxX_double(GEN x, ulong p) GEN FlxX_neg(GEN x, ulong p) GEN FlxX_sub(GEN P, GEN Q, ulong p) @@ -338,6 +377,8 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FlxX_to_FlxC(GEN x, long N, long sv) GEN FlxX_to_ZXX(GEN B) GEN FlxX_triple(GEN x, ulong p) + GEN FlxXC_to_ZXXC(GEN B) + GEN FlxXM_to_ZXXM(GEN B) GEN FlxXV_to_FlxM(GEN v, long n, long sv) GEN FlxY_Flx_div(GEN x, GEN y, ulong p) GEN FlxY_Flx_translate(GEN P, GEN c, ulong p) @@ -382,6 +423,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FlxqX_extgcd(GEN a, GEN b, GEN T, ulong p, GEN *ptu, GEN *ptv) GEN FlxqX_gcd(GEN P, GEN Q, GEN T, ulong p) GEN FlxqX_get_red(GEN S, GEN T, ulong p) + GEN FlxqX_halfgcd(GEN x, GEN y, GEN T, ulong p) GEN FlxqX_invBarrett(GEN T, GEN Q, ulong p) GEN FlxqX_mul(GEN x, GEN y, GEN T, ulong p) GEN FlxqX_normalize(GEN z, GEN T, ulong p) @@ -396,16 +438,18 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FlxqXQ_matrix_pow(GEN x, long n, long m, GEN S, GEN T, ulong p) GEN FlxqXQ_mul(GEN x, GEN y, GEN S, GEN T, ulong p) GEN FlxqXQ_pow(GEN x, GEN n, GEN S, GEN T, ulong p) + GEN FlxqXQ_powu(GEN x, ulong n, GEN S, GEN T, ulong p) GEN FlxqXQ_powers(GEN x, long n, GEN S, GEN T, ulong p) GEN FlxqXQ_sqr(GEN x, GEN S, GEN T, ulong p) GEN FlxqXQV_autpow(GEN x, long n, GEN S, GEN T, ulong p) + GEN FlxqXQV_autsum(GEN aut, long n, GEN S, GEN T, ulong p) GEN FlxqXV_prod(GEN V, GEN T, ulong p) GEN Kronecker_to_FlxqX(GEN z, GEN T, ulong p) ulong Rg_to_F2(GEN x) ulong Rg_to_Fl(GEN x, ulong p) GEN Rg_to_Flxq(GEN x, GEN T, ulong p) GEN RgX_to_Flx(GEN x, ulong p) - GEN Z_to_Flx(GEN x, ulong p, long v) + GEN Z_to_Flx(GEN x, ulong p, long sv) GEN ZX_to_Flx(GEN x, ulong p) GEN ZXV_to_FlxV(GEN v, ulong p) GEN ZXT_to_FlxT(GEN z, ulong p) @@ -419,8 +463,8 @@ cdef extern from "sage/libs/pari/parisage.h": long get_FlxqX_degree(GEN T) GEN get_FlxqX_mod(GEN T) long get_FlxqX_var(GEN T) - bb_field *get_Flxq_field(void **E, GEN T, ulong p) - bb_group *get_Flxq_star(void **E, GEN T, ulong p) + const bb_field *get_Flxq_field(void **E, GEN T, ulong p) + const bb_group *get_Flxq_star(void **E, GEN T, ulong p) GEN monomial_Flx(ulong a, long d, long vs) GEN pol1_FlxX(long v, long sv) GEN polx_FlxX(long v, long sv) @@ -449,7 +493,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FlxqE_sub(GEN P, GEN Q, GEN a4, GEN T, ulong p) GEN FlxqE_tatepairing(GEN t, GEN s, GEN m, GEN a4, GEN T, ulong p) GEN FlxqE_weilpairing(GEN t, GEN s, GEN m, GEN a4, GEN T, ulong p) - bb_group * get_FlxqE_group(void **E, GEN a4, GEN a6, GEN T, ulong p) + const bb_group * get_FlxqE_group(void **E, GEN a4, GEN a6, GEN T, ulong p) GEN RgE_to_FlxqE(GEN x, GEN T, ulong p) GEN random_FlxqE(GEN a4, GEN a6, GEN T, ulong p) @@ -498,8 +542,8 @@ cdef extern from "sage/libs/pari/parisage.h": GEN Fq_elldivpolmod(GEN a4, GEN a6, long n, GEN h, GEN T, GEN p) GEN RgE_to_FpE(GEN x, GEN p) GEN RgE_to_FpXQE(GEN x, GEN T, GEN p) - bb_group * get_FpE_group(void **E, GEN a4, GEN a6, GEN p) - bb_group * get_FpXQE_group(void **E, GEN a4, GEN a6, GEN T, GEN p) + const bb_group * get_FpE_group(void **E, GEN a4, GEN a6, GEN p) + const bb_group * get_FpXQE_group(void **E, GEN a4, GEN a6, GEN T, GEN p) GEN elltrace_extension(GEN t, long n, GEN p) GEN random_FpE(GEN a4, GEN a6, GEN p) GEN random_FpXQE(GEN a4, GEN a6, GEN T, GEN p) @@ -509,7 +553,10 @@ cdef extern from "sage/libs/pari/parisage.h": int Fp_issquare(GEN x, GEN p) GEN Fp_FpX_sub(GEN x, GEN y, GEN p) GEN Fp_FpXQ_log(GEN a, GEN g, GEN ord, GEN T, GEN p) + GEN FpV_FpM_polint(GEN xa, GEN ya, GEN p, long vs) GEN FpV_inv(GEN x, GEN p) + GEN FpV_invVandermonde(GEN L, GEN den, GEN p) + GEN FpV_polint(GEN xa, GEN ya, GEN p, long v) GEN FpV_roots_to_pol(GEN V, GEN p, long v) GEN FpX_Fp_add(GEN x, GEN y, GEN p) GEN FpX_Fp_add_shallow(GEN y, GEN x, GEN p) @@ -518,6 +565,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FpX_Fp_mulspec(GEN y, GEN x, GEN p, long ly) GEN FpX_Fp_sub(GEN x, GEN y, GEN p) GEN FpX_Fp_sub_shallow(GEN y, GEN x, GEN p) + GEN FpX_FpV_multieval(GEN P, GEN xa, GEN p) GEN FpX_FpXQ_eval(GEN f, GEN x, GEN T, GEN p) GEN FpX_FpXQV_eval(GEN f, GEN x, GEN T, GEN p) GEN FpX_Frobenius(GEN T, GEN p) @@ -585,7 +633,11 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FpXV_prod(GEN V, GEN p) GEN FpXV_red(GEN z, GEN p) int Fq_issquare(GEN x, GEN T, GEN p) + long Fq_ispower(GEN x, GEN K, GEN T, GEN p) GEN Fq_log(GEN a, GEN g, GEN ord, GEN T, GEN p) + GEN Fq_sqrtn(GEN a, GEN n, GEN T, GEN p, GEN *z) + GEN Fq_sqrt(GEN a, GEN T, GEN p) + long FqX_ispower(GEN f, ulong k, GEN T, GEN p, GEN *pt) GEN FqV_inv(GEN x, GEN T, GEN p) GEN Z_to_FpX(GEN a, GEN p, long v) GEN gener_FpXQ(GEN T, GEN p, GEN *o) @@ -593,7 +645,7 @@ cdef extern from "sage/libs/pari/parisage.h": long get_FpX_degree(GEN T) GEN get_FpX_mod(GEN T) long get_FpX_var(GEN T) - bb_group *get_FpXQ_star(void **E, GEN T, GEN p) + const bb_group *get_FpXQ_star(void **E, GEN T, GEN p) GEN random_FpX(long d, long v, GEN p) # FpX_factor.c @@ -602,6 +654,7 @@ cdef extern from "sage/libs/pari/parisage.h": int F2x_is_irred(GEN f) void F2xV_to_FlxV_inplace(GEN v) void F2xV_to_ZXV_inplace(GEN v) + GEN F2xqX_roots(GEN x, GEN T) int Flx_is_irred(GEN f, ulong p) GEN Flx_degfact(GEN f, ulong p) GEN Flx_factor(GEN f, ulong p) @@ -612,8 +665,10 @@ cdef extern from "sage/libs/pari/parisage.h": ulong Flx_oneroot(GEN f, ulong p) ulong Flx_oneroot_split(GEN f, ulong p) GEN Flx_roots(GEN f, ulong p) + GEN Flx_rootsff(GEN P, GEN T, ulong p) GEN FlxqX_Frobenius(GEN S, GEN T, ulong p) GEN FlxqXQ_halfFrobenius(GEN a, GEN S, GEN T, ulong p) + GEN FlxqX_roots(GEN S, GEN T, ulong p) long FlxqX_nbroots(GEN f, GEN T, ulong p) void FlxV_to_ZXV_inplace(GEN v) GEN FpX_degfact(GEN f, GEN p) @@ -629,15 +684,14 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FpX_rootsff(GEN P, GEN T, GEN p) GEN FpX_split_part(GEN f, GEN p) GEN FpXQX_Frobenius(GEN S, GEN T, GEN p) + GEN FpXQX_factor(GEN x, GEN T, GEN p) long FpXQX_nbfact(GEN u, GEN T, GEN p) long FpXQX_nbroots(GEN f, GEN T, GEN p) + GEN FpXQX_roots(GEN f, GEN T, GEN p) GEN FpXQXQ_halfFrobenius(GEN a, GEN S, GEN T, GEN p) - GEN FqX_deriv(GEN f, GEN T, GEN p) - GEN FqX_factor(GEN x, GEN T, GEN p) long FqX_is_squarefree(GEN P, GEN T, GEN p) long FqX_nbfact(GEN u, GEN T, GEN p) long FqX_nbroots(GEN f, GEN T, GEN p) - GEN FqX_roots(GEN f, GEN T, GEN p) GEN factcantor(GEN x, GEN p) GEN factorff(GEN f, GEN p, GEN a) GEN factormod0(GEN f, GEN p, long flag) @@ -656,6 +710,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FpXQX_fromdigits(GEN x, GEN B, GEN T, GEN p) GEN FpXQX_gcd(GEN P, GEN Q, GEN T, GEN p) GEN FpXQX_get_red(GEN S, GEN T, GEN p) + GEN FpXQX_halfgcd(GEN x, GEN y, GEN T, GEN p) GEN FpXQX_invBarrett(GEN S, GEN T, GEN p) GEN FpXQX_mul(GEN x, GEN y, GEN T, GEN p) GEN FpXQX_powu(GEN x, ulong n, GEN T, GEN p) @@ -672,10 +727,12 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FpXQXQ_sqr(GEN x, GEN S, GEN T, GEN p) GEN FpXQXQV_autpow(GEN aut, long n, GEN S, GEN T, GEN p) GEN FpXQXQV_autsum(GEN aut, long n, GEN S, GEN T, GEN p) + GEN FpXQXQV_auttrace(GEN aut, long n, GEN S, GEN T, GEN p) GEN FpXQXV_prod(GEN V, GEN Tp, GEN p) GEN FpXX_Fp_mul(GEN x, GEN y, GEN p) GEN FpXX_FpX_mul(GEN x, GEN y, GEN p) GEN FpXX_add(GEN x, GEN y, GEN p) + GEN FpXX_deriv(GEN P, GEN p) GEN FpXX_mulu(GEN P, ulong u, GEN p) GEN FpXX_neg(GEN x, GEN p) GEN FpXX_red(GEN z, GEN p) @@ -700,11 +757,6 @@ cdef extern from "sage/libs/pari/parisage.h": GEN F2m_F2c_mul(GEN x, GEN y) GEN F2m_mul(GEN x, GEN y) GEN F2m_powu(GEN x, ulong n) - GEN Flc_Fl_div(GEN x, ulong y, ulong p) - void Flc_Fl_div_inplace(GEN x, ulong y, ulong p) - GEN Flc_Fl_mul(GEN x, ulong y, ulong p) - void Flc_Fl_mul_inplace(GEN x, ulong y, ulong p) - void Flc_Fl_mul_part_inplace(GEN x, ulong y, ulong p, long l) GEN Flc_to_mod(GEN z, ulong pp) GEN Flm_Fl_add(GEN x, ulong y, ulong p) GEN Flm_Fl_mul(GEN y, ulong x, ulong p) @@ -719,11 +771,16 @@ cdef extern from "sage/libs/pari/parisage.h": GEN Flm_sub(GEN x, GEN y, ulong p) GEN Flm_to_mod(GEN z, ulong pp) GEN Flm_transpose(GEN x) + GEN Flv_Fl_div(GEN x, ulong y, ulong p) + void Flv_Fl_div_inplace(GEN x, ulong y, ulong p) + GEN Flv_Fl_mul(GEN x, ulong y, ulong p) + void Flv_Fl_mul_inplace(GEN x, ulong y, ulong p) + void Flv_Fl_mul_part_inplace(GEN x, ulong y, ulong p, long l) GEN Flv_add(GEN x, GEN y, ulong p) void Flv_add_inplace(GEN x, GEN y, ulong p) + GEN Flv_center(GEN z, ulong p, ulong ps2) ulong Flv_dotproduct(GEN x, GEN y, ulong p) ulong Flv_dotproduct_pre(GEN x, GEN y, ulong p, ulong pi) - GEN Flv_center(GEN z, ulong p, ulong ps2) GEN Flv_neg(GEN v, ulong p) void Flv_neg_inplace(GEN v, ulong p) GEN Flv_sub(GEN x, GEN y, ulong p) @@ -767,7 +824,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN ZpMs_ZpCs_solve(GEN M, GEN B, long nbrow, GEN p, long e) GEN gen_FpM_Wiedemann(void *E, GEN (*f)(void*, GEN), GEN B, GEN p) GEN gen_ZpM_Dixon(void *E, GEN (*f)(void*, GEN), GEN B, GEN p, long e) - GEN gen_matid(long n, void *E, bb_field *S) + GEN gen_matid(long n, void *E, const bb_field *S) GEN matid_F2m(long n) GEN matid_Flm(long n) GEN matid_F2xqM(long n, GEN T) @@ -780,6 +837,7 @@ cdef extern from "sage/libs/pari/parisage.h": # Hensel.c + GEN Z2_sqrt(GEN x, long e) GEN Zp_sqrt(GEN x, GEN p, long e) GEN Zp_sqrtlift(GEN b, GEN a, GEN p, long e) GEN Zp_sqrtnlift(GEN b, GEN n, GEN a, GEN p, long e) @@ -980,6 +1038,8 @@ cdef extern from "sage/libs/pari/parisage.h": GEN RgXn_reverse(GEN f, long e) GEN RgXn_sqr(GEN f, long n) GEN RgXnV_red_shallow(GEN P, long n) + GEN RgXn_powu(GEN x, ulong m, long n) + GEN RgXn_powu_i(GEN x, ulong m, long n) GEN ZX_translate(GEN P, GEN c) GEN ZX_unscale2n(GEN P, long n) GEN ZX_unscale(GEN P, GEN h) @@ -987,12 +1047,17 @@ cdef extern from "sage/libs/pari/parisage.h": int ZXQX_dvd(GEN x, GEN y, GEN T) long brent_kung_optpow(long d, long n, long m) GEN gen_bkeval(GEN Q, long d, GEN x, int use_sqr, void *E, - bb_algebra *ff, GEN cmul(void *E, GEN P, long a, GEN x)) + const bb_algebra *ff, GEN cmul(void *E, GEN P, long a, GEN x)) GEN gen_bkeval_powers(GEN P, long d, GEN V, void *E, - bb_algebra *ff, GEN cmul(void *E, GEN P, long a, GEN x)) - bb_algebra * get_Rg_algebra() + const bb_algebra *ff, GEN cmul(void *E, GEN P, long a, GEN x)) + const bb_algebra * get_Rg_algebra() # ZG.c + void ZGC_G_mul_inplace(GEN v, GEN x) + void ZGC_add_inplace(GEN x, GEN y) + GEN ZGC_add_sparse(GEN x, GEN y) + void ZGM_add_inplace(GEN x, GEN y) + GEN ZGM_add_sparse(GEN x, GEN y) GEN G_ZGC_mul(GEN x, GEN v) GEN G_ZG_mul(GEN x, GEN y) GEN ZGC_G_mul(GEN v, GEN x) @@ -1008,8 +1073,8 @@ cdef extern from "sage/libs/pari/parisage.h": # ZV.c void Flc_lincomb1_inplace(GEN X, GEN Y, ulong v, ulong q) - void RgM_check_ZM(GEN A, char *s) - void RgV_check_ZV(GEN A, char *s) + void RgM_check_ZM(GEN A, const char *s) + void RgV_check_ZV(GEN A, const char *s) GEN ZV_zc_mul(GEN x, GEN y) GEN ZC_ZV_mul(GEN x, GEN y) GEN ZC_Z_add(GEN x, GEN y) @@ -1100,9 +1165,9 @@ cdef extern from "sage/libs/pari/parisage.h": # ZX.c - void RgX_check_QX(GEN x, char *s) - void RgX_check_ZX(GEN x, char *s) - void RgX_check_ZXX(GEN x, char *s) + void RgX_check_QX(GEN x, const char *s) + void RgX_check_ZX(GEN x, const char *s) + void RgX_check_ZXX(GEN x, const char *s) GEN Z_ZX_sub(GEN x, GEN y) GEN ZX_Z_add(GEN y, GEN x) GEN ZX_Z_add_shallow(GEN y, GEN x) @@ -1150,111 +1215,112 @@ cdef extern from "sage/libs/pari/parisage.h": # algebras.c - GEN alg_centralproj(GEN al, GEN z, int maps) - GEN alg_change_overorder_shallow(GEN al, GEN ord) - GEN alg_complete(GEN rnf, GEN aut, GEN hi, GEN hf, long maxord) - GEN alg_csa_table(GEN nf, GEN mt, long v, long maxord) - GEN alg_cyclic(GEN rnf, GEN aut, GEN b, long maxord) - GEN alg_decomposition(GEN al) - long alg_get_absdim(GEN al) - long algabsdim(GEN al) - GEN alg_get_abssplitting(GEN al) - GEN alg_get_aut(GEN al) - GEN algaut(GEN al) - GEN alg_get_auts(GEN al) - GEN alg_get_b(GEN al) - GEN algb(GEN al) - GEN algcenter(GEN al) - GEN alg_get_center(GEN al) - GEN alg_get_char(GEN al) - GEN algchar(GEN al) - long alg_get_degree(GEN al) - long algdegree(GEN al) - long alg_get_dim(GEN al) - long algdim(GEN al) - GEN alg_get_hasse_f(GEN al) - GEN alghassef(GEN al) - GEN alg_get_hasse_i(GEN al) - GEN alghassei(GEN al) - GEN alg_get_invbasis(GEN al) - GEN alginvbasis(GEN al) - GEN alg_get_multable(GEN al) - GEN alg_get_basis(GEN al) - GEN algbasis(GEN al) - GEN alg_get_relmultable(GEN al) - GEN algrelmultable(GEN al) - GEN alg_get_splitpol(GEN al) - GEN alg_get_splittingfield(GEN al) - GEN algsplittingfield(GEN al) - GEN alg_get_splittingbasis(GEN al) - GEN alg_get_splittingbasisinv(GEN al) - GEN alg_get_splittingdata(GEN al) - GEN algsplittingdata(GEN al) - GEN alg_get_tracebasis(GEN al) - GEN alg_hasse(GEN nf, long n, GEN hi, GEN hf, long var, long flag) - GEN alg_hilbert(GEN nf, GEN a, GEN b, long v, long flag) - GEN alg_matrix(GEN nf, long n, long v, GEN L, long flag) - long alg_model(GEN al, GEN x) - GEN alg_ordermodp(GEN al, GEN p) - GEN alg_quotient(GEN al, GEN I, int maps) - GEN algradical(GEN al) - GEN algsimpledec(GEN al, int maps) - GEN algsubalg(GEN al, GEN basis) - long alg_type(GEN al) - GEN algadd(GEN al, GEN x, GEN y) - GEN algalgtobasis(GEN al, GEN x) - GEN algbasischarpoly(GEN al, GEN x, long v) - GEN algbasismul(GEN al, GEN x, GEN y) - GEN algbasismultable(GEN al, GEN x) - GEN algbasismultable_Flm(GEN mt, GEN x, ulong m) - GEN algbasistoalg(GEN al, GEN x) - GEN algcharpoly(GEN al, GEN x, long v) - GEN algdisc(GEN al) - GEN algdivl(GEN al, GEN x, GEN y) - GEN algdivr(GEN al, GEN x, GEN y) - GEN alghasse(GEN al, GEN pl) - GEN alginit(GEN A, GEN B, long v, long flag) - long algindex(GEN al, GEN pl) - GEN alginv(GEN al, GEN x) - int algisassociative(GEN mt0, GEN p) - int algiscommutative(GEN al) - int algisdivision(GEN al, GEN pl) - int algisramified(GEN al, GEN pl) - int algissemisimple(GEN al) - int algissimple(GEN al, long ss) - int algissplit(GEN al, GEN pl) - int algisdivl(GEN al, GEN x, GEN y, GEN* ptz) - int algisinv(GEN al, GEN x, GEN* ptix) - GEN algleftordermodp(GEN al, GEN Ip, GEN p) - GEN algmul(GEN al, GEN x, GEN y) - GEN algmultable(GEN al) - GEN alglathnf(GEN al, GEN m) - GEN algleftmultable(GEN al, GEN x) - GEN algneg(GEN al, GEN x) - GEN algnorm(GEN al, GEN x) - GEN algpoleval(GEN al, GEN pol, GEN x) - GEN algpow(GEN al, GEN x, GEN n) - GEN algprimesubalg(GEN al) - GEN algramifiedplaces(GEN al) - GEN algrandom(GEN al, GEN b) - GEN algsplittingmatrix(GEN al, GEN x) - GEN algsqr(GEN al, GEN x) - GEN algsub(GEN al, GEN x, GEN y) - GEN algtableinit(GEN mt, GEN p) - GEN algtensor(GEN al1, GEN al2, long maxord) - GEN algtrace(GEN al, GEN x) - long algtype(GEN al) - GEN bnfgwgeneric(GEN bnf, GEN Lpr, GEN Ld, GEN pl, long var) - GEN bnrgwsearch(GEN bnr, GEN Lpr, GEN Ld, GEN pl) - void checkalg(GEN x) - void checkhasse(GEN nf, GEN hi, GEN hf, long n) - long cyclicrelfrob(GEN rnf, GEN nf2, GEN auts, GEN pr) - GEN hassecoprime(GEN hi, GEN hf, long n) - GEN hassedown(GEN nf, long n, GEN hi, GEN hf) - GEN hassewedderburn(GEN hi, GEN hf, long n) - long localhasse(GEN rnf, GEN nf2, GEN cnd, GEN pl, GEN auts, GEN b, long k) - GEN nfgrunwaldwang(GEN nf0, GEN Lpr, GEN Ld, GEN pl, long var) - GEN nfgwkummer(GEN nf, GEN Lpr, GEN Ld, GEN pl, long var) + GEN alg_centralproj(GEN al, GEN z, int maps) + GEN alg_change_overorder_shallow(GEN al, GEN ord) + GEN alg_complete(GEN rnf, GEN aut, GEN hi, GEN hf, long maxord) + GEN alg_csa_table(GEN nf, GEN mt, long v, long maxord) + GEN alg_cyclic(GEN rnf, GEN aut, GEN b, long maxord) + GEN alg_decomposition(GEN al) + long alg_get_absdim(GEN al) + long algabsdim(GEN al) + GEN alg_get_abssplitting(GEN al) + GEN alg_get_aut(GEN al) + GEN algaut(GEN al) + GEN alg_get_auts(GEN al) + GEN alg_get_b(GEN al) + GEN algb(GEN al) + GEN algcenter(GEN al) + GEN alg_get_center(GEN al) + GEN alg_get_char(GEN al) + GEN algchar(GEN al) + long alg_get_degree(GEN al) + long algdegree(GEN al) + long alg_get_dim(GEN al) + long algdim(GEN al) + GEN alg_get_hasse_f(GEN al) + GEN alghassef(GEN al) + GEN alg_get_hasse_i(GEN al) + GEN alghassei(GEN al) + GEN alg_get_invbasis(GEN al) + GEN alginvbasis(GEN al) + GEN alg_get_multable(GEN al) + GEN alg_get_basis(GEN al) + GEN algbasis(GEN al) + GEN alg_get_relmultable(GEN al) + GEN algrelmultable(GEN al) + GEN alg_get_splitpol(GEN al) + GEN alg_get_splittingfield(GEN al) + GEN algsplittingfield(GEN al) + GEN alg_get_splittingbasis(GEN al) + GEN alg_get_splittingbasisinv(GEN al) + GEN alg_get_splittingdata(GEN al) + GEN algsplittingdata(GEN al) + GEN alg_get_tracebasis(GEN al) + GEN alg_hasse(GEN nf, long n, GEN hi, GEN hf, long var, long flag) + GEN alg_hilbert(GEN nf, GEN a, GEN b, long v, long flag) + GEN alg_matrix(GEN nf, long n, long v, GEN L, long flag) + long alg_model(GEN al, GEN x) + GEN alg_ordermodp(GEN al, GEN p) + GEN alg_quotient(GEN al, GEN I, int maps) + GEN algradical(GEN al) + GEN algsimpledec(GEN al, int maps) + GEN algsubalg(GEN al, GEN basis) + long alg_type(GEN al) + GEN algadd(GEN al, GEN x, GEN y) + GEN algalgtobasis(GEN al, GEN x) + GEN algbasischarpoly(GEN al, GEN x, long v) + GEN algbasismul(GEN al, GEN x, GEN y) + GEN algbasismultable(GEN al, GEN x) + GEN algbasismultable_Flm(GEN mt, GEN x, ulong m) + GEN algbasistoalg(GEN al, GEN x) + GEN algcharpoly(GEN al, GEN x, long v) + GEN algdisc(GEN al) + GEN algdivl(GEN al, GEN x, GEN y) + GEN algdivr(GEN al, GEN x, GEN y) + GEN alggroup(GEN gal, GEN p) + GEN alghasse(GEN al, GEN pl) + GEN alginit(GEN A, GEN B, long v, long flag) + long algindex(GEN al, GEN pl) + GEN alginv(GEN al, GEN x) + int algisassociative(GEN mt0, GEN p) + int algiscommutative(GEN al) + int algisdivision(GEN al, GEN pl) + int algisramified(GEN al, GEN pl) + int algissemisimple(GEN al) + int algissimple(GEN al, long ss) + int algissplit(GEN al, GEN pl) + int algisdivl(GEN al, GEN x, GEN y, GEN* ptz) + int algisinv(GEN al, GEN x, GEN* ptix) + GEN algleftordermodp(GEN al, GEN Ip, GEN p) + GEN algmul(GEN al, GEN x, GEN y) + GEN algmultable(GEN al) + GEN alglathnf(GEN al, GEN m) + GEN algleftmultable(GEN al, GEN x) + GEN algneg(GEN al, GEN x) + GEN algnorm(GEN al, GEN x) + GEN algpoleval(GEN al, GEN pol, GEN x) + GEN algpow(GEN al, GEN x, GEN n) + GEN algprimesubalg(GEN al) + GEN algramifiedplaces(GEN al) + GEN algrandom(GEN al, GEN b) + GEN algsplittingmatrix(GEN al, GEN x) + GEN algsqr(GEN al, GEN x) + GEN algsub(GEN al, GEN x, GEN y) + GEN algtableinit(GEN mt, GEN p) + GEN algtensor(GEN al1, GEN al2, long maxord) + GEN algtrace(GEN al, GEN x) + long algtype(GEN al) + GEN bnfgwgeneric(GEN bnf, GEN Lpr, GEN Ld, GEN pl, long var) + GEN bnrgwsearch(GEN bnr, GEN Lpr, GEN Ld, GEN pl) + void checkalg(GEN x) + void checkhasse(GEN nf, GEN hi, GEN hf, long n) + long cyclicrelfrob(GEN rnf, GEN auts, GEN pr) + GEN hassecoprime(GEN hi, GEN hf, long n) + GEN hassedown(GEN nf, long n, GEN hi, GEN hf) + GEN hassewedderburn(GEN hi, GEN hf, long n) + long localhasse(GEN rnf, GEN cnd, GEN pl, GEN auts, GEN b, long k) + GEN nfgrunwaldwang(GEN nf0, GEN Lpr, GEN Ld, GEN pl, long var) + GEN nfgwkummer(GEN nf, GEN Lpr, GEN Ld, GEN pl, long var) # alglin1.c @@ -1288,6 +1354,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN Flm_image(GEN x, ulong p) GEN Flm_invimage(GEN m, GEN v, ulong p) GEN Flm_indexrank(GEN x, ulong p) + GEN Flm_intersect(GEN x, GEN y, ulong p) GEN Flm_inv(GEN x, ulong p) GEN Flm_ker(GEN x, ulong p) GEN Flm_ker_sp(GEN x, ulong p, long deplin) @@ -1357,12 +1424,12 @@ cdef extern from "sage/libs/pari/parisage.h": GEN gauss(GEN a, GEN b) GEN gaussmodulo(GEN M, GEN D, GEN Y) GEN gaussmodulo2(GEN M, GEN D, GEN Y) - GEN gen_Gauss(GEN a, GEN b, void *E, bb_field *ff) - GEN gen_Gauss_pivot(GEN x, long *rr, void *E, bb_field *ff) - GEN gen_det(GEN a, void *E, bb_field *ff) - GEN gen_ker(GEN x, long deplin, void *E, bb_field *ff) - GEN gen_matcolmul(GEN a, GEN b, void *E, bb_field *ff) - GEN gen_matmul(GEN a, GEN b, void *E, bb_field *ff) + GEN gen_Gauss(GEN a, GEN b, void *E, const bb_field *ff) + GEN gen_Gauss_pivot(GEN x, long *rr, void *E, const bb_field *ff) + GEN gen_det(GEN a, void *E, const bb_field *ff) + GEN gen_ker(GEN x, long deplin, void *E, const bb_field *ff) + GEN gen_matcolmul(GEN a, GEN b, void *E, const bb_field *ff) + GEN gen_matmul(GEN a, GEN b, void *E, const bb_field *ff) GEN image(GEN x) GEN image2(GEN x) GEN imagecompl(GEN x) @@ -1459,37 +1526,39 @@ cdef extern from "sage/libs/pari/parisage.h": # anal.c - void addhelp(char *e, char *s) - void alias0(char *s, char *old) - GEN compile_str(char *s) + void addhelp(const char *e, char *s) + void alias0(const char *s, const char *old) + GEN compile_str(const char *s) GEN chartoGENstr(char c) long delete_var() - long fetch_user_var(char *s) + long fetch_user_var(const char *s) long fetch_var() long fetch_var_higher() GEN fetch_var_value(long vx, GEN t) - GEN gp_read_str(char *t) - entree* install(void *f, char *name, char *code) - entree* is_entry(char *s) - void kill0(char *e) + char * gp_embedded(const char *s) + void gp_embedded_init(long rsize, long vsize) + GEN gp_read_str(const char *t) + entree* install(void *f, const char *name, const char *code) + entree* is_entry(const char *s) + void kill0(const char *e) void pari_var_close() void pari_var_init() long pari_var_next() long pari_var_next_temp() long pari_var_create(entree *ep) - void name_var(long n, char *s) + void name_var(long n, const char *s) GEN readseq(char *t) GEN* safegel(GEN x, long l) long* safeel(GEN x, long l) GEN* safelistel(GEN x, long l) GEN* safegcoeff(GEN x, long a, long b) - GEN strntoGENstr(char *s, long n0) - GEN strtoGENstr(char *s) - GEN strtoi(char *s) - GEN strtor(char *s, long prec) + GEN strntoGENstr(const char *s, long n0) + GEN strtoGENstr(const char *s) + GEN strtoi(const char *s) + GEN strtor(const char *s, long prec) GEN type0(GEN x) - GEN varhigher(char *s, long v) - GEN varlower(char *s, long v) + GEN varhigher(const char *s, long v) + GEN varlower(const char *s, long v) # aprcl.c @@ -1498,9 +1567,9 @@ cdef extern from "sage/libs/pari/parisage.h": # Qfb.c GEN Qfb0(GEN x, GEN y, GEN z, GEN d, long prec) - void check_quaddisc(GEN x, long *s, long *r, char *f) - void check_quaddisc_imag(GEN x, long *r, char *f) - void check_quaddisc_real(GEN x, long *r, char *f) + void check_quaddisc(GEN x, long *s, long *r, const char *f) + void check_quaddisc_imag(GEN x, long *r, const char *f) + void check_quaddisc_real(GEN x, long *r, const char *f) long cornacchia(GEN d, GEN p, GEN *px, GEN *py) long cornacchia2(GEN d, GEN p, GEN *px, GEN *py) GEN nucomp(GEN x, GEN y, GEN L) @@ -1606,14 +1675,13 @@ cdef extern from "sage/libs/pari/parisage.h": GEN classno(GEN x) GEN classno2(GEN x) long clcm(long a, long b) - GEN conrey_normalize(GEN m, GEN cyc) GEN contfrac0(GEN x, GEN b, long flag) GEN contfracpnqn(GEN x, long n) GEN fibo(long n) GEN gboundcf(GEN x, long k) GEN gcf(GEN x) GEN gcf2(GEN b, GEN x) - bb_field *get_Fp_field(void **E, GEN p) + const bb_field *get_Fp_field(void **E, GEN p) ulong pgener_Fl(ulong p) ulong pgener_Fl_local(ulong p, GEN L) GEN pgener_Fp(GEN p) @@ -1658,6 +1726,7 @@ cdef extern from "sage/libs/pari/parisage.h": ulong rootsof1_Fl(ulong n, ulong p) GEN rootsof1_Fp(GEN n, GEN p) GEN rootsof1u_Fp(ulong n, GEN p) + long sisfundamental(long x) GEN sqrtint(GEN a) GEN ramanujantau(GEN n) ulong ugcd(ulong a, ulong b) @@ -1666,11 +1735,6 @@ cdef extern from "sage/libs/pari/parisage.h": long uissquareall(ulong A, ulong *sqrtA) long unegisfundamental(ulong x) long uposisfundamental(ulong x) - GEN znconreychar(GEN bid, GEN m) - GEN znconreyconductor(GEN bid, GEN co, GEN *pm) - GEN znconreyexp(GEN bid, GEN x) - GEN znconreyfromchar(GEN bid, GEN chi) - GEN znconreylog(GEN bid, GEN x) GEN znlog(GEN x, GEN g, GEN o) GEN znorder(GEN x, GEN o) GEN znprimroot(GEN m) @@ -1681,9 +1745,9 @@ cdef extern from "sage/libs/pari/parisage.h": GEN Z_smoothen(GEN N, GEN L, GEN *pP, GEN *pe) GEN boundfact(GEN n, ulong lim) - GEN check_arith_pos(GEN n, char *f) - GEN check_arith_non0(GEN n, char *f) - GEN check_arith_all(GEN n, char *f) + GEN check_arith_pos(GEN n, const char *f) + GEN check_arith_non0(GEN n, const char *f) + GEN check_arith_all(GEN n, const char *f) GEN clean_Z_factor(GEN f) GEN corepartial(GEN n, long l) GEN core0(GEN n, long flag) @@ -1696,6 +1760,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN digits(GEN N, GEN B) GEN divisors(GEN n) GEN divisorsu(ulong n) + GEN divisorsu_fact(GEN P, GEN e) GEN factor_pn_1(GEN p, ulong n) GEN factor_pn_1_limit(GEN p, long n, ulong lim) GEN factoru_pow(ulong n) @@ -1718,6 +1783,8 @@ cdef extern from "sage/libs/pari/parisage.h": GEN sumdigits(GEN n) GEN sumdigits0(GEN n, GEN B) ulong sumdigitsu(ulong n) + GEN usumdiv_fact(GEN f) + GEN usumdivk_fact(GEN f, ulong k) # base1.c @@ -1725,7 +1792,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN embed_T2(GEN x, long r1) GEN embednorm_T2(GEN x, long r1) GEN embed_norm(GEN x, long r1) - void check_ZKmodule(GEN x, char *s) + void check_ZKmodule(GEN x, const char *s) void checkbid(GEN bid) GEN checkbnf(GEN bnf) void checkbnr(GEN bnr) @@ -1733,7 +1800,7 @@ cdef extern from "sage/libs/pari/parisage.h": void checkabgrp(GEN v) void checksqmat(GEN x, long N) GEN checknf(GEN nf) - GEN checknfelt_mod(GEN nf, GEN x, char *s) + GEN checknfelt_mod(GEN nf, GEN x, const char *s) void checkprid(GEN bid) void checkrnf(GEN rnf) GEN factoredpolred(GEN x, GEN fa) @@ -1753,6 +1820,8 @@ cdef extern from "sage/libs/pari/parisage.h": GEN nfcertify(GEN x) GEN nfgaloismatrix(GEN nf, GEN s) GEN nfgaloispermtobasis(GEN nf, GEN gal) + void nfinit_step1(nfbasic_t *T, GEN x, long flag) + GEN nfinit_step2(nfbasic_t *T, long flag, long prec) GEN nfinit(GEN x, long prec) GEN nfinit0(GEN x, long flag, long prec) GEN nfinitall(GEN x, long flag, long prec) @@ -1790,9 +1859,9 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FqM_to_nfM(GEN z, GEN modpr) GEN FqV_to_nfV(GEN z, GEN modpr) GEN FqX_to_nfX(GEN x, GEN modpr) - GEN Rg_nffix(char *f, GEN T, GEN c, int lift) - GEN RgV_nffix(char *f, GEN T, GEN P, int lift) - GEN RgX_nffix(char *s, GEN nf, GEN x, int lift) + GEN Rg_nffix(const char *f, GEN T, GEN c, int lift) + GEN RgV_nffix(const char *f, GEN T, GEN P, int lift) + GEN RgX_nffix(const char *s, GEN nf, GEN x, int lift) long ZpX_disc_val(GEN f, GEN p) GEN ZpX_gcd(GEN f1, GEN f2, GEN p, GEN pm) GEN ZpX_reduced_resultant(GEN x, GEN y, GEN p, GEN pm) @@ -1886,8 +1955,8 @@ cdef extern from "sage/libs/pari/parisage.h": GEN nftrace(GEN nf, GEN x) long nfval(GEN nf, GEN x, GEN vp) long nfvalrem(GEN nf, GEN x, GEN pr, GEN *py) - GEN polmod_nffix(char *f, GEN rnf, GEN x, int lift) - GEN polmod_nffix2(char *f, GEN T, GEN relpol, GEN x, int lift) + GEN polmod_nffix(const char *f, GEN rnf, GEN x, int lift) + GEN polmod_nffix2(const char *f, GEN T, GEN relpol, GEN x, int lift) int pr_equal(GEN nf, GEN P, GEN Q) GEN rnfalgtobasis(GEN rnf, GEN x) GEN rnfbasistoalg(GEN rnf, GEN x) @@ -2005,37 +2074,43 @@ cdef extern from "sage/libs/pari/parisage.h": GEN nfeltup(GEN nf, GEN x, GEN zknf, GEN czknf) GEN rnfeltabstorel(GEN rnf, GEN x) GEN rnfeltdown(GEN rnf, GEN x) + GEN rnfeltdown0(GEN rnf, GEN x, long flag) GEN rnfeltreltoabs(GEN rnf, GEN x) GEN rnfeltup(GEN rnf, GEN x) + GEN rnfeltup0(GEN rnf, GEN x, long flag) GEN rnfidealabstorel(GEN rnf, GEN x) GEN rnfidealdown(GEN rnf, GEN x) GEN rnfidealhnf(GEN rnf, GEN x) GEN rnfidealmul(GEN rnf, GEN x, GEN y) GEN rnfidealnormabs(GEN rnf, GEN x) GEN rnfidealnormrel(GEN rnf, GEN x) + GEN rnfidealprimedec(GEN rnf, GEN pr) GEN rnfidealreltoabs(GEN rnf, GEN x) + GEN rnfidealreltoabs0(GEN rnf, GEN x, long flag) GEN rnfidealtwoelement(GEN rnf, GEN x) GEN rnfidealup(GEN rnf, GEN x) + GEN rnfidealup0(GEN rnf, GEN x, long flag) GEN rnfinit(GEN nf, GEN pol) + GEN rnfinit0(GEN nf, GEN pol, long flag) # bb_group.c GEN dlog_get_ordfa(GEN o) GEN dlog_get_ord(GEN o) - GEN gen_PH_log(GEN a, GEN g, GEN ord, void *E, bb_group *grp) - GEN gen_Shanks_init(GEN g, long n, void *E, bb_group *grp) - GEN gen_Shanks(GEN T, GEN x, ulong N, void *E, bb_group *grp) - GEN gen_Shanks_sqrtn(GEN a, GEN n, GEN q, GEN *zetan, void *E, bb_group *grp) - GEN gen_gener(GEN o, void *E, bb_group *grp) - GEN gen_ellgens(GEN d1, GEN d2, GEN m, void *E, bb_group *grp, + GEN gen_PH_log(GEN a, GEN g, GEN ord, void *E, const bb_group *grp) + GEN gen_Shanks_init(GEN g, long n, void *E, const bb_group *grp) + GEN gen_Shanks(GEN T, GEN x, ulong N, void *E, const bb_group *grp) + GEN gen_Shanks_sqrtn(GEN a, GEN n, GEN q, GEN *zetan, void *E, const bb_group *grp) + GEN gen_gener(GEN o, void *E, const bb_group *grp) + GEN gen_ellgens(GEN d1, GEN d2, GEN m, void *E, const bb_group *grp, GEN pairorder(void *E, GEN P, GEN Q, GEN m, GEN F)) - GEN gen_ellgroup(GEN N, GEN F, GEN *pt_m, void *E, bb_group *grp, + GEN gen_ellgroup(GEN N, GEN F, GEN *pt_m, void *E, const bb_group *grp, GEN pairorder(void *E, GEN P, GEN Q, GEN m, GEN F)) - GEN gen_factored_order(GEN a, GEN o, void *E, bb_group *grp) - GEN gen_order(GEN x, GEN o, void *E, bb_group *grp) - GEN gen_select_order(GEN o, void *E, bb_group *grp) + GEN gen_factored_order(GEN a, GEN o, void *E, const bb_group *grp) + GEN gen_order(GEN x, GEN o, void *E, const bb_group *grp) + GEN gen_select_order(GEN o, void *E, const bb_group *grp) - GEN gen_plog(GEN x, GEN g0, GEN q, void *E, bb_group *grp) + GEN gen_plog(GEN x, GEN g0, GEN q, void *E, const bb_group *grp) GEN gen_pow(GEN x, GEN n, void *E, GEN (*sqr)(void*, GEN), GEN (*mul)(void*, GEN, GEN)) GEN gen_pow_i(GEN x, GEN n, void *E, GEN (*sqr)(void*, GEN), GEN (*mul)(void*, GEN, GEN)) GEN gen_pow_fold(GEN x, GEN n, void *E, GEN (*sqr)(void*, GEN), GEN (*msqr)(void*, GEN)) @@ -2087,10 +2162,11 @@ cdef extern from "sage/libs/pari/parisage.h": GEN ZV_union_shallow(GEN x, GEN y) GEN binomial(GEN x, long k) GEN binomialuu(ulong n, ulong k) + int cmp_Flx(GEN x, GEN y) + int cmp_RgX(GEN x, GEN y) int cmp_nodata(void *data, GEN x, GEN y) int cmp_prime_ideal(GEN x, GEN y) int cmp_prime_over_p(GEN x, GEN y) - int cmp_RgX(GEN x, GEN y) int cmp_universal(GEN x, GEN y) GEN convol(GEN x, GEN y) int gen_cmp_RgX(void *data, GEN x, GEN y) @@ -2185,21 +2261,22 @@ cdef extern from "sage/libs/pari/parisage.h": # buch2.c + GEN Buchall(GEN P, long flag, long prec) + GEN Buchall_param(GEN P, double bach, double bach2, long nbrelpid, long flun, long prec) GEN bnfcompress(GEN bnf) GEN bnfinit0(GEN P, long flag, GEN data, long prec) + GEN bnfisprincipal0(GEN bnf, GEN x, long flall) + GEN bnfisunit(GEN bignf, GEN x) GEN bnfnewprec(GEN nf, long prec) GEN bnfnewprec_shallow(GEN nf, long prec) GEN bnrnewprec(GEN bnr, long prec) GEN bnrnewprec_shallow(GEN bnr, long prec) - GEN Buchall(GEN P, long flag, long prec) - GEN Buchall_param(GEN P, double bach, double bach2, long nbrelpid, long flun, long prec) - GEN isprincipal(GEN bnf, GEN x) - GEN bnfisprincipal0(GEN bnf, GEN x, long flall) GEN isprincipalfact(GEN bnf, GEN C, GEN L, GEN f, long flag) GEN isprincipalfact_or_fail(GEN bnf, GEN C, GEN P, GEN e) - GEN bnfisunit(GEN bignf, GEN x) - GEN signunits(GEN bignf) + GEN isprincipal(GEN bnf, GEN x) + GEN nfcyclotomicunits(GEN nf, GEN zu) GEN nfsign_units(GEN bnf, GEN archp, int add_zu) + GEN signunits(GEN bignf) # buch3.c @@ -2229,18 +2306,6 @@ cdef extern from "sage/libs/pari/parisage.h": GEN buchnarrow(GEN bignf) long bnfcertify(GEN bnf) long bnfcertify0(GEN bnf, long flag) - int char_check(GEN cyc, GEN chi) - GEN charker(GEN cyc, GEN chi) - GEN charker0(GEN cyc, GEN chi) - GEN charconj(GEN cyc, GEN chi) - GEN charconj0(GEN cyc, GEN chi) - GEN charorder(GEN cyc, GEN x) - GEN charorder0(GEN x, GEN chi) - GEN char_denormalize(GEN cyc, GEN D, GEN chic) - GEN char_normalize(GEN chi, GEN ncyc) - GEN char_rootof1(GEN d, long prec) - GEN char_rootof1_u(ulong d, long prec) - GEN cyc_normalize(GEN c) GEN decodemodule(GEN nf, GEN fa) GEN discrayabslist(GEN bnf, GEN listes) GEN discrayabslistarch(GEN bnf, GEN arch, ulong bound) @@ -2265,14 +2330,53 @@ cdef extern from "sage/libs/pari/parisage.h": long hyperell_locally_soluble(GEN pol, GEN p) long nf_hyperell_locally_soluble(GEN nf, GEN pol, GEN p) + # char.c + + int char_check(GEN cyc, GEN chi) + GEN charconj(GEN cyc, GEN chi) + GEN charconj0(GEN cyc, GEN chi) + GEN chardiv(GEN x, GEN a, GEN b) + GEN chardiv0(GEN x, GEN a, GEN b) + GEN chareval(GEN G, GEN chi, GEN n, GEN z) + GEN charker(GEN cyc, GEN chi) + GEN charker0(GEN cyc, GEN chi) + GEN charmul(GEN x, GEN a, GEN b) + GEN charmul0(GEN x, GEN a, GEN b) + GEN charorder(GEN cyc, GEN x) + GEN charorder0(GEN x, GEN chi) + GEN char_denormalize(GEN cyc, GEN D, GEN chic) + GEN char_normalize(GEN chi, GEN ncyc) + GEN char_rootof1(GEN d, long prec) + GEN char_rootof1_u(ulong d, long prec) + GEN char_simplify(GEN D, GEN C) + GEN cyc_normalize(GEN c) + int zncharcheck(GEN G, GEN chi) + GEN zncharconj(GEN G, GEN chi) + GEN znchardiv(GEN G, GEN a, GEN b) + GEN zncharker(GEN G, GEN chi) + GEN znchareval(GEN G, GEN chi, GEN n, GEN z) + GEN zncharinduce(GEN G, GEN chi, GEN N) + long zncharisodd(GEN G, GEN chi) + GEN zncharmul(GEN G, GEN a, GEN b) + GEN zncharorder(GEN G, GEN chi) + int znconrey_check(GEN cyc, GEN chi) + GEN znconrey_normalized(GEN G, GEN chi) + GEN znconreychar(GEN bid, GEN m) + GEN znconreyfromchar_normalized(GEN bid, GEN chi) + GEN znconreyconductor(GEN bid, GEN co, GEN *pm) + GEN znconreyexp(GEN bid, GEN x) + GEN znconreyfromchar(GEN bid, GEN chi) + GEN znconreylog(GEN bid, GEN x) + GEN znconreylog_normalize(GEN G, GEN m) + # compile.c GEN closure_deriv(GEN G) long localvars_find(GEN pack, entree *ep) - GEN localvars_read_str(char *str, GEN pack) + GEN localvars_read_str(const char *str, GEN pack) GEN snm_closure(entree *ep, GEN data) - GEN strtoclosure(char *s, long n, ...) - GEN strtofunction(char *s) + GEN strtoclosure(const char *s, long n, ...) + GEN strtofunction(const char *s) # concat.c @@ -2287,68 +2391,69 @@ cdef extern from "sage/libs/pari/parisage.h": # default.c extern int d_SILENT, d_ACKNOWLEDGE, d_INITRC, d_RETURN - GEN default0(char *a, char *b) + GEN default0(const char *a, const char *b) long getrealprecision() - entree *pari_is_default(char *s) - GEN sd_TeXstyle(char *v, long flag) - GEN sd_colors(char *v, long flag) - GEN sd_compatible(char *v, long flag) - GEN sd_datadir(char *v, long flag) - GEN sd_debug(char *v, long flag) - GEN sd_debugfiles(char *v, long flag) - GEN sd_debugmem(char *v, long flag) - GEN sd_factor_add_primes(char *v, long flag) - GEN sd_factor_proven(char *v, long flag) - GEN sd_format(char *v, long flag) - GEN sd_histsize(char *v, long flag) - GEN sd_log(char *v, long flag) - GEN sd_logfile(char *v, long flag) - GEN sd_nbthreads(char *v, long flag) - GEN sd_new_galois_format(char *v, long flag) - GEN sd_output(char *v, long flag) - GEN sd_parisize(char *v, long flag) - GEN sd_parisizemax(char *v, long flag) - GEN sd_path(char *v, long flag) - GEN sd_prettyprinter(char *v, long flag) - GEN sd_primelimit(char *v, long flag) - GEN sd_realbitprecision(char *v, long flag) - GEN sd_realprecision(char *v, long flag) - GEN sd_secure(char *v, long flag) - GEN sd_seriesprecision(char *v, long flag) - GEN sd_simplify(char *v, long flag) + entree *pari_is_default(const char *s) + GEN sd_TeXstyle(const char *v, long flag) + GEN sd_colors(const char *v, long flag) + GEN sd_compatible(const char *v, long flag) + GEN sd_datadir(const char *v, long flag) + GEN sd_debug(const char *v, long flag) + GEN sd_debugfiles(const char *v, long flag) + GEN sd_debugmem(const char *v, long flag) + GEN sd_factor_add_primes(const char *v, long flag) + GEN sd_factor_proven(const char *v, long flag) + GEN sd_format(const char *v, long flag) + GEN sd_histsize(const char *v, long flag) + GEN sd_log(const char *v, long flag) + GEN sd_logfile(const char *v, long flag) + GEN sd_nbthreads(const char *v, long flag) + GEN sd_new_galois_format(const char *v, long flag) + GEN sd_output(const char *v, long flag) + GEN sd_parisize(const char *v, long flag) + GEN sd_parisizemax(const char *v, long flag) + GEN sd_path(const char *v, long flag) + GEN sd_prettyprinter(const char *v, long flag) + GEN sd_primelimit(const char *v, long flag) + GEN sd_realbitprecision(const char *v, long flag) + GEN sd_realprecision(const char *v, long flag) + GEN sd_secure(const char *v, long flag) + GEN sd_seriesprecision(const char *v, long flag) + GEN sd_simplify(const char *v, long flag) GEN sd_sopath(char *v, int flag) - GEN sd_strictargs(char *v, long flag) - GEN sd_strictmatch(char *v, long flag) - GEN sd_string(char *v, long flag, char *s, char **f) - GEN sd_threadsize(char *v, long flag) - GEN sd_threadsizemax(char *v, long flag) - GEN sd_toggle(char *v, long flag, char *s, int *ptn) - GEN sd_ulong(char *v, long flag, char *s, ulong *ptn, ulong Min, ulong Max, char **msg) - GEN setdefault(char *s, char *v, long flag) + GEN sd_strictargs(const char *v, long flag) + GEN sd_strictmatch(const char *v, long flag) + GEN sd_string(const char *v, long flag, const char *s, char **f) + GEN sd_threadsize(const char *v, long flag) + GEN sd_threadsizemax(const char *v, long flag) + GEN sd_toggle(const char *v, long flag, const char *s, int *ptn) + GEN sd_ulong(const char *v, long flag, const char *s, ulong *ptn, ulong Min, ulong Max, const char **msg) + GEN setdefault(const char *s, const char *v, long flag) long setrealprecision(long n, long *prec) # gplib.c - GEN sd_breakloop(char *v, long flag) - GEN sd_echo(char *v, long flag) - GEN sd_graphcolormap(char *v, long flag) - GEN sd_graphcolors(char *v, long flag) - GEN sd_help(char *v, long flag) - GEN sd_histfile(char *v, long flag) - GEN sd_lines(char *v, long flag) - GEN sd_linewrap(char *v, long flag) - GEN sd_prompt(char *v, long flag) - GEN sd_prompt_cont(char *v, long flag) - GEN sd_psfile(char *v, long flag) - GEN sd_readline(char *v, long flag) - GEN sd_recover(char *v, long flag) - GEN sd_timer(char *v, long flag) + GEN sd_breakloop(const char *v, long flag) + GEN sd_echo(const char *v, long flag) + GEN sd_graphcolormap(const char *v, long flag) + GEN sd_graphcolors(const char *v, long flag) + GEN sd_help(const char *v, long flag) + GEN sd_histfile(const char *v, long flag) + GEN sd_lines(const char *v, long flag) + GEN sd_linewrap(const char *v, long flag) + GEN sd_prompt(const char *v, long flag) + GEN sd_prompt_cont(const char *v, long flag) + GEN sd_psfile(const char *v, long flag) + GEN sd_readline(const char *v, long flag) + GEN sd_recover(const char *v, long flag) + GEN sd_timer(const char *v, long flag) void pari_hit_return() void gp_load_gprc() - int gp_meta(char *buf, int ismain) - void pari_center(char *s) + int gp_meta(const char *buf, int ismain) + const char **gphelp_keyword_list() + void pari_center(const char *s) void pari_print_version() - char *gp_format_time(long delay) - char *gp_format_prompt(char *p) + const char *gp_format_time(long delay) + const char *gp_format_prompt(const char *p) void pari_alarm(long s) GEN gp_alarm(long s, GEN code) GEN gp_input() @@ -2357,8 +2462,8 @@ cdef extern from "sage/libs/pari/parisage.h": void gp_alarm_handler(int sig) void gp_sigint_fun() extern int h_REGULAR, h_LONG, h_APROPOS, h_RL - void gp_help(char *s, long flag) - void gp_echo_and_log(char *prompt, char *s) + void gp_help(const char *s, long flag) + void gp_echo_and_log(const char *prompt, const char *s) void print_fun_list(char **list, long nbli) # dirichlet.c @@ -2372,7 +2477,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN ellanalyticrank_bitprec(GEN e, GEN eps, long bitprec) GEN ellanal_globalred_all(GEN e, GEN *N, GEN *cb, GEN *tam) GEN ellheegner(GEN e) - GEN ellL1(GEN e, long r, long prec) + GEN ellL1(GEN E, long r, long prec) GEN ellL1_bitprec(GEN E, long r, long bitprec) # elldata.c @@ -2508,10 +2613,6 @@ cdef extern from "sage/libs/pari/parisage.h": # elltors.c long ellisdivisible(GEN E, GEN P, GEN n, GEN *Q) - # ellpadicL.c - GEN ellpadicL(GEN E, GEN p, long n, long r, GEN D, GEN C) - GEN ellpadicmoments(GEN E, GEN pp, long n, long r, GEN DD) - # ellisogeny.c GEN ellisogenyapply(GEN f, GEN P) @@ -2526,15 +2627,16 @@ cdef extern from "sage/libs/pari/parisage.h": # es.c - GEN externstr(char *cmd) - char *gp_filter(char *s) - GEN gpextern(char *cmd) - void gpsystem(char *s) - GEN readstr(char *s) + GEN externstr(const char *cmd) + char *gp_filter(const char *s) + GEN gpextern(const char *cmd) + void gpsystem(const char *s) + GEN readstr(const char *s) GEN GENtoGENstr_nospace(GEN x) GEN GENtoGENstr(GEN x) char* GENtoTeXstr(GEN x) char* GENtostr(GEN x) + char* GENtostr_raw(GEN x) char* GENtostr_unquoted(GEN x) GEN Str(GEN g) GEN Strchr(GEN g) @@ -2546,86 +2648,87 @@ cdef extern from "sage/libs/pari/parisage.h": void dbg_pari_heap() int file_is_binary(FILE *f) void err_flush() - void err_printf(char* pat, ...) - GEN gp_getenv(char *s) - GEN gp_read_file(char *s) - GEN gp_read_str_multiline(char *s, char *last) + void err_printf(const char* pat, ...) + GEN gp_getenv(const char *s) + GEN gp_read_file(const char *s) + GEN gp_read_str_multiline(const char *s, char *last) GEN gp_read_stream(FILE *f) GEN gp_readvec_file(char *s) GEN gp_readvec_stream(FILE *f) - void gpinstall(char *s, char *code, - char *gpname, char *lib) - GEN gsprintf(char *fmt, ...) - GEN gvsprintf(char *fmt, va_list ap) + void gpinstall(const char *s, const char *code, + const char *gpname, const char *lib) + GEN gsprintf(const char *fmt, ...) + GEN gvsprintf(const char *fmt, va_list ap) char* itostr(GEN x) void matbrute(GEN g, char format, long dec) - char* os_getenv(char *s) + char* os_getenv(const char *s) void (*os_signal(int sig, void (*f)(int)))(int) void outmat(GEN x) void output(GEN x) char* RgV_to_str(GEN g, long flag) void pari_add_hist(GEN z, long t) - void pari_ask_confirm(char *s) + void pari_ask_confirm(const char *s) void pari_fclose(pariFILE *f) void pari_flush() - pariFILE* pari_fopen(char *s, char *mode) - pariFILE* pari_fopen_or_fail(char *s, char *mode) - pariFILE* pari_fopengz(char *s) - void pari_fprintf(FILE *file, char *fmt, ...) + pariFILE* pari_fopen(const char *s, const char *mode) + pariFILE* pari_fopen_or_fail(const char *s, const char *mode) + pariFILE* pari_fopengz(const char *s) + void pari_fprintf(FILE *file, const char *fmt, ...) void pari_fread_chars(void *b, size_t n, FILE *f) GEN pari_get_hist(long p) long pari_get_histtime(long p) - char* pari_get_homedir(char *user) - int pari_is_dir(char *name) - int pari_is_file(char *name) + char* pari_get_homedir(const char *user) + int pari_is_dir(const char *name) + int pari_is_file(const char *name) int pari_last_was_newline() void pari_set_last_newline(int last) ulong pari_nb_hist() - void pari_printf(char *fmt, ...) + void pari_printf(const char *fmt, ...) void pari_putc(char c) - void pari_puts(char *s) - pariFILE* pari_safefopen(char *s, char *mode) - char* pari_sprintf(char *fmt, ...) + void pari_puts(const char *s) + pariFILE* pari_safefopen(const char *s, const char *mode) + char* pari_sprintf(const char *fmt, ...) int pari_stdin_isatty() - char* pari_strdup(char *s) - char* pari_strndup(char *s, long n) - char* pari_unique_dir(char *s) - char* pari_unique_filename(char *s) - void pari_unlink(char *s) - void pari_vfprintf(FILE *file, char *fmt, va_list ap) - void pari_vprintf(char *fmt, va_list ap) - char* pari_vsprintf(char *fmt, va_list ap) - char* path_expand(char *s) - void out_print0(PariOUT *out, char *sep, GEN g, long flag) - void out_printf(PariOUT *out, char *fmt, ...) + char* pari_strdup(const char *s) + char* pari_strndup(const char *s, long n) + char* pari_unique_dir(const char *s) + char* pari_unique_filename(const char *s) + void pari_unlink(const char *s) + void pari_vfprintf(FILE *file, const char *fmt, va_list ap) + void pari_vprintf(const char *fmt, va_list ap) + char* pari_vsprintf(const char *fmt, va_list ap) + char* path_expand(const char *s) + void out_print0(PariOUT *out, const char *sep, GEN g, long flag) + void out_printf(PariOUT *out, const char *fmt, ...) void out_putc(PariOUT *out, char c) - void out_puts(PariOUT *out, char *s) + void out_puts(PariOUT *out, const char *s) void out_term_color(PariOUT *out, long c) - void out_vprintf(PariOUT *out, char *fmt, va_list ap) - char* pari_sprint0(char *msg, GEN g, long flag) + void out_vprintf(PariOUT *out, const char *fmt, va_list ap) + char* pari_sprint0(const char *msg, GEN g, long flag) + void print(GEN g) extern int f_RAW, f_PRETTYMAT, f_PRETTY, f_TEX void print0(GEN g, long flag) void print1(GEN g) - void printf0(char *fmt, GEN args) - void printsep(char *s, GEN g) - void printsep1(char *s, GEN g) + void printf0(const char *fmt, GEN args) + void printsep(const char *s, GEN g) + void printsep1(const char *s, GEN g) void printtex(GEN g) - char* stack_sprintf(char *fmt, ...) - char* stack_strcat(char *s, char *t) - char* stack_strdup(char *s) - void strftime_expand(char *s, char *buf, long max) - GEN Strprintf(char *fmt, GEN args) - FILE* switchin(char *name) - void switchout(char *name) + char* stack_sprintf(const char *fmt, ...) + char* stack_strcat(const char *s, const char *t) + char* stack_strdup(const char *s) + void strftime_expand(const char *s, char *buf, long max) + GEN Strprintf(const char *fmt, GEN args) + FILE* switchin(const char *name) + void switchout(const char *name) void term_color(long c) char* term_get_color(char *s, long c) void texe(GEN g, char format, long dec) - char* type_name(long t) + const char* type_name(long t) void warning0(GEN g) - void write0(char *s, GEN g) - void write1(char *s, GEN g) - void writebin(char *name, GEN x) - void writetex(char *s, GEN g) + void write0(const char *s, GEN g) + void write1(const char *s, GEN g) + void writebin(const char *name, GEN x) + void writetex(const char *s, GEN g) # eval.c @@ -2746,6 +2849,8 @@ cdef extern from "sage/libs/pari/parisage.h": long FFM_rank(GEN M, GEN ff) GEN FFX_factor(GEN f, GEN x) GEN FFX_roots(GEN f, GEN x) + GEN FqX_to_FFX(GEN x, GEN ff) + GEN Fq_to_FF(GEN x, GEN ff) GEN Z_FF_div(GEN a, GEN b) GEN ffgen(GEN T, long v) GEN fflog(GEN x, GEN g, GEN o) @@ -2907,6 +3012,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN RgX_RgM_eval_col(GEN x, GEN M, long c) GEN RgX_cxeval(GEN T, GEN u, GEN ui) GEN RgX_deflate_max(GEN x0, long *m) + long RgX_deflate_order(GEN x) long RgX_degree(GEN x, long v) GEN RgX_integ(GEN x) GEN bitprecision0(GEN x, long n) @@ -3058,6 +3164,7 @@ cdef extern from "sage/libs/pari/parisage.h": hashtable *hash_create_str(ulong s, long stack) hashtable *hash_create(ulong minsize, ulong (*hash)(void*), int (*eq)(void*, void*), int use_stack) void hash_insert(hashtable *h, void *k, void *v) + void hash_insert2(hashtable *h, void *k, void *v, ulong hash) GEN hash_keys(hashtable *h) GEN hash_values(hashtable *h) hashentry *hash_search(hashtable *h, void *k) @@ -3066,8 +3173,8 @@ cdef extern from "sage/libs/pari/parisage.h": hashentry *hash_remove(hashtable *h, void *k) hashentry *hash_remove_select(hashtable *h, void *k, void *E, int (*select)(void*, hashentry*)) void hash_destroy(hashtable *h) - ulong hash_str(char *str) - ulong hash_str2(char *s) + ulong hash_str(const char *str) + ulong hash_str2(const char *s) ulong hash_GEN(GEN x) # hyperell.c @@ -3193,12 +3300,12 @@ cdef extern from "sage/libs/pari/parisage.h": void gunclone(GEN x) void gunclone_deep(GEN x) GEN listcopy(GEN x) - void timer_printf(pari_timer *T, char *format, ...) - void msgtimer(char *format, ...) - long name_numerr(char *s) + void timer_printf(pari_timer *T, const char *format, ...) + void msgtimer(const char *format, ...) + long name_numerr(const char *s) void new_chunk_resize(size_t x) GEN newblock(size_t n) - char * numerr_name(long errnum) + const char * numerr_name(long errnum) GEN obj_check(GEN S, long K) GEN obj_checkbuild(GEN S, long tag, GEN (*build)(GEN)) GEN obj_checkbuild_padicprec(GEN S, long tag, GEN (*build)(GEN, long), long prec) @@ -3213,7 +3320,7 @@ cdef extern from "sage/libs/pari/parisage.h": void pari_add_defaults_module(entree *ep) void pari_close() void pari_close_opts(ulong init_opts) - GEN pari_compile_str(char *lex) + GEN pari_compile_str(const char *lex) int pari_daemon() void pari_err(int numerr, ...) GEN pari_err_last() @@ -3236,7 +3343,7 @@ cdef extern from "sage/libs/pari/parisage.h": void paristack_setsize(size_t rsize, size_t vsize) void parivstack_resize(ulong newsize) void parivstack_reset() - GEN trap0(char *e, GEN f, GEN r) + GEN trap0(const char *e, GEN f, GEN r) void shiftaddress(GEN x, long dec) void shiftaddress_canon(GEN x, long dec) long timer() @@ -3253,7 +3360,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN intnumgauss(void *E, GEN (*eval)(void*, GEN), GEN a, GEN b, GEN tab, long prec) GEN intnumgaussinit(long n, long prec) GEN intnuminit(GEN a, GEN b, long m, long prec) - GEN intnumromb(void *E, GEN (*eval) (void *, GEN), GEN a, GEN b, long flag, long prec) + GEN intnumromb(void *E, GEN (*eval)(void *, GEN), GEN a, GEN b, long flag, long prec) GEN intnumromb_bitprec(void *E, GEN (*eval)(void *, GEN), GEN a, GEN b, long flag, long bit) GEN sumnum(void *E, GEN (*eval)(void*, GEN), GEN a, GEN tab, long prec) GEN sumnuminit(GEN fast, long prec) @@ -3297,49 +3404,35 @@ cdef extern from "sage/libs/pari/parisage.h": GEN lfun_get_w2(GEN tech) GEN lfun_get_expot(GEN tech) long lfun_get_der(GEN tech) - GEN lfun(GEN ldata, GEN s, long prec) - GEN lfun_bitprec(GEN ldata, GEN s, long bitprec) - GEN lfun0_bitprec(GEN ldata, GEN s, long der, long bitprec) - GEN lfun0(GEN ldata, GEN s, long der, long prec) - long lfuncheckfeq(GEN data, GEN t0, long prec) - long lfuncheckfeq_bitprec(GEN data, GEN t0, long bitprec) - GEN lfunconductor(GEN data, GEN maxcond, long flag, long prec) - GEN lfunconductor_bitprec(GEN data, GEN maxcond, long flag, long bitprec) + long lfun_get_bitprec(GEN tech) + GEN lfun(GEN ldata, GEN s, long bitprec) + GEN lfun0(GEN ldata, GEN s, long der, long bitprec) + long lfuncheckfeq(GEN data, GEN t0, long bitprec) + GEN lfunconductor(GEN data, GEN maxcond, long flag, long bitprec) GEN lfuncost(GEN lmisc, GEN dom, long der, long bitprec) GEN lfuncost0(GEN L, GEN dom, long der, long bitprec) GEN lfuncreate(GEN obj) GEN lfunan(GEN ldata, long L, long prec) - GEN lfunhardy(GEN ldata, GEN t, long prec) - GEN lfunhardy_bitprec(GEN ldata, GEN t, long bitprec) - GEN lfuninit(GEN ldata, GEN dom, long der, long prec) - GEN lfuninit_bitprec(GEN ldata, GEN dom, long der, long bitprec) - GEN lfuninit0(GEN ldata, GEN dom, long der, long prec) - GEN lfuninit0_bitprec(GEN ldata, GEN dom, long der, long bitprec) + GEN lfunhardy(GEN ldata, GEN t, long bitprec) + GEN lfuninit(GEN ldata, GEN dom, long der, long bitprec) + GEN lfuninit0(GEN ldata, GEN dom, long der, long bitprec) GEN lfuninit_make(long t, GEN ldata, GEN molin, GEN domain) long lfunisvgaell(GEN Vga, long flag) - GEN lfunlambda(GEN ldata, GEN s, long prec) - GEN lfunlambda_bitprec(GEN ldata, GEN s, long bitprec) - GEN lfunlambda0(GEN ldata, GEN s, long der, long prec) - GEN lfunlambda0_bitprec(GEN ldata, GEN s, long der, long bitprec) + GEN lfunlambda(GEN ldata, GEN s, long bitprec) + GEN lfunlambda0(GEN ldata, GEN s, long der, long bitprec) GEN lfunmisc_to_ldata(GEN ldata) GEN lfunmisc_to_ldata_shallow(GEN ldata) - long lfunorderzero(GEN ldata, long prec) - long lfunorderzero_bitprec(GEN ldata, long bitprec) + long lfunorderzero(GEN ldata, long bitprec) GEN lfunprod_get_fact(GEN tech) - GEN lfunrootno(GEN data, long prec) - GEN lfunrootno_bitprec(GEN data, long bitprec) - GEN lfunrootres(GEN data, long prec) - GEN lfunrootres_bitprec(GEN data, long bitprec) + GEN lfunrootno(GEN data, long bitprec) + GEN lfunrootres(GEN data, long bitprec) GEN lfunrtopoles(GEN r) - GEN lfuntheta(GEN data, GEN t, long m, long prec) - GEN lfuntheta_bitprec(GEN data, GEN t, long m, long bitprec) + GEN lfuntheta(GEN data, GEN t, long m, long bitprec) long lfunthetacost0(GEN L, GEN tdom, long m, long bitprec) long lfunthetacost(GEN ldata, GEN tdom, long m, long bitprec) - GEN lfunthetainit(GEN ldata, GEN tinf, long m, long prec) - GEN lfunthetainit_bitprec(GEN ldata, GEN tdom, long m, long bitprec) + GEN lfunthetainit(GEN ldata, GEN tdom, long m, long bitprec) GEN lfunthetacheckinit(GEN data, GEN tinf, long m, long *ptbitprec, long fl) - GEN lfunzeros(GEN ldata, GEN lim, long divz, long prec) - GEN lfunzeros_bitprec(GEN ldata, GEN lim, long divz, long bitprec) + GEN lfunzeros(GEN ldata, GEN lim, long divz, long bitprec) int sdomain_isincl(long k, GEN dom, GEN dom0) GEN theta_get_an(GEN tdata) GEN theta_get_K(GEN tdata) @@ -3352,25 +3445,20 @@ cdef extern from "sage/libs/pari/parisage.h": # lfunutils.c GEN dirzetak(GEN nf, GEN b) - GEN ellmoddegree(GEN e, long prec) - GEN ellmoddegree_bitprec(GEN e, long bitprec) - GEN lfunabelianrelinit(GEN bnfabs, GEN bnf, GEN polrel, GEN dom, long der, long prec) - GEN lfunabelianrelinit_bitprec(GEN bnfabs, GEN bnf, GEN polrel, GEN dom, long der, long bitprec) + GEN ellmoddegree(GEN e, long bitprec) + GEN lfunabelianrelinit(GEN bnfabs, GEN bnf, GEN polrel, GEN dom, long der, long bitprec) GEN lfunartin(GEN N, GEN G, GEN M, long o) - GEN lfundiv(GEN ldata1, GEN ldata2, long prec) - GEN lfunellmfpeters_bitprec(GEN E, long bitprec) - GEN lfunetaquo(GEN ldata) - GEN lfunmfspec(GEN ldata, long prec) - GEN lfunmfspec_bitprec(GEN lmisc, long bitprec) - GEN lfunmfpeters(GEN ldata, long prec) - GEN lfunmfpeters_bitprec(GEN ldata, long bitprec) - GEN lfunmul(GEN ldata1, GEN ldata2, long prec) + GEN lfundiv(GEN ldata1, GEN ldata2, long bitprec) + GEN lfunellmfpeters(GEN E, long bitprec) + GEN lfunetaquo(GEN eta) + GEN lfungenus2(GEN PS) + GEN lfunmfspec(GEN lmisc, long bitprec) + GEN lfunmfpeters(GEN ldata, long bitprec) + GEN lfunmul(GEN ldata1, GEN ldata2, long bitprec) GEN lfunqf(GEN ldata) GEN lfunsymsq(GEN ldata, GEN known, long prec) - GEN lfunsymsqspec(GEN ldata, long prec) - GEN lfunsymsqspec_bitprec(GEN lmisc, long bitprec) - GEN lfunzetakinit(GEN pol, GEN dom, long der, long flag, long prec) - GEN lfunzetakinit_bitprec(GEN pol, GEN dom, long der, long flag, long bitprec) + GEN lfunsymsqspec(GEN lmisc, long bitprec) + GEN lfunzetakinit(GEN pol, GEN dom, long der, long flag, long bitprec) # lll.c @@ -3409,15 +3497,12 @@ cdef extern from "sage/libs/pari/parisage.h": double dbllambertW0(double a) double dbllambertW_1(double a) - double dbllemma526(double a, double b, double c, long B) - double dblcoro526(double a, double c, long B) - GEN gammamellininv(GEN Vga, GEN s, long m, long prec) - GEN gammamellininv_bitprec(GEN Vga, GEN s, long m, long bitprec) + double dbllemma526(double a, double b, double c, double B) + double dblcoro526(double a, double c, double B) + GEN gammamellininv(GEN Vga, GEN s, long m, long bitprec) GEN gammamellininvasymp(GEN Vga, long nlimmax, long m) - GEN gammamellininvinit(GEN Vga, long m, long prec) - GEN gammamellininvinit_bitprec(GEN Vga, long m, long bitprec) - GEN gammamellininvrt(GEN K, GEN x, long prec) - GEN gammamellininvrt_bitprec(GEN K, GEN s, long bitprec) + GEN gammamellininvinit(GEN Vga, long m, long bitprec) + GEN gammamellininvrt(GEN K, GEN s, long bitprec) # members.c @@ -3571,13 +3656,13 @@ cdef extern from "sage/libs/pari/parisage.h": # paricfg.c - extern char *paricfg_datadir - extern char *paricfg_version - extern char *paricfg_buildinfo - extern long paricfg_version_code - extern char *paricfg_vcsversion - extern char *paricfg_compiledate - extern char *paricfg_mt_engine + extern const char *paricfg_datadir + extern const char *paricfg_version + extern const char *paricfg_buildinfo + extern const long paricfg_version_code + extern const char *paricfg_vcsversion + extern const char *paricfg_compiledate + extern const char *paricfg_mt_engine # part.c @@ -3741,13 +3826,13 @@ cdef extern from "sage/libs/pari/parisage.h": GEN Flx_roots_naive(GEN f, ulong p) GEN FlxX_resultant(GEN u, GEN v, ulong p, long sx) GEN Flxq_ffisom_inv(GEN S, GEN Tp, ulong p) - GEN FpV_polint(GEN xa, GEN ya, GEN p, long v) GEN FpX_FpXY_resultant(GEN a, GEN b0, GEN p) GEN FpX_factorff_irred(GEN P, GEN Q, GEN p) void FpX_ffintersect(GEN P, GEN Q, long n, GEN l, GEN *SP, GEN *SQ, GEN MA, GEN MB) GEN FpX_ffisom(GEN P, GEN Q, GEN l) GEN FpX_translate(GEN P, GEN c, GEN p) GEN FpXQ_ffisom_inv(GEN S, GEN Tp, GEN p) + GEN FpXQX_normalize(GEN z, GEN T, GEN p) GEN FpXV_FpC_mul(GEN V, GEN W, GEN p) GEN FpXY_Fq_evaly(GEN Q, GEN y, GEN T, GEN p, long vx) GEN Fq_Fp_mul(GEN x, GEN y, GEN T, GEN p) @@ -3777,7 +3862,6 @@ cdef extern from "sage/libs/pari/parisage.h": GEN FqX_Fq_add(GEN y, GEN x, GEN T, GEN p) GEN FqX_Fq_mul_to_monic(GEN P, GEN U, GEN T, GEN p) GEN FqX_eval(GEN x, GEN y, GEN T, GEN p) - GEN FqX_normalize(GEN z, GEN T, GEN p) GEN FqX_translate(GEN P, GEN c, GEN T, GEN p) GEN FqXQ_powers(GEN x, long l, GEN S, GEN T, GEN p) GEN FqXQ_matrix_pow(GEN y, long n, long m, GEN S, GEN T, GEN p) @@ -3793,12 +3877,12 @@ cdef extern from "sage/libs/pari/parisage.h": int Rg_is_FpXQ(GEN x, GEN *pT, GEN *pp) GEN Rg_to_Fp(GEN x, GEN p) GEN Rg_to_FpXQ(GEN x, GEN T, GEN p) - GEN RgC_to_Flc(GEN x, ulong p) GEN RgC_to_FpC(GEN x, GEN p) int RgM_is_FpM(GEN x, GEN *p) GEN RgM_to_Flm(GEN x, ulong p) GEN RgM_to_FpM(GEN x, GEN p) int RgV_is_FpV(GEN x, GEN *p) + GEN RgV_to_Flv(GEN x, ulong p) GEN RgV_to_FpV(GEN x, GEN p) int RgX_is_FpX(GEN x, GEN *p) GEN RgX_to_FpX(GEN x, GEN p) @@ -3823,7 +3907,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN ffnbirred(GEN p, long n) GEN ffnbirred0(GEN p, long n, long flag) GEN ffsumnbirred(GEN p, long n) - bb_field *get_Fq_field(void **E, GEN T, GEN p) + const bb_field *get_Fq_field(void **E, GEN T, GEN p) GEN init_Fq(GEN p, long n, long v) GEN pol_x_powers(long N, long v) GEN residual_characteristic(GEN x) @@ -3876,8 +3960,8 @@ cdef extern from "sage/libs/pari/parisage.h": GEN qfautoexport(GEN g, long flag) GEN qfisom(GEN g, GEN h, GEN flags) GEN qfisom0(GEN g, GEN h, GEN flags) - GEN qfisominit(GEN g, GEN flags) - GEN qfisominit0(GEN g, GEN flags) + GEN qfisominit(GEN g, GEN flags, GEN minvec) + GEN qfisominit0(GEN g, GEN flags, GEN minvec) GEN qforbits(GEN G, GEN V) # qfparam.c @@ -4036,7 +4120,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN teich(GEN x) GEN teichmullerinit(long p, long n) GEN teichmuller(GEN x, GEN tab) - GEN trans_eval(char *fun, GEN (*f) (GEN, long), GEN x, long prec) + GEN trans_eval(const char *fun, GEN (*f) (GEN, long), GEN x, long prec) ulong upowuu(ulong p, ulong k) ulong usqrtn(ulong a, ulong n) ulong usqrt(ulong a) @@ -4057,6 +4141,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN gcosh(GEN x, long prec) GEN ggammah(GEN x, long prec) GEN ggamma(GEN x, long prec) + GEN ggamma1m1(GEN x, long prec) GEN glngamma(GEN x, long prec) GEN gpsi(GEN x, long prec) GEN gsinh(GEN x, long prec) @@ -4109,16 +4194,20 @@ cdef extern from "sage/libs/pari/parisage.h": GEN weberf2(GEN x, long prec) # modsym.c - GEN Eisenstein_symbol(GEN W, GEN c) - GEN Q_xpm(GEN W, GEN xpm, GEN c) GEN Qevproj_apply(GEN T, GEN pro) GEN Qevproj_apply_vecei(GEN T, GEN pro, long k) GEN Qevproj_init(GEN M) GEN RgX_act_Gl2Q(GEN g, long k) GEN RgX_act_ZGl2Q(GEN z, long k) void checkms(GEN W) + void checkmspadic(GEN W) + GEN ellpadicL(GEN E, GEN p, long n, GEN s, long r, GEN D) GEN msfromcusp(GEN W, GEN c) GEN msfromell(GEN E, long signe) + GEN msfromhecke(GEN W, GEN v, GEN H) + long msgetlevel(GEN W) + long msgetsign(GEN W) + long msgetweight(GEN W) GEN msatkinlehner(GEN W, long Q, GEN) GEN mscuspidal(GEN W, long flag) GEN mseisenstein(GEN W) @@ -4126,15 +4215,18 @@ cdef extern from "sage/libs/pari/parisage.h": GEN mshecke(GEN W, long p, GEN H) GEN msinit(GEN N, GEN k, long sign) long msissymbol(GEN W, GEN s) - GEN mspadicmoments(GEN W, GEN phi, long p, long n) + GEN msomseval(GEN W, GEN phi, GEN path) + GEN mspadicinit(GEN W, long p, long n, long flag) + GEN mspadicL(GEN oms, GEN s, long r) + GEN mspadicmoments(GEN W, GEN phi, long D) + GEN mspadicseries(GEN M, long teichi) GEN mspathgens(GEN W) GEN mspathlog(GEN W, GEN path) GEN msnew(GEN W) GEN msstar(GEN W, GEN) GEN msqexpansion(GEN W, GEN proV, ulong B) GEN mssplit(GEN W, GEN H) - GEN mstooms(GEN W, GEN phi, long p, long n) - GEN omseval(GEN O, GEN path) + GEN mstooms(GEN W, GEN phi) # zetamult.c GEN zetamult(GEN avec, long prec) @@ -4391,9 +4483,9 @@ cdef extern from "sage/libs/pari/parisage.h": int varncmp(long x, long y) cdef extern from "sage/libs/pari/parisage.h": - GEN set_gel(GEN x, long n, GEN z) # gel(x,n) = z - GEN set_gmael(GEN x, long i, long j, GEN z) # gmael(x,i,j) = z - GEN set_gcoeff(GEN x, long i, long j, GEN z) # gcoeff(x,i,j) = z + GEN set_gel(GEN x, long n, GEN z) # gel(x, n) = z + GEN set_gmael(GEN x, long i, long j, GEN z) # gmael(x, i, j) = z + GEN set_gcoeff(GEN x, long i, long j, GEN z) # gcoeff(x, i, j) = z # Inline functions in separate file diff --git a/src/sage/libs/pari/parisage.h b/src/sage/libs/pari/parisage.h index 5729aa11f18..30d3024a814 100644 --- a/src/sage/libs/pari/parisage.h +++ b/src/sage/libs/pari/parisage.h @@ -3,6 +3,7 @@ #include #undef coeff /* Conflicts with NTL */ +#undef ulong /* Conflicts with FLINT */ /* Array element assignment */ diff --git a/src/sage/libs/pari/tests.py b/src/sage/libs/pari/tests.py index bce508418f3..67adc50cd21 100644 --- a/src/sage/libs/pari/tests.py +++ b/src/sage/libs/pari/tests.py @@ -1184,9 +1184,9 @@ sage: e.elllseries(2.1) 0.402838047956645 sage: e.elllseries(1, precision=128) - 6.21952537507477 E-39 + 3.19632265064095 E-40 sage: e.elllseries(1, precision=256) - 2.95993347819786 E-77 + 8.68747983667209 E-79 sage: e.elllseries(-2) 0 sage: e.elllseries(2.1, A=1.1) diff --git a/src/sage/libs/pari/types.pxd b/src/sage/libs/pari/types.pxd index 55d5c10606e..88285e78382 100644 --- a/src/sage/libs/pari/types.pxd +++ b/src/sage/libs/pari/types.pxd @@ -74,6 +74,7 @@ cdef extern from "sage/libs/pari/parisage.h": struct forvec_t struct entree struct gp_context + struct nfbasic_t struct pariFILE struct pari_mt struct pari_stack diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py index 18a69cc5c6b..ff13d0dba1b 100644 --- a/src/sage/rings/number_field/number_field_ideal.py +++ b/src/sage/rings/number_field/number_field_ideal.py @@ -205,9 +205,8 @@ def __hash__(self): """ EXAMPLES:: - sage: NumberField(x^2 + 1, 'a').ideal(7).__hash__() - 848642427 # 32-bit - 3643975048496365947 # 64-bit + sage: NumberField(x^2 + 1, 'a').ideal(7).__hash__() # random + 7806919040325273549 """ try: return self._hash diff --git a/src/sage/rings/number_field/number_field_rel.py b/src/sage/rings/number_field/number_field_rel.py index 06ce39d9190..a3768371cba 100644 --- a/src/sage/rings/number_field/number_field_rel.py +++ b/src/sage/rings/number_field/number_field_rel.py @@ -204,21 +204,21 @@ def __init__(self, base, polynomial, name, sage: l. = k.extension(5*x^2 + 3); l Number Field in b with defining polynomial 5*x^2 + 3 over its base field sage: l.pari_rnf() - [x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4), ..., y^4 + 6*y^2 + 1, x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4)], [0]] + [x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4), ..., y^4 + 6*y^2 + 1, x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4)], [0, 0]] sage: b b sage: l. = k.extension(x^2 + 3/5); l Number Field in b with defining polynomial x^2 + 3/5 over its base field sage: l.pari_rnf() - [x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4), ..., y^4 + 6*y^2 + 1, x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4)], [0]] + [x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4), ..., y^4 + 6*y^2 + 1, x^2 + (-1/2*y^2 + y - 3/2)*x + (-1/4*y^3 + 1/4*y^2 - 3/4*y - 13/4)], [0, 0]] sage: b b sage: l. = k.extension(x - 1/a0); l Number Field in b with defining polynomial x + 1/2*a0 over its base field sage: l.pari_rnf() - [x, [[4, -x^3 - x^2 - 7*x - 3, -x^3 + x^2 - 7*x + 3, 2*x^3 + 10*x], 1/4], ..., [x^4 + 6*x^2 + 1, -x, -1, y^4 + 6*y^2 + 1, x], [0]] + [x, [[4, -x^3 - x^2 - 7*x - 3, -x^3 + x^2 - 7*x + 3, 2*x^3 + 10*x], 1/4], ..., [x^4 + 6*x^2 + 1, -x, -1, y^4 + 6*y^2 + 1, x], [0, 0]] sage: b -1/2*a0 diff --git a/src/sage_setup/autogen/pari/doc.py b/src/sage_setup/autogen/pari/doc.py index e554da6b345..ed9db9288f4 100644 --- a/src/sage_setup/autogen/pari/doc.py +++ b/src/sage_setup/autogen/pari/doc.py @@ -106,6 +106,7 @@ def raw_to_rest(doc): doc = doc.replace("@[pm]", "±") doc = doc.replace("@[nbrk]", unichr(0xa0)) doc = doc.replace("@[agrave]", "à") + doc = doc.replace("@[aacute]", "á") doc = doc.replace("@[eacute]", "é") doc = doc.replace("@[ouml]", "ö") doc = doc.replace("@[uuml]", "ü") From 04d57eb05c1d473352c1d0fd482d7a5b89fd3f5d Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Tue, 24 May 2016 18:10:56 +0200 Subject: [PATCH 021/135] Add patch for R needed for the 'R CMD' command to work on Cygwin. This is needed specifically when the cygwin drive is mounted with the noacl option. With ACL support it may work as is. This is needed both at build time (to install packages that are installed by default with R) and at run time. See http://trac.sagemath.org/ticket/20655 --- build/pkgs/r/patches/rcmd_exec.patch | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 build/pkgs/r/patches/rcmd_exec.patch diff --git a/build/pkgs/r/patches/rcmd_exec.patch b/build/pkgs/r/patches/rcmd_exec.patch new file mode 100644 index 00000000000..581491dab91 --- /dev/null +++ b/build/pkgs/r/patches/rcmd_exec.patch @@ -0,0 +1,11 @@ +--- a/src/scripts/Rcmd.in 2016-05-24 17:54:31.786568400 +0200 ++++ b/src/scripts/Rcmd.in 2016-05-24 17:54:55.402067200 +0200 +@@ -50,7 +50,7 @@ + exit 1 + ;; + *) +- if test -x "${R_HOME}/bin/${1}"; then ++ if test -f "${R_HOME}/bin/${1}"; then + cmd="${R_HOME}/bin/${1}" + else + cmd="${1}" From ca19af1eabcaa84698633fb8e2f2dcbf23cd32a7 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Thu, 26 May 2016 21:11:01 -0500 Subject: [PATCH 022/135] Added the option to get the sets `X` and `Y`, where `N` is `M/X\Y`. --- src/sage/matroids/matroid.pxd | 4 ++-- src/sage/matroids/matroid.pyx | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/sage/matroids/matroid.pxd b/src/sage/matroids/matroid.pxd index 1325ddcbb08..1b3af89b036 100644 --- a/src/sage/matroids/matroid.pxd +++ b/src/sage/matroids/matroid.pxd @@ -33,7 +33,7 @@ cdef class Matroid(SageObject): cpdef _is_coclosed(self, X) cpdef _minor(self, contractions, deletions) - cpdef _has_minor(self, N) + cpdef _has_minor(self, N, certificate=*) cpdef _line_length(self, F) cpdef _extension(self, element, hyperplanes) @@ -118,7 +118,7 @@ cdef class Matroid(SageObject): cpdef _backslash_(self, X) cpdef dual(self) cpdef truncation(self) - cpdef has_minor(self, N) + cpdef has_minor(self, N, certificate=*) cpdef has_line_minor(self, k, hyperlines=*) cpdef _has_line_minor(self, k, hyperlines) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 52fc77ee86f..85f9a4ae032 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -85,7 +85,7 @@ additional functionality (e.g. linear extensions). - :meth:`delete() ` - :meth:`dual() ` - :meth:`truncation() ` - - :meth:`has_minor() ` + - :meth:`() ` - :meth:`has_line_minor() ` @@ -1101,17 +1101,18 @@ cdef class Matroid(SageObject): import minor_matroid return minor_matroid.MinorMatroid(self, contractions, deletions) - cpdef _has_minor(self, N): + cpdef _has_minor(self, N, certificate=False): """ Test if matroid has the specified minor. INPUT: - - ``N`` -- An instance of a ``Matroid`` object. + - ``N`` -- An instance of a ``Matroid`` object.- optional parameter `certificate` -- a boolean. OUTPUT: - Boolean. + Boolean, + and `(X,Y)` -- frozen sets, where `N` is `M/X\Y`. EXAMPLES:: @@ -1120,6 +1121,8 @@ cdef class Matroid(SageObject): False sage: M._has_minor(matroids.Uniform(2, 4)) True + sage: M._has_minor(matroids.Uniform(2, 4), True) + (True, (frozenset({'a', 'c'}), frozenset({'b', 'e'}))) .. TODO:: @@ -1127,17 +1130,25 @@ cdef class Matroid(SageObject): See [Hlineny]_ p.1219 for hints to that end. """ if self is N: + if certificate: + return True, None return True rd = self.full_rank() - N.full_rank() cd = self.full_corank() - N.full_corank() if rd < 0 or cd < 0: + if certificate: + return False, None return False YY = self.dual().independent_r_sets(cd) for X in self.independent_r_sets(rd): for Y in YY: if X.isdisjoint(Y): if N._is_isomorphic(self._minor(contractions=X, deletions=Y)): + if certificate: + return True, (X,Y) return True + if certificate: + return False, None return False cpdef _line_length(self, F): @@ -3884,17 +3895,19 @@ cdef class Matroid(SageObject): return self._extension(l, [])._minor(contractions=frozenset([l]), deletions=frozenset([])) - cpdef has_minor(self, N): + cpdef has_minor(self, N, certificate=False): """ Check if ``self`` has a minor isomorphic to ``N``. INPUT: - - ``N`` -- A matroid. + - ``N`` -- A matroid, + - optional parameter `certificate` -- a boolean. OUTPUT: - Boolean. + Boolean, + and `(X,Y)` -- frozen sets, where `N` is `M/X\Y`. .. SEEALSO:: @@ -3913,10 +3926,12 @@ cdef class Matroid(SageObject): False sage: matroids.named_matroids.NonFano().has_minor(M) True + sage: matroids.named_matroids.NonFano().has_minor(M, True) + (True, (frozenset(), frozenset({'g'}))) """ if not isinstance(N, Matroid): raise ValueError("N must be a matroid.") - return self._has_minor(N) + return self._has_minor(N, certificate) cpdef has_line_minor(self, k, hyperlines=None): """ From 85a6317e97c5f889736f1677d1afb15901d23810 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sat, 28 May 2016 15:02:01 -0500 Subject: [PATCH 023/135] Fixed errors --- src/sage/matroids/matroid.pyx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 85f9a4ae032..13060fed51c 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -85,7 +85,7 @@ additional functionality (e.g. linear extensions). - :meth:`delete() ` - :meth:`dual() ` - :meth:`truncation() ` - - :meth:`() ` + - :meth:`has_minor() ` - :meth:`has_line_minor() ` @@ -1107,7 +1107,8 @@ cdef class Matroid(SageObject): INPUT: - - ``N`` -- An instance of a ``Matroid`` object.- optional parameter `certificate` -- a boolean. + - ``N`` -- An instance of a ``Matroid`` object. + - optional parameter `certificate` -- a boolean. OUTPUT: @@ -1121,6 +1122,8 @@ cdef class Matroid(SageObject): False sage: M._has_minor(matroids.Uniform(2, 4)) True + sage: M._has_minor(matroids.Uniform(2, 4), certificate=True) + (True, (frozenset({'a', 'c'}), frozenset({'b', 'e'}))) sage: M._has_minor(matroids.Uniform(2, 4), True) (True, (frozenset({'a', 'c'}), frozenset({'b', 'e'}))) @@ -3901,7 +3904,7 @@ cdef class Matroid(SageObject): INPUT: - - ``N`` -- A matroid, + - ``N`` -- A matroid, - optional parameter `certificate` -- a boolean. OUTPUT: From aaf8d13c5986c1ea7beb29b0c5fe60f53a850d0e Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sat, 28 May 2016 16:50:35 -0500 Subject: [PATCH 024/135] Added the option to get a certificate to is_chordal, _is_circuit_chordal, and is_chordal. --- src/sage/matroids/matroid.pxd | 6 ++-- src/sage/matroids/matroid.pyx | 54 ++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/sage/matroids/matroid.pxd b/src/sage/matroids/matroid.pxd index 1325ddcbb08..d6d3c04d961 100644 --- a/src/sage/matroids/matroid.pxd +++ b/src/sage/matroids/matroid.pxd @@ -163,9 +163,9 @@ cdef class Matroid(SageObject): cpdef is_k_closed(self, int k) # matroid chordality - cpdef _is_circuit_chordal(self, frozenset C) - cpdef is_circuit_chordal(self, C) - cpdef is_chordal(self, k1=*, k2=*) + cpdef _is_circuit_chordal(self, frozenset C, certificate=*) + cpdef is_circuit_chordal(self, C, certificate=*) + cpdef is_chordal(self, k1=*, k2=*, certificate=*) cpdef chordality(self) # optimization diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 52fc77ee86f..d803873e85d 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -6122,10 +6122,19 @@ cdef class Matroid(SageObject): # matroid chordality - cpdef _is_circuit_chordal(self, frozenset C): + cpdef _is_circuit_chordal(self, frozenset C, certificate=False): """ Check if the circuit ``C`` has a chord. + INPUT: + + - ``C`` -- a circuit + - ``certificate`` -- (optional) boolean, False if not given. + + OUTPUT: + - Boolean, + and if certificate, ``(x, Ax, Bx)`` -- a cord ``x`` of ``C``, and circuits ``Ax`` and ``Bx`` showing that ``x`` is a chord, or None if the circuit is not chordal. + EXAMPLES:: sage: M = matroids.Uniform(2,4) @@ -6134,8 +6143,16 @@ cdef class Matroid(SageObject): sage: M = matroids.named_matroids.Fano() sage: M._is_circuit_chordal(frozenset(['b','c','d'])) False + sage: M._is_circuit_chordal(frozenset(['b','c','d']), certificate=True) + (False, None) + sage: M._is_circuit_chordal(frozenset(['b','c','d']), True) + (False, None) sage: M._is_circuit_chordal(frozenset(['a','b','d','e'])) True + sage: M._is_circuit_chordal(frozenset(['a','b','d','e']), certificate=True) + (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) + sage: M._is_circuit_chordal(frozenset(['a','b','d','e']), True) + (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) """ cdef set X cdef frozenset Ax, Bx @@ -6149,10 +6166,14 @@ cdef class Matroid(SageObject): if not self._is_independent(Bx): # If x is spanned by C, then A+x is the unique circuit in C-e+x; # so x is a chord iff the complementary B is a circuit. + if certificate: + return True, (x, frozenset(Ax), frozenset(Bx)) return True + if certificate: + return False, None return False - cpdef is_circuit_chordal(self, C): + cpdef is_circuit_chordal(self, C, certificate=False): r""" Check if the circuit ``C`` has a chord. @@ -6160,19 +6181,36 @@ cdef class Matroid(SageObject): exists sets `A, B` such that `C = A \sqcup B` and `A + x` and `B + x` are circuits. + INPUT: + + - ``C`` -- a circuit + - ``certificate`` -- (optional) boolean, False if not given. + + OUTPUT: + - Boolean, + and if certificate, ``(x, Ax, Bx)`` -- a cord ``x`` of ``C``, and circuits ``Ax`` and ``Bx`` showing that ``x`` is a chord, or None if the circuit is not chordal. + EXAMPLES:: sage: M = matroids.named_matroids.Fano() sage: M.is_circuit_chordal(['b','c','d']) False + sage: M.is_circuit_chordal(['b','c','d'], certificate=True) + (False, None) + sage: M.is_circuit_chordal(['b','c','d'], True) + (False, None) sage: M.is_circuit_chordal(['a','b','d','e']) True + sage: M.is_circuit_chordal(['a','b','d','e'], certificate=True) + (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) + sage: M.is_circuit_chordal(['a','b','d','e'], True) + (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) """ if not self.is_circuit(C): raise ValueError("input C is not a circuit") - return self._is_circuit_chordal(frozenset(C)) + return self._is_circuit_chordal(frozenset(C), certificate) - cpdef is_chordal(self, k1=4, k2=None): + cpdef is_chordal(self, k1=4, k2=None, certificate=False): r""" Return if a matroid is ``[k1, k2]``-chordal. @@ -6187,6 +6225,8 @@ cdef class Matroid(SageObject): - ``k1`` -- (optional) the integer `k_1` - ``k2`` -- (optional) the integer `k_2`; if not specified, then this method returns if ``self`` is `k_1`-chordal + - ``certificate`` -- (optional) Boolean, False if not specified, + if true, and matroid is not chordal, returns a circuit which is not chordal. .. SEEALSO:: @@ -6205,6 +6245,10 @@ cdef class Matroid(SageObject): [False, False, False, False, True, True] sage: M.is_chordal(4, 5) False + sage: M.is_chordal(4, 5, certificate=True) + (False, frozenset({'a', 'b', 'e', 'f', 'g'})) + sage: M.is_chordal(4, 5, True) + (False, frozenset({'a', 'b', 'e', 'f', 'g'})) """ cdef frozenset C if k2 is None: @@ -6213,6 +6257,8 @@ cdef class Matroid(SageObject): if len(C) < k1 or len(C) > k2: continue if not self._is_circuit_chordal(C): + if certificate: + return False, frozenset(C) return False return True From 6fc388d3bc08caa5625272453d95723ca0e8055d Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sat, 28 May 2016 20:26:53 -0500 Subject: [PATCH 025/135] Removed repeated doctest --- src/sage/matroids/matroid.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 13060fed51c..7a6ed7f114f 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1124,8 +1124,6 @@ cdef class Matroid(SageObject): True sage: M._has_minor(matroids.Uniform(2, 4), certificate=True) (True, (frozenset({'a', 'c'}), frozenset({'b', 'e'}))) - sage: M._has_minor(matroids.Uniform(2, 4), True) - (True, (frozenset({'a', 'c'}), frozenset({'b', 'e'}))) .. TODO:: From e5151995672638410e2da8b74b9f75a6c93628d9 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sat, 28 May 2016 21:55:27 -0500 Subject: [PATCH 026/135] removed doctest --- src/sage/matroids/matroid.pyx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index d803873e85d..91e7ca6becc 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -6145,14 +6145,10 @@ cdef class Matroid(SageObject): False sage: M._is_circuit_chordal(frozenset(['b','c','d']), certificate=True) (False, None) - sage: M._is_circuit_chordal(frozenset(['b','c','d']), True) - (False, None) sage: M._is_circuit_chordal(frozenset(['a','b','d','e'])) True sage: M._is_circuit_chordal(frozenset(['a','b','d','e']), certificate=True) (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) - sage: M._is_circuit_chordal(frozenset(['a','b','d','e']), True) - (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) """ cdef set X cdef frozenset Ax, Bx @@ -6197,14 +6193,10 @@ cdef class Matroid(SageObject): False sage: M.is_circuit_chordal(['b','c','d'], certificate=True) (False, None) - sage: M.is_circuit_chordal(['b','c','d'], True) - (False, None) sage: M.is_circuit_chordal(['a','b','d','e']) True sage: M.is_circuit_chordal(['a','b','d','e'], certificate=True) (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) - sage: M.is_circuit_chordal(['a','b','d','e'], True) - (True, ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'}))) """ if not self.is_circuit(C): raise ValueError("input C is not a circuit") @@ -6247,8 +6239,6 @@ cdef class Matroid(SageObject): False sage: M.is_chordal(4, 5, certificate=True) (False, frozenset({'a', 'b', 'e', 'f', 'g'})) - sage: M.is_chordal(4, 5, True) - (False, frozenset({'a', 'b', 'e', 'f', 'g'})) """ cdef frozenset C if k2 is None: From e663be3dc4374e7d52dc7f327510a432b02a35f9 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Tue, 31 May 2016 09:34:05 -0500 Subject: [PATCH 027/135] Started working, saved so I can change branch --- src/sage/matroids/matroid.pxd | 6 +++--- src/sage/matroids/matroid.pyx | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/sage/matroids/matroid.pxd b/src/sage/matroids/matroid.pxd index d6d3c04d961..101ce76ccda 100644 --- a/src/sage/matroids/matroid.pxd +++ b/src/sage/matroids/matroid.pxd @@ -163,9 +163,9 @@ cdef class Matroid(SageObject): cpdef is_k_closed(self, int k) # matroid chordality - cpdef _is_circuit_chordal(self, frozenset C, certificate=*) - cpdef is_circuit_chordal(self, C, certificate=*) - cpdef is_chordal(self, k1=*, k2=*, certificate=*) + cpdef _is_circuit_chordal(self, frozenset C, bint certificate=*) + cpdef is_circuit_chordal(self, C, bint certificate=*) + cpdef is_chordal(self, k1=*, k2=*, bint certificate=*) cpdef chordality(self) # optimization diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 91e7ca6becc..3a0117c67f3 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -6122,18 +6122,21 @@ cdef class Matroid(SageObject): # matroid chordality - cpdef _is_circuit_chordal(self, frozenset C, certificate=False): + cpdef _is_circuit_chordal(self, frozenset C, bint certificate=False): """ Check if the circuit ``C`` has a chord. INPUT: - ``C`` -- a circuit - - ``certificate`` -- (optional) boolean, False if not given. + - ``certificate`` -- (default: ``False``) boolean OUTPUT: - - Boolean, - and if certificate, ``(x, Ax, Bx)`` -- a cord ``x`` of ``C``, and circuits ``Ax`` and ``Bx`` showing that ``x`` is a chord, or None if the circuit is not chordal. + + - boolean and if certificate is ``True``, also return a tuple + ``(x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and ``Bx`` + are circuits whose union is ``C`` and ``x``, or ``None`` if + ``C`` is not chordal EXAMPLES:: @@ -6169,7 +6172,7 @@ cdef class Matroid(SageObject): return False, None return False - cpdef is_circuit_chordal(self, C, certificate=False): + cpdef is_circuit_chordal(self, C, bint certificate=False): r""" Check if the circuit ``C`` has a chord. @@ -6180,11 +6183,14 @@ cdef class Matroid(SageObject): INPUT: - ``C`` -- a circuit - - ``certificate`` -- (optional) boolean, False if not given. + - ``certificate`` -- (default: ``False``) boolean OUTPUT: - - Boolean, - and if certificate, ``(x, Ax, Bx)`` -- a cord ``x`` of ``C``, and circuits ``Ax`` and ``Bx`` showing that ``x`` is a chord, or None if the circuit is not chordal. + + - boolean and if certificate is ``True``, also return a tuple + ``(x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and ``Bx`` + are circuits whose union is ``C`` and ``x``, or ``None`` if + ``C`` is not chordal EXAMPLES:: @@ -6202,7 +6208,7 @@ cdef class Matroid(SageObject): raise ValueError("input C is not a circuit") return self._is_circuit_chordal(frozenset(C), certificate) - cpdef is_chordal(self, k1=4, k2=None, certificate=False): + cpdef is_chordal(self, k1=4, k2=None, bint certificate=False): r""" Return if a matroid is ``[k1, k2]``-chordal. @@ -6217,8 +6223,8 @@ cdef class Matroid(SageObject): - ``k1`` -- (optional) the integer `k_1` - ``k2`` -- (optional) the integer `k_2`; if not specified, then this method returns if ``self`` is `k_1`-chordal - - ``certificate`` -- (optional) Boolean, False if not specified, - if true, and matroid is not chordal, returns a circuit which is not chordal. + - ``certificate`` -- (default: ``False``) boolean; if + ``True`` and ``self`` is not chordal, return a circuit .. SEEALSO:: From 1a33e6340048cb10168d5e061be89e9bd558ac24 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Tue, 31 May 2016 11:47:35 -0500 Subject: [PATCH 028/135] Eddited documentation --- src/sage/matroids/matroid.pyx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 7a6ed7f114f..a0072f0d56e 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1103,17 +1103,19 @@ cdef class Matroid(SageObject): cpdef _has_minor(self, N, certificate=False): """ - Test if matroid has the specified minor. + Test if matroid has the specified minor, + and optionally frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. INPUT: - ``N`` -- An instance of a ``Matroid`` object. - - optional parameter `certificate` -- a boolean. + - ``certificate`` -- (Defalt: ``False``) If true, returns frozensets + ``X`` and ``Y`` where ``N`` is `M/X\Y`. OUTPUT: Boolean, - and `(X,Y)` -- frozen sets, where `N` is `M/X\Y`. + and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is ``self.minor(X, Y)``. EXAMPLES:: @@ -1146,7 +1148,7 @@ cdef class Matroid(SageObject): if X.isdisjoint(Y): if N._is_isomorphic(self._minor(contractions=X, deletions=Y)): if certificate: - return True, (X,Y) + return True, X, Y return True if certificate: return False, None @@ -3898,17 +3900,19 @@ cdef class Matroid(SageObject): cpdef has_minor(self, N, certificate=False): """ - Check if ``self`` has a minor isomorphic to ``N``. + Check if ``self`` has a minor isomorphic to ``N``, + and optionally frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. - INPUT: + INPUT: - - ``N`` -- A matroid, - - optional parameter `certificate` -- a boolean. + - ``N`` -- An instance of a ``Matroid`` object. + - ``certificate`` -- (Defalt: ``False``) If true, returns ``frozenset``s + ``X`` and ``Y`` where ``N`` is `M/X\Y`. OUTPUT: Boolean, - and `(X,Y)` -- frozen sets, where `N` is `M/X\Y`. + and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is ``self.minor(X, Y)``. .. SEEALSO:: From 19826d187f2173348a4f5d3ec2fe9b00f647f8f8 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Tue, 31 May 2016 11:56:34 -0500 Subject: [PATCH 029/135] Eddited errors in documentation --- src/sage/matroids/matroid.pyx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index a0072f0d56e..3d8efb7f7f1 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1104,18 +1104,18 @@ cdef class Matroid(SageObject): cpdef _has_minor(self, N, certificate=False): """ Test if matroid has the specified minor, - and optionally frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. + and optionally return frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. INPUT: - - ``N`` -- An instance of a ``Matroid`` object. - - ``certificate`` -- (Defalt: ``False``) If true, returns frozensets - ``X`` and ``Y`` where ``N`` is `M/X\Y`. + - ``N`` -- An instance of a ``Matroid`` object, + - ``certificate`` -- Boolean (Defalt: ``False``) If true, returns frozensets + ``X`` and ``Y`` where ``N`` is isomorphic to ``self.minor(X, Y)``. OUTPUT: Boolean, - and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is ``self.minor(X, Y)``. + and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is isomorphic to ``self.minor(X, Y)``. EXAMPLES:: @@ -3901,18 +3901,18 @@ cdef class Matroid(SageObject): cpdef has_minor(self, N, certificate=False): """ Check if ``self`` has a minor isomorphic to ``N``, - and optionally frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. + and optionally return frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. - INPUT: + INPUT: - - ``N`` -- An instance of a ``Matroid`` object. - - ``certificate`` -- (Defalt: ``False``) If true, returns ``frozenset``s - ``X`` and ``Y`` where ``N`` is `M/X\Y`. + - ``N`` -- A ``Matroid``, + - ``certificate`` -- Boolean (Defalt: ``False``) If true, returns ``frozenset``s + ``X`` and ``Y`` where ``N`` is isomorphic to ``self.minor(X, Y)``. OUTPUT: Boolean, - and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is ``self.minor(X, Y)``. + and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is isomorphic to ``self.minor(X, Y)``. .. SEEALSO:: From 9a33e778ee9c0c8e79ebdf527b9061192b759c51 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Thu, 2 Jun 2016 18:48:32 -0500 Subject: [PATCH 030/135] Eddited Documentation --- src/sage/matroids/matroid.pyx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 3a0117c67f3..84e5b5e9994 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -6126,16 +6126,18 @@ cdef class Matroid(SageObject): """ Check if the circuit ``C`` has a chord. - INPUT: + INPUT: - ``C`` -- a circuit - - ``certificate`` -- (default: ``False``) boolean + - ``certificate`` -- (default: ``False``) boolean, if ``True``, finds an element + ``x`` and, disjoint except at ``x``, circuits ``Ax`` and ``Bx`` so that + ``Ax`` union ``Bx`` is the elements of ``C`` together with ``x``. OUTPUT: - boolean and if certificate is ``True``, also return a tuple - ``(x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and ``Bx`` - are circuits whose union is ``C`` and ``x``, or ``None`` if + ``(x, Ax, Bx)``, where ``x`` is a chord of ``C`` with ``Ax`` and ``Bx`` + circuits whose union is the elements of ``C`` together with ``x``, or ``None`` if ``C`` is not chordal EXAMPLES:: @@ -6180,7 +6182,7 @@ cdef class Matroid(SageObject): exists sets `A, B` such that `C = A \sqcup B` and `A + x` and `B + x` are circuits. - INPUT: + INPUT: - ``C`` -- a circuit - ``certificate`` -- (default: ``False``) boolean From 5b3522e33bcd7555e1e57405e39784103e1644ac Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sun, 5 Jun 2016 07:32:01 -0500 Subject: [PATCH 031/135] Eddited documentation --- src/sage/matroids/matroid.pyx | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 84e5b5e9994..0c63a738189 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -6129,16 +6129,14 @@ cdef class Matroid(SageObject): INPUT: - ``C`` -- a circuit - - ``certificate`` -- (default: ``False``) boolean, if ``True``, finds an element - ``x`` and, disjoint except at ``x``, circuits ``Ax`` and ``Bx`` so that - ``Ax`` union ``Bx`` is the elements of ``C`` together with ``x``. + - ``certificate`` -- (default: ``False``) a boolean, if ``True`` + return ``True, (x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and + ``Bx`` are circuits whose union is the elements of ``C`` + together with ``x``, if ``False`` return ``False, None``. OUTPUT: - - boolean and if certificate is ``True``, also return a tuple - ``(x, Ax, Bx)``, where ``x`` is a chord of ``C`` with ``Ax`` and ``Bx`` - circuits whose union is the elements of ``C`` together with ``x``, or ``None`` if - ``C`` is not chordal + - boolean or tuple EXAMPLES:: @@ -6185,14 +6183,14 @@ cdef class Matroid(SageObject): INPUT: - ``C`` -- a circuit - - ``certificate`` -- (default: ``False``) boolean + - ``certificate`` -- (default: ``False``) a boolean, if ``True`` + return ``True, (x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and + ``Bx`` are circuits whose union is the elements of ``C`` + together with ``x``, if ``False`` return ``False, None``. OUTPUT: - - boolean and if certificate is ``True``, also return a tuple - ``(x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and ``Bx`` - are circuits whose union is ``C`` and ``x``, or ``None`` if - ``C`` is not chordal + - boolean or tuple EXAMPLES:: @@ -6226,7 +6224,12 @@ cdef class Matroid(SageObject): - ``k2`` -- (optional) the integer `k_2`; if not specified, then this method returns if ``self`` is `k_1`-chordal - ``certificate`` -- (default: ``False``) boolean; if - ``True`` and ``self`` is not chordal, return a circuit + ``True`` return ``True, C``, where ``C`` is a non + ``k1`` ``k2`` circuit + + Output: + + - boolean or tuple .. SEEALSO:: From 0b86a6bec61f3121d872aee6e7decbf1dae42d8d Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sun, 5 Jun 2016 07:44:48 -0500 Subject: [PATCH 032/135] Eddited documentation --- src/sage/matroids/matroid.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 3d8efb7f7f1..afaa053a6a3 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1109,13 +1109,13 @@ cdef class Matroid(SageObject): INPUT: - ``N`` -- An instance of a ``Matroid`` object, - - ``certificate`` -- Boolean (Defalt: ``False``) If true, returns frozensets - ``X`` and ``Y`` where ``N`` is isomorphic to ``self.minor(X, Y)``. + - ``certificate`` -- Boolean (Defalt: ``False``) If ``True``, returns + ``True, (X, Y, dic) where ``N`` is isomorphic to ``self.minor(X, Y)``, + and ``dic`` is an isomorphism between ``N`` and ``self.minor(X, Y)``. OUTPUT: - Boolean, - and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is isomorphic to ``self.minor(X, Y)``. + boolean or tuple. EXAMPLES:: @@ -1148,7 +1148,7 @@ cdef class Matroid(SageObject): if X.isdisjoint(Y): if N._is_isomorphic(self._minor(contractions=X, deletions=Y)): if certificate: - return True, X, Y + return True, (X, Y, N._isomorphism(self._minor(contractions=X, deletions=Y))) return True if certificate: return False, None From d05d6d24cfde51e83a973e2044394747f260e49c Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sun, 5 Jun 2016 07:48:09 -0500 Subject: [PATCH 033/135] Fixed error in documentation --- src/sage/matroids/matroid.pyx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index afaa053a6a3..e6cefd1209d 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -3905,14 +3905,14 @@ cdef class Matroid(SageObject): INPUT: - - ``N`` -- A ``Matroid``, - - ``certificate`` -- Boolean (Defalt: ``False``) If true, returns ``frozenset``s - ``X`` and ``Y`` where ``N`` is isomorphic to ``self.minor(X, Y)``. + - ``N`` -- An instance of a ``Matroid`` object, + - ``certificate`` -- Boolean (Defalt: ``False``) If ``True``, returns + ``True, (X, Y, dic) where ``N`` is isomorphic to ``self.minor(X, Y)``, + and ``dic`` is an isomorphism between ``N`` and ``self.minor(X, Y)``. OUTPUT: - Boolean, - and (if ``certificate`` is ``True``,) frozensets ``X``, ``Y``, where ``N`` is isomorphic to ``self.minor(X, Y)``. + boolean or tuple. .. SEEALSO:: @@ -3931,7 +3931,7 @@ cdef class Matroid(SageObject): False sage: matroids.named_matroids.NonFano().has_minor(M) True - sage: matroids.named_matroids.NonFano().has_minor(M, True) + sage: matroids.named_matroids.NonFano().has_minor(M, certificate=True) (True, (frozenset(), frozenset({'g'}))) """ if not isinstance(N, Matroid): From 15131de5207f9d2b9eabc24e6b11e97506cecfc9 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Sun, 5 Jun 2016 07:58:39 -0500 Subject: [PATCH 034/135] Fixed spacing error --- src/sage/matroids/matroid.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index e6cefd1209d..5229bebbb89 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1109,7 +1109,7 @@ cdef class Matroid(SageObject): INPUT: - ``N`` -- An instance of a ``Matroid`` object, - - ``certificate`` -- Boolean (Defalt: ``False``) If ``True``, returns + - ``certificate`` -- Boolean (Defalt: ``False``) If ``True``, returns ``True, (X, Y, dic) where ``N`` is isomorphic to ``self.minor(X, Y)``, and ``dic`` is an isomorphism between ``N`` and ``self.minor(X, Y)``. @@ -3906,7 +3906,7 @@ cdef class Matroid(SageObject): INPUT: - ``N`` -- An instance of a ``Matroid`` object, - - ``certificate`` -- Boolean (Defalt: ``False``) If ``True``, returns + - ``certificate`` -- Boolean (Defalt: ``False``) If ``True``, returns ``True, (X, Y, dic) where ``N`` is isomorphic to ``self.minor(X, Y)``, and ``dic`` is an isomorphism between ``N`` and ``self.minor(X, Y)``. From 87533057d70e226d533fce0e853cc8a700c74a40 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Tue, 7 Jun 2016 17:01:44 -0500 Subject: [PATCH 035/135] Fixed doctest --- src/sage/matroids/matroid.pxd | 4 ++-- src/sage/matroids/matroid.pyx | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sage/matroids/matroid.pxd b/src/sage/matroids/matroid.pxd index 1b3af89b036..99aaa4bd9c3 100644 --- a/src/sage/matroids/matroid.pxd +++ b/src/sage/matroids/matroid.pxd @@ -33,7 +33,7 @@ cdef class Matroid(SageObject): cpdef _is_coclosed(self, X) cpdef _minor(self, contractions, deletions) - cpdef _has_minor(self, N, certificate=*) + cpdef _has_minor(self, N, bint certificate=*) cpdef _line_length(self, F) cpdef _extension(self, element, hyperplanes) @@ -118,7 +118,7 @@ cdef class Matroid(SageObject): cpdef _backslash_(self, X) cpdef dual(self) cpdef truncation(self) - cpdef has_minor(self, N, certificate=*) + cpdef has_minor(self, N, bint certificate=*) cpdef has_line_minor(self, k, hyperlines=*) cpdef _has_line_minor(self, k, hyperlines) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 5229bebbb89..2eb1a393803 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1101,7 +1101,7 @@ cdef class Matroid(SageObject): import minor_matroid return minor_matroid.MinorMatroid(self, contractions, deletions) - cpdef _has_minor(self, N, certificate=False): + cpdef _has_minor(self, N, bint certificate=False): """ Test if matroid has the specified minor, and optionally return frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. @@ -1125,7 +1125,8 @@ cdef class Matroid(SageObject): sage: M._has_minor(matroids.Uniform(2, 4)) True sage: M._has_minor(matroids.Uniform(2, 4), certificate=True) - (True, (frozenset({'a', 'c'}), frozenset({'b', 'e'}))) + (True, (frozenset({'a', 'c'}), frozenset({'b', 'e'}), + {0: 'h', 1: 'd', 2: 'g', 3: 'f'})) .. TODO:: @@ -3898,7 +3899,7 @@ cdef class Matroid(SageObject): return self._extension(l, [])._minor(contractions=frozenset([l]), deletions=frozenset([])) - cpdef has_minor(self, N, certificate=False): + cpdef has_minor(self, N, bint certificate=False): """ Check if ``self`` has a minor isomorphic to ``N``, and optionally return frozensets ``X`` and ``Y`` so that ``N`` is isomorphic to ``self.minor(X, Y)``. @@ -3932,7 +3933,8 @@ cdef class Matroid(SageObject): sage: matroids.named_matroids.NonFano().has_minor(M) True sage: matroids.named_matroids.NonFano().has_minor(M, certificate=True) - (True, (frozenset(), frozenset({'g'}))) + (True, (frozenset(), frozenset({'g'}), + {0: 'b', 1: 'c', 2: 'a', 3: 'd', 4: 'e', 5: 'f'})) """ if not isinstance(N, Matroid): raise ValueError("N must be a matroid.") From a8150a534f8531fb4eb0afeef233a86cc5b3f1c9 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Tue, 14 Jun 2016 10:15:46 +0200 Subject: [PATCH 036/135] 18709: fix import --- src/sage/rings/cfinite_sequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/cfinite_sequence.py b/src/sage/rings/cfinite_sequence.py index 86ee472bfb8..5244cfcd1dc 100644 --- a/src/sage/rings/cfinite_sequence.py +++ b/src/sage/rings/cfinite_sequence.py @@ -811,7 +811,7 @@ def closed_form(self): True """ from sage.symbolic.ring import SR - from sage.rings.arith import lcm, binomial + from sage.arith.all import lcm, binomial __, parts = (self.ogf()).partial_fraction_decomposition() cm = lcm([part.factor().unit().denominator() for part in parts]) expr = SR(0) From e8c5b4e1fdb1c4708f300d361daee941ef490c33 Mon Sep 17 00:00:00 2001 From: Tara Fife Date: Thu, 14 Jul 2016 17:32:35 -0500 Subject: [PATCH 037/135] Fixed return when we test if a matroid has itself as a minor. --- src/sage/matroids/matroid.pyx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 2eb1a393803..4fc3fad7cc0 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1135,7 +1135,7 @@ cdef class Matroid(SageObject): """ if self is N: if certificate: - return True, None + return True, (frozenset(), frozenset(), {x: x for x in self.groundset()}) return True rd = self.full_rank() - N.full_rank() cd = self.full_corank() - N.full_corank() @@ -3935,6 +3935,12 @@ cdef class Matroid(SageObject): sage: matroids.named_matroids.NonFano().has_minor(M, certificate=True) (True, (frozenset(), frozenset({'g'}), {0: 'b', 1: 'c', 2: 'a', 3: 'd', 4: 'e', 5: 'f'})) + sage: M = matroids.named_matroids.Fano() + sage: M.has_minor(M, True) + (True, + (frozenset(), + frozenset(), + {'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'e': 'e', 'f': 'f', 'g': 'g'})) """ if not isinstance(N, Matroid): raise ValueError("N must be a matroid.") From f5fc535f7ca0a493f7e8b0b33079b8ffbc466fc1 Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Thu, 28 Jul 2016 04:05:59 -0400 Subject: [PATCH 038/135] 21085: blow ups for affine curves --- src/sage/schemes/curves/affine_curve.py | 139 +++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index 551abc30b45..76ea9a9de9f 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -45,7 +45,8 @@ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.schemes.affine.affine_space import is_AffineSpace +from sage.schemes.affine.affine_space import (is_AffineSpace, + AffineSpace) from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme_affine @@ -211,6 +212,142 @@ def multiplicity(self, P): I = R.ideal([f(chng_coords) for f in self.defining_polynomials()]) return singular.mult(singular.std(I)).sage() + def blowup(self, P): + r""" + Return the blow up this affine curve at the point ``P``. + + This curve must be irreducible and its base ring must be a field. Let `C` denote this curve, and let + `n` denote the dimension of the affine ambient space of `C`. Then the blow up of `C` at ``P`` is a + subvariety of the mixed product space `\mathbb{A}^{n}\times\mathbb{P}^{n-1}`. This function describes + the blow up in each of the standard affine charts of the product space. + + INPUT: + + - ``P`` -- a point on this curve. + + OUTPUT: + + - a tuple consisting of two elements. The first element is a list of affine curves that represent + the blow up of this curve at ``P`` in each of the standard affine charts of the mixed product space. + The second element is a list of lists of transition maps between the affine charts such that the + ijth element is the transition map from the ith chart to the jth chart. + + EXAMPLES:: + + sage: A. = AffineSpace(QQ, 2) + sage: C = Curve([y^2 - x^3], A) + sage: Q = A([0,0]) + sage: C.blowup(Q) + ([Affine Plane Curve over Rational Field defined by z1^2 - z0, + Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1], + [[Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0, z1), + Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0*z1, 1/z1)], + [Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0*z1, 1/z1), + Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0, z1)]]) + + :: + + sage: K. = QuadraticField(2) + sage: A. = AffineSpace(K, 3) + sage: C = Curve([(y - 2)^2 - (x + a)^3, z - x - a], A) + sage: Q = A([-a,2,0]) + sage: B = C.blowup(Q) + sage: B[0] + [Affine Curve over Number Field in a with defining polynomial x^2 - 2 + defined by z1^2 - z0 + (-a), z2 - 1, + Affine Curve over Number Field in a with defining polynomial x^2 - 2 + defined by -z0*z1^3 + 2*z1^3 + 1, -z1 + z2, + Affine Curve over Number Field in a with defining polynomial x^2 - 2 + defined by -z0*z1^3 + z2^2, -z1 + 1] + sage: B[1][0][2] + Scheme endomorphism of Affine Space of dimension 3 over Number Field in + a with defining polynomial x^2 - 2 + Defn: Defined on coordinates by sending (z0, z1, z2) to + (z0*z2 + (a)*z2, 1/z2, z1/z2) + sage: B[1][2][0] + Scheme endomorphism of Affine Space of dimension 3 over Number Field in + a with defining polynomial x^2 - 2 + Defn: Defined on coordinates by sending (z0, z1, z2) to + (z0*z1 + (-a), z2/z1, 1/z1) + """ + try: + self(P) + except TypeError: + raise TypeError("(=%s) must be a point on this curve"%P) + if not self.base_ring() in Fields(): + raise TypeError("the base ring of this curve must be a field") + if not self.defining_ideal().is_prime(): + raise TypeError("this curve must be irreducible") + A = self.ambient_space() + n = A.dimension_relative() + R = PolynomialRing(A.base_ring(), 2*n, 'x') + # move the defining polynomials of this curve into R + H = Hom(A.coordinate_ring(), R) + psi = H([R.gens()[i] for i in range(n)]) + n_polys = [psi(f) for f in self.defining_polynomials()] + # the blow up ideal of A at the point P is the ideal generated by + # (x_i - P[i])*x_{j + n} - (x_j - P[j])*x_{i + n} for i != j from 0,...,n-1 + # in the mixed product space of A^n and P^{n-1}. We describe the blow up of + # this curve at P in each affine chart + patches = [] + for i in range(n): + # in this chart, x_{i + n} is assumed to be 1 + # substitute in x_{j} = (x_{i} - P[i])*x_{j + n} + P[j] for each j != i + coords = list(R.gens()) + for j in range(n): + if j != i: + coords[j] = (R.gens()[i] - P[i])*R.gens()[j + n] + P[j] + c_polys = [f(coords) for f in n_polys] + c_A = AffineSpace(R.base_ring(), n, 'z') + H = Hom(R, c_A.coordinate_ring()) + coords = [0]*(2*n) + coords[i] = c_A.gens()[0] + t = 1 + for j in range(n): + if j != i: + coords[j + n] = c_A.gens()[t] + t = t + 1 + else: + coords[j + n] = 1 + psi = H(coords) + c_polys = [psi(f) for f in c_polys] + # remove the component corresponding to the exceptional divisor + for j in range(len(c_polys)): + while (c_A.gens()[0] - P[i]).divides(c_polys[j]): + c_polys[j] = c_A.coordinate_ring()(c_polys[j]/(c_A.gens()[0] - P[i])) + patches.append(c_A.curve(c_polys)) + # create the transition maps between the charts + t_maps = [] + for i in range(n): + maps = [] + for j in range(n): + AA = patches[i].ambient_space() + BB = patches[j].ambient_space() + H = Hom(AA, BB) + vars = AA.gens() + homvars = list(AA.gens()) + homvars.pop(0) + homvars.insert(i, 1) + coords = [(vars[0] - P[i])*homvars[j] + P[j]] + for t in range(n): + if t != j: + coords.append(homvars[t]/homvars[j]) + maps.append(H(coords)) + t_maps.append(maps) + return tuple([patches, t_maps]) + class AffinePlaneCurve(AffineCurve): def __init__(self, A, f): r""" From c09d3b086d3ba180743d7bc02ba150783ca76d4d Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Thu, 28 Jul 2016 16:51:58 -0500 Subject: [PATCH 039/135] Using a dedicated key class instead of non-facade posets. --- src/sage/combinat/posets/moebius_algebra.py | 145 +++++++++++++++----- 1 file changed, 111 insertions(+), 34 deletions(-) diff --git a/src/sage/combinat/posets/moebius_algebra.py b/src/sage/combinat/posets/moebius_algebra.py index 9913d7d02cd..a00f426e99c 100644 --- a/src/sage/combinat/posets/moebius_algebra.py +++ b/src/sage/combinat/posets/moebius_algebra.py @@ -96,27 +96,6 @@ class MoebiusAlgebra(Parent, UniqueRepresentation): European Journal of Combinatorics, **19**, 1998. :doi:`10.1006/eujc.1998.0227`. """ - @staticmethod - def __classcall_private__(cls, R, L): - """ - Normalize input to ensure a unique representation. - - TESTS:: - - sage: L1 = posets.BooleanLattice(4) - sage: L2 = posets.BooleanLattice(4, facade=False) - sage: L1 is L2 - False - sage: M1 = L1.moebius_algebra(QQ) - sage: M2 = L2.moebius_algebra(QQ) - sage: M1 is M2 - True - """ - # We force the lattice to not be a facade in order to guarantee - # that the ordering of the poset is used (see #21054). - L = LatticePoset(L, facade=False) - return super(MoebiusAlgebra, cls).__classcall__(cls, R, L) - def __init__(self, R, L): """ Initialize ``self``. @@ -170,16 +149,7 @@ def lattice(self): sage: M = L.moebius_algebra(QQ) sage: M.lattice() Finite lattice containing 16 elements - - For technical reasons (the defining lattice is forced to be a - non-facade lattice), the result is not equal to ``L``:: - sage: M.lattice() == L - False - - However it is isomorphic:: - - sage: M.lattice().is_isomorphic(L) True """ return self._lattice @@ -290,14 +260,17 @@ def __init__(self, M, prefix='I'): ## Change of basis: E = M.E() + key = lambda x: _Key(M._lattice, x) self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), - triangular='lower', unitriangular=True + triangular='lower', unitriangular=True, + key=key ).register_as_coercion() E.module_morphism(E._to_idempotent_basis, codomain=self, category=self.category(), - triangular='lower', unitriangular=True + triangular='lower', unitriangular=True, + key=key ).register_as_coercion() @@ -576,7 +549,8 @@ def __init__(self, M, prefix='C'): E = M.E() phi = self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), - triangular='lower', unitriangular=True) + triangular='lower', unitriangular=True, + key=lambda x: _Key(M._lattice, x)) phi.register_as_coercion() (~phi).register_as_coercion() @@ -656,7 +630,8 @@ def __init__(self, M, prefix='KL'): E = M.E() phi = self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), - triangular='lower', unitriangular=True) + triangular='lower', unitriangular=True, + key=lambda x: _Key(M._lattice, x)) phi.register_as_coercion() (~phi).register_as_coercion() @@ -785,3 +760,105 @@ def one(self): class ElementMethods: pass +class _Key(object): + """ + Helper class to be a key for the module morphisms of the Möbius algebra + that uses the comparison of the poset. + """ + def __init__(self, P, elt): + """ + sage: from sage.combinat.posets.moebius_algebra import _Key + sage: L = posets.BooleanLattice(4) + sage: K = _Key(L, 5) + sage: isinstance(K, _Key) + True + sage: K._poset is L + True + """ + self._poset = P + self._elt = elt + + def __eq__(self, other): + """ + sage: from sage.combinat.posets.moebius_algebra import _Key + sage: L = posets.BooleanLattice(4) + sage: K1 = _Key(L, 5) + sage: K2 = _Key(L, 5) + sage: K1 == K2 + True + sage: K3 = _Key(L, 8) + sage: K1 == K3 + False + """ + return self._elt == other._elt + + def __ne__(self, other): + """ + sage: from sage.combinat.posets.moebius_algebra import _Key + sage: L = posets.BooleanLattice(4) + sage: K1 = _Key(L, 5) + sage: K2 = _Key(L, 5) + sage: K1 != K2 + False + sage: K3 = _Key(L, 8) + sage: K1 != K3 + True + """ + return self._elt != other._elt + + def __lt__(self, other): + """ + sage: from sage.combinat.posets.moebius_algebra import _Key + sage: L = posets.BooleanLattice(4) + sage: K1 = _Key(L, 1) + sage: K2 = _Key(L, 5) + sage: K1 < K2 + True + sage: K3 = _Key(L, 3) + sage: K3 < K2 + False + """ + return self._poset.lt(self._elt, other._elt) + + def __gt__(self, other): + """ + sage: from sage.combinat.posets.moebius_algebra import _Key + sage: L = posets.BooleanLattice(4) + sage: K1 = _Key(L, 1) + sage: K2 = _Key(L, 5) + sage: K2 > K1 + True + sage: K3 = _Key(L, 3) + sage: K2 > K3 + False + """ + return self._poset.gt(self._elt, other._elt) + + def __le__(self, other): + """ + sage: from sage.combinat.posets.moebius_algebra import _Key + sage: L = posets.BooleanLattice(4) + sage: K1 = _Key(L, 1) + sage: K2 = _Key(L, 5) + sage: K1 <= K2 + True + sage: K3 = _Key(L, 3) + sage: K3 <= K2 + False + """ + return self._poset.le(self._elt, other._elt) + + def __ge__(self, other): + """ + sage: from sage.combinat.posets.moebius_algebra import _Key + sage: L = posets.BooleanLattice(4) + sage: K1 = _Key(L, 1) + sage: K2 = _Key(L, 5) + sage: K2 >= K1 + True + sage: K3 = _Key(L, 3) + sage: K2 >= K3 + False + """ + return self._poset.ge(self._elt, other._elt) + From 499bbe65ec6fd20546c15f815f2a40faf29eb972 Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Thu, 28 Jul 2016 20:36:19 -0500 Subject: [PATCH 040/135] Addressing Darij's comments. --- src/sage/combinat/posets/moebius_algebra.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage/combinat/posets/moebius_algebra.py b/src/sage/combinat/posets/moebius_algebra.py index a00f426e99c..0f50ba85d2f 100644 --- a/src/sage/combinat/posets/moebius_algebra.py +++ b/src/sage/combinat/posets/moebius_algebra.py @@ -764,6 +764,10 @@ class _Key(object): """ Helper class to be a key for the module morphisms of the Möbius algebra that uses the comparison of the poset. + + Because posets are often facades, we need to a way to force the + elements to use the comparison of the poset (the natural order on the + objects may not be a linear extension). """ def __init__(self, P, elt): """ From 872f3c0e21ab0d8608257f980c7ce6867dbcca8b Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Sat, 30 Jul 2016 09:53:25 -0500 Subject: [PATCH 041/135] Fixing pickleability for Moebius algebra morphisms. --- src/sage/combinat/posets/moebius_algebra.py | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/sage/combinat/posets/moebius_algebra.py b/src/sage/combinat/posets/moebius_algebra.py index 0f50ba85d2f..87a9d5b1390 100644 --- a/src/sage/combinat/posets/moebius_algebra.py +++ b/src/sage/combinat/posets/moebius_algebra.py @@ -260,17 +260,16 @@ def __init__(self, M, prefix='I'): ## Change of basis: E = M.E() - key = lambda x: _Key(M._lattice, x) self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), triangular='lower', unitriangular=True, - key=key + key=self._key ).register_as_coercion() E.module_morphism(E._to_idempotent_basis, codomain=self, category=self.category(), triangular='lower', unitriangular=True, - key=key + key=self._key ).register_as_coercion() @@ -550,7 +549,7 @@ def __init__(self, M, prefix='C'): phi = self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), triangular='lower', unitriangular=True, - key=lambda x: _Key(M._lattice, x)) + key=self._key) phi.register_as_coercion() (~phi).register_as_coercion() @@ -631,7 +630,7 @@ def __init__(self, M, prefix='KL'): phi = self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), triangular='lower', unitriangular=True, - key=lambda x: _Key(M._lattice, x)) + key=self._key) phi.register_as_coercion() (~phi).register_as_coercion() @@ -757,6 +756,20 @@ def one(self): R = self.realization_of().a_realization() return self(R.one()) + def _key(self, x): + """ + Generate the key for comparisons in the basis module morphisms. + + EXAMPLES:: + + sage: L = posets.BooleanLattice(4) + sage: M = L.moebius_algebra(QQ) + sage: E = M.E() + sage: type(E._key(5)) + + """ + return _Key(self.realization_of()._lattice, x) + class ElementMethods: pass From 138920133555e167a5776756f39e9ebbcd4cee57 Mon Sep 17 00:00:00 2001 From: Vincent Delecroix <20100.delecroix@gmail.com> Date: Mon, 1 Aug 2016 16:30:34 -0400 Subject: [PATCH 042/135] 21135: fix octave interface for version >= 4.0 --- src/sage/interfaces/octave.py | 90 ++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 11 deletions(-) diff --git a/src/sage/interfaces/octave.py b/src/sage/interfaces/octave.py index cfbbceba3bc..7fa0f39a00c 100644 --- a/src/sage/interfaces/octave.py +++ b/src/sage/interfaces/octave.py @@ -156,6 +156,48 @@ import os from .expect import Expect, ExpectElement +def get_octave_version(command=None, server=None): + r""" + Get the octave version given the ``command`` and ``server``. + + This does *not* launch the interface (since the latter needs configuration + options that actually depend on the version). + + EXAMPLES:: + + sage: from sage.interfaces.octave import get_octave_version + sage: octave.version() # optional - octave # indirect doctest + '...' + """ + import re + from subprocess import Popen, PIPE + + version_string = re.compile("GNU Octave, version (\d+\.\d+\.\d+)") + + if command is None: + raise ValueError("a command must be provided") + + if server: + cmd = [server, command, "--version"] + else: + cmd = [command, "--version"] + + try: + proc = Popen(cmd, stdout=PIPE) + except OSError: + raise ValueError("octave not available") + + s = proc.communicate() + if proc.poll(): + raise ValueError("octave sent a non-zero signal (={})".format(proc.poll())) + + first_line = s[0].split('\n')[0] + m = version_string.match(first_line) + if m is None: + raise ValueError("Octave first line of output does not fit with what " + "was expected:\n{}".format(first_line)) + + return m.group(1) class Octave(Expect): r""" @@ -173,18 +215,35 @@ class Octave(Expect): 'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n\n' """ - def __init__(self, maxread=None, script_subdirectory=None, logfile=None, server=None, server_tmpdir=None, - seed=None): + def __init__(self, maxread=None, script_subdirectory=None, logfile=None, + server=None, server_tmpdir=None, seed=None, command=None): """ EXAMPLES:: sage: octave == loads(dumps(octave)) True """ + if command is None: + import os + command = os.getenv('SAGE_OCTAVE_COMMAND') or 'octave' + if server is None: + import os + server = os.getenv('SAGE_OCTAVE_SERVER') or None + + version = get_octave_version(command=command, server=server) + major = int(version.split('.')[0]) + + if major < 4: + prompt = '>' + options = " --no-line-editing --silent" + else: + prompt = '>>' + options = " --no-gui --no-line-editing --silent" + Expect.__init__(self, name = 'octave', - prompt = '>', - command = "sage-native-execute octave --no-line-editing --silent", + prompt = prompt, + command = command + options, server = server, server_tmpdir = server_tmpdir, script_subdirectory = script_subdirectory, @@ -410,10 +469,14 @@ def version(self): EXAMPLES:: - sage: octave.version() # optional - octave; random output depending on version - '2.1.73' + sage: v = octave.version() # optional - octave + sage: v # optional - octave; random + '2.13.7' + + sage: import re + sage: assert re.match("\d+\.\d+\.\d+", v) is not None # optional - octave """ - return octave_version() + return str(self("version")).strip() def solve_linear_system(self, A, b): r""" @@ -783,11 +846,16 @@ def octave_console(): def octave_version(): """ - Return the version of Octave installed. + DEPRECATED: Return the version of Octave installed. EXAMPLES:: - sage: octave_version() # optional - octave; and output is random - '2.9.12' + sage: octave_version() # optional - octave + doctest:...: DeprecationWarning: This has been deprecated. Use + octave.version() instead + See http://trac.sagemath.org/21135 for details. + '...' """ - return str(octave('version')).strip() + from sage.misc.superseded import deprecation + deprecation(21135, "This has been deprecated. Use octave.version() instead") + return octave.version() From 4ac06e644890058ecba960752e0cab43678bd7ec Mon Sep 17 00:00:00 2001 From: Bill Page Date: Fri, 8 Jan 2016 14:28:00 +0000 Subject: [PATCH 043/135] improved octave interface from https://github.com/billpage/sage-octave without a part in _matrix() that is broken for complex matrices --- src/sage/interfaces/octave.py | 66 ++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/src/sage/interfaces/octave.py b/src/sage/interfaces/octave.py index 7fa0f39a00c..79d1f9f9c94 100644 --- a/src/sage/interfaces/octave.py +++ b/src/sage/interfaces/octave.py @@ -155,6 +155,7 @@ import os from .expect import Expect, ExpectElement +from sage.misc.misc import verbose def get_octave_version(command=None, server=None): r""" @@ -242,8 +243,11 @@ def __init__(self, maxread=None, script_subdirectory=None, logfile=None, Expect.__init__(self, name = 'octave', - prompt = prompt, - command = command + options, + # We want the prompt sequence to be unique to avoid confusion with syntax error messages containing >>> + prompt = 'octave\:\d+> ', + # We don't want any pagination of output + command = "sage-native-execute octave --no-line-editing --silent --eval 'PS2(PS1());more off' --persist", + maxread = maxread, server = server, server_tmpdir = server_tmpdir, script_subdirectory = script_subdirectory, @@ -330,6 +334,57 @@ def _install_hints(self): octave starts up. * Darwin ports and fink have Octave as well. """ + def _eval_line(self, line, reformat=True, allow_use_file=False, + wait_for_prompt=True, restart_if_needed=False): + """ + EXAMPLES:: + + sage: print(octave._eval_line('2+2')) #optional - octave + ans = 4 + """ + if not wait_for_prompt: + return Expect._eval_line(self, line) + if line == '': + return '' + if self._expect is None: + self._start() + if allow_use_file and len(line)>3000: + return self._eval_line_using_file(line) + try: + E = self._expect + # debug + # self._synchronize(cmd='1+%s\n') + verbose("in = '%s'"%line,level=3) + E.sendline(line) + E.expect(self._prompt) + out = E.before + # debug + verbose("out = '%s'"%out,level=3) + except EOF: + if self._quit_string() in line: + return '' + except KeyboardInterrupt: + self._keyboard_interrupt() + if reformat: + if 'syntax error' in out: + raise SyntaxError(out) + out = "\n".join(out.splitlines()[1:]) + return out + + def _keyboard_interrupt(self): + print("CntrlC: Interrupting %s..."%self) + if self._restart_on_ctrlc: + try: + self._expect.close(force=1) + except pexpect.ExceptionPexpect as msg: + raise pexpect.ExceptionPexpect( "THIS IS A BUG -- PLEASE REPORT. This should never happen.\n" + msg) + self._start() + raise KeyboardInterrupt("Restarting %s (WARNING: all variables defined in previous session are now invalid)"%self) + else: + self._expect.send('\003') # control-c + #self._expect.expect(self._prompt) + #self._expect.expect(self._prompt) + raise KeyboardInterrupt("Ctrl-c pressed while running %s"%self) def quit(self, verbose=False): """ @@ -408,7 +463,7 @@ def set(self, var, value): """ cmd = '%s=%s;'%(var,value) out = self.eval(cmd) - if out.find("error") != -1: + if out.find("error") != -1 or out.find("Error") != -1: raise TypeError("Error executing code in Octave\nCODE:\n\t%s\nOctave ERROR:\n\t%s"%(cmd, out)) def get(self, var): @@ -686,8 +741,11 @@ def _matrix_(self, R=None): sage: matrix(ZZ, A) # optional - octave [1 2] [3 4] + sage: A = octave('[1,2;3,4.5]') # optional - octave + sage: matrix(RR, A) # optional - octave + [1.00000000000000 2.00000000000000] + [3.00000000000000 4.50000000000000] """ - oc = self.parent() if not self.ismatrix(): raise TypeError('not an octave matrix') if R is None: From 70e2c125ad26e98e53d5f50bc9cafda93605bd92 Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Tue, 2 Aug 2016 22:14:37 +0100 Subject: [PATCH 044/135] update docs, ensure clean exit (so that sage-cleaner exists cleanly) --- src/sage/interfaces/octave.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/sage/interfaces/octave.py b/src/sage/interfaces/octave.py index 79d1f9f9c94..367fb1f1736 100644 --- a/src/sage/interfaces/octave.py +++ b/src/sage/interfaces/octave.py @@ -318,20 +318,13 @@ def _install_hints(self): from Sage. You can read all about Octave at http://www.gnu.org/software/octave/ - LINUX / WINDOWS (colinux): - Do apt-get install octave as root on your machine - (or, in Windows, in the colinux console). + LINUX: + Do apt-get install octave as root on your machine (Ubuntu/Debian). + Other Linux systems have octave too. OS X: - * This website has links to binaries for OS X PowerPC - and OS X Intel builds of the latest version of Octave: - http://hpc.sourceforge.net/ - Once you get the tarball from there, go to the / directory - and type - tar zxvf octave-intel-bin.tar.gz - to extract it to usr/local/... Make sure /usr/local/bin - is in your PATH. Then type "octave" and verify that - octave starts up. + * This website has details on OS X builds of Octave: + http://wiki.octave.org/Octave_for_MacOS_X * Darwin ports and fink have Octave as well. """ def _eval_line(self, line, reformat=True, allow_use_file=False, @@ -342,6 +335,7 @@ def _eval_line(self, line, reformat=True, allow_use_file=False, sage: print(octave._eval_line('2+2')) #optional - octave ans = 4 """ + from pexpect.exceptions import EOF if not wait_for_prompt: return Expect._eval_line(self, line) if line == '': @@ -365,11 +359,14 @@ def _eval_line(self, line, reformat=True, allow_use_file=False, return '' except KeyboardInterrupt: self._keyboard_interrupt() - if reformat: - if 'syntax error' in out: - raise SyntaxError(out) - out = "\n".join(out.splitlines()[1:]) - return out + try: + if reformat: + if 'syntax error' in out: + raise SyntaxError(out) + out = "\n".join(out.splitlines()[1:]) + return out + except NameError: + return '' def _keyboard_interrupt(self): print("CntrlC: Interrupting %s..."%self) From e01d07511d6e6f2bd870313fa365374355bf06f4 Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Tue, 2 Aug 2016 23:57:05 +0100 Subject: [PATCH 045/135] use octave-cli and the cleanup as suggested; fix octave_console() note that octave (version 4.0.1) actually launches octave-gui and this is not we want anyway. octave-cli does the right thing. The latter is available for versions 3 and 4, an so we do not need to figure out versions at __init__. --- src/sage/interfaces/octave.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/sage/interfaces/octave.py b/src/sage/interfaces/octave.py index 367fb1f1736..5de29046428 100644 --- a/src/sage/interfaces/octave.py +++ b/src/sage/interfaces/octave.py @@ -226,7 +226,7 @@ def __init__(self, maxread=None, script_subdirectory=None, logfile=None, """ if command is None: import os - command = os.getenv('SAGE_OCTAVE_COMMAND') or 'octave' + command = os.getenv('SAGE_OCTAVE_COMMAND') or 'octave-cli' if server is None: import os server = os.getenv('SAGE_OCTAVE_SERVER') or None @@ -246,7 +246,7 @@ def __init__(self, maxread=None, script_subdirectory=None, logfile=None, # We want the prompt sequence to be unique to avoid confusion with syntax error messages containing >>> prompt = 'octave\:\d+> ', # We don't want any pagination of output - command = "sage-native-execute octave --no-line-editing --silent --eval 'PS2(PS1());more off' --persist", + command = command + options + " --eval 'PS2(PS1());more off' --persist", maxread = maxread, server = server, server_tmpdir = server_tmpdir, @@ -327,6 +327,7 @@ def _install_hints(self): http://wiki.octave.org/Octave_for_MacOS_X * Darwin ports and fink have Octave as well. """ + def _eval_line(self, line, reformat=True, allow_use_file=False, wait_for_prompt=True, restart_if_needed=False): """ @@ -374,13 +375,11 @@ def _keyboard_interrupt(self): try: self._expect.close(force=1) except pexpect.ExceptionPexpect as msg: - raise pexpect.ExceptionPexpect( "THIS IS A BUG -- PLEASE REPORT. This should never happen.\n" + msg) + raise RuntimeError( "THIS IS A BUG -- PLEASE REPORT. This should never happen.\n" + msg) self._start() raise KeyboardInterrupt("Restarting %s (WARNING: all variables defined in previous session are now invalid)"%self) else: self._expect.send('\003') # control-c - #self._expect.expect(self._prompt) - #self._expect.expect(self._prompt) raise KeyboardInterrupt("Ctrl-c pressed while running %s"%self) def quit(self, verbose=False): @@ -896,7 +895,7 @@ def octave_console(): from sage.repl.rich_output.display_manager import get_display_manager if not get_display_manager().is_in_terminal(): raise RuntimeError('Can use the console only in the terminal. Try %%octave magics instead.') - os.system('octave') + os.system('octave-cli') def octave_version(): From 56e4fb38f47ee24a88a2752393cf2a0b16eead0b Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Wed, 3 Aug 2016 16:53:26 -0500 Subject: [PATCH 046/135] Using the Hasse diagram's promise that 0..n is a linear extension. --- src/sage/combinat/posets/moebius_algebra.py | 139 +++----------------- 1 file changed, 15 insertions(+), 124 deletions(-) diff --git a/src/sage/combinat/posets/moebius_algebra.py b/src/sage/combinat/posets/moebius_algebra.py index 87a9d5b1390..e3329df71cd 100644 --- a/src/sage/combinat/posets/moebius_algebra.py +++ b/src/sage/combinat/posets/moebius_algebra.py @@ -251,6 +251,17 @@ def __init__(self, M, prefix='I'): sage: L = posets.BooleanLattice(4) sage: M = L.moebius_algebra(QQ) sage: TestSuite(M.I()).run() + + Check that the transition maps can be pickled:: + + sage: L = posets.BooleanLattice(4) + sage: M = L.moebius_algebra(QQ) + sage: E = M.E() + sage: I = M.I() + sage: phi = E.coerce_map_from(I) + sage: loads(dumps(phi)) + Generic morphism: + ... """ self._basis_name = "idempotent" CombinatorialFreeModule.__init__(self, M.base_ring(), @@ -263,13 +274,13 @@ def __init__(self, M, prefix='I'): self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), triangular='lower', unitriangular=True, - key=self._key + key=M._lattice._element_to_vertex ).register_as_coercion() E.module_morphism(E._to_idempotent_basis, codomain=self, category=self.category(), triangular='lower', unitriangular=True, - key=self._key + key=M._lattice._element_to_vertex ).register_as_coercion() @@ -549,7 +560,7 @@ def __init__(self, M, prefix='C'): phi = self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), triangular='lower', unitriangular=True, - key=self._key) + key=M._lattice._element_to_vertex) phi.register_as_coercion() (~phi).register_as_coercion() @@ -630,7 +641,7 @@ def __init__(self, M, prefix='KL'): phi = self.module_morphism(self._to_natural_basis, codomain=E, category=self.category(), triangular='lower', unitriangular=True, - key=self._key) + key=M._lattice._element_to_vertex) phi.register_as_coercion() (~phi).register_as_coercion() @@ -756,126 +767,6 @@ def one(self): R = self.realization_of().a_realization() return self(R.one()) - def _key(self, x): - """ - Generate the key for comparisons in the basis module morphisms. - - EXAMPLES:: - - sage: L = posets.BooleanLattice(4) - sage: M = L.moebius_algebra(QQ) - sage: E = M.E() - sage: type(E._key(5)) - - """ - return _Key(self.realization_of()._lattice, x) - class ElementMethods: pass -class _Key(object): - """ - Helper class to be a key for the module morphisms of the Möbius algebra - that uses the comparison of the poset. - - Because posets are often facades, we need to a way to force the - elements to use the comparison of the poset (the natural order on the - objects may not be a linear extension). - """ - def __init__(self, P, elt): - """ - sage: from sage.combinat.posets.moebius_algebra import _Key - sage: L = posets.BooleanLattice(4) - sage: K = _Key(L, 5) - sage: isinstance(K, _Key) - True - sage: K._poset is L - True - """ - self._poset = P - self._elt = elt - - def __eq__(self, other): - """ - sage: from sage.combinat.posets.moebius_algebra import _Key - sage: L = posets.BooleanLattice(4) - sage: K1 = _Key(L, 5) - sage: K2 = _Key(L, 5) - sage: K1 == K2 - True - sage: K3 = _Key(L, 8) - sage: K1 == K3 - False - """ - return self._elt == other._elt - - def __ne__(self, other): - """ - sage: from sage.combinat.posets.moebius_algebra import _Key - sage: L = posets.BooleanLattice(4) - sage: K1 = _Key(L, 5) - sage: K2 = _Key(L, 5) - sage: K1 != K2 - False - sage: K3 = _Key(L, 8) - sage: K1 != K3 - True - """ - return self._elt != other._elt - - def __lt__(self, other): - """ - sage: from sage.combinat.posets.moebius_algebra import _Key - sage: L = posets.BooleanLattice(4) - sage: K1 = _Key(L, 1) - sage: K2 = _Key(L, 5) - sage: K1 < K2 - True - sage: K3 = _Key(L, 3) - sage: K3 < K2 - False - """ - return self._poset.lt(self._elt, other._elt) - - def __gt__(self, other): - """ - sage: from sage.combinat.posets.moebius_algebra import _Key - sage: L = posets.BooleanLattice(4) - sage: K1 = _Key(L, 1) - sage: K2 = _Key(L, 5) - sage: K2 > K1 - True - sage: K3 = _Key(L, 3) - sage: K2 > K3 - False - """ - return self._poset.gt(self._elt, other._elt) - - def __le__(self, other): - """ - sage: from sage.combinat.posets.moebius_algebra import _Key - sage: L = posets.BooleanLattice(4) - sage: K1 = _Key(L, 1) - sage: K2 = _Key(L, 5) - sage: K1 <= K2 - True - sage: K3 = _Key(L, 3) - sage: K3 <= K2 - False - """ - return self._poset.le(self._elt, other._elt) - - def __ge__(self, other): - """ - sage: from sage.combinat.posets.moebius_algebra import _Key - sage: L = posets.BooleanLattice(4) - sage: K1 = _Key(L, 1) - sage: K2 = _Key(L, 5) - sage: K2 >= K1 - True - sage: K3 = _Key(L, 3) - sage: K2 >= K3 - False - """ - return self._poset.ge(self._elt, other._elt) - From 1aa31cfc9509132b0684479ed2f9535163bceea1 Mon Sep 17 00:00:00 2001 From: Kevin Lui Date: Thu, 4 Aug 2016 22:26:02 -0700 Subject: [PATCH 047/135] added an() method to newforms --- src/sage/modular/modform/element.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/sage/modular/modform/element.py b/src/sage/modular/modform/element.py index b5d1c19782c..404734e795d 100644 --- a/src/sage/modular/modform/element.py +++ b/src/sage/modular/modform/element.py @@ -1190,6 +1190,32 @@ def hecke_eigenvalue_field(self): """ return self.__hecke_eigenvalue_field + def an(self, n): + """ + Return the coefficient of `q^n` in the power series of self. + + INPUT: + + - ``n`` - a positive integer + + OUTPUT: + + - the coefficient of `q^n` in the power series of self. + + EXAMPLES:: + + sage: f = Newforms(11)[0]; f + q - 2*q^2 - q^3 + 2*q^4 + q^5 + O(q^6) + sage: f.an(100) + -8 + + sage: g = Newforms(23, names='a')[0]; g + q + a0*q^2 + (-2*a0 - 1)*q^3 + (-a0 - 1)*q^4 + 2*a0*q^5 + O(q^6) + sage: g.an(3) + -2*a0 - 1 + """ + return self.modular_symbols(1).eigenvalue(n, self._name()) + def _compute(self, X): """ Compute the coefficients of `q^n` of the power series of self, From e5fc48064b490ac4e4bdc432885b38c0eaea3e27 Mon Sep 17 00:00:00 2001 From: Kevin Lui Date: Fri, 5 Aug 2016 01:13:22 -0700 Subject: [PATCH 048/135] changed name from an to coefficient --- src/sage/modular/modform/element.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/modular/modform/element.py b/src/sage/modular/modform/element.py index 404734e795d..470a880feb6 100644 --- a/src/sage/modular/modform/element.py +++ b/src/sage/modular/modform/element.py @@ -1190,7 +1190,7 @@ def hecke_eigenvalue_field(self): """ return self.__hecke_eigenvalue_field - def an(self, n): + def coefficient(self, n): """ Return the coefficient of `q^n` in the power series of self. @@ -1206,12 +1206,12 @@ def an(self, n): sage: f = Newforms(11)[0]; f q - 2*q^2 - q^3 + 2*q^4 + q^5 + O(q^6) - sage: f.an(100) + sage: f.coefficient(100) -8 sage: g = Newforms(23, names='a')[0]; g q + a0*q^2 + (-2*a0 - 1)*q^3 + (-a0 - 1)*q^4 + 2*a0*q^5 + O(q^6) - sage: g.an(3) + sage: g.coefficient(3) -2*a0 - 1 """ return self.modular_symbols(1).eigenvalue(n, self._name()) From 729390469e49f31ba2d5576c165797fcca2ce354 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Sat, 6 Aug 2016 08:28:11 +0200 Subject: [PATCH 049/135] 16166: factorial(...) fails for some arguments --- src/sage/functions/other.py | 6 ++++++ src/sage/symbolic/pynac.pyx | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py index 312ed1c3e61..4dec42b3032 100644 --- a/src/sage/functions/other.py +++ b/src/sage/functions/other.py @@ -1601,6 +1601,12 @@ def __init__(self): sage: (factorial(x) == y).solve(x) [factorial(x) == y] + Check that :trac:`16166` is fixed:: + + sage: RBF=RealBallField(53) + sage: factorial(RBF(4.2)) + [32.5780960503313 +/- 6.71e-14] + Test pickling:: sage: loads(dumps(factorial)) diff --git a/src/sage/symbolic/pynac.pyx b/src/sage/symbolic/pynac.pyx index fbe7306a603..fe7ee534b35 100644 --- a/src/sage/symbolic/pynac.pyx +++ b/src/sage/symbolic/pynac.pyx @@ -1340,7 +1340,7 @@ cdef object py_factorial(object x) except +: try: x_in_ZZ = ZZ(x) coercion_success = True - except TypeError: + except (TypeError, ValueError): coercion_success = False if coercion_success and x_in_ZZ >= 0: From a1b0b8d5369562bd122032af825bcdbd82ccb776 Mon Sep 17 00:00:00 2001 From: Salvatore Stella Date: Sat, 6 Aug 2016 20:18:22 +0200 Subject: [PATCH 050/135] Now only making the minimum changes to fix coercions --- .../rings/polynomial/laurent_polynomial.pyx | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index 0d3c29bd7e4..269e32144c5 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1331,26 +1331,29 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): TESTS:: Check that :trac:`19538` is fixed - - sage: R = LaurentPolynomialRing(ZZ, 'x', 4) - sage: S = LaurentPolynomialRing(ZZ, 'x0,x1') - sage: S.inject_variables() - Defining x0, x1 - sage: x0 in R - True + + sage: R = LaurentPolynomialRing(QQ,'x2,x0') + sage: S = LaurentPolynomialRing(QQ,'x',3) + sage: f = S.coerce_map_from(R) + sage: f(R.gen(0) + R.gen(1)^2) + x0^2 + x2 + sage: _.parent() + Multivariate Laurent Polynomial Ring in x0, x1, x2 over Rational Field """ if isinstance(x, LaurentPolynomial_mpair): - inject_dict = {} - for y in x.variables(): - x_index = x.parent().gens().index(y) - name = x.parent().variable_names()[x_index] - inject_dict[parent.variable_names().index(name)] = x_index - tmp_x = x.dict() - x = dict() - n = int(parent.ngens()) - for k in tmp_x.keys(): - img_k = ETuple(dict([(a,k[inject_dict[a]]) for a in inject_dict.keys()]),n) - x[img_k] = tmp_x[k] + # check if parent contains all the generators of x.parent() for coercions + try: + inject_dict = dict(enumerate([parent.variable_names().index(v) for v in x.parent().variable_names()])) + tmp_x = x.dict() + x = dict() + n = int(parent.ngens()) + m = len(inject_dict) + for k in tmp_x.keys(): + img_k = ETuple(dict([(inject_dict[a],k[a]) for a in xrange(m)]),n) + x[img_k] = tmp_x[k] + # otherwise just pass along a dict for conversions + except: + x = x.dict() elif isinstance(x, PolyDict): x = x.dict() if isinstance(x, dict): From 848759e44c63903327e635d656563d6686c9f32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 8 Aug 2016 16:58:33 +0200 Subject: [PATCH 051/135] remove all \atop and \choose (as deprecated latex) --- .../thematic_tutorials/lie/branching_rules.rst | 4 ++-- .../thematic_tutorials/linear_programming.rst | 4 ++-- src/sage/coding/delsarte_bounds.py | 2 +- src/sage/combinat/combinat.py | 2 +- src/sage/combinat/sloane_functions.py | 17 +++++++---------- src/sage/functions/orthogonal_polys.py | 2 +- src/sage/graphs/generic_graph.py | 2 +- src/sage/graphs/graph.py | 2 +- src/sage/matroids/basis_matroid.pyx | 2 +- src/sage/matroids/circuit_closures_matroid.pyx | 2 +- .../modular/pollack_stevens/padic_lseries.py | 4 ++-- .../hypellfrob/hypellfrob.cpp | 4 ++-- .../hyperelliptic_curves/monsky_washnitzer.py | 2 +- src/sage/schemes/projective/projective_space.py | 2 +- src/sage/tensor/modules/ext_pow_free_module.py | 4 ++-- .../tensor/modules/finite_rank_free_module.py | 2 +- 16 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/doc/en/thematic_tutorials/lie/branching_rules.rst b/src/doc/en/thematic_tutorials/lie/branching_rules.rst index 92db628dc93..bd16ca3db87 100644 --- a/src/doc/en/thematic_tutorials/lie/branching_rules.rst +++ b/src/doc/en/thematic_tutorials/lie/branching_rules.rst @@ -641,8 +641,8 @@ Symmetric powers ---------------- The `k`-th symmetric and exterior power homomorphisms map -`GL(n) \to GL \left({n+k-1 \choose k} \right)` and -`GL \left({n \choose k} \right)`. The corresponding branching rules +`GL(n) \to GL \left(\binom{n+k-1}{k} \right)` and +`GL \left(\binom{n}{k} \right)`. The corresponding branching rules are not implemented but a special case is. The `k`-th symmetric power homomorphism `SL(2) \to GL(k+1)` has its image inside of `SO(2r+1)` if `k = 2r` and inside of `Sp(2r)` if `k = 2r-1`. Hence there are diff --git a/src/doc/en/thematic_tutorials/linear_programming.rst b/src/doc/en/thematic_tutorials/linear_programming.rst index 63b96676910..d51174291b7 100644 --- a/src/doc/en/thematic_tutorials/linear_programming.rst +++ b/src/doc/en/thematic_tutorials/linear_programming.rst @@ -319,7 +319,7 @@ the matching, which is a linear constraint. We will be solving: .. MATH:: \text{Max: } & \sum_{e \in E(G)} m_e\\ - \text{Such that: } & \forall v, \sum_{e \in E(G) \atop v \sim e} m_e \leq 1 + \text{Such that: } & \forall v, \sum_{\substack{e \in E(G) \\ v \sim e}} m_e \leq 1 Let us write the Sage code of this MILP:: @@ -385,7 +385,7 @@ following LP .. MATH:: \text{Max: } & \sum_{sv \in G} f_{sv}\\ - \text{Such that: } & \forall v \in G, {v \neq s \atop v \neq t}, \sum_{vu \in G} f_{vu} - \sum_{uv \in G} f_{uv} = 0\\ + \text{Such that: } & \forall v \in G, {\substack{v \neq s \\ v \neq t}}, \sum_{vu \in G} f_{vu} - \sum_{uv \in G} f_{uv} = 0\\ & \forall uv \in G, f_{uv} \leq 1\\ We will solve the flow problem on an orientation of Chvatal's diff --git a/src/sage/coding/delsarte_bounds.py b/src/sage/coding/delsarte_bounds.py index 934c215c6c6..69c1c806f37 100644 --- a/src/sage/coding/delsarte_bounds.py +++ b/src/sage/coding/delsarte_bounds.py @@ -29,7 +29,7 @@ def Krawtchouk(n,q,l,x,check=True): .. math:: - K^{n,q}_l(x)=\sum_{j=0}^l (-1)^j(q-1)^{(l-j)}{x \choose j}{n-x \choose l-j}, + K^{n,q}_l(x)=\sum_{j=0}^l (-1)^j(q-1)^{(l-j)}\binom{x}{j}\binom{n-x}{l-j}, INPUT: diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 351bc222c05..98c1db4a3e2 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -417,7 +417,7 @@ def catalan_number(n): .. MATH:: - C_n = \frac{1}{n+1}{2n\choose n} = \frac{(2n)!}{(n+1)!\,n!} + C_n = \frac{1}{n+1}\binom{2n}{n} = \frac{(2n)!}{(n+1)!\,n!} \qquad\mbox{ for }\quad n\ge 0. diff --git a/src/sage/combinat/sloane_functions.py b/src/sage/combinat/sloane_functions.py index 162ff0e9f9e..c2508ff4897 100644 --- a/src/sage/combinat/sloane_functions.py +++ b/src/sage/combinat/sloane_functions.py @@ -879,7 +879,7 @@ class A007318(SloaneSequence): def __init__(self): r""" Pascal's triangle read by rows: - `C(n,k) = {n \choose k} = \frac {n!} {(k!(n-k)!)}`, + `C(n,k) = \binom{n}{k} = \frac {n!} {(k!(n-k)!)}`, `0 \le k \le n`. INPUT: @@ -4195,21 +4195,18 @@ class A000108(SloaneSequence): def __init__(self): r""" Catalan numbers: - `C_n = \frac{{{2n}\choose{n}}}{n+1} = \frac {(2n)!}{n!(n+1)!}`. + `C_n = \frac{\binom{2n}{n}}{n+1} = \frac{(2n)!}{n!(n+1)!}`. + Also called Segner numbers. INPUT: - - ``n`` - non negative integer - OUTPUT: - - ``integer`` - function value - EXAMPLES:: sage: a = sloane.A000108;a @@ -5120,7 +5117,7 @@ class A000984(SloaneSequence): def __init__(self): r""" Central binomial coefficients: - `2n \choose n = \frac {(2n)!} {(n!)^2}`. + `\binom{2n}{n} = \frac {(2n)!} {(n!)^2}`. INPUT: @@ -5175,7 +5172,7 @@ class A001405(SloaneSequence): def __init__(self): r""" Central binomial coefficients: - `n \choose \lfloor \frac {n}{ 2} \rfloor`. + `\binom{n}{\lfloor \frac {n}{ 2} \rfloor}`. INPUT: @@ -5231,7 +5228,7 @@ class A000292(SloaneSequence): def __init__(self): r""" Tetrahedral (or pyramidal) numbers: - `{n+2} \choose 3 = n(n+1)(n+2)/6`. + `\binom{n+2}{3} = n(n+1)(n+2)/6`. INPUT: @@ -6578,7 +6575,7 @@ def _eval(self, n): class A000217(SloaneSequence): def __init__(self): r""" - Triangular numbers: `a(n) = {n+1} \choose 2) = n(n+1)/2`. + Triangular numbers: `a(n) = \binom{n+1}{2}) = n(n+1)/2`. INPUT: diff --git a/src/sage/functions/orthogonal_polys.py b/src/sage/functions/orthogonal_polys.py index 20f0f98493c..6c147c68bde 100644 --- a/src/sage/functions/orthogonal_polys.py +++ b/src/sage/functions/orthogonal_polys.py @@ -189,7 +189,7 @@ .. math:: - P_n^{(\alpha,\beta)} (z) = \frac{\Gamma (\alpha+n+1)}{n!\Gamma (\alpha+\beta+n+1)} \sum_{m=0}^n {n\choose m} \frac{\Gamma (\alpha + \beta + n + m + 1)}{\Gamma (\alpha + m + 1)} \left(\frac{z-1}{2}\right)^m . + P_n^{(\alpha,\beta)} (z) = \frac{\Gamma (\alpha+n+1)}{n!\Gamma (\alpha+\beta+n+1)} \sum_{m=0}^n \binom{n}{m} \frac{\Gamma (\alpha + \beta + n + m + 1)}{\Gamma (\alpha + m + 1)} \left(\frac{z-1}{2}\right)^m . diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 5b871052141..bb94d5886e9 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -11939,7 +11939,7 @@ def subgraph_search_count(self, G, induced=False): 0 If we count instead the number of `T_3` in `T_5`, we expect - the answer to be `{5 \choose 3}`:: + the answer to be `\binom{5}{3}`:: sage: T3 = T5.subgraph([0,1,2]) sage: T5.subgraph_search_count(T3) diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 899d1b7ca1c..f8c1f025fd2 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -6735,7 +6735,7 @@ def kirchhoff_symanzik_polynomial(self, name='t'): .. MATH:: - \Psi_G(t) = \sum_{T\subseteq V\\atop{\\text{a spanning tree}}} \prod_{e \\not\in E(T)} t_e + \Psi_G(t) = \sum_{\substack{T\subseteq V \\ \text{a spanning tree}}} \prod_{e \\not\in E(T)} t_e This is also called the first Symanzik polynomial or the Kirchhoff polynomial. diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index 89574bf5168..f34dbfdf2ee 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -348,7 +348,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): ALGORITHM: A BasisMatroid on `n` elements and of rank `r` is stored as a - bitvector of length `n \choose r`. The `i`-th bit in this vector + bitvector of length `\binom{n}{r}`. The `i`-th bit in this vector indicates that the `i`-th `r`-set in the lexicographic enumeration of `r`-subsets of the groundset is a basis. Reversing this bitvector yields a bitvector that indicates whether the complement of an diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 20ece775885..df2dfcf6884 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -78,7 +78,7 @@ cdef class CircuitClosuresMatroid(Matroid): As each independent set of size `k` is in at most one closure(`C`) of rank `k`, and each closure(`C`) of rank `k` contains at least `k + 1` - independent sets of size `k`, there are at most `{n \choose k}/(k + 1)` + independent sets of size `k`, there are at most `\binom{n}{k}/(k + 1)` such closures-of-circuits of rank `k`. Each closure(`C`) takes `O(n)` bits to store, giving an upper bound of `O(2^n)` on the space complexity of the entire matroid. diff --git a/src/sage/modular/pollack_stevens/padic_lseries.py b/src/sage/modular/pollack_stevens/padic_lseries.py index 32b3d8a935c..ce1056121cf 100644 --- a/src/sage/modular/pollack_stevens/padic_lseries.py +++ b/src/sage/modular/pollack_stevens/padic_lseries.py @@ -363,7 +363,7 @@ def _basic_integral(self, a, j): def log_gamma_binomial(p, gamma, z, n, M): r""" Return the list of coefficients in the power series - expansion (up to precision `M`) of `{\log_p(z)/\log_p(\gamma) \choose n}` + expansion (up to precision `M`) of `\binom{\log_p(z)/\log_p(\gamma)}{n}` INPUT: @@ -376,7 +376,7 @@ def log_gamma_binomial(p, gamma, z, n, M): OUTPUT: The list of coefficients in the power series expansion of - `{\log_p(z)/\log_p(\gamma) \choose n}` + `\binom{\log_p(z)/\log_p(\gamma)}{n}` EXAMPLES:: diff --git a/src/sage/schemes/hyperelliptic_curves/hypellfrob/hypellfrob.cpp b/src/sage/schemes/hyperelliptic_curves/hypellfrob/hypellfrob.cpp index 1e43990dfad..1e60c2ea26b 100644 --- a/src/sage/schemes/hyperelliptic_curves/hypellfrob/hypellfrob.cpp +++ b/src/sage/schemes/hyperelliptic_curves/hypellfrob/hypellfrob.cpp @@ -457,7 +457,7 @@ int matrix(mat_ZZ& output, const ZZ& p, int N, const ZZX& Q, int force_ntl) } // For 0 <= j < N, compute Btemp[j] = - // (-1)^j \sum_{k=j}^{N-1} 4^{-k} {2k \choose k} {k \choose j} + // (-1)^j \sum_{k=j}^{N-1} 4^{-k} {2k choose k} {k choose j} ZZ_p fourth = to_ZZ_p(1) / 4; ZZ_p fourth_pow = to_ZZ_p(1); vector Btemp(N); @@ -472,7 +472,7 @@ int matrix(mat_ZZ& output, const ZZ& p, int N, const ZZX& Q, int force_ntl) } // Compute the coefficients B_{j, r} = p C_{j, r} (-1)^j - // \sum_{k=j}^{N-1} 4^{-k} {2k \choose k} {k \choose j}, + // \sum_{k=j}^{N-1} 4^{-k} {2k choose k} {k choose j}, // where C_{j, r} is the coefficient of x^r in Q(x)^j. vector > B(N); ZZ_pX Qpow = to_ZZ_pX(p); diff --git a/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py b/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py index bf405eb3cdb..54e03e331dd 100644 --- a/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py +++ b/src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py @@ -1236,7 +1236,7 @@ def frobenius_expansion_by_series(Q, p, M): .. math:: - F0 = \sum_{k=0}^{M-2} {-1/2 \choose k} p x^{p-1} E^k T^{(M-2-k)p} + F0 = \sum_{k=0}^{M-2} \binom{-1/2}{k} p x^{p-1} E^k T^{(M-2-k)p} and diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index 068f20fa5ce..928655e8999 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -449,7 +449,7 @@ def _linear_system_as_kernel(self, d, pt, m): OUTPUT: - A matrix of size `{m-1+n \choose n}` x `{d+n \choose n}` where n is the + A matrix of size `\binom{m-1+n}{n}` x `\binom{d+n}{n}` where n is the relative dimension of self. The base ring of the matrix is a ring that contains the base ring of self and the coefficients of the given point. diff --git a/src/sage/tensor/modules/ext_pow_free_module.py b/src/sage/tensor/modules/ext_pow_free_module.py index 72b8349109b..9c0f044c3f3 100644 --- a/src/sage/tensor/modules/ext_pow_free_module.py +++ b/src/sage/tensor/modules/ext_pow_free_module.py @@ -14,7 +14,7 @@ that vanish whenever any of two of their arguments are equal. Note that `\Lambda^1(M^*) = M^*` (the dual of `M`). -`\Lambda^p(M^*)` is a free module of rank `\left({n\atop p}\right)` over `R`, +`\Lambda^p(M^*)` is a free module of rank `\binom{n}{p}` over `R`, where `n` is the rank of `M`. Accordingly, exterior powers of free modules are implemented by a class, :class:`ExtPowerFreeModule`, which inherits from the class @@ -62,7 +62,7 @@ class ExtPowerFreeModule(FiniteRankFreeModule): that vanish whenever any of two of their arguments are equal. Note that `\Lambda^1(M^*) = M^*` (the dual of `M`). - `\Lambda^p(M^*)` is a free module of rank `\left({n\atop p}\right)` over + `\Lambda^p(M^*)` is a free module of rank `\binom{n}{p}` over `R`, where `n` is the rank of `M`. Accordingly, the class :class:`ExtPowerFreeModule` inherits from the class :class:`~sage.tensor.modules.finite_rank_free_module.FiniteRankFreeModule`. diff --git a/src/sage/tensor/modules/finite_rank_free_module.py b/src/sage/tensor/modules/finite_rank_free_module.py index c6633ee49d1..b20e3a20f3b 100644 --- a/src/sage/tensor/modules/finite_rank_free_module.py +++ b/src/sage/tensor/modules/finite_rank_free_module.py @@ -967,7 +967,7 @@ def dual_exterior_power(self, p): \longrightarrow R that vanish whenever any of two of their arguments are equal. - `\Lambda^p(M^*)` is a free module of rank `\left({n\atop p}\right)` + `\Lambda^p(M^*)` is a free module of rank `\binom{n}{p}` over the same ring as `M`, where `n` is the rank of `M`. INPUT: From 0659590941803923118ab0fbecb001b41bb6e328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 8 Aug 2016 22:05:05 +0200 Subject: [PATCH 052/135] trac 21193 detail --- src/sage/combinat/sloane_functions.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/sage/combinat/sloane_functions.py b/src/sage/combinat/sloane_functions.py index c2508ff4897..c43c0fb8b62 100644 --- a/src/sage/combinat/sloane_functions.py +++ b/src/sage/combinat/sloane_functions.py @@ -6575,20 +6575,16 @@ def _eval(self, n): class A000217(SloaneSequence): def __init__(self): r""" - Triangular numbers: `a(n) = \binom{n+1}{2}) = n(n+1)/2`. + Triangular numbers: `a(n) = \binom{n+1}{2} = n(n+1)/2`. INPUT: - - ``n`` - non negative integer - OUTPUT: - - ``integer`` - function value - EXAMPLES:: sage: a = sloane.A000217;a From 7811cac99f07aa1ce7bd2f829075f7c2539a4b0e Mon Sep 17 00:00:00 2001 From: Armin Straub Date: Mon, 8 Aug 2016 21:32:45 -0500 Subject: [PATCH 053/135] 18709: rewrite and simplify closed_form, supporting multiple roots --- src/sage/rings/cfinite_sequence.py | 94 ++++++++++-------------------- 1 file changed, 31 insertions(+), 63 deletions(-) diff --git a/src/sage/rings/cfinite_sequence.py b/src/sage/rings/cfinite_sequence.py index e678acadcff..232fe16b0a8 100644 --- a/src/sage/rings/cfinite_sequence.py +++ b/src/sage/rings/cfinite_sequence.py @@ -764,7 +764,7 @@ def series(self, n): R = LaurentSeriesRing(QQ, 'x', default_prec=n) return R(self.ogf()) - def closed_form(self): + def closed_form(self, n = 'n'): """ Return a symbolic expression in ``n`` that maps ``n`` to the n-th member of the sequence. @@ -810,72 +810,40 @@ def closed_form(self): sage: all(_.subs(n==i).simplify_full()==fibonacci(i) for i in range(10)) True """ + from sage.arith.all import binomial + from sage.rings.qqbar import QQbar + from sage.symbolic.ring import SR - from sage.arith.all import lcm, binomial - __, parts = (self.ogf()).partial_fraction_decomposition() - cm = lcm([part.factor().unit().denominator() for part in parts]) + n = SR(n) expr = SR(0) + + R = FractionField(PolynomialRing(QQbar, self.parent().variable_name())) + ogf = R(self.ogf()) + + __, parts = ogf.partial_fraction_decomposition() for part in parts: - denom = part.denominator() - num = part.numerator() - f = denom.factor() - assert len(f) == 1 - denom_base = f[0][0] - denom_exp = f[0][1] - cc_denom = denom.constant_coefficient() - denom = denom/cc_denom - num = num/cc_denom - cc_denom_base = denom_base.constant_coefficient() - denom_base = denom_base/cc_denom_base - dl = denom_base.list() - term = SR(0) - n = SR.var('n') - can_simplify = True - - if len(dl) == 2: - constant_factor = num - if dl[1] == -1: - term = SR(constant_factor) - else: - term = SR(constant_factor)*SR(-dl[1])**n - if denom_exp > 1: - term *= binomial(n+denom_exp-1, denom_exp-1) - elif len(dl) == 3 and denom_exp == 1: - from sage.functions.other import sqrt - a0 = self[0] - a1 = self[1] - c = -dl[1] - d = -dl[2] - r1 = 2*d/(-c+sqrt(c**2+4*d)) - r2 = 2*d/(-c-sqrt(c**2+4*d)) - term = ((a1-c*a0+a0*r1)*r1**n-(a1-c*a0+a0*r2)*r2**n)/sqrt(c**2+4*d) - elif denom_exp == 1: - from operator import add, mul - from sage.rings.qqbar import QQbar - from sage.matrix.constructor import Matrix - deg = len(dl)-1 - num_coeffs = num.coefficients(sparse=False) - num_coeffs += [0] * (deg - len(num_coeffs)) - can_simplify = False - R = PolynomialRing(QQbar, 'X') - X = R.gen() - roots = denom_base.roots(QQbar) - full_prod = reduce(mul, [X-r for (r,_) in roots], 1) - prods = [full_prod/(X-roots[i][0]) for i in range(deg)] - m = Matrix(QQbar, [[prods[j].numerator().list(X)[i] - for j in range(deg)] for i in range(deg)]) - rv = m.inverse() * Matrix(QQbar, deg, 1, num_coeffs) - for i in range(deg): - c = rv[i][0] - c.exactify() - term += SR(c/roots[i][0]) * SR(1/roots[i][0])**n - else: - return [] + denom = part.denominator().factor() + denom_base, denom_exp = denom[0] + + # If the partial fraction decomposition was done correctly, there + # is only one factor, of degree 1, and monic. + assert len(denom) == 1 and len(denom_base.list()) == 2 and denom_base.list()[1] == 1 + + # this part is of the form a/(x+b)^{m+1} + a = QQbar(part.numerator()) / denom.unit() + m = denom_exp - 1 + b = denom_base.constant_coefficient() + + # term = a*SR(1/b)**(m+1)*SR(-1/b)**(n) + c = SR((a*(1/b)**(m+1)).radical_expression()) + r = SR((-1/b).radical_expression()) + term = c * r**n + if m > 0: + term *= binomial(n+m, m) + expr += term - if can_simplify: - return expr.simplify_full() - else: - return expr + + return expr class CFiniteSequences_generic(CommutativeRing, UniqueRepresentation): From 5a046fe8c581a3e29894ba50706efc82e2af7462 Mon Sep 17 00:00:00 2001 From: Kiran Kedlaya Date: Tue, 9 Aug 2016 12:41:55 +0000 Subject: [PATCH 054/135] Correct doctest formatting --- .../hyperelliptic_curves/hyperelliptic_finite_field.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index cf4d6e3e56c..869946a4d9f 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -523,6 +523,7 @@ def frobenius_polynomial(self): x^4 + 2*x^3 - 58*x^2 + 202*x + 10201 Over prime fields of odd characteristic, `f` may have even degree:: + sage: H = HyperellipticCurve(t^6 + 27*t + 3) sage: H.frobenius_polynomial() x^4 + 25*x^3 + 322*x^2 + 2525*x + 10201 @@ -1130,10 +1131,11 @@ def count_points(self, n=1): sage: H.count_points(6) [2, 24, 74, 256, 1082, 4272] - This example shows that ticket #20391 is resolved: + This example shows that :trac:`20391` is resolved: + sage: x = polygen(GF(4099)) sage: H = HyperellipticCurve(x^6 + x + 1) - sage: H.count_points(1) + sage: H.count_points(1) [4106] """ K = self.base_ring() From c814597edef29a03cb1ae787fb484d2e84dcc461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 10 Aug 2016 09:10:05 +0200 Subject: [PATCH 055/135] trac #18916 reviewer's commit (details) --- .../hyperelliptic_curves/hyperelliptic_finite_field.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index 699a3015182..06c3b88897d 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -424,7 +424,7 @@ def frobenius_polynomial_matrix(self, M=None, algorithm='hypellfrob'): def frobenius_polynomial_pari(self): r""" Compute the charpoly of frobenius, as an element of `\ZZ[x]`, - by calling the PARI function hyperellcharpoly. + by calling the PARI function ``hyperellcharpoly``. EXAMPLES:: @@ -547,9 +547,11 @@ def frobenius_polynomial(self): g = self.genus() f, h = self.hyperelliptic_polynomials() - if e == 1 and q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and h==0 and f.degree() %2 == 1: + if (e == 1 and + q >= (2*g+1)*(2*self._frobenius_coefficient_bound_charpoly()-1) and + h == 0 and f.degree() % 2): return self.frobenius_polynomial_matrix() - elif q%2 == 1: + elif q % 2 == 1: return self.frobenius_polynomial_pari() else: return self.frobenius_polynomial_cardinalities() @@ -1132,7 +1134,7 @@ def count_points(self, n=1): sage: H.count_points(6) [2, 24, 74, 256, 1082, 4272] - This example shows that :trac:`20391` is resolved: + This example shows that :trac:`20391` is resolved:: sage: x = polygen(GF(4099)) sage: H = HyperellipticCurve(x^6 + x + 1) From b923e361515f8fceb9d9cc62075ef763c05eba25 Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Thu, 11 Aug 2016 06:13:40 -0400 Subject: [PATCH 056/135] 21085: update the affine blow up function. --- src/sage/schemes/curves/affine_curve.py | 99 ++++++++++++++----------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index 76ea9a9de9f..25396eda8de 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -212,35 +212,31 @@ def multiplicity(self, P): I = R.ideal([f(chng_coords) for f in self.defining_polynomials()]) return singular.mult(singular.std(I)).sage() - def blowup(self, P): + def blowup(self): r""" - Return the blow up this affine curve at the point ``P``. + Return the blow up of this affine curve at the origin. - This curve must be irreducible and its base ring must be a field. Let `C` denote this curve, and let - `n` denote the dimension of the affine ambient space of `C`. Then the blow up of `C` at ``P`` is a - subvariety of the mixed product space `\mathbb{A}^{n}\times\mathbb{P}^{n-1}`. This function describes - the blow up in each of the standard affine charts of the product space. - - INPUT: - - - ``P`` -- a point on this curve. + An error is returned if the origin is not a point on this curve. The blow up is described + by affine charts. OUTPUT: - - a tuple consisting of two elements. The first element is a list of affine curves that represent - the blow up of this curve at ``P`` in each of the standard affine charts of the mixed product space. - The second element is a list of lists of transition maps between the affine charts such that the - ijth element is the transition map from the ith chart to the jth chart. + - a tuple consisting of three elements. The first is a tuple of curves in affine space of + the same dimension as the ambient space of this subscheme, which define the blow up in + each affine chart. The second is a tuple of tuples such that the jth element of the ith + tuple is the transition map from the ith affine patch to the jth affine patch. Lastly, + the third element is a tuple consisting of the restrictions of the projection map from + the blow up back to the original subscheme, restricted to each affine patch. There the + ith element will be the projection from the ith affine patch. EXAMPLES:: sage: A. = AffineSpace(QQ, 2) sage: C = Curve([y^2 - x^3], A) - sage: Q = A([0,0]) - sage: C.blowup(Q) - ([Affine Plane Curve over Rational Field defined by z1^2 - z0, - Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1], - [[Scheme endomorphism of Affine Space of dimension 2 over Rational + sage: C.blowup() + ((Affine Plane Curve over Rational Field defined by z1^2 - z0, + Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1), + ([Scheme endomorphism of Affine Space of dimension 2 over Rational Field Defn: Defined on coordinates by sending (z0, z1) to (z0, z1), @@ -255,60 +251,67 @@ def blowup(self, P): Scheme endomorphism of Affine Space of dimension 2 over Rational Field Defn: Defined on coordinates by sending (z0, z1) to - (z0, z1)]]) + (z0, z1)]), + (Scheme morphism: + From: Affine Plane Curve over Rational Field defined by z1^2 - z0 + To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + Defn: Defined on coordinates by sending (z0, z1) to + (z0, z0*z1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1 + To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + Defn: Defined on coordinates by sending (z0, z1) to + (z0*z1, z0))) :: sage: K. = QuadraticField(2) sage: A. = AffineSpace(K, 3) - sage: C = Curve([(y - 2)^2 - (x + a)^3, z - x - a], A) - sage: Q = A([-a,2,0]) - sage: B = C.blowup(Q) + sage: C = Curve([y^2 - a*x^5, x - z], A) + sage: B = C.blowup() sage: B[0] - [Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by z1^2 - z0 + (-a), z2 - 1, - Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by -z0*z1^3 + 2*z1^3 + 1, -z1 + z2, - Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by -z0*z1^3 + z2^2, -z1 + 1] + (Affine Curve over Number Field in a with defining polynomial x^2 - 2 + defined by (-a)*z0^3 + z1^2, -z2 + 1, Affine Curve over Number Field in + a with defining polynomial x^2 - 2 defined by (-a)*z0^3*z1^5 + 1, z1 - + z2, Affine Curve over Number Field in a with defining polynomial x^2 - 2 + defined by (-a)*z0^3*z1^5 + z2^2, z1 - 1) sage: B[1][0][2] Scheme endomorphism of Affine Space of dimension 3 over Number Field in a with defining polynomial x^2 - 2 Defn: Defined on coordinates by sending (z0, z1, z2) to - (z0*z2 + (a)*z2, 1/z2, z1/z2) + (z0*z2, 1/z2, z1/z2) sage: B[1][2][0] Scheme endomorphism of Affine Space of dimension 3 over Number Field in a with defining polynomial x^2 - 2 Defn: Defined on coordinates by sending (z0, z1, z2) to - (z0*z1 + (-a), z2/z1, 1/z1) + (z0*z1, z2/z1, 1/z1) """ + A = self.ambient_space() + n = A.dimension_relative() try: - self(P) + self([0]*n) except TypeError: - raise TypeError("(=%s) must be a point on this curve"%P) + raise TypeError("the origin must be a point on this curve") if not self.base_ring() in Fields(): raise TypeError("the base ring of this curve must be a field") if not self.defining_ideal().is_prime(): raise TypeError("this curve must be irreducible") - A = self.ambient_space() - n = A.dimension_relative() R = PolynomialRing(A.base_ring(), 2*n, 'x') # move the defining polynomials of this curve into R H = Hom(A.coordinate_ring(), R) psi = H([R.gens()[i] for i in range(n)]) n_polys = [psi(f) for f in self.defining_polynomials()] - # the blow up ideal of A at the point P is the ideal generated by - # (x_i - P[i])*x_{j + n} - (x_j - P[j])*x_{i + n} for i != j from 0,...,n-1 + # the blow up ideal of A at the origin is the ideal generated by + # x_i*x_{j + n} - x_j*x_{i + n} for i != j from 0,...,n-1 # in the mixed product space of A^n and P^{n-1}. We describe the blow up of - # this curve at P in each affine chart + # this curve at the origin in each affine chart patches = [] for i in range(n): # in this chart, x_{i + n} is assumed to be 1 - # substitute in x_{j} = (x_{i} - P[i])*x_{j + n} + P[j] for each j != i + # substitute in x_{j} = x_{i}*x_{j + n} for each j != i coords = list(R.gens()) for j in range(n): if j != i: - coords[j] = (R.gens()[i] - P[i])*R.gens()[j + n] + P[j] + coords[j] = R.gens()[i]*R.gens()[j + n] c_polys = [f(coords) for f in n_polys] c_A = AffineSpace(R.base_ring(), n, 'z') H = Hom(R, c_A.coordinate_ring()) @@ -325,8 +328,8 @@ def blowup(self, P): c_polys = [psi(f) for f in c_polys] # remove the component corresponding to the exceptional divisor for j in range(len(c_polys)): - while (c_A.gens()[0] - P[i]).divides(c_polys[j]): - c_polys[j] = c_A.coordinate_ring()(c_polys[j]/(c_A.gens()[0] - P[i])) + while c_A.gens()[0].divides(c_polys[j]): + c_polys[j] = c_A.coordinate_ring()(c_polys[j]/c_A.gens()[0]) patches.append(c_A.curve(c_polys)) # create the transition maps between the charts t_maps = [] @@ -340,13 +343,21 @@ def blowup(self, P): homvars = list(AA.gens()) homvars.pop(0) homvars.insert(i, 1) - coords = [(vars[0] - P[i])*homvars[j] + P[j]] + coords = [vars[0]*homvars[j]] for t in range(n): if t != j: coords.append(homvars[t]/homvars[j]) maps.append(H(coords)) t_maps.append(maps) - return tuple([patches, t_maps]) + # create the restrictions of the projection map + proj_maps = [] + for i in range(n): + p_A = patches[i].ambient_space() + H = Hom(patches[i], self) + coords = [p_A.gens()[0]*p_A.gens()[j] for j in range(1,n)] + coords.insert(i, p_A.gens()[0]) + proj_maps.append(H(coords)) + return tuple([tuple(patches), tuple(t_maps), tuple(proj_maps)]) class AffinePlaneCurve(AffineCurve): def __init__(self, A, f): From c80277a2ea1663d4803e4974985f829d27d5259c Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Thu, 11 Aug 2016 14:11:00 +0200 Subject: [PATCH 057/135] Make sure the WINDOWS64_ABI flag is set on Cygwin as well, otherwise the assembly routines use the wrong calling convention. See https://trac.sagemath.org/ticket/21223 --- build/pkgs/ecm/patches/cygwin.patch | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 build/pkgs/ecm/patches/cygwin.patch diff --git a/build/pkgs/ecm/patches/cygwin.patch b/build/pkgs/ecm/patches/cygwin.patch new file mode 100644 index 00000000000..5afe8cb952e --- /dev/null +++ b/build/pkgs/ecm/patches/cygwin.patch @@ -0,0 +1,26 @@ +Make sure the assembly routines use the appropriate calling convention +for Windows in Cygwin as well. See https://trac.sagemath.org/ticket/21223 +diff -ruN a/configure b/configure +--- a/configure 2016-08-11 13:51:46.936572300 +0200 ++++ b/configure 2016-08-11 13:53:31.281801500 +0200 +@@ -12957,7 +12957,7 @@ + + + case $host in +- *-*-mingw32) ++ *-*-mingw32|*cygwin*) + echo 'define(, <1>)' >>$gmp_tmpconfigm4 + + +diff -ruN a/configure.in b/configure.in +--- a/configure.in 2016-08-11 13:51:46.869520300 +0200 ++++ b/configure.in 2016-08-11 13:52:46.240830400 +0200 +@@ -256,7 +256,7 @@ + GMP_ASM_TYPE + + case $host in +- *-*-mingw32) GMP_DEFINE([WINDOWS64_ABI], 1) ++ *-*-mingw32|*cygwin*) GMP_DEFINE([WINDOWS64_ABI], 1) + AC_DEFINE([WINDOWS64_ABI], 1,[Define to 1 if x86_64 mulredc*() functions should be called with Windows ABI]);; + *) ;; + esac From 6361e6cdac8484964b9e952f5b482b986113aaee Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Thu, 11 Aug 2016 15:21:00 +0200 Subject: [PATCH 058/135] Bump patch level --- build/pkgs/ecm/package-version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pkgs/ecm/package-version.txt b/build/pkgs/ecm/package-version.txt index 49df80bfeb4..ca08977a763 100644 --- a/build/pkgs/ecm/package-version.txt +++ b/build/pkgs/ecm/package-version.txt @@ -1 +1 @@ -6.4.4 +6.4.4.p0 From 3dd26e7cd33ac155e9d102952701b26c2d6f5b99 Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Fri, 12 Aug 2016 03:05:44 -0400 Subject: [PATCH 059/135] 21085: resolution of singularities implementation, first attempt --- src/sage/schemes/curves/affine_curve.py | 251 +++++++++++++++++++++++- 1 file changed, 244 insertions(+), 7 deletions(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index b7afedaedaf..b4d83f19e07 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -35,7 +35,8 @@ from __future__ import absolute_import from sage.categories.fields import Fields -from sage.categories.homset import Hom +from sage.categories.number_fields import NumberFields +from sage.categories.homset import Hom, End from sage.interfaces.all import singular import sage.libs.singular @@ -44,6 +45,7 @@ from sage.rings.all import degree_lowest_rational_function from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing +from sage.rings.qqbar import number_field_elements_from_algebraics, QQbar from sage.schemes.affine.affine_space import (is_AffineSpace, AffineSpace) @@ -150,10 +152,6 @@ def projective_closure(self, i=0, PP=None): from .constructor import Curve return Curve(AlgebraicScheme_subscheme_affine.projective_closure(self, i, PP)) -class AffinePlaneCurve(AffineCurve): - - _point = point.AffinePlaneCurvePoint_field - def blowup(self): r""" Return the blow up of this affine curve at the origin. @@ -164,11 +162,11 @@ def blowup(self): OUTPUT: - a tuple consisting of three elements. The first is a tuple of curves in affine space of - the same dimension as the ambient space of this subscheme, which define the blow up in + the same dimension as the ambient space of this curve, which define the blow up in each affine chart. The second is a tuple of tuples such that the jth element of the ith tuple is the transition map from the ith affine patch to the jth affine patch. Lastly, the third element is a tuple consisting of the restrictions of the projection map from - the blow up back to the original subscheme, restricted to each affine patch. There the + the blow up back to the original curve, restricted to each affine patch. There the ith element will be the projection from the ith affine patch. EXAMPLES:: @@ -301,6 +299,245 @@ def blowup(self): proj_maps.append(H(coords)) return tuple([tuple(patches), tuple(t_maps), tuple(proj_maps)]) + def resolution_of_singularities(self, extend=False): + r""" + Return a nonsingular model for this affine curve created by blowing up its singular points. + + The nonsingular model is given as a collection of affine patches that cover it. If ``extend`` is ``False`` + and if the base field is a number field, or if the base field is a finite field, the model returned may have + singularities with coordinates not contained in the base field. + + INPUT: + + - ``extend`` -- (default: False) specifies whether to extend the base field when necessary to find all + singular points when this curve is defined over a number field. If ``extend`` is ``False``, then only + singularities with coordinates in the base field of this curve will be resolved. However, setting + ``extend`` to ``True`` will slow down computations. + + OUTPUT: + + - a tuple consisting of three elements. The first is a tuple of curves in affine space of + the same dimension as the ambient space of this curve, which represent affine patches + of the resolution of singularities. The second is a tuple of tuples such that the jth + element of the ith tuple is the transition map from the ith patch to the jth patch. Lastly, + the third element is a tuple consisting of birational maps from the patches back to the + original curve that were created by composing the projection maps generated from the blow up + computations. There the ith element will be a map from the ith patch. + + EXAMPLES:: + + sage: A. = AffineSpace(QQ, 2) + sage: C = Curve([y^2 - x^3], A) + sage: C.resolution_of_singularities() + ((Affine Plane Curve over Rational Field defined by z1^2 - z0, + Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1), + ((Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0, z1), + Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0*z1, 1/z1)), + (Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0*z1, 1/z1), + Scheme endomorphism of Affine Space of dimension 2 over Rational + Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0, z1))), + (Scheme morphism: + From: Affine Plane Curve over Rational Field defined by z1^2 - z0 + To: Affine Space of dimension 2 over Rational Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0, z0*z1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1 + To: Affine Space of dimension 2 over Rational Field + Defn: Defined on coordinates by sending (z0, z1) to + (z0*z1, z0))) + + :: + + sage: set_verbose(-1) + sage: K. = QuadraticField(3) + sage: A. = AffineSpace(K, 2) + sage: C = Curve([(x^2 + y^2 - y - 2)*(y - x^2 + 2) + a*y^3], A) + sage: R = C.resolution_of_singularities(True) # long time (3 seconds) + sage: R[0] + (Affine Plane Curve over Number Field in a with defining polynomial y^4 + - 4*y^2 + 1 defined by (a^2 - 1)*z0^2*z1^3 - z0^2*z1^2 + (-4*a)*z0*z1^3 + + (2*a^3 - 6*a)*z0*z1^2 - z1^2 + 2*z1 - 1, Affine Plane Curve over + Number Field in a with defining polynomial y^4 - 4*y^2 + 1 defined by + -z0^2*z1^2 + (a^2 - 1)*z0^2*z1 + (2*a^3 - 6*a)*z0*z1 - z1^2 + (-4*a)*z0 + + 2*z1 - 1, Affine Plane Curve over Number Field in a with defining + polynomial y^4 - 4*y^2 + 1 defined by -z0^2*z1^4 - z0^2*z1^2 + (-4*a^3 + + 12*a)*z0*z1^3 + 2*z0*z1^2 + (-2*a^3 + 6*a)*z0*z1 - 8*z1^2 + (a^2 - 1)*z0 + + (4*a^3 - 12*a)*z1 - 1) + + :: + + sage: A. = AffineSpace(GF(5), 3) + sage: C = Curve([y - x^3, (z - 2)^2 - y^3 - x^3], A) + sage: R = C.resolution_of_singularities() + sage: R[0] + (Affine Curve over Finite Field of size 5 defined by -z0^2 + z1, + -z0*z1^3 + z2^2 - z0, + Affine Curve over Finite Field of size 5 defined by -z0^2*z1^3 + 1, + -z0*z1^3 + z2^2 - z0, + Affine Curve over Finite Field of size 5 defined by -z0^2*z1^3 + z2, + -z0*z1^3 - z0*z2^3 + 1) + """ + # helper function for extending the base field (in the case of working over a number field) + def extension(self): + psi = self.base_ring().embeddings(QQbar)[0] + pts = self.change_ring(psi).rational_points() + L = [pt[j] for j in range(len(self.ambient_space().gens())) for pt in pts] + L.extend([psi(g) for g in self.base_ring().gens()]) + K = number_field_elements_from_algebraics(L)[0] + return [K, self.base_ring().embeddings(K)[0]] + # find the set of singular points of this curve + # in the case that the base field is a number field, extend it as needed (if extend == True) + C = self + n = C.ambient_space().dimension_relative() + if C.base_ring() in NumberFields() and extend: + C = C.change_ring(extension(C.singular_subscheme())[1]) + H = End(C.ambient_space()) + placeholder = H(C.ambient_space().gens()) + # the list res holds the data for the patches of the resolution of singularities + # each element is a list consisting of the curve defining the patch, a list + # of the transition maps from that patch to the other patches, a projection + # map from the patch to the original curve, and the set of singular points + # of the patch + res = [[C, [placeholder], placeholder, C.singular_points()]] + not_resolved = True + t = 0 + # loop through the patches and blow up each until no patch has singular points + while not_resolved: + [BC, t_maps, pi, pts] = [res[t][0], res[t][1], res[t][2], res[t][3]] + # check if there are any singular points in this patch + if len(pts) == 0: + t = t + 1 + if t == len(res): + not_resolved = False + continue + # the identity map should be replaced for each of the charts of the blow up + t_maps.pop(t) + # translate pts[0] to the origin + H = End(BC.ambient_space()) + # translation map and inverse + phi = H([BC.ambient_space().gens()[i] - pts[0][i] for i in range(n)]) + phi_inv = H([BC.ambient_space().gens()[i] + pts[0][i] for i in range(n)]) + # create the translated curve + BC = BC.ambient_space().curve([f(phi_inv.defining_polynomials()) for f in BC.defining_polynomials()]) + # translate the singular points + pts = [phi(BC.ambient_space()(pts[i])) for i in range(len(pts))] + # blow up the origin + B = list(BC.blowup()) + B = [list(B[0]), [list(B[1][i]) for i in range(len(B[1]))], list(B[2])] + # the t-th element of res will be replaced with the new data corresponding to the charts + # of the blow up + res.pop(t) + # take out the transition maps from the other resolution patches to the t-th patch + old_maps = [res[i][1].pop(t) for i in range(len(res))] + patches_to_add = [] + # generate the needed data for each patch of the blow up + for i in range(len(B[0])): + # check if there are any singular points where this patch meets the exceptional divisor + AA = AffineSpace(B[0][i].base_ring(), n - 1, 'x') + coords = [0] + coords.extend(list(AA.gens())) + H = Hom(B[0][i].ambient_space().coordinate_ring(), AA.coordinate_ring()) + poly_hom = H(coords) + X = AA.subscheme([poly_hom(f) for f in B[0][i].defining_polynomials()]) + # in the case of working over a number field, it might be necessary to extend the base + # field in order to find all intersection points + if B[0][i].base_ring() in NumberFields() and extend: + emb = extension(X)[1] + # coerce everything to the new base field + phi = phi.change_ring(emb) + phi_inv = phi_inv.change_ring(emb) + BC = BC.change_ring(emb) + t_maps = [t_maps[j].change_ring(emb) for j in range(len(t_maps))] + old_maps = [old_maps[j].change_ring(emb) for j in range(len(old_maps))] + pi = pi.change_ring(emb) + pts = [pt.change_ring(emb) for pt in pts] + # coerce the current blow up data + X = X.change_ring(emb) + for j in range(len(B[0])): + B[0][j] = B[0][j].change_ring(emb) + for j in range(len(B[1])): + for k in range(len(B[1])): + B[1][j][k] = B[1][j][k].change_ring(emb) + for j in range(len(B[2])): + B[2][j] = B[2][j].change_ring(emb) + # coerce the other data in res + for j in range(len(res)): + res[j][0] = res[j][0].change_ring(emb) + for k in range(len(res[j][1])): + res[j][1][k] = res[j][1][k].change_ring(emb) + res[j][2].change_ring(emb) + for k in range(len(res[j][3])): + res[j][3][k] = res[j][3][k].change_ring(emb) + b_data = [] + # add the curve that defines this patch + b_data.append(B[0][i]) + # compose the current transition maps from the original curve to the other patches + # with the projection map + H = Hom(B[0][i].ambient_space(), BC.ambient_space()) + t_pi = H([phi_inv.defining_polynomials()[j](B[2][i].defining_polynomials()) for j in range(n)]) + coords = [BC.ambient_space().gens()[j]/BC.ambient_space().gens()[i] for j in range(n)] + coords.pop(i) + coords.insert(0, BC.ambient_space().gens()[i]) + H = Hom(BC.ambient_space(), B[0][i].ambient_space()) + tmp_pi_inv = H(coords) + t_pi_inv = H([tmp_pi_inv.defining_polynomials()[j](phi.defining_polynomials()) for j in range(n)]) + L = list(t_maps) + for j in range(len(t_maps)): + H = Hom(B[0][i].ambient_space(), L[j].codomain()) + L[j] = H([L[j].defining_polynomials()[k](t_pi.defining_polynomials()) for k in range(n)]) + for j in range(len(B[1][i])): + L.insert(t + j, B[1][i][j]) + b_data.append(L) + # update transition maps of each other element of res + for j in range(len(res)): + H = Hom(res[j][0].ambient_space(), B[0][i].ambient_space()) + new_t_map = H([t_pi_inv.defining_polynomials()[k](old_maps[j].defining_polynomials()) for k in\ + range(n)]) + res[j][1].insert(t + i, new_t_map) + # create the projection map + tmp_pi = B[2][i] + H = Hom(tmp_pi.domain(), pi.codomain()) + coords = [phi_inv.defining_polynomials()[j](tmp_pi.defining_polynomials()) for j in range(n)] + coords = [pi.defining_polynomials()[j](coords) for j in range(n)] + b_data.append(H(coords)) + # singular points + # translate the singular points of the parent patch (other than that which was the center of the + # blow up) by the inverse of the first projection map + n_pts = [] + for j in range(1, len(pts)): + # make sure this point is in this chart before attempting to map it + if pts[j][i] != 0: + n_pts.append(tmp_pi_inv(pts[j])) + # add in the points found from the exceptional divisor + for pt in X.rational_points(): + tmp_pt = B[0][i].ambient_space()([0] + list(pt)) + if B[0][i].is_singular(tmp_pt): + n_pts.append(tmp_pt) + b_data.append(n_pts) + patches_to_add.append(b_data) + for i in range(len(patches_to_add)): + res.insert(t + i, patches_to_add[i]) + t = 0 + patches = [res[i][0] for i in range(len(res))] + t_maps = [tuple(res[i][1]) for i in range(len(res))] + p_maps = [res[i][2] for i in range(len(res))] + return tuple([tuple(patches), tuple(t_maps), tuple(p_maps)]) + +class AffinePlaneCurve(AffineCurve): + + _point = point.AffinePlaneCurvePoint_field + def __init__(self, A, f): r""" Initialization function. From ba0f74f44b525c22fc3e28b6dca8e8490dea57a2 Mon Sep 17 00:00:00 2001 From: Armin Straub Date: Fri, 12 Aug 2016 08:18:30 -0500 Subject: [PATCH 060/135] 16671: fixed some doc strings --- src/sage/functions/log.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 2490ff6cfd4..8a0139eb3a3 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -904,11 +904,13 @@ def _eval_(self, z): class Function_harmonic_number_generalized(BuiltinFunction): r""" Harmonic and generalized harmonic number functions, - defined by + defined by: .. math:: - H_{n}=H_{n,1}=\sum_{k=1}^n\frac1k,\qquad H_{n,m}=\sum_{k=1}^n\frac1{k^m} + H_{n}=H_{n,1}=\sum_{k=1}^n\frac1k + + H_{n,m}=\sum_{k=1}^n\frac1{k^m} They are also well-defined for complex argument, through: @@ -919,7 +921,7 @@ class Function_harmonic_number_generalized(BuiltinFunction): H_{s,m}=\zeta(m)-\zeta(m,s-1) If called with a single argument, that argument is ``s`` and ``m`` is - assumed to be 1 (the normal harmonic numbers ``H_m``). + assumed to be 1 (the normal harmonic numbers ``H_s``). ALGORITHM: @@ -1035,10 +1037,6 @@ def _eval_(self, z, m): 0.386627621982332 sage: harmonic_number(3,5/2) 1/27*sqrt(3) + 1/8*sqrt(2) + 1 - sage: harmonic_number(Qp(5)(10),1) - 4*5^-1 + 2 + 2*5 + 4*5^2 + 3*5^3 + 5^4 + ... - sage: harmonic_number(Qp(5)(10),2) - 4*5^-1 + 3 + 5 + 3*5^2 + 2*5^3 + 3*5^5 + ... """ if m == 0: return z @@ -1167,7 +1165,7 @@ def _swap_harmonic(a,b): return harmonic_number(b,a) class Function_harmonic_number(BuiltinFunction): r""" - Harmonic number function, defined by + Harmonic number function, defined by: .. math:: @@ -1207,8 +1205,6 @@ def _eval_(self, z, **kwds): -2*log(2) + 46/15 sage: harmonic_number(2*x) harmonic_number(2*x) - sage: harmonic_number(Qp(5)(3)) - 1 + 5 + 4*5^2 + 4*5^4 + 4*5^6 + ... """ from sage.symbolic.ring import SR P = s_parent(z) From 4a6bfbfe819f427ec1485b8b1e8ea0a704af6682 Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Sat, 13 Aug 2016 05:37:01 -0400 Subject: [PATCH 061/135] 21085: some minor changes - used the compositions of morphisms functionality from #15378 - changed how the variable names in the blowup function are created in order to better keep track of which variables correspond to which patches --- src/sage/schemes/curves/affine_curve.py | 247 ++++++++++++++---------- 1 file changed, 143 insertions(+), 104 deletions(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index b4d83f19e07..e615990ff86 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -174,33 +174,33 @@ def blowup(self): sage: A. = AffineSpace(QQ, 2) sage: C = Curve([y^2 - x^3], A) sage: C.blowup() - ((Affine Plane Curve over Rational Field defined by z1^2 - z0, - Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1), - ([Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0, z1), - Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0*z1, 1/z1)], - [Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0*z1, 1/z1), - Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0, z1)]), + ((Affine Plane Curve over Rational Field defined by s1^2 - x, + Affine Plane Curve over Rational Field defined by -y*s0^3 + 1), + ([Scheme endomorphism of Affine Plane Curve over Rational Field defined + by s1^2 - x + Defn: Defined on coordinates by sending (x, s1) to + (x, s1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by s1^2 - x + To: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + Defn: Defined on coordinates by sending (x, s1) to + (x*s1, 1/s1)], [Scheme morphism: + From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + To: Affine Plane Curve over Rational Field defined by s1^2 - x + Defn: Defined on coordinates by sending (y, s0) to + (y*s0, 1/s0), + Scheme endomorphism of Affine Plane Curve over Rational Field defined + by -y*s0^3 + 1 + Defn: Defined on coordinates by sending (y, s0) to + (y, s0)]), (Scheme morphism: - From: Affine Plane Curve over Rational Field defined by z1^2 - z0 + From: Affine Plane Curve over Rational Field defined by s1^2 - x To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 - Defn: Defined on coordinates by sending (z0, z1) to - (z0, z0*z1), Scheme morphism: - From: Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1 + Defn: Defined on coordinates by sending (x, s1) to + (x, x*s1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 - Defn: Defined on coordinates by sending (z0, z1) to - (z0*z1, z0))) + Defn: Defined on coordinates by sending (y, s0) to + (y*s0, y))) :: @@ -210,20 +210,47 @@ def blowup(self): sage: B = C.blowup() sage: B[0] (Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by (-a)*z0^3 + z1^2, -z2 + 1, Affine Curve over Number Field in - a with defining polynomial x^2 - 2 defined by (-a)*z0^3*z1^5 + 1, z1 - - z2, Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by (-a)*z0^3*z1^5 + z2^2, z1 - 1) + defined by (-a)*x^3 + s1^2, -s2 + 1, + Affine Curve over Number Field in a with defining polynomial x^2 - 2 + defined by (-a)*y^3*s0^5 + 1, s0 - s2, + Affine Curve over Number Field in a with defining polynomial x^2 - 2 + defined by (-a)*z^3*s0^5 + s1^2, s0 - 1) sage: B[1][0][2] - Scheme endomorphism of Affine Space of dimension 3 over Number Field in - a with defining polynomial x^2 - 2 - Defn: Defined on coordinates by sending (z0, z1, z2) to - (z0*z2, 1/z2, z1/z2) + Scheme morphism: + From: Affine Curve over Number Field in a with defining polynomial x^2 + - 2 defined by (-a)*x^3 + s1^2, -s2 + 1 + To: Affine Curve over Number Field in a with defining polynomial x^2 + - 2 defined by (-a)*z^3*s0^5 + s1^2, s0 - 1 + Defn: Defined on coordinates by sending (x, s1, s2) to + (x*s2, 1/s2, s1/s2) sage: B[1][2][0] - Scheme endomorphism of Affine Space of dimension 3 over Number Field in - a with defining polynomial x^2 - 2 - Defn: Defined on coordinates by sending (z0, z1, z2) to - (z0*z1, z2/z1, 1/z1) + Scheme morphism: + From: Affine Curve over Number Field in a with defining polynomial x^2 + - 2 defined by (-a)*z^3*s0^5 + s1^2, s0 - 1 + To: Affine Curve over Number Field in a with defining polynomial x^2 + - 2 defined by (-a)*x^3 + s1^2, -s2 + 1 + Defn: Defined on coordinates by sending (z, s0, s1) to + (z*s0, s1/s0, 1/s0) + sage: B[2] + (Scheme morphism: + From: Affine Curve over Number Field in a with defining polynomial + x^2 - 2 defined by (-a)*x^3 + s1^2, -s2 + 1 + To: Affine Curve over Number Field in a with defining polynomial + x^2 - 2 defined by (-a)*x^5 + y^2, x - z + Defn: Defined on coordinates by sending (x, s1, s2) to + (x, x*s1, x*s2), Scheme morphism: + From: Affine Curve over Number Field in a with defining polynomial + x^2 - 2 defined by (-a)*y^3*s0^5 + 1, s0 - s2 + To: Affine Curve over Number Field in a with defining polynomial + x^2 - 2 defined by (-a)*x^5 + y^2, x - z + Defn: Defined on coordinates by sending (y, s0, s2) to + (y*s0, y, y*s2), Scheme morphism: + From: Affine Curve over Number Field in a with defining polynomial + x^2 - 2 defined by (-a)*z^3*s0^5 + s1^2, s0 - 1 + To: Affine Curve over Number Field in a with defining polynomial + x^2 - 2 defined by (-a)*x^5 + y^2, x - z + Defn: Defined on coordinates by sending (z, s0, s1) to + (z*s0, z*s1, z)) """ A = self.ambient_space() n = A.dimension_relative() @@ -235,25 +262,38 @@ def blowup(self): raise TypeError("the base ring of this curve must be a field") if not self.defining_ideal().is_prime(): raise TypeError("this curve must be irreducible") - R = PolynomialRing(A.base_ring(), 2*n, 'x') + # attempt to make the variable names more organized + # the convention used here is to have the homogeneous coordinates for the projective component of the + # product space the blow up resides in be generated from the letter 's'. The following loop is in place + # to prevent conflicts in the names from occurring + rf = 1 + for i in range(n): + if str(A.gens()[i])[0] == 's' and len(str(A.gens()[i])) > rf: + rf = len(str(A.gens()[i])) + var_names = [str(A.gens()[i]) for i in range(n)] + ['s'*rf + str(i) for i in range(n)] + R = PolynomialRing(A.base_ring(), 2*n, var_names) # move the defining polynomials of this curve into R H = Hom(A.coordinate_ring(), R) psi = H([R.gens()[i] for i in range(n)]) n_polys = [psi(f) for f in self.defining_polynomials()] # the blow up ideal of A at the origin is the ideal generated by - # x_i*x_{j + n} - x_j*x_{i + n} for i != j from 0,...,n-1 - # in the mixed product space of A^n and P^{n-1}. We describe the blow up of + # z_i*s_j - z_j*s_i for i != j from 0,...,n-1 + # in the mixed product space of A^n and P^{n-1} where the z_i are the gens + # of A^n, and the s_i are the gens for P^{n-1}. We describe the blow up of # this curve at the origin in each affine chart patches = [] for i in range(n): - # in this chart, x_{i + n} is assumed to be 1 - # substitute in x_{j} = x_{i}*x_{j + n} for each j != i + # in this chart, s_i is assumed to be 1 + # substitute in z_j = z_i*s_j for each j != i coords = list(R.gens()) for j in range(n): if j != i: coords[j] = R.gens()[i]*R.gens()[j + n] c_polys = [f(coords) for f in n_polys] - c_A = AffineSpace(R.base_ring(), n, 'z') + var_names = list(R.gens())[n:2*n] + var_names.pop(i) + var_names.insert(0, R.gens()[i]) + c_A = AffineSpace(R.base_ring(), n, var_names) H = Hom(R, c_A.coordinate_ring()) coords = [0]*(2*n) coords[i] = c_A.gens()[0] @@ -277,8 +317,7 @@ def blowup(self): maps = [] for j in range(n): AA = patches[i].ambient_space() - BB = patches[j].ambient_space() - H = Hom(AA, BB) + H = Hom(patches[i], patches[j]) vars = AA.gens() homvars = list(AA.gens()) homvars.pop(0) @@ -329,33 +368,33 @@ def resolution_of_singularities(self, extend=False): sage: A. = AffineSpace(QQ, 2) sage: C = Curve([y^2 - x^3], A) sage: C.resolution_of_singularities() - ((Affine Plane Curve over Rational Field defined by z1^2 - z0, - Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1), - ((Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0, z1), - Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0*z1, 1/z1)), - (Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0*z1, 1/z1), - Scheme endomorphism of Affine Space of dimension 2 over Rational - Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0, z1))), + ((Affine Plane Curve over Rational Field defined by s1^2 - x, + Affine Plane Curve over Rational Field defined by -y*s0^3 + 1), + ((Scheme endomorphism of Affine Plane Curve over Rational Field defined + by s1^2 - x + Defn: Defined on coordinates by sending (x, s1) to + (x, s1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by s1^2 - x + To: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + Defn: Defined on coordinates by sending (x, s1) to + (x*s1, 1/s1)), (Scheme morphism: + From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + To: Affine Plane Curve over Rational Field defined by s1^2 - x + Defn: Defined on coordinates by sending (y, s0) to + (y*s0, 1/s0), + Scheme endomorphism of Affine Plane Curve over Rational Field defined + by -y*s0^3 + 1 + Defn: Defined on coordinates by sending (y, s0) to + (y, s0))), (Scheme morphism: - From: Affine Plane Curve over Rational Field defined by z1^2 - z0 - To: Affine Space of dimension 2 over Rational Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0, z0*z1), Scheme morphism: - From: Affine Plane Curve over Rational Field defined by -z0*z1^3 + 1 - To: Affine Space of dimension 2 over Rational Field - Defn: Defined on coordinates by sending (z0, z1) to - (z0*z1, z0))) + From: Affine Plane Curve over Rational Field defined by s1^2 - x + To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + Defn: Defined on coordinates by sending (x, s1) to + (x, x*s1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + Defn: Defined on coordinates by sending (y, s0) to + (y*s0, y))) :: @@ -366,14 +405,15 @@ def resolution_of_singularities(self, extend=False): sage: R = C.resolution_of_singularities(True) # long time (3 seconds) sage: R[0] (Affine Plane Curve over Number Field in a with defining polynomial y^4 - - 4*y^2 + 1 defined by (a^2 - 1)*z0^2*z1^3 - z0^2*z1^2 + (-4*a)*z0*z1^3 - + (2*a^3 - 6*a)*z0*z1^2 - z1^2 + 2*z1 - 1, Affine Plane Curve over - Number Field in a with defining polynomial y^4 - 4*y^2 + 1 defined by - -z0^2*z1^2 + (a^2 - 1)*z0^2*z1 + (2*a^3 - 6*a)*z0*z1 - z1^2 + (-4*a)*z0 - + 2*z1 - 1, Affine Plane Curve over Number Field in a with defining - polynomial y^4 - 4*y^2 + 1 defined by -z0^2*z1^4 - z0^2*z1^2 + (-4*a^3 + - 12*a)*z0*z1^3 + 2*z0*z1^2 + (-2*a^3 + 6*a)*z0*z1 - 8*z1^2 + (a^2 - 1)*z0 - + (4*a^3 - 12*a)*z1 - 1) + - 4*y^2 + 1 defined by (a^2 - 1)*x^2*ss1^3 - x^2*ss1^2 + (-4*a)*x*ss1^3 + + (2*a^3 - 6*a)*x*ss1^2 - ss1^2 + 2*ss1 - 1, + Affine Plane Curve over Number Field in a with defining polynomial y^4 + - 4*y^2 + 1 defined by -s1^2*ss0^2 + (a^2 - 1)*s1^2*ss0 + (2*a^3 - + 6*a)*s1*ss0 - ss0^2 + (-4*a)*s1 + 2*ss0 - 1, + Affine Plane Curve over Number Field in a with defining polynomial y^4 + - 4*y^2 + 1 defined by -y^2*s0^4 - y^2*s0^2 + (-4*a^3 + 12*a)*y*s0^3 + + 2*y*s0^2 + (-2*a^3 + 6*a)*y*s0 - 8*s0^2 + (a^2 - 1)*y + (4*a^3 - + 12*a)*s0 - 1) :: @@ -381,12 +421,12 @@ def resolution_of_singularities(self, extend=False): sage: C = Curve([y - x^3, (z - 2)^2 - y^3 - x^3], A) sage: R = C.resolution_of_singularities() sage: R[0] - (Affine Curve over Finite Field of size 5 defined by -z0^2 + z1, - -z0*z1^3 + z2^2 - z0, - Affine Curve over Finite Field of size 5 defined by -z0^2*z1^3 + 1, - -z0*z1^3 + z2^2 - z0, - Affine Curve over Finite Field of size 5 defined by -z0^2*z1^3 + z2, - -z0*z1^3 - z0*z2^3 + 1) + (Affine Curve over Finite Field of size 5 defined by -x^2 + s1, -x*s1^3 + + s2^2 - x, + Affine Curve over Finite Field of size 5 defined by -y^2*s0^3 + 1, + -y*s0^3 + s2^2 - y, + Affine Curve over Finite Field of size 5 defined by -z^2*s0^3 + s1, + -z*s0^3 - z*s1^3 + 1) """ # helper function for extending the base field (in the case of working over a number field) def extension(self): @@ -402,7 +442,7 @@ def extension(self): n = C.ambient_space().dimension_relative() if C.base_ring() in NumberFields() and extend: C = C.change_ring(extension(C.singular_subscheme())[1]) - H = End(C.ambient_space()) + H = End(C) placeholder = H(C.ambient_space().gens()) # the list res holds the data for the patches of the resolution of singularities # each element is a list consisting of the curve defining the patch, a list @@ -414,7 +454,7 @@ def extension(self): t = 0 # loop through the patches and blow up each until no patch has singular points while not_resolved: - [BC, t_maps, pi, pts] = [res[t][0], res[t][1], res[t][2], res[t][3]] + [old_BC, t_maps, pi, pts] = [res[t][0], res[t][1], res[t][2], res[t][3]] # check if there are any singular points in this patch if len(pts) == 0: t = t + 1 @@ -424,14 +464,20 @@ def extension(self): # the identity map should be replaced for each of the charts of the blow up t_maps.pop(t) # translate pts[0] to the origin - H = End(BC.ambient_space()) + H = End(old_BC.ambient_space()) # translation map and inverse - phi = H([BC.ambient_space().gens()[i] - pts[0][i] for i in range(n)]) - phi_inv = H([BC.ambient_space().gens()[i] + pts[0][i] for i in range(n)]) + phi = H([old_BC.ambient_space().gens()[i] - pts[0][i] for i in range(n)]) + phi_inv = H([old_BC.ambient_space().gens()[i] + pts[0][i] for i in range(n)]) # create the translated curve - BC = BC.ambient_space().curve([f(phi_inv.defining_polynomials()) for f in BC.defining_polynomials()]) + BC = old_BC.ambient_space().curve([f(phi_inv.defining_polynomials()) for f in\ + old_BC.defining_polynomials()]) + # restrict the domain and codomain of phi, phi_inv for compatibility with future maps + H = Hom(old_BC, BC) + phi = H(phi.defining_polynomials()) + H = Hom(BC, old_BC) + phi_inv = H(phi_inv.defining_polynomials()) # translate the singular points - pts = [phi(BC.ambient_space()(pts[i])) for i in range(len(pts))] + pts = [phi(old_BC(pts[i])) for i in range(len(pts))] # blow up the origin B = list(BC.blowup()) B = [list(B[0]), [list(B[1][i]) for i in range(len(B[1]))], list(B[2])] @@ -484,33 +530,26 @@ def extension(self): b_data.append(B[0][i]) # compose the current transition maps from the original curve to the other patches # with the projection map - H = Hom(B[0][i].ambient_space(), BC.ambient_space()) - t_pi = H([phi_inv.defining_polynomials()[j](B[2][i].defining_polynomials()) for j in range(n)]) + t_pi = phi_inv*B[2][i] coords = [BC.ambient_space().gens()[j]/BC.ambient_space().gens()[i] for j in range(n)] coords.pop(i) coords.insert(0, BC.ambient_space().gens()[i]) - H = Hom(BC.ambient_space(), B[0][i].ambient_space()) + H = Hom(BC, B[0][i]) tmp_pi_inv = H(coords) - t_pi_inv = H([tmp_pi_inv.defining_polynomials()[j](phi.defining_polynomials()) for j in range(n)]) + t_pi_inv = tmp_pi_inv*phi L = list(t_maps) for j in range(len(t_maps)): - H = Hom(B[0][i].ambient_space(), L[j].codomain()) - L[j] = H([L[j].defining_polynomials()[k](t_pi.defining_polynomials()) for k in range(n)]) + L[j] = L[j]*t_pi for j in range(len(B[1][i])): L.insert(t + j, B[1][i][j]) b_data.append(L) # update transition maps of each other element of res for j in range(len(res)): - H = Hom(res[j][0].ambient_space(), B[0][i].ambient_space()) - new_t_map = H([t_pi_inv.defining_polynomials()[k](old_maps[j].defining_polynomials()) for k in\ - range(n)]) + new_t_map = t_pi_inv*old_maps[j] res[j][1].insert(t + i, new_t_map) # create the projection map tmp_pi = B[2][i] - H = Hom(tmp_pi.domain(), pi.codomain()) - coords = [phi_inv.defining_polynomials()[j](tmp_pi.defining_polynomials()) for j in range(n)] - coords = [pi.defining_polynomials()[j](coords) for j in range(n)] - b_data.append(H(coords)) + b_data.append(pi*phi_inv*tmp_pi) # singular points # translate the singular points of the parent patch (other than that which was the center of the # blow up) by the inverse of the first projection map From 3fcaf85fe46b32f7408f07cd4484761666463aa6 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Sat, 13 Aug 2016 17:04:17 +0200 Subject: [PATCH 062/135] 21232: Fractional part function {x} --- src/sage/functions/all.py | 2 +- src/sage/functions/other.py | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/sage/functions/all.py b/src/sage/functions/all.py index 342f5995822..0eb6add9839 100644 --- a/src/sage/functions/all.py +++ b/src/sage/functions/all.py @@ -23,7 +23,7 @@ from .other import ( ceil, floor, gamma, psi, factorial, beta, binomial, abs_symbolic, erf, sqrt, log_gamma, gamma_inc, incomplete_gamma, gamma_inc_lower, - arg, real_part, real, + arg, real_part, real, frac, imag_part, imag, imaginary, conjugate) from .log import (exp, exp_polar, log, ln, polylog, dilog, lambert_w) diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py index e8a148a0542..5ee3d3fac90 100644 --- a/src/sage/functions/other.py +++ b/src/sage/functions/other.py @@ -686,6 +686,80 @@ def __init__(self): Function_Order() +class Function_frac(BuiltinFunction): + def __init__(self): + r""" + The fractional part function `\{x\}`. + + ``frac(x)`` is defined as `\{x\} = x - \lfloor x\rfloor`. + + EXAMPLES:: + + sage: frac(5.4) + 0.400000000000000 + sage: type(frac(5.4)) + + sage: frac(456/123) + 29/41 + sage: var('x') + x + sage: a = frac(5.4 + x); a + frac(x + 5.40000000000000) + sage: frac(cos(8)/cos(2)) + cos(8)/cos(2) + + Test pickling:: + + sage: loads(dumps(floor)) + floor + """ + BuiltinFunction.__init__(self, "frac", + conversions=dict(sympy='frac')) + + def _print_latex_(self, x): + r""" + EXAMPLES:: + + sage: latex(frac(x)) + \left\{ x \right\} + """ + return r"\left\{ %s \right\}"%latex(x) + + def _evalf_(self, x, **kwds): + """ + EXAMPLES:: + + sage: frac(pi).n() + 0.141592653589793 + sage: frac(pi).n(200) + 0.14159265358979323846264338327950288419716939937510582097494 + """ + return x - floor(x) + + def _eval_(self, x): + """ + EXAMPLES:: + + sage: frac(x).subs(x==7.5) + 0.500000000000000 + sage: frac(x) + frac(x) + """ + try: + return x - x.floor() + except AttributeError: + if isinstance(x, (int, long)): + return x - Integer(x) + elif isinstance(x, (float, complex)): + return x - Integer(int(math.floor(x))) + elif isinstance(x, sage.symbolic.expression.Expression): + ret = floor(x) + if not hasattr(ret, "operator") or not ret.operator() == floor: + return x - ret + return None + +frac = Function_frac() + class Function_gamma(GinacFunction): def __init__(self): From 78e1ce23310ece13ece4eec995b849e5fc95ccf4 Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Sun, 14 Aug 2016 03:04:45 -0400 Subject: [PATCH 063/135] 21085: changes from review --- src/sage/schemes/curves/affine_curve.py | 83 ++++++++++++++++++------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index e615990ff86..74f2c0d1420 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -44,9 +44,10 @@ from sage.rings.all import degree_lowest_rational_function +from sage.rings.number_field.number_field import NumberField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.qqbar import number_field_elements_from_algebraics, QQbar - +from sage.rings.rational_field import is_RationalField from sage.schemes.affine.affine_space import (is_AffineSpace, AffineSpace) @@ -251,6 +252,15 @@ def blowup(self): x^2 - 2 defined by (-a)*x^5 + y^2, x - z Defn: Defined on coordinates by sending (z, s0, s1) to (z*s0, z*s1, z)) + + :: + + sage: A. = AffineSpace(QuadraticField(-1), 2) + sage: C = A.curve([y^2 + x^2]) + sage: C.blowup() + Traceback (most recent call last): + ... + TypeError: this curve must be irreducible """ A = self.ambient_space() n = A.dimension_relative() @@ -260,7 +270,7 @@ def blowup(self): raise TypeError("the origin must be a point on this curve") if not self.base_ring() in Fields(): raise TypeError("the base ring of this curve must be a field") - if not self.defining_ideal().is_prime(): + if not self.is_irreducible(): raise TypeError("this curve must be irreducible") # attempt to make the variable names more organized # the convention used here is to have the homogeneous coordinates for the projective component of the @@ -344,7 +354,8 @@ def resolution_of_singularities(self, extend=False): The nonsingular model is given as a collection of affine patches that cover it. If ``extend`` is ``False`` and if the base field is a number field, or if the base field is a finite field, the model returned may have - singularities with coordinates not contained in the base field. + singularities with coordinates not contained in the base field. An error is returned if this curve is already + nonsingular, or if it has no singular points over its base field. INPUT: @@ -401,19 +412,15 @@ def resolution_of_singularities(self, extend=False): sage: set_verbose(-1) sage: K. = QuadraticField(3) sage: A. = AffineSpace(K, 2) - sage: C = Curve([(x^2 + y^2 - y - 2)*(y - x^2 + 2) + a*y^3], A) - sage: R = C.resolution_of_singularities(True) # long time (3 seconds) + sage: C = A.curve(x^4 + 2*x^2 + a*y^3 + 1) + sage: R = C.resolution_of_singularities(extend=True) # long time (2 seconds) sage: R[0] - (Affine Plane Curve over Number Field in a with defining polynomial y^4 - - 4*y^2 + 1 defined by (a^2 - 1)*x^2*ss1^3 - x^2*ss1^2 + (-4*a)*x*ss1^3 - + (2*a^3 - 6*a)*x*ss1^2 - ss1^2 + 2*ss1 - 1, - Affine Plane Curve over Number Field in a with defining polynomial y^4 - - 4*y^2 + 1 defined by -s1^2*ss0^2 + (a^2 - 1)*s1^2*ss0 + (2*a^3 - - 6*a)*s1*ss0 - ss0^2 + (-4*a)*s1 + 2*ss0 - 1, - Affine Plane Curve over Number Field in a with defining polynomial y^4 - - 4*y^2 + 1 defined by -y^2*s0^4 - y^2*s0^2 + (-4*a^3 + 12*a)*y*s0^3 + - 2*y*s0^2 + (-2*a^3 + 6*a)*y*s0 - 8*s0^2 + (a^2 - 1)*y + (4*a^3 - - 12*a)*s0 - 1) + (Affine Plane Curve over Number Field in a0 with defining polynomial y^4 + - 4*y^2 + 16 defined by (1/8*a0^3 - a0)*x^2*ss1^3 + (-a0^2 + 2)*x*ss1^3 + 1, + Affine Plane Curve over Number Field in a0 with defining polynomial y^4 + - 4*y^2 + 16 defined by (1/8*a0^3 - a0)*s1^2*ss0 + ss0^2 + (-a0^2 + 2)*s1, + Affine Plane Curve over Number Field in a0 with defining polynomial y^4 + - 4*y^2 + 16 defined by y^2*s0^4 + (-1/2*a0^3)*y*s0^3 - 4*s0^2 + (1/8*a0^3 - a0)*y) :: @@ -427,21 +434,47 @@ def resolution_of_singularities(self, extend=False): -y*s0^3 + s2^2 - y, Affine Curve over Finite Field of size 5 defined by -z^2*s0^3 + s1, -z*s0^3 - z*s1^3 + 1) + + :: + + sage: A. = AffineSpace(QQ, 2) + sage: C = Curve([y - x^2 + 1], A) + sage: C.resolution_of_singularities() + Traceback (most recent call last): + ... + TypeError: this curve is already nonsingular + + :: + + sage: A. = AffineSpace(QQ, 2) + sage: C = A.curve([(x^2 + y^2 - y - 2)*(y - x^2 + 2) + y^3]) + sage: C.resolution_of_singularities() + Traceback (most recent call last): + ... + TypeError: this curve has no singular points over its base field. If + working over a number field use extend=True """ # helper function for extending the base field (in the case of working over a number field) def extension(self): - psi = self.base_ring().embeddings(QQbar)[0] - pts = self.change_ring(psi).rational_points() - L = [pt[j] for j in range(len(self.ambient_space().gens())) for pt in pts] - L.extend([psi(g) for g in self.base_ring().gens()]) + F = self.base_ring() + pts = self.change_ring(F.embeddings(QQbar)[0]).rational_points() + L = [t for pt in pts for t in pt] K = number_field_elements_from_algebraics(L)[0] - return [K, self.base_ring().embeddings(K)[0]] + if is_RationalField(K): + return F.embeddings(F)[0] + else: + if is_RationalField(F): + return F.embeddings(K)[0] + else: + # make sure the defining polynomial variable names are the same for K, N + N = NumberField(K.defining_polynomial().parent()(F.defining_polynomial()), str(K.gen())) + return N.composite_fields(K, both_maps=True)[0][1]*F.embeddings(N)[0] # find the set of singular points of this curve # in the case that the base field is a number field, extend it as needed (if extend == True) C = self n = C.ambient_space().dimension_relative() if C.base_ring() in NumberFields() and extend: - C = C.change_ring(extension(C.singular_subscheme())[1]) + C = C.change_ring(extension(C.singular_subscheme())) H = End(C) placeholder = H(C.ambient_space().gens()) # the list res holds the data for the patches of the resolution of singularities @@ -450,6 +483,12 @@ def extension(self): # map from the patch to the original curve, and the set of singular points # of the patch res = [[C, [placeholder], placeholder, C.singular_points()]] + if len(res[0][3]) == 0: + if C.is_smooth(): + raise TypeError("this curve is already nonsingular") + else: + raise TypeError("this curve has no singular points over its base field. If working over"\ + " a number field use extend=True") not_resolved = True t = 0 # loop through the patches and blow up each until no patch has singular points @@ -499,7 +538,7 @@ def extension(self): # in the case of working over a number field, it might be necessary to extend the base # field in order to find all intersection points if B[0][i].base_ring() in NumberFields() and extend: - emb = extension(X)[1] + emb = extension(X) # coerce everything to the new base field phi = phi.change_ring(emb) phi_inv = phi_inv.change_ring(emb) From 3371add1a7de1b1d0dc1efa1b18bed7faf1f6c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 14 Aug 2016 13:15:26 +0200 Subject: [PATCH 064/135] trac #21193 trying to fix pdf issue --- src/sage/coding/delsarte_bounds.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/coding/delsarte_bounds.py b/src/sage/coding/delsarte_bounds.py index 69c1c806f37..b238a9919e0 100644 --- a/src/sage/coding/delsarte_bounds.py +++ b/src/sage/coding/delsarte_bounds.py @@ -20,8 +20,9 @@ #***************************************************************************** from __future__ import print_function -def Krawtchouk(n,q,l,x,check=True): - """ + +def Krawtchouk(n, q, l, x, check=True): + r""" Compute ``K^{n,q}_l(x)``, the Krawtchouk (a.k.a. Kravchuk) polynomial. See :wikipedia:`Kravchuk_polynomials`; It is defined by the generating function From ed5c3435628e113424688a9a315b7445cda8d597 Mon Sep 17 00:00:00 2001 From: Kiran Kedlaya Date: Sun, 14 Aug 2016 16:04:12 +0000 Subject: [PATCH 065/135] Remove spurious changes to PARI headers --- src/sage/libs/pari/paridecl.pxd | 1 - src/sage/libs/pari/parisage.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/sage/libs/pari/paridecl.pxd b/src/sage/libs/pari/paridecl.pxd index bcccfac93af..52b8e929c45 100644 --- a/src/sage/libs/pari/paridecl.pxd +++ b/src/sage/libs/pari/paridecl.pxd @@ -656,7 +656,6 @@ cdef extern from "sage/libs/pari/parisage.h": int F2x_is_irred(GEN f) void F2xV_to_FlxV_inplace(GEN v) void F2xV_to_ZXV_inplace(GEN v) - GEN F2xqX_roots(GEN x, GEN T) int Flx_is_irred(GEN f, ulong p) GEN Flx_degfact(GEN f, ulong p) GEN Flx_factor(GEN f, ulong p) diff --git a/src/sage/libs/pari/parisage.h b/src/sage/libs/pari/parisage.h index 30d3024a814..5729aa11f18 100644 --- a/src/sage/libs/pari/parisage.h +++ b/src/sage/libs/pari/parisage.h @@ -3,7 +3,6 @@ #include #undef coeff /* Conflicts with NTL */ -#undef ulong /* Conflicts with FLINT */ /* Array element assignment */ From 45e9053e16471ae3b6658bc9dbfb7b3429714c2c Mon Sep 17 00:00:00 2001 From: Vincent Delecroix <20100.delecroix@gmail.com> Date: Mon, 11 Jul 2016 17:27:40 -0400 Subject: [PATCH 066/135] Trac 21005: new pari release --- build/pkgs/pari/checksums.ini | 6 ++-- build/pkgs/pari/package-version.txt | 2 +- src/sage/libs/pari/tests.py | 18 +++++----- src/sage_setup/autogen/pari/doc.py | 54 ++++++++++++++++++++++++----- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/build/pkgs/pari/checksums.ini b/build/pkgs/pari/checksums.ini index ccbfa9e208c..19999aceb9c 100644 --- a/build/pkgs/pari/checksums.ini +++ b/build/pkgs/pari/checksums.ini @@ -1,4 +1,4 @@ tarball=pari-VERSION.tar.gz -sha1=a936e0ed661c8e453578f3c129c3a454e2039e3e -md5=59f2e4c3c51f7652182400489cd76e6a -cksum=1366291737 +sha1=efd1eb6b8d87066b2b9f3b2c38ecb30bbfdb48d2 +md5=f3f3342913a3b3b306970b3462f4d47d +cksum=1553747906 diff --git a/build/pkgs/pari/package-version.txt b/build/pkgs/pari/package-version.txt index f9e24123df3..4a4ef6b5825 100644 --- a/build/pkgs/pari/package-version.txt +++ b/build/pkgs/pari/package-version.txt @@ -1 +1 @@ -2.8-2771-gb70b447.p0 +2.8.0.alpha.p0 diff --git a/src/sage/libs/pari/tests.py b/src/sage/libs/pari/tests.py index 6d4b6e145f2..281506d855f 100644 --- a/src/sage/libs/pari/tests.py +++ b/src/sage/libs/pari/tests.py @@ -1167,13 +1167,13 @@ [0, 1, [1, 0, 0, 0], 1] sage: e = pari(EllipticCurve('27a3').a_invariants()).ellinit() sage: e.elllocalred(3) - [3, 2, [1, -1, 0, 1], 1] + [3, 2, [1, 0, 0, 0], 1] sage: e = pari(EllipticCurve('24a4').a_invariants()).ellinit() sage: e.elllocalred(2) - [3, 3, [1, 1, 0, 1], 2] + [3, 3, [1, 0, 0, 0], 2] sage: e = pari(EllipticCurve('20a2').a_invariants()).ellinit() sage: e.elllocalred(2) - [2, 4, [1, 1, 0, 1], 3] + [2, 4, [1, 0, 0, 0], 3] sage: e = pari(EllipticCurve('11a2').a_invariants()).ellinit() sage: e.elllocalred(11) [1, 5, [1, 0, 0, 0], 1] @@ -1185,22 +1185,22 @@ [1, 10, [1, 0, 0, 0], 2] sage: e = pari(EllipticCurve('32a3').a_invariants()).ellinit() sage: e.elllocalred(2) - [5, -1, [1, 1, 1, 0], 1] + [5, -1, [1, 0, 0, 0], 1] sage: e = pari(EllipticCurve('24a5').a_invariants()).ellinit() sage: e.elllocalred(2) - [3, -2, [1, 2, 1, 4], 1] + [3, -2, [1, 0, 0, 0], 1] sage: e = pari(EllipticCurve('24a2').a_invariants()).ellinit() sage: e.elllocalred(2) - [3, -3, [1, 2, 1, 4], 2] + [3, -3, [1, 0, 0, 0], 2] sage: e = pari(EllipticCurve('20a1').a_invariants()).ellinit() sage: e.elllocalred(2) - [2, -4, [1, 0, 1, 2], 3] + [2, -4, [1, 0, 0, 0], 3] sage: e = pari(EllipticCurve('24a1').a_invariants()).ellinit() sage: e.elllocalred(2) - [3, -5, [1, 0, 1, 2], 4] + [3, -5, [1, 0, 0, 0], 4] sage: e = pari(EllipticCurve('90c2').a_invariants()).ellinit() sage: e.elllocalred(3) - [2, -10, [1, 96, 1, 316], 4] + [2, -10, [1, 0, 0, 0], 4] sage: e = pari([0,1,1,-2,0]).ellinit() sage: e.elllseries(2.1) diff --git a/src/sage_setup/autogen/pari/doc.py b/src/sage_setup/autogen/pari/doc.py index 59e2635e62f..02ec02574ff 100644 --- a/src/sage_setup/autogen/pari/doc.py +++ b/src/sage_setup/autogen/pari/doc.py @@ -37,7 +37,8 @@ escape_percent = re.compile(r"^(\S.*)[%]", re.MULTILINE) escape_hash = re.compile(r"^(\S.*)[#]", re.MULTILINE) -label_link = re.compile(r"(Section *)?\[@\[startbold\]Label: *(se:)?([^@]*)@\[endbold\]\]") +label_define = re.compile(r"@\[label [a-zA-Z0-9:]*\]") +label_ref = re.compile(r"(Section *)?@\[startref\](se:)?([^@]*)@\[endref\]") def sub_loop(regex, repl, text): @@ -123,8 +124,9 @@ def raw_to_rest(doc): # insert a non-breaking space doc = end_space.sub("\\1" + unichr(0xa0) + "\\2", doc) - # Remove links - doc = label_link.sub("``\\3`` (in the PARI manual)", doc) + # Fix labels and references + doc = label_define.sub("", doc) + doc = label_ref.sub("``\\3`` (in the PARI manual)", doc) # Bullet items doc = doc.replace("@3@[startbold]*@[endbold] ", "@BULLET ") @@ -238,7 +240,7 @@ def get_raw_doc(function): sage: from sage_setup.autogen.pari.doc import get_raw_doc sage: get_raw_doc("cos") - '@[startbold]cos@[dollar](x)@[dollar]:@[endbold]\n\n\n\nCosine of @[dollar]x@[dollar].\n\n\nThe library syntax is @[startcode]GEN @[startbold]gcos@[endbold](GEN x, long prec)@[endcode].\n\n\n' + '@[startbold]cos@[dollar](x)@[dollar]:@[endbold]\n\n@[label se:cos]\nCosine of @[dollar]x@[dollar].\n\n\nThe library syntax is @[startcode]GEN @[startbold]gcos@[endbold](GEN x, long prec)@[endcode].\n\n\n' sage: get_raw_doc("abcde") Traceback (most recent call last): ... @@ -274,7 +276,7 @@ def get_rest_doc(function): .. MATH:: - f(x) = \exp(-i\Pi/24).\eta((x+1)/2)/\eta(x) {such that} + f(x) = \exp(-i\pi/24).\eta((x+1)/2)/\eta(x) {such that} j = (f^{24}-16)^3/f^{24}, where :math:`j` is the elliptic :math:`j`-invariant (see the function :literal:`ellj`). @@ -294,14 +296,16 @@ def get_rest_doc(function): Note the identities :math:`f^8 = f_1^8+f_2^8` and :math:`ff_1f_2 = \sqrt2`. + :: sage: print(get_rest_doc("ellap")) Let :math:`E` be an :literal:`ell` structure as output by :literal:`ellinit`, defined over - :math:`\mathbb{Q}` or a finite field :math:`\mathbb{F}_q`. The argument :math:`p` is best left omitted if the - curve is defined over a finite field, and must be a prime number otherwise. - This function computes the trace of Frobenius :math:`t` for the elliptic curve :math:`E`, - defined by the equation :math:`\#E(\mathbb{F}_q) = q+1 - t`. + a number field or a finite field :math:`\mathbb{F}_q`. The argument :math:`p` is best left + omitted if the curve is defined over a finite field, and must be a prime + number or a maximal ideal otherwise. This function computes the trace of + Frobenius :math:`t` for the elliptic curve :math:`E`, defined by the equation :math:`\#E(\mathbb{F}_q) + = q+1 - t` (for primes of good reduction). When the characteristic of the finite field is large, the availability of the :literal:`seadata` package will speed the computation. @@ -338,6 +342,38 @@ def get_rest_doc(function): ? ellap(E) %8 = -3 + If the curve is defined over a more general number field than :math:`\mathbb{Q}`, + the maximal ideal :math:`p` must be explicitly given in :literal:`idealprimedec` + format. If :math:`p` is above :math:`2` or :math:`3`, the function currently assumes (without + checking) that the given model is locally minimal at :math:`p`. There is no + restriction at other primes. + + :: + + ? K = nfinit(a^2+1); E = ellinit([1+a,0,1,0,0], K); + ? fa = idealfactor(K, E.disc) + %2 = + [ [5, [-2, 1]~, 1, 1, [2, -1; 1, 2]] 1] + + [[13, [5, 1]~, 1, 1, [-5, -1; 1, -5]] 2] + ? ellap(E, fa[1,1]) + %3 = -1 \\ non-split multiplicative reduction + ? ellap(E, fa[2,1]) + %4 = 1 \\ split multiplicative reduction + ? P17 = idealprimedec(K,17)[1]; + ? ellap(E, P17) + %6 = 6 \\ good reduction + ? E2 = ellchangecurve(E, [17,0,0,0]); + ? ellap(E2, P17) + %8 = 6 \\ same, starting from a non-miminal model + + ? P3 = idealprimedec(K,3)[1]; + ? E3 = ellchangecurve(E, [3,0,0,0]); + ? ellap(E, P3) \\ OK: E is minimal at P3 + %11 = -2 + ? ellap(E3, P3) \\ junk: E3 is not minimal at P3 | 3 + %12 = 0 + :strong:`Algorithms used.` If :math:`E/\mathbb{F}_q` has CM by a principal imaginary quadratic order we use a fast explicit formula (involving essentially Kronecker symbols and Cornacchia's algorithm), in :math:`O(\log q)^2`. From 36fdef4c1f58f5a24a71e79d418a715ef36dbf4e Mon Sep 17 00:00:00 2001 From: Vincent Delecroix <20100.delecroix@gmail.com> Date: Mon, 11 Jul 2016 18:10:39 -0400 Subject: [PATCH 067/135] Trac 21005: update paridecl.pxd --- src/sage/libs/pari/paridecl.pxd | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/sage/libs/pari/paridecl.pxd b/src/sage/libs/pari/paridecl.pxd index 52b8e929c45..614ea22491d 100644 --- a/src/sage/libs/pari/paridecl.pxd +++ b/src/sage/libs/pari/paridecl.pxd @@ -2594,7 +2594,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN ellrandom(GEN e) long ellrootno(GEN e, GEN p) long ellrootno_global(GEN e) - GEN ellsea(GEN E, GEN p, long early_abort) + GEN ellsea(GEN E, ulong smallfact) GEN ellsigma(GEN om, GEN z, long flag, long prec) GEN ellsub(GEN e, GEN z1, GEN z2) GEN elltaniyama(GEN e, long prec) @@ -3014,10 +3014,11 @@ cdef extern from "sage/libs/pari/parisage.h": GEN padic_to_Q_shallow(GEN x) GEN QpV_to_QV(GEN v) GEN RgM_mulreal(GEN x, GEN y) - GEN RgX_RgM_eval_col(GEN x, GEN M, long c) GEN RgX_cxeval(GEN T, GEN u, GEN ui) GEN RgX_deflate_max(GEN x0, long *m) long RgX_deflate_order(GEN x) + long ZX_deflate_order(GEN x) + GEN ZX_deflate_max(GEN x, long *m) long RgX_degree(GEN x, long v) GEN RgX_integ(GEN x) GEN bitprecision0(GEN x, long n) @@ -3056,6 +3057,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN ggrando(GEN x, long n) GEN ggt(GEN x, GEN y) GEN gimag(GEN x) + GEN gisexactzero(GEN g) GEN gle(GEN x, GEN y) GEN glt(GEN x, GEN y) GEN gmod(GEN x, GEN y) @@ -3067,8 +3069,10 @@ cdef extern from "sage/libs/pari/parisage.h": GEN gne(GEN x, GEN y) GEN gnot(GEN x) GEN gpolvar(GEN y) + GEN gppadicprec(GEN x, GEN p) GEN gppoldegree(GEN x, long v) long gprecision(GEN x) + GEN gpserprec(GEN x, long v) GEN greal(GEN x) GEN grndtoi(GEN x, long *e) GEN ground(GEN x) @@ -3096,6 +3100,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN imag_i(GEN x) GEN integ(GEN x, long v) GEN integser(GEN x) + GEN inv_ser(GEN b) int iscomplex(GEN x) int isexactzero(GEN g) int isrationalzeroscalar(GEN g) @@ -3142,7 +3147,9 @@ cdef extern from "sage/libs/pari/parisage.h": GEN scalarpol_shallow(GEN x, long v) GEN scalarser(GEN x, long v, long prec) GEN ser_unscale(GEN P, GEN h) + long serprec(GEN x, long v) GEN serreverse(GEN x) + GEN sertoser(GEN x, long prec) GEN simplify(GEN x) GEN simplify_shallow(GEN x) GEN tayl(GEN x, long v, long precdl) @@ -3427,7 +3434,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN lfunlambda0(GEN ldata, GEN s, long der, long bitprec) GEN lfunmisc_to_ldata(GEN ldata) GEN lfunmisc_to_ldata_shallow(GEN ldata) - long lfunorderzero(GEN ldata, long bitprec) + long lfunorderzero(GEN ldata, long m, long bitprec) GEN lfunprod_get_fact(GEN tech) GEN lfunrootno(GEN data, long bitprec) GEN lfunrootres(GEN data, long bitprec) @@ -3460,7 +3467,7 @@ cdef extern from "sage/libs/pari/parisage.h": GEN lfunmfspec(GEN lmisc, long bitprec) GEN lfunmfpeters(GEN ldata, long bitprec) GEN lfunmul(GEN ldata1, GEN ldata2, long bitprec) - GEN lfunqf(GEN ldata) + GEN lfunqf(GEN ldata, long prec) GEN lfunsymsq(GEN ldata, GEN known, long prec) GEN lfunsymsqspec(GEN lmisc, long bitprec) GEN lfunzetakinit(GEN pol, GEN dom, long der, long flag, long bitprec) From 9cf577602f84622d6fcceb10c6caa929ac4971bb Mon Sep 17 00:00:00 2001 From: Vincent Delecroix <20100.delecroix@gmail.com> Date: Sun, 24 Jul 2016 17:01:37 -0400 Subject: [PATCH 068/135] Trac 21005: fix pari doc --- src/sage_setup/autogen/pari/doc.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sage_setup/autogen/pari/doc.py b/src/sage_setup/autogen/pari/doc.py index 02ec02574ff..46f6166b0ad 100644 --- a/src/sage_setup/autogen/pari/doc.py +++ b/src/sage_setup/autogen/pari/doc.py @@ -9,7 +9,8 @@ from six import unichr -leading_ws = re.compile("^ +", re.MULTILINE) +leading_ws = re.compile("^( +)", re.MULTILINE) +trailing_ws = re.compile("( +)$", re.MULTILINE) double_space = re.compile(" +") end_space = re.compile(r"(@\[end[a-z]*\])([A-Za-z])") @@ -93,6 +94,10 @@ def raw_to_rest(doc): Traceback (most recent call last): ... SyntaxError: @ found: @[invalid] + + sage: s = '@3@[startbold]*@[endbold] snip @[dollar]0@[dollar]\ndividing @[dollar]#E@[dollar].' + sage: raw_to_rest(s) + u'- snip :math:`0`\n dividing :math:`\\#E`.' """ doc = doc.decode("utf-8") @@ -114,8 +119,9 @@ def raw_to_rest(doc): doc = doc.replace("@[uuml]", "ü") doc = doc.replace("\\'{a}", "á") - # Remove leading whitespace from every line + # Remove leading and trailing whitespace from every line doc = leading_ws.sub("", doc) + doc = trailing_ws.sub("", doc) # Remove multiple spaces doc = double_space.sub(" ", doc) @@ -133,6 +139,10 @@ def raw_to_rest(doc): doc = sub_loop(bullet_loop, "\\1 \\3", doc) doc = doc.replace("@BULLET ", "- ") + # Add =VOID= in front of all leading whitespace (which was + # intentionally added) to avoid confusion with verbatim blocks. + doc = leading_ws.sub(r"=VOID=\1", doc) + # Verbatim blocks doc = begin_verb.sub("::\n\n@0", doc) doc = end_verb.sub("", doc) @@ -162,6 +172,9 @@ def raw_to_rest(doc): doc = doc.replace("@[cbr]", "}") doc = doc.replace("@[startword]", "\\") doc = doc.replace("@[endword]", "") + # (special rules for Hom and Frob, see trac ticket 21005) + doc = doc.replace("@[startlword]Hom@[endlword]", "\\text{Hom}") + doc = doc.replace("@[startlword]Frob@[endlword]", "\\text{Frob}") doc = doc.replace("@[startlword]", "\\") doc = doc.replace("@[endlword]", "") doc = doc.replace("@[startbi]", "\\mathbb{") @@ -186,6 +199,7 @@ def raw_to_rest(doc): doc = doc.replace("=MID=", r"\|") doc = doc.replace("=PERCENT=", r"\%") doc = doc.replace("=HASH=", r"\#") + doc = doc.replace("=VOID=", "") # Handle DISPLAYMATH doc = doc.replace("@[endDISPLAYMATH]", "\n\n") From 89dbcf480dbe452c0f9dcbde634777b3659c5a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Mon, 15 Aug 2016 10:04:23 +0300 Subject: [PATCH 069/135] Corner case for complements(). --- src/sage/combinat/posets/lattices.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sage/combinat/posets/lattices.py b/src/sage/combinat/posets/lattices.py index 4a59b17ffc7..c591ff1dc26 100644 --- a/src/sage/combinat/posets/lattices.py +++ b/src/sage/combinat/posets/lattices.py @@ -1126,11 +1126,20 @@ def complements(self, element=None): ....: for v_c in v_complements: ....: assert L.meet(v,v_c) == L.bottom() ....: assert L.join(v,v_c) == L.top() + + sage: Posets.ChainPoset(0).complements() + {} + sage: Posets.ChainPoset(1).complements() + {0: [0]} + sage: Posets.ChainPoset(2).complements() + {0: [1], 1: [0]} """ if element is None: + n = self.cardinality() + if n == 1: + return {self[0]: [self[0]]} jn = self.join_matrix() mt = self.meet_matrix() - n = self.cardinality() zero = 0 one = n-1 c = [[] for x in range(n)] From 50b6d64a5aff21a803ca9efbb16bd5bcab412637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 15 Aug 2016 14:09:02 +0200 Subject: [PATCH 070/135] a bunch of absolute imports in pyx files --- src/sage/categories/action.pyx | 11 ++++--- .../orthogonal_arrays_find_recursive.pyx | 32 +++++++++---------- src/sage/geometry/triangulation/base.pyx | 11 +++---- src/sage/graphs/base/c_graph.pyx | 2 +- src/sage/graphs/base/graph_backends.pyx | 13 +++++--- src/sage/libs/gap/util.pyx | 4 +-- src/sage/libs/pari/closure.pyx | 6 ++-- src/sage/matrix/matrix_cyclo_dense.pyx | 16 +++++----- src/sage/matrix/matrix_dense.pxd | 2 +- src/sage/matrix/matrix_double_dense.pyx | 11 ++++--- src/sage/matroids/basis_exchange_matroid.pyx | 8 +++-- src/sage/matroids/basis_matroid.pyx | 15 ++++++--- .../matroids/circuit_closures_matroid.pyx | 9 ++++-- src/sage/matroids/linear_matroid.pyx | 8 ++--- src/sage/matroids/matroid.pyx | 29 +++++++++-------- src/sage/matroids/union_matroid.pyx | 6 +++- src/sage/misc/lazy_import.pyx | 5 +-- src/sage/misc/sage_timeit_class.pyx | 3 +- .../modular/arithgroup/arithgroup_element.pyx | 10 +++--- src/sage/plot/plot3d/base.pyx | 10 +++--- src/sage/structure/factory.pyx | 3 +- 21 files changed, 119 insertions(+), 95 deletions(-) diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 7cacb63c049..2712fe79964 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -57,13 +57,14 @@ AUTHOR: # # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import -from functor cimport Functor -from morphism cimport Morphism -from map cimport Map +from .functor cimport Functor +from .morphism cimport Morphism +from .map cimport Map from sage.structure.parent cimport Parent -import homset +from . import homset import sage.structure.element from weakref import ref from sage.misc.constant_function import ConstantFunction @@ -79,7 +80,7 @@ cdef inline category(x): cdef class Action(Functor): def __init__(self, G, S, bint is_left = 1, op=None): - from groupoid import Groupoid + from .groupoid import Groupoid Functor.__init__(self, Groupoid(G), category(S)) self.G = G self.US = ref(S) diff --git a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx index 139679a70f6..6d2a3e5cce0 100644 --- a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +++ b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx @@ -44,10 +44,10 @@ REFERENCES: Functions --------- """ -from __future__ import print_function +from __future__ import print_function, absolute_import from sage.misc.cachefunc import cached_function -from orthogonal_arrays import orthogonal_array +from .orthogonal_arrays import orthogonal_array from sage.rings.integer cimport Integer, smallInteger from sage.arith.all import prime_powers @@ -151,7 +151,7 @@ cpdef find_product_decomposition(int k,int n): # faster to use that rather than calling the divisors function continue if is_available(k, n1) and is_available(k, n2): - from orthogonal_arrays import wilson_construction + from .orthogonal_arrays import wilson_construction return wilson_construction, (None,k,n1,n2,(),False) return False @@ -201,7 +201,7 @@ cpdef find_wilson_decomposition_with_one_truncated_group(int k,int n): is_available(k ,m+1) and is_available(k+1,r ) and is_available(k ,u )): - from orthogonal_arrays import wilson_construction + from .orthogonal_arrays import wilson_construction return wilson_construction, (None,k,r,m,(u,),False) return False @@ -263,7 +263,7 @@ cpdef find_wilson_decomposition_with_two_truncated_groups(int k,int n): r2 = r1_p_r2-r1 if is_available(k,r2): assert n == r*m+r1+r2 - from orthogonal_arrays import wilson_construction + from .orthogonal_arrays import wilson_construction return wilson_construction, (None,k,r,m,(r1,r2),False) return False @@ -303,7 +303,7 @@ cpdef find_construction_3_3(int k,int n): if (is_available(k+i, nn ) and is_available(k , mm+i)): - from orthogonal_arrays_build_recursive import construction_3_3 + from .orthogonal_arrays_build_recursive import construction_3_3 return construction_3_3, (k,nn,mm,i) cpdef find_construction_3_4(int k,int n): @@ -346,7 +346,7 @@ cpdef find_construction_3_4(int k,int n): if (is_available(k+r+1,nn) and is_available(k , s) and (is_available(k,mm+r) or is_available(k,mm+r+1))): - from orthogonal_arrays_build_recursive import construction_3_4 + from .orthogonal_arrays_build_recursive import construction_3_4 return construction_3_4, (k,nn,mm,r,s) cpdef find_construction_3_5(int k,int n): @@ -396,7 +396,7 @@ cpdef find_construction_3_5(int k,int n): (r==0 or is_available(k,r)) and (s==0 or is_available(k,s)) and (t==0 or is_available(k,t))): - from orthogonal_arrays_build_recursive import construction_3_5 + from .orthogonal_arrays_build_recursive import construction_3_5 return construction_3_5, (k,nn,mm,r,s,t) cpdef find_construction_3_6(int k,int n): @@ -437,7 +437,7 @@ cpdef find_construction_3_6(int k,int n): if (is_available(k+i,nn) and smallInteger(nn).is_prime_power()): - from orthogonal_arrays_build_recursive import construction_3_6 + from .orthogonal_arrays_build_recursive import construction_3_6 return construction_3_6, (k,nn,mm,i) cpdef find_q_x(int k,int n): @@ -489,7 +489,7 @@ cpdef find_q_x(int k,int n): # is_available(k+1,q) and is_available(k, x+2 ) and smallInteger(q).is_prime_power()): - from orthogonal_arrays_build_recursive import construction_q_x + from .orthogonal_arrays_build_recursive import construction_q_x return construction_q_x, (k,q,x) return False @@ -543,7 +543,7 @@ cpdef find_thwart_lemma_3_5(int k,int N): sage: for k,n in kn: # not tested -- too long ....: assert designs.orthogonal_array(k,n,existence=True) is True # not tested -- too long """ - from orthogonal_arrays_build_recursive import thwart_lemma_3_5 + from .orthogonal_arrays_build_recursive import thwart_lemma_3_5 cdef int n,m,a,b,c,d,NN,na,nb,nc for n in prime_powers(k+2,N-2): # There must exist a OA(k+3,n) thus n>=k+2 @@ -657,7 +657,7 @@ cpdef find_thwart_lemma_4_1(int k,int n): not is_available(k,mm+4)): continue - from orthogonal_arrays_build_recursive import thwart_lemma_4_1 + from .orthogonal_arrays_build_recursive import thwart_lemma_4_1 return thwart_lemma_4_1,(k,nn,mm) return False @@ -702,7 +702,7 @@ cpdef find_three_factor_product(int k,int n): not is_available(k,n2) or not is_available(k,n3)): continue - from orthogonal_arrays_build_recursive import three_factor_product + from .orthogonal_arrays_build_recursive import three_factor_product return three_factor_product,(k-1,n1,n2,n3) return False @@ -727,7 +727,7 @@ cpdef find_brouwer_separable_design(int k,int n): sage: find_brouwer_separable_design(5,14) False """ - from orthogonal_arrays_build_recursive import brouwer_separable_design + from .orthogonal_arrays_build_recursive import brouwer_separable_design cdef int q,x,baer_subplane_size, max_t, min_t, t,e1,e2,e3,e4 for q in prime_powers(2,n): @@ -938,13 +938,13 @@ cpdef find_brouwer_van_rees_with_one_truncated_column(int k,int n): values = int_as_sum(remainder, available_multipliers, r) if values is not None: - from orthogonal_arrays import wilson_construction + from .orthogonal_arrays import wilson_construction return (wilson_construction, (None,k,r,m,[[(x,1) for x in values]])) return False -from designs_pyx cimport _OA_cache, _OA_cache_size +from .designs_pyx cimport _OA_cache, _OA_cache_size cdef int is_available(int k,int n) except -1: r""" Return whether Sage can build an OA(k,n) diff --git a/src/sage/geometry/triangulation/base.pyx b/src/sage/geometry/triangulation/base.pyx index 22fb3af870e..291b9bcd7d2 100644 --- a/src/sage/geometry/triangulation/base.pyx +++ b/src/sage/geometry/triangulation/base.pyx @@ -16,6 +16,7 @@ AUTHORS: # # http://www.gnu.org/licenses/ ######################################################################## +from __future__ import absolute_import from sage.misc.fast_methods cimport hash_by_id from sage.structure.sage_object cimport SageObject @@ -25,8 +26,8 @@ from sage.matrix.constructor import matrix from sage.misc.misc import uniq from sage.misc.cachefunc import cached_method -from functions cimport binomial -from triangulations cimport \ +from .functions cimport binomial +from .triangulations cimport \ triangulations_ptr, init_triangulations, next_triangulation, delete_triangulations @@ -1016,10 +1017,6 @@ cdef class ConnectedTriangulationsIterator(SageObject): (9, 10) """ t = next_triangulation(self._tp) - if len(t)==0: + if len(t) == 0: raise StopIteration return t - - - - diff --git a/src/sage/graphs/base/c_graph.pyx b/src/sage/graphs/base/c_graph.pyx index 3d11c4ea00f..d354937dbfb 100644 --- a/src/sage/graphs/base/c_graph.pyx +++ b/src/sage/graphs/base/c_graph.pyx @@ -38,7 +38,7 @@ method :meth:`realloc `. # Distributed under the terms of the GNU General Public License (GPL) # http://www.gnu.org/licenses/ #************************************************************************** -from __future__ import print_function +from __future__ import print_function, absolute_import include "sage/data_structures/bitset.pxi" diff --git a/src/sage/graphs/base/graph_backends.pyx b/src/sage/graphs/base/graph_backends.pyx index f5ab9e8dc32..ccdff17186b 100644 --- a/src/sage/graphs/base/graph_backends.pyx +++ b/src/sage/graphs/base/graph_backends.pyx @@ -54,8 +54,11 @@ Classes and methods # Distributed under the terms of the GNU General Public License (GPL) # http://www.gnu.org/licenses/ #******************************************************************************* -from c_graph cimport CGraphBackend -from c_graph cimport CGraph +from __future__ import absolute_import + +from .c_graph cimport CGraphBackend +from .c_graph cimport CGraph + cdef class GenericGraphBackend(SageObject): """ @@ -670,9 +673,9 @@ cdef class GenericGraphBackend(SageObject): sage: loads(dumps(gi)) == gi True """ - from static_sparse_backend import StaticSparseBackend - from sparse_graph import SparseGraphBackend - from dense_graph import DenseGraphBackend + from .static_sparse_backend import StaticSparseBackend + from .sparse_graph import SparseGraphBackend + from .dense_graph import DenseGraphBackend # implementation, data_structure, multiedges, directed, loops if isinstance(self, CGraphBackend): diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx index d0df7441e45..e96387998f4 100644 --- a/src/sage/libs/gap/util.pyx +++ b/src/sage/libs/gap/util.pyx @@ -10,11 +10,11 @@ Utility functions for libGAP # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ ############################################################################### -from __future__ import print_function +from __future__ import print_function, absolute_import from sage.env import SAGE_LOCAL from libc.stdint cimport uintptr_t -from element cimport * +from .element cimport * ############################################################################ diff --git a/src/sage/libs/pari/closure.pyx b/src/sage/libs/pari/closure.pyx index 99d4b303e38..a0bf9153953 100644 --- a/src/sage/libs/pari/closure.pyx +++ b/src/sage/libs/pari/closure.pyx @@ -27,7 +27,7 @@ EXAMPLES:: # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** - +from __future__ import absolute_import from cpython.tuple cimport * from cpython.object cimport PyObject_Call @@ -36,8 +36,8 @@ from cpython.ref cimport Py_INCREF include "cysignals/signals.pxi" from .paridecl cimport * -from pari_instance cimport pari_instance -from gen cimport objtogen +from .pari_instance cimport pari_instance +from .gen cimport objtogen cdef inline GEN call_python_func_impl "call_python_func"(GEN* args, object py_func) except NULL: diff --git a/src/sage/matrix/matrix_cyclo_dense.pyx b/src/sage/matrix/matrix_cyclo_dense.pyx index f80721a10f4..c18407e3276 100644 --- a/src/sage/matrix/matrix_cyclo_dense.pyx +++ b/src/sage/matrix/matrix_cyclo_dense.pyx @@ -36,7 +36,7 @@ AUTHORS: # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** - +from __future__ import absolute_import include "cysignals/signals.pxi" include "sage/ext/cdefs.pxi" @@ -46,13 +46,13 @@ from sage.structure.element cimport ModuleElement, RingElement, Element, Vector from sage.misc.randstate cimport randstate, current_randstate from sage.libs.gmp.randomize cimport * -from constructor import matrix -from matrix_space import MatrixSpace -from matrix cimport Matrix -import matrix_dense -from matrix_integer_dense import _lift_crt +from .constructor import matrix +from .matrix_space import MatrixSpace +from .matrix cimport Matrix +from . import matrix_dense +from .matrix_integer_dense import _lift_crt from sage.structure.element cimport Matrix as baseMatrix -from misc import matrix_integer_dense_rational_reconstruction +from .misc import matrix_integer_dense_rational_reconstruction from sage.rings.rational_field import QQ from sage.rings.integer_ring import ZZ @@ -1508,7 +1508,7 @@ cdef class Matrix_cyclo_dense(matrix_dense.Matrix_dense): K = self.base_ring() phi = K.defining_polynomial() from sage.rings.all import GF - from constructor import matrix + from .constructor import matrix F = GF(p) aa = [a for a, _ in phi.change_ring(F).roots()] n = K.degree() diff --git a/src/sage/matrix/matrix_dense.pxd b/src/sage/matrix/matrix_dense.pxd index 8a19d12ccbd..21d17df0116 100644 --- a/src/sage/matrix/matrix_dense.pxd +++ b/src/sage/matrix/matrix_dense.pxd @@ -1,4 +1,4 @@ -from matrix cimport Matrix +from .matrix cimport Matrix cdef class Matrix_dense(Matrix): cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value) diff --git a/src/sage/matrix/matrix_double_dense.pyx b/src/sage/matrix/matrix_double_dense.pyx index 374fce361dc..c18ef165052 100644 --- a/src/sage/matrix/matrix_double_dense.pyx +++ b/src/sage/matrix/matrix_double_dense.pyx @@ -44,24 +44,25 @@ TESTS:: # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import import math import sage.rings.real_double import sage.rings.complex_double -from matrix cimport Matrix +from .matrix cimport Matrix from sage.structure.element cimport ModuleElement,Vector -from constructor import matrix +from .constructor import matrix from sage.modules.free_module_element import vector cimport sage.structure.element -from matrix_space import MatrixSpace +from .matrix_space import MatrixSpace from sage.misc.decorators import rename_keyword cimport numpy as cnumpy -numpy=None -scipy=None +numpy = None +scipy = None # This is for the Numpy C API to work cnumpy.import_array() diff --git a/src/sage/matroids/basis_exchange_matroid.pyx b/src/sage/matroids/basis_exchange_matroid.pyx index 88955d24663..9c249da3076 100644 --- a/src/sage/matroids/basis_exchange_matroid.pyx +++ b/src/sage/matroids/basis_exchange_matroid.pyx @@ -37,13 +37,17 @@ Methods # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import + include 'sage/data_structures/bitset.pxi' -from matroid cimport Matroid -from set_system cimport SetSystem +from .matroid cimport Matroid +from .set_system cimport SetSystem + from copy import copy from itertools import combinations, permutations + cdef class BasisExchangeMatroid(Matroid): r""" Class BasisExchangeMatroid is a virtual class that derives from Matroid. diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index 89574bf5168..c0271f0cff2 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -71,16 +71,21 @@ Methods # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import + include 'sage/data_structures/bitset.pxi' -from matroid cimport Matroid -from basis_exchange_matroid cimport BasisExchangeMatroid -from itertools import permutations + +from .matroid cimport Matroid +from .basis_exchange_matroid cimport BasisExchangeMatroid +from .set_system cimport SetSystem + from sage.arith.all import binomial -from set_system cimport SetSystem -from itertools import combinations + +from itertools import permutations, combinations # class of general matroids, represented by their list of bases + cdef class BasisMatroid(BasisExchangeMatroid): """ Create general matroid, stored as a set of bases. diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 20ece775885..99c8b8bc86a 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -65,9 +65,12 @@ Methods # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** -from matroid cimport Matroid -from set_system cimport SetSystem -from utilities import setprint_s +from __future__ import absolute_import + +from .matroid cimport Matroid +from .set_system cimport SetSystem +from .utilities import setprint_s + cdef class CircuitClosuresMatroid(Matroid): """ diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index e7332b5f814..3015d8082cd 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -108,15 +108,15 @@ Methods # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** -from __future__ import print_function +from __future__ import print_function, absolute_import include 'sage/data_structures/bitset.pxi' from sage.matroids.matroid cimport Matroid from sage.matroids.basis_exchange_matroid cimport BasisExchangeMatroid -from lean_matrix cimport LeanMatrix, GenericMatrix, BinaryMatrix, TernaryMatrix, QuaternaryMatrix, IntegerMatrix, generic_identity -from set_system cimport SetSystem -from utilities import newlabel, spanning_stars, spanning_forest, lift_cross_ratios +from .lean_matrix cimport LeanMatrix, GenericMatrix, BinaryMatrix, TernaryMatrix, QuaternaryMatrix, IntegerMatrix, generic_identity +from .set_system cimport SetSystem +from .utilities import newlabel, spanning_stars, spanning_forest, lift_cross_ratios from sage.graphs.spanning_tree import kruskal from sage.graphs.graph import Graph diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 8ab6790d9a0..84d9aed0919 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -326,15 +326,17 @@ Methods # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import + from sage.structure.sage_object cimport SageObject from itertools import combinations, permutations, product -from set_system cimport SetSystem +from .set_system cimport SetSystem from sage.graphs.spanning_tree import kruskal from sage.graphs.graph import Graph from sage.matrix.constructor import matrix from sage.misc.superseded import deprecation -from utilities import newlabel, sanitize_contractions_deletions, spanning_forest, spanning_stars +from .utilities import newlabel, sanitize_contractions_deletions, spanning_forest, spanning_stars from sage.rings.all import ZZ from sage.numerical.mip import MixedIntegerLinearProgram @@ -1098,7 +1100,7 @@ cdef class Matroid(SageObject): {'e', 'f', 'g', 'h'}, {'a', 'b', 'g', 'h'}, {'c', 'd', 'e', 'f'}}, 4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}} """ - import minor_matroid + from . import minor_matroid return minor_matroid.MinorMatroid(self, contractions, deletions) cpdef _has_minor(self, N): @@ -1194,7 +1196,7 @@ cdef class Matroid(SageObject): sage: [sorted(C) for C in N.circuits() if len(C) == 3] [[0, 1, 6]] """ - import basis_matroid + from . import basis_matroid return basis_matroid.BasisMatroid(self)._extension(element, hyperplanes) # ** user-facing methods ** @@ -3454,8 +3456,8 @@ cdef class Matroid(SageObject): sage: M._is_isomorphism(N, morphism) True """ - import basis_exchange_matroid - import basis_matroid + from . import basis_exchange_matroid + from . import basis_matroid sf = basis_matroid.BasisMatroid(self) if not isinstance(other, basis_exchange_matroid.BasisExchangeMatroid): ot = basis_matroid.BasisMatroid(other) @@ -3530,7 +3532,7 @@ cdef class Matroid(SageObject): sage: M1 == M3 # indirect doctest True """ - import basis_matroid + from . import basis_matroid if op in [0, 1, 4, 5]: # <, <=, >, >= return NotImplemented if left.__class__ != right.__class__: @@ -3866,7 +3868,7 @@ cdef class Matroid(SageObject): {'a', 'e', 'i'}, {'b', 'd', 'i'}, {'g', 'h', 'i'}}, 3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}' """ - import dual_matroid + from . import dual_matroid return dual_matroid.DualMatroid(self) cpdef truncation(self): @@ -4323,7 +4325,7 @@ cdef class Matroid(SageObject): sage: len(list(M.linear_subclasses(line_length=5))) 44 """ - import extension + from . import extension return extension.LinearSubclasses(self, line_length=line_length, subsets=subsets) cpdef extensions(self, element=None, line_length=None, subsets=None): @@ -4382,7 +4384,7 @@ cdef class Matroid(SageObject): 5 """ - import extension + from . import extension if element is None: element = newlabel(self.groundset()) else: @@ -7499,7 +7501,7 @@ cdef class Matroid(SageObject): sage: G.show() """ - import matroids_plot_helpers + from . import matroids_plot_helpers if pos_method == 1 and pos_dict != None: # check sanity of pos_dict and add it to cached info if sane if matroids_plot_helpers.posdict_is_sane(self, pos_dict) == True: @@ -7605,8 +7607,8 @@ cdef class Matroid(SageObject): if self.rank() > 3: raise NotImplementedError # check sanity of pos_dict and add it to cached info if sane - if(pos_dict!=None): - import matroids_plot_helpers + if pos_dict is not None: + from . import matroids_plot_helpers if matroids_plot_helpers.posdict_is_sane(self,pos_dict) ==True: self._cached_info={'plot_positions':pos_dict,'lineorders':lineorders} return @@ -7639,4 +7641,3 @@ cdef class Matroid(SageObject): """ from sage.homology.simplicial_complex import SimplicialComplex return SimplicialComplex(self.no_broken_circuits_sets(ordering)) - diff --git a/src/sage/matroids/union_matroid.pyx b/src/sage/matroids/union_matroid.pyx index 4c51acb2ff9..713bb386c58 100644 --- a/src/sage/matroids/union_matroid.pyx +++ b/src/sage/matroids/union_matroid.pyx @@ -1,4 +1,8 @@ -from matroid cimport Matroid +from __future__ import absolute_import + +from .matroid cimport Matroid + + cdef class MatroidUnion(Matroid): r""" Matroid Union. diff --git a/src/sage/misc/lazy_import.pyx b/src/sage/misc/lazy_import.pyx index 9137a40a399..b21aca6a60f 100644 --- a/src/sage/misc/lazy_import.pyx +++ b/src/sage/misc/lazy_import.pyx @@ -51,14 +51,15 @@ AUTHOR: # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import from cpython.object cimport PyObject_RichCompare import os, cPickle as pickle, operator import inspect -import sageinspect +from . import sageinspect -from lazy_import_cache import get_cache_file +from .lazy_import_cache import get_cache_file cdef binop(op, left, right): if isinstance(left, LazyImport): diff --git a/src/sage/misc/sage_timeit_class.pyx b/src/sage/misc/sage_timeit_class.pyx index 229e4871e90..4c369f8c9b1 100644 --- a/src/sage/misc/sage_timeit_class.pyx +++ b/src/sage/misc/sage_timeit_class.pyx @@ -3,10 +3,11 @@ The ``timeit`` command This uses the function :func:`~sage.misc.sage_timeit.sage_timeit`. """ +from __future__ import absolute_import # This is here in Cython so we can get the interpreter globals -import sage_timeit +from . import sage_timeit class SageTimeit: diff --git a/src/sage/modular/arithgroup/arithgroup_element.pyx b/src/sage/modular/arithgroup/arithgroup_element.pyx index f89997023d2..615cd7ad42b 100644 --- a/src/sage/modular/arithgroup/arithgroup_element.pyx +++ b/src/sage/modular/arithgroup/arithgroup_element.pyx @@ -13,6 +13,7 @@ Elements of Arithmetic Subgroups # http://www.gnu.org/licenses/ # ################################################################################ +from __future__ import absolute_import from sage.structure.element cimport MultiplicativeGroupElement, MonoidElement, Element from sage.rings.all import ZZ @@ -21,7 +22,8 @@ from sage.modular.cusps import Cusp from sage.matrix.matrix_space import MatrixSpace from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense -M2Z = MatrixSpace(ZZ,2) +M2Z = MatrixSpace(ZZ, 2) + cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): r""" @@ -78,7 +80,7 @@ cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): True """ if check: - from all import is_ArithmeticSubgroup + from .arithgroup_generic import is_ArithmeticSubgroup if not is_ArithmeticSubgroup(parent): raise TypeError("parent (= %s) must be an arithmetic subgroup"%parent) @@ -106,7 +108,7 @@ cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): sage: x = matrix(ZZ,2,[1,1,0,1]) sage: unpickle_build(si, (Gamma0(13), {'_ArithmeticSubgroupElement__x': x})) """ - from all import SL2Z + from .congroup_sl2z import SL2Z oldparent, kwdict = state self._set_parent(SL2Z) if '_ArithmeticSubgroupElement__x' in kwdict: @@ -424,7 +426,7 @@ cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): [0 1] )) """ - from all import SL2Z + from .congroup_sl2z import SL2Z return SL2Z, (self.__x,) def multiplicative_order(self): diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 8fd4c9c37f0..b11893730f9 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -28,7 +28,7 @@ AUTHORS: # # http://www.gnu.org/licenses/ #***************************************************************************** -from __future__ import print_function +from __future__ import print_function, absolute_import from cpython.list cimport * from cpython.object cimport PyObject @@ -49,8 +49,8 @@ from sage.modules.free_module_element import vector from sage.rings.real_double import RDF from sage.misc.temporary_file import tmp_filename -from texture import Texture, is_Texture -from transform cimport Transformation, point_c, face_c +from .texture import Texture, is_Texture +from .transform cimport Transformation, point_c, face_c include "point_c.pxi" from sage.interfaces.tachyon import tachyon_rt @@ -1196,7 +1196,7 @@ end_scene""" % (render_params.antialiasing, T = [xyz_min[i] - a_min[i] for i in range(3)] X = X.translate(T) if frame: - from shapes2 import frame3d, frame_labels + from .shapes2 import frame3d, frame_labels F = frame3d(xyz_min, xyz_max, opacity=0.5, color=(0,0,0), thickness=thickness) if labels: F += frame_labels(xyz_min, xyz_max, a_min_orig, a_max_orig) @@ -1205,7 +1205,7 @@ end_scene""" % (render_params.antialiasing, if axes: # draw axes - from shapes import arrow3d + from .shapes import arrow3d A = (arrow3d((min(0,a_min[0]),0, 0), (max(0,a_max[0]), 0,0), thickness, color="blue"), arrow3d((0,min(0,a_min[1]), 0), (0, max(0,a_max[1]), 0), diff --git a/src/sage/structure/factory.pyx b/src/sage/structure/factory.pyx index d210c101cfe..d97dc95716c 100644 --- a/src/sage/structure/factory.pyx +++ b/src/sage/structure/factory.pyx @@ -53,10 +53,11 @@ AUTHORS: # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import import types -from sage_object cimport SageObject +from .sage_object cimport SageObject cdef sage_version from sage.version import version as sage_version From f09dd88e7410e45941648b6db4841666d9b94cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Mon, 15 Aug 2016 15:40:29 +0300 Subject: [PATCH 071/135] Add certificate to is_complemented(). --- src/sage/combinat/posets/hasse_diagram.py | 46 ++++++++++++----------- src/sage/combinat/posets/lattices.py | 41 +++++++++++++++++--- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index 87a04f4936d..39f37f40a1f 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -1383,36 +1383,40 @@ def vertical_decomposition(self, return_list=False): result.pop() # Remove the top element. return result - def is_complemented_lattice(self): - r""" - Return ``True`` if ``self`` is the Hasse diagram of a - complemented lattice, and ``False`` otherwise. + def is_complemented(self): + """ + Return an element of the lattice that has no complement. + + If the lattice is complemented, return ``None``. EXAMPLES:: sage: from sage.combinat.posets.hasse_diagram import HasseDiagram - sage: H = HasseDiagram({0:[1, 2, 3], 1:[4], 2:[4], 3:[4]}) - sage: H.is_complemented_lattice() - True sage: H = HasseDiagram({0:[1, 2], 1:[3], 2:[3], 3:[4]}) - sage: H.is_complemented_lattice() - False + sage: H.is_complemented() + 1 + + sage: H = HasseDiagram({0:[1, 2, 3], 1:[4], 2:[4], 3:[4]}) + sage: H.is_complemented() is None + True """ - from itertools import izip - try: - mt = self.meet_matrix() - jn = self.join_matrix() - except ValueError: - return False - n = self.cardinality() - 1 - for row1, row2 in izip(mt, jn): - for c1, c2 in izip(row1, row2): - if c1 == 0 and c2 == n: + mt = self.meet_matrix() + jn = self.join_matrix() + top = self.cardinality()-1 + has_complement = [False]*top + + for i in xrange(1, top): + if has_complement[i]: + continue + for j in xrange(top, 0, -1): + if jn[i,j] == top and mt[i,j] == 0: + has_complement[j] = True break else: - return False - return True + return i + + return None def complements(self): r""" diff --git a/src/sage/combinat/posets/lattices.py b/src/sage/combinat/posets/lattices.py index 4a59b17ffc7..fe6517af9ec 100644 --- a/src/sage/combinat/posets/lattices.py +++ b/src/sage/combinat/posets/lattices.py @@ -788,22 +788,53 @@ def is_join_semidistributive(self): return self._hasse_diagram.is_semidistributive('join') is None - def is_complemented(self): + def is_complemented(self, certificate=False): r""" - Returns ``True`` if ``self`` is a complemented lattice, and + Return ``True`` if the lattice is complemented, and ``False`` otherwise. + A lattice is complemented if every element has at least one + complement. + + INPUT: + + - ``certificate`` -- (default: ``False``) whether to return + a certificate + + OUTPUT: + + - If ``certificate=True`` return either ``(True, None)`` or + ``(False, e)``, where ``e`` is an element without a complement. + If ``certificate=False`` return ``True`` or ``False``. + + .. SEEALSO:: + + :meth:`complements` + EXAMPLES:: - sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) + sage: L = LatticePoset({0: [1, 2, 3], 1: [4], 2: [4], 3: [4]}) sage: L.is_complemented() True - sage: L = LatticePoset({0:[1,2],1:[3],2:[3],3:[4]}) + sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], 4: [6], + ....: 5: [7], 6: [7]}) sage: L.is_complemented() False + sage: L.is_complemented(certificate=True) + (False, 2) + + TESTS:: + + sage: [Posets.ChainPoset(i).is_complemented() for i in range(5)] + [True, True, True, False, False] """ - return self._hasse_diagram.is_complemented_lattice() + e = self._hasse_diagram.is_complemented() + if not certificate: + return e is None + if e is None: + return (True, None) + return (False, self._vertex_to_element(e)) def is_relatively_complemented(self, certificate=False): """ From 5e6e2615fc5fd7e607f920f167a2b1b6571c2534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 15 Aug 2016 18:38:01 +0200 Subject: [PATCH 072/135] more py3 imports in pyx files --- src/sage/combinat/designs/designs_pyx.pyx | 4 ++-- src/sage/combinat/designs/evenly_distributed_sets.pyx | 4 ++-- src/sage/functions/prime_pi.pyx | 3 ++- src/sage/libs/mpmath/ext_libmp.pyx | 6 +++--- src/sage/matrix/action.pyx | 4 ++-- src/sage/matrix/change_ring.pyx | 7 ++++--- src/sage/matrix/misc.pyx | 11 ++++++----- src/sage/matrix/strassen.pyx | 4 ++-- src/sage/rings/polynomial/polynomial_ring.py | 4 ++-- 9 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/sage/combinat/designs/designs_pyx.pyx b/src/sage/combinat/designs/designs_pyx.pyx index 60b0cd06999..0316a6b55e3 100644 --- a/src/sage/combinat/designs/designs_pyx.pyx +++ b/src/sage/combinat/designs/designs_pyx.pyx @@ -6,7 +6,7 @@ This module implements the design methods that need to be somewhat efficient. Functions --------- """ -from __future__ import print_function +from __future__ import print_function, absolute_import include "sage/data_structures/bitset.pxi" include "cysignals/memory.pxi" @@ -595,7 +595,7 @@ def is_quasi_difference_matrix(M,G,int k,int lmbda,int mu,int u,verbose=False): Column 1 contains 2 empty entries instead of the expected lambda.u=1.1=1 False """ - from difference_family import group_law + from .difference_family import group_law assert k>=2 assert lmbda >=1 diff --git a/src/sage/combinat/designs/evenly_distributed_sets.pyx b/src/sage/combinat/designs/evenly_distributed_sets.pyx index dcffad25cc6..26043d0a15a 100644 --- a/src/sage/combinat/designs/evenly_distributed_sets.pyx +++ b/src/sage/combinat/designs/evenly_distributed_sets.pyx @@ -15,7 +15,7 @@ might want to update this database with more values. Classes and methods ------------------- """ -from __future__ import print_function +from __future__ import print_function, absolute_import cimport cython @@ -311,7 +311,7 @@ cdef class EvenlyDistributedSetsBacktracker: xe = self.K.multiplicative_generator() ** (self.e) df = [[xe**j*b for b in B] for j in range((self.q-1)/(2*self.e))] if check: - from difference_family import is_difference_family + from .difference_family import is_difference_family if not is_difference_family(self.K, df, self.q, self.k, 1): raise RuntimeError("a wrong evenly distributed set was " "produced by the Sage library for the parameters:\n" diff --git a/src/sage/functions/prime_pi.pyx b/src/sage/functions/prime_pi.pyx index 9d7635cff1b..8590db30f0c 100644 --- a/src/sage/functions/prime_pi.pyx +++ b/src/sage/functions/prime_pi.pyx @@ -27,6 +27,7 @@ EXAMPLES:: # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import absolute_import include "cysignals/memory.pxi" include "cysignals/signals.pxi" @@ -41,7 +42,7 @@ from sage.libs.gmp.mpz cimport * cdef uint64_t arg_to_uint64(x, str s1, str s2) except -1: if not isinstance(x, Integer): - from other import floor + from .other import floor x = Integer(floor(x)) if mpz_sgn((x).value) <= 0: return 0ull diff --git a/src/sage/libs/mpmath/ext_libmp.pyx b/src/sage/libs/mpmath/ext_libmp.pyx index 9c2fc924205..a4c64886e1d 100644 --- a/src/sage/libs/mpmath/ext_libmp.pyx +++ b/src/sage/libs/mpmath/ext_libmp.pyx @@ -1,13 +1,13 @@ """ Faster versions of some key functions in mpmath.libmp. """ -from __future__ import print_function +from __future__ import print_function, absolute_import -from ext_impl cimport * +from .ext_impl cimport * from sage.libs.gmp.all cimport * from sage.rings.integer cimport Integer -from ext_impl import exp_fixed, cos_sin_fixed, log_int_fixed +from .ext_impl import exp_fixed, cos_sin_fixed, log_int_fixed # Note: not thread-safe cdef MPF tmp1 diff --git a/src/sage/matrix/action.pyx b/src/sage/matrix/action.pyx index eca14ef4b3a..0119ad3710f 100644 --- a/src/sage/matrix/action.pyx +++ b/src/sage/matrix/action.pyx @@ -59,11 +59,11 @@ AUTHOR: # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** - +from __future__ import absolute_import import operator -from matrix_space import MatrixSpace, is_MatrixSpace +from .matrix_space import MatrixSpace, is_MatrixSpace from sage.modules.free_module import FreeModule, is_FreeModule from sage.structure.element cimport coercion_model diff --git a/src/sage/matrix/change_ring.pyx b/src/sage/matrix/change_ring.pyx index 1f80ba1a663..7d8ad3fe133 100644 --- a/src/sage/matrix/change_ring.pyx +++ b/src/sage/matrix/change_ring.pyx @@ -1,10 +1,11 @@ """ Functions for changing the base ring of matrices quickly. """ +from __future__ import absolute_import -from matrix_space import MatrixSpace -from matrix_real_double_dense cimport Matrix_real_double_dense -from matrix_integer_dense cimport Matrix_integer_dense +from .matrix_space import MatrixSpace +from .matrix_real_double_dense cimport Matrix_real_double_dense +from .matrix_integer_dense cimport Matrix_integer_dense from sage.rings.real_double import RDF diff --git a/src/sage/matrix/misc.pyx b/src/sage/matrix/misc.pyx index 8e7dfca527d..2b960b5c6f7 100644 --- a/src/sage/matrix/misc.pyx +++ b/src/sage/matrix/misc.pyx @@ -9,6 +9,7 @@ existence of this file -- is now a non-issue, since some bugs in Cython were fixed. Probably all this code should be moved into the relevant classes and this file deleted. """ +from __future__ import absolute_import include "cysignals/signals.pxi" include "sage/ext/cdefs.pxi" @@ -25,11 +26,11 @@ include 'sage/modules/vector_rational_sparse_c.pxi' include 'sage/modules/vector_modn_sparse_h.pxi' include 'sage/modules/vector_modn_sparse_c.pxi' -from matrix0 cimport Matrix -from matrix_integer_dense cimport Matrix_integer_dense -from matrix_integer_sparse cimport Matrix_integer_sparse -from matrix_rational_dense cimport Matrix_rational_dense -from matrix_rational_sparse cimport Matrix_rational_sparse +from .matrix0 cimport Matrix +from .matrix_integer_dense cimport Matrix_integer_dense +from .matrix_integer_sparse cimport Matrix_integer_sparse +from .matrix_rational_dense cimport Matrix_rational_dense +from .matrix_rational_sparse cimport Matrix_rational_sparse from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ diff --git a/src/sage/matrix/strassen.pyx b/src/sage/matrix/strassen.pyx index 6848158dbdf..466a8ca6d78 100644 --- a/src/sage/matrix/strassen.pyx +++ b/src/sage/matrix/strassen.pyx @@ -13,9 +13,9 @@ multiplication algorithms. # # http://www.gnu.org/licenses/ ################################################################################ -from __future__ import print_function +from __future__ import print_function, absolute_import -from matrix_window cimport MatrixWindow +from .matrix_window cimport MatrixWindow include "cysignals/signals.pxi" diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index 6797027a039..efe39ce7532 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -286,8 +286,8 @@ def __init__(self, base_ring, name=None, sparse=False, element_class=None, categ if is_PolynomialRing(base_ring): self._Karatsuba_threshold = 0 else: - from sage.matrix.matrix_space import is_MatrixSpace - if is_MatrixSpace(base_ring): + from sage.matrix.matrix_space import MatrixSpace + if isinstance(base_ring, MatrixSpace): self._Karatsuba_threshold = 0 else: self._Karatsuba_threshold = 8 From 7d99aa5b0ec3b471b216cb0216b1f29ceca3d47a Mon Sep 17 00:00:00 2001 From: Aram Dermenjian Date: Mon, 15 Aug 2016 16:57:52 -0400 Subject: [PATCH 073/135] Update plot to keep information from extra kwds instead of overwriting them --- src/sage/plot/plot.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index 2e0c8155031..afefbee4315 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -1828,6 +1828,12 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) if hasattr(funcs, 'plot'): G = funcs.plot(*args, **original_opts) + + # If we already have certain items already set, then update them + for ext in G._extra_kwds: + if ext in G_kwds: + G_kwds[ext] = G._extra_kwds[ext] + # if we are using the generic plotting method else: n = len(args) From 18e134827efea0245a4276307156953caeb4c11b Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Tue, 16 Aug 2016 10:02:18 +0200 Subject: [PATCH 074/135] Trac #21164: 64bit vs 32bite --- src/sage/misc/lazy_list.pyx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sage/misc/lazy_list.pyx b/src/sage/misc/lazy_list.pyx index bebccb6b37d..447ba5fb04a 100644 --- a/src/sage/misc/lazy_list.pyx +++ b/src/sage/misc/lazy_list.pyx @@ -921,7 +921,8 @@ cdef class lazy_list_generic(object): sage: L._info() cache length 5 start 2 - stop 9223372036854775807 + stop 9223372036854775807 # 64-bit + stop 2147483647 # 32-bit step 1 """ if self.master is not None: # this is a slice @@ -1028,7 +1029,8 @@ cdef class lazy_list_from_iterator(lazy_list_generic): sage: L._info() cache length 5 start 2 - stop 9223372036854775807 + stop 9223372036854775807 # 64-bit + stop 2147483647 # 32-bit step 1 """ while len(self.cache) <= i: @@ -1112,7 +1114,8 @@ cdef class lazy_list_from_function(lazy_list_generic): sage: L._info() cache length 5 start 2 - stop 9223372036854775807 + stop 9223372036854775807 # 64-bit + stop 2147483647 # 32-bit step 1 """ while len(self.cache) <= i: @@ -1191,7 +1194,8 @@ cdef class lazy_list_from_update_function(lazy_list_generic): sage: L._info() cache length 7 start 2 - stop 9223372036854775807 + stop 9223372036854775807 # 64-bit + stop 2147483647 # 32-bit step 1 """ cdef Py_ssize_t l,ll From a4adca5f24de505dfe56316ddc9bd47954746415 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Tue, 16 Aug 2016 11:07:51 +0200 Subject: [PATCH 075/135] Change the patch order so that configure gets touched after configure.in --- build/pkgs/ecm/patches/cygwin.patch | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/build/pkgs/ecm/patches/cygwin.patch b/build/pkgs/ecm/patches/cygwin.patch index 5afe8cb952e..219d8f34ed9 100644 --- a/build/pkgs/ecm/patches/cygwin.patch +++ b/build/pkgs/ecm/patches/cygwin.patch @@ -1,17 +1,5 @@ Make sure the assembly routines use the appropriate calling convention for Windows in Cygwin as well. See https://trac.sagemath.org/ticket/21223 -diff -ruN a/configure b/configure ---- a/configure 2016-08-11 13:51:46.936572300 +0200 -+++ b/configure 2016-08-11 13:53:31.281801500 +0200 -@@ -12957,7 +12957,7 @@ - - - case $host in -- *-*-mingw32) -+ *-*-mingw32|*cygwin*) - echo 'define(, <1>)' >>$gmp_tmpconfigm4 - - diff -ruN a/configure.in b/configure.in --- a/configure.in 2016-08-11 13:51:46.869520300 +0200 +++ b/configure.in 2016-08-11 13:52:46.240830400 +0200 @@ -24,3 +12,15 @@ diff -ruN a/configure.in b/configure.in AC_DEFINE([WINDOWS64_ABI], 1,[Define to 1 if x86_64 mulredc*() functions should be called with Windows ABI]);; *) ;; esac +diff -ruN a/configure b/configure +--- a/configure 2016-08-11 13:51:46.936572300 +0200 ++++ b/configure 2016-08-11 13:53:31.281801500 +0200 +@@ -12957,7 +12957,7 @@ + + + case $host in +- *-*-mingw32) ++ *-*-mingw32|*cygwin*) + echo 'define(, <1>)' >>$gmp_tmpconfigm4 + + From 7b77cada90c47df4301480a298fc2f95c7eaf79f Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Tue, 16 Aug 2016 10:57:18 +0200 Subject: [PATCH 076/135] Improve warnings in doctester --- src/sage/doctest/forker.py | 49 ++++++++++++++++++++------------------ src/sage/misc/stopgap.pyx | 20 +++++++--------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index d3daed67e8d..3e358b0d937 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -125,35 +125,38 @@ def init_sage(): stringPict.terminal_width = lambda self:0 -def warning_function(file): +def showwarning_with_traceback(message, category, filename, lineno, file=sys.stderr, line=None): r""" - Creates a function that prints warnings to the given file. + Displays a warning message with a traceback. - INPUT: - - - ``file`` -- an open file handle. - - OUTPUT: + INPUT: see :func:`warnings.showwarning`. - - a function that prings warnings to the given file. + OUTPUT: None EXAMPLES:: - sage: from sage.doctest.forker import warning_function - sage: import tempfile - sage: F = tempfile.TemporaryFile() - sage: wrn = warning_function(F) - sage: wrn("bad stuff", UserWarning, "myfile.py", 0) - sage: F.seek(0) - sage: F.read() - 'doctest:...: UserWarning: bad stuff\n' + sage: from sage.doctest.forker import showwarning_with_traceback + sage: showwarning_with_traceback("bad stuff", UserWarning, "myfile.py", 0) + doctest:warning + ... + File "", line 1, in + showwarning_with_traceback("bad stuff", UserWarning, "myfile.py", Integer(0)) + : + UserWarning: bad stuff """ - def doctest_showwarning(message, category, filename, lineno, file=file, line=None): - try: - file.write(warnings.formatwarning(message, category, 'doctest', lineno, line)) - except IOError: - pass # the file (probably stdout) is invalid - return doctest_showwarning + # Get traceback to display in warning + tb = traceback.extract_stack() + tb = tb[:-1] # Drop this stack frame for showwarning_with_traceback() + + # Format warning + lines = ["doctest:warning\n"] # Match historical warning messages in doctests + lines.extend(traceback.format_list(tb)) + lines.append(":\n") # Match historical warning messages in doctests + lines.extend(traceback.format_exception_only(category, message)) + try: + file.writelines(lines) + except IOError: + pass # the file is invalid class SageSpoofInOut(SageObject): @@ -605,7 +608,7 @@ def run(self, test, compileflags=None, out=None, clear_globs=True): """ self.setters = {} randstate.set_random_seed(long(0)) - warnings.showwarning = warning_function(sys.stdout) + warnings.showwarning = showwarning_with_traceback self.running_doctest_digest = hashlib.md5() self.test = test if compileflags is None: diff --git a/src/sage/misc/stopgap.pyx b/src/sage/misc/stopgap.pyx index d15918559da..67e80a6853e 100644 --- a/src/sage/misc/stopgap.pyx +++ b/src/sage/misc/stopgap.pyx @@ -2,13 +2,15 @@ Stopgaps """ -######################################################################## +#***************************************************************************** # Copyright (C) 2012 William Stein # -# Distributed under the terms of the GNU General Public License (GPL) -# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. # http://www.gnu.org/licenses/ -######################################################################## +#***************************************************************************** import warnings @@ -32,10 +34,8 @@ def set_state(bint mode): sage: sage.misc.stopgap.set_state(True) sage: sage.misc.stopgap.stopgap("Displays something.", 123456) doctest:...: - ******************************************************************************** - Displays something. + StopgapWarning: Displays something. This issue is being tracked at http://trac.sagemath.org/sage_trac/ticket/123456. - ******************************************************************************** sage: sage.misc.stopgap.set_state(False) """ global ENABLED @@ -67,11 +67,9 @@ def stopgap(message, int ticket_no): sage: import sage.misc.stopgap sage: sage.misc.stopgap.set_state(True) sage: sage.misc.stopgap.stopgap("Computation of heights on elliptic curves over number fields can return very imprecise results.", 12509) - doctest:...: - ******************************************************************************** - Computation of heights on elliptic curves over number fields can return very imprecise results. + doctest:... + StopgapWarning: Computation of heights on elliptic curves over number fields can return very imprecise results. This issue is being tracked at http://trac.sagemath.org/sage_trac/ticket/12509. - ******************************************************************************** sage: sage.misc.stopgap.stopgap("This is not printed", 12509) sage: sage.misc.stopgap.set_state(False) # so rest of doctesting fine """ From b2ebe0b1c13b61aeccbbf87fbf44351a82044455 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Tue, 16 Aug 2016 16:03:38 +0200 Subject: [PATCH 077/135] Added patch description --- build/pkgs/r/patches/rcmd_exec.patch | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/pkgs/r/patches/rcmd_exec.patch b/build/pkgs/r/patches/rcmd_exec.patch index 581491dab91..e9550fc3781 100644 --- a/build/pkgs/r/patches/rcmd_exec.patch +++ b/build/pkgs/r/patches/rcmd_exec.patch @@ -1,3 +1,8 @@ +On Cygwin some of the scripts in $R_HOME/bin can fail to be recognized +as executable, because they do no contain a shebang line and, depending +on the ACL settings in the Cygwin mount, may not have an executable flag +either. This results in the scripts not being run properly. It's fine +to just check that they exist. See https://trac.sagemath.org/ticket/20655 --- a/src/scripts/Rcmd.in 2016-05-24 17:54:31.786568400 +0200 +++ b/src/scripts/Rcmd.in 2016-05-24 17:54:55.402067200 +0200 @@ -50,7 +50,7 @@ From 53ada4539978b91c61ae2622d27ce64c8747f067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 15 Aug 2016 10:38:30 +0200 Subject: [PATCH 078/135] start handling removed attributes func_* and im_* --- src/fpickle_setup.py | 33 ++++++++++++++---------- src/sage/categories/primer.py | 3 ++- src/sage/categories/sets_cat.py | 3 ++- src/sage/combinat/integer_lists/lists.py | 5 ++-- src/sage/functions/piecewise.py | 4 ++- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/fpickle_setup.py b/src/fpickle_setup.py index 503fd7313b4..f9572d2546d 100644 --- a/src/fpickle_setup.py +++ b/src/fpickle_setup.py @@ -1,33 +1,35 @@ """ The purpose of this file is to allow instancemethods to be pickable. This is needed in setup.py only and not installed anywhere, thus is not -a library file. It solves the issue from #11874. +a library file. It solves the issue from :trac:`11874`. """ - import types -from six.moves import copyreg import copy - +from six.moves import copyreg +from six import get_method_function, get_method_self # The following four methods are taken from twisted.persisted.styles # into sage.misc.fpickle, and then here. It was needed due to # chicken vs egg issue, as we cannot use sage.misc.fpickle in # setup.py of sage-***.spkg + + def pickleMethod(method): 'support function for copyreg to pickle method refs' - return unpickleMethod, (method.im_func.__name__, - method.im_self, - method.im_class) + return unpickleMethod, (get_method_function(method).__name__, + get_method_self(method), + get_method_self(method).__class__) + def unpickleMethod(im_name, - im_self, - im_class): + im_self, + im_class): 'support function for copyreg to unpickle method refs' try: - unbound = getattr(im_class,im_name) + unbound = getattr(im_class, im_name) if im_self is None: return unbound - bound=types.MethodType(unbound.im_func, + bound = types.MethodType(get_method_function(unbound), im_self) return bound except AttributeError: @@ -35,10 +37,10 @@ def unpickleMethod(im_name, # Attempt a common fix before bailing -- if classes have # changed around since we pickled this method, we may still be # able to get it by looking on the instance's current class. - unbound = getattr(im_self.__class__,im_name) + unbound = getattr(im_self.__class__, im_name) if im_self is None: return unbound - bound=types.MethodType(unbound.im_func, + bound = types.MethodType(get_method_function(unbound), im_self) return bound @@ -48,15 +50,18 @@ def unpickleMethod(im_name, oldModules = {} + def pickleModule(module): 'support function for copyreg to pickle module refs' return unpickleModule, (module.__name__,) + def unpickleModule(name): 'support function for copyreg to unpickle module refs' if name in oldModules: name = oldModules[name] - return __import__(name,{},{},'x') + return __import__(name, {}, {}, 'x') + copyreg.pickle(types.ModuleType, pickleModule, diff --git a/src/sage/categories/primer.py b/src/sage/categories/primer.py index ae1bbbf3bfa..a121e417acc 100644 --- a/src/sage/categories/primer.py +++ b/src/sage/categories/primer.py @@ -945,7 +945,8 @@ class SubcategoryMethods: sage: x._mul_?? # not tested sage: x._mul_.__module__ 'sage.categories.coercion_methods' - sage: x._mul_.im_func is Magmas.ElementMethods._mul_parent.im_func + sage: from six import get_method_function as gmf + sage: gmf(x._mul_) is gmf(Magmas.ElementMethods._mul_parent) True ``product`` is a mathematical method implemented by the parent:: diff --git a/src/sage/categories/sets_cat.py b/src/sage/categories/sets_cat.py index 30c0b2b6af2..006ff9b2291 100644 --- a/src/sage/categories/sets_cat.py +++ b/src/sage/categories/sets_cat.py @@ -1733,7 +1733,8 @@ def is_finite(self): TESTS:: - sage: C.is_finite.im_func is sage.categories.sets_cat.Sets.Infinite.ParentMethods.is_finite.im_func + sage: from six import get_method_function as gmf + sage: gmf(C.is_finite) is gmf(sage.categories.sets_cat.Sets.Infinite.ParentMethods.is_finite) True """ return False diff --git a/src/sage/combinat/integer_lists/lists.py b/src/sage/combinat/integer_lists/lists.py index 74057fa1eab..9b04a73030a 100644 --- a/src/sage/combinat/integer_lists/lists.py +++ b/src/sage/combinat/integer_lists/lists.py @@ -25,6 +25,7 @@ from sage.structure.list_clone import ClonableArray from sage.structure.parent import Parent from sage.combinat.integer_lists.base import IntegerListsBackend +from six import get_method_function class IntegerList(ClonableArray): @@ -172,9 +173,9 @@ def __eq__(self, other): a = self._element_constructor b = other._element_constructor if ismethod(a): - a = a.im_func + a = get_method_function(a) if ismethod(b): - b = b.im_func + b = get_method_function(b) return a == b def __ne__(self, other): diff --git a/src/sage/functions/piecewise.py b/src/sage/functions/piecewise.py index a8dd006b189..b7824cb61d4 100644 --- a/src/sage/functions/piecewise.py +++ b/src/sage/functions/piecewise.py @@ -75,6 +75,8 @@ from sage.rings.rational_field import QQ from sage.rings.infinity import minus_infinity, infinity +from six import get_function_code + class PiecewiseFunction(BuiltinFunction): def __init__(self): @@ -145,7 +147,7 @@ def __call__(self, function_pieces, **kwds): if isinstance(function, FunctionType): if var is None: var = SR.var('x') - if function.func_code.co_argcount == 0: + if get_function_code(function).co_argcount == 0: function = function() else: function = function(var) From 5888a667a6a29e4b00f888a38a5bedbf5a575312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 16 Aug 2016 18:24:42 +0200 Subject: [PATCH 079/135] trac 21253 reviewer's commit (pep8 only) --- src/sage/combinat/posets/hasse_diagram.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index 39f37f40a1f..df7ff3dbc06 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -1403,14 +1403,14 @@ def is_complemented(self): """ mt = self.meet_matrix() jn = self.join_matrix() - top = self.cardinality()-1 - has_complement = [False]*top + top = self.cardinality() - 1 + has_complement = [False] * top for i in xrange(1, top): if has_complement[i]: continue for j in xrange(top, 0, -1): - if jn[i,j] == top and mt[i,j] == 0: + if jn[i, j] == top and mt[i, j] == 0: has_complement[j] = True break else: From c7b05ff737e1b6a3f5d70b34a1b639f2a50cc26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 16 Aug 2016 19:11:14 +0200 Subject: [PATCH 080/135] py3: handling ifilterfalse and izip_longest --- src/sage/combinat/finite_state_machine.py | 9 +++++---- src/sage/combinat/words/morphism.py | 4 +++- src/sage/sets/set_from_iterator.py | 3 ++- .../tests/article_heuberger_krenn_kropf_fsm-in-sage.py | 8 ++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index dd229935e44..5b2ec666a19 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -932,6 +932,7 @@ import collections import itertools +from six.moves import zip_longest import sage @@ -9755,7 +9756,7 @@ def construct_final_word_out(self, letters, allow_non_final=True): sage: F.state(0).final_word_out [] """ - from itertools import cycle, izip_longest + from itertools import cycle if not isinstance(letters, list): letters = [letters] @@ -12753,14 +12754,14 @@ def cartesian_product(self, other, only_accessible_components=True): def function(*transitions): if equal(t.word_in for t in transitions): return (transitions[0].word_in, - list(itertools.izip_longest( + list(zip_longest( *(t.word_out for t in transitions) ))) else: raise LookupError def final_function(*states): - return list(itertools.izip_longest(*(s.final_word_out + return list(zip_longest(*(s.final_word_out for s in states))) return self.product_FiniteStateMachine( @@ -14072,7 +14073,7 @@ def tupleofwords_to_wordoftuples(tupleofwords): ....: ([1, 2], [3, 4, 5, 6], [7])) [(1, 3, 7), (2, 4, None), (None, 5, None), (None, 6, None)] """ - return list(itertools.izip_longest(*tupleofwords, fillvalue=None)) + return list(zip_longest(*tupleofwords, fillvalue=None)) def wordoftuples_to_tupleofwords(wordoftuples): diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 54d91104587..d20d33ada1d 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -88,6 +88,8 @@ from __future__ import print_function import itertools +from six.moves import filterfalse + from sage.misc.callable_dict import CallableDict from sage.structure.sage_object import SageObject from sage.misc.cachefunc import cached_method @@ -2051,7 +2053,7 @@ def has_left_conjugate(self): sage: WordMorphism('a->abbab,b->abb,c->').has_left_conjugate() True """ - I = itertools.ifilterfalse(FiniteWord_class.is_empty, self.images()) + I = filterfalse(FiniteWord_class.is_empty, self.images()) try: letter = next(I)[0] diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index 0ca8332c086..ec05e14d96c 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -67,11 +67,12 @@ from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets from sage.categories.sets_cat import EmptySetError -from itertools import izip_longest + import os from sage.misc.function_mangling import ArgumentFixer from sage.misc.lazy_list import lazy_list + class EnumeratedSetFromIterator(Parent): """ A class for enumerated set built from an iterator. diff --git a/src/sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py b/src/sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py index ed7abe6e784..8fa1c3db659 100644 --- a/src/sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py +++ b/src/sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py @@ -304,12 +304,12 @@ Sage example in fsm-in-sage.tex, line 815:: - sage: from itertools import izip_longest + sage: from six.moves import zip_longest sage: def final_minus(state1, state2): ....: return [x - y for x, y in - ....: izip_longest(state1.final_word_out, - ....: state2.final_word_out, - ....: fillvalue=0)] + ....: zip_longest(state1.final_word_out, + ....: state2.final_word_out, + ....: fillvalue=0)] Sage example in fsm-in-sage.tex, line 829:: From 272179c1188c531d7a3a5a8aad64002cb4472c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 29 Jul 2016 15:37:08 +0200 Subject: [PATCH 081/135] more cases of python3-compatible divisions --- src/sage/coding/delsarte_bounds.py | 5 +++-- .../designs/group_divisible_designs.py | 7 ++++--- src/sage/combinat/designs/resolvable_bibd.py | 21 +++++++++---------- src/sage/crypto/mq/sbox.py | 8 +++---- src/sage/functions/hyperbolic.py | 6 ++++-- .../hyperbolic_space/hyperbolic_interface.py | 7 ++++--- src/sage/graphs/generic_graph.py | 7 +++---- src/sage/knots/link.py | 7 ++++--- src/sage/logic/logic.py | 5 +++-- src/sage/misc/sage_eval.py | 4 ++-- src/sage/misc/sageinspect.py | 2 +- src/sage/repl/load.py | 4 ++-- src/sage/rings/finite_rings/integer_mod.pyx | 4 ++-- src/sage/symbolic/function.pyx | 3 ++- 14 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/sage/coding/delsarte_bounds.py b/src/sage/coding/delsarte_bounds.py index 934c215c6c6..3c8a57a896e 100644 --- a/src/sage/coding/delsarte_bounds.py +++ b/src/sage/coding/delsarte_bounds.py @@ -18,7 +18,8 @@ # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** -from __future__ import print_function +from __future__ import print_function, division + def Krawtchouk(n,q,l,x,check=True): """ @@ -56,7 +57,7 @@ def Krawtchouk(n,q,l,x,check=True): sage: Krawtchouk(int(3),int(2),int(3),int(3)) -1 sage: Krawtchouk(int(3),int(2),int(3),int(3),check=False) - -5 + -1.0 sage: Kravchuk(24,2,5,4) 2224 diff --git a/src/sage/combinat/designs/group_divisible_designs.py b/src/sage/combinat/designs/group_divisible_designs.py index af79540ff1b..91dcf914a63 100644 --- a/src/sage/combinat/designs/group_divisible_designs.py +++ b/src/sage/combinat/designs/group_divisible_designs.py @@ -22,7 +22,7 @@ Functions --------- """ -from __future__ import absolute_import +from __future__ import absolute_import, division #***************************************************************************** # This program is free software: you can redistribute it and/or modify @@ -182,10 +182,11 @@ def GDD_4_2(q,existence=False,check=True): from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF G = GF(q,'x') w = G.primitive_element() - e = w**((q-1)/3) + e = w**((q - 1) // 3) # A first parallel class is defined. G acts on it, which yields all others. - first_class = [[(0,0),(1,w**i),(1,e*w**i),(1,e*e*w**i)] for i in range((q-1)/6)] + first_class = [[(0,0),(1,w**i),(1,e*w**i),(1,e*e*w**i)] + for i in range((q - 1) // 6)] label = {p:i for i,p in enumerate(G)} classes = [[[2*label[x[1]+g]+(x[0]+j)%2 for x in S] diff --git a/src/sage/combinat/designs/resolvable_bibd.py b/src/sage/combinat/designs/resolvable_bibd.py index bb446f1ac30..a1e01913a5b 100644 --- a/src/sage/combinat/designs/resolvable_bibd.py +++ b/src/sage/combinat/designs/resolvable_bibd.py @@ -47,8 +47,7 @@ Functions --------- """ -from __future__ import print_function -from __future__ import absolute_import +from __future__ import print_function, absolute_import, division from sage.arith.all import is_prime_power from sage.combinat.designs.bibd import BalancedIncompleteBlockDesign @@ -119,7 +118,7 @@ def resolvable_balanced_incomplete_block_design(v,k,existence=False): if k==2: if existence: return True - classes = [[[(c+i)%(v-1),(c+v-i)%(v-1)] for i in range(1,v//2)] + classes = [[[(c+i)%(v-1),(c+v-i)%(v-1)] for i in range(1, v//2)] for c in range(v-1)] for i,classs in enumerate(classes): classs.append([v-1,i]) @@ -211,7 +210,7 @@ def kirkman_triple_system(v,existence=False): q = (v-1)//2 K = GF(q,'x') a = K.primitive_element() - t = (q-1)/6 + t = (q - 1) // 6 # m is the solution of a^m=(a^t+1)/2 from sage.groups.generic import discrete_log @@ -252,7 +251,7 @@ def kirkman_triple_system(v,existence=False): q = v//3 K = GF(q,'x') a = K.primitive_element() - t = (q-1)/6 + t = (q - 1) // 6 A0 = [(0,0),(0,1),(0,2)] B = [[(a**i,j),(a**(i+2*t),j),(a**(i+4*t),j)] for j in range(3) for i in range(t)] @@ -333,7 +332,7 @@ def kirkman_triple_system(v,existence=False): B.pop(0) # Pasting the KTS(n') without {x,x',\infty} blocks - classes = [[] for i in range((v-1)/2)] + classes = [[] for i in range((v-1) // 2)] gdd = {4:gdd4, 7: gdd7} for B in PBD_4_7((v-1)//2,check=False): for i,classs in enumerate(gdd[len(B)]): @@ -622,10 +621,10 @@ def PBD_4_7(v,check=True, existence=False): return PBD_4_7_from_Y(GDD,check=check) - elif v%6 == 1 and GDD_4_2((v-1)/6,existence=True): + elif v % 6 == 1 and GDD_4_2((v - 1) // 6, existence=True): # VII.5.17 from [BJL99] - gdd = GDD_4_2((v-1)/6) - return PBD_4_7_from_Y(gdd,check=check) + gdd = GDD_4_2((v - 1) // 6) + return PBD_4_7_from_Y(gdd, check=check) elif v == 202: # IV.4.5.p from [BJL99] @@ -647,8 +646,8 @@ def PBD_4_7(v,check=True, existence=False): # construction on the truncated transversal design (which is a GDD). # # We write vv = 4g+u while satisfying the hypotheses. - vv = (v-1)/3 - for g in range((vv+5-1)//5,vv//4+1): + vv = (v - 1) // 3 + for g in range((vv + 5 - 1) // 5, vv // 4 + 1): u = vv-4*g if (orthogonal_array(5,g,existence=True) and PBD_4_7(3*g+1,existence=True) and diff --git a/src/sage/crypto/mq/sbox.py b/src/sage/crypto/mq/sbox.py index 3ca6e24e329..a7e92562e88 100644 --- a/src/sage/crypto/mq/sbox.py +++ b/src/sage/crypto/mq/sbox.py @@ -1,7 +1,7 @@ r""" S-Boxes and Their Algebraic Representations """ -from __future__ import print_function +from __future__ import print_function, division from sage.combinat.integer_vector import IntegerVectors from sage.crypto.boolean_function import BooleanFunction @@ -1306,7 +1306,7 @@ def is_almost_bent(self): if is_even(m): return False - return self.nonlinearity() == 2**(m-1) - 2**((m-1)/2) + return self.nonlinearity() == 2**(m-1) - 2**((m-1)//2) def fixed_points(self): """ @@ -1420,10 +1420,10 @@ def is_bent(self): m = self.m n = self.n - if not is_even(m) or n > m/2: + if not is_even(m) or n > m//2: return False - return self.nonlinearity() == 2**(m-1) - 2**(m/2 - 1) + return self.nonlinearity() == 2**(m-1) - 2**(m//2 - 1) def is_involution(self): r""" diff --git a/src/sage/functions/hyperbolic.py b/src/sage/functions/hyperbolic.py index 283f25d7b24..ffba291c133 100644 --- a/src/sage/functions/hyperbolic.py +++ b/src/sage/functions/hyperbolic.py @@ -1,6 +1,8 @@ """ Hyperbolic Functions """ +from __future__ import division + from sage.symbolic.function import GinacFunction, BuiltinFunction from sage.rings.infinity import Infinity from sage.symbolic.expression import Expression @@ -650,7 +652,7 @@ def _eval_numpy_(self, x): sage: import numpy sage: a = numpy.linspace(0,1,3) sage: arcsech(a) - doctest:...: RuntimeWarning: divide by zero encountered in divide + doctest:...: RuntimeWarning: divide by zero encountered in ...divide array([ inf, 1.3169579, 0. ]) """ return arccosh(1.0 / x) @@ -699,7 +701,7 @@ def _eval_numpy_(self, x): sage: import numpy sage: a = numpy.linspace(0,1,3) sage: arccsch(a) - doctest:...: RuntimeWarning: divide by zero encountered in divide + doctest:...: RuntimeWarning: divide by zero encountered in ...divide array([ inf, 1.44363548, 0.88137359]) """ return arcsinh(1.0 / x) diff --git a/src/sage/geometry/hyperbolic_space/hyperbolic_interface.py b/src/sage/geometry/hyperbolic_space/hyperbolic_interface.py index d2a4008207f..947090cfd58 100644 --- a/src/sage/geometry/hyperbolic_space/hyperbolic_interface.py +++ b/src/sage/geometry/hyperbolic_space/hyperbolic_interface.py @@ -40,7 +40,6 @@ sage: HyperbolicPlane().PD().get_point(1/2 + I/2) Point in PD 1/2*I + 1/2 """ - #*********************************************************************** # # Copyright (C) 2013 Greg Laun @@ -52,6 +51,8 @@ # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #*********************************************************************** +from __future__ import division + from sage.structure.unique_representation import UniqueRepresentation from sage.structure.parent import Parent from sage.misc.abstract_method import abstract_method @@ -203,5 +204,5 @@ def _an_element_(self): sage: H.HM().an_element() Point in HM (0, 0, 1) """ - return self(self.realization_of().PD().get_point(0)) - + from sage.rings.integer_ring import ZZ + return self(self.realization_of().PD().get_point(ZZ.zero())) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 38a860b2fc0..11166bf5d25 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -308,8 +308,7 @@ Methods ------- """ -from __future__ import print_function -from __future__ import absolute_import +from __future__ import print_function, absolute_import, division from copy import copy from sage.misc.decorators import options @@ -15909,9 +15908,9 @@ def wiener_index(self, by_weight=False, algorithm=None, check_weight=check_weight)[0] total = 0 for u in distances.values(): - total = total + sum(u.values()) + total += sum(u.values()) - return total / 2 + return total // 2 def average_distance(self, by_weight=False, algorithm=None, weight_function=None): diff --git a/src/sage/knots/link.py b/src/sage/knots/link.py index 4ee1818d302..0484eb0c181 100644 --- a/src/sage/knots/link.py +++ b/src/sage/knots/link.py @@ -50,6 +50,7 @@ # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import division from sage.matrix.constructor import matrix from sage.rings.integer_ring import ZZ @@ -854,7 +855,7 @@ def _enhanced_states(self): ncross = len(crossings) smoothings = [] nmax = max(flatten(crossings)) + 1 - for i in range(2** ncross): + for i in range(2 ** ncross): v = Integer(i).bits() v = v + (ncross - len(v))*[0] G = Graph() @@ -872,7 +873,7 @@ def _enhanced_states(self): G.add_edge((cr[2], cr[3], n), cr[3]) sm = set(tuple(sorted(x for x in b if isinstance(x, tuple))) for b in G.connected_components()) - iindex = (writhe - ncross + 2 * sum(v)) / 2 + iindex = (writhe - ncross + 2 * sum(v)) // 2 jmin = writhe + iindex - len(sm) jmax = writhe + iindex + len(sm) smoothings.append((tuple(v), sm, iindex, jmin, jmax)) @@ -1644,7 +1645,7 @@ def alexander_polynomial(self, var='t'): f = (seifert_matrix - t * seifert_matrix.transpose()).determinant() if f != 0: exp = f.exponents() - return t ** ((-max(exp) - min(exp)) / 2) * f + return t ** ((-max(exp) - min(exp)) // 2) * f return f def determinant(self): diff --git a/src/sage/logic/logic.py b/src/sage/logic/logic.py index c9a70951228..1fc28582cfd 100644 --- a/src/sage/logic/logic.py +++ b/src/sage/logic/logic.py @@ -25,7 +25,7 @@ # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** -from __future__ import print_function +from __future__ import print_function, division import string @@ -388,13 +388,14 @@ def get_bit(x, c): b = 'False' else: b = 'True' - x /= 2 + x = x // 2 bits.append(b) if c > len(bits) - 1: return 'False' else: return bits[c] + def eval(toks): r""" Evaluate the expression contained in ``toks``. diff --git a/src/sage/misc/sage_eval.py b/src/sage/misc/sage_eval.py index 7e9608215c0..4945cfddfea 100644 --- a/src/sage/misc/sage_eval.py +++ b/src/sage/misc/sage_eval.py @@ -10,7 +10,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from __future__ import absolute_import +from __future__ import absolute_import, division import six from copy import copy import sage.repl.preparse as preparser @@ -92,7 +92,7 @@ def sage_eval(source, locals=None, cmds='', preparse=True): :: sage: x = 5 - sage: eval('4/3 + x', {'x':25}) + sage: eval('4/3 + x', {'x':25}) # optional - python2 26 sage: sage_eval('4/3 + x', locals={'x':25}) 79/3 diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index 2f14a0b8d39..6271fc16825 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -654,7 +654,7 @@ def visit_BinOp(self, node): sage: import ast, sage.misc.sageinspect as sms sage: visitor = sms.SageArgSpecVisitor() sage: vis = lambda x: visitor.visit(ast.parse(x).body[0].value) - sage: [vis(d) for d in ['(3+(2*4))', '7|8', '5^3', '7/3', '7//3', '3<<4']] #indirect doctest + sage: [vis(d) for d in ['(3+(2*4))', '7|8', '5^3', '7/3', '7//3', '3<<4']] #indirect doctest # optional - python2 [11, 15, 6, 2, 2, 48] """ op = node.op.__class__.__name__ diff --git a/src/sage/repl/load.py b/src/sage/repl/load.py index 0d8b406ba29..491746fa03d 100644 --- a/src/sage/repl/load.py +++ b/src/sage/repl/load.py @@ -98,9 +98,9 @@ def load(filename, globals, attach=False): sage: t = tmp_filename(ext='.py') sage: open(t,'w').write("print 'hi', 2/3; z = -2/7") sage: z = 1 - sage: sage.repl.load.load(t, globals()) + sage: sage.repl.load.load(t, globals()) # optional - python2 hi 0 - sage: z + sage: z # optional - python2 -1 A ``.sage`` file *is* preparsed:: diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index 58c6b5f1ee3..18ecc165eb5 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -67,7 +67,7 @@ TESTS:: # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** -from __future__ import print_function +from __future__ import print_function, division include "cysignals/signals.pxi" include "sage/ext/stdsage.pxi" @@ -2507,7 +2507,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: e = Mod(8, 2^5 - 1) sage: e >> 3 1 - sage: int(e)/int(2^3) + sage: int(e)/int(2^3) # optional - python2 1 """ if k == 0: diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index c97e875ef3e..aea435579f2 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -12,6 +12,7 @@ Classes for symbolic functions # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import division from .ginac cimport * @@ -704,7 +705,7 @@ cdef class Function(SageObject): sage: import numpy sage: a = numpy.arange(5) sage: csc(a) - doctest:...: RuntimeWarning: divide by zero encountered in divide + doctest:...: RuntimeWarning: divide by zero encountered in ...divide array([ inf, 1.18839511, 1.09975017, 7.0861674 , -1.32134871]) sage: factorial(a) From 2d80c2547ab5b4034d0140c6f8529cd526d89683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 16 Aug 2016 21:14:12 +0200 Subject: [PATCH 082/135] trac 21257 get rid also of ifilter --- .../tutorial-comprehensions.rst | 3 ++- src/sage/combinat/finite_state_machine.py | 11 +++++++---- src/sage/combinat/permutation.py | 5 +++-- src/sage/combinat/tutorial.py | 3 ++- src/sage/dynamics/interval_exchanges/labelled.py | 15 +++++++++------ src/sage/dynamics/interval_exchanges/reduced.py | 5 +++-- src/sage/dynamics/interval_exchanges/template.py | 4 ++-- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst b/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst index 1bcc1e9a3f1..d6740a180e0 100644 --- a/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst +++ b/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst @@ -232,7 +232,8 @@ The functions :func:`map` and :func:`filter` also have an analogue:: sage: list(itertools.imap(lambda z: z.cycle_type(), Permutations(3))) [[1, 1, 1], [2, 1], [2, 1], [3], [3], [2, 1]] - sage: list(itertools.ifilter(lambda z: z.has_pattern([1,2]), Permutations(3))) + sage: from six.moves import filter + sage: list(filter(lambda z: z.has_pattern([1,2]), Permutations(3))) [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2]] diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index 5b2ec666a19..440e528e7e9 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -5522,7 +5522,8 @@ def iter_initial_states(self): sage: [s.label() for s in F.iter_initial_states()] ['A'] """ - return itertools.ifilter(lambda s:s.is_initial, self.iter_states()) + from six.moves import filter + return filter(lambda s:s.is_initial, self.iter_states()) def final_states(self): @@ -5572,8 +5573,8 @@ def iter_final_states(self): sage: [s.label() for s in F.iter_final_states()] ['A', 'C'] """ - return itertools.ifilter(lambda s:s.is_final, self.iter_states()) - + from six.moves import filter + return filter(lambda s:s.is_final, self.iter_states()) def state(self, state): """ @@ -9082,8 +9083,10 @@ def prepone_output(self): Transition from 1 to 0: 0|0, Transition from 1 to 1: 1|1,(0, 0)] """ + from six.moves import filter + def find_common_output(state): - if any(itertools.ifilter( + if any(filter( lambda transition: not transition.word_out, self.transitions(state))) \ or state.is_final and not state.final_word_out: diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 07b26f5c8ab..3f829cf6729 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -1772,10 +1772,11 @@ def number_of_noninversions(self, k): sage: Permutation([2, 1]).number_of_noninversions(3) 0 """ + from six.moves import filter if k > len(self): return 0 - incr_iterator = itertools.ifilter( lambda pos: all( pos[i] < pos[i+1] - for i in range(k-1) ), + incr_iterator = filter( lambda pos: all( pos[i] < pos[i+1] + for i in range(k-1) ), itertools.combinations(self, k) ) return sum(1 for _ in incr_iterator) diff --git a/src/sage/combinat/tutorial.py b/src/sage/combinat/tutorial.py index 56fe5727975..3d428a8647b 100644 --- a/src/sage/combinat/tutorial.py +++ b/src/sage/combinat/tutorial.py @@ -1270,7 +1270,8 @@ or select the elements satisfying a certain condition:: - sage: list(itertools.ifilter(lambda z: z.has_pattern([1,2]), + sage: from six.moves import filter + sage: list(filter(lambda z: z.has_pattern([1,2]), ....: Permutations(3))) [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2]] diff --git a/src/sage/dynamics/interval_exchanges/labelled.py b/src/sage/dynamics/interval_exchanges/labelled.py index 8bc86144cc0..d70e677f63e 100644 --- a/src/sage/dynamics/interval_exchanges/labelled.py +++ b/src/sage/dynamics/interval_exchanges/labelled.py @@ -711,7 +711,8 @@ def LabelledPermutationsIET_iterator(nintervals=None, b a c ***** """ - from itertools import imap, ifilter, product + from itertools import imap, product + from six.moves import filter from sage.combinat.permutation import Permutations if not irreducible: @@ -730,7 +731,7 @@ def LabelledPermutationsIET_iterator(nintervals=None, P = [g(_) for _ in Permutations(nintervals)] return imap(f,product(P,P)) else: - return ifilter( + return filter( lambda x: x.is_irreducible(), LabelledPermutationsIET_iterator(nintervals,False,alphabet)) @@ -2321,11 +2322,12 @@ def full_loop_iterator(self, start=None, max_length=1): [1 1] ***** """ - from itertools import ifilter, imap + from itertools import imap + from six.moves import filter g = self.path(start) - ifull = ifilter( + ifull = filter( lambda x: x.is_loop() and x.is_full(), self._all_path_extension(g,max_length)) @@ -2359,11 +2361,12 @@ def full_nloop_iterator(self, start=None, length=1): [1 1] ***** """ - from itertools import ifilter, imap + from itertools import imap + from six.moves import filter g = self.path(start) - ifull = ifilter( + ifull = filter( lambda x: x.is_loop() and x.is_full(), self._all_npath_extension(g,length)) diff --git a/src/sage/dynamics/interval_exchanges/reduced.py b/src/sage/dynamics/interval_exchanges/reduced.py index 73cda33cabe..f37ff26be64 100644 --- a/src/sage/dynamics/interval_exchanges/reduced.py +++ b/src/sage/dynamics/interval_exchanges/reduced.py @@ -413,7 +413,8 @@ def ReducedPermutationsIET_iterator( a b c c b a """ - from itertools import imap,ifilter + from itertools import imap + from six.moves import filter from sage.combinat.permutation import Permutations if irreducible is False: @@ -430,7 +431,7 @@ def ReducedPermutationsIET_iterator( alphabet=alphabet) return imap(f, Permutations(nintervals)) else: - return ifilter(lambda x: x.is_irreducible(), + return filter(lambda x: x.is_irreducible(), ReducedPermutationsIET_iterator(nintervals,False,alphabet)) class ReducedPermutationIET(ReducedPermutation, PermutationIET): diff --git a/src/sage/dynamics/interval_exchanges/template.py b/src/sage/dynamics/interval_exchanges/template.py index efdc0f64211..abe2fe015d0 100644 --- a/src/sage/dynamics/interval_exchanges/template.py +++ b/src/sage/dynamics/interval_exchanges/template.py @@ -2789,8 +2789,8 @@ def vertex_iterator(self): :: sage: r = iet.RauzyDiagram('a b c d','d c b a') - sage: from itertools import ifilter - sage: r_1n = ifilter(lambda x: x.is_cylindric(), r) + sage: from six.moves import filter + sage: r_1n = filter(lambda x: x.is_cylindric(), r) sage: for p in r_1n: print(p) a b c d d c b a From 141a784aac9d083327f9e8907583ac7a99cc5a31 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Wed, 17 Aug 2016 08:24:21 +0200 Subject: [PATCH 083/135] 21232: change LaTeX, return shortcut --- src/sage/functions/other.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py index 5ee3d3fac90..a8ea4b040d1 100644 --- a/src/sage/functions/other.py +++ b/src/sage/functions/other.py @@ -707,6 +707,8 @@ def __init__(self): frac(x + 5.40000000000000) sage: frac(cos(8)/cos(2)) cos(8)/cos(2) + sage: latex(frac(x)) + \operatorname{frac}\left(x\right) Test pickling:: @@ -714,16 +716,8 @@ def __init__(self): floor """ BuiltinFunction.__init__(self, "frac", - conversions=dict(sympy='frac')) - - def _print_latex_(self, x): - r""" - EXAMPLES:: - - sage: latex(frac(x)) - \left\{ x \right\} - """ - return r"\left\{ %s \right\}"%latex(x) + conversions=dict(sympy='frac'), + latex_name=r"\operatorname{frac}") def _evalf_(self, x, **kwds): """ @@ -749,7 +743,7 @@ def _eval_(self, x): return x - x.floor() except AttributeError: if isinstance(x, (int, long)): - return x - Integer(x) + return Integer(0) elif isinstance(x, (float, complex)): return x - Integer(int(math.floor(x))) elif isinstance(x, sage.symbolic.expression.Expression): From 49f6c3594f20de7097434cafa3417f2ea668af24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 17 Aug 2016 09:38:01 +0200 Subject: [PATCH 084/135] trac 21257 some of reviewer's comments --- src/sage/combinat/permutation.py | 7 ++----- src/sage/combinat/tutorial.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 3f829cf6729..a6e70721def 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -1772,13 +1772,10 @@ def number_of_noninversions(self, k): sage: Permutation([2, 1]).number_of_noninversions(3) 0 """ - from six.moves import filter if k > len(self): return 0 - incr_iterator = filter( lambda pos: all( pos[i] < pos[i+1] - for i in range(k-1) ), - itertools.combinations(self, k) ) - return sum(1 for _ in incr_iterator) + return sum(1 for pos in itertools.combinations(self, k) + if all(pos[i] < pos[i + 1] for i in range(k - 1))) def length(self): r""" diff --git a/src/sage/combinat/tutorial.py b/src/sage/combinat/tutorial.py index 3d428a8647b..329a3342b36 100644 --- a/src/sage/combinat/tutorial.py +++ b/src/sage/combinat/tutorial.py @@ -1242,6 +1242,9 @@ sage: import itertools +The behaviour of this library has changed a lot between Python 2 and +Python 3. What follows is mostly written for Python 2. + We will demonstrate some applications, taking as a starting point the permutations of `3`:: @@ -1255,24 +1258,25 @@ [(0, [1, 2, 3]), (1, [1, 3, 2]), (2, [2, 1, 3]), (3, [2, 3, 1]), (4, [3, 1, 2]), (5, [3, 2, 1])] -select only the elements in positions 2, 3, and 4 (analogue of +or select only the elements in positions 2, 3, and 4 (analogue of ``l[1:4]``):: sage: import itertools sage: list(itertools.islice(Permutations(3), 1, 4)) [[1, 3, 2], [2, 1, 3], [2, 3, 1]] -apply a function to all the elements:: +The itertools methods ``imap`` and ``ifilter`` have been renamed to +``map`` and ``filter`` in Python 3. You should rather avoid using them, +as follows. - sage: list(itertools.imap(lambda z: z.cycle_type(), - ....: Permutations(3))) +To apply a function to all the elements, one can do:: + + sage: [z.cycle_type() for z in Permutations(3)] [[1, 1, 1], [2, 1], [2, 1], [3], [3], [2, 1]] -or select the elements satisfying a certain condition:: +and similarly to select the elements satisfying a certain condition:: - sage: from six.moves import filter - sage: list(filter(lambda z: z.has_pattern([1,2]), - ....: Permutations(3))) + sage: [z for z in Permutations(3) if z.has_pattern([1,2])] [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2]] In all these situations, ``attrcall`` can be an advantageous alternative From afc90d4e8b968e626ea54789f1e05b154b053759 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Wed, 17 Aug 2016 10:12:41 +0200 Subject: [PATCH 085/135] Add terminado as standard package --- build/pkgs/terminado/SPKG.txt | 10 ++++++++++ build/pkgs/terminado/checksums.ini | 4 ++++ build/pkgs/terminado/dependencies | 5 +++++ build/pkgs/terminado/package-version.txt | 1 + build/pkgs/terminado/spkg-install | 3 +++ build/pkgs/terminado/type | 1 + 6 files changed, 24 insertions(+) create mode 100644 build/pkgs/terminado/SPKG.txt create mode 100644 build/pkgs/terminado/checksums.ini create mode 100644 build/pkgs/terminado/dependencies create mode 100644 build/pkgs/terminado/package-version.txt create mode 100755 build/pkgs/terminado/spkg-install create mode 100644 build/pkgs/terminado/type diff --git a/build/pkgs/terminado/SPKG.txt b/build/pkgs/terminado/SPKG.txt new file mode 100644 index 00000000000..8f5a4b8d6ff --- /dev/null +++ b/build/pkgs/terminado/SPKG.txt @@ -0,0 +1,10 @@ += terminado = + +== Description == + +This is a Tornado websocket backend for the term.js Javascript terminal +emulator library. + +It evolved out of pyxterm, which was part of GraphTerm (as lineterm.py), +v0.57.0 (2014-07-18), and ultimately derived from the public-domain +Ajaxterm code, v0.11 (2008-11-13) (also on Github as part of QWeb). diff --git a/build/pkgs/terminado/checksums.ini b/build/pkgs/terminado/checksums.ini new file mode 100644 index 00000000000..227dc1cef2d --- /dev/null +++ b/build/pkgs/terminado/checksums.ini @@ -0,0 +1,4 @@ +tarball=terminado-VERSION.tar.gz +sha1=5b2e42a23d6195474d320d4923c673866ccab07e +md5=5b6c65da27fe1ed07a9f80f0588cdaba +cksum=2602823520 diff --git a/build/pkgs/terminado/dependencies b/build/pkgs/terminado/dependencies new file mode 100644 index 00000000000..2904ced1d75 --- /dev/null +++ b/build/pkgs/terminado/dependencies @@ -0,0 +1,5 @@ +$(PYTHON) | pip ptyprocess tornado + +---------- +All lines of this file are ignored except the first. +It is copied by SAGE_ROOT/build/make/install into SAGE_ROOT/build/make/Makefile. diff --git a/build/pkgs/terminado/package-version.txt b/build/pkgs/terminado/package-version.txt new file mode 100644 index 00000000000..5a2a5806df6 --- /dev/null +++ b/build/pkgs/terminado/package-version.txt @@ -0,0 +1 @@ +0.6 diff --git a/build/pkgs/terminado/spkg-install b/build/pkgs/terminado/spkg-install new file mode 100755 index 00000000000..f3dc65c1dd4 --- /dev/null +++ b/build/pkgs/terminado/spkg-install @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cd src && pip install --verbose --no-index . diff --git a/build/pkgs/terminado/type b/build/pkgs/terminado/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/terminado/type @@ -0,0 +1 @@ +standard From fdb403eb74130532900c41e73c54e5de8fb441d0 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Wed, 17 Aug 2016 11:05:16 +0200 Subject: [PATCH 086/135] Add entrypoints and configparser packages --- build/pkgs/configparser/SPKG.txt | 22 +++++++++++++++++++++ build/pkgs/configparser/checksums.ini | 4 ++++ build/pkgs/configparser/dependencies | 5 +++++ build/pkgs/configparser/package-version.txt | 1 + build/pkgs/configparser/spkg-install | 3 +++ build/pkgs/configparser/type | 1 + build/pkgs/entrypoints/SPKG.txt | 17 ++++++++++++++++ build/pkgs/entrypoints/checksums.ini | 4 ++++ build/pkgs/entrypoints/dependencies | 5 +++++ build/pkgs/entrypoints/package-version.txt | 1 + build/pkgs/entrypoints/setup.py | 9 +++++++++ build/pkgs/entrypoints/spkg-install | 7 +++++++ build/pkgs/entrypoints/type | 1 + 13 files changed, 80 insertions(+) create mode 100644 build/pkgs/configparser/SPKG.txt create mode 100644 build/pkgs/configparser/checksums.ini create mode 100644 build/pkgs/configparser/dependencies create mode 100644 build/pkgs/configparser/package-version.txt create mode 100755 build/pkgs/configparser/spkg-install create mode 100644 build/pkgs/configparser/type create mode 100644 build/pkgs/entrypoints/SPKG.txt create mode 100644 build/pkgs/entrypoints/checksums.ini create mode 100644 build/pkgs/entrypoints/dependencies create mode 100644 build/pkgs/entrypoints/package-version.txt create mode 100755 build/pkgs/entrypoints/setup.py create mode 100755 build/pkgs/entrypoints/spkg-install create mode 100644 build/pkgs/entrypoints/type diff --git a/build/pkgs/configparser/SPKG.txt b/build/pkgs/configparser/SPKG.txt new file mode 100644 index 00000000000..6c687197d7d --- /dev/null +++ b/build/pkgs/configparser/SPKG.txt @@ -0,0 +1,22 @@ += configparser = + +== Description == + +This library brings the updated configparser from Python 3.5 to Python 2.6-3.5. + +The ancient ConfigParser module available in the standard library 2.x +has seen a major update in Python 3.2. This is a backport of those +changes so that they can be used directly in Python 2.6 - 3.5. + +To use the configparser backport instead of the built-in version on both +Python 2 and Python 3, simply import it explicitly as a backport: + + from backports import configparser + +If you'd like to use the backport on Python 2 and the built-in version +on Python 3, use that invocation instead: + + import configparser + +For detailed documentation consult the vanilla version at +http://docs.python.org/3/library/configparser.html. diff --git a/build/pkgs/configparser/checksums.ini b/build/pkgs/configparser/checksums.ini new file mode 100644 index 00000000000..6555456d07f --- /dev/null +++ b/build/pkgs/configparser/checksums.ini @@ -0,0 +1,4 @@ +tarball=configparser-VERSION.tar.gz +sha1=8ee6b29c6a11977c0e094da1d4f5f71e7e7ac78b +md5=cfdd915a5b7a6c09917a64a573140538 +cksum=3139292895 diff --git a/build/pkgs/configparser/dependencies b/build/pkgs/configparser/dependencies new file mode 100644 index 00000000000..d5dab729e18 --- /dev/null +++ b/build/pkgs/configparser/dependencies @@ -0,0 +1,5 @@ +$(PYTHON) | pip + +---------- +All lines of this file are ignored except the first. +It is copied by SAGE_ROOT/build/make/install into SAGE_ROOT/build/make/Makefile. diff --git a/build/pkgs/configparser/package-version.txt b/build/pkgs/configparser/package-version.txt new file mode 100644 index 00000000000..1545d966571 --- /dev/null +++ b/build/pkgs/configparser/package-version.txt @@ -0,0 +1 @@ +3.5.0 diff --git a/build/pkgs/configparser/spkg-install b/build/pkgs/configparser/spkg-install new file mode 100755 index 00000000000..f3dc65c1dd4 --- /dev/null +++ b/build/pkgs/configparser/spkg-install @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cd src && pip install --verbose --no-index . diff --git a/build/pkgs/configparser/type b/build/pkgs/configparser/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/configparser/type @@ -0,0 +1 @@ +standard diff --git a/build/pkgs/entrypoints/SPKG.txt b/build/pkgs/entrypoints/SPKG.txt new file mode 100644 index 00000000000..89b2078a05a --- /dev/null +++ b/build/pkgs/entrypoints/SPKG.txt @@ -0,0 +1,17 @@ += entrypoints = + +== Description == + +Discover and load entry points from installed packages. + +== Upstream Contact == + +https://github.com/takluyver/entrypoints + +== Special Update/Build Instructions == + +Upstream does not provide a source tarball, so the tarball was taken +from github and renamed. + +The source tarball does not contain setup.py, so we put the setup +commands in spkg-install. diff --git a/build/pkgs/entrypoints/checksums.ini b/build/pkgs/entrypoints/checksums.ini new file mode 100644 index 00000000000..d9690c66b6b --- /dev/null +++ b/build/pkgs/entrypoints/checksums.ini @@ -0,0 +1,4 @@ +tarball=entrypoints-VERSION.tar.gz +sha1=75f43c6051e5d7b3bec7cf11fb7228d447efb06b +md5=7dae980f7c6affd777dc60a51c8d0b0b +cksum=2039305359 diff --git a/build/pkgs/entrypoints/dependencies b/build/pkgs/entrypoints/dependencies new file mode 100644 index 00000000000..70d522ac04d --- /dev/null +++ b/build/pkgs/entrypoints/dependencies @@ -0,0 +1,5 @@ +$(PYTHON) | pip configparser + +---------- +All lines of this file are ignored except the first. +It is copied by SAGE_ROOT/build/make/install into SAGE_ROOT/build/make/Makefile. diff --git a/build/pkgs/entrypoints/package-version.txt b/build/pkgs/entrypoints/package-version.txt new file mode 100644 index 00000000000..ee1372d33a2 --- /dev/null +++ b/build/pkgs/entrypoints/package-version.txt @@ -0,0 +1 @@ +0.2.2 diff --git a/build/pkgs/entrypoints/setup.py b/build/pkgs/entrypoints/setup.py new file mode 100755 index 00000000000..75efa80db5b --- /dev/null +++ b/build/pkgs/entrypoints/setup.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +# +# Upstream does not have a setup.py file, so we use this instead +# + +from entrypoints import __version__ as v + +from setuptools import setup +setup(name="entrypoints", version=v, py_modules=["entrypoints"]) diff --git a/build/pkgs/entrypoints/spkg-install b/build/pkgs/entrypoints/spkg-install new file mode 100755 index 00000000000..1d8f52b775a --- /dev/null +++ b/build/pkgs/entrypoints/spkg-install @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# +# Upstream does not have a setup.py file, so we supply one with Sage +# + +mv setup.py src +cd src && pip install --verbose --no-index . diff --git a/build/pkgs/entrypoints/type b/build/pkgs/entrypoints/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/entrypoints/type @@ -0,0 +1 @@ +standard From 0e12eb077db56d239a1ab21d91a32b76c06d89ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 17 Aug 2016 12:11:35 +0200 Subject: [PATCH 087/135] trac 21257 another reviewer suggestion --- .../thematic_tutorials/tutorial-comprehensions.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst b/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst index d6740a180e0..f4b6bdadba0 100644 --- a/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst +++ b/src/doc/en/thematic_tutorials/tutorial-comprehensions.rst @@ -227,16 +227,20 @@ Here is the analogue of list slicing:: sage: list(itertools.islice(Permutations(3), 1, 4)) [[1, 3, 2], [2, 1, 3], [2, 3, 1]] -The functions :func:`map` and :func:`filter` also have an analogue:: - - sage: list(itertools.imap(lambda z: z.cycle_type(), Permutations(3))) +The behaviour of the functions :func:`map` and :func:`filter` has +changed between Python 2 and Python 3. In Python 3, they return an +iterator. If you want to use this new behaviour in Python 2, and keep +your code compatible with Python3, you can use the compatibility +library ``six`` as follows:: + + sage: from six.moves import map + sage: list(map(lambda z: z.cycle_type(), Permutations(3))) [[1, 1, 1], [2, 1], [2, 1], [3], [3], [2, 1]] sage: from six.moves import filter sage: list(filter(lambda z: z.has_pattern([1,2]), Permutations(3))) [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2]] - .. TOPIC:: Exercises #. Define an iterator for the `i`-th prime for `5 Date: Wed, 17 Aug 2016 16:14:56 +0200 Subject: [PATCH 088/135] py3: getting rid of iterkeys() --- .../letterplace/free_algebra_letterplace.pyx | 2 +- src/sage/categories/category_cy_helper.pyx | 8 +- src/sage/coding/codecan/codecan.pyx | 2 +- src/sage/combinat/finite_state_machine.py | 141 +----------------- .../finite_state_machine_generators.py | 2 +- src/sage/combinat/integer_lists/invlex.pyx | 4 +- .../dynamics/interval_exchanges/template.py | 4 +- src/sage/graphs/base/c_graph.pyx | 2 +- src/sage/graphs/generic_graph.py | 6 +- src/sage/graphs/graph.py | 6 +- .../perm_gps/partn_ref/refinement_graphs.pyx | 6 +- src/sage/libs/gap/util.pyx | 2 +- .../matroids/circuit_closures_matroid.pyx | 2 +- src/sage/misc/mrange.py | 2 +- src/sage/modular/pollack_stevens/manin_map.py | 4 +- src/sage/plot/line.py | 6 +- .../elliptic_curves/gal_reps_number_field.py | 4 +- src/sage/structure/parent.pyx | 2 +- src/sage/structure/unique_representation.py | 2 +- src/sage/symbolic/units.py | 4 +- 20 files changed, 38 insertions(+), 173 deletions(-) diff --git a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx index e78f85ce779..d0f74bd8125 100644 --- a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx +++ b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx @@ -833,7 +833,7 @@ cdef class FreeAlgebra_letterplace(Algebra): if not D: return self.zero() cdef int l - for e in D.iterkeys(): + for e in D: l = len(e) break cdef dict out = {} diff --git a/src/sage/categories/category_cy_helper.pyx b/src/sage/categories/category_cy_helper.pyx index ffc22dd9edc..30b3b903376 100644 --- a/src/sage/categories/category_cy_helper.pyx +++ b/src/sage/categories/category_cy_helper.pyx @@ -110,8 +110,8 @@ cpdef tuple _flatten_categories(categories, ClasscallMetaclass JoinCategory): cdef bint is_supercategory_of_done(new_cat, dict done): # This is a helper function. It replaces the closure - # any(cat.is_subcategory(new_cat) for cat in done.iterkeys()) - for cat in done.iterkeys(): + # any(cat.is_subcategory(new_cat) for cat in done) + for cat in done: if cat.is_subcategory(new_cat): return True return False @@ -193,7 +193,7 @@ cpdef tuple join_as_tuple(tuple categories, tuple axioms, tuple ignore_axioms): new_axioms.add(axiom) # Mark old categories with new axioms as todo - for category in done.iterkeys(): + for category in done: for axiom in new_axioms: todo.add( (category, axiom) ) for new_cat in new_cats: @@ -205,7 +205,7 @@ cpdef tuple join_as_tuple(tuple categories, tuple axioms, tuple ignore_axioms): for axiom in axiomsS.difference(axs): todo.add( (new_cat, axiom) ) - return _sort_uniq(done.iterkeys()) + return _sort_uniq(done) ############################################# diff --git a/src/sage/coding/codecan/codecan.pyx b/src/sage/coding/codecan/codecan.pyx index 977ce77b947..06ea08c5663 100644 --- a/src/sage/coding/codecan/codecan.pyx +++ b/src/sage/coding/codecan/codecan.pyx @@ -297,7 +297,7 @@ cdef class InnerGroup: factor = d.get(self.get_rep(i)) if factor and not factor.is_zero(): m.rescale_row(i, factor) - for i in d.iterkeys(): + for i in d: first_nz_rep = self.join_rows(first_nz_rep, i) # rescale the already fixed part by column multiplications for col in fixed_minimized_cols: diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index dd229935e44..dbbec5ce6ac 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -4695,7 +4695,7 @@ def latex_options(self, self.format_transition_label = format_transition_label if loop_where is not None: - permissible = list(tikz_automata_where.iterkeys()) + permissible = list(tikz_automata_where) for state in self.states(): if hasattr(loop_where, '__call__'): where = loop_where(state.label()) @@ -4714,7 +4714,7 @@ def latex_options(self, (state.label(), permissible)) if initial_where is not None: - permissible = list(tikz_automata_where.iterkeys()) + permissible = list(tikz_automata_where) for state in self.iter_initial_states(): if hasattr(initial_where, '__call__'): where = initial_where(state.label()) @@ -4745,7 +4745,7 @@ def latex_options(self, self.accepting_distance = accepting_distance if accepting_where is not None: - permissible = list(tikz_automata_where.iterkeys()) + permissible = list(tikz_automata_where) for state in self.iter_final_states(): if hasattr(accepting_where, '__call__'): where = accepting_where(state.label()) @@ -14941,7 +14941,6 @@ def result(self, format_output=None): return self._finished_ return [r[:2] + (format_output(r[2]),) for r in self._finished_] - def preview_word(self, track_number=None, length=1, return_word=False): """ Reads a word from the input tape. @@ -14996,140 +14995,6 @@ def preview_word(self, track_number=None, length=1, return_word=False): track_number, length, return_word) - @property - def current_state(self): - """ - The current/reached state in the process. - - .. WARNING:: - - This attribute is deprecated and should not be used any - longer (it may return a wrong result for non-deterministic - finite state machines). - - TESTS:: - - sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]}, - ....: initial_states=['A'], final_states=['A']) - sage: it = inverter.iter_process(input_tape=[0, 1, 1]) - sage: for current in it: - ....: s = it.current_state - ....: print(current) - ....: print('current state: {}'.format(s)) - doctest:...: DeprecationWarning: This attribute will be - removed in future releases. Use result() at the end of our - iteration or the output of next(). - See http://trac.sagemath.org/16538 for details. - process (1 branch) - + at state 'A' - +-- tape at 1, [[1]] - current state: 'A' - process (1 branch) - + at state 'A' - +-- tape at 2, [[1, 0]] - current state: 'A' - process (1 branch) - + at state 'A' - +-- tape at 3, [[1, 0, 0]] - current state: 'A' - process (0 branches) - current state: None - """ - from sage.misc.superseded import deprecation - deprecation(16538, 'This attribute will be removed in future ' - 'releases. Use result() at the end of our ' - 'iteration or the output of next().') - if not self._current_: - return None - return next(next(self._current_.itervalues()).iterkeys()) - - - @property - def output_tape(self): - """ - The written output. - - .. WARNING:: - - This attribute is deprecated and should not be used any - longer (it may return a wrong result for non-deterministic - finite state machines). - - TESTS:: - - sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]}, - ....: initial_states=['A'], final_states=['A']) - sage: it = inverter.iter_process(input_tape=[0, 1, 1]) - sage: for current in it: - ....: t = it.output_tape - ....: print(current) - ....: print('output: {}'.format(t)) - doctest:...: DeprecationWarning: This attribute will be removed - in future releases. Use result() at the end of our iteration - or the output of next(). - See http://trac.sagemath.org/16538 for details. - process (1 branch) - + at state 'A' - +-- tape at 1, [[1]] - output: [1] - process (1 branch) - + at state 'A' - +-- tape at 2, [[1, 0]] - output: [1, 0] - process (1 branch) - + at state 'A' - +-- tape at 3, [[1, 0, 0]] - output: [1, 0, 0] - process (0 branches) - output: None - """ - from sage.misc.superseded import deprecation - deprecation(16538, 'This attribute will be removed in future ' - 'releases. Use result() at the end of our iteration ' - 'or the output of next().') - if not self._current_: - return None - return next(next(self._current_.itervalues()).itervalues()).outputs[0] - - - @property - def accept_input(self): - """ - Is ``True`` if the reached state is accepted. This is only available - at the end of the iteration process. - - .. WARNING:: - - This attribute is deprecated and should not be used any - longer (it may return a wrong result for non-deterministic - finite state machines). - - TESTS:: - - sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]}, - ....: initial_states=['A'], final_states=['A']) - sage: it = inverter.iter_process(input_tape=[0, 1, 1]) - sage: for _ in it: - ....: pass - sage: it.result() - [Branch(accept=True, state='A', output=[1, 0, 0])] - sage: it.accept_input - doctest:...: DeprecationWarning: This attribute will be removed - in future releases. Use result() at the end of our iteration - or the output of next(). - See http://trac.sagemath.org/16538 for details. - True - """ - from sage.misc.superseded import deprecation - deprecation(16538, 'This attribute will be removed in future ' - 'releases. Use result() at the end of our iteration ' - 'or the output of next().') - try: - return self._finished_[0].accept - except KeyError: - raise AttributeError - - #***************************************************************************** diff --git a/src/sage/combinat/finite_state_machine_generators.py b/src/sage/combinat/finite_state_machine_generators.py index 1398a3ae207..4ff2615e59e 100644 --- a/src/sage/combinat/finite_state_machine_generators.py +++ b/src/sage/combinat/finite_state_machine_generators.py @@ -1977,7 +1977,7 @@ def f(n): if carry >= 0}, multiedges=False) - initial_values_set = set(initial_values.iterkeys()) + initial_values_set = set(initial_values) missing_initial_values = required_initial_values.difference( initial_values_set) diff --git a/src/sage/combinat/integer_lists/invlex.pyx b/src/sage/combinat/integer_lists/invlex.pyx index 28b68771a0d..2dee7535d6b 100644 --- a/src/sage/combinat/integer_lists/invlex.pyx +++ b/src/sage/combinat/integer_lists/invlex.pyx @@ -29,6 +29,8 @@ limitations and lack of robustness w.r.t. input. #***************************************************************************** from __future__ import print_function +from builtins import object + from sage.misc.classcall_metaclass import ClasscallMetaclass, typecall from sage.misc.cachefunc import cached_method from sage.combinat.integer_lists.base cimport IntegerListsBackend @@ -1285,7 +1287,7 @@ class IntegerListsLexIter(object): self._current_sum -= self._current_list[-1] self._current_list.pop() - def next(self): + def __next__(self): r""" Return the next element in the iteration. diff --git a/src/sage/dynamics/interval_exchanges/template.py b/src/sage/dynamics/interval_exchanges/template.py index efdc0f64211..97894ca547a 100644 --- a/src/sage/dynamics/interval_exchanges/template.py +++ b/src/sage/dynamics/interval_exchanges/template.py @@ -3313,7 +3313,7 @@ def __iter__(self): H(0, 0) H(0, 0) """ - for data in self._succ.iterkeys(): + for data in self._succ: yield self._vertex_to_permutation(data) def __contains__(self, element): @@ -3335,7 +3335,7 @@ def __contains__(self, element): sage: q in s True """ - for p in self._succ.iterkeys(): + for p in self._succ: if self._vertex_to_permutation(p) == element: return True diff --git a/src/sage/graphs/base/c_graph.pyx b/src/sage/graphs/base/c_graph.pyx index 3d11c4ea00f..e0277fb1e82 100644 --- a/src/sage/graphs/base/c_graph.pyx +++ b/src/sage/graphs/base/c_graph.pyx @@ -1846,7 +1846,7 @@ cdef class CGraphBackend(GenericGraphBackend): """ cdef int i if verts is None: - S = set(self.vertex_ints.iterkeys()) + S = set(self.vertex_ints) for i in range((self._cg).active_vertices.size): if (i not in self.vertex_labels and bitset_in((self._cg).active_vertices, i)): diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 38a860b2fc0..560f3d002cd 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -9777,7 +9777,7 @@ def vertex_iterator(self, vertices=None): 100000 loops, best of 3: 8.85 [micro]s per loop sage: timeit V = list(P.vertex_iterator()) # not tested 100000 loops, best of 3: 5.74 [micro]s per loop - sage: timeit V = list(P._nxg.adj.iterkeys()) # not tested + sage: timeit V = list(P._nxg.adj) # not tested 100000 loops, best of 3: 3.45 [micro]s per loop In other words, if you want a fast vertex iterator, call the @@ -9856,7 +9856,7 @@ def vertices(self, key=None): 100000 loops, best of 3: 8.85 [micro]s per loop sage: timeit V = list(P.vertex_iterator()) # not tested 100000 loops, best of 3: 5.74 [micro]s per loop - sage: timeit V = list(P._nxg.adj.iterkeys()) # not tested + sage: timeit V = list(P._nxg.adj) # not tested 100000 loops, best of 3: 3.45 [micro]s per loop We illustrate various ways to use a ``key`` to sort the list:: @@ -19832,7 +19832,7 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input = True, if len(set(perm.values())) < len(perm): raise NotImplementedError("Non injective relabeling") - for v in perm.iterkeys(): + for v in perm: if v in self: try: hash(perm[v]) diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 899d1b7ca1c..1997259c832 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -5499,7 +5499,7 @@ def cliques_number_of(self, vertices=None, cliques=None): {0: 1, 1: 1, 2: 1, 3: 1, 4: 2} sage: F = graphs.Grid2dGraph(2,3) sage: X = F.cliques_number_of() - sage: for v in sorted(X.iterkeys()): + sage: for v in sorted(X): ....: print("{} {}".format(v, X[v])) (0, 0) 2 (0, 1) 3 @@ -5992,7 +5992,7 @@ def cliques_vertex_clique_number(self, algorithm="cliquer", vertices=None, {0: 2, 1: 4, 2: 4, 3: 4, 4: 4} sage: F = graphs.Grid2dGraph(2,3) sage: X = F.cliques_vertex_clique_number(algorithm="networkx") - sage: for v in sorted(X.iterkeys()): + sage: for v in sorted(X): ....: print("{} {}".format(v, X[v])) (0, 0) 2 (0, 1) 2 @@ -6056,7 +6056,7 @@ def cliques_containing_vertex(self, vertices=None, cliques=None): {0: [[0, 4]], 1: [[1, 2, 3, 4]], 2: [[1, 2, 3, 4]], 3: [[1, 2, 3, 4]], 4: [[0, 4], [1, 2, 3, 4]]} sage: F = graphs.Grid2dGraph(2,3) sage: X = F.cliques_containing_vertex() - sage: for v in sorted(X.iterkeys()): + sage: for v in sorted(X): ....: print("{} {}".format(v, X[v])) (0, 0) [[(0, 1), (0, 0)], [(1, 0), (0, 0)]] (0, 1) [[(0, 1), (0, 0)], [(0, 1), (0, 2)], [(0, 1), (1, 1)]] diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx index adc8f900343..c5a29def5ae 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx @@ -91,7 +91,7 @@ def isomorphic(G1, G2, partn, ordering2, dig, use_indicator_function, sparse=Fal G_in = copy(G_in) to = G_in.relabel(return_map=True) frm = {} - for v in to.iterkeys(): + for v in to: frm[to[v]] = v if first: partition = [[to[v] for v in cell] for cell in partn] @@ -382,7 +382,7 @@ def search_tree(G_in, partition, lab=True, dig=False, dict_rep=False, certificat G_in = copy(G_in) to = G_in.relabel(return_map=True) frm = {} - for v in to.iterkeys(): + for v in to: frm[to[v]] = v partition = [[to[v] for v in cell] for cell in partition] else: @@ -459,7 +459,7 @@ def search_tree(G_in, partition, lab=True, dig=False, dict_rep=False, certificat return_tuple = [list_of_gens] if dict_rep: ddd = {} - for v in frm.iterkeys(): + for v in frm: ddd[frm[v]] = v if v != 0 else n return_tuple.append(ddd) if lab: diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx index d0df7441e45..25eed9afb8e 100644 --- a/src/sage/libs/gap/util.pyx +++ b/src/sage/libs/gap/util.pyx @@ -134,7 +134,7 @@ cdef void gasman_callback(): Callback before each GAP garbage collection """ global owned_objects_refcount - for obj in owned_objects_refcount.iterkeys(): + for obj in owned_objects_refcount: libGAP_MARK_BAG((obj).value) diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 20ece775885..3ff711e3a5e 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -156,7 +156,7 @@ cdef class CircuitClosuresMatroid(Matroid): else: self._groundset = frozenset(groundset) self._circuit_closures = {} - for k in circuit_closures.iterkeys(): + for k in circuit_closures: self._circuit_closures[k] = frozenset([frozenset(X) for X in circuit_closures[k]]) self._matroid_rank = self.rank(self._groundset) diff --git a/src/sage/misc/mrange.py b/src/sage/misc/mrange.py index c073a27c372..c6b92018096 100644 --- a/src/sage/misc/mrange.py +++ b/src/sage/misc/mrange.py @@ -694,7 +694,7 @@ def cantor_product(*args, **kwds): elif repeat < 0: raise ValueError("repeat argument cannot be negative") if kwds: - raise TypeError("'{}' is an invalid keyword argument for this function".format(next(kwds.iterkeys()))) + raise TypeError("'{}' is an invalid keyword argument for this function".format(list(kwds)[0])) mm = m * repeat for n in count(0): diff --git a/src/sage/modular/pollack_stevens/manin_map.py b/src/sage/modular/pollack_stevens/manin_map.py index 136dcb77eb7..34f75bdf787 100644 --- a/src/sage/modular/pollack_stevens/manin_map.py +++ b/src/sage/modular/pollack_stevens/manin_map.py @@ -688,10 +688,8 @@ def _right_action(self, gamma): (17, -34, 69) """ D = {} - sd = self._dict # we should eventually replace the for loop with a call to apply_many - keys = [ky for ky in sd.iterkeys()] - for ky in keys: + for ky in self._dict: D[ky] = self(gamma * ky) * gamma return self.__class__(self._codomain, self._manin, D, check=False) diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py index e164e0cd869..66beb52e588 100644 --- a/src/sage/plot/line.py +++ b/src/sage/plot/line.py @@ -42,10 +42,10 @@ def __init__(self, xdata, ydata, options): sage: Line([-1,2], [17,4], {'thickness':2}) Line defined by 2 points """ - valid_options = self._allowed_options().keys() - for opt in options.iterkeys(): + valid_options = self._allowed_options() + for opt in options: if opt not in valid_options: - raise RuntimeError("Error in line(): option '%s' not valid."%opt) + raise RuntimeError("Error in line(): option '%s' not valid." % opt) self.xdata = xdata self.ydata = ydata GraphicPrimitive_xydata.__init__(self, options) diff --git a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py index 6ec92e8e661..c50b575ab3c 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py +++ b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py @@ -658,7 +658,7 @@ def _exceptionals(E, L, patience=1000): unexc = [] # Primes we discover are unexceptional go here. - for l in D.iterkeys(): + for l in D: tr = GF(l)(trace) det = GF(l)(determinant) disc = GF(l)(discriminant) @@ -699,7 +699,7 @@ def _exceptionals(E, L, patience=1000): if (D == {}) or (patience == 0): break - for l in D.iterkeys(): + for l in D: output.append(l) output.sort() diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 33b552cfb80..ea7c6389b15 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -3295,7 +3295,7 @@ cdef bint _may_cache_none(x, y, tag) except -1: # with the only exception of the path from y to x. # See #12969. cdef EltPair P - for P in _coerce_test_dict.iterkeys(): + for P in _coerce_test_dict: if (P.y is y) and (P.x is not x) and (P.tag is tag): return 0 return 1 diff --git a/src/sage/structure/unique_representation.py b/src/sage/structure/unique_representation.py index 73d8908c257..a60ee9f5662 100644 --- a/src/sage/structure/unique_representation.py +++ b/src/sage/structure/unique_representation.py @@ -1109,7 +1109,7 @@ def _clear_cache_(cls): cache = C.__classcall__.cache except AttributeError: pass - for k in cache.iterkeys(): + for k in cache: if issubclass(k[0][0],cls): del_list.append(k) for k in del_list: diff --git a/src/sage/symbolic/units.py b/src/sage/symbolic/units.py index c3c4dfef2d2..5b7f62fd6d3 100644 --- a/src/sage/symbolic/units.py +++ b/src/sage/symbolic/units.py @@ -512,8 +512,8 @@ def evalunitdict(): for k, v in unitdict.iteritems(): for a in v: unit_to_type[a] = k - for w in unitdict.iterkeys(): - for j in unitdict[w].iterkeys(): + for w in unitdict: + for j in unitdict[w]: if isinstance(unitdict[w][j], tuple): unitdict[w][j] = unitdict[w][j][0] value_to_unit[w] = dict(zip(unitdict[w].itervalues(), unitdict[w].iterkeys())) From c519fe613d583630a2c7957335c05170a76c531b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 17 Aug 2016 18:38:28 +0200 Subject: [PATCH 089/135] trac 21193 more work on doc of delsarte bounds --- src/sage/coding/delsarte_bounds.py | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/sage/coding/delsarte_bounds.py b/src/sage/coding/delsarte_bounds.py index b238a9919e0..e18587ad857 100644 --- a/src/sage/coding/delsarte_bounds.py +++ b/src/sage/coding/delsarte_bounds.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- r""" Delsarte, a.k.a. Linear Programming (LP), upper bounds @@ -25,12 +26,19 @@ def Krawtchouk(n, q, l, x, check=True): r""" Compute ``K^{n,q}_l(x)``, the Krawtchouk (a.k.a. Kravchuk) polynomial. - See :wikipedia:`Kravchuk_polynomials`; It is defined by the generating function - `(1+(q-1)z)^{n-x}(1-z)^x=\sum_{l} K^{n,q}_l(x)z^l` and is equal to + See :wikipedia:`Kravchuk_polynomials`. + + It is defined by the generating function .. math:: - K^{n,q}_l(x)=\sum_{j=0}^l (-1)^j(q-1)^{(l-j)}\binom{x}{j}\binom{n-x}{l-j}, + (1+(q-1)z)^{n-x}(1-z)^x=\sum_{l} K^{n,q}_l(x)z^l + + and is equal to + + .. math:: + + K^{n,q}_l(x)=\sum_{j=0}^l (-1)^j (q-1)^{(l-j)} \binom{x}{j} \binom{n-x}{l-j}, INPUT: @@ -38,8 +46,9 @@ def Krawtchouk(n, q, l, x, check=True): - ``l`` -- a nonnegative integer - - ``check`` -- check the input for correctness. ``True`` by default. Otherwise, pass it - as it is. Use ``check=False`` at your own risk. + - ``check`` -- check the input for correctness. ``True`` by + default. Otherwise, pass it as it is. Use ``check=False`` at + your own risk. EXAMPLES:: @@ -141,7 +150,8 @@ def _delsarte_LP_building(n, d, d_star, q, isinteger, solver, maxc = 0): def delsarte_bound_hamming_space(n, d, q, return_data=False, solver="PPL", isinteger=False): """ - Find the Delsarte bound [1]_ on codes in Hamming space ``H_q^n`` of minimal distance ``d`` + Find the Delsarte bound [1]_ on codes in Hamming space ``H_q^n`` + of minimal distance ``d`` INPUT: @@ -152,16 +162,20 @@ def delsarte_bound_hamming_space(n, d, q, return_data=False, solver="PPL", isint - ``q`` -- the size of the alphabet - - ``return_data`` -- if ``True``, return a triple ``(W,LP,bound)``, where ``W`` is - a weights vector, and ``LP`` the Delsarte upper bound LP; both of them are Sage LP - data. ``W`` need not be a weight distribution of a code. + - ``return_data`` -- if ``True``, return a triple + ``(W,LP,bound)``, where ``W`` is a weights vector, and ``LP`` + the Delsarte upper bound LP; both of them are Sage LP data. + ``W`` need not be a weight distribution of a code. - - ``solver`` -- the LP/ILP solver to be used. Defaults to ``PPL``. It is arbitrary - precision, thus there will be no rounding errors. With other solvers - (see :class:`MixedIntegerLinearProgram` for the list), you are on your own! + - ``solver`` -- the LP/ILP solver to be used. Defaults to + ``PPL``. It is arbitrary precision, thus there will be no + rounding errors. With other solvers (see + :class:`MixedIntegerLinearProgram` for the list), you are on + your own! - - ``isinteger`` -- if ``True``, uses an integer programming solver (ILP), rather - that an LP solver. Can be very slow if set to ``True``. + - ``isinteger`` -- if ``True``, uses an integer programming solver + (ILP), rather that an LP solver. Can be very slow if set to + ``True``. EXAMPLES: @@ -210,8 +224,6 @@ def delsarte_bound_hamming_space(n, d, q, return_data=False, solver="PPL", isint .. [1] \P. Delsarte, An algebraic approach to the association schemes of coding theory, Philips Res. Rep., Suppl., vol. 10, 1973. - - """ from sage.numerical.mip import MIPSolverException A, p = _delsarte_LP_building(n, d, 0, q, isinteger, solver) @@ -288,7 +300,7 @@ def delsarte_bound_additive_hamming_space(n, d, q, d_star=1, q_base=0, sage: delsarte_bound_additive_hamming_space(11,3,4,q_base=2) 16 - Such a d_star is not possible:: + Such a ``d_star`` is not possible:: sage: delsarte_bound_additive_hamming_space(11,3,4,d_star=9) Solver exception: PPL : There is no feasible solution From 43c1136d2deea867dc67e9100dbe778ca8527903 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Wed, 17 Aug 2016 20:35:10 +0200 Subject: [PATCH 090/135] Exclude plain text from IPython super call --- src/sage/repl/display/formatter.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sage/repl/display/formatter.py b/src/sage/repl/display/formatter.py index b65f045b70c..d8baa94cd81 100644 --- a/src/sage/repl/display/formatter.py +++ b/src/sage/repl/display/formatter.py @@ -144,6 +144,16 @@ def format(self, obj, include=None, exclude=None): ({u'image/png': '\x89PNG...', u'text/plain': u''}, {}) + + Test that ``__repr__`` is only called once when generating text output:: + + sage: class Repper(object): + ....: def __repr__(self): + ....: print('__repr__ called') + ....: return 'I am repper' + sage: Repper() + __repr__ called + I am repper """ # First, use Sage rich output if there is any PLAIN_TEXT = u'text/plain' @@ -157,6 +167,8 @@ def format(self, obj, include=None, exclude=None): # Finally, try IPython rich representation (obj._repr_foo_ methods) if exclude is not None: exclude = list(exclude) + [PLAIN_TEXT] + else: + exclude = [PLAIN_TEXT] ipy_format, ipy_metadata = super(SageDisplayFormatter, self).format( obj, include=include, exclude=exclude) ipy_format.update(sage_format) From 8169d5b21177bd57046f3758b016d9a1285d19ee Mon Sep 17 00:00:00 2001 From: Stefan van Zwam Date: Wed, 17 Aug 2016 13:41:49 -0500 Subject: [PATCH 091/135] Deleted some periods --- src/sage/matroids/matroid.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 0c63a738189..970f01d24aa 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -6132,7 +6132,7 @@ cdef class Matroid(SageObject): - ``certificate`` -- (default: ``False``) a boolean, if ``True`` return ``True, (x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and ``Bx`` are circuits whose union is the elements of ``C`` - together with ``x``, if ``False`` return ``False, None``. + together with ``x``, if ``False`` return ``False, None`` OUTPUT: @@ -6186,7 +6186,7 @@ cdef class Matroid(SageObject): - ``certificate`` -- (default: ``False``) a boolean, if ``True`` return ``True, (x, Ax, Bx)``, where ``x`` is a chord and ``Ax`` and ``Bx`` are circuits whose union is the elements of ``C`` - together with ``x``, if ``False`` return ``False, None``. + together with ``x``, if ``False`` return ``False, None`` OUTPUT: From 9042104196f2d3b9822b3827aa2bbd70097f7b95 Mon Sep 17 00:00:00 2001 From: Armin Straub Date: Wed, 17 Aug 2016 17:16:51 -0500 Subject: [PATCH 092/135] 16671: simplify evaluation of harmonic numbers --- src/sage/functions/log.py | 45 +++++++++++---------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 8a0139eb3a3..7828e13e1cc 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -1042,20 +1042,9 @@ def _eval_(self, z, m): return z elif m == 1: return harmonic_m1._eval_(z) - from sage.symbolic.ring import SR - P = s_parent(z) - if not hasattr(z, 'operator') and not self._is_numerical(z): - try: - z = ZZ(z) - except TypeError: - pass - else: - if (isinstance(m, (Integer, int))): - if P in (ZZ, int): - P = QQ - return SR(P(sum(1/(k**m) for k in range(1,z+1)))) - elif isinstance(m, Rational): - return sum(1/(k**m) for k in range(1,z+1)) + + if z in ZZ and z >= 0: + return sum(1/(k**m) for k in xrange(1,z+1)) def _evalf_(self, z, m, parent=None, algorithm=None): """ @@ -1071,9 +1060,12 @@ def _evalf_(self, z, m, parent=None, algorithm=None): 2.36889632899995 - 3.51181956521611*I """ if m == 0: + if parent is None: + return z return parent(z) elif m == 1: - return harmonic_m1._evalf_(z, parent) + return harmonic_m1._evalf_(z, parent, algorithm) + from sage.functions.transcendental import zeta, hurwitz_zeta return zeta(m) - hurwitz_zeta(m,z+1) @@ -1206,28 +1198,17 @@ def _eval_(self, z, **kwds): sage: harmonic_number(2*x) harmonic_number(2*x) """ - from sage.symbolic.ring import SR - P = s_parent(z) - if P in (ZZ, int): - P = QQ - if not hasattr(z, 'operator') and not self._is_numerical(z): - try: - z = ZZ(QQ(z)) - except TypeError: - pass - if isinstance(z, Integer): + if z in ZZ: if z == 0: return Integer(0) elif z == 1: return Integer(1) - else: + elif z > 1: import sage.libs.flint.arith as flint_arith - return SR(P(flint_arith.harmonic_number(z))) - elif isinstance(z, Rational): - from sage.calculus.calculus import symbolic_sum - from sage.rings.infinity import infinity - x = SR.var('x') - return z*symbolic_sum(1/x/(z+x),x,1,infinity) + return flint_arith.harmonic_number(z) + elif z in QQ: + from sage.functions.other import psi1 + return psi1(z+1) - psi1(1) def _evalf_(self, z, parent=None, algorithm='mpmath'): """ From 1cbb355d5f51adf31d06de992798825cead6566b Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Wed, 17 Aug 2016 20:34:45 -0400 Subject: [PATCH 093/135] 21085: generalized blowup() to work for any point on a given curve --- src/sage/schemes/curves/affine_curve.py | 341 +++++++++++++++--------- 1 file changed, 208 insertions(+), 133 deletions(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index 74f2c0d1420..54fb4d05cbe 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -153,12 +153,15 @@ def projective_closure(self, i=0, PP=None): from .constructor import Curve return Curve(AlgebraicScheme_subscheme_affine.projective_closure(self, i, PP)) - def blowup(self): + def blowup(self, P): r""" - Return the blow up of this affine curve at the origin. + Return the blow up of this affine curve at the point ``P``. - An error is returned if the origin is not a point on this curve. The blow up is described - by affine charts. + The blow up is described by affine charts. This curve must be irreducible. + + INPUT: + + - ``P`` -- a point on this curve at which to blow up. OUTPUT: @@ -174,90 +177,154 @@ def blowup(self): sage: A. = AffineSpace(QQ, 2) sage: C = Curve([y^2 - x^3], A) - sage: C.blowup() + sage: Q = A([0,0]) + sage: C.blowup(Q) ((Affine Plane Curve over Rational Field defined by s1^2 - x, - Affine Plane Curve over Rational Field defined by -y*s0^3 + 1), - ([Scheme endomorphism of Affine Plane Curve over Rational Field defined - by s1^2 - x - Defn: Defined on coordinates by sending (x, s1) to - (x, s1), Scheme morphism: - From: Affine Plane Curve over Rational Field defined by s1^2 - x - To: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 - Defn: Defined on coordinates by sending (x, s1) to - (x*s1, 1/s1)], [Scheme morphism: - From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 - To: Affine Plane Curve over Rational Field defined by s1^2 - x - Defn: Defined on coordinates by sending (y, s0) to - (y*s0, 1/s0), - Scheme endomorphism of Affine Plane Curve over Rational Field defined - by -y*s0^3 + 1 - Defn: Defined on coordinates by sending (y, s0) to - (y, s0)]), - (Scheme morphism: + Affine Plane Curve over Rational Field defined by y*s0^3 - 1), + ([Scheme endomorphism of Affine Plane Curve over Rational Field defined by s1^2 - x + Defn: Defined on coordinates by sending (x, s1) to + (x, s1), Scheme morphism: From: Affine Plane Curve over Rational Field defined by s1^2 - x - To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + To: Affine Plane Curve over Rational Field defined by y*s0^3 - 1 Defn: Defined on coordinates by sending (x, s1) to - (x, x*s1), Scheme morphism: - From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 - To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + (x*s1, 1/s1)], [Scheme morphism: + From: Affine Plane Curve over Rational Field defined by y*s0^3 - 1 + To: Affine Plane Curve over Rational Field defined by s1^2 - x Defn: Defined on coordinates by sending (y, s0) to - (y*s0, y))) + (y*s0, 1/s0), + Scheme endomorphism of Affine Plane Curve over Rational Field defined by y*s0^3 - 1 + Defn: Defined on coordinates by sending (y, s0) to + (y, s0)]), + (Scheme morphism: + From: Affine Plane Curve over Rational Field defined by s1^2 - x + To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + Defn: Defined on coordinates by sending (x, s1) to + (x, x*s1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by y*s0^3 - 1 + To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 + Defn: Defined on coordinates by sending (y, s0) to + (y*s0, y))) :: sage: K. = QuadraticField(2) sage: A. = AffineSpace(K, 3) sage: C = Curve([y^2 - a*x^5, x - z], A) - sage: B = C.blowup() + sage: Q = A([0,0,0]) + sage: B = C.blowup(Q) sage: B[0] - (Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by (-a)*x^3 + s1^2, -s2 + 1, - Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by (-a)*y^3*s0^5 + 1, s0 - s2, - Affine Curve over Number Field in a with defining polynomial x^2 - 2 - defined by (-a)*z^3*s0^5 + s1^2, s0 - 1) + (Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s2 - 1, + 2*x^3 + (-a)*s1^2, + Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s0 - s2, + 2*y^3*s2^5 + (-a), + Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s0 - 1, + 2*z^3 + (-a)*s1^2) sage: B[1][0][2] Scheme morphism: - From: Affine Curve over Number Field in a with defining polynomial x^2 - - 2 defined by (-a)*x^3 + s1^2, -s2 + 1 - To: Affine Curve over Number Field in a with defining polynomial x^2 - - 2 defined by (-a)*z^3*s0^5 + s1^2, s0 - 1 - Defn: Defined on coordinates by sending (x, s1, s2) to - (x*s2, 1/s2, s1/s2) + From: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s2 - 1, + 2*x^3 + (-a)*s1^2 + To: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s0 - 1, + 2*z^3 + (-a)*s1^2 + Defn: Defined on coordinates by sending (x, s1, s2) to + (x*s2, 1/s2, s1/s2) sage: B[1][2][0] Scheme morphism: - From: Affine Curve over Number Field in a with defining polynomial x^2 - - 2 defined by (-a)*z^3*s0^5 + s1^2, s0 - 1 - To: Affine Curve over Number Field in a with defining polynomial x^2 - - 2 defined by (-a)*x^3 + s1^2, -s2 + 1 - Defn: Defined on coordinates by sending (z, s0, s1) to - (z*s0, s1/s0, 1/s0) + From: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s0 - 1, + 2*z^3 + (-a)*s1^2 + To: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s2 - 1, + 2*x^3 + (-a)*s1^2 + Defn: Defined on coordinates by sending (z, s0, s1) to + (z*s0, s1/s0, 1/s0) sage: B[2] (Scheme morphism: - From: Affine Curve over Number Field in a with defining polynomial - x^2 - 2 defined by (-a)*x^3 + s1^2, -s2 + 1 - To: Affine Curve over Number Field in a with defining polynomial - x^2 - 2 defined by (-a)*x^5 + y^2, x - z - Defn: Defined on coordinates by sending (x, s1, s2) to - (x, x*s1, x*s2), Scheme morphism: - From: Affine Curve over Number Field in a with defining polynomial - x^2 - 2 defined by (-a)*y^3*s0^5 + 1, s0 - s2 - To: Affine Curve over Number Field in a with defining polynomial - x^2 - 2 defined by (-a)*x^5 + y^2, x - z - Defn: Defined on coordinates by sending (y, s0, s2) to - (y*s0, y, y*s2), Scheme morphism: - From: Affine Curve over Number Field in a with defining polynomial - x^2 - 2 defined by (-a)*z^3*s0^5 + s1^2, s0 - 1 - To: Affine Curve over Number Field in a with defining polynomial - x^2 - 2 defined by (-a)*x^5 + y^2, x - z - Defn: Defined on coordinates by sending (z, s0, s1) to - (z*s0, z*s1, z)) + From: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by + s2 - 1, 2*x^3 + (-a)*s1^2 + To: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by + (-a)*x^5 + y^2, x - z + Defn: Defined on coordinates by sending (x, s1, s2) to + (x, x*s1, x*s2), Scheme morphism: + From: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by + s0 - s2, 2*y^3*s2^5 + (-a) + To: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by + (-a)*x^5 + y^2, x - z + Defn: Defined on coordinates by sending (y, s0, s2) to + (y*s0, y, y*s2), Scheme morphism: + From: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by + s0 - 1, 2*z^3 + (-a)*s1^2 + To: Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by + (-a)*x^5 + y^2, x - z + Defn: Defined on coordinates by sending (z, s0, s1) to + (z*s0, z*s1, z)) + + :: + + sage: A. = AffineSpace(QQ, 2) + sage: C = A.curve((y - 3/2)^3 - (x + 2)^5 - (x + 2)^6) + sage: Q = A([-2,3/2]) + sage: C.blowup(Q) + ((Affine Plane Curve over Rational Field defined by x^3 - s1^3 + 7*x^2 + 16*x + 12, + Affine Plane Curve over Rational Field defined by 8*y^3*s0^6 - 36*y^2*s0^6 + 8*y^2*s0^5 + + 54*y*s0^6 - 24*y*s0^5 - 27*s0^6 + 18*s0^5 - 8), + ([Scheme endomorphism of Affine Plane Curve over Rational Field defined by x^3 - s1^3 + 7*x^2 + + 16*x + 12 + Defn: Defined on coordinates by sending (x, s1) to + (x, s1), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by x^3 - s1^3 + 7*x^2 + 16*x + 12 + To: Affine Plane Curve over Rational Field defined by 8*y^3*s0^6 - 36*y^2*s0^6 + 8*y^2*s0^5 + + 54*y*s0^6 - 24*y*s0^5 - 27*s0^6 + 18*s0^5 - 8 + Defn: Defined on coordinates by sending (x, s1) to + (x*s1 + 2*s1 + 3/2, 1/s1)], [Scheme morphism: + From: Affine Plane Curve over Rational Field defined by 8*y^3*s0^6 - 36*y^2*s0^6 + 8*y^2*s0^5 + + 54*y*s0^6 - 24*y*s0^5 - 27*s0^6 + 18*s0^5 - 8 + To: Affine Plane Curve over Rational Field defined by x^3 - s1^3 + 7*x^2 + 16*x + 12 + Defn: Defined on coordinates by sending (y, s0) to + (y*s0 - 3/2*s0 - 2, 1/s0), + Scheme endomorphism of Affine Plane Curve over Rational Field defined by 8*y^3*s0^6 - 36*y^2*s0^6 + + 8*y^2*s0^5 + 54*y*s0^6 - 24*y*s0^5 - 27*s0^6 + 18*s0^5 - 8 + Defn: Defined on coordinates by sending (y, s0) to + (y, s0)]), + (Scheme morphism: + From: Affine Plane Curve over Rational Field defined by x^3 - s1^3 + 7*x^2 + 16*x + 12 + To: Affine Plane Curve over Rational Field defined by -x^6 - 13*x^5 - 70*x^4 - 200*x^3 + y^3 - + 320*x^2 - 9/2*y^2 - 272*x + 27/4*y - 795/8 + Defn: Defined on coordinates by sending (x, s1) to + (x, x*s1 + 2*s1 + 3/2), Scheme morphism: + From: Affine Plane Curve over Rational Field defined by 8*y^3*s0^6 - 36*y^2*s0^6 + 8*y^2*s0^5 + + 54*y*s0^6 - 24*y*s0^5 - 27*s0^6 + 18*s0^5 - 8 + To: Affine Plane Curve over Rational Field defined by -x^6 - 13*x^5 - 70*x^4 - 200*x^3 + y^3 - + 320*x^2 - 9/2*y^2 - 272*x + 27/4*y - 795/8 + Defn: Defined on coordinates by sending (y, s0) to + (y*s0 - 3/2*s0 - 2, y))) + + :: + + sage: A. = AffineSpace(QQ, 4) + sage: C = A.curve([((x + 1)^2 + y^2)^3 - 4*(x + 1)^2*y^2, y - z, w - 4]) + sage: Q = A([-1,0,0,4]) + sage: B = C.blowup(Q) + sage: B[0] + (Affine Curve over Rational Field defined by s3, s1 - s2, x^2*s2^6 + + 2*x*s2^6 + 3*x^2*s2^4 + s2^6 + 6*x*s2^4 + 3*x^2*s2^2 + 3*s2^4 + 6*x*s2^2 + + x^2 - s2^2 + 2*x + 1, + Affine Curve over Rational Field defined by s3, s2 - 1, y^2*s0^6 + + 3*y^2*s0^4 + 3*y^2*s0^2 + y^2 - 4*s0^2, + Affine Curve over Rational Field defined by s3, s1 - 1, z^2*s0^6 + + 3*z^2*s0^4 + 3*z^2*s0^2 + z^2 - 4*s0^2, + Closed subscheme of Affine Space of dimension 4 over Rational Field + defined by: + 1) + sage: Q = A([0,0,0,0]) + sage: B = C.blowup(Q) + Traceback (most recent call last): + ... + TypeError: (=(0, 0, 0, 0)) must be a point on this curve :: sage: A. = AffineSpace(QuadraticField(-1), 2) sage: C = A.curve([y^2 + x^2]) - sage: C.blowup() + sage: Q = A([0,0]) + sage: C.blowup(Q) Traceback (most recent call last): ... TypeError: this curve must be irreducible @@ -265,9 +332,9 @@ def blowup(self): A = self.ambient_space() n = A.dimension_relative() try: - self([0]*n) + self(P) except TypeError: - raise TypeError("the origin must be a point on this curve") + raise TypeError("(=%s) must be a point on this curve"%P) if not self.base_ring() in Fields(): raise TypeError("the base ring of this curve must be a field") if not self.is_irreducible(): @@ -286,19 +353,19 @@ def blowup(self): H = Hom(A.coordinate_ring(), R) psi = H([R.gens()[i] for i in range(n)]) n_polys = [psi(f) for f in self.defining_polynomials()] - # the blow up ideal of A at the origin is the ideal generated by - # z_i*s_j - z_j*s_i for i != j from 0,...,n-1 + # the blow up ideal of A at P is the ideal generated by + # (z_i - p_i)*s_j - (z_j - p_j)*s_i for i != j from 0,...,n-1 # in the mixed product space of A^n and P^{n-1} where the z_i are the gens - # of A^n, and the s_i are the gens for P^{n-1}. We describe the blow up of - # this curve at the origin in each affine chart + # of A^n, the s_i are the gens for P^{n-1}, and P = (p_1,...,p_n). We describe the + # blow up of this curve at P in each affine chart patches = [] for i in range(n): # in this chart, s_i is assumed to be 1 - # substitute in z_j = z_i*s_j for each j != i + # substitute in z_j = (z_i - p_i)*s_j + p_j for each j != i coords = list(R.gens()) for j in range(n): if j != i: - coords[j] = R.gens()[i]*R.gens()[j + n] + coords[j] = (R.gens()[i] - P[i])*R.gens()[j + n] + P[j] c_polys = [f(coords) for f in n_polys] var_names = list(R.gens())[n:2*n] var_names.pop(i) @@ -316,11 +383,21 @@ def blowup(self): coords[j + n] = 1 psi = H(coords) c_polys = [psi(f) for f in c_polys] - # remove the component corresponding to the exceptional divisor - for j in range(len(c_polys)): - while c_A.gens()[0].divides(c_polys[j]): - c_polys[j] = c_A.coordinate_ring()(c_polys[j]/c_A.gens()[0]) - patches.append(c_A.curve(c_polys)) + # choose the component of the subscheme defined by these polynomials + # that corresponds to the proper transform + irr_comps = c_A.subscheme(c_polys).irreducible_components() + for j in range(len(irr_comps)): + proper_transform = True + for f in irr_comps[j].defining_polynomials(): + if (c_A.gens()[0] - P[i]).divides(f): + proper_transform = False + break + if proper_transform: + patches.append(c_A.curve(irr_comps[j].defining_polynomials())) + break + elif j + 1 == len(irr_comps): + # patch of blowup in this chart is empty + patches.append(c_A.subscheme(1)) # create the transition maps between the charts t_maps = [] for i in range(n): @@ -332,7 +409,7 @@ def blowup(self): homvars = list(AA.gens()) homvars.pop(0) homvars.insert(i, 1) - coords = [vars[0]*homvars[j]] + coords = [(vars[0] - P[i])*homvars[j] + P[j]] for t in range(n): if t != j: coords.append(homvars[t]/homvars[j]) @@ -343,8 +420,9 @@ def blowup(self): for i in range(n): p_A = patches[i].ambient_space() H = Hom(patches[i], self) - coords = [p_A.gens()[0]*p_A.gens()[j] for j in range(1,n)] - coords.insert(i, p_A.gens()[0]) + homvars = list(p_A.gens())[1:n] + homvars.insert(i, 1) + coords = [(p_A.gens()[0] - P[i])*homvars[j] + P[j] for j in range(n)] proj_maps.append(H(coords)) return tuple([tuple(patches), tuple(t_maps), tuple(proj_maps)]) @@ -355,7 +433,7 @@ def resolution_of_singularities(self, extend=False): The nonsingular model is given as a collection of affine patches that cover it. If ``extend`` is ``False`` and if the base field is a number field, or if the base field is a finite field, the model returned may have singularities with coordinates not contained in the base field. An error is returned if this curve is already - nonsingular, or if it has no singular points over its base field. + nonsingular, or if it has no singular points over its base field. This curve must be irreducible. INPUT: @@ -380,21 +458,19 @@ def resolution_of_singularities(self, extend=False): sage: C = Curve([y^2 - x^3], A) sage: C.resolution_of_singularities() ((Affine Plane Curve over Rational Field defined by s1^2 - x, - Affine Plane Curve over Rational Field defined by -y*s0^3 + 1), - ((Scheme endomorphism of Affine Plane Curve over Rational Field defined - by s1^2 - x + Affine Plane Curve over Rational Field defined by y*s0^3 - 1), + ((Scheme endomorphism of Affine Plane Curve over Rational Field defined by s1^2 - x Defn: Defined on coordinates by sending (x, s1) to (x, s1), Scheme morphism: From: Affine Plane Curve over Rational Field defined by s1^2 - x - To: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + To: Affine Plane Curve over Rational Field defined by y*s0^3 - 1 Defn: Defined on coordinates by sending (x, s1) to (x*s1, 1/s1)), (Scheme morphism: - From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + From: Affine Plane Curve over Rational Field defined by y*s0^3 - 1 To: Affine Plane Curve over Rational Field defined by s1^2 - x Defn: Defined on coordinates by sending (y, s0) to (y*s0, 1/s0), - Scheme endomorphism of Affine Plane Curve over Rational Field defined - by -y*s0^3 + 1 + Scheme endomorphism of Affine Plane Curve over Rational Field defined by y*s0^3 - 1 Defn: Defined on coordinates by sending (y, s0) to (y, s0))), (Scheme morphism: @@ -402,7 +478,7 @@ def resolution_of_singularities(self, extend=False): To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 Defn: Defined on coordinates by sending (x, s1) to (x, x*s1), Scheme morphism: - From: Affine Plane Curve over Rational Field defined by -y*s0^3 + 1 + From: Affine Plane Curve over Rational Field defined by y*s0^3 - 1 To: Affine Plane Curve over Rational Field defined by -x^3 + y^2 Defn: Defined on coordinates by sending (y, s0) to (y*s0, y))) @@ -415,12 +491,10 @@ def resolution_of_singularities(self, extend=False): sage: C = A.curve(x^4 + 2*x^2 + a*y^3 + 1) sage: R = C.resolution_of_singularities(extend=True) # long time (2 seconds) sage: R[0] - (Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - - 4*y^2 + 16 defined by (1/8*a0^3 - a0)*x^2*ss1^3 + (-a0^2 + 2)*x*ss1^3 + 1, - Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - - 4*y^2 + 16 defined by (1/8*a0^3 - a0)*s1^2*ss0 + ss0^2 + (-a0^2 + 2)*s1, - Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - - 4*y^2 + 16 defined by y^2*s0^4 + (-1/2*a0^3)*y*s0^3 - 4*s0^2 + (1/8*a0^3 - a0)*y) + (Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by + 24*x*s1^3 + (3*a0^3)*s1^3 + (a0^3 - 8*a0)*x^2 + (8*a0^2 - 16)*x + (-a0^3 + 8*a0), Affine Plane Curve + over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by 8*y^2*s0^4 + + (-4*a0^3)*y*s0^3 - 32*s0^2 + (a0^3 - 8*a0)*y) :: @@ -428,12 +502,27 @@ def resolution_of_singularities(self, extend=False): sage: C = Curve([y - x^3, (z - 2)^2 - y^3 - x^3], A) sage: R = C.resolution_of_singularities() sage: R[0] - (Affine Curve over Finite Field of size 5 defined by -x^2 + s1, -x*s1^3 - + s2^2 - x, - Affine Curve over Finite Field of size 5 defined by -y^2*s0^3 + 1, - -y*s0^3 + s2^2 - y, - Affine Curve over Finite Field of size 5 defined by -z^2*s0^3 + s1, - -z*s0^3 - z*s1^3 + 1) + (Affine Curve over Finite Field of size 5 defined by x^2 - s1, s1^4 - x*s2^2 + s1, x*s1^3 - s2^2 + x, + Affine Curve over Finite Field of size 5 defined by y*s2^2 - y^2 - 1, s2^4 - s0^3 - y^2 - 2, y*s0^3 + - s2^2 + y, Affine Curve over Finite Field of size 5 defined by s0^3*s1 + z*s1^3 + s1^4 - 2*s1^3 - 1, + z*s0^3 + z*s1^3 - 2*s0^3 - 2*s1^3 - 1, z^2*s1^3 + z*s1^3 - s1^3 - z + s1 + 2) + + :: + + sage: A. = AffineSpace(QQ, 4) + sage: C = A.curve([((x - 2)^2 + y^2)^2 - (x - 2)^2 - y^2 + (x - 2)^3, z - y - 7, w - 4]) + sage: B = C.resolution_of_singularities() + sage: B[0] + (Affine Curve over Rational Field defined by s3, s1 - s2, x^2*s2^4 - + 4*x*s2^4 + 2*x^2*s2^2 + 4*s2^4 - 8*x*s2^2 + x^2 + 7*s2^2 - 3*x + 1, + Affine Curve over Rational Field defined by s3, s2 - 1, y^2*s0^4 + + 2*y^2*s0^2 + y*s0^3 + y^2 - s0^2 - 1, + Affine Curve over Rational Field defined by s3, s1 - 1, z^2*s0^4 - + 14*z*s0^4 + 2*z^2*s0^2 + z*s0^3 + 49*s0^4 - 28*z*s0^2 - 7*s0^3 + z^2 + + 97*s0^2 - 14*z + 48, + Closed subscheme of Affine Space of dimension 4 over Rational Field + defined by: + 1) :: @@ -473,6 +562,8 @@ def extension(self): # in the case that the base field is a number field, extend it as needed (if extend == True) C = self n = C.ambient_space().dimension_relative() + if not self.is_irreducible(): + raise TypeError("this curve must be irreducible") if C.base_ring() in NumberFields() and extend: C = C.change_ring(extension(C.singular_subscheme())) H = End(C) @@ -493,7 +584,7 @@ def extension(self): t = 0 # loop through the patches and blow up each until no patch has singular points while not_resolved: - [old_BC, t_maps, pi, pts] = [res[t][0], res[t][1], res[t][2], res[t][3]] + [BC, t_maps, pi, pts] = [res[t][0], res[t][1], res[t][2], res[t][3]] # check if there are any singular points in this patch if len(pts) == 0: t = t + 1 @@ -502,23 +593,8 @@ def extension(self): continue # the identity map should be replaced for each of the charts of the blow up t_maps.pop(t) - # translate pts[0] to the origin - H = End(old_BC.ambient_space()) - # translation map and inverse - phi = H([old_BC.ambient_space().gens()[i] - pts[0][i] for i in range(n)]) - phi_inv = H([old_BC.ambient_space().gens()[i] + pts[0][i] for i in range(n)]) - # create the translated curve - BC = old_BC.ambient_space().curve([f(phi_inv.defining_polynomials()) for f in\ - old_BC.defining_polynomials()]) - # restrict the domain and codomain of phi, phi_inv for compatibility with future maps - H = Hom(old_BC, BC) - phi = H(phi.defining_polynomials()) - H = Hom(BC, old_BC) - phi_inv = H(phi_inv.defining_polynomials()) - # translate the singular points - pts = [phi(old_BC(pts[i])) for i in range(len(pts))] - # blow up the origin - B = list(BC.blowup()) + # blow up pts[0] + B = list(BC.blowup(pts[0])) B = [list(B[0]), [list(B[1][i]) for i in range(len(B[1]))], list(B[2])] # the t-th element of res will be replaced with the new data corresponding to the charts # of the blow up @@ -530,7 +606,7 @@ def extension(self): for i in range(len(B[0])): # check if there are any singular points where this patch meets the exceptional divisor AA = AffineSpace(B[0][i].base_ring(), n - 1, 'x') - coords = [0] + coords = [pts[0][i]] coords.extend(list(AA.gens())) H = Hom(B[0][i].ambient_space().coordinate_ring(), AA.coordinate_ring()) poly_hom = H(coords) @@ -540,8 +616,6 @@ def extension(self): if B[0][i].base_ring() in NumberFields() and extend: emb = extension(X) # coerce everything to the new base field - phi = phi.change_ring(emb) - phi_inv = phi_inv.change_ring(emb) BC = BC.change_ring(emb) t_maps = [t_maps[j].change_ring(emb) for j in range(len(t_maps))] old_maps = [old_maps[j].change_ring(emb) for j in range(len(old_maps))] @@ -569,13 +643,13 @@ def extension(self): b_data.append(B[0][i]) # compose the current transition maps from the original curve to the other patches # with the projection map - t_pi = phi_inv*B[2][i] - coords = [BC.ambient_space().gens()[j]/BC.ambient_space().gens()[i] for j in range(n)] + t_pi = B[2][i] + coords = [(BC.ambient_space().gens()[j] - pts[0][j])/(BC.ambient_space().gens()[i] - pts[0][i]) for\ + j in range(n)] coords.pop(i) coords.insert(0, BC.ambient_space().gens()[i]) H = Hom(BC, B[0][i]) - tmp_pi_inv = H(coords) - t_pi_inv = tmp_pi_inv*phi + t_pi_inv = H(coords) L = list(t_maps) for j in range(len(t_maps)): L[j] = L[j]*t_pi @@ -587,19 +661,20 @@ def extension(self): new_t_map = t_pi_inv*old_maps[j] res[j][1].insert(t + i, new_t_map) # create the projection map - tmp_pi = B[2][i] - b_data.append(pi*phi_inv*tmp_pi) + b_data.append(pi*t_pi) # singular points # translate the singular points of the parent patch (other than that which was the center of the # blow up) by the inverse of the first projection map n_pts = [] for j in range(1, len(pts)): # make sure this point is in this chart before attempting to map it - if pts[j][i] != 0: - n_pts.append(tmp_pi_inv(pts[j])) + try: + n_pts.append(t_pi_inv(pts[j])) + except (TypeError, ZeroDivisionError): + pass # add in the points found from the exceptional divisor for pt in X.rational_points(): - tmp_pt = B[0][i].ambient_space()([0] + list(pt)) + tmp_pt = B[0][i].ambient_space()([pts[0][i]] + list(pt)) if B[0][i].is_singular(tmp_pt): n_pts.append(tmp_pt) b_data.append(n_pts) From 78fdd8169cf389b44ff87dcfd0712bc66338114b Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Thu, 18 Aug 2016 00:01:51 -0400 Subject: [PATCH 094/135] 21085: add import back in that was accidentally removed during merge - also fixed doctest in resolution_of_singularities --- src/sage/schemes/curves/affine_curve.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index 2aed94fab02..02353ccff0a 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -47,6 +47,7 @@ from sage.rings.number_field.number_field import NumberField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.qqbar import number_field_elements_from_algebraics, QQbar +from sage.rings.rational_field import is_RationalField from sage.schemes.affine.affine_space import (AffineSpace, is_AffineSpace) @@ -488,8 +489,7 @@ def resolution_of_singularities(self, extend=False): sage: K. = QuadraticField(3) sage: A. = AffineSpace(K, 2) sage: C = A.curve(x^4 + 2*x^2 + a*y^3 + 1) - sage: R = C.resolution_of_singularities(extend=True) # long time (2 seconds) - sage: R[0] + sage: R = C.resolution_of_singularities(extend=True)[0] # long time (2 seconds) (Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by 24*x*s1^3 + (3*a0^3)*s1^3 + (a0^3 - 8*a0)*x^2 + (8*a0^2 - 16)*x + (-a0^3 + 8*a0), Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by 8*y^2*s0^4 + From 5a176a170a07e482249b92d75a81cced665fd06b Mon Sep 17 00:00:00 2001 From: Kiran Kedlaya Date: Thu, 18 Aug 2016 05:20:27 +0000 Subject: [PATCH 095/135] Modify zeta method of rings to croak on non-integral domains --- src/sage/rings/ring.pyx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 32826402f4f..aaf569e3374 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -1044,7 +1044,8 @@ cdef class Ring(ParentWithGens): - ``n`` -- positive integer - ``all`` -- bool (default: False) - whether to return - a list of all primitive `n`-th roots of unity. + a list of all primitive `n`-th roots of unity. If True, raise a ``ValueError`` + if ``self`` is not an integral domain. OUTPUT: @@ -1092,7 +1093,12 @@ cdef class Ring(ParentWithGens): Traceback (most recent call last): ... ValueError: no 3rd root of unity in Rational Field + sage: IntegerModRing(8).zeta(2, all = True) + ... + ValueError: ring is not an integral domain """ + if all and not self.is_integral_domain(): + raise ValueError, "ring is not an integral domain" if n == 2: if all: return [self(-1)] From 1347786e4be87b6e3a0be960dd09943ec6ad79f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Thu, 18 Aug 2016 09:36:15 +0300 Subject: [PATCH 096/135] Add jump_number() to posets. --- src/sage/combinat/posets/posets.py | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 8e687f71ea4..382fcad7b78 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -63,6 +63,7 @@ :meth:`~FinitePoset.width` | Return the number of elements in a longest antichain of the poset. :meth:`~FinitePoset.relations_number` | Return the number of relations in the poset. :meth:`~FinitePoset.dimension` | Return the dimension of the poset. + :meth:`~FinitePoset.jump_number` | Return the jump number of the poset. :meth:`~FinitePoset.has_bottom` | Return ``True`` if the poset has a unique minimal element. :meth:`~FinitePoset.has_top` | Return ``True`` if the poset has a unique maximal element. :meth:`~FinitePoset.is_bounded` | Return ``True`` if the poset has both unique minimal and unique maximal element. @@ -2919,6 +2920,68 @@ def init_LP(k,cycles,inc_P): for l in linear_extensions] return k + def jump_number(self, certificate=False): + """ + Return the jump number of the poset. + + A *jump* in a linear extension `[e_1, \ldots, e_n]` of a poset `P` + is a pair `(e_i, e_{i+1})` so that `e_{i+1}` does not cover `e_i` + in `P`. The jump number of a poset is the minimal number of jumps + in linear extensions of a poset. + + INPUT: + + - ``certificate`` -- (default: ``False``) Whether to return + a certificate + + OUTPUT: + + - If ``certificate=True`` return a pair `(n, l)` where + `n` is the jump number and `l` is a linear extension + with `n` jumps. If ``certificate=False`` return only + the jump number. + + EXAMPLES:: + + sage: B3 = Posets.BooleanLattice(3) + sage: B3.jump_number() + 3 + + sage: N = Poset({1: [3, 4], 2: [3]}) + sage: N.jump_number(certificate=True) + (1, [1, 4, 2, 3]) + + TESTS:: + + sage: E = Poset() + sage: E.jump_number(certificate=True) + (0, []) + + sage: C4 = Posets.ChainPoset(4) + sage: A4 = Posets.AntichainPoset(4) + sage: C4.jump_number() + 0 + sage: A4.jump_number() + 3 + """ + H = self._hasse_diagram + jumps_min = H.order() # = "Infinity" + + for lin_ext in H.topological_sort_generator(): + jumpcount = 0 + for a, b in zip(lin_ext, lin_ext[1:]): + if not H.has_edge(a, b): + jumpcount += 1 + if jumpcount >= jumps_min: + break + else: + jumps_min = jumpcount + best_le = lin_ext + + if certificate: + return (jumps_min, [self._vertex_to_element(v) for v in best_le]) + return jumps_min + def rank_function(self): r""" Return the (normalized) rank function of the poset, From 8b488cce9aa6a9c9c727afccb1de21ca267d1ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 18 Aug 2016 08:54:48 +0200 Subject: [PATCH 097/135] trac 21193 adding r(aw) to doc chains --- src/sage/matroids/basis_matroid.pyx | 2 +- src/sage/matroids/circuit_closures_matroid.pyx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index f34dbfdf2ee..3b542228650 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -328,7 +328,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): # dual and minors cpdef dual(self): - """ + r""" Return the dual of the matroid. Let `M` be a matroid with ground set `E`. If `B` is the set of bases diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index df2dfcf6884..885fa7f83a7 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -70,7 +70,7 @@ from set_system cimport SetSystem from utilities import setprint_s cdef class CircuitClosuresMatroid(Matroid): - """ + r""" A general matroid `M` is characterized by its rank `r(M)` and the set of pairs From 042ed0fe3a8b2e8e28e468b99158d8acf81f4b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 18 Aug 2016 09:29:30 +0200 Subject: [PATCH 098/135] correct doc for cmap parameter --- src/sage/plot/density_plot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sage/plot/density_plot.py b/src/sage/plot/density_plot.py index 1ab5400c993..48bbeb7e9bd 100644 --- a/src/sage/plot/density_plot.py +++ b/src/sage/plot/density_plot.py @@ -173,7 +173,10 @@ def density_plot(f, xrange, yrange, **options): - ``plot_points`` -- integer (default: 25); number of points to plot in each direction of the grid - - ``cmap`` -- a colormap (type ``cmap_help()`` for more information). + - ``cmap`` -- a colormap (default: ``'gray'``), the name of + a predefined colormap, a list of colors or an instance of a matplotlib + Colormap. Type: ``import matplotlib.cm; matplotlib.cm.datad.keys()`` + for available colormap names. - ``interpolation`` -- string (default: ``'catrom'``), the interpolation method to use: ``'bilinear'``, ``'bicubic'``, ``'spline16'``, From 4a3b20f54da5c7aceb6a4310d940d48fac213b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 18 Aug 2016 15:47:33 +0200 Subject: [PATCH 099/135] trac 21266 trying to fix doctests in generic_graph color_by_label --- src/sage/graphs/generic_graph.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 560f3d002cd..c74e215a16b 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -17342,14 +17342,14 @@ def _color_by_label(self, format='hex', as_function=False, default_color = "blac The default output is a dictionary assigning edges to colors:: sage: G._color_by_label() - {'#0000ff': [((1,3,2,4), (1,4)(2,3), 3), ..., ((1,3), (1,4,3), 3)], - '#00ff00': [((1,3,2,4), (1,2,4), 2), ..., ((1,3), (1,2,3), 2)], - '#ff0000': [((1,3,2,4), (1,3)(2,4), 1), ..., ((1,3), (1,3,2), 1)]} + {'#0000ff': [((1,3,2,4), (1,4)(2,3), 3), ...], + '#00ff00': [((1,3,2,4), (1,2,4), 2), ...], + '#ff0000': [((1,3,2,4), (1,3)(2,4), 1), ...]} sage: G._color_by_label({1: "blue", 2: "red", 3: "green"}) - {'blue': [((1,3,2,4), (1,3)(2,4), 1), ..., ((1,3), (1,3,2), 1)], - 'green': [((1,3,2,4), (1,4)(2,3), 3), ..., ((1,3), (1,4,3), 3)], - 'red': [((1,3,2,4), (1,2,4), 2), ..., ((1,3), (1,2,3), 2)]} + {'blue': [((1,3,2,4), (1,3)(2,4), 1), ...], + 'green': [((1,3,2,4), (1,4)(2,3), 3), ...], + 'red': [((1,3,2,4), (1,2,4), 2), ...]} TESTS: From c369240b164cb3a206e7f11c095af7a86afa1404 Mon Sep 17 00:00:00 2001 From: Aram Dermenjian Date: Thu, 18 Aug 2016 10:05:55 -0400 Subject: [PATCH 100/135] Add test for aspect ratio problem --- src/sage/plot/plot.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index 07f7b4ad2d9..f27163e750d 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -1891,6 +1891,16 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) sage: label = '$' + latex(hello) + '$' sage: plot(x, x, 0, 1, legend_label=label) Graphics object consisting of 1 graphics primitive + + Extra kwds should be saved if object has a plot method, :trac:`20924`:: + + sage: G = graphs.PetersenGraph() + sage: p = G.plot() + sage: p.aspect_ratio() + 1.0 + sage: pp = plot(G) + sage: pp.aspect_ratio() + 1.0 """ if 'color' in kwds and 'rgbcolor' in kwds: raise ValueError('only one of color or rgbcolor should be specified') From 50d05de7b5c3c1e7dc134ad4c1548a9b0186fbbd Mon Sep 17 00:00:00 2001 From: Ben Hutz Date: Thu, 18 Aug 2016 09:48:08 -0500 Subject: [PATCH 101/135] 21285: error in change_ring for affine morphisms --- src/sage/schemes/generic/morphism.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/sage/schemes/generic/morphism.py b/src/sage/schemes/generic/morphism.py index 2934b49b971..b13bb802a8c 100644 --- a/src/sage/schemes/generic/morphism.py +++ b/src/sage/schemes/generic/morphism.py @@ -1428,6 +1428,18 @@ def change_ring(self, R, check=True): Scheme endomorphism of Affine Space of dimension 2 over Algebraic Field Defn: Defined on coordinates by sending (x, y) to (1.122462048309373?*x/y, y + 1) + + :: + + sage: K. = QuadraticField(-1) + sage: A. = AffineSpace(K, 2) + sage: H = End(A) + sage: phi = H([x/y, y]) + sage: emb = K.embeddings(QQbar)[0] + sage: phi.change_ring(emb) + Scheme endomorphism of Affine Space of dimension 2 over Algebraic Field + Defn: Defined on coordinates by sending (x, y) to + (x/y, y) """ K = self.codomain().base_ring() T = self.domain().change_ring(R) @@ -1439,7 +1451,7 @@ def change_ring(self, R, check=True): if isinstance(R, Morphism): if R.domain() == self.base_ring(): - R = self.coordinate_ring().hom(R, T.ambient_space().coordinate_ring()) + R = self.domain().ambient_space().coordinate_ring().hom(R, T.ambient_space().coordinate_ring()) G = [] for f in self: if isinstance(f, FractionFieldElement): From 98dde121eaf82a53208b1e33e9fe5a578d3a48d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 18 Aug 2016 18:41:09 +0200 Subject: [PATCH 102/135] trac 21238 fix example in tuto free module --- src/sage/modules/tutorial_free_modules.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sage/modules/tutorial_free_modules.py b/src/sage/modules/tutorial_free_modules.py index 9258e8b83b0..719a3312a3b 100644 --- a/src/sage/modules/tutorial_free_modules.py +++ b/src/sage/modules/tutorial_free_modules.py @@ -42,8 +42,11 @@ B[1.00000000000000*I] sage: F = CombinatorialFreeModule(ZZ, Partitions(NonNegativeIntegers(), max_part=3)); F.an_element() 2*B[[]] + 2*B[[1]] + 3*B[[2]] - sage: F = CombinatorialFreeModule(ZZ, ['spam', 'eggs', 42]); F.an_element() - 3*B[42] + 2*B['eggs'] + 2*B['spam'] + sage: F = CombinatorialFreeModule(ZZ, ['spam', 'eggs', '42']); F.an_element() + 3*B['42'] + 2*B['eggs'] + 2*B['spam'] + +Note that we use '42' (and not the number 42) so that all objects are +comparable in a deterministic way. Lists are not hashable, and thus cannot be used to index the basis; instead one can use tuples:: From 3e6ef521b41bb654261b6243d38c080284590203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Fri, 19 Aug 2016 09:30:51 +0300 Subject: [PATCH 103/135] to spaces. --- src/sage/combinat/posets/posets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 382fcad7b78..b1dacd447f0 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -2926,8 +2926,8 @@ def jump_number(self, certificate=False): A *jump* in a linear extension `[e_1, \ldots, e_n]` of a poset `P` is a pair `(e_i, e_{i+1})` so that `e_{i+1}` does not cover `e_i` - in `P`. The jump number of a poset is the minimal number of jumps - in linear extensions of a poset. + in `P`. The jump number of a poset is the minimal number of jumps + in linear extensions of a poset. INPUT: From 47e73c69fbc3c82cf9c3ebad1ec177280414f8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 19 Aug 2016 09:40:41 +0200 Subject: [PATCH 104/135] trac 21238 better wording --- src/sage/modules/tutorial_free_modules.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sage/modules/tutorial_free_modules.py b/src/sage/modules/tutorial_free_modules.py index 719a3312a3b..f6b87a06fa8 100644 --- a/src/sage/modules/tutorial_free_modules.py +++ b/src/sage/modules/tutorial_free_modules.py @@ -45,8 +45,11 @@ sage: F = CombinatorialFreeModule(ZZ, ['spam', 'eggs', '42']); F.an_element() 3*B['42'] + 2*B['eggs'] + 2*B['spam'] -Note that we use '42' (and not the number 42) so that all objects are -comparable in a deterministic way. +Note that we use '42' (and not the number 42) in order to ensure that +all objects are comparable in a deterministic way, which allows the +elements to be printed in a predictable manner. It is not mandatory +that indices have such a stable ordering, but if they do not, then the +elements may be displayed in some random order. Lists are not hashable, and thus cannot be used to index the basis; instead one can use tuples:: From bebf7b02f5cbe21fe85975821414b78fa65efadc Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Fri, 19 Aug 2016 04:33:25 -0400 Subject: [PATCH 105/135] 21085: minor improvements - blowup has default option to blow up origin - fixed a minor bug with the inverse projection maps - avoid uneccessary base field extensions --- src/sage/schemes/curves/affine_curve.py | 112 +++++++++++++----------- 1 file changed, 62 insertions(+), 50 deletions(-) diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index 02353ccff0a..635042e0132 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -35,6 +35,7 @@ from __future__ import absolute_import from sage.categories.fields import Fields +from sage.categories.finite_fields import FiniteFields from sage.categories.number_fields import NumberFields from sage.categories.homset import Hom, End from sage.interfaces.all import singular @@ -153,7 +154,7 @@ def projective_closure(self, i=0, PP=None): from .constructor import Curve return Curve(AlgebraicScheme_subscheme_affine.projective_closure(self, i, PP)) - def blowup(self, P): + def blowup(self, P=None): r""" Return the blow up of this affine curve at the point ``P``. @@ -161,7 +162,8 @@ def blowup(self, P): INPUT: - - ``P`` -- a point on this curve at which to blow up. + - ``P`` -- (default: None) a point on this curve at which to blow up. If ``None``, then ``P`` is + taken to be the origin. OUTPUT: @@ -177,8 +179,7 @@ def blowup(self, P): sage: A. = AffineSpace(QQ, 2) sage: C = Curve([y^2 - x^3], A) - sage: Q = A([0,0]) - sage: C.blowup(Q) + sage: C.blowup() ((Affine Plane Curve over Rational Field defined by s1^2 - x, Affine Plane Curve over Rational Field defined by y*s0^3 - 1), ([Scheme endomorphism of Affine Plane Curve over Rational Field defined by s1^2 - x @@ -210,8 +211,7 @@ def blowup(self, P): sage: K. = QuadraticField(2) sage: A. = AffineSpace(K, 3) sage: C = Curve([y^2 - a*x^5, x - z], A) - sage: Q = A([0,0,0]) - sage: B = C.blowup(Q) + sage: B = C.blowup() sage: B[0] (Affine Curve over Number Field in a with defining polynomial x^2 - 2 defined by s2 - 1, 2*x^3 + (-a)*s1^2, @@ -300,7 +300,7 @@ def blowup(self, P): sage: A. = AffineSpace(QQ, 4) sage: C = A.curve([((x + 1)^2 + y^2)^3 - 4*(x + 1)^2*y^2, y - z, w - 4]) - sage: Q = A([-1,0,0,4]) + sage: Q = C([-1,0,0,4]) sage: B = C.blowup(Q) sage: B[0] (Affine Curve over Rational Field defined by s3, s1 - s2, x^2*s2^6 + @@ -313,24 +313,25 @@ def blowup(self, P): Closed subscheme of Affine Space of dimension 4 over Rational Field defined by: 1) - sage: Q = A([0,0,0,0]) + sage: Q = A([6,2,3,1]) sage: B = C.blowup(Q) Traceback (most recent call last): ... - TypeError: (=(0, 0, 0, 0)) must be a point on this curve + TypeError: (=(6, 2, 3, 1)) must be a point on this curve :: sage: A. = AffineSpace(QuadraticField(-1), 2) sage: C = A.curve([y^2 + x^2]) - sage: Q = A([0,0]) - sage: C.blowup(Q) + sage: C.blowup() Traceback (most recent call last): ... TypeError: this curve must be irreducible """ A = self.ambient_space() n = A.dimension_relative() + if P is None: + P = A([0]*n) try: self(P) except TypeError: @@ -433,7 +434,8 @@ def resolution_of_singularities(self, extend=False): The nonsingular model is given as a collection of affine patches that cover it. If ``extend`` is ``False`` and if the base field is a number field, or if the base field is a finite field, the model returned may have singularities with coordinates not contained in the base field. An error is returned if this curve is already - nonsingular, or if it has no singular points over its base field. This curve must be irreducible. + nonsingular, or if it has no singular points over its base field. This curve must be irreducible, and must be + defined over a number field or finite field. INPUT: @@ -489,11 +491,13 @@ def resolution_of_singularities(self, extend=False): sage: K. = QuadraticField(3) sage: A. = AffineSpace(K, 2) sage: C = A.curve(x^4 + 2*x^2 + a*y^3 + 1) - sage: R = C.resolution_of_singularities(extend=True)[0] # long time (2 seconds) + sage: C.resolution_of_singularities(extend=True)[0] # long time (2 seconds) (Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by - 24*x*s1^3 + (3*a0^3)*s1^3 + (a0^3 - 8*a0)*x^2 + (8*a0^2 - 16)*x + (-a0^3 + 8*a0), Affine Plane Curve - over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by 8*y^2*s0^4 + - (-4*a0^3)*y*s0^3 - 32*s0^2 + (a0^3 - 8*a0)*y) + 24*x^2*ss1^3 + 24*ss1^3 + (a0^3 - 8*a0), + Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by + 24*s1^2*ss0 + (a0^3 - 8*a0)*ss0^2 + (6*a0^3)*s1, + Affine Plane Curve over Number Field in a0 with defining polynomial y^4 - 4*y^2 + 16 defined by + 8*y^2*s0^4 + (-4*a0^3)*y*s0^3 - 32*s0^2 + (a0^3 - 8*a0)*y) :: @@ -563,6 +567,8 @@ def extension(self): n = C.ambient_space().dimension_relative() if not self.is_irreducible(): raise TypeError("this curve must be irreducible") + if not (self.base_ring() in NumberFields() or self.base_ring() in FiniteFields()): + raise NotImplementedError("this curve must be defined over either a number field or a finite field") if C.base_ring() in NumberFields() and extend: C = C.change_ring(extension(C.singular_subscheme())) H = End(C) @@ -612,36 +618,46 @@ def extension(self): X = AA.subscheme([poly_hom(f) for f in B[0][i].defining_polynomials()]) # in the case of working over a number field, it might be necessary to extend the base # field in order to find all intersection points + n_pts = [] if B[0][i].base_ring() in NumberFields() and extend: emb = extension(X) - # coerce everything to the new base field - BC = BC.change_ring(emb) - t_maps = [t_maps[j].change_ring(emb) for j in range(len(t_maps))] - old_maps = [old_maps[j].change_ring(emb) for j in range(len(old_maps))] - pi = pi.change_ring(emb) - pts = [pt.change_ring(emb) for pt in pts] - # coerce the current blow up data X = X.change_ring(emb) - for j in range(len(B[0])): - B[0][j] = B[0][j].change_ring(emb) - for j in range(len(B[1])): - for k in range(len(B[1])): - B[1][j][k] = B[1][j][k].change_ring(emb) - for j in range(len(B[2])): - B[2][j] = B[2][j].change_ring(emb) - # coerce the other data in res - for j in range(len(res)): - res[j][0] = res[j][0].change_ring(emb) - for k in range(len(res[j][1])): - res[j][1][k] = res[j][1][k].change_ring(emb) - res[j][2].change_ring(emb) - for k in range(len(res[j][3])): - res[j][3][k] = res[j][3][k].change_ring(emb) - b_data = [] - # add the curve that defines this patch - b_data.append(B[0][i]) - # compose the current transition maps from the original curve to the other patches - # with the projection map + tmp_curve = B[0][i].change_ring(emb) + for pt in X.rational_points(): + tmp_pt = tmp_curve([pts[0][i]] + list(pt)) + if tmp_curve.is_singular(tmp_pt): + n_pts.append(tmp_pt) + # avoid needlessly extending the base field + if len(n_pts) > 0: + # coerce everything to the new base field + BC = BC.change_ring(emb) + t_maps = [t_maps[j].change_ring(emb) for j in range(len(t_maps))] + old_maps = [old_maps[j].change_ring(emb) for j in range(len(old_maps))] + pi = pi.change_ring(emb) + pts = [pt.change_ring(emb) for pt in pts] + # coerce the current blow up data + for j in range(len(B[0])): + B[0][j] = B[0][j].change_ring(emb) + for j in range(len(B[1])): + for k in range(len(B[1])): + B[1][j][k] = B[1][j][k].change_ring(emb) + for j in range(len(B[2])): + B[2][j] = B[2][j].change_ring(emb) + # coerce the other data in res + for j in range(len(res)): + res[j][0] = res[j][0].change_ring(emb) + for k in range(len(res[j][1])): + res[j][1][k] = res[j][1][k].change_ring(emb) + res[j][2].change_ring(emb) + for k in range(len(res[j][3])): + res[j][3][k] = res[j][3][k].change_ring(emb) + else: + for pt in X.rational_points(): + tmp_pt = B[0][i]([pts[0][i]] + list(pt)) + if B[0][i].is_singular(tmp_pt): + n_pts.append(tmp_pt) + b_data = [B[0][i]] + # projection map and its inverse t_pi = B[2][i] coords = [(BC.ambient_space().gens()[j] - pts[0][j])/(BC.ambient_space().gens()[i] - pts[0][i]) for\ j in range(n)] @@ -649,6 +665,8 @@ def extension(self): coords.insert(0, BC.ambient_space().gens()[i]) H = Hom(BC, B[0][i]) t_pi_inv = H(coords) + # compose the current transition maps from the original curve to the other patches + # with the projection map L = list(t_maps) for j in range(len(t_maps)): L[j] = L[j]*t_pi @@ -664,18 +682,12 @@ def extension(self): # singular points # translate the singular points of the parent patch (other than that which was the center of the # blow up) by the inverse of the first projection map - n_pts = [] for j in range(1, len(pts)): # make sure this point is in this chart before attempting to map it try: - n_pts.append(t_pi_inv(pts[j])) + n_pts.append(t_pi_inv(BC(pts[j]))) except (TypeError, ZeroDivisionError): pass - # add in the points found from the exceptional divisor - for pt in X.rational_points(): - tmp_pt = B[0][i].ambient_space()([pts[0][i]] + list(pt)) - if B[0][i].is_singular(tmp_pt): - n_pts.append(tmp_pt) b_data.append(n_pts) patches_to_add.append(b_data) for i in range(len(patches_to_add)): From aaf0345c876f25ceed933ce01d38b9e0c1fc912f Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Fri, 19 Aug 2016 10:36:40 +0200 Subject: [PATCH 106/135] bliss has no dependencies --- build/pkgs/bliss/dependencies | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 build/pkgs/bliss/dependencies diff --git a/build/pkgs/bliss/dependencies b/build/pkgs/bliss/dependencies new file mode 100644 index 00000000000..3546cda4614 --- /dev/null +++ b/build/pkgs/bliss/dependencies @@ -0,0 +1,5 @@ +# no dependencies + +---------- +All lines of this file are ignored except the first. +It is copied by SAGE_ROOT/build/make/install into SAGE_ROOT/build/make/Makefile. From 9ceab139109747004dea9d7f01373df5ee34c1c4 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Fri, 19 Aug 2016 11:10:22 +0200 Subject: [PATCH 107/135] Add package version check to OptionalExtension --- src/sage_setup/optional_extension.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sage_setup/optional_extension.py b/src/sage_setup/optional_extension.py index ef0738beab8..e1c57aca3ab 100644 --- a/src/sage_setup/optional_extension.py +++ b/src/sage_setup/optional_extension.py @@ -19,7 +19,9 @@ from distutils.extension import Extension -from sage.misc.package import is_package_installed +from sage.misc.package import is_package_installed, list_packages + +all_packages = list_packages(local=True) class CythonizeExtension(Extension): @@ -52,7 +54,7 @@ def OptionalExtension(*args, **kwds): - ``condition`` -- (boolean) the actual condition - ``package`` -- (string) the condition is that this package is - installed (only used if ``condition`` is not given) + installed and up-to-date (only used if ``condition`` is not given) EXAMPLES:: @@ -74,7 +76,13 @@ def OptionalExtension(*args, **kwds): condition = kwds.pop("condition") except KeyError: pkg = kwds.pop("package") - condition = is_package_installed(pkg) + try: + pkginfo = all_packages[pkg] + except KeyError: + # Might be an installed old-style package + condition = is_package_installed(pkg) + else: + condition = (pkginfo["installed_version"] == pkginfo["remote_version"]) if condition: return Extension(*args, **kwds) From 1fb82d7ff069acf6f266ca966dbcd79b7d7c9872 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Fri, 19 Aug 2016 11:18:39 +0200 Subject: [PATCH 108/135] Minor optimizations to list_packages() --- src/sage/misc/package.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/sage/misc/package.py b/src/sage/misc/package.py index 9440f75dc58..bdddb6347f8 100644 --- a/src/sage/misc/package.py +++ b/src/sage/misc/package.py @@ -217,31 +217,33 @@ def list_packages(*pkg_types, **opts): pkgs = {} for p in os.listdir(SAGE_PKGS): - if not os.path.isfile(os.path.join(SAGE_PKGS, p, "type")): + try: + f = open(os.path.join(SAGE_PKGS, p, "type")) + except IOError: + # Probably an empty directory => ignore continue - pkg = {'name': p} - with open(os.path.join(SAGE_PKGS, p, "type")) as f: - pkg['type'] = f.read().strip() + with f: + typ = f.read().strip() - if pkg['type'] not in pkg_types: + if typ not in pkg_types: continue - pkg['installed_version'] = installed.get(p) + pkg = {'name': p, 'type': typ, 'installed_version': installed.get(p)} pkg['installed'] = pkg['installed_version'] is not None - package_filename = os.path.join(SAGE_PKGS, p, "package-version.txt") if pkg['type'] == 'pip': if not local: pkg['remote_version'] = pip_remote_version(p, ignore_URLError=ignore_URLError) else: pkg['remote_version'] = None - elif os.path.isfile(package_filename): + else: + # If package-version.txt does not exist, that is an error + # in the build system => we just propagate the exception + package_filename = os.path.join(SAGE_PKGS, p, "package-version.txt") with open(package_filename) as f: pkg['remote_version'] = f.read().strip() pkg['installed_version'] = installed.get(p) - else: - raise RuntimeError pkgs[p] = pkg From aa04d96490354c92f222a16f0016dcd2f681bb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Fri, 19 Aug 2016 13:34:19 +0300 Subject: [PATCH 109/135] Add algorithm-keyword to canonical labeling of posets. --- src/sage/combinat/posets/posets.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 8e687f71ea4..af594946acb 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -4503,12 +4503,17 @@ def relabel(self, relabeling): elements=elements, category=self.category(), facade=self._is_facade) - def canonical_label(self): + def canonical_label(self, algorithm=None): """ Return the unique poset on the labels `\{0, \ldots, n-1\}` (where `n` is the number of elements in the poset) that is isomorphic to this poset and invariant in the isomorphism class. + INPUT: + + - ``algorithm``, a string or ``None`` -- a parameter forwarded + to underlying graph function to select the algorithm to use + .. SEEALSO:: - Canonical labeling of directed graphs: @@ -4552,8 +4557,14 @@ def canonical_label(self): sage: Poset().canonical_label() # Test the empty poset Finite poset containing 0 elements + + sage: D2 = Posets.DiamondPoset(4).canonical_label(algorithm='bliss') # optional: bliss + sage: B2 = Posets.BooleanLattice(2).canonical_label(algorithm='bliss') # optional: bliss + sage: D2 == B2 # optional: bliss + True """ - canonical_label = self._hasse_diagram.canonical_label(certificate=True)[1] + canonical_label = self._hasse_diagram.canonical_label(certificate=True, + algorithm=algorithm)[1] canonical_label = {self._elements[v]:i for v,i in canonical_label.iteritems()} return self.relabel(canonical_label) From e93e5928f4d0b8db0b28d84838994d0aea686d70 Mon Sep 17 00:00:00 2001 From: Aram Dermenjian Date: Fri, 19 Aug 2016 07:00:47 -0400 Subject: [PATCH 110/135] Remove unneeded whitespace and grammatical changes --- src/sage/plot/plot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index f27163e750d..15b6075915c 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -1892,7 +1892,7 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) sage: plot(x, x, 0, 1, legend_label=label) Graphics object consisting of 1 graphics primitive - Extra kwds should be saved if object has a plot method, :trac:`20924`:: + Extra keywords should be saved if object has a plot method, :trac:`20924`:: sage: G = graphs.PetersenGraph() sage: p = G.plot() @@ -1919,11 +1919,11 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) if hasattr(funcs, 'plot'): G = funcs.plot(*args, **original_opts) - # If we already have certain items already set, then update them + # If we have extra keywords already set, then update them for ext in G._extra_kwds: if ext in G_kwds: G_kwds[ext] = G._extra_kwds[ext] - + # if we are using the generic plotting method else: n = len(args) From c392e7e5571d84940668945c46d8119ded864a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Fri, 19 Aug 2016 15:41:13 +0300 Subject: [PATCH 111/135] Added reference. --- src/sage/combinat/posets/posets.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index b1dacd447f0..28f7eec6e4d 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -2951,6 +2951,14 @@ def jump_number(self, certificate=False): sage: N.jump_number(certificate=True) (1, [1, 4, 2, 3]) + REFERENCES: + + .. [BIANCO] L. Bianco, P. Dell‘Olmo, S. Giordani + An Optimal Algorithm to Find the Jump Number of Partially Ordered Sets + Computational Optimization and Applications, + 1997, Volume 8, Issue 2, pp 197--210, + http://link.springer.com/article/10.1023/A%3A1008625405476 + TESTS:: sage: E = Poset() From 45377eecadf076cf5bb0dc771f37250611a6c41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 19 Aug 2016 15:00:54 +0200 Subject: [PATCH 112/135] getting rid of some useless .keys() --- src/sage/combinat/matrices/latin.py | 9 +++++---- src/sage/combinat/posets/posets.py | 4 ++-- .../root_system/extended_affine_weyl_group.py | 2 +- .../root_system/reflection_group_complex.py | 14 +++++++------- src/sage/combinat/sf/jack.py | 4 ++-- src/sage/combinat/sf/sf.py | 2 +- src/sage/combinat/words/morphism.py | 12 ++++++------ src/sage/ext/interactive_constructors_c.pyx | 2 +- src/sage/knots/link.py | 14 +++++++------- src/sage/parallel/use_fork.py | 2 +- src/sage/plot/plot3d/base.pyx | 2 +- src/sage/repl/attach.py | 2 +- .../rings/polynomial/laurent_polynomial.pyx | 18 +++++++++--------- src/sage/schemes/elliptic_curves/cm.py | 8 ++++---- .../schemes/elliptic_curves/padic_lseries.py | 2 +- 15 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/sage/combinat/matrices/latin.py b/src/sage/combinat/matrices/latin.py index e035a673ff3..a07925120f0 100644 --- a/src/sage/combinat/matrices/latin.py +++ b/src/sage/combinat/matrices/latin.py @@ -790,7 +790,7 @@ def permissable_values(self, r, c): # in the previous for-loop. pass - return vals.keys() + return list(vals) def random_empty_cell(self): """ @@ -821,9 +821,10 @@ def random_empty_cell(self): if self[r, c] < 0: cells[ (r,c) ] = True - cells = cells.keys() + cells = list(cells) - if len(cells) == 0: return None + if not cells: + return None rc = cells[ ZZ.random_element(len(cells)) ] @@ -2838,7 +2839,7 @@ def dlxcpp_find_completions(P, nr_to_find = None): comps = [] - for i in SOLUTIONS.keys(): + for i in SOLUTIONS: soln = list(i) from copy import deepcopy diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 8e687f71ea4..78824f65726 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -1757,7 +1757,7 @@ def plot(self, label_elements=True, element_labels=None, for (element, label) in element_labels.items()) graph = graph.relabel(relabeling, inplace = False) if heights is not None: - for key in heights.keys(): + for key in heights: heights[key] = [relabeling[i] for i in heights[key]] if cover_labels is not None: @@ -6775,7 +6775,7 @@ def _ford_fulkerson_chronicle(G, s, t, a): # X: list of vertices of G' reachable from s, along with # the shortest paths from s to them. X = Gprime.shortest_paths(s) - if t in X.keys(): + if t in X: # Step MC2a in Britz-Fomin, Algorithm 7.2. shortest_path = X[t] shortest_path_in_edges = zip(shortest_path[:-1],shortest_path[1:]) diff --git a/src/sage/combinat/root_system/extended_affine_weyl_group.py b/src/sage/combinat/root_system/extended_affine_weyl_group.py index d540bc3718c..b8d1b68b575 100644 --- a/src/sage/combinat/root_system/extended_affine_weyl_group.py +++ b/src/sage/combinat/root_system/extended_affine_weyl_group.py @@ -450,7 +450,7 @@ def __init__(self, cartan_type, general_linear, **print_options): self._n = self._cartan_type.n + 1 else: self._general_linear = False - for option in print_options.keys(): + for option in print_options: if option == 'translation': self._prefixt = print_options['translation'] elif option == 'fundamental': diff --git a/src/sage/combinat/root_system/reflection_group_complex.py b/src/sage/combinat/root_system/reflection_group_complex.py index 759a3b536e2..82db840bc16 100644 --- a/src/sage/combinat/root_system/reflection_group_complex.py +++ b/src/sage/combinat/root_system/reflection_group_complex.py @@ -1018,7 +1018,7 @@ def reflection_eigenvalues_family(self): sage: W = ReflectionGroup((3,1,2)) # optional - gap3 sage: reflection_eigenvalues = W.reflection_eigenvalues_family() # optional - gap3 - sage: for elt in sorted(reflection_eigenvalues.keys()): # optional - gap3 + sage: for elt in sorted(reflection_eigenvalues): # optional - gap3 ....: print('%s %s'%(elt, reflection_eigenvalues[elt])) # optional - gap3 () [0, 0] (1,3,9)(2,4,10)(6,11,17)(8,12,18)(14,19,23)(15,16,20)(21,22,24) [1/3, 0] @@ -1032,7 +1032,7 @@ def reflection_eigenvalues_family(self): sage: W = ReflectionGroup(23) # optional - gap3 sage: reflection_eigenvalues = W.reflection_eigenvalues_family() # optional - gap3 - sage: for elt in sorted(reflection_eigenvalues.keys()): # optional - gap3 + sage: for elt in sorted(reflection_eigenvalues): # optional - gap3 ....: print('%s %s'%(elt, reflection_eigenvalues[elt])) # optional - gap3 () [0, 0, 0] (1,8,4)(2,21,3)(5,10,11)(6,18,17)(7,9,12)(13,14,15)(16,23,19)(20,25,26)(22,24,27)(28,29,30) [1/3, 2/3, 0] @@ -1501,7 +1501,7 @@ def invariant_form(self, brute_force=False): C = self.cartan_matrix() if not self.is_well_generated(): - indep_inds = sorted(self._index_set_inverse[key] for key in self.independent_roots().keys()) + indep_inds = sorted(self._index_set_inverse[key] for key in self.independent_roots()) C = C.matrix_from_rows_and_columns(indep_inds,indep_inds) for j in range(n): @@ -1635,7 +1635,7 @@ def set_reflection_representation(self,refl_repr=None): ----- sage: W.set_reflection_representation() # optional - gap3 """ - if refl_repr is None or set(refl_repr.keys()) == set(self.index_set()): + if refl_repr is None or set(refl_repr) == set(self.index_set()): self._reflection_representation = refl_repr else: raise ValueError("the reflection representation must be defined for the complete index set") @@ -1660,7 +1660,7 @@ def conjugacy_class_representative(self): [1, 2, 1] [1] """ W = self.parent() - for w in W._conjugacy_classes.keys(): + for w in W._conjugacy_classes: if self in W._conjugacy_classes[w]: return w return W.conjugacy_classes_representatives()[ gap3("PositionClass(%s,%s)"%(W._gap_group._name,self)).sage()-1 ] @@ -1683,7 +1683,7 @@ def conjugacy_class(self): W = self.parent() if self not in W.conjugacy_classes_representatives(): self = self.conjugacy_class_representative() - if self in W._conjugacy_classes.keys(): + if self in W._conjugacy_classes: return W._conjugacy_classes[self] gens = W.simple_reflections() count = 0 @@ -1949,7 +1949,7 @@ def to_matrix(self, on_space="primal"): if W._reflection_representation is None: Delta = W.independent_roots() Phi = W.roots() - inds = [ W._index_set_inverse[i] for i in W.independent_roots().keys() ] + inds = [W._index_set_inverse[i] for i in W.independent_roots()] M = Matrix([Phi[self(i+1)-1] for i in inds]) mat = W.base_change_matrix() * M else: diff --git a/src/sage/combinat/sf/jack.py b/src/sage/combinat/sf/jack.py index 9ca31c52e02..7819f4df7f4 100644 --- a/src/sage/combinat/sf/jack.py +++ b/src/sage/combinat/sf/jack.py @@ -1209,8 +1209,8 @@ def _h_cache(self, n): to_cache_1 = self._self_to_h_cache[n] from_cache_2 = self._P._m_to_self_cache[n] to_cache_2 = self._h_to_self_cache[n] - for mu in from_cache_1.keys(): - for la in from_cache_1[mu].keys(): + for mu in from_cache_1: + for la in from_cache_1[mu]: if not la in to_cache_1: to_cache_1[la] = {} to_cache_2[la] = {} diff --git a/src/sage/combinat/sf/sf.py b/src/sage/combinat/sf/sf.py index 90c73ca580b..00307d02cc8 100644 --- a/src/sage/combinat/sf/sf.py +++ b/src/sage/combinat/sf/sf.py @@ -1433,7 +1433,7 @@ def __init_extra__(self): from sage.combinat.sf.classical import conversion_functions - for (basis1_name, basis2_name) in conversion_functions.keys(): + for (basis1_name, basis2_name) in conversion_functions: basis1 = getattr(self, basis1_name)() basis2 = getattr(self, basis2_name)() on_basis = SymmetricaConversionOnBasis(t = conversion_functions[basis1_name,basis2_name], domain = basis1, codomain = basis2) diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 54d91104587..eb54d078bcd 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -2537,7 +2537,7 @@ def rauzy_fractal_points(self, n=None, exchange=False, eig=None, translate=None, if translate is not None: if isinstance(translate, dict): - for a in translate.keys(): + for a in translate: translate[a] = [vector(RealField_prec, v) for v in translate[a]] else: @@ -2784,7 +2784,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, translate=None, p elif isinstance(colormap, str): from matplotlib import cm - if not colormap in cm.datad.keys(): + if not colormap in cm.datad: raise RuntimeError("Color map %s not known (type sorted(colors) for valid names)" % colormap) colormap = cm.__dict__[colormap] @@ -2817,9 +2817,9 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, translate=None, p # 1D plots if dim_fractal == 1: from sage.all import plot - for a in col_dict.keys(): + for a in col_dict: # We plot only the points with a color in col_dict and with positive opacity - if (a in col_dict.keys()) and (opacity[a] > 0): + if (a in col_dict) and (opacity[a] > 0): G += plot([x[0] for x in orbit_points[a]], color=col_dict[a], alpha=opacity[a], thickness=point_size) if plot_basis: from matplotlib import cm @@ -2836,9 +2836,9 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, translate=None, p elif point_size is None and dim_fractal == 3: point_size = 8 - for a in col_dict.keys(): + for a in col_dict: # We plot only the points with a color in col_dict and with positive opacity - if (a in col_dict.keys()) and (opacity[a] > 0): + if (a in col_dict) and (opacity[a] > 0): G += points(orbit_points[a], color=col_dict[a], alpha=opacity[a], size=point_size) if plot_basis: diff --git a/src/sage/ext/interactive_constructors_c.pyx b/src/sage/ext/interactive_constructors_c.pyx index 625351f8f4e..321e368b5a0 100644 --- a/src/sage/ext/interactive_constructors_c.pyx +++ b/src/sage/ext/interactive_constructors_c.pyx @@ -79,7 +79,7 @@ def inject_on(verbose=True): G = globals() if verbose: print("Redefining:", end=" ") - for X in sorted(sage.ext.interactive_constructors_c.__dict__.keys()): + for X in sorted(sage.ext.interactive_constructors_c.__dict__): if not 'inject' in X and X[0] != '_' and X[:4] != 'sage': if verbose: print(X, end=" ") diff --git a/src/sage/knots/link.py b/src/sage/knots/link.py index 4ee1818d302..daaef43e2cb 100644 --- a/src/sage/knots/link.py +++ b/src/sage/knots/link.py @@ -651,7 +651,7 @@ def _directions_of_edges(self): D = next_crossing[0] a = D[(D.index(a)+2) % 4] - unassigned = set(flatten(pd_code)).difference(set(tails.keys())) + unassigned = set(flatten(pd_code)).difference(set(tails)) while unassigned: a = unassigned.pop() for x in pd_code: @@ -925,13 +925,13 @@ def _khovanov_homology_cached(self, height, ring=ZZ): for st in states: i, j = st[3], st[4] if j == height: - if (i,j) in bases.keys(): + if (i,j) in bases: bases[i,j].append(st) else: bases[i,j] = [st] complexes = {} - for (i, j) in bases.keys(): - if (i+1, j) in bases.keys(): + for (i, j) in bases: + if (i+1, j) in bases: m = matrix(ring, len(bases[(i,j)]), len(bases[(i+1,j)])) for ii in range(m.nrows()): V1 = bases[(i,j)][ii] @@ -945,7 +945,7 @@ def _khovanov_homology_cached(self, height, ring=ZZ): else: m = matrix(ring, len(bases[(i,j)]), 0) complexes[i] = m.transpose() - if not (i-1, j) in bases.keys(): + if not (i-1, j) in bases: complexes[i-1] = matrix(ring, len(bases[(i,j)]), 0) homologies = ChainComplex(complexes).homology() return tuple(sorted(homologies.items())) @@ -2649,7 +2649,7 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, **kwargs): nregion+=[[a, -sig] for a in rev] nregion.append([segments[-e][0], 1]) nregions.append(nregion) - N = max(segments.keys()) + 1 + N = max(segments) + 1 segments = [i for j in segments.values() for i in j] badregions = [nr for nr in nregions if any(-1 == x[1] for x in nr)] while badregions: @@ -2679,7 +2679,7 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, **kwargs): segments.append(N1) segments.append(N2) if type(badregion[b][0]) in (int, Integer): - segmenttoadd = [x for x in pieces.keys() + segmenttoadd = [x for x in pieces if badregion[b][0] in pieces[x]] if len(segmenttoadd) > 0: pieces[segmenttoadd[0]].append(N2) diff --git a/src/sage/parallel/use_fork.py b/src/sage/parallel/use_fork.py index 673e43888c1..64357be569e 100644 --- a/src/sage/parallel/use_fork.py +++ b/src/sage/parallel/use_fork.py @@ -201,7 +201,7 @@ def __call__(self, f, inputs): if self.verbose: print("Killing any remaining workers...") sys.stdout.flush() - for pid in workers.keys(): + for pid in workers: try: os.kill(pid, signal.SIGKILL) os.waitpid(pid, 0) diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 990b329c880..e55641d1458 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -1232,7 +1232,7 @@ end_scene""" % (render_params.antialiasing, # Remove all of the keys that are viewing options, since the remaining # kwds might be passed on. - for key_to_remove in SHOW_DEFAULTS.keys(): + for key_to_remove in SHOW_DEFAULTS: kwds.pop(key_to_remove, None) # deal with any aspect_ratio instances passed from the default options to plot diff --git a/src/sage/repl/attach.py b/src/sage/repl/attach.py index 03b87d5a52c..b8b5c1ff786 100644 --- a/src/sage/repl/attach.py +++ b/src/sage/repl/attach.py @@ -398,7 +398,7 @@ def attached_files(): True """ global attached - return list(sorted(attached.keys())) + return sorted(attached) def detach(filename): diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index e496987d3d5..36974007202 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -80,7 +80,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial_generic): f = parent.polynomial_ring()((f).__u) elif (not isinstance(f, Polynomial)) or (parent is not f.parent()): if isinstance(f, dict): - v = min(f.keys()) + v = min(f) f = dict((i-v,c) for i,c in f.items()) n += v f = parent.polynomial_ring()(f) @@ -1334,7 +1334,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): x = x.dict() if isinstance(x, dict): self._mon = ETuple({},int(parent.ngens())) - for k in x.keys(): # ETuple-ize keys, set _mon + for k in x: # ETuple-ize keys, set _mon if not isinstance(k, (tuple, ETuple)) or len(k) != parent.ngens(): self._mon = ETuple({}, int(parent.ngens())) break @@ -1346,7 +1346,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): self._mon = self._mon.emin(k) # point-wise min of _mon and k if len(self._mon.nonzero_positions()) != 0: # factor out _mon D = {} - for k in x.keys(): + for k in x: D[k.esub(self._mon)] = x[k] x = D else: # since x should coerce into parent, _mon should be (0,...,0) @@ -1427,7 +1427,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): D = self._poly._mpoly_dict_recursive(self.parent().variable_names(), self.parent().base_ring()) if i is None: e = None - for k in D.keys(): + for k in D: if e is None: e = k else: @@ -1437,7 +1437,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): self._mon = self._mon.eadd(e) else: e = None - for k in D.keys(): + for k in D: if e is None or k[i] < e: e = k[i] if e > 0: @@ -1452,7 +1452,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): sage: a = w^2*z^-1+3; a w^2*z^-1 + 3 sage: d = a._dict() - sage: keys = list(sorted(d.keys())); keys + sage: keys = list(sorted(d)); keys [(0, 0), (2, -1)] sage: d[keys[0]] 3 @@ -1463,7 +1463,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): D = self._poly._mpoly_dict_recursive(self.parent().variable_names(), self.parent().base_ring()) if len(self._mon.nonzero_positions()) > 0: DD = {} - for k in D.keys(): + for k in D: DD[k.eadd(self._mon)] = D[k] return DD else: @@ -1866,7 +1866,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): g = self.parent().gens() nvars = len(g) vars = [] - for k in d.keys(): + for k in d: vars = union(vars,k.nonzero_positions()) if len(vars) == nvars: break @@ -2358,7 +2358,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial_generic): d = self._dict() out = 0 - for mon in d.keys(): + for mon in d: term = d[mon] for i in range(len(mon)): if i in vars: diff --git a/src/sage/schemes/elliptic_curves/cm.py b/src/sage/schemes/elliptic_curves/cm.py index b81efea1cbf..ac8b1d6534f 100644 --- a/src/sage/schemes/elliptic_curves/cm.py +++ b/src/sage/schemes/elliptic_curves/cm.py @@ -414,7 +414,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None): EXAMPLES:: sage: v = sage.schemes.elliptic_curves.cm.discriminants_with_bounded_class_number(3) - sage: v.keys() + sage: list(v) [1, 2, 3] sage: v[1] [(-3, 3), (-3, 2), (-3, 1), (-4, 2), (-4, 1), (-7, 2), (-7, 1), (-8, 1), (-11, 1), (-19, 1), (-43, 1), (-67, 1), (-163, 1)] @@ -423,7 +423,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None): sage: v[3] [(-3, 9), (-3, 6), (-11, 2), (-19, 2), (-23, 2), (-23, 1), (-31, 2), (-31, 1), (-43, 2), (-59, 1), (-67, 2), (-83, 1), (-107, 1), (-139, 1), (-163, 2), (-211, 1), (-283, 1), (-307, 1), (-331, 1), (-379, 1), (-499, 1), (-547, 1), (-643, 1), (-883, 1), (-907, 1)] sage: v = sage.schemes.elliptic_curves.cm.discriminants_with_bounded_class_number(8, proof=False) - sage: [len(v[h]) for h in v.keys()] + sage: [len(v[h]) for h in v] [13, 29, 25, 84, 29, 101, 38, 208] Find all class numbers for discriminant up to 50:: @@ -528,14 +528,14 @@ def lb(f): T[h] = [z] f += 1 - for h in T.keys(): + for h in T: T[h] = list(reversed(T[h])) if fund_count is not None: # Double check that we found the right number of fundamental # discriminants; we might as well, since Watkins provides this # data. - for h in T.keys(): + for h in T: if len([D for D,f in T[h] if f==1]) != fund_count[h]: raise RuntimeError("number of discriminants inconsistent with Watkins's table") diff --git a/src/sage/schemes/elliptic_curves/padic_lseries.py b/src/sage/schemes/elliptic_curves/padic_lseries.py index 741bc9fcc42..b015ec6b0c7 100644 --- a/src/sage/schemes/elliptic_curves/padic_lseries.py +++ b/src/sage/schemes/elliptic_curves/padic_lseries.py @@ -676,7 +676,7 @@ def _get_series_from_cache(self, n, prec, D, eta): except AttributeError: self.__series = {} except KeyError: - for _n, _prec, _D, _eta in self.__series.keys(): + for _n, _prec, _D, _eta in self.__series: if _n == n and _D == D and _eta == eta and _prec >= prec: return self.__series[(_n,_prec,_D,_eta)].add_bigoh(prec) return None From 2c5dae819d7ec13774f4e7a19925e7b844f7285a Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Fri, 19 Aug 2016 16:22:35 +0200 Subject: [PATCH 113/135] Print warnings to stdout instead of stderr --- src/sage/doctest/forker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 3e358b0d937..9d63323e35c 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -125,7 +125,7 @@ def init_sage(): stringPict.terminal_width = lambda self:0 -def showwarning_with_traceback(message, category, filename, lineno, file=sys.stderr, line=None): +def showwarning_with_traceback(message, category, filename, lineno, file=sys.stdout, line=None): r""" Displays a warning message with a traceback. From 1ed88aef15cae31754965a9a6eb2de55667ca5c4 Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Fri, 19 Aug 2016 16:26:03 +0100 Subject: [PATCH 114/135] removed unused prompt and unneeded option (improved x 3) --- src/sage/interfaces/octave.py | 56 +---------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/src/sage/interfaces/octave.py b/src/sage/interfaces/octave.py index 5de29046428..664b547a0ac 100644 --- a/src/sage/interfaces/octave.py +++ b/src/sage/interfaces/octave.py @@ -157,49 +157,6 @@ from .expect import Expect, ExpectElement from sage.misc.misc import verbose -def get_octave_version(command=None, server=None): - r""" - Get the octave version given the ``command`` and ``server``. - - This does *not* launch the interface (since the latter needs configuration - options that actually depend on the version). - - EXAMPLES:: - - sage: from sage.interfaces.octave import get_octave_version - sage: octave.version() # optional - octave # indirect doctest - '...' - """ - import re - from subprocess import Popen, PIPE - - version_string = re.compile("GNU Octave, version (\d+\.\d+\.\d+)") - - if command is None: - raise ValueError("a command must be provided") - - if server: - cmd = [server, command, "--version"] - else: - cmd = [command, "--version"] - - try: - proc = Popen(cmd, stdout=PIPE) - except OSError: - raise ValueError("octave not available") - - s = proc.communicate() - if proc.poll(): - raise ValueError("octave sent a non-zero signal (={})".format(proc.poll())) - - first_line = s[0].split('\n')[0] - m = version_string.match(first_line) - if m is None: - raise ValueError("Octave first line of output does not fit with what " - "was expected:\n{}".format(first_line)) - - return m.group(1) - class Octave(Expect): r""" Interface to the Octave interpreter. @@ -230,23 +187,12 @@ def __init__(self, maxread=None, script_subdirectory=None, logfile=None, if server is None: import os server = os.getenv('SAGE_OCTAVE_SERVER') or None - - version = get_octave_version(command=command, server=server) - major = int(version.split('.')[0]) - - if major < 4: - prompt = '>' - options = " --no-line-editing --silent" - else: - prompt = '>>' - options = " --no-gui --no-line-editing --silent" - Expect.__init__(self, name = 'octave', # We want the prompt sequence to be unique to avoid confusion with syntax error messages containing >>> prompt = 'octave\:\d+> ', # We don't want any pagination of output - command = command + options + " --eval 'PS2(PS1());more off' --persist", + command = command + " --no-line-editing --silent --eval 'PS2(PS1());more off' --persist", maxread = maxread, server = server, server_tmpdir = server_tmpdir, From 9c54b52140981fa4798289355184e8707e693db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Sat, 20 Aug 2016 07:16:55 +0300 Subject: [PATCH 115/135] Link type to :doi:. --- src/sage/combinat/posets/posets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 28f7eec6e4d..814f4453b71 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -2957,7 +2957,7 @@ def jump_number(self, certificate=False): An Optimal Algorithm to Find the Jump Number of Partially Ordered Sets Computational Optimization and Applications, 1997, Volume 8, Issue 2, pp 197--210, - http://link.springer.com/article/10.1023/A%3A1008625405476 + :doi:`10.1023/A:1008625405476` TESTS:: From 5fe1193455a645b489b1536b803b9cb803df7dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 20 Aug 2016 18:30:58 +0200 Subject: [PATCH 116/135] a bunch of typos, including "because" --- COPYING.txt | 2 +- src/sage/combinat/combinat.py | 4 ++-- src/sage/combinat/designs/difference_family.py | 2 +- src/sage/databases/oeis.py | 2 +- src/sage/libs/symmetrica/sc.pxi | 3 ++- src/sage/modular/arithgroup/arithgroup_perm.py | 4 ++-- src/sage/modular/btquotients/pautomorphicform.py | 2 +- src/sage/modular/local_comp/local_comp.py | 4 +++- src/sage/modular/modform/numerical.py | 2 +- src/sage/modular/modform_hecketriangle/abstract_space.py | 3 ++- .../modform_hecketriangle/hecke_triangle_group_element.py | 8 ++++---- src/sage/modular/modform_hecketriangle/readme.py | 2 +- src/sage/modular/pollack_stevens/sigma0.py | 2 +- src/sage/modular/pollack_stevens/space.py | 6 +++--- src/sage/monoids/automatic_semigroup.py | 4 ++-- src/sage/plot/plot3d/implicit_plot3d.py | 2 +- src/sage/rings/padics/padic_generic_element.pyx | 2 +- src/sage/rings/polynomial/polynomial_zmod_flint.pyx | 2 +- src/sage/stats/distributions/dgs_gauss.h | 4 ++-- 19 files changed, 32 insertions(+), 28 deletions(-) diff --git a/COPYING.txt b/COPYING.txt index 975b650e91c..8ef939ee866 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -801,7 +801,7 @@ at the notice in config.guess or ltmain.sh.) The atomic_ops library contains some code that is covered by the GNU General Public License, but is not needed by, nor linked into the collector library. -It is included here only becuase the atomic_ops distribution is, for +It is included here only because the atomic_ops distribution is, for simplicity, included in its entirety. ================================================================================ diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 351bc222c05..53b2dcf12ca 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -943,7 +943,7 @@ def __cmp__(self, other): .. WARNING:: :class:`CombinatorialObject` must come **before** :class:`Element` - for this to work becuase :class:`Element` is ahead of + for this to work because :class:`Element` is ahead of :class:`CombinatorialObject` in the MRO (method resolution order):: @@ -1140,7 +1140,7 @@ def __nonzero__(self): .. WARNING:: :class:`CombinatorialObject` must come **before** :class:`Element` - for this to work becuase :class:`Element` is ahead of + for this to work because :class:`Element` is ahead of :class:`CombinatorialObject` in the MRO (method resolution order):: diff --git a/src/sage/combinat/designs/difference_family.py b/src/sage/combinat/designs/difference_family.py index c00145fec39..b77ee2931b3 100644 --- a/src/sage/combinat/designs/difference_family.py +++ b/src/sage/combinat/designs/difference_family.py @@ -472,7 +472,7 @@ def df_q_6_1(K, existence=False, check=True): def radical_difference_set(K, k, l=1, existence=False, check=True): r""" Return a difference set made of a cyclotomic coset in the finite field - ``K`` and with paramters ``k`` and ``l``. + ``K`` and with parameters ``k`` and ``l``. Most of these difference sets appear in chapter VI.18.48 of the Handbook of combinatorial designs. diff --git a/src/sage/databases/oeis.py b/src/sage/databases/oeis.py index c19e51f120c..fafdd389ab3 100644 --- a/src/sage/databases/oeis.py +++ b/src/sage/databases/oeis.py @@ -1162,7 +1162,7 @@ def _repr_(self): def __call__(self, k): r""" - Returns the element of the sequence ``self`` whith index ``k``. + Return the element of the sequence ``self`` with index ``k``. INPUT: diff --git a/src/sage/libs/symmetrica/sc.pxi b/src/sage/libs/symmetrica/sc.pxi index 75f5b4d05de..d37fbd3e5e2 100644 --- a/src/sage/libs/symmetrica/sc.pxi +++ b/src/sage/libs/symmetrica/sc.pxi @@ -50,7 +50,8 @@ def charvalue_symmetrica(irred, cls, table=None): of that character on that class or permutation. Note that the table may be NULL, in which case the value is computed, or it may be taken from a precalculated charactertable. - FIXME: add table paramter + + FIXME: add table parameter EXAMPLES:: diff --git a/src/sage/modular/arithgroup/arithgroup_perm.py b/src/sage/modular/arithgroup/arithgroup_perm.py index 2a0bc6d4025..7bffca46169 100644 --- a/src/sage/modular/arithgroup/arithgroup_perm.py +++ b/src/sage/modular/arithgroup/arithgroup_perm.py @@ -726,7 +726,7 @@ def relabel(self, inplace=True): The implementation of modular subgroup by action of generators on cosets depends on the choice of a numbering. This function provides - canonical labels in the sense that two equal subgroups whith different + canonical labels in the sense that two equal subgroups with different labels are relabeled the same way. The default implementation relabels the group itself. If you want to get a relabeled copy of your modular subgroup, put to ``False`` the option ``inplace``. @@ -740,7 +740,7 @@ def relabel(self, inplace=True): construct a canonical representative of a transitive subgroup in its conjugacy class in the full symmetric group. - 1. The identity is still numbered `0` and set the curent vertex to be + 1. The identity is still numbered `0` and set the current vertex to be the identity. 2. Number the cycle of `S3` the current vertex belongs to: if the diff --git a/src/sage/modular/btquotients/pautomorphicform.py b/src/sage/modular/btquotients/pautomorphicform.py index 418e9d0fad4..c839da89ba6 100644 --- a/src/sage/modular/btquotients/pautomorphicform.py +++ b/src/sage/modular/btquotients/pautomorphicform.py @@ -628,7 +628,7 @@ class BruhatTitsHarmonicCocycles(AmbientHeckeModule, UniqueRepresentation): def __classcall__(cls, X, k, prec=None, basis_matrix=None, base_field=None): r""" Represent a space of Gamma invariant harmonic - cocycles valued in a cofficient module. + cocycles valued in a coefficient module. INPUT: diff --git a/src/sage/modular/local_comp/local_comp.py b/src/sage/modular/local_comp/local_comp.py index 0b4e9672b56..fb7deeab53f 100644 --- a/src/sage/modular/local_comp/local_comp.py +++ b/src/sage/modular/local_comp/local_comp.py @@ -561,7 +561,9 @@ def check_tempered(self): class PrimitiveSupercuspidal(LocalComponentBase): r""" - A primitive supercuspidal representation. Except for some excpetional cases + A primitive supercuspidal representation. + + Except for some exceptional cases when `p = 2` which we do not implement here, such representations are parametrized by smooth characters of tamely ramified quadratic extensions of `\QQ_p`. diff --git a/src/sage/modular/modform/numerical.py b/src/sage/modular/modform/numerical.py index 79de2037c06..aef1901148a 100644 --- a/src/sage/modular/modform/numerical.py +++ b/src/sage/modular/modform/numerical.py @@ -206,7 +206,7 @@ def _eigenvectors(self): then they should compare as equal, causing both eigenvectors to be absent from the matrix returned. The remaining eigenvalues (ostensibly unique) are visible in the test, which should be - indepedent of which eigenvectors are returned, but it does presume + independent of which eigenvectors are returned, but it does presume an ordering of these eigenvectors for the test to succeed. This exercises a correction in :trac:`8018`. :: diff --git a/src/sage/modular/modform_hecketriangle/abstract_space.py b/src/sage/modular/modform_hecketriangle/abstract_space.py index b22ef397c30..a7065930b6d 100644 --- a/src/sage/modular/modform_hecketriangle/abstract_space.py +++ b/src/sage/modular/modform_hecketriangle/abstract_space.py @@ -666,8 +666,9 @@ def homogeneous_part(self, k, ep): def weight_parameters(self): r""" Check whether ``self`` has a valid weight and multiplier. + If not then an exception is raised. Otherwise the two weight - paramters corresponding to the weight and multiplier of ``self`` + parameters corresponding to the weight and multiplier of ``self`` are returned. The weight parameters are e.g. used to calculate dimensions diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py index a7216109411..70e7e7b864b 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py @@ -158,7 +158,7 @@ def __init__(self, parent, M, check=True, **kwargs): # results are stored/cached in the element. Moreover this avoids code duplication. # In particular this means we cannot call the method from _matrix_check(). # Instead it is called here in the __init__ method of the element - # (after the prelimenary checks). + # (after the preliminary checks). if check: if self._matrix.determinant() != 1: raise TypeError("The matrix is not an element of {}, it has determinant {} != 1.".format(parent, self._matrix.determinant())) @@ -3167,8 +3167,8 @@ def acton(self, tau): def _act_on_(self, other, self_on_left): r""" - Defines the action by linear fractional transformation of Hecke triangle group - elements on complext points (using :meth:`acton`). + Define the action by linear fractional transformation of Hecke triangle group + elements on complex points (using :meth:`acton`). For the action on matrices by conjugation :meth:`acton` has to be used explicitely (to avoid confusion/ambiguity in expressions of the form gamma1*gamma2*z). @@ -3288,7 +3288,7 @@ def slash(self, f, tau=None, k=None): try: tau = f.numerator().parent().gen() except (ValueError, TypeError, AttributeError): - raise ValueError("f={} is not a rational function or a polynomial in one variable, so tau has to be specfied explicitely!".format(f)) + raise ValueError("f={} is not a rational function or a polynomial in one variable, so tau has to be specified explicitely!".format(f)) if (tau in HyperbolicPlane()): tau = tau.to_model('UHP').coordinates() diff --git a/src/sage/modular/modform_hecketriangle/readme.py b/src/sage/modular/modform_hecketriangle/readme.py index 42c2b3dd69a..77ce69c695a 100644 --- a/src/sage/modular/modform_hecketriangle/readme.py +++ b/src/sage/modular/modform_hecketriangle/readme.py @@ -107,7 +107,7 @@ An element can be represented in several ways: - As a matrix over the base ring (default) - - As a product of the generatos ``S`` and ``T`` + - As a product of the generators ``S`` and ``T`` - As a product of basic blocks conjugated by some element EXAMPLES:: diff --git a/src/sage/modular/pollack_stevens/sigma0.py b/src/sage/modular/pollack_stevens/sigma0.py index 3ea55a15ca1..fd8bd350a05 100644 --- a/src/sage/modular/pollack_stevens/sigma0.py +++ b/src/sage/modular/pollack_stevens/sigma0.py @@ -417,7 +417,7 @@ def base_ring(self): def _coerce_map_from_(self, other): r""" - Find out wheter other coerces into self. + Find out whether ``other`` coerces into ``self``. The *only* thing that coerces canonically into `\Sigma_0` is another `\Sigma_0`. It is *very bad* if integers are allowed to coerce in, as diff --git a/src/sage/modular/pollack_stevens/space.py b/src/sage/modular/pollack_stevens/space.py index 3f519c4657d..026d3c58944 100644 --- a/src/sage/modular/pollack_stevens/space.py +++ b/src/sage/modular/pollack_stevens/space.py @@ -202,7 +202,7 @@ def __init__(self, group, coefficients, sign=0): else: self.Element = PSModularSymbolElement_dist self._sign = sign - # should distingish between Gamma0 and Gamma1... + # should distinguish between Gamma0 and Gamma1... self._source = ManinRelations(group.level()) # Register the action of 2x2 matrices on self. @@ -626,7 +626,7 @@ def _an_element_(self): .. WARNING:: - This isn't really an element of the space becuase it doesn't satisfy + This is not really an element of the space because it does not satisfy the Manin relations. EXAMPLES:: @@ -647,7 +647,7 @@ def _an_element_(self): def random_element(self, M=None): r""" - Return a random overcovergent modular symbol in this space with `M` moments + Return a random overconvergent modular symbol in this space with `M` moments INPUT: diff --git a/src/sage/monoids/automatic_semigroup.py b/src/sage/monoids/automatic_semigroup.py index f3274f7197c..4268e9f87dc 100644 --- a/src/sage/monoids/automatic_semigroup.py +++ b/src/sage/monoids/automatic_semigroup.py @@ -628,9 +628,9 @@ def __iter__(self): if self._constructed: return iter(self._elements) else: - return self._iter_concurent() + return self._iter_concurrent() - def _iter_concurent(self): + def _iter_concurrent(self): """ We need to take special care since several iterators may run concurrently. diff --git a/src/sage/plot/plot3d/implicit_plot3d.py b/src/sage/plot/plot3d/implicit_plot3d.py index da87df2d8ba..fb5d879a43b 100644 --- a/src/sage/plot/plot3d/implicit_plot3d.py +++ b/src/sage/plot/plot3d/implicit_plot3d.py @@ -137,7 +137,7 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): sage: implicit_plot3d(x^2 + y ^2 + z^2 +sin(4*x) + sin(4*y) + sin(4*z) -1, (x, -2, 2), (y, -2, 2), (z, -2, 2)) Graphics3d Object - A klein bottle:: + A Klein bottle:: sage: implicit_plot3d((x^2+y^2+z^2+2*y-1)*((x^2+y^2+z^2-2*y-1)^2-8*z^2)+16*x*z*(x^2+y^2+z^2-2*y-1), (x, -3, 3), (y, -3.1, 3.1), (z, -4, 4)) Graphics3d Object diff --git a/src/sage/rings/padics/padic_generic_element.pyx b/src/sage/rings/padics/padic_generic_element.pyx index 41417414adf..9f0d292d9ab 100644 --- a/src/sage/rings/padics/padic_generic_element.pyx +++ b/src/sage/rings/padics/padic_generic_element.pyx @@ -1027,7 +1027,7 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES: The greatest common divisor is either zero or a power of the - uniformizing paramter:: + uniformizing parameter:: sage: R = Zp(3) sage: R.zero().xgcd(R.zero()) diff --git a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx index a1f25795d47..f355dbb5ece 100644 --- a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx @@ -729,7 +729,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): """ Return this polynomial divided by its leading coefficient. - Raises ValueError if the leading cofficient is not invertible in the + Raises ValueError if the leading coefficient is not invertible in the base ring. EXAMPLES:: diff --git a/src/sage/stats/distributions/dgs_gauss.h b/src/sage/stats/distributions/dgs_gauss.h index 5e8ba3cbfa1..119efa89ebc 100644 --- a/src/sage/stats/distributions/dgs_gauss.h +++ b/src/sage/stats/distributions/dgs_gauss.h @@ -190,7 +190,7 @@ struct _dgs_disc_gauss_mp_t; typedef struct _dgs_disc_gauss_dp_t { /** - The width paramter `σ`, i.e. samples are accepted with probability + The width parameter `σ`, i.e. samples are accepted with probability proportional to `\exp(-(x-c)²/(2σ²))` */ @@ -410,7 +410,7 @@ void dgs_disc_gauss_dp_clear(dgs_disc_gauss_dp_t *self); typedef struct _dgs_disc_gauss_mp_t { /** - The width paramter `σ`, i.e. samples are accepted with probability + The width parameter `σ`, i.e. samples are accepted with probability proportional to `\exp(-(x-c)²/(2σ²))` */ From d835e10ed7a8576b38ea2a244d16f27b8d9fdc21 Mon Sep 17 00:00:00 2001 From: Kevin Lui Date: Sat, 20 Aug 2016 14:39:19 -0400 Subject: [PATCH 117/135] added abelian_variety() to ell_rational_field --- .../elliptic_curves/ell_rational_field.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 9aa16e04fc7..6d5ad309ba8 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -1079,6 +1079,33 @@ def modular_symbol_space(self, sign=1, base_ring=Q, bound=None): self.__modular_symbol_space[typ] = M return M + def abelian_variety(self, base_ring=QQ): + r""" + Return self as a modular abelian variety. + + INPUT: + + - ``base_ring`` -- (default: QQ) a ring + + OUTPUT: + + - a modular abelian variety + + EXAMPLES:: + + sage: E = EllipticCurve('11a') + sage: E.abelian_variety() + Abelian variety J0(11) of dimension 1 + sage: E.abelian_variety(base_ring=QQbar) + Abelian variety J0(11) over Algebraic Field of dimension 1 + + sage: E = EllipticCurve('33a') + sage: E.abelian_variety() + Abelian subvariety of dimension 1 of J0(33) + """ + return self.modular_symbol_space(sign=0, + base_ring=base_ring).abelian_variety() + def _modular_symbol_normalize(self, sign, use_eclib, normalize, implementation): r""" Normalize parameters for :meth:`modular_symbol`. From 05cf4e92070789e364bc13ee2c9b92903584944d Mon Sep 17 00:00:00 2001 From: Kiran Kedlaya Date: Sat, 20 Aug 2016 21:06:39 +0000 Subject: [PATCH 118/135] Correct exception raising to Py3 format --- src/sage/rings/ring.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index aaf569e3374..0479a7bfb64 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -1098,7 +1098,7 @@ cdef class Ring(ParentWithGens): ValueError: ring is not an integral domain """ if all and not self.is_integral_domain(): - raise ValueError, "ring is not an integral domain" + raise ValueError("ring is not an integral domain") if n == 2: if all: return [self(-1)] From f48fd21df5802c8c55ab337c9dc34d5699f4b14a Mon Sep 17 00:00:00 2001 From: Armin Straub Date: Sat, 20 Aug 2016 22:04:22 -0500 Subject: [PATCH 119/135] 18709: improve docstrings; make case of multiple roots more efficient --- src/sage/rings/cfinite_sequence.py | 96 +++++++++++++++++------------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/src/sage/rings/cfinite_sequence.py b/src/sage/rings/cfinite_sequence.py index 232fe16b0a8..1d6af493702 100644 --- a/src/sage/rings/cfinite_sequence.py +++ b/src/sage/rings/cfinite_sequence.py @@ -71,13 +71,15 @@ REFERENCES: -.. [GK82] Greene, Daniel H.; Knuth, Donald E. (1982), "2.1.1 Constant +.. [GK82] Daniel H. Greene and Donald E. (1982), "2.1.1 Constant coefficients - A) Homogeneous equations", Mathematics for the Analysis of Algorithms (2nd ed.), Birkhauser, p. 17. +.. [KP11] Manuel Kauers and Peter Paule. The Concrete Tetrahedron. + Springer-Verlag, 2011. .. [SZ94] Bruno Salvy and Paul Zimmermann. - Gfun: a Maple package for the manipulation of generating and holonomic functions in one variable. - Acm transactions on mathematical software, 20.2:163-177, 1994. -.. [Z11] Zeilberger, Doron. "The C-finite ansatz." The Ramanujan Journal +.. [Z11] Doron Zeilberger. "The C-finite ansatz." The Ramanujan Journal (2011): 1-10. """ @@ -766,49 +768,60 @@ def series(self, n): def closed_form(self, n = 'n'): """ - Return a symbolic expression in ``n`` that maps ``n`` to the n-th member of the sequence. + Return a symbolic expression in ``n``, which equals the n-th term of + the sequence. - It is easy to show that any C-finite sequence has a closed form of the type: + It is a well-known property of C-finite sequences ``a_n`` that they + have a closed form of the type: .. MATH:: - a_n = \sum_{i=1}^d c_i \cdot r_i^(n-s), \qquad\text{$n\ge s$, $d$ the degree of the sequence}, + a_n = \sum_{i=1}^d c_i(n) \cdot r_i^n, - with ``c_i`` constants, ``r_i`` the roots of the o.g.f. denominator, and ``s`` the offset of - the sequence (see for example :arxiv:`0704.2481`). + where ``r_i`` are the roots of the characteristic equation and + ``c_i(n)`` is a polynomial (whose degree equals the multiplicity of + ``r_i`` minus one). This is a natural generalization of Binet's + formula for Fibonacci numbers. See, for instance, [KP, Theorem 4.1]. - EXAMPLES:: + Note that if the o.g.f. has a polynomial part, that is, if the + numerator degree is not strictly less than the denominator degree, + then this closed form holds only when ``n`` exceeds the degree of that + polynomial part. In that case, the returned expression will differ + from the sequence for small ``n``. - sage: n = var('n') + EXAMPLES:: - sage: CFiniteSequence(x/(1-x)).closed_form() + sage: CFiniteSequence(1/(1-x)).closed_form() 1 - sage: CFiniteSequence(x/(1-x^2)).closed_form() - -1/2*(-1)^n + 1/2 - sage: CFiniteSequence(x/(1-x^3)).closed_form() - 1/9*sqrt(3)*(sqrt(3) + 6*sin(2/3*pi*n)) - sage: CFiniteSequence(x/(1-x^4)).closed_form() - 1/2*I*(-I)^n - 1/2*I*(-1)^(1/2*n) - 1/4*(-1)^n + 1/4 - sage: CFiniteSequence(x/(1+x^3)).closed_form() - -1/9*sqrt(3)*(sqrt(3)*cos(pi*n) + I*sqrt(3)*sin(pi*n) - 6*sin(1/3*pi*n)) - sage: CFiniteSequence(x/(1+x^4)).closed_form() - -(0.1767766952966369? - 0.1767766952966369?*I)*(0.7071067811865475? + ... + sage: CFiniteSequence(x^2/(1-x)).closed_form() + 1 + sage: CFiniteSequence(1/(1-x^2)).closed_form() + 1/2*(-1)^n + 1/2 + sage: CFiniteSequence(1/(1+x^3)).closed_form() + 1/3*(-1)^n + 1/3*(1/2*I*sqrt(3) + 1/2)^n + 1/3*(-1/2*I*sqrt(3) + 1/2)^n + sage: CFiniteSequence(1/(1-x)/(1-2*x)/(1-3*x)).closed_form() + 9/2*3^n - 4*2^n + 1/2 + + Binet's formula for the Fibonacci numbers:: + + sage: CFiniteSequence(x/(1-x-x^2)).closed_form() + 1/5*sqrt(5)*(1/2*sqrt(5) + 1/2)^n - 1/5*sqrt(5)*(-1/2*sqrt(5) + 1/2)^n + sage: [_.subs(n=k).full_simplify() for k in range(6)] + [0, 1, 1, 2, 3, 5] + + sage: CFiniteSequence((4*x+3)/(1-2*x-5*x^2)).closed_form() + 1/12*(sqrt(6) + 1)^n*(7*sqrt(6) + 18) - 1/12*(-sqrt(6) + 1)^n*(7*sqrt(6) - 18) + + Examples with multiple roots:: sage: CFiniteSequence(x*(x^2+4*x+1)/(1-x)^5).closed_form() 1/4*n^4 + 1/2*n^3 + 1/4*n^2 sage: CFiniteSequence((1+2*x-x^2)/(1-x)^4/(1+x)^2).closed_form() 1/12*n^3 - 1/8*(-1)^n*(n + 1) + 3/4*n^2 + 43/24*n + 9/8 - sage: CFiniteSequence(1/(1-x)/(1-2*x)/(1-3*x)).closed_form() - 1/2*3^(n + 2) - 2^(n + 2) + 1/2 sage: CFiniteSequence(1/(1-x)^3/(1-2*x)^4).closed_form() - 1/3*(n^3 - 3*n^2 + 20*n - 36)*2^(n + 2) + 1/2*n^2 + 19/2*n + 49 - - sage: CFiniteSequence((4*x+3)/(1-2*x-5*x^2)).closed_form() - 1/12*sqrt(6)*((-5/(sqrt(6) + 1))^n*(3*sqrt(6) - 7) + 3*sqrt(6)*(5/(sqrt(6) - 1))^n + 7*(5/(sqrt(6) - 1))^n) - sage: CFiniteSequence(x/(1-x-x^2)).closed_form() - -1/5*sqrt(5)*((-2/(sqrt(5) + 1))^n - (2/(sqrt(5) - 1))^n) - sage: all(_.subs(n==i).simplify_full()==fibonacci(i) for i in range(10)) - True + 4/3*(n^3 - 3*n^2 + 20*n - 36)*2^n + 1/2*n^2 + 19/2*n + 49 + sage: CFiniteSequence((x/(1-x-x^2))^2).closed_form() + 1/25*(5*n - sqrt(5))*(1/2*sqrt(5) + 1/2)^n + 1/25*(5*n + sqrt(5))*(-1/2*sqrt(5) + 1/2)^n """ from sage.arith.all import binomial from sage.rings.qqbar import QQbar @@ -820,28 +833,25 @@ def closed_form(self, n = 'n'): R = FractionField(PolynomialRing(QQbar, self.parent().variable_name())) ogf = R(self.ogf()) - __, parts = ogf.partial_fraction_decomposition() + __, parts = ogf.partial_fraction_decomposition(decompose_powers=False) for part in parts: denom = part.denominator().factor() denom_base, denom_exp = denom[0] - # If the partial fraction decomposition was done correctly, there - # is only one factor, of degree 1, and monic. - assert len(denom) == 1 and len(denom_base.list()) == 2 and denom_base.list()[1] == 1 - - # this part is of the form a/(x+b)^{m+1} - a = QQbar(part.numerator()) / denom.unit() + # denominator is of the form (x+b)^{m+1} m = denom_exp - 1 b = denom_base.constant_coefficient() + # check that the partial fraction decomposition was indeed done correctly + # (that is, there is only one factor, of degree 1, and monic) + assert len(denom) == 1 and len(denom_base.list()) == 2 and denom_base.list()[1] == 1 and denom.unit() == 1 - # term = a*SR(1/b)**(m+1)*SR(-1/b)**(n) - c = SR((a*(1/b)**(m+1)).radical_expression()) r = SR((-1/b).radical_expression()) - term = c * r**n - if m > 0: - term *= binomial(n+m, m) + c = SR(0) + for (k, a) in enumerate(part.numerator().list()): + a = QQbar(a) + c += binomial(n+m-k,m) * SR(((-1)**k*a*b**(k-m-1)).radical_expression()) - expr += term + expr += c.expand() * r**n return expr From b7b4f52a98112531a9e7fc13bfeedcc3756df97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 21 Aug 2016 22:30:23 +0200 Subject: [PATCH 120/135] detail --- .../modform_hecketriangle/hecke_triangle_group_element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py index 70e7e7b864b..4e7bbca2690 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py @@ -3170,7 +3170,7 @@ def _act_on_(self, other, self_on_left): Define the action by linear fractional transformation of Hecke triangle group elements on complex points (using :meth:`acton`). - For the action on matrices by conjugation :meth:`acton` has to be used explicitely + For the action on matrices by conjugation :meth:`acton` has to be used explicitly (to avoid confusion/ambiguity in expressions of the form gamma1*gamma2*z). EXAMPLES:: From 1424bbc5e3083686ecddbdbcfd4ceff2f9c824e9 Mon Sep 17 00:00:00 2001 From: Kevin Lui Date: Sun, 21 Aug 2016 17:12:16 -0400 Subject: [PATCH 121/135] added automorphisms to rational_field --- src/sage/rings/rational_field.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 2e0652794ed..13815c06c08 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -57,6 +57,7 @@ ZZ = None from sage.structure.parent_gens import ParentWithGens +from sage.structure.sequence import Sequence import sage.rings.number_field.number_field_base as number_field_base from sage.misc.fast_methods import Singleton @@ -591,6 +592,25 @@ def embeddings(self, K): raise ValueError("no embeddings of the rational field into K.") return [self.hom(K)] + def automorphisms(self): + r""" + Return all Galois automorphisms of self. + + OUTPUT: + + - a sequence containing just the identity morphism + + EXAMPLES:: + + sage: QQ.automorphisms() + [ + Ring endomorphism of Rational Field + Defn: 1 |--> 1 + ] + """ + return Sequence([self.hom(1, self)], cr=True, immutable=False, + check=False) + def places(self, all_complex=False, prec=None): r""" Return the collection of all infinite places of self, which From 2f97002d4c513605cefa8ea485c7699cdcf15f59 Mon Sep 17 00:00:00 2001 From: Kevin Lui Date: Sun, 21 Aug 2016 21:37:12 -0400 Subject: [PATCH 122/135] formatting changes to automorphims in rational_field --- src/sage/rings/rational_field.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 13815c06c08..21ca8f5344f 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -594,11 +594,11 @@ def embeddings(self, K): def automorphisms(self): r""" - Return all Galois automorphisms of self. + Return all Galois automorphisms of ``self``. OUTPUT: - - a sequence containing just the identity morphism + - a sequence containing just the identity morphism EXAMPLES:: @@ -609,7 +609,7 @@ def automorphisms(self): ] """ return Sequence([self.hom(1, self)], cr=True, immutable=False, - check=False) + check=False) def places(self, all_complex=False, prec=None): r""" From e2388b142bd34a4a0e88600207675a81cfff2d83 Mon Sep 17 00:00:00 2001 From: Kiran Kedlaya Date: Mon, 22 Aug 2016 01:58:28 +0000 Subject: [PATCH 123/135] Add traceback line to doctest --- src/sage/rings/ring.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 0479a7bfb64..2e41cc0c6ba 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -1094,6 +1094,7 @@ cdef class Ring(ParentWithGens): ... ValueError: no 3rd root of unity in Rational Field sage: IntegerModRing(8).zeta(2, all = True) + Traceback (most recent call last): ... ValueError: ring is not an integral domain """ From 92cfdb33d1d67b95ceacfbbc8c073ca8dc013c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 22 Aug 2016 10:23:06 +0200 Subject: [PATCH 124/135] removal of another bunch of useless .keys() --- src/sage/sandpiles/sandpile.py | 28 +++++++++---------- src/sage/structure/factorization.py | 6 ++-- src/sage/structure/global_options.py | 20 ++++++------- src/sage/structure/misc.pyx | 3 +- src/sage/symbolic/units.py | 2 +- .../tensor/modules/free_module_morphism.py | 2 +- src/sage/tensor/modules/free_module_tensor.py | 24 ++++++++-------- .../french_book/programmation_doctest.py | 2 +- src/sage/typeset/ascii_art.py | 5 +--- src/sage/typeset/unicode_art.py | 6 +--- 10 files changed, 45 insertions(+), 53 deletions(-) diff --git a/src/sage/sandpiles/sandpile.py b/src/sage/sandpiles/sandpile.py index 5baa98bbdfd..fedba3d149a 100644 --- a/src/sage/sandpiles/sandpile.py +++ b/src/sage/sandpiles/sandpile.py @@ -453,7 +453,7 @@ def help(verbose=True): # latter occurs, something should be changed. from sage.misc.sagedoc import detex methods = [] - for i in sorted(Sandpile.__dict__.keys()): + for i in sorted(Sandpile.__dict__): if i[0]!='_': s = eval('getdoc(Sandpile.' + i +')') period = s.find('.') @@ -2934,7 +2934,7 @@ def help(verbose=True): # latter occurs, something should be changed. from sage.misc.sagedoc import detex methods = [] - for i in sorted(SandpileConfig.__dict__.keys()): + for i in sorted(SandpileConfig.__dict__): if i[0]!='_': s = eval('getdoc(SandpileConfig.' + i +')') period = s.find('.') @@ -3057,7 +3057,7 @@ def __setitem__(self, key, item): In the example, above, changing the value of ``c`` at some vertex makes a call to setitem, which resets some of the stored variables for ``c``. """ - if key in self.keys(): + if key in self: dict.__setitem__(self,key,item) S = self._sandpile V = self._vertices @@ -3754,7 +3754,7 @@ def support(self): sage: c.support() [1, 2] """ - return [i for i in self.keys() if self[i] !=0] + return [i for i in self if self[i] !=0] def add_random(self, distrib=None): @@ -4288,7 +4288,7 @@ def help(verbose=True): # latter occurs, something should be changed. from sage.misc.sagedoc import detex methods = [] - for i in sorted(SandpileDivisor.__dict__.keys()): + for i in sorted(SandpileDivisor.__dict__): if i[0]!='_': s = eval('getdoc(SandpileDivisor.' + i +')') period = s.find('.') @@ -4408,7 +4408,7 @@ def __setitem__(self, key, item): In the example, above, changing the value of `D` at some vertex makes a call to setitem, which resets some of the stored variables for `D`. """ - if key in self.keys(): + if key in self: dict.__setitem__(self,key,item) S = self._sandpile V = self._vertices @@ -5920,7 +5920,7 @@ def support(self): sage: S.vertices() [0, 1, 2, 3] """ - return [i for i in self.keys() if self[i] !=0] + return [i for i in self if self[i] !=0] def _set_Dcomplex(self): r""" @@ -6304,7 +6304,7 @@ def sandlib(selector=None): for i in sandpiles: print(' ', i, ':', sandpiles[i]['description']) print("") - elif selector not in sandpiles.keys(): + elif selector not in sandpiles: print(selector, 'is not in the sandlib.') else: return Sandpile(sandpiles[selector]['graph'], 0) @@ -6504,7 +6504,7 @@ def aztec_sandpile(n): aztec_sandpile[(-half-i,half+j)] = {} aztec_sandpile[(half+i,-half-j)] = {} aztec_sandpile[(-half-i,-half-j)] = {} - non_sinks = aztec_sandpile.keys() + non_sinks = list(aztec_sandpile) aztec_sandpile['sink'] = {} for vert in non_sinks: weight = abs(vert[0]) + abs(vert[1]) @@ -6513,13 +6513,13 @@ def aztec_sandpile(n): if weight < n: aztec_sandpile[vert] = {(x+1,y):1, (x,y+1):1, (x-1,y):1, (x,y-1):1} else: - if (x+1,y) in aztec_sandpile.keys(): + if (x+1,y) in aztec_sandpile: aztec_sandpile[vert][(x+1,y)] = 1 - if (x,y+1) in aztec_sandpile.keys(): + if (x,y+1) in aztec_sandpile: aztec_sandpile[vert][(x,y+1)] = 1 - if (x-1,y) in aztec_sandpile.keys(): + if (x-1,y) in aztec_sandpile: aztec_sandpile[vert][(x-1,y)] = 1 - if (x,y-1) in aztec_sandpile.keys(): + if (x,y-1) in aztec_sandpile: aztec_sandpile[vert][(x,y-1)] = 1 if len(aztec_sandpile[vert]) < 4: out_degree = 4 - len(aztec_sandpile[vert]) @@ -7022,7 +7022,7 @@ def min_cycles(G, v): """ pr = G.neighbors_in(v) sp = G.shortest_paths(v) - return [sp[i] for i in pr if i in sp.keys()] + return [sp[i] for i in pr if i in sp] def wilmes_algorithm(M): r""" diff --git a/src/sage/structure/factorization.py b/src/sage/structure/factorization.py index 5caa12e4d85..0b09b4e1b6c 100644 --- a/src/sage/structure/factorization.py +++ b/src/sage/structure/factorization.py @@ -1094,7 +1094,7 @@ def __mul__(self, other): d1 = dict(self) d2 = dict(other) s = {} - for a in set(d1.keys()).union(set(d2.keys())): + for a in set(d1).union(set(d2)): s[a] = d1.get(a,0) + d2.get(a,0) return Factorization(list(s.iteritems()), unit=self.unit()*other.unit()) else: @@ -1245,7 +1245,7 @@ def gcd(self, other): d1 = dict(self) d2 = dict(other) s = {} - for a in set(d1.keys()).intersection(set(d2.keys())): + for a in set(d1).intersection(set(d2)): s[a] = min(d1[a],d2[a]) return Factorization(list(s.iteritems())) else: @@ -1287,7 +1287,7 @@ def lcm(self, other): d1 = dict(self) d2 = dict(other) s = {} - for a in set(d1.keys()).union(set(d2.keys())): + for a in set(d1).union(set(d2)): s[a] = max(d1.get(a,0),d2.get(a,0)) return Factorization(list(s.iteritems())) else: diff --git a/src/sage/structure/global_options.py b/src/sage/structure/global_options.py index bfded8e9c14..a0e4ecaee74 100644 --- a/src/sage/structure/global_options.py +++ b/src/sage/structure/global_options.py @@ -861,7 +861,7 @@ def __repr__(self): - drink: water - food: apple """ - options=self._value.keys()+self._linked_value.keys() + options = list(self._value) + list(self._linked_value) for x in self._alt_names: options.remove(x) if options == []: @@ -1081,7 +1081,7 @@ def __setstate__(self, state): unpickle = options_class.options state.pop('option_class') state.pop('options_module') - for setting in unpickle.__dict__.keys(): + for setting in unpickle.__dict__: self.__dict__[setting] = unpickle.__dict__[setting] # reset the options in `self` to their defaults @@ -1126,7 +1126,7 @@ def __getstate__(self): raise PicklingError('%s cannot be pickled because it is not associated with a class' % self) pickle={'option_class': self._option_class, 'options_module': self._options_module} - for opt in self._value.keys(): + for opt in self._value: if opt not in self._alt_names and self[opt]!=self.__default_value[opt]: pickle[opt] = self[opt] for opt in self._linked_value: @@ -1179,8 +1179,8 @@ def _add_option(self, option, specifications): self._legal_values[option] = [] for spec in sorted(specifications): # NB: options processed alphabetically! if spec == 'alias': - self._alias[option]=specifications[spec] - self._legal_values[option]+=specifications[spec].keys() + self._alias[option] = specifications[spec] + self._legal_values[option] += list(specifications[spec]) for opt in specifications[spec]: doc[opt] = 'alias for ``%s``'%specifications[spec][opt] elif spec == 'alt_name': @@ -1227,11 +1227,11 @@ def _add_option(self, option, specifications): doc[val] = specifications[spec][val] doc.update(specifications[spec]) if self._case_sensitive[option]: - self._legal_values[option] += [val for val in specifications[spec].keys()] - self._display_values[option] = {val:val for val in specifications[spec].keys()} + self._legal_values[option] += list(specifications[spec]) + self._display_values[option] = {val: val for val in specifications[spec]} else: - self._legal_values[option] += [val.lower() for val in specifications[spec].keys()] - self._display_values[option] = {val.lower():val for val in specifications[spec].keys()} + self._legal_values[option] += [val.lower() for val in specifications[spec]] + self._display_values[option] = {val.lower(): val for val in specifications[spec]} elif spec != 'description': raise ValueError('Initialization error in Global options for %s: %s not recognized!'%(self._name, spec)) @@ -1244,7 +1244,7 @@ def _add_option(self, option, specifications): if option in self._linked_value: self._doc[option]=doc else: - width = max(len(v) for v in doc.keys()) + 4 if doc!={} else 4 + width = max(len(v) for v in doc) + 4 if doc != {} else 4 if len(doc) > 0: self._doc[option]='- ``{}`` -- (default: ``{}``)\n{}\n{}\n'.format( option, self._default_value(option), diff --git a/src/sage/structure/misc.pyx b/src/sage/structure/misc.pyx index e54e52c91d2..0a4747af5dd 100644 --- a/src/sage/structure/misc.pyx +++ b/src/sage/structure/misc.pyx @@ -323,8 +323,7 @@ def dir_with_other_class(self, cls): # attributes coming from subclasses of A will be ignored ret.update(dir(self.__class__)) if hasattr(self, "__dict__"): - ret.update(self.__dict__.keys()) + ret.update(list(self.__dict__)) if not isinstance(self, cls): ret.update(dir(cls)) return sorted(ret) - diff --git a/src/sage/symbolic/units.py b/src/sage/symbolic/units.py index c3c4dfef2d2..5f027c38376 100644 --- a/src/sage/symbolic/units.py +++ b/src/sage/symbolic/units.py @@ -1129,7 +1129,7 @@ def _tab_completion(self): sage: dir(units.force) ['_Units__data', ..., 'dyne', ..., 'ton_force'] """ - return sorted([x for x in self.__data.keys() if '/' not in x]) + return sorted([x for x in self.__data if '/' not in x]) def __getattr__(self, name): """ diff --git a/src/sage/tensor/modules/free_module_morphism.py b/src/sage/tensor/modules/free_module_morphism.py index b3fadaa9a28..1046b835bec 100644 --- a/src/sage/tensor/modules/free_module_morphism.py +++ b/src/sage/tensor/modules/free_module_morphism.py @@ -1038,7 +1038,7 @@ def is_identity(self): # Some basis in which ``self`` has a representation is picked at # random and the test is performed on the images of the basis # elements: - basis = self._matrices.keys()[0][0] + basis = list(self._matrices)[0][0] for i in fmodule.irange(): if self(basis[i]) != basis[i]: return False diff --git a/src/sage/tensor/modules/free_module_tensor.py b/src/sage/tensor/modules/free_module_tensor.py index 0d7b19effcd..d0c72d3c067 100644 --- a/src/sage/tensor/modules/free_module_tensor.py +++ b/src/sage/tensor/modules/free_module_tensor.py @@ -1008,7 +1008,7 @@ class :class:`~sage.tensor.modules.comp.Components`; if such sage: f = M.basis('f') sage: t.set_comp(f)[0,1] = 4 - sage: t._components.keys() # the components w.r.t. basis e have been deleted + sage: list(t._components) # the components w.r.t. basis e have been deleted [Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer Ring] sage: t.display(f) t = 4 f_0*f^1 @@ -1021,7 +1021,7 @@ class :class:`~sage.tensor.modules.comp.Components`; if such sage: M.set_change_of_basis(e, f, a) sage: t.display(e) t = -4 e_1*e^2 - sage: t._components.keys() # random output (dictionary keys) + sage: sorted(t._components) # random output (dictionary keys) [Basis (e_0,e_1,e_2) on the Rank-3 free module M over the Integer Ring, Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer Ring] @@ -1087,7 +1087,7 @@ class :class:`~sage.tensor.modules.comp.Components`; The components w.r.t. basis e have been kept:: - sage: t._components.keys() # # random output (dictionary keys) + sage: sorted(t._components) # # random output (dictionary keys) [Basis (e_0,e_1,e_2) on the Rank-3 free module M over the Integer Ring, Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer Ring] sage: t.display(f) @@ -1124,21 +1124,21 @@ def del_other_comp(self, basis=None): sage: u = M([2,1,-5]) sage: f = M.basis('f') sage: u.add_comp(f)[:] = [0,4,2] - sage: u._components.keys() # random output (dictionary keys) + sage: sorted(u._components) # random output (dictionary keys) [Basis (e_1,e_2,e_3) on the Rank-3 free module M over the Integer Ring, Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring] sage: u.del_other_comp(f) - sage: u._components.keys() + sage: list(u._components) [Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring] Let us restore the components w.r.t. e and delete those w.r.t. f:: sage: u.add_comp(e)[:] = [2,1,-5] - sage: u._components.keys() # random output (dictionary keys) + sage: sorted(u._components) # random output (dictionary keys) [Basis (e_1,e_2,e_3) on the Rank-3 free module M over the Integer Ring, Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring] sage: u.del_other_comp() # default argument: basis = e - sage: u._components.keys() + sage: list(u._components) [Basis (e_1,e_2,e_3) on the Rank-3 free module M over the Integer Ring] """ @@ -1342,9 +1342,9 @@ def common_basis(self, other): on different bases and no connection between these bases have been set:: - sage: u._components.keys() + sage: list(u._components) [Basis (e_1,e_2,e_3) on the Rank-3 free module M over the Integer Ring] - sage: v._components.keys() + sage: list(v._components) [Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring] Linking bases ``e`` and ``f`` changes the result:: @@ -1357,7 +1357,7 @@ def common_basis(self, other): Indeed, v is now known in basis e:: - sage: v._components.keys() # random output (dictionary keys) + sage: sorted(v._components) # random output (dictionary keys) [Basis (f_1,f_2,f_3) on the Rank-3 free module M over the Integer Ring, Basis (e_1,e_2,e_3) on the Rank-3 free module M over the Integer Ring] @@ -2332,9 +2332,9 @@ def contract(self, *args): [ 7 6 -4] [ 3 -1 -2] sage: b.del_other_comp(h) # deletes components w.r.t. basis e - sage: b._components.keys() # indeed: + sage: list(b._components) # indeed: [Basis (h_0,h_1,h_2) on the Rank-3 free module M over the Integer Ring] - sage: a._components.keys() # while a is known only in basis e: + sage: list(a._components) # while a is known only in basis e: [Basis (e_0,e_1,e_2) on the Rank-3 free module M over the Integer Ring] sage: s1 = a.contract(1, b, 1) ; s1 # yet the computation is possible Type-(1,2) tensor on the Rank-3 free module M over the Integer Ring diff --git a/src/sage/tests/french_book/programmation_doctest.py b/src/sage/tests/french_book/programmation_doctest.py index de56228d7db..861e1632ae3 100644 --- a/src/sage/tests/french_book/programmation_doctest.py +++ b/src/sage/tests/french_book/programmation_doctest.py @@ -695,7 +695,7 @@ sage: D = {'a0':'b0', 'a1':'b1', 'a2':'b2', 'a3':'b0',\ ....: 'a4':'b3', 'a5':'b3'} - sage: E = Set(D.keys()) ; Imf = Set(D.values()) + sage: E = Set(D) ; Imf = Set(D.values()) sage: Imf == Set(map (lambda t:D[t], E)) # est équivalent True diff --git a/src/sage/typeset/ascii_art.py b/src/sage/typeset/ascii_art.py index 05db7103389..51a6e896166 100644 --- a/src/sage/typeset/ascii_art.py +++ b/src/sage/typeset/ascii_art.py @@ -248,13 +248,10 @@ def ascii_art(*obj, **kwds): """ separator = kwds.pop('sep', empty_ascii_art) if kwds: - raise ValueError('unknown keyword arguments: {0}'.format(kwds.keys())) + raise ValueError('unknown keyword arguments: {0}'.format(list(kwds))) if len(obj) == 1: return _ascii_art_factory.build(obj[0]) if not isinstance(separator, AsciiArt): separator = _ascii_art_factory.build(separator) obj = map(_ascii_art_factory.build, obj) return _ascii_art_factory.concatenate(obj, separator, empty_ascii_art) - - - diff --git a/src/sage/typeset/unicode_art.py b/src/sage/typeset/unicode_art.py index 29a374362fa..6ae6a125a8d 100644 --- a/src/sage/typeset/unicode_art.py +++ b/src/sage/typeset/unicode_art.py @@ -115,14 +115,10 @@ def unicode_art(*obj, **kwds): """ separator = kwds.pop('sep', empty_unicode_art) if kwds: - raise ValueError('unknown keyword arguments: {0}'.format(kwds.keys())) + raise ValueError('unknown keyword arguments: {0}'.format(list(kwds))) if len(obj) == 1: return _unicode_art_factory.build(obj[0]) if not isinstance(separator, UnicodeArt): separator = _unicode_art_factory.build(separator) obj = map(_unicode_art_factory.build, obj) return _unicode_art_factory.concatenate(obj, separator, empty_unicode_art) - - - - From e80f38b5f6d210df78f5f11bdbbf19ae5afb5717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Labb=C3=A9?= Date: Mon, 22 Aug 2016 16:12:05 +0200 Subject: [PATCH 125/135] 12364: adding doctest --- src/sage/graphs/generic_graph.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 38a860b2fc0..f9d0b7dcef4 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -17948,6 +17948,18 @@ def layout_graphviz(self, dim = 2, prog = 'dot', **options): Use the graphviz functionality of Networkx 1.0 once it will be merged into Sage. + + TESTS: + + Make sure that :trac:`12364` is fixed:: + + sage: m = WordMorphism('a->abb,b->ba') + sage: w = m.fixed_point('a') + sage: prefix = Word(list(w[:100])) + sage: pals = prefix.palindromes() + sage: poset = Poset((pals, lambda x,y: x.is_factor(y))) + sage: H = poset.hasse_diagram() + sage: d = H.layout_graphviz() # optional - dot2tex graphviz """ assert_have_dot2tex() assert dim == 2, "3D graphviz layout not implemented" From 290fea92c090dab6de9dda881524613ddcb2814b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 22 Aug 2016 20:14:07 +0200 Subject: [PATCH 126/135] implement the magnitude function of a graph --- src/sage/graphs/graph.py | 89 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 899d1b7ca1c..583344b8fec 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -6825,6 +6825,95 @@ def kirchhoff_symanzik_polynomial(self, name='t'): D = matrix.diagonal(PolynomialRing(ZZ, name, self.size()).gens()) return (circuit_mtrx.transpose() * D * circuit_mtrx).determinant() + @doc_index("Leftovers") + def magnitude_function(self): + """ + Return the magnitude function of the graph as a rational function. + + This is defined as the sum of all coefficients in the inverse + of the matrix `Z` whose coefficient `Z_{i,j}` indexed by a + pair of vertices `(i,j)` is `q^d(i,j)` where `d` is the distance + function in the graph. + + By convention, if the distance from `i` to `j` is infinite + (for two vertices not path connected) then `Z_{i,j}=0`. + + The value of the magnitude function at `q=0` is the + cardinality of the graph. The value of the magnitude function + at `q=0` is always `1`. The magnitude function of a disjoint + union is the sum of the magnitudes functions of the connected + components. + + EXAMPLES:: + + sage: g = Graph({1:[], 2:[]}) + sage: g.magnitude_function() + 2 + + sage: g = graphs.CycleGraph(4) + sage: g.magnitude_function() + 4/(q^2 + 2*q + 1) + + sage: g = graphs.CycleGraph(5) + sage: m = g.magnitude_function(); m + 5/(2*q^2 + 2*q + 1) + + One can expand the magnitude as a power series in `q` as follows:: + + sage: q = QQ[['q']].gen() + sage: m(q) + 5 - 10*q + 10*q^2 - 20*q^4 + 40*q^5 - 40*q^6 + ... + + One can use the substitution `q = exp(-t)` to obtain + the magnitude function as a function of `t`:: + + sage: g = graphs.CycleGraph(6) + sage: m = g.magnitude_function() + sage: t = var('t') + sage: m(exp(-t)) + 6/(2*e^(-t) + 2*e^(-2*t) + e^(-3*t) + 1) + + TESTS:: + + sage: g = Graph() + sage: g.magnitude_function() + 0 + + sage: g = Graph({1:[]}) + sage: g.magnitude_function() + 1 + + sage: g = graphs.PathGraph(4) + sage: g.magnitude_function() + (-2*q + 4)/(q + 1) + + REFERENCES: + + TODO + """ + from sage.matrix.constructor import matrix + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing + from sage.graphs.distances_all_pairs import distances_all_pairs + + ring = PolynomialRing(ZZ, 'q') + q = ring.gen() + N = self.order() + if not N: + return ring.zero() + dist = distances_all_pairs(self) + vertices = list(self) + Z = matrix(ring, N, N, ring.zero()) + for i in range(N): + Z[i, i] = ring.one() + for i in range(N): + for j in range(i): + dij = dist[vertices[i]][vertices[j]] + if dij in ZZ: + Z[i, j] = Z[j, i] = q ** dij + else: + Z[i, j] = Z[j, i] = ring.zero() + return sum(sum(u) for u in ~Z) + @doc_index("Leftovers") def ihara_zeta_function_inverse(self): """ From 3430f54fe5e2399872602bef8d887775c02c199f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 22 Aug 2016 20:20:37 +0200 Subject: [PATCH 127/135] trac 21308 better doc --- src/sage/graphs/graph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 583344b8fec..b95a87f595a 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -6840,9 +6840,9 @@ def magnitude_function(self): The value of the magnitude function at `q=0` is the cardinality of the graph. The value of the magnitude function - at `q=0` is always `1`. The magnitude function of a disjoint - union is the sum of the magnitudes functions of the connected - components. + at `q=1` is the number of connected components. The magnitude + function of a disjoint union is the sum of the magnitudes + functions of the connected components. EXAMPLES:: From 8138e208df862d148f83e2d5784b72b5f75111b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 22 Aug 2016 20:35:48 +0200 Subject: [PATCH 128/135] trac 21308 add one reference + more doc --- src/sage/graphs/graph.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index b95a87f595a..e89426d8827 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -6842,7 +6842,9 @@ def magnitude_function(self): cardinality of the graph. The value of the magnitude function at `q=1` is the number of connected components. The magnitude function of a disjoint union is the sum of the magnitudes - functions of the connected components. + functions of the connected components. The magnitude function + of a Cartesian product is the product of the magnitudes + functions of the factors. EXAMPLES:: @@ -6889,7 +6891,8 @@ def magnitude_function(self): REFERENCES: - TODO + .. [Lein] Tom Leinster, *The magnitude of metric spaces*. + Doc. Math. 18 (2013), 857-905. """ from sage.matrix.constructor import matrix from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing From 87f18ad6d6016375a45a2782aefd99aa4a28502f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 Aug 2016 09:05:48 +0200 Subject: [PATCH 129/135] trac 21308 better doc --- src/sage/graphs/graph.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index e89426d8827..e0f3581ec72 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -6839,12 +6839,10 @@ def magnitude_function(self): (for two vertices not path connected) then `Z_{i,j}=0`. The value of the magnitude function at `q=0` is the - cardinality of the graph. The value of the magnitude function - at `q=1` is the number of connected components. The magnitude - function of a disjoint union is the sum of the magnitudes - functions of the connected components. The magnitude function - of a Cartesian product is the product of the magnitudes - functions of the factors. + cardinality of the graph. The magnitude function of a disjoint + union is the sum of the magnitudes functions of the connected + components. The magnitude function of a Cartesian product is + the product of the magnitudes functions of the factors. EXAMPLES:: @@ -6866,7 +6864,7 @@ def magnitude_function(self): sage: m(q) 5 - 10*q + 10*q^2 - 20*q^4 + 40*q^5 - 40*q^6 + ... - One can use the substitution `q = exp(-t)` to obtain + One can also use the substitution `q = exp(-t)` to obtain the magnitude function as a function of `t`:: sage: g = graphs.CycleGraph(6) From 85cb0a96aba48edb95da0875e2b89b3ce51982b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 Aug 2016 09:59:08 +0200 Subject: [PATCH 130/135] trac 21310 get rid of itervalues in the combinat folder --- src/sage/combinat/alternating_sign_matrix.py | 9 ++++--- .../combinat/designs/difference_family.py | 4 ++- .../combinat/designs/incidence_structures.py | 6 +++-- .../combinat/designs/orthogonal_arrays.py | 4 ++- .../orthogonal_arrays_find_recursive.pyx | 4 ++- src/sage/combinat/finite_state_machine.py | 4 ++- src/sage/combinat/matrices/hadamard_matrix.py | 6 +++-- src/sage/combinat/permutation.py | 4 ++- src/sage/combinat/posets/posets.py | 6 +++-- src/sage/combinat/words/suffix_trees.py | 25 +++++++++++-------- 10 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/sage/combinat/alternating_sign_matrix.py b/src/sage/combinat/alternating_sign_matrix.py index b8ca873b1ec..96f1cd841c8 100644 --- a/src/sage/combinat/alternating_sign_matrix.py +++ b/src/sage/combinat/alternating_sign_matrix.py @@ -30,6 +30,8 @@ # python3 from __future__ import division +from six import itervalues + import itertools import copy from sage.misc.classcall_metaclass import ClasscallMetaclass @@ -1416,10 +1418,9 @@ def _lattice_initializer(self): sage: P.is_lattice() True """ - (mts, rels) = MonotoneTriangles(self._n)._lattice_initializer() - bij = dict((t, self.from_monotone_triangle(t)) for t in mts) - asms, rels = bij.itervalues(), [(bij[a], bij[b]) for (a,b) in rels] - return (asms, rels) + mts, rels = MonotoneTriangles(self._n)._lattice_initializer() + bij = {t: self.from_monotone_triangle(t) for t in mts} + return (itervalues(bij), [(bij[a], bij[b]) for (a, b) in rels]) def cover_relations(self): r""" diff --git a/src/sage/combinat/designs/difference_family.py b/src/sage/combinat/designs/difference_family.py index c00145fec39..0e8e4880d09 100644 --- a/src/sage/combinat/designs/difference_family.py +++ b/src/sage/combinat/designs/difference_family.py @@ -51,6 +51,8 @@ from __future__ import division, print_function from __future__ import absolute_import +from six import itervalues + from sage.misc.cachefunc import cached_method from sage.categories.sets_cat import EmptySetError @@ -285,7 +287,7 @@ def is_difference_family(G, D, v=None, k=None, l=None, verbose=False): where[gg].add(i) tmp_counter[gg] += 1 - if sum(tmp_counter.itervalues()) != k*(k-1): + if sum(itervalues(tmp_counter)) != k * (k - 1): if verbose: print("repeated element in the {}-th block {}".format(i,d)) return False diff --git a/src/sage/combinat/designs/incidence_structures.py b/src/sage/combinat/designs/incidence_structures.py index 66dfffbc447..14d8955022d 100644 --- a/src/sage/combinat/designs/incidence_structures.py +++ b/src/sage/combinat/designs/incidence_structures.py @@ -40,6 +40,8 @@ #*************************************************************************** from __future__ import print_function +from six import itervalues + from sage.misc.cachefunc import cached_method from sage.rings.all import ZZ @@ -879,7 +881,7 @@ def degrees(self, size=None): In a Steiner triple system, all pairs have degree 1:: sage: S13 = designs.steiner_triple_system(13) - sage: all(v == 1 for v in S13.degrees(2).itervalues()) + sage: all(v == 1 for v in S13.degrees(2).values()) True """ if size is None: @@ -1899,7 +1901,7 @@ def is_resolvable(self, certificate=False, solver=None, verbose=0, check=True): False """ if self._classes is None: - degrees = set(self.degrees().itervalues()) + degrees = set(itervalues(self.degrees())) if len(degrees) != 1: self._classes = False else: diff --git a/src/sage/combinat/designs/orthogonal_arrays.py b/src/sage/combinat/designs/orthogonal_arrays.py index 1a5a7fd41fe..395c2dd0d16 100644 --- a/src/sage/combinat/designs/orthogonal_arrays.py +++ b/src/sage/combinat/designs/orthogonal_arrays.py @@ -58,6 +58,8 @@ from __future__ import print_function from __future__ import absolute_import +from six import itervalues + from sage.misc.cachefunc import cached_function from sage.categories.sets_cat import EmptySetError from sage.misc.unknown import Unknown @@ -1705,7 +1707,7 @@ def OA_n_times_2_pow_c_from_matrix(k,c,G,A,Y,check=True): Hij = set([(Y[i] - Y[j]) * v for v in H]) for s in range(2 * G_card): g_to_col_indices[B[i][s] - B[j][s]].append(s) - for s1,s2 in g_to_col_indices.itervalues(): + for s1, s2 in itervalues(g_to_col_indices): v1 = A[i][s1][1] - A[j][s1][1] v2 = A[i][s2][1] - A[j][s2][1] diff --git a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx index 139679a70f6..4941b732d83 100644 --- a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +++ b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx @@ -46,6 +46,8 @@ Functions """ from __future__ import print_function +from six import itervalues + from sage.misc.cachefunc import cached_function from orthogonal_arrays import orthogonal_array from sage.rings.integer cimport Integer, smallInteger @@ -798,7 +800,7 @@ cpdef find_brouwer_separable_design(int k,int n): # OA(k,n+x)-OA(k,x). Useful in find_brouwer_separable_design from sage.combinat.designs.database import QDM as _QDM cdef dict ioa_indexed_by_n_minus_x = {} -for x in _QDM.itervalues(): +for x in itervalues(_QDM): for (n,_,_,u),(k,_) in x.items(): if u>1: if not n in ioa_indexed_by_n_minus_x: diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index dd229935e44..b4288516fe0 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -930,6 +930,8 @@ #***************************************************************************** from __future__ import print_function +from six import itervalues + import collections import itertools import sage @@ -6727,7 +6729,7 @@ def add_transition(self, *args, **kwargs): if is_FSMTransition(d): return self._add_fsm_transition_(d) else: - d = next(kwargs.itervalues()) + d = next(itervalues(kwargs)) if hasattr(d, 'iteritems'): args = [] kwargs = d diff --git a/src/sage/combinat/matrices/hadamard_matrix.py b/src/sage/combinat/matrices/hadamard_matrix.py index 4f0473c818a..29ed55adaf9 100644 --- a/src/sage/combinat/matrices/hadamard_matrix.py +++ b/src/sage/combinat/matrices/hadamard_matrix.py @@ -55,6 +55,8 @@ #***************************************************************************** from __future__ import print_function +from six import itervalues + from sage.rings.integer_ring import ZZ from sage.rings.integer import Integer from sage.matrix.constructor import matrix, block_matrix, block_diagonal_matrix, diagonal_matrix @@ -296,8 +298,8 @@ def is_hadamard_matrix(M, normalized=False, skew=False, verbose=False): prod = (M*M.transpose()).dict() if (len(prod) != n or - set(prod.itervalues()) != {n} or - any( (i,i) not in prod for i in range(n) )): + set(itervalues(prod)) != {n} or + any((i, i) not in prod for i in range(n))): if verbose: print("The product M*M.transpose() is not equal to nI") return False diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 07b26f5c8ab..c480c4deb20 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -228,6 +228,8 @@ #***************************************************************************** from __future__ import print_function, absolute_import +from six import itervalues + from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets @@ -5482,7 +5484,7 @@ def cardinality(self): d[i] = d.get(i, 0) + 1 c = factorial(len(lmset)) - for i in d.itervalues(): + for i in itervalues(d): if i != 1: c //= factorial(i) return ZZ(c) diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 8e687f71ea4..2329709282d 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -243,6 +243,8 @@ # python3 from __future__ import division, print_function, absolute_import +from six import itervalues + import copy from sage.misc.cachefunc import cached_method from sage.misc.lazy_attribute import lazy_attribute @@ -5921,8 +5923,8 @@ def is_slender(self): d = {} for y in self.upper_covers(x): for c in self.upper_covers(y): - d[c] = d.get(c,0) + 1 - if not all( y < 3 for y in d.itervalues() ): + d[c] = d.get(c, 0) + 1 + if not all(y < 3 for y in itervalues(d)): return False return True diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index e04d34350e8..aef63659c01 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -10,6 +10,9 @@ # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** + +from six import iteritems + from sage.structure.sage_object import SageObject from sage.graphs.digraph import DiGraph from sage.sets.set import Set @@ -204,8 +207,8 @@ def node_to_word(self, state=0): if state == 0: return Words(self._alphabet)() # We first invert the transition function - tf_inv = dict(izip(self._transition_function.itervalues(), - self._transition_function)) + tf_inv = {b: a for a, b in iteritems(self._transition_function)} + # Starting from the active state, # read labels along the unique path to the root. (u,letter) = tf_inv[state] @@ -448,7 +451,7 @@ def to_digraph(self): [0 0 0 0 0 0] """ dag = {} - for ((u,letter),v) in self._transition_function.iteritems(): + for ((u, letter), v) in iteritems(self._transition_function): dag.setdefault(u, {})[v] = letter return DiGraph(dag) @@ -752,7 +755,7 @@ def _find_transition(self, state, letter): return ((0, 0), 0) else: if state in self._transition_function: - for ((k,p),s) in self._transition_function[state].iteritems(): + for ((k,p),s) in iteritems(self._transition_function[state]): if self._letters[k-1] == letter: return ((k,p), s) return None @@ -836,7 +839,7 @@ def to_digraph(self, word_labels=False): return DiGraph(d) d = self.transition_function_dictionary() for u in d: - for (v,(i,j)) in d[u].iteritems(): + for (v, (i, j)) in iteritems(d[u]): if word_labels: d[u][v] = self._word[i:j] elif j is None: @@ -1122,7 +1125,7 @@ def edge_iterator(self): queue = [0] while queue: v=queue.pop() - for ((i,j),u) in self._transition_function[v].iteritems(): + for ((i,j),u) in iteritems(self._transition_function[v]): yield (v,u,(i-1,j)) queue.append(u) @@ -1202,7 +1205,7 @@ def number_of_factors(self,n=None): num_factors += 1 if l < n: if self._transition_function[v] != {}: - for ((i,j),u) in self._transition_function[v].iteritems(): + for ((i,j),u) in iteritems(self._transition_function[v]): if j is None: j = self.word().length() if j - i >= n - l: @@ -1255,7 +1258,7 @@ def factor_iterator(self,n=None): (v,w) = queue.pop() yield w if self._transition_function[v] != {}: - for ((i,j),u) in self._transition_function[v].iteritems(): + for ((i,j),u) in iteritems(self._transition_function[v]): if j is None: j = self.word().length() for k in range(i,j): @@ -1270,7 +1273,7 @@ def factor_iterator(self,n=None): yield w if length_w < n: if self._transition_function[v] != {}: - for ((i,j),u) in self._transition_function[v].iteritems(): + for ((i,j),u) in iteritems(self._transition_function[v]): if j is None: j = self.word().length() if j - i >= n - length_w: @@ -1333,8 +1336,8 @@ def trie_type_dict(self): """ d = {} new_node = len(self._transition_function) - for (u, dd) in self._transition_function.iteritems(): - for (sl, v) in dd.iteritems(): + for (u, dd) in iteritems(self._transition_function): + for (sl, v) in iteritems(dd): w = self._word[sl[0]-1:sl[1]] if w.length() == 1: d[u,w] = v From ef8652a8df3f0c43770c0d423fc5743153ec7de2 Mon Sep 17 00:00:00 2001 From: Kevin Lui Date: Tue, 23 Aug 2016 04:56:34 -0400 Subject: [PATCH 131/135] removed base_ring option from abelian_variety() in ell_rational_field.py --- .../schemes/elliptic_curves/ell_rational_field.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 6d5ad309ba8..659624e341f 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -1079,14 +1079,10 @@ def modular_symbol_space(self, sign=1, base_ring=Q, bound=None): self.__modular_symbol_space[typ] = M return M - def abelian_variety(self, base_ring=QQ): + def abelian_variety(self): r""" Return self as a modular abelian variety. - INPUT: - - - ``base_ring`` -- (default: QQ) a ring - OUTPUT: - a modular abelian variety @@ -1096,15 +1092,12 @@ def abelian_variety(self, base_ring=QQ): sage: E = EllipticCurve('11a') sage: E.abelian_variety() Abelian variety J0(11) of dimension 1 - sage: E.abelian_variety(base_ring=QQbar) - Abelian variety J0(11) over Algebraic Field of dimension 1 sage: E = EllipticCurve('33a') sage: E.abelian_variety() Abelian subvariety of dimension 1 of J0(33) """ - return self.modular_symbol_space(sign=0, - base_ring=base_ring).abelian_variety() + return self.modular_symbol_space(sign=0).abelian_variety() def _modular_symbol_normalize(self, sign, use_eclib, normalize, implementation): r""" From f49db4ab66d2e6c693981ef7fd5c5552a94629c2 Mon Sep 17 00:00:00 2001 From: "Johan S. R. Nielsen" Date: Wed, 24 Aug 2016 00:18:56 +0200 Subject: [PATCH 132/135] Rewrite coerce_binop. Fix a bug exposed by this in fields.py --- src/sage/categories/fields.py | 2 +- src/sage/structure/element.pyx | 260 +++++++++++++-------------------- 2 files changed, 104 insertions(+), 158 deletions(-) diff --git a/src/sage/categories/fields.py b/src/sage/categories/fields.py index 9b941563492..b8286c36e66 100644 --- a/src/sage/categories/fields.py +++ b/src/sage/categories/fields.py @@ -235,7 +235,7 @@ def _gcd_univariate_polynomial(self, f, g): x """ - ret = EuclideanDomains().ElementMethods().gcd(f,g) + ret = EuclideanDomains().element_class.gcd(f,g) c = ret.leading_coefficient() if c.is_unit(): return (1/c)*ret diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 9e8f766fea5..62042c899b6 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -154,6 +154,7 @@ from sage.misc import sageinspect from sage.misc.classcall_metaclass cimport ClasscallMetaclass from sage.misc.superseded import deprecated_function_alias from sage.arith.numerical_approx cimport digits_to_bits +from sage.misc.decorators import sage_wraps # Create a dummy attribute error, using some kind of lazy error message, # so that neither the error itself not the message need to be created @@ -3329,170 +3330,115 @@ def coercion_traceback(dump=True): return coercion_model.exception_stack() -cdef class NamedBinopMethod: - """ - A decorator to be used on binary operation methods that should operate - on elements of the same parent. If the parents of the arguments differ, - coercion is performed, then the method is re-looked up by name on the - first argument. - - In short, using the ``NamedBinopMethod`` (alias ``coerce_binop``) decorator - on a method gives it the exact same semantics of the basic arithmetic - operations like ``_add_``, ``_sub_``, etc. in that both operands are - guaranteed to have exactly the same parent. - """ - cdef _self - cdef _func - cdef _name - - def __init__(self, func, name=None, obj=None): - """ - TESTS:: - - sage: from sage.structure.element import NamedBinopMethod - sage: NamedBinopMethod(gcd)(12, 15) - 3 - """ - self._func = func - if name is None: - if isinstance(func, types.FunctionType): - name = func.__name__ - if isinstance(func, types.UnboundMethodType): - name = func.__func__.__name__ - else: - name = func.__name__ - self._name = name - self._self = obj - - def __call__(self, x, y=None, **kwds): - """ - TESTS:: - - sage: from sage.structure.element import NamedBinopMethod - sage: test_func = NamedBinopMethod(lambda x, y, **kwds: (x, y, kwds), '_add_') - sage: class test_class(Rational): - ....: def __init__(self,value): - ....: self.v = value - ....: @NamedBinopMethod - ....: def test_add(self, other, keyword='z'): - ....: return (self.v, other, keyword) - - Calls func directly if the two arguments have the same parent:: - - sage: test_func(1, 2) - (1, 2, {}) - sage: x = test_class(1) - sage: x.test_add(1/2) - (1, 1/2, 'z') - sage: x.test_add(1/2, keyword=3) - (1, 1/2, 3) - - Passes through coercion and does a method lookup if the - left operand is not the same:: - - sage: test_func(0.5, 1) - (0.500000000000000, 1.00000000000000, {}) - sage: test_func(1, 2, algorithm='fast') - (1, 2, {'algorithm': 'fast'}) - sage: test_func(1, 1/2) - 3/2 - sage: x.test_add(2) - (1, 2, 'z') - sage: x.test_add(2, keyword=3) - (1, 2, 3) - - A real example:: - - sage: R1=QQ['x,y'] - sage: R2=QQ['x,y,z'] - sage: f=R1(1) - sage: g=R1(2) - sage: h=R2(1) - sage: f.gcd(g) - 1 - sage: f.gcd(g,algorithm='modular') - 1 - sage: f.gcd(h) - 1 - sage: f.gcd(h,algorithm='modular') - 1 - sage: h.gcd(f) - 1 - sage: h.gcd(f,algorithm='modular') - 1 - """ - if y is None: - if self._self is None: - self._func(x, **kwds) - else: - x, y = self._self, x - if not have_same_parent(x, y): - old_x = x - x,y = coercion_model.canonical_coercion(x, y) - if old_x is x: - return self._func(x,y, **kwds) - else: - return getattr(x, self._name)(y, **kwds) - else: - return self._func(x,y, **kwds) - - def __get__(self, obj, objtype): - """ - Used to transform from an unbound to a bound method. - - TESTS:: - sage: from sage.structure.element import NamedBinopMethod - sage: R. = ZZ[] - sage: isinstance(x.quo_rem, NamedBinopMethod) - True - sage: x.quo_rem(x) - (1, 0) - sage: type(x).quo_rem(x,x) - (1, 0) - """ - return NamedBinopMethod(self._func, self._name, obj) - - def _sage_doc_(self): - """ - Return the docstring of the wrapped object for introspection. - - EXAMPLES:: - - sage: from sage.structure.element import NamedBinopMethod - sage: g = NamedBinopMethod(gcd) - sage: from sage.misc.sageinspect import sage_getdoc - sage: sage_getdoc(g) == sage_getdoc(gcd) - True - """ - return sageinspect._sage_getdoc_unformatted(self._func) +def coerce_binop(method): + r""" + Decorator for a binary operator method for applying coercion to the + arguments before calling the method. + + Consider a parent class in the category framework, `S`, whose element class + expose a method `binop`. If `a` and `b` are elements of `S`, then + `a.binop(b)` behaves as expected. If `a` and `b` are not elements of `S`, + but rather have a common parent `T` whose element class also exposes + `binop`, we would rather expect `a.binop(b)` to compute `aa.binop(bb)`, + where `aa = T(a)` and `bb = T(b)`. This decorator ensures that behaviour + without having to otherwise modify the implementation of `binop` on the + element class of `A`. + + Since coercion will be attempted on the arguments of the decorated method, a + `TypeError` will be thrown if there is no common parent between the + elements. An `AttributeError` or `NotImplementedError` or similar will be + thrown if there is a common parent of the arguments, but its element class + does not implement a method of the same name as the decorated method. + + EXAMPLES: + + Sparse polynomial rings uses `@coerce_binop` on `gcd`:: + + sage: S. = PolynomialRing(ZZ,sparse=True) + sage: f = x^2 + sage: g = x + sage: f.gcd(g) #indirect doctest + x + sage: T = PolynomialRing(QQ, sparse=True) + sage: h = 1/2*T(x) + sage: u = f.gcd(h); u #indirect doctest + x + sage: u.parent() == T + True - def _sage_src_(self): - """ - Return the source of the wrapped object for introspection. + Another real example:: - EXAMPLES:: + sage: R1=QQ['x,y'] + sage: R2=QQ['x,y,z'] + sage: f=R1(1) + sage: g=R1(2) + sage: h=R2(1) + sage: f.gcd(g) + 1 + sage: f.gcd(g,algorithm='modular') + 1 + sage: f.gcd(h) + 1 + sage: f.gcd(h,algorithm='modular') + 1 + sage: h.gcd(f) + 1 + sage: h.gcd(f,'modular') + 1 - sage: from sage.structure.element import NamedBinopMethod - sage: g = NamedBinopMethod(gcd) - sage: 'def gcd(' in g._sage_src_() - True - """ - return sageinspect.sage_getsource(self._func) + We demonstrate a small class using `@coerce_binop` on a method:: + + sage: from sage.structure.element import coerce_binop + sage: class MyRational(Rational): + ....: def __init__(self,value): + ....: self.v = value + ....: @coerce_binop + ....: def test_add(self, other, keyword='z'): + ....: return (self.v, other, keyword) + + Calls func directly if the two arguments have the same parent:: + + sage: x = MyRational(1) + sage: x.test_add(1/2) + (1, 1/2, 'z') + sage: x.test_add(1/2, keyword=3) + (1, 1/2, 3) + + Passes through coercion and does a method lookup if the left operand is not + the same. If the common parent's element class does not have a method of the + same name, an exception is raised:: + + sage: x.test_add(2) + (1, 2, 'z') + sage: x.test_add(2, keyword=3) + (1, 2, 3) + sage: x.test_add(CC(2)) + Traceback (most recent call last): + ... + MonkeyError - def _sage_argspec_(self): - """ - Return the argspec of the wrapped object for introspection. + TESTS: - EXAMPLES:: + Test that additional arguments given to the method does not override the + `self` argument, see #21322:: - sage: from sage.structure.element import NamedBinopMethod - sage: g = NamedBinopMethod(gcd) - sage: g._sage_argspec_() - ArgSpec(args=['a', 'b'], varargs=None, keywords='kwargs', defaults=(None,)) - """ - return sageinspect.sage_getargspec(self._func) + sage: f.gcd(g, 1) + Traceback (most recent call last): + ... + MonkeyError + """ + @sage_wraps(method) + def new_method(self, other, *args, **kwargs): + if have_same_parent(self, other): + return method(self, other, *args, **kwargs) + else: + a, b = coercion_model.canonical_coercion(self, other) + if a is self: + return method(a, b, *args, **kwargs) + else: + return getattr(a, method.__name__)(b, *args, **kwargs) + return new_method -coerce_binop = NamedBinopMethod ############################################################################### From cfb532633e7b7df58b8b4ec00c7dc1e0b99c90aa Mon Sep 17 00:00:00 2001 From: Xavier Caruso Date: Wed, 24 Aug 2016 16:49:08 +0200 Subject: [PATCH 133/135] Small fixes. All doctests pass (hopefully) --- src/sage/categories/euclidean_domains.py | 5 +++-- .../padics/polynomial_padic_capped_relative_dense.py | 3 +-- src/sage/structure/element.pyx | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/categories/euclidean_domains.py b/src/sage/categories/euclidean_domains.py index ae02bccfcbc..7dfd00825af 100644 --- a/src/sage/categories/euclidean_domains.py +++ b/src/sage/categories/euclidean_domains.py @@ -250,8 +250,9 @@ def gcd(self, other): EXAMPLES:: - sage: EuclideanDomains().ElementMethods().gcd(6,4) - 2 + sage: R. = PolynomialRing(Integers(5), sparse=True) + sage: x.gcd(x+1) # indirect doctest + 1 """ A = self B = other diff --git a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py index 3acae3b11f1..b179349d3de 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py @@ -1139,8 +1139,7 @@ def xgcd(self, right): from sage.misc.stopgap import stopgap stopgap("Extended gcd computations over p-adic fields are performed using the standard Euclidean algorithm which might produce mathematically incorrect results in some cases.", 13439) - from sage.rings.polynomial.polynomial_element_generic import Polynomial_generic_field - return Polynomial_generic_field.xgcd(self,right) + return Polynomial_generic_cdv.xgcd(self,right) #def discriminant(self): # raise NotImplementedError diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 62042c899b6..3e0b01f379d 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -3359,7 +3359,7 @@ def coerce_binop(method): sage: g = x sage: f.gcd(g) #indirect doctest x - sage: T = PolynomialRing(QQ, sparse=True) + sage: T = PolynomialRing(QQ, name='x', sparse=True) sage: h = 1/2*T(x) sage: u = f.gcd(h); u #indirect doctest x @@ -3415,7 +3415,7 @@ def coerce_binop(method): sage: x.test_add(CC(2)) Traceback (most recent call last): ... - MonkeyError + AttributeError: 'sage.rings.complex_number.ComplexNumber' object has no attribute 'test_add' TESTS: @@ -3425,7 +3425,7 @@ def coerce_binop(method): sage: f.gcd(g, 1) Traceback (most recent call last): ... - MonkeyError + TypeError: algorithm 1 not supported """ @sage_wraps(method) def new_method(self, other, *args, **kwargs): From 7344f3a7a1eaf9b9bd35f37556f7bac2614364c0 Mon Sep 17 00:00:00 2001 From: Xavier Caruso Date: Wed, 24 Aug 2016 20:19:21 +0200 Subject: [PATCH 134/135] Small change in a doctest --- src/sage/categories/euclidean_domains.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/categories/euclidean_domains.py b/src/sage/categories/euclidean_domains.py index 7dfd00825af..7631d6d93c1 100644 --- a/src/sage/categories/euclidean_domains.py +++ b/src/sage/categories/euclidean_domains.py @@ -250,9 +250,9 @@ def gcd(self, other): EXAMPLES:: - sage: R. = PolynomialRing(Integers(5), sparse=True) - sage: x.gcd(x+1) # indirect doctest - 1 + sage: R. = PolynomialRing(QQ, sparse=True) + sage: EuclideanDomains().element_class.gcd(x,x+1) + -1 """ A = self B = other From 5cd62cb4b22712140bbfb4a48a574ccd929f2d3a Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 26 Aug 2016 08:45:30 +0200 Subject: [PATCH 135/135] Updated SageMath version to 7.4.beta2 --- VERSION.txt | 2 +- build/pkgs/configure/checksums.ini | 6 +++--- build/pkgs/configure/package-version.txt | 2 +- src/bin/sage-banner | 2 +- src/bin/sage-version.sh | 4 ++-- src/sage/version.py | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 42cf16a7d71..ff73d5399b3 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -SageMath version 7.4.beta1, Release Date: 2016-08-17 +SageMath version 7.4.beta2, Release Date: 2016-08-26 diff --git a/build/pkgs/configure/checksums.ini b/build/pkgs/configure/checksums.ini index 2e8e93506b1..54ff89d1ee8 100644 --- a/build/pkgs/configure/checksums.ini +++ b/build/pkgs/configure/checksums.ini @@ -1,4 +1,4 @@ tarball=configure-VERSION.tar.gz -sha1=7bf585bca9e2ee124152b7ff7268e63bdee8d5ba -md5=71088e94c8b154037848cbf03ff823c4 -cksum=2410748983 +sha1=3d13a8f9dcaef6c048d0d21f91338b0b3d0fe125 +md5=63fc727ca070844c580b5a722d177cb1 +cksum=3010448970 diff --git a/build/pkgs/configure/package-version.txt b/build/pkgs/configure/package-version.txt index f84d24e50aa..a14f8d53343 100644 --- a/build/pkgs/configure/package-version.txt +++ b/build/pkgs/configure/package-version.txt @@ -1 +1 @@ -178 +179 diff --git a/src/bin/sage-banner b/src/bin/sage-banner index f36927bcdc6..45254525af7 100644 --- a/src/bin/sage-banner +++ b/src/bin/sage-banner @@ -1,5 +1,5 @@ ┌────────────────────────────────────────────────────────────────────┐ -│ SageMath version 7.4.beta1, Release Date: 2016-08-17 │ +│ SageMath version 7.4.beta2, Release Date: 2016-08-26 │ │ Type "notebook()" for the browser-based notebook interface. │ │ Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ diff --git a/src/bin/sage-version.sh b/src/bin/sage-version.sh index ee6ac8a9f3f..400764b856f 100644 --- a/src/bin/sage-version.sh +++ b/src/bin/sage-version.sh @@ -1,4 +1,4 @@ # Sage version information for shell scripts # This file is auto-generated by the sage-update-version script, do not edit! -SAGE_VERSION='7.4.beta1' -SAGE_RELEASE_DATE='2016-08-17' +SAGE_VERSION='7.4.beta2' +SAGE_RELEASE_DATE='2016-08-26' diff --git a/src/sage/version.py b/src/sage/version.py index 009cb992521..1b7107a2816 100644 --- a/src/sage/version.py +++ b/src/sage/version.py @@ -1,4 +1,4 @@ # Sage version information for Python scripts # This file is auto-generated by the sage-update-version script, do not edit! -version = '7.4.beta1' -date = '2016-08-17' +version = '7.4.beta2' +date = '2016-08-26'