Average Error: 34.3 → 10.3
Time: 8.2s
Precision: binary64
\[\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 -1.612020823558058 \cdot 10^{+78}:\\ \;\;\;\;\frac{\frac{\left(-b\right) - b}{3}}{a}\\ \mathbf{elif}\;b \leq 7.869053993413591 \cdot 10^{-64}:\\ \;\;\;\;\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} \]
\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 -1.612020823558058 \cdot 10^{+78}:\\
\;\;\;\;\frac{\frac{\left(-b\right) - b}{3}}{a}\\

\mathbf{elif}\;b \leq 7.869053993413591 \cdot 10^{-64}:\\
\;\;\;\;\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}
(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 -1.612020823558058e+78)
   (/ (/ (- (- b) b) 3.0) a)
   (if (<= b 7.869053993413591e-64)
     (/ (- (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 <= -1.612020823558058e+78) {
		tmp = ((-b - b) / 3.0) / a;
	} else if (b <= 7.869053993413591e-64) {
		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

Derivation

  1. Split input into 3 regimes
  2. if b < -1.612020823558058e78

    1. Initial program 42.5

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

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

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

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

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

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

    if -1.612020823558058e78 < b < 7.8690539934135913e-64

    1. Initial program 13.8

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

      \[\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 *-un-lft-identity_binary6413.8

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

    if 7.8690539934135913e-64 < b

    1. Initial program 53.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.612020823558058 \cdot 10^{+78}:\\ \;\;\;\;\frac{\frac{\left(-b\right) - b}{3}}{a}\\ \mathbf{elif}\;b \leq 7.869053993413591 \cdot 10^{-64}:\\ \;\;\;\;\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} \]

Reproduce

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