U
    Hvfw  ã                   @   sT   zd dl ZW n ek
r    Y nX zd dlmZ W n ek
rF   Y nX dd„ ZdS )é    N©Úxc                    s²   t ˆ ƒ}t‡ fdd„t|ƒD ƒƒ}t|  td|¡ ¡ }|d g}t|ƒD ]}| |d |  ¡ ¡ qJt 	d¡g}td|ƒD ]"}| ||  
t|d ¡| ¡ q|dd„ |D ƒ}|S )a”  Given a series

    f(x) = a[1]*x + a[2]*x**2 + ... + a[n-1]*x**(n - 1),

    use the Lagrange inversion formula to compute a series

    g(x) = b[1]*x + b[2]*x**2 + ... + b[n-1]*x**(n - 1)

    so that f(g(x)) = g(f(x)) = x mod x**n. We must have a[0] = 0, so
    necessarily b[0] = 0 too.

    The algorithm is naive and could be improved, but speed isn't an
    issue here and it's easy to read.

    c                 3   s   | ]}ˆ | t |  V  qd S )Nr   )Ú.0Úi©Úa© úC/tmp/pip-unpacked-wheel-96ln3f52/scipy/special/_precompute/utils.pyÚ	<genexpr>   s     z%lagrange_inversion.<locals>.<genexpr>r   éÿÿÿÿé   c                 S   s   g | ]}t  |¡‘qS r   )ÚmpÚmpf)r   r   r   r   r	   Ú
<listcomp>%   s     z&lagrange_inversion.<locals>.<listcomp>)ÚlenÚsumÚranger   ZseriesZremoveOÚappendÚexpandr   r   Zcoeff)r   ÚnÚfÚhZhpowerÚkÚbr   r   r	   Úlagrange_inversion   s    
 r   )Zmpmathr   ÚImportErrorZ	sympy.abcr   r   r   r   r   r	   Ú<module>   s   