Average Error: 33.6 → 8.5
Time: 7.2s
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 -1.3249665758399062 \cdot 10^{+154}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 2.227512516590462 \cdot 10^{-227}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 5.134094891995538 \cdot 10^{+120}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}}\\ \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 -1.3249665758399062 \cdot 10^{+154}:\\
\;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\

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

\mathbf{elif}\;b \leq 5.134094891995538 \cdot 10^{+120}:\\
\;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}\\

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

\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 -1.3249665758399062e+154)
   (/ (* 2.0 (- (/ (* a c) b) b)) (* 2.0 a))
   (if (<= b 2.227512516590462e-227)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))
     (if (<= b 5.134094891995538e+120)
       (/ 1.0 (/ 0.5 (/ c (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))))))
       (/ 1.0 (/ 0.5 (/ c (* 2.0 (- (/ (* a c) b) b)))))))))
double code(double a, double b, double c) {
	return (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.3249665758399062e+154) {
		tmp = (2.0 * (((a * c) / b) - b)) / (2.0 * a);
	} else if (b <= 2.227512516590462e-227) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (2.0 * a);
	} else if (b <= 5.134094891995538e+120) {
		tmp = 1.0 / (0.5 / (c / (-b - sqrt((b * b) - (c * (a * 4.0))))));
	} else {
		tmp = 1.0 / (0.5 / (c / (2.0 * (((a * c) / b) - b))));
	}
	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

Original33.6
Target20.5
Herbie8.5
\[\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 < -1.32496657583990621e154

    1. Initial program 64.0

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Simplified12.1

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

    if -1.32496657583990621e154 < b < 2.2275125165904618e-227

    1. Initial program 9.3

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

    if 2.2275125165904618e-227 < b < 5.13409489199553824e120

    1. Initial program 36.7

      \[\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-+_binary64_142936.8

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(4 \cdot a\right)} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied clear-num_binary64_145414.7

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

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

    if 5.13409489199553824e120 < b

    1. Initial program 61.2

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

      \[\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. Simplified34.3

      \[\leadsto \frac{\frac{\color{blue}{\left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity_binary64_145534.3

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

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

      \[\leadsto \frac{\color{blue}{\left(4 \cdot a\right)} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied clear-num_binary64_145434.2

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

      \[\leadsto \frac{1}{\color{blue}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}\]
    12. Taylor expanded around inf 6.2

      \[\leadsto \frac{1}{\frac{0.5}{\frac{c}{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}}}\]
    13. Simplified6.2

      \[\leadsto \frac{1}{\frac{0.5}{\frac{c}{\color{blue}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3249665758399062 \cdot 10^{+154}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 2.227512516590462 \cdot 10^{-227}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 5.134094891995538 \cdot 10^{+120}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}}\\ \end{array}\]

Reproduce

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