Average Error: 33.8 → 8.8
Time: 1.4min
Precision: binary64
Cost: 8707
\[\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.3447584199663284 \cdot 10^{+109}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.002773495656876 \cdot 10^{-150}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.5210644500600335 \cdot 10^{+50}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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.3447584199663284 \cdot 10^{+109}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\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.3447584199663284e+109)
   (- (/ c b) (/ b a))
   (if (<= b 3.002773495656876e-150)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
     (if (<= b 3.5210644500600335e+50)
       (/
        (/ (* a (* c -4.0)) (+ b (sqrt (- (* b b) (* c (* a 4.0))))))
        (* a 2.0))
       (- (/ c 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.3447584199663284e+109) {
		tmp = (c / b) - (b / a);
	} else if (b <= 3.002773495656876e-150) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
	} else if (b <= 3.5210644500600335e+50) {
		tmp = ((a * (c * -4.0)) / (b + sqrt((b * b) - (c * (a * 4.0))))) / (a * 2.0);
	} else {
		tmp = -(c / 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.8
Target21.0
Herbie8.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}\]

Alternatives

Alternative 1
Error10.3
Cost8002
\[\begin{array}{l} \mathbf{if}\;b \leq -8.035059411985508 \cdot 10^{+108}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.624161150164621 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 2
Error13.7
Cost7874
\[\begin{array}{l} \mathbf{if}\;b \leq -5.275499183256394 \cdot 10^{-73}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 2.783056805972697 \cdot 10^{-11}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 3
Error13.6
Cost7746
\[\begin{array}{l} \mathbf{if}\;b \leq -6.767664192189726 \cdot 10^{-73}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 3.450208845312404 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{-4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 4
Error14.1
Cost7618
\[\begin{array}{l} \mathbf{if}\;b \leq -2.0851517047750132 \cdot 10^{-106}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 2.5447133222605828 \cdot 10^{-11}:\\ \;\;\;\;\frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 5
Error23.0
Cost7169
\[\begin{array}{l} \mathbf{if}\;b \leq 3.094968887251983 \cdot 10^{-192}:\\ \;\;\;\;\frac{\left|b\right| - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 6
Error23.0
Cost577
\[\begin{array}{l} \mathbf{if}\;b \leq 3.094968887251983 \cdot 10^{-192}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 7
Error39.6
Cost577
\[\begin{array}{l} \mathbf{if}\;b \leq 5.0110558632484 \cdot 10^{-310}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 8
Error56.4
Cost64
\[0\]
Alternative 9
Error61.6
Cost64
\[1\]

Error

Time

Derivation

  1. Split input into 4 regimes
  2. if b < -1.34475841996632838e109

    1. Initial program 49.3

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

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -1.34475841996632838e109 < b < 3.002773495656876e-150

    1. Initial program 10.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied +-commutative_binary64_103110.8

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

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

    if 3.002773495656876e-150 < b < 3.5210644500600335e50

    1. Initial program 36.8

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt_binary64_112336.8

      \[\leadsto \frac{\sqrt{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} - b}{a \cdot 2}\]
    5. Applied rem-sqrt-square_binary64_111436.8

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

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

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

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

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

    if 3.5210644500600335e50 < b

    1. Initial program 56.8

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

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

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
    4. Simplified4.1

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3447584199663284 \cdot 10^{+109}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.002773495656876 \cdot 10^{-150}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.5210644500600335 \cdot 10^{+50}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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