| Alternative 1 | |
|---|---|
| Accuracy | 85.7% |
| 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 (/ (- c) (+ b (sqrt (fma c (* a -3.0) (* b b))))))
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 / (b + sqrt(fma(c, (a * -3.0), (b * b))));
}
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(-c) / Float64(b + sqrt(fma(c, Float64(a * -3.0), Float64(b * b))))) 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[((-c) / N[(b + N[Sqrt[N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{-c}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}
Initial program 55.2%
Simplified55.2%
[Start]55.2 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]55.2 | \[ \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 [<=]55.2 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]54.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 [=>]54.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/ [<=]54.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 [=>]54.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 [=>]55.2 | \[ \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 [<=]55.2 | \[ \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 [<=]55.2 | \[ \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* [<=]55.2 | \[ \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 [<=]55.2 | \[ \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 [<=]55.2 | \[ \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 [<=]54.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 [=>]54.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-rr56.7%
Taylor expanded in b around 0 99.1%
Applied egg-rr61.8%
Simplified99.6%
[Start]61.8 | \[ e^{\mathsf{log1p}\left(\frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)} \cdot -1\right)} - 1
\] |
|---|---|
expm1-def [=>]85.0 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)} \cdot -1\right)\right)}
\] |
expm1-log1p [=>]99.3 | \[ \color{blue}{\frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)} \cdot -1}
\] |
*-commutative [=>]99.3 | \[ \color{blue}{-1 \cdot \frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
mul-1-neg [=>]99.3 | \[ \color{blue}{-\frac{c \cdot a}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
associate-/r* [=>]99.5 | \[ -\color{blue}{\frac{\frac{c \cdot a}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
associate-/l* [=>]99.6 | \[ -\frac{\color{blue}{\frac{c}{\frac{a}{a}}}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-/l/ [=>]99.6 | \[ -\color{blue}{\frac{c}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{a}{a}}}
\] |
*-inverses [=>]99.6 | \[ -\frac{c}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \color{blue}{1}}
\] |
*-rgt-identity [=>]99.6 | \[ -\frac{c}{\color{blue}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
remove-double-neg [<=]99.6 | \[ -\frac{c}{\color{blue}{-\left(-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}
\] |
remove-double-neg [=>]99.6 | \[ -\frac{c}{\color{blue}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}
\] |
unpow2 [<=]99.6 | \[ -\frac{c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, \color{blue}{{b}^{2}}\right)}}
\] |
fma-udef [=>]99.6 | \[ -\frac{c}{b + \sqrt{\color{blue}{a \cdot \left(c \cdot -3\right) + {b}^{2}}}}
\] |
*-commutative [=>]99.6 | \[ -\frac{c}{b + \sqrt{a \cdot \color{blue}{\left(-3 \cdot c\right)} + {b}^{2}}}
\] |
associate-*l* [<=]99.6 | \[ -\frac{c}{b + \sqrt{\color{blue}{\left(a \cdot -3\right) \cdot c} + {b}^{2}}}
\] |
*-commutative [=>]99.6 | \[ -\frac{c}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -3\right)} + {b}^{2}}}
\] |
fma-def [=>]99.6 | \[ -\frac{c}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -3, {b}^{2}\right)}}}
\] |
unpow2 [=>]99.6 | \[ -\frac{c}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -3, \color{blue}{b \cdot b}\right)}}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 85.7% |
| Cost | 14788 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 7680 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.5% |
| Cost | 7492 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.5% |
| Cost | 7492 |
| Alternative 5 | |
|---|---|
| Accuracy | 82.3% |
| Cost | 832 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.6% |
| Cost | 320 |
herbie shell --seed 2023122
(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)))