?

Average Error: 34.3 → 10.2
Time: 25.2s
Precision: binary64
Cost: 7624

?

\[\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 -9.5 \cdot 10^{+95}:\\ \;\;\;\;\frac{\mathsf{fma}\left(1.5, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.55 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{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 -9.5e+95)
   (/ (fma 1.5 (/ c (/ b a)) (* b -2.0)) (* a 3.0))
   (if (<= b 1.55e-75)
     (/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) b) (* a 3.0))
     (/ (* c -0.5) 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 <= -9.5e+95) {
		tmp = fma(1.5, (c / (b / a)), (b * -2.0)) / (a * 3.0);
	} else if (b <= 1.55e-75) {
		tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
	} else {
		tmp = (c * -0.5) / 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 <= -9.5e+95)
		tmp = Float64(fma(1.5, Float64(c / Float64(b / a)), Float64(b * -2.0)) / Float64(a * 3.0));
	elseif (b <= 1.55e-75)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0));
	else
		tmp = Float64(Float64(c * -0.5) / 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, -9.5e+95], N[(N[(1.5 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.55e-75], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $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 -9.5 \cdot 10^{+95}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1.5, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{a \cdot 3}\\

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

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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if b < -9.5000000000000004e95

    1. Initial program 47.1

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

      \[\leadsto \frac{\color{blue}{1.5 \cdot \frac{c \cdot a}{b} + -2 \cdot b}}{3 \cdot a} \]
    3. Simplified4.3

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

      [Start]11.0

      \[ \frac{1.5 \cdot \frac{c \cdot a}{b} + -2 \cdot b}{3 \cdot a} \]

      fma-def [=>]11.0

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

      associate-/l* [=>]4.3

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

      *-commutative [=>]4.3

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

    if -9.5000000000000004e95 < b < 1.55000000000000003e-75

    1. Initial program 13.2

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

    if 1.55000000000000003e-75 < b

    1. Initial program 52.9

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

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

      [Start]52.9

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

      *-lft-identity [<=]52.9

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

      metadata-eval [<=]52.9

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

      times-frac [<=]52.9

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

      *-commutative [<=]52.9

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

      times-frac [=>]52.9

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

      associate-*r/ [=>]52.9

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

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

      \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
      Proof

      [Start]9.2

      \[ -0.5 \cdot \frac{c}{b} \]

      associate-*r/ [=>]9.2

      \[ \color{blue}{\frac{-0.5 \cdot c}{b}} \]

      *-commutative [=>]9.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{+95}:\\ \;\;\;\;\frac{\mathsf{fma}\left(1.5, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.55 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error10.3
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -3.6 \cdot 10^{+96}:\\ \;\;\;\;\frac{\mathsf{fma}\left(1.5, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{a \cdot 3}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 2
Error13.5
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-63}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot 2\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{-75}:\\ \;\;\;\;\left(\sqrt{-3 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 3
Error13.6
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2.4 \cdot 10^{-61}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot 2\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-75}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{c \cdot \left(a \cdot -3\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 4
Error13.5
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -3.8 \cdot 10^{-66}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot 2\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 5.8 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(c \cdot a\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 5
Error13.5
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -6 \cdot 10^{-65}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot 2\right) \cdot -0.3333333333333333\\ \mathbf{elif}\;b \leq 4.2 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 6
Error22.7
Cost964
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\left(-1.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot 2\right) \cdot -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 7
Error22.7
Cost836
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + \frac{c}{b} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 8
Error36.4
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 4.5 \cdot 10^{-286}:\\ \;\;\;\;\frac{b}{a} \cdot -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 9
Error22.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.32 \cdot 10^{-284}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 10
Error22.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 7.2 \cdot 10^{-286}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 11
Error22.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.85 \cdot 10^{-289}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 12
Error22.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.25 \cdot 10^{-283}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 13
Error59.3
Cost320
\[\frac{b}{a} \cdot -0.3333333333333333 \]

Error

Reproduce?

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