本文整理汇总了Python中sympy.Rational.match方法的典型用法代码示例。如果您正苦于以下问题:Python Rational.match方法的具体用法?Python Rational.match怎么用?Python Rational.match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Rational
的用法示例。
在下文中一共展示了Rational.match方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_symbol
# 需要导入模块: from sympy import Rational [as 别名]
# 或者: from sympy.Rational import match [as 别名]
def test_symbol():
x = Symbol('x')
a,b,c,p,q = map(Wild, 'abcpq')
e = x
assert e.match(x) == {}
assert e.match(a) == {a: x}
e = Rational(5)
assert e.match(c) == {c: 5}
assert e.match(e) == {}
assert e.match(e+1) == None
示例2: test_behavior2
# 需要导入模块: from sympy import Rational [as 别名]
# 或者: from sympy.Rational import match [as 别名]
def test_behavior2():
x = Symbol('x')
p = Wild('p')
e = Rational(6)
assert e.match(2*p) == {p: 3}
e = 3*x + 3 + 6/x
a = Wild('a', exclude = [x])
assert e.expand().match(a*x**2 + a*x + 2*a) == None
assert e.expand().match(p*x**2 + p*x + 2*p) == {p: 3/x}
示例3: test_match_exclude
# 需要导入模块: from sympy import Rational [as 别名]
# 或者: from sympy.Rational import match [as 别名]
def test_match_exclude():
x = Symbol('x')
y = Symbol('y')
p = Wild("p")
q = Wild("q")
r = Wild("r")
e = Rational(6)
assert e.match(2*p) == {p: 3}
e = 3/(4*x + 5)
assert e.match(3/(p*x + q)) == {p: 4, q: 5}
e = 3/(4*x + 5)
assert e.match(p/(q*x + r)) == {p: 3, q: 4, r: 5}
e = 2/(x + 1)
assert e.match(p/(q*x + r)) == {p: 2, q: 1, r: 1}
e = 1/(x + 1)
assert e.match(p/(q*x + r)) == {p: 1, q: 1, r: 1}
e = 4*x + 5
assert e.match(p*x + q) == {p: 4, q: 5}
e = 4*x + 5*y + 6
assert e.match(p*x + q*y + r) == {p: 4, q: 5, r: 6}
a = Wild('a', exclude=[x])
e = 3*x
assert e.match(p*x) == {p: 3}
assert e.match(a*x) == {a: 3}
e = 3*x**2
assert e.match(p*x) == {p: 3*x}
assert e.match(a*x) is None
e = 3*x + 3 + 6/x
assert e.match(p*x**2 + p*x + 2*p) == {p: 3/x}
assert e.match(a*x**2 + a*x + 2*a) is None