?

Average Error: 43.6 → 0.7
Time: 20.9s
Precision: binary64
Cost: 41216

?

\[\left(\left(1.1102230246251565 \cdot 10^{-16} < a \land a < 9007199254740992\right) \land \left(1.1102230246251565 \cdot 10^{-16} < b \land b < 9007199254740992\right)\right) \land \left(1.1102230246251565 \cdot 10^{-16} < c \land c < 9007199254740992\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \frac{\frac{\left(6 \cdot \left(c \cdot \left(a \cdot {b}^{2}\right)\right) + -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right) \cdot \frac{1}{b + \sqrt{t_0}}}{b \cdot b + t_0}}{a} \cdot -0.3333333333333333 \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
 (let* ((t_0 (fma a (* c -3.0) (* b b))))
   (*
    (/
     (/
      (*
       (+ (* 6.0 (* c (* a (pow b 2.0)))) (* -9.0 (* (pow c 2.0) (pow a 2.0))))
       (/ 1.0 (+ b (sqrt t_0))))
      (+ (* b b) t_0))
     a)
    -0.3333333333333333)))
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 t_0 = fma(a, (c * -3.0), (b * b));
	return (((((6.0 * (c * (a * pow(b, 2.0)))) + (-9.0 * (pow(c, 2.0) * pow(a, 2.0)))) * (1.0 / (b + sqrt(t_0)))) / ((b * b) + t_0)) / a) * -0.3333333333333333;
}
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)
	t_0 = fma(a, Float64(c * -3.0), Float64(b * b))
	return Float64(Float64(Float64(Float64(Float64(Float64(6.0 * Float64(c * Float64(a * (b ^ 2.0)))) + Float64(-9.0 * Float64((c ^ 2.0) * (a ^ 2.0)))) * Float64(1.0 / Float64(b + sqrt(t_0)))) / Float64(Float64(b * b) + t_0)) / a) * -0.3333333333333333)
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_] := Block[{t$95$0 = N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(N[(N[(6.0 * N[(c * N[(a * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-9.0 * N[(N[Power[c, 2.0], $MachinePrecision] * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] * -0.3333333333333333), $MachinePrecision]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\
\frac{\frac{\left(6 \cdot \left(c \cdot \left(a \cdot {b}^{2}\right)\right) + -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right) \cdot \frac{1}{b + \sqrt{t_0}}}{b \cdot b + t_0}}{a} \cdot -0.3333333333333333
\end{array}

Error?

Derivation?

  1. Initial program 43.6

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

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

    [Start]43.6

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

    *-lft-identity [<=]43.6

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

    metadata-eval [<=]43.6

    \[ \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 [<=]43.6

    \[ \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)}} \]

    neg-mul-1 [<=]43.6

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

    distribute-rgt-neg-in [=>]43.6

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

    times-frac [=>]43.6

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

    *-commutative [=>]43.6

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

    \[\leadsto \frac{\color{blue}{\frac{\left({b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}\right) \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a} \cdot -0.3333333333333333 \]
  4. Taylor expanded in b around 0 0.7

    \[\leadsto \frac{\frac{\color{blue}{\left(6 \cdot \left(c \cdot \left(a \cdot {b}^{2}\right)\right) + -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)} \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a} \cdot -0.3333333333333333 \]
  5. Final simplification0.7

    \[\leadsto \frac{\frac{\left(6 \cdot \left(c \cdot \left(a \cdot {b}^{2}\right)\right) + -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right) \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a} \cdot -0.3333333333333333 \]

Alternatives

Alternative 1
Error0.7
Cost28352
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ -0.3333333333333333 \cdot \frac{\frac{\frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \left(b \cdot b\right)\right), -9 \cdot \left(a \cdot \left(c \cdot \left(c \cdot a\right)\right)\right)\right)}{b + \sqrt{t_0}}}{b \cdot b + t_0}}{a} \end{array} \]
Alternative 2
Error4.3
Cost14912
\[-0.3333333333333333 \cdot \frac{\frac{\mathsf{fma}\left(3, c \cdot \left(a \cdot b\right), \left(c \cdot c\right) \cdot \left(-2.25 \cdot \frac{a \cdot a}{b}\right)\right)}{b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a} \]
Alternative 3
Error4.3
Cost14912
\[-0.3333333333333333 \cdot \frac{\frac{\mathsf{fma}\left(3, b \cdot \left(c \cdot a\right), \left(c \cdot c\right) \cdot \frac{-2.25 \cdot \left(a \cdot a\right)}{b}\right)}{b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a} \]
Alternative 4
Error10.8
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3} \leq -30:\\ \;\;\;\;\left(b - \sqrt{b \cdot b + -3 \cdot \left(c \cdot a\right)}\right) \cdot \frac{-0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 5
Error6.3
Cost13696
\[\mathsf{fma}\left(-0.375, \frac{c \cdot c}{\frac{{b}^{3}}{a}}, -0.5 \cdot \frac{c}{b}\right) \]
Alternative 6
Error6.5
Cost7680
\[\begin{array}{l} t_0 := c \cdot \frac{a}{b}\\ \frac{-0.5 \cdot t_0 + -0.375 \cdot \frac{{t_0}^{2}}{b}}{a} \end{array} \]
Alternative 7
Error12.3
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023066 
(FPCore (a b c)
  :name "Cubic critical, medium range"
  :precision binary64
  :pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))