Average Error: 34.6 → 10.5
Time: 31.0s
Precision: binary64
Cost: 14152
\[\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 -8 \cdot 10^{+114}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-101}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-3 \cdot a\right)\right)}}{3 \cdot a} - \frac{b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot 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 -8e+114)
   (/ (/ b a) -1.5)
   (if (<= b 5e-101)
     (- (/ (sqrt (fma b b (* c (* -3.0 a)))) (* 3.0 a)) (/ 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 <= -8e+114) {
		tmp = (b / a) / -1.5;
	} else if (b <= 5e-101) {
		tmp = (sqrt(fma(b, b, (c * (-3.0 * a)))) / (3.0 * a)) - (b / (3.0 * a));
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function code(a, b, c)
	tmp = 0.0
	if (b <= -8e+114)
		tmp = Float64(Float64(b / a) / -1.5);
	elseif (b <= 5e-101)
		tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(-3.0 * a)))) / Float64(3.0 * a)) - Float64(b / Float64(3.0 * a)));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -8e+114], N[(N[(b / a), $MachinePrecision] / -1.5), $MachinePrecision], If[LessEqual[b, 5e-101], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(-3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision] - N[(b / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\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 -8 \cdot 10^{+114}:\\
\;\;\;\;\frac{\frac{b}{a}}{-1.5}\\

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

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


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if b < -8e114

    1. Initial program 51.6

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)} - b\right) \cdot \frac{0.3333333333333333}{a}} \]
      Proof
    3. Taylor expanded in b around -inf 4.0

      \[\leadsto \color{blue}{\left(-2 \cdot b\right)} \cdot \frac{0.3333333333333333}{a} \]
    4. Applied egg-rr4.0

      \[\leadsto \color{blue}{\frac{b}{a} \cdot -0.6666666666666666} \]
    5. Applied egg-rr3.9

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

    if -8e114 < b < 5.0000000000000001e-101

    1. Initial program 13.0

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

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

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

    if 5.0000000000000001e-101 < b

    1. Initial program 52.3

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

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

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

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

Alternatives

Alternative 1
Error10.5
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -2.6 \cdot 10^{+113}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-101}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 2
Error10.6
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -5.1 \cdot 10^{+143}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ne 0:\\ \;\;\;\;\frac{-2}{\frac{a}{b} \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-101}:\\ \;\;\;\;\left(\sqrt{c \cdot \left(-3 \cdot a\right) + b \cdot b} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 3
Error10.5
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.4 \cdot 10^{+153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ne 0:\\ \;\;\;\;\frac{-2}{\frac{a}{b} \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-101}:\\ \;\;\;\;\frac{\sqrt{\left(c \cdot a\right) \cdot -3 + b \cdot b} - b}{a} \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 4
Error14.3
Cost7432
\[\begin{array}{l} \mathbf{if}\;b \leq -2.05 \cdot 10^{-38}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-101}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{-3 \cdot \left(c \cdot a\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 5
Error14.3
Cost7432
\[\begin{array}{l} \mathbf{if}\;b \leq -5.1 \cdot 10^{-36}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 1.75 \cdot 10^{-102}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{c \cdot \left(-3 \cdot a\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 6
Error14.3
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -8.5 \cdot 10^{-38}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-101}:\\ \;\;\;\;\left(\sqrt{\left(a \cdot -3\right) \cdot c} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 7
Error14.3
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -3.5 \cdot 10^{-40}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-101}:\\ \;\;\;\;\frac{\left(\sqrt{\left(-3 \cdot c\right) \cdot a} - b\right) \cdot 0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 8
Error14.3
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.1 \cdot 10^{-38}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-101}:\\ \;\;\;\;\frac{\sqrt{\left(-3 \cdot c\right) \cdot a} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 9
Error14.6
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -1.4 \cdot 10^{-40}:\\ \;\;\;\;\frac{\frac{b}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 4.8 \cdot 10^{-101}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(c \cdot a\right)}}{a} \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 10
Error39.2
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq -6.5 \cdot 10^{-305}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;0 \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 11
Error39.2
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq -6.5 \cdot 10^{-305}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;0 \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 12
Error22.5
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.3 \cdot 10^{-216}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 13
Error22.5
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 8.5 \cdot 10^{-220}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 14
Error56.5
Cost320
\[0 \cdot \frac{0.3333333333333333}{a} \]

Error

Reproduce

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