本文整理汇总了Python中sympy.core.basic.Basic.abs方法的典型用法代码示例。如果您正苦于以下问题:Python Basic.abs方法的具体用法?Python Basic.abs怎么用?Python Basic.abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.basic.Basic
的用法示例。
在下文中一共展示了Basic.abs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import abs [as 别名]
def _eval_apply(self, arg):
#XXX this doesn't work, but it should (see #390):
#return arg**S.Half
arg = Basic.sympify(arg)
if isinstance(arg, Basic.Number):
if isinstance(arg, Basic.NaN):
return S.NaN
if isinstance(arg, Basic.Infinity):
return S.Infinity
if isinstance(arg, Basic.NegativeInfinity):
return S.ImaginaryUnit * S.Infinity
if isinstance(arg, Basic.Rational):
factors = arg.factors()
sqrt_factors = {}
eval_factors = {}
n = Basic.Integer(1)
for k,v in factors.items():
n *= Basic.Integer(k) ** (v//2)
if v % 2:
n *= Basic.Integer(k) ** S.Half
return n
return arg ** S.Half
if arg.is_nonnegative:
coeff, terms = arg.as_coeff_terms()
if not isinstance(coeff, Basic.One):
return self(coeff) * self(Basic.Mul(*terms))
base, exp = arg.as_base_exp()
if isinstance(exp, Basic.Number):
if exp == 2:
return Basic.abs(base)
return base ** (exp/2)