Skip to content

Commit

Permalink
Merge e7e2f88 into f98cf5f
Browse files Browse the repository at this point in the history
  • Loading branch information
enadeau committed Jun 5, 2019
2 parents f98cf5f + e7e2f88 commit 10b1a15
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- The ascii_plot, and to_tikz method in MeshPatt
### Removed
- The broken latex method in MeshPatt
### Fixed
- Wrong examples in the README. README.rst is now tested

## [1.0.0] - 2019-04-15
### Added
Expand Down
36 changes: 22 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ permuta
:target: https://pypi.python.org/pypi/Permuta
.. image:: https://img.shields.io/pypi/pyversions/Permuta.svg
:target: https://pypi.python.org/pypi/Permuta
.. image:: http://img.shields.io/badge/readme-tested-brightgreen.svg
:alt: Travis
:target: https://travis-ci.org/PermutaTriangle/Permuta

Permuta is a Python library for working with perms (short for permutations),
patterns, and mesh patterns.
Expand Down Expand Up @@ -73,10 +76,16 @@ Permutations are zero-based in Permuta and can be created using any iterable.
>>> Perm((2, 1, 3)) # Warning: it will initialise with any iterable
Perm((2, 1, 3))
>>> Perm((2, 1, 3), check=True) # If you are unsure, you can check
Traceback (most recent call last):
...
ValueError: Element out of range: 3
>>> Perm((4, 2, 3, 0, 0), check=True)
Traceback (most recent call last):
...
ValueError: Duplicate element: 0
>>> Perm("123", check=True)
Traceback (most recent call last):
...
TypeError: ''1'' object is not an integer
Permutations can also be created using some specific class methods.
Expand Down Expand Up @@ -104,23 +113,22 @@ Printing perms gives zero-based strings.
ε
>>> print(Perm((2, 1, 0)))
210
>>> print(Perm((6, 2, 10, 9, 3, 8, 0, 1, 5, 11, 4, 7))
>>> print(Perm((6, 2, 10, 9, 3, 8, 0, 1, 5, 11, 4, 7)))
62(10)938015(11)47
The avoids, contains, and occurrence methods enable working with patterns:

.. code-block:: python
>>> p = Perm((0,2,1,3))
Perm((0,2,1,3))
>>> p.contains(Perm((2, 1, 0)))
False
>>> p.avoids(Perm((0, 1)))
False
>>> p.occurrences_of(Perm((1, 0)))
[[3, 2]]
>>> Perm((0, 1)).occurrences_in(p)
[[1, 3], [1, 2], [1, 4], [3, 4], [2, 4]]
>>> list(p.occurrences_of(Perm((1, 0))))
[(1, 2)]
>>> list(Perm((0, 1)).occurrences_in(p))
[(0, 1), (0, 2), (0, 3), (1, 3), (2, 3)]
The basic symmetries are implemented:

Expand All @@ -137,7 +145,7 @@ To take direct sums and skew sums we use ``+`` and ``-``:
>>> p + q
Perm((0, 2, 1, 3, 4, 5, 6, 7, 8))
>>> p - q
Perm((4, 5, 6, 7, 8, 0, 2, 1, 3))
Perm((5, 7, 6, 8, 0, 1, 2, 3, 4))
There are numerous practical methods available:

Expand Down Expand Up @@ -189,11 +197,11 @@ You can get the n-th perm of the class or iterate:

.. code-block:: python
>> [perm_class[n] for n in range(10)]
[Perm(()), Perm((0,)), Perm((1, 0)), Perm((0, 1)), Perm((2, 1, 0)), Perm((2, 0, 1)), Perm((0, 2, 1)), Perm((0, 1, 2)), Perm((3, 2, 1, 0)), Perm((3, 2, 0, 1))]
>>> sorted([perm_class[n] for n in range(8)])
[Perm(()), Perm((0,)), Perm((0, 1)), Perm((1, 0)), Perm((0, 1, 2)), Perm((0, 2, 1)), Perm((2, 0, 1)), Perm((2, 1, 0))]
>>> perm_class_iter = iter(perm_class)
>>> [next(perm_class_iter) for _ in range(10)]
[Perm(()), Perm((0,)), Perm((1, 0)), Perm((0, 1)), Perm((2, 1, 0)), Perm((2, 0, 1)), Perm((0, 2, 1)), Perm((0, 1, 2)), Perm((3, 2, 1, 0)), Perm((3, 2, 0, 1))]
>>> sorted([next(perm_class_iter) for _ in range(8)])
[Perm(()), Perm((0,)), Perm((0, 1)), Perm((1, 0)), Perm((0, 1, 2)), Perm((0, 2, 1)), Perm((2, 0, 1)), Perm((2, 1, 0))]
(BEWARE: Lexicographic order is not guaranteed at the moment!)

Expand All @@ -206,7 +214,7 @@ You can define a subset of perms of a specific length in the perm class:
>>> perm_class_14 = perm_class.of_length(14)
>>> perm_class_14
<PermSet of all perms of length 14 avoiding {102, 120}>
Av((Perm((1, 0, 2)), Perm((1, 2, 0)))).of_length(14)
You can ask for the size of the subset because it is guaranteed to be finite:

Expand All @@ -226,8 +234,8 @@ but indexing has yet to be implemented:
True
>>> Perm(range(10)) - Perm(range(4)) in perm_class_14
False
>>> next(iter(perm_class_14))
Perm((13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
>>> next(iter(perm_class_14)) in perm_class_14
True
License
#######
Expand Down
6 changes: 6 additions & 0 deletions permuta/perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,12 @@ def __str__(self):
return "".join(str(i) if i < 10 else '({})'.format(i) for i in self)

def __lt__(self, other):
"""
>>> p1 = Perm((0,1,2,3))
>>> p2 = Perm((0,1,2))
>>> p2 <= p1
True
"""
return (len(self), tuple(self)) < (len(other), tuple(other))

def __le__(self, other):
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
test=pytest

[tool:pytest]
addopts = --verbose --pep8 --isort --doctest-modules --doctest-ignore-import-errors
testpaths = tests permuta
addopts = --verbose --pep8 --isort --doctest-modules --doctest-ignore-import-errors
testpaths = tests permuta README.rst
pep8ignore =
tests/* ALL
isort_ignore = tests/*

0 comments on commit 10b1a15

Please sign in to comment.