Average Error: 19.3 → 7.5
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 -3.6419385251769567 \cdot 10^{+130}:\\ \;\;\;\;\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}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;b \leq 1.827145917976237 \cdot 10^{+108}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{c \cdot a}{b} - b \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\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 -3.6419385251769567 \cdot 10^{+130}:\\
\;\;\;\;\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}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\end{array}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\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 -3.6419385251769567e+130)
   (if (>= b 0.0)
     (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* c (* 4.0 a))))))
     (* 1.0 (- (/ c b) (/ b a))))
   (if (<= b 1.827145917976237e+108)
     (if (>= b 0.0)
       (/
        (* 2.0 c)
        (-
         (- b)
         (*
          (sqrt (sqrt (- (* b b) (* c (* 4.0 a)))))
          (sqrt (sqrt (- (* b b) (* c (* 4.0 a))))))))
       (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* 2.0 a)))
     (if (>= b 0.0)
       (/ (* 2.0 c) (- (* 2.0 (/ (* c a) b)) (* b 2.0)))
       (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) 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 <= -3.6419385251769567e+130)) {
		double tmp_1;
		if ((b >= 0.0)) {
			tmp_1 = (((double) (2.0 * c)) / ((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))));
		} else {
			tmp_1 = ((double) (1.0 * ((double) ((c / b) - (b / a)))));
		}
		tmp = tmp_1;
	} else {
		double tmp_2;
		if ((b <= 1.827145917976237e+108)) {
			double tmp_3;
			if ((b >= 0.0)) {
				tmp_3 = (((double) (2.0 * c)) / ((double) (((double) -(b)) - ((double) (((double) sqrt(((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))) * ((double) sqrt(((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))))))))));
			} else {
				tmp_3 = (((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))) - b)) / ((double) (2.0 * a)));
			}
			tmp_2 = tmp_3;
		} else {
			double tmp_4;
			if ((b >= 0.0)) {
				tmp_4 = (((double) (2.0 * c)) / ((double) (((double) (2.0 * (((double) (c * a)) / b))) - ((double) (b * 2.0)))));
			} else {
				tmp_4 = (((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (4.0 * a)))))))) - b)) / ((double) (2.0 * a)));
			}
			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 < -3.64193852517695668e130

    1. Initial program 54.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. Simplified54.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 -inf 10.3

      \[\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{\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\]
    4. Simplified10.3

      \[\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{\left(2 \cdot \frac{c \cdot a}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\]
    5. Taylor expanded around 0 3.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}:\\ \;\;\;\;1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}\\ \end{array}\]
    6. Simplified3.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}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

    if -3.64193852517695668e130 < b < 1.82714591797623707e108

    1. Initial program 8.5

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

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

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

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

    if 1.82714591797623707e108 < b

    1. Initial program 29.2

      \[\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. Simplified29.2

      \[\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 6.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.6419385251769567 \cdot 10^{+130}:\\ \;\;\;\;\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}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;b \leq 1.827145917976237 \cdot 10^{+108}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\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}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{c \cdot a}{b} - b \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\]

Reproduce

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