Average Error: 33.5 → 9.8
Time: 8.6s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.0439797130993678 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 8.094037225273647 \cdot 10^{-74}:\\ \;\;\;\;\frac{\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot 0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\ \end{array} \]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -1.0439797130993678 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\


\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 -1.0439797130993678e+154)
   (/ (- b) a)
   (if (<= b 8.094037225273647e-74)
     (/ (* (- (sqrt (- (* b b) (* (* a 4.0) c))) b) 0.5) a)
     (/ 1.0 (- (/ a b) (/ b c))))))
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 <= -1.0439797130993678e+154) {
		tmp = -b / a;
	} else if (b <= 8.094037225273647e-74) {
		tmp = ((sqrt((b * b) - ((a * 4.0) * c)) - b) * 0.5) / a;
	} else {
		tmp = 1.0 / ((a / b) - (b / c));
	}
	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

Original33.5
Target20.4
Herbie9.8
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if b < -1.0439797130993678e154

    1. Initial program 64.0

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    4. Simplified1.8

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if -1.0439797130993678e154 < b < 8.0940372252736475e-74

    1. Initial program 11.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}} \]
    3. Using strategy rm
    4. Applied div-inv_binary6411.8

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{a \cdot 2}} \]
    5. Simplified11.8

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

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

    if 8.0940372252736475e-74 < b

    1. Initial program 53.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}} \]
    3. Using strategy rm
    4. Applied clear-num_binary6453.2

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

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{2}}}} \]
    6. Taylor expanded around 0 9.5

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{b} - \frac{b}{c}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.0439797130993678 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 8.094037225273647 \cdot 10^{-74}:\\ \;\;\;\;\frac{\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot 0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\ \end{array} \]

Reproduce

herbie shell --seed 2021205 
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))