| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 9760 |
\[e^{-\mathsf{log1p}\left(e^{\frac{-x}{s}}\right)}
\]

(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (/ (- x) s))))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
float code(float x, float s) {
return expf(-log1pf(expf((-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 exp(Float32(-log1p(exp(Float32(Float32(-x) / s))))) end
\frac{1}{1 + e^{\frac{-x}{s}}}
e^{-\mathsf{log1p}\left(e^{\frac{-x}{s}}\right)}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 99.7%
Applied egg-rr99.7%
[Start]99.7% | \[ \frac{1}{1 + e^{\frac{-x}{s}}}
\] |
|---|---|
div-inv [=>]99.6% | \[ \frac{1}{1 + e^{\color{blue}{\left(-x\right) \cdot \frac{1}{s}}}}
\] |
exp-prod [=>]77.1% | \[ \frac{1}{1 + \color{blue}{{\left(e^{-x}\right)}^{\left(\frac{1}{s}\right)}}}
\] |
neg-mul-1 [=>]77.1% | \[ \frac{1}{1 + {\left(e^{\color{blue}{-1 \cdot x}}\right)}^{\left(\frac{1}{s}\right)}}
\] |
exp-prod [=>]77.1% | \[ \frac{1}{1 + {\color{blue}{\left({\left(e^{-1}\right)}^{x}\right)}}^{\left(\frac{1}{s}\right)}}
\] |
pow-pow [=>]99.7% | \[ \frac{1}{1 + \color{blue}{{\left(e^{-1}\right)}^{\left(x \cdot \frac{1}{s}\right)}}}
\] |
div-inv [<=]99.7% | \[ \frac{1}{1 + {\left(e^{-1}\right)}^{\color{blue}{\left(\frac{x}{s}\right)}}}
\] |
Applied egg-rr99.8%
[Start]99.7% | \[ \frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}
\] |
|---|---|
add-exp-log [=>]99.7% | \[ \color{blue}{e^{\log \left(\frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}\right)}}
\] |
log-rec [=>]99.7% | \[ e^{\color{blue}{-\log \left(1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}}
\] |
log1p-udef [<=]99.8% | \[ e^{-\color{blue}{\mathsf{log1p}\left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}}
\] |
Simplified99.8%
[Start]99.8% | \[ e^{-\mathsf{log1p}\left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}
\] |
|---|---|
exp-prod [<=]99.8% | \[ e^{-\mathsf{log1p}\left(\color{blue}{e^{-1 \cdot \frac{x}{s}}}\right)}
\] |
neg-mul-1 [<=]99.8% | \[ e^{-\mathsf{log1p}\left(e^{\color{blue}{-\frac{x}{s}}}\right)}
\] |
distribute-neg-frac [=>]99.8% | \[ e^{-\mathsf{log1p}\left(e^{\color{blue}{\frac{-x}{s}}}\right)}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 9760 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 6656 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 3552 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 3456 |
| Alternative 5 | |
|---|---|
| Accuracy | 62.5% |
| Cost | 548 |
| Alternative 6 | |
|---|---|
| Accuracy | 60.7% |
| Cost | 484 |
| Alternative 7 | |
|---|---|
| Accuracy | 62.2% |
| Cost | 484 |
| Alternative 8 | |
|---|---|
| Accuracy | 54.0% |
| Cost | 356 |
| Alternative 9 | |
|---|---|
| Accuracy | 59.0% |
| Cost | 356 |
| Alternative 10 | |
|---|---|
| Accuracy | 44.7% |
| Cost | 292 |
| Alternative 11 | |
|---|---|
| Accuracy | 43.6% |
| Cost | 260 |
| Alternative 12 | |
|---|---|
| Accuracy | 42.4% |
| Cost | 196 |
| Alternative 13 | |
|---|---|
| Accuracy | 25.2% |
| Cost | 32 |
herbie shell --seed 2023256
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))