| Alternative 1 | |
|---|---|
| Error | 5.1 |
| Cost | 74500 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (+ a a))))
(if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) -30.0)
(* t_0 (* t_0 (/ 1.0 (* t_0 (* t_0 (/ 1.0 t_0))))))
(+
(*
-0.25
(/
(+
(* (pow c 4.0) (* 4.0 (pow a 4.0)))
(* 16.0 (* (pow c 4.0) (pow a 4.0))))
(* a (pow b 7.0))))
(+
(* -1.0 (/ c b))
(+
(* -1.0 (/ (* a (pow c 2.0)) (pow b 3.0)))
(* -2.0 (/ (* (pow c 3.0) (pow a 2.0)) (pow b 5.0)))))))))double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a + a);
double tmp;
if (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -30.0) {
tmp = t_0 * (t_0 * (1.0 / (t_0 * (t_0 * (1.0 / t_0)))));
} else {
tmp = (-0.25 * (((pow(c, 4.0) * (4.0 * pow(a, 4.0))) + (16.0 * (pow(c, 4.0) * pow(a, 4.0)))) / (a * pow(b, 7.0)))) + ((-1.0 * (c / b)) + ((-1.0 * ((a * pow(c, 2.0)) / pow(b, 3.0))) + (-2.0 * ((pow(c, 3.0) * pow(a, 2.0)) / pow(b, 5.0)))));
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) + (c * (a * (-4.0d0))))) - b) / (a + a)
if (((-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)) <= (-30.0d0)) then
tmp = t_0 * (t_0 * (1.0d0 / (t_0 * (t_0 * (1.0d0 / t_0)))))
else
tmp = ((-0.25d0) * ((((c ** 4.0d0) * (4.0d0 * (a ** 4.0d0))) + (16.0d0 * ((c ** 4.0d0) * (a ** 4.0d0)))) / (a * (b ** 7.0d0)))) + (((-1.0d0) * (c / b)) + (((-1.0d0) * ((a * (c ** 2.0d0)) / (b ** 3.0d0))) + ((-2.0d0) * (((c ** 3.0d0) * (a ** 2.0d0)) / (b ** 5.0d0)))))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a + a);
double tmp;
if (((-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -30.0) {
tmp = t_0 * (t_0 * (1.0 / (t_0 * (t_0 * (1.0 / t_0)))));
} else {
tmp = (-0.25 * (((Math.pow(c, 4.0) * (4.0 * Math.pow(a, 4.0))) + (16.0 * (Math.pow(c, 4.0) * Math.pow(a, 4.0)))) / (a * Math.pow(b, 7.0)))) + ((-1.0 * (c / b)) + ((-1.0 * ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0))) + (-2.0 * ((Math.pow(c, 3.0) * Math.pow(a, 2.0)) / Math.pow(b, 5.0)))));
}
return tmp;
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
def code(a, b, c): t_0 = (math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a + a) tmp = 0 if ((-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -30.0: tmp = t_0 * (t_0 * (1.0 / (t_0 * (t_0 * (1.0 / t_0))))) else: tmp = (-0.25 * (((math.pow(c, 4.0) * (4.0 * math.pow(a, 4.0))) + (16.0 * (math.pow(c, 4.0) * math.pow(a, 4.0)))) / (a * math.pow(b, 7.0)))) + ((-1.0 * (c / b)) + ((-1.0 * ((a * math.pow(c, 2.0)) / math.pow(b, 3.0))) + (-2.0 * ((math.pow(c, 3.0) * math.pow(a, 2.0)) / math.pow(b, 5.0))))) return tmp
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a + a)) tmp = 0.0 if (Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) <= -30.0) tmp = Float64(t_0 * Float64(t_0 * Float64(1.0 / Float64(t_0 * Float64(t_0 * Float64(1.0 / t_0)))))); else tmp = Float64(Float64(-0.25 * Float64(Float64(Float64((c ^ 4.0) * Float64(4.0 * (a ^ 4.0))) + Float64(16.0 * Float64((c ^ 4.0) * (a ^ 4.0)))) / Float64(a * (b ^ 7.0)))) + Float64(Float64(-1.0 * Float64(c / b)) + Float64(Float64(-1.0 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0))) + Float64(-2.0 * Float64(Float64((c ^ 3.0) * (a ^ 2.0)) / (b ^ 5.0)))))); end return tmp end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a + a); tmp = 0.0; if (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -30.0) tmp = t_0 * (t_0 * (1.0 / (t_0 * (t_0 * (1.0 / t_0))))); else tmp = (-0.25 * ((((c ^ 4.0) * (4.0 * (a ^ 4.0))) + (16.0 * ((c ^ 4.0) * (a ^ 4.0)))) / (a * (b ^ 7.0)))) + ((-1.0 * (c / b)) + ((-1.0 * ((a * (c ^ 2.0)) / (b ^ 3.0))) + (-2.0 * (((c ^ 3.0) * (a ^ 2.0)) / (b ^ 5.0))))); end tmp_2 = tmp; end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], -30.0], N[(t$95$0 * N[(t$95$0 * N[(1.0 / N[(t$95$0 * N[(t$95$0 * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.25 * N[(N[(N[(N[Power[c, 4.0], $MachinePrecision] * N[(4.0 * N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(16.0 * N[(N[Power[c, 4.0], $MachinePrecision] * N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[(N[Power[c, 3.0], $MachinePrecision] * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a + a}\\
\mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \leq -30:\\
\;\;\;\;t_0 \cdot \left(t_0 \cdot \frac{1}{t_0 \cdot \left(t_0 \cdot \frac{1}{t_0}\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;-0.25 \cdot \frac{{c}^{4} \cdot \left(4 \cdot {a}^{4}\right) + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)\\
\end{array}
Results
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -30Initial program 8.7
Simplified8.7
[Start]8.7 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]8.7 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-97 [=>]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \color{blue}{\left(0 - b\right)}}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]8.7 | \[ \frac{\color{blue}{\left(0 + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) - b}}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]8.7 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + 0\right)} - b}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]8.7 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a \cdot 2}}
\] |
metadata-eval [<=]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \color{blue}{\left(1 + 1\right)}}
\] |
metadata-eval [<=]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \left(\color{blue}{\frac{4}{4}} + 1\right)}
\] |
metadata-eval [<=]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \left(\frac{4}{4} + \color{blue}{\frac{4}{4}}\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-23 [<=]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{\frac{4}{4} \cdot a + a \cdot \frac{4}{4}}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [<=]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a \cdot \frac{4}{4}} + a \cdot \frac{4}{4}}
\] |
metadata-eval [=>]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \color{blue}{1} + a \cdot \frac{4}{4}}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a} + a \cdot \frac{4}{4}}
\] |
metadata-eval [=>]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a + a \cdot \color{blue}{1}}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]8.7 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a + \color{blue}{a}}
\] |
Applied egg-rr8.7
Applied egg-rr8.7
if -30 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 30.1
Simplified30.1
[Start]30.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]30.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-97 [=>]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \color{blue}{\left(0 - b\right)}}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]30.1 | \[ \frac{\color{blue}{\left(0 + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) - b}}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]30.1 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + 0\right)} - b}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]30.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}{2 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a \cdot 2}}
\] |
metadata-eval [<=]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \color{blue}{\left(1 + 1\right)}}
\] |
metadata-eval [<=]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \left(\color{blue}{\frac{4}{4}} + 1\right)}
\] |
metadata-eval [<=]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \left(\frac{4}{4} + \color{blue}{\frac{4}{4}}\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-23 [<=]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{\frac{4}{4} \cdot a + a \cdot \frac{4}{4}}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [<=]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a \cdot \frac{4}{4}} + a \cdot \frac{4}{4}}
\] |
metadata-eval [=>]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot \color{blue}{1} + a \cdot \frac{4}{4}}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a} + a \cdot \frac{4}{4}}
\] |
metadata-eval [=>]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a + a \cdot \color{blue}{1}}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]30.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a + \color{blue}{a}}
\] |
Taylor expanded in b around inf 4.8
Simplified4.7
[Start]4.8 | \[ -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-82 [=>]4.8 | \[ \color{blue}{-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-82 [=>]4.7 | \[ -0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \color{blue}{\left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]4.7 | \[ -0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{\color{blue}{a \cdot {c}^{2}}}{{b}^{3}} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)
\] |
Taylor expanded in c around 0 4.7
Simplified4.7
[Start]4.7 | \[ -0.25 \cdot \frac{4 \cdot \left({c}^{4} \cdot {a}^{4}\right) + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-7 [=>]4.7 | \[ -0.25 \cdot \frac{\color{blue}{{c}^{4} \cdot \left(4 \cdot {a}^{4}\right)} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)
\] |
Final simplification5.1
| Alternative 1 | |
|---|---|
| Error | 5.1 |
| Cost | 74500 |
| Alternative 2 | |
|---|---|
| Error | 6.7 |
| Cost | 44804 |
| Alternative 3 | |
|---|---|
| Error | 6.7 |
| Cost | 41156 |
| Alternative 4 | |
|---|---|
| Error | 6.7 |
| Cost | 41028 |
| Alternative 5 | |
|---|---|
| Error | 15.2 |
| Cost | 14852 |
| Alternative 6 | |
|---|---|
| Error | 10.0 |
| Cost | 13764 |
| Alternative 7 | |
|---|---|
| Error | 23.1 |
| Cost | 256 |
herbie shell --seed 2023090
(FPCore (a b c)
:name "Quadratic roots, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))