MeshPatt

class permuta.MeshPatt(pattern=Perm(()), shading=frozenset())

Bases: permuta.MeshPatt.MeshPatternBase, permuta.interfaces.Patt.Patt, permuta.interfaces.Rotatable.Rotatable, permuta.interfaces.Shiftable.Shiftable, permuta.interfaces.Flippable.Flippable

A mesh pattern class.

pattern

<permuta.Perm> The underlying classical pattern.

shading

frozenset The shading as a immutable set of coordinates, with lower-left as origin.

static __new__(pattern=Perm(()), shading=frozenset())

Return a MeshPatt instance.

Parameters:
  • cls – The class of which an instance is requested.
  • pattern – <permuta.Perm> or <collections.Iterable> An perm or an iterable corresponding to a legal perm.
  • shading – <collections.Iterable> An iterable of 2-tuples.
Raises:
  • TypeError – Bad argument type.
  • ValueError – Bad argument, but correct type.
add_decrease(pos)

Adds an decreasing pattern (1, 0) into the given coordinate.

Parameters:pos – tuple The coordinate of the position to insert (1, 0) into.
Returns: <permuta.MeshPatt>
The new pattern with the decreasing pattern inserted into pos.

Examples

>>> MeshPatt((0,)).add_decrease((0, 0))
MeshPatt(Perm((1, 0, 2)), frozenset())
>>> MeshPatt((0, 1, 2), [(1, 0), (2, 1), (3, 2)]).add_decrease((2, 0))
MeshPatt(Perm((2, 3, 1, 0, 4)), frozenset({(1, 2), (5, 4), (3, 3), (2, 3), (4, 3), (1, 0), (1, 1)}))
add_increase(pos)

Adds an increasing pattern (0, 1) into the given coordinate.

Parameters:pos – tuple The coordinate of the position to insert (0, 1) into.
Returns: <permuta.MeshPatt>
The new pattern with the increased pattern inserted into pos.

Examples

>>> MeshPatt((0,)).add_increase((0, 0))
MeshPatt(Perm((0, 1, 2)), frozenset())
>>> MeshPatt((0, 1, 2), [(1, 0), (2, 1), (3, 2)]).add_increase((2, 0))
MeshPatt(Perm((2, 3, 0, 1, 4)), frozenset({(1, 2), (5, 4), (3, 3), (2, 3), (4, 3), (1, 0), (1, 1)}))
add_point(pos, shade_dir=-1, safe=True)

Returns a mesh pattern with a point added in the box at position pos. If shade_dir is specified adds shading in that direction.

Parameters:
  • pos – tuple Coordinates corresponding to a box in the pattern.
  • shade_dir – int The direction which to shade within the box.
  • safe – bool, optional True to check if box must not be shaded.
Raises:
  • ValueError – Bad box argument, if it is already shaded.
  • TypeError – Bad argument type.
Returns: <permuta.MeshPatt>
The mesh pattern with a point added in pos.
all_symmetries()

Return the set of all symmetries of the mesh pattern.

Returns: <set>
All the symmetries of a mesh pattern.
can_shade(pos)

Returns whether it is possible to shade the box at position pos according to the Shading Lemma. Every direction is checked and the list of the values of the adjacent points to the box that can be used is returned.

Parameters:pos – tuple The position of the box to check.
Returns: list
The values of the points in the permutation adjacent to the box at pos that can be used to shade the box.

Examples

>>> MeshPatt((0,),[(0, 0)]).can_shade((1, 1))
[]
>>> MeshPatt((1, 2, 0), [(2,2),(3,0),(3,2),(3,3)]).can_shade((1, 2))
[1, 2]
can_shade2(pos1, pos2)

Returns whether it is possible to shade the boxes at positions pos1, pos2 according to the Shading Lemma. Every direction is checked and the list of the values of the adjacent points to the box that can be used is returned.

Parameters:
  • pos1 – tuple The position of the first box to check.
  • pos2 – tuple The position of the second box to check.
Returns: list
The values of the points in the permutation adjacent to the boxes at pos1 and pos2 that can be used to shade the box.

Examples:

can_simul_shade(pos1, pos2)

Returns whether it is possible to shade the boxes at positions pos1, pos2 according to the Shading Lemma. Every direction is checked and the list of the values of the adjacent points to the box that can be used is returned.

Parameters:
  • pos1 – tuple The position of the first box to check.
  • pos2 – tuple The position of the second box to check.
Returns: list
The values of the points in the permutation adjacent to the boxes at pos1 and pos2 that can be used to shade the box.

Examples:

complement()

Returns the complement of the mesh pattern, which has the complement of the underlying pattern and every shading flipped across the horizontal axis.

Returns: <permuta.MeshPatt>
The complement of the meshpatt.

Examples

>>> MeshPatt(Perm((0,)), frozenset({(0, 1)})).complement()
MeshPatt(Perm((0,)), frozenset({(0, 0)}))
>>> MeshPatt(Perm((0, 2, 1)), frozenset({(0, 1), (0, 0), (1, 0), (0, 2), (0, 3)})).complement()
MeshPatt(Perm((2, 0, 1)), frozenset({(0, 1), (1, 3), (0, 0), (0, 3), (0, 2)}))
flip_diagonal()

Return self flipped along the diagonal which is equivalent to the ‘inverse’ of the pattern.

Returns: <permuta.MeshPatt>
The ‘inverse’ of the meshpatt.

Examples

>>> MeshPatt(Perm((0,)), frozenset({(0, 1)})).inverse()
MeshPatt(Perm((0,)), frozenset({(1, 0)}))
flip_horizontal()

Return self flipped horizontally which is equivalent to the complement.

Returns: <permuta.MeshPatt>
The complement of the meshpatt.

Examples

>>> MeshPatt(Perm((0,)), frozenset({(0, 1)})).flip_horizontal()
MeshPatt(Perm((0,)), frozenset({(0, 0)}))
>>> MeshPatt(Perm((0, 2, 1)), frozenset({(0, 1), (0, 0), (1, 0), (0, 2), (0, 3)})).flip_horizontal()
MeshPatt(Perm((2, 0, 1)), frozenset({(0, 1), (1, 3), (0, 0), (0, 3), (0, 2)}))
flip_vertical()

Return self flipped vertically which is equivalent to the meshpatt reversed.

Returns: <permuta.MeshPatt>
The meshpatt reversed.

Examples

>>> MeshPatt(Perm((0,)), frozenset({(0, 1)})).flip_vertical()
MeshPatt(Perm((0,)), frozenset({(1, 1)}))
>>> MeshPatt(Perm((2, 1, 0)), frozenset({(3, 2), (3, 3), (0, 2), (2, 2), (1, 1)})).flip_vertical()
MeshPatt(Perm((0, 1, 2)), frozenset({(1, 2), (3, 2), (2, 1), (0, 3), (0, 2)}))
has_anchored_point()

Checks if the mesh pattern has any point anchored to the boundary. Returns a tuple (right, top, left, bottom) where each value represent whether the point is anchored to the corresponding direction.

Returns: tuple
Each boolean in the tuple tells whether the mesh pattern is anchored to the corresponding direction.

Examples

>>> MeshPatt(Perm((0, 1)), frozenset({(0, 0), (1, 0), (2, 0), (1, 1)})).has_anchored_point()
(False, False, False, True)
inverse()

Returns the inverse of the meshpatt, that is the meshpatt with the underlying classical pattern as the inverse and the shadings hold the same relation between the points. This is equivalent to flipping the pattern over the diagonal.

Returns: <permuta.MeshPatt>
The ‘inverse’ of the meshpatt.

Examples

>>> MeshPatt(Perm((0,)), frozenset({(0, 1)})).inverse()
MeshPatt(Perm((0,)), frozenset({(1, 0)}))
is_pointfree(lower_left, upper_right)

Check if a region in the grid has no points.

Parameters:
  • self – A mesh pattern.
  • lower_left – (int, int) A point coordinate of self.
  • upper_right – (int, int) A point coordinate of self.
Raises:

ValueError – Bad argument, but correct type.

Returns: bool
True if and only if all points self[x] for x in the range lower_left[0] + 1 to upper_right[0] - 1 (inclusive) have values less than lower_left[1] or greater than or equal to upper_right[1].
is_shaded(lower_left, upper_right=None)

Check if a region of the grid is shaded.

Parameters:
  • self – A mesh pattern.
  • lower_left – (int, int) A shading coordinate of self.
  • upper_right – (int, int) A shading coordinate of self.
Raises:

ValueError – Bad argument, but correct type.

Returns: bool
If upper_right is None, then True if and only if lower_left is shaded; otherwise, True if and only if all regions (x, y) for x in the range lower_left[0] to upper_right[0] (inclusive) and for y in the range lower_left[1] to upper_right[1] (inclusive) are shaded.
latex(scale=0.3)

Returns the LaTeX code for the TikZ figure of the mesh pattern. The LaTeX code requires the TikZ library ‘patterns’.

Parameters:scale – <numbers.Real> The scale of the image.
Returns: str
The LaTeX code for the TikZ figure of the pattern.
non_pointless_boxes()

Returns the coordinates of the boxes that have a point on their boundaries in one of their four corners.

Returns: set
The set of boxes with points in one of the corners.

Examples

>>> MeshPatt(Perm((0, 1)), frozenset({(0, 1), (2, 0), (0, 2)})).non_pointless_boxes()
{(0, 1), (1, 2), (0, 0), (2, 1), (2, 2), (1, 0), (1, 1)}
>>> MeshPatt(Perm((1, 0, 2)), frozenset({(1, 3), (3, 0), (0, 3), (0, 1), (1, 2), (3, 1), (2, 0), (1, 1)})).non_pointless_boxes()
{(1, 2), (0, 1), (3, 2), (3, 3), (0, 2), (2, 1), (2, 0), (2, 3), (2, 2), (1, 0), (1, 1)}
occurrences_in(perm)

Find all indices of occurrences of self in perm.

Parameters:
  • self – The mesh pattern whose occurrences are to be found.
  • perm – <permuta.Perm> The permutation to search for occurrences in.
Yields: numbers.Integral
The indices of the occurrences of self in perm. Each yielded element l is a list of integer indices of the permutation perm such that self.pattern == permuta.Perm.to_standard([perm[i] for i in l]) and that no element not in the occurrence falls within self.shading.
static random(length)

Return a random mesh pattern of the specified length.

Parameters:length – <numbers.Integral> The length of the random pattern.

Examples

>>> MeshPatt.random(1) in set(MeshPatt.unrank(Perm((0)), i) for i in range(0, 16))
True
>>> len(MeshPatt.random(4))
4
rank()

Computes the rank of the mesh pattern, the bit string of the shadings interpreted as an integer.

Returns: numbers.Integral
The rank of the mesh pattern.

Examples

>>> rank = MeshPatt(Perm((1, 0, 2)), frozenset({(0, 0), (3, 0), (0, 2), (2, 1), (2, 3), (1, 2), (3, 3), (3, 1), (1, 1)})).rank()
>>> rank
47717
>>> bin(rank)
'0b1011101001100101'
reverse()

Returns the reversed mesh patterns, which has the underlying pattern reversed and every shading flipped across the vertical axis.

Returns: <permuta.MeshPatt>
The meshpatt reversed.

Examples

>>> MeshPatt(Perm((0,)), frozenset({(0, 1)})).reverse()
MeshPatt(Perm((0,)), frozenset({(1, 1)}))
>>> MeshPatt(Perm((2, 1, 0)), frozenset({(3, 2), (3, 3), (0, 2), (2, 2), (1, 1)})).reverse()
MeshPatt(Perm((0, 1, 2)), frozenset({(1, 2), (3, 2), (2, 1), (0, 3), (0, 2)}))
shadable_boxes()

Returns a dictionary of all tuples of shadable boxes with the shading lemma, with the keys as the points used to shade the tuples of boxes.

Returns: dict
Dictionary with keys as points and values as tuples of boxes.

Examples: >>> dict(MeshPatt(Perm((0, 3, 1, 2)), frozenset({(3, 2), (3, 0), (4, 2), (1, 0), (0, 3), (1, 2), (2, 0), (0, 4), (0, 2)})).shadable_boxes()) {0: [((0, 0),)], 3: [((1, 3),), ((1, 3), (1, 4)), ((1, 4),)], 1: [((2, 2),)]}

shade(positions)

Returns the mesh pattern with the added shadings given by positions.

Parameters:positions – tuple or <collections.Iterable> The shading given as a single coordinate or as an iterable of coordinates.
Raises:ValueError – Bad argument, but correct type.
Returns: <permuta.MeshPatt>
The new meshpatt with the added shadings.
sub_mesh_pattern(indices)

Return the mesh pattern induced by indices.

Parameters:indices – <collections.Iterable> of <numbers.Integral> A list of unique indices of elements in self.
Returns: <permuta.MeshPattern>
A mesh pattern where the pattern is the permutation induced by the indices and a region is shaded if and only if the corresponding region of self is fully shaded.
Exampes:
>>> shading = frozenset({(3, 2), (1, 3), (4, 2), (0, 3), (1, 2), (4, 3), (3, 4), (4, 1)})
>>> MeshPatt(Perm((3, 2, 1, 0)), shading).sub_mesh_pattern((0, 1, 3))
MeshPatt(Perm((2, 1, 0)), frozenset({(1, 2), (3, 2), (3, 1), (0, 2)}))
>>> MeshPatt(Perm((2, 3, 1, 0)), shading).sub_mesh_pattern((1, 2, 3))
MeshPatt(Perm((2, 1, 0)), frozenset({(3, 2), (3, 1), (2, 3)}))
static unrank(pattern, number)

Return the number-th shading of pattern.

Parameters:
  • pattern – <permuta.Perm> or <collections.Iterable> An perm or an iterable corresponding to a legal perm.
  • number – <numbers.Integral> An integer of which binary representation corresponds to a legal shading.
Raises:
  • TypeError – Bad argument type.
  • ValueError – Bad argument, but correct type.

Examples

>>> bin(22563)
'0b101100000100011'
>>> MeshPatt.unrank((0, 1, 2), 22563)
MeshPatt(Perm((0, 1, 2)), frozenset({(0, 1), (3, 2), (0, 0), (3, 0), (2, 3), (1, 1)}))