Skip to content

Commit

Permalink
Trac #34745: modernize super in algebras/ again
Browse files Browse the repository at this point in the history
using the short syntax super() where possible

URL: https://trac.sagemath.org/34745
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Nov 21, 2022
2 parents f2fa759 + 6cc5798 commit 623ea74
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 85 deletions.
10 changes: 4 additions & 6 deletions src/sage/algebras/clifford_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
- Travis Scrimshaw (2013-09-06): Initial version
- Trevor K. Karn (2022-07-27): Rewrite basis indexing using FrozenBitset
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2013-2022 Travis Scrimshaw <tcscrims at gmail.com>
# (C) 2022 Trevor Karn <karnx018 at umn.edu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************

# https://www.gnu.org/licenses/
# ****************************************************************************
from sage.misc.cachefunc import cached_method
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
Expand Down Expand Up @@ -631,7 +629,7 @@ def _element_constructor_(self, x):
return self.element_class(self, {FrozenBitset((i,)): R.one() for i in x})

try:
return super(CliffordAlgebra, self)._element_constructor_(x)
return super()._element_constructor_(x)
except TypeError:
raise TypeError(f'do not know how to make {x=} an element of self')

Expand Down
12 changes: 6 additions & 6 deletions src/sage/algebras/commutative_dga.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def __classcall__(cls, A, im_gens):
raise ValueError("The given dictionary does not determine a degree 1 map")

im_gens = tuple(im_gens.get(x, A.zero()) for x in A.gens())
return super(Differential, cls).__classcall__(cls, A, im_gens)
return super().__classcall__(cls, A, im_gens)

def __init__(self, A, im_gens):
r"""
Expand Down Expand Up @@ -998,9 +998,9 @@ def __classcall__(cls, base, names=None, degrees=None, R=None, I=None, category=
for i in range(n) if is_odd(tot_degs[i])],
side='twosided')

return super(GCAlgebra, cls).__classcall__(cls, base=base, names=names,
degrees=degrees, R=R, I=I,
category=category)
return super().__classcall__(cls, base=base, names=names,
degrees=degrees, R=R, I=I,
category=category)

def __init__(self, base, R=None, I=None, names=None, degrees=None, category=None):
"""
Expand Down Expand Up @@ -1236,7 +1236,7 @@ def _coerce_map_from_(self, other):
.gens()):
return False
return self.cover_ring().has_coerce_map_from(other.cover_ring())
return super(GCAlgebra, self)._coerce_map_from_(other)
return super()._coerce_map_from_(other)

def _element_constructor_(self, x, coerce=True):
r"""
Expand Down Expand Up @@ -1755,7 +1755,7 @@ def _coerce_map_from_(self, other):
return False
elif isinstance(other, GCAlgebra): # Not multigraded
return False
return super(GCAlgebra_multigraded, self)._coerce_map_from_(other)
return super()._coerce_map_from_(other)

def basis(self, n, total=False):
"""
Expand Down
19 changes: 9 additions & 10 deletions src/sage/algebras/hecke_algebras/cubic_hecke_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,15 @@
- Sebastian Oehms May 2020: initial version
"""

##############################################################################
# ###########################################################################
# Copyright (C) 2020 Sebastian Oehms <seb.oehms@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
##############################################################################

# https://www.gnu.org/licenses/
# ###########################################################################
from warnings import warn

from sage.combinat.free_module import CombinatorialFreeModule
Expand Down Expand Up @@ -188,7 +186,8 @@ def __invert__(self):
inverse_Tietze = ()
len_self = len(self_Tietze)

inverse_Tietze = tuple([-1*self_Tietze[len_self - i - 1] for i in range(len_self)])
inverse_Tietze = tuple([-1 * self_Tietze[len_self - i - 1]
for i in range(len_self)])
P = self.parent()
return P(inverse_Tietze)

Expand Down Expand Up @@ -829,9 +828,9 @@ def __classcall_private__(cls, n=None, names='c', cubic_equation_parameters=None

from sage.structure.category_object import normalize_names
names = tuple(normalize_names(n, names))
return super(CubicHeckeAlgebra, cls).__classcall__(cls, names,
cubic_equation_parameters=cubic_equation_parameters,
cubic_equation_roots=cubic_equation_roots)
return super().__classcall__(cls, names,
cubic_equation_parameters=cubic_equation_parameters,
cubic_equation_roots=cubic_equation_roots)

def __init__(self, names, cubic_equation_parameters=None, cubic_equation_roots=None):
r"""
Expand Down Expand Up @@ -3272,7 +3271,7 @@ def cubic_hecke_subalgebra(self, nstrands=None):
if nstrands == self._nstrands - 1 and self._cubic_hecke_subalgebra is not None:
return self._cubic_hecke_subalgebra

names_red = names[:nstrands-1]
names_red = names[:nstrands - 1]
if self.base_ring() == self.base_ring(generic=True):
SubHeckeAlg = CubicHeckeAlgebra(names=names_red)
else:
Expand Down
26 changes: 12 additions & 14 deletions src/sage/algebras/hecke_algebras/cubic_hecke_base_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
- Sebastian Oehms May 2020: initial version
"""

##############################################################################
# ###########################################################################
# Copyright (C) 2020 Sebastian Oehms <seb.oehms@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
##############################################################################

# https://www.gnu.org/licenses/
# ###########################################################################
from sage.structure.category_object import normalize_names
from sage.structure.element import get_coercion_model
from sage.categories.action import Action
Expand Down Expand Up @@ -152,7 +150,7 @@ def _act_(self, perm, pol):
for key, value in pol.dict().items():
newkey = [0] * len(key)
for pos, k in enumerate(key):
newkey[perm(pos+1)-1] = k
newkey[perm(pos + 1) - 1] = k
pol_dict[tuple(newkey)] = value
return self.domain()(pol_dict)

Expand Down Expand Up @@ -313,7 +311,7 @@ def _element_constructor_(self, x, mon=None):
from sage.interfaces.gap3 import GAP3Element
if isinstance(x, GAP3Element):
return self._convert_from_gap3_mvp(x)
return super(CubicHeckeExtensionRing, self)._element_constructor_(x, mon=mon)
return super()._element_constructor_(x, mon=mon)

def _coerce_map_from_(self, R):
r"""
Expand All @@ -338,8 +336,8 @@ def _coerce_map_from_(self, R):
markov = R.markov_trace_version()
a, b, c, *rem = self.gens()
iu = a + b + c
iv = a*b + a*c + b*c
iw = a*b*c
iv = a * b + a * c + b * c
iw = a * b * c
im_gens = [iu, iv, iw]
if markov:
if self.markov_trace_version():
Expand All @@ -351,7 +349,7 @@ def _coerce_map_from_(self, R):
else:
embedding_into_extension_ring = R.hom(im_gens)
return embedding_into_extension_ring
return super(CubicHeckeExtensionRing, self)._coerce_map_from_(R)
return super()._coerce_map_from_(R)

def hom(self, im_gens, codomain=None, check=True, base_map=None):
r"""
Expand Down Expand Up @@ -383,13 +381,13 @@ def hom(self, im_gens, codomain=None, check=True, base_map=None):
e3, *im_remain = im_gens
hom_cycl_gen = self.base_ring().hom([e3], codomain=e3.parent(), check=check, base_map=base_map)
verbose("hom_cycl_gen %s" % hom_cycl_gen, level=2)
return super(CubicHeckeExtensionRing, self).hom(im_remain, codomain=codomain, check=check, base_map=hom_cycl_gen)
return super().hom(im_remain, codomain=codomain, check=check, base_map=hom_cycl_gen)
else:
if base_map is None:
raise ValueError('number of images must be four (inculding a '
'third root of unity at first position) or a '
'base_map (on %s) must be given' % self.base_ring())
return super(CubicHeckeExtensionRing, self).hom(im_gens, codomain=codomain, check=check, base_map=base_map)
return super().hom(im_gens, codomain=codomain, check=check, base_map=base_map)

def _an_element_(self):
r"""
Expand Down Expand Up @@ -1164,10 +1162,10 @@ def mirror_involution(self):
if self._mirror is None:
if self._is_markov_trace_version():
u, v, w, s = self.gens()
self._mirror = self.hom([v/w, u/w, ~w, ~s])
self._mirror = self.hom([v / w, u / w, ~w, ~s])
else:
u, v, w = self.gens()
self._mirror = self.hom([v/w, u/w, ~w])
self._mirror = self.hom([v / w, u / w, ~w])
return self._mirror

def create_specialization(self, im_cubic_equation_parameters, im_writhe_parameter=None):
Expand Down
Loading

0 comments on commit 623ea74

Please sign in to comment.