Average Error: 28.7 → 0.7
Time: 22.3s
Precision: binary64
Cost: 27712
\[\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} \]
\[\frac{\sqrt{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}}{\frac{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{\sqrt{3 \cdot \left(a \cdot c\right)}}} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (/
  (sqrt (+ (* a (* c 3.0)) (- (* b b) (* b b))))
  (/
   (* (* a -3.0) (+ b (sqrt (fma a (* c -3.0) (* b b)))))
   (sqrt (* 3.0 (* a c))))))
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) {
	return sqrt(((a * (c * 3.0)) + ((b * b) - (b * b)))) / (((a * -3.0) * (b + sqrt(fma(a, (c * -3.0), (b * b))))) / sqrt((3.0 * (a * c))));
}
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)
	return Float64(sqrt(Float64(Float64(a * Float64(c * 3.0)) + Float64(Float64(b * b) - Float64(b * b)))) / Float64(Float64(Float64(a * -3.0) * Float64(b + sqrt(fma(a, Float64(c * -3.0), Float64(b * b))))) / sqrt(Float64(3.0 * Float64(a * c)))))
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_] := N[(N[Sqrt[N[(N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(N[(a * -3.0), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(3.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\sqrt{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}}{\frac{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{\sqrt{3 \cdot \left(a \cdot c\right)}}}

Error

Derivation

  1. Initial program 28.7

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

    \[\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.7

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

    remove-double-neg [<=]28.7

    \[ \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.7

    \[ \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.2

    \[ \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.2

    \[ \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.3

    \[ \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.3

    \[ \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.7

    \[ \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.7

    \[ \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.7

    \[ \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.7

    \[ \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.7

    \[ \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.7

    \[ \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.3

    \[ \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.3

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

    associate-*r/ [=>]29.3

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

    associate-*l/ [<=]29.2

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

    distribute-lft-out-- [=>]28.7

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

    *-commutative [=>]28.7

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

    neg-mul-1 [=>]28.7

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

    *-commutative [=>]28.7

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

    associate-/l* [=>]28.7

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

    metadata-eval [=>]28.7

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

    /-rgt-identity [=>]28.7

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

    cancel-sign-sub-inv [=>]28.7

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

    +-commutative [=>]28.7

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

    *-commutative [=>]28.7

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

    distribute-lft-neg-in [=>]28.7

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

    associate-*r* [=>]28.7

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

    *-commutative [=>]28.7

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

    fma-def [=>]28.7

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

    metadata-eval [=>]28.7

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

    associate-/r* [=>]28.7

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

    metadata-eval [=>]28.7

    \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{\color{blue}{-0.3333333333333333}}{a} \]
  3. Applied egg-rr27.8

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

    \[\leadsto \frac{\sqrt{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{\sqrt{\color{blue}{3 \cdot \left(c \cdot a\right)}}}} \]
  5. Applied egg-rr0.7

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

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

Alternatives

Alternative 1
Error8.8
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 -0.023:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{\frac{b \cdot b - t_0}{a}}{b + \sqrt{t_0}}\\ \mathbf{else}:\\ \;\;\;\;-0.375 \cdot \frac{c \cdot c}{\frac{{b}^{3}}{a}} + -0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 2
Error8.8
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 -0.023:\\ \;\;\;\;\left(b \cdot b - t_0\right) \cdot \frac{\frac{-0.3333333333333333}{a}}{b + \sqrt{t_0}}\\ \mathbf{else}:\\ \;\;\;\;-0.375 \cdot \frac{c \cdot c}{\frac{{b}^{3}}{a}} + -0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 3
Error0.7
Cost27200
\[\begin{array}{l} t_0 := \sqrt{3 \cdot \left(a \cdot c\right)}\\ \frac{t_0}{\frac{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{t_0}} \end{array} \]
Alternative 4
Error9.0
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -0.023:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.375 \cdot \frac{c \cdot c}{\frac{{b}^{3}}{a}} + -0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 5
Error9.0
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -0.023:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.375 \cdot \frac{c \cdot c}{\frac{{b}^{3}}{a}} + -0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 6
Error9.0
Cost14852
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -0.023:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{a \cdot \left(c \cdot -3\right) + b \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.375 \cdot \frac{c \cdot c}{\frac{{b}^{3}}{a}} + -0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 7
Error9.4
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 11:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -3\right) + b \cdot b}\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot \left(\frac{-0.5}{b} + -0.375 \cdot \left(c \cdot \frac{a}{{b}^{3}}\right)\right)\\ \end{array} \]
Alternative 8
Error9.4
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 11:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{a \cdot \left(c \cdot -3\right) + b \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \left(\frac{-0.5}{b} + -0.375 \cdot \left(c \cdot \frac{a}{{b}^{3}}\right)\right)\\ \end{array} \]
Alternative 9
Error11.7
Cost7296
\[c \cdot \left(\frac{-0.5}{b} + -0.375 \cdot \left(c \cdot \frac{a}{{b}^{3}}\right)\right) \]
Alternative 10
Error22.7
Cost320
\[c \cdot \frac{-0.5}{b} \]
Alternative 11
Error22.6
Cost320
\[\frac{c \cdot -0.5}{b} \]

Error

Reproduce

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