§
    ¬³ÙgÄá  ã                   ó  — d Z ddlmZmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZmZmZm Z m!Z!m"Z" ddl#m$Z$ ddlm%Z% ddl&Z&d„ Z'd„ Z(d„ Z)d„ Z*d„ Z+d„ Z,d„ Z-d„ Z.d„ Z/d„ Z0d„ Z1d„ Z2d„ Z3d„ Z4d„ Z5d„ Z6d„ Z7dHd „Z8d!„ Z9d"„ Z:d#„ Z;d$„ Z<d%„ Z=d&„ Z>d'„ Z?d(„ Z@d)„ ZAd*„ ZBd+„ ZCd,„ ZDd-„ ZEd.„ ZFd/„ ZGd0„ ZHd1„ ZId2„ ZJd3„ ZKd4„ ZLd5„ ZMd6„ ZNd7„ ZOd8„ ZPd9„ ZQd:„ ZRd;„ ZSdId=„ZTd>„ ZUd?d@dAdBdCdDœZVdE„ ZWdF„ ZXdG„ ZYdS )Ja9  Power series evaluation and manipulation using sparse Polynomials

Implementing a new function
---------------------------

There are a few things to be kept in mind when adding a new function here::

    - The implementation should work on all possible input domains/rings.
      Special cases include the ``EX`` ring and a constant term in the series
      to be expanded. There can be two types of constant terms in the series:

        + A constant value or symbol.
        + A term of a multivariate series not involving the generator, with
          respect to which the series is to expanded.

      Strictly speaking, a generator of a ring should not be considered a
      constant. However, for series expansion both the cases need similar
      treatment (as the user does not care about inner details), i.e, use an
      addition formula to separate the constant part and the variable part (see
      rs_sin for reference).

    - All the algorithms used here are primarily designed to work for Taylor
      series (number of iterations in the algo equals the required order).
      Hence, it becomes tricky to get the series of the right order if a
      Puiseux series is input. Use rs_puiseux? in your function if your
      algorithm is not designed to handle fractional powers.

Extending rs_series
-------------------

To make a function work with rs_series you need to do two things::

    - Many sure it works with a constant term (as explained above).
    - If the series contains constant terms, you might need to extend its ring.
      You do so by adding the new terms to the rings as generators.
      ``PolyRing.compose`` and ``PolyRing.add_gens`` are two functions that do
      so and need to be called every time you expand a series containing a
      constant term.

Look at rs_sin and rs_series for further reference.

é    )ÚQQÚEX)ÚPolyElementÚringÚsring)ÚDomainError)Úmonomial_minÚmonomial_mulÚmonomial_divÚmonomial_ldiv)Úifac)Ú	PoleErrorÚFunctionÚExpr)ÚRational)Úigcd)	ÚsinÚcosÚtanÚatanÚexpÚatanhÚtanhÚlogÚceiling)Úas_int©Úgiant_stepsNc                 óN  — t          |                      ¦   «         ¦  «        }|                     ¦   «          |                      ¦   «         }| j        }|j        }|                      ¦   «         }|                      ¦   «         }t          ||¦  «        D ]\  }}||||d         z
  f<   Œ|S )a¨  
    Compute ``x**n * p1(1/x)`` for a univariate polynomial ``p1`` in ``x``.

    Examples
    ========

    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import _invert_monoms
    >>> R, x = ring('x', ZZ)
    >>> p = x**2 + 2*x + 3
    >>> _invert_monoms(p)
    3*x**2 + 2*x + 1

    See Also
    ========

    sympy.polys.densebasic.dup_reverse
    r   )	ÚlistÚitemsÚsortÚdegreer   ÚzeroÚ
listcoeffsÚ
listmonomsÚzip)	Úp1ÚtermsÚdegÚRÚpÚcvÚmvÚmviÚcvis	            úM/granary/edev/quantum/lib/python3.11/site-packages/sympy/polys/ring_series.pyÚ_invert_monomsr2   ;   s’   € õ( �—’‘”ÑÔ€EØ	‡J‚J�L„L€LØ
�)Š)‰+Œ+€CØ
Œ€AØ	Œ€AØ	�Š‰Œ€BØ	�Š‰Œ€BÝ˜˜B‘K”Kð !ð !‰ˆˆSØ ˆˆ3��Q”‰<ˆ/ÑÐØ€Hó    c                 óJ   — t          d| ¦  «        }|d         dk    rdg|z   }|S )z8Return a list of precision steps for the Newton's methodé   r   r   )ÚtargetÚress     r1   Ú_giant_stepsr8   Z   s.   € å
�a˜Ñ
 Ô
 €CØ
ˆ1„v�‚{€{Øˆc�C‰iˆØ€Jr3   c                 ó�   — | j         }|j        }|j                             |¦  «        }| D ]}||         |k    rŒ| |         ||<   Œ|S )a´  
    Truncate the series in the ``x`` variable with precision ``prec``,
    that is, modulo ``O(x**prec)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_trunc
    >>> R, x = ring('x', QQ)
    >>> p = x**10 + x**5 + x + 1
    >>> rs_trunc(p, x, 12)
    x**10 + x**5 + x + 1
    >>> rs_trunc(p, x, 10)
    x**5 + x + 1
    )r   r$   ÚgensÚindex)r(   ÚxÚprecr+   r,   ÚiÚexp1s          r1   Úrs_truncr@   a   sV   € ð$ 	Œ€AØ	Œ€AØ	Œ�Š�Q‰Œ€AØð ð ˆØ�Œ7�dŠ?ˆ?ØØ�T”(ˆˆ$‰ˆØ€Hr3   c                 óÎ   — | j         j                             |¦  «        }| D ]B}||         t          ||         ¦  «        k    r dS ||         dk     rt	          d|z  ¦  «        ‚ŒCdS )a†  
    Test if ``p`` is Puiseux series in ``x``.

    Raise an exception if it has a negative power in ``x``.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_is_puiseux
    >>> R, x = ring('x', QQ)
    >>> p = x**QQ(2,5) + x**QQ(2,3) + x
    >>> rs_is_puiseux(p, x)
    True
    Tr   zThe series is not regular in %sF)r   r:   r;   ÚintÚ
ValueError)r,   r<   r;   Úks       r1   Úrs_is_puiseuxrE   |   sw   € ð" ŒFŒK×Ò˜aÑ Ô €EØð Dð DˆØˆUŒ8•s˜1˜Uœ8‘}”}Ò$Ð$Ø�4�4ØˆUŒ8�aŠ<ˆ<ÝÐ>ÀÑBÑCÔCÐCð àˆ5r3   c                 ó�  ‡‡— |j         j                             |¦  «        Šd}|D ]—}|‰         }t          |t          ¦  «        r;|                     ¦   «         \  }}t          ||z  t          ||¦  «        z  ¦  «        }ŒZ|t          |¦  «        k    r*|j        }t          ||z  t          ||¦  «        z  ¦  «        }Œ˜|dk    rut          |‰|¦  «        }	 | |	|||z  ¦  «        }
t          d|¦  «        Št          |
t          ¦  «        rt          ˆˆfd„|
D ¦   «         ¦  «        }
nt          |
‰‰¦  «        }
n | |||¦  «        }
|
S )aÈ  
    Return the puiseux series for `f(p, x, prec)`.

    To be used when function ``f`` is implemented only for regular series.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_puiseux, rs_exp
    >>> R, x = ring('x', QQ)
    >>> p = x**QQ(2,5) + x**QQ(2,3) + x
    >>> rs_puiseux(rs_exp,p, x, 1)
    1/2*x**(4/5) + x**(2/3) + x**(2/5) + 1
    é   c                 ó2   •— g | ]}t          |‰‰¦  «        ‘ŒS © )Úpow_xin)Ú.0Úrxr;   Ún1s     €€r1   ú
<listcomp>zrs_puiseux.<locals>.<listcomp>µ   s%   ø€ Ð:Ð:Ð:°"•w˜r 5¨"Ñ-Ô-Ð:Ð:Ð:r3   )r   r:   r;   Ú
isinstancer   Úas_numer_denomrB   r   ÚdenominatorrJ   r   Útuple)Úfr,   r<   r=   ÚnrD   ÚpowerÚnumÚdenr(   Úrr;   rM   s              @@r1   Ú
rs_puiseuxrY   •   sY  øø€ ð" ŒFŒK×Ò˜aÑ Ô €EØ	€AØð +ð +ˆØ�%”ˆÝ�e�XÑ&Ô&ð 	+Ø×+Ò+Ñ-Ô-‰HˆC�Ý�A�c‘E�T ! S™\œ\Ñ)Ñ*Ô*ˆAˆAØ•c˜%‘j”jÒ Ð ØÔ#ˆCÝ�A�c‘E�T ! S™\œ\Ñ)Ñ*Ô*ˆAøØˆA‚v€vÝ�Q˜˜qÑ!Ô!ˆØˆAˆb�!�T˜!‘VÑÔˆÝ��1‰XŒXˆÝ�a�ÑÔð 	&ÝÐ:Ð:Ð:Ð:Ð:¸Ð:Ñ:Ô:Ñ;Ô;ˆAˆAå˜˜5 "Ñ%Ô%ˆAˆAàˆAˆa��D‰MŒMˆØ€Hr3   c                 óø  — |j         j                             |¦  «        }d}|D ]}}||         }t          |t          ¦  «        r.|                     ¦   «         \  }	}
||
z  t          ||
¦  «        z  }ŒM|t          |¦  «        k    r|j        }
||
z  t          ||
¦  «        z  }Œ~|dk    rDt          |||¦  «        } | |||||z  ¦  «        }t          d|¦  «        }t          |||¦  «        }n | ||||¦  «        }|S )z‡
    Return the puiseux series for `f(p, q, x, prec)`.

    To be used when function ``f`` is implemented only for regular series.
    rG   )r   r:   r;   rO   r   rP   r   rB   rQ   rJ   r   )rS   r,   Úqr<   r=   r;   rT   rD   rU   rV   rW   r(   rX   rM   s                 r1   Úrs_puiseux2r\   ¼   s  € ð ŒFŒK×Ò˜aÑ Ô €EØ	€AØð &ð &ˆØ�%”ˆÝ�e�XÑ&Ô&ð 	&Ø×+Ò+Ñ-Ô-‰HˆC�Ø�#‘�˜a ™œÑ%ˆAˆAØ•c˜%‘j”jÒ Ð ØÔ#ˆCØ�#‘�˜a ™œÑ%ˆAøØˆA‚v€vÝ�Q˜˜qÑ!Ô!ˆØˆAˆb�!�Q˜˜Q™ÑÔˆÝ��1‰XŒXˆÝ�A�u˜bÑ!Ô!ˆˆàˆAˆa��A�tÑÔˆØ€Hr3   c                 ó:  ‡— | j         }|j        }|j        |j         j        k    s||j         k    rt          d¦  «        ‚|j                             |¦  «        Št          |t          ¦  «        st          d¦  «        ‚||j         k    rÿ|j        }t          | 
                    ¦   «         ¦  «        }|                     ˆfd„¬¦  «         |j        dk    rS|  
                    ¦   «         D ]=\  }}	|D ]5\  }
}|d         |
d         z   }||k     r|f} ||d¦  «        |	|z  z   ||<   Œ5 Œ>n`|j        }|  
                    ¦   «         D ]D\  }}	|D ]<\  }
}|‰         |
‰         z   |k     r" |||
¦  «        } ||d¦  «        |	|z  z   ||<   Œ< ŒE|                     ¦   «          |S )a´  
    Return the product of the given two series, modulo ``O(x**prec)``.

    ``x`` is the series variable or its position in the generators.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_mul
    >>> R, x = ring('x', QQ)
    >>> p1 = x**2 + 2*x + 1
    >>> p2 = x + 1
    >>> rs_mul(p1, p2, x, 3)
    3*x**2 + 3*x + 1
    z!p1 and p2 must have the same ringzp2 must be a polynomialc                 ó    •— | d         ‰         S ©Nr   rI   ©ÚeÚivs    €r1   ú<lambda>zrs_mul.<locals>.<lambda>ñ   s   ø€  ! A¤$ r¤(€ r3   ©ÚkeyrG   r   )r   r$   Ú	__class__rC   r:   r;   rO   r   Úgetr    r!   r"   Úngensr
   Ú
strip_zero)r(   Úp2r<   r=   r+   r,   rg   Úitems2r?   Úv1Úexp2Úv2r   r
   rb   s                 @r1   Úrs_mulro   Õ   sË  ø€ ð$ 	Œ€AØ	Œ€AØ„{�b”gÔ'Ò'Ð'¨1°´ª<¨<ÝÐ<Ñ=Ô=Ð=Ø	
Œ�Š�a‰Œ€BÝ�b�+Ñ&Ô&ð 4ÝÐ2Ñ3Ô3Ð3ØˆBŒG‚|€|ØŒeˆÝ�b—h’h‘j”jÑ!Ô!ˆØ�ŠÐ*Ð*Ð*Ð*ˆÑ+Ô+Ð+ØŒ7�aŠ<ˆ<ØŸHšH™JœJð ð ‘��bØ &ð ð ‘H�D˜"Ø˜qœ' D¨¤GÑ+�CØ˜T’z�zØ"˜g˜Ø!$  S¨!¡¤¨r°"©uÑ!4˜˜#™˜àøðð œ>ˆLØŸHšH™JœJð ð ‘��bØ &ð ð ‘H�D˜"Ø˜B”x $ r¤(Ñ*¨TÒ1Ð1Ø*˜l¨4°Ñ6Ô6˜Ø!$  S¨!¡¤¨r°"©uÑ!4˜˜#™˜àøà‡L‚L�N„N€NØ€Hr3   c                 óØ  ‡— | j         }|j        }|j                             |¦  «        Š|j        }t          |                      ¦   «         ¦  «        }|                     ˆfd„¬¦  «         |j        }t          t          |¦  «        ¦  «        D ]a}||         \  }	}
t          |¦  «        D ]D}||         \  }}|	‰         |‰         z   |k     r" ||	|¦  «        } ||d¦  «        |
|z  z   ||<   ŒD Œb|                     d¦  «        }|j        }|                      ¦   «         D ]5\  }}d|‰         z  |k     r! |||¦  «        } ||d¦  «        |dz  z   ||<   Œ6|                     ¦   «          |S )aA  
    Square the series modulo ``O(x**prec)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_square
    >>> R, x = ring('x', QQ)
    >>> p = x**2 + 2*x + 1
    >>> rs_square(p, x, 3)
    6*x**2 + 4*x + 1
    c                 ó    •— | d         ‰         S r_   rI   r`   s    €r1   rc   zrs_square.<locals>.<lambda>  s   ø€ ˜Q˜qœT "œX€ r3   rd   r   r5   )r   r$   r:   r;   rg   r    r!   r"   r
   ÚrangeÚlenÚimul_numri   )r(   r<   r=   r+   r,   rg   r!   r
   r>   r?   rl   Újrm   rn   r   ÚexpvÚvÚe2rb   s                     @r1   Ú	rs_squarery     s€  ø€ ð 	Œ€AØ	Œ€AØ	
Œ�Š�a‰Œ€BØ
Œ%€CÝ�—’‘”ÑÔ€EØ	‡J‚JÐ%Ð%Ð%Ð%€JÑ&Ô&Ð&Ø”>€LÝ•3�u‘:”:ÑÔð ð ˆØ˜”8‰ˆˆbÝ�q‘”ð 	ð 	ˆAØ˜Q”x‰HˆD�"Ø�BŒx˜$˜rœ(Ñ" TÒ)Ð)Ø"�l 4¨Ñ.Ô.�Ø˜˜S !™œ r¨"¡uÑ,��#‘�àøØ	�
Š
�1‰Œ€AØ
Œ%€CØ—8’8‘:”:ð &ð &‰ˆˆaØˆT�"ŒX‰:˜ÒÐØ�˜d DÑ)Ô)ˆBØ�C˜˜A‘J”J  A¡Ñ%ˆAˆb‰EøØ‡L‚L�N„N€NØ€Hr3   c                 ó   — | j         }t          |t          ¦  «        rmt          |j        ¦  «        }t          |j        ¦  «        }|dk    r+t          | |||¦  «        }|dk    rt          ||||¦  «        }nt          | |||¦  «        }|S t          |¦  «        }|dk    r| r |d¦  «        S t          d¦  «        ‚|dk     r$t          | | ||¦  «        } t          | ||¦  «        S |dk    rt          | ||¦  «        S |dk    rt          | ||¦  «        S |dk    r#t          | ||¦  «        }t          | |||¦  «        S  |d¦  «        }		 |dz  rt          | |	||¦  «        }	|dz  }|snt          | ||¦  «        } |dz  }Œ6|	S )a4  
    Return ``p1**n`` modulo ``O(x**prec)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_pow
    >>> R, x = ring('x', QQ)
    >>> p = x + 1
    >>> rs_pow(p, 4, x, 3)
    6*x**2 + 4*x + 1
    rG   r   z0**0 is undefinedr5   é   )r   rO   r   rB   r,   r[   Úrs_nth_rootÚrs_powr   rC   Úrs_series_inversionr@   ry   ro   )
r(   rT   r<   r=   r+   ÚnpÚnqr7   rj   r,   s
             r1   r}   r}   0  s¿  € ð 	Œ€AÝ�!•XÑÔð 	Ý�”‰XŒXˆÝ�”‰XŒXˆØ�Š7ˆ7Ý˜b " a¨Ñ.Ô.ˆCØ�QŠwˆwÝ˜S " a¨Ñ.Ô.�øå˜˜R  DÑ)Ô)ˆCØˆ
åˆq‰	Œ	€AØˆA‚v€vØð 	2Ø�1�Q‘4”4ˆKåÐ0Ñ1Ô1Ð1Øˆ1‚u€uÝ�B˜˜˜A˜tÑ$Ô$ˆÝ" 2 q¨$Ñ/Ô/Ð/ØˆA‚v€vÝ˜˜A˜tÑ$Ô$Ð$ØˆA‚v€vÝ˜˜Q Ñ%Ô%Ð%ØˆA‚v€vÝ�r˜1˜dÑ#Ô#ˆÝ�b˜"˜a Ñ&Ô&Ð&Ø	ˆˆ!‰Œ€AðØˆq‰5ð 	Ý�r˜1˜a Ñ&Ô&ˆAØ�‰FˆAØð ØÝ�r˜1˜dÑ#Ô#ˆØ�‰Fˆðð €Hr3   c                 ó  — | j         }|j        } |d¦  «        }t          |¦  «        D ]}|j        |         ||df<   Œ|D ]"}||         ||                     |¦  «        df<   Œ# |d¦  «        }	t          |                      ¦   «         ¦  «        }
|
D ]í} |d¦  «        }t          |¦  «        D ]Â}||         }|dk    rŒ||f|vr‘t          |d¦  «        \  }}|dk    r%||f|v rt          |||f         ||¦  «        |||f<   nS||dz
  f|v r+t          |||dz
  f         ||df         ||¦  «        |||f<   nt          ||df         |||¦  «        |||f<   t          ||||f         ||¦  «        }ŒÃ|	|| |         z  z  }	Œî|	S )aÅ  
    Substitution with truncation according to the mapping in ``rules``.

    Return a series with precision ``prec`` in the generator ``x``

    Note that substitutions are not done one after the other

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_subs
    >>> R, x, y = ring('x, y', QQ)
    >>> p = x**2 + y**2
    >>> rs_subs(p, {x: x+ y, y: x+ 2*y}, x, 3)
    2*x**2 + 6*x*y + 5*y**2
    >>> (x + y)**2 + (x + 2*y)**2
    2*x**2 + 6*x*y + 5*y**2

    which differs from

    >>> rs_subs(rs_subs(p, {x: x+ y}, x, 3), {y: x+ 2*y}, x, 3)
    5*x**2 + 12*x*y + 8*y**2

    Parameters
    ----------
    p : :class:`~.PolyElement` Input series.
    rules : ``dict`` with substitution mappings.
    x : :class:`~.PolyElement` in which the series truncation is to be done.
    prec : :class:`~.Integer` order of the series after truncation.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_subs
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_subs(x**2+y**2, {y: (x+y)**2}, x, 3)
     6*x**2*y**2 + x**2 + 4*x*y**3 + y**4
    r   rG   r5   )r   rh   rr   r:   r;   ÚsortedÚkeysÚdivmodry   ro   r}   )r,   Úrulesr<   r=   r+   rh   Údr>   Úvarr(   Úp_keysrv   rj   rU   r[   rX   s                   r1   Úrs_subsr‰   f  sà  € ðP 	
Œ€AØŒG€EØ	ˆˆ!‰Œ€AÝ�5‰\Œ\ð ð ˆØ”F˜1”Iˆˆ1ˆaˆ&‰	ˆ	Øð *ð *ˆØ$ Sœzˆˆ1�7Š7�3‰<Œ<˜Ð
ÑÐØ	
ˆˆ1‰Œ€BÝ�A—F’F‘H”HÑÔ€FØð ð ˆØˆQˆq‰TŒTˆÝ�u‘”ð 	4ð 	4ˆAØ˜”GˆEØ˜ŠzˆzØØ�5ˆz Ð"Ð"Ý˜e QÑ'Ô'‘��1Ø˜’6�6˜q !˜f¨˜k˜kÝ$-¨a°°A°¬i¸¸DÑ$AÔ$A�A�q˜%�j‘M�MØ˜ ™�^ qÐ(Ð(Ý$*¨1¨a°¸±¨^Ô+<¸aÀÀAÀ¼iØ+,¨dñ%4ô %4�A�q˜%�j‘M�Mõ %+¨1¨a°¨V¬9°e¸QÀÑ$EÔ$E�A�q˜%�j‘MÝ˜˜A˜q %˜jœM¨1¨dÑ3Ô3ˆBˆBØ
ˆb��4”‰jÑˆˆØ€Ir3   c                 óÌ   — | j         }|j                             |¦  «        }|j        }dg|j        z  }d||<   t          |¦  «        }| D ]}t          ||¦  «        |k    r dS ŒdS )aF  
    Check if ``p`` has a constant term in ``x``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import _has_constant_term
    >>> R, x = ring('x', QQ)
    >>> p = x**2 + x + 1
    >>> _has_constant_term(p, x)
    True
    r   rG   TF©r   r:   r;   Ú
zero_monomrh   rR   r	   )r,   r<   r+   rb   ÚzmÚaÚmivrv   s           r1   Ú_has_constant_termr�   ª  sy   € ð 	
Œ€AØ	
Œ�Š�a‰Œ€BØ	
Œ€BØ	
ˆˆAŒG‰€AØ€A€b�EÝ
�‰(Œ(€CØð ð ˆÝ˜˜cÑ"Ô" bÒ(Ð(Ø�4�4ð )àˆ5r3   c                 óö   — | j         }|j                             |¦  «        }|j        }dg|j        z  }d||<   t          |¦  «        }d}| D ],}t          ||¦  «        |k    r| ||| |         i¦  «        z  }Œ-|S )zÝReturn constant term in p with respect to x

    Note that it is not simply `p[R.zero_monom]` as there might be multiple
    generators in the ring R. We want the `x`-free term which can contain other
    generators.
    r   rG   r‹   )	r,   r<   r+   r>   r�   rŽ   r�   Úcrv   s	            r1   Ú_get_constant_termr“   Ä  s�   € ð 	
Œ€AØ	Œ�Š�Q‰Œ€AØ	
Œ€BØ	
ˆˆAŒG‰€AØ€A€a�DÝ
�‰(Œ(€CØ	€AØð $ð $ˆÝ˜˜cÑ"Ô" bÒ(Ð(Ø���D˜!˜Dœ'�?Ñ#Ô#Ñ#ˆAøØ€Hr3   c                 ó®   ‡— | j         j                             |¦  «        Št          | ˆfd„¬¦  «        ‰         }|dk     rt	          d|z  ¦  «        ‚‰|fS )Nc                 ó   •— | ‰         S ©NrI   ©rD   r;   s    €r1   rc   z#_check_series_var.<locals>.<lambda>Ù  ó   ø€ ˜Q˜uœX€ r3   rd   r   z7Asymptotic expansion of %s around [oo] not implemented.)r   r:   r;   Úminr   )r,   r<   ÚnameÚmr;   s       @r1   Ú_check_series_varrœ   ×  sl   ø€ ØŒFŒK×Ò˜aÑ Ô €EÝˆAÐ%Ð%Ð%Ð%Ð&Ñ&Ô& uÔ-€AØˆ1‚u€uÝð 'Ø)-ñ.ñ /ô /ð 	/à�!ˆ8€Or3   c                 ó  — t          | |¦  «        rt          t          | ||¦  «        S | j        }|j        }| |         }|t          |¦  «        k    rt          |¦  «        }|| vrt          d¦  «        ‚t          | |z
  |¦  «        rt          d¦  «        ‚ |d¦  «        }|j        t          u rd}||k    r |d¦  «        |z  }n |d¦  «        }t          |¦  «        D ],}dt          || ||¦  «        z
  }	|t          ||	||¦  «        z   }Œ-|S )a�  
    Univariate series inversion ``1/p`` modulo ``O(x**prec)``.

    The Newton method is used.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import _series_inversion1
    >>> R, x = ring('x', QQ)
    >>> p = x + 1
    >>> _series_inversion1(p, x, 4)
    -x**3 + x**2 - x + 1
    úNo constant term in seriesz8p cannot contain a constant term depending on parametersrG   )rE   rY   Ú_series_inversion1r   rŒ   rB   rC   r�   Údomainr   r8   ro   )
r,   r<   r=   r+   r�   r’   Úoner(   ÚprecxÚts
             r1   rŸ   rŸ   ß  s9  € õ" �Q˜ÑÔð :ÝÕ,¨a°°DÑ9Ô9Ð9Ø	Œ€AØ	
Œ€BØ	ˆ"Œ€Að �s�4‰yŒyÒÐÝ�4‰yŒyˆà	�€{€{ÝÐ5Ñ6Ô6Ð6Ý˜!˜a™% Ñ#Ô#ð 'Ýð &ñ 'ô 'ð 	'à
ˆ!ˆA‰$Œ$€CØ„x•2€~€~ØˆØˆC‚x€xàˆQˆq‰TŒT�!‰VˆˆàˆQˆq‰TŒTˆÝ˜dÑ#Ô#ð *ð *ˆØ•�r˜1˜a Ñ'Ô'Ñ'ˆØ•&˜˜Q  5Ñ)Ô)Ñ)ˆˆØ€Ir3   c                 óª  ‡— | j         }| |j        k    rt          ‚|j        }|j                             |¦  «        Št          | ˆfd„¬¦  «        ‰         }|rt          | ‰| ¦  «        } ||z   }|| vrt          d¦  «        ‚t          | | |         z
  |¦  «        rt          d¦  «        ‚t          | ||¦  «        }|dk    rt          |‰| ¦  «        }|S )aý  
    Multivariate series inversion ``1/p`` modulo ``O(x**prec)``.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_series_inversion
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_series_inversion(1 + x*y**2, x, 4)
    -x**3*y**6 + x**2*y**4 - x*y**2 + 1
    >>> rs_series_inversion(1 + x*y**2, y, 4)
    -x*y**2 + 1
    >>> rs_series_inversion(x + x**2, x, 4)
    x**3 - x**2 + x - 1 + x**(-1)
    c                 ó   •— | ‰         S r–   rI   r—   s    €r1   rc   z%rs_series_inversion.<locals>.<lambda>$  r˜   r3   rd   rž   z>p - p[0] must not have a constant term in the series variablesr   )r   r$   ÚZeroDivisionErrorrŒ   r:   r;   r™   Úmul_xinÚNotImplementedErrorr�   rŸ   )r,   r<   r=   r+   r�   r›   rX   r;   s          @r1   r~   r~     sõ   ø€ ð$ 	
Œ€AØˆAŒF‚{€{ÝÐØ	
Œ€BØŒF�LŠL˜‰OŒO€EÝˆAÐ%Ð%Ð%Ð%Ð&Ñ&Ô& uÔ-€AØð Ý�A�u˜q˜bÑ!Ô!ˆØ�a‰xˆØ	�€{€{Ý!Ð">Ñ?Ô?Ð?å˜!˜a œe™) QÑ'Ô'ð :Ý!ð #9ñ :ô :ð 	:å˜1˜a Ñ&Ô&€AØˆA‚v€vÝ�A�u˜q˜bÑ!Ô!ˆØ€Hr3   c                 óÆ   — |\  }}| j         }dg|j        z  }|||<   t          |¦  «        } |d¦  «        }| D ]'}||         |k    r| |         |t          ||¦  «        <   Œ(|S )z2Coefficient of `x_i**j` in p, where ``t`` = (i, j)r   )r   rh   rR   r   )r,   r£   r>   ru   r+   Úexpv1r(   rv   s           r1   Ú_coefficient_tr«   3  sz   € à�D€A€qØ	Œ€AØˆC�”‰K€EØ€Eˆ!�HÝ�%‰LŒL€EØ	
ˆˆ1‰Œ€BØð 4ð 4ˆØ�Œ7�aŠ<ˆ<Ø,-¨d¬GˆB�|˜D %Ñ(Ô(Ñ)øØ€Ir3   c                 ó  — t          | |¦  «        rt          ‚| j        }|j                             |¦  «        } ||¦  «        }|j                             |¦  «        }t          | |¦  «        rt          d¦  «        ‚t          | |df¦  «        }|j        }||v rt          |¦  «        dk    sJ ‚||         }||z  }	t          d|¦  «        D ]9}
t          | ||	i||
dz   ¦  «        }t          |||
f¦  «        ||
z  z  }|	||z  z  }	Œ:|	S )ab  
    Reversion of a series.

    ``p`` is a series with ``O(x**n)`` of the form $p = ax + f(x)$
    where $a$ is a number different from 0.

    $f(x) = \sum_{k=2}^{n-1} a_kx_k$

    Parameters
    ==========

      a_k : Can depend polynomially on other variables, not indicated.
      x : Variable with name x.
      y : Variable with name y.

    Returns
    =======

    Solve $p = y$, that is, given $ax + f(x) - y = 0$,
    find the solution $x = r(y)$ up to $O(y^n)$.

    Algorithm
    =========

    If $r_i$ is the solution at order $i$, then:
    $ar_i + f(r_i) - y = O\left(y^{i + 1}\right)$

    and if $r_{i + 1}$ is the solution at order $i + 1$, then:
    $ar_{i + 1} + f(r_{i + 1}) - y = O\left(y^{i + 2}\right)$

    We have, $r_{i + 1} = r_i + e$, such that,
    $ae + f(r_i) = O\left(y^{i + 2}\right)$
    or $e = -f(r_i)/a$

    So we use the recursion relation:
    $r_{i + 1} = r_i - f(r_i)/a$
    with the boundary condition: $r_1 = y$

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_series_reversion, rs_trunc
    >>> R, x, y, a, b = ring('x, y, a, b', QQ)
    >>> p = x - x**2 - 2*b*x**2 + 2*a*b*x**2
    >>> p1 = rs_series_reversion(p, x, 3, y); p1
    -2*y**2*a*b + 2*y**2*b + y**2 + y
    >>> rs_trunc(p.compose(x, p1), y, 3)
    y
    z9p must not contain a constant term in the series variablerG   r5   )rE   r¨   r   r:   r;   r�   rC   r«   rŒ   rs   rr   r‰   )r,   r<   rT   Úyr+   ÚnxÚnyrŽ   r�   rX   r>   Úsps               r1   Úrs_series_reversionr±   @  s%  € õh �Q˜ÑÔð "Ý!Ð!Ø	Œ€AØ	
Œ�Š�a‰Œ€BØ	ˆˆ!‰Œ€AØ	
Œ�Š�a‰Œ€BÝ˜!˜QÑÔð %Ýð $ñ %ô %ð 	%å�q˜2˜q˜'Ñ"Ô"€AØ	
Œ€BØ�ˆ7ˆ7•s˜1‘v”v ’{�{�{�{Ø	ˆ"Œ€AØ	ˆ!‰€AÝ�1�a‰[Œ[ð ð ˆÝ�Q˜˜A˜  1 q¡5Ñ)Ô)ˆÝ˜B  Q Ñ(Ô(¨¨A©Ñ-ˆØ	ˆR�‰T‰	ˆˆØ€Hr3   rG   c                 óþ  — 	 | j         }t          |¦  «        }|sK |d¦  «        }|d         |z  }t          d|¦  «        D ]"}	t          || ||¦  «        }|||	         |z  z  }Œ#|S t	          t          j        |¦  «        dz   ¦  «        }
t          ||
¦  «        \  }}|r|dz  } |d¦  «        g} |d¦  «        }t          | ¦  «        dk     r;t          d|
¦  «        D ])}	t          || ||¦  «        }|                     |¦  «         Œ*n^t          d|
¦  «        D ]M}	|	dz  dk    rt          ||	dz           ||¦  «        }nt          || ||¦  «        }|                     |¦  «         ŒNt          |d         | ||¦  «        } |d¦  «        } |d¦  «        }t          |dz
  ¦  «        D ]f}|
|z  }||         }t          d|
¦  «        D ]}||||z            ||         z  z  }Œt          ||||¦  «        }||z  }t          ||||¦  «        }|s nŒg|dz
  }|
|z  }||k     r`||          |d¦  «        z  }t          d|
¦  «        D ]$}||z   |k    r n||||z            ||         z  z  }Œ%t          ||||¦  «        }||z  }|S )a  
    Return a series `sum c[n]*p**n` modulo `O(x**prec)`.

    It reduces the number of multiplications by summing concurrently.

    `ax = [1, p, p**2, .., p**(J - 1)]`
    `s = sum(c[i]*ax[i]` for i in `range(r, (r + 1)*J))*p**((K - 1)*J)`
    with `K >= (n + 1)/J`

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_series_from_list, rs_trunc
    >>> R, x = ring('x', QQ)
    >>> p = x**2 + x + 1
    >>> c = [1, 2, 3]
    >>> rs_series_from_list(p, c, x, 4)
    6*x**3 + 11*x**2 + 8*x + 6
    >>> rs_trunc(1 + 2*p + 3*p**2, x, 4)
    6*x**3 + 11*x**2 + 8*x + 6
    >>> pc = R.from_list(list(reversed(c)))
    >>> rs_trunc(pc.compose(x, p), x, 4)
    6*x**3 + 11*x**2 + 8*x + 6

    rG   r   é   r5   éÿÿÿÿ)
r   rs   rr   ro   rB   ÚmathÚsqrtr„   Úappendry   )r,   r’   r<   r=   Úconcurr+   rT   r[   Úsr>   ÚJÚKrX   ÚaxÚpjÚbrD   Ús1ru   s                      r1   Úrs_series_from_listrÀ   ˆ  sñ  € ð<ð 	
Œ€AÝˆA‰Œ€AØð ØˆAˆa‰DŒDˆØˆaŒD�‰FˆÝ�q˜!‘”ð 	ð 	ˆAÝ�q˜!˜Q Ñ%Ô%ˆAØ��1”�a‘‰KˆAˆAØˆÝ�DŒI�a‰LŒL˜1ÑÑÔ€AÝ�!�Q‰<Œ<�D€A€qØð Ø	ˆQ‰ˆØ
ˆ!ˆA‰$Œ$ˆ€BØ	ˆˆ!‰Œ€AÝ
ˆ1�v„v�‚{€{Ý�q˜!‘”ð 	ð 	ˆAÝ�q˜!˜Q Ñ%Ô%ˆAØ�IŠI�a‰LŒLˆLˆLð	õ �q˜!‘”ð 	ð 	ˆAØ�1‰u˜ŠzˆzÝ˜b  A¡œh¨¨4Ñ0Ô0��å˜1˜a  DÑ)Ô)�Ø�IŠI�a‰LŒLˆLˆLå	��2”˜˜1˜dÑ	#Ô	#€BØ	ˆˆ!‰Œ€AØ	ˆˆ!‰Œ€AÝ�1�q‘5‰\Œ\ð 	ð 	ˆØˆa‰CˆØˆqŒTˆÝ�q˜!‘”ð 	!ð 	!ˆAØ�!�A˜‘E”(˜2˜aœ5‘.Ñ ˆBˆBÝ�B˜˜1˜dÑ#Ô#ˆØ	ˆR‰ˆÝ�1�b˜!˜TÑ"Ô"ˆØð 	ØˆEð	à	ˆA‰€AØ	ˆ!‰€AØˆ1‚u€uØˆqŒT�!�!�A‘$”$‰YˆÝ�q˜!‘”ð 	!ð 	!ˆAØ�1‰u˜ŠzˆzØ�Ø�!�A˜‘E”(˜2˜aœ5‘.Ñ ˆBˆBÝ�B˜˜1˜dÑ#Ô#ˆØ	ˆR‰ˆØ€Hr3   c                 ó  — | j         }|j                             |¦  «        }|j        }dg|j        z  }d||<   t          |¦  «        }| D ]A}||         r7t          ||¦  «        }|                     | |         ||         z  ¦  «        ||<   ŒB|S )a»  
    Return partial derivative of ``p`` with respect to ``x``.

    Parameters
    ==========

    x : :class:`~.PolyElement` with respect to which ``p`` is differentiated.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_diff
    >>> R, x, y = ring('x, y', QQ)
    >>> p = x + x**2*y**3
    >>> rs_diff(p, x)
    2*x*y**3 + 1
    r   rG   )r   r:   r;   r$   rh   rR   r   Ú
domain_new)r,   r<   r+   rT   r(   Úmnrv   ra   s           r1   Úrs_diffrÄ   á  s•   € ð( 	
Œ€AØ	Œ�Š�Q‰Œ€AØ	
Œ€BØ
ˆˆQŒW‰€BØ€B€q�EÝ	ˆr‰Œ€BØð 2ð 2ˆØ�Œ7ð 	2Ý˜d BÑ'Ô'ˆAØ—L’L  4¤¨¨a¬¡Ñ1Ô1ˆBˆq‰EøØ€Ir3   c                 ó  — | j         }|j        }|j                             |¦  «        }dg|j        z  }d||<   t          |¦  «        }| D ]<}t          ||¦  «        }|                     | |         ||         dz   z  ¦  «        ||<   Œ=|S )aº  
    Integrate ``p`` with respect to ``x``.

    Parameters
    ==========

    x : :class:`~.PolyElement` with respect to which ``p`` is integrated.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_integrate
    >>> R, x, y = ring('x, y', QQ)
    >>> p = x + x**2*y**3
    >>> rs_integrate(p, x)
    1/3*x**3*y**3 + 1/2*x**2
    r   rG   )r   r$   r:   r;   rh   rR   r
   rÂ   )r,   r<   r+   r(   rT   rÃ   rv   ra   s           r1   Úrs_integraterÆ     s�   € ð( 	
Œ€AØ	
Œ€BØ	Œ�Š�Q‰Œ€AØ
ˆˆQŒW‰€BØ€B€q�EÝ	ˆr‰Œ€Bàð 4ð 4ˆÝ˜˜rÑ"Ô"ˆØ—’˜Q˜tœW d¨1¤g°¡kÑ2Ñ3Ô3ˆˆ1‰ˆØ€Ir3   c                 óþ  — | j         }t          d|j        ¦  «        \  }}t          |d         ¦  «        }|dd…         ||fz   }|j        }|| v r|| |         z   }	| | |         z
  }
n|}	| }
t	          |t
          ¦  «        r t          |	|¦  «        |Ž }n	 ||	g|¢R Ž }t          |                     ¦   «         ¦  «        }dg|z  }|D ]}|d         ||d         d         <   Œt          |
||d         |d         ¦  «        }
|
S )a  
    Function of a multivariate series computed by substitution.

    The case with f method name is used to compute `rs\_tan` and `rs\_nth\_root`
    of a multivariate series:

        `rs\_fun(p, tan, iv, prec)`

        tan series is first computed for a dummy variable _x,
        i.e, `rs\_tan(\_x, iv, prec)`. Then we substitute _x with p to get the
        desired series

    Parameters
    ==========

    p : :class:`~.PolyElement` The multivariate series to be expanded.
    f : `ring\_series` function to be applied on `p`.
    args[-2] : :class:`~.PolyElement` with respect to which, the series is to be expanded.
    args[-1] : Required order of the expanded series.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_fun, _tan1
    >>> R, x, y = ring('x, y', QQ)
    >>> p = x + x*y + x**2*y + x**3*y**2
    >>> rs_fun(p, _tan1, x, 4)
    1/3*x**3*y**3 + 2*x**3*y**2 + x**3*y + 1/3*x**3 + x**2*y + x*y + x
    Ú_xr´   Néþÿÿÿr   rG   )
r   r    rB   rŒ   rO   ÚstrÚgetattrr‚   r!   rÀ   )r,   rS   ÚargsÚ_RÚR1rÈ   ÚhÚargs1r�   Úx1r(   r[   rŽ   r’   r<   s                  r1   Úrs_funrÒ   !  s  € ð@ 
Œ€BÝ�$˜œ	Ñ"Ô"�F€BˆÝˆD�ŒH‰Œ€AØ��"�ŒI˜˜Q˜Ñ€EØ	Œ€Bð 
ˆQ€w€wØ�!�B”%‰ZˆØ��2”‰YˆˆàˆØˆÝ�!•SÑÔð Ø�G�B˜‰NŒN˜EÐ"ˆˆàˆAˆbˆM�5ˆMˆMˆMˆÝˆq�wŠw‰yŒyÑÔ€AØ	
ˆˆA‰€AØð ð ˆØ�q”Tˆˆ!ˆAŒ$ˆqŒ'‰
ˆ
Ý	˜R  D¨¤H¨d°2¬hÑ	7Ô	7€BØ€Ir3   c                 óÀ   — | j         } |d¦  «        }|                      ¦   «         D ]6\  }}t          |¦  «        }||xx         |z  cc<   ||t          |¦  «        <   Œ7|S )zF
    Return `p*x_i**n`.

    `x\_i` is the ith variable in ``p``.
    r   ©r   r!   r    rR   ©r,   r>   rT   r+   r[   rD   rw   Úk1s           r1   r§   r§   Y  si   € ð 	
Œ€AØ	ˆˆ!‰Œ€AØ—’‘	”	ð ð ‰ˆˆ1Ý�!‰WŒWˆØ
ˆ1ˆˆŒ�‰
ˆˆ‰Øˆ�%�‰)Œ)‰ˆØ€Hr3   c                 óÀ   — | j         } |d¦  «        }|                      ¦   «         D ]6\  }}t          |¦  «        }||xx         |z  cc<   ||t          |¦  «        <   Œ7|S )a6  
    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import pow_xin
    >>> R, x, y = ring('x, y', QQ)
    >>> p = x**QQ(2,5) + x + x**QQ(2,3)
    >>> index = p.ring.gens.index(x)
    >>> pow_xin(p, index, 15)
    x**15 + x**10 + x**6
    r   rÔ   rÕ   s           r1   rJ   rJ   g  si   € ð 	
Œ€AØ	ˆˆ!‰Œ€AØ—’‘	”	ð ð ‰ˆˆ1Ý�!‰WŒWˆØ
ˆ1ˆˆŒ�‰
ˆˆ‰Øˆ�%�‰)Œ)‰ˆØ€Hr3   c                 óú  — t          | |¦  «        rt          t          | |||¦  «        S | j        }|j        }|| vrt          d¦  «        ‚t          |¦  «        }| |         dk    sJ ‚ |d¦  «        }| dk    r| S |dk    r |d¦  «        S |dk    r| S |dk     r| }d}nd}t          |¦  «        D ]7}t          ||dz   ||¦  «        }	t          |	| ||¦  «        }	|||z  |	|z  z
  z  }Œ8|r|S t          |||¦  «        S )z_
    Univariate series expansion of the nth root of ``p``.

    The Newton method is used.
    rž   rG   r   )rE   r\   Ú
_nth_root1r   rŒ   r¨   r   r8   r}   ro   rŸ   )
r,   rT   r<   r=   r+   r�   r(   Úsignr¢   Útmps
             r1   rÙ   rÙ   z  sA  € õ �Q˜ÑÔð 6Ý�: q¨!¨Q°Ñ5Ô5Ð5Ø	Œ€AØ	
Œ€BØ	�€{€{Ý!Ð">Ñ?Ô?Ð?Ýˆq‰	Œ	€AØˆRŒ5�AŠ:ˆ:ˆ:ˆ:Ø	
ˆˆ1‰Œ€BØˆA‚v€vØˆØˆA‚v€vØˆq�‰tŒtˆØˆA‚v€vØˆØˆ1‚u€uØˆBˆØˆˆàˆÝ˜dÑ#Ô#ð ð ˆÝ�R˜˜Q™  5Ñ)Ô)ˆÝ�S˜!˜Q Ñ&Ô&ˆØ
ˆb�‰d�S˜‘U‰lÑˆˆØð /Øˆ	å! " a¨Ñ.Ô.Ð.r3   c                 óÄ  ‡— |dk    r*| dk    rt          d¦  «        ‚|                      d¦  «        S |dk    rt          | ||¦  «        S | j        }|j                             |¦  «        Št          | ˆfd„¬¦  «        ‰         }t          | ‰| ¦  «        } ||z  }t          | dz
  |¦  «        rý|j        }| |         }|j	        t          u r(|                     ¦   «         }|t          d|¦  «        z  }	nŸt          |t          ¦  «        rO	 |                     ¦   «         } ||t          d|¦  «        z  ¦  «        }	nX# t           $ r t          d¦  «        ‚w xY w	  ||t!          d|¦  «        z  ¦  «        }	n# t           $ r t          d¦  «        ‚w xY wt#          | |z  |||¦  «        |	z  }
nt%          | |||¦  «        }
|r!t          ||¦  «        }t          |
‰|¦  «        }
|
S )a  
    Multivariate series expansion of the nth root of ``p``.

    Parameters
    ==========

    p : Expr
        The polynomial to computer the root of.
    n : integer
        The order of the root to be computed.
    x : :class:`~.PolyElement`
    prec : integer
        Order of the expanded series.

    Notes
    =====

    The result of this function is dependent on the ring over which the
    polynomial has been defined. If the answer involves a root of a constant,
    make sure that the polynomial is over a real field. It cannot yet handle
    roots of symbols.

    Examples
    ========

    >>> from sympy.polys.domains import QQ, RR
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_nth_root
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_nth_root(1 + x + x*y, -3, x, 3)
    2/9*x**2*y**2 + 4/9*x**2*y + 2/9*x**2 - 1/3*x*y - 1/3*x + 1
    >>> R, x, y = ring('x, y', RR)
    >>> rs_nth_root(3 + x + x*y, 3, x, 2)
    0.160249952256379*x*y + 0.160249952256379*x + 1.44224957030741
    r   z0**0 expressionrG   c                 ó   •— | ‰         S r–   rI   r—   s    €r1   rc   zrs_nth_root.<locals>.<lambda>Ê  r˜   r3   rd   ú3The given series cannot be expanded in this domain.)rC   r   r@   r:   r;   r™   r§   r�   rŒ   r    r   Úas_exprr   rO   r   r   r   r|   rÙ   )r,   rT   r<   r=   r+   r›   r�   r’   Úc_exprÚconstr7   r;   s              @r1   r|   r|   �  s   ø€ ðH 	ˆA‚v€vØ�Š6ˆ6ÝÐ.Ñ/Ô/Ð/à—6’6˜!‘9”9ÐØˆA‚v€vÝ˜˜1˜dÑ#Ô#Ð#Ø	Œ€AØŒF�LŠL˜‰OŒO€EÝˆAÐ%Ð%Ð%Ð%Ð&Ñ&Ô& uÔ-€AÝ��5˜1˜"ÑÔ€AØˆA�I€Då˜!˜a™% Ñ#Ô#ð (ØŒ\ˆØˆbŒEˆØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFØ�B˜q !™HœHÑ$ˆEˆEÝ˜�;Ñ'Ô'ð 	$ð$ØŸš™œ�Ø˜˜&¥2 a¨¡8¤8Ñ,Ñ-Ô-��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð$Ø˜˜!�X a¨™^œ^Ñ+Ñ,Ô,��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøõ ˜!˜A™#˜q ! TÑ*Ô*¨5Ñ0ˆˆå˜˜A˜q $Ñ'Ô'ˆØð %Ýˆq�!‰HŒHˆÝ�c˜5 !Ñ$Ô$ˆØ€Js   Ä	0D: Ä:EÅE5 Å5Fc                 óœ  — t          | |¦  «        rt          t          | ||¦  «        S | j        }| dk    r|j        S t          | |¦  «        }|�rxd}|dk    r�n"|                     ¦   «         }|j        t          u rt          |¦  «        }nðt          |t          ¦  «        r¤	  |t          |¦  «        ¦  «        }nÁ# t          $ r} |                     t          |¦  «        g¦  «        }|                      |¦  «        } |                     |¦  «        }|                     |¦  «        } |t          |¦  «        ¦  «        }Y n;w xY w	  |t          |¦  «        ¦  «        }n# t          $ r t          d¦  «        ‚w xY w|                      |¦  «        }t#          |t%          | ||¦  «        ||dz
  ¦  «        }t'          ||¦  «        |z   S t(          ‚)aø  
    The Logarithm of ``p`` modulo ``O(x**prec)``.

    Notes
    =====

    Truncation of ``integral dx p**-1*d p/dx`` is used.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_log
    >>> R, x = ring('x', QQ)
    >>> rs_log(1 + x, x, 8)
    1/7*x**7 - 1/6*x**6 + 1/5*x**5 - 1/4*x**4 + 1/3*x**3 - 1/2*x**2 + x
    >>> rs_log(x**QQ(3, 2) + 1, x, 5)
    1/3*x**(9/2) - 1/2*x**3 + x**(3/2)
    rG   r   rÞ   )rE   rY   Úrs_logr   r$   r“   rß   r    r   r   rO   r   rC   Úadd_gensÚset_ringr   Údiffro   rŸ   rÆ   r¨   )r,   r<   r=   r+   r’   rá   rà   Údlogs           r1   rã   rã   é  sÎ  € õ* �Q˜ÑÔð .Ý�& ! Q¨Ñ-Ô-Ð-Ø	Œ€AØˆA‚v€vØŒvˆÝ˜1˜aÑ Ô €AØñ "ØˆØ�Š6ˆ6Ùà—Y’Y‘[”[ˆFØŒx�2ˆ~ˆ~Ý˜F™œ��Ý˜A�{Ñ+Ô+ð (ð+Ø˜A�c &™kœk™NœN�E�EøÝ!ð +ð +ð +ØŸ
š
¥C¨¡K¤K =Ñ1Ô1�AØŸ
š
 1™œ�AØŸ
š
 1™œ�AØŸ
š
 1™œ�AØ˜A�c &™kœk™NœN�E�E�Eð+øøøð(Ø˜A�c !™fœf™IœI�E�EøÝ!ð (ð (ð (Ý%ð ''ñ (ô (ð (ð(øøøð �vŠv�a‰yŒyˆÝ�dÕ.¨q°!°TÑ:Ô:¸A¸tÀa¹xÑHÔHˆÝ˜D !Ñ$Ô$ uÑ,Ð,å!Ð!s   Â!B: Â:BEÅ EÅE ÅE8c                 óÀ  — t          | |¦  «        rt          t          | ||¦  «        S | j        } |d¦  «        }t	          | |¦  «        rt          d¦  «        ‚||j        v rwt          |¦  «        D ]e}t          |||¦  «        }t          ||||¦  «        | z
  }t          ||dz   ||¦  «        }t          |||¦  «        }t          ||||¦  «        }	||	z  }Œf|S t
          ‚)a£  
    Calculate the series expansion of the principal branch of the Lambert W
    function.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_LambertW
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_LambertW(x + x*y, x, 3)
    -x**2*y**2 - 2*x**2*y - x**2 + x*y + x

    See Also
    ========

    LambertW
    r   z>Polynomial must not have constant term in the series variablesrG   )rE   rY   Úrs_LambertWr   r�   r¨   r:   r8   Úrs_expro   r~   )
r,   r<   r=   r+   r(   r¢   ra   rj   Úp3rÛ   s
             r1   ré   ré   "  s  € õ( �Q˜ÑÔð 3Ý�+ q¨!¨TÑ2Ô2Ð2Ø	Œ€AØ	
ˆˆ1‰Œ€BÝ˜!˜QÑÔð :Ý!ð #9ñ :ô :ð 	:àˆAŒF€{€{Ý! $Ñ'Ô'ð 	ð 	ˆEÝ�r˜1˜eÑ$Ô$ˆAÝ˜˜2˜q %Ñ(Ô(¨1Ñ,ˆBÝ˜˜2 ™6 1 eÑ,Ô,ˆBÝ$ R¨¨EÑ2Ô2ˆBÝ˜˜R  EÑ*Ô*ˆCØ�#‰IˆBˆBØˆ	å!Ð!r3   c                 ó¤   — | j         } |d¦  «        }t          |¦  «        D ]-}| t          |||¦  «        z
  }t          ||||¦  «        }||z  }Œ.|S )zHelper function for `rs\_exp`. rG   )r   r8   rã   ro   )r,   r<   r=   r+   r(   r¢   ÚptrÛ   s           r1   Ú_exp1rî   I  sf   € à	Œ€AØ	
ˆˆ1‰Œ€BÝ˜dÑ#Ô#ð ð ˆØ•˜˜A˜uÑ%Ô%Ñ%ˆÝ�R˜˜Q Ñ&Ô&ˆØ
ˆc‰	ˆˆØ€Ir3   c                 ó  — t          | |¦  «        rt          t          | ||¦  «        S | j        }t	          | |¦  «        }|�rP|j        t          u r%|                     ¦   «         }t          |¦  «        }�nt          |t          ¦  «        r¸	 |                     ¦   «         } |t          |¦  «        ¦  «        }nÁ# t          $ r} |                     t          |¦  «        g¦  «        }|                      |¦  «        } |                     |¦  «        }|                     |¦  «        } |t          |¦  «        ¦  «        }Y n;w xY w	  |t          |¦  «        ¦  «        }n# t          $ r t          d¦  «        ‚w xY w| |z
  }|t          |||¦  «        z  S t          | ¦  «        dk    rt!          | ||¦  «        S  |d¦  «        }d}	g }t#          |¦  «        D ]$}
|                     ||	z  ¦  «         |
dz  }
|	|
z  }	Œ%t'          | |||¦  «        }|S )a:  
    Exponentiation of a series modulo ``O(x**prec)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_exp
    >>> R, x = ring('x', QQ)
    >>> rs_exp(x**2, x, 7)
    1/6*x**6 + 1/2*x**4 + x**2 + 1
    rÞ   r³   rG   )rE   rY   rê   r   r“   r    r   rß   r   rO   r   rC   rä   rå   r   rs   rî   rr   r·   rÀ   )r,   r<   r=   r+   r’   rà   rá   r(   r¡   rT   rD   rX   s               r1   rê   rê   S  s  € õ �Q˜ÑÔð .Ý�& ! Q¨Ñ-Ô-Ð-Ø	Œ€AÝ˜1˜aÑ Ô €AØñ )ØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFÝ˜‘K”KˆE‰EÝ˜�;Ñ'Ô'ð 	$ð'ØŸš™œ�Ø˜�#˜f™+œ+™œ��øÝð 'ð 'ð 'Ø—J’J¥ F¡¤˜}Ñ-Ô-�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M�Ø˜�#˜f™+œ+™œ���ð'øøøð$Ø˜�#˜a™&œ&™	œ	��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð �‰Uˆð •V˜B  4Ñ(Ô(Ñ(Ð(å
ˆ1�v„v�‚{€{Ý�Q˜˜4Ñ Ô Ð Ø
ˆ!ˆA‰$Œ$€CØ	€AØ
€AÝ�4‰[Œ[ð ð ˆØ	�Š��Q‘‰ŒˆØ	ˆQ‰ˆØ	ˆQ‰ˆˆå˜A˜q ! TÑ*Ô*€AØ€Hs   Â,B8 Â8BD?Ä>D?ÅE ÅE6c                 ó  — | j         } |d¦  «        }| g}t          | ||¦  «        }t          d|¦  «        D ]#}|                     ||z  d|z  dz   z  ¦  «         Œ$t	          ||||¦  «        }t          || ||¦  «        }|S )zS
    Expansion using formula.

    Faster on very small and univariate series.
    r´   rG   r5   ©r   ry   rr   r·   rÀ   ro   )	r,   rb   r=   r+   Úmor’   rj   rD   r¹   s	            r1   Ú_atanró   Œ  s™   € ð 	
Œ€AØ	
ˆˆ2‰Œ€BØ
ˆˆ€AÝ	�1�b˜$Ñ	Ô	€BÝ�1�d‰^Œ^ð "ð "ˆØ	�Š��Q‘˜˜!™˜a™‘Ñ!Ô!Ð!Ð!Ý˜B  2 tÑ,Ô,€AÝˆq�!�R˜ÑÔ€AØ€Hr3   c                 ó  — t          | |¦  «        rt          t          | ||¦  «        S | j        }d}t	          | |¦  «        rØ|j        }| |         }|j        t          u r$|                     ¦   «         }t          |¦  «        }n—t          |t          ¦  «        rK	 |                     ¦   «         } |t          |¦  «        ¦  «        }nT# t          $ r t          d¦  «        ‚w xY w	  |t          |¦  «        ¦  «        }n# t          $ r t          d¦  «        ‚w xY w|                      |¦  «        }t          | ||¦  «         |d¦  «        z   }	t!          |	||dz
  ¦  «        }	t#          ||	||dz
  ¦  «        }	t%          |	|¦  «        |z   S )a®  
    The arctangent of a series

    Return the series expansion of the atan of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_atan
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_atan(x + x*y, x, 4)
    -1/3*x**3*y**3 - x**3*y**2 - x**3*y - 1/3*x**3 + x*y + x

    See Also
    ========

    atan
    r   rÞ   rG   )rE   rY   Úrs_atanr   r�   rŒ   r    r   rß   r   rO   r   rC   r   ræ   ry   r~   ro   rÆ   ©
r,   r<   r=   r+   rá   r�   r’   rà   Údpr(   s
             r1   rõ   rõ   œ  s¤  € õ* �Q˜ÑÔð /Ý�' 1 a¨Ñ.Ô.Ð.Ø	Œ€AØ€EÝ˜!˜QÑÔð $ØŒ\ˆØˆbŒEˆØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFÝ˜‘L”LˆEˆEÝ˜�;Ñ'Ô'ð 	$ð$ØŸš™œ�Ø˜�$˜v™,œ,™œ��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð$Ø˜�$˜q™'œ'™
œ
��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð 
�Š�‰Œ€BÝ	�1�a˜Ñ	Ô	   1¡¤Ñ	%€BÝ	˜R  D¨1¡HÑ	-Ô	-€BÝ	��B˜˜4 !™8Ñ	$Ô	$€BÝ˜˜AÑÔ Ñ&Ð&ó   Â,C ÃCÃ#C< Ã<Dc                 ó”  — t          | |¦  «        rt          t          | ||¦  «        S t          | |¦  «        rt	          d¦  «        ‚| j        }||j        v rìt          | ¦  «        dk    rat          | |¦  «        }dt          | ||dz
  ¦  «        z
  }t          |d||dz
  ¦  «        }t          ||||dz
  ¦  «        }t          ||¦  «        S  |d¦  «        }d|dg}t          d|d¦  «        D ]D}|                     |dz
  dz  |d         z  ||dz
  z  z  ¦  «         |                     d¦  «         ŒEt          | |||¦  «        S t          ‚)aŽ  
    Arcsine of a series

    Return the series expansion of the asin of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_asin
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_asin(x, x, 8)
    5/112*x**7 + 3/40*x**5 + 1/6*x**3 + x

    See Also
    ========

    asin
    z:Polynomial must not have constant term in series variablesr³   rG   rÉ   r   r{   r5   )rE   rY   Úrs_asinr�   r¨   r   r:   rs   rÄ   ry   r|   ro   rÆ   rr   r·   rÀ   )	r,   r<   r=   r+   r÷   r(   r¡   r’   rD   s	            r1   rú   rú   Ò  si  € õ* �Q˜ÑÔð /Ý�' 1 a¨Ñ.Ô.Ð.Ý˜!˜QÑÔð 6Ý!ð #5ñ 6ô 6ð 	6à	Œ€AØˆAŒF€{€{åˆq‰6Œ6�BŠ;ˆ;Ý˜˜A‘”ˆBØ•Y˜q ! T¨A¡XÑ.Ô.Ñ.ˆBÝ˜R  Q¨¨q©Ñ1Ô1ˆBÝ˜˜B  4¨!¡8Ñ,Ô,ˆBÝ  AÑ&Ô&Ð&Øˆa�‰dŒdˆØ��QˆKˆÝ�q˜$ Ñ"Ô"ð 	ð 	ˆAØ�HŠH�a˜!‘e˜a‘Z  "¤Ñ% q¨!¨a©%¡yÑ1Ñ2Ô2Ð2Ø�HŠH�Q‰KŒKˆKˆKÝ" 1 a¨¨DÑ1Ô1Ð1õ "Ð!r3   c           
      óÈ   — | j         } |d¦  «        }t          |¦  «        D ]?}| t          |||¦  «        z
  }t          |dt	          |||¦  «        z   ||¦  «        }||z  }Œ@|S )a�  
    Helper function of :func:`rs_tan`.

    Return the series expansion of tan of a univariate series using Newton's
    method. It takes advantage of the fact that series expansion of atan is
    easier than that of tan.

    Consider `f(x) = y - \arctan(x)`
    Let r be a root of f(x) found using Newton's method.
    Then `f(r) = 0`
    Or `y = \arctan(x)` where `x = \tan(y)` as required.
    r   rG   )r   r8   rõ   ro   ry   ©r,   r<   r=   r+   r(   r¢   rÛ   s          r1   Ú_tan1rý   ÿ  sy   € ð 	
Œ€AØ	
ˆˆ1‰Œ€BÝ˜dÑ#Ô#ð ð ˆØ•'˜"˜a Ñ'Ô'Ñ'ˆÝ�S˜!�i¨¨A¨uÑ5Ô5Ñ5°q¸%Ñ@Ô@ˆØ
ˆc‰	ˆˆØ€Ir3   c                 óä  — t          | |¦  «        rt          t          | ||¦  «        }|S | j        }d}t	          | |¦  «        }|�ry|j        t          u r%|                     ¦   «         }t          |¦  «        }�nt          |t          ¦  «        r¸	 |                     ¦   «         } |t          |¦  «        ¦  «        }nÁ# t          $ r} |                     t          |¦  «        g¦  «        }|                      |¦  «        } |                     |¦  «        }|                     |¦  «        } |t          |¦  «        ¦  «        }Y n;w xY w	  |t          |¦  «        ¦  «        }n# t          $ r t          d¦  «        ‚w xY w| |z
  }t          |||¦  «        }	t          d||	z  z
  ||¦  «        }
t!          ||	z   |
||¦  «        S |j        dk    rt%          | ||¦  «        S t'          | t          ||¦  «        S )a¦  
    Tangent of a series.

    Return the series expansion of the tan of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_tan
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_tan(x + x*y, x, 4)
    1/3*x**3*y**3 + x**3*y**2 + x**3*y + 1/3*x**3 + x*y + x

   See Also
   ========

   _tan1, tan
   r   rÞ   rG   )rE   rY   Úrs_tanr   r“   r    r   rß   r   rO   r   rC   rä   rå   r   r~   ro   rh   rý   rÒ   )r,   r<   r=   rX   r+   rá   r’   rà   r(   Út2r£   s              r1   rÿ   rÿ     só  € õ* �Q˜ÑÔð Ý•v˜q ! TÑ*Ô*ˆØˆØ	Œ€AØ€EÝ˜1˜aÑ Ô €AØñ .ØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFÝ˜‘K”KˆE‰EÝ˜�;Ñ'Ô'ð 	$ð'ØŸš™œ�Ø˜�#˜f™+œ+™œ��øÝð 'ð 'ð 'Ø—J’J¥ F¡¤˜Ñ/Ô/�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M�Ø˜�#˜f™+œ+™œ���ð'øøøð$Ø˜�#˜a™&œ&™	œ	��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð �‰Uˆõ �B˜˜4Ñ Ô ˆÝ  E¨"¡H¡¨a°Ñ6Ô6ˆÝ�e˜b‘j ! Q¨Ñ-Ô-Ð-à„w�!‚|€|Ý�Q˜˜4Ñ Ô Ð å�a�  DÑ)Ô)Ð)s   Â,B< Â<BEÅEÅE  Å E:c                 óh  — t          | |¦  «        rt          t          | ||¦  «        }|S t          | |d¦  «        \  }}|d|z  z   }t	          | ||¦  «        \  }}t          ||| ¦  «        }t          |||¦  «        }t          ||||¦  «        }	t          |	|| ¦  «        }	t          |	||¦  «        }	|	S )a�  
    Cotangent of a series

    Return the series expansion of the cot of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_cot
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_cot(x, x, 6)
    -2/945*x**5 - 1/45*x**3 - 1/3*x + x**(-1)

    See Also
    ========

    cot
    Úcotr5   )	rE   rY   Úrs_cotrœ   Ú
rs_cos_sinr§   r~   ro   r@   )
r,   r<   r=   rX   r>   r›   Úprec1r’   r¹   r7   s
             r1   r  r  P  sÅ   € õ. �Q˜ÑÔð Ý•v˜q ! TÑ*Ô*ˆØˆÝ˜Q  5Ñ)Ô)�D€A€qØ�1�Q‘3‰J€EÝ�a˜˜EÑ"Ô"�D€A€qÝ��1�q�bÑÔ€AÝ˜A˜q %Ñ(Ô(€AÝ
��A�q˜%Ñ
 Ô
 €CÝ
�#�q˜1˜"Ñ
Ô
€CÝ
�3˜˜4Ñ
 Ô
 €CØ€Jr3   c                 óî  — t          | |¦  «        rt          t          | ||¦  «        S |j        }| s |d¦  «        S t	          | |¦  «        }|�rÊ|j        t          u r4|                     ¦   «         }t          |¦  «        t          |¦  «        }}�nZt          |t          ¦  «        rö	 |                     ¦   «         } |t          |¦  «        ¦  «         |t          |¦  «        ¦  «        }}nÿ# t          $ r£ |                     t          |¦  «        t          |¦  «        g¦  «        }|                      |¦  «        } |                     |¦  «        }|                     |¦  «        } |t          |¦  «        ¦  «         |t          |¦  «        ¦  «        }}Y nSw xY w	  |t          |¦  «        ¦  «         |t          |¦  «        ¦  «        }}n# t          $ r t          d¦  «        ‚w xY w| |z
  }t          |||¦  «        |z  t!          |||¦  «        |z  z   S t#          | ¦  «        dk    rY|j        dk    rNt'          | dz  ||¦  «        }	t)          |	||¦  «        }t+          d|z   ||¦  «        }t-          |d|	z  ||¦  «        S  |d¦  «        }
d}dg}t/          d|dz   d¦  «        D ];}|                     |
|z  ¦  «         |                     d¦  «         || |dz   z  z  }Œ<t3          | |||¦  «        S )a#  
    Sine of a series

    Return the series expansion of the sin of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_sin
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_sin(x + x*y, x, 4)
    -1/6*x**3*y**3 - 1/2*x**3*y**2 - 1/2*x**3*y - 1/6*x**3 + x*y + x
    >>> rs_sin(x**QQ(3, 2) + x*y**QQ(7, 5), x, 4)
    -1/2*x**(7/2)*y**(14/5) - 1/6*x**3*y**(21/5) + x**(3/2) + x*y**(7/5)

    See Also
    ========

    sin
    r   rÞ   r³   rG   r5   )rE   rY   Úrs_sinr   r“   r    r   rß   r   r   rO   r   rC   rä   rå   r   Úrs_cosrs   rh   rÿ   ry   r~   ro   rr   r·   rÀ   )r,   r<   r=   r+   r’   rà   Út1r   r(   r£   r¡   rT   rD   s                r1   r  r  t  só  € õ. �Q˜ÑÔð .Ý�& ! Q¨Ñ-Ô-Ð-Ø	Œ€AØð Øˆq�‰tŒtˆÝ˜1˜aÑ Ô €AØñ ?ØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFÝ˜‘[”[¥# f¡+¤+�ˆB‰BÝ˜�;Ñ'Ô'ð 	$ð8ØŸš™œ�Ø˜�3˜v™;œ;™œ¨¨­3¨v©;¬;©¬�B��øÝð 8ð 8ð 8Ø—J’J¥ F¡¤­S°©[¬[Ð9Ñ:Ô:�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M�Ø˜�3˜v™;œ;™œ¨¨­3¨v©;¬;©¬�B���ð8øøøð$Ø˜�3˜q™6œ6™œ A A¥c¨!¡f¤f¡I¤I�B��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð �‰Uˆõ �b˜!˜TÑ"Ô" 2Ñ%­¨r°1°dÑ(;Ô(;¸BÑ(>Ñ>Ð>õ ˆ1�v„v�‚{€{�q”w !’|�|Ý�1�Q‘3˜˜4Ñ Ô ˆÝ�q˜!˜TÑ"Ô"ˆÝ   R¡¨¨DÑ1Ô1ˆÝ�b˜!˜A™#˜q $Ñ'Ô'Ð'Ø
ˆ!ˆA‰$Œ$€CØ	€AØ	
ˆ€AÝ�1�d˜Q‘h Ñ"Ô"ð ð ˆØ	�Š��Q‘‰ŒˆØ	�Š�‰ŒˆØ	ˆaˆR��Q‘‰Z‰ˆˆÝ˜q ! Q¨Ñ-Ô-Ð-s    Â'AC, Ã,B*FÆFÆ0G ÇG(c                 ó’  — t          | |¦  «        rt          t          | ||¦  «        S | j        }t	          | |¦  «        }|�r*|j        t          u r4|                     ¦   «         }t          |¦  «        t          |¦  «        }}�n*t          |t          ¦  «        rÆ	 |                     ¦   «         } |t          |¦  «        ¦  «         |t          |¦  «        ¦  «        }}nÏ# t          $ rs |                     t          |¦  «        t          |¦  «        g¦  «        }|                      |¦  «        } |                     |¦  «        }|                     |¦  «        }Y nSw xY w	  |t          |¦  «        ¦  «         |t          |¦  «        ¦  «        }}n# t          $ r t          d¦  «        ‚w xY w| |z
  }t          |||¦  «        }t!          |||¦  «        }	|                     |j        ¦  «                             |	j        ¦  «        }|                     |¦  «         |	                     |¦  «          |t          |¦  «        ¦  «         |t          |¦  «        ¦  «        }}
||z  |	|
z  z
  S t%          | ¦  «        dk    rY|j        dk    rNt)          | dz  ||¦  «        }t+          |||¦  «        }t-          d|z   ||¦  «        }t/          |d|z
  ||¦  «        S  |d¦  «        }d}g }t1          d|dz   d¦  «        D ];}|                     ||z  ¦  «         |                     d¦  «         || |dz
  z  z  }Œ<t5          | |||¦  «        S )aù  
    Cosine of a series

    Return the series expansion of the cos of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_cos
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_cos(x + x*y, x, 4)
    -1/2*x**2*y**2 - x**2*y - 1/2*x**2 + 1
    >>> rs_cos(x + x*y, x, 4)/x**QQ(7, 5)
    -1/2*x**(3/5)*y**2 - x**(3/5)*y - 1/2*x**(3/5) + x**(-7/5)

    See Also
    ========

    cos
    rÞ   r³   rG   r5   r   )rE   rY   r  r   r“   r    r   rß   r   r   rO   r   rC   rä   rå   r   r  Úcomposers   rh   rÿ   ry   r~   ro   rr   r·   rÀ   )r,   r<   r=   r+   r’   rà   Ú_r(   Úp_cosÚp_sinr	  r   r£   r¡   rT   rD   s                   r1   r  r  º  s+  € õ. �Q˜ÑÔð .Ý�& ! Q¨Ñ-Ô-Ð-Ø	Œ€AÝ˜1˜aÑ Ô €AØñ #ØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFÝ�v‘;”;¥ F¡¤ˆqˆA‰AÝ˜�;Ñ'Ô'ð 	$ð"ØŸš™œ�Ø�q�˜V™œ‘~”~ q q­¨V©¬¡~¤~�1��øÝð "ð "ð "Ø—J’J¥ F¡¤­S°©[¬[Ð9Ñ:Ô:�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M�Ø—J’J˜q‘M”M���ð	"øøøð$Ø�q�˜Q™œ‘y”y ! !¥C¨¡F¤F¡)¤)�1��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð �‰Uˆõ �r˜1˜dÑ#Ô#ˆÝ�r˜1˜dÑ#Ô#ˆØ�IŠI�e”jÑ!Ô!×)Ò)¨%¬*Ñ5Ô5ˆØ�Š�qÑÔÐØ�Š�qÑÔÐØ�•3�v‘;”;‘”  ¥3 v¡;¤;¡¤ˆBˆØ�R‰x˜% ™(Ñ"Ð"õ ˆ1�v„v�‚{€{�q”w !’|�|Ý�1�Q‘3˜˜4Ñ Ô ˆÝ�q˜!˜TÑ"Ô"ˆÝ   2¡ q¨$Ñ/Ô/ˆÝ�b˜!˜b™& ! TÑ*Ô*Ð*Ø
ˆ!ˆA‰$Œ$€CØ	€AØ
€AÝ�1�d˜Q‘h Ñ"Ô"ð ð ˆØ	�Š��Q‘‰ŒˆØ	�Š�‰ŒˆØ	ˆaˆR��Q‘‰Z‰ˆˆÝ˜q ! Q¨Ñ-Ô-Ð-s    ÂAC ÃA:EÅEÅ 0F ÆF+c                 ó  — t          | |¦  «        rt          t          | ||¦  «        S t          | dz  ||¦  «        }t	          |||¦  «        }t          d|z   ||¦  «        }t          |d|z
  ||¦  «        t          |d|z  ||¦  «        fS )zƒ
    Return the tuple ``(rs_cos(p, x, prec)`, `rs_sin(p, x, prec))``.

    Is faster than calling rs_cos and rs_sin separately
    r5   rG   )rE   rY   r  rÿ   ry   r~   ro   )r,   r<   r=   r£   r   r(   s         r1   r  r    s”   € õ �Q˜ÑÔð 2Ý�* a¨¨DÑ1Ô1Ð1Ýˆq�‰s�A�tÑÔ€AÝ	�1�a˜Ñ	Ô	€BÝ	˜Q ™V Q¨Ñ	-Ô	-€BÝ�2�q˜2‘v˜q $Ñ'Ô'­°°A°a±C¸¸DÑ)AÔ)AÐBÐBr3   c                 óü   — | j         } |d¦  «        }|g}t          | ||¦  «        }t          d|¦  «        D ] }|                     |d|z  dz   z  ¦  «         Œ!t	          ||||¦  «        }t          || ||¦  «        }|S )zR
    Expansion using formula

    Faster for very small and univariate series
    rG   r5   rñ   )	r,   r<   r=   r+   r¡   r’   rj   rD   r¹   s	            r1   Ú_atanhr    s“   € ð 	
Œ€AØ
ˆ!ˆA‰$Œ$€CØ	ˆ€AÝ	�1�a˜Ñ	Ô	€BÝ�1�d‰^Œ^ð  ð  ˆØ	�Š��a˜‘c˜A‘g‘ÑÔÐÐÝ˜B  1 dÑ+Ô+€AÝˆq�!�Q˜ÑÔ€AØ€Hr3   c                 óô  — t          | |¦  «        rt          t          | ||¦  «        S | j        }d}t	          | |¦  «        rØ|j        }| |         }|j        t          u r$|                     ¦   «         }t          |¦  «        }n—t          |t          ¦  «        rK	 |                     ¦   «         } |t          |¦  «        ¦  «        }nT# t          $ r t          d¦  «        ‚w xY w	  |t          |¦  «        ¦  «        }n# t          $ r t          d¦  «        ‚w xY wt          | |¦  «        }t          | ||¦  «         dz   }	t!          |	||dz
  ¦  «        }	t#          ||	||dz
  ¦  «        }	t%          |	|¦  «        |z   S )a¸  
    Hyperbolic arctangent of a series

    Return the series expansion of the atanh of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_atanh
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_atanh(x + x*y, x, 4)
    1/3*x**3*y**3 + x**3*y**2 + x**3*y + 1/3*x**3 + x*y + x

    See Also
    ========

    atanh
    r   rÞ   rG   )rE   rY   Úrs_atanhr   r�   rŒ   r    r   rß   r   rO   r   rC   r   rÄ   ry   r~   ro   rÆ   rö   s
             r1   r  r     sŸ  € õ* �Q˜ÑÔð 0Ý�( A q¨$Ñ/Ô/Ð/Ø	Œ€AØ€EÝ˜!˜QÑÔð $ØŒ\ˆØˆbŒEˆØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFÝ˜&‘M”MˆEˆEÝ˜�;Ñ'Ô'ð 	$ð$ØŸš™œ�Ø˜�% ™-œ-Ñ(Ô(��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð$Ø˜�% ™(œ(™œ��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøõ 
��A‰Œ€BÝ�Q˜˜4Ñ Ô Ð	  1Ñ	$€BÝ	˜R  D¨1¡HÑ	-Ô	-€BÝ	��B˜˜4 !™8Ñ	$Ô	$€BÝ˜˜AÑÔ Ñ&Ð&rø   c                 ó¤   — t          | |¦  «        rt          t          | ||¦  «        S t          | ||¦  «        }t	          |||¦  «        }||z
  dz  S )a¶  
    Hyperbolic sine of a series

    Return the series expansion of the sinh of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_sinh
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_sinh(x + x*y, x, 4)
    1/6*x**3*y**3 + 1/2*x**3*y**2 + 1/2*x**3*y + 1/6*x**3 + x*y + x

    See Also
    ========

    sinh
    r5   )rE   rY   Úrs_sinhrê   r~   ©r,   r<   r=   r£   r	  s        r1   r  r  V  óZ   € õ* �Q˜ÑÔð /Ý�' 1 a¨Ñ.Ô.Ð.Ýˆq�!�TÑÔ€AÝ	˜Q  4Ñ	(Ô	(€BØ�‰F�A‰:Ðr3   c                 ó¤   — t          | |¦  «        rt          t          | ||¦  «        S t          | ||¦  «        }t	          |||¦  «        }||z   dz  S )až  
    Hyperbolic cosine of a series

    Return the series expansion of the cosh of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_cosh
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_cosh(x + x*y, x, 4)
    1/2*x**2*y**2 + x**2*y + 1/2*x**2 + 1

    See Also
    ========

    cosh
    r5   )rE   rY   Úrs_coshrê   r~   r  s        r1   r  r  q  r  r3   c           
      óÈ   — | j         } |d¦  «        }t          |¦  «        D ]?}| t          |||¦  «        z
  }t          |dt	          |||¦  «        z
  ||¦  «        }||z  }Œ@|S )a  
    Helper function of :func:`rs_tanh`

    Return the series expansion of tanh of a univariate series using Newton's
    method. It takes advantage of the fact that series expansion of atanh is
    easier than that of tanh.

    See Also
    ========

    _tanh
    r   rG   )r   r8   r  ro   ry   rü   s          r1   Ú_tanhr  Œ  sy   € ð 	
Œ€AØ	
ˆˆ1‰Œ€BÝ˜dÑ#Ô#ð ð ˆØ•(˜2˜q %Ñ(Ô(Ñ(ˆÝ�S˜!�i¨¨A¨tÑ4Ô4Ñ4°a¸Ñ?Ô?ˆØ
ˆc‰	ˆˆØ€Ir3   c                 ó  — t          | |¦  «        rt          t          | ||¦  «        S | j        }d}t	          | |¦  «        �r|j        }| |         }|j        t          u r$|                     ¦   «         }t          |¦  «        }n—t          |t          ¦  «        rK	 |                     ¦   «         } |t          |¦  «        ¦  «        }nT# t          $ r t          d¦  «        ‚w xY w	  |t          |¦  «        ¦  «        }n# t          $ r t          d¦  «        ‚w xY w| |z
  }t          |||¦  «        }	t          d||	z  z   ||¦  «        }
t          ||	z   |
||¦  «        S |j        dk    rt#          | ||¦  «        S t%          | t"          ||¦  «        S )a²  
    Hyperbolic tangent of a series

    Return the series expansion of the tanh of ``p``, about 0.

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_tanh
    >>> R, x, y = ring('x, y', QQ)
    >>> rs_tanh(x + x*y, x, 4)
    -1/3*x**3*y**3 - x**3*y**2 - x**3*y - 1/3*x**3 + x*y + x

    See Also
    ========

    tanh
    r   rÞ   rG   )rE   rY   Úrs_tanhr   r�   rŒ   r    r   rß   r   rO   r   rC   r   r~   ro   rh   r  rÒ   )r,   r<   r=   r+   rá   r�   r’   rà   r(   r	  r£   s              r1   r  r  ¡  s²  € õ* �Q˜ÑÔð /Ý�' 1 a¨Ñ.Ô.Ð.Ø	Œ€AØ€EÝ˜!˜QÑÔñ .ØŒ\ˆØˆbŒEˆØŒ8•rˆ>ˆ>Ø—Y’Y‘[”[ˆFÝ˜‘L”LˆEˆEÝ˜�;Ñ'Ô'ð 	$ð$ØŸš™œ�Ø˜�$˜v™,œ,™œ��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð$Ø˜�$˜q™'œ'™
œ
��øÝð $ð $ð $Ý!ð ##ñ $ô $ð $ð$øøøð �‰UˆÝ�R˜˜DÑ!Ô!ˆÝ  E¨"¡H¡¨a°Ñ6Ô6ˆÝ�e˜b‘j ! Q¨Ñ-Ô-Ð-à„w�!‚|€|Ý�Q˜˜4Ñ Ô Ð å�a�  4Ñ(Ô(Ð(s   Â,C ÃC Ã$C= Ã=Dc                 óÈ   — |                       ¦   «         }t          | ¦  «        }t          |||¦  «        }t          |                     |¦  «        |||¦  «        }|||z  z
  }|S )aO  
    Compute the truncated Newton sum of the polynomial ``p``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_newton
    >>> R, x = ring('x', QQ)
    >>> p = x**2 - 2
    >>> rs_newton(p, x, 5)
    8*x**4 + 4*x**2 + 2
    )r#   r2   r~   ro   ræ   )r,   r<   r=   r*   r(   rj   rë   r7   s           r1   Ú	rs_newtonr  ×  s^   € ð �(Š(‰*Œ*€CÝ	˜Ñ	Ô	€BÝ	˜R  DÑ	)Ô	)€BÝ	�—’˜‘
”
˜B  4Ñ	(Ô	(€BØ
��1‘‰*€CØ€Jr3   Fc                 ó^  — | j         }|j        t          k    rt          ‚|j        }|sC|                      ¦   «         D ]-\  }}|t          t          |d         ¦  «        ¦  «        z  ||<   Œ.nB|                      ¦   «         D ]-\  }}|t          t          |d         ¦  «        ¦  «        z  ||<   Œ.|S )a»  
    Return ``sum f_i/i!*x**i`` from ``sum f_i*x**i``,
    where ``x`` is the first variable.

    If ``invers=True`` return ``sum f_i*i!*x**i``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_hadamard_exp
    >>> R, x = ring('x', QQ)
    >>> p = 1 + x + x**2 + x**3
    >>> rs_hadamard_exp(p)
    1/6*x**3 + 1/2*x**2 + x + 1
    r   )r   r    r   r¨   r$   r!   rB   r   )r(   Úinverser+   r,   r?   rl   s         r1   Úrs_hadamard_expr"  í  s±   € ð$ 	Œ€AØ„x•2‚~€~Ý!Ð!Ø	Œ€AØð ,ØŸš™
œ
ð 	,ð 	,‰HˆD�"Ø��T $ q¤'™]œ]Ñ+Ô+Ñ+ˆAˆd‰GˆGð	,ð Ÿš™
œ
ð 	,ð 	,‰HˆD�"Ø��T $ q¤'™]œ]Ñ+Ô+Ñ+ˆAˆd‰GˆGØ€Hr3   c                 óŠ  — | j         }|j        d         }|                      ¦   «         |                     ¦   «         z  dz   }t          | ||¦  «        }t	          |¦  «        }t          |||¦  «        }t	          |¦  «        }t          ||||¦  «        }	t	          |	d¦  «        }
|
d         |
z
  |z  }t          ||¦  «        }t          |||¦  «        }t          |¦  «        }| 	                    ¦   «         d         }|                      ¦   «         |                     ¦   «         z  |                     ¦   «         z
  }|r|||z  z  }|S )a}  
    compute the composed sum ``prod(p2(x - beta) for beta root of p1)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_compose_add
    >>> R, x = ring('x', QQ)
    >>> f = x**2 - 2
    >>> g = x**2 - 3
    >>> rs_compose_add(f, g)
    x**4 - 10*x**2 + 1

    References
    ==========

    .. [1] A. Bostan, P. Flajolet, B. Salvy and E. Schost
           "Fast Computation with Two Algebraic Numbers",
           (2002) Research Report 4579, Institut
           National de Recherche en Informatique et en Automatique
    r   rG   T)r   )
r   r:   r#   r  r"  ro   rÆ   rê   r2   Ú	primitive)r(   rj   r+   r<   r=   Únp1Únp1eÚnp2Únp2eÚnp3eÚnp3Únp3ar[   r÷   s                 r1   Úrs_compose_addr,    s'  € ð0 	Œ€AØ	ŒˆqŒ	€AØ�9Š9‰;Œ;�r—y’y‘{”{Ñ" QÑ&€DÝ
�B˜˜4Ñ
 Ô
 €CÝ˜3ÑÔ€DÝ
�B˜˜4Ñ
 Ô
 €CÝ˜3ÑÔ€DÝ�$˜˜a Ñ&Ô&€DÝ
˜$ Ñ
%Ô
%€CØ�ŒI˜‰O˜QÑ€DÝ�T˜1ÑÔ€AÝˆq�!�TÑÔ€AÝ�qÑÔ€AØ	�Š‰Œ�aÔ€AØ	�Š‰Œ�R—Y’Y‘[”[Ñ	  1§8¢8¡:¤:Ñ	-€Bð 
ð Øˆa�‰e‰GˆØ€Hr3   r  r  rê   rÿ   rã   )r   r   r   r   r   c                 óÞ   ‡— d}d}|dk    rt          | |||¦  «        }|dz  }|dk    °|j        } ||¦  «        }|j                             |¦  «        Št	          |ˆfd„¬¦  «        ‰         S )z=Find the minimum power of `a` in the series expansion of exprr   r5   c                 ó   •— | ‰         S r–   rI   )r£   r>   s    €r1   rc   zrs_min_pow.<locals>.<lambda>P  s   ø€  Q q¤T€ r3   rd   )Ú
_rs_seriesr   r:   r;   r™   )ÚexprÚ	series_rsrŽ   ÚseriesrT   r+   r>   s         @r1   Ú
rs_min_powr3  F  s‚   ø€ à€FØ	€AØ
�AŠ+ˆ+Ý˜D )¨Q°Ñ2Ô2ˆØ	ˆQ‰ˆð �AŠ+ˆ+ð 	Œ€AØ	ˆˆ!‰Œ€AØ	Œ�Š�Q‰Œ€AÝˆv˜>˜>˜>˜>Ð*Ñ*Ô*¨1Ô-Ð-r3   c                 óæ  ‡— | j         }|j        Št          d„ |D ¦   «         ¦  «        s	| j        s|S |                      |¦  «        s|S | j        rÓ|d         }t          |¦  «        dk    rt          ‚t          |t          dd¬¦  «        \  }}t          ||||¦  «        }‰ 
                    |¦  «         
                    |j        ¦  «        Š|                     ‰¦  «        } t          t          t          | j        ¦  «                 ¦  «        | ‰|¦  «        |¦  «        }|S | j        �rJt          |¦  «        }	|D ]3}|j        s*t          |dd¬¦  «        \  }}
‰ 
                    |¦  «        ŠŒ4t%          t'          t(          |ˆfd„|D ¦   «         |gt          |¦  «        z  ¦  «        ¦  «        }t+          |¦  «        } ‰d¦  «        }t-          |	¦  «        D ]~}t          ||          ‰||         ¦  «        |||z
  ||         z   ¦  «        }‰ 
                    |j        ¦  «        Š|                     ‰¦  «        }|                     ‰¦  «        }||z  }Œt/          | ‰|¦  «        |¦  «        }|S | j        ržt          |¦  «        }	 ‰d¦  «        }t-          |	¦  «        D ]r}t          ||          ‰||         ¦  «        ||¦  «        }‰ 
                    |j        ¦  «        Š|                     ‰¦  «        }|                     ‰¦  «        }||z  }Œs|S | j        r„t          | j        t          dd¬¦  «        \  }}
‰ 
                    |¦  «        Št          | j         ‰| j        ¦  «        ||¦  «        }t7          || j        |                     |¦  «        |¦  «        S t;          | t<          ¦  «        r2|                      ¦   «         rt          | t          dd¬¦  «        d         S t          ‚)	Nc              3   óJ   K  — | ]}|                      t          ¦  «        V — Œd S r–   )Úhasr   )rK   Úargs     r1   ú	<genexpr>z_rs_series.<locals>.<genexpr>Z  s.   è è € Ð1Ð1 Sˆs�wŠw•xÑ Ô Ð1Ð1Ð1Ð1Ð1Ð1r3   r   rG   FT©r    Úexpandr2  )r:  r2  c                 ó&   •— g | ]} ‰|¦  «        ‘ŒS rI   rI   )rK   r7  r+   s     €r1   rN   z_rs_series.<locals>.<listcomp>€  s!   ø€ Ð.FÐ.FÐ.F¸#¨q¨q°©v¬vÐ.FÐ.FÐ.Fr3   ) rÌ   r   ÚanyÚis_Functionr6  rs   r¨   r   r   r/  r  rå   ÚevalÚ_convert_funcrÊ   ÚfuncÚis_MulÚ	is_Numberr    Úmapr3  Úsumrr   r@   Úis_AddÚis_PowÚbaser}   r   rO   r   Úis_constant)r0  r1  rŽ   r=   rÌ   r7  rÎ   r2  Úseries_innerrT   r  Úmin_powsÚsum_powsr>   Ú_seriesr+   s                  @r1   r/  r/  S  sè  ø€ ð Œ9€DØŒ€Aõ Ð1Ð1¨DÐ1Ñ1Ô1Ñ1Ô1ð ¸$Ô:Jð ØÐà�8Š8�A‰;Œ;ð I"ØÐà	Ô	ð F"Ø�1ŒgˆÝˆt‰9Œ9�qŠ=ˆ=Ý%Ð%Ý˜3¥r°%ÀÐEÑEÔE‰
ˆˆFÝ! # v¨q°$Ñ7Ô7ˆð �IŠI�b‰MŒM×!Ò! ,Ô"3Ñ4Ô4ˆØ#×,Ò,¨QÑ/Ô/ˆØ4••m¥C¨¬	¡N¤NÔ3Ñ4Ô4°\ØˆAˆa‰DŒD�$ñô ˆàˆà	Œñ ,"Ý�‰IŒIˆØð 	"ð 	"ˆCØ”=ð "Ý˜c¨%¸Ð=Ñ=Ô=‘��AØ—I’I˜b‘M”M�øÝ��J¨Ð.FÐ.FÐ.FÐ.FÀÐ.FÑ.FÔ.FØˆC•�D‘	”	‰Mñô ñ ô ˆå�x‘=”=ˆØ��1‘”ˆå�q‘”ð 	ð 	ˆAÝ   a¤¨!¨!¨D°¬G©*¬*°a¸À¹Ø˜”ñ:ñ ô ˆGà—	’	˜'œ,Ñ'Ô'ˆAØ×&Ò& qÑ)Ô)ˆGØ—_’_ QÑ'Ô'ˆFØ�gÑˆFˆFÝ˜& ! ! A¡$¤$¨Ñ-Ô-ˆØˆà	Œð "Ý�‰IŒIˆØ��1‘”ˆÝ�q‘”ð 	ð 	ˆAÝ   a¤¨!¨!¨D°¬G©*¬*°a¸Ñ>Ô>ˆGØ—	’	˜'œ,Ñ'Ô'ˆAØ×&Ò& qÑ)Ô)ˆGØ—_’_ QÑ'Ô'ˆFØ�gÑˆFˆFØˆà	Œð "Ý�d”i­°5ÀÐFÑFÔF‰ˆˆAØ�IŠI�b‰MŒMˆÝ! $¤)¨Q¨Q¨t¬y©\¬\¸1¸dÑCÔCˆÝ�l D¤H¨l×.?Ò.?ÀÑ.BÔ.BÀDÑIÔIÐIõ 
�D�$Ñ	Ô	ð " D×$4Ò$4Ñ$6Ô$6ð "Ý�T¥"¨U¸4Ð@Ñ@Ô@ÀÔCÐCõ "Ð!r3   c                 óª  — t          | t          dd¬¦  «        \  }}||j        vr|                     |g¦  «        }|                     |¦  «        }t          | |||¦  «        }|j        } ||¦  «        }|                     |¦  «        dz   }||k    rt          |||¦  «        S t          dd¦  «        D ]î}t          | ||||z   ¬¦  «        }|                     |j        ¦  «        }|                     |¦  «        dz   }	|	|k    r�t          |||z
  |z  |	|z
  z  z   ¦  «        }
t          | |||
¬¦  «        }|                     |¦  «        dz   |k     rNt          | |||
¬¦  «        }|                     |j        ¦  «        }|
dz  }
|                     |¦  «        dz   |k     °N n$ n"t          dt          |¦  «        ›d	| ›�¦  «        ‚t          |||¦  «        S )
a+  Return the series expansion of an expression about 0.

    Parameters
    ==========

    expr : :class:`Expr`
    a : :class:`Symbol` with respect to which expr is to be expanded
    prec : order of the series expansion

    Currently supports multivariate Taylor series expansion. This is much
    faster that SymPy's series method as it uses sparse polynomial operations.

    It automatically creates the simplest ring required to represent the series
    expansion through repeated calls to sring.

    Examples
    ========

    >>> from sympy.polys.ring_series import rs_series
    >>> from sympy import sin, cos, exp, tan, symbols, QQ
    >>> a, b, c = symbols('a, b, c')
    >>> rs_series(sin(a) + exp(a), a, 5)
    1/24*a**4 + 1/2*a**2 + 2*a + 1
    >>> series = rs_series(tan(a + b)*cos(a + c), a, 2)
    >>> series.as_expr()
    -a*sin(c)*tan(b) + a*cos(c)*tan(b)**2 + a*cos(c) + cos(c)*tan(b)
    >>> series = rs_series(exp(a**QQ(1,3) + a**QQ(2, 5)), a, 1)
    >>> series.as_expr()
    a**(11/15) + a**(4/5)/2 + a**(2/5) + a**(2/3)/2 + a**(1/3) + 1

    FTr9  rG   é	   )r=   r5   zCould not calculate z terms for )r   r   Úsymbolsrä   rå   r/  r   r#   r@   rr   r   rC   rÊ   )r0  rŽ   r=   r+   r2  ÚgenÚprec_gotÚmorer(   Únew_precÚprec_dos              r1   Ú	rs_seriesrU  ¨  s  € õ@ �d¥2¨e¸DÐAÑAÔA�I€A€vØ�”	ÐÐØ�JŠJ˜�uÑÔˆØ�_Š_˜QÑÔ€FÝ˜˜f a¨Ñ.Ô.€FØŒ€AØ
ˆ!ˆA‰$Œ$€CØ�}Š}˜SÑ!Ô! AÑ%€Hà�4ÒÐÝ˜  TÑ*Ô*Ð*õ ˜!˜Q‘K”Kð 	2ð 	2ˆDÝ˜D &¨!°$¸±+Ð>Ñ>Ô>ˆBØ—,’,˜rœwÑ'Ô'ˆCØ—y’y ‘~”~¨Ñ)ˆHØ˜8Ò#Ð#Ý! $¨$°©/¸4Ñ)?ÀØñBñ *ñ #ñ ô �å  f¨a°gÐ>Ñ>Ô>�Ø—i’i ‘n”n qÑ(¨4Ò/Ð/Ý# D¨&°!¸'ÐBÑBÔB�BØŸ,š, r¤wÑ/Ô/�CØ˜q‘L�Gð —i’i ‘n”n qÑ(¨4Ò/Ð/ð �à�å�*Ý # D¡	¤	 	 	¨4¨4ð1ñ 2ô 2ð 2å˜˜C Ñ&Ô&Ð&r3   )rG   )F)ZÚ__doc__Úsympy.polys.domainsr   r   Úsympy.polys.ringsr   r   r   Úsympy.polys.polyerrorsr   Úsympy.polys.monomialsr	   r
   r   r   Úmpmath.libmp.libintmathr   Ú
sympy.corer   r   r   Úsympy.core.numbersr   Úsympy.core.intfuncr   Úsympy.functionsr   r   r   r   r   r   r   r   r   Úsympy.utilities.miscr   r   rµ   r2   r8   r@   rE   rY   r\   ro   ry   r}   r‰   r�   r“   rœ   rŸ   r~   r«   r±   rÀ   rÄ   rÆ   rÒ   r§   rJ   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?  r3  r/  rU  rI   r3   r1   ú<module>ra     s±  ðð)ð )ðV 'Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø .Ð .Ð .Ð .Ð .Ð .ð2ð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2à (Ð (Ð (Ð (Ð (Ð (Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø #Ð #Ð #Ð #Ð #Ð #Ø OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø /Ð /Ð /Ð /Ð /Ð /Ø €€€ðð ð ð>ð ð ðð ð ð6ð ð ð2%ð %ð %ðNð ð ð21ð 1ð 1ðf&ð &ð &ðP4ð 4ð 4ðlBð Bð BðHð ð ð4ð ð ð&ð ð ð,ð ,ð ,ð\$ð $ð $ðLð ð ðFð Fð FðPWð Wð Wð Wðrð ð ð@ð ð ð@6ð 6ð 6ðpð ð ðð ð ð&!/ð !/ð !/ðFJð Jð JðX7"ð 7"ð 7"ðr%"ð %"ð %"ðNð ð ð7ð 7ð 7ðrð ð ð 4'ð 4'ð 4'ðl+"ð +"ð +"ðZð ð ð*:*ð :*ð :*ðx"ð "ð "ðHD.ð D.ð D.ðLG.ð G.ð G.ðRCð Cð Cðð ð ð 4'ð 4'ð 4'ðlð ð ð6ð ð ð6ð ð ð*4)ð 4)ð 4)ðlð ð ð,ð ð ð ð<0ð 0ð 0ðh ØØØØð
ð 
€ð
.ð 
.ð 
.ðS"ð S"ð S"ðjB'ð B'ð B'ð B'ð B'r3   