Average Error: 20.5 → 7.2
Time: 7.9s
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.1244998464394334 \cdot 10^{+82}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{2}{\frac{a}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \leq 7.250966043701229 \cdot 10^{+121}:\\ \;\;\;\;\begin{array}{l} t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\ \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + t_0}{a}\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot c\right) \cdot \frac{1}{t_0 - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{-2 \cdot \frac{a \cdot c}{b}}\\ \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.1244998464394334 \cdot 10^{+82}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{2}{\frac{a}{b}}\\

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


\end{array}\\

\mathbf{elif}\;b \leq 7.250966043701229 \cdot 10^{+121}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + t_0}{a}\\

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


\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\

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


\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 (<= b -2.1244998464394334e+82)
   (if (>= b 0.0) (* -0.5 (/ 2.0 (/ a b))) (/ (* 2.0 c) (* b -2.0)))
   (if (<= b 7.250966043701229e+121)
     (let* ((t_0 (sqrt (fma a (* c -4.0) (* b b)))))
       (if (>= b 0.0)
         (* -0.5 (/ (+ b t_0) a))
         (* (* 2.0 c) (/ 1.0 (- t_0 b)))))
     (if (>= b 0.0)
       (* -0.5 (/ (+ b b) a))
       (/ (* 2.0 c) (* -2.0 (/ (* a c) 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.1244998464394334e+82) {
		double tmp_2;
		if (b >= 0.0) {
			tmp_2 = -0.5 * (2.0 / (a / b));
		} else {
			tmp_2 = (2.0 * c) / (b * -2.0);
		}
		tmp_1 = tmp_2;
	} else if (b <= 7.250966043701229e+121) {
		double t_0 = sqrt(fma(a, (c * -4.0), (b * b)));
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = -0.5 * ((b + t_0) / a);
		} else {
			tmp_3 = (2.0 * c) * (1.0 / (t_0 - b));
		}
		tmp_1 = tmp_3;
	} else if (b >= 0.0) {
		tmp_1 = -0.5 * ((b + b) / a);
	} else {
		tmp_1 = (2.0 * c) / (-2.0 * ((a * c) / b));
	}
	return tmp_1;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -2.12449984643943344e82

    1. Initial program 28.2

      \[\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. Simplified28.1

      \[\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 a around 0 28.1

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{\color{blue}{2 \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \end{array} \]
    7. Applied associate-/l*_binary643.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \color{blue}{\frac{2}{\frac{a}{b}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \end{array} \]
    8. Applied *-un-lft-identity_binary643.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{2}{\color{blue}{1 \cdot \frac{a}{b}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \end{array} \]
    9. Applied *-un-lft-identity_binary643.4

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

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

    if -2.12449984643943344e82 < b < 7.2509660437012287e121

    1. Initial program 9.6

      \[\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. Simplified9.7

      \[\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. Applied div-inv_binary649.7

      \[\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}:\\ \;\;\;\;\left(c \cdot 2\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}\\ \end{array} \]

    if 7.2509660437012287e121 < b

    1. Initial program 53.5

      \[\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. Simplified53.5

      \[\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 a around 0 3.4

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + b}{a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{c \cdot 2}{-2 \cdot \frac{c \cdot a}{b}}}\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.1244998464394334 \cdot 10^{+82}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{2}{\frac{a}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\ \end{array}\\ \mathbf{elif}\;b \leq 7.250966043701229 \cdot 10^{+121}:\\ \;\;\;\;\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}:\\ \;\;\;\;\left(2 \cdot c\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{-2 \cdot \frac{a \cdot c}{b}}\\ \end{array} \]

Reproduce

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