
(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 (+ (exp (/ x (- s))) 1.0)))
float code(float x, float s) {
return 1.0f / (expf((x / -s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (exp((x / -s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32(exp(Float32(x / Float32(-s))) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / (exp((x / -s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{e^{\frac{x}{-s}} + 1}
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 0.007000000216066837)
0.5
(if (<= t_0 100000000376832.0)
(/ -1.0 (* x (* (/ 1.0 (* x s)) (- x (* s 2.0)))))
(if (<= t_0 1.9999999889914546e+33)
(/ -1.0 (/ (- (* (/ x s) (/ x s)) 4.0) (/ x s)))
(/ 1.0 (/ (* x (+ 2.0 (/ x s))) x)))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= 0.007000000216066837f) {
tmp = 0.5f;
} else if (t_0 <= 100000000376832.0f) {
tmp = -1.0f / (x * ((1.0f / (x * s)) * (x - (s * 2.0f))));
} else if (t_0 <= 1.9999999889914546e+33f) {
tmp = -1.0f / ((((x / s) * (x / s)) - 4.0f) / (x / s));
} else {
tmp = 1.0f / ((x * (2.0f + (x / s))) / x);
}
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.007000000216066837e0) then
tmp = 0.5e0
else if (t_0 <= 100000000376832.0e0) then
tmp = (-1.0e0) / (x * ((1.0e0 / (x * s)) * (x - (s * 2.0e0))))
else if (t_0 <= 1.9999999889914546e+33) then
tmp = (-1.0e0) / ((((x / s) * (x / s)) - 4.0e0) / (x / s))
else
tmp = 1.0e0 / ((x * (2.0e0 + (x / s))) / x)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(0.007000000216066837)) tmp = Float32(0.5); elseif (t_0 <= Float32(100000000376832.0)) tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(Float32(1.0) / Float32(x * s)) * Float32(x - Float32(s * Float32(2.0)))))); elseif (t_0 <= Float32(1.9999999889914546e+33)) tmp = Float32(Float32(-1.0) / Float32(Float32(Float32(Float32(x / s) * Float32(x / s)) - Float32(4.0)) / Float32(x / s))); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(2.0) + Float32(x / s))) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(0.007000000216066837)) tmp = single(0.5); elseif (t_0 <= single(100000000376832.0)) tmp = single(-1.0) / (x * ((single(1.0) / (x * s)) * (x - (s * single(2.0))))); elseif (t_0 <= single(1.9999999889914546e+33)) tmp = single(-1.0) / ((((x / s) * (x / s)) - single(4.0)) / (x / s)); else tmp = single(1.0) / ((x * (single(2.0) + (x / s))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 0.007000000216066837:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 100000000376832:\\
\;\;\;\;\frac{-1}{x \cdot \left(\frac{1}{x \cdot s} \cdot \left(x - s \cdot 2\right)\right)}\\
\mathbf{elif}\;t\_0 \leq 1.9999999889914546 \cdot 10^{+33}:\\
\;\;\;\;\frac{-1}{\frac{\frac{x}{s} \cdot \frac{x}{s} - 4}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.00700000022Initial program 99.9%
Taylor expanded in x around 0 51.8%
if 0.00700000022 < (/.f32 (neg.f32 x) s) < 1e14Initial program 100.0%
Taylor expanded in x around 0 15.2%
mul-1-neg15.2%
unsub-neg15.2%
Simplified15.2%
Taylor expanded in x around inf 15.2%
sub-neg15.2%
associate-*r/15.2%
metadata-eval15.2%
distribute-neg-frac15.2%
metadata-eval15.2%
Simplified15.2%
frac-add48.8%
div-inv56.5%
fma-define56.5%
Applied egg-rr56.5%
*-commutative56.5%
mul-1-neg56.5%
fmm-def56.5%
*-commutative56.5%
Simplified56.5%
if 1e14 < (/.f32 (neg.f32 x) s) < 1.99999999e33Initial program 100.0%
Taylor expanded in x around 0 11.3%
mul-1-neg11.3%
unsub-neg11.3%
Simplified11.3%
sub-neg11.3%
flip-+89.6%
metadata-eval89.6%
distribute-neg-frac289.6%
distribute-neg-frac289.6%
distribute-neg-frac289.6%
Applied egg-rr89.6%
Taylor expanded in x around inf 89.6%
if 1.99999999e33 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
Taylor expanded in x around inf 94.0%
sub-neg94.0%
associate-*r/94.0%
metadata-eval94.0%
distribute-neg-frac94.0%
metadata-eval94.0%
Simplified94.0%
Taylor expanded in x around 0 94.0%
mul-1-neg94.0%
sub-neg94.0%
Simplified94.0%
associate-*r/100.0%
sub-neg100.0%
div-inv100.0%
distribute-rgt-neg-in100.0%
mul-1-neg100.0%
div-inv100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
frac-times100.0%
metadata-eval100.0%
metadata-eval100.0%
frac-times100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
div-inv100.0%
Applied egg-rr100.0%
Final simplification64.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))) (t_1 (+ 2.0 (/ x s))))
(if (<= t_0 -5.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 1.9999999889914546e+33)
(/ -1.0 (/ (- (/ x (* s (/ s x))) 4.0) t_1))
(/ 1.0 (/ (* x t_1) x))))))
float code(float x, float s) {
float t_0 = x / -s;
float t_1 = 2.0f + (x / s);
float tmp;
if (t_0 <= -5.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= 1.9999999889914546e+33f) {
tmp = -1.0f / (((x / (s * (s / x))) - 4.0f) / t_1);
} else {
tmp = 1.0f / ((x * t_1) / x);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: t_1
real(4) :: tmp
t_0 = x / -s
t_1 = 2.0e0 + (x / s)
if (t_0 <= (-5.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else if (t_0 <= 1.9999999889914546e+33) then
tmp = (-1.0e0) / (((x / (s * (s / x))) - 4.0e0) / t_1)
else
tmp = 1.0e0 / ((x * t_1) / x)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) t_1 = Float32(Float32(2.0) + Float32(x / s)) tmp = Float32(0.0) if (t_0 <= Float32(-5.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (t_0 <= Float32(1.9999999889914546e+33)) tmp = Float32(Float32(-1.0) / Float32(Float32(Float32(x / Float32(s * Float32(s / x))) - Float32(4.0)) / t_1)); else tmp = Float32(Float32(1.0) / Float32(Float32(x * t_1) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; t_1 = single(2.0) + (x / s); tmp = single(0.0); if (t_0 <= single(-5.0)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (t_0 <= single(1.9999999889914546e+33)) tmp = single(-1.0) / (((x / (s * (s / x))) - single(4.0)) / t_1); else tmp = single(1.0) / ((x * t_1) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
t_1 := 2 + \frac{x}{s}\\
\mathbf{if}\;t\_0 \leq -5:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq 1.9999999889914546 \cdot 10^{+33}:\\
\;\;\;\;\frac{-1}{\frac{\frac{x}{s \cdot \frac{s}{x}} - 4}{t\_1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot t\_1}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5Initial program 100.0%
Taylor expanded in x around 0 5.3%
mul-1-neg5.3%
unsub-neg5.3%
Simplified5.3%
Taylor expanded in x around inf 5.3%
sub-neg5.3%
associate-*r/5.3%
metadata-eval5.3%
distribute-neg-frac5.3%
metadata-eval5.3%
Simplified5.3%
Taylor expanded in x around 0 28.1%
if -5 < (/.f32 (neg.f32 x) s) < 1.99999999e33Initial program 99.9%
Taylor expanded in x around 0 54.5%
mul-1-neg54.5%
unsub-neg54.5%
Simplified54.5%
sub-neg54.5%
flip-+77.5%
metadata-eval77.5%
distribute-neg-frac277.5%
distribute-neg-frac277.5%
distribute-neg-frac277.5%
Applied egg-rr77.5%
clear-num77.5%
frac-times78.3%
*-un-lft-identity78.3%
add-sqr-sqrt-0.0%
sqrt-unprod81.2%
sqr-neg81.2%
sqrt-unprod78.3%
add-sqr-sqrt78.3%
add-sqr-sqrt-0.0%
sqrt-unprod81.2%
sqr-neg81.2%
sqrt-unprod78.3%
add-sqr-sqrt78.3%
Applied egg-rr78.3%
if 1.99999999e33 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
Taylor expanded in x around inf 94.0%
sub-neg94.0%
associate-*r/94.0%
metadata-eval94.0%
distribute-neg-frac94.0%
metadata-eval94.0%
Simplified94.0%
Taylor expanded in x around 0 94.0%
mul-1-neg94.0%
sub-neg94.0%
Simplified94.0%
associate-*r/100.0%
sub-neg100.0%
div-inv100.0%
distribute-rgt-neg-in100.0%
mul-1-neg100.0%
div-inv100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
frac-times100.0%
metadata-eval100.0%
metadata-eval100.0%
frac-times100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
div-inv100.0%
Applied egg-rr100.0%
Final simplification62.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 2.0)
0.5
(if (<= t_0 5.000000100204387e+20)
(/ 1.0 (* x (/ (+ x (* s -2.0)) (* x s))))
(/ 1.0 (/ (* x (+ 2.0 (/ x s))) x))))))
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 <= 5.000000100204387e+20f) {
tmp = 1.0f / (x * ((x + (s * -2.0f)) / (x * s)));
} else {
tmp = 1.0f / ((x * (2.0f + (x / s))) / x);
}
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 <= 5.000000100204387e+20) then
tmp = 1.0e0 / (x * ((x + (s * (-2.0e0))) / (x * s)))
else
tmp = 1.0e0 / ((x * (2.0e0 + (x / s))) / x)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(2.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(5.000000100204387e+20)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(x + Float32(s * Float32(-2.0))) / Float32(x * s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(2.0) + Float32(x / s))) / x)); 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(5.000000100204387e+20)) tmp = single(1.0) / (x * ((x + (s * single(-2.0))) / (x * s))); else tmp = single(1.0) / ((x * (single(2.0) + (x / s))) / x); 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 5.000000100204387 \cdot 10^{+20}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x + s \cdot -2}{x \cdot s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 51.5%
if 2 < (/.f32 (neg.f32 x) s) < 5.0000001e20Initial program 100.0%
Taylor expanded in x around 0 7.7%
mul-1-neg7.7%
unsub-neg7.7%
Simplified7.7%
Taylor expanded in x around inf 7.7%
sub-neg7.7%
associate-*r/7.7%
metadata-eval7.7%
distribute-neg-frac7.7%
metadata-eval7.7%
Simplified7.7%
+-commutative7.7%
frac-2neg7.7%
metadata-eval7.7%
frac-2neg7.7%
frac-add38.7%
*-un-lft-identity38.7%
add-sqr-sqrt38.7%
sqrt-unprod38.7%
sqr-neg38.7%
sqrt-unprod-0.0%
add-sqr-sqrt38.7%
add-sqr-sqrt-0.0%
sqrt-unprod38.7%
sqr-neg38.7%
sqrt-unprod38.7%
add-sqr-sqrt38.7%
metadata-eval38.7%
add-sqr-sqrt-0.0%
sqrt-unprod52.2%
sqr-neg52.2%
sqrt-unprod38.7%
add-sqr-sqrt38.7%
add-sqr-sqrt38.7%
sqrt-unprod38.7%
sqr-neg38.7%
Applied egg-rr38.7%
if 5.0000001e20 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 60.2%
mul-1-neg60.2%
unsub-neg60.2%
Simplified60.2%
Taylor expanded in x around inf 60.2%
sub-neg60.2%
associate-*r/60.2%
metadata-eval60.2%
distribute-neg-frac60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around 0 60.2%
mul-1-neg60.2%
sub-neg60.2%
Simplified60.2%
associate-*r/76.6%
sub-neg76.6%
div-inv76.6%
distribute-rgt-neg-in76.6%
mul-1-neg76.6%
div-inv76.6%
add-sqr-sqrt-0.0%
sqrt-unprod94.7%
frac-times94.7%
metadata-eval94.7%
metadata-eval94.7%
frac-times94.7%
sqrt-unprod76.6%
add-sqr-sqrt76.6%
div-inv76.6%
Applied egg-rr76.6%
Final simplification56.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 4.999999873689376e-5)
0.5
(if (<= t_0 5.000000100204387e+20)
(/ (* (* x s) (/ -1.0 x)) (- x (* s 2.0)))
(/ 1.0 (/ (* x (+ 2.0 (/ x s))) x))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= 4.999999873689376e-5f) {
tmp = 0.5f;
} else if (t_0 <= 5.000000100204387e+20f) {
tmp = ((x * s) * (-1.0f / x)) / (x - (s * 2.0f));
} else {
tmp = 1.0f / ((x * (2.0f + (x / s))) / x);
}
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 <= 4.999999873689376e-5) then
tmp = 0.5e0
else if (t_0 <= 5.000000100204387e+20) then
tmp = ((x * s) * ((-1.0e0) / x)) / (x - (s * 2.0e0))
else
tmp = 1.0e0 / ((x * (2.0e0 + (x / s))) / x)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(4.999999873689376e-5)) tmp = Float32(0.5); elseif (t_0 <= Float32(5.000000100204387e+20)) tmp = Float32(Float32(Float32(x * s) * Float32(Float32(-1.0) / x)) / Float32(x - Float32(s * Float32(2.0)))); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(2.0) + Float32(x / s))) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(4.999999873689376e-5)) tmp = single(0.5); elseif (t_0 <= single(5.000000100204387e+20)) tmp = ((x * s) * (single(-1.0) / x)) / (x - (s * single(2.0))); else tmp = single(1.0) / ((x * (single(2.0) + (x / s))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 5.000000100204387 \cdot 10^{+20}:\\
\;\;\;\;\frac{\left(x \cdot s\right) \cdot \frac{-1}{x}}{x - s \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 4.99999987e-5Initial program 99.9%
Taylor expanded in x around 0 51.6%
if 4.99999987e-5 < (/.f32 (neg.f32 x) s) < 5.0000001e20Initial program 99.8%
Taylor expanded in x around 0 22.3%
mul-1-neg22.3%
unsub-neg22.3%
Simplified22.3%
Taylor expanded in x around inf 22.3%
sub-neg22.3%
associate-*r/22.3%
metadata-eval22.3%
distribute-neg-frac22.3%
metadata-eval22.3%
Simplified22.3%
frac-add44.7%
div-inv51.6%
fma-define51.6%
Applied egg-rr51.6%
*-commutative51.6%
mul-1-neg51.6%
fmm-def51.6%
*-commutative51.6%
Simplified51.6%
associate-/r*51.7%
*-un-lft-identity51.7%
*-commutative51.7%
times-frac28.4%
clear-num18.2%
/-rgt-identity18.2%
*-commutative18.2%
Applied egg-rr18.2%
associate-*r/44.8%
Simplified44.8%
if 5.0000001e20 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 60.2%
mul-1-neg60.2%
unsub-neg60.2%
Simplified60.2%
Taylor expanded in x around inf 60.2%
sub-neg60.2%
associate-*r/60.2%
metadata-eval60.2%
distribute-neg-frac60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around 0 60.2%
mul-1-neg60.2%
sub-neg60.2%
Simplified60.2%
associate-*r/76.6%
sub-neg76.6%
div-inv76.6%
distribute-rgt-neg-in76.6%
mul-1-neg76.6%
div-inv76.6%
add-sqr-sqrt-0.0%
sqrt-unprod94.7%
frac-times94.7%
metadata-eval94.7%
metadata-eval94.7%
frac-times94.7%
sqrt-unprod76.6%
add-sqr-sqrt76.6%
div-inv76.6%
Applied egg-rr76.6%
Final simplification57.3%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.007000000216066837) 0.5 (/ -1.0 (* x (* (/ 1.0 (* x s)) (- x (* s 2.0)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.007000000216066837f) {
tmp = 0.5f;
} else {
tmp = -1.0f / (x * ((1.0f / (x * s)) * (x - (s * 2.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) <= 0.007000000216066837e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x * ((1.0e0 / (x * s)) * (x - (s * 2.0e0))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(0.007000000216066837)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(Float32(1.0) / Float32(x * s)) * Float32(x - Float32(s * Float32(2.0)))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(0.007000000216066837)) tmp = single(0.5); else tmp = single(-1.0) / (x * ((single(1.0) / (x * s)) * (x - (s * single(2.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 0.007000000216066837:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \left(\frac{1}{x \cdot s} \cdot \left(x - s \cdot 2\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.00700000022Initial program 99.9%
Taylor expanded in x around 0 51.8%
if 0.00700000022 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 45.7%
mul-1-neg45.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 45.7%
sub-neg45.7%
associate-*r/45.7%
metadata-eval45.7%
distribute-neg-frac45.7%
metadata-eval45.7%
Simplified45.7%
frac-add54.7%
div-inv62.0%
fma-define62.0%
Applied egg-rr62.0%
*-commutative62.0%
mul-1-neg62.0%
fmm-def62.0%
*-commutative62.0%
Simplified62.0%
Final simplification55.7%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0) 0.5 (/ 1.0 (/ (* x (+ 2.0 (/ x s))) x))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((x * (2.0f + (x / 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) <= 2.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((x * (2.0e0 + (x / s))) / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(2.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(2.0) + Float32(x / s))) / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(2.0)) tmp = single(0.5); else tmp = single(1.0) / ((x * (single(2.0) + (x / s))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 51.5%
if 2 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 45.3%
mul-1-neg45.3%
unsub-neg45.3%
Simplified45.3%
Taylor expanded in x around inf 45.3%
sub-neg45.3%
associate-*r/45.3%
metadata-eval45.3%
distribute-neg-frac45.3%
metadata-eval45.3%
Simplified45.3%
Taylor expanded in x around 0 45.3%
mul-1-neg45.3%
sub-neg45.3%
Simplified45.3%
associate-*r/57.0%
sub-neg57.0%
div-inv57.0%
distribute-rgt-neg-in57.0%
mul-1-neg57.0%
div-inv57.0%
add-sqr-sqrt-0.0%
sqrt-unprod83.6%
frac-times83.6%
metadata-eval83.6%
metadata-eval83.6%
frac-times83.6%
sqrt-unprod57.0%
add-sqr-sqrt57.0%
div-inv57.0%
Applied egg-rr57.0%
Final simplification53.5%
(FPCore (x s) :precision binary32 (if (<= (- x) 3.999999999279835e-23) 0.5 (* x (/ s (* x (- (* s 2.0) x))))))
float code(float x, float s) {
float tmp;
if (-x <= 3.999999999279835e-23f) {
tmp = 0.5f;
} else {
tmp = x * (s / (x * ((s * 2.0f) - x)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= 3.999999999279835e-23) then
tmp = 0.5e0
else
tmp = x * (s / (x * ((s * 2.0e0) - x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(3.999999999279835e-23)) tmp = Float32(0.5); else tmp = Float32(x * Float32(s / Float32(x * Float32(Float32(s * Float32(2.0)) - x)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(3.999999999279835e-23)) tmp = single(0.5); else tmp = x * (s / (x * ((s * single(2.0)) - x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 3.999999999279835 \cdot 10^{-23}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{s}{x \cdot \left(s \cdot 2 - x\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 4e-23Initial program 100.0%
Taylor expanded in x around 0 47.0%
if 4e-23 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 54.2%
mul-1-neg54.2%
unsub-neg54.2%
Simplified54.2%
Taylor expanded in x around inf 54.2%
sub-neg54.2%
associate-*r/54.2%
metadata-eval54.2%
distribute-neg-frac54.2%
metadata-eval54.2%
Simplified54.2%
frac-add55.8%
div-inv61.5%
fma-define61.5%
Applied egg-rr61.5%
*-commutative61.5%
mul-1-neg61.5%
fmm-def61.5%
*-commutative61.5%
Simplified61.5%
associate-/r*56.8%
*-un-lft-identity56.8%
*-commutative56.8%
times-frac61.3%
clear-num54.3%
/-rgt-identity54.3%
*-commutative54.3%
Applied egg-rr54.3%
associate-*l*55.5%
associate-/l/56.3%
*-commutative56.3%
associate-*r/57.7%
*-rgt-identity57.7%
Simplified57.7%
Final simplification51.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -5.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -5.0f) {
tmp = 1.0f / (x * (2.0f / 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) <= (-5.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / 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(x / Float32(-s)) <= Float32(-5.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / 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(-5.0)) tmp = single(1.0) / (x * (single(2.0) / 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 -5:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5Initial program 100.0%
Taylor expanded in x around 0 5.3%
mul-1-neg5.3%
unsub-neg5.3%
Simplified5.3%
Taylor expanded in x around inf 5.3%
sub-neg5.3%
associate-*r/5.3%
metadata-eval5.3%
distribute-neg-frac5.3%
metadata-eval5.3%
Simplified5.3%
Taylor expanded in x around 0 28.1%
if -5 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 64.5%
mul-1-neg64.5%
unsub-neg64.5%
Simplified64.5%
Final simplification50.7%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0) 0.5 (/ 1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 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) :: tmp
if ((x / -s) <= 2.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= 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) tmp = single(0.0); if ((x / -s) <= 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}
\mathbf{if}\;\frac{x}{-s} \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 51.5%
if 2 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 45.3%
mul-1-neg45.3%
unsub-neg45.3%
Simplified45.3%
Taylor expanded in x around inf 40.2%
associate-*r/40.2%
neg-mul-140.2%
Simplified40.2%
add-sqr-sqrt-0.0%
sqrt-unprod65.4%
sqr-neg65.4%
sqrt-unprod40.2%
add-sqr-sqrt40.2%
*-un-lft-identity40.2%
Applied egg-rr40.2%
*-lft-identity40.2%
Simplified40.2%
clear-num45.3%
inv-pow45.3%
Applied egg-rr45.3%
unpow-145.3%
Simplified45.3%
Final simplification49.2%
(FPCore (x s) :precision binary32 (if (<= x -4.999999987376214e-7) (* s (/ 1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999987376214e-7f) {
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 <= (-4.999999987376214e-7)) 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(-4.999999987376214e-7)) 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(-4.999999987376214e-7)) 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 -4.999999987376214 \cdot 10^{-7}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999999e-7Initial program 100.0%
Taylor expanded in x around 0 54.0%
mul-1-neg54.0%
unsub-neg54.0%
Simplified54.0%
Taylor expanded in x around inf 47.7%
associate-*r/47.7%
neg-mul-147.7%
Simplified47.7%
clear-num54.0%
distribute-frac-neg254.0%
distribute-frac-neg54.0%
associate-/r/47.7%
add-sqr-sqrt47.7%
sqrt-unprod56.3%
sqr-neg56.3%
sqrt-unprod-0.0%
add-sqr-sqrt47.7%
Applied egg-rr47.7%
if -4.99999999e-7 < x Initial program 99.9%
Taylor expanded in x around 0 46.9%
Final simplification47.2%
(FPCore (x s) :precision binary32 (if (<= x -4.999999987376214e-7) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999987376214e-7f) {
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 <= (-4.999999987376214e-7)) 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(-4.999999987376214e-7)) 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(-4.999999987376214e-7)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999987376214 \cdot 10^{-7}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999999e-7Initial program 100.0%
Taylor expanded in x around 0 54.0%
mul-1-neg54.0%
unsub-neg54.0%
Simplified54.0%
Taylor expanded in x around inf 47.7%
associate-*r/47.7%
neg-mul-147.7%
Simplified47.7%
add-sqr-sqrt-0.0%
sqrt-unprod59.8%
sqr-neg59.8%
sqrt-unprod47.7%
add-sqr-sqrt47.7%
*-un-lft-identity47.7%
Applied egg-rr47.7%
*-lft-identity47.7%
Simplified47.7%
if -4.99999999e-7 < x Initial program 99.9%
Taylor expanded in x around 0 46.9%
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.9%
Taylor expanded in x around 0 34.7%
Final simplification34.7%
herbie shell --seed 2024089
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))