o
    oh                     @   sx  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d Z'dd Z(dd Z)dd Z*dd Z+dd Z,dd Z-dd Z.dd Z/d d! Z0d"d# Z1d$d% Z2d&d' Z3d(d) Z4d*d+ Z5d,d- Z6d.d/ Z7dud1d2Z8d3d4 Z9d5d6 Z:d7d8 Z;d9d: Z<d;d< Z=d=d> Z>d?d@ Z?dAdB Z@dCdD ZAdEdF ZBdGdH ZCdIdJ ZDdKdL ZEdMdN ZFdOdP ZGdQdR ZHdSdT ZIdUdV ZJdWdX ZKdYdZ ZLd[d\ ZMd]d^ ZNd_d` ZOdadb ZPdcdd ZQdedf ZRdgdh ZSdvdjdkZTdldm ZUdVdXdHdRdBdnZVdodp ZWdqdr ZXdsdt ZYdS )wa9  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           	      C   sb   t |  }|  |  }| j}|j}|  }|  }t||D ]\}}||||d  f< q!|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cvi r/   k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/polys/ring_series.py_invert_monoms;   s   r1   c                 C   s$   t d| }|d dkrdg| }|S )z8Return a list of precision steps for the Newton's method   r   r   )targetresr/   r/   r0   _giant_stepsZ   s   

r5   c                 C   s@   | j }|j}|j|}| D ]}|| |krq| | ||< q|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exp1r/   r/   r0   rs_trunca   s   r<   c                 C   sN   | j j|}| D ]}|| t|| kr dS || dk r$td| q	d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   r6   r7   int
ValueError)r*   r8   r7   kr/   r/   r0   rs_is_puiseux|   s   r@   c                    s   |j j| d}|D ]1}|  }t|tr(| \}}t|| t|| }q|t|kr<|j}t|| t|| }q|dkrot	| |}	| |	||| }
t
d|t|
trgt fdd|
D }
|
S t	|
 }
|
S | |||}
|
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                    s   g | ]}t | qS r/   )pow_xin).0rxr7   n1r/   r0   
<listcomp>   s    zrs_puiseux.<locals>.<listcomp>)r   r6   r7   
isinstancer   as_numer_denomr=   r   denominatorrB   r   tuple)fr*   r8   r9   nr?   powernumdenr&   rr/   rE   r0   
rs_puiseux   s,   


rR   c                 C   s   |j j|}d}|D ]-}|| }t|tr&| \}	}
||
 t||
 }q|t|kr8|j}
||
 t||
 }q|dkrYt	|||}| ||||| }t
d|}t	|||}|S | ||||}|S )z
    Return the puiseux series for `f(p, q, x, prec)`.

    To be used when function ``f`` is implemented only for regular series.
    rA   )r   r6   r7   rH   r   rI   r   r=   rJ   rB   r   )rL   r*   qr8   r9   r7   rM   r?   rN   rO   rP   r&   rQ   rF   r/   r/   r0   rs_puiseux2   s&   

rT   c                    sD  | j }|j}|j|j jks||j krtd|j| t|ts%td||j kr|j}t	|
 }|j fddd |jdkrn| 
 D ]&\}}	|D ]\}
}|d |
d  }||k rk|f}||d|	|  ||< qL qFn.|j}| 
 D ]&\}}	|D ]\}
}|  |
   |k r|||
}||d|	|  ||< q{ qu|  |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   r/   eivr/   r0   <lambda>       zrs_mul.<locals>.<lambda>keyrA   r   )r   r"   	__class__r>   r6   r7   rH   r   getr   r   r    ngensr	   
strip_zero)r&   p2r8   r9   r)   r*   r`   items2r;   v1exp2v2r   r	   r/   rY   r0   rs_mul   s>   


	
rh   c                    s  | j }|j}|j| |j}t|  }|j fddd |j}t	t
|D ]0}|| \}	}
t	|D ]#}|| \}}|	  |   |k rW||	|}||d|
|  ||< q4 q(|d}|j}|  D ]\}}d|   |k r|||}||d|d  ||< qe|  |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                    rU   rV   r/   rW   rY   r/   r0   r[     r\   zrs_square.<locals>.<lambda>r]   r   r2   )r   r"   r6   r7   r`   r   r   r    r	   rangelenimul_numrb   )r&   r8   r9   r)   r*   r`   r   r	   r:   r;   re   jrf   rg   r   expvve2r/   rY   r0   	rs_square  s2   


rp   c           
      C   s@  | j }t|tr3t|j}t|j}|dkr*t| |||}|dkr(t||||}|S t| |||}|S t|}|dkrE| rA|dS t	d|dk rWt| | ||} t
| ||S |dkrat| ||S |dkrkt| ||S |dkr|t| ||}t| |||S |d}		 |d@ rt| |	||}	|d8 }|s	 |	S t| ||} |d }q)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
    rA   r   z0**0 is undefinedr2      )r   rH   r   r=   r*   rS   rs_nth_rootrs_powr   r>   rs_series_inversionr<   rp   rh   )
r&   rM   r8   r9   r)   npnqr4   rc   r*   r/   r/   r0   rs   0  sJ   


rs   c                 C   sj  | j }|j}|d}t|D ]}|j| ||df< q|D ]}|| |||df< q|d}	t|  }
|
D ]|}|d}t|D ]i}|| }|dkrKq@||f|vrt|d\}}|dkrq||f|v rqt|||f |||||f< n-||d f|v rt	|||d f ||df |||||f< nt
||df ||||||f< t	||||f ||}q@|	|| |  7 }	q6|	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   rA   r2   )r   ra   ri   r6   r7   sortedkeysdivmodrp   rh   rs   )r*   rulesr8   r9   r)   ra   dr:   varr&   p_keysrm   rc   rN   rS   rQ   r/   r/   r0   rs_subsf  s6   (r~   c                 C   sV   | j }|j|}|j}dg|j }d||< t|}| D ]}t|||kr( dS q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   rA   TFr   r6   r7   
zero_monomra   rK   r   )r*   r8   r)   rZ   zmamivrm   r/   r/   r0   _has_constant_term  s   r   c           	      C   sh   | j }|j|}|j}dg|j }d||< t|}d}| D ]}t|||kr1|||| | i7 }q|S )zReturn 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   rA   r   )	r*   r8   r)   r:   r   r   r   crm   r/   r/   r0   _get_constant_term  s   r   c                    sB   | j j| t|  fddd  }|dk rtd|  |fS )Nc                       |   S Nr/   r?   r7   r/   r0   r[         z#_check_series_var.<locals>.<lambda>r]   r   z7Asymptotic expansion of %s around [oo] not implemented.)r   r6   r7   minr   )r*   r8   namemr/   r   r0   _check_series_var  s   r   c           
      C   s   t | |rtt| ||S | j}|j}| | }|t|kr t|}|| vr(tdt| | |r3td|d}|jt	u r>d}||krI|d| }n|d}t
|D ]}dt|| || }	|t||	|| }qQ|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 parametersrA   )r@   rR   _series_inversion1r   r   r=   r>   r   domainr   r5   rh   )
r*   r8   r9   r)   r   r   oner&   precxtr/   r/   r0   r     s*   

r   c                    s   | j }| |jkr
t|j}|j| t|  fddd  }|r,t|  | } || }|| vr4tdt	| | |  |rAtdt
| ||}|dkrRt| | }|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                    r   r   r/   r   r   r/   r0   r[   $  r   z%rs_series_inversion.<locals>.<lambda>r]   r   z>p - p[0] must not have a constant term in the series variablesr   )r   r"   ZeroDivisionErrorr   r6   r7   r   mul_xinNotImplementedErrorr   r   )r*   r8   r9   r)   r   r   rQ   r/   r   r0   rt     s"   
rt   c                 C   s^   |\}}| j }dg|j }|||< t|}|d}| D ]}|| |kr,| | |t||< q|S )z2Coefficient of `x_i**j` in p, where ``t`` = (i, j)r   )r   ra   rK   r
   )r*   r   r:   rl   r)   expv1r&   rm   r/   r/   r0   _coefficient_t3  s   r   c                 C   s   t | |rt| j}|j|}||}|j|}t| |r#tdt| |df}|j}||v r7t	|dks9J || }|| }	t
d|D ]}
t| ||	i||
d }t|||
f||
  }|	|| 8 }	qF|	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 variablerA   r2   )r@   r   r   r6   r7   r   r>   r   r   rj   ri   r~   )r*   r8   rM   yr)   nxnyr   r   rQ   r:   spr/   r/   r0   rs_series_reversion@  s$   
4
r   rA   c                 C   s,  	 | j }t|}|s-|d}|d | }td|D ]}	t|| ||}|||	 | 7 }q|S tt|d }
t||
\}}|rC|d7 }|dg}|d}t| dk rgtd|
D ]}	t|| ||}|| qWn%td|
D ]}	|	d dkrt	||	d  ||}nt|| ||}|| qlt|d | ||}|d}|d}t|d D ]4}|
| }|| }td|
D ]}||||  ||  7 }qt||||}||7 }t||||}|s nq|d }|
| }||k r|| |d }td|
D ]}|| |kr n||||  ||  7 }qt||||}||7 }|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

    rA   r      r2   )
r   rj   ri   rh   r=   mathsqrtry   appendrp   )r*   r   r8   r9   concurr)   rM   rS   sr:   JKrQ   axpjbr?   s1rl   r/   r/   r0   rs_series_from_list  sf   

r   c                 C   sn   | j }|j|}|j}dg|j }d||< t|}| D ]}|| r4t||}|| | ||  ||< q|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   rA   )r   r6   r7   r"   ra   rK   r   
domain_new)r*   r8   r)   rM   r&   mnrm   rX   r/   r/   r0   rs_diff  s   
r   c                 C   sj   | j }|j}|j|}dg|j }d||< t|}| D ]}t||}|| | || d  ||< q|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   rA   )r   r"   r6   r7   ra   rK   r	   r   )r*   r8   r)   r&   rM   r   rm   rX   r/   r/   r0   rs_integrate  s   
 r   c                 G   s   | j }t d|j\}}t|d }|dd ||f }|j}|| v r/|| |  }	| | |  }
n|}	| }
t|tr@t|	|| }n||	g|R  }t| }dg| }|D ]}|d ||d d < qUt	|
||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   Nr   rA   )
r   r   r=   r   rH   strgetattrrw   r   r   )r*   rL   args_RR1r   hargs1r   x1r&   rS   r   r   r8   r/   r/   r0   rs_fun!  s&    

r   c                 C   sH   | j }|d}|  D ]\}}t|}||  |7  < ||t|< q|S )zF
    Return `p*x_i**n`.

    `x\_i` is the ith variable in ``p``.
    r   r   r   r   rK   r*   r:   rM   r)   rS   r?   rn   k1r/   r/   r0   r   Y  s   r   c                 C   sH   | j }|d}|  D ]\}}t|}||  |9  < ||t|< q|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   r/   r/   r0   rB   g  s   rB   c           
      C   s   t | |rtt| |||S | j}|j}|| vrtdt|}| | dks'J |d}| dkr1| S |dkr9|dS |dkr?| S |dk rI| }d}nd}t|D ]}t||d ||}	t	|	| ||}	||| |	|  7 }qO|rp|S t
|||S )z_
    Univariate series expansion of the nth root of ``p``.

    The Newton method is used.
    r   rA   r   )r@   rT   
_nth_root1r   r   r   r   r5   rs   rh   r   )
r*   rM   r8   r9   r)   r   r&   signr   tmpr/   r/   r0   r   z  s4   
r   c                    sf  |dkr| dkrt d| dS |dkrt| ||S | j}|j| t|  fddd  }t|  | } ||8 }t| d |r|j}| | }|j	t
u rZ| }|td| }	n7t|trzz| }||td| }	W n" t yy   tdw z||td| }	W n t y   tdw t| | ||||	 }
nt| |||}
|rt||}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 expressionrA   c                    r   r   r/   r   r   r/   r0   r[     r   zrs_nth_root.<locals>.<lambda>r]   3The given series cannot be expanded in this domain.)r>   r   r<   r6   r7   r   r   r   r   r   r   as_exprr   rH   r   r   r   rr   r   )r*   rM   r8   r9   r)   r   r   r   c_exprconstr4   r/   r   r0   rr     sF   $



rr   c                 C   s*  t | |rtt| ||S | j}| dkr|jS t| |}|rd}|dkr$nV| }|jtu r2t	|}nHt
|trfz|t	|}W n: tye   |t	|g}| |} ||}||}|t	|}Y nw z|t	|}W n tyy   tdw | |}t|t| ||||d }t||| 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)
    rA   r   r   )r@   rR   rs_logr   r"   r   r   r   r   r   rH   r   r>   add_gensset_ringr   diffrh   r   r   r   )r*   r8   r9   r)   r   r   r   dlogr/   r/   r0   r     s@   








r   c           
      C   s   t | |rtt| ||S | j}|d}t| |rtd||jv rSt|D ]+}t|||}t	|||||  }t	||d ||}t
|||}t	||||}	||	8 }q%|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 variablesrA   )r@   rR   rs_LambertWr   r   r   r6   r5   rs_exprh   rt   )
r*   r8   r9   r)   r&   r   rX   rc   p3r   r/   r/   r0   r   "  s    



r   c                 C   sF   | j }|d}t|D ]}| t||| }t||||}||7 }q|S )zHelper function for `rs\_exp`. rA   )r   r5   r   rh   )r*   r8   r9   r)   r&   r   ptr   r/   r/   r0   _exp1I  s   
r   c                 C   s^  t | |rtt| ||S | j}t| |}|r||jtu r$| }t|}nLt	|t
r\z| }|t|}W n: ty[   |t|g}| |} ||}||}|t|}Y nw z|t|}W n tyo   tdw | | }|t||| S t| dkrt| ||S |d}d}	g }t|D ]}
|||	  |
d7 }
|	|
9 }	qt| |||}|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   rA   )r@   rR   r   r   r   r   r   r   r   rH   r   r>   r   r   r   rj   r   ri   r   r   )r*   r8   r9   r)   r   r   r   r&   r   rM   r?   rQ   r/   r/   r0   r   S  sJ   








r   c           	      C   sl   | j }|d}| g}t| ||}td|D ]}||| d| d   qt||||}t|| ||}|S )zS
    Expansion using formula.

    Faster on very small and univariate series.
    r   rA   r2   r   rp   ri   r   r   rh   )	r*   rZ   r9   r)   mor   rc   r?   r   r/   r/   r0   _atan  s   r   c           
      C   s  t | |rtt| ||S | j}d}t| |r\|j}| | }|jtu r+| }t	|}n1t
|trHz| }|t	|}W n tyG   tdw z|t	|}W n ty[   tdw | |}t| |||d }	t|	||d }	t||	||d }	t|	|| 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   rA   )r@   rR   rs_atanr   r   r   r   r   r   r   rH   r   r>   r   r   rp   rt   rh   r   
r*   r8   r9   r)   r   r   r   r   dpr&   r/   r/   r0   r     s6   





r   c           	      C   s   t | |rtt| ||S t| |rtd| j}||jv rzt| dkrIt| |}dt	| ||d  }t
|d||d }t||||d }t||S |d}d|dg}td|dD ]}||d d |d  ||d    |d qXt| |||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   rA   r   r   rq   r2   )r@   rR   rs_asinr   r   r   r6   rj   r   rp   rr   rh   r   ri   r   r   )	r*   r8   r9   r)   r   r&   r   r   r?   r/   r/   r0   r     s&   





&r   c                 C   sR   | j }|d}t|D ]}| t||| }t|dt||| ||}||7 }q|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   rA   )r   r5   r   rh   rp   r*   r8   r9   r)   r&   r   r   r/   r/   r0   _tan1     
r   c                 C   sF  t | |rtt| ||}|S | j}d}t| |}|r|jtu r(| }t|}nLt	|t
r`z| }|t|}W n: ty_   |t|g}| |} ||}||}|t|}Y nw z|t|}W n tys   tdw | | }t|||}	td||	  ||}
t||	 |
||S |jdkrt| ||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   rA   )r@   rR   rs_tanr   r   r   r   r   r   rH   r   r>   r   r   r   rt   rh   ra   r   r   )r*   r8   r9   rQ   r)   r   r   r   r&   t2r   r/   r/   r0   r     sB   








r   c           
      C   s   t | |rtt| ||}|S t| |d\}}|d|  }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
    cotr2   )	r@   rR   rs_cotr   
rs_cos_sinr   rt   rh   r<   )
r*   r8   r9   rQ   r:   r   prec1r   r   r4   r/   r/   r0   r   P  s   
r   c                 C   s  t | |rtt| ||S |j}| s|dS t| |}|r|jtu r/| }t|t	|}}ndt
|trxz| }|t||t	|}}W nK tyw   |t|t	|g}| |} ||}||}|t||t	|}}Y nw z|t||t	|}}W n ty   tdw | | }t|||| t||||  S t| dkr|jdkrt| d ||}	t|	||}td| ||}t|d|	 ||S |d}
d}dg}td|d dD ]}||
|  |d || |d  9 }qt| |||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   rA   r2   )r@   rR   rs_sinr   r   r   r   r   r   r   rH   r   r>   r   r   r   rs_cosrj   ra   r   rp   rt   rh   ri   r   r   )r*   r8   r9   r)   r   r   t1r   r&   r   r   rM   r?   r/   r/   r0   r   t  sR   






 
r   c                 C   s$  t | |rtt| ||S | j}t| |}|r|jtu r)| }t|t	|}}nWt
|trez| }|t||t	|}}W n> tyd   |t|t	|g}| |} ||}||}Y nw z|t||t	|}}W n ty   tdw | | }t|||}t|||}	||j|	j}|| |	| |t||t	|}
}|| |	|
  S t| dkr|jdkrt| d ||}t|||}td| ||}t|d| ||S |d}d}g }td|d dD ]}|||  |d || |d  9 }qt| |||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   rA   r2   r   )r@   rR   r   r   r   r   r   r   r   r   rH   r   r>   r   r   r   r   composerj   ra   r   rp   rt   rh   ri   r   r   )r*   r8   r9   r)   r   r   _r&   p_cosp_sinr   r   r   r   rM   r?   r/   r/   r0   r     sX   








r   c                 C   sh   t | |rtt| ||S t| d ||}t|||}td| ||}t|d| ||t|d| ||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
    r2   rA   )r@   rR   r   r   rp   rt   rh   )r*   r8   r9   r   r   r&   r/   r/   r0   r     s   
$r   c           	      C   sf   | j }|d}|g}t| ||}td|D ]}||d| d   qt||||}t|| ||}|S )zR
    Expansion using formula

    Faster for very small and univariate series
    rA   r2   r   )	r*   r8   r9   r)   r   r   rc   r?   r   r/   r/   r0   _atanh  s   r   c           
      C   s  t | |rtt| ||S | j}d}t| |r\|j}| | }|jtu r+| }t	|}n1t
|trHz| }|t	|}W n tyG   tdw z|t	|}W n ty[   tdw t| |}t| || d }	t|	||d }	t||	||d }	t|	|| 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   rA   )r@   rR   rs_atanhr   r   r   r   r   r   r   rH   r   r>   r   r   rp   rt   rh   r   r   r/   r/   r0   r      s6   





r   c                 C   s<   t | |rtt| ||S t| ||}t|||}|| d 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
    r2   )r@   rR   rs_sinhr   rt   r*   r8   r9   r   r   r/   r/   r0   r   V  
   
r   c                 C   s<   t | |rtt| ||S t| ||}t|||}|| d 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
    r2   )r@   rR   rs_coshr   rt   r   r/   r/   r0   r   q  r   r   c                 C   sR   | j }|d}t|D ]}| t||| }t|dt||| ||}||7 }q|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   rA   )r   r5   r   rh   rp   r   r/   r/   r0   _tanh  r   r   c                 C   s  t | |rtt| ||S | j}d}t| |ry|j}| | }|jtu r+| }t	|}n1t
|trHz| }|t	|}W n tyG   tdw z|t	|}W n ty[   tdw | | }t|||}	td||	  ||}
t||	 |
||S |jdkrt| ||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   rA   )r@   rR   rs_tanhr   r   r   r   r   r   r   rH   r   r>   r   rt   rh   ra   r   r   )r*   r8   r9   r)   r   r   r   r   r&   r   r   r/   r/   r0   r     s:   





r   c                 C   s@   |   }t| }t|||}t|||||}|||  }|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!   r1   rt   rh   r   )r*   r8   r9   r(   r&   rc   r   r4   r/   r/   r0   	rs_newton  s   r   Fc                 C   sz   | j }|jtkr
t|j}|s&|  D ]\}}|tt|d  ||< q|S |  D ]\}}|tt|d  ||< q*|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   r=   r   )r&   inverser)   r*   r;   re   r/   r/   r0   rs_hadamard_exp  s   
r   c                 C   s   | j }|jd }|  |  d }t| ||}t|}t|||}t|}t||||}	t|	d}
|
d |
 | }t||}t|||}t|}|	 d }|  |  |  }|rc|||  }|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   rA   T)r   )
r   r6   r!   r   r   rh   r   r   r1   	primitive)r&   rc   r)   r8   r9   np1np1enp2np2enp3enp3np3arS   r   r/   r/   r0   rs_compose_add  s$   


r   )r   r   r   r   r   c                    s`   d}d}|dkrt | |||}|d9 }|dks|j}||}|j| t| fddd  S )z=Find the minimum power of `a` in the series expansion of exprr   r2   c                    r   r   r/   )r   r:   r/   r0   r[   P  r   zrs_min_pow.<locals>.<lambda>r]   )
_rs_seriesr   r6   r7   r   )expr	series_rsr   seriesrM   r)   r/   r   r0   
rs_min_powF  s   r  c                    s  | j }|j tdd |D s| js|S | |s|S | jrZ|d }t|dkr*tt|tddd\}}t	||||} 
|
|j | }ttt| j | ||}|S | jrt|}	|D ]}|jsvt|ddd\}}
 
| qcttt| fd	d
|D |gt| }t|} d}t|	D ])}t	||  || ||| ||  } 
|j | }| }||9 }qt| ||}|S | jrt|}	 d}t|	D ]#}t	||  || ||} 
|j | }| }||7 }q|S | jr,t| jtddd\}}
 
| t	| j | j||}t|| j|||S t| trA|  rAt| tdddd S t)Nc                 s   s    | ]}| tV  qd S r   )hasr   rC   argr/   r/   r0   	<genexpr>Z  s    z_rs_series.<locals>.<genexpr>r   rA   FTr   expandr   )r  r   c                    s   g | ]} |qS r/   r/   r  r)   r/   r0   rG     s    z_rs_series.<locals>.<listcomp>) r   r   anyis_Functionr  rj   r   r   r   r   r   r   eval_convert_funcr   funcis_Mul	is_Numberr   mapr  sumri   r<   is_Addis_Powbasers   r   rH   r   is_constant)r   r   r   r9   r   r  r   r   series_innerrM   r   min_powssum_powsr:   _seriesr/   r  r0   r   S  st   









r   c                 C   sR  t | tddd\}}||jvr||g}||}t| |||}|j}||}||d }||kr9t|||S t	ddD ]Z}t| |||| d}||j}||d }	|	|krt
||| | |	|   }
t| |||
d}||d |k rt| |||
d}||j}|
d9 }
||d |k sz n n
tdt|| f 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

    FTr  rA   	   )r9   r2   z#Could not calculate %s terms for %s)r   r   symbolsr   r   r   r   r!   r<   ri   r   r>   r   )r   r   r9   r)   r   genprec_gotmorer&   new_precprec_dor/   r/   r0   	rs_series  s<    



r!  )rA   )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   r1   r5   r<   r@   rR   rT   rh   rp   rs   r~   r   r   r   r   rt   r   r   r   r   r   r   r   rB   r   rr   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/   r0   <module>   s    +,'3(6D.&
HY  8#L9'
96-<$FI66
4U