This is a script written in pure Rust that solves for roots in a quadratic equation x^2+px+q=0 using the Vieta's theorem (sum of the roots = -p, product of the roots = q) with focus on efficiency
It is a CLI app, so download the binary file for your platform from "Releases" and run in it in your terminal with p and q values for that quadratic equation as arguments.
For example, let's say you got the following equation: x^2-28+96=0, this is how you'd solve for roots using this script:
./vietta-solver -28 96Change vietta-solver to name of the executable, so if you are on Windows for example, the command would be like this:
./vietta-solver.exe -28 96- What is Vieta's theorem?
- Basically, it states that in a quadratic equation like
x^2+px+q=0, the sum of the two roots equals negativep, and their product equalsq:x1+x2=-p; x1*x2=q
- Basically, it states that in a quadratic equation like
- Why it is Vietta and not Vieta solver?
- I did not know that "Vieta" is written with one t
- Why did you build it?
- In my 9th grade, Vieta's theorem was used very often, and it was too hard for me to guess numbers that produce a specific product and a specific sum as it is guesswork and not concise calculation. It turned out to be an amazing side project to practice my problem solving and Rust skills. This is quite a niche theorem, i could not find it on Wikipedia. You can find out more about it here
- Will this work if there is a coefficient for
x^2?- No.
Firstly, you need to ensure that Rust toolchain is installed on your system, you can install it with rustup
Clone this repository and cd into it, run cargo build --release in the terminal from the repository folder. You will find the binary in target/release directory
This script has some technical limitations:
- Only integers are allowed, no floating point numbers
- Numbers flowing through the app can only be 32 bit integers in size (between -2147483648 and 2147483647)
- If you need to process bigger numbers, you can do so by editing the source code, simply replace
i32withi64ori128and compile the crate again
- If you need to process bigger numbers, you can do so by editing the source code, simply replace
- For now, this is a single-threaded application, it will utilize just one core of your CPU