本文整理汇总了Python中sympy.Add.make_args方法的典型用法代码示例。如果您正苦于以下问题:Python Add.make_args方法的具体用法?Python Add.make_args怎么用?Python Add.make_args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Add
的用法示例。
在下文中一共展示了Add.make_args方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gcd_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def test_gcd_terms():
f = 2*(x + 1)*(x + 4)/(5*x**2 + 5) + (2*x + 2)*(x + 5)/(x**2 + 1)/5 + (2*x + 2)*(x + 6)/(5*x**2 + 5)
assert _gcd_terms(f) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
assert _gcd_terms(Add.make_args(f)) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
assert gcd_terms(f) == (S(6)/5)*((1 + x)*(5 + x)/(1 + x**2))
assert gcd_terms(Add.make_args(f)) == (S(6)/5)*((1 + x)*(5 + x)/(1 + x**2))
assert gcd_terms((2*x + 2)**3 + (2*x + 2)**2) == 4*(x + 1)**2*(2*x + 3)
assert gcd_terms(0) == 0
assert gcd_terms(1) == 1
assert gcd_terms(x) == x
assert gcd_terms(2 + 2*x) == Mul(2, 1 + x, evaluate=False)
arg = x*(2*x + 4*y)
garg = 2*x*(x + 2*y)
assert gcd_terms(arg) == garg
assert gcd_terms(sin(arg)) == sin(garg)
# issue 3040-like
alpha, alpha1, alpha2, alpha3 = symbols('alpha:4')
a = alpha**2 - alpha*x**2 + alpha + x**3 - x*(alpha + 1)
rep = (alpha, (1 + sqrt(5))/2 + alpha1*x + alpha2*x**2 + alpha3*x**3)
s = (a/(x - alpha)).subs(*rep).series(x, 0, 1)
assert simplify(collect(s, x)) == -sqrt(5)/2 - S(3)/2 + O(x)
# issue 2818
assert _gcd_terms([S.Zero, S.Zero]) == (0, 0, 1)
assert _gcd_terms([2*x + 4]) == (2, x + 2, 1)
示例2: test_gcd_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def test_gcd_terms():
f = 2*(x + 1)*(x + 4)/(5*x**2 + 5) + (2*x + 2)*(x + 5)/(x**2 + 1)/5 + \
(2*x + 2)*(x + 6)/(5*x**2 + 5)
assert _gcd_terms(f) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
assert _gcd_terms(Add.make_args(f)) == \
((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
newf = (S(6)/5)*((1 + x)*(5 + x)/(1 + x**2))
assert gcd_terms(f) == newf
args = Add.make_args(f)
# non-Basic sequences of terms treated as terms of Add
assert gcd_terms(list(args)) == newf
assert gcd_terms(tuple(args)) == newf
assert gcd_terms(set(args)) == newf
# but a Basic sequence is treated as a container
assert gcd_terms(Tuple(*args)) != newf
assert gcd_terms(Basic(Tuple(1, 3*y + 3*x*y), Tuple(1, 3))) == \
Basic((1, 3*y*(x + 1)), (1, 3))
# but we shouldn't change keys of a dictionary or some may be lost
assert gcd_terms(Dict((x*(1 + y), 2), (x + x*y, y + x*y))) == \
Dict({x*(y + 1): 2, x + x*y: y*(1 + x)})
assert gcd_terms((2*x + 2)**3 + (2*x + 2)**2) == 4*(x + 1)**2*(2*x + 3)
assert gcd_terms(0) == 0
assert gcd_terms(1) == 1
assert gcd_terms(x) == x
assert gcd_terms(2 + 2*x) == Mul(2, 1 + x, evaluate=False)
arg = x*(2*x + 4*y)
garg = 2*x*(x + 2*y)
assert gcd_terms(arg) == garg
assert gcd_terms(sin(arg)) == sin(garg)
# issue 6139-like
alpha, alpha1, alpha2, alpha3 = symbols('alpha:4')
a = alpha**2 - alpha*x**2 + alpha + x**3 - x*(alpha + 1)
rep = (alpha, (1 + sqrt(5))/2 + alpha1*x + alpha2*x**2 + alpha3*x**3)
s = (a/(x - alpha)).subs(*rep).series(x, 0, 1)
assert simplify(collect(s, x)) == -sqrt(5)/2 - S(3)/2 + O(x)
# issue 5917
assert _gcd_terms([S.Zero, S.Zero]) == (0, 0, 1)
assert _gcd_terms([2*x + 4]) == (2, x + 2, 1)
eq = x/(x + 1/x)
assert gcd_terms(eq, fraction=False) == eq
eq = x/2/y + 1/x/y
assert gcd_terms(eq, fraction=True, clear=True) == \
(x**2 + 2)/(2*x*y)
assert gcd_terms(eq, fraction=True, clear=False) == \
(x**2/2 + 1)/(x*y)
assert gcd_terms(eq, fraction=False, clear=True) == \
(x + 2/x)/(2*y)
assert gcd_terms(eq, fraction=False, clear=False) == \
(x/2 + 1/x)/y
示例3: test_make_args
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def test_make_args():
assert Add.make_args(x) == (x,)
assert Mul.make_args(x) == (x,)
assert Add.make_args(x*y*z) == (x*y*z,)
assert Mul.make_args(x*y*z) == (x*y*z).args
assert Add.make_args(x + y + z) == (x + y + z).args
assert Mul.make_args(x + y + z) == (x + y + z,)
assert Add.make_args((x + y)**z) == ((x + y)**z,)
assert Mul.make_args((x + y)**z) == ((x + y)**z,)
示例4: test_gcd_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def test_gcd_terms():
f = 2*(x + 1)*(x + 4)/(5*x**2 + 5) + (2*x + 2)*(x + 5)/(x**2 + 1)/5 + (2*x + 2)*(x + 6)/(5*x**2 + 5)
assert _gcd_terms(f) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
assert _gcd_terms(Add.make_args(f)) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
assert gcd_terms(f) == (S(6)/5)*((1 + x)*(5 + x)/(1 + x**2))
assert gcd_terms(Add.make_args(f)) == (S(6)/5)*((1 + x)*(5 + x)/(1 + x**2))
assert gcd_terms(0) == 0
assert gcd_terms(1) == 1
assert gcd_terms(x) == x
示例5: test_gcd_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def test_gcd_terms():
f = 2*(x + 1)*(x + 4)/(5*x**2 + 5) + (2*x + 2)*(x + 5)/(x**2 + 1)/5 + (2*x + 2)*(x + 6)/(5*x**2 + 5)
assert _gcd_terms(f) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
assert _gcd_terms(Add.make_args(f)) == ((S(6)/5)*((1 + x)/(1 + x**2)), 5 + x, 1)
assert gcd_terms(f) == (S(6)/5)*((1 + x)*(5 + x)/(1 + x**2))
assert gcd_terms(Add.make_args(f)) == (S(6)/5)*((1 + x)*(5 + x)/(1 + x**2))
assert gcd_terms((2*x + 2)**3 + (2*x + 2)**2) == 4*(x + 1)**2*(2*x + 3)
assert gcd_terms(0) == 0
assert gcd_terms(1) == 1
assert gcd_terms(x) == x
assert gcd_terms(2 + 2*x) == Mul(2, 1 + x, evaluate=False)
示例6: cancel_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def cancel_terms(sym, x_term, coef):
if coef.is_Add:
for arg_c in coef.args:
sym = cancel_terms(sym, x_term, arg_c)
else:
terms = Add.make_args(sym)
return Add.fromiter(t for t in terms if t != x_term*coef)
示例7: _as_ordered_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def _as_ordered_terms(self, expr, order=None):
"""A compatibility function for ordering terms in Add. """
order = order or self.order
if order == 'old':
return sorted(Add.make_args(expr), key=cmp_to_key(Basic._compare_pretty))
else:
return expr.as_ordered_terms(order=order)
示例8: analyze
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def analyze(self, expr):
"""Rewrite an expression as sorted list of terms. """
gens, terms = set([]), []
for term in Add.make_args(expr):
coeff, cpart, ncpart = [], {}, []
for factor in Mul.make_args(term):
if not factor.is_commutative:
ncpart.append(factor)
else:
if factor.is_Number:
coeff.append(factor)
else:
base, exp = _analyze_power(*factor.as_base_exp())
cpart[base] = exp
gens.add(base)
terms.append((coeff, cpart, ncpart, term))
gens = sorted(gens, Basic._compare_pretty)
k, indices = len(gens), {}
for i, g in enumerate(gens):
indices[g] = i
result = []
for coeff, cpart, ncpart, term in terms:
monom = [0]*k
for base, exp in cpart.iteritems():
monom[indices[base]] = exp
result.append((coeff, monom, ncpart, term))
if self.order is None:
return sorted(result, Basic._compare_pretty)
else:
return sorted(result, self._compare_terms)
示例9: test_identity_removal
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def test_identity_removal():
assert Add.make_args(x + 0) == (x,)
assert Mul.make_args(x*1) == (x,)
示例10: get_max_coef
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def get_max_coef(sym, x_term):
return Add.fromiter(
get_max_coef_mul(s, x_term) for s in Add.make_args(sym)
)
示例11: get_max_coef_list
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import make_args [as 别名]
def get_max_coef_list(sym, x_term):
return [get_max_coef_mul(s, x_term) for s in Add.make_args(sym)]