diff --git a/build/pkgs/matplotlib/make-setup-config.py b/build/pkgs/matplotlib/make-setup-config.py index 98450dec2fd..4f9acf1f04c 100644 --- a/build/pkgs/matplotlib/make-setup-config.py +++ b/build/pkgs/matplotlib/make-setup-config.py @@ -1,5 +1,4 @@ from configparser import ConfigParser -import pkgconfig import os config = ConfigParser() @@ -23,7 +22,7 @@ print("NOTE: Set SAGE_MATPLOTLIB_GUI to anything but 'no' to try to build the Matplotlib GUI.") -graphical_backend='False' +graphical_backend = 'False' if os.environ.get('SAGE_MATPLOTLIB_GUI', 'no').lower() != 'no': graphical_backend = 'auto' @@ -35,7 +34,7 @@ config.add_section('gui_support') for backend in ('gtk', 'gtkagg', 'tkagg', 'wxagg', 'macosx', 'windowing'): - config.set('gui_support', backend, graphical_backend) + config.set('gui_support', backend, graphical_backend) with open('src/mplsetup.cfg', 'w') as configfile: config.write(configfile) diff --git a/src/sage/algebras/quatalg/quaternion_algebra.py b/src/sage/algebras/quatalg/quaternion_algebra.py index 3bde7b21536..1ad378eea65 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra.py +++ b/src/sage/algebras/quatalg/quaternion_algebra.py @@ -2690,15 +2690,13 @@ def multiply_by_conjugate(self, J): R = self.quaternion_algebra() return R.ideal(basis, check=False) - def is_equivalent(I, J, B=10): + def is_equivalent(self, J, B=10) -> bool: """ - Return ``True`` if ``I`` and ``J`` are equivalent as right ideals. + Return ``True`` if ``self`` and ``J`` are equivalent as right ideals. INPUT: - - ``I`` -- a fractional quaternion ideal (self) - - - ``J`` -- a fractional quaternion ideal with same order as ``I`` + - ``J`` -- a fractional quaternion ideal with same order as ``self`` - ``B`` -- a bound to compute and compare theta series before doing the full equivalence test @@ -2718,15 +2716,16 @@ def is_equivalent(I, J, B=10): sage: R[0].is_equivalent(S) True """ - if not isinstance(I, QuaternionFractionalIdeal_rational): + # shorthand: let I be self + if not isinstance(self, QuaternionFractionalIdeal_rational): return False - if I.right_order() != J.right_order(): - raise ValueError("I and J must be right ideals") + if self.right_order() != J.right_order(): + raise ValueError("self and J must be right ideals") # Just test theta series first. If the theta series are # different, the ideals are definitely not equivalent. - if B > 0 and I.theta_series_vector(B) != J.theta_series_vector(B): + if B > 0 and self.theta_series_vector(B) != J.theta_series_vector(B): return False # The theta series are the same, so perhaps the ideals are @@ -2734,7 +2733,7 @@ def is_equivalent(I, J, B=10): # 1. Compute I * Jbar # see Prop. 1.17 in Pizer. Note that we use IJbar instead of # JbarI since we work with right ideals - IJbar = I.multiply_by_conjugate(J) + IJbar = self.multiply_by_conjugate(J) # 2. Determine if there is alpha in K such # that N(alpha) = N(I)*N(J) as explained by Pizer. diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index d322305b223..46cc279a287 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -1243,6 +1243,7 @@ def _print_latex_(self, z, m): harmonic_number = Function_harmonic_number_generalized() + class _Function_swap_harmonic(BuiltinFunction): r""" Harmonic number function with swapped arguments. For internal use only. @@ -1262,14 +1263,18 @@ class _Function_swap_harmonic(BuiltinFunction): """ def __init__(self): BuiltinFunction.__init__(self, "_swap_harmonic", nargs=2) + def _eval_(self, a, b, **kwds): - return harmonic_number(b,a,**kwds) + return harmonic_number(b, a, **kwds) + _swap_harmonic = _Function_swap_harmonic() + 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: diff --git a/src/sage/groups/abelian_gps/dual_abelian_group.py b/src/sage/groups/abelian_gps/dual_abelian_group.py index df2b51e0d57..521267cccae 100644 --- a/src/sage/groups/abelian_gps/dual_abelian_group.py +++ b/src/sage/groups/abelian_gps/dual_abelian_group.py @@ -63,11 +63,10 @@ # http://www.gnu.org/licenses/ ########################################################################### -from sage.rings.infinity import infinity from sage.structure.category_object import normalize_names from sage.structure.unique_representation import UniqueRepresentation from sage.groups.abelian_gps.dual_abelian_group_element import ( - DualAbelianGroupElement, is_DualAbelianGroupElement ) + DualAbelianGroupElement, is_DualAbelianGroupElement) from sage.misc.mrange import mrange from sage.misc.cachefunc import cached_method from sage.groups.group import AbelianGroup as AbelianGroupBase @@ -126,7 +125,7 @@ def __init__(self, G, names, base_ring): self._group = G names = normalize_names(G.ngens(), names) self._assign_names(names) - AbelianGroupBase.__init__(self) # TODO: category=CommutativeGroups() + AbelianGroupBase.__init__(self) # TODO: category=CommutativeGroups() def group(self): """ @@ -165,7 +164,7 @@ def __str__(self): sage: print(Fd) DualAbelianGroup( AbelianGroup ( 3, (5, 64, 729) ) ) """ - s = "DualAbelianGroup( AbelianGroup ( %s, %s ) )"%(self.ngens(), self.gens_orders()) + s = "DualAbelianGroup( AbelianGroup ( %s, %s ) )" % (self.ngens(), self.gens_orders()) return s def _repr_(self): @@ -188,9 +187,9 @@ def _repr_(self): eldv = G.gens_orders() gp = "" for x in eldv: - if x!=0: - gp = gp + "Z/%sZ x "%x - if x==0: + if x != 0: + gp = gp + "Z/%sZ x " % x + if x == 0: gp = gp + "Z x " gp = gp[:-2].strip() s = 'Dual of Abelian Group isomorphic to ' + gp + ' over ' + str(self.base_ring()) @@ -235,7 +234,7 @@ def random_element(self): result = self.one() for g in self.gens(): order = g.order() - result *= g**(randint(0,order)) + result *= g**(randint(0, order)) return result def gen(self, i=0): @@ -255,8 +254,8 @@ def gen(self, i=0): """ n = self.group().ngens() if i < 0 or i >= n: - raise IndexError("Argument i (= %s) must be between 0 and %s."%(i, n-1)) - x = [0]*n + raise IndexError("Argument i (= %s) must be between 0 and %s." % (i, n - 1)) + x = [0] * n if self.gens_orders()[i] != 1: x[i] = 1 return self.element_class(self, x) @@ -324,7 +323,7 @@ def invariants(self): # TODO: deprecate return self.group().gens_orders() - def __contains__(self,X): + def __contains__(self, X): """ Implements "in". diff --git a/src/sage/interfaces/ecm.py b/src/sage/interfaces/ecm.py index 171040c77a3..81ca002056f 100644 --- a/src/sage/interfaces/ecm.py +++ b/src/sage/interfaces/ecm.py @@ -46,11 +46,11 @@ # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 3 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ ############################################################################### import re -import subprocess +from subprocess import Popen, PIPE, call from sage.structure.sage_object import SageObject from sage.rings.integer_ring import ZZ @@ -216,8 +216,6 @@ def _run_ecm(self, cmd, n): sage: ecm._run_ecm(['cat'], 1234) '1234' """ - from subprocess import Popen, PIPE - # Under normal usage this program only returns ASCII; anything # else mixed is garbage and an error # So just accept latin-1 without encoding errors, and let the @@ -261,7 +259,7 @@ def interact(self): """ print("Enter numbers to run ECM on them.") print("Press control-D to exit.") - subprocess.call(self._cmd) + call(self._cmd) # Recommended settings from # http://www.mersennewiki.org/index.php/Elliptic_Curve_Method @@ -661,7 +659,7 @@ def factor(self, n, factor_digits=None, B1=2000, proof=False, **kwds): # Step 3: Call find_factor until a factorization is found n_factorization = [n] while len(n_factorization) == 1: - n_factorization = self.find_factor(n,B1=B1) + n_factorization = self.find_factor(n, B1=B1) factors.extend(n_factorization) return sorted(probable_prime_factors) diff --git a/src/sage/modules/quotient_module.py b/src/sage/modules/quotient_module.py index f7aa99210a1..10db2189997 100644 --- a/src/sage/modules/quotient_module.py +++ b/src/sage/modules/quotient_module.py @@ -19,12 +19,11 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.structure.richcmp import rich_to_bool, richcmp - from .free_module import (Module_free_ambient, FreeModule_ambient, FreeModule_ambient_field) + ############################################################################### # # Quotients of ambient free modules over a domain @@ -80,7 +79,7 @@ def __init__(self, module, sub): v = [C(self._free_cover, x.list(), coerce=False, copy=False) for x in sub.gens()] w = [C(self._free_cover, x.list(), coerce=False, copy=False) for x in module.free_relations().gens()] self._relations = self._free_cover.submodule(v + w, check=False) - else: # Otherwise module should be a free module + else: # Otherwise module should be a free module self._free_cover = module self._relations = sub @@ -448,7 +447,7 @@ def _repr_(self): sage: Q._repr_() 'Vector space quotient V/W of dimension 1 over Finite Field in a of size 3^2 where\nV: Vector space of degree 3 and dimension 2 over Finite Field in a of size 3^2\nUser basis matrix:\n[1 0 a]\n[a a 1]\nW: Vector space of degree 3 and dimension 1 over Finite Field in a of size 3^2\nBasis matrix:\n[ 1 1 a + 2]' """ - return "%s space quotient V/W of dimension %s over %s where\nV: %s\nW: %s"%( + return "%s space quotient V/W of dimension %s over %s where\nV: %s\nW: %s" % ( "Sparse vector" if self.is_sparse() else "Vector", self.dimension(), self.base_ring(), self.V(), self.W()) @@ -675,4 +674,3 @@ def relations(self): return self._sub W = relations - diff --git a/src/sage/symbolic/expression_conversions.py b/src/sage/symbolic/expression_conversions.py index c5a8240cda0..430b102ba4a 100644 --- a/src/sage/symbolic/expression_conversions.py +++ b/src/sage/symbolic/expression_conversions.py @@ -15,7 +15,9 @@ # https://www.gnu.org/licenses/ ############################################################################### -import operator as _operator +from operator import eq, ne, gt, lt, ge, le, mul, pow, neg, add, truediv +from functools import reduce + from sage.rings.rational_field import QQ from sage.symbolic.ring import SR from sage.structure.element import Expression @@ -23,7 +25,6 @@ from sage.symbolic.operators import arithmetic_operators, relation_operators, FDerivativeOperator, add_vararg, mul_vararg from sage.rings.number_field.number_field_element_quadratic import NumberFieldElement_gaussian from sage.rings.universal_cyclotomic_field import UniversalCyclotomicField -from functools import reduce class FakeExpression(): @@ -59,7 +60,7 @@ def __repr__(self): sage: FakeExpression([x, y], operator.truediv) FakeExpression([x, y], ) """ - return "FakeExpression(%r, %r)"%(self._operands, self._operator) + return "FakeExpression(%r, %r)" % (self._operands, self._operator) def pyobject(self): """ @@ -200,7 +201,7 @@ def __call__(self, ex=None): return self.symbol(ex) if operator in arithmetic_operators: - if getattr(self, 'use_fake_div', False) and (operator is _operator.mul or operator is mul_vararg): + if getattr(self, 'use_fake_div', False) and (operator is mul or operator is mul_vararg): div = self.get_fake_div(ex) return self.arithmetic(div, div.operator()) return self.arithmetic(ex, operator) @@ -238,7 +239,7 @@ def get_fake_div(self, ex): for arg in ex.operands(): ops = arg.operands() try: - if arg.operator() is _operator.pow and repr(ops[1]) == '-1': + if arg.operator() is pow and repr(ops[1]) == '-1': d.append(ops[0]) else: n.append(arg) @@ -250,22 +251,22 @@ def get_fake_div(self, ex): repr_n = [repr(_) for _ in n] if len(n) == 2 and "-1" in repr_n: a = n[0] if repr_n[1] == "-1" else n[1] - return FakeExpression([a], _operator.neg) + return FakeExpression([a], neg) else: return ex elif len_d == 1: d = d[0] else: - d = FakeExpression(d, _operator.mul) + d = FakeExpression(d, mul) if len(n) == 0: - return FakeExpression([SR.one(), d], _operator.truediv) + return FakeExpression([SR.one(), d], truediv) elif len(n) == 1: n = n[0] else: - n = FakeExpression(n, _operator.mul) + n = FakeExpression(n, mul) - return FakeExpression([n,d], _operator.truediv) + return FakeExpression([n, d], truediv) def pyobject(self, ex, obj): """ @@ -379,6 +380,7 @@ def composition(self, ex, operator): """ raise NotImplementedError("composition") + class InterfaceInit(Converter): def __init__(self, interface): """ @@ -395,7 +397,7 @@ def __init__(self, interface): '(%pi)+(exp((_SAGE_VAR_x)^(2)))+(2)' """ - self.name_init = "_%s_init_"%interface.name() + self.name_init = "_%s_init_" % interface.name() self.interface = interface self.relation_symbols = interface._relation_symbols() @@ -417,12 +419,11 @@ def symbol(self, ex): sage: g.symbol(x) 'sageVARx' """ - if self.interface.name()=='maxima': - return '_SAGE_VAR_'+repr(SR(ex)) - elif self.interface.name() == 'giac': + if self.interface.name() == 'maxima': + return '_SAGE_VAR_' + repr(SR(ex)) + if self.interface.name() == 'giac': return 'sageVAR' + repr(SR(ex)) - else: - return repr(SR(ex)) + return repr(SR(ex)) def pyobject(self, ex, obj): """ @@ -440,7 +441,7 @@ def pyobject(self, ex, obj): sage: ii.pyobject(pi, pi.pyobject()) 'Pi' """ - if (self.interface.name() in ['pari','gp'] and + if (self.interface.name() in ['pari', 'gp'] and isinstance(obj, NumberFieldElement_gaussian)): return repr(obj) try: @@ -460,8 +461,8 @@ def relation(self, ex, operator): sage: m.relation(x==3, operator.lt) '_SAGE_VAR_x < 3' """ - return "%s %s %s"%(self(ex.lhs()), self.relation_symbols[operator], - self(ex.rhs())) + return "%s %s %s" % (self(ex.lhs()), self.relation_symbols[operator], + self(ex.rhs())) def tuple(self, ex): """ @@ -575,8 +576,8 @@ def derivative(self, ex, operator): sage: (gamma_inc(x,x+1).diff(x)).simplify() -(x + 1)^(x - 1)*e^(-x - 1) + D[0](gamma)(x, x + 1) """ - #This code should probably be moved into the interface - #object in a nice way. + # This code should probably be moved into the interface + # object in a nice way. from sage.symbolic.ring import is_SymbolicVariable if self.name_init != "_maxima_init_": raise NotImplementedError @@ -591,20 +592,22 @@ def derivative(self, ex, operator): # trac #12796. Note that we cannot use SR.temp_var here # since two conversions of the same expression have to be # equal. - temp_args = [SR.symbol("_symbol%s"%i) for i in range(len(args))] + temp_args = [SR.symbol("_symbol%s" % i) for i in range(len(args))] f = operator.function()(*temp_args) params = operator.parameter_set() - params = ["%s, %s"%(temp_args[i]._maxima_init_(), params.count(i)) for i in set(params)] - subs = ["%s = %s"%(t._maxima_init_(),a._maxima_init_()) for t,a in zip(temp_args,args)] - outstr = "at(diff(%s, %s), [%s])"%(f._maxima_init_(), - ", ".join(params), - ", ".join(subs)) + params = ["%s, %s" % (temp_args[i]._maxima_init_(), params.count(i)) for i in set(params)] + subs = ["%s = %s" % (t._maxima_init_(), a._maxima_init_()) + for t, a in zip(temp_args, args)] + outstr = "at(diff(%s, %s), [%s])" % (f._maxima_init_(), + ", ".join(params), + ", ".join(subs)) else: f = operator.function()(*args) params = operator.parameter_set() - params = ["%s, %s"%(args[i]._maxima_init_(), params.count(i)) for i in set(params)] - outstr = "diff(%s, %s)"%(f._maxima_init_(), - ", ".join(params)) + params = ["%s, %s" % (args[i]._maxima_init_(), params.count(i)) + for i in set(params)] + outstr = "diff(%s, %s)" % (f._maxima_init_(), + ", ".join(params)) return outstr def arithmetic(self, ex, operator): @@ -617,7 +620,7 @@ def arithmetic(self, ex, operator): sage: m.arithmetic(x+2, sage.symbolic.operators.add_vararg) '(_SAGE_VAR_x)+(2)' """ - args = ["(%s)"%self(op) for op in ex.operands()] + args = ["(%s)" % self(op) for op in ex.operands()] return arithmetic_operators[operator].join(args) def composition(self, ex, operator): @@ -636,7 +639,7 @@ def composition(self, ex, operator): 'Sin[x]' """ ops = ex.operands() - #FIXME: consider stripping pyobjects() in ops + # FIXME: consider stripping pyobjects() in ops if hasattr(operator, self.name_init + "evaled_"): return getattr(operator, self.name_init + "evaled_")(*ops) else: @@ -646,7 +649,8 @@ def composition(self, ex, operator): except (TypeError, AttributeError): op = repr(operator) - return self.interface._function_call_string(op,ops,[]) + return self.interface._function_call_string(op, ops, []) + ######### # Sympy # @@ -780,9 +784,8 @@ def relation(self, ex, op): sage: s.relation(x > 0, operator.gt) x > 0 """ - from operator import eq, ne, gt, lt, ge, le from sympy import Eq, Ne, Gt, Lt, Ge, Le - ops = {eq : Eq, ne : Ne, gt : Gt, lt : Lt, ge : Ge, le : Le} + ops = {eq: Eq, ne: Ne, gt: Gt, lt: Lt, ge: Ge, le: Le} return ops.get(op)(self(ex.lhs()), self(ex.rhs()), evaluate=False) def composition(self, ex, operator): @@ -940,6 +943,7 @@ def derivative(self, ex, operator): sympy_converter = SympyConverter() + ########## # FriCAS # ########## @@ -1096,7 +1100,7 @@ def derivative(self, ex, operator): """ from sage.symbolic.ring import is_SymbolicVariable - args = ex.operands() # the arguments the derivative is evaluated at + args = ex.operands() # the arguments the derivative is evaluated at params = operator.parameter_set() params_set = set(params) mult = ",".join(str(params.count(i)) for i in params_set) @@ -1123,8 +1127,10 @@ def derivative(self, ex, operator): return outstr + fricas_converter = FriCASConverter() + ############# # Algebraic # ############# @@ -1199,7 +1205,7 @@ def arithmetic(self, ex, operator): # can change the value of a radical expression (by changing which # root is selected). try: - if operator is _operator.pow: + if operator is pow: from sage.rings.all import Rational base, expt = ex.operands() base = self.field(base) @@ -1207,20 +1213,20 @@ def arithmetic(self, ex, operator): return self.field(base**expt) else: if operator is add_vararg: - operator = _operator.add + operator = add elif operator is mul_vararg: - operator = _operator.mul + operator = mul return reduce(operator, map(self, ex.operands())) except TypeError: pass - if operator is _operator.pow: + if operator is pow: from sage.symbolic.constants import e, pi, I base, expt = ex.operands() - if base == e and expt / (pi*I) in QQ: + if base == e and expt / (pi * I) in QQ: return exp(expt)._algebraic_(self.field) - raise TypeError("unable to convert %r to %s"%(ex, self.field)) + raise TypeError("unable to convert %r to %s" % (ex, self.field)) def composition(self, ex, operator): """ @@ -1291,17 +1297,17 @@ def composition(self, ex, operator): if func_name == 'exp': if operand.is_trivial_zero(): return self.field.one() - if not (SR(-1).sqrt()*operand).is_real(): + if not (SR(-1).sqrt() * operand).is_real(): raise ValueError("unable to represent as an algebraic number") # Coerce (not convert, see #22571) arg to a rational arg = operand.imag()/(2*ex.parent().pi()) try: rat_arg = QQ.coerce(arg.pyobject()) except TypeError: - raise TypeError("unable to convert %r to %s"%(ex, self.field)) + raise TypeError("unable to convert %r to %s" % (ex, self.field)) res = zeta(rat_arg.denom())**rat_arg.numer() elif func_name in ['sin', 'cos', 'tan']: - exp_ia = exp(SR(-1).sqrt()*operand, hold=hold)._algebraic_(QQbar) + exp_ia = exp(SR(-1).sqrt() * operand, hold=hold)._algebraic_(QQbar) if func_name == 'sin': res = (exp_ia - ~exp_ia) / (2 * zeta(4)) elif func_name == 'cos': @@ -1322,13 +1328,14 @@ def composition(self, ex, operator): res = ~self.reciprocal_trig_functions[func_name](operand)._algebraic_(QQbar) else: res = func(operand._algebraic_(self.field)) - #We have to handle the case where we get the same symbolic - #expression back. For example, QQbar(zeta(7)). See - #ticket #12665. + # We have to handle the case where we get the same symbolic + # expression back. For example, QQbar(zeta(7)). See + # ticket #12665. if (res - ex).is_trivial_zero(): - raise TypeError("unable to convert %r to %s"%(ex, self.field)) + raise TypeError("unable to convert %r to %s" % (ex, self.field)) return self.field(res) + def algebraic(ex, field): """ Returns the symbolic expression *ex* as a element of the algebraic @@ -1372,6 +1379,7 @@ def algebraic(ex, field): """ return AlgebraicConverter(field)(ex) + ############## # Polynomial # ############## @@ -1424,7 +1432,7 @@ def __init__(self, ex, base_ring=None, ring=None): self.varnames = ring.variable_names_recursive() for v in ex.variables(): if repr(v) not in self.varnames and v not in base_ring: - raise TypeError("%s is not a variable of %s" %(v, ring)) + raise TypeError("%s is not a variable of %s" % (v, ring)) self.ring = ring self.base_ring = base_ring elif base_ring is not None: @@ -1456,10 +1464,10 @@ def symbol(self, ex): y """ try: - #The symbol is one of the polynomial generators + # The symbol is one of the polynomial generators return self.ring(repr(ex)) except TypeError: - #The symbol should go into the base ring + # The symbol should go into the base ring return self.base_ring(repr(ex)) def pyobject(self, ex, obj): @@ -1541,17 +1549,18 @@ def arithmetic(self, ex, operator): """ if not any(repr(v) in self.varnames for v in ex.variables()): return self.base_ring(ex) - elif operator == _operator.pow: + elif operator == pow: from sage.rings.integer import Integer base, exp = ex.operands() return self(base)**Integer(exp) if operator == add_vararg: - operator = _operator.add + operator = add elif operator == mul_vararg: - operator = _operator.mul + operator = mul ops = [self(a) for a in ex.operands()] return reduce(operator, ops) + def polynomial(ex, base_ring=None, ring=None): """ Return a polynomial from the symbolic expression ``ex``. @@ -1739,7 +1748,7 @@ def relation(self, ex, operator): ... NotImplementedError """ - if operator is not _operator.eq: + if operator is not eq: raise NotImplementedError return self(ex.lhs() - ex.rhs()) @@ -1777,23 +1786,23 @@ def arithmetic(self, ex, operator): # exponent before the exponent gets (potentially) converted # to another type. operands = ex.operands() - if operator is _operator.pow: + if operator is pow: exponent = operands[1] if exponent == -1: - return self.etb.call(_operator.truediv, 1, operands[0]) + return self.etb.call(truediv, 1, operands[0]) elif exponent == 0.5: from sage.misc.functional import sqrt return self.etb.call(sqrt, operands[0]) elif exponent == -0.5: from sage.misc.functional import sqrt - return self.etb.call(_operator.truediv, 1, self.etb.call(sqrt, operands[0])) - elif operator is _operator.neg: + return self.etb.call(truediv, 1, self.etb.call(sqrt, operands[0])) + elif operator is neg: return self.etb.call(operator, operands[0]) if operator == add_vararg: - operator = _operator.add + operator = add elif operator == mul_vararg: - operator = _operator.mul - return reduce(lambda x,y: self.etb.call(operator, x,y), operands) + operator = mul + return reduce(lambda x, y: self.etb.call(operator, x, y), operands) def symbol(self, ex): r""" @@ -1846,6 +1855,7 @@ def tuple(self, ex): """ return ex.operands() + def fast_callable(ex, etb): """ Given an ExpressionTreeBuilder *etb*, return an Expression representing @@ -1867,6 +1877,7 @@ def fast_callable(ex, etb): """ return FastCallableConverter(ex, etb)() + class RingConverter(Converter): def __init__(self, R, subs_dict=None): """ @@ -1940,15 +1951,15 @@ def arithmetic(self, ex, operator): sage: R(a) 2*z^2 + z + 3 """ - if operator not in [_operator.pow, add_vararg, mul_vararg]: + if operator not in [pow, add_vararg, mul_vararg]: raise TypeError operands = ex.operands() - if operator is _operator.pow: + if operator is pow: from sage.all import Integer, Rational base, expt = operands - if expt == Rational(((1,2))): + if expt == Rational(((1, 2))): from sage.misc.functional import sqrt return sqrt(self(base)) try: @@ -1960,9 +1971,9 @@ def arithmetic(self, ex, operator): return base ** expt if operator == add_vararg: - operator = _operator.add + operator = add elif operator == mul_vararg: - operator = _operator.mul + operator = mul return reduce(operator, map(self, operands)) def composition(self, ex, operator): @@ -1974,7 +1985,7 @@ def composition(self, ex, operator): sage: R(cos(2)) -0.4161468365471424? """ - res = operator(*[self(_) for _ in ex.operands()]) + res = operator(*[self(op) for op in ex.operands()]) if res.parent() is not self.ring: raise TypeError else: @@ -2094,6 +2105,7 @@ def tuple(self, ex): """ return ex.operands() + class SubstituteFunction(ExpressionTreeWalker): def __init__(self, ex, *args): """ @@ -2178,6 +2190,7 @@ def derivative(self, ex, operator): else: return operator(*[self(_) for _ in ex.operands()]) + class Exponentialize(ExpressionTreeWalker): # Implementation note: this code is executed once at first # reference in the code using it, therefore avoiding rebuilding @@ -2216,7 +2229,7 @@ def __init__(self, ex): expressions. EXAMPLES:: - + sage: from sage.symbolic.expression_conversions import Exponentialize sage: d = Exponentialize(sin(x)) sage: d(sin(x)) @@ -2268,7 +2281,7 @@ def __init__(self, ex, force=False): """ self.ex = ex self.force = force - + def composition(self, ex, op): """ Return the composition of ``self`` with ``ex`` by ``op``. @@ -2306,6 +2319,7 @@ def composition(self, ex, op): return cosh(arg) + sinh(arg) return exp(arg) + class HoldRemover(ExpressionTreeWalker): def __init__(self, ex, exclude=None): """ diff --git a/src/sage/typeset/character_art.py b/src/sage/typeset/character_art.py index 7ec212f0631..9681f0b8c53 100644 --- a/src/sage/typeset/character_art.py +++ b/src/sage/typeset/character_art.py @@ -24,8 +24,6 @@ # # https://www.gnu.org/licenses/ # ****************************************************************************** - -import os import sys from sage.structure.sage_object import SageObject