
    sg[                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ ddlmZ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Z& G d de      Z' G d de'      Z( G d de      Z) G d de      Z*d Z+d Z,d Z-d Z.d Z/d  Z0d(d"Z1d# Z2d$ Z3d% Z4d& Z5d' Z6y!))zClebsch-Gordon Coefficients.    )Sum)Add)Expr)expand)Mul)Pow)Eq)S)Wildsymbols)sympify)sqrt)	Piecewise)
prettyForm
stringPict)KroneckerDelta)clebsch_gordan	wigner_3j	wigner_6j	wigner_9j)
PRECEDENCE)CGWigner3jWigner6jWigner9jcg_simpc                       e Zd ZdZdZd Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zd Zd Zd Zy)r   a  Class for the Wigner-3j symbols.

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

    Wigner 3j-symbols are coefficients determined by the coupling of
    two angular momenta. When created, they are expressed as symbolic
    quantities that, for numerical parameters, can be evaluated using the
    ``.doit()`` method [1]_.

    Parameters
    ==========

    j1, m1, j2, m2, j3, m3 : Number, Symbol
        Terms determining the angular momentum of coupled angular momentum
        systems.

    Examples
    ========

    Declare a Wigner-3j coefficient and calculate its value

        >>> from sympy.physics.quantum.cg import Wigner3j
        >>> w3j = Wigner3j(6,0,4,0,2,0)
        >>> w3j
        Wigner3j(6, 0, 4, 0, 2, 0)
        >>> w3j.doit()
        sqrt(715)/143

    See Also
    ========

    CG: Clebsch-Gordan coefficients

    References
    ==========

    .. [1] Varshalovich, D A, Quantum Theory of Angular Momentum. 1988.
    Tc           	      Z    t        t        ||||||f      }t        j                  | g| S Nmapr   r   __new__)clsj1m1j2m2j3m3argss           K/var/www/html/venv/lib/python3.12/site-packages/sympy/physics/quantum/cg.pyr"   zWigner3j.__new__Q   s/    7RRR45||C'$''    c                      | j                   d   S Nr   r*   selfs    r+   r$   zWigner3j.j1U       yy|r,   c                      | j                   d   S N   r/   r0   s    r+   r%   zWigner3j.m1Y   r2   r,   c                      | j                   d   S N   r/   r0   s    r+   r&   zWigner3j.j2]   r2   r,   c                      | j                   d   S N   r/   r0   s    r+   r'   zWigner3j.m2a   r2   r,   c                      | j                   d   S N   r/   r0   s    r+   r(   zWigner3j.j3e   r2   r,   c                      | j                   d   S N   r/   r0   s    r+   r)   zWigner3j.m3i   r2   r,   c                 <    t        d | j                  D               S )Nc              3   4   K   | ]  }|j                     y wr   	is_number.0args     r+   	<genexpr>z'Wigner3j.is_symbolic.<locals>.<genexpr>o        :s}}:   allr*   r0   s    r+   is_symboliczWigner3j.is_symbolicm       :		::::r,   c                    |j                  | j                        |j                  | j                        f|j                  | j                        |j                  | j                        f|j                  | j
                        |j                  | j                        ffd}d}dgdz  }t        d      D ]#  t        fdt        d      D              |<   % d }t        d      D ]  }d }t        d      D ]     |   }	|   |	j                         z
  }
|
dz  }|
|z
  }t        |	j                  d|z         }	t        |	j                  d|z         }	||	}dt        |j                  d|z         }t        |j                  |	       } ||}t        |      D ]  }t        |j                  d       } t        |j                  |       } t        |j                          }|S )Nr8   r5   r;   c              3   J   K   | ]  }   |   j                           y wr   widthrG   ijms     r+   rI   z#Wigner3j._pretty.<locals>.<genexpr>z        <a!A$q'--/<    # )_printr$   r%   r&   r'   r(   r)   rangemaxrT   r   rightleftbelowparensr1   printerr*   hsepvsepmaxwDrV   D_rowswdeltawleftwright_rW   rX   s                 @@r+   _prettyzWigner3j._prettyr   s   nnTWW%w~~dgg'>?^^DGG$gnnTWW&=>^^DGG$gnnTWW&=>@ tAvq 	=A<58<<DG	=q 	,AE1X 4aDGa1779,
%F
 34s5y 12=E"EKKD$9:"EKKN34 y4[ .-.AGGEN+A+	,, 
#r,   c           	          t        |j                  | j                  | j                  | j                  | j
                  | j                  | j                  f      }dt        |      z  S )NzH\left(\begin{array}{ccc} %s & %s & %s \\ %s & %s & %s \end{array}\right))	r!   r\   r$   r&   r(   r%   r'   r)   tupler1   rd   r*   labels       r+   _latexzWigner3j._latex   sP    GNNTWWdggtwwGGTWWdgg%/ 0Z%L 	r,   c                     | j                   rt        d      t        | j                  | j                  | j
                  | j                  | j                  | j                        S NzCoefficients must be numerical)	rN   
ValueErrorr   r$   r&   r(   r%   r'   r)   r1   hintss     r+   doitzWigner3j.doit   sD    =>>$''477DGGTWWdggNNr,   N)__name__
__module____qualname____doc__is_commutativer"   propertyr$   r%   r&   r'   r(   r)   rN   ro   rt   rz    r,   r+   r   r   &   s    &P N(             ; ;!FOr,   r   c                   2    e Zd ZdZed   dz
  Zd Zd Zd Zy)r   a  Class for Clebsch-Gordan coefficient.

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

    Clebsch-Gordan coefficients describe the angular momentum coupling between
    two systems. The coefficients give the expansion of a coupled total angular
    momentum state and an uncoupled tensor product state. The Clebsch-Gordan
    coefficients are defined as [1]_:

    .. math ::
        C^{j_3,m_3}_{j_1,m_1,j_2,m_2} = \left\langle j_1,m_1;j_2,m_2 | j_3,m_3\right\rangle

    Parameters
    ==========

    j1, m1, j2, m2 : Number, Symbol
        Angular momenta of states 1 and 2.

    j3, m3: Number, Symbol
        Total angular momentum of the coupled system.

    Examples
    ========

    Define a Clebsch-Gordan coefficient and evaluate its value

        >>> from sympy.physics.quantum.cg import CG
        >>> from sympy import S
        >>> cg = CG(S(3)/2, S(3)/2, S(1)/2, -S(1)/2, 1, 1)
        >>> cg
        CG(3/2, 3/2, 1/2, -1/2, 1, 1)
        >>> cg.doit()
        sqrt(3)/2
        >>> CG(j1=S(1)/2, m1=-S(1)/2, j2=S(1)/2, m2=+S(1)/2, j3=1, m3=0).doit()
        sqrt(2)/2


    Compare [2]_.

    See Also
    ========

    Wigner3j: Wigner-3j symbols

    References
    ==========

    .. [1] Varshalovich, D A, Quantum Theory of Angular Momentum. 1988.
    .. [2] `Clebsch-Gordan Coefficients, Spherical Harmonics, and d Functions
        <https://pdg.lbl.gov/2020/reviews/rpp2020-rev-clebsch-gordan-coefs.pdf>`_
        in P.A. Zyla *et al.* (Particle Data Group), Prog. Theor. Exp. Phys.
        2020, 083C01 (2020).
    r   r5   c                     | j                   rt        d      t        | j                  | j                  | j
                  | j                  | j                  | j                        S rv   )	rN   rw   r   r$   r&   r(   r%   r'   r)   rx   s     r+   rz   zCG.doit   sD    =>>dggtww$''477SSr,   c                    |j                  | j                  | j                  | j                  | j                  fd      }|j                  | j
                  | j                  fd      }t        |j                         |j                               }t        |j                  d       }t        |j                  d       }||j                         k(  s+t        |j                  d||j                         z
  z         }||j                         k(  s+t        |j                  d||j                         z
  z         }t        dd|z  z         }t        |j                  |       }t        |j                  |       }|S )N,)	delimiterr[   C)
_print_seqr$   r%   r&   r'   r(   r)   r^   rT   r   r`   r_   r   ra   above)r1   rd   r*   bottoppadrj   s          r+   ro   z
CG._pretty   s1     WWdggtww0C ! A  $''477!3s C#))+syy{+#((3-(#((3-(ciik!ciiS399;->(?@ACciik!ciiS399;->(?@ACsSW}%%%r,   c           	          t        |j                  | j                  | j                  | j                  | j
                  | j                  | j                  f      }dt        |      z  S )NzC^{%s,%s}_{%s,%s,%s,%s})	r!   r\   r(   r)   r$   r%   r&   r'   rq   rr   s       r+   rt   z	CG._latex   sK    GNNTWWdggtwwGGTWWdgg%/ 0)E%L88r,   N)	r{   r|   r}   r~   r   
precedencerz   ro   rt   r   r,   r+   r   r      s)    5l E"Q&JT
$9r,   r   c                       e Zd ZdZd Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zd
 Zd Zd Zy)r   zaClass for the Wigner-6j symbols

    See Also
    ========

    Wigner3j: Wigner-3j symbols

    c           	      Z    t        t        ||||||f      }t        j                  | g| S r   r    )r#   r$   r&   j12r(   rW   j23r*   s           r+   r"   zWigner6j.__new__   s/    7RS"a56||C'$''r,   c                      | j                   d   S r.   r/   r0   s    r+   r$   zWigner6j.j1  r2   r,   c                      | j                   d   S r4   r/   r0   s    r+   r&   zWigner6j.j2  r2   r,   c                      | j                   d   S r7   r/   r0   s    r+   r   zWigner6j.j12  r2   r,   c                      | j                   d   S r:   r/   r0   s    r+   r(   zWigner6j.j3  r2   r,   c                      | j                   d   S r=   r/   r0   s    r+   rW   z
Wigner6j.j  r2   r,   c                      | j                   d   S r@   r/   r0   s    r+   r   zWigner6j.j23  r2   r,   c                 <    t        d | j                  D               S )Nc              3   4   K   | ]  }|j                     y wr   rD   rF   s     r+   rI   z'Wigner6j.is_symbolic.<locals>.<genexpr>  rJ   rK   rL   r0   s    r+   rN   zWigner6j.is_symbolic  rO   r,   c                    |j                  | j                        |j                  | j                        f|j                  | j                        |j                  | j                        f|j                  | j
                        |j                  | j                        ffd}d}dgdz  }t        d      D ]#  t        fdt        d      D              |<   % d }t        d      D ]  }d }t        d      D ]     |   }	|   |	j                         z
  }
|
dz  }|
|z
  }t        |	j                  d|z         }	t        |	j                  d|z         }	||	}dt        |j                  d|z         }t        |j                  |	       } ||}t        |      D ]  }t        |j                  d       } t        |j                  |       } t        |j                  dd	       }|S )
Nr8   r5   rQ   r;   c              3   J   K   | ]  }   |   j                           y wr   rS   rU   s     r+   rI   z#Wigner6j._pretty.<locals>.<genexpr>)  rY   rZ   r[   {}r`   r_   )r\   r$   r(   r&   rW   r   r   r]   r^   rT   r   r_   r`   ra   rb   rc   s                 @@r+   ro   zWigner6j._pretty!  s   nnTWW%w~~dgg'>?^^DGG$gnnTVV&<=^^DHH%w~~dhh'?@B tAvq 	=A<58<<DG	=q 	,AE1X 4aDGa1779,
%F
 34s5y 12=E"EKKD$9:"EKKN34 y4[ .-.AGGEN+A+	,, c56r,   c           	          t        |j                  | j                  | j                  | j                  | j
                  | j                  | j                  f      }dt        |      z  S )NzJ\left\{\begin{array}{ccc} %s & %s & %s \\ %s & %s & %s \end{array}\right\})	r!   r\   r$   r&   r   r(   rW   r   rq   rr   s       r+   rt   zWigner6j._latexD  sP    GNNTWWdggtxxGGTVVTXX%/ 0\%L 	r,   c                     | j                   rt        d      t        | j                  | j                  | j
                  | j                  | j                  | j                        S rv   )	rN   rw   r   r$   r&   r   r(   rW   r   rx   s     r+   rz   zWigner6j.doitJ  sD    =>>$''488TWWdffdhhOOr,   N)r{   r|   r}   r~   r"   r   r$   r&   r   r(   rW   r   rN   ro   rt   rz   r   r,   r+   r   r      s    (             ; ;!FPr,   r   c                       e Zd ZdZd Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zed        Zd Zd Zd Zy)r   zaClass for the Wigner-9j symbols

    See Also
    ========

    Wigner3j: Wigner-3j symbols

    c
                 `    t        t        |||||||||	f	      }
t        j                  | g|
 S r   r    )r#   r$   r&   r   r(   j4j34j13j24rW   r*   s              r+   r"   zWigner9j.__new__Y  s5    7RS"b#sCCD||C'$''r,   c                      | j                   d   S r.   r/   r0   s    r+   r$   zWigner9j.j1]  r2   r,   c                      | j                   d   S r4   r/   r0   s    r+   r&   zWigner9j.j2a  r2   r,   c                      | j                   d   S r7   r/   r0   s    r+   r   zWigner9j.j12e  r2   r,   c                      | j                   d   S r:   r/   r0   s    r+   r(   zWigner9j.j3i  r2   r,   c                      | j                   d   S r=   r/   r0   s    r+   r   zWigner9j.j4m  r2   r,   c                      | j                   d   S r@   r/   r0   s    r+   r   zWigner9j.j34q  r2   r,   c                      | j                   d   S )N   r/   r0   s    r+   r   zWigner9j.j13u  r2   r,   c                      | j                   d   S )N   r/   r0   s    r+   r   zWigner9j.j24y  r2   r,   c                      | j                   d   S )N   r/   r0   s    r+   rW   z
Wigner9j.j}  r2   r,   c                 <    t        d | j                  D               S )Nc              3   4   K   | ]  }|j                     y wr   rD   rF   s     r+   rI   z'Wigner9j.is_symbolic.<locals>.<genexpr>  rJ   rK   rL   r0   s    r+   rN   zWigner9j.is_symbolic  rO   r,   c                    |j                  | j                        |j                  | j                        |j                  | j                        f|j                  | j                        |j                  | j
                        |j                  | j                        f|j                  | j                        |j                  | j                        |j                  | j                        ffd}d}dgdz  }t        d      D ]#  t        fdt        d      D              |<   % d }t        d      D ]  }d }t        d      D ]     |   }	|   |	j                         z
  }
|
dz  }|
|z
  }t        |	j                  d|z         }	t        |	j                  d|z         }	||	}dt        |j                  d|z         }t        |j                  |	       } ||}t        |      D ]  }t        |j!                  d       } t        |j!                  |       } t        |j#                  dd	       }|S )
Nr8   r5   rQ   r;   c              3   J   K   | ]  }   |   j                           y wr   rS   rU   s     r+   rI   z#Wigner9j._pretty.<locals>.<genexpr>  rY   rZ   r[   r   r   r   )r\   r$   r(   r   r&   r   r   r   r   rW   r]   r^   rT   r   r_   r`   ra   rb   rc   s                 @@r+   ro   zWigner9j._pretty  s   ^^!..17>>$((3KM^^!..17>>$((3KM^^DHH%w~~dhh'?PTPVPVAWXZ tAvq 	=A<58<<DG	=q 	,AE1X 4aDGa1779,
%F
 34s5y 12=E"EKKD$9:"EKKN34 y4[ .-.AGGEN+A+	,, c56r,   c                    t        |j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  f	      }dt        |      z  S )NzZ\left\{\begin{array}{ccc} %s & %s & %s \\ %s & %s & %s \\ %s & %s & %s \end{array}\right\})r!   r\   r$   r&   r   r(   r   r   r   r   rW   rq   rr   s       r+   rt   zWigner9j._latex  sc    GNNTWWdggtxx488TXXtvv%? @l%L 	r,   c                 
   | j                   rt        d      t        | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  	      S rv   )rN   rw   r   r$   r&   r   r(   r   r   r   r   rW   rx   s     r+   rz   zWigner9j.doit  s_    =>>$''488TWWdggtxxQUQYQY[_[c[ceiekekllr,   N)r{   r|   r}   r~   r"   r   r$   r&   r   r(   r   r   r   r   rW   rN   ro   rt   rz   r   r,   r+   r   r   P  s    (                   ; ;$Lmr,   r   c                 `   t        | t              rt        |       S t        | t              rt	        |       S t        | t
              r)t        | j                  D cg c]  }t        |       c} S t        | t              r)t        t        | j                        | j                        S | S c c}w )a  Simplify and combine CG coefficients.

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

    This function uses various symmetry and properties of sums and
    products of Clebsch-Gordan coefficients to simplify statements
    involving these terms [1]_.

    Examples
    ========

    Simplify the sum over CG(a,alpha,0,0,a,alpha) for all alpha to
    2*a+1

        >>> from sympy.physics.quantum.cg import CG, cg_simp
        >>> a = CG(1,1,0,0,1,1)
        >>> b = CG(1,0,0,0,1,0)
        >>> c = CG(1,-1,0,0,1,-1)
        >>> cg_simp(a+b+c)
        3

    See Also
    ========

    CG: Clebsh-Gordan coefficients

    References
    ==========

    .. [1] Varshalovich, D A, Quantum Theory of Angular Momentum. 1988.
    )
isinstancer   _cg_simp_addr   _cg_simp_sumr   r*   r   r   baseexp)erH   s     r+   r   r     s    B !SA	As	A	As	QVV4cWS\455	As	7166?AEE**	 5s   B+c                    g }g }t        |       } | j                  D ]  }|j                  t              rt	        |t
              r|j                  t        |             Ct	        |t              rpd}|j                  D ]&  }t	        |t
              r|t        |      z  }"||z  }( |j                  t              r|j                  |       |j                  |       |j                  |       |j                  |        t        |      \  }}|j                  |       t        |      \  }}|j                  |       t        |      \  }}|j                  |       t        | t        | z   S )a  Takes a sum of terms involving Clebsch-Gordan coefficients and
    simplifies the terms.

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

    First, we create two lists, cg_part, which is all the terms involving CG
    coefficients, and other_part, which is all other terms. The cg_part list
    is then passed to the simplification methods, which return the new cg_part
    and any additional terms that are added to other_part
    r5   )r   r*   hasr   r   r   appendr   r   _check_varsh_871_1_check_varsh_871_2_check_varsh_872_9r   )r   cg_part
other_partrH   termstermothers          r+   r   r     sA    GJq	Avv #772;#s#!!,s"34C%HH &D!$,d!33	&
 99R=NN5)%%e,s#c"%#( (0NGUe'0NGUe'0NGUe=3
+++r,   c                     t        t        d      \  }}}}|t        |||d||      z  }d|z  dz   t        |d      z  }|t	        |      z  }d|z  dz   }||z   }	t        ||||| ||||f||f||		      S )N)aalphabltr   r8   r5   )r!   r   r   r   abs_check_cg_simp)
	term_listr   r   r   r   exprsimpsign
build_expr
index_exprs
             r+   r   r     s    $ 9:OAuabE1aE**DaC!G^Aq))Dc"g:D1qJUJ$dB	Aua;LqRSfV`blmmr,   c                 
   t        t        d      \  }}}}|t        |||| |d      z  }t        d|z  dz         t	        |d      z  }d||z
  z  |z  t        |      z  }d|z  dz   }||z   }	t        ||||| ||||f||f||		      S )N)r   r   cr   r   r8   r5   rQ   )r!   r   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   s
             r+   r   r     s    $ 9:OAuabE1ufa++D!a=1--D!e)RB'D1qJUJ$dB	Aua;LqRSfV`blmmr,   c                    t        t        d      \	  }}}}}}}}}	|	t        ||||||      dz  z  }
t        j                  }|	t        |	      z  }t        ||z
        }t        ||z         }||z   dz   t        |||kD  fdt        ||      f|||kD  f      z
  }||z   |z
  }t        |
|||	| |||||||	f||||f||	      \  } }t        ||z
        }||z   }|dz   |z
  ||z   dz   z  }||z
  ||z   z  |z   |z   }t        |
|||	| |||||||	f||||f||	      \  } }t        ||||||      t        ||||||      z  }
t        ||      t        ||      z  }t        j                  }t        ||z
        }t        ||z         }||z   dz   t        |||kD  fdt        ||      f|||kD  f      z
  }||z   |z
  }t        |
||t        j                  | ||||||||f||||||f||	      \  } }t        ||z
        }||z   }|dz   |z
  ||z   dz   z  }||z
  ||z   z  |z   |z   }t        |
||t        j                  | ||||||||f||||||f||	      \  } }| ||z   |z   fS )N)	r   r   alphapr   betabetapr   gammar   r8   r5   r   )
r!   r   r   r
   Oner   r   r	   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   xyr   r   other1other2other3other4s                        r+   r   r   )  s   58 @J 6K2Aufaua
 bE1dAu-q00D55Dc"g:DAE
AEDLAQY1q5zAr!Qx=1a!e*MMJQJ&tT4YESTVZ\]_dfhHilmotvwy}k~  AK  MW  XIv 	AE
A	AAa%!)a!eai(Ja%!a%1$u,J&tT4YESTVZ\]_dfhHilmotvwy}k~  AK  MW  XIv
 a4E*2aE1e+LLD%(e)DDD55DAE
AEDLAQY1q5zAr!Qx=1a!e*MMJQJ&tT4	AuV\^_aeglnoqvKwz{  ~C  EK  MN  PT  V[  z\  ^h  jt  uIv 	AE
A	AAa%!)a!eai(Ja%!a%1$u,J&tT4	AuV\^_aeglnoqvKwz{  ~C  EK  MN  PT  V[  z\  ^h  jt  uIvfvo...r,   c	           
      T   d}	d}
|
t        |      k  r~t        ||
   | t        |            }||
dz  }
0|j                  |      j                  s|
dz  }
Q|D cg c]	  }|||   f }}dg|j                  |      z  }t	        |
t        |            D ]	  }t        ||   | j                  |      t        |      t        |      z
  |j                  |      |j                  |      f      }|]|j                  |      j                  |      j                  s|| j                  |d      j                  |      j                  |      |j                  |      |j                  |      j                  |      f||j                  |      j                  |      <    t        d |D              st        |D cg c]  }t        |d          c} }|D cg c]  }|d   	 }}|j                          |j                          |D cg c]  }|j                  |       c} |D ]7  }t        |d         |kD  s|j                  |d   ||d   z  z
  |d   z         9 |	|||z  j                  |      z  z  }	n|
dz  }
|
t        |      k  r~||	fS c c}w c c}w c c}w c c}w )a   Checks for simplifications that can be made, returning a tuple of the
    simplified list of terms and any terms generated by simplification.

    Parameters
    ==========

    expr: expression
        The expression with Wild terms that will be matched to the terms in
        the sum

    simp: expression
        The expression with Wild terms that is substituted in place of the CG
        terms in the case of simplification

    sign: expression
        The expression with Wild terms denoting the sign that is on expr that
        must match

    lt: expression
        The expression with Wild terms that gives the leading term of the
        matched expr

    term_list: list
        A list of all of the terms is the sum to be simplified

    variables: list
        A list of all the variables that appears in expr

    dep_variables: list
        A list of the variables that must match for all the terms in the sum,
        i.e. the dependent variables

    build_index_expr: expression
        Expression with Wild terms giving the number of elements in cg_index

    index_expr: expression
        Expression with Wild terms giving the index terms have when storing
        them to cg_index

    r   Nr5   )r   c              3   $   K   | ]  }|d u  
 y wr   r   )rG   rV   s     r+   rI   z!_check_cg_simp.<locals>.<genexpr>  s     /19/s   r8   r;   )len	_check_cgsubsrE   r]   anyminr   sortreversepopr   )r   r   r   r   r   	variablesdep_variablesbuild_index_exprr   r   rV   sub_1r   sub_depcg_indexrW   sub_2r   min_ltindicess                       r+   r   r   V  s   R J	A
c)n
)A,c)n==FA$$U+55FA*78QAuQx=886*//66q#i.) 	[AilDIIg,>IQTUbQc@ckoktktuzk{  ~B  ~G  ~G  HO  ~P  kQ  RE}??7+007AA=>		"a@P@U@UV]@^@c@cdi@jlnlslstylz  }A  }F  }F  GN  }O  }T  }T  UZ  }[  >[HZ__W-2259:	[ /h//X?TCQL?@F,45DQ5G5LLNOO(/11immA1  KtAw<&($$tAwQ'?a&HJK &$t)!1!1%!888JFA9 c)n
: j  + 9 @5 2s   J<JJ J%Nc                     | j                  |      }|y|6t        |t              st        d      |d   |d   j	                  |      k(  syt        |      |k(  r|S y)z2Checks whether a term matches the given expressionNzsign must be a tupler   r5   )matchr   rq   	TypeErrorr   r   )cg_termr   lengthr   matchess        r+   r   r     sh     mmD!G$&233Aw47..11
7|v r,   c                 H    t        |       } t        |       } t        |       } | S r   )_check_varsh_sum_871_1_check_varsh_sum_871_2_check_varsh_sum_872_4)r   s    r+   r   r     s%    q!Aq!Aq!AHr,   c                 
   t        d      }t        d      }t        d      }| j                  t        t	        |||d||      || |f            }|2t        |      dk(  r$d|z  dz   t        |d      z  j                  |      S | S )Nr   r   r   r   r8   r5   )r   r   r   r   r   r   r   r   )r   r   r   r   r   s        r+   r  r    s    S	AGES	AGGC1eQ1e4uqb!nEFESZ1_1q.A..44U;;Hr,   c                 0   t        d      }t        d      }t        d      }| j                  t        d||z
  z  t	        |||| |d      z  || |f            }|;t        |      dk(  r-t        d|z  dz         t        |d      z  j                  |      S | S )Nr   r   r   rQ   r   r8   r5   )	r   r   r   r   r   r   r   r   r   )r   r   r   r   r   s        r+   r  r    s    S	AGES	AGGR1u9bE1ufa;;eaR^LNESZ1_QqS1WnQ2288??Hr,   c           	      B   t        d      }t        d      }t        d      }t        d      }t        d      }t        d      }t        d      }t        d      }t        ||||||      }	t        ||||||      }
| j                  t	        |	|
z  || |f|| |f            }|6t        |      d	k(  r(t        ||      t        ||      z  j                  |      S | j                  t	        |	d
z  || |f|| |f            }|t        |      dk(  rt        j                  S | S )Nr   r   r   r   r   cpr   gammapr   r8   r>   )
r   r   r   r   r   r   r   r   r
   r   )r   r   r   r   r   r   r  r   r  cg1cg2match1match2s                r+   r  r    s   GE6?DS	AS	AS	A	dBME(^F
Qq$5
)C
Qq$F
+CWWSS51"a.4!Q-@AFc&kQ.q"%nUF&CCII&QQWWSa%!Q$A?@Fc&kQ.uuHr,   c                 4   t        | t              r| fddfS g }d}t        | t        t        f      st	        d      t        | t              ro| j
                  j                  rY| j
                  j                  r=t        | j
                        D cg c]  }|j                  | j                         c} n| fddfS t        | t              rI| j                  D ])  }t        |t              r|j                  |       %||z  }+ |||t        |      z  fS y c c}w )Nr5   z term must be CG, Add, Mul or Pow)r   r   r   r   NotImplementedErrorr   rE   r]   r   r   r*   r   )r   cgcoeffrn   rH   s        r+   _cg_listr    s    $w1}	BEdS#J'!"DEE$!3!388,1$((O=qbii		"=7Aq= $99 	C#r"		#		
 5%E
***  >s   "Dr   )7r~   sympy.concrete.summationsr   sympy.core.addr   sympy.core.exprr   sympy.core.functionr   sympy.core.mulr   sympy.core.powerr   sympy.core.relationalr	   sympy.core.singletonr
   sympy.core.symbolr   r   sympy.core.sympifyr   (sympy.functions.elementary.miscellaneousr   $sympy.functions.elementary.piecewiser    sympy.printing.pretty.stringpictr   r   (sympy.functions.special.tensor_functionsr   sympy.physics.wignerr   r   r   r   sympy.printing.precedencer   __all__r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r,   r+   <module>r#     s   
 # )    &    $ " - & 9 : C C P P 0xOt xOvS9 S9lVPt VPremt emP*Z+,\nn*/ZH!V(+r,   