U
    ZÊ¹j¤Y  ã                   @   s  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d„ Zdd„ Z dd„ Z!dd„ Z"G dd„ deƒZ#G dd„ de#ƒZ$d!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_seriesZ
matplotlibc           	      C   s”   ddl m} |d |d |d   }}td| t | | ƒ}d| || | |ƒ | }| |tj¡d }|td| || | |ƒ | |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ÚLZcos_termZformulaÚa0© r!   úS/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/series/fourier.pyÚfourier_cos_seq   s    ÿÿr#   c                 C   sd   ddl m} |d |d |d   }}td| t | | ƒ}td| || | |ƒ | |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   Zsin_termr!   r!   r"   Úfourier_sin_seq    s    ÿÿr$   c                 C   sÊ   dd„ }d\}}}|dkr0|| ƒt  t   }}}t|tƒrnt|ƒdkrR|\}}}nt|ƒdkrn|| ƒ}|\}}t|tƒrˆ|dksˆ|dkr˜tdt|ƒ ƒ‚tj	tj
g}||ks´||k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                 S   s6   | j }t|ƒdkr| ¡ S |s&tdƒS td|  ƒ‚d S )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   Úfreer!   r!   r"   Ú_find_x@   s    ýÿz _process_limits.<locals>._find_x)NNNNé   r   zInvalid limits given: %sz.Both the start and end value should be bounded)r   r   r   r'   Ú
isinstancer
   r)   Ústrr   ÚNegativeInfinityÚInfinityr   )r   r   r+   r   ÚstartÚstopZ	unboundedr!   r!   r"   Ú_process_limits)   s     

r3   c                    sÂ   dd„ }‡ ‡fdd„}ddl m}m}m} |||| ƒƒƒ}| ¡ }	tddd	„ d
d	„ gd�‰ td‡fdd	„gd�‰|	d D ]@}
|
 ¡ d }|D ]*}||ˆƒsŒ||ˆ|ƒsŒd| f    S qŒqxd|fS )Nc                 S   s
   || j kS ©N©r&   )Úexprsr   r!   r!   r"   Úcheck_fxc   s    zfinite_check.<locals>.check_fxc                    sB   t | ttfƒr>| jd }| ˆ t|  | ˆ ¡d k	r:dS dS d S )Nr   TF)r-   r   r   ÚargsÚmatchr   )Ú_exprr   r   Zsincos_args)ÚaÚbr!   r"   Úcheck_sincosf   s
    
z"finite_check.<locals>.check_sincosr   )ÚTR2ÚTR1Úsincos_to_sumr;   c                 S   s   | j S r4   ©Z
is_Integer©r%   r!   r!   r"   Ú<lambda>s   ó    zfinite_check.<locals>.<lambda>c                 S   s
   | t jkS r4   ©r   r   rB   r!   r!   r"   rC   s   rD   ©Ú
propertiesr<   c                    s
   ˆ | j kS r4   r5   rB   ©r   r!   r"   rC   t   rD   r   FT)Úsympy.simplify.fur>   r?   r@   Úas_coeff_addr   Zas_coeff_mul)Úfr   r   r7   r=   r>   r?   r@   r:   Z	add_coeffÚsZ
mul_coeffsÚtr!   )r;   r<   r   r"   Úfinite_checka   s    	rN   c                   @   s  e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zd5dd„Zd6dd „Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd7d+d,„Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd)S )8Ú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                 G   s   t t|ƒ}tj| f|žŽ S r4   )Úmapr   r   Ú__new__)Úclsr8   r!   r!   r"   rQ   �   s    
zFourierSeries.__new__c                 C   s
   | j d S ©Nr   ©r8   ©Úselfr!   r!   r"   Úfunction”   s    zFourierSeries.functionc                 C   s   | j d d S ©Nr   r   rT   rU   r!   r!   r"   r   ˜   s    zFourierSeries.xc                 C   s   | j d d | j d d fS )Nr   r   rT   rU   r!   r!   r"   Úperiodœ   s    zFourierSeries.periodc                 C   s   | j d d S )Nr   r   rT   rU   r!   r!   r"   r        s    zFourierSeries.a0c                 C   s   | j d d S )Nr   r   rT   rU   r!   r!   r"   Úan¤   s    zFourierSeries.anc                 C   s   | j d d S )Nr   rT   rU   r!   r!   r"   Úbn¨   s    zFourierSeries.bnc                 C   s
   t dtƒS rS   )r   r   rU   r!   r!   r"   Úinterval¬   s    zFourierSeries.intervalc                 C   s   | j jS r4   )r\   ÚinfrU   r!   r!   r"   r1   °   s    zFourierSeries.startc                 C   s   | j jS r4   )r\   ÚsuprU   r!   r!   r"   r2   ´   s    zFourierSeries.stopc                 C   s   t S r4   )r   rU   r!   r!   r"   Úlength¸   s    zFourierSeries.lengthc                 C   s   t | jd | jd  ƒd S )Nr   r   r   )ÚabsrY   rU   r!   r!   r"   r   ¼   s    zFourierSeries.Lc                 C   s   | j }| |¡r| S d S r4   )r   Úhas)rV   ÚoldÚnewr   r!   r!   r"   Ú
_eval_subsÀ   s    
zFourierSeries._eval_subsr,   c                 C   sJ   |dkrt | ƒS g }| D ](}t|ƒ|kr, qB|tjk	r| |¡ q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
        N)Úiterr'   r   r   Úappendr   )rV   r   ÚtermsrM   r!   r!   r"   ÚtruncateÅ   s     
zFourierSeries.truncatec                    s&   ‡ fd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                    s.   g | ]&\}}|t jk	rtt| ˆ  ƒ| ‘qS r!   )r   r   r   r   )Ú.0ÚirM   ©r   r!   r"   Ú
<listcomp>3  s    
ÿz5FourierSeries.sigma_approximation.<locals>.<listcomp>N)Ú	enumerater   )rV   r   rg   r!   rk   r"   Úsigma_approximationñ   s    Bz!FourierSeries.sigma_approximationc                 C   s\   t |ƒ| j }}||jkr*td||f ƒ‚| j| }| 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
        ú '%s' should be independent of %sr   )
r   r   r&   r)   r    rW   r   r8   rZ   r[   )rV   rL   r   r    Úsfuncr!   r!   r"   Úshift7  s    


zFourierSeries.shiftc                 C   s|   t |ƒ| j }}||jkr*td||f ƒ‚| j ||| ¡}| j ||| ¡}| 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
        ro   r   ©r   r   r&   r)   rZ   r   r[   rW   r   r8   r    ©rV   rL   r   rZ   r[   rp   r!   r!   r"   ÚshiftxV  s    
zFourierSeries.shiftxc                 C   st   t |ƒ| j }}||jkr*td||f ƒ‚| j |¡}| j |¡}| j| }| jd | }|  	|| 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
        ro   r   r   )
r   r   r&   r)   rZ   Z	coeff_mulr[   r    r8   r   )rV   rL   r   rZ   r[   r    rp   r!   r!   r"   Úscalev  s    

zFourierSeries.scalec                 C   s|   t |ƒ| j }}||jkr*td||f ƒ‚| j ||| ¡}| j ||| ¡}| 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
        ro   r   rr   rs   r!   r!   r"   Úscalex—  s    
zFourierSeries.scalexNr   c                 C   s    | D ]}|t jk	r|  S qd S r4   rE   )rV   r   ZlogxÚcdirrM   r!   r!   r"   Ú_eval_as_leading_term·  s    
z#FourierSeries._eval_as_leading_termc                 C   s&   |dkr| j S | j |¡| j |¡ S rS   )r    rZ   Zcoeffr[   )rV   Úptr!   r!   r"   Ú
_eval_term¼  s    zFourierSeries._eval_termc                 C   s
   |   d¡S )Néÿÿÿÿ)ru   rU   r!   r!   r"   Ú__neg__Á  s    zFourierSeries.__neg__c                 C   s˜   t |tƒrŽ| j|jkrtdƒ‚| j|j }}| j|j ||¡ }| j|jkrP|S | j|j }| j	|j	 }| j
|j
 }|  || jd |||f¡S t| |ƒS )Nú(Both the series should have same periodsr   )r-   rO   rY   r)   r   rW   r   r&   rZ   r[   r    r   r8   r   )rV   Úotherr   ÚyrW   rZ   r[   r    r!   r!   r"   Ú__add__Ä  s    
zFourierSeries.__add__c                 C   s   |   | ¡S r4   )r€   )rV   r~   r!   r!   r"   Ú__sub__×  s    zFourierSeries.__sub__)r,   )r,   )Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rQ   ÚpropertyrW   r   rY   r    rZ   r[   r\   r1   r2   r_   r   rd   rh   rn   rq   rt   ru   rv   rx   rz   r|   r€   r�   r!   r!   r!   r"   rO      sH   











,
F ! 
rO   c                   @   sX   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ Zd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                    s�  t |ƒ}t |ƒ}t |ƒ}t|tƒr0t|ƒdk�s€| ¡ \}}ddlm‰  |t‡ fdd„|D ƒŽ  }|jddddd� ¡ \}}|d ‰t	|d |d	  ƒd }	t
d
dd„ dd„ gd�}
t
d‡fdd„gd�}i }i }|D ]œ}| |t|
t|	  ˆ ƒ ¡}| |t|
t|	  ˆ ƒ ¡}|�r@|| | ||
 tj¡ |||
 < qÖ|�rj|| | ||
 tj¡ |||
 < qÖ||7 }qÖt|||ƒ}t | |||¡S )Nr,   r   ©ÚTR10c                    s   g | ]}ˆ |ƒ‘qS r!   r!   )ri   rj   rˆ   r!   r"   rl     s     z/FiniteFourierSeries.__new__.<locals>.<listcomp>F)ZtrigZ
power_baseZ	power_expÚlogr   r   r;   c                 S   s   | j S r4   rA   rB   r!   r!   r"   rC     rD   z-FiniteFourierSeries.__new__.<locals>.<lambda>c                 S   s
   | t jk	S r4   rE   rB   r!   r!   r"   rC     rD   rF   r<   c                    s
   ˆ | j kS r4   r5   rB   rH   r!   r"   rC     rD   )r   r-   r   r'   rJ   rI   r‰   r   Úexpandr`   r   r9   r   r   r   Úgetr   r   r   rQ   )rR   rK   r   r6   ÚcÚeZrexprr    Zexp_lsr   r;   r<   rZ   r[   ÚprM   Úqr!   )r‰   r   r"   rQ     s0    $$
zFiniteFourierSeries.__new__c                 C   sB   | j r
dnd}|tt| j ¡ ƒ t| j ¡ ƒ¡ƒd 7 }td|ƒS rX   )r    ÚmaxÚsetrZ   ÚkeysÚunionr[   r   )rV   Ú_lengthr!   r!   r"   r\   &  s    *zFiniteFourierSeries.intervalc                 C   s   | j | j S r4   )r2   r1   rU   r!   r!   r"   r_   ,  s    zFiniteFourierSeries.lengthc                 C   sd   t |ƒ| j }}||jkr*td||f ƒ‚|  ¡  ||| ¡}| j ||| ¡}|  || jd |¡S ©Nro   r   ©	r   r   r&   r)   rh   r   rW   r   r8   ©rV   rL   r   r:   rp   r!   r!   r"   rt   0  s    
zFiniteFourierSeries.shiftxc                 C   sT   t |ƒ| j }}||jkr*td||f ƒ‚|  ¡ | }| j| }|  || jd |¡S r–   )r   r   r&   r)   rh   rW   r   r8   r˜   r!   r!   r"   ru   ;  s    

zFiniteFourierSeries.scalec                 C   sd   t |ƒ| j }}||jkr*td||f ƒ‚|  ¡  ||| ¡}| j ||| ¡}|  || jd |¡S r–   r—   r˜   r!   r!   r"   rv   F  s    
zFiniteFourierSeries.scalexc                 C   sb   |dkr| j S | j |tj¡t|t| j  | j ƒ | j	 |tj¡t
|t| j  | j ƒ  }|S rS   )r    rZ   rŒ   r   r   r   r   r   r   r[   r   )rV   ry   Ú_termr!   r!   r"   rz   Q  s    &&ÿzFiniteFourierSeries._eval_termc                 C   sŒ   t |tƒr&| t| j| jd dd�¡S t |tƒrˆ| j|jkrDtdƒ‚| j	|j	 }}| j|j 
||¡ }| j	|jkrv|S t|| jd d�S d S )Nr   F)Úfiniter}   )r   )r-   rO   r€   r   rW   r8   r‡   rY   r)   r   r   r&   )rV   r~   r   r   rW   r!   r!   r"   r€   Y  s    
ÿ
zFiniteFourierSeries.__add__N)r‚   rƒ   r„   r…   rQ   r†   r\   r_   rt   ru   rv   rz   r€   r!   r!   r!   r"   r‡   Û  s   &$

r‡   NTc                 C   s:  t | ƒ} t| |ƒ}|d }|| jkr(| S |rdt|d |d  ƒd }t| ||ƒ\}}|rdt| ||ƒS tdƒ}|d |d  d }|j�r|  || ¡}	| |	krÎt	| ||ƒ\}
}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   r3   r&   r`   rN   r‡   r	   Úis_zeror   r#   r   r   rO   r   r   r$   )rK   r   rš   r   r   Ú	is_finiteZres_fr   ÚcenterZneg_fr    rZ   r[   r!   r!   r"   r   j  s6     %

r   )NT)&r…   Zsympy.core.numbersr   r   Zsympy.core.symbolr   Zsympy.core.exprr   Zsympy.core.addr   Zsympy.core.containersr   Zsympy.core.singletonr   r	   r
   Zsympy.core.sympifyr   Z(sympy.functions.elementary.trigonometricr   r   r   Zsympy.series.series_classr   Zsympy.series.sequencesr   Zsympy.sets.setsr   Zsympy.utilities.iterablesr   Z__doctest_requires__r#   r$   r3   rN   rO   r‡   r   r!   r!   r!   r"   Ú<module>   s0   
	8  ^ 