
(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.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 2.5)
(/ 1.0 (+ (/ 1.0 (+ (/ x s) 1.0)) 1.0))
(if (<= t_0 3999999937226998000.0)
(/ -1.0 (* x (* (- (* s -2.0) x) (/ -1.0 (* x s)))))
(if (<= t_0 INFINITY)
(/ 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 <= 2.5f) {
tmp = 1.0f / ((1.0f / ((x / s) + 1.0f)) + 1.0f);
} else if (t_0 <= 3999999937226998000.0f) {
tmp = -1.0f / (x * (((s * -2.0f) - x) * (-1.0f / (x * s))));
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (x / s);
}
return tmp;
}
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(2.5)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / Float32(Float32(x / s) + Float32(1.0))) + Float32(1.0))); elseif (t_0 <= Float32(3999999937226998000.0)) tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(Float32(s * Float32(-2.0)) - x) * Float32(Float32(-1.0) / Float32(x * s))))); elseif (t_0 <= Float32(Inf)) 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(2.5)) tmp = single(1.0) / ((single(1.0) / ((x / s) + single(1.0))) + single(1.0)); elseif (t_0 <= single(3999999937226998000.0)) tmp = single(-1.0) / (x * (((s * single(-2.0)) - x) * (single(-1.0) / (x * s)))); elseif (t_0 <= single(Inf)) 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 2.5:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{x}{s} + 1} + 1}\\
\mathbf{elif}\;t\_0 \leq 3999999937226998000:\\
\;\;\;\;\frac{-1}{x \cdot \left(\left(s \cdot -2 - x\right) \cdot \frac{-1}{x \cdot s}\right)}\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\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) < 2.5Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 93.9%
if 2.5 < (/.f32 (neg.f32 x) s) < 3.99999994e18Initial program 99.3%
Taylor expanded in x around 0 9.3%
mul-1-neg9.3%
unsub-neg9.3%
Simplified9.3%
Taylor expanded in x around inf 9.3%
associate-*r/9.3%
metadata-eval9.3%
Simplified9.3%
frac-sub41.0%
div-inv49.7%
*-commutative49.7%
add-sqr-sqrt49.7%
sqrt-unprod49.7%
sqr-neg49.7%
sqrt-unprod-0.0%
add-sqr-sqrt49.5%
distribute-lft-neg-in49.5%
*-commutative49.5%
distribute-lft-neg-in49.5%
metadata-eval49.5%
*-rgt-identity49.5%
Applied egg-rr49.5%
*-commutative49.5%
Simplified49.5%
if 3.99999994e18 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 100.0%
Taylor expanded in x around 0 65.1%
mul-1-neg65.1%
unsub-neg65.1%
Simplified65.1%
*-un-lft-identity65.1%
cancel-sign-sub-inv65.1%
metadata-eval65.1%
add-log-exp100.0%
pow-exp100.0%
flip-+-0.0%
metadata-eval-0.0%
pow-exp-0.0%
add-log-exp-0.0%
neg-mul-1-0.0%
pow-exp-0.0%
add-log-exp-0.0%
neg-mul-1-0.0%
distribute-neg-frac2-0.0%
distribute-neg-frac2-0.0%
pow-exp-0.0%
Applied egg-rr41.2%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 44.0%
mul-1-neg44.0%
unsub-neg44.0%
Simplified44.0%
Taylor expanded in x around inf 21.3%
associate-*r/21.3%
neg-mul-121.3%
Simplified21.3%
add-sqr-sqrt-0.0%
sqrt-unprod32.3%
sqr-neg32.3%
sqrt-unprod22.7%
add-sqr-sqrt22.7%
clear-num23.6%
inv-pow23.6%
Applied egg-rr23.6%
unpow-123.6%
Simplified23.6%
Final simplification74.4%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.5) (/ 1.0 (+ (/ 1.0 (+ (/ x s) 1.0)) 1.0)) (/ -1.0 (* x (* (- (* s -2.0) x) (/ -1.0 (* x s)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.5f) {
tmp = 1.0f / ((1.0f / ((x / s) + 1.0f)) + 1.0f);
} else {
tmp = -1.0f / (x * (((s * -2.0f) - x) * (-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.5e0) then
tmp = 1.0e0 / ((1.0e0 / ((x / s) + 1.0e0)) + 1.0e0)
else
tmp = (-1.0e0) / (x * (((s * (-2.0e0)) - x) * ((-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.5)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / Float32(Float32(x / s) + Float32(1.0))) + Float32(1.0))); else tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(Float32(s * Float32(-2.0)) - x) * 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.5)) tmp = single(1.0) / ((single(1.0) / ((x / s) + single(1.0))) + single(1.0)); else tmp = single(-1.0) / (x * (((s * single(-2.0)) - x) * (single(-1.0) / (x * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 2.5:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{x}{s} + 1} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \left(\left(s \cdot -2 - x\right) \cdot \frac{-1}{x \cdot s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2.5Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 93.9%
if 2.5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 47.3%
mul-1-neg47.3%
unsub-neg47.3%
Simplified47.3%
Taylor expanded in x around inf 47.3%
associate-*r/47.3%
metadata-eval47.3%
Simplified47.3%
frac-sub59.2%
div-inv63.7%
*-commutative63.7%
add-sqr-sqrt63.7%
sqrt-unprod63.7%
sqr-neg63.7%
sqrt-unprod-0.0%
add-sqr-sqrt63.7%
distribute-lft-neg-in63.7%
*-commutative63.7%
distribute-lft-neg-in63.7%
metadata-eval63.7%
*-rgt-identity63.7%
Applied egg-rr63.7%
*-commutative63.7%
Simplified63.7%
Final simplification82.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.5) (/ 1.0 (+ (/ 1.0 (+ (/ x s) 1.0)) 1.0)) (/ -1.0 (* x (/ (- x (* s -2.0)) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.5f) {
tmp = 1.0f / ((1.0f / ((x / s) + 1.0f)) + 1.0f);
} else {
tmp = -1.0f / (x * ((x - (s * -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) <= 2.5e0) then
tmp = 1.0e0 / ((1.0e0 / ((x / s) + 1.0e0)) + 1.0e0)
else
tmp = (-1.0e0) / (x * ((x - (s * (-2.0e0))) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(2.5)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / Float32(Float32(x / s) + Float32(1.0))) + Float32(1.0))); else tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(x - Float32(s * Float32(-2.0))) / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(2.5)) tmp = single(1.0) / ((single(1.0) / ((x / s) + single(1.0))) + single(1.0)); else tmp = single(-1.0) / (x * ((x - (s * single(-2.0))) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 2.5:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{x}{s} + 1} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot -2}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2.5Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 93.9%
if 2.5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 47.3%
mul-1-neg47.3%
unsub-neg47.3%
Simplified47.3%
Taylor expanded in x around inf 47.3%
associate-*r/47.3%
metadata-eval47.3%
Simplified47.3%
frac-sub59.2%
div-inv63.7%
*-commutative63.7%
add-sqr-sqrt63.7%
sqrt-unprod63.7%
sqr-neg63.7%
sqrt-unprod-0.0%
add-sqr-sqrt63.7%
distribute-lft-neg-in63.7%
*-commutative63.7%
distribute-lft-neg-in63.7%
metadata-eval63.7%
*-rgt-identity63.7%
Applied egg-rr63.7%
associate-*r/59.1%
*-rgt-identity59.1%
*-commutative59.1%
Simplified59.1%
Final simplification80.3%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -0.004000000189989805) (/ 1.0 (+ (/ 1.0 (+ (/ x s) 1.0)) 1.0)) (/ 1.0 (+ (- 3.0 (/ x s)) -1.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -0.004000000189989805f) {
tmp = 1.0f / ((1.0f / ((x / s) + 1.0f)) + 1.0f);
} else {
tmp = 1.0f / ((3.0f - (x / s)) + -1.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.004000000189989805e0)) then
tmp = 1.0e0 / ((1.0e0 / ((x / s) + 1.0e0)) + 1.0e0)
else
tmp = 1.0e0 / ((3.0e0 - (x / s)) + (-1.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-0.004000000189989805)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / Float32(Float32(x / s) + Float32(1.0))) + Float32(1.0))); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(3.0) - Float32(x / s)) + Float32(-1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-0.004000000189989805)) tmp = single(1.0) / ((single(1.0) / ((x / s) + single(1.0))) + single(1.0)); else tmp = single(1.0) / ((single(3.0) - (x / s)) + single(-1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -0.004000000189989805:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{x}{s} + 1} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(3 - \frac{x}{s}\right) + -1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -0.00400000019Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.4%
if -0.00400000019 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 65.0%
mul-1-neg65.0%
unsub-neg65.0%
Simplified65.0%
expm1-log1p-u65.0%
Applied egg-rr65.0%
expm1-undefine65.0%
sub-neg65.0%
log1p-undefine65.0%
rem-exp-log65.1%
associate-+r-65.1%
metadata-eval65.1%
metadata-eval65.1%
Simplified65.1%
Final simplification75.8%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (+ (- 3.0 (/ x s)) -1.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / ((3.0f - (x / s)) + -1.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) <= (-2.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / ((3.0e0 - (x / s)) + (-1.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-2.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(3.0) - Float32(x / s)) + Float32(-1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-2.0)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / ((single(3.0) - (x / s)) + single(-1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -2:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(3 - \frac{x}{s}\right) + -1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
Taylor expanded in x around 0 5.0%
mul-1-neg5.0%
unsub-neg5.0%
Simplified5.0%
Taylor expanded in x around inf 5.0%
associate-*r/5.0%
metadata-eval5.0%
Simplified5.0%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 65.1%
mul-1-neg65.1%
unsub-neg65.1%
Simplified65.1%
expm1-log1p-u65.2%
Applied egg-rr65.2%
expm1-undefine65.2%
sub-neg65.2%
log1p-undefine65.1%
rem-exp-log65.2%
associate-+r-65.2%
metadata-eval65.2%
metadata-eval65.2%
Simplified65.2%
Final simplification52.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2.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) <= (-2.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(-2.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(-2.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 -2:\\
\;\;\;\;\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) < -2Initial program 100.0%
Taylor expanded in x around 0 5.0%
mul-1-neg5.0%
unsub-neg5.0%
Simplified5.0%
Taylor expanded in x around inf 5.0%
associate-*r/5.0%
metadata-eval5.0%
Simplified5.0%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 65.1%
mul-1-neg65.1%
unsub-neg65.1%
Simplified65.1%
Final simplification52.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.5) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.5f) {
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) <= 0.5e0) 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(0.5)) 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(0.5)) 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 0.5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0 53.3%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 47.1%
mul-1-neg47.1%
unsub-neg47.1%
Simplified47.1%
Taylor expanded in x around inf 47.0%
associate-*r/47.0%
mul-1-neg47.0%
Simplified47.0%
Final simplification50.8%
(FPCore (x s) :precision binary32 (if (<= x -2.000000033724767e-16) (* s (/ -1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.000000033724767e-16f) {
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 <= (-2.000000033724767e-16)) 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(-2.000000033724767e-16)) 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(-2.000000033724767e-16)) 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 -2.000000033724767 \cdot 10^{-16}:\\
\;\;\;\;s \cdot \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.00000003e-16Initial program 99.8%
Taylor expanded in x around 0 52.7%
mul-1-neg52.7%
unsub-neg52.7%
Simplified52.7%
Taylor expanded in x around inf 49.9%
associate-*r/49.9%
neg-mul-149.9%
Simplified49.9%
div-inv49.9%
add-sqr-sqrt-0.0%
sqrt-unprod67.3%
sqr-neg67.3%
sqrt-unprod49.2%
add-sqr-sqrt49.2%
Applied egg-rr49.2%
associate-*r/49.2%
*-rgt-identity49.2%
Simplified49.2%
add-sqr-sqrt-0.0%
sqrt-unprod58.6%
sqr-neg58.6%
sqrt-unprod49.9%
add-sqr-sqrt49.9%
clear-num52.6%
associate-/r/49.9%
frac-2neg49.9%
metadata-eval49.9%
remove-double-neg49.9%
Applied egg-rr49.9%
if -2.00000003e-16 < x Initial program 99.8%
Taylor expanded in x around 0 49.7%
Final simplification49.8%
(FPCore (x s) :precision binary32 (if (<= x -0.020999999716877937) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.020999999716877937f) {
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 <= (-0.020999999716877937e0)) 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(-0.020999999716877937)) 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(-0.020999999716877937)) 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 -0.020999999716877937:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.0209999997Initial program 100.0%
Taylor expanded in x around 0 61.0%
mul-1-neg61.0%
unsub-neg61.0%
Simplified61.0%
Taylor expanded in x around inf 57.7%
associate-*r/57.7%
neg-mul-157.7%
Simplified57.7%
add-sqr-sqrt-0.0%
sqrt-unprod68.4%
sqr-neg68.4%
sqrt-unprod57.7%
add-sqr-sqrt57.7%
clear-num61.0%
inv-pow61.0%
Applied egg-rr61.0%
unpow-161.0%
Simplified61.0%
if -0.0209999997 < x Initial program 99.7%
Taylor expanded in x around 0 46.4%
Final simplification50.6%
(FPCore (x s) :precision binary32 (if (<= x -2.000000033724767e-16) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.000000033724767e-16f) {
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 <= (-2.000000033724767e-16)) 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(-2.000000033724767e-16)) tmp = Float32(s / Float32(-x)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-2.000000033724767e-16)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.000000033724767 \cdot 10^{-16}:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.00000003e-16Initial program 99.8%
Taylor expanded in x around 0 52.7%
mul-1-neg52.7%
unsub-neg52.7%
Simplified52.7%
Taylor expanded in x around inf 49.9%
associate-*r/49.9%
neg-mul-149.9%
Simplified49.9%
if -2.00000003e-16 < x Initial program 99.8%
Taylor expanded in x around 0 49.7%
Final simplification49.8%
(FPCore (x s) :precision binary32 (if (<= x -0.020999999716877937) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.020999999716877937f) {
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 <= (-0.020999999716877937e0)) 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(-0.020999999716877937)) 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(-0.020999999716877937)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.020999999716877937:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.0209999997Initial program 100.0%
Taylor expanded in x around 0 61.0%
mul-1-neg61.0%
unsub-neg61.0%
Simplified61.0%
Taylor expanded in x around inf 57.7%
associate-*r/57.7%
neg-mul-157.7%
Simplified57.7%
div-inv57.7%
add-sqr-sqrt-0.0%
sqrt-unprod68.4%
sqr-neg68.4%
sqrt-unprod57.7%
add-sqr-sqrt57.7%
Applied egg-rr57.7%
associate-*r/57.7%
*-rgt-identity57.7%
Simplified57.7%
if -0.0209999997 < x Initial program 99.7%
Taylor expanded in x around 0 46.4%
Final simplification49.6%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 35.0%
Final simplification35.0%
herbie shell --seed 2024055
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))