Math Interpreter is a Python-based command-line tool designed to evaluate, plot, and manage mathematical expressions. It provides a rich set of features for defining expressions, evaluating them at specific points, plotting graphs, and saving/loading expressions from files. The project is built with modularity and extensibility in mind, making it easy to add new features or adapt it to specific needs.
- Expression Management: Define and store mathematical expressions with variables.
- Evaluation: Evaluate expressions at specific points.
- Plotting: Generate 2D and 3D plots for single-variable and two-variable expressions.
- File Operations: Save and load expressions to/from files.
- Rich UI: Interactive command-line interface with help and error handling.
- Python 3.8 or higher
pip(Python package manager)
-
Clone the repository:
git clone https://github.com/your-username/math-interpreter.git cd math-interpreter -
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python src/ui.py
Run the application and interact with the command-line interface. The UI provides a help menu (h) and a quit option (q).
python src/ui.pyType h to display the list of available commands and their usage.
| Command | Description | Example |
|---|---|---|
GET |
Define a new expression. | GET f = sin(x) + cos(x) |
EVAL |
Evaluate an expression at specific points. | EVAL f at (3.14) |
PLOT |
Plot an expression with optional ranges. | PLOT f in (-100, 100, -50, 50) |
LOAD |
Load expressions from a file. | LOAD expressions.math |
SAVE |
Save an expression to a file with optional ranges. | SAVE f in (-100, 100, -50, 50) |
> GET f = sin(x) + cos(x)
Expression 'f' saved successfully
> EVAL f at (3.14)
Evaluation result: 0.0
> PLOT f in (-10, 10)
Plot created for 'f'
> SAVE f in (-10, 10)
Plot saved for 'f'
> LOAD expressions.math
Expressions loaded from 'expressions.math'
math-interpreter/
├── src/
│ ├── command/
│ │ ├── processor.py # Command processing logic
│ │ ├── handler.py # Command handlers for GET, EVAL, PLOT, etc.
│ ├── core/
│ │ ├── parser.py # Expression parsing logic
│ │ ├── evaluator.py # Expression evaluation logic
│ │ ├── expression.py # Expression classes (e.g., Addition, Multiplication)
│ │ ├── context.py # Context for variables and functions
│ │ ├── tokenizer.py # Tokenizer for parsing expressions
│ ├── expression/
│ │ ├── base.py # Base class for expressions
│ │ ├── repository.py # Repository for managing expressions
│ ├── plotter/
│ │ ├── factory.py # Factory for creating plotters
│ │ ├── strategy.py # Plotting strategies (2D, 3D)
│ ├── ui.py # Command-line user interface
├── README.md # Project documentation
├── requirements.txt # Python dependencies
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes and push them to your fork.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.