Skip to content

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

Description

@hbarthels

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions