| Alternative 1 | |
|---|---|
| Error | 13.4 |
| Cost | 7432 |
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -4.2e-62)
(- (/ c b))
(if (<= b 1.1e+125)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a))
(- (/ c b) (/ b a)))))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 tmp;
if (b <= -4.2e-62) {
tmp = -(c / b);
} else if (b <= 1.1e+125) {
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
} else {
tmp = (c / b) - (b / a);
}
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) :: tmp
if (b <= (-4.2d-62)) then
tmp = -(c / b)
else if (b <= 1.1d+125) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
else
tmp = (c / b) - (b / a)
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 tmp;
if (b <= -4.2e-62) {
tmp = -(c / b);
} else if (b <= 1.1e+125) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
} else {
tmp = (c / b) - (b / a);
}
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): tmp = 0 if b <= -4.2e-62: tmp = -(c / b) elif b <= 1.1e+125: tmp = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function code(a, b, c) tmp = 0.0 if (b <= -4.2e-62) tmp = Float64(-Float64(c / b)); elseif (b <= 1.1e+125) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); 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) tmp = 0.0; if (b <= -4.2e-62) tmp = -(c / b); elseif (b <= 1.1e+125) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -4.2e-62], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.1e+125], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -4.2 \cdot 10^{-62}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{+125}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
Results
| Original | 34.2 |
|---|---|
| Target | 21.0 |
| Herbie | 10.0 |
if b < -4.1999999999999998e-62Initial program 54.0
Simplified54.0
[Start]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}}
\] |
metadata-eval [<=]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \color{blue}{\left(1 + 1\right)}}
\] |
metadata-eval [<=]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \left(\color{blue}{\frac{4}{4}} + 1\right)}
\] |
metadata-eval [<=]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \left(\frac{4}{4} + \color{blue}{\frac{4}{4}}\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-23 [<=]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{4}{4} \cdot a + a \cdot \frac{4}{4}}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [<=]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot \frac{4}{4}} + a \cdot \frac{4}{4}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \frac{4}{4} + \color{blue}{\frac{4}{4} \cdot a}}
\] |
rational_best_oopsla_all_46_json_45_simplify-23 [=>]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{4}{4} \cdot \left(a + a\right)}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\left(a + a\right) \cdot \frac{4}{4}}}
\] |
metadata-eval [=>]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(a + a\right) \cdot \color{blue}{1}}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]54.0 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a + a}}
\] |
Taylor expanded in b around -inf 8.8
Simplified8.8
[Start]8.8 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.8 | \[ \color{blue}{\frac{c}{b} \cdot -1}
\] |
rational_best_oopsla_all_46_json_45_simplify-92 [=>]8.8 | \[ \color{blue}{-\frac{c}{b}}
\] |
if -4.1999999999999998e-62 < b < 1.09999999999999995e125Initial program 12.9
if 1.09999999999999995e125 < b Initial program 54.6
Simplified54.6
[Start]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}}
\] |
metadata-eval [<=]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \color{blue}{\left(1 + 1\right)}}
\] |
metadata-eval [<=]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \left(\color{blue}{\frac{4}{4}} + 1\right)}
\] |
metadata-eval [<=]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \left(\frac{4}{4} + \color{blue}{\frac{4}{4}}\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-23 [<=]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{4}{4} \cdot a + a \cdot \frac{4}{4}}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [<=]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot \frac{4}{4}} + a \cdot \frac{4}{4}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot \frac{4}{4} + \color{blue}{\frac{4}{4} \cdot a}}
\] |
rational_best_oopsla_all_46_json_45_simplify-23 [=>]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{4}{4} \cdot \left(a + a\right)}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\left(a + a\right) \cdot \frac{4}{4}}}
\] |
metadata-eval [=>]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(a + a\right) \cdot \color{blue}{1}}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]54.6 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a + a}}
\] |
Taylor expanded in b around inf 2.5
Simplified2.5
[Start]2.5 | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]2.5 | \[ \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]2.5 | \[ \color{blue}{\frac{b}{a} \cdot -1} + \frac{c}{b}
\] |
rational_best_oopsla_all_46_json_45_simplify-92 [=>]2.5 | \[ \color{blue}{\left(-\frac{b}{a}\right)} + \frac{c}{b}
\] |
Applied egg-rr2.5
Simplified2.5
[Start]2.5 | \[ \left(-\frac{b}{a}\right) - \left(-\frac{c}{b}\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-94 [=>]2.5 | \[ \color{blue}{\frac{b}{a} \cdot -1} - \left(-\frac{c}{b}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-94 [=>]2.5 | \[ \frac{b}{a} \cdot -1 - \color{blue}{\frac{c}{b} \cdot -1}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [<=]2.5 | \[ \frac{b}{a} \cdot -1 - \color{blue}{-1 \cdot \frac{c}{b}}
\] |
rational_best_oopsla_all_46_json_45_simplify-13 [<=]2.5 | \[ \color{blue}{-1 \cdot \left(\frac{b}{a} - \frac{c}{b}\right)}
\] |
metadata-eval [<=]2.5 | \[ \color{blue}{\left(-1\right)} \cdot \left(\frac{b}{a} - \frac{c}{b}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-87 [<=]2.5 | \[ \color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]2.5 | \[ \color{blue}{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]2.5 | \[ \color{blue}{\frac{c}{b} - \frac{b}{a}}
\] |
Final simplification10.0
| Alternative 1 | |
|---|---|
| Error | 13.4 |
| Cost | 7432 |
| Alternative 2 | |
|---|---|
| Error | 22.9 |
| Cost | 580 |
| Alternative 3 | |
|---|---|
| Error | 40.1 |
| Cost | 388 |
| Alternative 4 | |
|---|---|
| Error | 22.9 |
| Cost | 388 |
| Alternative 5 | |
|---|---|
| Error | 56.7 |
| Cost | 192 |
herbie shell --seed 2023090
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))