Average Error: 19.4 → 6.3
Time: 9.3s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -2.795577173814291 \cdot 10^{+87} \lor \neg \left(b \leq 3.8060811703142394 \cdot 10^{+144}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\ \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{t_0 - b}\\ \end{array}\\ \end{array} \]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\


\end{array}
\begin{array}{l}
\mathbf{if}\;b \leq -2.795577173814291 \cdot 10^{+87} \lor \neg \left(b \leq 3.8060811703142394 \cdot 10^{+144}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\


\end{array}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_0 - b}\\


\end{array}\\


\end{array}
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))
   (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))
(FPCore (a b c)
 :precision binary64
 (if (or (<= b -2.795577173814291e+87) (not (<= b 3.8060811703142394e+144)))
   (if (>= b 0.0) (* -0.5 (/ (+ b b) a)) (/ (* c 2.0) (- (- b) b)))
   (let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
     (if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ (* c 2.0) (- t_0 b))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (-b - sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
	} else {
		tmp = (2.0 * c) / (-b + sqrt((b * b) - ((4.0 * a) * c)));
	}
	return tmp;
}
double code(double a, double b, double c) {
	double tmp_1;
	if ((b <= -2.795577173814291e+87) || !(b <= 3.8060811703142394e+144)) {
		double tmp_2;
		if (b >= 0.0) {
			tmp_2 = -0.5 * ((b + b) / a);
		} else {
			tmp_2 = (c * 2.0) / (-b - b);
		}
		tmp_1 = tmp_2;
	} else {
		double t_0 = sqrt((b * b) - (c * (a * 4.0)));
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = (-b - t_0) / (a * 2.0);
		} else {
			tmp_3 = (c * 2.0) / (t_0 - b);
		}
		tmp_1 = tmp_3;
	}
	return tmp_1;
}

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

Derivation

  1. Split input into 2 regimes
  2. if b < -2.7955771738142911e87 or 3.80608117031423939e144 < b

    1. Initial program 38.8

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

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}\\ } \end{array}} \]
    3. Taylor expanded in b around -inf 21.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{c \cdot 2}}{-1 \cdot b - b}\\ \end{array} \]
    4. Taylor expanded in a around 0 2.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \color{blue}{b}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{-1 \cdot b - b}\\ \end{array} \]

    if -2.7955771738142911e87 < b < 3.80608117031423939e144

    1. Initial program 8.4

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.795577173814291 \cdot 10^{+87} \lor \neg \left(b \leq 3.8060811703142394 \cdot 10^{+144}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\ \end{array} \]

Reproduce

herbie shell --seed 2021329 
(FPCore (a b c)
  :name "jeff quadratic root 1"
  :precision binary64
  (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))