K iq>ddlmZmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlm Z Gdde!Z"Gdde"eee e eeeeeeeeeZ#y))gtlt)xrange)SpecialFunctions)RSCache)QuadratureMethods) LaplaceTransformInversionMethods)CalculusMethods)OptimizationMethods) ODEMethods) MatrixMethods)MatrixCalculusMethods)LinearAlgebraMethods)Eigen)IdentificationMethods)VisualizationMethods)libmpc eZdZy)ContextN)__name__ __module__ __qualname__U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mpmath/ctx_base.pyrrsrrcDeZdZejZej ZdZdZdZdZ dZ dZ dZ dZ dZd Zd Zd Zd Zd Zd dZd!dZdZd"dZd#dZd$dZdZdZdZdZdZeej@Z!eejDZ"eejFZ#eejHZ$eejJZ%eejLZ'eejPZ)eejTZ+eejXZ-d%dZ.d%dZ/dZ0dZ1dZ2dZ3y)&StandardBaseContextci|_tj|tj|t j|t j|t j|tj|yN)_aliasesr__init__rr r r r)ctxs rr"zStandardBaseContext.__init__*s] !!#&""3'(11#6  %s#rc |jjD]\}} t||t||y#t$rY,wxYwr )r!itemssetattrgetattrAttributeError)r#aliasvalues r _init_aliasesz!StandardBaseContext._init_aliases4sNLL..0 LE5 UGC$78 "  s< AAFctd|y)NzWarning:)printr#msgs rwarnzStandardBaseContext.warn@s  j#rct|r ) ValueErrorr.s r bad_domainzStandardBaseContext.bad_domainCs orc6t|dr |jS|S)Nreal)hasattrr5r#xs r_rezStandardBaseContext._reFs 1f 66MrcJt|dr |jS|jS)Nimag)r6r;zeror7s r_imzStandardBaseContext._imKs 1f 66Mxxrc|Sr rr7s r _as_pointszStandardBaseContext._as_pointsPsrc &|j| Sr convert)r#r8kwargss rfnegzStandardBaseContext.fnegSs Arc H|j||j|zSr rAr#r8yrCs rfaddzStandardBaseContext.faddV{{1~ckk!n,,rc H|j||j|z Sr rArFs rfsubzStandardBaseContext.fsubYrIrc H|j||j|zSr rArFs rfmulzStandardBaseContext.fmul\rIrc H|j||j|z Sr rArFs rfdivzStandardBaseContext.fdiv_rIrc|r<|rtd|D|jStd|D|jS|rtd|D|jSt||jS)Nc38K|]}t|dzywNabs.0r8s r z+StandardBaseContext.fsum..es4!CFAI4sc32K|]}t|ywr rTrVs rrXz+StandardBaseContext.fsum..fs-1A-sc3&K|] }|dz ywrRrrVs rrXz+StandardBaseContext.fsum..hs+1+s)sumr<)r#argsabsolutesquareds rfsumzStandardBaseContext.fsumbsa 4t4chh??--sxx8 8 +d+SXX6 64""rNc| t||}|r+|jtfd|D|jStd|D|jS)Nc3:K|]\}}||zywr r)rWr8rGcfs rrXz+StandardBaseContext.fdot..ps0EQq"Q%0sc3,K|] \}}||zywr r)rWr8rGs rrXz+StandardBaseContext.fdot..rs,1!,s)zipconjr[r<)r#xsys conjugaterbs @rfdotzStandardBaseContext.fdotksM >RB B0R0#((; ;,,chh7 7rc6|j}|D]}||z} |Sr )one)r#r\prodargs rfprodzStandardBaseContext.fprodts(ww C CKD  rc >t|j||fi|y)z6 Equivalent to ``print(nstr(x, n))``. N)r-nstr)r#r8nrCs rnprintzStandardBaseContext.nprintzs hchhq!&v&'rcldjz j|}t|}t|kr jSj |rgt |z}t|j |kr |jSt|j|krjd|j S|S#t$ret|jr|jfdcYSt|dr(|Dcgc]}j|ncc}wc}cYSY|SwxYw)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``. drc(j|Sr )chop)ar#tols rz*StandardBaseContext.chop..s!S)9r__iter__)epsrBrUr<_is_complex_typemaxr;r5mpc TypeError isinstancematrixapplyr6rv)r#r8rxabsxpart_tolrws` ` rrvzStandardBaseContext.chops  ;cgg+C 5 AAq6D1v|xx##A&sDH-qvv;)66Mqvv;)771aff--   5!SZZ(ww9::q*%234QC(444&  5s05C AC3C4D3;D3 D%$ D32D3c|j|}|$|"|jd|j dzx}}||}n||}t||z }||kryt|}t|}||kr ||z }||kS||z }||kS)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 rT)rBldexpprecrU) r#strel_epsabs_epsdiffabssabsterrs ralmosteqzStandardBaseContext.almosteqsB KKN ?w # !chhYq[ 9 9Gg ?G _G1Q3x 7?1v1v $;t)Cg~t)Cg~rcFt|dkstdt|zt|dk\stdt|zd}d}t|dk(r|d}nt|dk\r |d}|d}t|dk(r|d}|j||j|j|}}}||z|k7sJd||kDr|dkDrgSt}n |dkrgSt}g}d}|} |||zz}|dz }|||r|j |n |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 %irz+arange expected at least 1 argument, got %irrSz0dt is too small and would cause an infinite loop)lenrmpfrrappend) r#r\rwdtbopresultirs rarangezStandardBaseContext.arangesR@4yA~I!$i() )4yA~I!$i() )   t9>QA Y!^QAQA t9>aB771:swwqz3772;b12v{NNN{ q5Av BAv B  BqDA FA!Qx a  rct|dk(r7|j|d}|j|d}t|d}nct|dk(r>t|ddsJ|dj}|dj }t|d}nt dt|z|dkr tdd|vs|drV|dk(r|j|gS||z |j|dz z }t|Dcgc] }||z|z }}||d <|S||z |j|z }t|Dcgc] }||z|z }}|Scc}wcc}w) 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')] rrrrS_mpi_z*linspace expected 2 or 3 arguments, got %izn must be greater than 0endpoint) rrintr6rwrrr2r) r#r\rCrwrrqsteprrGs rlinspacezStandardBaseContext.linspace sj* t9>Q AQ ADG A Y!^47G, ,,Q AQ ADG AH!$i() ) q578 8V#vj'9Av |#ESWWQU^+D%+AY/4!/A/AbEESWWQZ'D%+AY/4!/A/ 00s E<Ec N|j|fi||j|fi|fSr )cossinr#zrCs rcos_sinzStandardBaseContext.cos_sinNs-swwq#F#WSWWQ%9&%999rc N|j|fi||j|fi|fSr )cospisinpirs r cospi_sinpizStandardBaseContext.cospi_sinpiQs-syy%f%ysyy'=f'===rc0td|dzzd|zzS)Nig?r)r)r#ps r_default_hyper_maxprecz*StandardBaseContext._default_hyper_maxprecTs4!T'>AaC'((rc|j} d} ||zdz|_|j}|j}d}|D]U}||z }||zsD|rB|j|} t || }|j|} | | z |jkDrn|dz }W| z } | | k7rn,| |ks |j rn|t |j| z }|||_S#||_wxYwN rr)rninfr<magr}_fixed_precisionmin) r#terms check_stepr extraprecmax_magrktermterm_magsum_mag cancellations rsum_accuratelyz"StandardBaseContext.sum_accuratelyasxx I)+a/((HH!GDIA N#&774="%gx"8"%''!*"X-8!FA '0 </)+s/C/CS<88 '(CHtCHs CC C c|j} d} ||zdz|_|j}|j}|}d}|D]Y} || z}| |z } ||zsC|j| } t || }|j||z } | |jkDrn|dz }[| z } | | k7rn,| |ks |j rn|t |j| z }|||_S#||_wxYwr)rrrkrr}rr)r#factorsrrrrrkrrfactorrrrrs rmul_accuratelyz"StandardBaseContext.mul_accurately}s xx I)+a/((gg%i FKA!C>> 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#r8rGs rpowerzStandardBaseContext.powers {{1~Q//rc$|j|Sr )zeta)r#rqs r _zeta_intzStandardBaseContext._zeta_intsxx{rc$dgfd}|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 rcfdxxdz cc<dkDrjdz|i|S)Nrrz%maxcalls: function evaluated %i times) NoConvergence)r\rCNcounterr#fs rf_maxcalls_wrappedz8StandardBaseContext.maxcalls..f_maxcalls_wrappedsC AJ!OJqzA~''(ORS(STTd%f% %rr)r#rrrrs``` @rmaxcallszStandardBaseContext.maxcallss # & "!rcbifd}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|jf}n|}j}| vr |\}}||k\r|S|i|}||f |<|Sr )tupler%r) r\rCkeyrcpreccvaluer*r#rf_caches rf_cachedz-StandardBaseContext.memoize..f_cachedslE&,,.1188Dg~ ' vD="7Nt&v&E %=GCLLr)r__doc__)r#rrrs`` @rmemoizezStandardBaseContext.memoizes.( JJ99r)FF)NF)r )NN)r)4rrrrr ComplexResultr"r+rverboser0r3r9r=r?rDrHrKrMrOr_rirnrrrvrrrrrr staticmethodgcd_gcd list_primesisprimebernfracmoebiusifac_ifaceulernum _eulernum stirling1 _stirling1 stirling2 _stirling2rrrrrrrrrrrsB''M''M$G  ----#8 ( "H1fGR,\:>)  "Du001K5==)GENN+H5==)G  $EU^^,Ieoo.Jeoo.J8@0$"0$rrN)$operatorrr libmp.backendrfunctions.functionsrfunctions.rszetarcalculus.quadraturer calculus.inverselaplacer calculus.calculusr calculus.optimizationr calculus.odesr matrices.matricesrmatrices.calculusrmatrices.linalgrmatrices.eigenridentificationr visualizationrrobjectrrrrrrsv!1%2E.6%,41!1/ f V' $ Vr