a
    Q¹§e©  ã                   @   sZ   d Z ddlZzddlZddlmZ W n ey6   Y n0 dd„ Zdd„ Z	e
dkrVe	ƒ  dS )zŠCompute a Pade approximation for the principal branch of the
Lambert W function around 0 and compare it to various other
approximations.

é    Nc                  C   s,   dd„ t dƒD ƒ} t | dd¡\}}||fS )Nc                 S   s   g | ]}t jt jd |d‘qS )r   )Ún)ÚmpmathÚdiffÚlambertw)Ú.0r   © r   úV/var/www/sunrise/env/lib/python3.9/site-packages/scipy/special/_precompute/lambertw.pyÚ
<listcomp>   ó    z!lambertw_pade.<locals>.<listcomp>é   é   é   )Úranger   Zpade)ZderivsÚpÚqr   r   r   Úlambertw_pade   s    r   c                  C   sd  t tƒ t d¡T tƒ \} }| d d d… |d d d…  } }t d| › ƒ t d|› ƒ W d   ƒ n1 sl0    Y  t ddd¡t ddd¡ }}t ||¡\}}|d|  }g }| ¡ D ]}| 	t
t |¡ƒ¡ q¼t |¡ |j¡}tjd	d
d\}}t dd„ | D ƒ¡} t dd„ |D ƒ¡}t | |¡t ||¡ }	t|	| ƒ}
|d  |||
¡ t |¡t t |¡¡ }t|| ƒ}|d
  |||¡ t dt d
¡| d
  ¡} d|  | d d	  }t|| ƒ}|d  |||¡}|j|| ¡  ¡ d t ¡  tjd
d
d\}}|
|k }| |||¡}t dd¡}| dt|ƒ d |d¡ |j||d t ¡  d S )Né2   éÿÿÿÿzp = zq = g      ø¿g      ø?éK   y              ð?r   é   )ZnrowsZncolsc                 S   s   g | ]}t |ƒ‘qS r   ©Úfloat)r   Zp0r   r   r   r	   '   r
   zmain.<locals>.<listcomp>c                 S   s   g | ]}t |ƒ‘qS r   r   )r   Zq0r   r   r   r	   (   r
   r   r   )Úaxg333333Ó¿g333333Ó?g      Àgš™™™™™É?Úr)ÚprintÚ__doc__r   Zworkdpsr   ÚnpZlinspaceZmeshgridÚflattenÚappendÚcomplexr   ÚarrayZreshapeÚshapeÚpltZsubplotsZpolyvalÚabsZ
pcolormeshÚlogÚsqrtÚexpZcolorbarZravelÚtolistÚshowZplot)r   r   ÚxÚyÚzZlambertw_stdZz0ZfigZaxesZpade_approxZpade_errZ
asy_approxZasy_errZseries_approxZ
series_errZimr   Zpade_betterÚtr   r   r   Úmain   sF    
,r-   Ú__main__)r   Únumpyr   r   Zmatplotlib.pyplotZpyplotr"   ÚImportErrorr   r-   Ú__name__r   r   r   r   Ú<module>   s   .