https://github.com/kdkasad/eqnp
Mathematical derivative calculator and simplification engine
https://github.com/kdkasad/eqnp
calculator calculus parser python3
Last synced: 3 months ago
JSON representation
Mathematical derivative calculator and simplification engine
- Host: GitHub
- URL: https://github.com/kdkasad/eqnp
- Owner: kdkasad
- License: other
- Created: 2022-02-17T18:17:14.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-18T21:47:51.000Z (over 2 years ago)
- Last Synced: 2025-02-03T04:11:55.627Z (3 months ago)
- Topics: calculator, calculus, parser, python3
- Language: Python
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eqnp
A simple symbolic derivative calculator and simplification engine.## Goal
The goal of eqnp is to be a program which can parse expressions (and maybe
equations at some point) and can manipulate them in various ways. This might
eventually include:* Simplifying
* Differentiating (finding derivatives)
* Integrating (finding integrals)
* Solving (isolating variables)In addition, this is a project that I'm creating only from my own knowledge. My
goal is to not use any resources relating to the actual function of eqnp.
(Python documentation is acceptable, of course.)## Install
eqnp is a Python package, so it can be installed in multiple ways.
### Install directly from repository
Run the following command to download and install eqnp.
```sh
$ python -m pip install git+https://github.com/kdkasad/eqnp
```### Clone repository
Another method is to clone the repository first, then install from the local
copy.```sh
$ git clone https://github.com/kdkasad/eqnp
$ cd eqnp
$ python -m pip install .
```## Usage
Import the `parse_expression()` function from `eqnp.parser`:
```python
from eqnp.parser import parse_expression# or
from eqnp import *
```Then run `parse_expression(...)`, passing in a string which is an expression.
[See below](#expression-string-syntax) for syntax.### Example
```python
In [1]: import eqnpIn [2]: function = eqnp.parse_expression(' 1 / x^2 ')
In [3]: print(function)
Out[3]: Division(1, Exponent(x, 2))In [4]: derivative = function.differentiate(respectTo='x')
In [5]: print(derivative)
Out[5]: Division(Subtraction(Multiplication(0, Exponent(x, 2)), Multiplication(1, Multiplication(Multiplication(2, Exponent(x, Subtraction(2, 1))), 1))), Exponent(Exponent(x, 2), 2))In [6]: derivative = derivative.simplify_fully()
In [7]: print(derivative)
Out[7]: Division(Subtraction(0, Multiplication(2, x)), Exponent(x, 4))# Out[7] is equivalent to '(-2 * x) / (x ^ 4)'
```### Expression string syntax
Currently, the following operators, functions, and other syntactical structures
are supported (`...` means an expression):| Syntax | Meaning |
| --- | --- |
| `... + ...` | Addition -- Must have operands on either side |
| `... - ...` | Subtraction -- Must have operands on either side |
| `... * ...` | Multiplication -- Must have operands on either side |
| `... / ...` | Division -- Must have operands on either side |
| `(...)` | Grouping -- used to group operations to enforce a certain order |
| `\|...\|` | Absolute value -- same as `abs(...)` |
| `abs(...)` | Absolute value |
| `sin(...)` | Sine function |
| `cos(...)` | Cosine function |
| `tan(...)` | Tangent function |
| `csc(...)` | Cosecant function |
| `sec(...)` | Secant function |
| `cot(...)` | Cotangent function |
| `-n` | Negation -- `n` must be a constant number |> Note: The absolute value bars do not have to be escaped. They're only that way in the markdown file because the table syntax uses pipe characters.
## To do
There are still a lot of features that I want to implement. Some are listed as
`# TODO:` comments in the source code, but I'll put a list here too:* Pull all constants out of nested multiplication expressions
* Flip negative exponents in fractions to opposite side
* Add inverse trigonometric functions
* Implement integration