Ë
    7^(h
+  ã                   óÞ   — d dl mZ d dlmZ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 d dlmZmZ d d	lmZ d d
lmZ d dlmZmZmZ  ed«      Z G d„ de«      Zd„ Z G d„ de«      Zy)é    )ÚExpr)ÚDefinedFunctionÚArgumentIndexError)ÚIÚpi)ÚS)ÚDummy)Úassoc_legendre)Ú	factorial)ÚAbsÚ	conjugate)Úexp)Úsqrt)ÚsinÚcosÚcotÚxc                   óT   — e Zd ZdZed„ «       Zd„ Zdd„Zd„ Zd„ Z	d„ Z
d„ Zdd	„Zd
„ Zy)ÚYnma4  
    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                 óV  — |j                  «       r>| }t        j                  |z  t        dt        z  |z  |z  «      z  t        ||||«      z  S |j                  «       r| }t        ||||«      S |j                  «       r*| }t        dt        z  |z  |z  «      t        ||||«      z  S y )Néþÿÿÿ)Úcould_extract_minus_signr   ÚNegativeOner   r   r   )ÚclsÚnÚmÚthetaÚphis        úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/functions/special/spherical_harmonics.pyÚevalzYnm.eval‰   s­   € ð ×%Ñ%Ô'Ø�ˆAÜ—=‘= !Ñ#¤c¨"¬Q©$¨q©&°©*£oÑ5¼¸A¸qÀ%ÈÓ8MÑMÐMØ×)Ñ)Ô+Ø�FˆEÜ�q˜!˜U CÓ(Ð(Ø×'Ñ'Ô)Ø�$ˆCÜ�rœ!‘t˜A‘v˜c‘z“?¤S¨¨A¨u°cÓ%:Ñ:Ð:ð *ó    c                 óX  — | j                   \  }}}}t        d|z  dz   dt        z  z  t        ||z
  «      z  t        ||z   «      z  «      t	        t
        |z  |z  «      z  t        ||t        |«      «      z  }|j                  t        t        |«      dz   dz   «      t        |«      «      S ©Né   é   é   )
Úargsr   r   r   r   r   r
   r   Úsubsr   )ÚselfÚhintsr   r   r   r   Úrvs          r   Ú_eval_expand_funczYnm._eval_expand_func˜   s    € ØŸ9™9Ñˆˆ1ˆe�SÜ�A�a‘C˜!‘G˜a¤™dÑ#¤i°°A±Ó&6Ñ6´yÀÀQÁÓ7GÑGÓHÜ”A�a‘C˜‘G“ñÜ-¨a°´C¸³JÓ?ñ@ˆð �w‰w”tœS ›Z¨™]˜N¨QÑ.Ó/´°U³Ó<Ð<r!   c                 óœ  — |dk(  rt        | |«      ‚|dk(  rt        | |«      ‚|dk(  rl| j                  \  }}}}|t        |«      z  t        ||||«      z  t	        ||z
  ||z   dz   z  «      t        t         |z  «      z  t        ||dz   ||«      z  z   S |dk(  r)| j                  \  }}}}t        |z  t        ||||«      z  S t        | |«      ‚)Nr%   r$   é   r&   )r   r'   r   r   r   r   r   )r)   Úargindexr   r   r   r   s         r   Úfdiffz	Ynm.fdiffŸ   sç   € Ø�qŠ=ä$ T¨8Ó4Ð4Ø˜Š]ä$ T¨8Ó4Ð4Ø˜Š]à#Ÿy™yÑˆAˆq�%˜Øœ˜E›
‘N¤S¨¨A¨u°cÓ%:Ñ:Ü˜!˜a™% ! a¡%¨!¡)Ñ,Ó-´´Q°B°s±F³Ñ;¼cÀ!ÀQÈÁUÈEÐSVÓ>WÑWñXð Yà˜Š]à#Ÿy™yÑˆAˆq�%˜Ü�q‘5œ3˜q ! U¨CÓ0Ñ0Ð0ä$ T¨8Ó4Ð4r!   c                 ó&   — | j                  d¬«      S )NT©Úfunc)Úexpand©r)   r   r   r   r   Úkwargss         r   Ú_eval_rewrite_as_polynomialzYnm._eval_rewrite_as_polynomial²   s   € ð �{‰{ ˆ{Ó%Ð%r!   c                 ó,   — | j                  t        «      S ©N)Úrewriter   r5   s         r   Ú_eval_rewrite_as_sinzYnm._eval_rewrite_as_sin·   s   € Ø�|‰|œCÓ Ð r!   c                 óº   — ddl m}m}  || j                  d¬«      «      }|j	                  t        t        |«      «      t        |«      i«      } | ||«      «      S )Nr   )ÚsimplifyÚtrigsimpTr2   )Úsympy.simplifyr=   r>   r4   Úxreplacer   r   )	r)   r   r   r   r   r6   r=   r>   Úterms	            r   Ú_eval_rewrite_as_coszYnm._eval_rewrite_as_cosº   sJ   € ç5ñ ˜Ÿ™¨˜Ó.Ó/ˆà�}‰}œc¤# e£*›o¬c°%«jÐ9Ó:ˆÙ™ ›Ó'Ð'r!   c                 óv   — | j                   \  }}}}t        j                  |z  | j                  || ||«      z  S r9   )r'   r   r   r3   )r)   r   r   r   r   s        r   Ú_eval_conjugatezYnm._eval_conjugateÄ   s9   € àŸ9™9Ñˆˆ1ˆe�SÜ�}‰}˜aÑ $§)¡)¨A°¨r°5¸#Ó">Ñ>Ð>r!   c                 ó¨  — | j                   \  }}}}t        d|z  dz   dt        z  z  t        ||z
  «      z  t        ||z   «      z  «      t	        ||z  «      z  t        ||t	        |«      «      z  }t        d|z  dz   dt        z  z  t        ||z
  «      z  t        ||z   «      z  «      t        ||z  «      z  t        ||t	        |«      «      z  }||fS r#   )r'   r   r   r   r   r
   r   )	r)   Údeepr*   r   r   r   r   ÚreÚims	            r   Úas_real_imagzYnm.as_real_imagÉ   sÕ   € àŸ9™9Ñˆˆ1ˆe�SÜ�A�a‘C˜!‘G˜a¤™dÑ#¤i°°A±Ó&6Ñ6´yÀÀQÁÓ7GÑGÓHÜ�!�C‘%‹jñÜ)¨!¨Q´°E³
Ó;ñ<ˆä�A�a‘C˜!‘G˜a¤™dÑ#¤i°°A±Ó&6Ñ6´yÀÀQÁÓ7GÑGÓHÜ�!�C‘%‹jñÜ)¨!¨Q´°E³
Ó;ñ<ˆà�Bˆxˆr!   c                 ó�  — ddl m}m} | j                  d   j	                  |«      }| j                  d   j	                  |«      }| j                  d   j	                  |«      }| j                  d   j	                  |«      } ||«      5  |j                  ||||«      }d d d «       t        j                  |«      S # 1 sw Y   ŒxY w)Nr   )ÚmpÚworkprecr%   r$   r.   )ÚmpmathrK   rL   r'   Ú
_to_mpmathÚ	spherharmr   Ú_from_mpmath)	r)   ÚprecrK   rL   r   r   r   r   Úress	            r   Ú_eval_evalfzYnm._eval_evalfÒ   sª   € ÷ 	(Ø�I‰I�a‰L×#Ñ# DÓ)ˆØ�I‰I�a‰L×#Ñ# DÓ)ˆØ—	‘	˜!‘×'Ñ'¨Ó-ˆØ�i‰i˜‰l×%Ñ% dÓ+ˆÙ�d‹^ñ 	1Ø—,‘,˜q ! U¨CÓ0ˆC÷	1ä× Ñ   dÓ+Ð+÷	1ð 	1ús   Â	B<Â<CN)r&   )T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr    r,   r0   r7   r;   rB   rD   rI   rS   © r!   r   r   r      sE   „ ñwðr ñ
;ó ð
;ò=ó5ò&&ò
!ò(ò?ó
ó,r!   r   c                 ó0   — t        t        | |||«      «      S )a0  
    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_cr[   à   s   € ôP ”S˜˜A˜u cÓ*Ó+Ð+r!   c                   ó    — e Zd ZdZed„ «       Zy)ÚZnma{  
    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                 ó"  — |j                   r+t        ||||«      t        ||||«      z   t        d«      z  }|S |j                  rt        ||||«      S |j
                  r2t        ||||«      t        ||||«      z
  t        d«      t        z  z  }|S y )Nr$   )Úis_positiver   r[   r   Úis_zeroÚis_negativer   )r   r   r   r   r   Úzzs         r   r    zZnm.evalE  s�   € à�=Š=Ü�a˜˜E 3Ó'¬%°°1°e¸SÓ*AÑAÄTÈ!ÃWÑLˆBØˆIØ�YŠYÜ�q˜!˜U CÓ(Ð(Ø�]Š]Ü�a˜˜E 3Ó'¬%°°1°e¸SÓ*AÑAÄdÈ1ÃgÌaÁiÑPˆBØˆIð r!   N)rT   rU   rV   rW   rX   r    rY   r!   r   r]   r]     s   „ ñ7ðr ñó ñr!   r]   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   r[   r]   rY   r!   r   ú<module>ro      sU   ðÝ  ß Cß $Ý "Ý #Ý *Ý >ß ?Ý 6Ý 9ß BÑ Bá
ˆ3ƒZ€ôN,ˆ/ô N,òb(,ôVCˆ/õ Cr!   