
(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%
distribute-frac-neg99.6%
exp-neg99.6%
Applied egg-rr99.6%
Applied egg-rr99.4%
pow-sqr99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around inf 99.5%
metadata-eval99.5%
unpow-199.5%
metadata-eval99.5%
pow-sqr99.5%
hypot-undefine99.7%
exp-prod99.7%
*-commutative99.7%
exp-prod99.8%
Simplified99.8%
(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%
distribute-frac-neg99.6%
exp-neg99.6%
Applied egg-rr99.6%
Applied egg-rr99.4%
pow-sqr99.7%
metadata-eval99.7%
Simplified99.7%
add-exp-log99.7%
log-pow99.7%
add-log-exp99.7%
Applied egg-rr99.7%
(FPCore (x s) :precision binary32 (sqrt (pow (+ (exp (/ x (- s))) 1.0) -2.0)))
float code(float x, float s) {
return sqrtf(powf((expf((x / -s)) + 1.0f), -2.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = sqrt(((exp((x / -s)) + 1.0e0) ** (-2.0e0)))
end function
function code(x, s) return sqrt((Float32(exp(Float32(x / Float32(-s))) + Float32(1.0)) ^ Float32(-2.0))) end
function tmp = code(x, s) tmp = sqrt(((exp((x / -s)) + single(1.0)) ^ single(-2.0))); end
\begin{array}{l}
\\
\sqrt{{\left(e^{\frac{x}{-s}} + 1\right)}^{-2}}
\end{array}
Initial program 99.6%
distribute-frac-neg99.6%
exp-neg99.6%
Applied egg-rr99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 0.5)
(/ 1.0 (+ (/ 1.0 (+ (/ x s) 1.0)) 1.0))
(if (<= t_0 499999992153374700.0)
(/ (- (/ (pow s 2.0) s)) x)
(if (<= t_0 1.9999999867631625e+37)
(/ 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 <= 0.5f) {
tmp = 1.0f / ((1.0f / ((x / s) + 1.0f)) + 1.0f);
} else if (t_0 <= 499999992153374700.0f) {
tmp = -(powf(s, 2.0f) / s) / x;
} else if (t_0 <= 1.9999999867631625e+37f) {
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 <= 0.5e0) then
tmp = 1.0e0 / ((1.0e0 / ((x / s) + 1.0e0)) + 1.0e0)
else if (t_0 <= 499999992153374700.0e0) then
tmp = -((s ** 2.0e0) / s) / x
else if (t_0 <= 1.9999999867631625e+37) 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(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(0.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(499999992153374700.0)) tmp = Float32(Float32(-Float32((s ^ Float32(2.0)) / s)) / x); elseif (t_0 <= Float32(1.9999999867631625e+37)) 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(0.5)) tmp = single(1.0) / ((single(1.0) / ((x / s) + single(1.0))) + single(1.0)); elseif (t_0 <= single(499999992153374700.0)) tmp = -((s ^ single(2.0)) / s) / x; elseif (t_0 <= single(1.9999999867631625e+37)) 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 0.5:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{x}{s} + 1} + 1}\\
\mathbf{elif}\;t\_0 \leq 499999992153374700:\\
\;\;\;\;\frac{-\frac{{s}^{2}}{s}}{x}\\
\mathbf{elif}\;t\_0 \leq 1.9999999867631625 \cdot 10^{+37}:\\
\;\;\;\;\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) < 0.5Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 94.4%
+-commutative94.4%
Simplified94.4%
if 0.5 < (/.f32 (neg.f32 x) s) < 4.99999992e17Initial program 98.1%
Taylor expanded in x around 0 9.3%
neg-mul-19.3%
unsub-neg9.3%
Simplified9.3%
Taylor expanded in x around inf 9.1%
associate-*r/9.1%
neg-mul-19.1%
Simplified9.1%
neg-sub09.1%
flip--39.8%
metadata-eval39.8%
pow239.8%
add-sqr-sqrt39.8%
sqrt-unprod5.9%
sqr-neg5.9%
sqrt-unprod-0.0%
add-sqr-sqrt38.4%
sub-neg38.4%
neg-sub038.4%
add-sqr-sqrt-0.0%
sqrt-unprod5.9%
sqr-neg5.9%
sqrt-unprod39.8%
add-sqr-sqrt39.8%
Applied egg-rr39.8%
sub0-neg39.8%
Simplified39.8%
if 4.99999992e17 < (/.f32 (neg.f32 x) s) < 1.99999999e37Initial program 100.0%
Taylor expanded in x around 0 13.6%
neg-mul-113.6%
unsub-neg13.6%
Simplified13.6%
*-un-lft-identity13.6%
cancel-sign-sub-inv13.6%
metadata-eval13.6%
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-exp0.1%
neg-mul-10.1%
distribute-neg-frac20.1%
distribute-neg-frac20.1%
pow-exp0.1%
Applied egg-rr97.6%
if 1.99999999e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 87.6%
associate-*r/87.6%
neg-mul-187.6%
Simplified87.6%
clear-num100.0%
inv-pow100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification87.8%
(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.6%
Final simplification99.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -0.0005499999970197678)
(/ 1.0 (+ (/ 1.0 (+ (/ x s) 1.0)) 1.0))
(if (<= t_0 1.9999999867631625e+37)
(/ 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 <= -0.0005499999970197678f) {
tmp = 1.0f / ((1.0f / ((x / s) + 1.0f)) + 1.0f);
} else if (t_0 <= 1.9999999867631625e+37f) {
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 <= (-0.0005499999970197678e0)) then
tmp = 1.0e0 / ((1.0e0 / ((x / s) + 1.0e0)) + 1.0e0)
else if (t_0 <= 1.9999999867631625e+37) 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(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-0.0005499999970197678)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / Float32(Float32(x / s) + Float32(1.0))) + Float32(1.0))); elseif (t_0 <= Float32(1.9999999867631625e+37)) 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(-0.0005499999970197678)) tmp = single(1.0) / ((single(1.0) / ((x / s) + single(1.0))) + single(1.0)); elseif (t_0 <= single(1.9999999867631625e+37)) 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 -0.0005499999970197678:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{x}{s} + 1} + 1}\\
\mathbf{elif}\;t\_0 \leq 1.9999999867631625 \cdot 10^{+37}:\\
\;\;\;\;\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) < -5.5e-4Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 94.3%
+-commutative94.3%
Simplified94.3%
if -5.5e-4 < (/.f32 (neg.f32 x) s) < 1.99999999e37Initial program 99.2%
Taylor expanded in x around 0 41.6%
neg-mul-141.6%
unsub-neg41.6%
Simplified41.6%
*-un-lft-identity41.6%
cancel-sign-sub-inv41.6%
metadata-eval41.6%
add-log-exp95.0%
pow-exp95.0%
flip-+35.0%
metadata-eval35.0%
pow-exp35.0%
add-log-exp35.0%
neg-mul-135.0%
pow-exp35.0%
add-log-exp36.0%
neg-mul-136.0%
distribute-neg-frac236.0%
distribute-neg-frac236.0%
pow-exp36.0%
Applied egg-rr68.4%
if 1.99999999e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 87.6%
associate-*r/87.6%
neg-mul-187.6%
Simplified87.6%
clear-num100.0%
inv-pow100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification83.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -0.0005499999970197678) (/ 1.0 (+ (/ 1.0 (+ (/ x s) 1.0)) 1.0)) (/ -1.0 (/ (- x (* s 2.0)) s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -0.0005499999970197678f) {
tmp = 1.0f / ((1.0f / ((x / s) + 1.0f)) + 1.0f);
} else {
tmp = -1.0f / ((x - (s * 2.0f)) / 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.0005499999970197678e0)) then
tmp = 1.0e0 / ((1.0e0 / ((x / s) + 1.0e0)) + 1.0e0)
else
tmp = (-1.0e0) / ((x - (s * 2.0e0)) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-0.0005499999970197678)) 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(x - Float32(s * Float32(2.0))) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-0.0005499999970197678)) 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))) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -0.0005499999970197678:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{x}{s} + 1} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x - s \cdot 2}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -5.5e-4Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 94.3%
+-commutative94.3%
Simplified94.3%
if -5.5e-4 < (/.f32 (neg.f32 x) s) Initial program 99.4%
Taylor expanded in x around 0 56.3%
neg-mul-156.3%
unsub-neg56.3%
Simplified56.3%
Taylor expanded in s around 0 56.3%
*-commutative56.3%
Simplified56.3%
Final simplification71.3%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) 0.5 (/ -1.0 (/ (- x (* s 2.0)) s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 0.5f;
} else {
tmp = -1.0f / ((x - (s * 2.0f)) / s);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= (-1.0e0)) then
tmp = 0.5e0
else
tmp = (-1.0e0) / ((x - (s * 2.0e0)) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(Float32(x - Float32(s * Float32(2.0))) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-1.0)) tmp = single(0.5); else tmp = single(-1.0) / ((x - (s * single(2.0))) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x - s \cdot 2}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.4%
Taylor expanded in x around 0 56.6%
neg-mul-156.6%
unsub-neg56.6%
Simplified56.6%
Taylor expanded in s around 0 56.6%
*-commutative56.6%
Simplified56.6%
Final simplification45.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) 0.5 (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (-1.0f + (3.0f - (x / s)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= (-1.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-1.0)) tmp = single(0.5); else tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.4%
Taylor expanded in x around 0 56.6%
neg-mul-156.6%
unsub-neg56.6%
Simplified56.6%
expm1-log1p-u56.5%
Applied egg-rr56.5%
expm1-undefine56.5%
sub-neg56.5%
log1p-undefine56.4%
rem-exp-log56.6%
associate-+r-56.6%
metadata-eval56.6%
metadata-eval56.6%
Simplified56.6%
Final simplification45.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (2.0f - (x / s));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= (-1.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 - (x / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-1.0)) tmp = single(0.5); else tmp = single(1.0) / (single(2.0) - (x / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.4%
Taylor expanded in x around 0 56.6%
neg-mul-156.6%
unsub-neg56.6%
Simplified56.6%
Final simplification45.9%
(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.8%
Taylor expanded in x around 0 46.4%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.4%
Taylor expanded in x around 0 42.1%
neg-mul-142.1%
unsub-neg42.1%
Simplified42.1%
Taylor expanded in x around inf 42.1%
mul-1-neg42.1%
distribute-frac-neg242.1%
Simplified42.1%
Final simplification44.5%
(FPCore (x s) :precision binary32 (if (<= x -9.999999717180685e-10) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999717180685e-10f) {
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.999999717180685e-10)) 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.999999717180685e-10)) 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.999999717180685e-10)) 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.999999717180685 \cdot 10^{-10}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999972e-10Initial program 99.9%
Taylor expanded in x around 0 48.7%
neg-mul-148.7%
unsub-neg48.7%
Simplified48.7%
Taylor expanded in x around inf 43.5%
associate-*r/43.5%
neg-mul-143.5%
Simplified43.5%
clear-num48.6%
inv-pow48.6%
add-sqr-sqrt-0.0%
sqrt-unprod63.9%
sqr-neg63.9%
sqrt-unprod48.2%
add-sqr-sqrt48.2%
Applied egg-rr48.2%
unpow-148.2%
Simplified48.2%
if -9.99999972e-10 < x Initial program 99.5%
Taylor expanded in x around 0 42.0%
(FPCore (x s) :precision binary32 (if (<= x -9.9999998245167e-14) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.9999998245167e-14f) {
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.9999998245167e-14)) 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.9999998245167e-14)) 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(-9.9999998245167e-14)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.9999998245167 \cdot 10^{-14}:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999982e-14Initial program 99.9%
Taylor expanded in x around 0 46.0%
neg-mul-146.0%
unsub-neg46.0%
Simplified46.0%
Taylor expanded in x around inf 41.0%
associate-*r/41.0%
neg-mul-141.0%
Simplified41.0%
if -9.99999982e-14 < x Initial program 99.5%
Taylor expanded in x around 0 43.6%
Final simplification42.5%
(FPCore (x s) :precision binary32 (if (<= x -9.999999717180685e-10) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999717180685e-10f) {
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.999999717180685e-10)) 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.999999717180685e-10)) 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.999999717180685e-10)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999717180685 \cdot 10^{-10}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999972e-10Initial program 99.9%
Taylor expanded in x around 0 48.7%
neg-mul-148.7%
unsub-neg48.7%
Simplified48.7%
Taylor expanded in x around inf 43.5%
associate-*r/43.5%
neg-mul-143.5%
Simplified43.5%
add-sqr-sqrt-0.0%
sqrt-unprod61.3%
sqr-neg61.3%
sqrt-unprod43.1%
add-sqr-sqrt43.1%
*-un-lft-identity43.1%
Applied egg-rr43.1%
*-lft-identity43.1%
Simplified43.1%
if -9.99999972e-10 < x Initial program 99.5%
Taylor expanded in x around 0 42.0%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.6%
Taylor expanded in x around 0 29.0%
herbie shell --seed 2024177
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))