
    \hX                     b#   S SK Jr  S SKJr  S SKJrJrJr  S SK	J
r
  S SKJrJrJr  S SKJr  \R"                  r " S S\5      rS	 r\" \" S S
SS5      \" \" S S
S5      \" S SS5      \" S S
S5      \" S
SS5      5      \" \" S
SS5      \" S5      " S S
S5      \" S SS5      \" S SS
5      \" S S
5      " SS5      \" S S5      " S
S5      \" S S5      " S
S5      5      5      r\" \" S S
SSSSSS5      \" \" S S
SS5      \" S S
SS5      \" S
SSS5      \" SSSS5      \" S SSS5      \" SSSS5      5      \" \" S S
SS5      " SSSS5      \" S SSS
5      " SSSS5      \" S SSS5      " S
SSS5      \" S S
5      " SS5      " SS5      " SS5      \" S S5      " S
S5      " SS5      " SS5      \" S S5      " S
S5      " SS5      " SS5      \" S S5      " S
S5      " SS5      " SS5      \" S S5      " S
S5      " SS5      " SS5      \" S S5      " S
S5      " SS5      " SS5      \" S
SS5      " SSS5      \" S5      " S SS5      " SSS5      \" S SS5      " S
SS5      \" S SS5      " S
SS5      5      5      r\" \" S S
SSSS5      \" \" S S
S5      \" S SS5      \" S SS5      \" S S
S5      \" S
SS5      \" SSS5      \" SSS5      \" S
SS5      5      \" \" S5      " S
SSS5      \" S SSS5      \" S S
SS5      \" S S
5      " SS5      " SS5      \" S S5      " S
S5      " SS5      \" S S5      " S
S5      " SS5      \" S S5      " S
S5      " SS5      \" S S5      " S
S5      " SS5      \" S S5      " S
S5      " SS5      \" S SS
5      " SSS5      \" S S
S5      " SSS5      \" S SS5      " S
SS5      \" S SS5      " S
SS5      5      5      r\" \" S S
SSSSSSSSSSSSSSSSSS5      \" \" S S
SSS5      \" S S
SSS5      \" S
SSSS5      \" SSSSS5      \" SSSSS5      \" S SSSS5      \" SSSSS5      \" SSSSS5      \" SSSSS5      \" SSSSS5      \" SSSSS5      \" SSSSS5      5      \" / \" S S
SSS5      " SSSSS5      " SSSSS5      " SSSSS5      P\" S SSSS
5      " SSSSS5      " SSSSS5      " SSSSS5      P\" S SSSS5      " S
SSSS5      " SSSSS5      " SSSSS5      P\" S SSSS5      " S
SSSS5      " SSSSS5      " SSSSS5      P\" S SSSS5      " S
SSSS5      " SSSSS5      " SSSSS5      P\" S SSSS5      " S
SSSS5      " SSSSS5      " SSSSS5      P\" S S
5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S5      " S SS5      " SSS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      " SSS5      " SSS5      P76 5      r\" \" S S
SSSSSSSSSS5      \" \" S S
S5      \" S SS5      \" S SS5      \" S SS5      \" S S
S5      \" S
SS5      \" S
SS5      \" SSS5      \" SSS5      \" SSS5      \" SSS5      \" SSS5      \" SSS5      \" SSS5      \" S
SS5      \" SSS5      \" SSS5      \" SSS5      \" SSS5      \" SSS5      5      \" / \" S5      " S
SSSS5      " SSSSS5      P\" S SSSS5      " SSSSS5      P\" S S
SSS5      " SSSSS5      P\" S SSSS5      " S
SSSS5      P\" S SSSS5      " S
SSSS5      P\" S SSSS
5      " SSSSS5      P\" S S
5      " SS5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S S5      " S
S5      " SS5      " SS5      " SS5      " SS5      P\" S SS
5      " SSS5      " SSS5      " SSS5      P\" S S
S5      " SSS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P\" S SS5      " S
SS5      " SSS5      " SSS5      P76 5      r\R2                   V s/ s H  n \" U 5      PM     sn r\R2                   V s/ s H  n \" U 5      PM     sn r\R2                   V s/ s H  n \" U 5      PM     sn r\R2                   V s/ s H  n \" U 5      PM     sn r\R2                   V s/ s H  n \" U 5      PM     sn rgs  sn f s  sn f s  sn f s  sn f s  sn f )    )Permutation)PermutationGroup)BasicTupledefault_sort_key)	FiniteSet)minlex	unflattenflatten)as_intc                       \ rS rSrSrSrSS jr\S 5       r\r	\S 5       r
\S 5       r\S 5       r\S	 5       r\S
 5       r\S 5       rS rS rSrg)
Polyhedron   a  
Represents the polyhedral symmetry group (PSG).

Explanation
===========

The PSG is one of the symmetry groups of the Platonic solids.
There are three polyhedral groups: the tetrahedral group
of order 12, the octahedral group of order 24, and the
icosahedral group of order 60.

All doctests have been given in the docstring of the
constructor of the object.

References
==========

.. [1] https://mathworld.wolfram.com/PolyhedralGroup.html

Nc           	         U Vs/ s H  n[        US[        S9PM     nnXU4 Vs/ s H  n[        U6 PM     sn=u  pp6[        R                  " U /UQ76 n[        U5      Ul        [        U6 Ul        U(       a'  US   R                  [        U5      :w  a  [        S5      e[        U=(       d    [        [        [        U5      5      5      /5      Ul        U$ s  snf s  snf )aw)  
The constructor of the Polyhedron group object.

Explanation
===========

It takes up to three parameters: the corners, faces, and
allowed transformations.

The corners/vertices are entered as a list of arbitrary
expressions that are used to identify each vertex.

The faces are entered as a list of tuples of indices; a tuple
of indices identifies the vertices which define the face. They
should be entered in a cw or ccw order; they will be standardized
by reversal and rotation to be give the lowest lexical ordering.
If no faces are given then no edges will be computed.

    >>> from sympy.combinatorics.polyhedron import Polyhedron
    >>> Polyhedron(list('abc'), [(1, 2, 0)]).faces
    {(0, 1, 2)}
    >>> Polyhedron(list('abc'), [(1, 0, 2)]).faces
    {(0, 1, 2)}

The allowed transformations are entered as allowable permutations
of the vertices for the polyhedron. Instance of Permutations
(as with faces) should refer to the supplied vertices by index.
These permutation are stored as a PermutationGroup.

Examples
========

>>> from sympy.combinatorics.permutations import Permutation
>>> from sympy import init_printing
>>> from sympy.abc import w, x, y, z
>>> init_printing(pretty_print=False, perm_cyclic=False)

Here we construct the Polyhedron object for a tetrahedron.

>>> corners = [w, x, y, z]
>>> faces = [(0, 1, 2), (0, 2, 3), (0, 3, 1), (1, 2, 3)]

Next, allowed transformations of the polyhedron must be given. This
is given as permutations of vertices.

Although the vertices of a tetrahedron can be numbered in 24 (4!)
different ways, there are only 12 different orientations for a
physical tetrahedron. The following permutations, applied once or
twice, will generate all 12 of the orientations. (The identity
permutation, Permutation(range(4)), is not included since it does
not change the orientation of the vertices.)

>>> pgroup = [Permutation([[0, 1, 2], [3]]),                       Permutation([[0, 1, 3], [2]]),                       Permutation([[0, 2, 3], [1]]),                       Permutation([[1, 2, 3], [0]]),                       Permutation([[0, 1], [2, 3]]),                       Permutation([[0, 2], [1, 3]]),                       Permutation([[0, 3], [1, 2]])]

The Polyhedron is now constructed and demonstrated:

>>> tetra = Polyhedron(corners, faces, pgroup)
>>> tetra.size
4
>>> tetra.edges
{(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)}
>>> tetra.corners
(w, x, y, z)

It can be rotated with an arbitrary permutation of vertices, e.g.
the following permutation is not in the pgroup:

>>> tetra.rotate(Permutation([0, 1, 3, 2]))
>>> tetra.corners
(w, x, z, y)

An allowed permutation of the vertices can be constructed by
repeatedly applying permutations from the pgroup to the vertices.
Here is a demonstration that applying p and p**2 for every p in
pgroup generates all the orientations of a tetrahedron and no others:

>>> all = ( (w, x, y, z),                     (x, y, w, z),                     (y, w, x, z),                     (w, z, x, y),                     (z, w, y, x),                     (w, y, z, x),                     (y, z, w, x),                     (x, z, y, w),                     (z, y, x, w),                     (y, x, z, w),                     (x, w, z, y),                     (z, x, w, y) )

>>> got = []
>>> for p in (pgroup + [p**2 for p in pgroup]):
...     h = Polyhedron(corners)
...     h.rotate(p)
...     got.append(h.corners)
...
>>> set(got) == set(all)
True

The make_perm method of a PermutationGroup will randomly pick
permutations, multiply them together, and return the permutation that
can be applied to the polyhedron to give the orientation produced
by those individual permutations.

Here, 3 permutations are used:

>>> tetra.pgroup.make_perm(3) # doctest: +SKIP
Permutation([0, 3, 1, 2])

To select the permutations that should be used, supply a list
of indices to the permutations in pgroup in the order they should
be applied:

>>> use = [0, 0, 2]
>>> p002 = tetra.pgroup.make_perm(3, use)
>>> p002
Permutation([1, 0, 3, 2])


Apply them one at a time:

>>> tetra.reset()
>>> for i in use:
...     tetra.rotate(pgroup[i])
...
>>> tetra.vertices
(x, w, z, y)
>>> sequentially = tetra.vertices

Apply the composite permutation:

>>> tetra.reset()
>>> tetra.rotate(p002)
>>> tetra.corners
(x, w, z, y)
>>> tetra.corners in all and tetra.corners == sequentially
True

Notes
=====

Defining permutation groups
---------------------------

It is not necessary to enter any permutations, nor is necessary to
enter a complete set of transformations. In fact, for a polyhedron,
all configurations can be constructed from just two permutations.
For example, the orientations of a tetrahedron can be generated from
an axis passing through a vertex and face and another axis passing
through a different vertex or from an axis passing through the
midpoints of two edges opposite of each other.

For simplicity of presentation, consider a square --
not a cube -- with vertices 1, 2, 3, and 4:

1-----2  We could think of axes of rotation being:
|     |  1) through the face
|     |  2) from midpoint 1-2 to 3-4 or 1-3 to 2-4
3-----4  3) lines 1-4 or 2-3


To determine how to write the permutations, imagine 4 cameras,
one at each corner, labeled A-D:

A       B          A       B
 1-----2            1-----3             vertex index:
 |     |            |     |                 1   0
 |     |            |     |                 2   1
 3-----4            2-----4                 3   2
C       D          C       D                4   3

original           after rotation
                   along 1-4

A diagonal and a face axis will be chosen for the "permutation group"
from which any orientation can be constructed.

>>> pgroup = []

Imagine a clockwise rotation when viewing 1-4 from camera A. The new
orientation is (in camera-order): 1, 3, 2, 4 so the permutation is
given using the *indices* of the vertices as:

>>> pgroup.append(Permutation((0, 2, 1, 3)))

Now imagine rotating clockwise when looking down an axis entering the
center of the square as viewed. The new camera-order would be
3, 1, 4, 2 so the permutation is (using indices):

>>> pgroup.append(Permutation((2, 0, 3, 1)))

The square can now be constructed:
    ** use real-world labels for the vertices, entering them in
       camera order
    ** for the faces we use zero-based indices of the vertices
       in *edge-order* as the face is traversed; neither the
       direction nor the starting point matter -- the faces are
       only used to define edges (if so desired).

>>> square = Polyhedron((1, 2, 3, 4), [(0, 1, 3, 2)], pgroup)

To rotate the square with a single permutation we can do:

>>> square.rotate(square.pgroup[0])
>>> square.corners
(1, 3, 2, 4)

To use more than one permutation (or to use one permutation more
than once) it is more convenient to use the make_perm method:

>>> p011 = square.pgroup.make_perm([0, 1, 1]) # diag flip + 2 rotations
>>> square.reset() # return to initial orientation
>>> square.rotate(p011)
>>> square.corners
(4, 2, 3, 1)

Thinking outside the box
------------------------

Although the Polyhedron object has a direct physical meaning, it
actually has broader application. In the most general sense it is
just a decorated PermutationGroup, allowing one to connect the
permutations to something physical. For example, a Rubik's cube is
not a proper polyhedron, but the Polyhedron class can be used to
represent it in a way that helps to visualize the Rubik's cube.

>>> from sympy import flatten, unflatten, symbols
>>> from sympy.combinatorics import RubikGroup
>>> facelets = flatten([symbols(s+'1:5') for s in 'UFRBLD'])
>>> def show():
...     pairs = unflatten(r2.corners, 2)
...     print(pairs[::2])
...     print(pairs[1::2])
...
>>> r2 = Polyhedron(facelets, pgroup=RubikGroup(2))
>>> show()
[(U1, U2), (F1, F2), (R1, R2), (B1, B2), (L1, L2), (D1, D2)]
[(U3, U4), (F3, F4), (R3, R4), (B3, B4), (L3, L4), (D3, D4)]
>>> r2.rotate(0) # cw rotation of F
>>> show()
[(U1, U2), (F3, F1), (U3, R2), (B1, B2), (L1, D1), (R3, R1)]
[(L4, L2), (F4, F2), (U4, R4), (B3, B4), (L3, D2), (D3, D4)]

Predefined Polyhedra
====================

For convenience, the vertices and faces are defined for the following
standard solids along with a permutation group for transformations.
When the polyhedron is oriented as indicated below, the vertices in
a given horizontal plane are numbered in ccw direction, starting from
the vertex that will give the lowest indices in a given face. (In the
net of the vertices, indices preceded by "-" indicate replication of
the lhs index in the net.)

tetrahedron, tetrahedron_faces
------------------------------

    4 vertices (vertex up) net:

         0 0-0
        1 2 3-1

    4 faces:

    (0, 1, 2) (0, 2, 3) (0, 3, 1) (1, 2, 3)

cube, cube_faces
----------------

    8 vertices (face up) net:

        0 1 2 3-0
        4 5 6 7-4

    6 faces:

    (0, 1, 2, 3)
    (0, 1, 5, 4) (1, 2, 6, 5) (2, 3, 7, 6) (0, 3, 7, 4)
    (4, 5, 6, 7)

octahedron, octahedron_faces
----------------------------

    6 vertices (vertex up) net:

         0 0 0-0
        1 2 3 4-1
         5 5 5-5

    8 faces:

    (0, 1, 2) (0, 2, 3) (0, 3, 4) (0, 1, 4)
    (1, 2, 5) (2, 3, 5) (3, 4, 5) (1, 4, 5)

dodecahedron, dodecahedron_faces
--------------------------------

    20 vertices (vertex up) net:

          0  1  2  3  4 -0
          5  6  7  8  9 -5
        14 10 11 12 13-14
        15 16 17 18 19-15

    12 faces:

    (0, 1, 2, 3, 4) (0, 1, 6, 10, 5) (1, 2, 7, 11, 6)
    (2, 3, 8, 12, 7) (3, 4, 9, 13, 8) (0, 4, 9, 14, 5)
    (5, 10, 16, 15, 14) (6, 10, 16, 17, 11) (7, 11, 17, 18, 12)
    (8, 12, 18, 19, 13) (9, 13, 19, 15, 14)(15, 16, 17, 18, 19)

icosahedron, icosahedron_faces
------------------------------

    12 vertices (face up) net:

         0  0  0  0 -0
        1  2  3  4  5 -1
         6  7  8  9  10 -6
          11 11 11 11 -11

    20 faces:

    (0, 1, 2) (0, 2, 3) (0, 3, 4)
    (0, 4, 5) (0, 1, 5) (1, 2, 6)
    (2, 3, 7) (3, 4, 8) (4, 5, 9)
    (1, 5, 10) (2, 6, 7) (3, 7, 8)
    (4, 8, 9) (5, 9, 10) (1, 6, 10)
    (6, 7, 11) (7, 8, 11) (8, 9, 11)
    (9, 10, 11) (6, 10, 11)

>>> from sympy.combinatorics.polyhedron import cube
>>> cube.edges
{(0, 1), (0, 3), (0, 4), (1, 2), (1, 5), (2, 3), (2, 6), (3, 7), (4, 5), (4, 7), (5, 6), (6, 7)}

If you want to use letters or other names for the corners you
can still use the pre-calculated faces:

>>> corners = list('abcdefgh')
>>> Polyhedron(corners, cube.faces).corners
(a, b, c, d, e, f, g, h)

References
==========

.. [1] www.ocf.berkeley.edu/~wwu/articles/platonicsolids.pdf

F)directedkeyr   z.Permutation size unequal to number of corners.)r	   r   r   r   __new__tuple_cornersr   _facessizelen
ValueErrorr   Permrange_pgroup)clscornersfacespgroupfaargsobjs           V/var/www/auris/envauris/lib/python3.13/site-packages/sympy/combinatorics/polyhedron.pyr   Polyhedron.__new__"   s    D KPP%QE/?@%P!( 89 81UAY 89	:mmC'$'W~&
fQinnG4MNN&1tE#g,/014
 Q9s
   CCc                     U R                   $ )a@  
Get the corners of the Polyhedron.

The method ``vertices`` is an alias for ``corners``.

Examples
========

>>> from sympy.combinatorics import Polyhedron
>>> from sympy.abc import a, b, c, d
>>> p = Polyhedron(list('abcd'))
>>> p.corners == p.vertices == (a, b, c, d)
True

See Also
========

array_form, cyclic_form
)r   selfs    r%   r   Polyhedron.corners  s    * }}    c                     [        U R                  S   5      nU R                   Vs/ s H  o!R                  U5      PM     sn$ s  snf )a  Return the indices of the corners.

The indices are given relative to the original position of corners.

Examples
========

>>> from sympy.combinatorics.polyhedron import tetrahedron
>>> tetrahedron = tetrahedron.copy()
>>> tetrahedron.array_form
[0, 1, 2, 3]

>>> tetrahedron.rotate(0)
>>> tetrahedron.array_form
[0, 2, 3, 1]
>>> tetrahedron.pgroup[0].array_form
[0, 2, 3, 1]

See Also
========

corners, cyclic_form
r   )listr#   r   index)r)   r   cs      r%   
array_formPolyhedron.array_form  s9    2 tyy|$*.,,7,Qa ,777s   Ac                 V    [         R                  " U R                  5      R                  $ )zReturn the indices of the corners in cyclic notation.

The indices are given relative to the original position of corners.

See Also
========

corners, array_form
)r   _af_newr0   cyclic_formr(   s    r%   r4   Polyhedron.cyclic_form  s     ||DOO,888r+   c                 ,    [        U R                  5      $ )z.
Get the number of corners of the Polyhedron.
)r   r   r(   s    r%   r   Polyhedron.size  s    
 4==!!r+   c                     U R                   $ )z"
Get the faces of the Polyhedron.
)r   r(   s    r%   r   Polyhedron.faces  s    
 {{r+   c                     U R                   $ )z)
Get the permutations of the Polyhedron.
)r   r(   s    r%   r    Polyhedron.pgroup  s    
 ||r+   c           
         U R                   cs  [        5       nU R                   HL  n[        [	        U5      5       H1  n[        [        X#   X#S-
     /5      5      nUR                  U5        M3     MN     [        U6 U l         U R                   $ )a  
Given the faces of the polyhedra we can get the edges.

Examples
========

>>> from sympy.combinatorics import Polyhedron
>>> from sympy.abc import a, b, c
>>> corners = (a, b, c)
>>> faces = [(0, 1, 2)]
>>> Polyhedron(corners, faces).edges
{(0, 1), (0, 2), (1, 2)}

   )	_edgessetr   r   r   r   sortedaddr   )r)   outputfaceiedges        r%   edgesPolyhedron.edges  sv      ;;UF

s4y)A $1u+(>!?@DJJt$ * # $V,DK{{r+   c                 R   [        U[        5      (       d  U R                  U   nO%UR                  U R                  :w  a  [	        S5      eUR
                  n[        [        U R                  5      5       Vs/ s H  o0R                  X#      PM     nn[        U5      U l
        gs  snf )ae  
Apply a permutation to the polyhedron *in place*. The permutation
may be given as a Permutation instance or an integer indicating
which permutation from pgroup of the Polyhedron should be
applied.

This is an operation that is analogous to rotation about
an axis by a fixed increment.

Notes
=====

When a Permutation is applied, no check is done to see if that
is a valid permutation for the Polyhedron. For example, a cube
could be given a permutation which effectively swaps only 2
vertices. A valid permutation (that rotates the object in a
physical way) will be obtained if one only uses
permutations from the ``pgroup`` of the Polyhedron. On the other
hand, allowing arbitrary rotations (applications of permutations)
gives a way to follow named elements rather than indices since
Polyhedron allows vertices to be named while Permutation works
only with indices.

Examples
========

>>> from sympy.combinatorics import Polyhedron, Permutation
>>> from sympy.combinatorics.polyhedron import cube
>>> cube = cube.copy()
>>> cube.corners
(0, 1, 2, 3, 4, 5, 6, 7)
>>> cube.rotate(0)
>>> cube.corners
(1, 2, 3, 0, 5, 6, 7, 4)

A non-physical "rotation" that is not prohibited by this method:

>>> cube.reset()
>>> cube.rotate(Permutation([[1, 2]], size=8))
>>> cube.corners
(0, 2, 1, 3, 4, 5, 6, 7)

Polyhedron can be used to follow elements of set that are
identified by letters instead of integers:

>>> shadow = h5 = Polyhedron(list('abcde'))
>>> p = Permutation([3, 0, 1, 2, 4])
>>> h5.rotate(p)
>>> h5.corners
(d, a, b, c, e)
>>> _ == shadow.corners
True
>>> copy = h5.copy()
>>> h5.rotate(p)
>>> h5.corners == copy.corners
False
z(Polyhedron and Permutation sizes differ.N)
isinstancer   r    r   r   r0   r   r   r   r   r   )r)   permr"   rD   r   s        r%   rotatePolyhedron.rotate   s    t $%%;;t$D yyDII% !KLLOO/4S5F/GH/G!<<%/GHg Is   7B$c                 ,    U R                   S   U l        g)a   Return corners to their original positions.

Examples
========

>>> from sympy.combinatorics.polyhedron import tetrahedron as T
>>> T = T.copy()
>>> T.corners
(0, 1, 2, 3)
>>> T.rotate(0)
>>> T.corners
(0, 2, 3, 1)
>>> T.reset()
>>> T.corners
(0, 1, 2, 3)
r   N)r#   r   r(   s    r%   resetPolyhedron.resetD  s    " 		!r+   )r   r>   ) rP   )__name__
__module____qualname____firstlineno____doc__r>   r   propertyr   verticesr0   r4   r   r   r    rF   rK   rN   __static_attributes__rP   r+   r%   r   r      s    ( Fm^  * H8 86 
9 
9 " "      0B'H%r+   r   c                  d  ^^ S n / SQn[        / SQS//5      [        / SQS//5      [        / SQS//5      [        / S	QS
//5      [        SS/S
S//5      [        SS
/SS//5      [        SS/SS
//5      /n[        [        S5      UU5      n/ SQn/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ4 Vs/ s H  n[        U5      PM     nn[        [        S5      UU5      n/ SQn[        [        S5      UU " XtU5      5      n	/ SQn
UU4S jn[        / SQ5      m[        / S Q5      mTT/S!R                  5       R	                  5        Vs/ s H
  o" U5      PM     sn-   n[        [        S"5      U
U5      n/ S#Qn[        [        S$5      UU " XU5      5      nX7XUXUX4
$ s  snf s  snf )%a  Return the permutation groups for each of the polyhedra and the face
definitions: tetrahedron, cube, octahedron, dodecahedron, icosahedron,
tetrahedron_faces, cube_faces, octahedron_faces, dodecahedron_faces,
icosahedron_faces

Explanation
===========

(This author did not find and did not know of a better way to do it though
there likely is such a way.)

Although only 2 permutations are needed for a polyhedron in order to
generate all the possible orientations, a group of permutations is
provided instead. A set of permutations is called a "group" if::

a*b = c (for any pair of permutations in the group, a and b, their
product, c, is in the group)

a*(b*c) = (a*b)*c (for any 3 permutations in the group associativity holds)

there is an identity permutation, I, such that I*a = a*I for all elements
in the group

a*b = I (the inverse of each permutation is also in the group)

None of the polyhedron groups defined follow these definitions of a group.
Instead, they are selected to contain those permutations whose powers
alone will construct all orientations of the polyhedron, i.e. for
permutations ``a``, ``b``, etc... in the group, ``a, a**2, ..., a**o_a``,
``b, b**2, ..., b**o_b``, etc... (where ``o_i`` is the order of
permutation ``i``) generate all permutations of the polyhedron instead of
mixed products like ``a*b``, ``a*b**2``, etc....

Note that for a polyhedron with n vertices, the valid permutations of the
vertices exclude those that do not maintain its faces. e.g. the
permutation BCDE of a square's four corners, ABCD, is a valid
permutation while CBDE is not (because this would twist the square).

Examples
========

The is_group checks for: closure, the presence of the Identity permutation,
and the presence of the inverse for each of the elements in the group. This
confirms that none of the polyhedra are true groups:

>>> from sympy.combinatorics.polyhedron import (
... tetrahedron, cube, octahedron, dodecahedron, icosahedron)
...
>>> polyhedra = (tetrahedron, cube, octahedron, dodecahedron, icosahedron)
>>> [h.pgroup.is_group for h in polyhedra]
...
[True, True, True, True, True]

Although tests in polyhedron's test suite check that powers of the
permutations in the groups generate all permutations of the vertices
of the polyhedron, here we also demonstrate the powers of the given
permutations create a complete group for the tetrahedron:

>>> from sympy.combinatorics import Permutation, PermutationGroup
>>> for h in polyhedra[:1]:
...     G = h.pgroup
...     perms = set()
...     for g in G:
...         for e in range(g.order()):
...             p = tuple((g**e).array_form)
...             perms.add(p)
...
...     perms = [Permutation(p) for p in perms]
...     assert PermutationGroup(perms).is_group

In addition to doing the above, the tests in the suite confirm that the
faces are all present after the application of each permutation.

References
==========

.. [1] https://dogschool.tripod.com/trianglegroup.html

c                    [        US   5      n[        [        U[        [        U5      5      5      5      n[	        U5      n/ nU H  nU R                  5       nUR                  U5        UR                  n	[        U V
s/ s H  oU
   PM	     sn
U5      nU Vs/ s H$  n[        [        [        [        USS95      5      PM&     nnUR                  [        U Vs/ s H  oU   PM	     sn5      5        M     U$ s  sn
f s  snf s  snf )Nr   F)r   )r   dictzipr   r   copyrK   r   r
   r   mapr   r	   appendr   )polyhordered_facesr    nfmap
flat_faces
new_pgroupphr/   jreorderr!   s                r%   _pgroup_of_double(_pgroup_calcs.<locals>._pgroup_of_double  s   a !
 Cc-013 4]+

A

AHHQK		A  z :z!1z :A>G !() '1 Sa%02 3 '  )
 dW#=WGW#=>?   !;)
 $>s   >C8
+C=D)r   r=      r   rm      r   ro   r=   r=   rm   ro   rq   r   rl   ro   )r   ro   rm   r=   rp   rm      ))r   r=   rm   ro   )r   r=      rr   )r=   rm      rs   )rm   ro      rt   )r   ro   ru   rr   )rr   rs   rt   ru   )r=   rm   ro   r   rs   rt   ru   rr   )rr   r   ro   ru   rs   r=   rm   rt   )rr   rs   r=   r   ru   rt   rm   ro   )r=   r   rr   rs   rm   ro   ru   rt   )rt   rm   r=   rs   ru   ro   r   rr   )rt   ru   ro   rm   rs   rr   r   r=   )ro   ru   rr   r   rm   rt   rs   r=   )rr   ru   rt   rs   r   ro   rm   r=   )rt   rs   rr   ru   rm   r=   r   ro   )r   ro   ru   rr   r=   rm   rt   rs   )rs   r=   r   rr   rt   rm   ro   ru   )rs   rt   rm   r=   rr   ru   ro   r   )ru   rr   r   ro   rt   rs   r=   rm      )rl   rn   r   ro   rr   )r   r=   rr   )r=   rm   rs   )rm   ro   rs   )ro   rr   rs   )r=   rr   rs   rt   ))r   r=   rm   ro   rr   )r   r=   rt   
   rs   )r=   rm   ru   r   rt   )rm   ro   rv      ru   )ro   rr   	      rv   )r   rr   rz      rs   )rs   rx         r|   )rt   rx   r}      r   )ru   r   r      ry   )rv   ry   r      r{   )rz   r{   r   r~   r|   )r~   r}   r   r   r   c                    > [        [        S5      5      /nS nU  H@  nUS;  a  [        U5      S-
  nOSnUS:X  a  TnOUS:X  a  TnUR                  U/U-  5        MB     [         R                  " U6 $ )N   01r=   01)r   r   intextendrmul)srvrf   sicount_f0_f1s        r%   _string_to_perm&_pgroup_calcs.<locals>._string_to_perm  su    59oB~B!9A3YAIIqc%i   yy"~r+   )r=   rm   ro   rr   r   rt   ru   rv   rz   rs   r   ry   r{   r|   rx   r}   r   r   r   r~   )rs   r   rr   rz   r|   rx   r=   ro   r{   r~   rt   rm   rv   r   r}   r   r   ru   ry   r   z
    0104 140 014 0410
    010 1403 03104 04103 102
    120 1304 01303 021302 03130
    0412041 041204103 04120410 041204104 041204102
    10 01 1402 0140 04102 0412 1204 1302 0130 03120r   )rl   rn   rw   )r   rr   rs   )r   r=   rs   )r=   rt   ru   )r=   rm   ru   )rm   ru   rv   )rm   ro   rv   )ro   rv   rz   )ro   rr   rz   )rr   rz   rx   )rr   rs   rx   )rs   rt   rx   )r=   rs   rt   )rt   ru   r   )ru   rv   r   )rv   rz   r   )rz   rx   r   )rt   rx   r   ry   )r   r   r   stripsplit)rj   tetrahedron_faces	_t_pgrouptetrahedron
cube_facesrf   	_c_pgroupcubeoctahedron_faces
octahedrondodecahedron_facesr   r   _dodeca_pgroupdodecahedronicosahedron_facesicosahedronr   r   s                    @@r%   _pgroup_calcsr   X  s7   `4 	i!i!i!i!q!fq!fq!fq!fq!fq!fI aK
J 	!            	
	
 a	
  & aD

 a$I68J
   , -C  , -C 3Z @7
 8=uwuuw@G #H @G!?1#5 @G #H HN b	L
F b	n	>?K z'7/ /}L#Hs   =F(F-r=   rm   ro   rr   rs   rt   ru   rv   rz   rx   r   ry   r{   r|   r~   r}   r   r   r   N) sympy.combinatoricsr   r   sympy.combinatorics.perm_groupsr   
sympy.corer   r   r   
sympy.setsr   sympy.utilities.iterablesr	   r
   r   sympy.utilities.miscr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )args   0r%   <module>r      s   3 < 5 5   B B 'yyJ	% J	%Zg/` 	!Q1	aAaAaAaA	
 
Q1Q1aQ1Q1Q
1aQ
1aQ
1a" 	!Q1aAq!	aAqaAqaAqaAqaAqaAq 
Q1aAq!$Q1aAq!$Q1aAq!$Q
1aAq!$Q
1aAq!$Q
1aAq!$Q
1aAq!$Q
1aAq!$Q
1aAq!$Q1aAQ1aAq!Q1aAQ1aA !0 	!Q1a	aAaAaAaAaAaAaAaA 
Q1aQ1aQ1aQ
1aAQ
1aAQ
1aAQ
1aAQ
1aAQ
1aAQ1aAQ1aAQ1aAQ1aA !
4 	!Q1aAq!QBBBBBO	aAq!aAr1aAr1aAr1aAr1aAr1aRR aRR aRR aRR aRR b"b"b!# 
 MQ1aAq!Q*2r2r2>r2r2rRMQ2q!Q2r2.q!RQ?2r2rRM 	QBAq!RA.q!RQ?2r2rRM 	Q2r1aRQ/1b!Q?2r2rR	M
 	Q2r2q!RQ/1b!Q?2r2rRM 	Q1b!Q2r2.q!RQ?2r2rRM 	Q
1aB1%a,Q3Ar:2rB2rJ2rRM 	Q
1aAq"%a,Q3Ar:2rB2rJ2rRM 	QAq!Q1%a,Q3Ar:2rB2rJ2rRM 	Q
1b!Q1%a,Q3Ar:2rB2rJ2rRM 	Q
1aB1%a,Q3Ar:2rB2rJ2rRM 	Q
1b!R B'2.q!4Q;ArB2rJ2rRM 	QAq!R B'2.q!4Q;ArB2rJ2rRM 	QAr1a B'2.q"5a;ArB2rJ2rRM 	QAr1b!!Q'2.q"5a<QB2rJ2rRM  	QAr1b!!R(A.q!4Q;ArB2rJ2rR!M" 	QAr1b!!R(B/26q"=aDQKArR#M$ 	QAr1b!!R(B/26q"=aDQKArR%M& 	QAr1b!!R(B/26q"=aDQKArR'M( 	QAr1b!!R(B/26q"=aDQKArR)M* 	QAr1b!!R(B/26q"=aDQKArR+M, 	Q1aB2q)!R4QB?BK-M. 	RAq!Q#Ar1-aR8BCBBO/M0 	QAq!Q1b)!R4QB?BK1M2 	Q2q"a Aq)!R4QB?BK3M4 	Q1aB2q)!R4QB?BK5M6 	QB1b!!R,QB72qA!QK7M8 	QAq"b!!Q+Ar26q"bA!QK9M: 	QB2q!!R,Q26q"bA!RK;M< 	QB2r"1b!,QB71bA!QK=M> 	Q2q"b!!R,QA6q"bA!QK?M.N` 	!Q1aAq!QB/	aAaAaAaAaAaAaAaAaAaAaAaBaBaBaAaBaBaBaRaR)* 
 4RAq!Q1aB/4Q1aAq"b!,4 	Q1aAq!R+4 	Q1aAq"b!,	4
 	Q1b!Q1b!,4 	Q2q!Q1b!,4 	Q
1aAq!$Q+Ar24 	Q
1aAq!$Q*2r24 	Q
1aAq!$Q+Ar24 	Q
1aB1%a+Ar24 	Q
1aB1%a+Ar24 	Q
1aB2&q!,Q24 	Q
1aAq"%a+Ar24 	Q
1aAq!$Q+Ar24 	Q
1b!R A&q!,Q24  	QAq!R A&q!,Q2!4" 	QAq!R A&q!,Q2#4$ 	QAq!Q1%a,Q2%4& 	QAr1a A&q!,Q2'4( 	QAq!Q2&q!,Q2)4* 	QAq!Q1%a+Ar2+4, 	Q1aAq"a(Ar2-4. 	Q1aAq!Q'2r2/40 	Q1aAq!Q'2r2142 	Q1aB1a(Ar2344 	Q1aB1a(Ar2546 	QAq!Q1b)!Q2748 	Q1aAq!R(B294: 	Q1aQ1a(Ar2;4< 	Q2q!Q2q)!Q2=4> 	Q1aB1a(B2?4/65p ,7+<+<=+<CU3Z+<= $(JJ/JSeCjJ/
*4*:*:;*:3E#J*:; ,8,>,>?,>SeCj,>? +6+<+<=+<CU3Z+<=  >/;?=s(   C6AFDAFD<AF"EAF'FAF,