Average Error: 19.8 → 6.9
Time: 4.8s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -4.1275090717025735 \cdot 10^{+127}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq -2.780192689850507 \cdot 10^{-300}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{-b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 2.838341990170196 \cdot 10^{+126}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left(\left(2 \cdot \frac{c \cdot a}{b} - b\right) - b\right)}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}
\begin{array}{l}
\mathbf{if}\;b \leq -4.1275090717025735 \cdot 10^{+127}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\

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

\end{array}\\

\mathbf{elif}\;b \leq -2.780192689850507 \cdot 10^{-300}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-b}\\

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

\end{array}\\

\mathbf{elif}\;b \leq 2.838341990170196 \cdot 10^{+126}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\

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

\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\

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

\end{array}
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))
   (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
(FPCore (a b c)
 :precision binary64
 (if (<= b -4.1275090717025735e+127)
   (if (>= b 0.0)
     (/ (* 2.0 c) (- (- (* 2.0 (* c (/ a b))) b) b))
     (/ (- (- (* 2.0 (* c (/ a b))) b) b) (* 2.0 a)))
   (if (<= b -2.780192689850507e-300)
     (if (>= b 0.0)
       (/ (* 2.0 c) (- b))
       (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))
     (if (<= b 2.838341990170196e+126)
       (if (>= b 0.0)
         (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))))
         (/ (exp (log (- (- (* 2.0 (/ (* c a) b)) b) b))) (* 2.0 a)))
       (if (>= b 0.0)
         (/ (* 2.0 c) (- (- (* 2.0 (* c (/ a b))) b) b))
         (/ (- (- (* 2.0 (* c (/ a b))) b) b) (* 2.0 a)))))))
double code(double a, double b, double c) {
	double tmp;
	if ((b >= 0.0)) {
		tmp = (((double) (2.0 * c)) / ((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))));
	} else {
		tmp = (((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a)));
	}
	return tmp;
}
double code(double a, double b, double c) {
	double tmp;
	if ((b <= -4.1275090717025735e+127)) {
		double tmp_1;
		if ((b >= 0.0)) {
			tmp_1 = (((double) (2.0 * c)) / ((double) (((double) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)));
		} else {
			tmp_1 = (((double) (((double) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)) / ((double) (2.0 * a)));
		}
		tmp = tmp_1;
	} else {
		double tmp_2;
		if ((b <= -2.780192689850507e-300)) {
			double tmp_3;
			if ((b >= 0.0)) {
				tmp_3 = (((double) (2.0 * c)) / ((double) -(b)));
			} else {
				tmp_3 = (((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))) - b)) / ((double) (2.0 * a)));
			}
			tmp_2 = tmp_3;
		} else {
			double tmp_4;
			if ((b <= 2.838341990170196e+126)) {
				double tmp_5;
				if ((b >= 0.0)) {
					tmp_5 = (((double) (2.0 * c)) / ((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))))));
				} else {
					tmp_5 = (((double) exp(((double) log(((double) (((double) (((double) (2.0 * (((double) (c * a)) / b))) - b)) - b)))))) / ((double) (2.0 * a)));
				}
				tmp_4 = tmp_5;
			} else {
				double tmp_6;
				if ((b >= 0.0)) {
					tmp_6 = (((double) (2.0 * c)) / ((double) (((double) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)));
				} else {
					tmp_6 = (((double) (((double) (((double) (2.0 * ((double) (c * (a / b))))) - b)) - b)) / ((double) (2.0 * a)));
				}
				tmp_4 = tmp_6;
			}
			tmp_2 = tmp_4;
		}
		tmp = tmp_2;
	}
	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

Derivation

  1. Split input into 3 regimes
  2. if b < -4.12750907170257349e127 or 2.83834199017019573e126 < b

    1. Initial program 42.0

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity_binary6425.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \frac{c \cdot a}{\color{blue}{1 \cdot b}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\]
    7. Applied times-frac_binary6422.4

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \left(\color{blue}{c} \cdot \frac{a}{b}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\]
    9. Taylor expanded around -inf 5.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\]
    10. Simplified2.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(c \cdot \frac{a}{b}\right) \cdot 2 - b\right) - b}{2 \cdot a}\\ \end{array}\]

    if -4.12750907170257349e127 < b < -2.78019268985050695e-300

    1. Initial program 8.8

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

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

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

    if -2.78019268985050695e-300 < b < 2.83834199017019573e126

    1. Initial program 8.7

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

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-exp-log_binary648.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b\right)}}{2 \cdot a}\\ \end{array}\]
    5. Taylor expanded around -inf 9.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left(\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b\right)}}{2 \cdot a}\\ \end{array}\]
    6. Simplified9.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.1275090717025735 \cdot 10^{+127}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq -2.780192689850507 \cdot 10^{-300}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{-b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 2.838341990170196 \cdot 10^{+126}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left(\left(2 \cdot \frac{c \cdot a}{b} - b\right) - b\right)}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}{2 \cdot a}\\ \end{array}\]

Reproduce

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