+
    iY                        R t ^ RIHtHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHt ^ RIHt ^ R	IHtHtHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHt RR./tR tR t R t!R t" ! R R]4      t# ! R R]#4      t$RR lt%R# )zFourier Series)oopi)Wild)Expr)Add)Tuple)S)DummySymbol)sympify)sincossinc)
SeriesBase)
SeqFormula)Interval)is_sequence
matplotlibc                   ^ RI Hp V^ ,          V^,          V^,          ,
          rT\        ^V,          \        ,          V,          V,          4      p^V,          V! W,          V4      ,          V,          pVP	                  V\
        P                  4      ^,          pV\        ^V,          V! W,          V4      ,          V,          V^\        34      3# )z,Returns the cos sequence in a Fourier series	integrate)	sympy.integralsr   r   r   subsr   Zeror   r   )	funclimitsnr   xLcos_termformulaa0s	   &&&      t/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/series/fourier.pyfourier_cos_seqr#      s    )!9fQi&)+q1Q3r6!8a< H(lYt??!CG	a	 1	$Bz!h,4?F)KK !1bz+ + +    c                   ^ RI Hp V^ ,          V^,          V^,          ,
          rT\        ^V,          \        ,          V,          V,          4      p\	        ^V,          V! W,          V4      ,          V,          V^\
        34      # )z,Returns the sin sequence in a Fourier seriesr   )r   r   r   r   r   r   )r   r   r   r   r   r   sin_terms   &&&    r"   fourier_sin_seqr'       si    )!9fQi&)+q1Q3r6!8a< Ha(lYt%GGq":' 'r$   c                   R pRRRrTpVf   V! V 4      \         ) \         rTp\        V\        4      '       d3   \        V4      ^8X  d   Vw  r4pM\        V4      ^8X  d   V! V 4      pVw  rE\	        V\
        4      '       d	   Ve   Vf   \        R\        V4      ,          4      h\        P                  \        P                  .pWF9   g   WV9   d   \        R4      h\        W4V34      # )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                     V P                   p\        V4      ^8X  d   VP                  4       # V'       g   \        R4      # \	        RV ,          4      h)   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_x _process_limits.<locals>._find_x@   sN      t9>88::P  r$   NzInvalid limits given: %sz.Both the start and end value should be bounded)r   r   r   r-   
isinstancer
   r/   strr   NegativeInfinityInfinityr   )r   r   r1   r   startstop	unboundeds   &&     r"   _process_limitsr:   )   s    . 4dA~ R$65!!v;!#NAd[AA KEa  EMT\3c&kABB##QZZ0IT.IJJAd#$$r$   c                 x  aaa R  pVV3R lp^ RI HpHpHp V! V! V! V 4      4      4      pVP	                  4       p	\        RR R .R7      o\        RV3R l.R7      oV	^,           FL  p
V
P                  4       ^,          pV F,  pV! VS4      '       d   K  V! VSV4      '       d   K&  R	V 3u u # 	  KN  	  R
V3# )c                     WP                   9  # Nr,   )exprsr   s   &&r"   check_fxfinite_check.<locals>.check_fxc   s    ****r$   c                    < \        V \        \        34      '       dK   V P                  ^ ,          pVP	                  S\
        V,          ,          V,          S,           4      e   R# R# R# )    NTF)r3   r   r   argsmatchr   )_exprr   r   sincos_argsabs   &&& r"   check_sincos"finite_check.<locals>.check_sincosf   sM    ec3Z((**Q-K  BqD!a0< )r$   )TR2TR1sincos_to_sumrH   c                     V P                   # r=   
is_Integerr+   s   &r"   <lambda>finite_check.<locals>.<lambda>s   s    r$   c                 (    V \         P                  8g  # r=   r   r   rR   s   &r"   rS   rT   s   s    QVVr$   
propertiesrI   c                 "   < SV P                   9  # r=   r>   r+   r   s   &r"   rS   rT   t   s    (?r$   FT)sympy.simplify.furL   rM   rN   as_coeff_addr   as_coeff_mul)fr   r   r@   rJ   rL   rM   rN   rF   	add_coeffs
mul_coeffstrH   rI   s   &f&          @@r"   finite_checkrc   a   s    + :9#c!f+&E""$IS46KNOAS?BCAq\\^^%a(
AQNNl1a&;&;ax   ;r$   c                   *  a  ] tR t^t o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       t]R	 4       t]R
 4       t]R 4       t]R 4       t]R 4       tR tRR ltRR ltR tR tR tR tR tR tR tR tR tRtV tR# )FourierSeriesa  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                R    \        \        V4      p\        P                  ! V .VO5!  # r=   )mapr   r   __new__)clsrD   s   &*r"   rh   FourierSeries.__new__   s"    7D!||C'$''r$   c                (    V P                   ^ ,          # rC   rD   selfs   &r"   functionFourierSeries.function   s    yy|r$   c                6    V P                   ^,          ^ ,          # r*   rm   rn   s   &r"   r   FourierSeries.x       yy|Ar$   c                j    V P                   ^,          ^,          V P                   ^,          ^,          3# rs   rm   rn   s   &r"   periodFourierSeries.period   s%    		!Q1a11r$   c                6    V P                   ^,          ^ ,          #    rm   rn   s   &r"   r!   FourierSeries.a0   ru   r$   c                6    V P                   ^,          ^,          # rz   rm   rn   s   &r"   anFourierSeries.an   ru   r$   c                6    V P                   ^,          ^,          # rz   rm   rn   s   &r"   bnFourierSeries.bn   ru   r$   c                "    \        ^ \        4      # rl   )r   r   rn   s   &r"   intervalFourierSeries.interval   s    2r$   c                .    V P                   P                  # r=   )r   infrn   s   &r"   r7   FourierSeries.start       }}   r$   c                .    V P                   P                  # r=   )r   suprn   s   &r"   r8   FourierSeries.stop   r   r$   c                    \         # r=   )r   rn   s   &r"   lengthFourierSeries.length   s    	r$   c                x    \        V P                  ^,          V P                  ^ ,          ,
          4      ^,          # rs   )absrw   rn   s   &r"   r   FourierSeries.L   s'    4;;q>DKKN23a77r$   c                P    V P                   pVP                  V4      '       d   V # R # r=   )r   has)ro   oldnewr   s   &&& r"   
_eval_subsFourierSeries._eval_subs   s"    FF771::K r$   c                    Vf   \        V 4      # . pV  F<  p\        V4      V8X  d    M+V\        P                  Jg   K+  VP	                  V4       K>  	  \        V!  # )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
)iterr-   r   r   appendr   )ro   r   termsrb   s   &&  r"   truncateFourierSeries.truncate   sS    @ 9:A5zQQ	  E{r$   c                    \        V RV 4       UUu. uF?  w  r#V\        P                  Jg   K  \        \        V,          V,          4      V,          NKA  	  ppp\        V!  # u uppi )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   )ro   r   irb   r   s   &&   r"   sigma_approximation!FourierSeries.sigma_approximation   s`    D 3<D!H2E %2E$!QVVO &b1fqj!A%%2E %E{%s
   A#(A#c                2   \        V4      V P                  r!W!P                  9   d   \        RV: RV: 24      hV P                  V,           pV P
                  V,           pV P                  W@P                  ^,          W0P                  V P                  34      # )aZ  
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/   r!   rp   r   rD   r~   r   )ro   r`   r   r!   sfuncs   &&   r"   shiftFourierSeries.shift7  sn    * qz46611aHIIWWq[!yy		!r77DGG.DEEr$   c                   \        V4      V P                  r!W!P                  9   d   \        RV: RV: 24      hV P                  P                  W"V,           4      pV P                  P                  W"V,           4      pV P                  P                  W"V,           4      pV P                  WPP                  ^,          V P                  W434      # )aT  
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/   r~   r   r   rp   r   rD   r!   ro   r`   r   r~   r   r   s   &&    r"   shiftxFourierSeries.shiftxV      * qz46611aHIIWW\\!U#WW\\!U#""1!e,yy		!tww.?@@r$   c                   \        V4      V P                  r!W!P                  9   d   \        RV: RV: 24      hV P                  P                  V4      pV P                  P                  V4      pV P                  V,          pV P                  ^ ,          V,          pV P                  W`P                  ^,          WSV34      # )aZ  
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~   	coeff_mulr   r!   rD   r   )ro   r`   r   r~   r   r!   r   s   &&     r"   scaleFourierSeries.scalev  s    * qz46611aHIIWWq!WWq!WWq[		!q yy		!rrl;;r$   c                   \        V4      V P                  r!W!P                  9   d   \        RV: RV: 24      hV P                  P                  W"V,          4      pV P                  P                  W"V,          4      pV P                  P                  W"V,          4      pV P                  WPP                  ^,          V P                  W434      # )aL  
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   s   &&    r"   scalexFourierSeries.scalex  r   r$   c                H    V  F  pV\         P                  Jg   K  Vu # 	  R # r=   rV   )ro   r   logxcdirrb   s   &&&& r"   _eval_as_leading_term#FourierSeries._eval_as_leading_term  s    A r$   c                    V^ 8X  d   V P                   # V P                  P                  V4      V P                  P                  V4      ,           # rl   )r!   r~   coeffr   )ro   pts   &&r"   
_eval_termFourierSeries._eval_term  s7    777Nww}}R 477==#444r$   c                $    V P                  R4      # )r*   )r   rn   s   &r"   __neg__FourierSeries.__neg__  s    zz"~r$   c                J   \        V\        4      '       Ed   V P                  VP                  8w  d   \        R 4      hV P                  VP                  r2V P
                  VP
                  P                  W24      ,           pV P                  VP                  9  d   V# V P                  VP                  ,           pV P                  VP                  ,           pV P                  VP                  ,           pV P                  W@P                  ^,          WuV34      # \        W4      # )(Both the series should have same periods)r3   re   rw   r/   r   rp   r   r,   r~   r   r!   r   rD   r   )ro   otherr   yrp   r~   r   r!   s   &&      r"   __add__FourierSeries.__add__  s    e]++{{ell* !KLL66577q}}u~~':':1'@@HvvX222588#B588#B588#B99Xyy|bb\BB4r$   c                &    V P                  V) 4      # r=   )r   )ro   r   s   &&r"   __sub__FourierSeries.__sub__  s    ||UF##r$    N)   ) __name__
__module____qualname____firstlineno____doc__rh   propertyrp   r   rw   r!   r~   r   r   r7   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classdictcell____classdict__s   @r"   re   re      s5     (     2 2         ! ! ! !   8 8
*XDLF>A@<BA@
5
 &$ $r$   re   c                   h   a  ] tR tRt o RtR t]R 4       t]R 4       tR t	R t
R tR	 tR
 tRtV tR# )FiniteFourierSeriesi  a  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           	       a \        V4      p\        V4      p\        V4      p\        V\        4      '       d   \        V4      ^8X  Eg   TP	                  4       w  rE^ RIHp T\        V Uu. uF
  qv! V4      NK  	  up!  ,           pVP                  RRRRR7      P	                  4       w  rV^ ,          o\        V^,          V^,          ,
          4      ^,          p\        RR R .R7      p\        RV3R	 l.R7      p/ p/ pV
 EF  pVP                  V\        V\        V,          ,          S,          4      ,          4      pVP                  V\        V\        V,          ,          S,          4      ,          4      pV'       dB   VV,          VP                  VV,          \         P"                  4      ,           VVV,          &   K  V'       dC   VV,          VP                  VV,          \         P"                  4      ,           VVV,          &   EK  V	V,          p	EK  	  \        WV4      p\$        P&                  ! WW#4      # u upi )
r   )TR10F)trig
power_base	power_explogrH   c                     V P                   # r=   rP   rR   s   &r"   rS   -FiniteFourierSeries.__new__.<locals>.<lambda>  s    r$   c                 &    V \         P                  J# r=   rV   rR   s   &r"   rS   r     s    QRQWQWr$   rW   rI   c                 "   < SV P                   9  # r=   r>   rZ   s   &r"   rS   r     s    0Gr$   )r   r3   r   r-   r\   r[   r   r   expandr   r   rE   r   r   r   getr   r   r   rh   )ri   r^   r   r?   cer   r   rexprr!   exp_lsr   rH   rI   r~   r   prb   qr   s   &&&&               @r"   rh   FiniteFourierSeries.__new__  s   AJ5%((SZ1_%%'DA.q1q!d1gq122E5UeY^_llnJBq	AF1Iq	)*Q.AS&<>W%Z[AS&G%JKABB GGAAaL1$4 556GGAAaL1$4 556 tbffQqT166&::BqtH tbffQqT166&::BqtH!GB  ""%E||CF223 2s   ,I
c           	        V P                   '       d   ^M^ pV\        \        V P                  P	                  4       4      P                  \        V P                  P	                  4       4      4      4      ^,           ,          p\        ^ V4      # rs   )r!   maxsetr~   keysunionr   r   )ro   _lengths   & r"   r   FiniteFourierSeries.interval&  s[    www!A3s477<<>*00TWW\\^1DEFJJ7##r$   c                <    V P                   V P                  ,
          # r=   )r8   r7   rn   s   &r"   r   FiniteFourierSeries.length,  s    yy4::%%r$   c                J   \        V4      V P                  r!W!P                  9   d   \        R V: RV: 24      hV P	                  4       P                  W"V,           4      pV P                  P                  W"V,           4      pV P                  W@P                  ^,          V4      # r   r   	r   r   r,   r/   r   r   rp   r   rD   ro   r`   r   rF   r   s   &&   r"   r   FiniteFourierSeries.shiftx0  v    qz46611aHII$$QA.""1!e,yy		!e44r$   c                   \        V4      V P                  r!W!P                  9   d   \        R V: RV: 24      hV P	                  4       V,          pV P
                  V,          pV P                  W@P                  ^,          V4      # r   )r   r   r,   r/   r   rp   r   rD   r   s   &&   r"   r   FiniteFourierSeries.scale;  sb    qz46611aHII!#!yy		!e44r$   c                J   \        V4      V P                  r!W!P                  9   d   \        R V: RV: 24      hV P	                  4       P                  W"V,          4      pV P                  P                  W"V,          4      pV P                  W@P                  ^,          V4      # r   r   r   s   &&   r"   r   FiniteFourierSeries.scalexF  r   r$   c                   V^ 8X  d   V P                   # V P                  P                  V\        P                  4      \        V\        V P                  ,          ,          V P                  ,          4      ,          V P                  P                  V\        P                  4      \        V\        V P                  ,          ,          V P                  ,          4      ,          ,           pV# rl   )r!   r~   r   r   r   r   r   r   r   r   r   )ro   r   _terms   && r"   r   FiniteFourierSeries._eval_termQ  s    777NB'#bBK.@466.I*JJ''++b!&&)Cb466k0BTVV0K,LLMr$   c                   \        V\        4      '       d9   VP                  \        V P                  V P
                  ^,          RR7      4      # \        V\        4      '       d   V P                  VP                  8w  d   \        R4      hV P                  VP                  r2V P                  VP                  P                  W24      ,           pV P                  VP                  9  d   V# \        W@P
                  ^,          R7      # R# )r*   F)finiter   )r   N)r3   re   r   fourier_seriesrp   rD   r   rw   r/   r   r   r,   )ro   r   r   r   rp   s   &&   r"   r   FiniteFourierSeries.__add__Y  s    e]++==tyy|7<"> ? ?233{{ell* !KLL66577q}}u~~':':1'@@HvvX222!(99Q<@@ 4r$   r   N)r   r   r   r   r   rh   r   r   r   r   r   r   r   r   r   r   r   s   @r"   r   r     sY     $L"3H $ $
 & &	5	5	5A Ar$   r   Nc                   \        V 4      p \        W4      pV^ ,          pW0P                  9  d   V # V'       dJ   \        V^,          V^,          ,
          4      ^,          p\	        WV4      w  rVV'       d   \        WV4      # \        R4      pV^,          V^,          ,           ^,          pVP                  '       d   V P                  W3) 4      p	W	8X  d/   \        WV4      w  r\        ^ ^\        34      p\        WWV34      # W	) 8X  d=   \        P                  p
\        ^ ^\        34      p\        WV4      p\        WWV34      # \        WV4      w  r\        WV4      p\        WWV34      # )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   rc   r   r	   is_zeror   r#   r   r   re   r   r   r'   )r^   r   r  r   r   	is_finiteres_fr   centerneg_fr!   r~   r   s   &&&          r"   r  r  j  sB   H 	
AQ'Fq	Aq	F1I%&*'a0	&q%88c
AQi&)#q(F~~~q":$Q2FBA2w'B RRL99&[BA2w'B A.B RRL99Q*FB	A	&BRRL11r$   )r  )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:   rc   re   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$   