?

Average Error: 44.0 → 0.5
Time: 22.2s
Precision: binary64
Cost: 34112

?

\[\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{\mathsf{fma}\left(-2, c \cdot \left(b \cdot b\right), \left(c \cdot c\right) \cdot \left(a \cdot 3\right)\right)}{\left(b + \sqrt{t_0}\right) \cdot \mathsf{fma}\left(b, b, t_0\right)} \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))))
   (/
    (fma -2.0 (* c (* b b)) (* (* c c) (* a 3.0)))
    (* (+ b (sqrt t_0)) (fma b b t_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 t_0 = fma(a, (c * -3.0), (b * b));
	return fma(-2.0, (c * (b * b)), ((c * c) * (a * 3.0))) / ((b + sqrt(t_0)) * fma(b, b, t_0));
}
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(fma(-2.0, Float64(c * Float64(b * b)), Float64(Float64(c * c) * Float64(a * 3.0))) / Float64(Float64(b + sqrt(t_0)) * fma(b, b, t_0)))
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[(-2.0 * N[(c * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(N[(c * c), $MachinePrecision] * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * N[(b * b + t$95$0), $MachinePrecision]), $MachinePrecision]), $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{\mathsf{fma}\left(-2, c \cdot \left(b \cdot b\right), \left(c \cdot c\right) \cdot \left(a \cdot 3\right)\right)}{\left(b + \sqrt{t_0}\right) \cdot \mathsf{fma}\left(b, b, t_0\right)}
\end{array}

Error?

Derivation?

  1. Initial program 44.0

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

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

    [Start]44.0

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

    remove-double-neg [<=]44.0

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

    sub-neg [<=]44.0

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

    div-sub [=>]44.3

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

    neg-mul-1 [=>]44.3

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

    associate-*l/ [<=]44.1

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

    distribute-frac-neg [=>]44.1

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

    fma-neg [=>]43.2

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

    /-rgt-identity [<=]43.2

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

    metadata-eval [<=]43.2

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

    associate-/l* [<=]43.2

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

    *-commutative [<=]43.2

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

    neg-mul-1 [<=]43.2

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

    fma-neg [<=]44.1

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

    neg-mul-1 [=>]44.1

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

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

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

    [Start]43.1

    \[ \frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{\left(\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right) \cdot \left(b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)} \]

    associate-*l* [=>]43.1

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

    associate-/r* [=>]43.1

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

    fma-def [=>]43.1

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

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

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

    [Start]0.5

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

    fma-def [=>]0.5

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

    unpow2 [=>]0.5

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

    *-commutative [=>]0.5

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

    associate-*l* [=>]0.5

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

    unpow2 [=>]0.5

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

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

Alternatives

Alternative 1
Error10.3
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3} \leq -9 \cdot 10^{-9}:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 2
Error10.3
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3} \leq -9 \cdot 10^{-9}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 3
Error10.3
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3} \leq -9 \cdot 10^{-9}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 4
Error0.6
Cost14016
\[\left(3 \cdot \left(c \cdot a\right)\right) \cdot \frac{\frac{-0.3333333333333333}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \]
Alternative 5
Error0.4
Cost14016
\[\frac{\frac{0.3333333333333333 \cdot \frac{c}{a}}{\frac{-0.3333333333333333}{a}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}} \]
Alternative 6
Error6.1
Cost13696
\[\mathsf{fma}\left(-0.375, \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}, \frac{-0.5}{\frac{b}{c}}\right) \]
Alternative 7
Error5.9
Cost13696
\[\mathsf{fma}\left(-0.375, \frac{c \cdot c}{\frac{{b}^{3}}{a}}, -0.5 \cdot \frac{c}{b}\right) \]
Alternative 8
Error11.2
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 8.6 \cdot 10^{-6}:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Error11.9
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023083 
(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)))