Average Error: 34.8 → 10.2
Time: 11.2s
Precision: binary64
Cost: 8002
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -5.45892145913632 \cdot 10^{+153}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.2901844560369386 \cdot 10^{-39}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -5.45892145913632 \cdot 10^{+153}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\

\mathbf{elif}\;b \leq 1.2901844560369386 \cdot 10^{-39}:\\
\;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3}}{a}\\

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

\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -5.45892145913632e+153)
   (/ (* b -2.0) (* 3.0 a))
   (if (<= b 1.2901844560369386e-39)
     (/ (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) 3.0) a)
     (* -0.5 (/ c b)))))
double code(double a, double b, double c) {
	return (-b + sqrt((b * b) - ((3.0 * a) * c))) / (3.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.45892145913632e+153) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 1.2901844560369386e-39) {
		tmp = ((sqrt((b * b) - ((3.0 * a) * c)) - b) / 3.0) / a;
	} else {
		tmp = -0.5 * (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
Error10.1
Cost8002
\[\begin{array}{l} \mathbf{if}\;b \leq -1.152442509815712 \cdot 10^{+138}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 4.7425045090226674 \cdot 10^{-42}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
Alternative 2
Error10.2
Cost8002
\[\begin{array}{l} \mathbf{if}\;b \leq -8.887918546354078 \cdot 10^{+139}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 4.3034790776983455 \cdot 10^{-41}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
Alternative 3
Error13.9
Cost7554
\[\begin{array}{l} \mathbf{if}\;b \leq -3.216026123156104 \cdot 10^{-136}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 2.7246677044628124 \cdot 10^{-51}:\\ \;\;\;\;-\frac{c}{\sqrt{a \cdot \left(c \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
Alternative 4
Error22.4
Cost769
\[\begin{array}{l} \mathbf{if}\;b \leq 7.39592424827649 \cdot 10^{-212}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
Alternative 5
Error22.5
Cost769
\[\begin{array}{l} \mathbf{if}\;b \leq 4.641734365265361 \cdot 10^{-210}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
Alternative 6
Error22.5
Cost641
\[\begin{array}{l} \mathbf{if}\;b \leq 4.5984243801846445 \cdot 10^{-211}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
Alternative 7
Error39.3
Cost641
\[\begin{array}{l} \mathbf{if}\;b \leq 4.1858178371903 \cdot 10^{-310}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 8
Error56.2
Cost64
\[0\]
Alternative 9
Error61.6
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if b < -5.45892145913632016e153

    1. Initial program 63.8

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

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

      \[\leadsto \frac{\color{blue}{-2 \cdot b}}{3 \cdot a}\]
    4. Simplified2.4

      \[\leadsto \frac{\color{blue}{b \cdot -2}}{3 \cdot a}\]
    5. Simplified2.4

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

    if -5.45892145913632016e153 < b < 1.29018445603693855e-39

    1. Initial program 14.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}}\]
    3. Using strategy rm
    4. Applied associate-/r*_binary64_377314.2

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

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

    if 1.29018445603693855e-39 < b

    1. Initial program 54.3

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}}\]
    4. Simplified7.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.45892145913632 \cdot 10^{+153}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.2901844560369386 \cdot 10^{-39}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2021044 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))