+
    i[                        R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIH t H!t!H"t"H#t# ^ RI$H%t% . R&Ot& ! R R]4      t' ! R R]'4      t( ! R R]4      t) ! R R]4      t*R t+R t,R t-R t.R t/R t0R'R  lt1R! t2R" t3R# t4R$ t5R% t6R# )(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Wigner9jc                      a  ] tR t^&t o RtRtR t]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       t]R	 4       t]R
 4       tR tR tR tRtV tR# )r   a8  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           	     X    \        \        WW4WV34      p\        P                  ! V .VO5!  # Nmapr   r   __new__)clsj1m1j2m2j3m3argss   &&&&&&& x/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/physics/quantum/cg.pyr    Wigner3j.__new__Q   s)    7RRR45||C'$''    c                (    V P                   ^ ,          #     r(   selfs   &r)   r"   Wigner3j.j1U       yy|r+   c                (    V P                   ^,          #    r/   r0   s   &r)   r#   Wigner3j.m1Y   r3   r+   c                (    V P                   ^,          #    r/   r0   s   &r)   r$   Wigner3j.j2]   r3   r+   c                (    V P                   ^,          #    r/   r0   s   &r)   r%   Wigner3j.m2a   r3   r+   c                (    V P                   ^,          #    r/   r0   s   &r)   r&   Wigner3j.j3e   r3   r+   c                (    V P                   ^,          #    r/   r0   s   &r)   r'   Wigner3j.m3i   r3   r+   c                    \         ;QJ d0    R  V P                   4       F  '       d   K   R'       * # 	  R'       * # ! R  V P                   4       4      '       * # )c              3   8   "   T F  qP                   x  K  	  R # 5ir   	is_number.0args   & r)   	<genexpr>'Wigner3j.is_symbolic.<locals>.<genexpr>o        :	}}	   FTallr(   r0   s   &r)   is_symbolicWigner3j.is_symbolicm   <    3:		:33::3::3:		::::r+   c                ^  aa VP                  V P                  4      VP                  V P                  4      3VP                  V P                  4      VP                  V P                  4      3VP                  V P
                  4      VP                  V P                  4      33o^p^pR.^,          p\        ^4       F%  o\        VV3R l\        ^4       4       4      VS&   K'  	  Rp\        ^4       EF  pRp\        ^4       F  oSS,          V,          p	VS,          V	P                  4       ,
          p
V
^,          pW,
          p\        V	P                  RV,          4      !  p	\        V	P                  RV,          4      !  p	Vf   T	pK  \        VP                  RV,          4      !  p\        VP                  V	4      !  pK  	  Vf   TpK  \        V4       F  p\        VP                  R4      !  pK  	  \        VP                  V4      !  pEK!  	  \        VP                  4       !  pV# )r:   c              3   `   <"   T F#  pSS,          V,          P                  4       x  K%  	  R # 5ir   widthrM   ijms   & r)   rO   #Wigner3j._pretty.<locals>.<genexpr>z   !     <8a!A$q'--//8   +.N )_printr"   r#   r$   r%   r&   r'   rangemaxr[   r   rightleftbelowparensr1   printerr(   hsepvsepmaxwDr]   D_rowswdeltawleftwright_r^   r_   s   &&*           @@r)   _prettyWigner3j._prettyr   s   nnTWW%w~~dgg'>?^^DGG$gnnTWW&=>^^DGG$gnnTWW&=>@ tAvqA<58<<DG qAE1XaDGa1779,
F
 34s5y 12=E"EKKD$9:"EKKN3  y4[- !AGGEN+A+ , 
#r+   c           	         \        VP                  V P                  V P                  V P                  V P
                  V P                  V P                  34      pR \        V4      ,          # )zH\left(\begin{array}{ccc} %s & %s & %s \\ %s & %s & %s \end{array}\right))	r   re   r"   r$   r&   r#   r%   r'   tupler1   rm   r(   labels   &&* r)   _latexWigner3j._latex   sP    GNNTWWdggtwwGGTWWdgg%/ 0Z%L 	r+   c                    V P                   '       d   \        R 4      h\        V P                  V P                  V P
                  V P                  V P                  V P                  4      # zCoefficients must be numerical)	rU   
ValueErrorr   r"   r$   r&   r#   r%   r'   r1   hintss   &,r)   doitWigner3j.doit   sG    =>>$''477DGGTWWdggNNr+    N)__name__
__module____qualname____firstlineno____doc__is_commutativer    propertyr"   r#   r$   r%   r&   r'   rU   rx   r~   r   __static_attributes____classdictcell____classdict__s   @r)   r   r   &   s     &P N(             ; ;!FO Or+   c                   V   a  ] tR t^t o Rt]R,          ^,
          tR tR tR t	Rt
V tR# )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   c                    V P                   '       d   \        R 4      h\        V P                  V P                  V P
                  V P                  V P                  V P                  4      # r   )	rU   r   r   r"   r$   r&   r#   r%   r'   r   s   &,r)   r   CG.doit   sG    =>>dggtww$''477SSr+   c                4   VP                  V P                  V P                  V P                  V P                  3R R7      pVP                  V P
                  V P                  3R R7      p\        VP                  4       VP                  4       4      p\        VP                  R4      !  p\        VP                  R4      !  pWSP                  4       8X  g4   \        VP                  RWSP                  4       ,
          ,          4      !  pWTP                  4       8X  g4   \        VP                  RWTP                  4       ,
          ,          4      !  p\        RRV,          ,           4      p\        VP                  V4      !  p\        VP                  V4      !  pV# ),)	delimiterrc   C)
_print_seqr"   r#   r$   r%   r&   r'   rg   r[   r   ri   rh   r   rj   above)r1   rm   r(   bottoppadrs   s   &&*    r)   rx   
CG._pretty   s)     WWdggtww0C ! A  $''477!3s C#))+syy{+#((3-(#((3-(iik!ciiS99;->(?@ACiik!ciiS99;->(?@ACsSW}%%%r+   c           	         \        VP                  V P                  V P                  V P                  V P
                  V P                  V P                  34      pR \        V4      ,          # )zC^{%s,%s}_{%s,%s,%s,%s})	r   re   r&   r'   r"   r#   r$   r%   r{   r|   s   &&* r)   r~   	CG._latex   sK    GNNTWWdggtwwGGTWWdgg%/ 0)E%L88r+   r   N)r   r   r   r   r   r   
precedencer   rx   r~   r   r   r   s   @r)   r   r      s1     5l E"Q&JT
$9 9r+   c                      a  ] tR t^t o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       t]R	 4       tR
 tR tR tRtV tR# )r   zQClass for the Wigner-6j symbols

See Also
========

Wigner3j: Wigner-3j symbols

c           	     X    \        \        WW4WV34      p\        P                  ! V .VO5!  # r   r   )r!   r"   r$   j12r&   r^   j23r(   s   &&&&&&& r)   r    Wigner6j.__new__   s)    7RSa56||C'$''r+   c                (    V P                   ^ ,          # r-   r/   r0   s   &r)   r"   Wigner6j.j1  r3   r+   c                (    V P                   ^,          # r5   r/   r0   s   &r)   r$   Wigner6j.j2  r3   r+   c                (    V P                   ^,          # r9   r/   r0   s   &r)   r   Wigner6j.j12  r3   r+   c                (    V P                   ^,          # r=   r/   r0   s   &r)   r&   Wigner6j.j3  r3   r+   c                (    V P                   ^,          # rA   r/   r0   s   &r)   r^   
Wigner6j.j  r3   r+   c                (    V P                   ^,          # rE   r/   r0   s   &r)   r   Wigner6j.j23  r3   r+   c                    \         ;QJ d0    R  V P                   4       F  '       d   K   R'       * # 	  R'       * # ! R  V P                   4       4      '       * # )c              3   8   "   T F  qP                   x  K  	  R # 5ir   rJ   rL   s   & r)   rO   'Wigner6j.is_symbolic.<locals>.<genexpr>  rQ   rR   FTrS   r0   s   &r)   rU   Wigner6j.is_symbolic  rW   r+   c                d  aa VP                  V P                  4      VP                  V P                  4      3VP                  V P                  4      VP                  V P                  4      3VP                  V P
                  4      VP                  V P                  4      33o^p^pR.^,          p\        ^4       F%  o\        VV3R l\        ^4       4       4      VS&   K'  	  Rp\        ^4       EF  pRp\        ^4       F  oSS,          V,          p	VS,          V	P                  4       ,
          p
V
^,          pW,
          p\        V	P                  RV,          4      !  p	\        V	P                  RV,          4      !  p	Vf   T	pK  \        VP                  RV,          4      !  p\        VP                  V	4      !  pK  	  Vf   TpK  \        V4       F  p\        VP                  R4      !  pK  	  \        VP                  V4      !  pEK!  	  \        VP                  RRR7      !  pV# )r:   c              3   `   <"   T F#  pSS,          V,          P                  4       x  K%  	  R # 5ir   rZ   r\   s   & r)   rO   #Wigner6j._pretty.<locals>.<genexpr>)  ra   rb   Nrc   {}ri   rh   rd   )re   r"   r&   r$   r^   r   r   rf   rg   r[   r   rh   ri   rj   rk   rl   s   &&*           @@r)   rx   Wigner6j._pretty!  s   nnTWW%w~~dgg'>?^^DGG$gnnTVV&<=^^DHH%w~~dhh'?@B tAvqA<58<<DG qAE1XaDGa1779,
F
 34s5y 12=E"EKKD$9:"EKKN3  y4[- !AGGEN+A+ , c56r+   c           	         \        VP                  V P                  V P                  V P                  V P
                  V P                  V P                  34      pR \        V4      ,          # )zJ\left\{\begin{array}{ccc} %s & %s & %s \\ %s & %s & %s \end{array}\right\})	r   re   r"   r$   r   r&   r^   r   r{   r|   s   &&* r)   r~   Wigner6j._latexD  sP    GNNTWWdggtxxGGTVVTXX%/ 0\%L 	r+   c                    V P                   '       d   \        R 4      h\        V P                  V P                  V P
                  V P                  V P                  V P                  4      # r   )	rU   r   r   r"   r$   r   r&   r^   r   r   s   &,r)   r   Wigner6j.doitJ  sG    =>>$''488TWWdffdhhOOr+   r   N)r   r   r   r   r   r    r   r"   r$   r   r&   r^   r   rU   rx   r~   r   r   r   r   s   @r)   r   r      s     (             ; ;!FP Pr+   c                      a  ] tR tRt o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       t]R	 4       t]R
 4       t]R 4       t]R 4       t]R 4       tR tR tR tRtV tR# )r   iP  zQClass for the Wigner-9j symbols

See Also
========

Wigner3j: Wigner-3j symbols

c
                \    \        \        WW4WVWxV	3	4      p
\        P                  ! V .V
O5!  # r   r   )r!   r"   r$   r   r&   j4j34j13j24r^   r(   s   &&&&&&&&&& r)   r    Wigner9j.__new__Y  s-    7RSbsCD||C'$''r+   c                (    V P                   ^ ,          # r-   r/   r0   s   &r)   r"   Wigner9j.j1]  r3   r+   c                (    V P                   ^,          # r5   r/   r0   s   &r)   r$   Wigner9j.j2a  r3   r+   c                (    V P                   ^,          # r9   r/   r0   s   &r)   r   Wigner9j.j12e  r3   r+   c                (    V P                   ^,          # r=   r/   r0   s   &r)   r&   Wigner9j.j3i  r3   r+   c                (    V P                   ^,          # rA   r/   r0   s   &r)   r   Wigner9j.j4m  r3   r+   c                (    V P                   ^,          # rE   r/   r0   s   &r)   r   Wigner9j.j34q  r3   r+   c                (    V P                   ^,          # )   r/   r0   s   &r)   r   Wigner9j.j13u  r3   r+   c                (    V P                   ^,          # )   r/   r0   s   &r)   r   Wigner9j.j24y  r3   r+   c                (    V P                   ^,          # )   r/   r0   s   &r)   r^   
Wigner9j.j}  r3   r+   c                    \         ;QJ d0    R  V P                   4       F  '       d   K   R'       * # 	  R'       * # ! R  V P                   4       4      '       * # )c              3   8   "   T F  qP                   x  K  	  R # 5ir   rJ   rL   s   & r)   rO   'Wigner9j.is_symbolic.<locals>.<genexpr>  rQ   rR   FTrS   r0   s   &r)   rU   Wigner9j.is_symbolic  rW   r+   c                   aa VP                  V P                  4      VP                  V P                  4      VP                  V P                  4      3VP                  V P                  4      VP                  V P
                  4      VP                  V P                  4      3VP                  V P                  4      VP                  V P                  4      VP                  V P                  4      33o^p^pR.^,          p\        ^4       F%  o\        VV3R l\        ^4       4       4      VS&   K'  	  Rp\        ^4       EF  pRp\        ^4       F  oSS,          V,          p	VS,          V	P                  4       ,
          p
V
^,          pW,
          p\        V	P                  RV,          4      !  p	\        V	P                  RV,          4      !  p	Vf   T	pK  \        VP                  RV,          4      !  p\        VP                  V	4      !  pK  	  Vf   TpK  \        V4       F  p\        VP!                  R4      !  pK  	  \        VP!                  V4      !  pEK!  	  \        VP#                  RRR7      !  pV# )r:   c              3   `   <"   T F#  pSS,          V,          P                  4       x  K%  	  R # 5ir   rZ   r\   s   & r)   rO   #Wigner9j._pretty.<locals>.<genexpr>  ra   rb   Nrc   r   r   r   rd   )re   r"   r&   r   r$   r   r   r   r   r^   rf   rg   r[   r   rh   ri   rj   rk   rl   s   &&*           @@r)   rx   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aDGa1779,
F
 34s5y 12=E"EKKD$9:"EKKN3  y4[- !AGGEN+A+ , c56r+   c                   \        VP                  V P                  V P                  V P                  V P
                  V P                  V P                  V P                  V P                  V P                  3	4      pR \        V4      ,          # )zZ\left\{\begin{array}{ccc} %s & %s & %s \\ %s & %s & %s \\ %s & %s & %s \end{array}\right\})r   re   r"   r$   r   r&   r   r   r   r   r^   r{   r|   s   &&* r)   r~   Wigner9j._latex  sc    GNNTWWdggtxx488TXXtvv%? @l%L 	r+   c                   V P                   '       d   \        R 4      h\        V P                  V P                  V P
                  V P                  V P                  V P                  V P                  V P                  V P                  4	      # r   )rU   r   r   r"   r$   r   r&   r   r   r   r   r^   r   s   &,r)   r   Wigner9j.doit  sb    =>>$''488TWWdggtxxQUQYQY[_[c[ceiekekllr+   r   N)r   r   r   r   r   r    r   r"   r$   r   r&   r   r   r   r   r^   rU   rx   r~   r   r   r   r   s   @r)   r   r   P  s     (                   ; ;$Lm mr+   c                   \        V \        4      '       d   \        V 4      # \        V \        4      '       d   \	        V 4      # \        V \
        4      '       d-   \        V P                   Uu. uF  p\        V4      NK  	  up!  # \        V \        4      '       d*   \        \        V P                  4      V P                  4      # V # u upi )ao  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(   cg_simpr   baseexp)erN   s   & r)   r   r     s    B !SA	As		A	As		QVV4VcWS\V455	As		7166?AEE**	 5s   ,Cc                L   . p. p\        V 4      p V P                   EF  pVP                  \        4      '       d   \	        V\
        4      '       d   VP                  \        V4      4       KQ  \	        V\        4      '       d   ^pVP                   F5  p\	        V\
        4      '       d   V\        V4      ,          pK-  WE,          pK7  	  VP                  \        4      '       d   VP                  V4       K  VP                  V4       K  VP                  V4       EK  VP                  V4       EK  	  \        V4      w  rVP                  V4       \        V4      w  rVP                  V4       \        V4      w  rVP                  V4       \        V!  \        V!  ,           # )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
)r   r(   hasr   r   r   appendr   r   _check_varsh_871_1_check_varsh_871_2_check_varsh_872_9r   )r   cg_part
other_partrN   termstermothers   &      r)   r   r     s<    GJq	Avv772;;#s##!!,s"34C%%HHD!$,,d!33	 %
 99R==NN5)%%e,s#c"% ( (0NGe'0NGe'0NGe=3
+++r+   c                    \        \        R4      w  rr4V\        WV^ W4      ,          p^V,          ^,           \        V^ 4      ,          pV\	        V4      ,          p^V,          ^,           pW,           p	\        WVWtWW#V3W3W4	      # )a)r   alphablt)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:OAab1a**DaC!G^Aq))Dc"g:D1qJJ$d	u;LqfV`mmr+   c                 J   \        \        R4      w  rr4V\        WW) V^ 4      ,          p\        ^V,          ^,           4      \	        V^ 4      ,          pRW,
          ,          V,          \        V4      ,          p^V,          ^,           pW,           p	\        WVWtWW#V3W3W4	      # )r   )r   r   cr  rd   )r   r
   r   r   r   r  r  )
r  r   r   r  r  r  r  r  r	  r
  s
   &         r)   r   r     s    $ 9:OAab1fa++D!a=1--D!)RB'D1qJJ$d	u;LqfV`mmr+   c                    \        \        R4      w	  rr4rVrxp	V	\        WWEWx4      ^,          ,          p
\        P                  pV	\        V	4      ,          p\        W,
          4      p\        W%,           4      pW,           ^,           \        WV8  3^ \        W4      3WV8  34      ,
          pW,           V,
          p\        WWWW$WWW3WWE3VV4	      w  p p\        W,
          4      pW,           pV^,           V,
          W,           ^,           ,          pW},
          W,           ,          V,           V,           p\        WWWW$WWW3WWE3VV4	      w  p p\        WWEWx4      \        WWFWx4      ,          p
\        W#4      \        WV4      ,          p\        P                  p\        W,
          4      p\        W%,           4      pW,           ^,           \        WV8  3^ \        W4      3WV8  34      ,
          pW,           V,
          p\        WV\        P                  WW#WEWgV3WW4WV3VV4	      w  p p\        W,
          4      pW,           pV^,           V,
          W,           ^,           ,          pW},
          W,           ,          V,           V,           p\        WV\        P                  WW#WEWgV3WW4WV3VV4	      w  p pV VV,           V,           3# )r   )	r   r   alphapr  betabetapr  gammar  )
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2Afa
 b1A-q00D55Dc"g:DAE
AELAYq5zAr!x=1!e*MMJJ&t4YEVZ_dHilmvwk~  AK  MW  XIv 	AE
A	Aa%!)aeai(J%!%1$u,J&t4YEVZ_dHilmvwk~  AK  MW  XIv
 a*2a1+LLD%()DDD55DAE
AELAYq5zAr!x=1!e*MMJJ&t4	u^_glqvKwz{  EK  PT  z\  ^h  jt  uIv 	AE
A	Aa%!)aeai(J%!%1$u,J&t4	u^_glqvKwz{  EK  PT  z\  ^h  jt  uIvfvo...r+   c	           
     h   ^ p	^ p
V
\        V4      8  Ed   \        WJ,          V \        V4      4      pVf   V
^,          p
K<  VP                  V4      P                  '       g   V
^,          p
Kh  V Uu. uF  qW,          3NK  	  ppR.VP                  V4      ,          p\	        V
\        V4      4       EF  p\        WO,          V P                  V4      \        V4      \        V4      ,
          VP                  V4      VP                  V4      3R7      pVf   Kg  VP                  V4      P                  V4      P                  '       g   K  WP                  V^4      P                  V4      P                  V4      VP                  V4      VP                  V4      P                  V4      3WP                  V4      P                  V4      &   EK  	  \
        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       Eg   \        V Uu. uF  p\        V^,          4      NK  	  up!  pV Uu. uF  pV^ ,          NK  	  ppVP                  4        VP                  4        V Uu. uF  qP                  V4      NK  	   pV FW  p\        V^,          4      V8  g   K  VP                  V^,          VV^,          ,          ,
          V^,          ,          4       KY  	  V	VW!,          P                  V4      ,          ,          p	EK  V
^,          p
EK  WI3# u upi u upi u upi u upi )aL  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

N)r  c              3   (   "   T F  qR J x  K
  	  R # 5ir   r   )rM   r]   s   & r)   rO   !_check_cg_simp.<locals>.<genexpr>  s     /h9hs   TF)len	_check_cgsubsrK   rf   anyminr  sortreversepopr   )r  r  r  r  r  	variablesdep_variablesbuild_index_exprr
  r   r]   sub_1r  sub_depcg_indexr^   sub_2r   min_ltindicess   &&&&&&&&&           r)   r  r  V  s   R J	A
c)n
),c)n==FA$$U+555FA*78-Qux=-86*//66q#i.)AilDIIg,>IQTUbQc@ckoktktuzk{  ~B  ~G  ~G  HO  ~P  kQ  RE}??7+007AAA=>		"a@P@U@UV]@^@c@cdi@jlnlslstylz  }A  }F  }F  GN  }O  }T  }T  UZ  }[  >[H__W-2259: * s/h/sss/h///X?XTCQLX?@F,45HDQHG5LLNOO(/11mmA1 tAw<&($$tAwQ'?a&HJ ! &$)!1!1%!888JFA  + 9 @5 2s   1L L%9L*1L/Nc                    V P                  V4      pVf   R# VeH   \        V\        4      '       g   \        R4      hV^ ,          V^,          P	                  V4      8X  g   R# \        V4      V8X  d   V# R# )z2Checks whether a term matches the given expressionNzsign must be a tuple)matchr   r{   	TypeErrorr  r  )cg_termr  lengthr  matchess   &&&& r)   r  r    sk     mmD!G$&&233Aw47..11
7|v r+   c                 H    \        V 4      p \        V 4      p \        V 4      p V # 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                 $   \        R 4      p\        R4      p\        R4      pV P                  \        \	        WV^ W4      W!) V34      4      pVeA   \        V4      ^8X  d1   ^V,          ^,           \        V^ 4      ,          P                  V4      # V # )r   r   r  )r
   r   r.  r   r   r  r   r  )r   r   r   r  r.  s   &    r)   r4  r4    s~    S	AGES	AGGC1Q14ub!nEFESZ1_1q.A..44U;;Hr+   c                 `   \        R 4      p\        R4      p\        R4      pV P                  \        RW,
          ,          \	        WW) V^ 4      ,          W!) V34      4      pVeJ   \        V4      ^8X  d:   \        ^V,          ^,           4      \        V^ 4      ,          P                  V4      # V # )r   r   r  rd   )	r
   r   r.  r   r   r  r   r   r  )r   r   r   r  r.  s   &    r)   r5  r5    s    S	AGES	AGGR19b1fa;;eR^LNESZ1_QqS1WnQ2288??Hr+   c           	      P   \        R 4      p\        R4      p\        R4      p\        R4      p\        R4      p\        R4      p\        R4      p\        R4      p\        W1WBWW4      p	\        W1WBWh4      p
V P                  \	        W,          W) V3W$) V34      4      pVe;   \        V4      ^8X  d+   \        WV4      \        Wx4      ,          P                  V4      # V P                  \	        V	^,          W) V3W$) V34      4      pVe!   \        V4      ^8X  d   \        P                  # V # )r   r  r   r  r  cpr  gammap)
r   r
   r   r.  r   r  r   r  r	   r  )r   r   r  r   r  r  r:  r  r;  cg1cg2match1match2s   &            r)   r6  r6    s   GE6?DS	AS	AS	A	dBME(^F
Qq
)C
Qq
+CWWS5"a.4Q-@AFc&kQ.q%nU&CCII&QQWWSa%Q$A?@Fc&kQ.uuHr+   c                    \        V \        4      '       d   V 3^^3# . p^p\        V \        \        34      '       g   \	        R4      h\        V \        4      '       d|   V P
                  P                  '       d`   V P
                  P                  '       d>   \        V P
                  4       Uu. uF  q1P                  V P                  4      NK  	   pMV 3^^3# \        V \        4      '       dY   V P                   F4  p\        V\        4      '       d   VP                  V4       K,  W$,          pK6  	  WV\        V4      ,          3# R# u upi )r6   z term must be CG, Add, Mul or PowN)r   r   r   r   NotImplementedErrorr   rK   rf   r   r   r(   r  )r   cgcoeffrw   rN   s   &    r)   _cg_listrD    s    $w1}	BEdS#J''!"DEE$!3!3!388,1$((O=Oqii		"O=7Aq= $99C#r""		#	 
 %E
***  >s   -#E	)r   r   r   r   r   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   r4  r5  r6  rD  r   r+   r)   <module>rV     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+   