
(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 -1.0) (/ x s)))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-1.0f), (x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp((-1.0e0)) ** (x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-1.0)) ^ Float32(x / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-1.0)) ^ (x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}
\end{array}
Initial program 99.9%
div-inv99.9%
exp-prod80.8%
neg-mul-180.8%
exp-prod80.8%
pow-pow99.9%
div-inv100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow E (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(((float) M_E), (-x / s)));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(2.71828182845904523536) ^ (-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + {e}^{\left(\frac{-x}{s}\right)}}
\end{array}
Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
exp-prod99.9%
Applied egg-rr99.9%
exp-1-e99.9%
Simplified99.9%
inv-pow99.9%
pow-pow100.0%
Applied egg-rr100.0%
*-commutative100.0%
mul-1-neg100.0%
distribute-neg-frac100.0%
Simplified100.0%
Final simplification100.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.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 0.10000000149011612)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= t_0 1.9999999360571385e+38)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (/ x s)))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= 0.10000000149011612f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (t_0 <= 1.9999999360571385e+38f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / (x / 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 <= 0.10000000149011612e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (t_0 <= 1.9999999360571385e+38) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / (x / 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(0.10000000149011612)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); elseif (t_0 <= Float32(1.9999999360571385e+38)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x / Float32(s * Float32(s / x)))) / Float32(x / 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(0.10000000149011612)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (t_0 <= single(1.9999999360571385e+38)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / (x / 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 0.10000000149011612:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;t_0 \leq 1.9999999360571385 \cdot 10^{+38}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.100000001Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 94.6%
if 0.100000001 < (/.f32 (neg.f32 x) s) < 1.99999994e38Initial program 100.0%
Taylor expanded in x around 0 11.2%
mul-1-neg11.2%
unsub-neg11.2%
Simplified11.2%
*-un-lft-identity11.2%
cancel-sign-sub-inv11.2%
metadata-eval11.2%
add-log-exp97.9%
pow-exp97.9%
flip-+0.8%
metadata-eval0.8%
pow-exp0.8%
add-log-exp0.8%
neg-mul-10.8%
pow-exp0.8%
add-log-exp2.2%
neg-mul-12.2%
distribute-neg-frac2.2%
distribute-neg-frac2.2%
pow-exp2.2%
Applied egg-rr56.4%
Taylor expanded in x around inf 56.0%
distribute-frac-neg56.0%
distribute-frac-neg56.0%
sqr-neg56.0%
clear-num56.0%
frac-times62.5%
*-un-lft-identity62.5%
Applied egg-rr62.5%
if 1.99999994e38 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
remove-double-neg86.6%
frac-2neg86.6%
clear-num100.0%
inv-pow100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification86.3%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 5.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (- (* 0.5 (* x (* x (* (/ 1.0 s) (/ 1.0 s))))) (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 5.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((0.5f * (x * (x * ((1.0f / s) * (1.0f / s))))) - (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) <= 5.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((0.5e0 * (x * (x * ((1.0e0 / s) * (1.0e0 / s))))) - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(5.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) * Float32(x * Float32(x * Float32(Float32(Float32(1.0) / s) * Float32(Float32(1.0) / s))))) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(5.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + ((single(0.5) * (x * (x * ((single(1.0) / s) * (single(1.0) / s))))) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 5:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{s} \cdot \frac{1}{s}\right)\right)\right) - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 5Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.6%
if 5 < (/.f32 (neg.f32 x) s) Initial program 100.0%
div-inv100.0%
exp-prod75.6%
neg-mul-175.6%
exp-prod75.6%
pow-pow100.0%
div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 82.2%
mul-1-neg82.2%
distribute-frac-neg82.2%
+-commutative82.2%
distribute-frac-neg82.2%
unsub-neg82.2%
unpow282.2%
unpow282.2%
times-frac70.4%
unpow270.4%
Simplified70.4%
unpow270.4%
sqr-neg70.4%
distribute-frac-neg70.4%
distribute-frac-neg70.4%
associate-*l/70.4%
*-un-lft-identity70.4%
times-frac79.6%
add-sqr-sqrt79.6%
sqrt-unprod78.5%
sqr-neg78.5%
sqrt-unprod-0.0%
add-sqr-sqrt51.4%
add-sqr-sqrt51.4%
sqrt-unprod50.5%
sqr-neg50.5%
sqrt-unprod-0.0%
add-sqr-sqrt79.6%
Applied egg-rr79.6%
div-inv79.6%
div-inv79.6%
associate-*l*88.9%
Applied egg-rr88.9%
Final simplification91.8%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 5.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (- (* 0.5 (* x (* x (/ (/ 1.0 s) s)))) (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 5.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((0.5f * (x * (x * ((1.0f / s) / s)))) - (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) <= 5.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((0.5e0 * (x * (x * ((1.0e0 / s) / s)))) - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(5.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) * Float32(x * Float32(x * Float32(Float32(Float32(1.0) / s) / s)))) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(5.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + ((single(0.5) * (x * (x * ((single(1.0) / s) / s)))) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 5:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \left(x \cdot \left(x \cdot \frac{\frac{1}{s}}{s}\right)\right) - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 5Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.6%
if 5 < (/.f32 (neg.f32 x) s) Initial program 100.0%
div-inv100.0%
exp-prod75.6%
neg-mul-175.6%
exp-prod75.6%
pow-pow100.0%
div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 82.2%
mul-1-neg82.2%
distribute-frac-neg82.2%
+-commutative82.2%
distribute-frac-neg82.2%
unsub-neg82.2%
unpow282.2%
unpow282.2%
times-frac70.4%
unpow270.4%
Simplified70.4%
unpow270.4%
sqr-neg70.4%
distribute-frac-neg70.4%
distribute-frac-neg70.4%
associate-*l/70.4%
*-un-lft-identity70.4%
times-frac79.6%
add-sqr-sqrt79.6%
sqrt-unprod78.5%
sqr-neg78.5%
sqrt-unprod-0.0%
add-sqr-sqrt51.4%
add-sqr-sqrt51.4%
sqrt-unprod50.5%
sqr-neg50.5%
sqrt-unprod-0.0%
add-sqr-sqrt79.6%
Applied egg-rr79.6%
div-inv79.6%
*-un-lft-identity79.6%
times-frac88.9%
/-rgt-identity88.9%
Applied egg-rr88.9%
Final simplification91.8%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -1.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (- (* 0.5 (* (/ x s) (/ x s))) (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -1.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((0.5f * ((x / s) * (x / s))) - (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 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((0.5e0 * ((x / s) * (x / s))) - (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(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x / s) * Float32(x / s))) - 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) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + ((single(0.5) * ((x / s) * (x / s))) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -1:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \left(\frac{x}{s} \cdot \frac{x}{s}\right) - \frac{x}{s}\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 93.9%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.9%
div-inv99.9%
exp-prod80.7%
neg-mul-180.7%
exp-prod80.7%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 81.9%
mul-1-neg81.9%
distribute-frac-neg81.9%
+-commutative81.9%
distribute-frac-neg81.9%
unsub-neg81.9%
unpow281.9%
unpow281.9%
times-frac80.2%
unpow280.2%
Simplified80.2%
unpow280.2%
Applied egg-rr80.2%
Final simplification85.5%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -1.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (- (* 0.5 (/ x (* s (/ s x)))) (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -1.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((0.5f * (x / (s * (s / x)))) - (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 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((0.5e0 * (x / (s * (s / x)))) - (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(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) * Float32(x / Float32(s * Float32(s / x)))) - 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) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + ((single(0.5) * (x / (s * (s / x)))) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -1:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \frac{x}{s \cdot \frac{s}{x}} - \frac{x}{s}\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 93.9%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.9%
div-inv99.9%
exp-prod80.7%
neg-mul-180.7%
exp-prod80.7%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 81.9%
mul-1-neg81.9%
distribute-frac-neg81.9%
+-commutative81.9%
distribute-frac-neg81.9%
unsub-neg81.9%
unpow281.9%
unpow281.9%
times-frac80.2%
unpow280.2%
Simplified80.2%
unpow280.2%
sqr-neg80.2%
distribute-frac-neg80.2%
distribute-frac-neg80.2%
associate-*l/80.2%
*-un-lft-identity80.2%
times-frac85.8%
add-sqr-sqrt62.4%
sqrt-unprod84.4%
sqr-neg84.4%
sqrt-unprod22.8%
add-sqr-sqrt67.7%
add-sqr-sqrt44.9%
sqrt-unprod67.4%
sqr-neg67.4%
sqrt-unprod23.4%
add-sqr-sqrt85.8%
Applied egg-rr85.8%
/-rgt-identity85.8%
associate-*r/80.2%
associate-/l*83.0%
div-inv83.0%
clear-num83.0%
Applied egg-rr83.0%
Final simplification87.2%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -1.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (- (* 0.5 (* x (/ (/ x s) s))) (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -1.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((0.5f * (x * ((x / s) / s))) - (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 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((0.5e0 * (x * ((x / s) / s))) - (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(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) * Float32(x * Float32(Float32(x / s) / s))) - 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) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + ((single(0.5) * (x * ((x / s) / s))) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -1:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \left(x \cdot \frac{\frac{x}{s}}{s}\right) - \frac{x}{s}\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 93.9%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.9%
div-inv99.9%
exp-prod80.7%
neg-mul-180.7%
exp-prod80.7%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 81.9%
mul-1-neg81.9%
distribute-frac-neg81.9%
+-commutative81.9%
distribute-frac-neg81.9%
unsub-neg81.9%
unpow281.9%
unpow281.9%
times-frac80.2%
unpow280.2%
Simplified80.2%
unpow280.2%
sqr-neg80.2%
distribute-frac-neg80.2%
distribute-frac-neg80.2%
associate-*l/80.2%
*-un-lft-identity80.2%
times-frac85.8%
add-sqr-sqrt62.4%
sqrt-unprod84.4%
sqr-neg84.4%
sqrt-unprod22.8%
add-sqr-sqrt67.7%
add-sqr-sqrt44.9%
sqrt-unprod67.4%
sqr-neg67.4%
sqrt-unprod23.4%
add-sqr-sqrt85.8%
Applied egg-rr85.8%
Final simplification88.9%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -0.0010000000474974513) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -0.0010000000474974513f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} 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) <= (-0.0010000000474974513e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
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(-0.0010000000474974513)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); 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(-0.0010000000474974513)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); 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 -0.0010000000474974513:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -0.00100000005Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 92.6%
if -0.00100000005 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 58.2%
mul-1-neg58.2%
unsub-neg58.2%
Simplified58.2%
Final simplification72.0%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -1.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -1.0f) {
tmp = 0.5f;
} 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 = 0.5e0
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(0.5); 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(0.5); 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:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 58.5%
mul-1-neg58.5%
unsub-neg58.5%
Simplified58.5%
Final simplification46.9%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ (- x) s))) (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 <= 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 <= 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(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(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 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 51.7%
if 2 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 35.7%
mul-1-neg35.7%
unsub-neg35.7%
Simplified35.7%
Taylor expanded in x around inf 35.7%
mul-1-neg35.7%
distribute-frac-neg35.7%
Simplified35.7%
Final simplification45.6%
(FPCore (x s) :precision binary32 (if (<= x -5.99999978589949e-8) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -5.99999978589949e-8f) {
tmp = 1.0f / (x / s);
} 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 <= (-5.99999978589949e-8)) then
tmp = 1.0e0 / (x / s)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-5.99999978589949e-8)) tmp = Float32(Float32(1.0) / Float32(x / s)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-5.99999978589949e-8)) tmp = single(1.0) / (x / s); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.99999978589949 \cdot 10^{-8}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.99999979e-8Initial program 100.0%
Taylor expanded in x around 0 45.5%
mul-1-neg45.5%
unsub-neg45.5%
Simplified45.5%
Taylor expanded in x around inf 40.4%
associate-*r/40.4%
neg-mul-140.4%
Simplified40.4%
remove-double-neg40.4%
frac-2neg40.4%
clear-num45.5%
inv-pow45.5%
add-sqr-sqrt45.5%
sqrt-unprod58.5%
sqr-neg58.5%
sqrt-unprod-0.0%
add-sqr-sqrt45.5%
Applied egg-rr45.5%
unpow-145.5%
Simplified45.5%
if -5.99999979e-8 < x Initial program 99.9%
Taylor expanded in x around 0 45.4%
Final simplification45.4%
(FPCore (x s) :precision binary32 (if (<= x -5.99999978589949e-8) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -5.99999978589949e-8f) {
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 <= (-5.99999978589949e-8)) 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(-5.99999978589949e-8)) 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(-5.99999978589949e-8)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.99999978589949 \cdot 10^{-8}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.99999979e-8Initial program 100.0%
Taylor expanded in x around 0 45.5%
mul-1-neg45.5%
unsub-neg45.5%
Simplified45.5%
Taylor expanded in x around inf 40.4%
associate-*r/40.4%
neg-mul-140.4%
Simplified40.4%
expm1-log1p-u40.4%
expm1-udef96.1%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod96.1%
add-sqr-sqrt96.1%
Applied egg-rr96.1%
expm1-def40.4%
expm1-log1p40.4%
Simplified40.4%
if -5.99999979e-8 < x Initial program 99.9%
Taylor expanded in x around 0 45.4%
Final simplification44.0%
(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.6%
Final simplification34.6%
herbie shell --seed 2024026
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))