Average Error: 19.8 → 6.9
Time: 5.7s
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:\\ \;\;\;\;2 \cdot \frac{c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(c \cdot \left(2 \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:\\ \;\;\;\;2 \cdot \frac{c}{\frac{c \cdot \left(a \cdot 4\right)}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - 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:\\ \;\;\;\;2 \cdot \frac{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:\\ \;\;\;\;2 \cdot \frac{c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(c \cdot \left(2 \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:\\
\;\;\;\;2 \cdot \frac{c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(c \cdot \left(2 \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:\\
\;\;\;\;2 \cdot \frac{c}{\frac{c \cdot \left(a \cdot 4\right)}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - 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:\\
\;\;\;\;2 \cdot \frac{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:\\
\;\;\;\;2 \cdot \frac{c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(c \cdot \left(2 \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)))
     (/ (- (- (* c (* 2.0 (/ a b))) b) b) (* 2.0 a)))
   (if (<= b -2.780192689850507e-300)
     (if (>= b 0.0)
       (*
        2.0
        (/ c (/ (* c (* a 4.0)) (- (sqrt (- (* b b) (* c (* a 4.0)))) 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)))
         (/ (- (- (* c (* 2.0 (/ 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) (c * ((double) (2.0 * (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) (c * ((double) (a * 4.0)))) / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))) - 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) (c * ((double) (2.0 * (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 Error: 42.0 bits

      \[\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. SimplifiedError: 42.0 bits

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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 Error: 25.0 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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. SimplifiedError: 22.4 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \left(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}\]
    5. Taylor expanded around -inf Error: 5.2 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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}\]
    6. SimplifiedError: 2.5 bits

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

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

    1. Initial program Error: 8.8 bits

      \[\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. SimplifiedError: 8.8 bits

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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 flip--Error: 8.8 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} \cdot \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{\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}\]
    5. SimplifiedError: 8.8 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\frac{\color{blue}{c \cdot \left(4 \cdot a\right)}}{\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}\]
    6. SimplifiedError: 8.8 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\frac{c \cdot \left(4 \cdot a\right)}{\color{blue}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - 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 Error: 8.7 bits

      \[\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. SimplifiedError: 8.7 bits

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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-logError: 8.8 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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 Error: 9.2 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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. SimplifiedError: 9.2 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left(\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b\right)}}{2 \cdot a}\\ \end{array}\]
    7. Using strategy rm
    8. Applied associate-*r/Error: 9.2 bits

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{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 simplificationError: 6.9 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.1275090717025735 \cdot 10^{+127}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(c \cdot \left(2 \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:\\ \;\;\;\;2 \cdot \frac{c}{\frac{c \cdot \left(a \cdot 4\right)}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - 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:\\ \;\;\;\;2 \cdot \frac{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:\\ \;\;\;\;2 \cdot \frac{c}{\left(2 \cdot \left(c \cdot \frac{a}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(c \cdot \left(2 \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))))