Computor v1 is a simple secondary degree equation solver.
It takes as argument a string representing an equation of degree n.
The program then reduces the equation so that it is of the form:
It then solves the equation if the last non-null degree is lower or equal to two.
The input is a string representing a mathematical equation.
Examples of valid inputs :
X + 2 = 3
2 * (X + 2) = -3
(X + 2) * 2 = -5 -4*X
-X - 2 * X^0 = -3
-X - 2 * X^0 = -3 - 4*X
-X - 2 * X^0 -(-3 - 4*X) = 0
-X - 2 * X^0 *(-3 - 4*X) = 0
-X - 2 * X^0 * (+3 - 4*X) = 0
-X - 2 * X^0 - (-3 * 4*X) = 0
X - 4 + 2*X + 30 = -4*X
3 * X^0 + 2 * X^1 * (2 + 3 * X^1 - 2 * X) = -(32 + 2*X - X^2)
X^4 - 9.7 * X^3 + 3 + 4 + X^0 = - 3 * X^1 * X^3
12 + 2*X * 5*X + 5*X^1 = -2
12 + 2*X * (5*X + 5*X^1) = -2
(-3 + X - X^2)*(2 - 3*X) = 0
X^2 + 3 - (2*X^2 + X) = -3*X^0
(-1 -X)^2 = 0
(-1 + X)^2 = X^2
(3*X + 9) + (1 - X + 3*X^2)^3 = -X -X^3
(3*X + 9) + (- X + 3*X^2)^3 = -X -X^3
(3*X + 9) * (- X + 3*X^2)^3 = (-2*X^2 + 5)^4
(3.7*X + 9) / (- X + 3*X^2)^3 = 1 / (-X -X^3)
You need to have python 3 installed on your machine.
./computor [-h] [-r] [-t] [-v] [-n] input
Positional arguments (= required):
Argument | Description |
---|---|
input | The input string representing the equation to solve |
Optional arguments :
Short flag | Long flag | Description |
---|---|---|
-h | --help | Show help message |
-r | --human_readable | Present the solution in a more "reader-friendly" format (^0 and 1 * are excluded) |
-t | --tree | Allows for visualizing the solving tree in the terminal window. |
-v | --verbose | Prints out each calculation involved in reducing and solving the equation |
-n | --neg | Tries to solve for negative degrees (multiplying each element by the absolute value of the lowest degree) |
The base program (i.e. with no optional flags on) will output the reduced form of the equation, the polynomial degree and the solutions if the equation is solvable :
Reduced form : -7 * X^0 + 4 * X^1 + 3 * X^2 = 0
Polynomial degree : 2
Discriminant is strictly positive. The two real solutions are:
X1 = -2.3333333333333335
X2 = 1
In case the degree is higher than two, this program will still reduce the equation but not solve for it:
Reduced form : -3 * X^0 + 4 * X^1 + 3 * X^2 - 1 * X^3 = 0
Polynomial degree : 3
This equation is of a degree higher than 2. This algorithm is not built to solve it.
Note that this program solve second degree equation when discriminant is negative; printing out the complex solutions.