diff --git a/src/sage/modular/arithgroup/tests.py b/src/sage/modular/arithgroup/tests.py index 5bf49898474..b0d6ba76aa3 100644 --- a/src/sage/modular/arithgroup/tests.py +++ b/src/sage/modular/arithgroup/tests.py @@ -12,6 +12,7 @@ # http://www.gnu.org/licenses/ # ################################################################################ +from __future__ import print_function from arithgroup_perm import ArithmeticSubgroup_Permutation, EvenArithmeticSubgroup_Permutation, OddArithmeticSubgroup_Permutation from sage.modular.arithgroup.all import Gamma, Gamma0, Gamma1, GammaH @@ -152,9 +153,8 @@ def _do(self, name): test_random ... """ - - print "test_%s"%name - Test.__dict__["test_%s"%name](self) + print("test_%s" % name) + Test.__dict__["test_%s" % name](self) def random(self, seconds=0): """ @@ -202,7 +202,7 @@ def test(self, name, seconds=0): s += " (will stop after about %s seconds)"%seconds t = cputime() self._do(name) - print "\ttime=%s\telapsed=%s"%(cputime(t),cputime(total)) + print("\ttime=%s\telapsed=%s" % (cputime(t), cputime(total))) n += 1 def test_random(self): @@ -217,7 +217,7 @@ def test_random(self): """ tests = [a for a in Test.__dict__.keys() if a[:5] == "test_" and a != "test_random"] name = prandom.choice(tests) - print "Doing random test %s"%name + print("Doing random test %s" % name) Test.__dict__[name](self) def test_relabel(self): @@ -264,13 +264,13 @@ def test_relabel(self): GG.relabel() for elt in ['_S2','_S3','_L','_R']: - if getattr(G,elt) != getattr(GG,elt): - print "s2 = %s" %str(s2) - print "s3 = %s" %str(s3) - print "ss2 = %s" %str(ss2) - print "ss3 = %s" %str(ss3) - print "pp = %s" %str(pp) - raise AssertionError("%s does not coincide" %elt) + if getattr(G, elt) != getattr(GG, elt): + print("s2 = %s" % str(s2)) + print("s3 = %s" % str(s3)) + print("ss2 = %s" % str(ss2)) + print("ss3 = %s" % str(ss3)) + print("pp = %s" % str(pp)) + raise AssertionError("%s does not coincide" % elt) def test_congruence_groups(self): r""" diff --git a/src/sage/modular/modform/test.py b/src/sage/modular/modform/test.py index ab93d3dfffb..c097c36e9ac 100644 --- a/src/sage/modular/modform/test.py +++ b/src/sage/modular/modform/test.py @@ -2,125 +2,124 @@ Run difficult calculations that test the modular forms functionality. -There's currently no good system for timing these doctests across -all platforms, so I'm turning these all into comments (so that they -aren't counted against are doctest coverage), noting that we should +There is currently no good system for timing these doctests across +all platforms, so I am turning these all into comments (so that they +are not counted against are doctest coverage), noting that we should use these when (if?) we one day have a good regression testing -system in place. All the functions below have just had the "def" -removed from the beginning of their declaration. --Craig Citro +system in place. + +Craig Citro + from sage.all import * m=0; t=0; tw=0 -pre(): +def pre(): global m, t, tw m = get_memory_usage() t = cputime() tw = walltime() -post(): +def post(): global m,t - print "total time: %s (wall: %.2f); memory usage diff: %sMB"%(cputime(t), - walltime(tw), get_memory_usage() - m) + print("total time: %s (wall: %.2f); memory usage diff: %sMB"%(cputime(t), + walltime(tw), get_memory_usage() - m)) -test1(): +def test1(): pre() for N in range(1,75): M = ModularForms(N,2) - print M - print M.basis() + print(M) + print(M.basis()) post() -test2(): +def test2(): pre() for N in range(1,30): M = ModularForms(Gamma1(N),2) - print M - print M.basis() + print(M) + print(M.basis()) post() -test3(): +def test3(): pre() for k in range(2,100): M = ModularForms(1,k) - print M - print M.basis() + print(M) + print(M.basis()) post() -test4(): +def test4(): pre() for N in range(1,30): M = ModularForms(N,4, prec=20) - print M - print M.basis() + print(M) + print(M.basis()) post() -test5(): +def test5(): pre() for N in range(1,50): M = ModularForms(N,2, prec=30) - print M - print M.basis() + print(M) + print(M.basis()) post() -test6(): +def test6(): pre() for N in range(225,230): M = ModularForms(N,2,prec=40) - print M - print M.basis() + print(M) + print(M.basis()) post() -test7(): +def test7(): pre() for k in range(2,30): M = ModularForms(2,k) - print M - print M.basis() + print(M) + print(M.basis()) post() -test8(): +def test8(): pre() for k in range(2,20): M = ModularForms(Gamma1(3),k) - print M - print M.basis() + print(M) + print(M.basis()) post() -test9(): +def test9(): pre() for k in range(2,11): M = ModularForms(Gamma1(8),k) M.set_precision(M.dimension()+2) - print M - print M.basis() + print(M) + print(M.basis()) post() -test10(): +def test10(): pre() for k in range(2,11): M = ModularForms(k,k) M.set_precision(M.dimension()+2) - print M - print M.basis() + print(M) + print(M.basis()) post() -test11(): +def test11(): pre() for i in range(100): M = ModularForms(randint(1,100),randint(2,6)) - print M - print M.basis() + print(M) + print(M.basis()) post() -test12(): +def test12(): S = CuspForms(23,2) - print S - print S.hecke_operator(2) - print S.hecke_operator(2).matrix() - + print(S) + print(S.hecke_operator(2)) + print(S.hecke_operator(2).matrix()) """ - diff --git a/src/sage/modular/modsym/tests.py b/src/sage/modular/modsym/tests.py index 0d2d4158aa8..a0807c20fd1 100644 --- a/src/sage/modular/modsym/tests.py +++ b/src/sage/modular/modsym/tests.py @@ -24,7 +24,7 @@ # # http://www.gnu.org/licenses/ #***************************************************************************** - +from __future__ import print_function import random @@ -105,15 +105,15 @@ def _modular_symbols_space(self): else: which = random.randrange(0,3) if which == 0: - print "gamma0" + print("gamma0") M = self._modular_symbols_space_gamma0() elif which == 1: - print "gamma1" + print("gamma1") M = self._modular_symbols_space_gamma1() else: - print "character" + print("character") M = self._modular_symbols_space_character() - print "\t",M + print("\t", M) return M def _level_weight_sign(self): @@ -129,8 +129,8 @@ def _level_weight_sign(self): """ level = random.choice(self.levels) weight = random.choice(self.weights) - sign = random.choice([-1,0,1]) - print "level = %s, weight = %s, sign = %s"%(level,weight,sign) + sign = random.choice([-1, 0, 1]) + print("level = %s, weight = %s, sign = %s" % (level, weight, sign)) return level, weight, sign def _modular_symbols_space_gamma0(self): @@ -193,8 +193,8 @@ def _do(self, name): test_random ... """ - print "test_%s"%name - Test.__dict__["test_%s"%name](self) + print("test_%s" % name) + Test.__dict__["test_%s" % name](self) ################################################################# # The tests @@ -234,7 +234,7 @@ def test(self, name, seconds=0): s += " (will stop after about %s seconds)"%seconds t = cputime() self._do(name) - print "\ttime=%s\telapsed=%s"%(cputime(t),cputime(total)) + print("\ttime=%s\telapsed=%s" % (cputime(t), cputime(total))) n += 1 def test_cs_dimension(self): @@ -330,6 +330,5 @@ def test_random(self): """ tests = [a for a in Test.__dict__.keys() if a[:5] == "test_" and a != "test_random"] name = random.choice(tests) - print "Doing random test %s"%name + print("Doing random test %s" % name) Test.__dict__[name](self) - diff --git a/src/sage/quadratic_forms/genera/genus.py b/src/sage/quadratic_forms/genera/genus.py index b9ef30a0fab..6e5042e0d04 100644 --- a/src/sage/quadratic_forms/genera/genus.py +++ b/src/sage/quadratic_forms/genera/genus.py @@ -8,6 +8,7 @@ # # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import print_function from sage.misc.all import prod from sage.arith.all import LCM @@ -743,8 +744,8 @@ def split_odd(A): B = C*A*C.transpose() even, j = is_even_matrix(B) if even: - print "B:" - print B + print("B:") + print(B) raise RuntimeError("The matrix A does not admit a non-even splitting.") return u, B @@ -844,8 +845,8 @@ def two_adic_symbol(A, val): # d0 = ZZ(A_8.determinant()) # no determinant over Z/8Z d0 = ZZ(R_8(MatrixSpace(ZZ,n)(A_8).determinant())) if d0 == 0: ## SANITY CHECK: The mod 8 determinant shouldn't be zero. - print "A:" - print A + print("A:") + print(A) assert False even, i = is_even_matrix(A_2) ## Determine whether the matrix is even or odd. if even: @@ -866,8 +867,8 @@ def two_adic_symbol(A, val): # d0 = A_8.det() # no determinant over Z/8Z d0 = ZZ(R_8(MatrixSpace(ZZ,n0,n0)(A_8).determinant())) if d0 == 0: - print "A:" - print A_new + print("A:") + print(A_new) assert False even, i = is_even_matrix(A_new) if even: diff --git a/src/sage/quadratic_forms/quadratic_form__local_density_congruence.py b/src/sage/quadratic_forms/quadratic_form__local_density_congruence.py index 540715a9fa3..f1111369d52 100644 --- a/src/sage/quadratic_forms/quadratic_form__local_density_congruence.py +++ b/src/sage/quadratic_forms/quadratic_form__local_density_congruence.py @@ -8,6 +8,7 @@ ## by a quadratic form at a prime (possibly subject to additional ## congruence conditions). ########################################################################## +from __future__ import print_function from copy import deepcopy @@ -438,7 +439,6 @@ def local_good_density_congruence(self, p, m, Zvec=None, NZvec=None): return self.local_good_density_congruence_odd(p, m, Zvec, NZvec) if (p == 2): - #print "\n Using the (p=2) Local_Good_Density_Even routine! \n" return self.local_good_density_congruence_even(m, Zvec, NZvec) raise RuntimeError("\n Error in Local_Good_Density: The 'prime' p = " + str(p) + " is < 2. \n") @@ -671,8 +671,8 @@ def local_badI_density_congruence(self, p, m, Zvec=None, NZvec=None): ## Check that the form is primitive... WHY DO WE NEED TO DO THIS?!? if (S0 == []): - print " Using Q = " + str(self) - print " and p = " + str(p) + print(" Using Q = " + str(self)) + print(" and p = " + str(p)) raise RuntimeError("Oops! The form is not primitive!") @@ -847,8 +847,8 @@ def local_badII_density_congruence(self, p, m, Zvec=None, NZvec=None): ## Check that the form is primitive... WHY IS THIS NECESSARY? if (S0 == []): - print " Using Q = " + str(self) - print " and p = " + str(p) + print(" Using Q = " + str(self)) + print(" and p = " + str(p)) raise RuntimeError("Oops! The form is not primitive!") diff --git a/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py b/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py index 62f063194e9..24134281806 100644 --- a/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py +++ b/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py @@ -10,7 +10,7 @@ ## Copyright by Jonathan Hanke 2007 ######################################################################## # python3 -from __future__ import division +from __future__ import division, print_function import copy @@ -195,7 +195,7 @@ def Pall_mass_density_at_odd_prime(self, p): p_mass = prod(jordan_mass_list) p_mass *= 2**(s-1) * p**nu - print jordan_list, MJL, jordan_mass_list, p_mass + print(jordan_list, MJL, jordan_mass_list, p_mass) ## Return the result return p_mass diff --git a/src/sage/quadratic_forms/quadratic_form__neighbors.py b/src/sage/quadratic_forms/quadratic_form__neighbors.py index f337a557704..da8a3809180 100644 --- a/src/sage/quadratic_forms/quadratic_form__neighbors.py +++ b/src/sage/quadratic_forms/quadratic_form__neighbors.py @@ -1,6 +1,8 @@ """ Neighbors """ +from __future__ import print_function + from sage.modules.free_module_element import vector from sage.rings.integer_ring import ZZ from copy import deepcopy @@ -116,7 +118,7 @@ def find_primitive_p_divisible_vector__next(self, p, v=None): ## Test that the last non-zero entry is 1 (to detect tampering). if w[nz] != 1: - print "Warning: The input vector to QuadraticForm.find_primitive_p_divisible_vector__next() is not normalized properly." + print("Warning: The input vector to QuadraticForm.find_primitive_p_divisible_vector__next() is not normalized properly.") @@ -129,8 +131,6 @@ def find_primitive_p_divisible_vector__next(self, p, v=None): while (ind < nz) and (w[ind] == p-1): ind += 1 - #print ind, nz, w - ## Increment if (ind < nz): w[ind] += 1 diff --git a/src/sage/quadratic_forms/quadratic_form__split_local_covering.py b/src/sage/quadratic_forms/quadratic_form__split_local_covering.py index 8fb637a2ca8..b37ea6fe5e5 100644 --- a/src/sage/quadratic_forms/quadratic_form__split_local_covering.py +++ b/src/sage/quadratic_forms/quadratic_form__split_local_covering.py @@ -5,6 +5,7 @@ ## Routines that look for a split local covering for a given quadratic ## ## form in 4 variables. ## ######################################################################### +from __future__ import print_function from copy import deepcopy @@ -259,8 +260,8 @@ def vectors_by_length(self, bound): ## SANITY CHECK: Roundoff Error is < 0.001 if abs(Q_val_double - Q_val) > 0.001: - print " x = ", x - print " Float = ", Q_val_double, " Long = ", Q_val + print(" x = ", x) + print(" Float = ", Q_val_double, " Long = ", Q_val) raise RuntimeError("The roundoff error is bigger than 0.001, so we should use more precision somewhere...") #print " Float = ", Q_val_double, " Long = ", Q_val, " XX " diff --git a/src/sage/quadratic_forms/quadratic_form__theta.py b/src/sage/quadratic_forms/quadratic_form__theta.py index eebbc25f086..2e8ce200948 100644 --- a/src/sage/quadratic_forms/quadratic_form__theta.py +++ b/src/sage/quadratic_forms/quadratic_form__theta.py @@ -10,6 +10,7 @@ - Gonzalo Tornaria (2010-03-23): theta series of degree 2 """ +from __future__ import print_function from copy import deepcopy @@ -63,7 +64,7 @@ def theta_series(self, Max=10, var_str='q', safe_flag=True): M = -1 if (Max not in ['mod_form']) and (not M >= 0): - print Max + print(Max) raise TypeError("Oops! Max is not an integer >= 0 or an allowed string.") if Max == 'mod_form': diff --git a/src/sage/repl/attach.py b/src/sage/repl/attach.py index c0d14130b38..a1200776943 100644 --- a/src/sage/repl/attach.py +++ b/src/sage/repl/attach.py @@ -13,7 +13,7 @@ sage: dir = tmp_dir() sage: src = os.path.join(dir, 'foobar.sage') sage: with open(src, 'w') as f: - ....: f.write('print ""\n') + ....: f.write('print("")\n') sage: attach(src) sage: os.listdir(dir) @@ -67,6 +67,7 @@ # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import print_function import os import six @@ -163,7 +164,7 @@ def load_attach_path(path=None, replace=False): ['.'] sage: t_dir = tmp_dir() sage: fullpath = os.path.join(t_dir, 'test.py') - sage: open(fullpath, 'w').write("print 37 * 3") + sage: open(fullpath, 'w').write("print(37 * 3)") sage: attach('test.py') Traceback (most recent call last): ... @@ -304,9 +305,9 @@ def attach(*files): sage: sage.repl.attach.reset() sage: t1 = tmp_filename(ext='.py') - sage: open(t1,'w').write("print 'hello world'") + sage: open(t1,'w').write("print('hello world')") sage: t2 = tmp_filename(ext='.py') - sage: open(t2,'w').write("print 'hi there xxx'") + sage: open(t2,'w').write("print('hi there xxx')") sage: attach(t1, t2) hello world hi there xxx @@ -379,7 +380,7 @@ def attached_files(): sage: sage.repl.attach.reset() sage: t = tmp_filename(ext='.py') - sage: open(t,'w').write("print 'hello world'") + sage: open(t,'w').write("print('hello world')") sage: attach(t) hello world sage: attached_files() @@ -405,7 +406,7 @@ def detach(filename): sage: sage.repl.attach.reset() sage: t = tmp_filename(ext='.py') - sage: open(t,'w').write("print 'hello world'") + sage: open(t,'w').write("print('hello world')") sage: attach(t) hello world sage: attached_files() == [t] @@ -419,7 +420,7 @@ def detach(filename): ['.'] sage: t_dir = tmp_dir() sage: fullpath = os.path.join(t_dir, 'test.py') - sage: open(fullpath, 'w').write("print 37 * 3") + sage: open(fullpath, 'w').write("print(37 * 3)") sage: load_attach_path(t_dir) sage: attach('test.py') 111 @@ -431,7 +432,7 @@ def detach(filename): sage: attach('test.py') 111 sage: fullpath = os.path.join(t_dir, 'test2.py') - sage: open(fullpath, 'w').write("print 3") + sage: open(fullpath, 'w').write("print(3)") sage: attach('test2.py') 3 sage: detach(attached_files()) @@ -473,7 +474,7 @@ def reset(): sage: sage.repl.attach.reset() sage: t = tmp_filename(ext='.py') - sage: open(t,'w').write("print 'hello world'") + sage: open(t,'w').write("print('hello world')") sage: attach(t) hello world sage: attached_files() == [t] diff --git a/src/sage/rings/contfrac.py b/src/sage/rings/contfrac.py index d29a87118ae..eeb37ada95d 100644 --- a/src/sage/rings/contfrac.py +++ b/src/sage/rings/contfrac.py @@ -38,6 +38,7 @@ - Niles Johnson (2010-08): ``random_element()`` should pass on ``*args`` and ``**kwds`` (:trac:`3893`). """ +from __future__ import print_function from sage.structure.unique_representation import UniqueRepresentation from sage.rings.ring import Field @@ -286,8 +287,8 @@ def _element_constructor_(self, data, *extra_args): if isinstance(data, FieldElement) and data.parent() is self: data = list(data) if extra_args: - print "data",data,type(data) - print "extra_args",extra_args, type(extra_args[0]) + print("data", data, type(data)) + print("extra_args", extra_args, type(extra_args[0])) data = list(extra_args[0]) if not isinstance(data, (tuple,list)): from sage.rings.rational_field import QQ diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 221f83c8054..3f9303e1c6c 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -14,6 +14,7 @@ RuntimeError: exponent must be at most 9223372036854775807 # 64-bit RuntimeError: exponent must be at most 2147483647 # 32-bit """ +from __future__ import print_function import sage.misc.prandom as random @@ -269,11 +270,12 @@ def test_random_elements(level=MAX_LEVEL, trials=1): r = random_rings(level) i = 0 for R in r: - print "survived %s tests (memory usage = %s)"%(i, get_memory_usage()) + print("survived %s tests (memory usage = %s)" % + (i, get_memory_usage())) i += 1 - print R - print R.random_element() - print "----" + print(R) + print(R.random_element()) + print("----") if i >= trials: return @@ -314,12 +316,13 @@ def test_random_arith(level=MAX_LEVEL, trials=1): """ i = 0 for x in random_rings(level): - print "survived %s tests (memory usage = %s)"%(i, get_memory_usage()) + print("survived %s tests (memory usage = %s)" % + (i, get_memory_usage())) i += 1 - print x + print(x) a = x.random_element(); b = x.random_element() - print a, b - print a*b+a-b+1 + print(a, b) + print(a*b+a-b+1) if i >= trials: return @@ -372,12 +375,12 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, threshold = randint(0, min(maxdeg1,maxdeg2)) R = PolynomialRing(base_ring, 'x') if verbose: - print "test_karatsuba_multiplication: ring={}, threshold={}".format(R, threshold) + print("test_karatsuba_multiplication: ring={}, threshold={}".format(R, threshold)) for i in range(numtests): f = R.random_element(randint(0, maxdeg1), *base_ring_random_elt_args) g = R.random_element(randint(0, maxdeg2), *base_ring_random_elt_args) if verbose: - print " ({})*({})".format(f, g) + print(" ({})*({})".format(f, g)) if ref_mul(f, g) - f._mul_karatsuba(g, threshold) != 0: raise ValueError("Multiplication failed") return diff --git a/src/sage/schemes/elliptic_curves/BSD.py b/src/sage/schemes/elliptic_curves/BSD.py index 735d4f65449..141bcc2f52b 100644 --- a/src/sage/schemes/elliptic_curves/BSD.py +++ b/src/sage/schemes/elliptic_curves/BSD.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- "Birch and Swinnerton-Dyer formulas" +from __future__ import print_function + #import ell_point #import formal_group #import ell_torsion @@ -470,7 +472,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, non_max_j_invs = [-12288000, 54000, 287496, 16581375] if BSD.curve.j_invariant() in non_max_j_invs: # is this possible for optimal curves? if verbosity > 0: - print 'CM by non maximal order: switching curves' + print('CM by non maximal order: switching curves') for E in BSD.curve.isogeny_class(): if E.j_invariant() not in non_max_j_invs: BSD.curve = E @@ -500,7 +502,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, sha2_upper_bd -= (BSD.rank - rank_lower_bd) BSD.bounds[2] = (sha2_lower_bd, sha2_upper_bd) if verbosity > 0: - print "Unable to compute the rank exactly -- used database." + print("Unable to compute the rank exactly -- used database.") if rank_lower_bd > 1: # We do not know BSD(E,p) for even a single p, since it's # an open problem to show that L^r(E,1)/(Reg*Omega) is @@ -515,7 +517,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, raise RuntimeError("Apparent contradiction: %d <= rank(sha[2]) <= %d, but ord_2(sha_an) = %d"%(sha2_lower_bd, sha2_upper_bd, BSD.sha_an.ord(2))) if BSD.bounds[2][0] == BSD.sha_an.ord(2) and BSD.sha_an.ord(2) == BSD.bounds[2][1]: if verbosity > 0: - print 'p = 2: True by 2-descent' + print('p = 2: True by 2-descent') BSD.primes = [] BSD.bounds.pop(2) BSD.proof[2] = ['2-descent'] @@ -578,7 +580,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if BSD.curve.has_cm(): if BSD.curve.analytic_rank() == 0: if verbosity > 0: - print ' p >= 5: true by Rubin' + print(' p >= 5: true by Rubin') BSD.primes.append(3) else: K = rings.QuadraticField(BSD.curve.cm_discriminant(), 'a') @@ -599,7 +601,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if p >= 5 and D_K%p != 0 and len(K.factor(p)) == 1: if BSD.curve.is_good(p): if verbosity > 2 and p in heegner_primes and heegner_index is None: - print 'ALERT: Prime p (%d) >= 5 dividing sha_an, good for E, inert in K, in heegner_primes, should not divide the actual Heegner index' + print('ALERT: Prime p (%d) >= 5 dividing sha_an, good for E, inert in K, in heegner_primes, should not divide the actual Heegner index') # Note that the following check is not entirely # exhaustive, in case there is a p not dividing # the Heegner index in heegner_primes, @@ -607,7 +609,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if p not in heegner_primes: raise RuntimeError("p = %d divides sha_an, is of good reduction for E, inert in K, and does not divide the Heegner index. This may be a counterexample to BSD, but is more likely a bug. %s"%(p,BSD.curve)) if verbosity > 0: - print 'True for p not in {%s} by Kolyvagin (via Stein & Lum -- unpublished) and Rubin.'%str(list(set(BSD.primes).union(set(kolyvagin_primes))))[1:-1] + print('True for p not in {%s} by Kolyvagin (via Stein & Lum -- unpublished) and Rubin.' % str(list(set(BSD.primes).union(set(kolyvagin_primes))))[1:-1]) BSD.proof['finite'] = copy(BSD.primes) else: # no CM # do some tricks to get to a finite set without calling bound_kolyvagin @@ -623,7 +625,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if 2 not in BSD.primes: if len(s) == 0: s = '2' else: s = '2, '+s - print 'True for p not in {' + s + '} by Kolyvagin.' + print('True for p not in {' + s + '} by Kolyvagin.') BSD.proof['finite'] = copy(BSD.primes) primes_to_remove = [] for p in BSD.primes: @@ -638,7 +640,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if BSD.rank > 0: continue if verbosity > 1: - print ' p = %d: Trying p_primary_bound'%p + print(' p = %d: Trying p_primary_bound' % p) p_bound = BSD.Sha.p_primary_bound(p) if p in BSD.proof: BSD.proof[p].append(('Stein-Wuthrich', p_bound)) @@ -646,15 +648,15 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, BSD.proof[p] = [('Stein-Wuthrich', p_bound)] if BSD.sha_an.ord(p) == 0 and p_bound == 0: if verbosity > 0: - print 'True for p=%d by Stein-Wuthrich.'%p + print('True for p=%d by Stein-Wuthrich.' % p) primes_to_remove.append(p) else: if p in BSD.bounds: BSD.bounds[p][1] = min(BSD.bounds[p][1], p_bound) else: BSD.bounds[p] = (0, p_bound) - print 'Analytic %d-rank is '%p + str(BSD.sha_an.ord(p)) + ', actual %d-rank is at most %d.'%(p, p_bound) - print ' by Stein-Wuthrich.\n' + print('Analytic %d-rank is '%p + str(BSD.sha_an.ord(p)) + ', actual %d-rank is at most %d.' % (p, p_bound)) + print(' by Stein-Wuthrich.\n') for p in primes_to_remove: BSD.primes.remove(p) kolyvagin_primes = [] @@ -673,7 +675,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if p == 2: continue if D_K%p != 0 and BSD.N%(p**2) != 0 and galrep.is_irreducible(p): if verbosity > 0: - print 'Kolyvagin\'s bound for p = %d applies by Cha.'%p + print('Kolyvagin\'s bound for p = %d applies by Cha.' % p) if p in BSD.proof: BSD.proof[p].append('Cha') else: @@ -731,7 +733,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, m_max = max([BSD.curve.tamagawa_number(q).ord(p) for q in BSD.N.prime_divisors()]) if m_max > 0: if verbosity > 0: - print 'Jetchev\'s results apply (at p = %d) with m_max ='%p, m_max + print('Jetchev\'s results apply (at p = %d) with m_max =' % p, m_max) if p in BSD.proof: BSD.proof[p].append(('Jetchev',m_max)) else: @@ -752,7 +754,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, BSD.proof[p] = [('Kolyvagin',ord_p_bound)] if BSD.sha_an.ord(p) == 0 and ord_p_bound == 0: if verbosity > 0: - print 'True for p = %d by Kolyvagin bound'%p + print('True for p = %d by Kolyvagin bound' % p) primes_to_remove.append(p) elif BSD.sha_an.ord(p) > ord_p_bound: raise RuntimeError("p = %d: ord_p_bound == %d, but sha_an.ord(p) == %d. This appears to be a counterexample to BSD, but is more likely a bug."%(p,ord_p_bound,BSD.sha_an.ord(p))) @@ -775,7 +777,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if p == 2: continue if p not in kato_primes: if verbosity > 0: - print 'Kato further implies that #Sha[%d] is trivial.'%p + print('Kato further implies that #Sha[%d] is trivial.' % p) primes_to_remove.append(p) if p in BSD.proof: BSD.proof[p].append(('Kato',0)) @@ -785,7 +787,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if galrep.is_surjective(p): bd = L_over_Omega.valuation(p) if verbosity > 1: - print 'Kato implies that ord_p(#Sha[%d]) <= %d '%(p,bd) + print('Kato implies that ord_p(#Sha[%d]) <= %d ' % (p, bd)) if p in BSD.proof: BSD.proof[p].append(('Kato',bd)) else: @@ -806,7 +808,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, if galrep.is_reducible(p): primes_to_remove.append(p) if verbosity > 0: - print 'True for p=%s by Mazur'%p + print('True for p=%s by Mazur' % p) for p in primes_to_remove: BSD.primes.remove(p) if p in BSD.proof: @@ -825,11 +827,11 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, for p in kolyvagin_primes: if p not in BSD.primes or p == 3: continue if verbosity > 0: - print ' p = %d: Trying harder for Heegner index'%p + print(' p = %d: Trying harder for Heegner index' % p) obt = 0 while p**(BSD.sha_an.ord(p)/2+1) <= M and max_height < 22: if verbosity > 2: - print ' trying max_height =', max_height + print(' trying max_height =', max_height) old_bound = M M, _, exact = BSD.curve.heegner_index_bound(D, max_height=max_height, secs_dc=secs_hi) if M == -1: @@ -840,11 +842,11 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, BSD.heegner_indexes[D] = exact M = exact if verbosity > 2: - print ' heegner index =', M + print(' heegner index =', M) else: M = max(M+[1]) if verbosity > 2: - print ' bound =', M + print(' bound =', M) if old_bound == M: obt += 1 if obt == 2: @@ -859,27 +861,27 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, upp = 2*expn BSD.bounds[p] = (low,upp) if verbosity > 0: - print ' got better bound on ord_p =', upp + print(' got better bound on ord_p =', upp) if low == upp: if upp != BSD.sha_an.ord(p): raise RuntimeError else: if verbosity > 0: - print ' proven!' + print(' proven!') BSD.primes.remove(p) break for p in kolyvagin_primes: if p not in BSD.primes or p == 3: continue for D in BSD.curve.heegner_discriminants_list(4): if D in BSD.heegner_index_upper_bound: continue - print ' discriminant', D + print(' discriminant', D) if verbosity > 0: - print 'p = %d: Trying discriminant = %d for Heegner index'%(p,D) + print('p = %d: Trying discriminant = %d for Heegner index' % (p, D)) max_height = max(10, BSD.curve.quadratic_twist(D).CPS_height_bound()) obt = 0 while True: if verbosity > 2: - print ' trying max_height =', max_height + print(' trying max_height =', max_height) old_bound = M if p**(BSD.sha_an.ord(p)/2+1) > M or max_height >= 22: break @@ -892,11 +894,11 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, BSD.heegner_indexes[D] = exact M = exact if verbosity > 2: - print ' heegner index =', M + print(' heegner index =', M) else: M = max(M+[1]) if verbosity > 2: - print ' bound =', M + print(' bound =', M) if old_bound == M: obt += 1 if obt == 2: @@ -911,20 +913,20 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, upp = 2*expn BSD.bounds[p] = (low,upp) if verbosity > 0: - print ' got better bound =', upp + print(' got better bound =', upp) if low == upp: if upp != BSD.sha_an.ord(p): raise RuntimeError else: if verbosity > 0: - print ' proven!' + print(' proven!') BSD.primes.remove(p) break # print some extra information if verbosity > 1: if len(BSD.primes) > 0: - print 'Remaining primes:' + print('Remaining primes:') for p in BSD.primes: s = 'p = ' + str(p) + ': ' if galrep.is_irreducible(p): @@ -961,7 +963,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, may_divide = False if may_divide: s += '\n may divide the Heegner index, for which only a bound was computed' - print s + print(s) if BSD.curve.has_cm(): if BSD.rank == 1: @@ -974,4 +976,3 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5, BSD.curve = BSD.curve.label() BSD.Sha = None return BSD if return_BSD else BSD.primes - diff --git a/src/sage/schemes/elliptic_curves/ell_egros.py b/src/sage/schemes/elliptic_curves/ell_egros.py index 6281d1ce0e7..d4d38822464 100644 --- a/src/sage/schemes/elliptic_curves/ell_egros.py +++ b/src/sage/schemes/elliptic_curves/ell_egros.py @@ -87,6 +87,7 @@ # # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import print_function from sage.misc.all import prod from sage.misc.all import xmrange @@ -404,16 +405,16 @@ def egros_get_j(S=[], proof=None, verbose=False): nw = 6**len(S) * 2 if verbose: - print "Finding possible j invariants for S = ",S - print "Using ", nw, " twists of base curve" + print("Finding possible j invariants for S = ", S) + print("Using ", nw, " twists of base curve") sys.stdout.flush() for ei in xmrange([6]*len(S) + [2]): w = prod([p**e for p,e in zip(reversed(SS),ei)],QQ(1)) wcount+=1 if verbose: - print "Curve #",wcount, "/",nw,":"; - print "w = ",w,"=",w.factor() + print("Curve #", wcount, "/", nw, ":") + print("w = ", w, "=", w.factor()) sys.stdout.flush() a6 = -1728*w d2 = 0 @@ -432,17 +433,17 @@ def egros_get_j(S=[], proof=None, verbose=False): try: pts = E23.S_integral_points(S,proof=proof) except RuntimeError: - pts=[] - print "Failed to find S-integral points on ",E23.ainvs() + pts = [] + print("Failed to find S-integral points on ", E23.ainvs()) if proof: if verbose: - print "--trying again with proof=False" + print("--trying again with proof=False") sys.stdout.flush() pts = E23.S_integral_points(S,proof=False) if verbose: - print "--done" + print("--done") if verbose: - print len(pts), " S-integral points: ",pts + print(len(pts), " S-integral points: ", pts) sys.stdout.flush() for P in pts: P = urst(P) @@ -453,11 +454,11 @@ def egros_get_j(S=[], proof=None, verbose=False): if is_possible_j(j,S): if not j in jlist: if verbose: - print "Adding possible j = ",j + print("Adding possible j = ", j) sys.stdout.flush() jlist += [j] else: if True: #verbose: - print "Discarding illegal j = ",j + print("Discarding illegal j = ", j) sys.stdout.flush() return sorted(jlist, key=lambda j: j.height()) diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py index d6040e17e54..7a48c410383 100644 --- a/src/sage/schemes/elliptic_curves/height.py +++ b/src/sage/schemes/elliptic_curves/height.py @@ -42,6 +42,7 @@ # # http://www.gnu.org/licenses/ ############################################################################## +from __future__ import print_function import numpy import math, bisect @@ -1574,7 +1575,6 @@ def wp(z): if abs_only: approx = abs(approx) approx += eps(err, abs_only) - # print "fk_approx", approx # refine using an estimate that's better near the pole z_bound = abs(z).upper() @@ -1715,7 +1715,7 @@ def complex_intersection_is_empty(self, Bk, v, verbose=False, use_half=True): # First try and prove a negative result (cheap). if verbose: - print "trying to prove negative result..." + print("trying to prove negative result...") intersection = None for B, n in sorted(zip(bounds, ZZ.range(1, k+1))): T = PeriodicRegion(CDF(1), CDF(tau), vals < B, full=not use_half) @@ -1732,7 +1732,7 @@ def complex_intersection_is_empty(self, Bk, v, verbose=False, use_half=True): # Now try to prove a positive result. if verbose: - print "trying to prove positive result..." + print("trying to prove positive result...") intersection = None for B, n in sorted(zip(bounds, ZZ.range(1, k+1))): @@ -1755,7 +1755,7 @@ def check_line(z): # This step here is the bottleneck. while not T.verify(check_line): if verbose: - print "bad" + print("bad") T = T.expand() if intersection is None: intersection = T @@ -1838,7 +1838,7 @@ def test_mu(self, mu, N, verbose=True): for n in ZZ.range(1, N+1): b = self.B(n, mu) if verbose: - print "B_%s(%s) = %s" % (n, mu, b) + print("B_%s(%s) = %s" % (n, mu, b)) if b < 1: return True Bk.append(b) @@ -1937,7 +1937,7 @@ def min_gr(self, tol, n_max, verbose=False): eps = 2.0 while eps > tol+1: if verbose: - print "height bound in [%s, %s]" % (mu, mu*eps) + print("height bound in [%s, %s]" % (mu, mu * eps)) eps = math.sqrt(eps) if test(mu*eps, n_max, False): mu = mu*eps diff --git a/src/sage/schemes/elliptic_curves/kraus.py b/src/sage/schemes/elliptic_curves/kraus.py index 22832b904fa..a6da60a3fa4 100644 --- a/src/sage/schemes/elliptic_curves/kraus.py +++ b/src/sage/schemes/elliptic_curves/kraus.py @@ -21,12 +21,12 @@ return such a model. The implementation of this functionality is based on work of Kraus -[Kraus] which gives a local condition for when a pair of number field +[Kraus]_ which gives a local condition for when a pair of number field elements \(c_4\), \(c_6\) belong to a Weierstrass model which is integral at a prime \(P\), together with a global version. Only primes dividing 2 or 3 are hard to deal with. In order to compute the corresponding integral model one then needs to combine together the -local transformations implicit in [Kraus] into a single global one. +local transformations implicit in [Kraus]_ into a single global one. Various utility functions relating to the testing and use of Kraus's conditions are included here. @@ -37,9 +37,9 @@ REFERENCES: -- [Kraus] Kraus, Alain, Quelques remarques a propos des invariants - \(c_4\), \(c_6\) et \(\Delta\) d'une courbe elliptique, Acta - Arith. 54 (1989), 75-80. +.. [Kraus] Kraus, Alain, Quelques remarques à propos des invariants + \(c_4\), \(c_6\) et \(\Delta\) d'une courbe elliptique, Acta + Arith. 54 (1989), 75-80. """ ############################################################################## @@ -57,6 +57,7 @@ # # http://www.gnu.org/licenses/ ############################################################################## +from __future__ import print_function from sage.all import prod from sage.rings.all import RealField, RR @@ -475,11 +476,11 @@ def test_a1a3_global(c4,c6,a1,a3, debug=False): E = c4c6_model(c4,c6).rst_transform(a1**2/12,a1/2,a3/2) if not (c4,c6) == E.c_invariants(): if debug: - print "wrong c-invariants" + print("wrong c-invariants") return False if not all([E.is_local_integral_model(P) for P in c4.parent().primes_above(2)]): if debug: - print "not integral at all primes above 2" + print("not integral at all primes above 2") return False return E diff --git a/src/sage/structure/global_options.py b/src/sage/structure/global_options.py index 5932bf38e39..fd71682649e 100644 --- a/src/sage/structure/global_options.py +++ b/src/sage/structure/global_options.py @@ -267,9 +267,9 @@ class MyClass(...): def _repr_(self): return self.global_options.dispatch(self,'_repr_','first_option') def _repr_with_bells(self): - print 'Bell!' + print('Bell!') def _repr_with_whistles(self): - print 'Whistles!' + print('Whistles!') In this example, ``first_option`` is an option of ``MyOptions`` which takes values ``bells``, ``whistles``, and so on. Note that it is necessary to make @@ -369,6 +369,7 @@ def _ge_option_b(self, other): # Distributed under the terms of the GNU General Public License (GPL) # http://www.gnu.org/licenses/ #***************************************************************************** +from __future__ import print_function from __builtin__ import str from sage.structure.sage_object import SageObject @@ -639,14 +640,16 @@ def __call__(self, *get_value, **set_value): - food: apple """ if get_value==() and set_value=={}: - print 'Current %s' % self + print('Current %s' % self) options=self._value.keys()+self._linked_value.keys() for x in self._alt_names: options.remove(x) options.sort() width=1+max(len(option) for option in options) - print '\n'.join(' - {:{}} {}'.format(option+':',width,self[option]) - for option in options) + print('\n'.join(' - {:{}} {}'.format(option + ':', + width, + self[option]) + for option in options)) # return these options if get_value!=(): diff --git a/src/sage/structure/test_factory.py b/src/sage/structure/test_factory.py index 722b957b515..be6fe49555e 100644 --- a/src/sage/structure/test_factory.py +++ b/src/sage/structure/test_factory.py @@ -16,6 +16,7 @@ # # http://www.gnu.org/licenses/ #****************************************************************************** +from __future__ import print_function from sage.structure.factory import UniqueFactory @@ -47,7 +48,7 @@ def create_object(self, version, key, **extra_args): Making object (1, 2, 4) """ - print "Making object", key + print("Making object", key) return A() test_factory = UniqueFactoryTester('sage.structure.test_factory.test_factory') diff --git a/src/sage/tests/benchmark.py b/src/sage/tests/benchmark.py index f04b507b2cb..9ace032143b 100644 --- a/src/sage/tests/benchmark.py +++ b/src/sage/tests/benchmark.py @@ -15,6 +15,7 @@ sage: import sage.tests.benchmark """ +from __future__ import print_function from sage.all import * # QQ, alarm, ModularSymbols, gp, pari, cputime, EllipticCurve import sage.libs.linbox.linbox as linbox @@ -83,10 +84,11 @@ def run(self, systems=None, timeout=60, trials=1, sort=False, optional=False): """ if sort: systems.sort() - print '\n\n\n' + str(self) + print('\n\n\n' + str(self)) #print "Timeout: %s seconds"%timeout - print ' %-12s%-12s%-12s%-12s%-12s%15s'%('System', 'min', - 'avg', 'max', 'trials', 'cpu or wall') + print(' %-12s%-12s%-12s%-12s%-12s%15s' % ('System', 'min', + 'avg', 'max', + 'trials', 'cpu or wall')) if systems is None: systems = STD_SYSTEMS if optional: @@ -112,14 +114,14 @@ def run(self, systems=None, timeout=60, trials=1, sort=False, optional=False): s += '%15fw'%t else: s += '%15fc'%t - print s + print(s) except AlarmInterrupt: - print '%-12sinterrupted (timeout: %s seconds wall time)'%( - S, timeout) + print('%-12sinterrupted (timeout: %s seconds wall time)' % + (S, timeout)) except AttributeError: pass except Exception as msg: - print msg + print(msg) bench = run