Skip to content

Commit

Permalink
Trac #28667: remove deprecated stuff in perfect matchings
Browse files Browse the repository at this point in the history
after #23982

URL: https://trac.sagemath.org/28667
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Oct 31, 2019
2 parents 07b08de + 9862f48 commit 2c2790d
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/sage/combinat/perfect_matching.py
@@ -1,3 +1,4 @@

r"""
Perfect matchings
Expand Down Expand Up @@ -68,6 +69,7 @@
from sage.combinat.combinat_cython import perfect_matchings_iterator
from sage.rings.infinity import infinity


class PerfectMatching(SetPartition):
r"""
A perfect matching.
Expand Down Expand Up @@ -167,7 +169,7 @@ def __classcall_private__(cls, parts):
fixed point free involution
"""
if ((isinstance(parts, list) and
all((isinstance(x, (int, Integer)) for x in parts)))
all(isinstance(x, (int, Integer)) for x in parts))
or isinstance(parts, Permutation)):
s = Permutation(parts)
if not all(e == 2 for e in s.cycle_type()):
Expand Down Expand Up @@ -220,7 +222,7 @@ def _repr_(self):

def _latex_(self):
r"""
A latex representation of ``self`` using the tikzpicture package.
A latex representation of ``self`` using the ``tikzpicture`` package.
EXAMPLES::
Expand Down Expand Up @@ -266,7 +268,7 @@ def standardization(self):
[(1, 5), (2, 3), (4, 6)]
"""
P = PerfectMatchings(2*len(self))
P = PerfectMatchings(2 * len(self))
return P(SetPartition.standardization(self))

def partner(self, x):
Expand Down Expand Up @@ -415,7 +417,8 @@ def loop_type(self, other=None):
sage: m = PerfectMatching([]); m.loop_type()
[]
"""
return Partition(sorted((len(l) // 2 for l in self.loops_iterator(other)),
return Partition(sorted((len(l) // 2
for l in self.loops_iterator(other)),
reverse=True))

def number_of_loops(self, other=None):
Expand All @@ -441,7 +444,7 @@ def number_of_loops(self, other=None):
sage: m.number_of_loops(n)
2
"""
return Integer( len(list(self.loops_iterator(other))) )
return Integer(len(list(self.loops_iterator(other))))

def Weingarten_function(self, d, other=None):
r"""
Expand Down Expand Up @@ -514,12 +517,6 @@ def to_noncrossing_set_partition(self):
for i in range(len(perm) // 2)])
return SetPartition(perm2.cycle_tuples())

from sage.misc.superseded import deprecated_function_alias
to_non_crossing_set_partition = deprecated_function_alias(23982, to_noncrossing_set_partition)
is_non_crossing = deprecated_function_alias(23982, SetPartition.is_noncrossing)
is_non_nesting = deprecated_function_alias(23982, SetPartition.is_nonnesting)
conjugate_by_permutation = deprecated_function_alias(23982, SetPartition.apply_permutation)


class PerfectMatchings(SetPartitions_set):
r"""
Expand Down Expand Up @@ -558,7 +555,6 @@ class PerfectMatchings(SetPartitions_set):
Test that ``x = M.an_element()`` is actually a perfect matching::
sage: set([]).union(*x) == M.base_set()
True
sage: sum([len(a) for a in x]) == M.base_set().cardinality()
Expand Down Expand Up @@ -602,7 +598,7 @@ def __classcall_private__(cls, s):
True
"""
if isinstance(s, (int, Integer)):
s = frozenset(range(1, s+1))
s = frozenset(range(1, s + 1))
else:
try:
if s.cardinality() == infinity:
Expand Down Expand Up @@ -637,8 +633,9 @@ def __iter__(self):
return
# The iterator from fixed-point-free involutions has the resulting
# list of pairs sorted by their minimal element.
for val in perfect_matchings_iterator(len(s)//2):
yield self.element_class(self, ((s[a], s[b]) for a,b in val), check=False, sort=False)
for val in perfect_matchings_iterator(len(s) // 2):
yield self.element_class(self, ((s[a], s[b]) for a, b in val),
check=False, sort=False)

def __contains__(self, x):
"""
Expand Down Expand Up @@ -680,7 +677,7 @@ def __contains__(self, x):
return False

base_set = Set([e for p in x for e in p])
return len(base_set) == 2*len(x) and base_set == Set(self._set)
return len(base_set) == 2 * len(x) and base_set == Set(self._set)

def base_set(self):
"""
Expand Down Expand Up @@ -722,10 +719,10 @@ def cardinality(self):
1
"""
n = len(self._set)
if n % 2 == 1:
if n % 2:
return Integer(0)
else:
return Integer(prod(i for i in range(n) if i % 2 == 1))
return Integer(prod(range(1, n, 2)))

def random_element(self):
r"""
Expand All @@ -749,13 +746,14 @@ def random_element(self):
"""
n = len(self._set)

if n % 2 == 1:
if n % 2:
raise ValueError("there is no perfect matching on an odd number of elements")

k = n // 2
p = Permutations(n).random_element()
l = list(self._set)
return self.element_class(self, [(l[p[2*i]-1], l[p[2*i+1]-1]) for i in range(k)],
return self.element_class(self, [(l[p[2 * i] - 1], l[p[2 * i + 1] - 1])
for i in range(k)],
check=False)

@cached_method
Expand All @@ -764,7 +762,7 @@ def Weingarten_matrix(self, N):
Return the Weingarten matrix corresponding to the set of
PerfectMatchings ``self``.
It is a useful theoretical tool to compute polynomial integral
It is a useful theoretical tool to compute polynomial integrals
over the orthogonal group `O_N` (see [CM]_).
EXAMPLES::
Expand All @@ -780,4 +778,3 @@ def Weingarten_matrix(self, N):
return G**(-1)

Element = PerfectMatching

0 comments on commit 2c2790d

Please sign in to comment.