| Alternative 1 | |
|---|---|
| Error | 8.8 |
| Cost | 28228 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c) :precision binary64 (/ (sqrt (+ (* a (* c 3.0)) (- (* b b) (* b b)))) (/ (* (* a -3.0) (+ b (sqrt (fma a (* c -3.0) (* b b))))) (sqrt (* 3.0 (* a 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 sqrt(((a * (c * 3.0)) + ((b * b) - (b * b)))) / (((a * -3.0) * (b + sqrt(fma(a, (c * -3.0), (b * b))))) / sqrt((3.0 * (a * 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(sqrt(Float64(Float64(a * Float64(c * 3.0)) + Float64(Float64(b * b) - Float64(b * b)))) / Float64(Float64(Float64(a * -3.0) * Float64(b + sqrt(fma(a, Float64(c * -3.0), Float64(b * b))))) / sqrt(Float64(3.0 * Float64(a * 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[Sqrt[N[(N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(N[(a * -3.0), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(3.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{\sqrt{a \cdot \left(c \cdot 3\right) + \left(b \cdot b - b \cdot b\right)}}{\frac{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}{\sqrt{3 \cdot \left(a \cdot c\right)}}}
Initial program 28.7
Simplified28.7
[Start]28.7 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]28.7 | \[ \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.7 | \[ \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.2 | \[ \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.2 | \[ \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.3 | \[ \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.3 | \[ \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.7 | \[ \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.7 | \[ \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.7 | \[ \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.7 | \[ \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.7 | \[ \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.7 | \[ \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.3 | \[ \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.3 | \[ \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}}
\] |
associate-*r/ [=>]29.3 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{\frac{-1 \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
associate-*l/ [<=]29.2 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{\frac{-1}{3 \cdot a} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}
\] |
distribute-lft-out-- [=>]28.7 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \left(\frac{-b}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}
\] |
*-commutative [=>]28.7 | \[ \color{blue}{\left(\frac{-b}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}}
\] |
neg-mul-1 [=>]28.7 | \[ \left(\frac{\color{blue}{-1 \cdot b}}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]28.7 | \[ \left(\frac{\color{blue}{b \cdot -1}}{-1} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-/l* [=>]28.7 | \[ \left(\color{blue}{\frac{b}{\frac{-1}{-1}}} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
metadata-eval [=>]28.7 | \[ \left(\frac{b}{\color{blue}{1}} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
/-rgt-identity [=>]28.7 | \[ \left(\color{blue}{b} - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{-1}{3 \cdot a}
\] |
cancel-sign-sub-inv [=>]28.7 | \[ \left(b - \sqrt{\color{blue}{b \cdot b + \left(-3 \cdot a\right) \cdot c}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
+-commutative [=>]28.7 | \[ \left(b - \sqrt{\color{blue}{\left(-3 \cdot a\right) \cdot c + b \cdot b}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]28.7 | \[ \left(b - \sqrt{\color{blue}{c \cdot \left(-3 \cdot a\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
distribute-lft-neg-in [=>]28.7 | \[ \left(b - \sqrt{c \cdot \color{blue}{\left(\left(-3\right) \cdot a\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-*r* [=>]28.7 | \[ \left(b - \sqrt{\color{blue}{\left(c \cdot \left(-3\right)\right) \cdot a} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
*-commutative [=>]28.7 | \[ \left(b - \sqrt{\color{blue}{a \cdot \left(c \cdot \left(-3\right)\right)} + b \cdot b}\right) \cdot \frac{-1}{3 \cdot a}
\] |
fma-def [=>]28.7 | \[ \left(b - \sqrt{\color{blue}{\mathsf{fma}\left(a, c \cdot \left(-3\right), b \cdot b\right)}}\right) \cdot \frac{-1}{3 \cdot a}
\] |
metadata-eval [=>]28.7 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot \color{blue}{-3}, b \cdot b\right)}\right) \cdot \frac{-1}{3 \cdot a}
\] |
associate-/r* [=>]28.7 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \color{blue}{\frac{\frac{-1}{3}}{a}}
\] |
metadata-eval [=>]28.7 | \[ \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{\color{blue}{-0.3333333333333333}}{a}
\] |
Applied egg-rr27.8
Taylor expanded in b around 0 27.0
Applied egg-rr0.7
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 8.8 |
| Cost | 28228 |
| Alternative 2 | |
|---|---|
| Error | 8.8 |
| Cost | 28228 |
| Alternative 3 | |
|---|---|
| Error | 0.7 |
| Cost | 27200 |
| Alternative 4 | |
|---|---|
| Error | 9.0 |
| Cost | 21060 |
| Alternative 5 | |
|---|---|
| Error | 9.0 |
| Cost | 21060 |
| Alternative 6 | |
|---|---|
| Error | 9.0 |
| Cost | 14852 |
| Alternative 7 | |
|---|---|
| Error | 9.4 |
| Cost | 7492 |
| Alternative 8 | |
|---|---|
| Error | 9.4 |
| Cost | 7492 |
| Alternative 9 | |
|---|---|
| Error | 11.7 |
| Cost | 7296 |
| Alternative 10 | |
|---|---|
| Error | 22.7 |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Error | 22.6 |
| Cost | 320 |
herbie shell --seed 2022349
(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)))