| Alternative 1 | |
|---|---|
| Error | 10.5 |
| Cost | 516 |
\[\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\left(2 + \frac{1}{2 - \frac{x}{s}}\right) + -2\\
\end{array}
\]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
(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)));
}
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
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 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
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\frac{1}{1 + e^{\frac{-x}{s}}}
\frac{1}{1 + e^{\frac{-x}{s}}}
Results
Initial program 0.1
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 10.5 |
| Cost | 516 |
| Alternative 2 | |
|---|---|
| Error | 10.1 |
| Cost | 196 |
| Alternative 3 | |
|---|---|
| Error | 20.7 |
| Cost | 32 |
herbie shell --seed 2022325
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))