fix complex sign operation

This commit is contained in:
hugogogo
2026-05-15 02:18:50 +02:00
parent b185647d2b
commit f25291f12f
5 changed files with 232 additions and 182 deletions

332
tester.sh
View File

@@ -50,6 +50,7 @@ while [[ "$#" -gt 0 ]]; do
--skip-solution) SKIP_SOLUTION=true ;;
--run-only) RUN_ONLY=true ;;
-b) FLAGS="$FLAGS -b" ;; # append -b to FLAGS
-d) FLAGS="$FLAGS -d" ;; # append -d to FLAGS
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
@@ -197,183 +198,192 @@ The polynomial degree is strictly greater than 2, I can't solve."
run_test \
"9. degree 2" \
"3x² + 2x -7x¹ = x" "\
Reduced form: 7 * x^0 + 1 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly negative, the two complex solutions are:
-1/6 + 9.11043i/6
-1/6 - 9.11043i/6"
run_test \
"10. degree 2" \
"3x² + 2x -7 = x" "\
Reduced form: 7 * x^0 + 1 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly negative, the two complex solutions are:
-1/6 + 9.11043i/6
-1/6 - 9.11043i/6"
run_test \
"11. degree 2" \
"-3x² + 2x -7 = x" "\
Reduced form: 7 * x^0 + 1 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly negative, the two complex solutions are:
-1/6 + 9.11043i/6
-1/6 - 9.11043i/6"
run_test \
"12. degree 2" \
"+3x² + 2x -7 = x" "\
Reduced form: 7 * x^0 + 1 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly negative, the two complex solutions are:
-1/6 + 9.11043i/6
-1/6 - 9.11043i/6"
run_test \
"13. degree 2" \
"3x² + 0x -7 = x" "\
Reduced form: -7 * x^0 - 1 * x^1 + 3 * x^2 = 0
Reduced form: 0 * x^0 - 6 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly positive, the two solutions are:
1.369924
-1.369924"
0
2"
run_test \
"14. degree 2" \
"3x² + 0x -0 = x" "\
Reduced form: 0 * x^0 - 1 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly positive, the two solutions are:
1.66667
-1.33333"
# run_test \
# "10. degree 2" \
# "3 * x^2 + 2 * x - 7 * x^1 = x" "\
# Reduced form: 0 * x^0 - 6 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Discriminant is strictly positive, the two solutions are:
# 2
# 0"
run_test \
"15. degree 2" \
"3x² + 2x -0 = x" "\
Reduced form: 0 * x^0 + 1 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly positive, the two solutions are:
1.33333
-1.66667"
# run_test \
# "11. degree 2" \
# "-3x² + 2x -7 = x" "\
# Reduced form: -7 * x^0 + 1 * x^1 - 3 * x^2 = 0
# Polynomial degree: 2
# Discriminant is strictly negative, the two complex solutions are:
# 0.166667 - 1.51841*i
# 0.166667 + 1.51841*i"
run_test \
"16. degree 1" \
"3x + 2x -0 = x" "\
Reduced form: 0 * x^0 + 4 * x^1 = 0
Polynomial degree: 1
The solution is:
0"
# run_test \
# "12. degree 2" \
# "+3x² + 2x -7 = x" "\
# Reduced form: -7 * x^0 + 1 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Discriminant is strictly positive, the two solutions are:
# 1.36992
# -1.70326"
run_test \
"17. degree 2" \
"3x² + x -0 = x" "\
Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Radicant is equal to zero, the solution is:
0"
# run_test \
# "13. degree 2" \
# "3x² + 0x -7 = x" "\
# Reduced form: -7 * x^0 - 1 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Discriminant is strictly positive, the two solutions are:
# 1.70326
# -1.36992"
run_test \
"18. degree 2" \
"0x² + x -0 = x" "\
Reduced form: 0 * x^0 = 0
Any real number is a solution."
# run_test \
# "14. degree 2" \
# "3x² + 0x -0 = x" "\
# Reduced form: 0 * x^0 - 1 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Discriminant is strictly positive, the two solutions are:
# 0.333333
# 0"
run_test \
"19. degree 5" \
"2x⁵ + x -0 = -7x^5" "\
Reduced form: 0 * x^0 + 1 * x^1 + 0 * x^2 + 0 * x^3 + 0 * x^4 + 9 * x^5 = 0
Polynomial degree: 5
The polynomial degree is strictly greater than 2, I can't solve."
# run_test \
# "15. degree 2" \
# "3x² + 2x -0 = x" "\
# Reduced form: 0 * x^0 + 1 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Discriminant is strictly positive, the two solutions are:
# 0
# -0.333333"
run_test \
"20. degree 1" \
"2x + x -0 = -7x" "\
Reduced form: 0 * x^0 + 10 * x^1 = 0
Polynomial degree: 1
The solution is:
0"
# run_test \
# "16. degree 1" \
# "3x + 2x -0 = x" "\
# Reduced form: 0 * x^0 + 4 * x^1 = 0
# Polynomial degree: 1
# The solution is:
# 0"
run_test \
"21. degree 1" \
"2x + x -3 = -7x" "\
Reduced form: -3 * x^0 + 10 * x^1 = 0
Polynomial degree: 1
The solution is:
0.3"
# run_test \
# "17. degree 2" \
# "3x² + x -0 = x" "\
# Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Radicant is equal to zero, the solution is:
# 0"
run_test \
"22. degree 1" \
"-2x + x -3 = -7x" "\
Reduced form: -3 * x^0 + 6 * x^1 = 0
Polynomial degree: 1
The solution is:
0.5"
# run_test \
# "18. degree 2" \
# "0x² + x -0 = x" "\
# Reduced form: 0 * x^0 = 0
# Any real number is a solution."
run_test \
"23. degree 2 without [=]" \
"3x^2" \
"" \
error
# run_test \
# "19. degree 5" \
# "2x⁵ + x -0 = -7x^5" "\
# Reduced form: 0 * x^0 + 1 * x^1 + 0 * x^2 + 0 * x^3 + 0 * x^4 + 9 * x^5 = 0
# Polynomial degree: 5
# The polynomial degree is strictly greater than 2, I can't solve."
run_test \
"24. degree 2" \
"3x^2 = 0" "\
Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Radicant is equal to zero, the solution is:
0"
# run_test \
# "20. degree 1" \
# "2x + x -0 = -7x" "\
# Reduced form: 0 * x^0 + 10 * x^1 = 0
# Polynomial degree: 1
# The solution is:
# 0"
run_test \
"25. degree 2" \
"3x^2 + 2 = 0" "\
Reduced form: 2 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Radicant is strictly negative, the two complex solutions are:
i√(2/3)
-i√(2/3)"
# run_test \
# "21. degree 1" \
# "2x + x -3 = -7x" "\
# Reduced form: -3 * x^0 + 10 * x^1 = 0
# Polynomial degree: 1
# The solution is:
# 0.3"
run_test \
"26. degree 2 pure" \
"3 * x^2 + 5 * x^1 - 2 * x^0 = 5 * x" "\
Reduced form: -2 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Radicant is strictly positive, the two solutions are:
√(2/3)
-√(2/3)"
# run_test \
# "22. degree 1" \
# "-2x + x -3 = -7x" "\
# Reduced form: -3 * x^0 + 6 * x^1 = 0
# Polynomial degree: 1
# The solution is:
# 0.5"
run_test \
"27. degree 2 pure" \
"9 * x^2 + 5 * x^1 - 2 * x^0 = 5 * x" "\
Reduced form: -2 * x^0 + 0 * x^1 + 9 * x^2 = 0
Polynomial degree: 2
Radicant is strictly positive, the two solutions are:
√(2)/3
-√(2)/3"
# run_test \
# "23. degree 2 without [=]" \
# "3x^2" \
# "" \
# error
run_test \
"28. degree 2 pure" \
"3 * x^2 + 5 * x^1 - 4 * x^0 = 5 * x" "\
Reduced form: -4 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Radicant is strictly positive, the two solutions are:
2/√(3)
-2/√(3)"
# run_test \
# "24. degree 2" \
# "3x^2 = 0" "\
# Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Radicant is equal to zero, the solution is:
# 0"
run_test \
"29. degree 2 pure" \
"16 * x^2 + 5 * x^1 - 4 * x^0 = 5 * x" "\
Reduced form: -4 * x^0 + 0 * x^1 + 16 * x^2 = 0
Polynomial degree: 2
Radicant is strictly positive, the two solutions are:
1/2
-1/2"
# run_test \
# "25. degree 2" \
# "3x^2 + 2 = 0" "\
# Reduced form: 2 * x^0 + 0 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Radicant is strictly negative, the two complex solutions are:
# i√(2/3)
# -i√(2/3)"
run_test \
"30. degree 2 pure" \
"4 * x^2 + 5 * x^1 - 16 * x^0 = 5 * x" "\
Reduced form: -16 * x^0 + 0 * x^1 + 4 * x^2 = 0
Polynomial degree: 2
Radicant is strictly positive, the two solutions are:
2
-2"
# run_test \
# "26. degree 2 pure" \
# "3 * x^2 + 5 * x^1 - 2 * x^0 = 5 * x" "\
# Reduced form: -2 * x^0 + 0 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Radicant is strictly positive, the two solutions are:
# √(2/3)
# -√(2/3)"
# run_test \
# "27. degree 2 pure" \
# "9 * x^2 + 5 * x^1 - 2 * x^0 = 5 * x" "\
# Reduced form: -2 * x^0 + 0 * x^1 + 9 * x^2 = 0
# Polynomial degree: 2
# Radicant is strictly positive, the two solutions are:
# √(2)/3
# -√(2)/3"
# run_test \
# "28. degree 2 pure" \
# "3 * x^2 + 5 * x^1 - 4 * x^0 = 5 * x" "\
# Reduced form: -4 * x^0 + 0 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Radicant is strictly positive, the two solutions are:
# 2/√(3)
# -2/√(3)"
# run_test \
# "29. degree 2 pure" \
# "16 * x^2 + 5 * x^1 - 4 * x^0 = 5 * x" "\
# Reduced form: -4 * x^0 + 0 * x^1 + 16 * x^2 = 0
# Polynomial degree: 2
# Radicant is strictly positive, the two solutions are:
# 1/2
# -1/2"
# run_test \
# "30. degree 2 pure" \
# "4 * x^2 + 5 * x^1 - 16 * x^0 = 5 * x" "\
# Reduced form: -16 * x^0 + 0 * x^1 + 4 * x^2 = 0
# Polynomial degree: 2
# Radicant is strictly positive, the two solutions are:
# 2
# -2"
# run_test \
# "31. degree 2" \
# "3x² + 2x -7 = x" "\
# Reduced form: -7 * x^0 + 1 * x^1 + 3 * x^2 = 0
# Polynomial degree: 2
# Discriminant is strictly positive, the two solutions are:
# 1.36992
# -1.70326"