Open Upabjojr opened 3 years ago
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?
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 variablesa
andb
should not contain the variablex
.In SymPy we are currently using things like
CustomConstraint(lambda a, x: not a.has(x))
, wherea.has(x)
is a SymPy expression that tells you ifx
is contained in the expression tree ofa
.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?