Ë
    7^(hï  ã            
       óð   — d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZ d d	lm Z  	 dddd
d
d„ dd
d
dœd„Z!d„ Z"d
d e«       fd
dœd„Z#y
)é    )ÚTuple)Úoo)ÚGtÚLt)ÚDummyÚSymbol)ÚAbs)ÚMinÚMax)ÚAnd)Ú
AssignmentÚAddAugmentedAssignmentÚbreak_Ú	CodeBlockÚDeclarationÚFunctionDefinitionÚPrintÚReturnÚScopeÚWhileÚVariableÚPointerÚreal)ÚisnanNg¼‰Ø—²Ò¼<Fc                 ó,   — |  | j                  |«      z  S ©N)Údiff)ÚeÚxs     úV/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/codegen/algorithms.pyú<lambda>r!      s   € ÀaÀRÈÏÉÈqË	Á\€ ó    )ÚrtolÚdebugÚitermaxÚcounterÚdelta_fnÚcseÚ
handle_nanÚboundsc                ó~  — |€t        «       }t        }d}nd„ }|j                  } || |«      }|	rQddlm}	  |	|j                  «       g«      \  }\  }|D ��cg c]  \  }}t        ||«      ‘Œ }}}|t        ||«      gz  }nt        ||«      g}|
�'|t        t        |«      t        |
t        «      «      gz  }|t        ||«      gz  }|�*|t        |t        t        ||d   «      |d   «      «      gz  }|r.t        ||gdj                  |j                  |«      «      }||gz  }t!        t#        |«      ||t#        |«      z  z   «      }t%        t'        |t(        t*        ¬«      «      g}|�q|xs t        d¬	«      }t'        j,                  |d«      }|j/                  t%        |«      «       |j/                  t        |d«      «       t1        |t3        ||«      «      }t        |t        |Ž «      }|}|r5|j/                  t        |gd
j                  |j                  «      «      «       ||gz  } |t        |Ž «      S c c}}w )až   Generates an AST for Newton-Raphson method (a root-finding algorithm).

    Explanation
    ===========

    Returns an abstract syntax tree (AST) based on ``sympy.codegen.ast`` for Netwon's
    method of root-finding.

    Parameters
    ==========

    expr : expression
    wrt : Symbol
        With respect to, i.e. what is the variable.
    atol : number or expression
        Absolute tolerance (stopping criterion)
    rtol : number or expression
        Relative tolerance (stopping criterion)
    delta : Symbol
        Will be a ``Dummy`` if ``None``.
    debug : bool
        Whether to print convergence information during iterations
    itermax : number or expr
        Maximum number of iterations.
    counter : Symbol
        Will be a ``Dummy`` if ``None``.
    delta_fn: Callable[[Expr, Symbol], Expr]
        computes the step, default is newtons method. For e.g. Halley's method
        use delta_fn=lambda e, x: -2*e*e.diff(x)/(2*e.diff(x)**2 - e*e.diff(x, 2))
    cse: bool
        Perform common sub-expression elimination on delta expression
    handle_nan: Token
        How to handle occurrence of not-a-number (NaN).
    bounds: Optional[tuple[Expr, Expr]]
        Perform optimization within bounds

    Examples
    ========

    >>> from sympy import symbols, cos
    >>> from sympy.codegen.ast import Assignment
    >>> from sympy.codegen.algorithms import newtons_method
    >>> x, dx, atol = symbols('x dx atol')
    >>> expr = cos(x) - x**3
    >>> algo = newtons_method(expr, x, atol=atol, delta=dx)
    >>> algo.has(Assignment(dx, -expr/expr.diff(x)))
    True

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Newton%27s_method

    Údeltac                 ó   — | S r   © )r   s    r    r!   z newtons_method.<locals>.<lambda>P   s   € ˜A€ r"   r   )r(   é   z{}=%12.5g {}=%12.5g\n)ÚtypeÚvalueT)Úintegerz{}=%12.5g\n)r   r   ÚnameÚsympy.simplify.cse_mainr(   Úfactorr   r   r   r   r   r   r
   r   r   Úformatr   r	   r   r   r   r   ÚdeducedÚappendr   r   )ÚexprÚwrtÚatolr,   r#   r$   r%   r&   r'   r(   r)   r*   ÚWrapperÚname_dÚ
delta_exprÚcsesÚredÚdumÚsub_eÚwhl_bdyÚprntÚreqÚdeclarsÚ	v_counterÚwhlÚblcks                             r    Únewtons_methodrJ      s#  € ðv €}Ü“ˆÜˆØ‰áˆØ—‘ˆá˜$ Ó$€JÙ
Ý/Ù˜J×-Ñ-Ó/Ð0Ó1‰ˆ‰fˆsØ<@×A©j¨c°5”:˜c 5Õ)ÐAˆÑAØ”J˜u cÓ*Ð+Ñ+‰ä˜e ZÓ0Ð1ˆØÐØ”Eœ% ›,¬	°*¼fÓ(EÓFÐGÑGˆØÔ& s¨EÓ2Ð3Ñ3€GØÐØ”J˜s¤C¬¨C°¸±Ó(;¸VÀA¹YÓ$GÓHÐIÑIˆÙÜ�c˜5�\Ð#;×#BÑ#BÀ3Ç8Á8ÈVÓ#TÓUˆØ�D�6ÑˆÜ
ŒS�‹Z˜ ¤S¨£X¡Ñ-Ó
.€CÜœ8 E´¼BÔ?Ó@ÐA€GØÐØÒ0œU¨4Ô0ˆÜ×$Ñ$ W¨aÓ0ˆ	Ø�‰”{ 9Ó-Ô.Ø�‰Ô-¨g°qÓ9Ô:Ü�#”r˜' 7Ó+Ó,ˆÜ
�”Y Ð(Ó
)€CØ€DÙØ�‰”E˜3˜% ×!6Ñ!6°s·x±xÓ!@ÓAÔBØˆSˆE�M€DÙ”9˜dÐ#Ó$Ð$ùó3 Bs   ÁH9c                 óŽ   — t        | t        «      r| j                  j                  } | S t        | t        «      r| j                  } | S r   )Ú
isinstancer   ÚvariableÚsymbolr   )Úargs    r    Ú
_symbol_ofrP   s   s<   € Ü�#”{Ô#Ø�l‰l×!Ñ!ˆð €Jô 
�CœÔ	"Ø�j‰jˆØ€Jr"   Únewton)r,   c          	      ó¶  — |€|f}|D �ci c]?  }t        |t        «      r-|j                  t        d|j                  j                  z  «      “ŒA }}|€+t        d|j                  z   «      }| j                  |«      rd}t        | |fd|i|¤Žj                  |«      }	t        |	t        «      r|	j                  }	| j                  j                  |D �ch c]  }t        |«      ’Œ c}«      }
|
r+t        ddj                  t        t         |
«      «      z  «      ‚t#        d„ |D «       «      }t%        |	t'        |«      «      }t)        t*        ||||¬«      S c c}w c c}w )	aÚ   Generates an AST for a function implementing the Newton-Raphson method.

    Parameters
    ==========

    expr : expression
    wrt : Symbol
        With respect to, i.e. what is the variable
    params : iterable of symbols
        Symbols appearing in expr that are taken as constants during the iterations
        (these will be accepted as parameters to the generated function).
    func_name : str
        Name of the generated function.
    attrs : Tuple
        Attribute instances passed as ``attrs`` to ``FunctionDefinition``.
    \*\*kwargs :
        Keyword arguments passed to :func:`sympy.codegen.algorithms.newtons_method`.

    Examples
    ========

    >>> from sympy import symbols, cos
    >>> from sympy.codegen.algorithms import newtons_method_function
    >>> from sympy.codegen.pyutils import render_as_module
    >>> x = symbols('x')
    >>> expr = cos(x) - x**3
    >>> func = newtons_method_function(expr, x)
    >>> py_mod = render_as_module(func)  # source code as string
    >>> namespace = {}
    >>> exec(py_mod, namespace, namespace)
    >>> res = eval('newton(0.5)', namespace)
    >>> abs(res - 0.865474033102) < 1e-12
    True

    See Also
    ========

    sympy.codegen.algorithms.newtons_method

    Nz(*%s)Úd_r,   zMissing symbols in params: %sz, c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr   )r   r   )Ú.0Úps     r    ú	<genexpr>z*newtons_method_function.<locals>.<genexpr>²   s   è ø€ Ò6¨!”H˜Q¤×%Ñ6ùs   ‚)Úattrs)rL   r   rN   r   r3   ÚhasrJ   Úxreplacer   ÚbodyÚfree_symbolsÚ
differencerP   Ú
ValueErrorÚjoinÚmapÚstrÚtupler   r   r   r   )r9   r:   ÚparamsÚ	func_namerX   r,   ÚkwargsrV   Úpointer_subsÚalgoÚnot_in_paramsrF   r[   s                r    Únewtons_method_functionri   {   s4  € ðR €~Ø�ˆà#ö?Ø¤z°!´WÔ'=ð —H‘Hœf W¨q¯x©x¯}©}Ñ%<Ó=Ñ=ð ?€Lð ?à€}Ü�t˜cŸh™h‘Ó'ˆØ�8‰8�EŒ?ØˆEÜ˜$ Ñ;¨5Ð;°FÑ;×DÑDÀ\ÓR€DÜ�$œÔØ�y‰yˆØ×%Ñ%×0Ñ0ÈÖ1PÀA´*¸Qµ-Ò1PÓQ€MÙÜÐ8¸4¿9¹9ÄSÌÈmÓE\Ó;]Ñ]Ó^Ð^ÜÑ6¨vÔ6Ó6€GÜ�Tœ6 #›;Ó'€DÜœd I¨w¸ÀEÔJÐJùò?ùò 2Qs   ŠAEÃE)gê-�™—q=N)$Úsympy.core.containersr   Úsympy.core.numbersr   Úsympy.core.relationalr   r   Úsympy.core.symbolr   r   Ú$sympy.functions.elementary.complexesr	   Ú(sympy.functions.elementary.miscellaneousr
   r   Úsympy.logic.boolalgr   Úsympy.codegen.astr   r   r   r   r   r   r   r   r   r   r   r   r   Úsympy.codegen.cfunctionsr   rJ   rP   ri   r.   r"   r    ú<module>rs      sv   ðÝ 'Ý !ß *ß -Ý 4ß =Ý #÷÷ ÷ õ õ +à Uð`%¸eÈ5Ø¨Ñ8QØ¨Øô`%òFð /3¸hÉeËgð 9KÐ`dõ 9Kr"   