o
    §ƒðjA
  ã                   @   sF   d Z ddlmZ ddlmZ ddlmZ ddd„Zd	d
„ Zdd„ Z	dS )z)Numerical Methods for Holonomic Functionsé    ©Úsympify)ÚDMFsubs)ÚmpFÚRK4c              	      sâ   | j }|j‰|jj}| ¡ ‰ |dkrt}nt}‡ fdd„|jD ƒ‰‡‡fdd„tˆƒD ƒ}| j	}t
|ƒˆk r:tdƒ‚| j}	|||	|d |ˆƒg}
t|dd… ƒD ]\}}|
 |||| ||
d	 ˆƒ¡ qP|smd
d„ |
D ƒS t|
ƒS )zk
    Numerical methods for numerical integration along a given set of
    points in the complex plane.
    ÚEulerc                    s   g | ]	}ˆ   | ¡ ¡‘qS © )ÚnewÚto_list)Ú.0Új)ÚKr   ú›/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/holonomic/numerical.pyÚ
<listcomp>   s    z_evalf.<locals>.<listcomp>c                    s   g | ]}ˆ|  ˆˆ   ‘qS r   r   ©r   Úi)ÚaÚdmfr   r   r      s    zNot Enough Initial Conditionsr   é   Néÿÿÿÿc                 S   s   g | ]}t |d  ƒ‘qS )r   r   r   r   r   r   r   &   s    )ÚannihilatorÚorderÚparentÚbaseÚ	get_fieldÚ_eulerÚ_rk4Ú
listofpolyÚrangeÚy0ÚlenÚ	TypeErrorÚx0Ú	enumerateÚappendr   )ÚfuncÚpointsÚderivativesÚmethodÚannÚRÚmethÚredr   r"   Úsolr   r   r   )r   r   r   r   Ú_evalf	   s&    r.   c           	         s¢   t |ƒ tj¡}t |ƒ tj¡}dd„ |D ƒ‰|| ‰ˆdd… ‰ d}t|ƒD ]}|t t| | |dd�ƒ tj¡ˆ|  7 }q'ˆ  |¡ ‡ ‡‡fdd„t|ƒD ƒS )	zs
    Euler's method for numerical integration.
    From x0 to x1 with initial values given at x0 as vector y0.
    c                 S   ó   g | ]
}t |ƒ tj¡‘qS r   ©r   Ú
_to_mpmathr   Úprecr   r   r   r   r   3   ó    z_euler.<locals>.<listcomp>r   Nr   T©Úmpmc                    s    g | ]}ˆ| ˆˆ |   ‘qS r   r   r   ©Úf_0ÚhÚy_0r   r   r   <   ó     ©r   r1   r   r2   r   r   r$   )	r,   r"   Úx1r   r   ÚAÚBÚf_0_nr   r   r6   r   r   +   s   ,
r   c                    s  t |ƒ tj¡}t |ƒ tj¡}dd„ |D ƒ‰|| ‰d}d}d}	d}
ˆdd… ‰ t|ƒD ]}|t t| | |dd�ƒ tj¡ˆ|  7 }q-ˆ  |¡ ‡ ‡‡fdd„td|ƒD ƒ‰t|ƒD ]#}|t t| | |ˆd	  dd�ƒ tj¡ˆ| ˆ | ˆ d	   7 }q\ˆ |¡ ‡‡‡fd
d„td|ƒD ƒ‰t|ƒD ]#}|	t t| | |ˆd	  dd�ƒ tj¡ˆ| ˆ| ˆ d	   7 }	q—ˆ |	¡ ‡‡‡fdd„td|ƒD ƒ‰t|ƒD ]}|
t t| | |ˆ dd�ƒ tj¡ˆ| ˆ| ˆ   7 }
qÒˆ |
¡ ‡ ‡‡‡‡‡fdd„t|ƒD ƒS )z1
    Runge-Kutta 4th order numerical method.
    c                 S   r/   r   r0   r   r   r   r   r   F   r3   z_rk4.<locals>.<listcomp>r   r   NTr4   c                    ó$   g | ]}ˆ| ˆ | ˆ d   ‘qS ©é   r   r   r6   r   r   r   S   ó   $ rB   c                    r@   rA   r   r   )Úf_1r8   r9   r   r   r   X   rC   c                    s    g | ]}ˆ| ˆ | ˆ  ‘qS r   r   r   )Úf_2r8   r9   r   r   r   ]   r:   c                    sD   g | ]}ˆ| ˆˆ | d ˆ|   d ˆ|   ˆ|   d  ‘qS )rB   é   r   r   ©r7   rD   rE   Úf_3r8   r9   r   r   r   b   s   D r;   )r,   r"   r<   r   r   r=   r>   r?   Úf_1_nÚf_2_nÚf_3_nr   r   rG   r   r   ?   s2   ,
D
D
<
 r   N)Fr   )
Ú__doc__Úsympy.core.sympifyr   Úsympy.holonomic.holonomicr   Úmpmathr   r.   r   r   r   r   r   r   Ú<module>   s    
"