
(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 13 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 (/ 1.0 (+ 1.0 (pow (exp -2.0) (/ x (* s 2.0))))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-2.0f), (x / (s * 2.0f))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp((-2.0e0)) ** (x / (s * 2.0e0))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-2.0)) ^ Float32(x / Float32(s * Float32(2.0)))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-2.0)) ^ (x / (s * single(2.0))))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-2}\right)}^{\left(\frac{x}{s \cdot 2}\right)}}
\end{array}
Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.8%
Applied egg-rr99.8%
inv-pow99.8%
pow-exp99.9%
*-commutative99.9%
pow-exp99.8%
sqr-pow99.8%
pow-prod-down99.8%
prod-exp99.9%
metadata-eval99.9%
associate-/l/99.9%
Applied egg-rr99.9%
*-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (+ 1.0 (expm1 (/ (- x) s))))))
float code(float x, float s) {
return 1.0f / (1.0f + (1.0f + expm1f((-x / s))));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + expm1(Float32(Float32(-x) / s))))) end
\begin{array}{l}
\\
\frac{1}{1 + \left(1 + \mathsf{expm1}\left(\frac{-x}{s}\right)\right)}
\end{array}
Initial program 99.9%
div-inv99.8%
exp-prod83.4%
neg-mul-183.4%
exp-prod83.4%
pow-pow99.8%
div-inv99.8%
Applied egg-rr99.8%
expm1-log1p-u99.8%
expm1-udef99.8%
log1p-udef99.9%
add-exp-log99.8%
pow-exp99.9%
*-commutative99.9%
pow-exp99.8%
inv-pow99.8%
rec-exp99.9%
distribute-neg-frac99.9%
Applied egg-rr99.9%
associate--l+99.9%
expm1-def99.9%
Simplified99.9%
Final simplification99.9%
(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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -1.0)
1.0
(if (<= t_0 9.999999680285692e+37)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ 2.0 (/ x s))))
(/ 1.0 (+ 1.0 (+ 1.0 (* 0.3333333333333333 (* x (/ -3.0 s))))))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -1.0f) {
tmp = 1.0f;
} else if (t_0 <= 9.999999680285692e+37f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / (2.0f + (x / s)));
} else {
tmp = 1.0f / (1.0f + (1.0f + (0.3333333333333333f * (x * (-3.0f / s)))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-1.0e0)) then
tmp = 1.0e0
else if (t_0 <= 9.999999680285692e+37) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / (2.0e0 + (x / s)))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + (0.3333333333333333e0 * (x * ((-3.0e0) / s)))))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-1.0)) tmp = Float32(1.0); elseif (t_0 <= Float32(9.999999680285692e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x / Float32(s * Float32(s / x)))) / Float32(Float32(2.0) + Float32(x / s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(0.3333333333333333) * Float32(x * Float32(Float32(-3.0) / s)))))); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-1.0)) tmp = single(1.0); elseif (t_0 <= single(9.999999680285692e+37)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / (single(2.0) + (x / s))); else tmp = single(1.0) / (single(1.0) + (single(1.0) + (single(0.3333333333333333) * (x * (single(-3.0) / s))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t_0 \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + 0.3333333333333333 \cdot \left(x \cdot \frac{-3}{s}\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.6%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Taylor expanded in s around 0 98.8%
if -1 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 99.7%
Taylor expanded in x around 0 53.5%
mul-1-neg53.5%
unsub-neg53.5%
Simplified53.5%
sub-neg53.5%
flip-+79.0%
metadata-eval79.0%
distribute-neg-frac79.0%
distribute-neg-frac79.0%
distribute-neg-frac79.0%
Applied egg-rr79.0%
distribute-frac-neg79.0%
distribute-frac-neg79.0%
sqr-neg79.0%
clear-num79.0%
frac-times80.5%
*-un-lft-identity80.5%
Applied egg-rr80.5%
if 9.99999968e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod6.3%
sqr-neg6.3%
sqrt-unprod6.3%
add-sqr-sqrt6.3%
add-cbrt-cube6.3%
pow1/36.3%
pow-flip6.3%
Applied egg-rr100.0%
Taylor expanded in s around -inf 100.0%
distribute-rgt-out100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
associate-*r/100.0%
*-commutative100.0%
associate-*r/100.0%
Simplified100.0%
Final simplification90.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -1.0)
1.0
(if (<= t_0 9.999999680285692e+37)
(/ 1.0 (/ (- 4.0 (* x (/ (/ x s) s))) (+ 2.0 (/ x s))))
(/ 1.0 (+ 1.0 (+ 1.0 (* 0.3333333333333333 (* x (/ -3.0 s))))))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -1.0f) {
tmp = 1.0f;
} else if (t_0 <= 9.999999680285692e+37f) {
tmp = 1.0f / ((4.0f - (x * ((x / s) / s))) / (2.0f + (x / s)));
} else {
tmp = 1.0f / (1.0f + (1.0f + (0.3333333333333333f * (x * (-3.0f / s)))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-1.0e0)) then
tmp = 1.0e0
else if (t_0 <= 9.999999680285692e+37) then
tmp = 1.0e0 / ((4.0e0 - (x * ((x / s) / s))) / (2.0e0 + (x / s)))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + (0.3333333333333333e0 * (x * ((-3.0e0) / s)))))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-1.0)) tmp = Float32(1.0); elseif (t_0 <= Float32(9.999999680285692e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x * Float32(Float32(x / s) / s))) / Float32(Float32(2.0) + Float32(x / s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(0.3333333333333333) * Float32(x * Float32(Float32(-3.0) / s)))))); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-1.0)) tmp = single(1.0); elseif (t_0 <= single(9.999999680285692e+37)) tmp = single(1.0) / ((single(4.0) - (x * ((x / s) / s))) / (single(2.0) + (x / s))); else tmp = single(1.0) / (single(1.0) + (single(1.0) + (single(0.3333333333333333) * (x * (single(-3.0) / s))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t_0 \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - x \cdot \frac{\frac{x}{s}}{s}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + 0.3333333333333333 \cdot \left(x \cdot \frac{-3}{s}\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.6%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Taylor expanded in s around 0 98.8%
if -1 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 99.7%
Taylor expanded in x around 0 53.5%
mul-1-neg53.5%
unsub-neg53.5%
Simplified53.5%
sub-neg53.5%
flip-+79.0%
metadata-eval79.0%
distribute-neg-frac79.0%
distribute-neg-frac79.0%
distribute-neg-frac79.0%
Applied egg-rr79.0%
associate-*r/79.0%
frac-2neg79.0%
add-sqr-sqrt49.2%
sqrt-unprod79.7%
sqr-neg79.7%
sqrt-unprod29.8%
add-sqr-sqrt78.9%
distribute-lft-neg-out78.9%
distribute-frac-neg78.9%
add-sqr-sqrt49.2%
sqrt-unprod79.6%
sqr-neg79.6%
sqrt-unprod29.8%
add-sqr-sqrt79.0%
add-sqr-sqrt49.2%
sqrt-unprod79.7%
sqr-neg79.7%
sqrt-unprod29.8%
add-sqr-sqrt78.9%
Applied egg-rr78.9%
*-commutative78.9%
*-un-lft-identity78.9%
times-frac82.8%
add-sqr-sqrt-0.0%
sqrt-unprod75.2%
sqr-neg75.2%
sqrt-unprod82.9%
add-sqr-sqrt82.9%
Applied egg-rr82.9%
if 9.99999968e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod6.3%
sqr-neg6.3%
sqrt-unprod6.3%
add-sqr-sqrt6.3%
add-cbrt-cube6.3%
pow1/36.3%
pow-flip6.3%
Applied egg-rr100.0%
Taylor expanded in s around -inf 100.0%
distribute-rgt-out100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
associate-*r/100.0%
*-commutative100.0%
associate-*r/100.0%
Simplified100.0%
Final simplification91.5%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -1.0) 1.0 (/ 1.0 (+ 1.0 (+ 1.0 (* 0.3333333333333333 (* x (/ -3.0 s))))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -1.0f) {
tmp = 1.0f;
} else {
tmp = 1.0f / (1.0f + (1.0f + (0.3333333333333333f * (x * (-3.0f / s)))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((-x / s) <= (-1.0e0)) then
tmp = 1.0e0
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + (0.3333333333333333e0 * (x * ((-3.0e0) / s)))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-1.0)) tmp = Float32(1.0); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(0.3333333333333333) * Float32(x * Float32(Float32(-3.0) / s)))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-1.0)) tmp = single(1.0); else tmp = single(1.0) / (single(1.0) + (single(1.0) + (single(0.3333333333333333) * (x * (single(-3.0) / s))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + 0.3333333333333333 \cdot \left(x \cdot \frac{-3}{s}\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.6%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Taylor expanded in s around 0 98.8%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
add-sqr-sqrt25.1%
sqrt-unprod40.8%
sqr-neg40.8%
sqrt-unprod17.3%
add-sqr-sqrt38.1%
add-cbrt-cube38.1%
pow1/338.1%
pow-flip38.1%
Applied egg-rr98.7%
Taylor expanded in s around -inf 63.4%
distribute-rgt-out63.4%
metadata-eval63.4%
Simplified63.4%
Taylor expanded in x around 0 63.4%
associate-*r/63.4%
*-commutative63.4%
associate-*r/63.4%
Simplified63.4%
Final simplification77.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -2.0)
1.0
(if (<= t_0 2.0) (+ 0.5 (/ (* x 0.25) s)) (/ 1.0 t_0)))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -2.0f) {
tmp = 1.0f;
} else if (t_0 <= 2.0f) {
tmp = 0.5f + ((x * 0.25f) / s);
} else {
tmp = 1.0f / t_0;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-2.0e0)) then
tmp = 1.0e0
else if (t_0 <= 2.0e0) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 / t_0
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-2.0)) tmp = Float32(1.0); elseif (t_0 <= Float32(2.0)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); else tmp = Float32(Float32(1.0) / t_0); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-2.0)) tmp = single(1.0); elseif (t_0 <= single(2.0)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(1.0) / t_0; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t_0 \leq -2:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.2%
Taylor expanded in x around inf 97.1%
mul-1-neg97.1%
unsub-neg97.1%
Simplified97.1%
Taylor expanded in s around 0 99.4%
if -2 < (/.f32 (neg.f32 x) s) < 2Initial program 99.8%
Taylor expanded in x around 0 96.0%
associate-*r/96.0%
Simplified96.0%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 41.3%
mul-1-neg41.3%
unsub-neg41.3%
Simplified41.3%
Taylor expanded in x around inf 41.3%
mul-1-neg41.3%
distribute-frac-neg41.3%
Simplified41.3%
Final simplification78.2%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ (- x) s))) (if (<= t_0 -1.0) 1.0 (if (<= t_0 2.0) 0.5 (/ 1.0 t_0)))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -1.0f) {
tmp = 1.0f;
} else if (t_0 <= 2.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / t_0;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-1.0e0)) then
tmp = 1.0e0
else if (t_0 <= 2.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / t_0
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-1.0)) tmp = Float32(1.0); elseif (t_0 <= Float32(2.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / t_0); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-1.0)) tmp = single(1.0); elseif (t_0 <= single(2.0)) tmp = single(0.5); else tmp = single(1.0) / t_0; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t_0 \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.6%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Taylor expanded in s around 0 98.8%
if -1 < (/.f32 (neg.f32 x) s) < 2Initial program 99.8%
Taylor expanded in x around 0 86.4%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 41.3%
mul-1-neg41.3%
unsub-neg41.3%
Simplified41.3%
Taylor expanded in x around inf 41.3%
mul-1-neg41.3%
distribute-frac-neg41.3%
Simplified41.3%
Final simplification75.6%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -1.0) 1.0 (/ 1.0 (+ 1.0 (+ 1.0 (/ -1.0 (/ s x)))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -1.0f) {
tmp = 1.0f;
} else {
tmp = 1.0f / (1.0f + (1.0f + (-1.0f / (s / x))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((-x / s) <= (-1.0e0)) then
tmp = 1.0e0
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + ((-1.0e0) / (s / x))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-1.0)) tmp = Float32(1.0); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(-1.0) / Float32(s / x))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-1.0)) tmp = single(1.0); else tmp = single(1.0) / (single(1.0) + (single(1.0) + (single(-1.0) / (s / x)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + \frac{-1}{\frac{s}{x}}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.6%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Taylor expanded in s around 0 98.8%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
add-sqr-sqrt25.1%
sqrt-unprod40.8%
sqr-neg40.8%
sqrt-unprod17.3%
add-sqr-sqrt38.1%
add-cbrt-cube38.1%
pow1/338.1%
pow-flip38.1%
Applied egg-rr98.7%
Taylor expanded in s around -inf 63.4%
distribute-rgt-out63.4%
metadata-eval63.4%
Simplified63.4%
clear-num63.4%
un-div-inv62.5%
*-un-lft-identity62.5%
*-commutative62.5%
times-frac62.5%
metadata-eval62.5%
Applied egg-rr62.5%
associate-/r*62.5%
metadata-eval62.5%
Simplified62.5%
Final simplification77.4%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -1.0) 1.0 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -1.0f) {
tmp = 1.0f;
} else {
tmp = 1.0f / (2.0f - (x / s));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((-x / s) <= (-1.0e0)) then
tmp = 1.0e0
else
tmp = 1.0e0 / (2.0e0 - (x / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-1.0)) tmp = Float32(1.0); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-1.0)) tmp = single(1.0); else tmp = single(1.0) / (single(2.0) - (x / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.6%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Taylor expanded in s around 0 98.8%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 62.5%
mul-1-neg62.5%
unsub-neg62.5%
Simplified62.5%
Final simplification77.4%
(FPCore (x s) :precision binary32 (if (<= x -1.999999987845058e-8) (/ (- s) x) (if (<= x 9.999999998199587e-24) 0.5 1.0)))
float code(float x, float s) {
float tmp;
if (x <= -1.999999987845058e-8f) {
tmp = -s / x;
} else if (x <= 9.999999998199587e-24f) {
tmp = 0.5f;
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-1.999999987845058e-8)) then
tmp = -s / x
else if (x <= 9.999999998199587e-24) then
tmp = 0.5e0
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.999999987845058e-8)) tmp = Float32(Float32(-s) / x); elseif (x <= Float32(9.999999998199587e-24)) tmp = Float32(0.5); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-1.999999987845058e-8)) tmp = -s / x; elseif (x <= single(9.999999998199587e-24)) tmp = single(0.5); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.999999987845058 \cdot 10^{-8}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{elif}\;x \leq 9.999999998199587 \cdot 10^{-24}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.99999999e-8Initial program 100.0%
Taylor expanded in x around 0 48.6%
mul-1-neg48.6%
unsub-neg48.6%
Simplified48.6%
Taylor expanded in x around inf 46.1%
associate-*r/46.1%
neg-mul-146.1%
Simplified46.1%
if -1.99999999e-8 < x < 1e-23Initial program 99.6%
Taylor expanded in x around 0 67.3%
if 1e-23 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.4%
Taylor expanded in x around inf 90.0%
mul-1-neg90.0%
unsub-neg90.0%
Simplified90.0%
Taylor expanded in s around 0 93.5%
Final simplification72.4%
(FPCore (x s) :precision binary32 (if (<= x 9.999999998199587e-24) 0.5 1.0))
float code(float x, float s) {
float tmp;
if (x <= 9.999999998199587e-24f) {
tmp = 0.5f;
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 9.999999998199587e-24) then
tmp = 0.5e0
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(9.999999998199587e-24)) tmp = Float32(0.5); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(9.999999998199587e-24)) tmp = single(0.5); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.999999998199587 \cdot 10^{-24}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1e-23Initial program 99.8%
Taylor expanded in x around 0 36.4%
if 1e-23 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.4%
Taylor expanded in x around inf 90.0%
mul-1-neg90.0%
unsub-neg90.0%
Simplified90.0%
Taylor expanded in s around 0 93.5%
Final simplification60.9%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 34.4%
Final simplification34.4%
herbie shell --seed 2024019
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))