Skip to content

Commit

Permalink
gh-38941: Details yang baxter
Browse files Browse the repository at this point in the history
    
small changes in one file

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: #38941
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Nov 14, 2024
2 parents b625a14 + 5f083f0 commit 78e68ab
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions src/sage/combinat/yang_baxter_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
# https://www.gnu.org/licenses/
# ****************************************************************************
from copy import copy

from sage.graphs.digraph import DiGraph
from sage.structure.sage_object import SageObject
Expand Down Expand Up @@ -45,8 +46,8 @@ def YangBaxterGraph(partition=None, root=None, operators=None):
OUTPUT: either:
- :class:`YangBaxterGraph_partition` -- if partition is defined
- :class:`YangBaxterGraph_generic` -- if partition is ``None``
- :class:`YangBaxterGraph_partition` -- if partition is defined
- :class:`YangBaxterGraph_generic` -- if partition is ``None``
EXAMPLES:
Expand Down Expand Up @@ -108,8 +109,7 @@ def YangBaxterGraph(partition=None, root=None, operators=None):
"""
if partition is None:
return YangBaxterGraph_generic(root=root, operators=operators)
else:
return YangBaxterGraph_partition(partition=Partition(partition))
return YangBaxterGraph_partition(partition=Partition(partition))

# *********** General class for Yang-Baxter Graphs ***********

Expand Down Expand Up @@ -203,7 +203,7 @@ def _digraph(self):
digraph.add_edge(u, v, l)
return digraph

def __hash__(self):
def __hash__(self) -> int:
r"""
TESTS::
Expand Down Expand Up @@ -236,7 +236,7 @@ def __eq__(self, other) -> bool:
sage: Y3.__eq__(Y2)
False
"""
return type(self) is type(other) and self._digraph == other._digraph
return isinstance(other, YangBaxterGraph_generic) and self._digraph == other._digraph

def __ne__(self, other) -> bool:
r"""
Expand Down Expand Up @@ -311,7 +311,6 @@ def __copy__(self):
sage: Y == B
True
"""
from copy import copy
Y = self.__class__(self._root, self._operators)
Y._digraph = copy(self._digraph)
return Y
Expand Down Expand Up @@ -421,9 +420,7 @@ def vertices(self, sort=False) -> list:
sage: Y.vertices(sort=True)
[(0, 2, 1, 0), (2, 0, 1, 0), (2, 1, 0, 0)]
"""
if sort:
return sorted(self)
return list(self)
return sorted(self) if sort else list(self)

def edges(self):
r"""
Expand Down Expand Up @@ -505,7 +502,6 @@ def relabel_vertices(self, v, relabel_operator, inplace=True):
sage: Y.vertices(sort=True)
[(1, 2, 3, 4), (2, 1, 3, 4), (2, 3, 1, 4)]
"""
from copy import copy
relabelling = self.vertex_relabelling_dict(v, relabel_operator)
Y = self if inplace else copy(self)
Y._root = relabelling[Y._root]
Expand Down Expand Up @@ -540,11 +536,7 @@ def relabel_edges(self, edge_dict, inplace=True):
sage: Y.edges()
[((0, 2, 1, 0), (2, 0, 1, 0), 17), ((2, 0, 1, 0), (2, 1, 0, 0), 27)]
"""
if inplace:
Y = self
else:
from copy import copy
Y = copy(self)
Y = self if inplace else copy(self)
digraph = Y._digraph
for u, v in digraph.edges(sort=False, labels=False):
digraph.set_edge_label(u, v, edge_dict[u, v])
Expand Down Expand Up @@ -614,7 +606,6 @@ def __copy__(self):
sage: Y == B
True
"""
from copy import copy
Y = self.__class__(self._partition)
Y._digraph = copy(self._digraph)
return Y
Expand All @@ -634,7 +625,7 @@ def _digraph(self):
[((0, 1, 0), (1, 0, 0), Swap positions 0 and 1)]
"""
digraph = super()._digraph
for (u, v, op) in digraph.edges(sort=True):
for u, v, op in digraph.edges():
digraph.set_edge_label(u, v, SwapOperator(op.position()))
return digraph

Expand Down Expand Up @@ -754,11 +745,10 @@ def relabel_vertices(self, v, inplace=True):
Y._digraph.relabel(relabelling, inplace=inplace)
Y._vertex_ordering = Y._digraph.vertices(sort=True)
return
else:
from copy import copy
Y = copy(self)
Y._root = relabelling[Y._root]
return Y._digraph.relabel(relabelling, inplace=inplace)

Y = copy(self)
Y._root = relabelling[Y._root]
return Y._digraph.relabel(relabelling, inplace=inplace)

# ------------- Some Yang-Baxter operators ------------------

Expand All @@ -777,7 +767,7 @@ def __init__(self, i):
"""
self._position = i

def __hash__(self):
def __hash__(self) -> int:
r"""
TESTS::
Expand Down Expand Up @@ -925,9 +915,8 @@ def __call__(self, u):
j = i + 1
if u[i] < u[j]:
v = list(u)
(v[j], v[i]) = (v[i], v[j])
v[j], v[i] = v[i], v[j]
if isinstance(u, Permutation):
return Permutation(v)
return type(u)(v)
else:
return u
return u

0 comments on commit 78e68ab

Please sign in to comment.