I needed a way to tell cse not to create substitutions containing a subset of symbols.
I've implemented this functionality by adding a keyword argument ignore to cse.
I found this to be useful e.g. when doing code-generation where a set of variables may change much more often than others. If you don't include the frequently changing variables in the common subexpressions, then the substitutions stay valid over e.g. iterations in numerical code.
Let me know what you think.
Add kwarg 'ignore' to cse() for disqualification.
cc @cdsousa & @smichr if interested (based on git blame).
It would be better to use AssertionError here. In the loop below you can just write assert y not in sub.free_symbols, "Sub-expressions containing y must be ignored". You could also rewrite this as
assert y not in sub.free_symbols, "Sub-expressions containing y must be ignored"
assert any(y in sub.free_symbols for symb, sub in subst1), "cse failed to identify any term with y"
Just the one comment. +1 otherwise. Feel free to request reviews (using the GitHub feature) from me for codegen related PRs.
Make test of cse with 'ignore' more terse