This commit is contained in:
gbrochar 2023-08-09 07:48:22 +02:00
parent c0de467076
commit c35996c0d4
1 changed files with 45 additions and 1 deletions

View File

@ -1,5 +1,49 @@
use super::*; use super::*;
pub fn solve(equation: Vec<GaussianRational>) -> Vec<GaussianRational> { fn zero() -> GaussianRational {
GaussianRational::new(Rational::new(0, 1), Rational::new(0, 1))
}
fn minus_one() -> GaussianRational {
GaussianRational::new(Rational::new(-1, 1), Rational::new(0, 1))
}
fn degree_zero(equation: Vec<GaussianRational>) {
println!("Polynomial degree: 0");
if equation[0] == zero() {
println!("Every real number is a solution ! Personally, I'd rather say that this equation is valid.")
} else {
println!("This equation has no solution ! Personally, I'd rather say that this equation is invalid.")
}
}
fn degree_one(equation: Vec<GaussianRational>) {
println!("Polynomial degree: 1");
let x = minus_one() * equation[0] / equation[1];
println!("The solution is");
println!("{:?}", x);
}
/*
fn degree_two(equation: Vec<GaussianRational>) {
println!("Polynomial degree: 2");
let delta = equation[1] * equation[1] + 4 * equation[0] * equation[0];
}
*/
pub fn solve(mut equation: Vec<GaussianRational>) -> Vec<GaussianRational> {
for i in (1..equation.len()).rev() {
if equation[i] == zero() {
equation.pop();
}
}
crate::pretty(&equation);
match equation.len() {
0 => unreachable!(),
1 => degree_zero(equation),
2 => degree_one(equation),
//3 => degree_two(equation),
_ => println!("Polynomial of degree greater than 2 detected, I can't solve that !"),
}
vec![] vec![]
} }