Average Error: 34.6 → 8.7
Time: 11.0s
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 -3.24196586675541 \cdot 10^{+138}:\\ \;\;\;\;2 \cdot \left(-0.3333333333333333 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \leq -9.990041030723927 \cdot 10^{-308}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 8.030044591380852 \cdot 10^{-29}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b \cdot -2}\\ \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 -3.24196586675541 \cdot 10^{+138}:\\
\;\;\;\;2 \cdot \left(-0.3333333333333333 \cdot \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \leq 8.030044591380852 \cdot 10^{-29}:\\
\;\;\;\;\frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right)}\\

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


\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 -3.24196586675541e+138)
   (* 2.0 (* -0.3333333333333333 (/ b a)))
   (if (<= b -9.990041030723927e-308)
     (/ (/ (- (sqrt (- (* b b) (* (* a 3.0) c))) b) 3.0) a)
     (if (<= b 8.030044591380852e-29)
       (/ c (- (- b) (hypot b (sqrt (* c (* a -3.0))))))
       (/ c (* b -2.0))))))
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 <= -3.24196586675541e+138) {
		tmp = 2.0 * (-0.3333333333333333 * (b / a));
	} else if (b <= -9.990041030723927e-308) {
		tmp = ((sqrt((b * b) - ((a * 3.0) * c)) - b) / 3.0) / a;
	} else if (b <= 8.030044591380852e-29) {
		tmp = c / (-b - hypot(b, sqrt(c * (a * -3.0))));
	} else {
		tmp = c / (b * -2.0);
	}
	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 < -3.24196586675541025e138

    1. Initial program 57.8

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

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

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

      \[\leadsto \frac{\frac{3 \cdot \left(c \cdot a\right)}{\color{blue}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}}{3 \cdot a} \]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary6462.9

      \[\leadsto \frac{\frac{3 \cdot \left(c \cdot a\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}\right)}}}{3 \cdot a} \]
    8. Applied times-frac_binary6462.9

      \[\leadsto \frac{\color{blue}{\frac{3}{1} \cdot \frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}}{3 \cdot a} \]
    9. Applied times-frac_binary6462.9

      \[\leadsto \color{blue}{\frac{\frac{3}{1}}{3} \cdot \frac{\frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{a}} \]
    10. Simplified62.9

      \[\leadsto \color{blue}{1} \cdot \frac{\frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{a} \]
    11. Simplified63.8

      \[\leadsto 1 \cdot \color{blue}{\left(1 \cdot \frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right)}\right)} \]
    12. Taylor expanded around -inf 44.3

      \[\leadsto 1 \cdot \left(1 \cdot \color{blue}{\left(2 \cdot \frac{c \cdot b}{{\left(\sqrt{-3 \cdot \left(c \cdot a\right)}\right)}^{2}}\right)}\right) \]
    13. Simplified2.9

      \[\leadsto 1 \cdot \left(1 \cdot \color{blue}{\left(2 \cdot \left(-0.3333333333333333 \cdot \frac{b}{a}\right)\right)}\right) \]

    if -3.24196586675541025e138 < b < -9.99004103072392733e-308

    1. Initial program 9.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Using strategy rm
    3. Applied associate-/r*_binary649.2

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

    if -9.99004103072392733e-308 < b < 8.03004459138085156e-29

    1. Initial program 24.7

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

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

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

      \[\leadsto \frac{\frac{3 \cdot \left(c \cdot a\right)}{\color{blue}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}}{3 \cdot a} \]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary6418.3

      \[\leadsto \frac{\frac{3 \cdot \left(c \cdot a\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}\right)}}}{3 \cdot a} \]
    8. Applied times-frac_binary6418.3

      \[\leadsto \frac{\color{blue}{\frac{3}{1} \cdot \frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}}{3 \cdot a} \]
    9. Applied times-frac_binary6418.2

      \[\leadsto \color{blue}{\frac{\frac{3}{1}}{3} \cdot \frac{\frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{a}} \]
    10. Simplified18.2

      \[\leadsto \color{blue}{1} \cdot \frac{\frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{a} \]
    11. Simplified14.2

      \[\leadsto 1 \cdot \color{blue}{\left(1 \cdot \frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right)}\right)} \]
    12. Using strategy rm
    13. Applied *-commutative_binary6414.2

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

    if 8.03004459138085156e-29 < b

    1. Initial program 54.8

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

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

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

      \[\leadsto \frac{\frac{3 \cdot \left(c \cdot a\right)}{\color{blue}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}}{3 \cdot a} \]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary6426.1

      \[\leadsto \frac{\frac{3 \cdot \left(c \cdot a\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}\right)}}}{3 \cdot a} \]
    8. Applied times-frac_binary6426.1

      \[\leadsto \frac{\color{blue}{\frac{3}{1} \cdot \frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}}{3 \cdot a} \]
    9. Applied times-frac_binary6426.1

      \[\leadsto \color{blue}{\frac{\frac{3}{1}}{3} \cdot \frac{\frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{a}} \]
    10. Simplified26.1

      \[\leadsto \color{blue}{1} \cdot \frac{\frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{a} \]
    11. Simplified28.0

      \[\leadsto 1 \cdot \color{blue}{\left(1 \cdot \frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right)}\right)} \]
    12. Taylor expanded around inf 7.3

      \[\leadsto 1 \cdot \left(1 \cdot \frac{c}{\color{blue}{-2 \cdot b}}\right) \]
    13. Simplified7.3

      \[\leadsto 1 \cdot \left(1 \cdot \frac{c}{\color{blue}{b \cdot -2}}\right) \]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.24196586675541 \cdot 10^{+138}:\\ \;\;\;\;2 \cdot \left(-0.3333333333333333 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \leq -9.990041030723927 \cdot 10^{-308}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 8.030044591380852 \cdot 10^{-29}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -3\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b \cdot -2}\\ \end{array} \]

Reproduce

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