https://github.com/lcbx/calculus
a proof of concept library to handle derivation of mathematical expression in Python
https://github.com/lcbx/calculus
Last synced: about 1 month ago
JSON representation
a proof of concept library to handle derivation of mathematical expression in Python
- Host: GitHub
- URL: https://github.com/lcbx/calculus
- Owner: Lcbx
- Created: 2019-10-23T17:59:05.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-24T19:56:51.000Z (over 6 years ago)
- Last Synced: 2025-03-17T01:43:46.873Z (over 1 year ago)
- Language: Python
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Calculus
A simple and elegant way of calculating mathematical derivatives
Uses overloaded operators on a custom Var class to construct a mathematical expression tree.
Expressions can be evaluated, derived and simplified by manipulating said tree.
Supports addition, multiplication and partly exponents. Only about 80 effective Lines of code
Example :
``` python
a, b, c = Var(2.), Var(3.), Var(6.)
expr = a + b * c
print("a =", a.value, " b =", b.value, " c =", c.value, " and f =", expr,"=", expr.evaluate())
print("f'(a) =", expr.d(a), "=", expr.d(a).simplify(), "=", expr.d(a).evaluate()) # 1 + (0 * 3 + 6 * 0)
print("f'(b) =", expr.d(b), "=", expr.d(b).simplify(), "=", expr.d(b).evaluate()) # 0 + (0 * 3 + 6 * 1)
print("f'(c) =", expr.d(c), "=", expr.d(c).simplify(), "=", expr.d(c).evaluate()) # 0 + (1 * 3 + 6 * 0)
```
Result: