§
    OŠtjï  ã            
       óø   — 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#dS )é    )ÚTuple)Úoo)ÚGtÚLt)ÚDummyÚSymbol)ÚAbs)ÚMinÚMax)ÚAnd)Ú
AssignmentÚAddAugmentedAssignmentÚbreak_Ú	CodeBlockÚDeclarationÚFunctionDefinitionÚPrintÚReturnÚScopeÚWhileÚVariableÚPointerÚreal)Úisnançê-�™—q=Ng¼‰Ø—²Ò¼<Fc                 ó4   — |  |                       |¦  «        z  S ©N)Údiff)ÚeÚxs     úV/var/www/html/CA-Chatbot/venv/lib/python3.11/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        } || |¦  «        }|	rJddlm}	  |	|                     ¦   «         g¦  «        \  }\  }d„ |D ¦   «         }|t          ||¦  «        gz  }nt          ||¦  «        g}|
�4|t          t          |¦  «        t          |
t          ¦  «        ¦  «        gz  }|t          ||¦  «        gz  }|�<|t          |t          t          ||d         ¦  «        |d         ¦  «        ¦  «        gz  }|r1t          ||gd                     |j        |¦  «        ¦  «        }||gz  }t!          t#          |¦  «        ||t#          |¦  «        z  z   ¦  «        }t%          t'          |t(          t*          ¬	¦  «        ¦  «        g}|�Š|pt          d
¬¦  «        }t'          j        |d¦  «        }|                     t%          |¦  «        ¦  «         |                     t          |d¦  «        ¦  «         t1          |t3          ||¦  «        ¦  «        }t          |t          |Ž ¦  «        }|}|r<|                     t          |gd                     |j        ¦  «        ¦  «        ¦  «         ||gz  } |t          |Ž ¦  «        S )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

    NÚdeltac                 ó   — | S r   © )r    s    r!   r"   z newtons_method.<locals>.<lambda>P   s   € ˜A€ r#   r   )r)   c                 ó4   — g | ]\  }}t          ||¦  «        ‘ŒS r/   )r   )Ú.0ÚdumÚsub_es      r!   ú
<listcomp>z"newtons_method.<locals>.<listcomp>W   s&   € ÐAÐAÐA©j¨c°5•:˜c 5Ñ)Ô)ÐAÐAÐAr#   é   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Úwhl_bdyÚprntÚreqÚdeclarsÚ	v_counterÚwhlÚblcks                           r!   Únewtons_methodrN      s¢  € ðv €}Ý‘”ˆÝˆØˆˆà�+ˆØ”ˆà�˜$ Ñ$Ô$€JØ
ð 2Ø/Ð/Ð/Ð/Ð/Ð/Ø�s˜J×-Ò-Ñ/Ô/Ð0Ñ1Ô1‰ˆ‰fˆsØAÐA¸DÐAÑAÔAˆØ•J˜u cÑ*Ô*Ð+Ñ+ˆˆå˜e ZÑ0Ô0Ð1ˆØÐØ•E�% ™,œ,­	°*½fÑ(EÔ(EÑFÔFÐGÑGˆØÕ& s¨EÑ2Ô2Ð3Ñ3€GØÐØ•J˜s¥C­¨C°¸´Ñ(;Ô(;¸VÀA¼YÑ$GÔ$GÑHÔHÐIÑIˆØð Ý�c˜5�\Ð#;×#BÒ#BÀ3Ä8ÈVÑ#TÔ#TÑUÔUˆØ�D�6ÑˆÝ
�S�‰ZŒZ˜ ¥S¨¡X¤X¡Ñ-Ñ
.Ô
.€CÝ�8 Eµ½BÐ?Ñ?Ô?Ñ@Ô@ÐA€GØÐØÐ0�U¨4Ð0Ñ0Ô0ˆÝÔ$ W¨aÑ0Ô0ˆ	Ø�Š•{ 9Ñ-Ô-Ñ.Ô.Ð.Ø�ŠÕ-¨g°qÑ9Ô9Ñ:Ô:Ð:Ý�#•r˜' 7Ñ+Ô+Ñ,Ô,ˆÝ
�•Y Ð(Ñ
)Ô
)€CØ€DØð CØ�Š•E˜3˜% ×!6Ò!6°s´xÑ!@Ô!@ÑAÔAÑBÔBÐBØˆSˆE�M€DØˆ7•9˜dÐ#Ñ$Ô$Ð$r#   c                 ó‚   — t          | t          ¦  «        r| j        j        } nt          | t          ¦  «        r| j        } | S r   )Ú
isinstancer   ÚvariableÚsymbolr   )Úargs    r!   Ú
_symbol_ofrT   s   s>   € Ý�#•{Ñ#Ô#ð ØŒlÔ!ˆˆÝ	�C�Ñ	"Ô	"ð ØŒjˆØ€Jr#   Únewton)r-   c          	      ó\  — |€|f}d„ |D ¦   «         }|€.t          d|j        z   ¦  «        }|                      |¦  «        rd}t          | |fd|i|¤Ž                     |¦  «        }t          |t          ¦  «        r|j        }| j         	                    d„ |D ¦   «         ¦  «        }	|	r8t          dd                     t          t          |	¦  «        ¦  «        z  ¦  «        ‚t          d„ |D ¦   «         ¦  «        }
t          |t!          |¦  «        ¦  «        }t#          t$          ||
||¬	¦  «        S )
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

    Nc                 ó|   — i | ]9}t          |t          ¦  «        ¯|j        t          d |j        j        z  ¦  «        “Œ:S )z(*%s))rP   r   rR   r   r9   ©r1   Úps     r!   ú
<dictcomp>z+newtons_method_function.<locals>.<dictcomp>¦   sK   € ð ?ð ?ð ?Ø¥z°!µWÑ'=Ô'=ð?�A”H�f W¨q¬x¬}Ñ%<Ñ=Ô=ð ?ð ?ð ?r#   Úd_r-   c                 ó,   — h | ]}t          |¦  «        ’ŒS r/   )rT   rX   s     r!   ú	<setcomp>z*newtons_method_function.<locals>.<setcomp>¯   s   € Ð1PÐ1PÐ1PÀAµ*¸Q±-´-Ð1PÐ1PÐ1Pr#   zMissing symbols in params: %sz, c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S r   )r   r   rX   s     r!   ú	<genexpr>z*newtons_method_function.<locals>.<genexpr>²   s,   è è € Ð6Ð6¨!•H˜Q¥Ñ%Ô%Ð6Ð6Ð6Ð6Ð6Ð6r#   )Úattrs)r   r9   ÚhasrN   ÚxreplacerP   r   ÚbodyÚfree_symbolsÚ
differenceÚ
ValueErrorÚjoinÚmapÚstrÚtupler   r   r   r   )r?   r@   ÚparamsÚ	func_namer`   r-   ÚkwargsÚpointer_subsÚalgoÚnot_in_paramsrJ   rc   s               r!   Únewtons_method_functionrq   {   sC  € ðR €~Ø�ˆð?ð ?Ø#ð?ñ ?ô ?€Là€}Ý�t˜cœh‘Ñ'Ô'ˆØ�8Š8�E‰?Œ?ð 	ØˆEÝ˜$ Ð;Ð;¨5Ð;°FÐ;Ð;×DÒDÀ\ÑRÔR€DÝ�$�ÑÔð ØŒyˆØÔ%×0Ò0Ð1PÐ1PÈÐ1PÑ1PÔ1PÑQÔQ€MØð _ÝÐ8¸4¿9º9ÅSÍÈmÑE\ÔE\Ñ;]Ô;]Ñ]Ñ^Ô^Ð^ÝÐ6Ð6¨vÐ6Ñ6Ô6Ñ6Ô6€GÝ�T�6 #™;œ;Ñ'Ô'€DÝ�d I¨w¸ÀEÐJÑJÔJÐJr#   )r   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   rN   rT   rq   r/   r#   r!   ú<module>r{      sÏ  ðØ 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø !Ð !Ð !Ð !Ð !Ð !Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø #Ð #Ð #Ð #Ð #Ð #ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð +Ð *Ð *Ð *Ð *Ð *à Uð`%¸eÈ5Ø¨Ð8QÐ8QØ¨Øð`%ð `%ð `%ð `%ð `%ðFð ð ð /3¸hÈeÈeÉgÌgð 9KÐ`dð 9Kð 9Kð 9Kð 9Kð 9Kð 9Kð 9Kr#   