| Alternative 1 | |
|---|---|
| Error | 0.18% |
| Cost | 3456 |
\[\frac{1}{1 + e^{\frac{-x}{s}}}
\]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
(FPCore (x s) :precision binary32 (/ 1.0 (+ 2.0 (expm1 (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
float code(float x, float s) {
return 1.0f / (2.0f + expm1f((-x / s)));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(2.0) + expm1(Float32(Float32(-x) / s)))) end
\frac{1}{1 + e^{\frac{-x}{s}}}
\frac{1}{2 + \mathsf{expm1}\left(\frac{-x}{s}\right)}
Results
Initial program 0.18
Applied egg-rr0.2
Applied egg-rr0.75
Simplified0.19
[Start]0.75 | \[ {\left(1 + e^{-\frac{x}{s}}\right)}^{-0.5} \cdot {\left(1 + e^{-\frac{x}{s}}\right)}^{-0.5}
\] |
|---|---|
pow-sqr [=>]0.18 | \[ \color{blue}{{\left(1 + e^{-\frac{x}{s}}\right)}^{\left(2 \cdot -0.5\right)}}
\] |
metadata-eval [=>]0.18 | \[ {\left(1 + e^{-\frac{x}{s}}\right)}^{\color{blue}{-1}}
\] |
unpow-1 [=>]0.18 | \[ \color{blue}{\frac{1}{1 + e^{-\frac{x}{s}}}}
\] |
+-commutative [=>]0.18 | \[ \frac{1}{\color{blue}{e^{-\frac{x}{s}} + 1}}
\] |
metadata-eval [<=]0.18 | \[ \frac{1}{e^{-\frac{x}{s}} + \color{blue}{\left(2 - 1\right)}}
\] |
associate--l+ [<=]0.2 | \[ \frac{1}{\color{blue}{\left(e^{-\frac{x}{s}} + 2\right) - 1}}
\] |
+-commutative [<=]0.2 | \[ \frac{1}{\color{blue}{\left(2 + e^{-\frac{x}{s}}\right)} - 1}
\] |
associate--l+ [=>]0.18 | \[ \frac{1}{\color{blue}{2 + \left(e^{-\frac{x}{s}} - 1\right)}}
\] |
mul-1-neg [<=]0.18 | \[ \frac{1}{2 + \left(e^{\color{blue}{-1 \cdot \frac{x}{s}}} - 1\right)}
\] |
expm1-def [=>]0.19 | \[ \frac{1}{2 + \color{blue}{\mathsf{expm1}\left(-1 \cdot \frac{x}{s}\right)}}
\] |
mul-1-neg [=>]0.19 | \[ \frac{1}{2 + \mathsf{expm1}\left(\color{blue}{-\frac{x}{s}}\right)}
\] |
distribute-neg-frac [=>]0.19 | \[ \frac{1}{2 + \mathsf{expm1}\left(\color{blue}{\frac{-x}{s}}\right)}
\] |
Final simplification0.19
| Alternative 1 | |
|---|---|
| Error | 0.18% |
| Cost | 3456 |
| Alternative 2 | |
|---|---|
| Error | 7.71% |
| Cost | 808 |
| Alternative 3 | |
|---|---|
| Error | 6.09% |
| Cost | 808 |
| Alternative 4 | |
|---|---|
| Error | 7.4% |
| Cost | 744 |
| Alternative 5 | |
|---|---|
| Error | 7.18% |
| Cost | 680 |
| Alternative 6 | |
|---|---|
| Error | 8.17% |
| Cost | 552 |
| Alternative 7 | |
|---|---|
| Error | 7.58% |
| Cost | 516 |
| Alternative 8 | |
|---|---|
| Error | 34.81% |
| Cost | 388 |
| Alternative 9 | |
|---|---|
| Error | 51.7% |
| Cost | 356 |
| Alternative 10 | |
|---|---|
| Error | 53.05% |
| Cost | 164 |
| Alternative 11 | |
|---|---|
| Error | 64.53% |
| Cost | 32 |
herbie shell --seed 2023088
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))