\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 -5.601648774806547 \cdot 10^{+101}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 1.6674544466416018 \cdot 10^{-283}:\\
\;\;\;\;-0.5 \cdot \left(4 \cdot \frac{c}{b - \sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}\right)\\
\mathbf{elif}\;b \leq 3.4546240696680445 \cdot 10^{+63}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a} - 2 \cdot \frac{c}{b}\right)\\
\end{array}(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 -5.601648774806547e+101)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 1.6674544466416018e-283)
(*
-0.5
(*
4.0
(/
c
(-
b
(sqrt
(*
(sqrt (- (* b b) (* 4.0 (* c a))))
(sqrt (- (* b b) (* 4.0 (* c a))))))))))
(if (<= b 3.4546240696680445e+63)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) a))
(* -0.5 (- (* 2.0 (/ b a)) (* 2.0 (/ c b))))))))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 <= -5.601648774806547e+101) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 1.6674544466416018e-283) {
tmp = -0.5 * (4.0 * (c / (b - sqrt(sqrt((b * b) - (4.0 * (c * a))) * sqrt((b * b) - (4.0 * (c * a)))))));
} else if (b <= 3.4546240696680445e+63) {
tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / a);
} else {
tmp = -0.5 * ((2.0 * (b / a)) - (2.0 * (c / b)));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.2 |
|---|---|
| Target | 21.1 |
| Herbie | 6.7 |
if b < -5.6016487748065473e101Initial program 59.7
Simplified59.7
Taylor expanded around -inf 2.1
if -5.6016487748065473e101 < b < 1.6674544466416018e-283Initial program 31.4
Simplified31.4
rmApplied flip-+_binary64_346231.4
Simplified16.4
rmApplied *-un-lft-identity_binary64_348816.4
Applied *-un-lft-identity_binary64_348816.4
Applied times-frac_binary64_349416.4
Applied times-frac_binary64_349416.4
Simplified16.4
Simplified9.2
rmApplied add-sqr-sqrt_binary64_35109.2
if 1.6674544466416018e-283 < b < 3.4546240696680445e63Initial program 8.8
Simplified8.8
rmApplied *-un-lft-identity_binary64_34888.8
Applied associate-/r*_binary64_34328.8
if 3.4546240696680445e63 < b Initial program 41.0
Simplified41.0
Taylor expanded around inf 5.2
Final simplification6.7
herbie shell --seed 2021079
(FPCore (a b c)
:name "The quadratic formula (r2)"
: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)))