本文整理汇总了Python中sympy.Symbol.subs方法的典型用法代码示例。如果您正苦于以下问题:Python Symbol.subs方法的具体用法?Python Symbol.subs怎么用?Python Symbol.subs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Symbol
的用法示例。
在下文中一共展示了Symbol.subs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dict_set
# 需要导入模块: from sympy import Symbol [as 别名]
# 或者: from sympy.Symbol import subs [as 别名]
def test_dict_set():
x = Symbol('x')
a, b, c = map(Wild, 'abc')
f = 3*cos(4*x)
r = f.match(a*cos(b*x))
assert r == {a: 3, b: 4}
e = a/b*sin(b*x)
assert e.subs(r) == r[a]/r[b]*sin(r[b]*x)
assert e.subs(r) == 3*sin(4*x) / 4
s = set(r.items())
assert e.subs(s) == r[a]/r[b]*sin(r[b]*x)
assert e.subs(s) == 3*sin(4*x) / 4
assert e.subs(r) == r[a]/r[b]*sin(r[b]*x)
assert e.subs(r) == 3*sin(4*x) / 4
assert x.subs(Dict((x, 1))) == 1
示例2: test_issue_4680
# 需要导入模块: from sympy import Symbol [as 别名]
# 或者: from sympy.Symbol import subs [as 别名]
def test_issue_4680():
N = Symbol('N')
assert N.subs(dict(N=3)) == 3
示例3: test_issue_1581
# 需要导入模块: from sympy import Symbol [as 别名]
# 或者: from sympy.Symbol import subs [as 别名]
def test_issue_1581():
N = Symbol("N")
assert N.subs(dict(N=3)) == 3
示例4: Expr
# 需要导入模块: from sympy import Symbol [as 别名]
# 或者: from sympy.Symbol import subs [as 别名]
#.........这里部分代码省略.........
return Expr(-S.Infinity)
@staticmethod
def get_true():
return Expr(True)
@staticmethod
def get_false():
return Expr(False)
def __init__(self, val):
if not Expr.initialized:
Expr.initialized = True
Expr.init()
if isinstance(val, int) or isinstance(val, long):
self.expr = Integer(val)
elif isinstance(val, basestring):
self.expr = Symbol(val)
elif isinstance(val, bool) or isinstance(val, BooleanAtom):
self.expr = S.One if val else S.Zero
else:
assert isinstance(val, SymPyExpr) or isinstance(val, BooleanFunction) \
or (val == S.Infinity) or (val == -S.Infinity)
self.expr = val
def __str__(self):
return self.expr.__str__()
def __repr__(self):
r = self.__str__()
return r
def subs(self, expr_from, expr_to):
return Expr(self.expr.subs([(expr_from.expr, expr_to.expr)]))
def args(self):
return map(Expr, self.expr.args)
def sympy(self):
return self.expr
@staticmethod
def reduce_conditional(expr):
if isinstance(expr, And):
# And(x, y)
x, y = expr.args
# And(Or(a, b), y)
if isinstance(x, Or):
a, b = x.args
# And(Or(a, b), Or(c, d))
if isinstance(y, Or):
c, d = y.args
return [[a, c], [a, d], [b, c], [b, d]]
# And(Or(a, b), y)
red_args = map(reduce_contional, expr.args)
red_args = sum(red_args, [])
return red_args
elif isinstance(expr.expr, Or):
red_args = map(reduce_contional, expr.args)
return red_args
return expr
@staticmethod
def minmax_args(expr, ty):
if isinstance(expr, ty):