ó
    ‰*£h
+  ã                   óÞ   • S SK Jr  S SKJrJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S SKJrJr  S S	KJr  S S
KJr  S SKJrJrJr  \" S5      r " S S\5      rS r " S S\5      rg)é    )ÚExpr)ÚDefinedFunctionÚArgumentIndexError)ÚIÚpi)ÚS)ÚDummy)Úassoc_legendre)Ú	factorial)ÚAbsÚ	conjugate)Úexp)Úsqrt)ÚsinÚcosÚcotÚxc                   ó`   • \ rS rSrSr\S 5       rS rSS jrS r	S r
S rS	 rSS
 jrS rSrg)ÚYnmé   aè  
Spherical harmonics defined as

.. math::
    Y_n^m(\theta, \varphi) := \sqrt{\frac{(2n+1)(n-m)!}{4\pi(n+m)!}}
                              \exp(i m \varphi)
                              \mathrm{P}_n^m\left(\cos(\theta)\right)

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

``Ynm()`` gives the spherical harmonic function of order $n$ and $m$
in $\theta$ and $\varphi$, $Y_n^m(\theta, \varphi)$. The four
parameters are as follows: $n \geq 0$ an integer and $m$ an integer
such that $-n \leq m \leq n$ holds. The two angles are real-valued
with $\theta \in [0, \pi]$ and $\varphi \in [0, 2\pi]$.

Examples
========

>>> from sympy import Ynm, Symbol, simplify
>>> from sympy.abc import n,m
>>> theta = Symbol("theta")
>>> phi = Symbol("phi")

>>> Ynm(n, m, theta, phi)
Ynm(n, m, theta, phi)

Several symmetries are known, for the order:

>>> Ynm(n, -m, theta, phi)
(-1)**m*exp(-2*I*m*phi)*Ynm(n, m, theta, phi)

As well as for the angles:

>>> Ynm(n, m, -theta, phi)
Ynm(n, m, theta, phi)

>>> Ynm(n, m, theta, -phi)
exp(-2*I*m*phi)*Ynm(n, m, theta, phi)

For specific integers $n$ and $m$ we can evaluate the harmonics
to more useful expressions:

>>> simplify(Ynm(0, 0, theta, phi).expand(func=True))
1/(2*sqrt(pi))

>>> simplify(Ynm(1, -1, theta, phi).expand(func=True))
sqrt(6)*exp(-I*phi)*sin(theta)/(4*sqrt(pi))

>>> simplify(Ynm(1, 0, theta, phi).expand(func=True))
sqrt(3)*cos(theta)/(2*sqrt(pi))

>>> simplify(Ynm(1, 1, theta, phi).expand(func=True))
-sqrt(6)*exp(I*phi)*sin(theta)/(4*sqrt(pi))

>>> simplify(Ynm(2, -2, theta, phi).expand(func=True))
sqrt(30)*exp(-2*I*phi)*sin(theta)**2/(8*sqrt(pi))

>>> simplify(Ynm(2, -1, theta, phi).expand(func=True))
sqrt(30)*exp(-I*phi)*sin(2*theta)/(8*sqrt(pi))

>>> simplify(Ynm(2, 0, theta, phi).expand(func=True))
sqrt(5)*(3*cos(theta)**2 - 1)/(4*sqrt(pi))

>>> simplify(Ynm(2, 1, theta, phi).expand(func=True))
-sqrt(30)*exp(I*phi)*sin(2*theta)/(8*sqrt(pi))

>>> simplify(Ynm(2, 2, theta, phi).expand(func=True))
sqrt(30)*exp(2*I*phi)*sin(theta)**2/(8*sqrt(pi))

We can differentiate the functions with respect
to both angles:

>>> from sympy import Ynm, Symbol, diff
>>> from sympy.abc import n,m
>>> theta = Symbol("theta")
>>> phi = Symbol("phi")

>>> diff(Ynm(n, m, theta, phi), theta)
m*cot(theta)*Ynm(n, m, theta, phi) + sqrt((-m + n)*(m + n + 1))*exp(-I*phi)*Ynm(n, m + 1, theta, phi)

>>> diff(Ynm(n, m, theta, phi), phi)
I*m*Ynm(n, m, theta, phi)

Further we can compute the complex conjugation:

>>> from sympy import Ynm, Symbol, conjugate
>>> from sympy.abc import n,m
>>> theta = Symbol("theta")
>>> phi = Symbol("phi")

>>> conjugate(Ynm(n, m, theta, phi))
(-1)**(2*m)*exp(-2*I*m*phi)*Ynm(n, m, theta, phi)

To get back the well known expressions in spherical
coordinates, we use full expansion:

>>> from sympy import Ynm, Symbol, expand_func
>>> from sympy.abc import n,m
>>> theta = Symbol("theta")
>>> phi = Symbol("phi")

>>> expand_func(Ynm(n, m, theta, phi))
sqrt((2*n + 1)*factorial(-m + n)/factorial(m + n))*exp(I*m*phi)*assoc_legendre(n, m, cos(theta))/(2*sqrt(pi))

See Also
========

Ynm_c, Znm

References
==========

.. [1] https://en.wikipedia.org/wiki/Spherical_harmonics
.. [2] https://mathworld.wolfram.com/SphericalHarmonic.html
.. [3] https://functions.wolfram.com/Polynomials/SphericalHarmonicY/
.. [4] https://dlmf.nist.gov/14.30

c                 óh  • UR                  5       (       a<  U* n[        R                  U-  [        S[        -  U-  U-  5      -  [        XX45      -  $ UR                  5       (       a  U* n[        XX45      $ UR                  5       (       a(  U* n[        S[        -  U-  U-  5      [        XX45      -  $ g )Néþÿÿÿ)Úcould_extract_minus_signr   ÚNegativeOner   r   r   )ÚclsÚnÚmÚthetaÚphis        Úh/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/functions/special/spherical_harmonics.pyÚevalÚYnm.eval‰   sª   € ð ×%Ñ%×'Ñ'Ø�ˆAÜ—=‘= !Ñ#¤c¨"¬Q©$¨q©&°©*£oÑ5¼¸AÀ%Ó8MÑMÐMØ×)Ñ)×+Ñ+Ø�FˆEÜ�q˜UÓ(Ð(Ø×'Ñ'×)Ñ)Ø�$ˆCÜ�rœ!‘t˜A‘v˜c‘z“?¤S¨¨uÓ%:Ñ:Ð:ð *ó    c                 óN  • U R                   u  p#pE[        SU-  S-   S[        -  -  [        X#-
  5      -  [        X#-   5      -  5      [	        [
        U-  U-  5      -  [        X#[        U5      5      -  nUR                  [        [        U5      S-  * S-   5      [        U5      5      $ ©Né   é   é   )
Úargsr   r   r   r   r   r
   r   Úsubsr   )ÚselfÚhintsr   r   r   r   Úrvs          r    Ú_eval_expand_funcÚYnm._eval_expand_func˜   s–   € ØŸ9™9ÑˆˆeÜ�A�a‘C˜!‘G˜a¤™dÑ#¤i°±Ó&6Ñ6´yÀÁÓ7GÑGÓHÜ”A�a‘C˜‘G“ñÜ-¨a´C¸³JÓ?ñ@ˆð �w‰w”tœS ›Z¨™]˜N¨QÑ.Ó/´°U³Ó<Ð<r#   c                 ó†  • US:X  a  [        X5      eUS:X  a  [        X5      eUS:X  ad  U R                  u  p#pEU[        U5      -  [        X#XE5      -  [	        X#-
  X#-   S-   -  5      [        [        * U-  5      -  [        X#S-   XE5      -  -   $ US:X  a%  U R                  u  p#pE[        U-  [        X#XE5      -  $ [        X5      e)Nr'   r&   é   r(   )r   r)   r   r   r   r   r   )r+   Úargindexr   r   r   r   s         r    ÚfdiffÚ	Ynm.fdiffŸ   sÈ   € Ø�q‹=ä$ TÓ4Ð4Ø˜‹]ä$ TÓ4Ð4Ø˜‹]à#Ÿy™yÑˆA�%Øœ˜E›
‘N¤S¨¨uÓ%:Ñ:Ü˜!™% !¡%¨!¡)Ñ,Ó-´´Q°B°s±F³Ñ;¼cÀ!ÈÁUÈEÓ>WÑWñXð Yà˜‹]à#Ÿy™yÑˆA�%Ü�q‘5œ3˜q UÓ0Ñ0Ð0ä$ TÓ4Ð4r#   c                 ó    • U R                  SS9$ )NT©Úfunc)Úexpand©r+   r   r   r   r   Úkwargss         r    Ú_eval_rewrite_as_polynomialÚYnm._eval_rewrite_as_polynomial²   s   € ð �{‰{ ˆ{Ð%Ð%r#   c                 ó,   • U R                  [        5      $ ©N)Úrewriter   r9   s         r    Ú_eval_rewrite_as_sinÚYnm._eval_rewrite_as_sin·   s   € Ø�|‰|œCÓ Ð r#   c                 ó´   • SSK JnJn  U" U R                  SS95      nUR	                  [        [        U5      5      [        U5      05      nU" U" U5      5      $ )Nr   )ÚsimplifyÚtrigsimpTr6   )Úsympy.simplifyrC   rD   r8   Úxreplacer   r   )	r+   r   r   r   r   r:   rC   rD   Úterms	            r    Ú_eval_rewrite_as_cosÚYnm._eval_rewrite_as_cosº   sJ   € ç5ñ ˜Ÿ™¨˜Ð.Ó/ˆà�}‰}œc¤# e£*›o¬c°%«jÐ9Ó:ˆÙ™ ›Ó'Ð'r#   c                 ón   • U R                   u  pp4[        R                  U-  U R                  X* X45      -  $ r>   )r)   r   r   r7   )r+   r   r   r   r   s        r    Ú_eval_conjugateÚYnm._eval_conjugateÄ   s1   € àŸ9™9ÑˆˆeÜ�}‰}˜aÑ $§)¡)¨A¨r°5Ó">Ñ>Ð>r#   c                 ó’  • U R                   u  p4pV[        SU-  S-   S[        -  -  [        X4-
  5      -  [        X4-   5      -  5      [	        XF-  5      -  [        X4[	        U5      5      -  n[        SU-  S-   S[        -  -  [        X4-
  5      -  [        X4-   5      -  5      [        XF-  5      -  [        X4[	        U5      5      -  nXx4$ r%   )r)   r   r   r   r   r
   r   )	r+   Údeepr,   r   r   r   r   ÚreÚims	            r    Úas_real_imagÚYnm.as_real_imagÉ   s¿   € àŸ9™9ÑˆˆeÜ�A�a‘C˜!‘G˜a¤™dÑ#¤i°±Ó&6Ñ6´yÀÁÓ7GÑGÓHÜ�!‘%‹jñÜ)¨!´°E³
Ó;ñ<ˆä�A�a‘C˜!‘G˜a¤™dÑ#¤i°±Ó&6Ñ6´yÀÁÓ7GÑGÓHÜ�!‘%‹jñÜ)¨!´°E³
Ó;ñ<ˆàˆxˆr#   c                 ó˜  • SSK JnJn  U R                  S   R	                  U5      nU R                  S   R	                  U5      nU R                  S   R	                  U5      nU R                  S   R	                  U5      nU" U5         UR                  XEXg5      nS S S 5        [        R                  " WU5      $ ! , (       d  f       N%= f)Nr   )ÚmpÚworkprecr'   r&   r1   )ÚmpmathrT   rU   r)   Ú
_to_mpmathÚ	spherharmr   Ú_from_mpmath)	r+   ÚprecrT   rU   r   r   r   r   Úress	            r    Ú_eval_evalfÚYnm._eval_evalfÒ   sž   € ÷ 	(Ø�I‰I�a‰L×#Ñ# DÓ)ˆØ�I‰I�a‰L×#Ñ# DÓ)ˆØ—	‘	˜!‘×'Ñ'¨Ó-ˆØ�i‰i˜‰l×%Ñ% dÓ+ˆÙ�d�^Ø—,‘,˜q UÓ0ˆC÷ ä× Ò   dÓ+Ð+÷ �^ús   Â	B;Â;
C	© N)r(   )T)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úclassmethodr!   r.   r3   r;   r@   rH   rK   rQ   r\   Ú__static_attributes__r^   r#   r    r   r      sE   † ñwðr ñ
;ó ð
;ò=ô5ò&&ò
!ò(ò?ô
õ,r#   r   c                 ó,   • [        [        XX#5      5      $ )aÀ  
Conjugate spherical harmonics defined as

.. math::
    \overline{Y_n^m(\theta, \varphi)} := (-1)^m Y_n^{-m}(\theta, \varphi).

Examples
========

>>> from sympy import Ynm_c, Symbol, simplify
>>> from sympy.abc import n,m
>>> theta = Symbol("theta")
>>> phi = Symbol("phi")
>>> Ynm_c(n, m, theta, phi)
(-1)**(2*m)*exp(-2*I*m*phi)*Ynm(n, m, theta, phi)
>>> Ynm_c(n, m, -theta, phi)
(-1)**(2*m)*exp(-2*I*m*phi)*Ynm(n, m, theta, phi)

For specific integers $n$ and $m$ we can evaluate the harmonics
to more useful expressions:

>>> simplify(Ynm_c(0, 0, theta, phi).expand(func=True))
1/(2*sqrt(pi))
>>> simplify(Ynm_c(1, -1, theta, phi).expand(func=True))
sqrt(6)*exp(I*(-phi + 2*conjugate(phi)))*sin(theta)/(4*sqrt(pi))

See Also
========

Ynm, Znm

References
==========

.. [1] https://en.wikipedia.org/wiki/Spherical_harmonics
.. [2] https://mathworld.wolfram.com/SphericalHarmonic.html
.. [3] https://functions.wolfram.com/Polynomials/SphericalHarmonicY/

)r   r   )r   r   r   r   s       r    ÚYnm_crg   à   s   € ôP ”S˜˜uÓ*Ó+Ð+r#   c                   ó(   • \ rS rSrSr\S 5       rSrg)ÚZnmi  a×  
Real spherical harmonics defined as

.. math::

    Z_n^m(\theta, \varphi) :=
    \begin{cases}
      \frac{Y_n^m(\theta, \varphi) + \overline{Y_n^m(\theta, \varphi)}}{\sqrt{2}} &\quad m > 0 \\
      Y_n^m(\theta, \varphi) &\quad m = 0 \\
      \frac{Y_n^m(\theta, \varphi) - \overline{Y_n^m(\theta, \varphi)}}{i \sqrt{2}} &\quad m < 0 \\
    \end{cases}

which gives in simplified form

.. math::

    Z_n^m(\theta, \varphi) =
    \begin{cases}
      \frac{Y_n^m(\theta, \varphi) + (-1)^m Y_n^{-m}(\theta, \varphi)}{\sqrt{2}} &\quad m > 0 \\
      Y_n^m(\theta, \varphi) &\quad m = 0 \\
      \frac{Y_n^m(\theta, \varphi) - (-1)^m Y_n^{-m}(\theta, \varphi)}{i \sqrt{2}} &\quad m < 0 \\
    \end{cases}

Examples
========

>>> from sympy import Znm, Symbol, simplify
>>> from sympy.abc import n, m
>>> theta = Symbol("theta")
>>> phi = Symbol("phi")
>>> Znm(n, m, theta, phi)
Znm(n, m, theta, phi)

For specific integers n and m we can evaluate the harmonics
to more useful expressions:

>>> simplify(Znm(0, 0, theta, phi).expand(func=True))
1/(2*sqrt(pi))
>>> simplify(Znm(1, 1, theta, phi).expand(func=True))
-sqrt(3)*sin(theta)*cos(phi)/(2*sqrt(pi))
>>> simplify(Znm(2, 1, theta, phi).expand(func=True))
-sqrt(15)*sin(2*theta)*cos(phi)/(4*sqrt(pi))

See Also
========

Ynm, Ynm_c

References
==========

.. [1] https://en.wikipedia.org/wiki/Spherical_harmonics
.. [2] https://mathworld.wolfram.com/SphericalHarmonic.html
.. [3] https://functions.wolfram.com/Polynomials/SphericalHarmonicY/

c                 ó,  • UR                   (       a'  [        XX45      [        XX45      -   [        S5      -  nU$ UR                  (       a  [        XX45      $ UR
                  (       a.  [        XX45      [        XX45      -
  [        S5      [        -  -  nU$ g )Nr&   )Úis_positiver   rg   r   Úis_zeroÚis_negativer   )r   r   r   r   r   Úzzs         r    r!   ÚZnm.evalE  sy   € à�=�=Ü�a˜EÓ'¬%°°eÓ*AÑAÄTÈ!ÃWÑLˆBØˆIØ�Y�YÜ�q˜UÓ(Ð(Ø�]�]Ü�a˜EÓ'¬%°°eÓ*AÑAÄdÈ1ÃgÌaÁiÑPˆBØˆIð r#   r^   N)r_   r`   ra   rb   rc   rd   r!   re   r^   r#   r    ri   ri     s   † ñ7ðr ñó ór#   ri   N)Úsympy.core.exprr   Úsympy.core.functionr   r   Úsympy.core.numbersr   r   Úsympy.core.singletonr   Úsympy.core.symbolr	   Úsympy.functionsr
   Ú(sympy.functions.combinatorial.factorialsr   Ú$sympy.functions.elementary.complexesr   r   Ú&sympy.functions.elementary.exponentialr   Ú(sympy.functions.elementary.miscellaneousr   Ú(sympy.functions.elementary.trigonometricr   r   r   Ú_xr   rg   ri   r^   r#   r    Ú<module>r|      sU   ðÝ  ß Cß $Ý "Ý #Ý *Ý >ß ?Ý 6Ý 9ß BÑ Bá
ˆ3ƒZ€ôN,ˆ/ô N,òb(,ôVCˆ/õ Cr#   