Average Error: 34.6 → 10.9
Time: 6.9s
Precision: binary64
Cost: 8002
\[\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 -7.102439644234899 \cdot 10^{-32}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 9.908180707161701 \cdot 10^{-62}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{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 -7.102439644234899 \cdot 10^{-32}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 9.908180707161701 \cdot 10^{-62}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{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 -7.102439644234899e-32)
   (/ (- b) a)
   (if (<= b 9.908180707161701e-62)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 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 <= -7.102439644234899e-32) {
		tmp = -b / a;
	} else if (b <= 9.908180707161701e-62) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (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

Alternatives

Alternative 1
Error13.1
Cost7746
\[\begin{array}{l} \mathbf{if}\;b \leq -4.65690630187704 \cdot 10^{-48}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 3.799060668791859 \cdot 10^{-62}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 2
Error13.5
Cost7618
\[\begin{array}{l} \mathbf{if}\;b \leq -5.720701774836184 \cdot 10^{-124}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.9542320841650248 \cdot 10^{-64}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 3
Error22.4
Cost577
\[\begin{array}{l} \mathbf{if}\;b \leq 9.624881597762947 \cdot 10^{-279}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
Alternative 4
Error39.4
Cost577
\[\begin{array}{l} \mathbf{if}\;b \leq 5.7901680992929 \cdot 10^{-312}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 5
Error56.1
Cost64
\[0\]
Alternative 6
Error61.5
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if b < -7.1024396442348992e-32

    1. Initial program 30.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
    3. Taylor expanded around -inf 8.7

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified8.7

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
    5. Simplified8.7

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

    if -7.1024396442348992e-32 < b < 9.9081807071617013e-62

    1. Initial program 15.4

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

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

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

    if 9.9081807071617013e-62 < b

    1. Initial program 54.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
    3. Taylor expanded around inf 8.3

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

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
    5. Simplified8.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.102439644234899 \cdot 10^{-32}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 9.908180707161701 \cdot 10^{-62}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2021044 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))