本文整理汇总了Python中sympy.Mul.make_args方法的典型用法代码示例。如果您正苦于以下问题:Python Mul.make_args方法的具体用法?Python Mul.make_args怎么用?Python Mul.make_args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Mul
的用法示例。
在下文中一共展示了Mul.make_args方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_make_args
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul 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,)
示例2: test_issue_3268
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def test_issue_3268():
z = -5*sqrt(2)/(2*sqrt(2*sqrt(29) + 29)) + sqrt(-sqrt(29)/29 + S(1)/2)
assert Mul(*[powsimp(a) for a in Mul.make_args(z.normal())]) == 0
assert powsimp(z.normal()) == 0
assert simplify(z) == 0
assert powsimp(sqrt(2 + sqrt(3))*sqrt(2 - sqrt(3)) + 1) == 2
assert powsimp(z) != 0
示例3: trig_replace
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def trig_replace(self, M, angle, name):
"""Replaces trigonometric expressions cos(x)
and sin(x) by CX and SX
Parameters
==========
M: var or Matrix
Object of substitution
angle: var
symbol that stands for the angle value
name: int or string
brief name X for the angle
Notes
=====
The cos(x) and sin(x) will be replaced by CX and SX,
where X is the name and x is the angle
"""
if not isinstance(angle, Expr) or angle.is_number:
return M
cos_sym, sin_sym = tools.cos_sin_syms(name)
sym_list = [(cos_sym, cos(angle)), (sin_sym, sin(angle))]
subs_dict = {}
for sym, sym_old in sym_list:
if -1 in Mul.make_args(sym_old):
sym_old = -sym_old
subs_dict[sym_old] = sym
self.add_to_dict(sym, sym_old)
for i1 in xrange(M.shape[0]):
for i2 in xrange(M.shape[1]):
M[i1, i2] = M[i1, i2].subs(subs_dict)
return M
示例4: simp
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def simp(self, sym):
sym = factor(sym)
new_sym = tools.ONE
for expr in Mul.make_args(sym):
if expr.is_Pow:
expr, pow_val = expr.args
else:
pow_val = 1
expr = self.C2S2_simp(expr)
expr = self.CS12_simp(expr, silent=True)
new_sym *= expr**pow_val
return new_sym
示例5: simp
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def simp(self, sym):
sym = factor(sym)
new_sym = ONE
for e in Mul.make_args(sym):
if e.is_Pow:
e, p = e.args
else:
p = 1
e = self.C2S2_simp(e)
e = self.CS12_simp(e, silent=True)
new_sym *= e**p
return new_sym
示例6: _print_Mul
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def _print_Mul(self, expr):
"Copied from sympy StrPrinter and modified to remove division."
prec = precedence(expr)
c, e = expr.as_coeff_Mul()
if c < 0:
expr = _keep_coeff(-c, e)
sign = "-"
else:
sign = ""
a = [] # items in the numerator
b = [] # items that are in the denominator (if any)
if self.order not in ('old', 'none'):
args = expr.as_ordered_factors()
else:
# use make_args in case expr was something like -x -> x
args = Mul.make_args(expr)
# Gather args for numerator/denominator
for item in args:
if item.is_commutative and item.is_Pow and item.exp.is_Rational and item.exp.is_negative:
if item.exp != -1:
b.append(Pow(item.base, -item.exp, evaluate=False))
else:
b.append(Pow(item.base, -item.exp))
elif item.is_Rational and item is not S.Infinity:
if item.p != 1:
a.append(Rational(item.p))
if item.q != 1:
b.append(Rational(item.q))
else:
a.append(item)
a = a or [S.One]
a_str = [self.parenthesize(x, prec) for x in a]
b_str = [self.parenthesize(x, prec) for x in b]
if len(b) == 0:
return sign + '*'.join(a_str)
elif len(b) == 1:
# Thermo-Calc's parser can't handle division operators
return sign + '*'.join(a_str) + "*%s" % self.parenthesize(b[0]**(-1), prec)
else:
# TODO: Make this Thermo-Calc compatible by removing division operation
return sign + '*'.join(a_str) + "/(%s)" % '*'.join(b_str)
示例7: check_dimensions
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def check_dimensions(expr):
"""Return expr if there are not unitless values added to
dimensional quantities, else raise a ValueError."""
from sympy.solvers.solveset import _term_factors
# the case of adding a number to a dimensional quantity
# is ignored for the sake of SymPy core routines, so this
# function will raise an error now if such an addend is
# found.
# Also, when doing substitutions, multiplicative constants
# might be introduced, so remove those now
adds = expr.atoms(Add)
DIM_OF = dimsys_default.get_dimensional_dependencies
for a in adds:
deset = set()
for ai in a.args:
if ai.is_number:
deset.add(())
continue
dims = []
skip = False
for i in Mul.make_args(ai):
if i.has(Quantity):
i = Dimension(Quantity.get_dimensional_expr(i))
if i.has(Dimension):
dims.extend(DIM_OF(i).items())
elif i.free_symbols:
skip = True
break
if not skip:
deset.add(tuple(sorted(dims)))
if len(deset) > 1:
raise ValueError(
"addends have incompatible dimensions")
# clear multiplicative constants on Dimensions which may be
# left after substitution
reps = {}
for m in expr.atoms(Mul):
if any(isinstance(i, Dimension) for i in m.args):
reps[m] = m.func(*[
i for i in m.args if not i.is_number])
return expr.xreplace(reps)
示例8: analyze
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul 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: check_solutions
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def check_solutions(eq):
"""
Determines whether solutions returned by diophantine() satisfy the original
equation. Hope to generalize this so we can remove functions like check_ternay_quadratic,
check_solutions_normal, check_solutions()
"""
s = diophantine(eq)
factors = Mul.make_args(eq)
var = list(eq.free_symbols)
var.sort(key=default_sort_key)
while s:
solution = s.pop()
for f in factors:
if diop_simplify(f.subs(zip(var, solution))) == 0:
break
else:
return False
return True
示例10: _rewrite_gamma
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
#.........这里部分代码省略.........
if arg.is_Add:
arg = arg.as_independent(s)[1]
coeff, _ = arg.as_coeff_mul(s)
s_multipliers += [coeff/pi]
s_multipliers = [abs(x) for x in s_multipliers if x.is_real]
common_coefficient = S(1)
for x in s_multipliers:
if not x.is_Rational:
common_coefficient = x
break
s_multipliers = [x/common_coefficient for x in s_multipliers]
if any(not x.is_Rational for x in s_multipliers):
raise NotImplementedError
s_multiplier = common_coefficient/reduce(ilcm, [S(x.q) for x in s_multipliers], S(1))
if s_multiplier == common_coefficient:
if len(s_multipliers) == 0:
s_multiplier = common_coefficient
else:
s_multiplier = common_coefficient \
*reduce(igcd, [S(x.p) for x in s_multipliers])
exponent = S(1)
fac = S(1)
f = f.subs(s, s/s_multiplier)
fac /= s_multiplier
exponent = 1/s_multiplier
if a_ is not None:
a_ *= s_multiplier
if b_ is not None:
b_ *= s_multiplier
# 2)
numer, denom = f.as_numer_denom()
numer = Mul.make_args(numer)
denom = Mul.make_args(denom)
args = zip(numer, repeat(True)) + zip(denom, repeat(False))
facs = []
dfacs = []
# *_gammas will contain pairs (a, c) representing Gamma(a*s + c)
numer_gammas = []
denom_gammas = []
# exponentials will contain bases for exponentials of s
exponentials = []
def exception(fact):
return IntegralTransformError("Inverse Mellin", f, "Unrecognised form '%s'." % fact)
while args:
fact, is_numer = args.pop()
if is_numer:
ugammas, lgammas = numer_gammas, denom_gammas
ufacs, lfacs = facs, dfacs
else:
ugammas, lgammas = denom_gammas, numer_gammas
ufacs, lfacs = dfacs, facs
def linear_arg(arg):
""" Test if arg is of form a*s+b, raise exception if not. """
if not arg.is_polynomial(s):
raise exception(fact)
p = Poly(arg, s)
if p.degree() != 1:
raise exception(fact)
return p.all_coeffs()
# constants
if not fact.has(s):
示例11: test_identity_removal
# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import make_args [as 别名]
def test_identity_removal():
assert Add.make_args(x + 0) == (x,)
assert Mul.make_args(x*1) == (x,)