Skip to content

Commit

Permalink
Merge pull request #195 from PermutaTriangle/develop
Browse files Browse the repository at this point in the history
Version 2.3.0
  • Loading branch information
christianbean authored Mar 4, 2024
2 parents 1fb948a + 32cfb32 commit 7dd8f87
Show file tree
Hide file tree
Showing 29 changed files with 453 additions and 1,329 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: "3.10"
- name: install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
35 changes: 19 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ jobs:
fail-fast: false
matrix:
include:
- python: 3.8
- python: "3.11"
toxenv: flake8
os: ubuntu-latest
- python: 3.8
- python: "3.11"
toxenv: mypy
os: ubuntu-latest
- python: 3.8
- python: "3.11"
toxenv: pylint
os: ubuntu-latest
- python: 3.8
- python: "3.11"
toxenv: black
os: ubuntu-latest

- python: 3.7
toxenv: py37
os: ubuntu-latest
- python: 3.8
toxenv: py38
os: ubuntu-latest
Expand All @@ -34,25 +31,31 @@ jobs:
- python: "3.10"
toxenv: py310
os: ubuntu-latest
- python: pypy-3.7
toxenv: pypy37
- python: "3.11"
toxenv: py311
os: ubuntu-latest
- python: "3.12"
toxenv: py312
os: ubuntu-latest
- python: 'pypy3.9'
toxenv: pypy39
os: ubuntu-latest

- python: 3.8
toxenv: py38
- python: "3.11"
toxenv: py311
os: macos-latest
- python: 3.8
toxenv: py38
- python: "3.11"
toxenv: py311
os: windows-latest

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: install dependencies
run: python -m pip install --upgrade pip tox
run: python -m pip install --upgrade pip tox setuptools wheel
- name: run
env:
TOXENV: ${{ matrix.toxenv }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 21.9b0
rev: 22.10.0
hooks:
- id: black
3 changes: 1 addition & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ ignore-patterns=test_.*?py,
bisc_subfunctions.py
ignore= tests
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc())+'/permuta')"
disable=bad-continuation,
missing-module-docstring,
disable=missing-module-docstring,
fixme,
unsubscriptable-object,
unspecified-encoding
Expand Down
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
## Unreleased

## 2.3.0 - 2024-04-03
### Changed
- Updated dependency on automata-lib to version 7.0.1
- Perm.avoids/contains will raise a TypeError if input is not an iterable of Patt

### Added
- Now testing on Python 3.11
- 'simple' to the permtool command for checking if finitely many simples in a class

### Fixed
- bug in autobisc during setup

## 2.2.0 - 2021-10-21
### Added
Expand All @@ -29,6 +41,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Functions for ascents and descents now take an optional argument to specify what step size to calculate.
- Moved sorting functions from `permuta/bisc/perm_properties.py` to `permuta/patterns/perm.py`.
- If you pass an iterable (that is not a perm) to a contains method, then it will now raise an error.
These should be passed with the splat '*'.

## 2.0.3 - 2021-04-28
### Added
Expand Down
28 changes: 24 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ permuta
.. image:: https://requires.io/github/PermutaTriangle/Permuta/requirements.svg?branch=master
:target: https://requires.io/github/PermutaTriangle/Permuta/requirements/?branch=master
:alt: Requirements Status
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4725759.svg
:target: https://doi.org/10.5281/zenodo.4725759
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4725758.svg
:target: https://doi.org/10.5281/zenodo.4725758

Permuta is a Python library for working with perms (short for permutations),
patterns, and mesh patterns.
Expand Down Expand Up @@ -114,6 +114,21 @@ Printing perms gives zero-based strings.
>>> print(Perm((6, 2, 10, 9, 3, 8, 0, 1, 5, 11, 4, 7)))
(6)(2)(10)(9)(3)(8)(0)(1)(5)(11)(4)(7)
To get an iterator of all permutations of a certain length you can use

.. code-block:: python
>>> Perms4 = Perm.of_length(4)
You can run a for-loop over this iterator if you need to do something with all
the permutations of this size. If you just want a specific permutation of this
size you might be better off using the unrank function.

.. code-block:: python
>>> Perm.unrank(23,4)
Perm((3, 2, 1, 0))
The avoids, contains, and occurrence methods enable working with patterns:

.. code-block:: python
Expand Down Expand Up @@ -206,6 +221,11 @@ given class.
>>> for strat in find_strategies(basis):
... print(strat.reference())
Enumeration of Permutation Classes and Weighted Labelled Independent Sets: Corollary 4.3
>>> basis = [Perm((1, 3, 0, 2)), Perm((2, 0, 3, 1))]
>>> for strat in find_strategies(basis):
... print(strat.reference())
Enumeration of Permutation Classes and Weighted Labelled Independent Sets: Corollary 4.6
The class contains only finitely many simple permutations
Permutation statistics
######################
Expand Down Expand Up @@ -506,6 +526,6 @@ Citing
If you found this library helpful with your research and would like to cite us,
you can use the following `BibTeX`_ or go to `Zenodo`_ for alternative formats.

.. _BibTex: https://zenodo.org/record/4725759/export/hx#.YImTibX7SUk
.. _BibTex: https://zenodo.org/record/4945792/export/hx#.YImTibX7SUk

.. _Zenodo: https://doi.org/10.5281/zenodo.4725759
.. _Zenodo: https://doi.org/10.5281/zenodo.4725758
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[mypy]
check_untyped_defs = True
warn_return_any = True
warn_unused_configs = True
warn_no_return = False
Expand Down
2 changes: 1 addition & 1 deletion permuta/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .patterns import BivincularPatt, CovincularPatt, MeshPatt, Perm, VincularPatt
from .perm_sets.permset import Av, Basis, MeshBasis

__version__ = "2.2.0"
__version__ = "2.3.0"

__all__ = [
"Perm",
Expand Down
2 changes: 2 additions & 0 deletions permuta/bisc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# type: ignore

from .bisc import auto_bisc, bisc, create_bisc_input, read_bisc_file, write_bisc_files
from .bisc_subfunctions import (
patterns_suffice_for_bad,
Expand Down
15 changes: 7 additions & 8 deletions permuta/bisc/bisc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# type: ignore

import json
import os
import types
Expand All @@ -17,7 +19,6 @@


def bisc(A, m, n=None, report=False):

if isinstance(A, list):
D = defaultdict(list)
for perm in A:
Expand Down Expand Up @@ -54,7 +55,6 @@ def bisc(A, m, n=None, report=False):


def auto_bisc(prop):

L = 8 # Want to sanity check on at least S8, and one above n
n = 4
m = 2
Expand All @@ -69,10 +69,10 @@ def auto_bisc(prop):
if L not in A.keys():
print("You should have permutations up to length at least 8")
return
for i in range(L + 1):
for perm in Perm.of_length(i):
if perm not in A[i]:
B[i].append(perm)
for i in range(max(L + 1, max(A.keys()) + 1)):
if i > 7:
print("Populating the dictionary of bad perms of length ", i)
B[i] = [perm for perm in Perm.of_length(i) if perm not in A[i]]

elif isinstance(prop, types.FunctionType):
# If a property is passed in then we use it to populate both
Expand Down Expand Up @@ -212,7 +212,7 @@ def auto_bisc(prop):
oldL = L
if L < n + 1:
L = n + 1
if isinstance(prop, list) and L > max(A.keys):
if isinstance(prop, list) and L > max(A.keys()):
print("You need to input a longer list of permutations")
return

Expand Down Expand Up @@ -272,7 +272,6 @@ def create_bisc_input(N, prop):
A, B = {}, {}

for n in range(N + 1):

An, Bn = [], []

for perm in Perm.of_length(n):
Expand Down
18 changes: 10 additions & 8 deletions permuta/bisc/bisc_subfunctions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# type: ignore

from itertools import chain
from math import factorial

Expand Down Expand Up @@ -80,20 +82,20 @@ def add_good_shadings_to_goodpatts(perm, shading, loc, min_len, max_patt_len):

for i in range(loc, min(max_patt_len + 1, L)):

newPerm = []
newPermList = []
for j in chain(range(i), range(i + 1, L)):
if perm[j] > perm[i]:
newPerm.append(perm[j] - 1)
newPermList.append(perm[j] - 1)
else:
newPerm.append(perm[j])
nL = len(newPerm)
newPerm = Perm(newPerm)
newPermList.append(perm[j])
nL = len(newPermList)
newPerm = Perm(newPermList)

newShading = [
newShadingList = [
(sh[0] - (sh[0] > i), sh[1] - (sh[1] > perm[i])) for sh in shading
]
newShading.append((i, perm[i]))
newShading = set(newShading)
newShadingList.append((i, perm[i]))
newShading = set(newShadingList)

if nL <= max_patt_len:

Expand Down
2 changes: 1 addition & 1 deletion permuta/bisc/perm_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def baxter(perm: Perm) -> bool:

def simsun(perm: Perm) -> bool:
"""Returns true if the perm is a simsun permutation."""
return perm.avoids(*_SIMSUN_PATT)
return perm.avoids(_SIMSUN_PATT)


def dihedral(perm: Perm) -> bool:
Expand Down
23 changes: 21 additions & 2 deletions permuta/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import signal
import sys
import types
from typing import Any, Optional

from permuta import Av, Basis
from permuta.permutils import InsertionEncodablePerms, PolyPerms, lex_min


def sigint_handler(sig: int, _frame: types.FrameType) -> None:
def sigint_handler(sig: int, _frame: Optional[types.FrameType]) -> Any:
"""For terminating infinite task."""
if sig == signal.SIGINT:
print("\nExiting.")
Expand Down Expand Up @@ -50,10 +51,20 @@ def has_poly_growth(args: argparse.Namespace) -> None:
print(f"Av({basis}) is {'' if poly else 'not '}polynomial")


def has_finitely_many_simples(args: argparse.Namespace) -> None:
"""Check if a perm class has finitely many simples."""
basis = Basis.from_string(args.basis)
perm_class = Av(basis)
if perm_class.has_finitely_many_simples():
print(f"The class {perm_class} has finitely many simples.")
else:
print(f"The class {perm_class} has infinitely many simples")


def get_parser() -> argparse.ArgumentParser:
"""Construct and return parser."""
basis_str: str = (
"The basis as a string where the permutations are separated any token, "
"The basis as a string where the permutations are separated by any token, "
"(e.g. '231_4321', '0132:43210')"
)

Expand Down Expand Up @@ -96,6 +107,14 @@ def get_parser() -> argparse.ArgumentParser:
poly_parser.set_defaults(func=has_poly_growth)
poly_parser.add_argument("basis", help=basis_str)

# The simples command
simple_parser: argparse.ArgumentParser = subparsers.add_parser(
"simple",
description="A tool to check if a permutation class has finitely many simples.",
)
simple_parser.set_defaults(func=has_finitely_many_simples)
simple_parser.add_argument("basis", help=basis_str)

return parser


Expand Down
3 changes: 1 addition & 2 deletions permuta/enumeration_strategies/core_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def reference(cls) -> str:
)

@property
@staticmethod
def corr_number() -> str:
def corr_number(self) -> str:
"""The number of the corollary in the that gives this strategy."""
raise NotImplementedError

Expand Down
2 changes: 1 addition & 1 deletion permuta/misc/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def is_prime(n: int) -> bool:
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i ** 2 <= n:
while i**2 <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
Expand Down
Loading

0 comments on commit 7dd8f87

Please sign in to comment.