| Alternative 1 | |
|---|---|
| Error | 9.1 |
| Cost | 14788 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c) :precision binary64 (/ -3.0 (/ (+ b (sqrt (fma a (* -3.0 c) (* b b)))) (/ c 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 -3.0 / ((b + sqrt(fma(a, (-3.0 * c), (b * b)))) / (c / 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(-3.0 / Float64(Float64(b + sqrt(fma(a, Float64(-3.0 * c), Float64(b * b)))) / Float64(c / 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[(-3.0 / N[(N[(b + N[Sqrt[N[(a * N[(-3.0 * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(c / 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{-3}{\frac{b + \sqrt{\mathsf{fma}\left(a, -3 \cdot c, b \cdot b\right)}}{\frac{c}{3}}}
Initial program 28.9
Simplified28.9
[Start]28.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]28.9 | \[ \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.9 | \[ \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.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 [=>]29.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/ [<=]29.4 | \[ \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.4 | \[ \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.9 | \[ \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.9 | \[ \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.9 | \[ \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.9 | \[ \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.9 | \[ \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.9 | \[ \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.4 | \[ \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.4 | \[ \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}}
\] |
Applied egg-rr27.9
Taylor expanded in b around 0 0.6
Applied egg-rr0.6
Simplified0.4
[Start]0.6 | \[ \left(\left(c \cdot a\right) \cdot -3\right) \cdot \frac{1}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}
\] |
|---|---|
associate-*r/ [=>]0.6 | \[ \color{blue}{\frac{\left(\left(c \cdot a\right) \cdot -3\right) \cdot 1}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}}
\] |
associate-*l* [=>]0.6 | \[ \frac{\color{blue}{\left(c \cdot a\right) \cdot \left(-3 \cdot 1\right)}}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}
\] |
metadata-eval [=>]0.6 | \[ \frac{\left(c \cdot a\right) \cdot \color{blue}{-3}}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}
\] |
metadata-eval [<=]0.6 | \[ \frac{\left(c \cdot a\right) \cdot \color{blue}{\left(-3\right)}}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}
\] |
distribute-rgt-neg-in [<=]0.6 | \[ \frac{\color{blue}{-\left(c \cdot a\right) \cdot 3}}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}
\] |
*-commutative [<=]0.6 | \[ \frac{-\color{blue}{3 \cdot \left(c \cdot a\right)}}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}
\] |
distribute-neg-frac [<=]0.6 | \[ \color{blue}{-\frac{3 \cdot \left(c \cdot a\right)}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}}
\] |
associate-/l* [=>]0.6 | \[ -\color{blue}{\frac{3}{\frac{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}{c \cdot a}}}
\] |
distribute-neg-frac [=>]0.6 | \[ \color{blue}{\frac{-3}{\frac{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}{c \cdot a}}}
\] |
metadata-eval [=>]0.6 | \[ \frac{\color{blue}{-3}}{\frac{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(-a \cdot -3\right)}{c \cdot a}}
\] |
associate-/l* [=>]0.6 | \[ \frac{-3}{\color{blue}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{c \cdot a}{-a \cdot -3}}}}
\] |
distribute-rgt-neg-in [=>]0.6 | \[ \frac{-3}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{c \cdot a}{\color{blue}{a \cdot \left(--3\right)}}}}
\] |
metadata-eval [=>]0.6 | \[ \frac{-3}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\frac{c \cdot a}{a \cdot \color{blue}{3}}}}
\] |
associate-/r* [=>]0.5 | \[ \frac{-3}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\color{blue}{\frac{\frac{c \cdot a}{a}}{3}}}}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 9.1 |
| Cost | 14788 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 13632 |
| Alternative 3 | |
|---|---|
| Error | 0.6 |
| Cost | 7744 |
| Alternative 4 | |
|---|---|
| Error | 11.0 |
| Cost | 832 |
| Alternative 5 | |
|---|---|
| Error | 22.5 |
| Cost | 320 |
| Alternative 6 | |
|---|---|
| Error | 22.5 |
| Cost | 320 |
| Alternative 7 | |
|---|---|
| Error | 22.4 |
| Cost | 320 |
herbie shell --seed 2023057
(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)))