Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed "old" argument for match/matches #141

Merged
merged 1 commit into from Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions sympy/core/add.py
Expand Up @@ -363,8 +363,8 @@ def _matches_simple(self, expr, repl_dict):
return terms[0].matches(expr - coeff, repl_dict)
return

def matches(self, expr, repl_dict={}, old=False):
return AssocOp._matches_commutative(self, expr, repl_dict, old)
def matches(self, expr, repl_dict={}):
return AssocOp._matches_commutative(self, expr, repl_dict)

@staticmethod
def _combine_inverse(lhs, rhs):
Expand Down
21 changes: 6 additions & 15 deletions sympy/core/basic.py
Expand Up @@ -1379,7 +1379,7 @@ def count(self, query):
query = _make_find_query(query)
return sum(bool(query(sub)) for sub in preorder_traversal(self))

def matches(self, expr, repl_dict={}, old=False):
def matches(self, expr, repl_dict={}):
"""Helper method for match() that looks for a match between Wild
symbols in self and expressions in expr.

Expand Down Expand Up @@ -1408,12 +1408,12 @@ def matches(self, expr, repl_dict={}, old=False):
for arg, other_arg in zip(self.args, expr.args):
if arg == other_arg:
continue
d = arg.xreplace(d).matches(other_arg, d, old=old)
d = arg.xreplace(d).matches(other_arg, d)
if d is None:
return
return d

def match(self, pattern, old=False):
def match(self, pattern):
"""Pattern matching.

Wild symbols match all.
Expand Down Expand Up @@ -1441,15 +1441,6 @@ def match(self, pattern, old=False):
True
>>> (p*q**r).xreplace(e.match(p*q**r))
4*x**2

The ``old`` flag will give the old-style pattern matching where
expressions and patterns are essentially solved to give the
match. Both of the following give None unless ``old=True``:

>>> (x - 2).match(p - x, old=True)
{p_: 2*x - 2}
>>> (2/x).match(p*x, old=True)
{p_: 2/x**2}
"""
from sympy import signsimp
pattern = sympify(pattern)
Expand All @@ -1458,9 +1449,9 @@ def match(self, pattern, old=False):
# if we still have the same relationship between the types of
# input, then use the sign simplified forms
if (pattern.func == self.func) and (s.func == p.func):
rv = p.matches(s, old=old)
rv = p.matches(s)
else:
rv = pattern.matches(self, old=old)
rv = pattern.matches(self)
return rv

def count_ops(self, visual=None):
Expand Down Expand Up @@ -1590,7 +1581,7 @@ class Atom(Basic):

__slots__ = []

def matches(self, expr, repl_dict={}, old=False):
def matches(self, expr, repl_dict={}):
if self == expr:
return repl_dict

Expand Down
2 changes: 1 addition & 1 deletion sympy/core/function.py
Expand Up @@ -773,7 +773,7 @@ def __init__(cls, name, **assumptions):
nargs = FiniteSet(*nargs)
cls.nargs = nargs

def matches(self, expr, repl_dict={}, old=False):
def matches(self, expr, repl_dict={}):
if not isinstance(expr, (AppliedUndef, Function)):
return
if len(expr.args) not in self.nargs:
Expand Down
6 changes: 3 additions & 3 deletions sympy/core/mul.py
Expand Up @@ -812,10 +812,10 @@ def _matches_simple(self, expr, repl_dict):
return terms[0].matches(newexpr, repl_dict)
return

def matches(self, expr, repl_dict={}, old=False):
def matches(self, expr, repl_dict={}):
expr = sympify(expr)
if self.is_commutative and expr.is_commutative:
return AssocOp._matches_commutative(self, expr, repl_dict, old)
return AssocOp._matches_commutative(self, expr, repl_dict)
elif self.is_commutative is not expr.is_commutative:
return
c1, nc1 = self.args_cnc()
Expand All @@ -826,7 +826,7 @@ def matches(self, expr, repl_dict={}, old=False):
c2 = [1]
a = self.func(*c1)
if isinstance(a, AssocOp):
repl_dict = a._matches_commutative(self.func(*c2), repl_dict, old)
repl_dict = a._matches_commutative(self.func(*c2), repl_dict)
else:
repl_dict = a.matches(self.func(*c2), repl_dict)
if repl_dict:
Expand Down
4 changes: 2 additions & 2 deletions sympy/core/operations.py
Expand Up @@ -125,7 +125,7 @@ def flatten(cls, seq):
# c_part, nc_part, order_symbols
return [], new_seq, None

def _matches_commutative(self, expr, repl_dict={}, old=False):
def _matches_commutative(self, expr, repl_dict={}):
"""
Matches Add/Mul "pattern" to an expression "expr".

Expand Down Expand Up @@ -200,7 +200,7 @@ def _matches_commutative(self, expr, repl_dict={}, old=False):
return
newpattern = self.func(*wild_part)
newexpr = self._combine_inverse(expr, exact)
if not old and (expr.is_Add or expr.is_Mul):
if expr.is_Add or expr.is_Mul:
if newexpr.count_ops() > expr.count_ops():
return
return newpattern.matches(newexpr, repl_dict)
Expand Down
8 changes: 4 additions & 4 deletions sympy/core/power.py
Expand Up @@ -1077,7 +1077,7 @@ def as_numer_denom(self):
exp = -exp
return self.func(n, exp), self.func(d, exp)

def matches(self, expr, repl_dict={}, old=False):
def matches(self, expr, repl_dict={}):
expr = _sympify(expr)

# special case, pattern = 1 and expr.exp can match to 0
Expand All @@ -1101,13 +1101,13 @@ def matches(self, expr, repl_dict={}, old=False):
return sb.matches(expr**(1/se), repl_dict)

d = repl_dict.copy()
d = self.base.matches(b, d, old=old)
d = self.base.matches(b, d)
if d is None:
return

d = self.exp.xreplace(d).matches(e, d, old=old)
d = self.exp.xreplace(d).matches(e, d)
if d is None:
return Expr.matches(self, expr, repl_dict, old=old)
return Expr.matches(self, expr, repl_dict)
return d

def _eval_nseries(self, x, n, logx):
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/symbol.py
Expand Up @@ -296,7 +296,7 @@ def _hashable_content(self):
return super(Wild, self)._hashable_content() + (self.exclude, self.properties)

# TODO add check against another Wild
def matches(self, expr, repl_dict={}, old=False):
def matches(self, expr, repl_dict={}):
if any(expr.has(x) for x in self.exclude):
return
if any(not f(expr) for f in self.properties):
Expand Down
7 changes: 5 additions & 2 deletions sympy/integrals/meijerint.py
Expand Up @@ -112,6 +112,9 @@ def eval(cls, arg):
add((t**a - b**a)/(t - b), [0, a], [], [0, a], [], t/b,
b**(a - 1)*sin(a*pi)/pi)

add((z**a - b**a)/(z - b), [0, a], [], [0, a], [], z/b,
b**(a - 1)*sin(a*pi)/pi)

# 12
def A1(r, sign, nu):
return pi**(-S(1)/2)*(-sign*nu/2)**(1 - 2*r)
Expand Down Expand Up @@ -139,7 +142,7 @@ def tmpadd(r, sgn):
# (those after look obscure)

# Section 8.4.3
add(exp(polar_lift(-1)*t), [], [], [0], [])
add(exp(t), [], [], [0], [], t/polar_lift(-1))

# TODO can do sin^n, sinh^n by expansion ... where?
# 8.4.4 (hyperbolic functions)
Expand Down Expand Up @@ -1441,7 +1444,7 @@ def _rewrite_single(f, x, recursive=True):
if t in _lookup_table:
l = _lookup_table[t]
for formula, terms, cond, hint in l:
subs = f.match(formula, old=True)
subs = f.match(formula)
if subs:
subs_ = {}
for fro, to in subs.items():
Expand Down