a
    ˜¥»a™  ã                   @   sP   zd dl ZW n ey   Y n0 zd dlmZ W n eyB   Y n0 dd„ ZdS )é    N©Úxc                    s¶   t ˆ ƒ}t‡ fdd„tt ˆ ƒƒD ƒƒ}t|  td|¡ ¡ }|d g}t|ƒD ]}| |d |  ¡ ¡ qNt 	d¡g}td|ƒD ]"}| ||  
t|d ¡| ¡ q€t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© úY/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/scipy/special/_precompute/utils.pyÚ	<genexpr>   ó    z%lagrange_inversion.<locals>.<genexpr>r   éÿÿÿÿé   c                 S   s
   t  | ¡S r   )ÚmpÚmpfr   r	   r	   r
   Ú<lambda>%   r   z$lagrange_inversion.<locals>.<lambda>)ÚlenÚsumÚranger   ZseriesZremoveOÚappendÚexpandr   r   ZcoeffÚmap)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   