| Alternative 1 | |
|---|---|
| Error | 9.6 |
| Cost | 15684 |
(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 (/ 3.0 c)) (+ b (sqrt (fma b b (* a (* -3.0 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 (-3.0 / (3.0 / c)) / (b + sqrt(fma(b, b, (a * (-3.0 * 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(Float64(-3.0 / Float64(3.0 / c)) / Float64(b + sqrt(fma(b, b, Float64(a * Float64(-3.0 * 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[(-3.0 / N[(3.0 / c), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(a * N[(-3.0 * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\frac{-3}{\frac{3}{c}}}{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-3 \cdot c\right)\right)}}
Initial program 28.4
Simplified28.3
[Start]28.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]28.4 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]28.4 | \[ \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 [<=]28.4 | \[ \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)}}
\] |
*-commutative [<=]28.4 | \[ \frac{\color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot -1}}{-1 \cdot \left(3 \cdot a\right)}
\] |
times-frac [=>]28.4 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot \frac{-1}{3 \cdot a}}
\] |
associate-*r/ [=>]28.4 | \[ \color{blue}{\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot -1}{3 \cdot a}}
\] |
Applied egg-rr27.8
Simplified27.3
[Start]27.8 | \[ \frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right) \cdot \left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b\right)}}{3 \cdot a}
\] |
|---|---|
*-commutative [=>]27.8 | \[ \frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{\color{blue}{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}\right)}}}{3 \cdot a}
\] |
associate-/r* [=>]27.8 | \[ \frac{\color{blue}{\frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}}{3 \cdot a}
\] |
unpow2 [<=]27.8 | \[ \frac{\frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - \color{blue}{{b}^{2}} \cdot \left(b \cdot b\right)}{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
unpow2 [<=]27.8 | \[ \frac{\frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - {b}^{2} \cdot \color{blue}{{b}^{2}}}{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
pow-sqr [=>]27.3 | \[ \frac{\frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - \color{blue}{{b}^{\left(2 \cdot 2\right)}}}{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
metadata-eval [=>]27.3 | \[ \frac{\frac{\frac{{\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\right)}^{2} - {b}^{\color{blue}{4}}}{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right) + b \cdot b}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
Taylor expanded in b around 0 0.6
Simplified0.4
[Start]0.6 | \[ \frac{\frac{-3 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
|---|---|
*-commutative [=>]0.6 | \[ \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot -3}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
associate-*r* [<=]0.4 | \[ \frac{\frac{\color{blue}{c \cdot \left(a \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
Applied egg-rr0.4
Applied egg-rr24.3
Simplified0.3
[Start]24.3 | \[ e^{\mathsf{log1p}\left(\frac{\frac{a \cdot -3}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot c}{3 \cdot a}\right)} - 1
\] |
|---|---|
expm1-def [=>]9.3 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{a \cdot -3}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot c}{3 \cdot a}\right)\right)}
\] |
expm1-log1p [=>]0.4 | \[ \color{blue}{\frac{\frac{a \cdot -3}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot c}{3 \cdot a}}
\] |
associate-/l* [=>]0.4 | \[ \color{blue}{\frac{\frac{a \cdot -3}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{\frac{3 \cdot a}{c}}}
\] |
associate-*l/ [<=]0.6 | \[ \frac{\frac{a \cdot -3}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{\color{blue}{\frac{3}{c} \cdot a}}
\] |
*-rgt-identity [<=]0.6 | \[ \frac{\color{blue}{\frac{a \cdot -3}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}} \cdot 1}}{\frac{3}{c} \cdot a}
\] |
associate-*l/ [=>]0.6 | \[ \frac{\color{blue}{\frac{\left(a \cdot -3\right) \cdot 1}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}}{\frac{3}{c} \cdot a}
\] |
associate-*r/ [<=]0.6 | \[ \frac{\color{blue}{\left(a \cdot -3\right) \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}}{\frac{3}{c} \cdot a}
\] |
associate-*l/ [<=]0.6 | \[ \color{blue}{\frac{a \cdot -3}{\frac{3}{c} \cdot a} \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}
\] |
associate-*r/ [=>]0.5 | \[ \color{blue}{\frac{\frac{a \cdot -3}{\frac{3}{c} \cdot a} \cdot 1}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}
\] |
associate-*l/ [=>]0.5 | \[ \frac{\color{blue}{\frac{\left(a \cdot -3\right) \cdot 1}{\frac{3}{c} \cdot a}}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}
\] |
associate-*l* [=>]0.5 | \[ \frac{\frac{\color{blue}{a \cdot \left(-3 \cdot 1\right)}}{\frac{3}{c} \cdot a}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}
\] |
metadata-eval [=>]0.5 | \[ \frac{\frac{a \cdot \color{blue}{-3}}{\frac{3}{c} \cdot a}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 9.6 |
| Cost | 15684 |
| Alternative 2 | |
|---|---|
| Error | 9.6 |
| Cost | 15684 |
| Alternative 3 | |
|---|---|
| Error | 9.7 |
| Cost | 14788 |
| Alternative 4 | |
|---|---|
| Error | 0.4 |
| Cost | 13632 |
| Alternative 5 | |
|---|---|
| Error | 9.4 |
| Cost | 7492 |
| Alternative 6 | |
|---|---|
| Error | 11.6 |
| Cost | 1344 |
| Alternative 7 | |
|---|---|
| Error | 11.6 |
| Cost | 832 |
| Alternative 8 | |
|---|---|
| Error | 22.9 |
| Cost | 320 |
| Alternative 9 | |
|---|---|
| Error | 62.0 |
| Cost | 64 |
herbie shell --seed 2023187
(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)))