
    gq>                        d dl mZmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z   G d de!          Z" G d de"eee
eeeeeeeeee          Z#dS )    )gtlt   )xrange)SpecialFunctions)RSCache)QuadratureMethods) LaplaceTransformInversionMethods)CalculusMethods)OptimizationMethods)
ODEMethods)MatrixMethods)MatrixCalculusMethods)LinearAlgebraMethods)Eigen)IdentificationMethods)VisualizationMethods)libmpc                       e Zd ZdS )ContextN)__name__
__module____qualname__     K/var/www/html/ai-engine/env/lib/python3.11/site-packages/mpmath/ctx_base.pyr   r      s        Dr   r   c                      e Zd Zej        Zej        Zd Zd ZdZdZ	d Z
d Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd"dZd#dZd Zd$dZd%dZd&dZd Zd Zd Zd Zd Z eej                   Z! eej"                  Z" eej#                  Z# eej$                  Z$ eej%                  Z% eej&                  Z' eej(                  Z) eej*                  Z+ eej,                  Z-d'dZ.d'dZ/d Z0d Z1d  Z2d! Z3dS )(StandardBaseContextc                    i | _         t          j        |            t          j        |            t	          j        |            t          j        |            t          j        |            t          j        |            d S N)_aliasesr   __init__r   r	   r
   r   r   )ctxs    r   r"   zStandardBaseContext.__init__*   su    !#&&&"3'''(1#666 %%%s#####r   c           	          | j                                         D ]5\  }}	 t          | |t          | |                     &# t          $ r Y 2w xY wd S r    )r!   itemssetattrgetattrAttributeError)r#   aliasvalues      r   _init_aliasesz!StandardBaseContext._init_aliases4   sq    L..00 	 	LE5UGC$7$78888!   	 	s   A  
AAFc                 &    t          d|           d S )NzWarning:)printr#   msgs     r   warnzStandardBaseContext.warn@   s    j#r   c                      t          |          r    )
ValueErrorr.   s     r   
bad_domainzStandardBaseContext.bad_domainC   s    oor   c                 4    t          |d          r|j        S |S )Nreal)hasattrr5   r#   xs     r   _rezStandardBaseContext._reF   s     1f 	6Mr   c                 >    t          |d          r|j        S | j        S )Nimag)r6   r;   zeror7   s     r   _imzStandardBaseContext._imK   s"    1f 	6Mxr   c                     |S r    r   r7   s     r   
_as_pointszStandardBaseContext._as_pointsP   s    r   c                 .    |                      |           S r    convert)r#   r8   kwargss      r   fnegzStandardBaseContext.fnegS   s    Ar   c                 X    |                      |          |                      |          z   S r    rA   r#   r8   yrC   s       r   faddzStandardBaseContext.faddV   !    {{1~~ckk!nn,,r   c                 X    |                      |          |                      |          z
  S r    rA   rF   s       r   fsubzStandardBaseContext.fsubY   rI   r   c                 X    |                      |          |                      |          z  S r    rA   rF   s       r   fmulzStandardBaseContext.fmul\   rI   r   c                 X    |                      |          |                      |          z  S r    rA   rF   s       r   fdivzStandardBaseContext.fdiv_   rI   r   c                     |r@|rt          d |D             | j                  S t          d |D             | j                  S |rt          d |D             | j                  S t          || j                  S )Nc              3   :   K   | ]}t          |          d z  V  dS    Nabs.0r8   s     r   	<genexpr>z+StandardBaseContext.fsum.<locals>.<genexpr>e   s,      44!CFFAI444444r   c              3   4   K   | ]}t          |          V  d S r    rT   rV   s     r   rX   z+StandardBaseContext.fsum.<locals>.<genexpr>f   s(      --1A------r   c              3       K   | ]	}|d z  V  
dS rR   r   rV   s     r   rX   z+StandardBaseContext.fsum.<locals>.<genexpr>h   s&      ++1++++++r   )sumr<   )r#   argsabsolutesquareds       r   fsumzStandardBaseContext.fsumb   s     	9 @44t444ch???-----sx888 	7++d+++SX6664"""r   Nc                     |t          ||          }|r(| j        t          fd|D             | j                  S t          d |D             | j                  S )Nc              3   :   K   | ]\  }}| |          z  V  d S r    r   )rW   r8   rG   cfs      r   rX   z+StandardBaseContext.fdot.<locals>.<genexpr>p   s3      00EQq""Q%%000000r   c              3   &   K   | ]\  }}||z  V  d S r    r   )rW   r8   rG   s      r   rX   z+StandardBaseContext.fdot.<locals>.<genexpr>r   s*      ,,1!,,,,,,r   )zipconjr[   r<   )r#   xsys	conjugaterb   s       @r   fdotzStandardBaseContext.fdotk   sl    >RB 	8B0000R000#(;;;,,,,,ch777r   c                 (    | j         }|D ]}||z  }|S r    )one)r#   r\   prodargs       r   fprodzStandardBaseContext.fprodt   s(    w 	 	CCKDDr      c                 >    t           | j        ||fi |           dS )z6
        Equivalent to ``print(nstr(x, n))``.
        N)r-   nstr)r#   r8   nrC   s       r   nprintzStandardBaseContext.nprintz   s.     	hchq!&&v&&'''''r   c                 X    
d j         z  	                      |          }t          |          }t          |          k     r j        S                      |          ret          |z            }t          |j                  |k     r|j        S t          |j                  |k     r                     d|j                  S na# t          $ rT t          | j                  r|                     fd          cY S t          |d          r fd|D             cY S Y nw xY w|S )a  
        Chops off small real or imaginary parts, or converts
        numbers close to zero to exact zeros. The input can be a
        single number or an iterable::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> chop(5+1e-10j, tol=1e-9)
            mpf('5.0')
            >>> nprint(chop([1.0, 1e-20, 3+1e-18j, -4, 2]))
            [1.0, 0.0, 3.0, -4.0, 2.0]

        The tolerance defaults to ``100*eps``.
        Nd   r   c                 0                         |           S r    chop)ar#   tols    r   <lambda>z*StandardBaseContext.chop.<locals>.<lambda>   s    !S)9)9 r   __iter__c                 <    g | ]}                     |          S r   rw   )rW   ry   r#   rz   s     r   
<listcomp>z,StandardBaseContext.chop.<locals>.<listcomp>   s'    444QC((444r   )epsrB   rU   r<   _is_complex_typemaxr;   r5   mpc	TypeError
isinstancematrixapplyr6   )r#   r8   rz   absxpart_tols   ` `  r   rx   zStandardBaseContext.chop   sR    ;cg+C	5AAq66D1vv||x##A&& .sDH--qv;;))6Mqv;;))771af--- 	5 	5 	5!SZ(( ;ww99999:::::q*%% 544444!4444445 5	5
 s$   =C	 AC	 2C	 	8D'D'&D'c                 &   |                      |          }|#|!|                     d| j         dz             x}}||}n||}t          ||z
            }||k    rdS t          |          }t          |          }||k     r||z  }n||z  }||k    S )a  
        Determine whether the difference between `s` and `t` is smaller
        than a given epsilon, either relatively or absolutely.

        Both a maximum relative difference and a maximum difference
        ('epsilons') may be specified. The absolute difference is
        defined as `|s-t|` and the relative difference is defined
        as `|s-t|/\max(|s|, |t|)`.

        If only one epsilon is given, both are set to the same value.
        If none is given, both epsilons are set to `2^{-p+m}` where
        `p` is the current working precision and `m` is a small
        integer. The default setting typically allows :func:`~mpmath.almosteq`
        to be used to check for mathematical equality
        in the presence of small rounding errors.

        **Examples**

            >>> from mpmath import *
            >>> mp.dps = 15
            >>> almosteq(3.141592653589793, 3.141592653589790)
            True
            >>> almosteq(3.141592653589793, 3.141592653589700)
            False
            >>> almosteq(3.141592653589793, 3.141592653589700, 1e-10)
            True
            >>> almosteq(1e-20, 2e-20)
            True
            >>> almosteq(1e-20, 2e-20, rel_eps=0, abs_eps=0)
            False

        Nr      T)rB   ldexpprecrU   )	r#   strel_epsabs_epsdiffabssabsterrs	            r   almosteqzStandardBaseContext.almosteq   s    B KKNN?w #		!chYq[ 9 99Gg?GG_G1Q3xx7??41vv1vv$;;t)CCt)Cg~r   c                    t          |          dk    st          dt          |          z            t          |          dk    st          dt          |          z            d}d}t          |          dk    r	|d         }n#t          |          dk    r|d         }|d         }t          |          dk    r|d         }|                     |          |                     |          |                     |          }}}||z   |k    s
J d            ||k    r|dk    rg S t          }n|dk     rg S t          }g }d}|}	 |||z  z   }|dz  } |||          r|                    |           nn1|S )aa  
        This is a generalized version of Python's :func:`~mpmath.range` function
        that accepts fractional endpoints and step sizes and
        returns a list of ``mpf`` instances. Like :func:`~mpmath.range`,
        :func:`~mpmath.arange` can be called with 1, 2 or 3 arguments:

        ``arange(b)``
            `[0, 1, 2, \ldots, x]`
        ``arange(a, b)``
            `[a, a+1, a+2, \ldots, x]`
        ``arange(a, b, h)``
            `[a, a+h, a+h, \ldots, x]`

        where `b-1 \le x < b` (in the third case, `b-h \le x < b`).

        Like Python's :func:`~mpmath.range`, the endpoint is not included. To
        produce ranges where the endpoint is included, :func:`~mpmath.linspace`
        is more convenient.

        **Examples**

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> arange(4)
            [mpf('0.0'), mpf('1.0'), mpf('2.0'), mpf('3.0')]
            >>> arange(1, 2, 0.25)
            [mpf('1.0'), mpf('1.25'), mpf('1.5'), mpf('1.75')]
            >>> arange(1, -1, -0.75)
            [mpf('1.0'), mpf('0.25'), mpf('-0.5')]

           z+arange expected at most 3 arguments, got %ir   z+arange expected at least 1 argument, got %ir   rS   z0dt is too small and would cause an infinite loop)lenr   mpfr   r   append)	r#   r\   ry   dtbopresultir   s	            r   arangezStandardBaseContext.arange   s   @ 4yyA~~I!$ii( ) ) )4yyA~~I!$ii( ) ) ) t99>>QAAYY!^^QAQAt99>>aB771::swwqzz3772;;b12v{{{N{{{q55Avv	BBAvv	B	BqDAFAr!Qxx a    	 r   c                 $   t          |          dk    rL|                     |d                   |                     |d                   }t          |d                   }nzt          |          dk    rHt          |d         d          sJ |d         j        |d         j        }t          |d                   }nt          dt          |          z            |dk     rt          d          d|vs|d         r\|dk    r|                               gS |z
  |                     |dz
            z  fd	t          |          D             }||d
<   n7|z
  |                     |          z  fdt          |          D             }|S )a  
        ``linspace(a, b, n)`` returns a list of `n` evenly spaced
        samples from `a` to `b`. The syntax ``linspace(mpi(a,b), n)``
        is also valid.

        This function is often more convenient than :func:`~mpmath.arange`
        for partitioning an interval into subintervals, since
        the endpoint is included::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> linspace(1, 4, 4)
            [mpf('1.0'), mpf('2.0'), mpf('3.0'), mpf('4.0')]

        You may also provide the keyword argument ``endpoint=False``::

            >>> linspace(1, 4, 4, endpoint=False)
            [mpf('1.0'), mpf('1.75'), mpf('2.5'), mpf('3.25')]

        r   r   r   rS   _mpi_z*linspace expected 2 or 3 arguments, got %izn must be greater than 0endpointc                      g | ]
}|z  z   S r   r   rW   r   ry   steps     r   r~   z0StandardBaseContext.linspace.<locals>.<listcomp>G  !    ///4!///r   c                      g | ]
}|z  z   S r   r   r   s     r   r~   z0StandardBaseContext.linspace.<locals>.<listcomp>K  r   r   )	r   r   intr6   ry   r   r   r2   r   )r#   r\   rC   r   rr   rG   ry   r   s         @@r   linspacezStandardBaseContext.linspace   s   * t99>>Q  AQ  ADGAAYY!^^47G,,,,,Q	AQ	ADGAAH!$ii( ) ) )q557888V##vj'9#Avv

|#ESWWQU^^+D/////VAYY///AAbEEESWWQZZ'D/////VAYY///Ar   c                 :     | j         |fi | | j        |fi |fS r    )cossinr#   zrC   s      r   cos_sinzStandardBaseContext.cos_sinN  s5    swq##F##WSWQ%9%9&%9%999r   c                 :     | j         |fi | | j        |fi |fS r    )cospisinpir   s      r   cospi_sinpizStandardBaseContext.cospi_sinpiQ  s5    sy%%f%%ysy'='=f'='===r   c                 8    t          d|dz  z  d|z  z             S )Ni  g      ?r   )r   )r#   ps     r   _default_hyper_maxprecz*StandardBaseContext._default_hyper_maxprecT  s!    4!T'>AaC'(((r   r   c                    | j         }	 d}	 ||z   dz   | _         | j        }| j        }d} |            D ]]}||z  }||z  sL|rJ|                     |          }	t	          ||	          }|                     |          }
|
|	z
  | j         k    r n|dz  }^||
z
  }||k    rn'||k     s| j        rn|t          | j         |          z  }||| _         S # || _         w xY wN
   r      r   )r   ninfr<   magr   _fixed_precisionmin)r#   terms
check_stepr   	extraprecmax_magr   ktermterm_magsum_magcancellations               r   sum_accuratelyz"StandardBaseContext.sum_accuratelya  s"   x	I9)+a/(H!EGG  DIA
N " "#&774=="%gx"8"8"%''!**"X-88!EFAA&0<//)++s/C+S<888	'9( CHHtCHOOOOs   B<C 	Cc                    | j         }	 d}	 ||z   dz   | _         | j        }| j        }|}d} |            D ]a}	||	z  }|	|z
  }
||z  sK|                     |
          }t	          ||          }|                     ||z
            }| | j         k    r n|dz  }b||z
  }||k    rn'||k     s| j        rn|t          | j         |          z  }||| _         S # || _         w xY wr   )r   r   rk   r   r   r   r   )r#   factorsr   r   r   r   rk   r   r   factorr   r   r   r   s                 r   mul_accuratelyz"StandardBaseContext.mul_accurately}  s,   x	I9)+a/(g%gii  FKA!C<D
N "#&774=="%gx"8"8"%''!C%.. %9sx//!EFAA&0<//)++s/C+S<888	/90 CHHtCHOOOOs   CC 	Cc                 X    |                      |          |                      |          z  S )a  Converts `x` and `y` to mpmath numbers and evaluates
        `x^y = \exp(y \log(x))`::

            >>> from mpmath import *
            >>> mp.dps = 30; mp.pretty = True
            >>> power(2, 0.5)
            1.41421356237309504880168872421

        This shows the leading few digits of a large Mersenne prime
        (performing the exact calculation ``2**43112609-1`` and
        displaying the result in Python would be very slow)::

            >>> power(2, 43112609)-1
            3.16470269330255923143453723949e+12978188
        rA   )r#   r8   rG   s      r   powerzStandardBaseContext.power  s#      {{1~~Q//r   c                 ,    |                      |          S r    )zeta)r#   rr   s     r   	_zeta_intzStandardBaseContext._zeta_int  s    xx{{r   c                 $     dg fd}|S )a  
        Return a wrapped copy of *f* that raises ``NoConvergence`` when *f*
        has been called more than *N* times::

            >>> from mpmath import *
            >>> mp.dps = 15
            >>> f = maxcalls(sin, 10)
            >>> print(sum(f(n) for n in range(10)))
            1.95520948210738
            >>> f(10) # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
              ...
            NoConvergence: maxcalls: function evaluated 10 times

        r   c                  |    dxx         dz  cc<   d         k    r                     dz             | i |S )Nr   r   z%maxcalls: function evaluated %i times)NoConvergence)r\   rC   Ncounterr#   fs     r   f_maxcalls_wrappedz8StandardBaseContext.maxcalls.<locals>.f_maxcalls_wrapped  sU    AJJJ!OJJJqzA~~''(ORS(STTT1d%f%%%r   r   )r#   r   r   r   r   s   ``` @r   maxcallszStandardBaseContext.maxcalls  s?      #	& 	& 	& 	& 	& 	& 	& 	&
 "!r   c                 N     i  fd}j         |_         j        |_        |S )a  
        Return a wrapped copy of *f* that caches computed values, i.e.
        a memoized copy of *f*. Values are only reused if the cached precision
        is equal to or higher than the working precision::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = True
            >>> f = memoize(maxcalls(sin, 1))
            >>> f(2)
            0.909297426825682
            >>> f(2)
            0.909297426825682
            >>> mp.dps = 25
            >>> f(2) # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
              ...
            NoConvergence: maxcalls: function evaluated 1 times

        c                      |r$| t          |                                          f}n| }j        }|	v r	|         \  }}||k    r|
 S  | i |}||f	|<   |S r    )tupler%   r   )
r\   rC   keyr   cpreccvaluer*   r#   r   f_caches
          r   f_cachedz-StandardBaseContext.memoize.<locals>.f_cached  s     E&,,..1118Dg~~ 'vD=="7NAt&v&&E %=GCLLr   )r   __doc__)r#   r   r   r   s   `` @r   memoizezStandardBaseContext.memoize  sJ    ( 	 	 	 	 	 	 	 J9r   )FF)NF)ro   r    )NN)r   )4r   r   r   r   r   ComplexResultr"   r+   r   verboser0   r3   r9   r=   r?   rD   rH   rK   rM   rO   r_   ri   rn   rs   rx   r   r   r   r   r   r   staticmethodgcd_gcdlist_primesisprimebernfracmoebiusifac_ifaceulernum	_eulernum	stirling1
_stirling1	stirling2
_stirling2r   r   r   r   r   r   r   r   r   r   r      s        'M'M$ $ $    G      
  
    - - -- - -- - -- - -# # # #8 8 8 8  ( ( ( (" " " "H1 1 1 1fG G GR, , ,\: : :> > >) ) ) <	""D,u011Kl5=))G|EN++Hl5=))GL$$EU^,,Ieo..Jeo..J   8   @0 0 0$  " " "0$ $ $ $ $r   r   N)$operatorr   r   libmp.backendr   functions.functionsr   functions.rszetar   calculus.quadraturer	   calculus.inverselaplacer
   calculus.calculusr   calculus.optimizationr   calculus.odesr   matrices.matricesr   matrices.calculusr   matrices.linalgr   matrices.eigenr   identificationr   visualizationr    r   objectr   r   r   r   r   <module>r     s           ! ! ! ! ! ! 1 1 1 1 1 1 % % % % % % 2 2 2 2 2 2 E E E E E E . . . . . . 6 6 6 6 6 6 % % % % % % , , , , , , 4 4 4 4 4 4 1 1 1 1 1 1 ! ! ! ! ! ! 1 1 1 1 1 1 / / / / / /      	 	 	 	 	f 	 	 	V V V V V'$	V V V V Vr   