§
    OŠtj�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%dS )zFourier Seriesé    )ÚooÚpi)ÚWild)ÚExpr)ÚAdd)ÚTuple)ÚS)ÚDummyÚSymbol)Úsympify)ÚsinÚcosÚsinc)Ú
SeriesBase)Ú
SeqFormula)ÚInterval)Úis_sequence)Úfourier_seriesÚ
matplotlibc                 óV  — ddl m} |d         |d         |d         z
  }}t          d|z  t          z  |z  |z  ¦  «        }d|z   || |z  |¦  «        z  |z  }|                     |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/html/CA-Chatbot/venv/lib/python3.11/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˜Y t¨h¡¸Ñ?Ô?Ñ?À!ÑC€GØ	�Š�a�œÑ	 Ô	  1Ñ	$€BØ�z˜!˜h™,¨¨°4¸(±?ÀFÑ)KÔ)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+       s‰   € à)Ð)Ð)Ð)Ð)Ð)Ø�!Œ9�f˜Q”i &¨¤)Ñ+€q€AÝ�1�Q‘3•r‘6˜!‘8˜a‘<Ñ Ô €HÝ�a˜(‘l Y Y¨t°h©ÀÑ%GÔ%GÑGØñØ˜q¥"˜:ñ'ô 'ð 'r(   c                 óâ  — d„ }d\  }}}|€ || ¦  «        t            t           }}}t          |t          ¦  «        r=t          |¦  «        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|                     ¦   «         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@   s]   € ØÔ ˆÝˆt‰9Œ9˜Š>ˆ>Ø—8’8‘:”:ÐØð 	Ý˜‘:”:ÐåðPð ññô ð r(   )NNNNé   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�dÝ�‰[Œ[˜AÒÐØ�˜‘”ˆAØ ‰KˆE�4å�a�Ñ Ô ð C E M°T°\ÝÐ3µc¸&±k´kÑAÑBÔBÐBåÔ#¥Q¤ZÐ0€IØ�	ÐÐ˜T YÐ.Ð.ÝÐIÑJÔJÐJå�A�u˜dÐ#Ñ$Ô$Ð$r(   c                 ó‚  ‡‡‡— d„ }ˆˆfd„}ddl m}m}m}  | | || ¦  «        ¦  «        ¦  «        }|                     ¦   «         }	t          dd„ d„ g¬¦  «        Št          d	ˆfd
„g¬¦  «        Š|	d         D ]B}
|
                     ¦   «         d         }|D ]#} ||‰¦  «        s ||‰|¦  «        sd| fc c S Œ$ŒCd|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¦  «        r7| j        d         }|                     ‰t
          |z  z  |z  ‰z   ¦  «        �dS dS d S )Nr   TF)r6   r   r   ÚargsÚmatchr   )Ú_exprr!   r"   Úsincos_argsÚaÚbs       €€r&   Úcheck_sincosz"finite_check.<locals>.check_sincosf   s\   ø€ Ý�e�c¥3˜ZÑ(Ô(ð 	Øœ* Qœ-ˆKà× Ò  ¥B q¡D¡¨!¡¨a¡Ñ0Ô0Ð<Ø�tà�uð	ð 	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        k    S r@   ©r	   r   rR   s    r&   rS   zfinite_check.<locals>.<lambda>s   s   € ÀÅQÄ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Ð9Ð9Ð9Ð9Ð9Ð9Ð9Ð9ØˆM˜#˜#˜c˜c !™fœf™+œ+Ñ&Ô&€EØ×"Ò"Ñ$Ô$€IåˆSÐ4Ð4Ð6KÐ6KÐNÐOÑOÔO€AÝˆSÐ?Ð?Ð?Ð?ÐBÐCÑCÔC€Aà�qŒ\ð  ð  ˆØ—^’^Ñ%Ô% aÔ(ˆ
Øð 	 ð 	 ˆAØ�H˜Q ‘N”Nð   l l°1°a¸Ñ&;Ô&;ð  Ø˜a�x�����øð	 ð �ˆ;Ðr(   c                   óV  — 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dS )Ú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                 óP   — t          t          |¦  «        }t          j        | g|¢R Ž 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˜Œ|Ðr(   c                 ó(   — | j         d         d         S ©Nr   r   rk   rl   s    r&   r!   zFourierSeries.x˜   ó   € àŒy˜Œ|˜AŒÐr(   c                 óN   — | 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°¤NÑ2Ñ3Ô3°aÑ7Ð7r(   c                 óB   — | j         }|                     |¦  «        r| S d S r@   )r!   Úhas)rm   ÚoldÚnewr!   s       r&   Ú
_eval_subszFourierSeries._eval_subsÀ   s*   € ØŒFˆØ�7Š7�1‰:Œ:ð 	ØˆKð	ð 	r(   r5   c                 ó´   — |€t          | ¦  «        S g }| D ]:}t          |¦  «        |k    r n$|t          j        ur|                     |¦  «         Œ;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Å   sc   € ð@ ˆ9Ý˜‘:”:ÐàˆØð 	 ð 	 ˆAÝ�5‰zŒz˜QŠˆØ�Ø�œˆˆØ—’˜Q‘”�øå�Eˆ{Ðr(   c                 ó\   ‡— ˆfd„t          | d‰…         ¦  «        D ¦   «         }t          |Ž S )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
        c                 ól   •— g | ]0\  }}|t           j        u¯t          t          |z  ‰z  ¦  «        |z  ‘Œ1S © )r	   r   r   r   )Ú.0Úira   r    s      €r&   ú
<listcomp>z5FourierSeries.sigma_approximation.<locals>.<listcomp>3  sD   ø€ ð %ð %ð %©$¨!¨QØ�QœV�O�Oõ •b˜1‘f˜q‘jÑ!Ô! AÑ%Ø#�O�Or(   N)Ú	enumerater   )rm   r    rŒ   s    ` r&   Úsigma_approximationz!FourierSeries.sigma_approximationñ   sE   ø€ ðD%ð %ð %ð %µ)¸DÀÀ!À¼HÑ2EÔ2Eð %ñ %ô %ˆå�Eˆ{Ðr(   c                 óð   — t          |¦  «        | j        }}||j        v rt          d|›d|›�¦  «        ‚| j        |z   }| j        |z   }|                      || 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  s{   € õ* �q‰zŒz˜4œ6ˆ1ˆà�”ÐÐÝ�*À1À1À1ÀaÀaÐHÑIÔIÐIàŒW�q‰[ˆØ” Ñ!ˆà�yŠy˜ ¤	¨!¤¨r°4´7¸D¼GÐ.DÑEÔEÐEr(   c                 ór  — t          |¦  «        | j        }}||j        v rt          d|›d|›�¦  «        ‚| j                             |||z   ¦  «        }| j                             |||z   ¦  «        }| j                             |||z   ¦  «        }|                      || 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Œz˜4œ6ˆ1ˆà�”ÐÐÝ�*À1À1À1ÀaÀaÐHÑIÔIÐIàŒW�\Š\˜!˜Q ™UÑ#Ô#ˆØŒW�\Š\˜!˜Q ™UÑ#Ô#ˆØ”×"Ò" 1 a¨!¡eÑ,Ô,ˆà�yŠy˜ ¤	¨!¤¨t¬w¸¸BÐ.?Ñ@Ô@Ð@r(   c                 óP  — t          |¦  «        | j        }}||j        v rt          d|›d|›�¦  «        ‚| j                             |¦  «        }| j                             |¦  «        }| j        |z  }| j        d         |z  }|  	                    || 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Œz˜4œ6ˆ1ˆà�”ÐÐÝ�*À1À1À1ÀaÀaÐHÑIÔIÐIàŒW×Ò˜qÑ!Ô!ˆØŒW×Ò˜qÑ!Ô!ˆØŒW�q‰[ˆØ”	˜!”˜qÑ ˆà�yŠy˜ ¤	¨!¤¨r°2°r¨lÑ;Ô;Ð;r(   c                 ór  — t          |¦  «        | j        }}||j        v rt          d|›d|›�¦  «        ‚| j                             |||z  ¦  «        }| j                             |||z  ¦  «        }| j                             |||z  ¦  «        }|                      || 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                 ó4   — | D ]}|t           j        ur|c S Œd S r@   rU   )rm   r!   ÚlogxÚcdirra   s        r&   Ú_eval_as_leading_termz#FourierSeries._eval_as_leading_term·  s4   € Øð 	ð 	ˆAØ�œˆˆØ���ð ð	ð 	r(   c                 ó†   — |dk    r| j         S | j                             |¦  «        | j                             |¦  «        z   S rj   )r%   rv   Úcoeffrx   )rm   Úpts     r&   Ú
_eval_termzFourierSeries._eval_term¼  s9   € Ø�Š7ˆ7Ø”7ˆNØŒw�}Š}˜RÑ Ô  4¤7§=¢=°Ñ#4Ô#4Ñ4Ð4r(   c                 ó,   — |                       d¦  «        S )Néÿÿÿÿ)r¢   rl   s    r&   Ú__neg__zFourierSeries.__neg__Á  s   € Ø�zŠz˜"‰~Œ~Ðr(   c                 ó°  — t          |t          ¦  «        r²| j        |j        k    rt          d¦  «        ‚| j        |j        }}| j        |j                             ||¦  «        z   }| j        |j        vr|S | j        |j        z   }| j	        |j	        z   }| j
        |j
        z   }|                      || 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�]Ñ+Ô+ð 	CØŒ{˜eœlÒ*Ð*Ý Ð!KÑLÔLÐLà”6˜5œ7ˆqˆAØ”} u¤~×':Ò':¸1¸aÑ'@Ô'@Ñ@ˆHàŒv˜XÔ2Ð2Ð2Ø�à”˜5œ8Ñ#ˆBØ”˜5œ8Ñ#ˆBØ”˜5œ8Ñ#ˆBà—9’9˜X t¤y°¤|°b¸"¸b°\ÑBÔBÐBå�4˜ÑÔÐr(   c                 ó.   — |                       | ¦  «        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(   r&   rd   rd      s&  € € € € € ðð ð (ð (ð (ð ðð ñ „Xðð ðð ñ „Xðð ð2ð 2ñ „Xð2ð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ð!ð !ñ „Xð!ð ð!ð !ñ „Xð!ð ðð ñ „Xðð ð8ð 8ñ „Xð8ðð ð ð
*ð *ð *ð *ðXDð Dð Dð DðLFð Fð Fð>Að Að Að@<ð <ð <ðBAð Að Að@ð ð ð
5ð 5ð 5ð
ð ð ð ð  ð  ð&$ð $ð $ð $ð $r(   rd   c                   ób   — e Zd ZdZd„ Zed„ ¦   «         Zed„ ¦   «         Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
S )Ú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           	      óB  ‡‡— t          |¦  «        }t          |¦  «        }t          |¦  «        }t          |t          ¦  «        rt          |¦  «        dk    �s±|                     ¦   «         \  }}ddlmŠ |t          ˆfd„|D ¦   «         Ž z   }|                     dddd¬¦  «                             ¦   «         \  }}|d         Št          |d         |d         z
  ¦  «        dz  }	t          d	d
„ d„ g¬¦  «        }
t          dˆfd„g¬¦  «        }i }i }|D ]ã}|                     |t          |
t          |	z  z  ‰z  ¦  «        z  ¦  «        }|                     |t          |
t          |	z  z  ‰z  ¦  «        z  ¦  «        }|r9||         |                     ||
         t           j        ¦  «        z   |||
         <   Œ£|r9||         |                     ||
         t           j        ¦  «        z   |||
         <   ŒÞ||z  }Œät          |||¦  «        }t%          j        | |||¦  «        S )Nr5   r   )ÚTR10c                 ó&   •— g | ]} ‰|¦  «        ‘ŒS r�   r�   )r‘   r’   r¿   s     €r&   r“   z/FiniteFourierSeries.__new__.<locals>.<listcomp>  s!   ø€ Ð1Ð1Ð1¨!˜d˜d 1™gœgÐ1Ð1Ð1r(   F)Ú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È€ 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ÚeÚrexprr%   Úexp_lsr"   rI   rJ   rv   rx   Úpra   Úqr¿   r!   s                    @@r&   rg   zFiniteFourierSeries.__new__  s+  øø€ Ý�A‰JŒJˆÝ˜‘”ˆÝ˜‘”ˆå˜5¥%Ñ(Ô(ð 	&­S°©Z¬Z¸1ª_©_à×%Ò%Ñ'Ô'‰DˆAˆqØ.Ð.Ð.Ð.Ð.Ð.Ø�Ð1Ð1Ð1Ð1¨qÐ1Ñ1Ô1Ð2Ñ2ˆEØŸš¨5¸UÈeÐY^˜Ñ_Ô_×lÒlÑnÔn‰JˆB�à�q”	ˆAÝ�F˜1”I  q¤	Ñ)Ñ*Ô*¨QÑ.ˆAå�SÐ&<Ð&<Ð>WÐ>WÐ%ZÐ[Ñ[Ô[ˆAÝ�SÐ&GÐ&GÐ&GÐ&GÐ%JÐKÑKÔKˆAàˆBØˆBð ð ð �Ø—G’G˜A¥ A­¨a©¡L°1Ñ$4Ñ 5Ô 5Ñ5Ñ6Ô6�Ø—G’G˜A¥ A­¨a©¡L°1Ñ$4Ñ 5Ô 5Ñ5Ñ6Ô6�Øð Ø  œt b§f¢f¨Q¨q¬Tµ1´6Ñ&:Ô&:Ñ:�B�q˜”t‘H�HØð Ø  œt b§f¢f¨Q¨q¬Tµ1´6Ñ&:Ô&:Ñ:�B�q˜”t‘H�Hà˜!‘G�B�Bå˜"˜b "Ñ%Ô%ˆEåŒ|˜C  F¨EÑ2Ô2Ð2r(   c           	      ó  — | j         rdnd}|t          t          | j                             ¦   «         ¦  «                             t          | j                             ¦   «         ¦  «        ¦  «        ¦  «        dz   z  }t          d|¦  «        S rp   )r%   ÚmaxÚsetrv   ÚkeysÚunionrx   r   )rm   Ú_lengths     r&   rz   zFiniteFourierSeries.interval&  sk   € à”wÐ%�!�! AˆØ•3•s˜4œ7Ÿ<š<™>œ>Ñ*Ô*×0Ò0µ°T´W·\²\±^´^Ñ1DÔ1DÑEÔEÑFÔFÈÑJÑJˆÝ˜˜7Ñ#Ô#Ð#r(   c                 ó    — | j         | j        z
  S r@   )r;   r:   rl   s    r&   r�   zFiniteFourierSeries.length,  s   € àŒy˜4œ:Ñ%Ð%r(   c                 ó@  — t          |¦  «        | j        }}||j        v rt          d|›d|›�¦  «        ‚|                      ¦   «                              |||z   ¦  «        }| j                             |||z   ¦  «        }|                      || 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Œz˜4œ6ˆ1ˆà�”ÐÐÝ�*À1À1À1ÀaÀaÐHÑIÔIÐIà—’‘”×$Ò$ Q¨¨A©Ñ.Ô.ˆØ”×"Ò" 1 a¨!¡eÑ,Ô,ˆà�yŠy˜ ¤	¨!¤¨eÑ4Ô4Ð4r(   c                 óð   — t          |¦  «        | j        }}||j        v rt          d|›d|›�¦  «        ‚|                      ¦   «         |z  }| j        |z  }|                      || j        d         |¦  «        S rØ   )r   r!   r/   r2   r�   rn   r   rE   rÚ   s        r&   r¢   zFiniteFourierSeries.scale;  su   € Ý�q‰zŒz˜4œ6ˆ1ˆà�”ÐÐÝ�*À1À1À1ÀaÀaÐHÑIÔIÐIà—’‘” !Ñ#ˆØ” Ñ!ˆà�yŠy˜ ¤	¨!¤¨eÑ4Ô4Ð4r(   c                 ó@  — t          |¦  «        | j        }}||j        v rt          d|›d|›�¦  «        ‚|                      ¦   «                              |||z  ¦  «        }| j                             |||z  ¦  «        }|                      || j        d         |¦  «        S rØ   rÙ   rÚ   s        r&   r¤   zFiniteFourierSeries.scalexF  rÛ   r(   c                 óV  — |dk    r| j         S | j                             |t          j        ¦  «        t          |t          | j        z  z  | j        z  ¦  «        z  | 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Ñ.IÑ*JÔ*JÑJØ”'—+’+˜b¥!¤&Ñ)Ô)­C°µb¸4¼6±kÑ0BÀTÄVÑ0KÑ,LÔ,LÑLñMˆàˆr(   c                 ó¼  — t          |t          ¦  «        r5|                     t          | j        | j        d         d¬¦  «        ¦  «        S t          |t          ¦  «        r|| j        |j        k    rt          d¦  «        ‚| j	        |j	        }}| j        |j         
                    ||¦  «        z   }| j	        |j        vr|S t          || j        d         ¬¦  «        S d S )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�]Ñ+Ô+ð 	AØ—=’=¥°´¸t¼yÈ¼|Ø7<ð">ñ ">ô ">ñ ?ô ?ð ?å˜Õ2Ñ3Ô3ð 
	AØŒ{˜eœlÒ*Ð*Ý Ð!KÑLÔLÐLà”6˜5œ7ˆqˆAØ”} u¤~×':Ò':¸1¸aÑ'@Ô'@Ñ@ˆHàŒv˜XÔ2Ð2Ð2Ø�å! (°4´9¸Q´<Ð@Ñ@Ô@Ð@ð
	Að 
	Ar(   N)r·   r¸   r¹   rº   rg   r»   rz   r�   rž   r¢   r¤   r¬   r´   r�   r(   r&   r½   r½   Û  sµ   € € € € € ð$ð $ðL"3ð "3ð "3ðH ð$ð $ñ „Xð$ð
 ð&ð &ñ „Xð&ð	5ð 	5ð 	5ð	5ð 	5ð 	5ð	5ð 	5ð 	5ðð ð ðAð Að Að Að Ar(   r½   NTc                 ó  — t          | ¦  «        } t          | |¦  «        }|d         }|| j        vr| S |rHt          |d         |d         z
  ¦  «        dz  }t	          | ||¦  «        \  }}|rt          | ||¦  «        S t          d¦  «        }|d         |d         z   dz  }|j        r«|                      || ¦  «        }	| |	k    r?t          | ||¦  «        \  }
}t          ddt          f¦  «        }t          | ||
||f¦  «        S | |	 k    rHt          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  s¥  € õH 	�‰
Œ
€Aå˜Q Ñ'Ô'€FØˆqŒ	€Aà�”ÐÐØˆàð 9Ý��q”	˜F 1œIÑ%Ñ&Ô&¨Ñ*ˆÝ'¨¨1¨aÑ0Ô0Ñˆ	�5Øð 	9Ý& q¨&°%Ñ8Ô8Ð8åˆc‰
Œ
€AØ�QŒi˜& œ)Ñ# qÑ(€FØ„~ð 
:Ø—’�q˜1˜"‘”ˆØ�Š:ˆ:Ý$ Q¨°Ñ2Ô2‰FˆB�Ý˜A ¥2˜wÑ'Ô'ˆBÝ   F¨R°°R¨LÑ9Ô9Ð9Ø�5�&Š[ˆ[Ý”ˆBÝ˜A ¥2˜wÑ'Ô'ˆBÝ   F¨AÑ.Ô.ˆBÝ   F¨R°°R¨LÑ9Ô9Ð9Ý˜Q ¨Ñ*Ô*�F€BˆÝ	˜˜F AÑ	&Ô	&€BÝ˜˜F R¨¨R LÑ1Ô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Ð CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø -Ð -Ð -Ð -Ð -Ð -Ø $Ð $Ð $Ð $Ð $Ð $Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1ð ,¨l¨^Ð<Ð ð+ð +ð +ð'ð 'ð 'ð5%ð 5%ð 5%ðpð ð ð<Y$ð Y$ð Y$ð Y$ð Y$�Jñ Y$ô Y$ð Y$ðx
LAð LAð LAð LAð LA˜-ñ LAô LAð LAð^A2ð A2ð A2ð A2ð A2ð A2r(   