Ë
    7^(h�Y  ã                   ó
  — d 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 ddlmZmZ dd	lmZ dd
lmZ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giZd„ Zd„ Z d„ Z!d„ Z" G d„ de«      Z# G d„ de#«      Z$dd„Z%y)zFourier Seriesé    )ÚooÚpi)ÚWild)ÚExpr)ÚAdd)ÚTuple)ÚS)ÚDummyÚSymbol)Úsympify)ÚsinÚcosÚsinc)Ú
SeriesBase)Ú
SeqFormula)ÚInterval)Úis_sequence)Úfourier_seriesÚ
matplotlibc                 ó$  — ddl m} |d   |d   |d   z
  }}t        d|z  t        z  |z  |z  «      }d|z   || |z  |«      z  |z  }|j	                  |t
        j                  «      dz  }|t        d|z   || |z  |«      z  |z  |dt        f«      fS )z,Returns the cos sequence in a Fourier seriesr   ©Ú	integrateé   é   )	Úsympy.integralsr   r   r   Úsubsr	   ÚZeror   r   )	ÚfuncÚlimitsÚnr   ÚxÚLÚcos_termÚformulaÚa0s	            úR/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/series/fourier.pyÚfourier_cos_seqr'      s«   € å)Ø�!‰9�f˜Q‘i &¨¡)Ñ+€q€AÜ�1�Q‘3”r‘6˜!‘8˜a‘<Ó €HØ�(‰l™Y t¨h¡¸Ó?Ñ?À!ÑC€GØ	�‰�aœŸ™Ó	  1Ñ	$€BØŒz˜!˜h™,©°4¸(±?ÀFÓ)KÑKØñØ ! 1¤b˜zó+ð +ð +ó    c                 ó°   — ddl m} |d   |d   |d   z
  }}t        d|z  t        z  |z  |z  «      }t	        d|z   || |z  |«      z  |z  |dt
        f«      S )z,Returns the sin sequence in a Fourier seriesr   r   r   r   )r   r   r   r   r   r   )r   r   r    r   r!   r"   Úsin_terms          r&   Úfourier_sin_seqr+       sm   € å)Ø�!‰9�f˜Q‘i &¨¡)Ñ+€q€AÜ�1�Q‘3”r‘6˜!‘8˜a‘<Ó €HÜ�a˜(‘l¡Y¨t°h©ÀÓ%GÑGØñØ˜q¤"˜:ó'ð 'r(   c                 óš  — d„ }d\  }}}|€ || «      t          t         }}}t        |t        «      r0t        |«      dk(  r|\  }}}nt        |«      dk(  r || «      }|\  }}t	        |t
        «      r|�|€t        dt        |«      z  «      ‚t        j                  t        j                  g}||v s||v rt        d«      ‚t        |||f«      S )a  
    Limits should be of the form (x, start, stop).
    x should be a symbol. Both start and stop should be bounded.

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

    * If x is not given, x is determined from func.
    * If limits is None. Limit of the form (x, -pi, pi) is returned.

    Examples
    ========

    >>> from sympy.series.fourier import _process_limits as pari
    >>> from sympy.abc import x
    >>> pari(x**2, (x, -2, 2))
    (x, -2, 2)
    >>> pari(x**2, (-2, 2))
    (x, -2, 2)
    >>> pari(x**2, None)
    (x, -pi, pi)
    c                 óŒ   — | j                   }t        |«      dk(  r|j                  «       S |st        d«      S t	        d| z  «      ‚)Nr   Úkz¬ specify dummy variables for %s. If the function contains more than one free symbol, a dummy variable should be supplied explicitly e.g. FourierSeries(m*n**2, (n, -pi, pi)))Úfree_symbolsÚlenÚpopr
   Ú
ValueError)r   Úfrees     r&   Ú_find_xz _process_limits.<locals>._find_x@   sN   € Ø× Ñ ˆÜˆt‹9˜Š>Ø—8‘8“:ÐÙÜ˜“:ÐäðPð ñóð r(   )NNNé   r   zInvalid limits given: %sz.Both the start and end value should be bounded)r   r   r   r0   Ú
isinstancer   r2   Ústrr	   ÚNegativeInfinityÚInfinityr   )r   r   r4   r!   ÚstartÚstopÚ	unboundeds          r&   Ú_process_limitsr=   )   sÓ   € ò.ð &�N€A€uˆdØ€~Ù  ›¬¨¬R�$ˆ5ˆÜ�6œ5Ô!Üˆv‹;˜!ÒØ#‰NˆAˆu‘dÜ�‹[˜AÒÙ˜“ˆAØ ‰KˆE�4ä�aœÔ  E M°T°\ÜÐ3´c¸&³kÑAÓBÐBä×#Ñ#¤Q§Z¡ZÐ0€IØ�	Ñ˜T YÑ.ÜÐIÓJÐJä�A�u˜dÐ#Ó$Ð$r(   c                 óB  ‡‡‡— d„ }ˆˆfd„}ddl m}m}m}  | | || «      «      «      }|j	                  «       }	t        dd„ d„ g¬«      Št        d	ˆfd
„g¬«      Š|	d   D ]8  }
|
j                  «       d   }|D ]  } ||‰«      rŒ ||‰|«      rŒd| fc c S  Œ: d|fS )Nc                 ó   — || j                   vS ©N©r/   )Úexprsr!   s     r&   Úcheck_fxzfinite_check.<locals>.check_fxc   s   € Ø˜×*Ñ*Ð*Ð*r(   c                 ó–   •— t        | t        t        f«      r2| j                  d   }|j	                  ‰t
        |z  z  |z  ‰z   «      �yyy )Nr   TF)r6   r   r   ÚargsÚmatchr   )Ú_exprr!   r"   Úsincos_argsÚaÚbs       €€r&   Úcheck_sincosz"finite_check.<locals>.check_sincosf   sJ   ø€ Ü�eœc¤3˜ZÔ(ØŸ*™* Q™-ˆKà× Ñ  ¤B q¡D¡¨!¡¨a¡Ó0Ð<Øàð )r(   r   )ÚTR2ÚTR1Úsincos_to_sumrI   c                 ó   — | j                   S r@   ©Ú
is_Integer©r.   s    r&   ú<lambda>zfinite_check.<locals>.<lambda>s   s
   € ¨¯©€ r(   c                 ó(   — | t         j                  k7  S r@   ©r	   r   rR   s    r&   rS   zfinite_check.<locals>.<lambda>s   s   € ÀÄQÇVÁVÁ€ r(   ©Ú
propertiesrJ   c                 ó    •— ‰| j                   vS r@   rA   ©r.   r!   s    €r&   rS   zfinite_check.<locals>.<lambda>t   s   ø€ ¨°·±Ð(?€ r(   r   FT)Úsympy.simplify.furL   rM   rN   Úas_coeff_addr   Úas_coeff_mul)Úfr!   r"   rC   rK   rL   rM   rN   rG   Ú	add_coeffÚsÚ
mul_coeffsÚtrI   rJ   s    `           @@r&   Úfinite_checkrb   a   s´   ú€ ò+õ÷ :Ñ9Ù™#™c !›f›+Ó&€EØ×"Ñ"Ó$€IäˆSÑ4Ñ6KÐNÔO€AÜˆSÓ?ÐBÔC€Aà�q‰\ò  ˆØ—^‘^Ó% aÑ(ˆ
Øò 	 ˆAÙ˜Q •N¡l°1°a¸Õ&;Ø˜a�x”ñ	 ð ð �ˆ;Ð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ed„ «       Zd„ Zdd„Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚFourierSeriesa9  Represents Fourier sine/cosine series.

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

    This class only represents a fourier series.
    No computation is performed.

    For how to compute Fourier series, see the :func:`fourier_series`
    docstring.

    See Also
    ========

    sympy.series.fourier.fourier_series
    c                 óN   — t        t        |«      }t        j                  | g|¢­Ž S r@   )Úmapr   r   Ú__new__)ÚclsrE   s     r&   rg   zFourierSeries.__new__�   s"   € Ü”7˜DÓ!ˆÜ�|‰|˜CÐ' $Ò'Ð'r(   c                 ó    — | j                   d   S ©Nr   ©rE   ©Úselfs    r&   ÚfunctionzFourierSeries.function”   s   € à�y‰y˜‰|Ðr(   c                 ó&   — | j                   d   d   S ©Nr   r   rk   rl   s    r&   r!   zFourierSeries.x˜   ó   € à�y‰y˜‰|˜A‰Ðr(   c                 óJ   — | j                   d   d   | j                   d   d   fS )Nr   r   rk   rl   s    r&   ÚperiodzFourierSeries.periodœ   s%   € à—	‘	˜!‘˜Q‘ §¡¨1¡¨a¡Ð1Ð1r(   c                 ó&   — | j                   d   d   S )Nr   r   rk   rl   s    r&   r%   zFourierSeries.a0    rq   r(   c                 ó&   — | j                   d   d   S )Nr   r   rk   rl   s    r&   ÚanzFourierSeries.an¤   rq   r(   c                 ó&   — | j                   d   d   S )Nr   rk   rl   s    r&   ÚbnzFourierSeries.bn¨   rq   r(   c                 ó"   — t        dt        «      S rj   )r   r   rl   s    r&   ÚintervalzFourierSeries.interval¬   s   € ä˜œ2‹Ðr(   c                 ó.   — | j                   j                  S r@   )rz   Úinfrl   s    r&   r:   zFourierSeries.start°   ó   € à�}‰}× Ñ Ð r(   c                 ó.   — | j                   j                  S r@   )rz   Úsuprl   s    r&   r;   zFourierSeries.stop´   r}   r(   c                 ó   — t         S r@   )r   rl   s    r&   ÚlengthzFourierSeries.length¸   s   € äˆ	r(   c                 óX   — t        | j                  d   | j                  d   z
  «      dz  S )Nr   r   r   )Úabsrs   rl   s    r&   r"   zFourierSeries.L¼   s'   € ä�4—;‘;˜q‘> D§K¡K°¡NÑ2Ó3°aÑ7Ð7r(   c                 óB   — | j                   }|j                  |«      r| S y r@   )r!   Úhas)rm   ÚoldÚnewr!   s       r&   Ú
_eval_subszFourierSeries._eval_subsÀ   s    € Ø�F‰FˆØ�7‰7�1Œ:ØˆKð r(   c                 ó´   — |€t        | «      S g }| D ]=  }t        |«      |k(  r	 t        |Ž S |t        j                  usŒ-|j	                  |«       Œ? t        |Ž S )aÍ  
        Return the first n nonzero terms of the series.

        If ``n`` is None return an iterator.

        Parameters
        ==========

        n : int or None
            Amount of non-zero terms in approximation or None.

        Returns
        =======

        Expr or iterator :
            Approximation of function expanded into Fourier series.

        Examples
        ========

        >>> from sympy import fourier_series, pi
        >>> from sympy.abc import x
        >>> s = fourier_series(x, (x, -pi, pi))
        >>> s.truncate(4)
        2*sin(x) - sin(2*x) + 2*sin(3*x)/3 - sin(4*x)/2

        See Also
        ========

        sympy.series.fourier.FourierSeries.sigma_approximation
        )Úiterr0   r	   r   Úappendr   )rm   r    Útermsra   s       r&   ÚtruncatezFourierSeries.truncateÅ   sf   € ð@ ˆ9Ü˜“:ÐàˆØò 	 ˆAÜ�5‹z˜QŠØô �Eˆ{Ðð œŸ™ŠØ—‘˜Q•ð		 ô �Eˆ{Ðr(   c                 ó®   — t        | d| «      D ��cg c]/  \  }}|t        j                  urt        t        |z  |z  «      |z  ‘Œ1 }}}t        |Ž S c c}}w )a  
        Return :math:`\sigma`-approximation of Fourier series with respect
        to order n.

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

        Sigma approximation adjusts a Fourier summation to eliminate the Gibbs
        phenomenon which would otherwise occur at discontinuities.
        A sigma-approximated summation for a Fourier series of a T-periodical
        function can be written as

        .. math::
            s(\theta) = \frac{1}{2} a_0 + \sum _{k=1}^{m-1}
            \operatorname{sinc} \Bigl( \frac{k}{m} \Bigr) \cdot
            \left[ a_k \cos \Bigl( \frac{2\pi k}{T} \theta \Bigr)
            + b_k \sin \Bigl( \frac{2\pi k}{T} \theta \Bigr) \right],

        where :math:`a_0, a_k, b_k, k=1,\ldots,{m-1}` are standard Fourier
        series coefficients and
        :math:`\operatorname{sinc} \Bigl( \frac{k}{m} \Bigr)` is a Lanczos
        :math:`\sigma` factor (expressed in terms of normalized
        :math:`\operatorname{sinc}` function).

        Parameters
        ==========

        n : int
            Highest order of the terms taken into account in approximation.

        Returns
        =======

        Expr :
            Sigma approximation of function expanded into Fourier series.

        Examples
        ========

        >>> from sympy import fourier_series, pi
        >>> from sympy.abc import x
        >>> s = fourier_series(x, (x, -pi, pi))
        >>> s.sigma_approximation(4)
        2*sin(x)*sinc(pi/4) - 2*sin(2*x)/pi + 2*sin(3*x)*sinc(3*pi/4)/3

        See Also
        ========

        sympy.series.fourier.FourierSeries.truncate

        Notes
        =====

        The behaviour of
        :meth:`~sympy.series.fourier.FourierSeries.sigma_approximation`
        is different from :meth:`~sympy.series.fourier.FourierSeries.truncate`
        - it takes all nonzero terms of degree smaller than n, rather than
        first n nonzero ones.

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Gibbs_phenomenon
        .. [2] https://en.wikipedia.org/wiki/Sigma_approximation
        N)Ú	enumerater	   r   r   r   r   )rm   r    Úira   rŒ   s        r&   Úsigma_approximationz!FourierSeries.sigma_approximationñ   s\   € ôD 3<¸DÀÀ!¸HÓ2E÷ %©$¨!¨QØœQŸV™V‘Oô ”b˜1‘f˜q‘jÓ! AÓ%ð %ˆñ %ä�Eˆ{Ðùó%s   ’4Ac                 ó  — t        |«      | j                  }}||j                  v rt        d|›d|›�«      ‚| j                  |z   }| j
                  |z   }| j                  || j                  d   || j                  | j                  f«      S )aÊ  
        Shift the function by a term independent of x.

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

        f(x) -> f(x) + s

        This is fast, if Fourier series of f(x) is already
        computed.

        Examples
        ========

        >>> from sympy import fourier_series, pi
        >>> from sympy.abc import x
        >>> s = fourier_series(x**2, (x, -pi, pi))
        >>> s.shift(1).truncate()
        -4*cos(x) + cos(2*x) + 1 + pi**2/3
        ú'ú' should be independent of r   )
r   r!   r/   r2   r%   rn   r   rE   rv   rx   )rm   r_   r!   r%   Úsfuncs        r&   ÚshiftzFourierSeries.shift7  sv   € ô* �q‹z˜4Ÿ6™6ˆ1ˆà�—‘ÑÝÂ1ÁaÐHÓIÐIà�W‰W�q‰[ˆØ—‘ Ñ!ˆà�y‰y˜ §	¡	¨!¡¨r°4·7±7¸D¿G¹GÐ.DÓEÐEr(   c                 ó‚  — t        |«      | j                  }}||j                  v rt        d|›d|›�«      ‚| j                  j                  |||z   «      }| j                  j                  |||z   «      }| j                  j                  |||z   «      }| j                  || j                  d   | j                  ||f«      S )aÄ  
        Shift x by a term independent of x.

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

        f(x) -> f(x + s)

        This is fast, if Fourier series of f(x) is already
        computed.

        Examples
        ========

        >>> from sympy import fourier_series, pi
        >>> from sympy.abc import x
        >>> s = fourier_series(x**2, (x, -pi, pi))
        >>> s.shiftx(1).truncate()
        -4*cos(x + 1) + cos(2*x + 2) + pi**2/3
        r“   r”   r   ©r   r!   r/   r2   rv   r   rx   rn   r   rE   r%   ©rm   r_   r!   rv   rx   r•   s         r&   ÚshiftxzFourierSeries.shiftxV  ó¡   € ô* �q‹z˜4Ÿ6™6ˆ1ˆà�—‘ÑÝÂ1ÁaÐHÓIÐIà�W‰W�\‰\˜!˜Q ™UÓ#ˆØ�W‰W�\‰\˜!˜Q ™UÓ#ˆØ—‘×"Ñ" 1 a¨!¡eÓ,ˆà�y‰y˜ §	¡	¨!¡¨t¯w©w¸¸BÐ.?Ó@Ð@r(   c                 ób  — t        |«      | j                  }}||j                  v rt        d|›d|›�«      ‚| j                  j                  |«      }| j                  j                  |«      }| j                  |z  }| j                  d   |z  }| j                  || j                  d   |||f«      S )aÊ  
        Scale the function by a term independent of x.

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

        f(x) -> s * f(x)

        This is fast, if Fourier series of f(x) is already
        computed.

        Examples
        ========

        >>> from sympy import fourier_series, pi
        >>> from sympy.abc import x
        >>> s = fourier_series(x**2, (x, -pi, pi))
        >>> s.scale(2).truncate()
        -8*cos(x) + 2*cos(2*x) + 2*pi**2/3
        r“   r”   r   r   )
r   r!   r/   r2   rv   Ú	coeff_mulrx   r%   rE   r   )rm   r_   r!   rv   rx   r%   r•   s          r&   ÚscalezFourierSeries.scalev  s™   € ô* �q‹z˜4Ÿ6™6ˆ1ˆà�—‘ÑÝÂ1ÁaÐHÓIÐIà�W‰W×Ñ˜qÓ!ˆØ�W‰W×Ñ˜qÓ!ˆØ�W‰W�q‰[ˆØ—	‘	˜!‘˜qÑ ˆà�y‰y˜ §	¡	¨!¡¨r°2°r¨lÓ;Ð;r(   c                 ó‚  — t        |«      | j                  }}||j                  v rt        d|›d|›�«      ‚| j                  j                  |||z  «      }| j                  j                  |||z  «      }| j                  j                  |||z  «      }| j                  || j                  d   | j                  ||f«      S )a¼  
        Scale x by a term independent of x.

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

        f(x) -> f(s*x)

        This is fast, if Fourier series of f(x) is already
        computed.

        Examples
        ========

        >>> from sympy import fourier_series, pi
        >>> from sympy.abc import x
        >>> s = fourier_series(x**2, (x, -pi, pi))
        >>> s.scalex(2).truncate()
        -4*cos(2*x) + cos(4*x) + pi**2/3
        r“   r”   r   r˜   r™   s         r&   ÚscalexzFourierSeries.scalex—  r›   r(   c                 ó>   — | D ]  }|t         j                  usŒ|c S  y r@   rU   )rm   r!   ÚlogxÚcdirra   s        r&   Ú_eval_as_leading_termz#FourierSeries._eval_as_leading_term·  s!   € Øò 	ˆAØœŸ™ŠØ’ñ	r(   c                 ó’   — |dk(  r| j                   S | j                  j                  |«      | j                  j                  |«      z   S rj   )r%   rv   Úcoeffrx   )rm   Úpts     r&   Ú
_eval_termzFourierSeries._eval_term¼  s7   € Ø�Š7Ø—7‘7ˆNØ�w‰w�}‰}˜RÓ  4§7¡7§=¡=°Ó#4Ñ4Ð4r(   c                 ó$   — | j                  d«      S )Néÿÿÿÿ)rž   rl   s    r&   Ú__neg__zFourierSeries.__neg__Á  s   € Ø�z‰z˜"‹~Ðr(   c                 ó  — t        |t        «      rí| j                  |j                  k7  rt        d«      ‚| j                  |j                  }}| j
                  |j
                  j                  ||«      z   }| j                  |j                  vr|S | j                  |j                  z   }| j                  |j                  z   }| j                  |j                  z   }| j                  || j                  d   |||f«      S t        | |«      S )Nú(Both the series should have same periodsr   )r6   rd   rs   r2   r!   rn   r   r/   rv   rx   r%   r   rE   r   )rm   Úotherr!   Úyrn   rv   rx   r%   s           r&   Ú__add__zFourierSeries.__add__Ä  sÓ   € Ü�eœ]Ô+Ø�{‰{˜eŸl™lÒ*Ü Ð!KÓLÐLà—6‘6˜5Ÿ7™7ˆqˆAØ—}‘} u§~¡~×':Ñ':¸1¸aÓ'@Ñ@ˆHà�v‰v˜X×2Ñ2Ñ2Ø�à—‘˜5Ÿ8™8Ñ#ˆBØ—‘˜5Ÿ8™8Ñ#ˆBØ—‘˜5Ÿ8™8Ñ#ˆBà—9‘9˜X t§y¡y°¡|°b¸"¸b°\ÓBÐBä�4˜ÓÐr(   c                 ó&   — | j                  | «      S r@   )r°   )rm   r®   s     r&   Ú__sub__zFourierSeries.__sub__×  s   € Ø�|‰|˜U˜FÓ#Ð#r(   N)r5   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rg   Úpropertyrn   r!   rs   r%   rv   rx   rz   r:   r;   r�   r"   rˆ   r�   r‘   r–   rš   rž   r    r¤   r¨   r«   r°   r²   © r(   r&   rd   rd      s-  „ ñò (ð ñó ðð ñó ðð ñ2ó ð2ð ñó ðð ñó ðð ñó ðð ñó ðð ñ!ó ð!ð ñ!ó ð!ð ñó ðð ñ8ó ð8òó
*óXDòLFò>Aò@<òBAò@ò
5ò
ò ó&$r(   rd   c                   óT   — e Zd ZdZd„ Zed„ «       Zed„ «       Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zy
)ÚFiniteFourierSeriesaù  Represents Finite Fourier sine/cosine series.

    For how to compute Fourier series, see the :func:`fourier_series`
    docstring.

    Parameters
    ==========

    f : Expr
        Expression for finding fourier_series

    limits : ( x, start, stop)
        x is the independent variable for the expression f
        (start, stop) is the period of the fourier series

    exprs: (a0, an, bn) or Expr
        a0 is the constant term a0 of the fourier series
        an is a dictionary of coefficients of cos terms
         an[k] = coefficient of cos(pi*(k/L)*x)
        bn is a dictionary of coefficients of sin terms
         bn[k] = coefficient of sin(pi*(k/L)*x)

        or exprs can be an expression to be converted to fourier form

    Methods
    =======

    This class is an extension of FourierSeries class.
    Please refer to sympy.series.fourier.FourierSeries for
    further information.

    See Also
    ========

    sympy.series.fourier.FourierSeries
    sympy.series.fourier.fourier_series
    c           	      ó   ‡— t        |«      }t        |«      }t        |«      }t        |t        «      rt        |«      dk(  �sq|j	                  «       \  }}ddlm} |t        |D �cg c]
  } ||«      ‘Œ c}Ž z   }|j                  dddd¬«      j	                  «       \  }	}
|d   Št        |d   |d   z
  «      dz  }t        dd	„ d
„ g¬«      }t        dˆfd„g¬«      }i }i }|
D ]¿  }|j                  |t        |t        |z  z  ‰z  «      z  «      }|j                  |t        |t        |z  z  ‰z  «      z  «      }|r0||   |j                  ||   t         j"                  «      z   |||   <   Œ‰|r0||   |j                  ||   t         j"                  «      z   |||   <   Œ»|	|z  }	ŒÁ t        |	||«      }t%        j&                  | |||«      S c c}w )Nr5   r   )ÚTR10F)ÚtrigÚ
power_baseÚ	power_expÚlogr   r   rI   c                 ó   — | j                   S r@   rP   rR   s    r&   rS   z-FiniteFourierSeries.__new__.<locals>.<lambda>  s
   € °·±€ r(   c                 ó&   — | t         j                  uS r@   rU   rR   s    r&   rS   z-FiniteFourierSeries.__new__.<locals>.<lambda>  s   € ÈÔQR×QWÑQWÈ€ r(   rV   rJ   c                 ó    •— ‰| j                   vS r@   rA   rY   s    €r&   rS   z-FiniteFourierSeries.__new__.<locals>.<lambda>  s   ø€ °¸¿¹Ð0G€ r(   )r   r6   r   r0   r[   rZ   r¼   r   Úexpandrƒ   r   rF   r   r   r   Úgetr	   r   r   rg   )rh   r]   r   rB   ÚcÚer¼   r�   Úrexprr%   Úexp_lsr"   rI   rJ   rv   rx   Úpra   Úqr!   s                      @r&   rg   zFiniteFourierSeries.__new__  sÁ  ø€ Ü�A‹JˆÜ˜“ˆÜ˜“ˆä˜5¤%Ô(¬S°«Z¸1«_à×%Ñ%Ó'‰DˆAˆqÝ.Øœ¨qÖ1¨!™d 1�gÒ1Ð2Ñ2ˆEØŸ™¨5¸UÈeÐY^˜Ó_×lÑlÓn‰JˆB�à�q‘	ˆAÜ�F˜1‘I  q¡	Ñ)Ó*¨QÑ.ˆAä�SÑ&<Ñ>WÐ%ZÔ[ˆAÜ�SÓ&GÐ%JÔKˆAàˆBØˆBð ò �Ø—G‘G˜A¤ A¬¨a©¡L°1Ñ$4Ó 5Ñ5Ó6�Ø—G‘G˜A¤ A¬¨a©¡L°1Ñ$4Ó 5Ñ5Ó6�ÙØ  ™t b§f¡f¨Q¨q©T´1·6±6Ó&:Ñ:�B�q˜‘t’HÙØ  ™t b§f¡f¨Q¨q©T´1·6±6Ó&:Ñ:�B�q˜‘t’Hà˜!‘G‘Bðô ˜"˜b "Ó%ˆEä�|‰|˜C  F¨EÓ2Ð2ùò3 2s   Á%G
c           	      óþ   — | j                   rdnd}|t        t        | j                  j	                  «       «      j                  t        | j                  j	                  «       «      «      «      dz   z  }t        d|«      S rp   )r%   ÚmaxÚsetrv   ÚkeysÚunionrx   r   )rm   Ú_lengths     r&   rz   zFiniteFourierSeries.interval&  sY   € à—w’w‘! AˆØ”3”s˜4Ÿ7™7Ÿ<™<›>Ó*×0Ñ0´°T·W±W·\±\³^Ó1DÓEÓFÈÑJÑJˆÜ˜˜7Ó#Ð#r(   c                 ó4   — | j                   | j                  z
  S r@   )r;   r:   rl   s    r&   r�   zFiniteFourierSeries.length,  s   € à�y‰y˜4Ÿ:™:Ñ%Ð%r(   c                 ó2  — t        |«      | j                  }}||j                  v rt        d|›d|›�«      ‚| j	                  «       j                  |||z   «      }| j                  j                  |||z   «      }| j                  || j                  d   |«      S ©Nr“   r”   r   ©	r   r!   r/   r2   r�   r   rn   r   rE   ©rm   r_   r!   rG   r•   s        r&   rš   zFiniteFourierSeries.shiftx0  ó€   € Ü�q‹z˜4Ÿ6™6ˆ1ˆà�—‘ÑÝÂ1ÁaÐHÓIÐIà—‘“×$Ñ$ Q¨¨A©Ó.ˆØ—‘×"Ñ" 1 a¨!¡eÓ,ˆà�y‰y˜ §	¡	¨!¡¨eÓ4Ð4r(   c                 óò   — t        |«      | j                  }}||j                  v rt        d|›d|›�«      ‚| j	                  «       |z  }| j
                  |z  }| j                  || j                  d   |«      S rÔ   )r   r!   r/   r2   r�   rn   r   rE   rÖ   s        r&   rž   zFiniteFourierSeries.scale;  sh   € Ü�q‹z˜4Ÿ6™6ˆ1ˆà�—‘ÑÝÂ1ÁaÐHÓIÐIà—‘“ !Ñ#ˆØ—‘ Ñ!ˆà�y‰y˜ §	¡	¨!¡¨eÓ4Ð4r(   c                 ó2  — t        |«      | j                  }}||j                  v rt        d|›d|›�«      ‚| j	                  «       j                  |||z  «      }| j                  j                  |||z  «      }| j                  || j                  d   |«      S rÔ   rÕ   rÖ   s        r&   r    zFiniteFourierSeries.scalexF  r×   r(   c                 ó†  — |dk(  r| j                   S | j                  j                  |t        j                  «      t        |t        | j                  z  z  | j                  z  «      z  | j                  j                  |t        j                  «      t        |t        | j                  z  z  | j                  z  «      z  z   }|S rj   )r%   rv   rÅ   r	   r   r   r   r"   r!   rx   r   )rm   r§   Ú_terms      r&   r¨   zFiniteFourierSeries._eval_termQ  s‹   € Ø�Š7Ø—7‘7ˆNà—‘—‘˜B¤§¡Ó'¬#¨b´B¸¿¹±KÑ.@À4Ç6Á6Ñ.IÓ*JÑJØ—'‘'—+‘+˜b¤!§&¡&Ó)¬C°´b¸4¿6¹6±kÑ0BÀTÇVÁVÑ0KÓ,LÑLñMˆàˆr(   c                 óÞ  — t        |t        «      r4|j                  t        | j                  | j
                  d   d¬«      «      S t        |t        «      r™| j                  |j                  k7  rt        d«      ‚| j                  |j                  }}| j                  |j                  j                  ||«      z   }| j                  |j                  vr|S t        || j
                  d   ¬«      S y )Nr   F)Úfiniter­   )r   )r6   rd   r°   r   rn   rE   rº   rs   r2   r!   r   r/   )rm   r®   r!   r¯   rn   s        r&   r°   zFiniteFourierSeries.__add__Y  s¿   € Ü�eœ]Ô+Ø—=‘=¤°·±¸t¿y¹yÈ¹|Ø7<ô">ó ?ð ?ä˜Ô2Ô3Ø�{‰{˜eŸl™lÒ*Ü Ð!KÓLÐLà—6‘6˜5Ÿ7™7ˆqˆAØ—}‘} u§~¡~×':Ñ':¸1¸aÓ'@Ñ@ˆHà�v‰v˜X×2Ñ2Ñ2Ø�ä! (°4·9±9¸Q±<Ô@Ð@ð 4r(   N)r³   r´   rµ   r¶   rg   r·   rz   r�   rš   rž   r    r¨   r°   r¸   r(   r&   rº   rº   Û  sP   „ ñ$òL"3ðH ñ$ó ð$ð
 ñ&ó ð&ò	5ò	5ò	5òóAr(   rº   Nc                 óŒ  — t        | «      } t        | |«      }|d   }|| j                  vr| S |r6t        |d   |d   z
  «      dz  }t	        | ||«      \  }}|rt        | ||«      S t        d«      }|d   |d   z   dz  }|j                  r�| j                  || «      }	| |	k(  r2t        | ||«      \  }
}t        ddt        f«      }t        | ||
||f«      S | |	 k(  r?t        j                  }
t        ddt        f«      }t        | ||«      }t        | ||
||f«      S t        | ||«      \  }
}t        | ||«      }t        | ||
||f«      S )a`  Computes the Fourier trigonometric series expansion.

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

    Fourier trigonometric series of $f(x)$ over the interval $(a, b)$
    is defined as:

    .. math::
        \frac{a_0}{2} + \sum_{n=1}^{\infty}
        (a_n \cos(\frac{2n \pi x}{L}) + b_n \sin(\frac{2n \pi x}{L}))

    where the coefficients are:

    .. math::
        L = b - a

    .. math::
        a_0 = \frac{2}{L} \int_{a}^{b}{f(x) dx}

    .. math::
        a_n = \frac{2}{L} \int_{a}^{b}{f(x) \cos(\frac{2n \pi x}{L}) dx}

    .. math::
        b_n = \frac{2}{L} \int_{a}^{b}{f(x) \sin(\frac{2n \pi x}{L}) dx}

    The condition whether the function $f(x)$ given should be periodic
    or not is more than necessary, because it is sufficient to consider
    the series to be converging to $f(x)$ only in the given interval,
    not throughout the whole real line.

    This also brings a lot of ease for the computation because
    you do not have to make $f(x)$ artificially periodic by
    wrapping it with piecewise, modulo operations,
    but you can shape the function to look like the desired periodic
    function only in the interval $(a, b)$, and the computed series will
    automatically become the series of the periodic version of $f(x)$.

    This property is illustrated in the examples section below.

    Parameters
    ==========

    limits : (sym, start, end), optional
        *sym* denotes the symbol the series is computed with respect to.

        *start* and *end* denotes the start and the end of the interval
        where the fourier series converges to the given function.

        Default range is specified as $-\pi$ and $\pi$.

    Returns
    =======

    FourierSeries
        A symbolic object representing the Fourier trigonometric series.

    Examples
    ========

    Computing the Fourier series of $f(x) = x^2$:

    >>> from sympy import fourier_series, pi
    >>> from sympy.abc import x
    >>> f = x**2
    >>> s = fourier_series(f, (x, -pi, pi))
    >>> s1 = s.truncate(n=3)
    >>> s1
    -4*cos(x) + cos(2*x) + pi**2/3

    Shifting of the Fourier series:

    >>> s.shift(1).truncate()
    -4*cos(x) + cos(2*x) + 1 + pi**2/3
    >>> s.shiftx(1).truncate()
    -4*cos(x + 1) + cos(2*x + 2) + pi**2/3

    Scaling of the Fourier series:

    >>> s.scale(2).truncate()
    -8*cos(x) + 2*cos(2*x) + 2*pi**2/3
    >>> s.scalex(2).truncate()
    -4*cos(2*x) + cos(4*x) + pi**2/3

    Computing the Fourier series of $f(x) = x$:

    This illustrates how truncating to the higher order gives better
    convergence.

    .. plot::
        :context: reset
        :format: doctest
        :include-source: True

        >>> from sympy import fourier_series, pi, plot
        >>> from sympy.abc import x
        >>> f = x
        >>> s = fourier_series(f, (x, -pi, pi))
        >>> s1 = s.truncate(n = 3)
        >>> s2 = s.truncate(n = 5)
        >>> s3 = s.truncate(n = 7)
        >>> p = plot(f, s1, s2, s3, (x, -pi, pi), show=False, legend=True)

        >>> p[0].line_color = (0, 0, 0)
        >>> p[0].label = 'x'
        >>> p[1].line_color = (0.7, 0.7, 0.7)
        >>> p[1].label = 'n=3'
        >>> p[2].line_color = (0.5, 0.5, 0.5)
        >>> p[2].label = 'n=5'
        >>> p[3].line_color = (0.3, 0.3, 0.3)
        >>> p[3].label = 'n=7'

        >>> p.show()

    This illustrates how the series converges to different sawtooth
    waves if the different ranges are specified.

    .. plot::
        :context: close-figs
        :format: doctest
        :include-source: True

        >>> s1 = fourier_series(x, (x, -1, 1)).truncate(10)
        >>> s2 = fourier_series(x, (x, -pi, pi)).truncate(10)
        >>> s3 = fourier_series(x, (x, 0, 1)).truncate(10)
        >>> p = plot(x, s1, s2, s3, (x, -5, 5), show=False, legend=True)

        >>> p[0].line_color = (0, 0, 0)
        >>> p[0].label = 'x'
        >>> p[1].line_color = (0.7, 0.7, 0.7)
        >>> p[1].label = '[-1, 1]'
        >>> p[2].line_color = (0.5, 0.5, 0.5)
        >>> p[2].label = '[-pi, pi]'
        >>> p[3].line_color = (0.3, 0.3, 0.3)
        >>> p[3].label = '[0, 1]'

        >>> p.show()

    Notes
    =====

    Computing Fourier series can be slow
    due to the integration required in computing
    an, bn.

    It is faster to compute Fourier series of a function
    by using shifting and scaling on an already
    computed Fourier series rather than computing
    again.

    e.g. If the Fourier series of ``x**2`` is known
    the Fourier series of ``x**2 - 1`` can be found by shifting by ``-1``.

    See Also
    ========

    sympy.series.fourier.FourierSeries

    References
    ==========

    .. [1] https://mathworld.wolfram.com/FourierSeries.html
    r   r   r   r    )r   r=   r/   rƒ   rb   rº   r
   Úis_zeror   r'   r   r   rd   r	   r   r+   )r]   r   rÝ   r!   r"   Ú	is_finiteÚres_fr    ÚcenterÚneg_fr%   rv   rx   s                r&   r   r   j  sh  € ôH 	�‹
€Aä˜Q Ó'€FØˆq‰	€Aà�—‘ÑØˆáÜ��q‘	˜F 1™IÑ%Ó&¨Ñ*ˆÜ'¨¨1¨aÓ0Ñˆ	�5ÙÜ& q¨&°%Ó8Ð8äˆc‹
€AØ�Q‰i˜& ™)Ñ# qÑ(€FØ‡~‚~Ø—‘�q˜1˜"“ˆØ�Š:Ü$ Q¨°Ó2‰FˆB�Ü˜A ¤2˜wÓ'ˆBÜ   F¨R°°R¨LÓ9Ð9Ø�5�&Š[Ü—‘ˆBÜ˜A ¤2˜wÓ'ˆBÜ   F¨AÓ.ˆBÜ   F¨R°°R¨LÓ9Ð9Ü˜Q ¨Ó*�F€BˆÜ	˜˜F AÓ	&€BÜ˜˜F R¨¨R LÓ1Ð1r(   )NT)&r¶   Úsympy.core.numbersr   r   Úsympy.core.symbolr   Úsympy.core.exprr   Úsympy.core.addr   Úsympy.core.containersr   Úsympy.core.singletonr	   r
   r   Úsympy.core.sympifyr   Ú(sympy.functions.elementary.trigonometricr   r   r   Úsympy.series.series_classr   Úsympy.series.sequencesr   Úsympy.sets.setsr   Úsympy.utilities.iterablesr   Ú__doctest_requires__r'   r+   r=   rb   rd   rº   r   r¸   r(   r&   ú<module>rñ      s|   ðÙ ç 'Ý "Ý  Ý Ý 'Ý "ß +Ý &ß CÑ CÝ 0Ý -Ý $Ý 1ð ,¨l¨^Ð<Ð ò+ò'ò5%òpô<Y$�Jô Y$ôx
LA˜-ô LAô^A2r(   