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

Match arbitrary function #62

Open
sidmani opened this issue Jan 24, 2020 · 4 comments
Open

Match arbitrary function #62

sidmani opened this issue Jan 24, 2020 · 4 comments

Comments

@sidmani
Copy link

sidmani commented Jan 24, 2020

Is there any way to match a function with a certain number of arguments? Suppose I've defined a binary function sum, is there a way to create a pattern f(a, b) that matches sum(x, y)?

@hbarthels
Copy link
Contributor

hbarthels commented Jan 24, 2020

You mean a pattern where f is a variable that matches a function symbol, like f_[a_, b_] in Mathematica? Unfortunately, MatchPy doesn't support that yet.

If the functions you are considering are not actually arbitrary, that is, if you have a finite number of them that is known by the time you construct your patterns, you could achieve something similar by constructing one pattern for each function. With many-to-one matching, the performance should still be ok.

@sidmani
Copy link
Author

sidmani commented Jan 24, 2020

Unfortunately the functions are completely arbitrary. Do you know how I could implement that in MatchPy? How difficult would it be?

@hbarthels
Copy link
Contributor

@wheerd should be able to give you a better answer than me. From the algorithmic point of view, right now I don't see a reason why it should be impossible. I just don't have a good feeling for how much work it would be, and if it would integrate nicely into what we already have.

@wheerd
Copy link
Collaborator

wheerd commented Jan 28, 2020

Integrating it into the one-to-one matching would be relatively easy, but I don't know about the many-to-one case. My gut feeling is that would be complicated if you want to cover all the and iterate over all possible matches. I can't give much more pointers as I haven't worked on this in three years and my knowledge got a bit rusty.

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

No branches or pull requests

3 participants