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

FreeQ equivalent in MatchPy? #70

Open
Upabjojr opened this issue Jan 14, 2021 · 1 comment
Open

FreeQ equivalent in MatchPy? #70

Upabjojr opened this issue Jan 14, 2021 · 1 comment

Comments

@Upabjojr
Copy link
Contributor

Mathematica has FreeQ to test whether an expression contains a symbol. This is very useful in pattern matching for equations as you can specify that, for example, in a * x + b == 0 the variables a and b should not contain the variable x.

In SymPy we are currently using things like CustomConstraint(lambda a, x: not a.has(x)), where a.has(x) is a SymPy expression that tells you if x is contained in the expression tree of a.

Would it make sense to add an optimized FreeQ-like tester that checks whether the variable is contained in the expression during the matching iteration of MatchPy?

@hbarthels
Copy link
Contributor

I think that such a constraint is perhaps too application specific, so I wouldn't add it unless we get more request for it.

To improve this constraint in SymPy and avoid the lambda function, you could implement a subclass of the Constraint class. Is that an acceptable solution for you?

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

No branches or pull requests

2 participants