+
    i
+                         ^ RI Ht ^ RIHtHt ^ RIHt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HtHt ]! R4      t ! R R]4      tR t ! R R]4      tR# )    )Expr)DefinedFunctionArgumentIndexError)Ipi)S)Dummy)assoc_legendre)	factorial)Abs	conjugate)exp)sqrt)sincoscotxc                   l   a  ] tR t^t o Rt]R 4       tR tRR ltR t	R t
R tR tRR	 ltR
 tRtV tR# )Ynma  
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P                  4       '       dU   V) p\        P                  V,          \        R\        ,          V,          V,          4      ,          \        WW44      ,          # VP                  4       '       d   V) p\        WW44      # VP                  4       '       d9   V) p\        R\        ,          V,          V,          4      \        WW44      ,          # R# )   N)could_extract_minus_signr   NegativeOner   r   r   )clsnmthetaphis   &&&&&i/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/functions/special/spherical_harmonics.pyevalYnm.eval   s     %%''A==!#c"Q$q&*o5A%8MMM))++FEqU((''))$Cr!tAvcz?Su%::: *    c                   V P                   w  r#rE\        ^V,          ^,           ^\        ,          ,          \        W#,
          4      ,          \        W#,           4      ,          4      \	        \
        V,          V,          4      ,          \        W#\        V4      4      ,          pVP                  \        \        V4      ^,          ) ^,           4      \        V4      4      # r   )
argsr   r   r   r   r   r
   r   subsr   )selfhintsr   r   r   r   rvs   &,     r    _eval_expand_funcYnm._eval_expand_func   s    99eAaC!Gad#i&66y7GGHAaCG-aCJ?@ wwtSZ]NQ./U<<r#   c                   V^8X  d   \        W4      hV^8X  d   \        W4      hV^8X  d   V P                  w  r#rEV\        V4      ,          \        W#WE4      ,          \	        W#,
          W#,           ^,           ,          4      \        \        ) V,          4      ,          \        W#^,           WE4      ,          ,           # V^8X  d.   V P                  w  r#rE\        V,          \        W#WE4      ,          # \        W4      h)   )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]#yyA%E
NSu%::!%!%!),-QBsF;c!UE>WWX Y]#yyA%q53qU000$T44r#   c                &    V P                  R R7      # )Tfunc)expandr(   r   r   r   r   kwargss   &&&&&,r    _eval_rewrite_as_polynomialYnm._eval_rewrite_as_polynomial   s     {{{%%r#   c                ,    V P                  \        4      # N)rewriter   r6   s   &&&&&,r    _eval_rewrite_as_sinYnm._eval_rewrite_as_sin   s    ||C  r#   c                    ^ RI HpHp V! V P                  RR7      4      pVP	                  \        \        V4      4      \        V4      /4      pV! V! V4      4      # )r   )simplifytrigsimpTr3   )sympy.simplifyr@   rA   r5   xreplacer   r   )	r(   r   r   r   r   r7   r@   rA   terms	   &&&&&,   r    _eval_rewrite_as_cosYnm._eval_rewrite_as_cos   sJ    5 ./}}c#e*oc%j9:''r#   c                ~    V P                   w  rr4\        P                  V,          V P                  W) W44      ,          # r;   )r&   r   r   r4   )r(   r   r   r   r   s   &    r    _eval_conjugateYnm._eval_conjugate   s1    99e}}a$))Ar5">>>r#   c                B   V P                   w  r4rV\        ^V,          ^,           ^\        ,          ,          \        W4,
          4      ,          \        W4,           4      ,          4      \	        WF,          4      ,          \        W4\	        V4      4      ,          p\        ^V,          ^,           ^\        ,          ,          \        W4,
          4      ,          \        W4,           4      ,          4      \        WF,          4      ,          \        W4\	        V4      4      ,          pWx3# 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    99eAaC!Gad#i&66y7GGH!%j)!E
;<AaC!Gad#i&66y7GGH!%j)!E
;<xr#   c                   ^ RI HpHp V P                  ^ ,          P	                  V4      pV P                  ^,          P	                  V4      pV P                  ^,          P	                  V4      pV P                  ^,          P	                  V4      pV! V4      ;_uu_ 4        VP                  WEWg4      pRRR4       \        P                  ! XV4      #   + '       g   i     L'; i)r   )mpworkprecN)mpmathrQ   rR   r&   
_to_mpmath	spherharmr   _from_mpmath)	r(   precrQ   rR   r   r   r   r   ress	   &&       r    _eval_evalfYnm._eval_evalf   s     	(IIaL##D)IIaL##D)		!''-iil%%d+d^^,,qU0C   d++ ^s   !CC#	 N)   )T)__name__
__module____qualname____firstlineno____doc__classmethodr!   r+   r0   r8   r=   rE   rH   rN   rY   __static_attributes____classdictcell____classdict__s   @r    r   r      sM     wr 
; 
;=5&&
!(?
, ,r#   r   c                ,    \        \        WW#4      4      # )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_crh      s    P Su*++r#   c                   4   a  ] tR tRt o Rt]R 4       tRtV tR# )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                \   VP                   '       d0   \        WW44      \        WW44      ,           \        ^4      ,          pV# VP                  '       d   \        WW44      # VP
                  '       d;   \        WW44      \        WW44      ,
          \        ^4      \        ,          ,          pV# R# )r   N)is_positiver   rh   r   is_zerois_negativer   )r   r   r   r   r   zzs   &&&&& r    r!   Znm.evalE  s    ===aE'%e*AAT!WLBIYYYqU((]]]aE'%e*AAd1gaiPBI r#   r[   N)	r]   r^   r_   r`   ra   rb   r!   rc   rd   re   s   @r    rj   rj     s     7r  r#   rj   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   rh   rj   r[   r#   r    <module>r}      sU      C $ " # * > ? 6 9 B B
3ZN,/ N,b(,VC/ Cr#   