I don't know why I haven't used sympy before. I think I looked into it around 10 years ago, and I didn't appreciate the potential at the time. From playing around with it today, it's a capable symbolic math library. The documentation is rich as well. I really like it!
https://www.sympy.org/en/index.html
1/n