?

Average Error: 28.5 → 0.8
Time: 26.1s
Precision: binary64
Cost: 40960

?

\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\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)\\ \left(\frac{\mathsf{fma}\left(6, c \cdot \left(b \cdot \left(b \cdot a\right)\right), {\left(c \cdot a\right)}^{2} \cdot -9\right)}{b + \sqrt{t_0}} \cdot \frac{1}{\mathsf{fma}\left(b, b, t_0\right)}\right) \cdot \frac{-0.3333333333333333}{a} \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 6.0 (* c (* b (* b a))) (* (pow (* c a) 2.0) -9.0))
      (+ b (sqrt t_0)))
     (/ 1.0 (fma b b t_0)))
    (/ -0.3333333333333333 a))))
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(6.0, (c * (b * (b * a))), (pow((c * a), 2.0) * -9.0)) / (b + sqrt(t_0))) * (1.0 / fma(b, b, t_0))) * (-0.3333333333333333 / a);
}
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(fma(6.0, Float64(c * Float64(b * Float64(b * a))), Float64((Float64(c * a) ^ 2.0) * -9.0)) / Float64(b + sqrt(t_0))) * Float64(1.0 / fma(b, b, t_0))) * Float64(-0.3333333333333333 / a))
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[(6.0 * N[(c * N[(b * N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(c * a), $MachinePrecision], 2.0], $MachinePrecision] * -9.0), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(b * b + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-0.3333333333333333 / a), $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)\\
\left(\frac{\mathsf{fma}\left(6, c \cdot \left(b \cdot \left(b \cdot a\right)\right), {\left(c \cdot a\right)}^{2} \cdot -9\right)}{b + \sqrt{t_0}} \cdot \frac{1}{\mathsf{fma}\left(b, b, t_0\right)}\right) \cdot \frac{-0.3333333333333333}{a}
\end{array}

Error?

Derivation?

  1. Initial program 28.5

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

    \[\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]28.5

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

    remove-double-neg [<=]28.5

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

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

    div-sub [=>]29.0

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

    \[ \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/ [<=]29.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 [=>]29.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 [=>]28.5

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

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

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

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

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

    \[ \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 [<=]29.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 [=>]29.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-rr27.7

    \[\leadsto \color{blue}{\frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{\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)}} \cdot \frac{-0.3333333333333333}{a} \]
  4. Taylor expanded in b around 0 0.8

    \[\leadsto \frac{\color{blue}{6 \cdot \left(c \cdot \left(a \cdot {b}^{2}\right)\right) + -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)}}{\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)} \cdot \frac{-0.3333333333333333}{a} \]
  5. Applied egg-rr0.8

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

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

Alternatives

Alternative 1
Error0.8
Cost40960
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \frac{-0.3333333333333333}{a} \cdot \left(\frac{1}{b + \sqrt{t_0}} \cdot \frac{\mathsf{fma}\left(6, c \cdot \left(b \cdot \left(b \cdot a\right)\right), {\left(c \cdot a\right)}^{2} \cdot -9\right)}{\mathsf{fma}\left(b, b, t_0\right)}\right) \end{array} \]
Alternative 2
Error0.8
Cost34624
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \frac{-0.3333333333333333}{a} \cdot \frac{6 \cdot \left(c \cdot \left(a \cdot {b}^{2}\right)\right) + {\left(c \cdot a\right)}^{2} \cdot -9}{\left(b + \sqrt{t_0}\right) \cdot \left(b \cdot b + t_0\right)} \end{array} \]
Alternative 3
Error0.7
Cost28352
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \frac{-0.3333333333333333}{a} \cdot \frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \left(b \cdot b\right)\right), \left(c \cdot a\right) \cdot \left(\left(c \cdot a\right) \cdot -9\right)\right)}{\left(b + \sqrt{t_0}\right) \cdot \left(b \cdot b + t_0\right)} \end{array} \]
Alternative 4
Error6.4
Cost28228
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -3:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{\frac{b \cdot b - t_0}{a}}{b + \sqrt{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right) + c \cdot \left(\frac{a \cdot a}{{b}^{3}} \cdot -0.375\right)}\\ \end{array} \]
Alternative 5
Error6.4
Cost28228
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -3:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b \cdot b - t_0}{a \cdot \left(b + \sqrt{t_0}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right) + c \cdot \left(\frac{a \cdot a}{{b}^{3}} \cdot -0.375\right)}\\ \end{array} \]
Alternative 6
Error6.4
Cost28228
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -3:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot \left(b \cdot b - t_0\right)}{a \cdot \left(b + \sqrt{t_0}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right) + c \cdot \left(\frac{a \cdot a}{{b}^{3}} \cdot -0.375\right)}\\ \end{array} \]
Alternative 7
Error6.4
Cost21636
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -3:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right) + c \cdot \left(\frac{a \cdot a}{{b}^{3}} \cdot -0.375\right)}\\ \end{array} \]
Alternative 8
Error9.3
Cost13764
\[\begin{array}{l} \mathbf{if}\;b \leq 48:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
Alternative 9
Error9.3
Cost13764
\[\begin{array}{l} \mathbf{if}\;b \leq 49:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
Alternative 10
Error9.3
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 48:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
Alternative 11
Error9.3
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 49:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
Alternative 12
Error11.6
Cost7104
\[\frac{-0.3333333333333333}{\mathsf{fma}\left(0.6666666666666666, \frac{b}{c}, -0.5 \cdot \frac{a}{b}\right)} \]
Alternative 13
Error11.6
Cost832
\[\frac{-0.3333333333333333}{-0.5 \cdot \frac{a}{b} + 0.6666666666666666 \cdot \frac{b}{c}} \]
Alternative 14
Error22.9
Cost320
\[-0.5 \cdot \frac{c}{b} \]
Alternative 15
Error62.0
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023027 
(FPCore (a b c)
  :name "Cubic critical, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))