当前位置: 首页>>代码示例>>Python>>正文


Python Symbol.subs方法代码示例

本文整理汇总了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
开发者ID:malikdiarra,项目名称:sympy,代码行数:19,代码来源:test_subs.py

示例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
开发者ID:KsenijaM,项目名称:sympy,代码行数:5,代码来源:test_subs.py

示例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
开发者ID:catchmrbharath,项目名称:sympy,代码行数:5,代码来源:test_subs.py

示例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):
开发者ID:AlisaMaas,项目名称:llvm-sage,代码行数:70,代码来源:expr.py


注:本文中的sympy.Symbol.subs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。