
    \h                     h   S SK r S SKJrJrJrJr  S SKJr  S SKJ	r	J
r
  S SKJr  S SKJrJrJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  S S
KJr  S SKJr  S SK J!r!  S SK"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)J*r*J+r+  \" S5      r,\" S5      r-S r.\'S 5       r/\'S 5       r0S r1\'\+" S5      S 5       5       r2S r3g)    N)logMinMaxsqrt)Float)Symbolsymbols)cos)
AssignmentRaiseRuntimeError_QuotedString)newtons_methodnewtons_method_function)expm1)bind_C)render_as_module)import_module)ccode)compile_link_import_stringshas_chas_fortran)	may_xfail)skipraisesskip_under_pyodidecython	wurlitzerc            	          [        S5      u  pn[        U 5      U S-  -
  n[        X0X!5      nUR                  [	        X* UR                  U 5      -  5      5      (       d   eg )Nz	x dx atol   )r	   r
   r   hasr   diff)xdxatolexpralgos        [/var/www/auris/envauris/lib/python3.13/site-packages/sympy/codegen/tests/test_algorithms.pytest_newtons_methodr)      sV    +&KA4q6AqD=D$4,D88Jr51#567777    c                     [        SSS9n [        U 5      U S-  -
  n[        X5      n[        (       d  [	        S5        [        5       (       d  [	        S5        SS0n[        R                  " 5        n[        S	S
[        U5      -   4SSR                  S5      S-   4/XCS9u  pV[        UR                  S5      S-
  5      S:  d   e S S S 5        g ! , (       d  f       g = f)Nr#   Trealr    cython not installed.No C compiler found.stdc99znewton.c%#include <math.h>
#include <stdio.h>
_newton.pyx#cython: language_level={}
3zIcdef extern double newton(double)
def py_newton(x):
    return newton(x)
)	build_dircompile_kwargs      ?ߺv?-q=)r   r
   r   r   r   r   tempfileTemporaryDirectoryr   r   formatabs	py_newton)r#   r&   func
compile_kwfoldermodinfos          r(   #test_newtons_method_function__ccoderE      s    sAq6AqD=D"4+D6$%77#$J		$	$	&&/ 149$K@ A;BB3G66 81
 8	 3==%67%??? 
'	&	&s   0AC
Cc                     [        SSS9n [        U 5      U S-  -
  n[        X[        SS9/S9n[        (       d  [        S5        [        5       (       d  [        S	5        [        U/S
5      n[        R                  " 5        n[        SU4SSR                  S5      S-   4/US9u  pV[        UR                  S5      S-
  5      S:  d   e S S S 5        g ! , (       d  f       g = f)Nr#   Tr,   r    newton)name)attrsr.   zNo Fortran compiler found.
mod_newtonz
newton.f90r3   r4   r5   zRcdef extern double newton(double*)
def py_newton(double x):
    return newton(&x)
)r6   r8   r9   r:   )r   r
   r   r   r   r   r   f_moduler;   r<   r   r=   r>   r?   )r#   r&   r@   f_modrB   rC   rD   s          r(   #test_newtons_method_function__fcoderM   4   s    sAq6AqD=D"46x3H2IJD6$%==)*dV\*E		$	$	&&/5!;BB3G77 91
 	 3==%67%??? 
'	&	&s    AC
C c                      [        SSS9n [        U 5      U S-  -
  n[        X5      n[        U5      n0 n[	        X4U5        [        SU5      n[        US-
  5      S:  d   eg )Nr#   Tr,   r    znewton(0.5)r9   r:   )r   r
   r   	py_moduleexecevalr>   )r#   r&   r@   py_mod	namespaceress         r(   $test_newtons_method_function__pycoderU   K   se    sAq6AqD=D"4+Dt_FII&
}i
(Cs^#$u,,,r*   z,Emscripten does not support process spawningc                  0  ^^ [        S5      =n u  mpnU[        UT-  5      -  UTS-  -  -
  m[        [        UU4S j5        [        n[        TTXS9n[        5       (       d  [        S5        [        (       d  [        S5        SS0n[        R                  " 5        n[        S	S
[        U5      -   4SSR                  S5      S-   4/XgS9u  pU(       a1  [        R                  5        u  pUR                  S5      nS S S 5        OUR                  S5      n[!        WS-
  5      S:  d   eU(       d  [        S5        W
R#                  5       WR#                  5       pUS:X  d   eU
S:X  d   e S S S 5        g ! , (       d  f       Nm= f! , (       d  f       g = f)Nzx A k pr    c                     > [        T T5      $ N)r   )r&   r#   s   r(   <lambda>@test_newtons_method_function__ccode_parameters.<locals>.<lambda>[   s    6tQ?r*   )debugr/   r.   r0   r1   znewton_par.cr2   z_newton_par.pyxr4   r5   zycdef extern double newton(double, double, double, double)
def py_newton(x, A=1, k=1, p=1):
    return newton(x, A, k, p)
)r7   r6   r8   r9   r:   zAC-level output only tested when package 'wurlitzer' is available. zx=         0.5
x=      1.1121 d_x=     0.61214
x=     0.90967 d_x=    -0.20247
x=     0.86726 d_x=   -0.042409
x=     0.86548 d_x=  -0.0017867
x=     0.86547 d_x= -3.1022e-06
x=     0.86547 d_x= -9.3421e-12
x=     0.86547 d_x=  3.6902e-17
)r	   r
   r   
ValueErrorr   r   r   r   r   r;   r<   r   r   r=   pipesr?   r>   read)argsAkpuse_wurlitzerr@   rA   rB   rC   rD   outerrresultr&   r#   s                @@r(   .test_newtons_method_function__ccode_parametersrh   V   s     	**D:1aAS1X:!Q$D
:?@M"4DFD77#$6$%J		$	$	&&/ 149$K@ A!?!F!Fs!K"?"? A1
 %8	 "jss+ #" ]]3'F6N*+e333TU88:sxxzSbyy 	 	 		 	/ 
'	& #" 
'	&s&   AF)E6=A/F6
F	 F
Fc                    ^^^ [        SSSS9u  mn mp[        SSSS9nX!-
  S-
  nTU -
  U-  n[        U 5      [        [        [        T5      [        U 5      -
  U-  5      * 5      -   nU[        U5      -
  nS mSUUU4S	 j0SS
 0SS 0S.nXp4n	S GH9  n
U TTX4SSU
USSTT4[	        [        [        S5      5      5      S.	nUR                  5        VVs0 s H   u  pU[        U	SU S30[        U40 UD6D6_M"     nnnUR                  5        VVs0 s H  u  pU[        U5      _M     nnn0 n0 nUR                  5        H$  u  p0 =nUU'   [        UUU5        UU S3   UU'   M&     [        S5      nSSSS.nSnUR                  5        H:  u  nnU" USSSS5      nUUU   -  nU
(       a  US-  n[        UU-
  5      U:  a  M:   e   GM<     g s  snnf s  snnf )Nza b c N_geo N_totT)r-   nonnegativei)integerrj      c                 ,    [        [        X5      U5      $ rX   )r   r   )lowr&   highs      r(   _clamp:test_newtons_method_function__rtol_cse_nan.<locals>._clamp   s    3s>4((r*   delta_fnc                    > T" [        TU-  5      U-
  S-  U * U R                  U5      -  [        TU-  5      U-
  S-  5      $ )NgGz?)r   r"   )er#   rq   acs     r(   rY   <test_newtons_method_function__rtol_cse_nan.<locals>.<lambda>   sC    F!A#Yq[$BqvvayL!A#Yq[$5
r*   c                     SX R                  U5      -  -  SU R                  U5      S-  -  X R                  US5      -  -
  -  $ )N   r"   ru   r#   s     r(   rY   rx      s@    R66!9-=qA~PQRXRXYZ\]R^P^?^-_r*   c                     U * U R                  U5      -  SX R                  U5      -  U R                  US5      -  S-  U R                  U5      -  -
  -  $ )Nrm   r{   r|   r}   s     r(   rY   rx      sO    !AFF1Iq66!9QVVTUVW[AXYZAZ[\[a[abc[dAd?d1er*   )clamped_newtonhalley
halley_alt)FT<   g0.++gؗҬ<zencountered NaN.)	paramsitermaxr[   csecounterr%   rtolbounds
handle_nan	func_name_bz"13.2261515064168768938151923226496gMg<g      @g{Gz?g      Y@2   d   r{   )r	   r   r   r   r   r   r   itemsr   dictrO   rP   r   r>   )bN_geoN_totrk   N_ari	delta_ariln_delta_geoeqb_logmeth_kwr`   use_csekwargsrb   kwr@   vrR   rS   root_find_bnsrefreftolguessmethrg   reqrq   rv   rw   s                             @@@r(   *test_newtons_method_function__rtol_cse_nanr      s3   #$7dPTUAq!UsDd3AMAE1eIq6CAs1vu'<!= =>>LS^+G) & (
 
 `a!#fgG :D !Q-"tT[&%Aa5l;M.N OP

 jqivivixyix`e`a*D[qcH[VHZWYHZ[[ixy.2jjl;lda!Yq\/l;	LLNDA ""B1BO1#R\KN # 89$)U%P%++-JD$%sB4FfTl"Cqv|$s*** .# ! z;s   'GG)4r;   sympyr   r   r   r   sympy.core.numbersr   sympy.core.symbolr   r	   (sympy.functions.elementary.trigonometricr
   sympy.codegen.astr   r   r   r   sympy.codegen.algorithmsr   r   sympy.codegen.cfunctionsr   sympy.codegen.fnodesr   sympy.codegen.futilsr   rK   sympy.codegen.pyutilsrO   sympy.externalr   sympy.printing.codeprinterr   sympy.utilities._compilationr   r   r   !sympy.utilities._compilation.utilr   sympy.testing.pytestr   r   r   r   r   r)   rE   rM   rU   rh   r    r*   r(   <module>r      s     % % $ - 8 L L L * ' = ? ( , X X 7 A A	x	 +&	8 @ @. @ @,- BC. D .b++r*   