?

Average Error: 44.1 → 0.5
Time: 18.5s
Precision: binary64
Cost: 14784

?

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

Error?

Derivation?

  1. Initial program 44.1

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

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

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

    remove-double-neg [<=]44.1

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

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

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

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

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

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

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

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

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

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

    [Start]43.5

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

    associate-/l/ [=>]43.5

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

    /-rgt-identity [<=]43.5

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

    *-commutative [=>]43.5

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

    associate-/l* [=>]43.5

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

    associate-/r/ [=>]43.5

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

    metadata-eval [=>]43.5

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

    *-commutative [<=]43.5

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

    associate-/l/ [=>]43.5

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

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

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

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

Alternatives

Alternative 1
Error5.9
Cost14788
\[\begin{array}{l} t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{if}\;t_0 \leq -300:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}{\left(a \cdot -3\right) \cdot \left(-1.5 \cdot \frac{a \cdot c}{b} + b \cdot 2\right)}\\ \end{array} \]
Alternative 2
Error0.6
Cost14528
\[\frac{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)} \]
Alternative 3
Error0.6
Cost14528
\[\frac{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)} \]
Alternative 4
Error0.5
Cost14016
\[\frac{3 \cdot \left(a \cdot c\right)}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)} \]
Alternative 5
Error4.0
Cost8448
\[\frac{\frac{-0.3333333333333333}{a}}{\left(\frac{\left(a \cdot c\right) \cdot 0.375 - \left(a \cdot c\right) \cdot 0.75}{{b}^{3}} + 0.6666666666666666 \cdot \frac{b}{a \cdot c}\right) + 0.5 \cdot \frac{-1}{b}} \]
Alternative 6
Error6.0
Cost1856
\[\frac{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}{\left(a \cdot -3\right) \cdot \left(-1.5 \cdot \frac{a \cdot c}{b} + b \cdot 2\right)} \]
Alternative 7
Error6.0
Cost960
\[\frac{\frac{-0.3333333333333333}{a}}{\frac{b \cdot 0.6666666666666666}{a \cdot c} + \frac{-0.5}{b}} \]
Alternative 8
Error11.9
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

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