本文整理汇总了Python中sage.symbolic.ring.SR.variables方法的典型用法代码示例。如果您正苦于以下问题:Python SR.variables方法的具体用法?Python SR.variables怎么用?Python SR.variables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.symbolic.ring.SR
的用法示例。
在下文中一共展示了SR.variables方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fricas_integrator
# 需要导入模块: from sage.symbolic.ring import SR [as 别名]
# 或者: from sage.symbolic.ring.SR import variables [as 别名]
def fricas_integrator(expression, v, a=None, b=None):
"""
Integration using FriCAS
EXAMPLES::
sage: from sage.symbolic.integration.external import fricas_integrator # optional - fricas
sage: fricas_integrator(sin(x), x) # optional - fricas
-cos(x)
sage: fricas_integrator(cos(x), x) # optional - fricas
sin(x)
sage: fricas_integrator(1/(x^2-2), x, 0, 1) # optional - fricas
1/4*(log(3*sqrt(2) - 4) - log(sqrt(2)))*sqrt(2)
sage: fricas_integrator(1/(x^2+6), x, -oo, oo) # optional - fricas
1/6*pi*sqrt(6)
"""
if not isinstance(expression, Expression):
expression = SR(expression)
if a is None:
result = expression._fricas_().integrate(v)
else:
import sage.rings.infinity
if a == sage.rings.infinity.PlusInfinity():
a = "%plusInfinity"
elif a == sage.rings.infinity.MinusInfinity():
a = "%minusInfinity"
if b == sage.rings.infinity.PlusInfinity():
b = "%plusInfinity"
elif b == sage.rings.infinity.MinusInfinity():
b = "%minusInfinity"
result = expression._fricas_().integrate("{}={}..{}".format(v, a, b))
locals = {str(v): v for v in expression.variables()}
if str(result) == "potentialPole":
raise ValueError("The integrand has a potential pole"
" in the integration interval")
parsed_result = result.unparsed_input_form()
import sage.misc.sage_eval
try:
return sage.misc.sage_eval.sage_eval(parsed_result, locals=locals)
except:
raise ValueError("Unable to parse: {}".format(parsed_result))
示例2: fricas_integrator
# 需要导入模块: from sage.symbolic.ring import SR [as 别名]
# 或者: from sage.symbolic.ring.SR import variables [as 别名]
def fricas_integrator(expression, v, a=None, b=None, noPole=True):
"""
Integration using FriCAS
EXAMPLES::
sage: from sage.symbolic.integration.external import fricas_integrator # optional - fricas
sage: fricas_integrator(sin(x), x) # optional - fricas
-cos(x)
sage: fricas_integrator(cos(x), x) # optional - fricas
sin(x)
sage: fricas_integrator(1/(x^2-2), x, 0, 1) # optional - fricas
1/4*sqrt(2)*(log(3*sqrt(2) - 4) - log(sqrt(2)))
sage: fricas_integrator(1/(x^2+6), x, -oo, oo) # optional - fricas
1/6*sqrt(6)*pi
"""
if not isinstance(expression, Expression):
expression = SR(expression)
if a is None:
result = expression._fricas_().integrate(v)
else:
import sage.rings.infinity
if a == sage.rings.infinity.PlusInfinity():
a = "%plusInfinity"
elif a == sage.rings.infinity.MinusInfinity():
a = "%minusInfinity"
if b == sage.rings.infinity.PlusInfinity():
b = "%plusInfinity"
elif b == sage.rings.infinity.MinusInfinity():
b = "%minusInfinity"
if noPole:
result = expression._fricas_().integrate("{}={}..{}".format(v, a, b), '"noPole"')
else:
result = expression._fricas_().integrate("{}={}..{}".format(v, a, b))
locals = {str(v): v for v in expression.variables()}
if str(result) == "potentialPole":
raise ValueError("The integrand has a potential pole"
" in the integration interval")
return result.sage()
示例3: __call__
# 需要导入模块: from sage.symbolic.ring import SR [as 别名]
# 或者: from sage.symbolic.ring.SR import variables [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)