本文整理汇总了Python中sage.libs.mpmath.utils.call函数的典型用法代码示例。如果您正苦于以下问题:Python call函数的具体用法?Python call怎么用?Python call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _evalf_
def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: bessel_J(0.0, 1.0)
0.765197686557967
sage: bessel_J(0, 1).n(digits=20)
0.76519768655796655145
sage: bessel_J(0.5, 1.5)
0.649838074753747
Check for correct rounding (:trac:`17122`)::
sage: R = RealField(113)
sage: a = R("8.935761195587725798762818805462843676e-01")
sage: aa = RealField(200)(a)
sage: for n in [-10..10]:
....: b = bessel_J(R(n), a)
....: bb = R(bessel_J(n, aa))
....: if b != bb:
....: print n, b-bb
"""
if parent is not None:
x = parent(x)
try:
return x.jn(Integer(n))
except Exception:
pass
n, x = get_coercion_model().canonical_coercion(n, x)
import mpmath
return mpmath_utils.call(mpmath.besselj, n, x, parent=parent)
示例2: _evalf_
def _evalf_(self, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: erf(2).n()
0.995322265018953
sage: erf(2).n(200)
0.99532226501895273416206925636725292861089179704006007673835
sage: erf(pi - 1/2*I).n(100)
1.0000111669099367825726058952 + 1.6332655417638522934072124547e-6*I
TESTS:
Check that PARI/GP through the GP interface gives the same answer::
sage: gp.set_real_precision(59) # random
38
sage: print(gp.eval("1 - erfc(1)")); print(erf(1).n(200));
0.84270079294971486934122063508260925929606699796630290845994
0.84270079294971486934122063508260925929606699796630290845994
Check that for an imaginary input, the output is also imaginary, see
:trac:`13193`::
sage: erf(3.0*I)
1629.99462260157*I
sage: erf(33.0*I)
1.51286977510409e471*I
"""
R = parent or s_parent(x)
import mpmath
return mpmath_utils.call(mpmath.erf, x, parent=R)
示例3: __call__
def __call__(self, x, prec=None, coerce=True, hold=False ):
"""
Note that the ``prec`` argument is deprecated. The precision for
the result is deduced from the precision of the input. Convert
the input to a higher precision explicitly if a result with higher
precision is desired.
EXAMPLES::
sage: t = Ei(RealField(100)(2.5)); t
7.0737658945786007119235519625
sage: t.prec()
100
sage: Ei(1.1, prec=300)
doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example Ei(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., Ei(1).n(300), instead.
2.16737827956340306615064476647912607220394065907142504328679588538509331805598360907980986
"""
if prec is not None:
from sage.misc.misc import deprecation
deprecation("The prec keyword argument is deprecated. Explicitly set the precision of the input, for example Ei(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., Ei(1).n(300), instead.")
import mpmath
return mpmath_utils.call(mpmath.ei, x, prec=prec)
return BuiltinFunction.__call__(self, x, coerce=coerce, hold=hold)
示例4: _evalf_
def _evalf_(self, a, b, z, parent, algorithm=None):
"""
TESTS::
sage: hypergeometric_M(1,1,1).n()
2.71828182845905
"""
from mpmath import hyp1f1
return mpmath_utils.call(hyp1f1, a, b, z, parent=parent)
示例5: _evalf_
def _evalf_(self, n, z, parent=None):
"""
EXAMPLES::
"""
import mpmath
if isinstance(parent, Parent) and hasattr(parent, 'prec'):
prec = parent.prec()
else:
prec = 53
return mpmath_utils.call(mpmath.expint, n, z, prec=prec)
示例6: _evalf_
def _evalf_(self, n, x, parent=None, algorithm=None):
r"""
TESTS::
sage: zetaderiv(0, 3, hold=True).n() == zeta(3).n()
True
sage: zetaderiv(2, 3 + I).n()
0.0213814086193841 - 0.174938812330834*I
"""
from mpmath import zeta
return mpmath_utils.call(zeta, x, 1, n, parent=parent)
示例7: _evalf_
def _evalf_(self, a, z, parent=None, algorithm=None):
"""
EXAMPLES::
sage: struve_H(1/2,pi).n()
0.900316316157106
sage: struve_H(1/2,pi).n(200)
0.9003163161571060695551991910...
"""
import mpmath
return mpmath_utils.call(mpmath.struveh, a, z, parent=parent)
示例8: _evalf_
def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: bessel_J(0.0, 1.0)
0.765197686557966
sage: bessel_J(0, 1).n(digits=20)
0.76519768655796655145
"""
import mpmath
return mpmath_utils.call(mpmath.besselj, n, x, parent=parent)
示例9: _evalf_
def _evalf_(self, u, m, parent=None, algorithm=None):
"""
EXAMPLES::
sage: elliptic_eu(1,1).n()
0.761594155955765
sage: elliptic_eu(1,1).n(200)
0.7615941559557648881194582...
"""
R = parent or parent(z)
return mpmath_utils.call(elliptic_eu_f, u, m, parent=R)
示例10: _evalf_
def _evalf_(self, n, m, theta, phi, parent, **kwds):
r"""
TESTS::
sage: spherical_harmonic(3 + I, 2, 1, 2).n(100)
-0.35115433730748836508201061672 - 0.41556223397536866209990358597*I
sage: spherical_harmonic(I, I, I, I).n()
7.66678546069894 - 0.265754432549751*I
"""
from mpmath import spherharm
return mpmath_utils.call(spherharm, n, m, theta, phi, parent=parent)
示例11: _evalf_
def _evalf_(self, n, z, parent=None, algorithm=None):
"""
EXAMPLES::
sage: N(exp_integral_e(1, 1+I))
0.000281624451981418 - 0.179324535039359*I
sage: exp_integral_e(1, RealField(100)(1))
0.21938393439552027367716377546
"""
import mpmath
return mpmath_utils.call(mpmath.expint, n, z, parent=parent)
示例12: _evalf_
def _evalf_(self, x, **kwargs):
"""
EXAMPLES::
sage: from sage.functions.airy import airy_ai_simple
sage: airy_ai_simple(0.0)
0.355028053887817
sage: airy_ai_simple(1.0 * I)
0.331493305432141 - 0.317449858968444*I
We can use several methods for numerical evaluation::
sage: airy_ai_simple(3).n(algorithm='mpmath')
0.00659113935746072
sage: airy_ai_simple(3).n(algorithm='mpmath', prec=100)
0.0065911393574607191442574484080
sage: airy_ai_simple(3).n(algorithm='scipy') # rel tol 1e-10
0.006591139357460719
sage: airy_ai_simple(I).n(algorithm='scipy') # rel tol 1e-10
0.33149330543214117 - 0.3174498589684438*I
TESTS::
sage: parent(airy_ai_simple(3).n(algorithm='scipy'))
Real Field with 53 bits of precision
sage: airy_ai_simple(3).n(algorithm='scipy', prec=200)
Traceback (most recent call last):
...
NotImplementedError: airy_ai not implemented for precision > 53
"""
algorithm = kwargs.get('algorithm', 'mpmath') or 'mpmath'
parent = kwargs.get('parent')
if algorithm == 'scipy':
if hasattr(parent, 'prec') and parent.prec() > 53:
raise NotImplementedError("%s not implemented for precision > 53"%self.name())
from sage.rings.all import RR, CC
from sage.functions.other import real,imag
from scipy.special import airy as airy
if x in RR:
y = airy(real(x))[0]
if parent is None:
return RR(y)
else:
y = airy(complex(real(x),imag(x)))[0]
if parent is None:
return CC(y)
return parent(y)
elif algorithm == 'mpmath':
import mpmath
from sage.libs.mpmath import utils as mpmath_utils
return mpmath_utils.call(mpmath.airyai, x, parent=parent)
else:
raise ValueError("unknown algorithm '%s'" % algorithm)
示例13: __call__
def __call__(self, x, prec=None, coerce=True, hold=False):
"""
Note that the ``prec`` argument is deprecated. The precision for
the result is deduced from the precision of the input. Convert
the input to a higher precision explicitly if a result with higher
precision is desired.::
sage: t = gamma(RealField(100)(2.5)); t
1.3293403881791370204736256125
sage: t.prec()
100
sage: gamma(6, prec=53)
doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example gamma(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., gamma(1).n(300), instead.
120.000000000000
TESTS::
sage: gamma(pi,prec=100)
2.2880377953400324179595889091
sage: gamma(3/4,prec=100)
1.2254167024651776451290983034
"""
if prec is not None:
from sage.misc.misc import deprecation
deprecation("The prec keyword argument is deprecated. Explicitly set the precision of the input, for example gamma(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., gamma(1).n(300), instead.")
import mpmath
return mpmath_utils.call(mpmath.gamma, x, prec=prec)
# this is a kludge to keep
# sage: Q.<i> = NumberField(x^2+1)
# sage: gamma(i)
# working, since number field elements cannot be coerced into SR
# without specifying an explicit embedding into CC any more
try:
res = GinacFunction.__call__(self, x, coerce=coerce, hold=hold)
except TypeError, err:
# the __call__() method returns a TypeError for fast float arguments
# as well, we only proceed if the error message says that
# the arguments cannot be coerced to SR
if not str(err).startswith("cannot coerce"):
raise
from sage.misc.misc import deprecation
deprecation("Calling symbolic functions with arguments that cannot be coerced into symbolic expressions is deprecated.")
parent = RR if prec is None else RealField(prec)
try:
x = parent(x)
except (ValueError, TypeError):
x = parent.complex_field()(x)
res = GinacFunction.__call__(self, x, coerce=coerce, hold=hold)