
(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 (pow (hypot 1.0 (pow (exp -0.5) (/ x s))) -2.0))
float code(float x, float s) {
return powf(hypotf(1.0f, powf(expf(-0.5f), (x / s))), -2.0f);
}
function code(x, s) return hypot(Float32(1.0), (exp(Float32(-0.5)) ^ Float32(x / s))) ^ Float32(-2.0) end
function tmp = code(x, s) tmp = hypot(single(1.0), (exp(single(-0.5)) ^ (x / s))) ^ single(-2.0); end
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(1, {\left(e^{-0.5}\right)}^{\left(\frac{x}{s}\right)}\right)\right)}^{-2}
\end{array}
Initial program 99.6%
div-inv99.6%
exp-prod80.1%
neg-mul-180.1%
exp-prod80.1%
pow-pow99.5%
div-inv99.6%
Applied egg-rr99.6%
inv-pow99.6%
add-sqr-sqrt99.6%
add-sqr-sqrt99.6%
pow-exp99.6%
*-commutative99.6%
pow-exp99.5%
metadata-eval99.5%
pow-pow99.2%
add-sqr-sqrt98.6%
unpow-prod-down98.6%
Applied egg-rr99.1%
pow-sqr99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around inf 99.7%
exp-prod99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (pow (hypot 1.0 (exp (* -0.5 (/ x s)))) -2.0))
float code(float x, float s) {
return powf(hypotf(1.0f, expf((-0.5f * (x / s)))), -2.0f);
}
function code(x, s) return hypot(Float32(1.0), exp(Float32(Float32(-0.5) * Float32(x / s)))) ^ Float32(-2.0) end
function tmp = code(x, s) tmp = hypot(single(1.0), exp((single(-0.5) * (x / s)))) ^ single(-2.0); end
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(1, e^{-0.5 \cdot \frac{x}{s}}\right)\right)}^{-2}
\end{array}
Initial program 99.6%
div-inv99.6%
exp-prod80.1%
neg-mul-180.1%
exp-prod80.1%
pow-pow99.5%
div-inv99.6%
Applied egg-rr99.6%
inv-pow99.6%
add-sqr-sqrt99.6%
add-sqr-sqrt99.6%
pow-exp99.6%
*-commutative99.6%
pow-exp99.5%
metadata-eval99.5%
pow-pow99.2%
add-sqr-sqrt98.6%
unpow-prod-down98.6%
Applied egg-rr99.1%
pow-sqr99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around inf 99.7%
Final simplification99.7%
(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.6%
div-inv99.6%
exp-prod80.1%
neg-mul-180.1%
exp-prod80.1%
pow-pow99.5%
div-inv99.6%
Applied egg-rr99.6%
add-exp-log99.6%
log-rec99.6%
log1p-udef99.6%
pow-exp99.7%
neg-mul-199.7%
distribute-neg-frac99.7%
Applied egg-rr99.7%
Final simplification99.7%
(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.6%
div-inv99.6%
exp-prod80.1%
neg-mul-180.1%
exp-prod80.1%
pow-pow99.5%
div-inv99.6%
Applied egg-rr99.6%
Final simplification99.6%
(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.6%
Final simplification99.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -10.0)
0.5
(if (<= t_0 1.0000000409184788e+35)
(/ 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 <= -10.0f) {
tmp = 0.5f;
} else if (t_0 <= 1.0000000409184788e+35f) {
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 <= (-10.0e0)) then
tmp = 0.5e0
else if (t_0 <= 1.0000000409184788e+35) 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(-10.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(1.0000000409184788e+35)) 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(-10.0)) tmp = single(0.5); elseif (t_0 <= single(1.0000000409184788e+35)) 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 -10:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 1.0000000409184788 \cdot 10^{+35}:\\
\;\;\;\;\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) < -10Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) < 1.00000004e35Initial program 99.2%
Taylor expanded in x around 0 55.1%
mul-1-neg55.1%
unsub-neg55.1%
Simplified55.1%
sub-neg55.1%
neg-mul-155.1%
add-log-exp94.4%
log-pow94.8%
metadata-eval94.8%
pow-pow94.8%
flip-+50.2%
Applied egg-rr77.9%
distribute-frac-neg77.9%
distribute-frac-neg77.9%
sqr-neg77.9%
clear-num77.9%
frac-times80.0%
*-un-lft-identity80.0%
Applied egg-rr80.0%
*-un-lft-identity80.0%
frac-times77.9%
clear-num77.9%
Applied egg-rr77.9%
if 1.00000004e35 < (/.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%
sub-neg100.0%
neg-mul-1100.0%
add-log-exp100.0%
log-pow100.0%
metadata-eval100.0%
pow-pow100.0%
flip-+-0.0%
Applied egg-rr-0.0%
distribute-frac-neg-0.0%
distribute-frac-neg-0.0%
sqr-neg-0.0%
clear-num-0.0%
frac-2neg-0.0%
frac-times-0.0%
*-un-lft-identity-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
Applied egg-rr-0.0%
Taylor expanded in x around inf 100.0%
Final simplification62.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -10.0)
0.5
(if (<= t_0 1.0000000409184788e+35)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ (/ x s) 2.0)))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -10.0f) {
tmp = 0.5f;
} else if (t_0 <= 1.0000000409184788e+35f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / ((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 <= (-10.0e0)) then
tmp = 0.5e0
else if (t_0 <= 1.0000000409184788e+35) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / ((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(-10.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(1.0000000409184788e+35)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x / Float32(s * Float32(s / x)))) / 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(-10.0)) tmp = single(0.5); elseif (t_0 <= single(1.0000000409184788e+35)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / ((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 -10:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 1.0000000409184788 \cdot 10^{+35}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) < 1.00000004e35Initial program 99.2%
Taylor expanded in x around 0 55.1%
mul-1-neg55.1%
unsub-neg55.1%
Simplified55.1%
sub-neg55.1%
neg-mul-155.1%
add-log-exp94.4%
log-pow94.8%
metadata-eval94.8%
pow-pow94.8%
flip-+50.2%
Applied egg-rr77.9%
distribute-frac-neg77.9%
distribute-frac-neg77.9%
sqr-neg77.9%
clear-num77.9%
frac-times80.0%
*-un-lft-identity80.0%
Applied egg-rr80.0%
if 1.00000004e35 < (/.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%
sub-neg100.0%
neg-mul-1100.0%
add-log-exp100.0%
log-pow100.0%
metadata-eval100.0%
pow-pow100.0%
flip-+-0.0%
Applied egg-rr-0.0%
distribute-frac-neg-0.0%
distribute-frac-neg-0.0%
sqr-neg-0.0%
clear-num-0.0%
frac-2neg-0.0%
frac-times-0.0%
*-un-lft-identity-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
Applied egg-rr-0.0%
Taylor expanded in x around inf 100.0%
Final simplification64.0%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 2.0)
0.5
(if (<= t_0 1.0000000409184788e+35)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (/ x s)))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= 2.0f) {
tmp = 0.5f;
} else if (t_0 <= 1.0000000409184788e+35f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (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 <= 2.0e0) then
tmp = 0.5e0
else if (t_0 <= 1.0000000409184788e+35) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (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(2.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(1.0000000409184788e+35)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / 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(2.0)) tmp = single(0.5); elseif (t_0 <= single(1.0000000409184788e+35)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (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 2:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 1.0000000409184788 \cdot 10^{+35}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.8%
Taylor expanded in x around 0 53.4%
if 2 < (/.f32 (neg.f32 x) s) < 1.00000004e35Initial program 98.9%
Taylor expanded in x around 0 10.7%
mul-1-neg10.7%
unsub-neg10.7%
Simplified10.7%
sub-neg10.7%
neg-mul-110.7%
add-log-exp95.7%
log-pow96.4%
metadata-eval96.4%
pow-pow96.4%
flip-+0.3%
Applied egg-rr60.0%
Taylor expanded in x around inf 60.0%
if 1.00000004e35 < (/.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%
sub-neg100.0%
neg-mul-1100.0%
add-log-exp100.0%
log-pow100.0%
metadata-eval100.0%
pow-pow100.0%
flip-+-0.0%
Applied egg-rr-0.0%
distribute-frac-neg-0.0%
distribute-frac-neg-0.0%
sqr-neg-0.0%
clear-num-0.0%
frac-2neg-0.0%
frac-times-0.0%
*-un-lft-identity-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
Applied egg-rr-0.0%
Taylor expanded in x around inf 100.0%
Final simplification60.7%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -10.0) 0.5 (/ 1.0 (+ 2.0 (/ 0.3333333333333333 (/ s (* x -3.0)))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (2.0f + (0.3333333333333333f / (s / (x * -3.0f))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((-x / s) <= (-10.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 + (0.3333333333333333e0 / (s / (x * (-3.0e0)))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(0.3333333333333333) / Float32(s / Float32(x * Float32(-3.0)))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-10.0)) tmp = single(0.5); else tmp = single(1.0) / (single(2.0) + (single(0.3333333333333333) / (s / (x * single(-3.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{0.3333333333333333}{\frac{s}{x \cdot -3}}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.4%
distribute-frac-neg99.4%
exp-neg99.3%
div-inv99.3%
add-sqr-sqrt17.0%
sqrt-unprod41.9%
sqr-neg41.9%
sqrt-unprod26.0%
add-sqr-sqrt40.3%
div-inv40.3%
add-cbrt-cube40.3%
pow1/340.3%
pow-flip40.3%
Applied egg-rr98.8%
Taylor expanded in s around -inf 63.5%
distribute-rgt-out63.5%
metadata-eval63.5%
Simplified63.5%
expm1-log1p-u63.5%
expm1-udef90.3%
associate-+r+90.2%
metadata-eval90.2%
associate-*r/90.2%
Applied egg-rr90.2%
expm1-def63.5%
expm1-log1p63.5%
associate-/l*63.5%
Simplified63.5%
Final simplification51.0%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -10.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.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) <= (-10.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(-10.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(-10.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 -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.4%
Taylor expanded in x around 0 63.5%
mul-1-neg63.5%
unsub-neg63.5%
Simplified63.5%
Final simplification51.0%
(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.8%
Taylor expanded in x around 0 53.4%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.3%
Taylor expanded in x around 0 40.4%
mul-1-neg40.4%
unsub-neg40.4%
Simplified40.4%
Taylor expanded in x around inf 40.4%
mul-1-neg40.4%
distribute-frac-neg40.4%
Simplified40.4%
Final simplification48.7%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-6) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-6f) {
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 <= (-9.999999747378752e-6)) 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(-9.999999747378752e-6)) 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(-9.999999747378752e-6)) 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 -9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-6Initial program 99.8%
Taylor expanded in x around 0 52.1%
mul-1-neg52.1%
unsub-neg52.1%
Simplified52.1%
sub-neg52.1%
neg-mul-152.1%
add-log-exp98.7%
log-pow98.7%
metadata-eval98.7%
pow-pow98.7%
flip-+-0.0%
Applied egg-rr40.9%
distribute-frac-neg40.9%
distribute-frac-neg40.9%
sqr-neg40.9%
clear-num40.9%
frac-2neg40.9%
frac-times40.9%
*-un-lft-identity40.9%
add-sqr-sqrt40.9%
sqrt-unprod40.9%
sqr-neg40.9%
sqrt-unprod-0.0%
add-sqr-sqrt40.8%
Applied egg-rr40.8%
Taylor expanded in x around inf 52.0%
if -9.99999975e-6 < x Initial program 99.5%
Taylor expanded in x around 0 47.2%
Final simplification48.5%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-6) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-6f) {
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-6)) 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-6)) tmp = Float32(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-6)) 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^{-6}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-6Initial program 99.8%
Taylor expanded in x around 0 52.1%
mul-1-neg52.1%
unsub-neg52.1%
Simplified52.1%
Taylor expanded in x around inf 47.1%
associate-*r/47.1%
neg-mul-147.1%
Simplified47.1%
if -9.99999975e-6 < x Initial program 99.5%
Taylor expanded in x around 0 47.2%
Final simplification47.2%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-6) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-6f) {
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-6)) 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-6)) 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-6)) 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^{-6}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-6Initial program 99.8%
Taylor expanded in x around 0 52.1%
mul-1-neg52.1%
unsub-neg52.1%
Simplified52.1%
sub-neg52.1%
neg-mul-152.1%
add-log-exp98.7%
log-pow98.7%
metadata-eval98.7%
pow-pow98.7%
flip-+-0.0%
Applied egg-rr40.9%
distribute-frac-neg40.9%
distribute-frac-neg40.9%
sqr-neg40.9%
clear-num40.9%
frac-2neg40.9%
frac-times40.9%
*-un-lft-identity40.9%
add-sqr-sqrt40.9%
sqrt-unprod40.9%
sqr-neg40.9%
sqrt-unprod-0.0%
add-sqr-sqrt40.8%
Applied egg-rr40.8%
Taylor expanded in x around inf 47.0%
if -9.99999975e-6 < x Initial program 99.5%
Taylor expanded in x around 0 47.2%
Final simplification47.2%
(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.6%
Taylor expanded in x around 0 36.4%
Final simplification36.4%
herbie shell --seed 2024031
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))