Skip to content

Commit

Permalink
Fixed linter workflow, fixed bad type hint.
Browse files Browse the repository at this point in the history
Signed-off-by: Dashiell Stander <[email protected]>
  • Loading branch information
dashstander committed Sep 24, 2024
1 parent 684bf71 commit bf840ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Python Setup Rye
- name: Python Setup Rye
uses: eifinger/[email protected]
with:
enable-cache: true
Expand Down
26 changes: 22 additions & 4 deletions src/algebraist/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from itertools import chain
from math import factorial
from operator import mul
from typing import Iterator, Self, Sequence
from typing import Iterator, Sequence


def check_partition_shape(partition_shape: tuple[int, ...]) -> bool:
"""
Checks that a given shape defines a correct partition, in particular that is in decreasing order.
Args:
partition_shape (tuple[int]): the partition of n
partition_shape (tuple[int, ...]): the partition of n
Returns:
bool True if valid, False otherwise
"""
Expand All @@ -22,6 +22,15 @@ def check_partition_shape(partition_shape: tuple[int, ...]) -> bool:


def youngs_lattice_covering_relation(partition: tuple[int, ...]) -> list[tuple[int, ...]]:
"""
Takes a partition and returns a list of the partitions directly below it in Young's lattice.
Args:
partititon (tuple[int, ...]): an integer partition of n
Returns:
list[tuple[int, ...]] all of the partitions directly beneath partition
"""
children = []
for i in range(len(partition)):
if partition[i] > (partition[i+1] if i+1 < len(partition) else 0):
Expand All @@ -34,6 +43,9 @@ def youngs_lattice_covering_relation(partition: tuple[int, ...]) -> list[tuple[i


def youngs_lattice_down(top_partition: tuple[int, ...]) -> dict[tuple[int, ...], list[tuple[int, ...]]]:
"""
Generate the sub-lattice of Young's lattice from top_partition to (1,)
"""
lattice = {}
queue = deque([top_partition])
while queue:
Expand All @@ -47,7 +59,12 @@ def youngs_lattice_down(top_partition: tuple[int, ...]) -> dict[tuple[int, ...],


def generate_standard_young_tableaux(shape: tuple[int, ...]) -> list[list[list[int]]]:
n = sum(shape) - 1 # Adjust for 0-indexing
"""
A standard Young Tableau is a filling of a tableau lambda with the values 0...n-1 where the values are increasing from left to right in each row and top to bottom in each column. This function generates all of them for a given shape.
The standard Young Tableau for a given partition lambda are one-to-one with chains in the sub-lattice of Young's lattice from [(1,), lambda]. Here we generate the sub-lattice and then generate each chain.
"""
n = sum(shape) - 1
lattice = youngs_lattice_down(shape)

def backtrack(partition: tuple[int], value: int) -> Iterator[list[list[int]]]:
Expand All @@ -68,6 +85,7 @@ def backtrack(partition: tuple[int], value: int) -> Iterator[list[list[int]]]:

return backtrack(shape, n)


@cache
def generate_partitions(n: int) -> Sequence[tuple[int, ...]]:
if n <= 5:
Expand Down Expand Up @@ -165,7 +183,7 @@ def __lt__(self, other) -> bool:
else:
return self_n_index < other_n_index

def restrict(self) -> YoungTableau:
def restrict(self):
return YoungTableau([[v for v in row if v != self.n - 1] for row in self.values])

def restricted_shape(self) -> tuple[int, ...]:
Expand Down

0 comments on commit bf840ea

Please sign in to comment.