Ë
    7^(h0  ã                   ón   — d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 	  G d„ de«      Z
 G d„ d	e«      Zy)
é    N)ÚInterval)Úis_increasingÚis_decreasing)ÚOptimization)ÚUndefinedFunctionc                   ó4   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Zˆ xZS )Ú	SumApproxa8  
    Approximates sum by neglecting small terms.

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

    If terms are expressions which can be determined to be monotonic, then
    bounds for those expressions are added.

    Parameters
    ==========

    bounds : dict
        Mapping expressions to length 2 tuple of bounds (low, high).
    reltol : number
        Threshold for when to ignore a term. Taken relative to the largest
        lower bound among bounds.

    Examples
    ========

    >>> from sympy import exp
    >>> from sympy.abc import x, y, z
    >>> from sympy.codegen.rewriting import optimize
    >>> from sympy.codegen.approximations import SumApprox
    >>> bounds = {x: (-1, 1), y: (1000, 2000), z: (-10, 3)}
    >>> sum_approx3 = SumApprox(bounds, reltol=1e-3)
    >>> sum_approx2 = SumApprox(bounds, reltol=1e-2)
    >>> sum_approx1 = SumApprox(bounds, reltol=1e-1)
    >>> expr = 3*(x + y + exp(z))
    >>> optimize(expr, [sum_approx3])
    3*(x + y + exp(z))
    >>> optimize(expr, [sum_approx2])
    3*y + 3*exp(z)
    >>> optimize(expr, [sum_approx1])
    3*y

    c                 ó@   •— t        ‰| �  di |¤Ž || _        || _        y )N© )ÚsuperÚ__init__ÚboundsÚreltol)Úselfr   r   ÚkwargsÚ	__class__s       €úZ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/codegen/approximations.pyr   zSumApprox.__init__6   s!   ø€ Ü‰ÑÑ"˜6Ò"ØˆŒØˆ�ó    c                 ó^   ‡ — |j                  «       j                  ‰ j                  ˆ fd„«      S )Nc                 ó&   •— ‰j                  | «      S ©N©Úvalue©Úargr   s    €r   ú<lambda>z$SumApprox.__call__.<locals>.<lambda><   ó   ø€ ¸T¿Z¹ZÈ»_€ r   ©ÚfactorÚreplaceÚquery©r   Úexprs   ` r   Ú__call__zSumApprox.__call__;   ó!   ø€ Ø�{‰{‹}×$Ñ$ T§Z¡ZÓ1LÓMÐMr   c                 ó   — |j                   S r   )Úis_Addr"   s     r   r!   zSumApprox.query>   s   € Ø�{‰{Ðr   c           
      óž  ‡ — |j                   D �]-  }|j                  s&|‰ j                  v st        |j                  «      dk7  rŒ7|j                  \  }|‰ j                  vrŒTt        ‰ j                  |   Ž }t        |||«      rT|j                  |‰ j                  |   d   i«      |j                  |‰ j                  |   d   i«      f‰ j                  |<   ŒÊt        |||«      rU|j                  |‰ j                  |   d   i«      |j                  |‰ j                  |   d   i«      f‰ j                  |<   �Œ,|c S  t        ˆ fd„|j                   D «       «      rë|j                   D �cg c]!  }|j                  r||fn‰ j                  |   ‘Œ# }}d}|D ]<  \  }}|dcxk  r|k  rn nŒt        |t        t        |«      t        |«      «      «      }Œ> g }	t        |j                   |«      D ]H  \  }\  }}t        t        |«      t        |«      «      |‰ j                  z  k\  sŒ8|	j                  |«       ŒJ  |j                   |	Ž S |S c c}w )Né   r   c              3   óV   •K  — | ]   }|j                   xs |‰j                  v –— Œ" y ­wr   )Ú	is_numberr   )Ú.0Útermr   s     €r   ú	<genexpr>z"SumApprox.value.<locals>.<genexpr>V   s&   øè ø€ ÒJ¸ˆt�~‰~Ò4 ¨¯©Ð!4Ó4ÑJùs   ƒ&))Úargsr+   r   ÚlenÚfree_symbolsr   r   Úsubsr   ÚallÚmaxÚminÚabsÚzipr   ÚappendÚfunc)
r   Úaddr-   ÚfsÚintrvlr   Úlargest_abs_guaranteeÚloÚhiÚ	new_termss
   `         r   r   zSumApprox.valueA   s+  ø€ Ø—H‘Hó 	ˆDØ�~Š~ ¨¯©Ñ!4¼¸D×<MÑ<MÓ8NÐRSÒ8SØØ×#Ñ#‰CˆBØ˜Ÿ™Ñ$ØÜ˜tŸ{™{¨2™Ð/ˆFÜ˜T 6¨2Ô.à—I‘I˜r 4§;¡;¨r¡?°1Ñ#5Ð6Ó7Ø—I‘I˜r 4§;¡;¨r¡?°1Ñ#5Ð6Ó7ð%�—‘˜DÒ!ô ˜t V¨RÔ0à—I‘I˜r 4§;¡;¨r¡?°1Ñ#5Ð6Ó7Ø—I‘I˜r 4§;¡;¨r¡?°1Ñ#5Ð6Ó7ð%�—‘˜DÓ!ð
 ’
ð%	ô( ÓJÀÇÁÔJÔJØX[×X`ÑX`ÖaÐPT d§n¢n�t˜T‘l¸$¿+¹+ÀdÑ:KÑKÐaˆFÐaØ$%Ð!Ø ò C‘��BØ˜”=˜b•=ØÜ(+Ð,AÜ,/´°B³¼¸R»Ó,Aó)CÑ%ðCð
 ˆIÜ"% c§h¡h°Ó"7ò +‘�‘h�r˜2Ü”s˜2“w¤ B£Ó(Ð,AÀ$Ç+Á+Ñ,MÓMØ×$Ñ$ TÕ*ð+ð �3—8‘8˜YÐ'Ð'àˆJùò bs   Å+&I
©	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r!   r   Ú__classcell__©r   s   @r   r	   r	      s   ø„ ñ%ôNò
Nòö#r   r	   c                   ó6   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zd„ Zˆ xZS )ÚSeriesApproxa    Approximates functions by expanding them as a series.

    Parameters
    ==========

    bounds : dict
        Mapping expressions to length 2 tuple of bounds (low, high).
    reltol : number
        Threshold for when to ignore a term. Taken relative to the largest
        lower bound among bounds.
    max_order : int
        Largest order to include in series expansion
    n_point_checks : int (even)
        The validity of an expansion (with respect to reltol) is checked at
        discrete points (linearly spaced over the bounds of the variable). The
        number of points used in this numerical check is given by this number.

    Examples
    ========

    >>> from sympy import sin, pi
    >>> from sympy.abc import x, y
    >>> from sympy.codegen.rewriting import optimize
    >>> from sympy.codegen.approximations import SeriesApprox
    >>> bounds = {x: (-.1, .1), y: (pi-1, pi+1)}
    >>> series_approx2 = SeriesApprox(bounds, reltol=1e-2)
    >>> series_approx3 = SeriesApprox(bounds, reltol=1e-3)
    >>> series_approx8 = SeriesApprox(bounds, reltol=1e-8)
    >>> expr = sin(x)*sin(y)
    >>> optimize(expr, [series_approx2])
    x*(-y + (y - pi)**3/6 + pi)
    >>> optimize(expr, [series_approx3])
    (-x**3/6 + x)*sin(y)
    >>> optimize(expr, [series_approx8])
    sin(x)*sin(y)

    c                 óò   •— t        ‰| �  di |¤Ž || _        || _        || _        |dz  dk(  rt        d«      ‚|| _        t        j                  t        j                  | j                  «       «      | _
        y )Né   r)   z7Checking the solution at expansion point is not helpfulr   )r   r   r   r   Ú	max_orderÚ
ValueErrorÚn_point_checksÚmathÚceilÚlog10Ú_prec)r   r   r   rL   rN   r   r   s         €r   r   zSeriesApprox.__init__�   si   ø€ Ü‰ÑÑ"˜6Ò"ØˆŒØˆŒØ"ˆŒØ˜AÑ Ò"ÜÐVÓWÐWØ,ˆÔÜ—Y‘Y¤§
¡
¨4¯;©;Ó 7Ð7Ó8ˆ�
r   c                 ó^   ‡ — |j                  «       j                  ‰ j                  ˆ fd„«      S )Nc                 ó&   •— ‰j                  | «      S r   r   r   s    €r   r   z'SeriesApprox.__call__.<locals>.<lambda>˜   r   r   r   r"   s   ` r   r$   zSeriesApprox.__call__—   r%   r   c                 ót   — |j                   xr+ t        |t        «       xr t        |j                  «      dk(  S )Nr)   )Úis_FunctionÚ
isinstancer   r0   r/   r"   s     r   r!   zSeriesApprox.queryš   s7   € Ø× Ñ ò (¬°DÔ:KÓ)LÐ%Lò (Ü˜Ÿ	™	“N aÑ'ð	)r   c                 ód  — |j                   }t        |«      dk7  r|S |\  }|| j                  vr|S | j                  |   \  }}||z   dz  }d }t        | j                  dz   dd«      D ]Â  }|j                  |||¬«      j                  «       }	d}
t        | j                  «      D ]~  }||||z
  z  | j                  dz
  z  z   }|	j                  ||i«      }|j                  ||i«      }t        d||z  z
  j                  | j                  «      «      | j                  kD  sŒ|d}
 n |
r|	}ŒÂ n |€|S |S )Nr)   rK   r   éÿÿÿÿ)Úx0ÚnTF)r1   r0   r   ÚrangerL   ÚseriesÚremoveOrN   Úxreplacer6   ÚevalfrR   r   )r   Úfexprr1   Úsymbr>   r?   rZ   Úcheapestr[   ÚfseriÚn_okÚidxÚxÚvalÚrefs                  r   r   zSeriesApprox.valuež   sM  € Ø×)Ñ)ˆÜˆ|Ó Ò!ØˆLØ‰ˆØ�t—{‘{Ñ"ØˆLØ—‘˜TÑ"‰ˆˆBØ�2‰g�q‰[ˆØˆÜ�t—~‘~ aÑ'¨¨BÓ/ò 	ˆAØ—L‘L ¨"°�LÓ2×:Ñ:Ó<ˆEØˆDÜ˜T×0Ñ0Ó1ò �Ø˜˜b 2™g™¨×(;Ñ(;¸aÑ(?Ñ@Ñ@�Ø—n‘n d¨A YÓ/�Ø—n‘n d¨A YÓ/�Ü˜˜C ™G™×*Ñ*¨4¯:©:Ó6Ó7¸$¿+¹+ÓEØ �DÙðñ Ø ‘áð	ð  ÐØˆLàˆOr   )é   rj   rA   rG   s   @r   rI   rI   g   s   ø„ ñ$õJ9òNò)ör   rI   )rO   Úsympy.sets.setsr   Úsympy.calculus.singularitiesr   r   Úsympy.codegen.rewritingr   Úsympy.core.functionr   r	   rI   r   r   r   ú<module>ro      s6   ðÛ Ý $ß EÝ 0Ý 1ðôV�ô VôrT�<õ Tr   