本文整理汇总了Python中sympy.oo方法的典型用法代码示例。如果您正苦于以下问题:Python sympy.oo方法的具体用法?Python sympy.oo怎么用?Python sympy.oo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy
的用法示例。
在下文中一共展示了sympy.oo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_constants
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_constants():
assert sympify(sympy.E) == E
assert sympy.E == E._sympy_()
assert sympify(sympy.pi) == pi
assert sympy.pi == pi._sympy_()
assert sympify(sympy.GoldenRatio) == GoldenRatio
assert sympy.GoldenRatio == GoldenRatio._sympy_()
assert sympify(sympy.Catalan) == Catalan
assert sympy.Catalan == Catalan._sympy_()
assert sympify(sympy.EulerGamma) == EulerGamma
assert sympy.EulerGamma == EulerGamma._sympy_()
assert sympify(sympy.oo) == oo
assert sympy.oo == oo._sympy_()
assert sympify(sympy.zoo) == zoo
assert sympy.zoo == zoo._sympy_()
assert sympify(sympy.nan) == nan
assert sympy.nan == nan._sympy_()
示例2: test_integrate
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_integrate():
moments = quadpy.tools.integrate(lambda x: [x ** k for k in range(5)], -1, +1)
assert (moments == [2, 0, sympy.S(2) / 3, 0, sympy.S(2) / 5]).all()
moments = quadpy.tools.integrate(
lambda x: orthopy.line_segment.tree_legendre(x, 4, "monic", symbolic=True),
-1,
+1,
)
assert (moments == [2, 0, 0, 0, 0]).all()
# Example from Gautschi's "How to and how not to" article
moments = quadpy.tools.integrate(
lambda x: [x ** k * sympy.exp(-(x ** 3) / 3) for k in range(5)], 0, sympy.oo
)
S = numpy.vectorize(sympy.S)
gamma = numpy.vectorize(sympy.gamma)
n = numpy.arange(5)
reference = 3 ** (S(n - 2) / 3) * gamma(S(n + 1) / 3)
assert numpy.all([sympy.simplify(m - r) == 0 for m, r in zip(moments, reference)])
示例3: test_gaussian
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_gaussian():
"""
Make sure that symfit.distributions.Gaussians produces the expected
sympy expression.
"""
x0 = Parameter()
sig = Parameter(positive=True)
x = Variable()
new = sympy.exp(-(x - x0)**2/(2*sig**2))/sympy.sqrt((2*sympy.pi*sig**2))
assert isinstance(new, sympy.Expr)
g = Gaussian(x, x0, sig)
assert issubclass(g.__class__, sympy.Expr)
assert new == g
# A pdf should always integrate to 1 on its domain
assert sympy.integrate(g, (x, -sympy.oo, sympy.oo)) == 1
示例4: test_exp
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_exp():
"""
Make sure that symfit.distributions.Exp produces the expected
sympy expression.
"""
l = Parameter(positive=True)
x = Variable()
new = l * sympy.exp(- l * x)
assert isinstance(new, sympy.Expr)
e = Exp(x, l)
assert issubclass(e.__class__, sympy.Expr)
assert new == e
# A pdf should always integrate to 1 on its domain
assert sympy.integrate(e, (x, 0, sympy.oo)) == 1
示例5: default_args
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def default_args(self):
return (oo,)
示例6: _represent_default_basis
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def _represent_default_basis(self, **options):
if not self.N or self.N == oo:
raise NotImplementedError('Cannot represent infinite dimensional' +
' identity operator as a matrix')
format = options.get('format', 'sympy')
if format != 'sympy':
raise NotImplementedError('Representation in format ' +
'%s not implemented.' % format)
return eye(self.N)
示例7: eval
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def eval(cls, dimension):
if len(dimension.atoms()) == 1:
if not (dimension.is_Integer and dimension > 0 or dimension is oo
or dimension.is_Symbol):
raise TypeError('The dimension of a ComplexSpace can only'
'be a positive integer, oo, or a Symbol: %r'
% dimension)
else:
for dim in dimension.atoms():
if not (dim.is_Integer or dim is oo or dim.is_Symbol):
raise TypeError('The dimension of a ComplexSpace can only'
' contain integers, oo, or a Symbol: %r'
% dim)
示例8: dimension
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def dimension(self):
arg_list = [arg.dimension for arg in self.args]
if oo in arg_list:
return oo
else:
return reduce(lambda x, y: x*y, arg_list)
示例9: test_L2
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_L2():
b1 = L2(Interval(-oo, 1))
assert isinstance(b1, L2)
assert b1.dimension == oo
assert b1.interval == Interval(-oo, 1)
x = Symbol('x', real=True)
y = Symbol('y', real=True)
b2 = L2(Interval(x, y))
assert b2.dimension == oo
assert b2.interval == Interval(x, y)
assert b2.subs(x, -1) == L2(Interval(-1, y))
示例10: test_fock_space
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_fock_space():
f1 = FockSpace()
f2 = FockSpace()
assert isinstance(f1, FockSpace)
assert f1.dimension == oo
assert f1 == f2
示例11: test_direct_sum
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_direct_sum():
n = Symbol('n')
hs1 = ComplexSpace(2)
hs2 = ComplexSpace(n)
h = hs1 + hs2
assert isinstance(h, DirectSumHilbertSpace)
assert h.dimension == 2 + n
assert h.spaces == (hs1, hs2)
f = FockSpace()
h = hs1 + f + hs2
assert h.dimension == oo
assert h.spaces == (hs1, f, hs2)
示例12: test_stieltjes
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_stieltjes():
alpha0, beta0 = quadpy.tools.stieltjes(lambda t: 1, -1, +1, 5)
_, _, alpha1, beta1 = orthopy.line_segment.recurrence_coefficients.legendre(
5, "monic", symbolic=True
)
assert (alpha0 == alpha1).all()
assert (beta0 == beta1).all()
# def test_expt3():
# '''Full example from Gautschi's "How to and how not to" article.
# '''
# # moments = quadpy.tools.integrate(
# # lambda x: sympy.exp(-x**3/3),
# # 0, sympy.oo,
# # 31
# # )
# # print(moments)
# # alpha, beta = quadpy.tools.chebyshev(moments)
#
# alpha, beta = quadpy.tools.stieltjes(
# lambda x: sympy.exp(-x**3/3),
# 0, sympy.oo,
# 5
# )
# print(alpha)
# print(beta)
示例13: convert_atom
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def convert_atom(atom):
if atom.LETTER():
subscriptName = ''
if atom.subexpr():
subscript = None
if atom.subexpr().expr(): # subscript is expr
subscript = convert_expr(atom.subexpr().expr())
else: # subscript is atom
subscript = convert_atom(atom.subexpr().atom())
subscriptName = '_{' + StrPrinter().doprint(subscript) + '}'
return sympy.Symbol(atom.LETTER().getText() + subscriptName)
elif atom.SYMBOL():
s = atom.SYMBOL().getText()[1:]
if s == "infty":
return sympy.oo
else:
if atom.subexpr():
subscript = None
if atom.subexpr().expr(): # subscript is expr
subscript = convert_expr(atom.subexpr().expr())
else: # subscript is atom
subscript = convert_atom(atom.subexpr().atom())
subscriptName = StrPrinter().doprint(subscript)
s += '_{' + subscriptName + '}'
return sympy.Symbol(s)
elif atom.NUMBER():
s = atom.NUMBER().getText().replace(",", "")
return sympy.Number(s)
elif atom.DIFFERENTIAL():
var = get_differential_var(atom.DIFFERENTIAL())
return sympy.Symbol('d' + var.name)
elif atom.mathit():
text = rule2text(atom.mathit().mathit_text())
return sympy.Symbol(text)
示例14: test_requires_partial
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def test_requires_partial():
x, y, z, t, nu = symbols('x y z t nu')
n = symbols('n', integer=True)
f = x * y
assert requires_partial(Derivative(f, x)) is True
assert requires_partial(Derivative(f, y)) is True
## integrating out one of the variables
assert requires_partial(Derivative(Integral(exp(-x * y), (x, 0, oo)), y, evaluate=False)) is False
## bessel function with smooth parameter
f = besselj(nu, x)
assert requires_partial(Derivative(f, x)) is True
assert requires_partial(Derivative(f, nu)) is True
## bessel function with integer parameter
f = besselj(n, x)
assert requires_partial(Derivative(f, x)) is False
# this is not really valid (differentiating with respect to an integer)
# but there's no reason to use the partial derivative symbol there. make
# sure we don't throw an exception here, though
assert requires_partial(Derivative(f, n)) is False
## bell polynomial
f = bell(n, x)
assert requires_partial(Derivative(f, x)) is False
# again, invalid
assert requires_partial(Derivative(f, n)) is False
## legendre polynomial
f = legendre(0, x)
assert requires_partial(Derivative(f, x)) is False
f = legendre(n, x)
assert requires_partial(Derivative(f, x)) is False
# again, invalid
assert requires_partial(Derivative(f, n)) is False
f = x ** n
assert requires_partial(Derivative(f, x)) is False
assert requires_partial(Derivative(Integral((x*y) ** n * exp(-x * y), (x, 0, oo)), y, evaluate=False)) is False
# parametric equation
f = (exp(t), cos(t))
g = sum(f)
assert requires_partial(Derivative(g, t)) is False
# function of unspecified variables
f = symbols('f', cls=Function)
assert requires_partial(Derivative(f, x)) is False
assert requires_partial(Derivative(f, x, y)) is True
示例15: sympy_expr_abs_distance_key
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import oo [as 别名]
def sympy_expr_abs_distance_key(e):
"""
Transform expression into tuple for sorting and comparison.
e.g., sympy_expr_abs_distance_key(N**2 + 23) -> ((2, 0.0), (1, 0.0), (0, 23.0))
Multiple variables are treated equal (N*M == N**2).
"""
# Integers
if type(e) is int or e.is_Integer:
return ((0, abs(e)),)
# Infinity
if abs(e) is sympy.oo:
return ((sympy.oo, sympy.oo),)
# Expressions, replace all free_symbols with one
first_s = None
for i, s in enumerate(e.free_symbols):
# Skip and remember first symbol
if i == 0:
first_s = s
continue
e = e.subs(s, first_s)
e = e.expand()
key = []
# split into terms
terms, gens = e.as_terms()
assert gens == [first_s] or first_s is None and gens == [], \
"Expression was split into unusable terms: {}, expected.".format(gens, first_s)
# extract exponent and coefficient
for term, (coeff, cpart, ncpart) in terms:
coeff_real, coeff_imag = coeff
assert coeff_imag == 0, "Not supporting imaginary coefficients."
# Sort order: exponent (cpart), factor
key.append(cpart + (coeff_real,))
key[0] = (key[0][0], key[0][1])
# build key
key.sort(reverse=True)
# add missing exponent, coefficient tuples
i = 0
for exponent in reversed(range(key[0][0]+1)):
if len(key) > i and key[i][0] == exponent:
i += 1
continue
else:
key[i:i] = [(exponent, 0.0)]
i += 1
key = tuple(key)
return key