Average Error: 34.3 → 7.1
Time: 9.5s
Precision: binary64
\[\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 -3.4414061013038998 \cdot 10^{+56}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 8.083353603153632 \cdot 10^{-303}:\\ \;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\ \mathbf{elif}\;b \leq 7.508840126695903 \cdot 10^{+84}:\\ \;\;\;\;-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 \left(\frac{b}{a} - \frac{c}{b}\right)\right)\\ \end{array}\]
\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 -3.4414061013038998 \cdot 10^{+56}:\\
\;\;\;\;-\frac{c}{b}\\

\mathbf{elif}\;b \leq 8.083353603153632 \cdot 10^{-303}:\\
\;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\

\mathbf{elif}\;b \leq 7.508840126695903 \cdot 10^{+84}:\\
\;\;\;\;-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 \left(\frac{b}{a} - \frac{c}{b}\right)\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 -3.4414061013038998e+56)
   (- (/ c b))
   (if (<= b 8.083353603153632e-303)
     (* -0.5 (/ 4.0 (/ (- b (sqrt (- (* b b) (* 4.0 (* c a))))) c)))
     (if (<= b 7.508840126695903e+84)
       (* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) a))
       (* -0.5 (* 2.0 (- (/ b a) (/ 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 <= -3.4414061013038998e+56) {
		tmp = -(c / b);
	} else if (b <= 8.083353603153632e-303) {
		tmp = -0.5 * (4.0 / ((b - sqrt((b * b) - (4.0 * (c * a)))) / c));
	} else if (b <= 7.508840126695903e+84) {
		tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / a);
	} else {
		tmp = -0.5 * (2.0 * ((b / a) - (c / b)));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.3
Target21.0
Herbie7.1
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -3.44140610130389975e56

    1. Initial program 57.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified57.2

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Taylor expanded around -inf 3.7

      \[\leadsto -0.5 \cdot \color{blue}{\left(2 \cdot \frac{c}{b}\right)}\]
    4. Taylor expanded around 0 3.7

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if -3.44140610130389975e56 < b < 8.0833536031536319e-303

    1. Initial program 30.4

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified30.4

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Using strategy rm
    4. Applied flip-+_binary64_243930.4

      \[\leadsto -0.5 \cdot \frac{\color{blue}{\frac{b \cdot b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{a}\]
    5. Simplified17.6

      \[\leadsto -0.5 \cdot \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary64_246517.6

      \[\leadsto -0.5 \cdot \frac{\frac{4 \cdot \left(a \cdot c\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{\color{blue}{1 \cdot a}}\]
    8. Applied *-un-lft-identity_binary64_246517.6

      \[\leadsto -0.5 \cdot \frac{\color{blue}{1 \cdot \frac{4 \cdot \left(a \cdot c\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{1 \cdot a}\]
    9. Applied times-frac_binary64_247117.6

      \[\leadsto -0.5 \cdot \color{blue}{\left(\frac{1}{1} \cdot \frac{\frac{4 \cdot \left(a \cdot c\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}\right)}\]
    10. Simplified17.6

      \[\leadsto -0.5 \cdot \left(\color{blue}{1} \cdot \frac{\frac{4 \cdot \left(a \cdot c\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}\right)\]
    11. Simplified9.9

      \[\leadsto -0.5 \cdot \left(1 \cdot \color{blue}{\frac{4}{1 \cdot \frac{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{c}}}\right)\]

    if 8.0833536031536319e-303 < b < 7.508840126695903e84

    1. Initial program 9.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified9.7

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]

    if 7.508840126695903e84 < b

    1. Initial program 44.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified44.0

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Taylor expanded around inf 4.1

      \[\leadsto -0.5 \cdot \color{blue}{\left(2 \cdot \frac{b}{a} - 2 \cdot \frac{c}{b}\right)}\]
    4. Simplified4.1

      \[\leadsto -0.5 \cdot \color{blue}{\left(2 \cdot \left(\frac{b}{a} - \frac{c}{b}\right)\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.4414061013038998 \cdot 10^{+56}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 8.083353603153632 \cdot 10^{-303}:\\ \;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\ \mathbf{elif}\;b \leq 7.508840126695903 \cdot 10^{+84}:\\ \;\;\;\;-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 \left(\frac{b}{a} - \frac{c}{b}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2021043 
(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)))