本文整理汇总了Python中sage.structure.coerce.parent函数的典型用法代码示例。如果您正苦于以下问题:Python parent函数的具体用法?Python parent怎么用?Python parent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parent函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _evalf_
def _evalf_(self, x, parent):
"""
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.6332655417638522934072124548e-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
"""
try:
prec = parent.prec()
except AttributeError: # not a Sage parent
prec = 0
return parent(1) - parent(pari(x).erfc(prec))
开发者ID:ppurka,项目名称:sagelib,代码行数:26,代码来源:other.py
示例2: _eval_
def _eval_(self, z):
"""
EXAMPLES::
sage: z = var('z')
sage: sin_integral(z)
sin_integral(z)
sage: sin_integral(3.0)
1.84865252799947
sage: sin_integral(0)
0
"""
if not isinstance(z, Expression) and is_inexact(z):
return self._evalf_(z, parent(z))
# special case: z = 0
if isinstance(z, Expression):
if z.is_trivial_zero():
return z
else:
if not z:
return z
return None # leaves the expression unevaluated
开发者ID:Etn40ff,项目名称:sage,代码行数:25,代码来源:exp_integral.py
示例3: _eval_
def _eval_(self, n, x):
"""
EXAMPLES::
sage: y=var('y')
sage: bessel_I(y,x)
bessel_I(y, x)
sage: bessel_I(0.0, 1.0)
1.26606587775201
sage: bessel_I(1/2, 1)
sqrt(2)*sinh(1)/sqrt(pi)
sage: bessel_I(-1/2, pi)
sqrt(2)*cosh(pi)/pi
"""
if (not isinstance(n, Expression) and not isinstance(x, Expression) and
(is_inexact(n) or is_inexact(x))):
coercion_model = get_coercion_model()
n, x = coercion_model.canonical_coercion(n, x)
return self._evalf_(n, x, parent(n))
# special identities
if n == Integer(1) / Integer(2):
return sqrt(2 / (pi * x)) * sinh(x)
elif n == -Integer(1) / Integer(2):
return sqrt(2 / (pi * x)) * cosh(x)
return None # leaves the expression unevaluated
开发者ID:acrlakshman,项目名称:sage,代码行数:27,代码来源:bessel.py
示例4: _eval_
def _eval_(self, x, y):
"""
EXAMPLES::
sage: gamma_inc(2.,0)
1.00000000000000
sage: gamma_inc(2,0)
1
sage: gamma_inc(1/2,2)
-(erf(sqrt(2)) - 1)*sqrt(pi)
sage: gamma_inc(1/2,1)
-(erf(1) - 1)*sqrt(pi)
sage: gamma_inc(1/2,0)
sqrt(pi)
sage: gamma_inc(x,0)
gamma(x)
sage: gamma_inc(1,2)
e^(-2)
sage: gamma_inc(0,2)
-Ei(-2)
"""
if not isinstance(x, Expression) and not isinstance(y, Expression) and \
(is_inexact(x) or is_inexact(y)):
x, y = coercion_model.canonical_coercion(x, y)
return self._evalf_(x, y, parent(x))
if y == 0:
return gamma(x)
if x == 1:
return exp(-y)
if x == 0:
return -Ei(-y)
if x == Rational(1)/2: #only for x>0
return sqrt(pi)*(1-erf(sqrt(y)))
return None
开发者ID:ppurka,项目名称:sagelib,代码行数:35,代码来源:other.py
示例5: _evalf_
def _evalf_(self, *args, **kwds):
"""
Returns a numerical approximation of this function using
Maxima. Currently, this is limited to 53 bits of precision.
EXAMPLES::
sage: from sage.functions.special import MaximaFunction
sage: f = MaximaFunction("jacobi_sn")
sage: f(1/2,1/2)
jacobi_sn(1/2, 1/2)
sage: f(1/2,1/2).n()
0.470750473655657
TESTS::
sage: f(1/2,1/2).n(150)
Traceback (most recent call last):
...
NotImplementedError: jacobi_sn not implemented for precision > 53
"""
parent = kwds["parent"]
if hasattr(parent, "prec") and parent.prec() > 53:
raise NotImplementedError("%s not implemented for precision > 53" % self.name())
_init()
return parent(maxima("%s, numer" % self._maxima_init_evaled_(*args)))
开发者ID:jeromeca,项目名称:sage,代码行数:26,代码来源:special.py
示例6: _eval_
def _eval_(self, n, m, theta, phi, **kwargs):
r"""
TESTS::
sage: x, y = var('x y')
sage: spherical_harmonic(1, 2, x, y)
0
sage: spherical_harmonic(1, -2, x, y)
0
sage: spherical_harmonic(1/2, 2, x, y)
spherical_harmonic(1/2, 2, x, y)
sage: spherical_harmonic(3, 2, x, y)
15/4*sqrt(7/30)*cos(x)*e^(2*I*y)*sin(x)^2/sqrt(pi)
sage: spherical_harmonic(3, 2, 1, 2)
15/4*sqrt(7/30)*cos(1)*e^(4*I)*sin(1)^2/sqrt(pi)
sage: spherical_harmonic(3 + I, 2., 1, 2)
-0.351154337307488 - 0.415562233975369*I
"""
from sage.structure.coerce import parent
cc = get_coercion_model().canonical_coercion
coerced = cc(phi, cc(theta, cc(n, m)[0])[0])[0]
if is_inexact(coerced) and not isinstance(coerced, Expression):
return self._evalf_(n, m, theta, phi, parent=parent(coerced))
elif n in ZZ and m in ZZ and n > -1:
if abs(m) > n:
return ZZ(0)
return meval("spherical_harmonic({},{},{},{})".format(ZZ(n), ZZ(m), maxima(theta), maxima(phi)))
return
开发者ID:jeromeca,项目名称:sage,代码行数:29,代码来源:special.py
示例7: _eval_
def _eval_(self, n, z ):
"""
EXAMPLES::
"""
# howto find a common parent for n and z here?
if not isinstance(z, Expression) and is_inexact(z):
return self._evalf_(n, z, parent(z))
return None
开发者ID:benjaminfjones,项目名称:sage-devel,代码行数:8,代码来源:trac_11143_testing_expintegral_e.py
示例8: _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)
开发者ID:drupel,项目名称:sage,代码行数:11,代码来源:special.py
示例9: __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)
开发者ID:ppurka,项目名称:sagelib,代码行数:52,代码来源:other.py
示例10: eval_formula
def eval_formula(self, n, x):
"""
Evaluate ``chebyshev_T`` using an explicit formula.
See [ASHandbook]_ 227 (p. 782) for details for the recurions.
See also [EffCheby]_ for fast evaluation techniques.
INPUT:
- ``n`` -- an integer
- ``x`` -- a value to evaluate the polynomial at (this can be
any ring element)
EXAMPLES::
sage: chebyshev_T.eval_formula(-1,x)
x
sage: chebyshev_T.eval_formula(0,x)
1
sage: chebyshev_T.eval_formula(1,x)
x
sage: chebyshev_T.eval_formula(2,0.1) == chebyshev_T._evalf_(2,0.1)
True
sage: chebyshev_T.eval_formula(10,x)
512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1
sage: chebyshev_T.eval_algebraic(10,x).expand()
512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1
"""
if n < 0:
return self.eval_formula(-n, x)
elif n == 0:
return parent(x).one()
res = parent(x).zero()
for j in xrange(0, n // 2 + 1):
f = factorial(n - 1 - j) / factorial(j) / factorial(n - 2 * j)
res += (-1) ** j * (2 * x) ** (n - 2 * j) * f
res *= n / 2
return res
开发者ID:jeromeca,项目名称:sage,代码行数:39,代码来源:orthogonal_polys.py
示例11: eval_algebraic
def eval_algebraic(self, n, x):
"""
Evaluate :class:`chebyshev_U` as polynomial, using a recursive
formula.
INPUT:
- ``n`` -- an integer
- ``x`` -- a value to evaluate the polynomial at (this can be
any ring element)
EXAMPLES::
sage: chebyshev_U.eval_algebraic(5,x)
-2*((2*x + 1)*(2*x - 1)*x - 4*(2*x^2 - 1)*x)*(2*x + 1)*(2*x - 1)
sage: parent(chebyshev_U(3, Mod(8,9)))
Ring of integers modulo 9
sage: parent(chebyshev_U(3, Mod(1,9)))
Ring of integers modulo 9
sage: chebyshev_U(-3,x) + chebyshev_U(1,x)
0
sage: chebyshev_U(-1,Mod(5,8))
0
sage: parent(chebyshev_U(-1,Mod(5,8)))
Ring of integers modulo 8
sage: R.<t> = ZZ[]
sage: chebyshev_U.eval_algebraic(-2, t)
-1
sage: chebyshev_U.eval_algebraic(-1, t)
0
sage: chebyshev_U.eval_algebraic(0, t)
1
sage: chebyshev_U.eval_algebraic(1, t)
2*t
sage: n = 97; x = RIF(pi/n)
sage: chebyshev_U(n-1, cos(x)).contains_zero()
True
sage: R.<t> = Zp(2, 6, 'capped-abs')[]
sage: chebyshev_U(10^6+1, t)
(2 + O(2^6))*t + (O(2^6))
"""
if n == -1:
return parent(x).zero()
if n < 0:
return -self._eval_recursive_(-n - 2, x)[0]
return self._eval_recursive_(n, x)[0]
开发者ID:jeromeca,项目名称:sage,代码行数:47,代码来源:orthogonal_polys.py
示例12: _eval_
def _eval_(self, a, b, z, **kwargs):
"""
EXAMPLES::
sage: hypergeometric([], [], 0)
1
"""
if not isinstance(a,tuple) or not isinstance(b,tuple):
raise ValueError('First two parameters must be of type list.')
coercion_model = get_coercion_model()
co = reduce(lambda x, y: coercion_model.canonical_coercion(x, y)[0],
a + b + (z,))
if is_inexact(co) and not isinstance(co, Expression):
from sage.structure.coerce import parent
return self._evalf_(a, b, z, parent=parent(co))
if not isinstance(z, Expression) and z == 0: # Expression is excluded
return Integer(1) # to avoid call to Maxima
return
开发者ID:Etn40ff,项目名称:sage,代码行数:18,代码来源:hypergeometric.py
示例13: _eval_recursive_
def _eval_recursive_(self, n, x, both=False):
"""
If ``both=True``, compute ``(U(n,x), U(n-1,x))`` using a
recursive formula.
If ``both=False``, return instead a tuple ``(U(n,x), False)``.
EXAMPLES::
sage: chebyshev_U._eval_recursive_(3, x)
(4*((2*x + 1)*(2*x - 1) - 2*x^2)*x, False)
sage: chebyshev_U._eval_recursive_(3, x, True)
(4*((2*x + 1)*(2*x - 1) - 2*x^2)*x, ((2*x + 1)*(2*x - 1) + 2*x)*((2*x + 1)*(2*x - 1) - 2*x))
"""
if n == 0:
return parent(x).one(), 2 * x
assert n >= 1
a, b = self._eval_recursive_((n - 1) // 2, x, True)
if n % 2 == 0:
return (b + a) * (b - a), both and 2 * b * (x * b - a)
else:
return 2 * a * (b - x * a), both and (b + a) * (b - a)
开发者ID:jeromeca,项目名称:sage,代码行数:22,代码来源:orthogonal_polys.py
注:本文中的sage.structure.coerce.parent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论