Perm

class permuta.demo.Perm(*args) → None

Bases: permuta.interfaces.Displayable.Displayable

A perm class.

That is, a perm(utation) class (in the python sense).

Its constructor attempts to interpret anything you throw at it as a perm, but it’s probably easiest for a beginner to stick to numbers or lists of numbers: e.g., Perm(1324) or Perm(1, 3, 2, 4).

Examples

>>> Perm()  # Empty perm
()
>>> Perm([])  # Another empty perm
()
>>> Perm(132)  # From number
(1, 3, 2)
>>> Perm(248)  # Attempted interpretation
(1, 2, 3)
>>> Perm("1234")  # From string
(1, 2, 3, 4)
>>> Perm("dcab")  # This is equivalent to ...
(4, 3, 1, 2)
>>> Perm(["d", "c", "a", "b"])  # ... this
(4, 3, 1, 2)
>>> Perm(0, 0, 2, 1)  # Index is tie-breaker
(1, 2, 4, 3)
>>> Perm("Ragnar", "Christian", "Henning")
(3, 1, 2)
>>> Perm.monotone_increasing(4)
(1, 2, 3, 4)
>>> Perm.monotone_decreasing(3)
(3, 2, 1)
>>> random_perm = Perm.random(7)
__add__(other: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the direct sum of the perms.

__call__(value: int) → int

Map value to its image defined by the perm.

__contains__(patt: permuta.demo._Perm.Perm) → bool

Return True if the perm contains the patt, else False.

__getitem__(key: typing.Union[int, slice]) → typing.Union[int, list]

Return the (list of) values at the one-based key specified.

__len__() → int

Return the length of the perm.

__lshift__(n: int) → permuta.demo._Perm.Perm

Return the perm shifted n steps to the left.

__mul__(other: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the composition of the perms.

__pow__(n: int) → permuta.demo._Perm.Perm

Return the perm to the n-th power.

__radd__(other: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the direct sum of the perms (reflected).

__rmul__(other: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the composition of the perms (reflected).

__rshift__(n: int) → permuta.demo._Perm.Perm

Return the perm shifted n steps to the right.

__rsub__(other: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the skew sum of the perms (reflected).

__sub__(other: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the skew sum of the perms.

apply(iterable: typing.Iterable[T]) → typing.List[T]

Permute an iterable using the perm.

ascents() → list

Return the indices of values where the next value is greater.

See also

total_ascents()

avoids(patt: permuta.demo._Perm.Perm) → bool

Return True if the perm avoids the patt, else False.

complement() → permuta.demo._Perm.Perm

Return the complement of the perm.

compose(perm: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the composition of the two perms.

contains(patt: permuta.demo._Perm.Perm) → bool

Return True if the perm contains the patt, else False.

cycle_decomposition() → list

Return the cycle decomposition of the perm.

cycles() → list

Return the cycle decomposition of the perm.

descents() → list

Return the indices of values where the next value is greater.

See also

total_descents()

direct_sum(perm: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the direct sum of the two perms.

See also

__add__()

display(via='browser')

Display the perm.

Parameters:via
export(output)
fixed_points() → list

Return the fixed points of the perm.

flip_antidiagonally() → permuta.demo._Perm.Perm

Return the perm flipped antidiagonally.

flip_diagonally() → permuta.demo._Perm.Perm

Return the perm flipped diagonally.

flip_horizontally() → permuta.demo._Perm.Perm

Return the perm flipped horizontally.

flip_vertically() → permuta.demo._Perm.Perm

Return the perm flipped vertically.

inverse() → permuta.demo._Perm.Perm

Return the inverse of the perm.

inversions() → list

Return the list of the inversions of the perm.

is_decreasing() → bool

Return True if the perm is decreasing, and False otherwise.

is_increasing() → bool

Return True if the perm is increasing, and False otherwise.

major_index() → int

Return the major index of the perm.

classmethod monotone_decreasing(length: int) → permuta.demo._Perm.Perm

Return a monotone decreasing perm of the specified length.

classmethod monotone_increasing(length: int) → permuta.demo._Perm.Perm

Return a monotone increasing perm of the specified length.

multiply(perm: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the composition of the two perms.

occurrence_indices_in(perm: permuta.demo._Perm.Perm) → list

Find all indices of occurrences of the patt self in perm.

occurrence_indices_of(patt: permuta.demo._Perm.Perm) → list

Find all indices of occurrences of patt in the perm self.

occurrences_in(perm: permuta.demo._Perm.Perm) → list

Find all occurrences of the patt self in perm.

occurrences_of(patt: permuta.demo._Perm.Perm) → list

Find all occurrences of patt in the perm self.

peaks() → list

Return the indices of the peaks of the perm.

See also

total_peaks()

plot(*, browser=False, filename=None, file_format=None, **kwargs)

Display or save the perm with seaborn/matplotlib.

Returns an Axes object or None if seaborn is unavailable.

Keyword Arguments:
 
  • browser – If True, sends the image to a browser for viewing.
  • filename – Where to save the image.
  • file_format – The file format if one wishes to force one.

Other keyword arguments are passed to seaborn.heatmap. The default keyword arguments passed are:

cbar=False cmap=”Greys” square=True vmax=1 vmin=0 xticklabels=False yticklabels=False
Tips:
Set the “xticklabels” kwarg as range(len(self)) for a labelled x-axis and the “yticklabels kwarg as range(len(self), -1, -1) for a labelled y-axis.
classmethod random(length: int) → permuta.demo._Perm.Perm

Return a random perm of the specified length.

reverse() → permuta.demo._Perm.Perm

Return the reverse of the perm.

reverse_complement() → permuta.demo._Perm.Perm

Return the reverse complement of the perm.

rotate_left(n: int = 1) → permuta.demo._Perm.Perm

Return the perm rotated n left.

rotate_right(n: int = 1) → permuta.demo._Perm.Perm

Return the perm rotated n right.

shift_down(n: int = 1) → permuta.demo._Perm.Perm

Return the perm shifted n steps down.

shift_left(n: int = 1) → permuta.demo._Perm.Perm

Return the perm shifted n steps to the left.

shift_right(n: int = 1) → permuta.demo._Perm.Perm

Return the perm shifted n steps to the right.

shift_up(n: int = 1) → permuta.demo._Perm.Perm

Return the perm shifted n steps up.

skew_sum(perm: permuta.demo._Perm.Perm) → permuta.demo._Perm.Perm

Return the skew sum of the two perms.

See also

__sub__()

total_ascents() → int

Return the number of ascents in the perm.

total_cycles() → int

Return the number of cycles in the perm.

total_descents() → int

Return the number of descents in the perm.

total_fixed_points() → int

Return the number of fixed points in the perm.

total_inversions() → int

Return the number of inversions in the perm.

total_peaks() → int

Return the number of peaks in the perm.

total_valleys() → int

Return the number of valleys in the perm.

valleys() → list

Return the indices of the valleys of the perm.

See also

total_valleys()