| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 14016 |
\[\frac{\frac{-3 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-3 \cdot a\right)\right)}}}{a \cdot 3}
\]
(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 c) a) (+ b (sqrt (fma b b (* c (* -3.0 a)))))) (* 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 (((-3.0 * c) * a) / (b + sqrt(fma(b, b, (c * (-3.0 * a)))))) / (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(Float64(-3.0 * c) * a) / Float64(b + sqrt(fma(b, b, Float64(c * Float64(-3.0 * a)))))) / 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[(N[(-3.0 * c), $MachinePrecision] * a), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(c * N[(-3.0 * a), $MachinePrecision]), $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{\left(-3 \cdot c\right) \cdot a}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-3 \cdot a\right)\right)}}}{a \cdot 3}
Initial program 31.3%
Applied egg-rr32.1%
[Start]31.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
+-commutative [=>]31.3 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}}{3 \cdot a}
\] |
flip-+ [=>]31.3 | \[ \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right)}}}{3 \cdot a}
\] |
add-sqr-sqrt [<=]32.2 | \[ \frac{\frac{\color{blue}{\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right)}}{3 \cdot a}
\] |
sqr-neg [=>]32.2 | \[ \frac{\frac{\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right) - \color{blue}{b \cdot b}}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right)}}{3 \cdot a}
\] |
associate--l- [=>]32.2 | \[ \frac{\frac{\color{blue}{b \cdot b - \left(\left(3 \cdot a\right) \cdot c + b \cdot b\right)}}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right)}}{3 \cdot a}
\] |
+-commutative [<=]32.2 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + \left(3 \cdot a\right) \cdot c\right)}}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right)}}{3 \cdot a}
\] |
fma-def [=>]32.1 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(b, b, \left(3 \cdot a\right) \cdot c\right)}}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right)}}{3 \cdot a}
\] |
associate-*l* [=>]32.1 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{3 \cdot \left(a \cdot c\right)}\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right)}}{3 \cdot a}
\] |
add-sqr-sqrt [=>]0.0 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{\sqrt{-b} \cdot \sqrt{-b}}}}{3 \cdot a}
\] |
sqrt-unprod [=>]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}}}}{3 \cdot a}
\] |
sqr-neg [=>]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \sqrt{\color{blue}{b \cdot b}}}}{3 \cdot a}
\] |
sqrt-prod [=>]1.6 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{\sqrt{b} \cdot \sqrt{b}}}}{3 \cdot a}
\] |
add-sqr-sqrt [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{b}}}{3 \cdot a}
\] |
unsub-neg [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}}}{3 \cdot a}
\] |
+-commutative [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 3 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}
\] |
Taylor expanded in b around 0 99.2%
Simplified99.2%
[Start]99.2 | \[ \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}
\] |
|---|---|
associate-*r* [=>]99.2 | \[ \frac{\frac{\color{blue}{\left(-3 \cdot c\right) \cdot a}}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}}{3 \cdot a}
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 14016 |
| Alternative 2 | |
|---|---|
| Accuracy | 91.0% |
| Cost | 832 |
| Alternative 3 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Accuracy | 81.4% |
| Cost | 320 |
herbie shell --seed 2023138
(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)))