diff --git a/drg/array3d.py b/drg/array3d.py index 6c926a5..1ab41a8 100644 --- a/drg/array3d.py +++ b/drg/array3d.py @@ -78,7 +78,7 @@ def __repr__(self): String representation of the array. """ l = len(repr(self.n - 1)) - fmt = '%{}d: '.format(l) + fmt = f'%{l}d: ' return '\n\n'.join((fmt % i) + repr(M).replace('\n', '\n' + (' ' * (l+2))) for i, M in enumerate(self.A)) @@ -96,7 +96,7 @@ def _ascii_art_(self): ASCII art representation of the array. """ l = len(repr(self.n - 1)) - fmt = '%{}d: '.format(l) + fmt = f'%{l}d: ' art = [ascii_art(M) for M in self.A] return ascii_art("\n".join((fmt % i) + "\n"*a.height() for i, a in enumerate(art))) + \ @@ -115,7 +115,7 @@ def _unicode_art_(self): Unicode art representation of the array. """ l = len(repr(self.n - 1)) - fmt = '%{}d: '.format(l) + fmt = f'%{l}d: ' art = [unicode_art(M) for M in self.A] return unicode_art("\n".join((fmt % i) + "\n"*a.height() for i, a in enumerate(art))) + \ @@ -179,7 +179,7 @@ def subs(self, *exp): def variables(self): """ - Return the variables occuring in the array. + Return the variables occurring in the array. """ return tuple(set(sum((variables(x) for M in self for r in M for x in r), ()))) @@ -255,8 +255,8 @@ def __repr__(self): String representation of the array. """ l = len(repr(self.n - 1)) - fmt = '%{}d'.format(l) - return '\n\n'.join(('(%s, %s): ' % (fmt % i, fmt % j)) + + fmt = f'%{l}d' + return '\n\n'.join((f'({fmt % i}, {fmt % j}): ') + repr(M).replace('\n', '\n' + (' ' * (2*l+6))) for i, A in enumerate(self.A) for j, M in enumerate(A)) @@ -274,8 +274,8 @@ def _ascii_art_(self): ASCII art representation of the array. """ l = len(repr(self.n - 1)) - fmt = '%{}d'.format(l) - art = [("(%s, %s): " % (fmt % i, fmt % j), ascii_art(M)) + fmt = f'%{l}d' + art = [(f"({fmt % i}, {fmt % j}): ", ascii_art(M)) for i, A in enumerate(self.A) for j, M in enumerate(A)] return ascii_art("\n".join(i + "\n"*a.height() for i, a in art)) + \ ascii_art("\n".join(sum([a._matrix + [""] for i, a in art], []))) @@ -294,8 +294,8 @@ def _unicode_art_(self): Unicode art representation of the array. """ l = len(repr(self.n - 1)) - fmt = '%{}d'.format(l) - art = [("(%s, %s): " % (fmt % i, fmt % j), unicode_art(M)) + fmt = f'%{l}d' + art = [(f"({fmt % i}, {fmt % j}): ", unicode_art(M)) for i, A in enumerate(self.A) for j, M in enumerate(A)] return unicode_art("\n".join(i + "\n"*a.height() for i, a in art)) + \ unicode_art("\n".join(sum([a._matrix + [""] for i, a in art], @@ -363,7 +363,7 @@ def subs(self, *exp): def variables(self): """ - Return the variables occuring in the array. + Return the variables occurring in the array. """ return tuple(set(sum((variables(x) for A in self for M in A for r in M for x in r), diff --git a/drg/assoc_scheme.py b/drg/assoc_scheme.py index a514913..eebebb3 100644 --- a/drg/assoc_scheme.py +++ b/drg/assoc_scheme.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- -import six from copy import copy from warnings import warn -from sage.all import pi + +from sage.symbolic.constants import pi from sage.calculus.functional import expand as _expand from sage.calculus.functional import simplify as _simplify from sage.combinat.set_partition import SetPartitions @@ -14,7 +13,7 @@ from sage.matrix.constructor import identity_matrix from sage.misc.latex import latex from sage.misc.latex import LatexExpr -from sage.misc.misc import subsets +from sage.combinat.subset import subsets from sage.rings.integer import Integer from sage.structure.sage_object import SageObject from sage.symbolic.relation import solve as _solve @@ -397,9 +396,9 @@ def _compute_parameters(self, p, P, m, integral=False, name=None, for i in range(self._.d + 1): for j in range(self._.d + 1): p[h, i, j] = full_simplify( - sum(m[t] * P[t, h] * P[t, i] * P[t, j] - for t in range(self._.d + 1)) - / (self._.n * P[0, h])) + sum(m[t] * P[t, h] * P[t, i] * P[t, j] + for t in range(self._.d + 1)) + / (self._.n * P[0, h])) self._check_parameter(h, i, j, p[h, i, j], integral=integral, name=name, sym=sym) @@ -443,7 +442,7 @@ def _compute_pTable(self, expand=False, factor=False, def _copy(self, p): """ - Copy fields to the given obejct. + Copy fields to the given object. """ p._.d = self._.d p._.n = self._.n @@ -486,6 +485,7 @@ def _derived(self, derived=True): subcs = set() pars = self._get_parameters() c = self.classes() + def derived(): for pa, part in self._.fusion_schemes.items(): yield (pa, part, [], True) @@ -563,7 +563,7 @@ def _init_prefix(self): self._.prefix = "v%x" % (hash(self) % Integer(2)**32) def _init_schoenberg(self): - u""" + """ Initialize parameters for the computation of the limit up to which Schönberg's theorem is tested. """ @@ -674,7 +674,7 @@ def _subconstituent_name(h): def _subs(self, exp, p, seen): """ - Substitute the given subexpressions in the paramaters. + Substitute the given subexpressions in the parameters. """ if id(self) in seen: return (seen[id(self)], False) @@ -793,7 +793,7 @@ def check_feasible(self, checked=None, skip=None, derived=None, levels=3, return if skip is None: skip = set() - elif isinstance(skip, six.string_types): + elif isinstance(skip, str): skip = {skip} else: skip = set(skip) @@ -997,12 +997,12 @@ def polynomialOrders(self): if self.is_pPolynomial(): for order in self._.pPolynomial_ordering: pa = self.add_subscheme(DRGParameters(self, order=order), - "P-polynomial ordering %s" % (order, )) + f"P-polynomial ordering {order}") out["P", order] = pa if self.is_qPolynomial(): for order in self._.qPolynomial_ordering: pa = self.add_subscheme(QPolyParameters(self, order=order), - "Q-polynomial ordering %s" % (order, )) + f"Q-polynomial ordering {order}") out["Q", order] = pa return out @@ -1583,12 +1583,12 @@ def tripleSolution_generator(self, u, v, w, S=None, solver=None): if S is None: S = self.tripleEquations(u, v, w) return find(make_expressions((S[h, i, j], 0, - min(self._.p[u, h, i], - self._.p[v, h, j], - self._.p[w, i, j])) - for h in range(self._.d + 1) - for i in range(self._.d + 1) - for j in range(self._.d + 1)), + min(self._.p[u, h, i], + self._.p[v, h, j], + self._.p[w, i, j])) + for h in range(self._.d + 1) + for i in range(self._.d + 1) + for j in range(self._.d + 1)), S.variables(), solver=solver) def variables(self): @@ -1711,7 +1711,7 @@ def check_absoluteBound(self, expand=False, factor=False, @check(2) def check_schoenberg(self, expand=False, factor=False, simplify=False): - u""" + """ Check whether Schönberg's theorem holds. """ if len(self._.vars) > 0: @@ -1730,8 +1730,7 @@ def check_schoenberg(self, expand=False, factor=False, simplify=False): try: QPolyParameters(self, order=order).check_schoenberg() except InfeasibleError as ex: - raise InfeasibleError(ex, part="Q-polynomial ordering %s" % - (order, )) + raise InfeasibleError(ex, part=f"Q-polynomial ordering {order}") return rr = range(self._.d + 1) t = SR.symbol("__t") @@ -1955,9 +1954,9 @@ def __eq__(self, other): """ if isinstance(other, self._get_class()): return self._.hash_parameters == other._.hash_parameters - else: - return not isinstance(other, ASParameters) \ - and self._.hash_parameters == other + + return not isinstance(other, ASParameters) \ + and self._.hash_parameters == other def __hash__(self): """ @@ -1969,15 +1968,13 @@ def __repr__(self): """ String representation. """ - return "Parameters of a %s with %s %s" % \ - (self.OBJECT, self.ARRAY, self._format_parameterArray()) + return "Parameters of a {} with {} {}".format(self.OBJECT, self.ARRAY, self._format_parameterArray()) def _ascii_art_(self): """ ASCII art representation. """ - return ascii_art("Parameters of a %s with %s " % - (self.OBJECT, self.ARRAY), + return ascii_art(f"Parameters of a {self.OBJECT} with {self.ARRAY} ", self._format_parameterArray_ascii()) def _check_family(self): @@ -2074,11 +2071,11 @@ def _compute_dualParameters(self, q, k, m, tr): for i in range(self._.d + 1): for j in range(self._.d + 1): q[h, i, j] = full_simplify( - sum(k[t] * self._.omega[tr(h, t)] - * self._.omega[tr(i, t)] - * self._.omega[tr(j, t)] - for t in range(self._.d + 1)) - * m[i] * m[j] / self._.n) + sum(k[t] * self._.omega[tr(h, t)] + * self._.omega[tr(i, t)] + * self._.omega[tr(j, t)] + for t in range(self._.d + 1)) + * m[i] * m[j] / self._.n) self._check_parameter(h, i, j, q[h, i, j], integral=self.DUAL_INTEGRAL, name=self.DUAL_PARAMETER, @@ -2236,8 +2233,8 @@ def _compute_sizes(self, k, expand=False, factor=False, else: try: m = tuple(integralize(_simplify(_factor( - self._.n / sum(s * om**2 - for s, om in zip(k, omg))))) + self._.n / sum(s * om**2 + for s, om in zip(k, omg))))) for omg in self._.omega) except TypeError: raise InfeasibleError("%s not integral" % self.DUAL_SIZES) @@ -2245,7 +2242,7 @@ def _compute_sizes(self, k, expand=False, factor=False, def _copy(self, p): """ - Copy fields to the given obejct. + Copy fields to the given object. """ ASParameters._copy(self, p) if isinstance(p, self._get_class()): @@ -2278,15 +2275,14 @@ def _derived(self, derived=True): Generate parameters sets of derived association schemes. """ self.partSchemes() - for par, part, refs, reorder in ASParameters._derived(self, derived): - yield (par, part, refs, reorder) + yield from ASParameters._derived(self, derived) def _format_parameterArray(self): """ Return a string representation of the intersection array. """ - return "{%s; %s}" % tuple(', '.join(str(x) for x in l) - for l in self.parameterArray()) + return "{{{}; {}}}".format(*tuple(', '.join(str(x) for x in l) + for l in self.parameterArray())) def _format_parameterArray_ascii(self): """ @@ -2303,9 +2299,9 @@ def _format_parameterArray_latex(self): """ Return a LaTeX representation of the intersection array. """ - return r"\left\{%s; %s\right\}" % tuple(', '.join(latex(x) - for x in l) for l - in self.parameterArray()) + return r"\left\{{{}; {}\right\}}".format(*tuple(', '.join(latex(x) + for x in l) + for l in self.parameterArray())) def _format_parameterArray_unicode(self): """ @@ -2355,9 +2351,8 @@ def _latex_(self): """ LaTeX representation. """ - return LatexExpr(r"\text{Parameters of a %s with %s } %s" % - (self.OBJECT_LATEX, self.ARRAY, - self._format_parameterArray_latex())) + return LatexExpr(r"\text{{Parameters of a {} with {} }} {}".format(self.OBJECT_LATEX, self.ARRAY, + self._format_parameterArray_latex())) def _match(self, b, c): """ @@ -2384,8 +2379,7 @@ def _unicode_art_(self): """ Unicode art representation. """ - return unicode_art("Parameters of a %s with %s " % - (self.OBJECT, self.ARRAY), + return unicode_art(f"Parameters of a {self.OBJECT} with {self.ARRAY} ", self._format_parameterArray_unicode()) def antipodalSubscheme(self): @@ -2535,9 +2529,8 @@ def merge(self, k, p, *args, **kargs): eqs.append(c0 == cc) else: if len(bi) > 1 or len(ci) > 1: - raise IndexError("merging %s %s does not yield " - "a %s-polynomial scheme" % - (self.PARTS, sorted(adj), self.MATRIX)) + raise IndexError("merging {} {} does not yield " + "a {}-polynomial scheme".format(self.PARTS, sorted(adj), self.MATRIX)) b.append(next(iter(bi))) c.append(next(iter(ci))) cur = nxt @@ -2640,7 +2633,7 @@ def terwilligerPolynomial(self, var='x', i=2, p_order=None, q_order=None): self.pTable() if not self._has("Q"): self.dualEigenmatrix() - x = SR.symbol(var) if isinstance(var, six.string_types) else var + x = SR.symbol(var) if isinstance(var, str) else var ths = next(iter(zip(*self._.Q[p_order, q_order[1]]))) \ + (Integer(0), ) o = p_order[1] diff --git a/drg/aux.py b/drg/aux.py index 9d334d5..515fc30 100644 --- a/drg/aux.py +++ b/drg/aux.py @@ -1,5 +1,4 @@ from .references import refs as references -from .util import utf8 class InfeasibleError(Exception): @@ -16,7 +15,7 @@ def __init__(self, reason=None, refs=None, part=None): elif not isinstance(part, tuple): part = (part, ) if refs is None: - refs = [] + refs = [] elif not isinstance(refs, list): refs = [refs] refs = [(references[pap], thm) @@ -42,7 +41,7 @@ def __init__(self, reason=None, refs=None, part=None): if len(self.refs) > 0: msg.append("nonexistence by %s" % "; ".join(self.formatRef(ref) for ref in self.refs)) - self.args = (utf8(": ".join(msg)), ) + self.args = (": ".join(msg), ) @staticmethod def formatRef(ref): @@ -53,10 +52,10 @@ def formatRef(ref): if thm is None: return pap.name else: - return "%s, %s" % (pap.name, thm) + return f"{pap.name}, {thm}" -class Parameters(object): +class Parameters: """ An auxiliary class for storing the computed parameters. """ diff --git a/drg/coefflist.py b/drg/coefflist.py index c9db459..70b32be 100644 --- a/drg/coefflist.py +++ b/drg/coefflist.py @@ -1,9 +1,8 @@ -import six from sage.misc.functional import numerical_approx from sage.rings.integer import Integer from sage.symbolic.expression import Expression from sage.symbolic.ring import SR -from .util import checkNonneg + from .util import checkPos from .util import variables @@ -68,8 +67,8 @@ def __cmp__(self, other): if other is None: keys = set() else: - keys = set(six.iterkeys(other.val)) - for k in sorted(keys.union(six.iterkeys(self.val)), reverse=True): + keys = set(other.val) + for k in sorted(keys.union(self.val), reverse=True): if k not in keys: c = self.val[k].__cmp__(None) elif k not in self.val: diff --git a/drg/drg.py b/drg/drg.py index b597919..55cd2b7 100644 --- a/drg/drg.py +++ b/drg/drg.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- import operator -import six + from sage.arith.misc import GCD from sage.combinat.q_analogues import q_int from sage.functions.generalized import sgn @@ -9,7 +8,6 @@ from sage.functions.other import floor from sage.functions.other import sqrt from sage.functions.trig import cos -from sage.matrix.constructor import Matrix from sage.rings.finite_rings.integer_mod_ring import Integers from sage.rings.integer import Integer from sage.rings.infinity import Infinity @@ -26,15 +24,12 @@ from .find import find from .nonex import checkConditions from .nonex import classicalFamilies -from .nonex import families -from .nonex import sporadic from .partition import PartitionGraph from .util import checklist from .util import checkNonneg from .util import checkPos from .util import checkPrimePower from .util import eigenvalue_interval -from .util import full_simplify from .util import hard_ceiling from .util import hard_floor from .util import integralize @@ -559,7 +554,9 @@ def localEigenvalue_range(self, compute=False, b=None, lowm=None, then the relevant triple intersection numbers will be computed. """ refs = [] - out = lambda ii: (ii, refs) if return_refs else ii + + def out(ii): + return (ii, refs) if return_refs else ii a = self._.a[1] if a == 0: return out(RealSet([0, 0])) @@ -699,7 +696,8 @@ def localEigenvalue_range(self, compute=False, b=None, lowm=None, m1u = floor(-(rest * th3 + fix) / (th1 - th3)) if rest < 0 or m1u < 0: raise InfeasibleError("no solution for the multiplicities " - "of the eigenvalues of the local graph", refs + rr) + "of the eigenvalues of the local graph", + refs + rr) m1l = ceil(-(rest * th2 + fix) / (th1 - th2)) if m1l < 0: m1l = Integer(0) @@ -752,7 +750,7 @@ def maximalCliquePolynomial(self, var='x'): if not self._has("theta"): self.eigenvalues() m = -min(self._.theta, key=lambda x: CoefficientList(x, self._.vars)) - x = SR.symbol(var) if isinstance(var, six.string_types) else var + x = SR.symbol(var) if isinstance(var, str) else var M = ((x + m - 3) * (self._.k[1] - x + 1) - 2 * (x - 1) * (self._.a[1] - x + 2))**2 - \ (self._.k[1] - x + 1)**2 * (x + m - 1) * (x - (m-1) * (4*m-1)) @@ -828,7 +826,8 @@ def subconstituent(self, h, compute=False, check_local=True): [("Vidali13", "Thm. 4.6.3")]) if self._.subconstituents[h] is None: subc, refs, rels = PolyASParameters.subconstituent(self, h, - compute=compute, return_rels=True) + compute=compute, + return_rels=True) trd = tuple(range(subc._.d+1)) if subc is not None and len(rels) > 1 and rels[1] == 1 \ and subc.is_pPolynomial() \ @@ -1023,7 +1022,7 @@ def check_combinatorial(self): if self._.d >= 2: if self._.a[1] == 0 and any(2*self._.a[i] > self._.k[i] for i in range(2, self._.d+1)): - raise InfeasibleError(u"Turán's theorem", + raise InfeasibleError("Turán's theorem", ("BCN", "Prop. 5.6.4.")) for h in range(1, self._.d + 1): for i in range(self._.d + 1): @@ -1406,7 +1405,7 @@ def check_localEigenvalues(self, compute=False, check_range=True): (th1 * (self._.a[1] + 1) + self._.k[1]) * \ (thd * (self._.a[1] + 1) + self._.k[1]) refs = [] - jk = u"JurišićKoolen00" + jk = "JurišićKoolen00" jkt = "JKT00" if bd == 0: refs.append(jk) @@ -1440,7 +1439,7 @@ def check_localEigenvalues(self, compute=False, check_range=True): def checkMul(h): if self._.antipodal and self._.omega[h, self._.d] != 1 and \ - self._.m[h] < self._.k[1] + self._.r - 2: + self._.m[h] < self._.k[1] + self._.r - 2: return ("m[%d] < k+r-2" % h, "GodsilHensel92") elif self._.a[self._.d] == 0 and \ 1 not in [self._.omega[h, 2], @@ -1481,7 +1480,7 @@ def checkMul(h): rng, refs = self.localEigenvalue_range(compute=compute, b=(bm, bp), lowm=[h for h in s if - self._.m[h] < self._.k[1]], + self._.m[h] < self._.k[1]], return_refs=True) c = rng.cardinality() if rng.sup() <= bp or self._.subconstituents[1] is not None or \ diff --git a/drg/find.py b/drg/find.py index 43c7fd0..eefd1b0 100644 --- a/drg/find.py +++ b/drg/find.py @@ -45,7 +45,7 @@ def find(expressions, vars, conditions=None, solver=None): def makeLPExpression(e): return sum(e.coefficient(y) * v[str(y)] for y in vars) \ - + e.subs(zero) * lp[1] + + e.subs(zero) * lp[1] lpopt = makeLPExpression(opt) diff --git a/drg/nonex.py b/drg/nonex.py index 9da32f3..b69a9f5 100644 --- a/drg/nonex.py +++ b/drg/nonex.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .util import frac from .util import symbol @@ -30,19 +29,19 @@ ("p", ((55, 36, 11), (1, 4, 45))): "Gavrilyuk11", ("p", ((56, 36, 9), (1, 3, 48))): "Gavrilyuk11", ("p", ((69, 48, 24), (1, 4, 46))): "GavrilyukMakhnev12", - ("p", ((74, 54, 15), (1, 9, 60))): u"CoolsaetJurišić08", + ("p", ((74, 54, 15), (1, 9, 60))): "CoolsaetJurišić08", ("p", ((80, 54, 12), (1, 6, 60))): "KIPR19", ("p", ((83, 54, 21), (1, 6, 63))): "GVW21", ("p", ((105, 102, 99), (1, 2, 35))): "DeBruynVanhove15", ("p", ((125, 108, 24), (1, 9, 75))): "GVW21", ("p", ((126, 90, 10), (1, 6, 105))): "GVW21", - ("p", ((130, 96, 18), (1, 12, 117))): u"JurišićVidali17", + ("p", ((130, 96, 18), (1, 12, 117))): "JurišićVidali17", ("p", ((135, 128, 16), (1, 16, 120))): "Vidali18", ("p", ((147, 144, 135), (1, 4, 49))): "DeBruyn01", ("p", ((195, 160, 28), (1, 20, 168))): "GVW21", ("p", ((203, 160, 34), (1, 16, 170))): "GVW21", ("p", ((234, 165, 12), (1, 30, 198))): "Vidali18", - ("p", ((4818, 4248, 192), (1, 72, 4672))): u"JurišićVidali17", + ("p", ((4818, 4248, 192), (1, 72, 4672))): "JurišićVidali17", ("p", ((5928, 5920, 5888), (1, 5, 741))): "DeBruynVanhove15", ("p", ((120939612, 120939520, 120933632), (1, 65, 1314561))): "DeBruynVanhove15", @@ -217,11 +216,11 @@ ("p", ((r**2*(r+3), (r+1)*(r**2+2*r-2)), (1, r*(r+1)))): ([r >= 3, r != 4], "BondarenkoRadchenko13"), ("p", (((2*r**2 - 1)*(2*r+1), 4*r*(r**2-1), 2*r**2), - (1, 2*(r**2-1), r*(4*r**2-2)))): (r >= 2, u"JurišićVidali12"), + (1, 2*(r**2-1), r*(4*r**2-2)))): (r >= 2, "JurišićVidali12"), ("p", ((2*r**2*(2*r+1), (2*r-1)*(2*r**2+r+1), 2*r**2), - (1, 2*r**2, r*(4*r**2-1)))): (r >= 2, u"JurišićVidali12"), + (1, 2*r**2, r*(4*r**2-1)))): (r >= 2, "JurišićVidali12"), ("p", ((4*r**3 + 8*r**2 + 6*r + 1, 2*r*(r+1)*(2*r+1), 2*r**2 + 2*r + 1), - (1, 2*r*(r+1), (2*r+1)*(2*r**2+2*r+1)))): (r >= 1, u"CoolsaetJurišić08"), + (1, 2*r*(r+1), (2*r+1)*(2*r**2+2*r+1)))): (r >= 1, "CoolsaetJurišić08"), ("p", (((2*r+1)*(4*r+1)*(4*t-1), 8*r*(4*r*t-r+2*t), (r+t)*(4*r+1)), (1, (r+t)*(4*r+1), 4*r*(2*r+1)*(4*t-1)))): ([r >= 1, t >= 1], "Vidali18"), ("p", (((r+1)*(r**3-1), r*(r-1)*(r**2+r-1), r**2-1), @@ -229,7 +228,7 @@ ("p", ((r**2*(r*t+t+1), (r**2-1)*(r*t+1), r*(r-1)*(t+1), 1), (1, r*(t+1), (r**2-1)*(r*t+1), r**2*(r*t+t+1)))): ([r >= 3, t > 0, (r != 3, [t != 1, t != 3]), (r != 4, t != 2)], - u"JurišićKoolen11"), + "JurišićKoolen11"), ("p", ((2*r**2+r, 2*r**2+r-1, r**2, r, 1), (1, r, r**2, 2*r**2+r-1, 2*r**2+r))): (r >= 2, "CJK08"), diff --git a/drg/partition.py b/drg/partition.py index 87d79a8..8aed179 100644 --- a/drg/partition.py +++ b/drg/partition.py @@ -60,11 +60,13 @@ def __init__(self, p, h=0): """ assert h >= 0 and h <= p._.d, "distance not in feasible range" d = dict(sum([[((i, j), x) for j, x in enumerate(r) if x != 0] - for i, r in enumerate(p._.p[h])], [])) + for i, r in enumerate(p._.p[h])], [])) if h == 0: - pos = lambda t: t[:1] + def pos(t): + return t[:1] else: - pos = lambda t: t + def pos(t): + return t b = {k: Bubble(v, *pos(k)) for k, v in d.items()} V = b.values() Graph.__init__(self, diff --git a/drg/qpoly.py b/drg/qpoly.py index 00cd127..67d2598 100644 --- a/drg/qpoly.py +++ b/drg/qpoly.py @@ -1,9 +1,6 @@ -# -*- coding: utf-8 -*- from sage.functions.other import floor -from sage.matrix.constructor import Matrix from sage.rings.integer import Integer from sage.rings.rational_field import Q as QQ -from sage.symbolic.relation import solve as _solve from sage.symbolic.ring import SR from .array3d import Array3D from .assoc_scheme import ASParameters @@ -138,12 +135,11 @@ def _derived(self, derived=True): """ if self._.antipodal and self._.d >= 3: self.all_dismantlements() - for par, part, refs, reorder in PolyASParameters._derived(self, derived): - yield (par, part, refs, reorder) + yield from PolyASParameters._derived(self, derived) def _copy(self, p): """ - Copy fields to the given obejct. + Copy fields to the given object. """ PolyASParameters._copy(self, p) if self._has("dismantled_schemes"): @@ -198,7 +194,7 @@ def _get_class(): return QPolyParameters def _init_schoenberg(self): - u""" + """ Initialize parameters for the computation of the limit up to which Schönberg's theorem is tested. @@ -321,6 +317,7 @@ def subconstituent(self, h, compute=False): """ Return parameters of the h-th subconstituent if it is known to form an association scheme. + If the resulting scheme is Q-polynomial, the parameters are returned as such. @@ -329,7 +326,8 @@ def subconstituent(self, h, compute=False): """ if self._.subconstituents[h] is None: subc, refs, rels = PolyASParameters.subconstituent(self, h, - compute=compute, return_rels=True) + compute=compute, + return_rels=True) if subc is not None and subc.is_qPolynomial(): old, subc = subc, QPolyParameters(subc) self._.subconstituents[h] = (subc, refs) diff --git a/drg/references.py b/drg/references.py index f9b9c0d..4a0bcd9 100644 --- a/drg/references.py +++ b/drg/references.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- import re -from .util import utf8 from sage.structure.sage_object import SageObject @@ -59,22 +57,23 @@ def __repr__(self): """ String representation. """ - return "%s(%s)" % (self.__class__.__name__, utf8(self.name)) + return f"{self.__class__.__name__}({self.name})" def __str__(self): """ Print representation. """ - return utf8(self.name) + return self.name def author(self, bibtex=False, short=False): """ Return the author(s). """ abbrv = (lambda s: "%s." % s[0]) if short else (lambda s: s) - authors = ["%s%s" % (("%s " % " ".join(abbrv(name) for name in first)) - if first else "", last) for last, first - in self.fields["author"]] + authors = ["{}{}".format(("%s " % " ".join(abbrv(name) + for name in first)) + if first else "", last) + for last, first in self.fields["author"]] if not bibtex and len(authors) > 2: authors[:-1] = [", ".join(authors[:-1])] return " and ".join(authors) @@ -83,13 +82,13 @@ def bibtex(self): """ Return the BibTeX string. """ - return "@%s{%s\n%s}\n" % (self.__class__.__name__.lower(), - utf8(self.name), - "".join("%11s = {%s},\n" % - (key, - utf8(getattr(self, - key)(bibtex=True))) - for key in self.fields)) + return "@{}{{{}\n{}}}\n".format(self.__class__.__name__.lower(), + self.name, + "".join("%11s = {%s},\n" % + (key, + getattr(self, + key)(bibtex=True)) + for key in self.fields)) def range(self, name, delim): """ @@ -100,7 +99,7 @@ def range(self, name, delim): data = self.fields[name] if isinstance(data, tuple): left, right = data - return "%s%s%s" % (left, delim, right) + return f"{left}{delim}{right}" else: return data @@ -363,8 +362,8 @@ class Unpublished(Article): year=2005 ) -Article(u"CoolsaetJurišić08", - author=[("Coolsaet", ("Kris", )), (u"Jurišić", ("Aleksandar", ))], +Article("CoolsaetJurišić08", + author=[("Coolsaet", ("Kris", )), ("Jurišić", ("Aleksandar", ))], title="Using equality in the Krein conditions " "to prove nonexistence of certain distance-regular graphs", journal="J. Combin. Theory Ser. A", @@ -377,7 +376,7 @@ class Unpublished(Article): ) Article("CJK08", - author=[("Coolsaet", ("Kris", )), (u"Jurišić", ("Aleksandar", )), + author=[("Coolsaet", ("Kris", )), ("Jurišić", ("Aleksandar", )), ("Koolen", ("Jack", ))], title="On triangle-free distance-regular graphs " "with an eigenvalue multiplicity equal to the valency", @@ -414,7 +413,7 @@ class Unpublished(Article): ) Article("DeBruynVanhove15", - author=[("De Bruyn", ("Bart", )), ("Vanhove", (u"Frédéric", ))], + author=[("De Bruyn", ("Bart", )), ("Vanhove", ("Frédéric", ))], title="On $Q$-polynomial regular near $2d$-gons", journal="Combinatorica", fjournal="Combinatorica", @@ -611,7 +610,7 @@ class Unpublished(Article): Article("GSV20", author=[("Gavrilyuk", ("Alexander", "L.")), ("Suda", ("Sho", )), - ("Vidali", (u"Janoš", ))], + ("Vidali", ("Janoš", ))], title="On tight $4$-designs in Hamming association schemes", journal="Combinatorica", fjournal="Combinatorica", @@ -624,7 +623,7 @@ class Unpublished(Article): Article("GVW21", author=[("Gavrilyuk", ("Alexander", "L.")), - ("Vidali", (u"Janoš", )), + ("Vidali", ("Janoš", )), ("Williford", ("Jason", "S."))], title="On few-class $Q$-polynomial association schemes: " "feasible parameters and nonexistence results", @@ -676,8 +675,8 @@ class Unpublished(Article): year=1990 ) -Article(u"JurišićKoolen00", - author=[(u"Jurišić", ("Aleksandar", )), ("Koolen", ("Jack", ))], +Article("JurišićKoolen00", + author=[("Jurišić", ("Aleksandar", )), ("Koolen", ("Jack", ))], title="Nonexistence of some antipodal distance-regular graphs " "of diameter four", journal="European J. Combin.", @@ -688,8 +687,8 @@ class Unpublished(Article): year=2000 ) -Article(u"JurišićKoolen11", - author=[(u"Jurišić", ("Aleksandar", )), ("Koolen", ("Jack", ))], +Article("JurišićKoolen11", + author=[("Jurišić", ("Aleksandar", )), ("Koolen", ("Jack", ))], title=r"Classification of the family $\rm{AT4}(qs,q,q)$ " "of antipodal tight graphs", journal="J. Combin. Theory Ser. A", @@ -700,8 +699,8 @@ class Unpublished(Article): year=2011 ) -Article(u"JurišićVidali12", - author=[(u"Jurišić", ("Aleksandar", )), ("Vidali", (u"Janoš", ))], +Article("JurišićVidali12", + author=[("Jurišić", ("Aleksandar", )), ("Vidali", ("Janoš", ))], title="Extremal $1$-codes in distance-regular graphs of diameter $3$", journal="Des. Codes Cryptogr.", fjournal="Designs, Codes and Cryptography", @@ -712,8 +711,8 @@ class Unpublished(Article): year=2012 ) -Article(u"JurišićVidali17", - author=[(u"Jurišić", ("Aleksandar", )), ("Vidali", (u"Janoš", ))], +Article("JurišićVidali17", + author=[("Jurišić", ("Aleksandar", )), ("Vidali", ("Janoš", ))], title="Restrictions on classical distance-regular graphs", journal="J. Algebraic Combin.", fjournal="Journal of Algebraic Combinatorics", @@ -724,7 +723,7 @@ class Unpublished(Article): ) Article("JKT00", - author=[(u"Jurišić", ("Aleksandar", )), ("Koolen", ("Jack", )), + author=[("Jurišić", ("Aleksandar", )), ("Koolen", ("Jack", )), ("Terwilliger", ("Paul", ))], title="Tight distance-regular graphs", journal="J. Algebraic Combin.", @@ -811,7 +810,7 @@ class Unpublished(Article): title="On the nonexistence of strongly regular graphs " "with the parameters $(486, 165, 36, 66)$", journal="Ukrain. Mat. Zh.", - fjournal=u"Ukraïns′kiĭ Matematichniĭ Zhurnal", + fjournal="Ukraïns′kiĭ Matematichniĭ Zhurnal", volume=54, number=7, pages=(941, 949), @@ -901,7 +900,7 @@ class Unpublished(Article): edition="Second", series="EMS Series of Lectures in Mathematics", publisher="European Mathematical Society (EMS)", - address=u"Zürich", + address="Zürich", year=2009, url="https://doi.org/10.4171/066", pages=("xii", 287) @@ -937,7 +936,7 @@ class Unpublished(Article): ) Article("Urlep12", - author=[("Urlep", (u"Matjaž", ))], + author=[("Urlep", ("Matjaž", ))], title="Triple intersection numbers of " "$Q$-polynomial distance-regular graphs", journal="European J. Combin.", @@ -950,7 +949,7 @@ class Unpublished(Article): ) PhDThesis("Vidali13", - author=[("Vidali", (u"Janoš", ))], + author=[("Vidali", ("Janoš", ))], title="Codes in distance-regular graphs", school="University of Ljubljana", url="http://eprints.fri.uni-lj.si/2167/", @@ -958,7 +957,7 @@ class Unpublished(Article): ) Article("Vidali18", - author=[("Vidali", (u"Janoš", ))], + author=[("Vidali", ("Janoš", ))], title="Using symbolic computation " "to prove nonexistence of distance-regular graphs", journal="Electron. J. Combin", diff --git a/drg/util.py b/drg/util.py index 09597ee..804ed7c 100644 --- a/drg/util.py +++ b/drg/util.py @@ -1,11 +1,8 @@ import operator import re -import six -from sage.arith.misc import factor as factorize + from sage.calculus.functional import expand as _expand from sage.calculus.functional import simplify as _simplify -from sage.functions.other import ceil -from sage.functions.other import floor from sage.functions.other import sqrt from sage.rings.integer import Integer from sage.rings.number_field.number_field import NumberField @@ -117,7 +114,7 @@ def checkPrimePower(exp): def eigenvalue_interval(l, u): """ - Return an appropriate interval for eigenvalues between ``l'' and ``u''. + Return an appropriate interval for eigenvalues between ''l'' and ''u''. """ return INTERVAL[is_algebraic_integer(l), is_algebraic_integer(u)](l, u) @@ -135,7 +132,7 @@ def frac(a, b): """ Return the fraction ``a/b``. """ - return Integer(a)/Integer(b) + return Integer(a) / Integer(b) def full_simplify(exp): @@ -241,6 +238,7 @@ def is_integer(x): except TypeError: return False + def is_integral(sol): """ Determine whether a solution of a system of equations can be integral. @@ -400,17 +398,6 @@ def symbol(a=None): return SR.symbol(a) -def utf8(msg): - """ - UTF-8 encode the string. - - Provided for Python 2/3 compatibility. - """ - if six.PY2 and isinstance(msg, unicode): - msg = msg.encode("utf-8") - return msg - - def variables(exp): """ Return a list of variables in an expression. diff --git a/drg/view.py b/drg/view.py index 88f775f..b459f47 100644 --- a/drg/view.py +++ b/drg/view.py @@ -1,6 +1,5 @@ import math import operator -import six from sage.misc.latex import latex from sage.misc.latex import LatexExpr from sage.structure.sage_object import SageObject @@ -217,16 +216,14 @@ def latex_nonex(self): LaTeX representation in case of nonexistent parameter. """ part, key, obj = getattribute(self, 'nonex')() - return LatexExpr(r"\text{View of nonexistent %s }%s" - r"\text{ of }\left\langle%s\right\rangle" % - (part, latex(key), latex(obj))) + return LatexExpr(fr"\text{{View of nonexistent {part} }}{latex(key)}" + fr"\text{{ of }}\left\langle{latex(obj)}\right\rangle") def repr_nonex(self): """ String representation in case of nonexistent parameter. """ - return "View of nonexistent %s %s of <%s>" % \ - getattribute(self, 'nonex')() + return "View of nonexistent {} {} of <{}>".format(*getattribute(self, 'nonex')()) def unicode_art_nonex(self): """ @@ -236,10 +233,10 @@ def unicode_art_nonex(self): art = unicode_art(" ", obj, " ") return unicode_art("View of nonexistent %s " % part, key, " of ", unicode_left_parenthesis.character_art( - art.height()) + art.height()) + art + unicode_right_parenthesis.character_art( - art.height())) + art.height())) __repr__ = attr(repr, repr_nonex) __str__ = attr(str) @@ -299,28 +296,19 @@ def unicode_art_nonex(self): _latex_ = attr(latex, latex_nonex) _unicode_art_ = attr(unicode_art, unicode_art_nonex) - if six.PY2: - __cmp__ = attr(cmp) - __unicode__ = attr(unicode) - __div__ = attr(operator.div) - __idiv__ = attr(operator.idiv) - __long__ = attr(long) - __coerce__ = attr(coerce) - - if six.PY3: - @attr - def __rmatmul__(val, other): - """ - ``other @ val`` - """ - return val.__rmatmul__(other) - - __matmul__ = attr(operator.matmul) - __imatmul__ = attr(operator.imatmul) - __round__ = attr(round) - __trunc__ = attr(math.trunc) - __floor__ = attr(math.floor) - __ceil__ = attr(math.ceil) + @attr + def __rmatmul__(val, other): + """ + ``other @ val`` + """ + return val.__rmatmul__(other) + + __matmul__ = attr(operator.matmul) + __imatmul__ = attr(operator.imatmul) + __round__ = attr(round) + __trunc__ = attr(math.trunc) + __floor__ = attr(math.floor) + __ceil__ = attr(math.ceil) class AttrView(View): @@ -371,7 +359,7 @@ def nonex(self): return ("key", key, view) -class Param(object): +class Param: """ Descriptor class for read-only parameters. """