本文整理汇总了Python中sympy.core.Add.normal方法的典型用法代码示例。如果您正苦于以下问题:Python Add.normal方法的具体用法?Python Add.normal怎么用?Python Add.normal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.Add
的用法示例。
在下文中一共展示了Add.normal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: limit
# 需要导入模块: from sympy.core import Add [as 别名]
# 或者: from sympy.core.Add import normal [as 别名]
#.........这里部分代码省略.........
unknown_result = []
finite = []
zero = []
def _sift(term):
if z not in term.free_symbols:
if term.is_unbounded:
unbounded_const.append(term)
else:
finite.append(term)
else:
result = term.subs(z, z0)
bounded = result.is_bounded
if bounded is False or result is S.NaN:
unbounded.append(term)
if result != S.NaN:
# take result from direction given
result = limit(term, z, z0, dir)
unbounded_result.append(result)
elif bounded:
if result:
finite.append(result)
else:
zero.append(term)
else:
unknown.append(term)
unknown_result.append(result)
for term in e.args:
_sift(term)
bad = bool(unknown and unbounded)
if bad or len(unknown) > 1 or len(unbounded) > 1 and not zero:
uu = unknown + unbounded
# we won't be able to resolve this with unbounded
# terms, e.g. Sum(1/k, (k, 1, n)) - log(n) as n -> oo:
# since the Sum is unevaluated it's boundedness is
# unknown and the log(n) is oo so you get Sum - oo
# which is unsatisfactory. BUT...if there are both
# unknown and unbounded terms (condition 'bad') or
# there are multiple terms that are unknown, or
# there are multiple symbolic unbounded terms they may
# respond better if they are made into a rational
# function, so give them a chance to do so before
# reporting failure.
u = Add(*uu)
f = u.normal()
if f != u:
unknown = []
unbounded = []
unbounded_result = []
unknown_result = []
_sift(limit(f, z, z0, dir))
# We came in with a) unknown and unbounded terms or b) had multiple
# unknown terms
# At this point we've done one of 3 things.
# (1) We did nothing with f so we now report the error
# showing the troublesome terms which are now in uu. OR
# (2) We did something with f but the result came back as unknown.
# Normally this wouldn't be a problem,
# but we had either multiple terms that were troublesome (unk and
# unbounded or multiple unknown terms) so if we
# weren't able to resolve the boundedness by now, that indicates a
# problem so we report the error showing the troublesome terms which are
# now in uu.
if unknown:
if bad:
msg = 'unknown and unbounded terms present in %s'
elif unknown:
msg = 'multiple terms with unknown boundedness in %s'
raise NotImplementedError(msg % uu)
# OR
# (3) the troublesome terms have been identified as finite or unbounded
# and we proceed with the non-error code since the lists have been updated.
u = Add(*unknown_result)
if unbounded_result or unbounded_const:
unbounded.extend(zero)
inf_limit = Add(*(unbounded_result + unbounded_const))
if inf_limit is not S.NaN:
return inf_limit + u
if finite:
return Add(*finite) + limit(Add(*unbounded), z, z0, dir) + u
else:
return Add(*finite) + u
if e.is_Order:
args = e.args
return C.Order(limit(args[0], z, z0), *args[1:])
try:
r = gruntz(e, z, z0, dir)
if r is S.NaN:
raise PoleError()
except (PoleError, ValueError):
r = heuristics(e, z, z0, dir)
return r