本文整理汇总了Python中sympy.core.add.Add.primitive方法的典型用法代码示例。如果您正苦于以下问题:Python Add.primitive方法的具体用法?Python Add.primitive怎么用?Python Add.primitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.add.Add
的用法示例。
在下文中一共展示了Add.primitive方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _gcd_terms
# 需要导入模块: from sympy.core.add import Add [as 别名]
# 或者: from sympy.core.add.Add import primitive [as 别名]
def _gcd_terms(terms, isprimitive=False, fraction=True):
"""Helper function for :func:`gcd_terms`.
If ``isprimitive`` is True then the call to primitive
for an Add will be skipped. This is useful when the
content has already been extrated.
If ``fraction`` is True then the expression will appear over a common
denominator, the lcm of all term denominators.
"""
if isinstance(terms, Basic) and not isinstance(terms, Tuple):
terms = Add.make_args(terms)
terms = map(Term, [t for t in terms if t])
# there is some simplification that may happen if we leave this
# here rather than duplicate it before the mapping of Term onto
# the terms
if len(terms) == 0:
return S.Zero, S.Zero, S.One
if len(terms) == 1:
cont = terms[0].coeff
numer = terms[0].numer.as_expr()
denom = terms[0].denom.as_expr()
else:
cont = terms[0]
for term in terms[1:]:
cont = cont.gcd(term)
for i, term in enumerate(terms):
terms[i] = term.quo(cont)
if fraction:
denom = terms[0].denom
for term in terms[1:]:
denom = denom.lcm(term.denom)
numers = []
for term in terms:
numer = term.numer.mul(denom.quo(term.denom))
numers.append(term.coeff*numer.as_expr())
else:
numers = [t.as_expr() for t in terms]
denom = Term(S(1)).numer
cont = cont.as_expr()
numer = Add(*numers)
denom = denom.as_expr()
if not isprimitive and numer.is_Add:
_cont, numer = numer.primitive()
cont *= _cont
return cont, numer, denom
示例2: _gcd_terms
# 需要导入模块: from sympy.core.add import Add [as 别名]
# 或者: from sympy.core.add.Add import primitive [as 别名]
def _gcd_terms(terms, isprimitive=False):
"""Helper function for :func:`gcd_terms`. If `isprimitive` is True then the
call to primitive for an Add will be skipped. This is useful when the
content has already been extrated."""
if isinstance(terms, Basic) and not isinstance(terms, Tuple):
terms = Add.make_args(terms)
if len(terms) <= 1:
if not terms:
return S.Zero, S.Zero, S.One
else:
return terms[0], S.One, S.One
terms = map(Term, terms)
cont = terms[0]
for term in terms[1:]:
cont = cont.gcd(term)
for i, term in enumerate(terms):
terms[i] = term.quo(cont)
denom = terms[0].denom
for term in terms[1:]:
denom = denom.lcm(term.denom)
numers = []
for term in terms:
numer = term.numer.mul(denom.quo(term.denom))
numers.append(term.coeff*numer.as_expr())
cont = cont.as_expr()
numer = Add(*numers)
denom = denom.as_expr()
if not isprimitive and numer.is_Add:
_cont, numer = numer.primitive()
cont *= _cont
return cont, numer, denom
示例3: _gcd_terms
# 需要导入模块: from sympy.core.add import Add [as 别名]
# 或者: from sympy.core.add.Add import primitive [as 别名]
def _gcd_terms(terms):
"""Helper function for :func:`gcd_terms`. """
if isinstance(terms, Basic):
terms = Add.make_args(terms)
if len(terms) <= 1:
if not terms:
return S.Zero, S.Zero, S.One
else:
return terms[0], S.One, S.One
terms = map(Term, terms)
cont = terms[0]
for term in terms[1:]:
cont = cont.gcd(term)
for i, term in enumerate(terms):
terms[i] = term.quo(cont)
denom = terms[0].denom
for term in terms[1:]:
denom = denom.lcm(term.denom)
numers = []
for term in terms:
numer = term.numer.mul(denom.quo(term.denom))
numers.append(term.coeff*numer.as_expr())
cont = cont.as_expr()
numer = Add(*numers)
denom = denom.as_expr()
if numer.is_Add:
_cont, numer = numer.primitive()
cont *= _cont
return cont, numer, denom