本文整理汇总了Python中expr.Expr.matches方法的典型用法代码示例。如果您正苦于以下问题:Python Expr.matches方法的具体用法?Python Expr.matches怎么用?Python Expr.matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类expr.Expr
的用法示例。
在下文中一共展示了Expr.matches方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: matches
# 需要导入模块: from expr import Expr [as 别名]
# 或者: from expr.Expr import matches [as 别名]
def matches(self, expr, repl_dict={}, old=False):
expr = _sympify(expr)
# special case, pattern = 1 and expr.exp can match to 0
if expr is S.One:
d = repl_dict.copy()
d = self.exp.matches(S.Zero, d)
if d is not None:
return d
b, e = expr.as_base_exp()
# special case number
sb, se = self.as_base_exp()
if sb.is_Symbol and se.is_Integer and expr:
if e.is_rational:
return sb.matches(b**(e/se), repl_dict)
return sb.matches(expr**(1/se), repl_dict)
d = repl_dict.copy()
d = self.base.matches(b, d)
if d is None:
return None
d = self.exp.xreplace(d).matches(e, d)
if d is None:
return Expr.matches(self, expr, repl_dict)
return d
示例2: matches
# 需要导入模块: from expr import Expr [as 别名]
# 或者: from expr.Expr import matches [as 别名]
def matches(self, expr, repl_dict={}, evaluate=False):
if self in repl_dict:
if repl_dict[self] == expr:
return repl_dict
elif isinstance(expr, Derivative):
if len(expr.variables) == len(self.variables):
return Expr.matches(self, expr, repl_dict, evaluate)
示例3: matches
# 需要导入模块: from expr import Expr [as 别名]
# 或者: from expr.Expr import matches [as 别名]
def matches(self, expr, repl_dict={}):
expr = _sympify(expr)
b, e = expr.as_base_exp()
# special case, pattern = 1 and expr.exp can match to 0
if expr is S.One:
d = repl_dict.copy()
d = self.exp.matches(S.Zero, d)
if d is not None:
return d
d = repl_dict.copy()
d = self.base.matches(b, d)
if d is None:
return None
d = self.exp.xreplace(d).matches(e, d)
if d is None:
return Expr.matches(self, expr, repl_dict)
return d
示例4: matches
# 需要导入模块: from expr import Expr [as 别名]
# 或者: from expr.Expr import matches [as 别名]
def matches(self, expr, repl_dict={}, evaluate=False):
# this method needs a cleanup.
if self in repl_dict:
if repl_dict[self] == expr:
return repl_dict
else:
return None
if isinstance(expr, Derivative):
if len(expr.symbols) == len(self.symbols):
#print "MAYBE:",self, expr, repl_dict, evaluate
return Expr.matches(self, expr, repl_dict, evaluate)
#print "NONE:",self, expr, repl_dict, evaluate
return None
#print self, expr, repl_dict, evaluate
stop
if self.nargs is not None:
if self.nargs != expr.nargs:
return None
repl_dict = repl_dict.copy()
repl_dict[self] = expr
return repl_dict
示例5: matches
# 需要导入模块: from expr import Expr [as 别名]
# 或者: from expr.Expr import matches [as 别名]
def matches(self, expr, repl_dict={}, evaluate=False):
if evaluate:
return self.subs(repl_dict).matches(expr, repl_dict)
expr = _sympify(expr)
b, e = expr.as_base_exp()
# special case, pattern = 1 and expr.exp can match to 0
if expr is S.One:
d = repl_dict.copy()
d = self.exp.matches(S.Zero, d)
if d is not None:
return d
d = repl_dict.copy()
d = self.base.matches(b, d)
if d is None:
return None
d = self.exp.subs(d).matches(e, d)
if d is None:
return Expr.matches(self, expr, repl_dict, evaluate)
return d