Last active
November 3, 2023 06:29
-
-
Save simonLeary42/96311225259111f7dd5e2c46d78eba2c to your computer and use it in GitHub Desktop.
simplify math expressions with sympy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sympy | |
import readline # allow arrow keys while typing inputs | |
while True: | |
expression = input("expression: ") | |
unknowns = input("unknowns comma delimited: ") | |
exec_str = f"{unknowns} = sympy.symbols(\"{unknowns}\")" | |
print(f"> {exec_str}") | |
exec(exec_str) | |
exec_str = f"expr = {expression}" | |
print(f"> {exec_str}") | |
exec(exec_str) | |
print(f"> expr.simplify()") | |
print(expr.simplify()) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
user input was on the first 2 lines, nowhere else