| Alternative 1 | |
|---|---|
| Error | 0.1 |
| 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.1
Applied egg-rr0.1
Applied egg-rr0.1
Applied egg-rr0.3
Simplified0.1
[Start]0.3 | \[ e^{\mathsf{log1p}\left(\frac{1}{e^{\frac{x}{s} \cdot -1} + 1}\right)} - 1
\] |
|---|---|
expm1-def [=>]0.1 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{e^{\frac{x}{s} \cdot -1} + 1}\right)\right)}
\] |
expm1-log1p [=>]0.1 | \[ \color{blue}{\frac{1}{e^{\frac{x}{s} \cdot -1} + 1}}
\] |
metadata-eval [<=]0.1 | \[ \frac{1}{e^{\frac{x}{s} \cdot -1} + \color{blue}{\left(-1 + 2\right)}}
\] |
associate-+l+ [<=]0.1 | \[ \frac{1}{\color{blue}{\left(e^{\frac{x}{s} \cdot -1} + -1\right) + 2}}
\] |
metadata-eval [<=]0.1 | \[ \frac{1}{\left(e^{\frac{x}{s} \cdot -1} + \color{blue}{\left(-1\right)}\right) + 2}
\] |
sub-neg [<=]0.1 | \[ \frac{1}{\color{blue}{\left(e^{\frac{x}{s} \cdot -1} - 1\right)} + 2}
\] |
+-commutative [<=]0.1 | \[ \frac{1}{\color{blue}{2 + \left(e^{\frac{x}{s} \cdot -1} - 1\right)}}
\] |
*-commutative [<=]0.1 | \[ \frac{1}{2 + \left(e^{\color{blue}{-1 \cdot \frac{x}{s}}} - 1\right)}
\] |
expm1-def [=>]0.1 | \[ \frac{1}{2 + \color{blue}{\mathsf{expm1}\left(-1 \cdot \frac{x}{s}\right)}}
\] |
associate-*r/ [=>]0.1 | \[ \frac{1}{2 + \mathsf{expm1}\left(\color{blue}{\frac{-1 \cdot x}{s}}\right)}
\] |
neg-mul-1 [<=]0.1 | \[ \frac{1}{2 + \mathsf{expm1}\left(\frac{\color{blue}{-x}}{s}\right)}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 3456 |
| Alternative 2 | |
|---|---|
| Error | 10.0 |
| Cost | 196 |
| Alternative 3 | |
|---|---|
| Error | 20.9 |
| Cost | 32 |
herbie shell --seed 2023237
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))