Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions drg/array3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))) + \
Expand All @@ -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))) + \
Expand Down Expand Up @@ -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), ())))
Expand Down Expand Up @@ -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))
Expand All @@ -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], [])))
Expand All @@ -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],
Expand Down Expand Up @@ -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),
Expand Down
99 changes: 46 additions & 53 deletions drg/assoc_scheme.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2236,16 +2233,16 @@ 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)
return m

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()):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions drg/aux.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .references import refs as references
from .util import utf8


class InfeasibleError(Exception):
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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.
"""
Expand Down
Loading