?

Average Error: 43.8 → 0.4
Time: 20.7s
Precision: binary64
Cost: 13952

?

\[\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} \]
\[\frac{\frac{-c}{a}}{\frac{b}{a} + \frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a}} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (/ (/ (- c) a) (+ (/ b a) (/ (sqrt (fma a (* c -3.0) (* b b))) 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) {
	return (-c / a) / ((b / a) + (sqrt(fma(a, (c * -3.0), (b * b))) / 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)
	return Float64(Float64(Float64(-c) / a) / Float64(Float64(b / a) + Float64(sqrt(fma(a, Float64(c * -3.0), Float64(b * b))) / 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_] := N[(N[((-c) / a), $MachinePrecision] / N[(N[(b / a), $MachinePrecision] + N[(N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\frac{-c}{a}}{\frac{b}{a} + \frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a}}

Error?

Derivation?

  1. Initial program 43.8

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

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

    [Start]43.8

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

    *-lft-identity [<=]43.8

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

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

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

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

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

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

    *-commutative [=>]43.8

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

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

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

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

    [Start]0.4

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

    mul-1-neg [=>]0.4

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

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

Alternatives

Alternative 1
Error5.8
Cost21316
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3} \leq -2000:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{1}{b - \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}}}{-3}}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.375, \frac{c \cdot c}{\frac{{b}^{3}}{a}}, -0.5 \cdot \frac{c}{b}\right)\\ \end{array} \]
Alternative 2
Error5.8
Cost21124
\[\begin{array}{l} t_0 := c \cdot \left(a \cdot -3\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + t_0} - b}{a \cdot 3} \leq -2000:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.375, \frac{c \cdot c}{\frac{{b}^{3}}{a}}, -0.5 \cdot \frac{c}{b}\right)\\ \end{array} \]
Alternative 3
Error10.2
Cost21060
\[\begin{array}{l} t_0 := c \cdot \left(a \cdot -3\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + t_0} - b}{a \cdot 3} \leq -2 \cdot 10^{-10}:\\ \;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(b, b, t_0\right)}\right) \cdot \frac{-0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 4
Error10.2
Cost21060
\[\begin{array}{l} t_0 := c \cdot \left(a \cdot -3\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + t_0} - b}{a \cdot 3} \leq -2 \cdot 10^{-10}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 5
Error10.2
Cost14916
\[\begin{array}{l} t_0 := \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}\\ \mathbf{if}\;\frac{t_0 - b}{a \cdot 3} \leq -2 \cdot 10^{-10}:\\ \;\;\;\;\frac{\frac{1}{a} \cdot \left(b - t_0\right)}{-3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 6
Error10.2
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3} \leq -2 \cdot 10^{-10}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + -3 \cdot \left(c \cdot a\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 7
Error11.4
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 0.062:\\ \;\;\;\;\frac{-0.3333333333333333}{a} \cdot \left(b - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 8
Error57.3
Cost320
\[\frac{b}{a} \cdot -0.1111111111111111 \]
Alternative 9
Error12.2
Cost320
\[c \cdot \frac{-0.5}{b} \]
Alternative 10
Error12.1
Cost320
\[\frac{c \cdot -0.5}{b} \]

Error

Reproduce?

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