
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (pow (exp 2.0) (* -0.5 (log1p (exp (- (/ x s)))))))
float code(float x, float s) {
return powf(expf(2.0f), (-0.5f * log1pf(expf(-(x / s)))));
}
function code(x, s) return exp(Float32(2.0)) ^ Float32(Float32(-0.5) * log1p(exp(Float32(-Float32(x / s))))) end
\begin{array}{l}
\\
{\left(e^{2}\right)}^{\left(-0.5 \cdot \mathsf{log1p}\left(e^{-\frac{x}{s}}\right)\right)}
\end{array}
Initial program 99.8%
lift-/.f32N/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
log-powN/A
inv-powN/A
lift-/.f32N/A
lower-exp.f32N/A
lift-/.f32N/A
log-recN/A
lower-neg.f32N/A
lift-+.f32N/A
lower-log1p.f3299.8
Applied rewrites99.8%
lift-exp.f32N/A
lift-neg.f32N/A
lift-log1p.f32N/A
lift-+.f32N/A
neg-logN/A
inv-powN/A
metadata-evalN/A
pow-powN/A
lift-pow.f32N/A
log-powN/A
exp-prodN/A
lower-pow.f32N/A
lower-exp.f32N/A
lift-pow.f32N/A
pow-to-expN/A
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (- (/ x s)))))))
float code(float x, float s) {
return expf(-log1pf(expf(-(x / s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(-Float32(x / s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}
\end{array}
Initial program 99.8%
lift-/.f32N/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
log-powN/A
inv-powN/A
lift-/.f32N/A
lower-exp.f32N/A
lift-/.f32N/A
log-recN/A
lower-neg.f32N/A
lift-+.f32N/A
lower-log1p.f3299.9
Applied rewrites99.9%
Final simplification99.9%
herbie shell --seed 2024230
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))