Skip to content

Commit

Permalink
Min size downset (#56)
Browse files Browse the repository at this point in the history
* Added min_length to permutation

* Added small test

* Removed file

* Corrected downset
  • Loading branch information
engenmt authored Nov 6, 2023
1 parent 7eba9f5 commit e316f53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/permpy/permset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/permpy/permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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]
Expand Down
19 changes: 15 additions & 4 deletions tests/test_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},"
Expand All @@ -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},"
Expand Down Expand Up @@ -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."
Expand All @@ -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():
Expand Down Expand Up @@ -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}."

0 comments on commit e316f53

Please sign in to comment.