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

One-to-one matching: symbols with variable_name do not work in commutative functions #63

Open
hbarthels opened this issue Jul 20, 2020 · 2 comments
Labels

Comments

@hbarthels
Copy link
Contributor

In one-to-one matching, symbols that have a variable_name do not work in commutative functions. They seem to work correctly in many-to-one matching. Example:

from matchpy import Operation, Symbol, Arity, Pattern, match, ManyToOneMatcher

f = Operation.new('f', Arity.binary, commutative=True)
a_x = Symbol('a', variable_name='x')
a = Symbol('a')
b = Symbol('b')

subject = f(a, b)
pattern = Pattern(f(a_x, b))

print(list(match(subject, pattern)))

matcher = ManyToOneMatcher(pattern)
print(list(matcher.match(subject)))

This results in

[]
[(Pattern(f(a: x, b)), {'x': Symbol('a')})]

but it should result in

[{'x': Symbol('a')}]
[(Pattern(f(a: x, b)), {'x': Symbol('a')})]

So far, we don't have any tests that verify this functionality. Once it is fixed, we should add some.

@hbarthels hbarthels added the bug label Jul 20, 2020
@samithkavishke
Copy link

commutative = True part is not yet handled, even

f = Operation.new('f', Arity.variadic, commutative=True)
a_x = Symbol('a', variable_name='x')
a = Symbol('a')

subject = f(a)
pattern = Pattern(f(a_x))

print(list(match(subject, pattern)))

gives the answer of []

@samithkavishke
Copy link

This ManyToOneMathcer has entirely different way to handle this situation as it uses a separate class defined for this, we need to reform the OneToOne matcher in a same way to ensure this functionality. I think the current implementation is not easy to change and take the desired outcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants