| Alternative 1 | |
|---|---|
| Error | 3.1 |
| Cost | 7488 |
\[\mathsf{fma}\left(-0.375, \frac{c \cdot c}{b \cdot \frac{b \cdot b}{a}}, -0.5 \cdot \frac{c}{b}\right)
\]
(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 -3.0)) (+ b (sqrt (fma c (* a -3.0) (* 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 ((c * (a * -3.0)) / (b + sqrt(fma(c, (a * -3.0), (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(c * Float64(a * -3.0)) / Float64(b + sqrt(fma(c, Float64(a * -3.0), Float64(b * 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[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\frac{c \cdot \left(a \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}}{a \cdot 3}
Initial program 52.5
Applied egg-rr52.3
Simplified52.3
[Start]52.3 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
|---|---|
fma-udef [=>]52.2 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + 3 \cdot \left(a \cdot c\right)\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
fma-udef [<=]52.3 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
associate-*r* [=>]52.3 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{\left(3 \cdot a\right) \cdot c}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
*-commutative [=>]52.3 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot 3\right)} \cdot c\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
fma-def [<=]52.3 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot 3\right) \cdot c\right)}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -3\right)}}}}{3 \cdot a}
\] |
+-commutative [=>]52.3 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot 3\right) \cdot c\right)}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -3\right) + b \cdot b}}}}{3 \cdot a}
\] |
fma-def [=>]52.3 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(a \cdot 3\right) \cdot c\right)}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}}}{3 \cdot a}
\] |
Taylor expanded in b around 0 0.5
Simplified0.4
[Start]0.5 | \[ \frac{\frac{-3 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}}{3 \cdot a}
\] |
|---|---|
*-commutative [=>]0.5 | \[ \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot -3}}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}}{3 \cdot a}
\] |
associate-*l* [=>]0.4 | \[ \frac{\frac{\color{blue}{c \cdot \left(a \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}}{3 \cdot a}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 3.1 |
| Cost | 7488 |
| Alternative 2 | |
|---|---|
| Error | 3.1 |
| Cost | 7424 |
| Alternative 3 | |
|---|---|
| Error | 3.2 |
| Cost | 1344 |
| Alternative 4 | |
|---|---|
| Error | 3.3 |
| Cost | 1088 |
| Alternative 5 | |
|---|---|
| Error | 6.4 |
| Cost | 320 |
| Alternative 6 | |
|---|---|
| Error | 6.4 |
| Cost | 320 |
| Alternative 7 | |
|---|---|
| Error | 6.2 |
| Cost | 320 |
| Alternative 8 | |
|---|---|
| Error | 52.0 |
| Cost | 256 |
herbie shell --seed 2023053
(FPCore (a b c)
:name "Cubic critical, wide range"
:precision binary64
:pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))