ó
    Š*£hÔÉ  ã                   óx  • S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
  SSKJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJrJr  SSKJr  SSKJ r   SSK!J"r"J#r#J$r$  SSK%J&r&  SSK'J(r(J)r)J*r*  SSK+J,r,J-r-  SSK.J/r/  SSK0J1r1  SSK2J3r3  SSK4J5r5  SSK6J7r7  SSK8J9r9  S>S jr:S r;S?S jr<S r=S r>S r?S r@S  rAS! rBS" rCS# rDS$ rES% rFS& rGS' rHS( rIS) rJS* rKS+ rLS, rMS?S- jrNS. rO  S@S/ jrP " S0 S1\5      rQ " S2 S3\75      rR " S4 S5\R5      rS " S6 S7\S5      rT " S8 S9\S5      rU " S: S;\S5      rVSAS= jrWg<)BzFormal Power Seriesé    )Údefaultdict)ÚnanÚooÚzoo)ÚAdd)ÚExpr)Ú
DerivativeÚFunctionÚexpand)ÚMul)ÚRational)ÚEq)ÚInterval)ÚS)ÚWildÚDummyÚsymbolsÚSymbol)Úsympify)Úconvolution)ÚbinomialÚ	factorialÚrf)Úbell)ÚfloorÚfracÚceiling)ÚMinÚMax)Ú	Piecewise)ÚLimit)ÚOrder)Úsequence)Ú
SeriesBase)Úiterablec                 óD  • SSK JnJn  SSKJn  U n/ n	[        US-   5       GH{  n
U
(       a  UR                  U5      nUR                  U5      (       Ga7  [        R                  [        R                  pËU" X�US9nUR                  U5      (       a  UR                  5       n[        R                  " U5       H÷  nUR                  5       u  nnUR                  U5      (       d  XÎ-  nM2  [        U[         5      (       a  UR#                  U5      nUS   nUUS   -  nUR%                  5       u  nnUR'                  U5      u  nnU(       d  XÎ-  nM™  US   R)                  U5      nUU* -  nUUU-  -  nSU-  U-  [+        UU-   S-
  U5      R-                  [.        5      -  UUU-   -  -  nUU-  nMù     UR0                  (       a    gUR                  U5      (       dN  UR                  [2        5      (       d4  UR                  [4        5      (       d  UR                  [6        5      (       a    g[        U
5       H:  nX²U-   S-   -  nU" XÁ5      nXÉR9                  5       U-
  R;                  US5      -  nM<     UR=                  X"U
-
  5      XÊ4s  $ U	R?                  U5        GM~     g)a?  
Rational algorithm for computing
formula of coefficients of Formal Power Series
of a function.

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

Applicable when f(x) or some derivative of f(x)
is a rational function in x.

:func:`rational_algorithm` uses :func:`~.apart` function for partial fraction
decomposition. :func:`~.apart` by default uses 'undetermined coefficients
method'. By setting ``full=True``, 'Bronstein's algorithm' can be used
instead.

Looks for derivative of a function up to 4'th order (by default).
This can be overridden using order option.

Parameters
==========

x : Symbol
order : int, optional
    Order of the derivative of ``f``, Default is 4.
full : bool

Returns
=======

formula : Expr
ind : Expr
    Independent terms.
order : int
full : bool

Examples
========

>>> from sympy import log, atan
>>> from sympy.series.formal import rational_algorithm as ra
>>> from sympy.abc import x, k

>>> ra(1 / (1 - x), x, k)
(1, 0, 0)
>>> ra(log(1 + x), x, k)
(-1/((-1)**k*k), 0, 1)

>>> ra(atan(x), x, k, full=True)
((-I/(2*(-I)**k) + I/(2*I**k))/k, 0, 1)

Notes
=====

By setting ``full=True``, range of admissible functions to be solved using
``rational_algorithm`` can be increased. This option should be used
carefully as it can significantly slow down the computation as ``doit`` is
performed on the :class:`~.RootSum` object returned by the :func:`~.apart`
function. Use ``full=False`` whenever possible.

See Also
========

sympy.polys.partfrac.apart

References
==========

.. [1] Formal Power Series - Dominik Gruntz, Wolfram Koepf
.. [2] Power Series in Computer Algebra - Wolfram Koepf

r   )ÚRootSumÚapart©Ú	integrateé   )ÚfulléÿÿÿÿN) Úsympy.polysr'   r(   Úsympy.integralsr*   ÚrangeÚdiffÚis_rational_functionr   ÚZeroÚhasÚdoitr   Ú	make_argsÚas_numer_denomÚ
isinstancer   Úas_independentÚas_base_expÚas_coeff_addÚcoeffr   Úrewriter   Úis_zeror   r   r   ÚpopÚlimitÚsubsÚappend)ÚfÚxÚkÚorderr,   r'   r(   r*   r1   ÚdsÚir<   ÚsepÚtermsÚtÚnumÚdenÚindÚjÚaÚxtermÚxcÚaks                          ÚP/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/series/formal.pyÚrational_algorithmrU      sJ  € ÷R +Ý)à€DØ	€Bä�5˜1‘9×ˆÞØ—9‘9˜Q“<ˆDà×$Ñ$ Q×'Ò'ÜŸ™¤§¡�3á˜$¨Ñ-ˆEØ�y‰y˜×!Ñ!ØŸ
™
›�ä—]’] 5Ö)�Ø×+Ñ+Ó-‘��SØ—w‘w˜q—z‘zØ‘H’Cä! #¤s×+Ñ+à!×0Ñ0°Ó3˜Ø! !™f˜Ø˜s 1™v™˜ð !Ÿ_™_Ó.‘F�C˜Ø"×/Ñ/°Ó2‘H�A�uö Ø™˜Ù à˜q™Ÿ™¨Ó*�BØ˜"˜‘H�AØ˜2˜q™5‘L�Cà ™' C™-Ü" 1 q¡5¨1¡9¨aÓ0×8Ñ8¼ÓCñDà˜a !™e™*ñ%�Bð ˜R‘K’Eñ7 *ð< �}�}ÙØ—	‘	˜!—‘ §	¡	¬#§¡°%·)±)¼B·-±-Ø—I‘Iœc—N‘NÙä˜1–X�Ø a¡%¨!¡)Ñ,�Ù Ó'�ØŸ™› 3™×-Ñ-¨a°Ó3Ñ3’ñ ð —J‘J˜q a¡%Ó(¨#Ð1Ò1ð �I‰I�d�Oñm ðp ó    c                 óB  • U (       d  / $ U SS nU SS  H‡  nUR                  U5      S   n[        U5       HP  u  pVUR                  U5      S   nXG-  R                  5       nUR                  U5      (       d  MC  X%==   U-  ss'     Mt     UR	                  U5        M‰     U$ )a^  
Returns a list of all the rationally independent terms.

Examples
========

>>> from sympy import sin, cos
>>> from sympy.series.formal import rational_independent
>>> from sympy.abc import x

>>> rational_independent([cos(x), sin(x)], x)
[cos(x), sin(x)]
>>> rational_independent([x**2, sin(x), x*sin(x), x**3], x)
[x**3 + x**2, x*sin(x) + sin(x)]
r   r+   N)r9   Ú	enumerateÚcancelr2   rB   )	rJ   rD   rN   rK   ÚnrH   ÚtermÚdÚqs	            rT   Úrational_independentr^   ¨   s¢   € ö  Øˆ	à
��!ˆ*€Cà�1�2‹YˆØ×Ñ˜QÓ Ñ"ˆÜ  –~‰GˆAØ×#Ñ# AÓ& qÑ)ˆAØ‘—‘Ó ˆAØ×%Ñ% a×(Ó(Ø“˜!‘“Úñ &ð �J‰J�qŽMñ ð €JrV   c              #   óZ  ^ ^^^#   • SSK Jn  [        SU-  5      mUU UU4S jnSn[        SUS-   5       Hñ  nU" U5      u  p‰UR	                  5       nUR                  5       n
[        U
T5      nU(       d  [        U5      U:X  d  MQ  [        [        TS U" UTSU 5       5       5      5      nU(       a  S	nU	R                  U5      n	U	R                  5       S   n	U	R                  5       R                  [        5      S   S   n	U	R                  [        T" T5      5      5      U4v •  Mó     g7f)
aX  
Generates simple DE.

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

DE is of the form

.. math::
    f^k(x) + \sum\limits_{j=0}^{k-1} A_j f^j(x) = 0

where :math:`A_j` should be rational function in x.

Generates DE's upto order 4 (default). DE's can also have free parameters.

By increasing order, higher order DE's can be found.

Yields a tuple of (DE, order).
r   ©Úlinsolveza:%dc                 óf  >• TR                  TU 5      [        [        SU 5       Vs/ s H  nTU   TR                  TU5      -  PM     sn6 -   nT" T5      R                  TU 5      [        [        SU 5       Vs/ s H!  nTU   T" T5      R                  TU5      -  PM#     sn6 -   nX#4$ s  snf s  snf ©Nr   )r1   r   r0   )rE   rH   ÚeqÚDErP   rC   ÚgrD   s       €€€€rT   Ú_makeDEÚsimpleDE.<locals>._makeDEâ   s�   ø€ Ø�V‰V�A�q‹\œC¼UÀ1Àa¼[Ó!Iº[¸ ! A¡$ q§v¡v¨a°£|Ô"3¹[Ñ!IÐJÑJˆÙˆq‹T�Y‰Y�q˜!‹_œsÄ5ÈÈAÄ;Ó$OÂ;¸a Q q¡T©!¨A«$¯)©)°A°q«/Ô%9Á;Ñ$OÐPÑPˆØˆvˆùò "JùÚ$Os   ¦"B)
Á8(B.
Fr+   c              3   ó6   #   • U  H  o  H  o"v •  M     M     g 7f©N© ©Ú.0ÚsrH   s      rT   Ú	<genexpr>ÚsimpleDE.<locals>.<genexpr>î   s   é € ÐJÒ*> QËÀ1œqÉ™qÒ*>ùó   ‚NT)Úsympy.solvers.solvesetra   r   r0   r   Úas_ordered_termsr^   ÚlenÚdictÚziprA   r7   ÚfactorÚas_coeff_mulr	   Úcollect)rC   rD   rf   rF   ra   rg   ÚfoundrE   rd   re   rJ   rN   ÚsolrP   s   ```          @rT   ÚsimpleDEr|   Ê   s  ûé € õ( 0ä�˜%Ñ Ó!€A÷ð ð
 €EÜ�1�e˜a‘iÖ ˆÙ˜“‰ˆØ�Y‰Y‹[ˆØ×#Ñ#Ó%ˆÜ" 5¨!Ó,ˆÞ”C˜“H •MÜ”s˜1ÑJ©(°3¸¸"¸1¸Ô*>ÓJÓKÓLˆCÞØ�Ø—W‘W˜S“\�Ø×"Ñ"Ó$ QÑ'ˆBØ—‘“×)Ñ)¬*Ó5°aÑ8¸Ñ;ˆBØ—*‘*œZ©¨!«Ó-Ó.°Ð1Ô1ò !ùs   †A<D+ÂB%D+c                 ó€  • [         R                  nU R                  [        5      R	                  5       nSn[
        R                  " U 5       HS  nUR                  U5      u  px[        U[        5      (       a  UR                  n	OSn	Ub  X•:  a  U	nX7U" X)-   5      -  -  nMU     U(       a  UR                  X"U-
  5      nU$ )aK  Converts a DE with constant coefficients (explike) into a RE.

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

Performs the substitution:

.. math::
    f^j(x) \to r(k + j)

Normalises the terms so that lowest order of a term is always r(k).

Examples
========

>>> from sympy import Function, Derivative
>>> from sympy.series.formal import exp_re
>>> from sympy.abc import x, k
>>> f, r = Function('f'), Function('r')

>>> exp_re(-f(x) + Derivative(f(x)), r, k)
-r(k) + r(k + 1)
>>> exp_re(Derivative(f(x), x) + Derivative(f(x), (x, 2)), r, k)
r(k) + r(k + 1)

See Also
========

sympy.series.formal.hyper_re
Nr   )r   r3   Úatomsr
   r?   r   r6   r9   r8   r	   Úderivative_countrA   )
re   ÚrrE   ÚRErf   ÚminirK   r<   r\   rO   s
             rT   Úexp_rerƒ   ÷   s¨   € ô> 
�‰€Bà
�‰”Ó×ÑÓ €Aà€DÜ�]Š]˜2ÖˆØ×#Ñ# AÓ&‰ˆÜ�aœ×$Ñ$Ø×"Ñ"‰AàˆAØ‰<˜1›8ØˆDØ
‘a˜™“hÑÑŠñ ö Ø�W‰W�Q˜D™Ó!ˆØ€IrV   c                 ó   • [         R                  nU R                  [        5      R	                  5       nUR                  [
        5      R	                  5       nSn[        R                  " U R                  5       5       H—  nUR                  U5      u  p‰UR                  U5      u  p«UR                  U5      S   n[        U	[        5      (       a  U	R                  nOSnX:[        US-   U-
  U5      -  U" X--   U-
  5      -  -  nUb
  XÜ-
  U:  d  M“  XÜ-
  nM™     UR                  X"U-
  5      n[!        S5      nUR#                  U" X.-   5      5      $ )aO  
Converts a DE into a RE.

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

Performs the substitution:

.. math::
    x^l f^j(x) \to (k + 1 - l)_j . a_{k + j - l}

Normalises the terms so that lowest order of a term is always r(k).

Examples
========

>>> from sympy import Function, Derivative
>>> from sympy.series.formal import hyper_re
>>> from sympy.abc import x, k
>>> f, r = Function('f'), Function('r')

>>> hyper_re(-f(x) + Derivative(f(x)), r, k)
(k + 1)*r(k + 1) - r(k)
>>> hyper_re(-x*f(x) + Derivative(f(x), (x, 2)), r, k)
(k + 2)*(k + 3)*r(k + 3) - r(k)

See Also
========

sympy.series.formal.exp_re
Nr+   r   Úm)r   r3   r~   r
   r?   r   r   r6   r   r9   Úas_coeff_exponentr8   r	   r   r   rA   r   ry   )re   r€   rE   r�   rf   rD   r‚   rK   r<   r\   ÚcÚvÚlrO   r…   s                  rT   Úhyper_rerŠ   )  s   € ô@ 
�‰€Bà
�‰”Ó×ÑÓ €AØ	�‰”‹×ÑÓ€Aà€DÜ�]Š]˜2Ÿ9™9›;Ö'ˆØ×#Ñ# AÓ&‰ˆØ×#Ñ# AÓ&‰ˆØ×Ñ Ó" 1Ñ%ˆÜ�aœ×$Ñ$Ø×"Ñ"‰AàˆAØ
”"�Q˜‘U˜Q‘Y Ó"Ñ"¡Q q¡u¨q¡y£\Ñ1Ñ1ˆØ‰<˜1™5 4�<Ø‘5ŠDñ (ð 
�‰�˜‘HÓ	€BäˆS‹	€AØ�:‰:‘a˜™“hÓÐrV   c                 ój   • XU* -  -  n UR                  XDU-   5      nUR                  XDU-   5      nXX54$ rj   ©rA   )rC   rD   ÚPÚQrE   r…   Úshifts          rT   Ú_transformation_ar�   a  s>   € ØˆeˆV‰Ñ€AØ	�‰ˆq�e‘)Ó€AØ	�‰ˆq�e‘)Ó€AØ�ˆ:ÐrV   c                 óŠ   • U R                  XU-  5      n UR                  XDU-  5      nUR                  XDU-  5      nXV-  nXX54$ rj   rŒ   )rC   rD   r�   rŽ   rE   r…   Úscales          rT   Ú_transformation_cr“   h  sI   € Ø	�‰ˆq�U‘(Ó€AØ	�‰ˆq�e‘)Ó€AØ	�‰ˆq�e‘)Ó€AØ�J€AØ�ˆ:ÐrV   c                 ó˜   • U R                  U5      n UR                  XDS-   5      XE-   S-   -  nUR                  XDS-   5      US-   -  nXX54$ ©Nr+   )r1   rA   )rC   rD   r�   rŽ   rE   r…   s         rT   Ú_transformation_er–   p  sQ   € Ø	�‰ˆq‹	€AØ	�‰ˆq�a‘%Ó˜A™E A™IÑ&€AØ	�‰ˆq�a‘%Ó˜A ™EÑ"€AØ�ˆ:ÐrV   c                 óD   • U  VVs/ s H  u  p#X#U-   4PM     snn$ s  snnf rj   rk   )r{   r�   ÚresÚconds       rT   Ú_apply_shiftrš   w  ó#   € Ù14Ô5²¡I CˆS˜‘,Ó±Ò5Ð5ùÓ5ó   †c                 óD   • U  VVs/ s H  u  p#X#U-  4PM     snn$ s  snnf rj   rk   )r{   r’   r˜   r™   s       rT   Ú_apply_scalerž   {  r›   rœ   c           	      ó–   • U  VVs/ s H4  u  p4X4S-   UR                  5       S   R                  U5      -  -  US-   4PM6     snn$ s  snnf r•   )Úas_coeff_Addr<   )r{   rD   rE   r˜   r™   s        rT   Ú_apply_integrater¡     sW   € á ô"Ú ‘	�ð ˜A‘X × 1Ñ 1Ó 3°AÑ 6× <Ñ <¸QÓ ?Ñ@ÑAÀ4È!Á8ÓLÙ ò"ð "ùó "s   †;Ac                 ó6  • SSK Jn  / n[        US-   Xe-   S-   5       GHk  n	U	S:  S:X  a  M  U R                  X5      R	                  US5      [        U	5      -  n
U
R                  (       a  MO  XT-  U	-   nU
nUR                  XK5      nUR                  XK5      nUR                  USU-  5      R                  U5      S   nUR                  USU-  5      R                  U5      S   nXÏ* U-  U-  -  nU[        U" XÔ5      R                  5        V
Vs/ s H  u  n
n[        U
* U5      U-  PM     snn
6 -  nU[        U" Xä5      R                  5        V
Vs/ s H  u  n
n[        U
* U5      U-  PM     snn
6 -  nUR                  XË45        GMn     U$ s  snn
f s  snn
f )zComputes the formula for f.r   )Úrootsr+   T)r.   r£   r0   r1   r@   r   r>   rA   Úleadtermr   Úitemsr   rB   )rC   rD   r�   rŽ   rE   r…   Úk_maxr£   r{   rH   r€   Úktermr˜   Úpr]   Úc1Úc2Úmuls                     rT   Ú_compute_formular¬   „  s|  € å!à
€CÜ�5˜1‘9˜e™i¨!™m×,ˆØ�‰E�d‹?ÙØ�F‰F�1‹L×Ñ˜q !Ó$¤y°£|Ñ3ˆØ�9�9Ùà‘�a‘ˆØˆà�F‰F�1ÓˆØ�F‰F�1ÓˆØ�V‰V�A�q˜‘s‹^×$Ñ$ QÓ'¨Ñ*ˆØ�V‰V�A�q˜‘s‹^×$Ñ$ QÓ'¨Ñ*ˆØ��b‘˜1‰}ÑˆàŒs±%¸³+×2CÑ2CÔ2EÔFÒ2E©¨¨3”R˜˜˜A“Y ”^Ñ2EÒFÐGÑGˆØŒs±%¸³+×2CÑ2CÔ2EÔFÒ2E©¨¨3”R˜˜˜A“Y ”^Ñ2EÒFÐGÑGˆà�
‰
�C�<× ñ' -ð* €Jùó GùÛFs   ÄFÅFc           
      óN  • SSK JnJn  SSKJn  U" X$5      U" X45      p©[        U	5      nUR                  U
5        U" UR                  5        VVs/ s H+  u  pÍUR                  (       d  M  UR                  5       S   PM-     snn5      n[        XX#XEU5      u  pp5U" X45      n
U
(       a  [        U
R                  5       6 nO[        R                  nXõ-   n[        XX#XEU5      u  pp5X-  R!                  US5      n[#        U[$        5      (       d  US:w  a  gU" X45      n
U
(       a  ['        U
R                  5       6 nO[        R                  n[        R                  [(        * nn[+        UU-   S-   5       Hè  nU R-                  UU5      R!                  US5      [/        U5      -  nUR0                  SL ay  U n[        XX#XEU5      u  pp5[3        XX#XE5      u  pp5[5        XX#XE5      u  nnn[7        UX5      n[9        UU5      nU" UU5      nUUU-
  R!                  US5      -  nUS-  nUUU4s  $ U(       d  MÂ  UXÁUU-   -  -  -  n[;        UU-   U5      nUU:”  d  Mæ  UnMê     UR=                  XSU-  -  5      n[?        XX#XEU5      n[9        UU5      n[A        UU5      nUUU4$ s  snnf )zù
Recursive wrapper to rsolve_hypergeometric.

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

Returns a Tuple of (formula, series independent terms,
maximum power of x in independent terms) if successful
otherwise ``None``.

See :func:`rsolve_hypergeometric` for details.
r   )Úlcmr£   r)   r+   NF)!r.   r®   r£   r/   r*   ru   Úupdater¥   Úis_rationalr7   r“   r   Úkeysr   r3   r�   r@   r8   r!   r   r   r0   r1   r   Ú	is_finiter–   Ú_rsolve_hypergeometricr¡   rš   r   rA   r¬   rž   )rC   rD   r�   rŽ   rE   r…   r®   r£   r*   ÚprootsÚqrootsÚ	all_rootsr€   rK   r’   Úk_minr�   r‰   r¦   rN   ÚmprH   Úold_fr{   Úpow_xs                            rT   r³   r³   ¡  s‹  € ÷ 'Ý)ñ ˜1“[¡%¨£+ˆFÜ�V“€IØ×Ñ�VÔÙ°9·?±?Ô3Dô #Ò3D©4¨1Ø—M•Mó '�×!Ñ!Ó# AÔ&Ñ3Dò #ó $€Eä" 1¨¨q°UÓ;�J€Aˆ!ñ �1‹[€FÞÜ�V—[‘[“]Ð#‰ä—‘ˆØ‰I€EÜ" 1¨¨q°UÓ;�J€Aˆ!à	
‰�‰�A�qÓ€AÜ�aœ×Ñ A¨£FØá�1‹[€FÞÜ�V—[‘[“]Ð#‰ä—‘ˆä�f‰f”r�cˆ€CÜ�5˜1‘9˜q‘=Ö!ˆØ�F‰F�1�a‹L×Ñ˜q !Ó$¤y°£|Ñ3ˆØ�;‰;˜%ÒØˆEÜ*¨1°°q¸QÓ?‰JˆA�!Ü*¨1°°qÓ<‰JˆA�!Ü1°!¸¸aÓC‰LˆC��bÜ" 3¨Ó-ˆCÜ˜s AÓ&ˆCÙ˜C Ó#ˆCØ�E˜C‘K×&Ñ& q¨!Ó,Ñ,ˆCØ�!‰GˆBØ˜˜R�<ÒßˆQØ�1˜˜U™‘^Ñ#Ñ#ˆCÜ˜a %™i¨%Ó0ˆEØ�r�zØ’ñ# "ð$ �(‰(�1˜!˜E™'‘lÓ
#€Cä
˜1  q¨UÓ
3€CÜ
�s˜EÓ
"€CÜ
�s˜EÓ
"€Cà��Rˆ<Ðùóa#s   ÁJ!
Á*J!
c           	      óð  • [        XX#XE5      nUc  gUu  pxn	[        S 5      n
U H…  u  p¼UR                  5       u  pÞUR                  U5      nUR                  SL a  X±[        U5      -  -  n[        U5      nUR                  XDU-
  U-  5      n[        XO-  Xß-  5      nX¬==   U-  ss'   M‡     U
R                  5        VVs/ s H  u  pËX¼4PM
     nnnUR                  [        R                  S45        [        U6 nU	[        * L a  [        R                  nO U	R                  SL a  [        U	5      nOU	S-   nUS:  a0  U[!        [#        UX-  -  UUS45      5      -  n[        R                  nUUU4$ s  snnf )aD  
Solves RE of hypergeometric type.

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

Attempts to solve RE of the form

Q(k)*a(k + m) - P(k)*a(k)

Transformations that preserve Hypergeometric type:

    a. x**n*f(x): b(k + m) = R(k - n)*b(k)
    b. f(A*x): b(k + m) = A**m*R(k)*b(k)
    c. f(x**n): b(k + n*m) = R(k/n)*b(k)
    d. f(x**(1/m)): b(k + 1) = R(k*m)*b(k)
    e. f'(x): b(k + m) = ((k + m + 1)/(k + 1))*R(k + 1)*b(k)

Some of these transformations have been used to solve the RE.

Returns
=======

formula : Expr
ind : Expr
    Independent terms.
order : int

Examples
========

>>> from sympy import exp, ln, S
>>> from sympy.series.formal import rsolve_hypergeometric as rh
>>> from sympy.abc import x, k

>>> rh(exp(x), x, -S.One, (k + 1), k, 1)
(Piecewise((1/factorial(k), Eq(Mod(k, 1), 0)), (0, True)), 1, 1)

>>> rh(ln(1 + x), x, k**2, k*(k + 1), k, 1)
(Piecewise(((-1)**(k - 1)*factorial(k - 1)/RisingFactorial(2, k - 1),
 Eq(Mod(k, 1), 0)), (0, True)), x, 2)

References
==========

.. [1] Formal Power Series - Dominik Gruntz, Wolfram Koepf
.. [2] Power Series in Computer Algebra - Wolfram Koepf
Nc                  ó"   • [         R                  $ rj   ©r   r3   rk   rV   rT   Ú<lambda>Ú'rsolve_hypergeometric.<locals>.<lambda>   s   € ¤1§6¢6rV   FTr+   r   r-   )r³   r   r    r<   Ú
is_integerr   r   rA   r   r¥   rB   r   r3   r    r   r   Úsumr#   )rC   rD   r�   rŽ   rE   r…   ÚresultÚsol_listrN   r¸   Úsol_dictr˜   r™   rO   Úmkr‡   r{   rn   s                     rT   Úrsolve_hypergeometricrÆ   è  sd  € ôb $ A¨!°Ó5€Fà�~ØàÑ€H�2ä™>Ó*€HÛ‰	ˆØ×!Ñ!Ó#‰ˆØ�H‰H�Q‹Kˆà�<‰<˜5Ò Ø”d˜1“g‘:ÑˆCÜ�a“ˆAà�h‰h�q˜q™5 A™+Ó&ˆÜ�!‘%˜™ÓˆØ‹˜#Ñ�ñ ð )1¯©Ô(8Ô
9Ò(8™9˜4ˆC‹;Ñ(8€CÑ
9Ø‡J�J”—‘˜ˆ~ÔÜ
�Sˆ/€Cà	ŒbˆS‚yÜ�F‰F‰Ø	�‰˜%Ò	Ü�B‹K‰à�‰Fˆð 	ˆ1ƒuØŒs”8˜C !¡$™J¨¨A¨r¨
Ó3Ó4Ñ4ˆÜ�F‰Fˆà��aˆ=Ðùó# :s   ÃE2c                 óD  • [         R                  " U5      n[        U5      S:X  a{  [        UR	                  [
        5      5      n[        UR                  U5      u  pxUS   R                  S   US   R                  S   -
  n	U	S:  a  X‡p‡[        U	5      n	[        XXxXI5      $ g)z;See docstring of :func:`rsolve_hypergeometric` for details.é   r+   r   N)r   r6   rt   Úlistr~   r
   Úmapr<   ÚargsÚabsrÆ   )
rC   rD   r�   rf   rE   rJ   Úgsr�   rŽ   r…   s
             rT   Ú_solve_hyper_RErÎ   A  s‹   € ä�MŠM˜"Ó€Eä
ˆ5ƒz�QƒÜ�"—(‘(œ8Ó$Ó%ˆÜ�2—8‘8˜RÓ ‰ˆØˆq‰E�J‰J�q‰M˜B˜q™EŸJ™J q™MÑ)ˆØˆq‹5ØˆqÜ�A“ˆAÜ$ Q¨1°Ó6Ð6ð rV   c                 ó  • SSK Jn  [        R                  " U5       H)  nUR	                  U5      u  pxUR
                  (       d  M)    g   [        X#U5      n	0 n
[        [        [        R                  " U	5      5      5       HD  nU(       a  U R                  U5      n U R                  US5      X£" U5      R                  XK5      '   MF     U" X“" U5      U
5      nU(       a-  U[        U5      -  [        R                  [        R                  4$ g)z%Solves DE with constant coefficients.r   ©ÚrsolveN)Úsympy.solversrÑ   r   r6   r9   Úfree_symbolsrƒ   r0   rt   r1   r@   rA   r   r   r3   )rC   rD   re   rf   rE   rÑ   rK   r<   r\   r�   ÚinitrH   r{   s                rT   Ú_solve_explike_DErÕ   O  sÓ   € å$ä�]Š]˜2ÖˆØ×#Ñ# AÓ&‰ˆØ××ÑÙñ ô
 
��qÓ	€Bà€DÜ”3”s—}’} RÓ(Ó)Ö*ˆÞØ—‘�q“	ˆAØ !§¡¨¨1£ˆˆQˆq‹T�Y‰Y�q‹_Óñ +ñ
 ��Q�q“T˜4Ó
 €Cæ
Ø”i “lÑ"¤A§F¡F¬A¯F©FÐ3Ð3ð rV   c                 ó’  • SSK Jn  [        X#U5      n0 n[        [	        [
        R                  " U5      5      5       HP  nU(       a  U R                  U5      n U R                  US5      [        U5      -  Xs" U5      R                  XH5      '   MR     U" Xc" U5      U5      n	U	(       a!  U	[        R                  [        R                  4$ g)z4Converts DE into RE and solves using :func:`rsolve`.r   rÐ   N)rÒ   rÑ   rŠ   r0   rt   r   r6   r1   r@   r   rA   r   r3   )
rC   rD   re   rf   rE   rÑ   r�   rÔ   rH   r{   s
             rT   Ú_solve_simpler×   f  s�   € å$ä	�"˜Ó	€Bà€DÜ”3”s—}’} RÓ(Ó)Ö*ˆÞØ—‘�q“	ˆAØ !§¡¨¨1£´	¸!³Ñ <ˆˆQˆq‹T�Y‰Y�q‹_Óñ +ñ
 ��Q�q“T˜4Ó
 €Cæ
Ø”Q—V‘VœQŸV™VÐ$Ð$ð rV   c                 ó  • SSK Jn  / nU R                  [        U" U5      X#5      5      n[	        U5       Hj  nU R                  [        U" U5      X(5      5      n	X—-  R                  5       R                  U5      n	UR                  [        R                  " U	5      5        Ml     / n
U HH  nUR                  U5      (       a    O3UR                  [        5      (       d  M7  U
R                  U5        MJ     U
nU(       a�  [        [        US U" U[        U5      5       5       5      5      nU(       aZ  U R!                  U5      n U R#                  5       R%                  [        5      S   S   n U R                  [        U" U5      5      5      n U $ )zDConverts DE with free parameters into DE with constant coefficients.r   r`   c              3   ó6   #   • U  H  o  H  o"v •  M     M     g 7frj   rk   rl   s      rT   ro   Ú(_transform_explike_DE.<locals>.<genexpr>‹  s   é € ÐMÒ)A AË1ÀaœaÉ1™aÒ)Aùrq   r+   )rr   ra   r<   r	   r0   r   ry   Úextendr   r6   r4   r   rB   ru   rv   rÉ   rA   rw   rx   )re   rf   rD   rF   Úsymsra   rd   Úhighest_coeffrH   r<   ÚtempÚer{   s                rT   Ú_transform_explike_DErà   x  s,  € å/à	€BØ—H‘HœZ©¨!«¨aÓ7Ó8€MÜ�5Ž\ˆØ—‘œ¡A a£D¨!Ó/Ó0ˆØÑ&×.Ñ.Ó0×8Ñ8¸Ó;ˆØ
�	‰	”#—-’- Ó&Ö'ñ ð €DÛˆØ�5‰5��8‰8ÙØ�U‰U”6�]‹]Ø�K‰K˜ŽNñ	 ð ˆÞ	Ü”3�tÑM©°"´d¸4³jÔ)AÓMÓNÓOˆÞØ—‘˜“ˆBØ—‘“×)Ñ)¬*Ó5°aÑ8¸Ñ;ˆBØ—‘œJ¡q¨£tÓ,Ó-ˆBØ€IrV   c                 ót  • SSK Jn  [        XU5      n[        SU5       Vs/ s H  ovR	                  U" X'-   5      5      PM     nn[        [        US U" U[        U5      5       5       5      5      n	U	(       a»  [        S5      n
UR                  U	5      nUR                  5       R                  5       S   R                  U" X*-   5      5      nUR                  U5      S   S   n[        U5       HA  nUR	                  U" X'-   5      5      (       d  M#  U(       d  M,  UR                  X"U-
  5      n  U$    U$ s  snf )z@Converts DE with free parameters into RE of hypergeometric type.r   r`   r+   c              3   ó6   #   • U  H  o  H  o"v •  M     M     g 7frj   rk   rl   s      rT   ro   Ú#_transform_DE_RE.<locals>.<genexpr>š  s   é € ÐIÒ%= ÃqÀ!œ!Áq™!Ò%=ùrq   r…   )rr   ra   rŠ   r0   r<   ru   rv   rÉ   r   rA   rw   r7   ry   rx   )re   rf   rE   rF   rÜ   ra   r�   rH   rd   r{   r…   s              rT   Ú_transform_DE_RErä   “  s  € å/ä	�"˜Ó	€Bä&+¨A¨u¤oÓ	6¢o �(‰(‘1�Q‘U“8Ö
¡o€BÐ	6Ü
Œs�4ÑI¡X¨b´$°t³*Ô%=ÓIÓJÓ
K€CÞ
Ü�‹IˆØ�W‰W�S‹\ˆØ�Y‰Y‹[×'Ñ'Ó)¨!Ñ,×4Ñ4±Q°q±u³XÓ>ˆØ�_‰_˜QÓ Ñ" 1Ñ%ˆÜ�u–ˆAØ�x‰x™˜!™%›×!Ó!§a aØ—W‘W˜Q A¡Ó&�ØØ€Iñ	 ð €Iùò 
7s   ¡"D5c                 ó†  • SnUR                   R                  XA15      nU(       a  [        X$XSU5      nO[        X$U5      nUR                   R                  U15      (       d  [	        XX„U5      nU(       a  U$ U(       a  [        X$XU5      nUR                   R                  U15      (       d  [        XX$U5      nU(       a  U$ g)aá  
Solves the DE.

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

Tries to solve DE by either converting into a RE containing two terms or
converting into a DE having constant coefficients.

Returns
=======

formula : Expr
ind : Expr
    Independent terms.
order : int

Examples
========

>>> from sympy import Derivative as D, Function
>>> from sympy import exp, ln
>>> from sympy.series.formal import solve_de
>>> from sympy.abc import x, k
>>> f = Function('f')

>>> solve_de(exp(x), x, D(f(x), x) - f(x), 1, f, k)
(Piecewise((1/factorial(k), Eq(Mod(k, 1), 0)), (0, True)), 1, 1)

>>> solve_de(ln(1 + x), x, (x + 1)*D(f(x), x, 2) + D(f(x)), 2, f, k)
(Piecewise(((-1)**(k - 1)*factorial(k - 1)/RisingFactorial(2, k - 1),
 Eq(Mod(k, 1), 0)), (0, True)), x, 2)
N)rÓ   Ú
differencerä   rŠ   rÎ   rà   rÕ   )	rC   rD   re   rF   rf   rE   r{   rÜ   r�   s	            rT   Úsolve_derç   §  s­   € ðD €CØ�?‰?×%Ñ% q fÓ-€DæÜ˜b Q¨tÓ4‰ä�b˜QÓˆØ�?‰?×%Ñ% q c×*Ñ*Ü˜a B¨1Ó-ˆæ
Øˆ
æÜ" 2¨!°DÓ9ˆØ�?‰?×%Ñ% q c×*Ñ*Ü  b¨QÓ/ˆæ
Øˆ
ð rV   c           	      ó,  • [        S5      n/ nSn[        XXC5       HT  u  pxUb  [        XXxXB5      nU(       a  Us  $ UR                  R	                  U15      (       a  MC  UR                  U5        MV     U H  n[        XXtU5      nU(       d  M  Us  $    g)al  
Hypergeometric algorithm for computing Formal Power Series.

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

Steps:
    * Generates DE
    * Convert the DE into RE
    * Solves the RE

Examples
========

>>> from sympy import exp, ln
>>> from sympy.series.formal import hyper_algorithm

>>> from sympy.abc import x, k

>>> hyper_algorithm(exp(x), x, k)
(Piecewise((1/factorial(k), Eq(Mod(k, 1), 0)), (0, True)), 1, 1)

>>> hyper_algorithm(ln(1 + x), x, k)
(Piecewise(((-1)**(k - 1)*factorial(k - 1)/RisingFactorial(2, k - 1),
 Eq(Mod(k, 1), 0)), (0, True)), x, 2)

See Also
========

sympy.series.formal.simpleDE
sympy.series.formal.solve_de
rf   N)r
   r|   rç   rÓ   ræ   rB   r×   )	rC   rD   rE   rF   rf   Údesr{   re   rH   s	            rT   Úhyper_algorithmrê   ß  sŒ   € ôB 	�‹€Aà
€CØ
€CÜ˜! Ö)‰ˆØ‰>Ü˜1 ¨Ó-ˆCÞØŠJØ�‰×)Ñ)¨1¨#×.Ó.Ø�J‰J�rŽNñ *ó ˆÜ˜A "¨Ó+ˆßˆ3ØŠJò rV   c                 ó  • U[         R                  [         R                  4;   a�  U[         R                  L a  [         R                  O[         R                  * nU R	                  USU-  5      n[        X�SX4XVU5      n	U	c  gU	S   U	S   R	                  USU-  5      U	S   R	                  USU-  5      4$ U(       d  U[         R                  * :X  aŽ  U[         R                  * :X  a  U* U-   n
U* nUnO	X-   n
UnU* nU R	                  X5      n[        X�S[         R                  XEXg5      n	U	c  gU	S   U	S   R	                  XU-   5      U	S   R	                  XU-   5      4$ U R                  U5      (       aS  [        S5      n[        [        XU5      US[        45      n[        X-  US[        45      nU R                  US5      nXïU4$ [        U [        5      (       Ga:  Sn	[        [         R                  S[        45      n[         R                  Snn[        R                  " U 5       Hà  n[        UUS[         R                  XEXg5      nU(       a³  U	(       d  Sn	US   nUS   R                   UR                   :”  a  UnUR                   US   R                   n nO US   nUS   R                   UR                   n n[        [#        USU U-
   UUU  5       Vs/ s H  nUS   US   -  PM     sn6 nUUS   -  nUUS   U-   -  nMÛ  UU-  nMâ     U	(       a  XïU4$ gU R$                  R'                  U15      n[)        U 5      R*                  " U6 u  n nSn	[        S5      nU(       a  [-        XXÕU5      n	U	c  U(       a  [/        XXÕ5      n	U	c  gSSKJn  UR4                  (       a  [         R                  nOU" U5      n[        U	S   XÙS   [        45      nU" X-  U-  5      n[        UUS[        45      nU" U	S   U-  5      nXïU4$ s  snf )	zHRecursive wrapper to compute fps.

See :func:`compute_fps` for details.
r+   r   NrÈ   rE   FT)Úpowsimp)r   ÚInfinityÚNegativeInfinityÚOnerA   Ú_compute_fpsÚis_polynomialr   r#   ÚCoeffr   r<   r8   r   r3   r6   Ústartrv   rÓ   ræ   r   r9   rU   rê   Úsympy.simplify.powsimprì   r>   )rC   rD   Úx0ÚdirÚhyperrF   Úrationalr,   rÞ   rÂ   ÚrepÚrep2Úrep2brE   rS   ÚxkrN   rK   r˜   Úseqrn   ÚzÚsaverÜ   Úsymbrì   Ú
xk_formulas                              rT   rð   rð     sÄ  € ð
 
Œa�j‰jœ!×,Ñ,Ð-Ó-ØœQŸZ™ZÒ'Œa�eŠe¬a¯e©e¨VˆØ�v‰v�a˜˜1™‹~ˆÜ˜d q¨#°eÀtÓLˆØ‰>ØØ�q‘	˜6 !™9Ÿ>™>¨!¨Q¨q©SÓ1°6¸!±9·>±>À!ÀQÀqÁSÓ3IÐJÐJÞ	ˆs”q—u‘u�f‹}Ø”1—5‘5�&‹=Ø�"�r‘'ˆCØ�2ˆDØ‰Eà‘&ˆCØˆDØ�CˆEØ�v‰v�a‹~ˆÜ˜d q¬!¯%©%°¸xÓNˆØ‰>ØØ�q‘	˜6 !™9Ÿ>™>¨!°E©\Ó:Ø�q‘	—‘˜q¨¡,Ó/ð1ð 	1ð 	‡��q×ÑÜ�#‹JˆÜ”e˜A !“n q¨!¬R jÓ1ˆÜ�a‘d˜Q ¤2˜JÓ'ˆØ�g‰g�a˜‹mˆØ�sˆ{Ðô �!”S×ÒØˆÜ”a—f‘f˜q¤"˜gÓ&ˆÜ—&‘&˜$ˆRˆÜ—’˜qÖ!ˆAÜ˜q ! Q¬¯©¨u¸XÓLˆCÞÞØ!�FØ˜Q™�BØ�q‘6—<‘< "§(¡(Ó*Ø�CØŸ8™8 S¨¡V§\¡\�q�A�qà˜a™&�CØ˜q™6Ÿ<™<¨¯©�q�AÜ´°C¸¸1¸q¹5°NÀBÀqÈÀGÔ0LÓMÒ0L¨1˜Q˜q™T ! A¡$œYÑ0LÑMÐN�Ø�c˜!‘f‘�Ø�s˜1‘v ‘}Ñ$’à�q‘’ñ! "ö" Ø˜3�;ÐØð �>‰>×$Ñ$ a SÓ)€DÜ�q“	×(Ò(¨$Ð/�I€Qˆà€Fô 	ˆc‹
€AÞÜ# A¨!°DÓ9ˆà�~ž%Ü   qÓ0ˆà�~Øå.Ø‡|‡|Ü�u‰u‰á�t‹}ˆÜ	�&˜‘)˜a¨¡¬BÐ/Ó	0€BÙ˜™ ™Ó%€JÜ	�*˜q !¤R˜jÓ	)€BÙ
�&˜‘)˜dÑ"Ó
#€Cà�3ˆ;ÐùòK Ns   ËP
c           
      ób  • [        U 5      n [        U5      nU R                  U5      (       d  g[        U5      nUS:X  a  [        R                  nOSUS:X  a  [        R                  * nO;U[        R                  [        R                  * 4;  a  [	        S5      e[        U5      n[        XX#XEXg5      $ )a5  
Computes the formula for Formal Power Series of a function.

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

Tries to compute the formula by applying the following techniques
(in order):

* rational_algorithm
* Hypergeometric algorithm

Parameters
==========

x : Symbol
x0 : number, optional
    Point to perform series expansion about. Default is 0.
dir : {1, -1, '+', '-'}, optional
    If dir is 1 or '+' the series is calculated from the right and
    for -1 or '-' the series is calculated from the left. For smooth
    functions this flag will not alter the results. Default is 1.
hyper : {True, False}, optional
    Set hyper to False to skip the hypergeometric algorithm.
    By default it is set to False.
order : int, optional
    Order of the derivative of ``f``, Default is 4.
rational : {True, False}, optional
    Set rational to False to skip rational algorithm. By default it is set
    to True.
full : {True, False}, optional
    Set full to True to increase the range of rational algorithm.
    See :func:`rational_algorithm` for details. By default it is set to
    False.

Returns
=======

ak : sequence
    Sequence of coefficients.
xk : sequence
    Sequence of powers of x.
ind : Expr
    Independent terms.
mul : Pow
    Common terms.

See Also
========

sympy.series.formal.rational_algorithm
sympy.series.formal.hyper_algorithm
NÚ+Ú-zDir must be '+' or '-')r   r4   r   rï   Ú
ValueErrorrð   )rC   rD   rõ   rö   r÷   rF   rø   r,   s           rT   Úcompute_fpsr  s  sŽ   € ôn 	�‹
€AÜ�‹
€Aà�5‰5��8‰8Øä	�‹€Bà
ˆcƒzÜ�e‰e‰Ø	�‹Ü�u‰uˆf‰Ø	”Q—U‘UœQŸU™U˜F�OÓ	#ÜÐ1Ó2Ð2ä�c‹lˆä˜˜b u°XÓDÐDrV   c                   ó(   • \ rS rSrSr\S 5       rSrg)rò   i¾  zH
Coeff(p, x, n) represents the nth coefficient of the polynomial p in x
c                 óv   • UR                  U5      (       a#  UR                  (       a  UR                  X#5      $ g g rj   )rñ   rÀ   r<   )Úclsr¨   rD   rZ   s       rT   ÚevalÚ
Coeff.evalÂ  s-   € à�?‰?˜1×Ñ !§,§,Ø—7‘7˜1“=Ð ð #/ÐrV   rk   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úclassmethodr
  Ú__static_attributes__rk   rV   rT   rò   rò   ¾  s   † ñð ñ!ó ó!rV   rò   c                   ót  • \ rS rSrSrS rS r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS'S jrS'S jrS rS rS rS rS rS(S jrS)S jrS rS)S jrS)S jr S r!S  r"S! r#S" r$S# r%S$ r&S% r'S&r(g)*ÚFormalPowerSeriesiÈ  a  
Represents Formal Power Series of a function.

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

No computation is performed. This class should only to be used to represent
a series. No checks are performed.

For computing a series use :func:`fps`.

See Also
========

sympy.series.formal.fps
c                 óP   • [        [        U5      n[        R                  " U /UQ76 $ rj   )rÊ   r   r   Ú__new__)r	  rË   s     rT   r  ÚFormalPowerSeries.__new__Ù  s"   € Ü”7˜DÓ!ˆÜ�|Š|˜CÐ' $Ò'Ð'rV   c                 ó$  • US   S   nUR                   S   n[        UR                  US[        45      U l        [        [        U5      US[        45      U l        U R                  U R                  -  U l        [        SUS[        45      U l        g )Né   r   r+   )r-   r+   )	Ú	variablesr#   Úformular   Úak_seqr   Úfact_seqÚbell_coeff_seqÚsign_seq)ÚselfrË   rS   rE   s       rT   Ú__init__ÚFormalPowerSeries.__init__Ý  su   € Ø�!‰W�Q‰ZˆØ�L‰L˜‰OˆÜ˜rŸz™z¨A¨q´"¨:Ó6ˆŒÜ ¤¨1£°°1´b¨zÓ:ˆŒØ"Ÿk™k¨D¯M©MÑ9ˆÔÜ  ¨1¨a´¨*Ó5ˆ�rV   c                 ó    • U R                   S   $ rc   ©rË   ©r   s    rT   ÚfunctionÚFormalPowerSeries.functionå  ó   € à�y‰y˜‰|ÐrV   c                 ó    • U R                   S   $ r•   r$  r%  s    rT   rD   ÚFormalPowerSeries.xé  r(  rV   c                 ó    • U R                   S   $ )NrÈ   r$  r%  s    rT   rõ   ÚFormalPowerSeries.x0í  r(  rV   c                 ó    • U R                   S   $ )Né   r$  r%  s    rT   rö   ÚFormalPowerSeries.dirñ  r(  rV   c                 ó&   • U R                   S   S   $ )Nr  r   r$  r%  s    rT   rS   ÚFormalPowerSeries.akõ  ó   € à�y‰y˜‰|˜A‰ÐrV   c                 ó&   • U R                   S   S   $ )Nr  r+   r$  r%  s    rT   rü   ÚFormalPowerSeries.xkù  r2  rV   c                 ó&   • U R                   S   S   $ )Nr  rÈ   r$  r%  s    rT   rN   ÚFormalPowerSeries.indý  r2  rV   c                 ó"   • [        S[        5      $ rc   )r   r   r%  s    rT   ÚintervalÚFormalPowerSeries.interval  s   € ä˜œ2‹ÐrV   c                 ó.   • U R                   R                  $ rj   )r8  Úinfr%  s    rT   ró   ÚFormalPowerSeries.start  ó   € à�}‰}× Ñ Ð rV   c                 ó.   • U R                   R                  $ rj   )r8  Úsupr%  s    rT   ÚstopÚFormalPowerSeries.stop	  r=  rV   c                 ó   • [         $ rj   )r   r%  s    rT   ÚlengthÚFormalPowerSeries.length  s   € äˆ	rV   c                 óä   • SSK Jn  U R                  U R                  p2UR                  S   nU" UR
                  UR
                  -  XBR                  UR                  45      nU R                  U-   $ )z0Returns an infinite representation of the seriesr   )ÚSum)	Úsympy.concreterF  rS   rü   r  r  ró   r@  rN   )r   rF  rS   rü   rE   Úinf_sums         rT   ÚinfiniteÚFormalPowerSeries.infinite  sX   € õ 	'Ø—‘˜$Ÿ'™'ˆBØ�L‰L˜‰OˆÙ�b—j‘j 2§:¡:Ñ-°·8±8¸R¿W¹WÐ/EÓFˆà�x‰x˜'Ñ!Ð!rV   c                 óÂ   • UR                  U R                  5      S   R                  5       u  p#UR                  U R                  5      (       d  [        R
                  $ U$ )z!Returns the power of x in a term.r+   )r9   rD   r:   r4   r   r3   )r   r[   rQ   rº   s       rT   Ú
_get_pow_xÚFormalPowerSeries._get_pow_x  sG   € à×*Ñ*¨4¯6©6Ó2°1Ñ5×AÑAÓC‰ˆØ�y‰y˜Ÿ™× Ñ Ü—6‘6ˆMØˆrV   c                 óP  • / nU R                   n[        U 5       H‚  u  pEU R                  U5      nUR                  " U6 (       a  UR                  " U6 S   nXa:¼  a    OCUR
                  SL a
  XAS-   :X  a    O*U[        R                  Ld  Mq  UR                  U5        M„     [        U6 $ )z™
Truncated series as polynomial.

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

Returns series expansion of ``f`` upto order ``O(x**n)``
as a polynomial(without ``O`` term).
r   Tr+   )
rÓ   rX   rL  r4   r;   rÀ   r   r3   rB   r   )r   rZ   rJ   ÚsymrH   rK   Úxps          rT   Ú
polynomialÚFormalPowerSeries.polynomial"  s‘   € ð ˆØ×ÑˆÜ˜d–O‰DˆAØ—‘ Ó#ˆBØ�vŠv�sŽ|Ø—_’_ cÐ*¨1Ñ-�Ø‹wÙØ—‘ $Ò&¨1°A±«:ÙØœ!Ÿ&™&”Ø—‘˜Q–ñ $ô �Eˆ{ÐrV   c                 ó  • Uc  [        U 5      $ U R                  U R                  p2U R                  R	                  U5      nU[
        R                  L a  [
        R                  nU R                  U5      [        XBU45      -   $ )zž
Truncated series.

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

Returns truncated series expansion of f upto
order ``O(x**n)``.

If n is ``None``, returns an infinite iterator.
)
ÚiterrD   rõ   rü   r<   r   rî   rí   rQ  r"   )r   rZ   rD   rõ   Úpt_xks        rT   ÚtruncateÚFormalPowerSeries.truncate;  sh   € ð ‰9Ü˜“:Ðà—‘˜Ÿ™ˆ2Ø—‘—‘˜aÓ ˆØ”×#Ñ#Ò#Ü—‘ˆBà�‰˜qÓ!¤E¨%°R°Ó$9Ñ9Ð9rV   c                 ó$   • U R                  S5      $ rc   )Ú
_eval_termr%  s    rT   Ú
zero_coeffÚFormalPowerSeries.zero_coeffQ  s   € Ø�‰˜qÓ!Ð!rV   c                 óv  •  U R                   R                  U5      nU R                  R                  U5      R                  5       nX2-  nU R                  (       a¥  [
        R                  nU R                  n[        R                  " U R                  5       Ha  nU R                  U5      nUR                  " U6 (       a  UR                  " U6 S   nUS:X  a  US:  a  XW-  nML  X�:¼  d  MS  X�S-   :  d  M]  XW-  nMc     XE-  nUR                  U R                  5      $ ! [         a    [
        R                  n Níf = f©Nr   r+   )rü   r<   rS   ÚsimplifyÚ
IndexErrorr   r3   rN   rÓ   r   r6   rL  r4   r;   ry   rD   )	r   ÚptrU  Úpt_akr[   rN   rO  rK   rº   s	            rT   rY  ÚFormalPowerSeries._eval_termT  sû   € ð	#Ø—G‘G—M‘M "Ó%ˆEØ—G‘G—M‘M "Ó%×.Ñ.Ó0ˆEð ‘MˆDà�8�8Ü—&‘&ˆCØ×#Ñ#ˆCÜ—]’] 4§8¡8Ö,�ØŸ™¨Ó*�Ø—9’9˜c–?Ø!×.Ò.°Ð4°QÑ7�EØ˜“7˜u q›yØ‘H’CØ•[ U°!©V¥^Ø‘H’Cñ -ð ‰KˆDà�|‰|˜DŸF™FÓ#Ð#øô% ó 	Ü—6‘6ŠDð	ús   ‚AD ÄD8Ä7D8c                 óL   • U R                   nUR                  U5      (       a  U $ g rj   )rD   r4   )r   ÚoldÚnewrD   s       rT   Ú
_eval_subsÚFormalPowerSeries._eval_subsl  s"   € Ø�F‰FˆØ�7‰7�1�:‰:ØˆKð rV   c                 óD   • U  H  nU[         R                  Ld  M  Us  $    g rj   r½   )r   rD   ÚlogxÚcdirrK   s        rT   Ú_eval_as_leading_termÚ'FormalPowerSeries._eval_as_leading_termq  s   € ÛˆAØœŸ™ŒØ’ò rV   c           	      ó¦  • U R                   R                  U5      nU R                  R                  U5      nU R                  U R                  R
                  5      nU R                  nUR                  S   nUR
                  R                  U5      (       aº  / nUR
                  R                   H^  u  p‰[        R                  n
[        R                  " U5       H  nU R                  U5      nX«XL-   -  -  n
M     UR                  X©45        M`     [        U6 n[!        UR#                  XfS-   5      XeR$                  S-
  UR&                  45      nOD[!        UR
                  U-  R#                  XfS-   5      XeR$                  S-
  UR&                  45      nU R)                  X R*                  U R,                  U R.                  XPR                  U45      $ r]  )r&  r1   rN   rL  rü   r  rS   r  r4   rË   r   r3   r   r6   rB   r    r#   rA   ró   r@  ÚfuncrD   rõ   rö   )r   rD   rC   rN   Úpow_xkrS   rE   Úformrß   r‡   rÞ   rK   rº   s                rT   Ú_eval_derivativeÚ"FormalPowerSeries._eval_derivativev  sc  € Ø�M‰M×Ñ˜qÓ!ˆØ�h‰h�m‰m˜AÓˆà—‘ §¡§¡Ó1ˆØ�W‰WˆØ�L‰L˜‰OˆØ�:‰:�>‰>˜!×ÑØˆDØŸ
™
Ÿœ‘�Ü—v‘v�ÜŸš qÖ)�AØ ŸO™O¨AÓ.�EØ ¡Ñ0Ñ0’Dñ *ð —‘˜T˜IÖ&ñ (ô ˜dÐ#ˆDÜ˜$Ÿ)™) A¨1¡uÓ-°·8±8¸a±<ÀÇÁÐ/IÓJ‰Bä˜2Ÿ:™:¨Ñ.×4Ñ4°Q¸A¹Ó>ØŸh™h¨™l¨B¯G©GÐ4ó6ˆBð �y‰y˜ŸF™F D§G¡G¨T¯X©X¸¿G¹GÀSÐ7IÓJÐJrV   Nc           	      ó2  • SSK Jn  Uc  U R                  nO#[        U5      (       a  U" U R                  U5      $ U" U R                  U5      nU" U R
                  U5      nXTU-
  R                  US5      -  nU R                  U R                  R                  5      nU R                  nUR                  S   nUR                  R                  U5      (       a½  / n	UR                  R                   Ha  u  p«[        R                  n[         R"                  " U
5       H   nU R                  U5      nXÍXn-   S-   -  -  nM"     U	R%                  XË45        Mc     ['        U	6 n	[)        U	R+                  XˆS-
  5      X‡R,                  S-   UR.                  45      nOG[)        UR                  US-   -  R+                  XˆS-
  5      X‡R,                  S-   UR.                  45      nU R1                  X@R                  U R2                  U R4                  XpR                  U45      $ )zó
Integrate Formal Power Series.

Examples
========

>>> from sympy import fps, sin, integrate
>>> from sympy.abc import x
>>> f = fps(sin(x))
>>> f.integrate(x).truncate()
-1 + x**2/2 - x**4/24 + O(x**6)
>>> integrate(f, (x, 0, 1))
1 - cos(1)
r   r)   r+   )r/   r*   rD   r%   r&  rN   r@   rL  rü   r  rS   r  r4   rË   r   r3   r   r6   rB   r    r#   rA   ró   r@  rn  rõ   rö   )r   rD   Úkwargsr*   rC   rN   ro  rS   rE   rp  rß   r‡   rÞ   rK   rº   s                  rT   r*   ÚFormalPowerSeries.integrate�  sª  € õ 	.à‰9Ø—‘‰AÜ�a�[‰[Ù˜TŸ]™]¨AÓ.Ð.á�d—m‘m QÓ'ˆÙ˜Ÿ™ !Ó$ˆØ�C‘�‰˜q !Ó$Ñ$ˆà—‘ §¡§¡Ó1ˆØ�W‰WˆØ�L‰L˜‰OˆØ�:‰:�>‰>˜!×ÑØˆDØŸ
™
Ÿœ‘�Ü—v‘v�ÜŸš qÖ)�AØ ŸO™O¨AÓ.�EØ ¡°!Ñ!3Ñ4Ñ4’Dñ *ð —‘˜T˜IÖ&ñ (ô ˜dÐ#ˆDÜ˜$Ÿ)™) A¨1¡uÓ-°·8±8¸a±<ÀÇÁÐ/IÓJ‰Bä˜2Ÿ:™:¨°!©Ñ4×:Ñ:¸1À!¹eÓDØŸh™h¨™l¨B¯G©GÐ4ó6ˆBð �y‰y˜ŸF™F D§G¡G¨T¯X©X¸¿G¹GÀSÐ7IÓJÐJrV   c                 óh  • Uc  [        U 5      $ [        U5      n[        U[        5      (       d  [	        S5      eU R
                  UR
                  :w  a  [	        S5      eU R                  UR                  :w  a  [	        S5      eU R                  UR                  :w  a  [	        S5      e[        X5      $ )a  
Multiplies two Formal Power Series, using discrete convolution and
return the truncated terms upto specified order.

Parameters
==========

n : Number, optional
    Specifies the order of the term up to which the polynomial should
    be truncated.

Examples
========

>>> from sympy import fps, sin, exp
>>> from sympy.abc import x
>>> f1 = fps(sin(x))
>>> f2 = fps(exp(x))

>>> f1.product(f2, x).truncate(4)
x + x**2 + x**3/3 + O(x**4)

See Also
========

sympy.discrete.convolutions
sympy.series.formal.FormalPowerSeriesProduct

ú=Both series should be an instance of FormalPowerSeries class.ú9Both series should be calculated from the same direction.ú6Both series should be calculated about the same point.ú(Both series should have the same symbol.)	rT  r   r8   r  r  rö   rõ   rD   ÚFormalPowerSeriesProduct©r   ÚotherrD   rZ   s       rT   ÚproductÚFormalPowerSeries.productº  s«   € ð> ‰9Ü˜“:Ðä˜“ˆä˜%Ô!2×3Ñ3Üð 'ó (ð (ð �8‰8�u—y‘yÓ Üð 0ó 1ð 1à�W‰W˜Ÿ™Ó Üð ,ó -ð -ð �V‰V�u—w‘wÓÜÐGÓHÐHä'¨Ó4Ð4rV   c                 óâ   • [        SUS-   5       Vs/ s H*  n[        X[        U R                  SX-
  S-    5      5      PM,     nn[	        S5      n[        [        U5      US[        45      $ s  snf )aí  
self.coeff_bell(n) returns a sequence of Bell polynomials of the second kind.
Note that ``n`` should be a integer.

The second kind of Bell polynomials (are sometimes called "partial" Bell
polynomials or incomplete Bell polynomials) are defined as

.. math::
    B_{n,k}(x_1, x_2,\dotsc x_{n-k+1}) =
        \sum_{j_1+j_2+j_2+\dotsb=k \atop j_1+2j_2+3j_2+\dotsb=n}
        \frac{n!}{j_1!j_2!\dotsb j_{n-k+1}!}
        \left(\frac{x_1}{1!} \right)^{j_1}
        \left(\frac{x_2}{2!} \right)^{j_2} \dotsb
        \left(\frac{x_{n-k+1}}{(n-k+1)!} \right) ^{j_{n-k+1}}.

* ``bell(n, k, (x1, x2, ...))`` gives Bell polynomials of the second kind,
  `B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})`.

See Also
========

sympy.functions.combinatorial.numbers.bell

r+   NrE   )r0   r   Útupler  r   r#   r   )r   rZ   rO   Úinner_coeffsrE   s        rT   Ú
coeff_bellÚFormalPowerSeries.coeff_bellî  sq   € ô4 QVÐVWÐYZÐ[\ÑY\ÔP]Ó^ÒP]È1œ˜Q¤5¨×)<Ñ)<¸V¸a¹cÀ!¹eÐ)DÓ#EÖFÑP]ˆÐ^ä�#‹JˆÜœ˜lÓ+¨a°´B¨ZÓ8Ð8ùò _s   ’1A,c                 óú  • Uc  [        U 5      $ [        U5      n[        U[        5      (       d  [	        S5      eU R
                  UR
                  :w  a  [	        S5      eU R                  UR                  :w  a  [	        S5      eU R                  UR                  :w  a  [	        S5      eUR                  S5      R                  UR                  5      S   [        R                  La  [	        S5      e[        X5      $ )a  
Returns the truncated terms of the formal power series of the composed function,
up to specified ``n``.

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

If ``f`` and ``g`` are two formal power series of two different functions,
then the coefficient sequence ``ak`` of the composed formal power series `fp`
will be as follows.

.. math::
    \sum\limits_{k=0}^{n} b_k B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})

Parameters
==========

n : Number, optional
    Specifies the order of the term up to which the polynomial should
    be truncated.

Examples
========

>>> from sympy import fps, sin, exp
>>> from sympy.abc import x
>>> f1 = fps(exp(x))
>>> f2 = fps(sin(x))

>>> f1.compose(f2, x).truncate()
1 + x + x**2/2 - x**4/8 - x**5/15 + O(x**6)

>>> f1.compose(f2, x).truncate(8)
1 + x + x**2/2 - x**4/8 - x**5/15 - x**6/240 + x**7/90 + O(x**8)

See Also
========

sympy.functions.combinatorial.numbers.bell
sympy.series.formal.FormalPowerSeriesCompose

References
==========

.. [1] Comtet, Louis: Advanced combinatorics; the art of finite and infinite expansions. Reidel, 1974.

rw  rx  ry  rz  r   z\The formal power series of the inner function should not have any constant coefficient term.)rT  r   r8   r  r  rö   rõ   rD   rY  rx   r   r3   ÚFormalPowerSeriesComposer|  s       rT   ÚcomposeÚFormalPowerSeries.compose  së   € ðb ‰9Ü˜“:Ðä˜“ˆä˜%Ô!2×3Ñ3Üð 'ó (ð (ð �8‰8�u—y‘yÓ Üð 0ó 1ð 1à�W‰W˜Ÿ™Ó Üð ,ó -ð -ð �V‰V�u—w‘wÓÜÐGÓHÐHà×Ñ˜AÓ×+Ñ+¨E¯G©GÓ4°QÑ7¼q¿v¹vÒEÜð -ó .ð .ô (¨Ó4Ð4rV   c                 óŠ   • Uc  [        U 5      $ U R                  S5      R                  (       a  [        S5      e[	        U 5      $ )a  
Returns the truncated terms of the inverse of the formal power series,
up to specified ``n``.

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

If ``f`` and ``g`` are two formal power series of two different functions,
then the coefficient sequence ``ak`` of the composed formal power series ``fp``
will be as follows.

.. math::
    \sum\limits_{k=0}^{n} (-1)^{k} x_0^{-k-1} B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})

Parameters
==========

n : Number, optional
    Specifies the order of the term up to which the polynomial should
    be truncated.

Examples
========

>>> from sympy import fps, exp, cos
>>> from sympy.abc import x
>>> f1 = fps(exp(x))
>>> f2 = fps(cos(x))

>>> f1.inverse(x).truncate()
1 - x + x**2/2 - x**3/6 + x**4/24 - x**5/120 + O(x**6)

>>> f2.inverse(x).truncate(8)
1 + x**2/2 + 5*x**4/24 + 61*x**6/720 + O(x**8)

See Also
========

sympy.functions.combinatorial.numbers.bell
sympy.series.formal.FormalPowerSeriesInverse

References
==========

.. [1] Comtet, Louis: Advanced combinatorics; the art of finite and infinite expansions. Reidel, 1974.

r   zSConstant coefficient should exist for an inverse of a formal power series to exist.)rT  rY  r>   r  ÚFormalPowerSeriesInverse)r   rD   rZ   s      rT   ÚinverseÚFormalPowerSeries.inverseW  sE   € ðb ‰9Ü˜“:Ðà�?‰?˜1Ó×%×%Üð *ó +ð +ô (¨Ó-Ð-rV   c           	      ó@  • [        U5      n[        U[        5      (       Gaç  U R                  UR                  :w  a  [	        S5      eU R
                  UR
                  :w  a  [	        S5      eU R                  UR                  p2U R                  UR                  R                  X25      -   nU R                  UR                  ;  a  U$ U R                  UR                  -   nU R                  R                  UR                  R                  :”  a8  UR                  nUR                  R                  U R                  R                  p‡O7U R                  nU R                  R                  UR                  R                  p‡[        [        USX‡-
   U R                  Xx 5       V	s/ s H  o™S   U	S   -  PM     sn	6 n
U R                  UR                  -   U
-   nU R!                  XBU R
                  U R                  XPR                  U45      $ UR#                  U R                  5      (       dg  U R                  U-   nU R                  U-   nU R!                  X@R                  U R
                  U R                  U R                  U R                  U45      $ [        X5      $ s  sn	f )Nrx  ry  r   r+   )r   r8   r  rö   r  rõ   rD   r&  rA   rÓ   rS   ró   r   rv   rü   rN   rn  r4   )r   r}  rD   ÚyrC   rS   rý   rn   rß   rþ   rÿ   rN   s               rT   Ú__add__ÚFormalPowerSeries.__add__‘  sú  € Ü˜“ˆä�eÔ.×/Ò/Ø�x‰x˜5Ÿ9™9Ó$Ü ð "4ó 5ð 5à—‘˜EŸH™HÓ$Ü ð "0ó 1ð 1ð —6‘6˜5Ÿ7™7ˆqØ—‘ §¡× 3Ñ 3°AÓ 9Ñ9ˆAà�v‰v˜QŸ^™^Ó+Ø�à—‘˜5Ÿ8™8Ñ#ˆBØ�w‰w�}‰}˜uŸx™xŸ~™~Ó-Ø—h‘h�Ø—x‘x—~‘~ t§w¡w§}¡}‘1à—g‘g�Ø—w‘w—}‘} e§h¡h§n¡n�1Ü¬C°°A°q±u°ÀÇÁÈÀÔ,MÓNÒ,M q˜1™˜a ™dœÑ,MÑNÐOˆDØ—(‘(˜UŸY™YÑ&¨Ñ-ˆCà—9‘9˜Q 4§7¡7¨D¯H©H°r¿7¹7ÀCÐ6HÓIÐIà—‘˜4Ÿ6™6×"Ñ"Ø—‘ Ñ%ˆAØ—(‘(˜UÑ"ˆCà—9‘9˜Q§¡¨¯©°·±Ø"Ÿg™g t§w¡w°Ð4ó6ð 6ô �4ÓÐùò Os   Æ!Jc                 ó$   • U R                  U5      $ rj   ©r�  ©r   r}  s     rT   Ú__radd__ÚFormalPowerSeries.__radd__·  ó   € Ø�|‰|˜EÓ"Ð"rV   c           	      óÄ   • U R                  U R                  * U R                  U R                  U R                  U R
                  * U R                  U R                  * 45      $ rj   )rn  r&  rD   rõ   rö   rS   rü   rN   r%  s    rT   Ú__neg__ÚFormalPowerSeries.__neg__º  sG   € Ø�y‰y˜$Ÿ-™-˜¨¯©°·±¸$¿(¹(ØŸ7™7˜( D§G¡G¨d¯h©h¨YÐ7ó9ð 	9rV   c                 ó&   • U R                  U* 5      $ rj   r’  r“  s     rT   Ú__sub__ÚFormalPowerSeries.__sub__¾  s   € Ø�|‰|˜U˜FÓ#Ð#rV   c                 ó&   • U * R                  U5      $ rj   r’  r“  s     rT   Ú__rsub__ÚFormalPowerSeries.__rsub__Á  s   € Ø��‰˜uÓ%Ð%rV   c           	      ó\  • [        U5      nUR                  U R                  5      (       a  [        X5      $ U R                  U-  nU R
                  R                  U5      nU R                  U-  nU R                  X R                  U R                  U R                  X0R                  U45      $ rj   )r   r4   rD   r   r&  rS   Ú	coeff_mulrN   rn  rõ   rö   rü   )r   r}  rC   rS   rN   s        rT   Ú__mul__ÚFormalPowerSeries.__mul__Ä  sƒ   € Ü˜“ˆà�9‰9�T—V‘V×ÑÜ�tÓ#Ð#à�M‰M˜EÑ!ˆØ�W‰W×Ñ˜uÓ%ˆØ�h‰h˜Ñˆà�y‰y˜ŸF™F D§G¡G¨T¯X©X¸¿G¹GÀSÐ7IÓJÐJrV   c                 ó$   • U R                  U5      $ rj   )r¢  r“  s     rT   Ú__rmul__ÚFormalPowerSeries.__rmul__Ð  r–  rV   )r  r  r  r  ©é   rj   )Nr¨  ))r  r  r  r  r  r  r!  Úpropertyr&  rD   rõ   rö   rS   rü   rN   r8  ró   r@  rC  rI  rL  rQ  rV  rZ  rY  rf  rk  rq  r*   r~  rƒ  r‡  r‹  r�  r”  r˜  r›  rž  r¢  r¥  r  rk   rV   rT   r  r  È  sn  † ñò (ò6ð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð ñ!ó ð!ð ñ!ó ð!ð ñó ðð ñ"ó ð"òôô2:ò,"ò$ò0ò
ò
Kô.+KôZ25òh9ô>H5ôT8.òt$ òL#ò9ò$ò&ò
Kõ#rV   r  c                   ó–   • \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rS	 rS
 rS rSS jrS rS rSrg)ÚFiniteFormalPowerSeriesiÔ  z3Base Class for Product, Compose and Inverse classesc                 ó   • g rj   rk   )r   rË   s     rT   r!  Ú FiniteFormalPowerSeries.__init__×  s   € ØrV   c                 ó    • U R                   S   $ rc   r$  r%  s    rT   ÚffpsÚFiniteFormalPowerSeries.ffpsÚ  r(  rV   c                 ó    • U R                   S   $ r•   r$  r%  s    rT   ÚgfpsÚFiniteFormalPowerSeries.gfpsÞ  r(  rV   c                 ó.   • U R                   R                  $ rj   )r¯  r&  r%  s    rT   rC   ÚFiniteFormalPowerSeries.fâ  ó   € à�y‰y×!Ñ!Ð!rV   c                 ó.   • U R                   R                  $ rj   )r²  r&  r%  s    rT   rf   ÚFiniteFormalPowerSeries.gæ  r¶  rV   c                 ó   • [        S5      e)NzCNo infinite version for an object of FiniteFormalPowerSeries class.©ÚNotImplementedErrorr%  s    rT   rI  Ú FiniteFormalPowerSeries.infiniteê  s   € ä!ð #7ó 8ð 	8rV   c                 ó   • [        SU -  5      e)Nz(%s)._eval_terms()rº  ©r   rZ   s     rT   Ú_eval_termsÚ#FiniteFormalPowerSeries._eval_termsï  s   € Ü!Ð"6¸Ñ"=Ó>Ð>rV   c                 ó   • [        S5      e)Nz]By the current logic, one can get termsupto a certain order, instead of getting term by term.rº  )r   r`  s     rT   rY  Ú"FiniteFormalPowerSeries._eval_termò  s   € Ü!ð #\ó ]ð 	]rV   c                 ó$   • U R                  U5      $ rj   )r¿  r¾  s     rT   rQ  Ú"FiniteFormalPowerSeries.polynomialö  s   € Ø×Ñ Ó"Ð"rV   c                 ó¼   • U R                   nUR                  R                  U5      nUR                  UR                  pTU R                  U5      [        X4U45      -   $ rj   )r¯  rü   r<   rD   rõ   rQ  r"   )r   rZ   r¯  rU  rD   rõ   s         rT   rV  Ú FiniteFormalPowerSeries.truncateù  sI   € Ø�y‰yˆØ—‘—‘˜aÓ ˆØ—‘˜Ÿ™ˆ2à�‰˜qÓ!¤E¨%°R°Ó$9Ñ9Ð9rV   c                 ó   • [         erj   rº  ©r   rD   s     rT   rq  Ú(FiniteFormalPowerSeries._eval_derivative   ó   € Ü!Ð!rV   c                 ó   • [         erj   rº  rÈ  s     rT   r*   Ú!FiniteFormalPowerSeries.integrate  rÊ  rV   rk   Nr§  )r  r  r  r  r  r!  r©  r¯  r²  rC   rf   rI  r¿  rY  rQ  rV  rq  r*   r  rk   rV   rT   r«  r«  Ô  s�   † Ù=òð ñó ðð ñó ðð ñ"ó ð"ð ñ"ó ð"ð ñ8ó ð8ò?ò]ò#ô:ò"õ"rV   r«  c                   ó4   • \ rS rSrSrS r\S 5       rS rSr	g)r{  i  al  Represents the product of two formal power series of two functions.

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

No computation is performed. Terms are calculated using a term by term logic,
instead of a point by point logic.

There are two differences between a :obj:`FormalPowerSeries` object and a
:obj:`FormalPowerSeriesProduct` object. The first argument contains the two
functions involved in the product. Also, the coefficient sequence contains
both the coefficient sequence of the formal power series of the involved functions.

See Also
========

sympy.series.formal.FormalPowerSeries
sympy.series.formal.FiniteFormalPowerSeries

c                 óF  • U R                   U R                  p2UR                  R                  S   n[	        UR                  R
                  US[        45      U l        UR                  R                  S   n[	        UR                  R
                  US[        45      U l        g rc   )	r¯  r²  rS   r  r#   r  r   Úcoeff1Úcoeff2)r   rË   r¯  r²  rE   s        rT   r!  Ú!FormalPowerSeriesProduct.__init__  sq   € Ø—Y‘Y §	¡	ˆdà�G‰G×Ñ˜aÑ ˆÜ˜tŸw™wŸ™°°A´r°
Ó;ˆŒà�G‰G×Ñ˜aÑ ˆÜ˜tŸw™wŸ™°°A´r°
Ó;ˆ�rV   c                 ó4   • U R                   U R                  -  $ )z3Function of the product of two formal power series.)rC   rf   r%  s    rT   r&  Ú!FormalPowerSeriesProduct.function&  s   € ð �v‰v˜Ÿ™‰ÐrV   c                 ó   • U R                   U R                  p2[        USU USU 5      n/ n[        SU5       H<  nUR	                  XF   U R
                  R                  R                  U5      -  5        M>     [        U6 $ )av  
Returns the first ``n`` terms of the product formal power series.
Term by term logic is implemented here.

Examples
========

>>> from sympy import fps, sin, exp
>>> from sympy.abc import x
>>> f1 = fps(sin(x))
>>> f2 = fps(exp(x))
>>> fprod = f1.product(f2, x)

>>> fprod._eval_terms(4)
x**3/3 + x**2 + x

See Also
========

sympy.series.formal.FormalPowerSeries.product

Nr   )	rÏ  rÐ  r   r0   rB   r¯  rü   r<   r   )r   rZ   rÏ  rÐ  ÚaksrJ   rH   s          rT   r¿  Ú$FormalPowerSeriesProduct._eval_terms+  sr   € ð. Ÿ™ d§k¡k�ä˜&  !˜* f¨R¨a jÓ1ˆàˆÜ�q˜!–ˆAØ�L‰L˜™ $§)¡)§,¡,×"4Ñ"4°QÓ"7Ñ7Ö8ñ ô �Eˆ{ÐrV   )rÏ  rÐ  N)
r  r  r  r  r  r!  r©  r&  r¿  r  rk   rV   rT   r{  r{    s%   † ñò*<ð ñó ðõrV   r{  c                   ó.   • \ rS rSrSr\S 5       rS rSrg)r†  iM  aÆ  
Represents the composed formal power series of two functions.

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

No computation is performed. Terms are calculated using a term by term logic,
instead of a point by point logic.

There are two differences between a :obj:`FormalPowerSeries` object and a
:obj:`FormalPowerSeriesCompose` object. The first argument contains the outer
function and the inner function involved in the omposition. Also, the
coefficient sequence contains the generic sequence which is to be multiplied
by a custom ``bell_seq`` finite sequence. The finite terms will then be added up to
get the final terms.

See Also
========

sympy.series.formal.FormalPowerSeries
sympy.series.formal.FiniteFormalPowerSeries

c                 ó~   • U R                   U R                  U R                  R                  p2nUR	                  X25      $ )z.Function for the composed formal power series.)rC   rf   r¯  rD   rA   )r   rC   rf   rD   s       rT   r&  Ú!FormalPowerSeriesCompose.functionf  s-   € ð —&‘&˜$Ÿ&™& $§)¡)§+¡+ˆaˆØ�v‰v�a‹|ÐrV   c                 óZ  • U R                   U R                  p2UR                  5       /n[        SU5       Hl  nUR	                  U5      nUR
                  U-  nUR                  [        USU 6 UR                  US-
     -  UR                  R                  U5      -  5        Mn     [        U6 $ )aú  
Returns the first `n` terms of the composed formal power series.
Term by term logic is implemented here.

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

The coefficient sequence of the :obj:`FormalPowerSeriesCompose` object is the generic sequence.
It is multiplied by ``bell_seq`` to get a sequence, whose terms are added up to get
the final terms for the polynomial.

Examples
========

>>> from sympy import fps, sin, exp
>>> from sympy.abc import x
>>> f1 = fps(exp(x))
>>> f2 = fps(sin(x))
>>> fcomp = f1.compose(f2, x)

>>> fcomp._eval_terms(6)
-x**5/15 - x**4/8 + x**2/2 + x + 1

>>> fcomp._eval_terms(8)
x**7/90 - x**6/240 - x**5/15 - x**4/8 + x**2/2 + x + 1

See Also
========

sympy.series.formal.FormalPowerSeries.compose
sympy.series.formal.FormalPowerSeries.coeff_bell

r+   N)r¯  r²  rZ  r0   rƒ  r  rB   r   r  rü   r<   )r   rZ   r¯  r²  rJ   rH   Úbell_seqrý   s           rT   r¿  Ú$FormalPowerSeriesCompose._eval_termsl  s—   € ðF —Y‘Y §	¡	ˆdØ—‘Ó"Ð#ˆä�q˜!–ˆAØ—‘ qÓ)ˆHØ×&Ñ&¨Ñ1ˆCØ�L‰Lœ˜s 2 A˜w˜¨4¯=©=¸¸1¹Ñ+=Ñ=ÀÇÁÇÁÈaÓ@PÑPÖQñ ô
 �Eˆ{ÐrV   rk   N)	r  r  r  r  r  r©  r&  r¿  r  rk   rV   rT   r†  r†  M  s    † ñð0 ñó ðõ
+rV   r†  c                   óT   • \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	S r
Srg	)
rŠ  iš  aT  
Represents the Inverse of a formal power series.

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

No computation is performed. Terms are calculated using a term by term logic,
instead of a point by point logic.

There is a single difference between a :obj:`FormalPowerSeries` object and a
:obj:`FormalPowerSeriesInverse` object. The coefficient sequence contains the
generic sequence which is to be multiplied by a custom ``bell_seq`` finite sequence.
The finite terms will then be added up to get the final terms.

See Also
========

sympy.series.formal.FormalPowerSeries
sympy.series.formal.FiniteFormalPowerSeries

c                 óâ   • U R                   nUR                  R                  S   nUR                  5       n[	        XCS-   * -  US[
        45      nUR                  UR                  -  U-  U l        g r]  )	r¯  rü   r  rZ  r#   r   r  r  Úaux_seq)r   rË   r¯  rE   ÚinvÚinv_seqs         rT   r!  Ú!FormalPowerSeriesInverse.__init__°  s_   € Ø�y‰yˆØ�G‰G×Ñ˜aÑ ˆà�o‰oÓˆÜ˜3¨¡U 8Ñ,¨q°!´R¨jÓ9ˆØ—}‘} t§}¡}Ñ4°wÑ>ˆ�rV   c                 ó$   • U R                   nSU-  $ )z2Function for the inverse of a formal power series.r+   )rC   )r   rC   s     rT   r&  Ú!FormalPowerSeriesInverse.function¸  s   € ð �F‰FˆØ�1‰uˆrV   c                 ó   • [        S5      e©NzQOnly one function is considered while performinginverse of a formal power series.©r  r%  s    rT   rf   ÚFormalPowerSeriesInverse.g¾  ó   € äð <ó =ð 	=rV   c                 ó   • [        S5      eræ  rç  r%  s    rT   r²  ÚFormalPowerSeriesInverse.gfpsÃ  ré  rV   c                 óD  • U R                   nUR                  5       /n[        SU5       Hl  nUR                  U5      nU R                  U-  nUR                  [        USU 6 UR                  US-
     -  UR                  R                  U5      -  5        Mn     [        U6 $ )a   
Returns the first ``n`` terms of the composed formal power series.
Term by term logic is implemented here.

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

The coefficient sequence of the `FormalPowerSeriesInverse` object is the generic sequence.
It is multiplied by ``bell_seq`` to get a sequence, whose terms are added up to get
the final terms for the polynomial.

Examples
========

>>> from sympy import fps, exp, cos
>>> from sympy.abc import x
>>> f1 = fps(exp(x))
>>> f2 = fps(cos(x))
>>> finv1, finv2 = f1.inverse(), f2.inverse()

>>> finv1._eval_terms(6)
-x**5/120 + x**4/24 - x**3/6 + x**2/2 - x + 1

>>> finv2._eval_terms(8)
61*x**6/720 + 5*x**4/24 + x**2/2 + 1

See Also
========

sympy.series.formal.FormalPowerSeries.inverse
sympy.series.formal.FormalPowerSeries.coeff_bell

r+   N)
r¯  rZ  r0   rƒ  rß  rB   r   r  rü   r<   )r   rZ   r¯  rJ   rH   rÛ  rý   s          rT   r¿  Ú$FormalPowerSeriesInverse._eval_termsÈ  s�   € ðD �y‰yˆØ—‘Ó"Ð#ˆä�q˜!–ˆAØ—‘ qÓ)ˆHØ—<‘< (Ñ*ˆCØ�L‰Lœ˜s 2 A˜w˜¨4¯=©=¸¸1¹Ñ+=Ñ=ÀÇÁÇÁÈaÓ@PÑPÖQñ ô
 �Eˆ{ÐrV   )rß  N)r  r  r  r  r  r!  r©  r&  rf   r²  r¿  r  rk   rV   rT   rŠ  rŠ  š  sM   † ñò*?ð ñó ðð
 ñ=ó ð=ð ñ=ó ð=õ*rV   rŠ  Nc           
      óÞ   • [        U 5      n Uc@  U R                  n[        U5      S:X  a  UR                  5       nOU(       d  U $ [	        S5      e[        XX#XEXg5      n	U	c  U $ [        XX#U	5      $ )a!  
Generates Formal Power Series of ``f``.

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

Returns the formal series expansion of ``f`` around ``x = x0``
with respect to ``x`` in the form of a ``FormalPowerSeries`` object.

Formal Power Series is represented using an explicit formula
computed using different algorithms.

See :func:`compute_fps` for the more details regarding the computation
of formula.

Parameters
==========

x : Symbol, optional
    If x is None and ``f`` is univariate, the univariate symbols will be
    supplied, otherwise an error will be raised.
x0 : number, optional
    Point to perform series expansion about. Default is 0.
dir : {1, -1, '+', '-'}, optional
    If dir is 1 or '+' the series is calculated from the right and
    for -1 or '-' the series is calculated from the left. For smooth
    functions this flag will not alter the results. Default is 1.
hyper : {True, False}, optional
    Set hyper to False to skip the hypergeometric algorithm.
    By default it is set to False.
order : int, optional
    Order of the derivative of ``f``, Default is 4.
rational : {True, False}, optional
    Set rational to False to skip rational algorithm. By default it is set
    to True.
full : {True, False}, optional
    Set full to True to increase the range of rational algorithm.
    See :func:`rational_algorithm` for details. By default it is set to
    False.

Examples
========

>>> from sympy import fps, ln, atan, sin
>>> from sympy.abc import x, n

Rational Functions

>>> fps(ln(1 + x)).truncate()
x - x**2/2 + x**3/3 - x**4/4 + x**5/5 + O(x**6)

>>> fps(atan(x), full=True).truncate()
x - x**3/3 + x**5/5 + O(x**6)

Symbolic Functions

>>> fps(x**n*sin(x**2), x).truncate(8)
-x**(n + 6)/6 + x**(n + 2) + O(x**(n + 8))

See Also
========

sympy.series.formal.FormalPowerSeries
sympy.series.formal.compute_fps
r+   z multivariate formal power series)r   rÓ   rt   r?   r»  r  r  )
rC   rD   rõ   rö   r÷   rF   rø   r,   ÚfreerÂ   s
             rT   Úfpsrð  õ  so   € ôD 	�‹
€Aà�yØ�~‰~ˆÜˆt‹9˜‹>Ø—‘“
‰AÞØˆHä%Ð&HÓIÐIä˜˜r¨°hÓE€Fà�~Øˆä˜Q 2¨FÓ3Ð3rV   )r  F)r  )r   r+   Tr  TF)Nr   r+   Tr  TF)Xr  Úcollectionsr   Úsympy.core.numbersr   r   r   Úsympy.core.addr   Úsympy.core.exprr   Úsympy.core.functionr	   r
   r   Úsympy.core.mulr   r   Úsympy.core.relationalr   Úsympy.sets.setsr   Úsympy.core.singletonr   Úsympy.core.symbolr   r   r   r   Úsympy.core.sympifyr   Úsympy.discrete.convolutionsr   Ú(sympy.functions.combinatorial.factorialsr   r   r   Ú%sympy.functions.combinatorial.numbersr   Ú#sympy.functions.elementary.integersr   r   r   Ú(sympy.functions.elementary.miscellaneousr   r   Ú$sympy.functions.elementary.piecewiser    Úsympy.series.limitsr!   Úsympy.series.orderr"   Úsympy.series.sequencesr#   Úsympy.series.series_classr$   Úsympy.utilities.iterablesr%   rU   r^   r|   rƒ   rŠ   r�   r“   r–   rš   rž   r¡   r¬   r³   rÆ   rÎ   rÕ   r×   rà   rä   rç   rê   rð   r  rò   r  r«  r{  r†  rŠ  rð  rk   rV   rT   Ú<module>r     sI  ðÙ å #ç -Ñ -Ý Ý  ß <Ñ <Ý Ý 'Ý $Ý $Ý "ß :Ó :Ý &Ý 3ß LÑ LÝ 6ß DÑ Dß =Ý :Ý %Ý $Ý +Ý 0Ý .ôGòTôD*2òZ/òd5 òpòòò6ò6ò"ò
ò:DòNVòr7ò4ò.%ò$ò6ò(5ôp2òj\ð~ BFØôHEôV!ˆHô !ôI#˜
ô I#ôX0"Ð/ô 0"ôfCÐ6ô CôLJÐ6ô JôZXÐ6ô XõvR4rV   