本文整理汇总了Python中sage.symbolic.function.BuiltinFunction.__call__方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltinFunction.__call__方法的具体用法?Python BuiltinFunction.__call__怎么用?Python BuiltinFunction.__call__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.symbolic.function.BuiltinFunction
的用法示例。
在下文中一共展示了BuiltinFunction.__call__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def __call__(self, a, b, z, **kwargs):
"""
Return symbolic hypergeometric function expression.
INPUT:
- ``a`` -- a list or tuple of parameters
- ``b`` -- a list or tuple of parameters
- ``z`` -- a number or symbolic expression
EXAMPLES::
sage: hypergeometric([], [], 1)
hypergeometric((), (), 1)
sage: hypergeometric([], [1], 1)
hypergeometric((), (1,), 1)
sage: hypergeometric([2, 3], [1], 1)
hypergeometric((2, 3), (1,), 1)
sage: hypergeometric([], [], x)
hypergeometric((), (), x)
sage: hypergeometric([x], [], x^2)
hypergeometric((x,), (), x^2)
The only simplification that is done automatically is returning 1
if ``z`` is 0. For other simplifications use the
``simplify_hypergeometric`` method.
"""
return BuiltinFunction.__call__(self,
SR._force_pyobject(a),
SR._force_pyobject(b),
z, **kwargs)
示例2: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
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.
See http://trac.sagemath.org/7748 for details.
2.16737827956340306615064476647912607220394065907142504328679588538509331805598360907980986
"""
if prec is not None:
from sage.misc.superseded import deprecation
deprecation(7748, "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)
示例3: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def __call__(self, x, maximum_bits=20000):
"""
Allows an object of this class to behave like a function. If
``floor`` is an instance of this class, we can do ``floor(n)`` to
obtain the floor of ``n``.
TESTS::
sage: floor(SR(10^50 + 10^(-50)))
100000000000000000000000000000000000000000000000000
sage: floor(SR(10^50 - 10^(-50)))
99999999999999999999999999999999999999999999999999
sage: floor(int(10^50))
100000000000000000000000000000000000000000000000000
"""
try:
return x.floor()
except AttributeError:
if isinstance(x, (int, long)):
return Integer(x)
elif isinstance(x, (float, complex)):
return Integer(int(math.floor(x)))
elif type(x).__module__ == 'numpy':
import numpy
return numpy.floor(x)
x_original = x
from sage.rings.all import RealIntervalField
# If x can be coerced into a real interval, then we should
# try increasing the number of bits of precision until
# we get the floor at each of the endpoints is the same.
# The precision will continue to be increased up to maximum_bits
# of precision at which point it will raise a value error.
bits = 53
try:
x_interval = RealIntervalField(bits)(x)
upper_floor = x_interval.upper().floor()
lower_floor = x_interval.lower().floor()
while upper_floor != lower_floor and bits < maximum_bits:
bits += 100
x_interval = RealIntervalField(bits)(x)
upper_floor = x_interval.upper().floor()
lower_floor = x_interval.lower().floor()
if bits < maximum_bits:
return lower_floor
else:
try:
return floor(SR(x).full_simplify())
except ValueError:
pass
raise ValueError, "x (= %s) requires more than %s bits of precision to compute its floor"%(x, maximum_bits)
except TypeError:
# If x cannot be coerced into a RealField, then
# it should be left as a symbolic expression.
return BuiltinFunction.__call__(self, SR(x_original))
示例4: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def __call__(self, *args, **kwds):
r"""
Custom call method allows the user to pass one argument or two. If
one argument is passed, we assume it is ``z`` and that ``n=0``.
EXAMPLES::
sage: lambert_w(1)
lambert_w(1)
sage: lambert_w(1, 2)
lambert_w(1, 2)
"""
if len(args) == 2:
return BuiltinFunction.__call__(self, *args, **kwds)
elif len(args) == 1:
return BuiltinFunction.__call__(self, 0, args[0], **kwds)
else:
raise TypeError("lambert_w takes either one or two arguments.")
示例5: _derivative_
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def _derivative_(self, n, z, diff_param=None):
"""
If `n` is an integer strictly larger than 0, then the derivative of
`E_n(z)` with respect to `z` is `-E_{n-1}(z)`. See [A & S, 5.1.26].
EXAMPLES::
"""
if n in ZZ and n > 0:
return -1*BuiltinFunction.__call__(self, n-1, z)
else:
raise NotImplementedError("The derivative d/dz En(z) is only implemented for n = 1, 2, 3, ...")
示例6: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def __call__(self, z, m=1, **kwds):
r"""
Custom call method allows the user to pass one argument or two. If
one argument is passed, we assume it is ``z`` and that ``m=1``.
EXAMPLES::
sage: harmonic_number(x)
harmonic_number(x)
sage: harmonic_number(x,1)
harmonic_number(x)
sage: harmonic_number(x,2)
harmonic_number(x, 2)
"""
return BuiltinFunction.__call__(self, z, m, **kwds)
示例7: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def __call__(self, n, z, 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::
"""
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 En(RealField(300)(1), RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., En(1,1).n(300), instead.")
import mpmath
return mpmath_utils.call(mpmath.expint, n, z, prec=prec)
return BuiltinFunction.__call__(self, n, z, coerce=coerce, hold=hold)
示例8: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def __call__(self, function_pieces, **kwds):
r"""
Piecewise functions
INPUT:
- ``function_pieces`` -- a list of pairs consisting of a
domain and a symbolic function.
- ``var=x`` -- a symbolic variable or ``None`` (default). The
real variable in which the function is piecewise in.
OUTPUT:
A piecewise-defined function. A ``ValueError`` will be raised
if the domains of the pieces are not pairwise disjoint.
EXAMPLES::
sage: my_abs = piecewise([((-1, 0), -x), ([0, 1], x)], var=x); my_abs
piecewise(x|-->-x on (-1, 0), x|-->x on [0, 1]; x)
sage: [ my_abs(i/5) for i in range(-4, 5)]
[4/5, 3/5, 2/5, 1/5, 0, 1/5, 2/5, 3/5, 4/5]
TESTS::
sage: piecewise([([-1, 0], -x), ([0, 1], x)], var=x)
Traceback (most recent call last):
...
ValueError: domains must be pairwise disjoint
sage: step = piecewise([((-1, 0), -1), ([0, 0], 0), ((0, 1), 1)], var=x); step
piecewise(x|-->-1 on (-1, 0), x|-->0 on {0}, x|-->1 on (0, 1); x)
sage: step(-1/2), step(0), step(1/2)
(-1, 0, 1)
"""
from types import FunctionType
var = kwds.pop('var', None)
parameters = []
domain_list = []
for piece in function_pieces:
domain, function = piece
if not isinstance(domain, RealSet):
domain = RealSet(domain)
if domain.is_empty():
continue
if isinstance(function, FunctionType):
if var is None:
var = SR.var('x')
if function.func_code.co_argcount == 0:
function = function()
else:
function = function(var)
function = SR(function)
if var is None and len(function.variables()) > 0:
var = function.variables()[0]
parameters.append((domain, function))
domain_list.append(domain)
if not RealSet.are_pairwise_disjoint(*domain_list):
raise ValueError('domains must be pairwise disjoint')
if var is None:
var = self.default_variable()
parameters = SR._force_pyobject(tuple(parameters), recursive=False)
return BuiltinFunction.__call__(self, parameters, var, **kwds)
示例9: __call__
# 需要导入模块: from sage.symbolic.function import BuiltinFunction [as 别名]
# 或者: from sage.symbolic.function.BuiltinFunction import __call__ [as 别名]
def __call__(self, *args, **kwds):
"""
EXAMPLES::
sage: max_symbolic(3,5,x)
max(x, 5)
sage: max_symbolic(3,5,x, hold=True)
max(3, 5, x)
sage: max_symbolic([3,5,x])
max(x, 5)
::
sage: min_symbolic(3,5,x)
min(x, 3)
sage: min_symbolic(3,5,x, hold=True)
min(3, 5, x)
sage: min_symbolic([3,5,x])
min(x, 3)
TESTS:
We get an exception if no arguments are given::
sage: max_symbolic()
Traceback (most recent call last):
...
ValueError: number of arguments must be > 0
Check if we return None, when the builtin function would::
sage: max_symbolic([None]) is None
True
sage: max_symbolic([None, None]) is None
True
sage: min_symbolic([None]) is None
True
sage: min_symbolic([None, None]) is None
True
Check if a single argument which is not iterable works::
sage: max_symbolic(None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is not iterable
sage: max_symbolic(5)
Traceback (most recent call last):
...
TypeError: 'sage.rings.integer.Integer' object is not iterable
sage: max_symbolic(x)
Traceback (most recent call last):
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable
sage: min_symbolic(5)
Traceback (most recent call last):
...
TypeError: 'sage.rings.integer.Integer' object is not iterable
sage: min_symbolic(x)
Traceback (most recent call last):
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable
"""
if len(args) == 0:
raise ValueError("number of arguments must be > 0")
if len(args) == 1:
try:
args=(SR._force_pyobject(iter(args[0])),)
except TypeError as e:
raise e
try:
return BuiltinFunction.__call__(self, *args, **kwds)
except ValueError as e:
if e.args[0] == "return None":
return None