U
    ?hw                     @   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 Q/var/www/html/venv/lib/python3.8/site-packages/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   