From e316f53c363ca96c87e24d8f41698473894125aa Mon Sep 17 00:00:00 2001 From: Michael Engen Date: Sun, 5 Nov 2023 21:34:08 -0500 Subject: [PATCH] Min size downset (#56) * Added min_length to permutation * Added small test * Removed file * Corrected downset --- src/permpy/permset.py | 2 +- src/permpy/permutation.py | 7 +++---- tests/test_permutation.py | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/permpy/permset.py b/src/permpy/permset.py index 49b38f0..3d879a6 100644 --- a/src/permpy/permset.py +++ b/src/permpy/permset.py @@ -172,7 +172,7 @@ def upset(self, up_to_length): return upset - def downset(self): + def downset(self, min_size): """Return the downset of `self` as a list.""" bottom_edge = PermSet() bottom_edge.update(self) diff --git a/src/permpy/permutation.py b/src/permpy/permutation.py index fd0800b..0e72e24 100644 --- a/src/permpy/permutation.py +++ b/src/permpy/permutation.py @@ -1049,11 +1049,11 @@ def downset(self, min_length=0): else: new_perms[tau] = i - downset.append(set(new_perms)) + downset.append(set(new_perms.keys())) return downset[::-1] - def downset_profile(self): + def downset_profile(self, min_length=0): """Return the downset profile of self. Notes @@ -1065,7 +1065,7 @@ def downset_profile(self): # downset = [set([pi])] profile = [len(new_perms)] - for new_length in range(len(self) - 1, -1, -1): + for new_length in range(len(self) - 1, min_length - 1, -1): old_perms = new_perms new_perms = dict() @@ -1077,7 +1077,6 @@ def downset_profile(self): else: new_perms[tau] = i - # downset.append(new_perms) profile.append(len(new_perms)) return profile[::-1] diff --git a/tests/test_permutation.py b/tests/test_permutation.py index 08fb800..ecb4450 100644 --- a/tests/test_permutation.py +++ b/tests/test_permutation.py @@ -40,7 +40,7 @@ def test_direct_sum(): (q, q): Perm(31247568), (q, r): Perm(31245), } - for ((r, s), intended) in cases.items(): + for (r, s), intended in cases.items(): direct_sum = r + s assert direct_sum == intended, ( f"Expected the direct sum of {r} and {s} to be {intended}," @@ -59,7 +59,7 @@ def test_skew_sum(): (q, q): Perm(75683124), (q, r): Perm(42351), } - for ((r, s), intended) in cases.items(): + for (r, s), intended in cases.items(): skew_sum = r - s assert skew_sum == intended, ( f"Expected the skew sum of {r} and {s} to be {intended}," @@ -120,7 +120,7 @@ def test_containment(): def test_pow(): p = Perm(12345) for n in range(-5, 0, 5): - result = p ** n + result = p**n assert p == result, ( f"The identity permutation raised to the power {n}" f" resulted in {result}, not the identity permutation." @@ -129,7 +129,7 @@ def test_pow(): q = Perm(41352) powers = [Perm(12345), q, Perm(54321), Perm(25314), Perm(12345)] for exp, val in enumerate(powers): - assert q ** exp == val, f"Perm({q})^{exp} should be {val}, but it's {q**exp}!" + assert q**exp == val, f"Perm({q})^{exp} should be {val}, but it's {q**exp}!" def test_perm_to_ind(): @@ -448,3 +448,14 @@ def test_involved_in(): assert ( result == expected ), f"Perm({p}).involved_in({q}) is {result}, but it should be {expected}." + + +def test_involved_in(): + cases = [ + (Perm(123), [set([Perm()]), set([Perm(1)]), set([Perm(12)]), set([Perm(123)])]), + ] + for perm, expected in cases: + result = perm.downset() + assert ( + result == expected + ), f"Perm({perm}).downset() is {result}, but it should be {expected}."