本文整理汇总了Python中sympy.logcombine函数的典型用法代码示例。如果您正苦于以下问题:Python logcombine函数的具体用法?Python logcombine怎么用?Python logcombine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了logcombine函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logcombine_complex_coeff
def test_logcombine_complex_coeff():
# TODO: Make the expand() call in logcombine smart enough so that both
# these hold.
assert logcombine(Integral((sin(x**2)+cos(x**3))/x, x), force=True) == \
Integral((sin(x**2)+cos(x**3))/x, x)
assert logcombine(Integral((sin(x**2)+cos(x**3))/x, x)+ (2+3*I)*log(x), \
force=True) == log(x**2)+3*I*log(x) + \
Integral((sin(x**2)+cos(x**3))/x, x)
示例2: test_logcombine_2
def test_logcombine_2():
# The same as one of the tests above, but with Rational(a,b) replaced with a/b.
# This fails because of a bug in matches. See issue 1274.
x, y = symbols("xy")
assert logcombine((x*y+sqrt(x**4+y**4)+log(x)-log(y))/(pi*x**(2/3)*y**(3/2)), \
assume_pos_real=True) == log(x**(1/(pi*x**(2/3)*y**(3/2)))*y**(-1/\
(pi*x**(2/3)*y**(3/2)))) + (x**4 + y**4)**(1/2)/(pi*x**(2/3)*y**(3/2)) + \
x**(1/3)/(pi*y**(1/2))
示例3: logcombine_include_negative_power
def logcombine_include_negative_power(expr, force=False):
"""Perform a more powerful logcombine than SymPy's logcombine.
In SymPy:
logcombine(-log(x)) = -log(x), rather than log(1/x).
This behaviour is implemented here.
>>> SolveLogEquation.logcombine_include_negative_power(-sympy.log(2 * x + 1))
log(1/(2*x + 1))
"""
expr = sympy.logcombine(expr, force)
if expr.could_extract_minus_sign():
interior = expr.match(coeff0 * sympy.log(x0))[x0]
expr *= -1
expr = sympy.log(1 / interior)
return expr
示例4: log_solver
def log_solver(expr, check_validity=False):
"""Return valid solutions (i.e. solutions that don't evaluate any log that's part of the expression as complex)
for an expression that is the addition/subtraction of logs.
>>> SolveLogEquation.log_solver(sympy.log(x - 1))
[2]
>>> SolveLogEquation.log_solver(sympy.log(3 * x - 2) - 2 * sympy.log(x))
[1, 2]
"""
single_log = sympy.logcombine(expr, force=True)
interior = single_log.match(coeff0 * sympy.log(x0))[x0]
numerator, denominator = interior.as_numer_denom()
solutions = sympy.solve(numerator - denominator)
if check_validity:
return [solution for solution in solutions if SolveLogEquation.is_valid_solution(expr, solution)]
else:
return solutions
示例5: normalize_transformations
def normalize_transformations(w):
# same as
# lambda w: w.doit().expand().ratsimp().expand()
# except catch Polynomial error that could be triggered by ratsimp()
# and catch attribute error for objects like Interval
from sympy import PolynomialError
w = w.doit()
try:
w = w.expand()
except (AttributeError, TypeError):
pass
if w.has(sympy_log):
from sympy import logcombine
try:
w = logcombine(w)
except TypeError:
pass
try:
w = w.ratsimp().expand()
except (AttributeError, PolynomialError, UnicodeEncodeError, TypeError):
pass
return w
示例6: mysimp
def mysimp(expr):
from sympy import expand, logcombine, powsimp
return expand(
powsimp(logcombine(expr, force=True), force=True, deep=True),
force=True).replace(exp_polar, exp)
示例7: test_logcombine_1
def test_logcombine_1():
x, y = symbols("x,y")
a = Symbol("a")
z, w = symbols("z,w", positive=True)
b = Symbol("b", real=True)
assert logcombine(log(x)+2*log(y)) == log(x) + 2*log(y)
assert logcombine(log(x)+2*log(y), force=True) == log(x*y**2)
assert logcombine(a*log(w)+log(z)) == a*log(w) + log(z)
assert logcombine(b*log(z)+b*log(x)) == log(z**b) + b*log(x)
assert logcombine(b*log(z)-log(w)) == log(z**b/w)
assert logcombine(log(x)*log(z)) == log(x)*log(z)
assert logcombine(log(w)*log(x)) == log(w)*log(x)
assert logcombine(cos(-2*log(z)+b*log(w))) in [cos(log(w**b/z**2)),
cos(log(z**2/w**b))]
assert logcombine(log(log(x)-log(y))-log(z), force=True) == \
log(log((x/y)**(1/z)))
assert logcombine((2+I)*log(x), force=True) == I*log(x)+log(x**2)
assert logcombine((x**2+log(x)-log(y))/(x*y), force=True) == \
log(x**(1/(x*y))*y**(-1/(x*y)))+x/y
assert logcombine(log(x)*2*log(y)+log(z), force=True) == \
log(z*y**log(x**2))
assert logcombine((x*y+sqrt(x**4+y**4)+log(x)-log(y))/(pi*x**Rational(2, 3)*\
sqrt(y)**3), force=True) == \
log(x**(1/(pi*x**Rational(2, 3)*sqrt(y)**3))*y**(-1/(pi*\
x**Rational(2, 3)*sqrt(y)**3))) + sqrt(x**4 + y**4)/(pi*\
x**Rational(2, 3)*sqrt(y)**3) + x**Rational(1, 3)/(pi*sqrt(y))
assert logcombine(Eq(log(x), -2*log(y)), force=True) == \
Eq(log(x*y**2), Integer(0))
assert logcombine(Eq(y, x*acos(-log(x/y))), force=True) == \
Eq(y, x*acos(log(y/x)))
assert logcombine(gamma(-log(x/y))*acos(-log(x/y)), force=True) == \
acos(log(y/x))*gamma(log(y/x))
assert logcombine((2+3*I)*log(x), force=True) == \
log(x**2)+3*I*log(x)
assert logcombine(Eq(y, -log(x)), force=True) == Eq(y, log(1/x))
assert logcombine(Integral((sin(x**2)+cos(x**3))/x, x), force=True) == \
Integral((sin(x**2)+cos(x**3))/x, x)
assert logcombine(Integral((sin(x**2)+cos(x**3))/x, x)+ (2+3*I)*log(x), \
force=True) == log(x**2)+3*I*log(x) + \
Integral((sin(x**2)+cos(x**3))/x, x)
示例8: eval
def eval(cls, arg):
from sympy.assumptions import ask, Q
from sympy.calculus import AccumBounds
from sympy.sets.setexpr import SetExpr
from sympy.matrices.matrices import MatrixBase
from sympy import logcombine
if arg.is_Number:
if arg is S.NaN:
return S.NaN
elif arg is S.Zero:
return S.One
elif arg is S.One:
return S.Exp1
elif arg is S.Infinity:
return S.Infinity
elif arg is S.NegativeInfinity:
return S.Zero
elif arg is S.ComplexInfinity:
return S.NaN
elif isinstance(arg, log):
return arg.args[0]
elif isinstance(arg, AccumBounds):
return AccumBounds(exp(arg.min), exp(arg.max))
elif isinstance(arg, SetExpr):
return arg._eval_func(cls)
elif arg.is_Mul:
if arg.is_number or arg.is_Symbol:
coeff = arg.coeff(S.Pi*S.ImaginaryUnit)
if coeff:
if ask(Q.integer(2*coeff)):
if ask(Q.even(coeff)):
return S.One
elif ask(Q.odd(coeff)):
return S.NegativeOne
elif ask(Q.even(coeff + S.Half)):
return -S.ImaginaryUnit
elif ask(Q.odd(coeff + S.Half)):
return S.ImaginaryUnit
# Warning: code in risch.py will be very sensitive to changes
# in this (see DifferentialExtension).
# look for a single log factor
coeff, terms = arg.as_coeff_Mul()
# but it can't be multiplied by oo
if coeff in [S.NegativeInfinity, S.Infinity]:
return None
coeffs, log_term = [coeff], None
for term in Mul.make_args(terms):
term_ = logcombine(term)
if isinstance(term_, log):
if log_term is None:
log_term = term_.args[0]
else:
return None
elif term.is_comparable:
coeffs.append(term)
else:
return None
return log_term**Mul(*coeffs) if log_term else None
elif arg.is_Add:
out = []
add = []
for a in arg.args:
if a is S.One:
add.append(a)
continue
newa = cls(a)
if isinstance(newa, cls):
add.append(a)
else:
out.append(newa)
if out:
return Mul(*out)*cls(Add(*add), evaluate=False)
elif isinstance(arg, MatrixBase):
return arg.exp()