K i+0dZddlmZmZddlmZddlmZddlm Z ddl m Z m Z ddl mZddlmZmZmZd ZGd d eZd ZGd deZe dZdZGddeZdZGddeZdZGddeZe dZdZGddeZ dZ!GddeZ"d Z#Gd!d"eZ$d#Z%Gd$d%eZ&Gd&d'eZ'Gd(d)eZ(y*)+a# This module contains SymPy functions mathcin corresponding to special math functions in the C standard library (since C99, also available in C++11). The functions defined in this module allows the user to express functions such as ``expm1`` as a SymPy function for symbolic manipulation. )ArgumentIndexErrorFunction)Rational)Pow)S)explog)sqrt)BooleanFunctiontruefalsec:t|tjz SNrrOnexs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/codegen/cfunctions.py_expm1rs q6AEE>cHeZdZdZdZd dZdZdZeZe dZ dZ dZ y ) expm1a* Represents the exponential function minus one. Explanation =========== The benefit of using ``expm1(x)`` over ``exp(x) - 1`` is that the latter is prone to cancellation under finite precision arithmetic when x is close to zero. Examples ======== >>> from sympy.abc import x >>> from sympy.codegen.cfunctions import expm1 >>> '%.0e' % expm1(1e-99).evalf() '1e-99' >>> from math import exp >>> exp(1e-99) - 1 0.0 >>> expm1(x).diff(x) exp(x) See Also ======== log1p cH|dk(rt|jSt||@ Returns the first derivative of this function. r)rargsrselfargindexs rfdiffz expm1.fdiff4s& q= ? "$T84 4rc &t|jSr)rrrhintss r_eval_expand_funczexpm1._eval_expand_func=tyy!!rc :t|tjz Srrrargkwargss r_eval_rewrite_as_expzexpm1._eval_rewrite_as_exp@s3x!%%rcXtj|}||tjz Syr)revalrr)clsr)exp_args rr-z expm1.evalEs(((3-  QUU? " rc4|jdjSNr)ris_realrs r _eval_is_realzexpm1._eval_is_realKyy|###rc4|jdjSr1)r is_finiter3s r_eval_is_finitezexpm1._eval_is_finiteNsyy|%%%rNr) __name__ __module__ __qualname____doc__nargsr!r%r+_eval_rewrite_as_tractable classmethodr-r4r8rrrrsA8 E5" "6## $&rrc:t|tjzSr)r rrrs r_log1prCRs q155y>rcZeZdZdZdZd dZdZdZeZe dZ dZ dZ d Z d Zd Zy )log1paf Represents the natural logarithm of a number plus one. Explanation =========== The benefit of using ``log1p(x)`` over ``log(x + 1)`` is that the latter is prone to cancellation under finite precision arithmetic when x is close to zero. Examples ======== >>> from sympy.abc import x >>> from sympy.codegen.cfunctions import log1p >>> from sympy import expand_log >>> '%.0e' % expand_log(log1p(1e-99)).evalf() '1e-99' >>> from math import log >>> log(1 + 1e-99) 0.0 >>> log1p(x).diff(x) 1/(x + 1) See Also ======== expm1 rc|dk(r1tj|jdtjzz St||rrr)rrrrrs rr!z log1p.fdiffws8 q=55$))A,./ /$T84 4rc &t|jSr)rCrr#s rr%zlog1p._eval_expand_funcr&rc t|Sr)rCr(s r_eval_rewrite_as_logzlog1p._eval_rewrite_as_log c{rc|jrt|tjzS|js&tj |tjzS|j r%tt|tjzSyr) is_Rationalr rris_Floatr- is_numberrr.r)s rr-z log1p.evals^ ??sQUU{# #88C!%%K( ( ]]x}quu,- -rcV|jdtjzjSr1)rrris_nonnegativer3s rr4zlog1p._eval_is_reals ! quu$444rc|jdtjzjry|jdjS)NrF)rrris_zeror7r3s rr8zlog1p._eval_is_finites3 IIaL155 ) )yy|%%%rc4|jdjSr1)r is_positiver3s r_eval_is_positivezlog1p._eval_is_positivesyy|'''rc4|jdjSr1)rrTr3s r _eval_is_zerozlog1p._eval_is_zeror5rc4|jdjSr1)rrRr3s r_eval_is_nonnegativezlog1p._eval_is_nonnegativesyy|***rNr9)r:r;r<r=r>r!r%rJr?r@r-r4r8rWrYr[rArrrErEVsP: E5""6..5& ($+rrEc"tt|Sr)r_Twors r_exp2r_s tQ<rc<eZdZdZdZddZdZeZdZe dZ y) exp2a Represents the exponential function with base two. Explanation =========== The benefit of using ``exp2(x)`` over ``2**x`` is that the latter is not as efficient under finite precision arithmetic. Examples ======== >>> from sympy.abc import x >>> from sympy.codegen.cfunctions import exp2 >>> exp2(2).evalf() == 4.0 True >>> exp2(x).diff(x) log(2)*exp2(x) See Also ======== log2 rcH|dk(r|ttzSt||r)r r^rrs rr!z exp2.fdiffs& q=D > !$T84 4rc t|Sr)r_r(s r_eval_rewrite_as_Powzexp2._eval_rewrite_as_Pow Szrc &t|jSr)r_rr#s rr%zexp2._eval_expand_funcdii  rc2|jr t|Syr)rOr_rPs rr-z exp2.evals ==:  rNr9) r:r;r<r=r>r!rdr?r%r@r-rArrraras92 E5"6!rrac8t|ttz Sr)r r^rs r_log2rj q6#d) rcBeZdZdZdZd dZedZdZdZ dZ e Z y) log2a Represents the logarithm function with base two. Explanation =========== The benefit of using ``log2(x)`` over ``log(x)/log(2)`` is that the latter is not as efficient under finite precision arithmetic. Examples ======== >>> from sympy.abc import x >>> from sympy.codegen.cfunctions import log2 >>> log2(4).evalf() == 2.0 True >>> log2(x).diff(x) 1/(x*log(2)) See Also ======== exp2 log10 rc|dk(r0tjtt|jdzz St ||rG)rrr r^rrrs rr!z log2.fdiff8 q=55#d)DIIaL01 1$T84 4rc|jr*tj|t}|jr|Sy|j r |j tk(r |jSyyN)base)rOr r-r^is_Atomis_Powrrrr.r)results rr-z log2.evalL ==XXc-F~~  ZZCHH,77N-ZrcL|jtj|i|Sr)rewriter evalf)rrr*s r _eval_evalfzlog2._eval_evalfs#&t||C &&777rc &t|jSr)rjrr#s rr%zlog2._eval_expand_funcrgrc t|Sr)rjr(s rrJzlog2._eval_rewrite_as_logrerNr9) r:r;r<r=r>r!r@r-r{r%rJr?rArrrmrms>4 E58!"6rrmc||z|zSrrA)ryzs r_fmars Q37Nrc*eZdZdZdZddZdZddZy) fmaa Represents "fused multiply add". Explanation =========== The benefit of using ``fma(x, y, z)`` over ``x*y + z`` is that, under finite precision arithmetic, the former is supported by special instructions on some CPUs. Examples ======== >>> from sympy.abc import x, y, z >>> from sympy.codegen.cfunctions import fma >>> fma(x, y, z).diff(x) y cp|dvr|jd|z S|dk(rtjSt||)rrr\r\r)rrrrrs rr!z fma.fdiff6s< v 99Q\* * ]55L$T84 4rc &t|jSr)rrr#s rr%zfma._eval_expand_funcBsTYYrNc t|Sr)r)rr)limitvarr*s rr?zfma._eval_rewrite_as_tractableEs Cyrr9r)r:r;r<r=r>r!r%r?rArrrr s& E 5 rr c8t|ttz Sr)r _Tenrs r_log10rLrkrc<eZdZdZdZddZedZdZdZ e Z y) log10a$ Represents the logarithm function with base ten. Examples ======== >>> from sympy.abc import x >>> from sympy.codegen.cfunctions import log10 >>> log10(100).evalf() == 2.0 True >>> log10(x).diff(x) 1/(x*log(10)) See Also ======== log2 rc|dk(r0tjtt|jdzz St ||rG)rrr rrrrs rr!z log10.fdifferorc|jr*tj|t}|jr|Sy|j r |j tk(r |jSyyrq)rOr r-rrsrtrrrrus rr-z log10.evalorwrc &t|jSr)rrr#s rr%zlog10._eval_expand_funcxr&rc t|Sr)rr(s rrJzlog10._eval_rewrite_as_log{rKrNr9) r:r;r<r=r>r!r@r-r%rJr?rArrrrPs9$ E5""6rrc6t|tjSr)rrHalfrs r_Sqrtrs q!&&>rc,eZdZdZdZddZdZdZeZy)Sqrta Represents the square root function. Explanation =========== The reason why one would use ``Sqrt(x)`` over ``sqrt(x)`` is that the latter is internally represented as ``Pow(x, S.Half)`` which may not be what one wants when doing code-generation. Examples ======== >>> from sympy.abc import x >>> from sympy.codegen.cfunctions import Sqrt >>> Sqrt(x) Sqrt(x) >>> Sqrt(x).diff(x) 1/(2*sqrt(x)) See Also ======== Cbrt rcx|dk(r*t|jdtddtz St ||)rrrr\rrrr^rrs rr!z Sqrt.fdiffs8 q=tyy|Xb!_5d: :$T84 4rc &t|jSr)rrr#s rr%zSqrt._eval_expand_funcrgrc t|Sr)rr(s rrdzSqrt._eval_rewrite_as_PowrerNr9 r:r;r<r=r>r!r%rdr?rArrrrs%2 E5!"6rrc.t|tddS)Nrr)rrrs r_Cbrtrs q(1a. !!rc,eZdZdZdZddZdZdZeZy)Cbrta Represents the cube root function. Explanation =========== The reason why one would use ``Cbrt(x)`` over ``cbrt(x)`` is that the latter is internally represented as ``Pow(x, Rational(1, 3))`` which may not be what one wants when doing code-generation. Examples ======== >>> from sympy.abc import x >>> from sympy.codegen.cfunctions import Cbrt >>> Cbrt(x) Cbrt(x) >>> Cbrt(x).diff(x) 1/(3*x**(2/3)) See Also ======== Sqrt rc~|dk(r-t|jdtt dz dz St ||)rrrrrrs rr!z Cbrt.fdiffs= q=tyy|XteAg%679 9$T84 4rc &t|jSr)rrr#s rr%zCbrt._eval_expand_funcrgrc t|Sr)rr(s rrdzCbrt._eval_rewrite_as_PowrerNr9rrArrrrs%2 E5!"6rrcFtt|dt|dzS)Nr\)r r)rrs r_hypotrs Aq C1I% &&rc,eZdZdZdZddZdZdZeZy)hypota Represents the hypotenuse function. Explanation =========== The hypotenuse function is provided by e.g. the math library in the C99 standard, hence one may want to represent the function symbolically when doing code-generation. Examples ======== >>> from sympy.abc import x, y >>> from sympy.codegen.cfunctions import hypot >>> hypot(3, 4).evalf() == 5.0 True >>> hypot(x, y) hypot(x, y) >>> hypot(x, y).diff(x) x/hypot(x, y) r\c|dvr6d|j|dz zt|j|jzz St||)rrr\r)rr^funcrrs rr!z hypot.fdiffsJ v TYYxz**DDII1F,FG G$T84 4rc &t|jSr)rrr#s rr%zhypot._eval_expand_funcr&rc t|Sr)rr(s rrdzhypot._eval_rewrite_as_PowrKrNr9rrArrrrs%. E5""6rrc eZdZdZedZy)isnanrcX|tjurtS|jrtSyr)rNaNr rOr rPs rr-z isnan.evals! !%%<K ]]LrNr:r;r<r>r@r-rArrrr Errc eZdZdZedZy)isinfrcL|jrtS|jrtSyr) is_infiniter r7r rPs rr-z isinf.eval's ??K ]]LrNrrArrrr$rrrN))r=sympy.core.functionrrsympy.core.numbersrsympy.core.powerrsympy.core.singletonr&sympy.functions.elementary.exponentialrr (sympy.functions.elementary.miscellaneousr sympy.logic.boolalgr r r rrrCrEr^r_rarjrmrrrrrrrrrrrrrrArrrs=' ";9<<:&H:&zK+HK+Z t181h96896x&(&R u.6H.6b+68+6\",68,6^'*6H*6Z O  O r