本文整理汇总了Python中sympy.core.basic.Basic.sympify方法的典型用法代码示例。如果您正苦于以下问题:Python Basic.sympify方法的具体用法?Python Basic.sympify怎么用?Python Basic.sympify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.basic.Basic
的用法示例。
在下文中一共展示了Basic.sympify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def __new__(cls, expr, x, xlim, direction='<', **assumptions):
expr = Basic.sympify(expr)
x = Basic.sympify(x)
xlim = Basic.sympify(xlim)
if not isinstance(x, Basic.Symbol):
raise ValueError("Limit 2nd argument must be Symbol instance (got %s)" % (x))
assert isinstance(x, Basic.Symbol),`x`
if not expr.has(x):
return expr
if isinstance(xlim, Basic.NegativeInfinity):
xoo = InfLimit.limit_process_symbol()
if expr.has(xoo):
xoo = Basic.Symbol(x.name + '_oo',dummy=True,positive=True,unbounded=True)
return InfLimit(expr.subs(x,-xoo), xoo)
if isinstance(xlim, Basic.Infinity):
return InfLimit(expr, x)
else:
xoo = InfLimit.limit_process_symbol()
if expr.has(xoo):
xoo = Basic.Symbol(x.name + '_oo',dummy=True,positive=True,unbounded=True)
if direction=='<':
return InfLimit(expr.subs(x, xlim+1/xoo), xoo)
elif direction=='>':
return InfLimit(expr.subs(x, xlim-1/xoo), xoo)
else:
raise ValueError("Limit direction must be < or > (got %s)" % (direction))
# XXX This code is currently unreachable
obj = Basic.__new__(cls, expr, x, xlim, **assumptions)
obj.direction = direction
return obj
示例2: subs
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def subs(self, old, new):
old = Basic.sympify(old)
if old==self.func:
arg = self[0]
new = Basic.sympify(new)
return new(arg.subs(old, new))
return self
示例3: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def _eval_apply(cls, x, k):
x = Basic.sympify(x)
k = Basic.sympify(k)
if isinstance(x, Basic.NaN):
return S.NaN
elif isinstance(k, Basic.Integer):
if isinstance(k, Basic.NaN):
return S.NaN
elif isinstance(k, Basic.Zero):
return S.One
else:
result = S.One
if k.is_positive:
if isinstance(x, Basic.Infinity):
return S.Infinity
elif isinstance(x, Basic.NegativeInfinity):
if k.is_odd:
return S.NegativeInfinity
else:
return S.Infinity
else:
return reduce(lambda r, i: r*(x-i), xrange(0, int(k)), 1)
else:
if isinstance(x, Basic.Infinity):
return S.Infinity
elif isinstance(x, Basic.NegativeInfinity):
return S.Infinity
else:
return 1/reduce(lambda r, i: r*(x+i), xrange(1, abs(int(k))+1), 1)
示例4: __new__
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def __new__(cls, center, hradius, vradius, **kwargs):
hradius = Basic.sympify(hradius)
vradius = Basic.sympify(vradius)
if not isinstance(center, Point):
raise TypeError("center must be be a Point")
if hradius == vradius:
return Circle(center, hradius, **kwargs)
return GeometryEntity.__new__(cls, center, hradius, vradius, **kwargs)
示例5: __new__
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def __new__(cls, *args, **kwargs):
if isinstance(args[0], (tuple, list, set)):
coords = tuple([Basic.sympify(x) for x in args[0]])
else:
coords = tuple([Basic.sympify(x) for x in args])
if len(coords) != 2:
raise NotImplementedError("Only two dimensional points currently supported")
return GeometryEntity.__new__(cls, *coords)
示例6: taylor_term
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def taylor_term(self, n, x, *previous_terms):
if n == 0:
return 1 / Basic.sympify(x)
elif n < 0 or n % 2 == 0:
return S.Zero
else:
x = Basic.sympify(x)
B = S.Bernoulli(n+1)
F = Basic.Factorial(n+1)
return 2**(n+1) * B/F * x**n
示例7: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def _eval_apply(self, arg, base=None, **fixme):
if base is not None:
base = Basic.sympify(base)
if not isinstance(base, Basic.Exp1):
return self(arg)/self(base)
arg = Basic.sympify(arg)
if isinstance(arg, Basic.Number):
if isinstance(arg, Basic.Zero):
return S.NegativeInfinity
elif isinstance(arg, Basic.One):
return S.Zero
elif isinstance(arg, Basic.Infinity):
return S.Infinity
elif isinstance(arg, Basic.NegativeInfinity):
return S.Infinity
elif isinstance(arg, Basic.NaN):
return S.NaN
elif arg.is_negative:
return S.Pi * S.ImaginaryUnit + self(-arg)
elif isinstance(arg, Basic.Exp1):
return S.One
#this doesn't work due to caching: :(
#elif isinstance(arg, exp) and arg[0].is_real:
#using this one instead:
elif isinstance(arg, exp):
return arg[0]
#this shouldn't happen automatically (see the issue 252):
#elif isinstance(arg, Basic.Pow):
# if isinstance(arg.exp, Basic.Number) or \
# isinstance(arg.exp, Basic.NumberSymbol) or arg.exp.is_number:
# return arg.exp * self(arg.base)
#elif isinstance(arg, Basic.Mul) and arg.is_real:
# return Basic.Add(*[self(a) for a in arg])
elif not isinstance(arg, Basic.Add):
coeff = arg.as_coefficient(S.ImaginaryUnit)
if coeff is not None:
if isinstance(coeff, Basic.Infinity):
return S.Infinity
elif isinstance(coeff, Basic.NegativeInfinity):
return S.Infinity
elif isinstance(coeff, Basic.Rational):
if coeff.is_nonnegative:
return S.Pi * S.ImaginaryUnit * S.Half + self(coeff)
else:
return -S.Pi * S.ImaginaryUnit * S.Half + self(-coeff)
示例8: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def _eval_apply(self, arg):
arg = Basic.sympify(arg)
if isinstance(arg, Basic.NaN):
return S.NaN
elif arg.is_real:
return arg
else:
if not isinstance(arg, Basic.Add):
arg = [arg]
included, reverted, excluded = [], [], []
for term in arg:
coeff = term.as_coefficient(S.ImaginaryUnit)
if coeff is not None:
if not coeff.is_real:
reverted.append(coeff)
elif not term.has(S.ImaginaryUnit) and term.is_real:
excluded.append(term)
else:
included.append(term)
if len(arg[:]) != len(included):
a, b, c = map(lambda xs: Basic.Add(*xs),
[included, reverted, excluded])
return self(a) - im(b) + c
示例9: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [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)
示例10: __div__
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def __div__(self, divisor):
"""
Create a new point where each coordinate in this point is
divided by factor.
"""
divisor = Basic.sympify(divisor)
return Point( [x/divisor for x in self] )
示例11: _eval_apply
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def _eval_apply(self, arg):
arg = Basic.sympify(arg)
if isinstance(arg, Basic.Number):
if isinstance(arg, Basic.NaN):
return S.NaN
elif isinstance(arg, Basic.Infinity):
return S.Infinity * S.ImaginaryUnit
elif isinstance(arg, Basic.NegativeInfinity):
return S.NegativeInfinity * S.ImaginaryUnit
elif isinstance(arg, Basic.Zero):
return S.Pi*S.ImaginaryUnit / 2
elif isinstance(arg, Basic.One):
return S.Zero
elif isinstance(arg, Basic.NegativeOne):
return S.Pi*S.ImaginaryUnit
else:
cst_table = {
S.Half : S.Pi/3,
-S.Half : 2*S.Pi/3,
S.Sqrt(2)/2 : S.Pi/4,
-S.Sqrt(2)/2 : 3*S.Pi/4,
1/S.Sqrt(2) : S.Pi/4,
-1/S.Sqrt(2) : 3*S.Pi/4,
S.Sqrt(3)/2 : S.Pi/6,
-S.Sqrt(3)/2 : 5*S.Pi/6,
}
if arg in cst_table:
return cst_table[arg]*S.ImaginaryUnit
示例12: __mul__
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def __mul__(self, factor):
"""
Create a new point where each coordinate in this point is
multiplied by factor.
"""
factor = Basic.sympify(factor)
return Point( [x*factor for x in self] )
示例13: taylor_term
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def taylor_term(self, n, x, *previous_terms):
if n == 0:
return S.Pi / 2 # FIX THIS
elif n < 0 or n % 2 == 0:
return S.Zero
else:
x = Basic.sympify(x)
return (-1)**((n+1)//2) * x**n / n
示例14: taylor_term
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def taylor_term(self, n, x, *previous_terms):
if n<0: return S.Zero
if n==0: return S.One
x = Basic.sympify(x)
if previous_terms:
p = previous_terms[-1]
if p is not None:
return p * x / n
return x**n/Basic.Factorial()(n)
示例15: __new__
# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
def __new__(self, c, r, n, **kwargs):
r = Basic.sympify(r)
if not isinstance(c, Point):
raise GeometryError("RegularPolygon.__new__ requires c to be a Point instance")
if not isinstance(r, Basic):
raise GeometryError("RegularPolygon.__new__ requires r to be a number or Basic instance")
if n < 3:
raise GeometryError("RegularPolygon.__new__ requires n >= 3")
obj = GeometryEntity.__new__(self, c, r, n, **kwargs)
return obj