o
    jg8                     @   sP   d dl mZ ddlmZ ddlmZmZmZmZ ddl	m
Z
 G dd de
ZdS )	   )
CartanType    )fac)MatrixeyeRationaligcd)Atomc                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )	WeylGroupa\  
    For each semisimple Lie group, we have a Weyl group.  It is a subgroup of
    the isometry group of the root system.  Specifically, it's the subgroup
    that is generated by reflections through the hyperplanes orthogonal to
    the roots.  Therefore, Weyl groups are reflection groups, and so a Weyl
    group is a finite Coxeter group.

    c                 C   s   t | }t||_|S N)r	   __new__r   cartan_type)cls
cartantypeobj r   T/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/liealgebras/weyl_group.pyr      s   

zWeylGroup.__new__c                 C   s<   | j  }g }td|d D ]}dt| }|| q|S )a  
        This method creates the generating reflections of the Weyl group for
        a given Lie algebra.  For a Lie algebra of rank n, there are n
        different generating reflections.  This function returns them as
        a list.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> c = WeylGroup("F4")
        >>> c.generators()
        ['r1', 'r2', 'r3', 'r4']
        r   r)r   rankrangestrappend)selfn
generatorsi
reflectionr   r   r   r      s   
zWeylGroup.generatorsc                 C   s   | j  }| j jdkrt|d S | j jdv rt|d|  S | j jdkr/t|d|d   S | j jdkrG|dkr;dS |d	krAd
S |dkrGdS | j jdkrOdS | j jdkrWdS dS )a}  
        This method returns the order of the Weyl group.
        For types A, B, C, D, and E the order depends on
        the rank of the Lie algebra.  For types F and G,
        the order is fixed.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> c = WeylGroup("D4")
        >>> c.group_order()
        192.0
        Ar   BC   DE   i     i L,    i @)Fi  G   N)r   r   seriesr   r   r   r   r   r   group_order.   s&   
zWeylGroup.group_orderc                 C   s   | j  }| j jdkrdt|d  d t|d  d S | j jdv r-dtd|  d S | j jd	kr;d
t| d S | j jdkrS|dkrGdS |dkrMdS |dkrSdS | j jdkr[dS | j jdkrcdS dS )z
        This method returns some general information about the Weyl group for
        a given Lie algebra.  It returns the name of the group and the elements
        it acts on, if relevant.
        r   Sr   z : the symmetric group acting on z
 elements.r   z$The hyperoctahedral group acting on r!   r"   zThe symmetry group of the z-dimensional demihypercube.r#   r$   z%The symmetry group of the 6-polytope.r%   z%The symmetry group of the 7-polytope.r&   z%The symmetry group of the 8-polytope.r'   z7The symmetry group of the 24-cell, or icositetrachoron.r(   zFD6, the dihedral group of order 12, and symmetry group of the hexagon.N)r   r   r*   r   r+   r   r   r   
group_nameT   s&   
$zWeylGroup.group_namec           	      C   sL  | j  }| j jdkr/| |}d}|t|d kr-|| |9 }|d7 }|t|d ks|S | j jdkrU| |}d}|t|krS|| |9 }|d7 }|t|ksB|S | j jdkr{| |}d}|tdkry|| |9 }|d7 }|tdksh|S | j jdkrt|}|ddd }| |}| ||kr| |}|}| ||kst|d	 dkrd	S t|d
krdS t|dkrd	S t|d	 }d| t|d }|| }|S | j jdkr| |}d}|tdkr|| |9 }|d7 }|tdks|S | j jdv r$| |}d}|t|kr"|| |9 }|d7 }|t|ks|S dS )aZ  
        This method returns the order of a given Weyl group element, which should
        be specified by the user in the form of products of the generating
        reflections, i.e. of the form r1*r2 etc.

        For types A-F, this method current works by taking the matrix form of
        the specified element, and then finding what power of the matrix is the
        identity.  It then returns this power.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> b = WeylGroup("B4")
        >>> b.element_order('r1*r4*r2')
        4
        r   r   r"   r#   r&   r(   N   r!   r   r$   r'      r   )	r   r   r*   matrix_formr   listdelete_doubleslenr   )	r   weyleltr   aordereltsreflectionsmlcmr   r   r   element_ordert   sx   







zWeylGroup.element_orderc                 C   sN   d}t |}|D ]}|t|d k r ||d  |kr ||= ||= |d7 }q|S )z
        This is a helper method for determining the order of an element in the
        Weyl group of G2.  It takes a Weyl element and if repeated simple reflections
        in it, it deletes them.
        r   r   )r2   r4   )r   r9   countercopyeltr   r   r   r3      s   
zWeylGroup.delete_doublesc                 C   sH  t |}|ddd }| j }| jjdkrQt|d }|D ]0}t|}t|d }d||d |d f< d||d |f< d|||d f< d|||f< ||9 }q|S | jjdkrt|}|D ]_}t|}t|}||k rd||d |d f< d||d |f< d|||d f< d|||f< ||9 }q]d||d |d f< d||d |d f< d||d |d f< d||d |d f< ||9 }q]|S | jjd	krtd}|D ]K}t|}|dkrtg d
g dg dg}	||	9 }qttddtddtddgtddtddtddgtddtddtddgg}
||
9 }q|S | jjdkrtd}|D ]}t|}|dkrHtg dg dg dg dg}||9 }q'|dkrctg dg dg dg dg}||9 }q'|dkr~tg dg dg dg dg}||9 }q'ttddtddtddtddgtddtddtddtddgtddtddtddtddgtddtddtddtddgg}||9 }q'|S | jjdkrLtd}|D ]m}t|}|dkrttddtddtddtddtddtddtddtddgtddtddtddtddtddtddtddtddgtddtddtddtddtddtddtddtddgtddtddtddtddtddtddtddtddgtddtddtddtddtddtddtddtddgtddtddtddtddtddtddtddtddgtddtddtddtddtddtddtddtddgtddtddtddtddtddtddtddtddgg}||9 }q|dkrtd}d|d< d|d< d|d< d|d< ||9 }qtd}d||d |d f< d||d |d f< d||d |d f< d||d |d f< ||9 }q|S | jjdv rt|}|D ]F}t|}t|}|dkrrd|d< ||9 }qYd||d |d f< d||d |d f< d||d |d f< d||d |d f< ||9 }qY|S dS )a  
        This method takes input from the user in the form of products of the
        generating reflections, and returns the matrix corresponding to the
        element of the Weyl group.  Since each element of the Weyl group is
        a reflection of some type, there is a corresponding matrix representation.
        This method uses the standard representation for all the generating
        reflections.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> f = WeylGroup("F4")
        >>> f.matrix_form('r2*r3')
        Matrix([
        [1, 0, 0,  0],
        [0, 1, 0,  0],
        [0, 0, 0, -1],
        [0, 0, 1,  0]])

        r   Nr/   r   r   r"   r!   r(   )r   r   r   )r   r   r   )r   r   r   r'   r0   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r@   r#   r&   )r   r   )r   r   )r   r   )r   r   r   )r2   r   r   r*   r   intr   r   )r   r5   r8   r9   r   
matrixformr?   r6   matgen1gen2r   r   r   r1      s   






 
 
 $"""

"               

zWeylGroup.matrix_formc                 C   s   | j  }| j jdv r| j  S | j jdv r8ddd td|D d }|dd	d td|d D 7 }|S | j jd
krQd}|ddd tddD 7 }|S | j jdkr[d}|S dS )aL  
        This method returns the Coxeter diagram corresponding to a Weyl group.
        The Coxeter diagram can be obtained from a Lie algebra's Dynkin diagram
        by deleting all arrows; the Coxeter diagram is the undirected graph.
        The vertices of the Coxeter diagram represent the generating reflections
        of the Weyl group, $s_i$.  An edge is drawn between $s_i$ and $s_j$ if the order
        $m(i, j)$ of $s_is_j$ is greater than two.  If there is one edge, the order
        $m(i, j)$ is 3.  If there are two edges, the order $m(i, j)$ is 4, and if there
        are three edges, the order $m(i, j)$ is 6.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> c = WeylGroup("B3")
        >>> print(c.coxeter_diagram())
        0---0===0
        1   2   3
        )r   r"   r#   r   z---c                 s   s    | ]}d V  qdS )0Nr   .0r   r   r   r   	<genexpr>  s    z,WeylGroup.coxeter_diagram.<locals>.<genexpr>r   z===0
z   c                 s       | ]}t |V  qd S r   r   rH   r   r   r   rJ         r'   z0---0===0---0
c                 s   rK   r   rL   rH   r   r   r   rJ     rM      r(   u   0≡≡≡0
1   2N)r   r   r*   dynkin_diagramjoinr   )r   r   diagr   r   r   coxeter_diagramo  s   

"zWeylGroup.coxeter_diagramN)__name__
__module____qualname____doc__r   r   r,   r.   r<   r3   r1   rR   r   r   r   r   r
      s    	& S r
   N)r   r   mpmathr   sympy.core.backendr   r   r   r   sympy.core.basicr	   r
   r   r   r   r   <module>   s
   