
(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 15 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 -0.25) (* x (/ 4.0 s))))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-0.25f), (x * (4.0f / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp((-0.25e0)) ** (x * (4.0e0 / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-0.25)) ^ Float32(x * Float32(Float32(4.0) / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-0.25)) ^ (x * (single(4.0) / s)))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-0.25}\right)}^{\left(x \cdot \frac{4}{s}\right)}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
inv-pow99.8%
pow-exp99.8%
*-commutative99.8%
pow-exp99.7%
add-sqr-sqrt99.7%
unpow-prod-down99.7%
Applied egg-rr99.7%
pow-sqr99.7%
associate-*r/99.7%
remove-double-neg99.7%
neg-mul-199.7%
distribute-neg-frac299.7%
associate-*r/99.7%
neg-mul-199.7%
*-commutative99.7%
distribute-lft-neg-in99.7%
distribute-frac-neg299.7%
remove-double-neg99.7%
Simplified99.7%
add-sqr-sqrt99.7%
unpow-prod-down99.8%
pow1/299.8%
pow-exp99.8%
metadata-eval99.8%
pow1/299.8%
pow-exp99.8%
metadata-eval99.8%
Applied egg-rr99.8%
pow-sqr99.8%
associate-*l/99.8%
Simplified99.8%
sqr-pow99.8%
pow1/299.8%
pow-exp99.8%
metadata-eval99.8%
*-commutative99.8%
associate-/l*99.8%
metadata-eval99.8%
*-commutative99.8%
*-un-lft-identity99.8%
*-commutative99.8%
associate-/l*99.8%
pow1/299.8%
pow-exp99.8%
metadata-eval99.8%
*-commutative99.8%
associate-/l*99.8%
metadata-eval99.8%
*-commutative99.8%
*-un-lft-identity99.8%
*-commutative99.8%
associate-/l*99.8%
Applied egg-rr99.8%
pow-sqr99.8%
associate-*r*99.8%
metadata-eval99.8%
associate-*r/99.8%
*-commutative99.8%
associate-/l*99.8%
Simplified99.8%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 0.5) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ (/ (pow s 2.0) (- s)) x)))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 0.5f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = (powf(s, 2.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) <= 0.5e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = ((s ** 2.0e0) / -s) / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(0.5)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32((s ^ Float32(2.0)) / Float32(-s)) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(0.5)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = ((s ^ single(2.0)) / -s) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 0.5:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{s}^{2}}{-s}}{x}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.5Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 96.1%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 39.5%
neg-mul-139.5%
unsub-neg39.5%
Simplified39.5%
Taylor expanded in x around inf 35.4%
associate-*r/35.4%
neg-mul-135.4%
Simplified35.4%
neg-sub035.4%
flip--67.7%
metadata-eval67.7%
pow267.7%
add-sqr-sqrt67.7%
sqrt-unprod11.3%
sqr-neg11.3%
sqrt-unprod-0.0%
add-sqr-sqrt67.4%
sub-neg67.4%
neg-sub067.4%
add-sqr-sqrt-0.0%
sqrt-unprod11.3%
sqr-neg11.3%
sqrt-unprod67.7%
add-sqr-sqrt67.7%
Applied egg-rr67.7%
sub0-neg67.7%
Simplified67.7%
Final simplification85.0%
(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.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -500.0)
(/ 1.0 (+ 1.0 (+ 1.0 (+ -1.0 (/ -1.0 (+ (/ x s) -1.0))))))
(if (<= t_0 4.999999840142846e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -500.0f) {
tmp = 1.0f / (1.0f + (1.0f + (-1.0f + (-1.0f / ((x / s) + -1.0f)))));
} else if (t_0 <= 4.999999840142846e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (x / 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 <= (-500.0e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 + ((-1.0e0) + ((-1.0e0) / ((x / s) + (-1.0e0))))))
else if (t_0 <= 4.999999840142846e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
else
tmp = 1.0e0 / (x / 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(-500.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(-1.0) + Float32(Float32(-1.0) / Float32(Float32(x / s) + Float32(-1.0))))))); elseif (t_0 <= Float32(4.999999840142846e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(x / s) + Float32(2.0)))); else tmp = Float32(Float32(1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-500.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) + (single(-1.0) + (single(-1.0) / ((x / s) + single(-1.0)))))); elseif (t_0 <= single(4.999999840142846e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((x / s) + single(2.0))); else tmp = single(1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq -500:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left(-1 + \frac{-1}{\frac{x}{s} + -1}\right)\right)}\\
\mathbf{elif}\;t\_0 \leq 4.999999840142846 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -500Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.0%
expm1-log1p-u98.0%
log1p-define98.0%
expm1-undefine98.0%
add-exp-log98.0%
frac-2neg98.0%
metadata-eval98.0%
distribute-neg-in98.0%
metadata-eval98.0%
distribute-frac-neg298.0%
add-sqr-sqrt-0.0%
sqrt-unprod99.5%
sqr-neg99.5%
sqrt-unprod98.2%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
associate--l+98.2%
sub-neg98.2%
metadata-eval98.2%
Simplified98.2%
if -500 < (/.f32 (neg.f32 x) s) < 4.99999984e37Initial program 99.6%
Taylor expanded in x around 0 54.3%
neg-mul-154.3%
unsub-neg54.3%
Simplified54.3%
*-un-lft-identity54.3%
cancel-sign-sub-inv54.3%
metadata-eval54.3%
add-log-exp93.8%
pow-exp93.8%
flip-+49.4%
metadata-eval49.4%
pow-exp49.4%
add-log-exp49.4%
neg-mul-149.4%
pow-exp49.4%
add-log-exp50.0%
neg-mul-150.0%
distribute-neg-frac250.0%
distribute-neg-frac250.0%
pow-exp50.0%
Applied egg-rr76.3%
if 4.99999984e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 87.1%
associate-*r/87.1%
neg-mul-187.1%
Simplified87.1%
clear-num100.0%
inv-pow100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification86.2%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -500.0)
(- 1.0 (/ s x))
(if (<= t_0 0.5) (+ 0.5 (/ (* x 0.25) s)) (/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -500.0f) {
tmp = 1.0f - (s / x);
} else if (t_0 <= 0.5f) {
tmp = 0.5f + ((x * 0.25f) / s);
} else {
tmp = -1.0f / (x / 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 <= (-500.0e0)) then
tmp = 1.0e0 - (s / x)
else if (t_0 <= 0.5e0) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = (-1.0e0) / (x / 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(-500.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (t_0 <= Float32(0.5)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); else tmp = Float32(Float32(-1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-500.0)) tmp = single(1.0) - (s / x); elseif (t_0 <= single(0.5)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq -500:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -500Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.0%
Taylor expanded in x around inf 98.0%
neg-mul-198.0%
unsub-neg98.0%
Simplified98.0%
if -500 < (/.f32 (neg.f32 x) s) < 0.5Initial program 99.7%
Taylor expanded in x around 0 96.7%
associate-*r/96.7%
*-commutative96.7%
Simplified96.7%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 39.5%
neg-mul-139.5%
unsub-neg39.5%
Simplified39.5%
Taylor expanded in x around inf 39.5%
associate-*r/39.5%
neg-mul-139.5%
Simplified39.5%
Final simplification74.8%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -500.0) (/ 1.0 (+ 1.0 (+ 1.0 (+ -1.0 (/ -1.0 (+ (/ x s) -1.0)))))) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -500.0f) {
tmp = 1.0f / (1.0f + (1.0f + (-1.0f + (-1.0f / ((x / s) + -1.0f)))));
} else {
tmp = 1.0f / (-1.0f + (3.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) <= (-500.0e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 + ((-1.0e0) + ((-1.0e0) / ((x / s) + (-1.0e0))))))
else
tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-500.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(-1.0) + Float32(Float32(-1.0) / Float32(Float32(x / s) + Float32(-1.0))))))); else tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-500.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) + (single(-1.0) + (single(-1.0) / ((x / s) + single(-1.0)))))); else tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -500:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left(-1 + \frac{-1}{\frac{x}{s} + -1}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -500Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.0%
expm1-log1p-u98.0%
log1p-define98.0%
expm1-undefine98.0%
add-exp-log98.0%
frac-2neg98.0%
metadata-eval98.0%
distribute-neg-in98.0%
metadata-eval98.0%
distribute-frac-neg298.0%
add-sqr-sqrt-0.0%
sqrt-unprod99.5%
sqr-neg99.5%
sqrt-unprod98.2%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
associate--l+98.2%
sub-neg98.2%
metadata-eval98.2%
Simplified98.2%
if -500 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 62.7%
neg-mul-162.7%
unsub-neg62.7%
Simplified62.7%
expm1-log1p-u62.6%
Applied egg-rr62.6%
expm1-undefine62.6%
sub-neg62.6%
log1p-undefine62.6%
rem-exp-log62.7%
associate-+r-62.7%
metadata-eval62.7%
metadata-eval62.7%
Simplified62.7%
Final simplification74.1%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -500.0)
(- 1.0 (/ s x))
(if (<= t_0 2.0) 0.5 (/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -500.0f) {
tmp = 1.0f - (s / x);
} else if (t_0 <= 2.0f) {
tmp = 0.5f;
} else {
tmp = -1.0f / (x / 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 <= (-500.0e0)) then
tmp = 1.0e0 - (s / x)
else if (t_0 <= 2.0e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x / 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(-500.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (t_0 <= Float32(2.0)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-500.0)) tmp = single(1.0) - (s / x); elseif (t_0 <= single(2.0)) tmp = single(0.5); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq -500:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -500Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.0%
Taylor expanded in x around inf 98.0%
neg-mul-198.0%
unsub-neg98.0%
Simplified98.0%
if -500 < (/.f32 (neg.f32 x) s) < 2Initial program 99.7%
Taylor expanded in x around 0 87.1%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 39.7%
neg-mul-139.7%
unsub-neg39.7%
Simplified39.7%
Taylor expanded in x around inf 39.7%
associate-*r/39.7%
neg-mul-139.7%
Simplified39.7%
Final simplification72.3%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -500.0) (/ 1.0 (+ 1.0 (/ -1.0 (+ (/ x s) -1.0)))) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -500.0f) {
tmp = 1.0f / (1.0f + (-1.0f / ((x / s) + -1.0f)));
} else {
tmp = 1.0f / (-1.0f + (3.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) <= (-500.0e0)) then
tmp = 1.0e0 / (1.0e0 + ((-1.0e0) / ((x / s) + (-1.0e0))))
else
tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-500.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(-1.0) / Float32(Float32(x / s) + Float32(-1.0))))); else tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-500.0)) tmp = single(1.0) / (single(1.0) + (single(-1.0) / ((x / s) + single(-1.0)))); else tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -500:\\
\;\;\;\;\frac{1}{1 + \frac{-1}{\frac{x}{s} + -1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -500Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.0%
frac-2neg98.0%
metadata-eval98.0%
div-inv98.0%
distribute-neg-in98.0%
metadata-eval98.0%
distribute-frac-neg298.0%
add-sqr-sqrt-0.0%
sqrt-unprod99.5%
sqr-neg99.5%
sqrt-unprod98.2%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
associate-*r/98.2%
metadata-eval98.2%
Simplified98.2%
if -500 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 62.7%
neg-mul-162.7%
unsub-neg62.7%
Simplified62.7%
expm1-log1p-u62.6%
Applied egg-rr62.6%
expm1-undefine62.6%
sub-neg62.6%
log1p-undefine62.6%
rem-exp-log62.7%
associate-+r-62.7%
metadata-eval62.7%
metadata-eval62.7%
Simplified62.7%
Final simplification74.1%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -500.0) (- 1.0 (/ s x)) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -500.0f) {
tmp = 1.0f - (s / x);
} else {
tmp = 1.0f / (-1.0f + (3.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) <= (-500.0e0)) then
tmp = 1.0e0 - (s / x)
else
tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-500.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); else tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-500.0)) tmp = single(1.0) - (s / x); else tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -500:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -500Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.0%
Taylor expanded in x around inf 98.0%
neg-mul-198.0%
unsub-neg98.0%
Simplified98.0%
if -500 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 62.7%
neg-mul-162.7%
unsub-neg62.7%
Simplified62.7%
expm1-log1p-u62.6%
Applied egg-rr62.6%
expm1-undefine62.6%
sub-neg62.6%
log1p-undefine62.6%
rem-exp-log62.7%
associate-+r-62.7%
metadata-eval62.7%
metadata-eval62.7%
Simplified62.7%
Final simplification74.0%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (/ 1.0 (/ x s)) (if (<= x 1.0000000036274937e-15) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-5f) {
tmp = 1.0f / (x / s);
} else if (x <= 1.0000000036274937e-15f) {
tmp = 0.5f;
} else {
tmp = 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 <= (-9.999999747378752e-5)) then
tmp = 1.0e0 / (x / s)
else if (x <= 1.0000000036274937e-15) then
tmp = 0.5e0
else
tmp = 1.0e0 - (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999747378752e-5)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(1.0000000036274937e-15)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) - Float32(s / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.999999747378752e-5)) tmp = single(1.0) / (x / s); elseif (x <= single(1.0000000036274937e-15)) tmp = single(0.5); else tmp = single(1.0) - (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 1.0000000036274937 \cdot 10^{-15}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 50.7%
neg-mul-150.7%
unsub-neg50.7%
Simplified50.7%
Taylor expanded in x around inf 45.1%
associate-*r/45.1%
neg-mul-145.1%
Simplified45.1%
clear-num50.7%
inv-pow50.7%
add-sqr-sqrt-0.0%
sqrt-unprod67.3%
sqr-neg67.3%
sqrt-unprod50.7%
add-sqr-sqrt50.7%
Applied egg-rr50.7%
unpow-150.7%
Simplified50.7%
if -9.99999975e-5 < x < 1e-15Initial program 99.5%
Taylor expanded in x around 0 63.1%
if 1e-15 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.2%
Taylor expanded in x around inf 91.0%
neg-mul-191.0%
unsub-neg91.0%
Simplified91.0%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (* s (/ 1.0 x)) (if (<= x 1.0000000036274937e-15) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-5f) {
tmp = s * (1.0f / x);
} else if (x <= 1.0000000036274937e-15f) {
tmp = 0.5f;
} else {
tmp = 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 <= (-9.999999747378752e-5)) then
tmp = s * (1.0e0 / x)
else if (x <= 1.0000000036274937e-15) then
tmp = 0.5e0
else
tmp = 1.0e0 - (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999747378752e-5)) tmp = Float32(s * Float32(Float32(1.0) / x)); elseif (x <= Float32(1.0000000036274937e-15)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) - Float32(s / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.999999747378752e-5)) tmp = s * (single(1.0) / x); elseif (x <= single(1.0000000036274937e-15)) tmp = single(0.5); else tmp = single(1.0) - (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{elif}\;x \leq 1.0000000036274937 \cdot 10^{-15}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 50.7%
neg-mul-150.7%
unsub-neg50.7%
Simplified50.7%
Taylor expanded in x around inf 45.1%
associate-*r/45.1%
neg-mul-145.1%
Simplified45.1%
div-inv45.1%
add-sqr-sqrt-0.0%
sqrt-unprod64.2%
sqr-neg64.2%
sqrt-unprod45.1%
add-sqr-sqrt45.1%
Applied egg-rr45.1%
if -9.99999975e-5 < x < 1e-15Initial program 99.5%
Taylor expanded in x around 0 63.1%
if 1e-15 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.2%
Taylor expanded in x around inf 91.0%
neg-mul-191.0%
unsub-neg91.0%
Simplified91.0%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -500.0) (- 1.0 (/ s x)) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -500.0f) {
tmp = 1.0f - (s / x);
} 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) <= (-500.0e0)) then
tmp = 1.0e0 - (s / x)
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(-500.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); 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(-500.0)) tmp = single(1.0) - (s / x); 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 -500:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -500Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.0%
Taylor expanded in x around inf 98.0%
neg-mul-198.0%
unsub-neg98.0%
Simplified98.0%
if -500 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 62.7%
neg-mul-162.7%
unsub-neg62.7%
Simplified62.7%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (* s (/ 1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-5f) {
tmp = s * (1.0f / x);
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-9.999999747378752e-5)) then
tmp = s * (1.0e0 / x)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999747378752e-5)) tmp = Float32(s * Float32(Float32(1.0) / x)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.999999747378752e-5)) tmp = s * (single(1.0) / x); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 50.7%
neg-mul-150.7%
unsub-neg50.7%
Simplified50.7%
Taylor expanded in x around inf 45.1%
associate-*r/45.1%
neg-mul-145.1%
Simplified45.1%
div-inv45.1%
add-sqr-sqrt-0.0%
sqrt-unprod64.2%
sqr-neg64.2%
sqrt-unprod45.1%
add-sqr-sqrt45.1%
Applied egg-rr45.1%
if -9.99999975e-5 < x Initial program 99.7%
Taylor expanded in x around 0 49.3%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-5f) {
tmp = s / x;
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-9.999999747378752e-5)) then
tmp = s / x
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999747378752e-5)) tmp = Float32(s / x); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.999999747378752e-5)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 50.7%
neg-mul-150.7%
unsub-neg50.7%
Simplified50.7%
Taylor expanded in x around inf 45.1%
associate-*r/45.1%
neg-mul-145.1%
Simplified45.1%
neg-sub045.1%
sub-neg45.1%
add-sqr-sqrt-0.0%
sqrt-unprod64.2%
sqr-neg64.2%
sqrt-unprod45.1%
add-sqr-sqrt45.1%
Applied egg-rr45.1%
+-lft-identity45.1%
Simplified45.1%
if -9.99999975e-5 < x Initial program 99.7%
Taylor expanded in x around 0 49.3%
(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.8%
Taylor expanded in x around 0 37.0%
herbie shell --seed 2024117
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))