
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (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 -5.0)
0.5
(if (<= t_0 9.999999680285692e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ 2.0 (/ x s))))
(/
1.0
(+
1.0
(+
1.0
(+
(* -0.6666666666666666 (/ x s))
(- (* x (/ -0.6666666666666666 s)) (/ x s))))))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -5.0f) {
tmp = 0.5f;
} else if (t_0 <= 9.999999680285692e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (2.0f + (x / s)));
} else {
tmp = 1.0f / (1.0f + (1.0f + ((-0.6666666666666666f * (x / s)) + ((x * (-0.6666666666666666f / s)) - (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 <= (-5.0e0)) then
tmp = 0.5e0
else if (t_0 <= 9.999999680285692e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (2.0e0 + (x / s)))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + (((-0.6666666666666666e0) * (x / s)) + ((x * ((-0.6666666666666666e0) / s)) - (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(-5.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(9.999999680285692e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(2.0) + Float32(x / s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(-0.6666666666666666) * Float32(x / s)) + Float32(Float32(x * Float32(Float32(-0.6666666666666666) / s)) - 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(-5.0)) tmp = single(0.5); elseif (t_0 <= single(9.999999680285692e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (single(2.0) + (x / s))); else tmp = single(1.0) / (single(1.0) + (single(1.0) + ((single(-0.6666666666666666) * (x / s)) + ((x * (single(-0.6666666666666666) / s)) - (x / s))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq -5:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left(-0.6666666666666666 \cdot \frac{x}{s} + \left(x \cdot \frac{-0.6666666666666666}{s} - \frac{x}{s}\right)\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -5 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 99.7%
Taylor expanded in x around 0 52.3%
mul-1-neg52.3%
unsub-neg52.3%
Simplified52.3%
sub-neg52.3%
flip-+69.9%
metadata-eval69.9%
distribute-neg-frac69.9%
distribute-neg-frac69.9%
distribute-neg-frac69.9%
Applied egg-rr69.9%
if 9.99999968e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod6.3%
sqr-neg6.3%
sqrt-unprod6.3%
add-sqr-sqrt6.3%
add-cube-cbrt6.3%
pow36.3%
pow-flip6.3%
add-sqr-sqrt6.3%
sqrt-unprod6.3%
sqr-neg6.3%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in s around inf 95.7%
*-commutative95.7%
metadata-eval95.7%
distribute-rgt-out--2.0%
associate-*r/2.0%
*-commutative2.0%
metadata-eval2.0%
distribute-lft-out--2.0%
*-commutative2.0%
cancel-sign-sub-inv2.0%
*-commutative2.0%
distribute-frac-neg2.0%
add-sqr-sqrt2.0%
sqrt-unprod4.1%
sqr-neg4.1%
sqrt-unprod-0.0%
add-sqr-sqrt1.7%
distribute-lft-out1.7%
metadata-eval1.7%
*-rgt-identity1.7%
metadata-eval1.7%
distribute-rgt-out1.7%
*-commutative1.7%
add-sqr-sqrt1.7%
Applied egg-rr100.0%
associate-/l*100.0%
associate-/r/100.0%
Simplified100.0%
Final simplification57.2%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -5.0)
0.5
(if (<= t_0 6.000000213819608e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ 2.0 (/ x s))))
(/
1.0
(+
1.0
(+
1.0
(/ (- (* (* x -0.6666666666666666) (/ s x)) s) (* s (/ s x))))))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -5.0f) {
tmp = 0.5f;
} else if (t_0 <= 6.000000213819608e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (2.0f + (x / s)));
} else {
tmp = 1.0f / (1.0f + (1.0f + ((((x * -0.6666666666666666f) * (s / x)) - s) / (s * (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 <= (-5.0e0)) then
tmp = 0.5e0
else if (t_0 <= 6.000000213819608e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (2.0e0 + (x / s)))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + ((((x * (-0.6666666666666666e0)) * (s / x)) - s) / (s * (s / x)))))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-5.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(6.000000213819608e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(2.0) + Float32(x / s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(Float32(x * Float32(-0.6666666666666666)) * Float32(s / x)) - s) / Float32(s * Float32(s / x)))))); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-5.0)) tmp = single(0.5); elseif (t_0 <= single(6.000000213819608e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (single(2.0) + (x / s))); else tmp = single(1.0) / (single(1.0) + (single(1.0) + ((((x * single(-0.6666666666666666)) * (s / x)) - s) / (s * (s / x))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq -5:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 6.000000213819608 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + \frac{\left(x \cdot -0.6666666666666666\right) \cdot \frac{s}{x} - s}{s \cdot \frac{s}{x}}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -5 < (/.f32 (neg.f32 x) s) < 6.00000021e37Initial program 99.7%
Taylor expanded in x around 0 53.1%
mul-1-neg53.1%
unsub-neg53.1%
Simplified53.1%
sub-neg53.1%
flip-+68.9%
metadata-eval68.9%
distribute-neg-frac68.9%
distribute-neg-frac68.9%
distribute-neg-frac68.9%
Applied egg-rr68.9%
if 6.00000021e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod6.3%
sqr-neg6.3%
sqrt-unprod6.3%
add-sqr-sqrt6.3%
add-cube-cbrt6.3%
pow36.3%
pow-flip6.3%
add-sqr-sqrt6.3%
sqrt-unprod6.3%
sqr-neg6.3%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in s around inf 88.2%
*-commutative88.2%
metadata-eval88.2%
distribute-lft-out--4.9%
*-commutative4.9%
cancel-sign-sub-inv4.9%
*-commutative4.9%
distribute-frac-neg4.9%
add-sqr-sqrt4.9%
sqrt-unprod8.7%
sqr-neg8.7%
sqrt-unprod-0.0%
add-sqr-sqrt88.6%
distribute-lft-out88.6%
metadata-eval88.6%
*-rgt-identity88.6%
metadata-eval88.6%
distribute-rgt-out88.6%
*-commutative88.6%
add-sqr-sqrt88.6%
sqrt-unprod100.0%
Applied egg-rr88.6%
Applied egg-rr100.0%
Final simplification57.2%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -5.0)
0.5
(if (<= t_0 1.9999999360571385e+38)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ 2.0 (/ x s))))
(/ 1.0 t_0)))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -5.0f) {
tmp = 0.5f;
} else if (t_0 <= 1.9999999360571385e+38f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (2.0f + (x / s)));
} else {
tmp = 1.0f / t_0;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-5.0e0)) then
tmp = 0.5e0
else if (t_0 <= 1.9999999360571385e+38) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (2.0e0 + (x / s)))
else
tmp = 1.0e0 / t_0
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-5.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(1.9999999360571385e+38)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(2.0) + Float32(x / s)))); else tmp = Float32(Float32(1.0) / t_0); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-5.0)) tmp = single(0.5); elseif (t_0 <= single(1.9999999360571385e+38)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (single(2.0) + (x / s))); else tmp = single(1.0) / t_0; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq -5:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 1.9999999360571385 \cdot 10^{+38}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t\_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -5 < (/.f32 (neg.f32 x) s) < 1.99999994e38Initial program 99.7%
Taylor expanded in x around 0 52.0%
mul-1-neg52.0%
unsub-neg52.0%
Simplified52.0%
sub-neg52.0%
flip-+70.4%
metadata-eval70.4%
distribute-neg-frac70.4%
distribute-neg-frac70.4%
distribute-neg-frac70.4%
Applied egg-rr70.4%
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 100.0%
mul-1-neg100.0%
distribute-frac-neg100.0%
Simplified100.0%
Final simplification57.2%
(FPCore (x s)
:precision binary32
(if (<= (/ (- x) s) -5.0)
0.5
(/
1.0
(+
1.0
(+
1.0
(+ (* -0.6666666666666666 (/ x s)) (* (/ x s) -0.3333333333333333)))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -5.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (1.0f + (1.0f + ((-0.6666666666666666f * (x / s)) + ((x / s) * -0.3333333333333333f))));
}
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 = 0.5e0
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + (((-0.6666666666666666e0) * (x / s)) + ((x / s) * (-0.3333333333333333e0)))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-5.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(-0.6666666666666666) * Float32(x / s)) + Float32(Float32(x / s) * Float32(-0.3333333333333333)))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-5.0)) tmp = single(0.5); else tmp = single(1.0) / (single(1.0) + (single(1.0) + ((single(-0.6666666666666666) * (x / s)) + ((x / s) * single(-0.3333333333333333))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left(-0.6666666666666666 \cdot \frac{x}{s} + \frac{x}{s} \cdot -0.3333333333333333\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
add-sqr-sqrt19.9%
sqrt-unprod38.8%
sqr-neg38.8%
sqrt-unprod19.8%
add-sqr-sqrt36.2%
add-cube-cbrt36.2%
pow336.2%
pow-flip36.2%
add-sqr-sqrt19.7%
sqrt-unprod38.8%
sqr-neg38.8%
sqrt-unprod19.9%
add-sqr-sqrt99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Taylor expanded in s around inf 61.3%
Final simplification48.2%
(FPCore (x s)
:precision binary32
(if (<= (/ (- x) s) -5.0)
0.5
(/
1.0
(+
1.0
(+ 1.0 (/ (+ (* x -0.6666666666666666) (* x -0.3333333333333333)) s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -5.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (1.0f + (1.0f + (((x * -0.6666666666666666f) + (x * -0.3333333333333333f)) / 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 = 0.5e0
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 + (((x * (-0.6666666666666666e0)) + (x * (-0.3333333333333333e0))) / 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(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(x * Float32(-0.6666666666666666)) + Float32(x * Float32(-0.3333333333333333))) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-5.0)) tmp = single(0.5); else tmp = single(1.0) / (single(1.0) + (single(1.0) + (((x * single(-0.6666666666666666)) + (x * single(-0.3333333333333333))) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 + \frac{x \cdot -0.6666666666666666 + x \cdot -0.3333333333333333}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
add-sqr-sqrt19.9%
sqrt-unprod38.8%
sqr-neg38.8%
sqrt-unprod19.8%
add-sqr-sqrt36.2%
add-cube-cbrt36.2%
pow336.2%
pow-flip36.2%
add-sqr-sqrt19.7%
sqrt-unprod38.8%
sqr-neg38.8%
sqrt-unprod19.9%
add-sqr-sqrt99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Taylor expanded in s around inf 61.3%
Taylor expanded in s around 0 61.3%
Final simplification48.2%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -5.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -5.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) <= (-5.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(-5.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(-5.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 -5:\\
\;\;\;\;0.5\\
\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 28.1%
if -5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 61.3%
mul-1-neg61.3%
unsub-neg61.3%
Simplified61.3%
Final simplification48.2%
(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 49.0%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.9%
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 simplification45.9%
(FPCore (x s) :precision binary32 (if (<= x -5.00000006675716e-11) (* (/ s x) -0.6) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
tmp = (s / x) * -0.6f;
} 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.00000006675716e-11)) then
tmp = (s / x) * (-0.6e0)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-5.00000006675716e-11)) tmp = Float32(Float32(s / x) * Float32(-0.6)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-5.00000006675716e-11)) tmp = (s / x) * single(-0.6); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{s}{x} \cdot -0.6\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
add-sqr-sqrt-0.0%
sqrt-unprod6.7%
sqr-neg6.7%
sqrt-unprod6.7%
add-sqr-sqrt6.7%
add-cube-cbrt6.7%
pow36.7%
pow-flip6.7%
add-sqr-sqrt6.7%
sqrt-unprod6.7%
sqr-neg6.7%
sqrt-unprod-0.0%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in s around inf 50.1%
*-commutative50.1%
metadata-eval50.1%
distribute-lft-out--9.0%
*-commutative9.0%
cancel-sign-sub-inv9.0%
*-commutative9.0%
distribute-frac-neg9.0%
add-sqr-sqrt9.0%
sqrt-unprod17.4%
sqr-neg17.4%
sqrt-unprod-0.0%
add-sqr-sqrt50.5%
distribute-lft-out50.5%
metadata-eval50.5%
*-rgt-identity50.5%
metadata-eval50.5%
distribute-rgt-out50.5%
*-commutative50.5%
add-sqr-sqrt50.5%
sqrt-unprod78.0%
Applied egg-rr50.5%
Taylor expanded in x around inf 47.7%
*-commutative47.7%
Simplified47.7%
if -5.00000007e-11 < x Initial program 99.8%
Taylor expanded in x around 0 44.0%
Final simplification45.1%
(FPCore (x s) :precision binary32 (if (<= x -5.00000006675716e-11) (/ s (* x -1.6666666666666667)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
tmp = s / (x * -1.6666666666666667f);
} 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.00000006675716e-11)) then
tmp = s / (x * (-1.6666666666666667e0))
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-5.00000006675716e-11)) tmp = Float32(s / Float32(x * Float32(-1.6666666666666667))); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-5.00000006675716e-11)) tmp = s / (x * single(-1.6666666666666667)); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{s}{x \cdot -1.6666666666666667}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
add-sqr-sqrt-0.0%
sqrt-unprod6.7%
sqr-neg6.7%
sqrt-unprod6.7%
add-sqr-sqrt6.7%
add-cube-cbrt6.7%
pow36.7%
pow-flip6.7%
add-sqr-sqrt6.7%
sqrt-unprod6.7%
sqr-neg6.7%
sqrt-unprod-0.0%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in s around inf 50.1%
*-commutative50.1%
metadata-eval50.1%
distribute-lft-out--9.0%
*-commutative9.0%
cancel-sign-sub-inv9.0%
*-commutative9.0%
distribute-frac-neg9.0%
add-sqr-sqrt9.0%
sqrt-unprod17.4%
sqr-neg17.4%
sqrt-unprod-0.0%
add-sqr-sqrt50.5%
distribute-lft-out50.5%
metadata-eval50.5%
*-rgt-identity50.5%
metadata-eval50.5%
distribute-rgt-out50.5%
*-commutative50.5%
add-sqr-sqrt50.5%
sqrt-unprod78.0%
Applied egg-rr50.5%
Taylor expanded in s around 0 47.7%
distribute-rgt-out47.7%
metadata-eval47.7%
Simplified47.7%
if -5.00000007e-11 < x Initial program 99.8%
Taylor expanded in x around 0 44.0%
Final simplification45.1%
(FPCore (x s) :precision binary32 (if (<= x -5.00000006675716e-11) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
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.00000006675716e-11)) 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.00000006675716e-11)) 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(-5.00000006675716e-11)) tmp = -s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 99.9%
Taylor expanded in x around 0 50.1%
mul-1-neg50.1%
unsub-neg50.1%
Simplified50.1%
Taylor expanded in x around inf 47.2%
associate-*r/47.2%
neg-mul-147.2%
Simplified47.2%
if -5.00000007e-11 < x Initial program 99.8%
Taylor expanded in x around 0 44.0%
Final simplification44.9%
(FPCore (x s) :precision binary32 (if (<= x -1.0000000116860974e-7) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.0000000116860974e-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 <= (-1.0000000116860974e-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(-1.0000000116860974e-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(-1.0000000116860974e-7)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000116860974 \cdot 10^{-7}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.00000001e-7Initial program 99.9%
Taylor expanded in x around 0 52.1%
mul-1-neg52.1%
unsub-neg52.1%
Simplified52.1%
Taylor expanded in x around inf 52.1%
mul-1-neg52.1%
distribute-frac-neg52.1%
Simplified52.1%
expm1-log1p-u52.1%
expm1-udef96.1%
clear-num96.1%
add-sqr-sqrt96.1%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod-0.0%
add-sqr-sqrt95.9%
Applied egg-rr95.9%
expm1-def49.0%
expm1-log1p49.0%
Simplified49.0%
if -1.00000001e-7 < x Initial program 99.8%
Taylor expanded in x around 0 43.3%
Final simplification44.9%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 33.4%
Final simplification33.4%
herbie shell --seed 2024027
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))