Average Error: 34.1 → 6.7
Time: 9.8s
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 -5.027360149222957 \cdot 10^{+147}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq -7.490208502750257 \cdot 10^{-179}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c}}{a \cdot 3} - \frac{b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 2.4581016233270703 \cdot 10^{+134}:\\ \;\;\;\;\frac{-c}{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}\\ \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.027360149222957 \cdot 10^{+147}:\\
\;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\

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

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

\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.027360149222957e+147)
   (* (/ b a) -0.6666666666666666)
   (if (<= b -7.490208502750257e-179)
     (- (/ (sqrt (- (* b b) (* (* a 3.0) c))) (* a 3.0)) (/ b (* a 3.0)))
     (if (<= b 2.4581016233270703e+134)
       (/ (- c) (+ b (sqrt (- (* b b) (* 3.0 (* a c))))))
       (* -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.027360149222957e+147) {
		tmp = (b / a) * -0.6666666666666666;
	} else if (b <= -7.490208502750257e-179) {
		tmp = (sqrt((b * b) - ((a * 3.0) * c)) / (a * 3.0)) - (b / (a * 3.0));
	} else if (b <= 2.4581016233270703e+134) {
		tmp = -c / (b + sqrt((b * b) - (3.0 * (a * c))));
	} 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 4 regimes
  2. if b < -5.02736014922295721e147

    1. Initial program 62.2

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

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

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

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

    if -5.02736014922295721e147 < b < -7.4902085027502569e-179

    1. Initial program 7.1

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

      \[\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 div-sub_binary647.1

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

    if -7.4902085027502569e-179 < b < 2.4581016233270703e134

    1. Initial program 30.0

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

      \[\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 div-inv_binary6430.1

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

      \[\leadsto \left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \color{blue}{\frac{0.3333333333333333}{a}}\]
    6. Using strategy rm
    7. Applied flip--_binary6430.3

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b \cdot b}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + b}} \cdot \frac{0.3333333333333333}{a}\]
    8. Simplified16.6

      \[\leadsto \frac{\color{blue}{a \cdot \left(c \cdot -3\right)}}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + b} \cdot \frac{0.3333333333333333}{a}\]
    9. Simplified16.6

      \[\leadsto \frac{a \cdot \left(c \cdot -3\right)}{\color{blue}{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}} \cdot \frac{0.3333333333333333}{a}\]
    10. Using strategy rm
    11. Applied associate-*l/_binary6415.5

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

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

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

    if 2.4581016233270703e134 < b

    1. Initial program 62.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.027360149222957 \cdot 10^{+147}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq -7.490208502750257 \cdot 10^{-179}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c}}{a \cdot 3} - \frac{b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 2.4581016233270703 \cdot 10^{+134}:\\ \;\;\;\;\frac{-c}{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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