o
    *ήcV                     @   s,   d dl mZ ddlmZ G dd deZdS )   )Standard_Cartan    )eyec                   @   s\   e 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d Zdd ZdS )TypeDc                 C   s   |dk rt dt| d|S )N   zn cannot be less than 3D)
ValueErrorr   __new__)clsn r   ?/tmp/pip-target-vg8gfxp4/lib/python/sympy/liealgebras/type_d.pyr	      s   zTypeD.__new__c                 C   s   | j S )zDmension of the vector space V underlying the Lie algebra

        Examples
        ========

        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("D4")
        >>> c.dimension()
        4
        r   )selfr   r   r   	dimension   s   zTypeD.dimensionc                 C   s$   | j }dg| }d||< d||< |S )z
        This is a method just to generate roots
        with a 1 iin the ith position and a -1
        in the jth position.

        r   r   r   )r   ijr   rootr   r   r   
basic_root   s
   
zTypeD.basic_rootc                 C   sD   | j }||k r| |d |S dg| }d||d < d||d < |S )a  
        Every lie algebra has a unique root system.
        Given a root system Q, there is a subset of the
        roots such that an element of Q is called a
        simple root if it cannot be written as the sum
        of two elements in Q.  If we let D denote the
        set of simple roots, then it is clear that every
        element of Q can be written as a linear combination
        of elements of D with all coefficients non-negative.

        In D_n, the first n-1 simple roots are the same as
        the roots in A_(n-1) (a 1 in the ith position, a -1
        in the (i+1)th position, and zeroes elsewhere).
        The nth simple root is the root in which there 1s in
        the nth and (n-1)th positions, and zeroes elsewhere.

        This method returns the ith simple root for the D series.

        Examples
        ========

        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("D4")
        >>> c.simple_root(2)
        [0, 1, -1, 0]

        r   r      )r   r   )r   r   r   r   r   r   r   simple_root(   s   
zTypeD.simple_rootc                 C   sv   | j }i }d}td|d D ]*}t|d |D ] }|d7 }| ||||< |d7 }| ||}d||< |||< qq|S )a  
        This method generates all the positive roots of
        A_n.  This is half of all of the roots of D_n
        by multiplying all the positive roots by -1 we
        get the negative roots.

        Examples
        ========

        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("A3")
        >>> c.positive_roots()
        {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
                5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
        r   r   )r   ranger   )r   r   posrootskr   r   r   r   r   r   positive_rootsO   s   
zTypeD.positive_rootsc                 C   s   | j }d| |d  S )z<
        Returns the total number of roots for D_n"
        r   r   r   r   r   r   r   r   rootsm   s   zTypeD.rootsc                 C   s   | j }dt| }d}||d k r+d|||d f< d|||d f< |d7 }||d k sd||d |d f< d||d |d f< d||d |d f< d|d< |S )aM  
        Returns the Cartan matrix for D_n.
        The Cartan matrix matrix for a Lie algebra is
        generated by assigning an ordering to the simple
        roots, (alpha[1], ...., alpha[l]).  Then the ijth
        entry of the Cartan matrix is (<alpha[i],alpha[j]>).

        Examples
        ========

        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType('D4')
        >>> c.cartan_matrix()
            Matrix([
            [ 2, -1,  0,  0],
            [-1,  2, -1, -1],
            [ 0, -1,  2,  0],
            [ 0, -1,  0,  2]])

        r   r   r   r   )r   r   )r   r   )r   r   mr   r   r   r   cartan_matrixu   s   zTypeD.cartan_matrixc                 C   s   | j }||d  d S )zE
        Returns the number of independent generators of D_n
        r   r   r   r   r   r   r   basis   s   zTypeD.basisc                 C   s   | j }dtd|  d S )z>
        Returns the Lie algebra associated with D_n"
        zso(r   ))r   strr   r   r   r   lie_algebra   s   zTypeD.lie_algebrac                 C   s   | j }d|d  t|d  d }|d|d  d 7 }|d|d  d 7 }|d|d  d 7 }|ddd	 td|D d 7 }|d
dd	 td|d D d
 t| 7 }|S )Nz    r   r   
z0
z|
z---c                 s   s    | ]}d V  qdS )0Nr   .0r   r   r   r   	<genexpr>   s    z'TypeD.dynkin_diagram.<locals>.<genexpr>z   c                 s   s    | ]}t |V  qd S )N)r"   r&   r   r   r   r(      s    )r   r"   joinr   )r   r   diagr   r   r   dynkin_diagram   s   ".zTypeD.dynkin_diagramN)__name__
__module____qualname__r	   r   r   r   r   r   r   r    r#   r+   r   r   r   r   r      s    '#r   N)cartan_typer   sympy.core.backendr   r   r   r   r   r   <module>   s    