Average Error: 34.0 → 6.8
Time: 4.9s
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 -4.705720954619456 \cdot 10^{+141}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \leq -1.4544105329255394 \cdot 10^{-190}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.9089157297044016 \cdot 10^{+110}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \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 -4.705720954619456 \cdot 10^{+141}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \leq -1.4544105329255394 \cdot 10^{-190}:\\
\;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{1}{a \cdot 2}\\

\mathbf{elif}\;b \leq 5.9089157297044016 \cdot 10^{+110}:\\
\;\;\;\;\frac{4}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\

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

\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 -4.705720954619456e+141)
   (* 1.0 (- (/ c b) (/ b a)))
   (if (<= b -1.4544105329255394e-190)
     (* (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (/ 1.0 (* a 2.0)))
     (if (<= b 5.9089157297044016e+110)
       (* (/ 4.0 2.0) (/ c (- (- b) (sqrt (- (* b b) (* 4.0 (* c a)))))))
       (* (/ c b) -1.0)))))
double code(double a, double b, double c) {
	return (((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a)));
}
double code(double a, double b, double c) {
	double tmp;
	if ((b <= -4.705720954619456e+141)) {
		tmp = ((double) (1.0 * ((double) ((c / b) - (b / a)))));
	} else {
		double tmp_1;
		if ((b <= -1.4544105329255394e-190)) {
			tmp_1 = ((double) (((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))) - b)) * (1.0 / ((double) (a * 2.0)))));
		} else {
			double tmp_2;
			if ((b <= 5.9089157297044016e+110)) {
				tmp_2 = ((double) ((4.0 / 2.0) * (c / ((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))))))));
			} else {
				tmp_2 = ((double) ((c / b) * -1.0));
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	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

Original34.0
Target21.0
Herbie6.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 4 regimes
  2. if b < -4.70572095461945609e141

    1. Initial program Error: 58.7 bits

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf Error: 2.4 bits

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. SimplifiedError: 2.4 bits

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

    if -4.70572095461945609e141 < b < -1.4544105329255394e-190

    1. Initial program Error: 7.4 bits

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-invError: 7.6 bits

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. SimplifiedError: 7.6 bits

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

    if -1.4544105329255394e-190 < b < 5.9089157297044016e110

    1. Initial program Error: 29.3 bits

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+Error: 29.5 bits

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    4. SimplifiedError: 16.7 bits

      \[\leadsto \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. SimplifiedError: 16.7 bits

      \[\leadsto \frac{\frac{4 \cdot \left(a \cdot c\right)}{\color{blue}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identityError: 16.7 bits

      \[\leadsto \frac{\frac{4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}}{2 \cdot a}\]
    8. Applied times-fracError: 16.7 bits

      \[\leadsto \frac{\color{blue}{\frac{4}{1} \cdot \frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    9. Applied times-fracError: 16.7 bits

      \[\leadsto \color{blue}{\frac{\frac{4}{1}}{2} \cdot \frac{\frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}}\]
    10. SimplifiedError: 16.7 bits

      \[\leadsto \color{blue}{\frac{4}{2}} \cdot \frac{\frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}\]
    11. SimplifiedError: 10.0 bits

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

    if 5.9089157297044016e110 < b

    1. Initial program Error: 60.4 bits

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf Error: 2.6 bits

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplificationError: 6.8 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.705720954619456 \cdot 10^{+141}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \leq -1.4544105329255394 \cdot 10^{-190}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.9089157297044016 \cdot 10^{+110}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

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