Skip to content

Instantly share code, notes, and snippets.

@Upabjojr
Created September 13, 2019 22:04
Show Gist options
  • Save Upabjojr/f866ce14d3eee6b0dd5f28c340785814 to your computer and use it in GitHub Desktop.
Save Upabjojr/f866ce14d3eee6b0dd5f28c340785814 to your computer and use it in GitHub Desktop.
# Replace with date and time the code was generated:
from generated_tempdir_2019_09_13_232810.generated_part000000 import match_root
from sympy import *
x = symbols("x")
def check_constraints(subst, constraints):
for cons in constraints:
ret = cons(**{k: v for k, v in subst.items() if k in cons.__code__.co_varnames})
if not ret:
return False
return True
expr_list = [
Integral(x, x),
Integral(x**2, x),
Integral(1/(1+x), x),
Integral(1/x, x),
Integral(sin(x), x),
Integral(sin(x)*cos(x), x),
]
for expr in expr_list:
g = match_root(expr)
ret = list(g)
results = [repl(**subst) for repl, subst, constraints in ret if check_constraints(subst, constraints)]
clean = [i for i in results if not isinstance(i, Function)]
pprint(expr)
pprint(clean)
print("===========================")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment