This project is the direct continuation of computorv1.
Computor v2 is a program that works like an advanced calculator. It can evaluate complex expressions, solve equations, store variables and functions... It has been written as part of the 42 school curriculum.
My motivation was drastically reduced during the project due to the few experience points gained for the time invested. 42, my programming school, considers that a simple network project completed in a few hours yields 22450 XP compared to 9450 XP for Computor v2. This project took me hundreds of hours... I learned what I wanted. This is why I did not want to finish all the features on the optimizer. However, I left the document that I had written on the rules to apply if necessary. GLHF 🙂
- ⌨️ A CLI that allows the user to interact with the program
- 🧮 An evaluator with support for:
- 📊 Complex numbers
- 📐 Matrices
- 📏 Arithmetic operations
- 💾 Functions and variables assignment
- 📈 Equations solving of degree up to 2
- 📜 Auto-completion for functions and variables names
- 💽 Commands history
- 🧱 Built-in constants:
e
- Euler's numberi
- Imaginary unitinf
- Infinitypi
- Pitau
- Tau
- 🧱 Built-in functions:
abs
- Absolute valuecos
- Cosineexp
- Exponentialidentity
- Identity matrixinv
- Inverse matrixlog
- Natural logarithmones
- Matrix of onessin
- Sinesqrt
- Square roottan
- Tangenttranspose
- Transpose matrixzeros
- Matrix of zeros
- ⌨️ Built-in commands with prefix
%
:clear
- 🧹 Clear the screendelete
- 🗑️ Delete a variable or a functionhelp
- 📚 Display the list of available commands or the help of a specific commandshow
- 📜 Display all stored functions and/or variables
- 📈 Functions with multiple arguments
- Expressions evaluation can be done without using
= ?
at the end of the line. - Support for digits and underscores in function and variable names
- Matrix exponentiation use the exponentiation by squaring algorithm for better performance
- The commands history is saved in a file to be persistent between sessions
- The program can be run in a non-interactive mode by providing a file as a shell redirection like this:
./computorv2 < file.txt
Python 3.9.2 or higher is recommended to run the program. An additional package named PLY is also required. You can install it by running the following command:
pip3 install -r requirements.txt
To use the program, run the following command:
make run
Then, you can enter your expressions in the prompt that appears.
- 🔬 Some examples are available in the example directory.
⚠️ Implicit multiplication has a higher priority than every other operation, so:2x ^ 3
is evaluated as(2 * x) ^ 3
2 * x ^ 3
is evaluated as2 * (x ^ 3)
- 💡 You can use the
%help
command to display the list of available commands. - 💡 You can use the
up
anddown
arrow keys to navigate through the commands history. - 💡 You can exit the program by pressing
Ctrl + D
.
The source code is covered by unit tests written using the unittest framework provided by Python. There are located in the test directory. The CLI is the only part of the program that is not covered by tests.
To run the unit tests, you can use the following command:
make test
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.