
(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 (/ (pow E (/ -0.5 (/ s x))) (exp (* (/ x s) 0.5))))))
float code(float x, float s) {
return 1.0f / (1.0f + (powf(((float) M_E), (-0.5f / (s / x))) / expf(((x / s) * 0.5f))));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32((Float32(exp(1)) ^ Float32(Float32(-0.5) / Float32(s / x))) / exp(Float32(Float32(x / s) * Float32(0.5)))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + ((single(2.71828182845904523536) ^ (single(-0.5) / (s / x))) / exp(((x / s) * single(0.5))))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{{e}^{\left(\frac{-0.5}{\frac{s}{x}}\right)}}{e^{\frac{x}{s} \cdot 0.5}}}
\end{array}
Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt48.4%
sqrt-unprod61.1%
sqr-neg61.1%
sqrt-unprod15.0%
add-sqr-sqrt29.8%
add-sqr-sqrt29.8%
associate-/r*29.7%
add-sqr-sqrt15.0%
sqrt-unprod28.0%
sqr-neg28.0%
sqrt-unprod13.0%
add-sqr-sqrt26.0%
Applied egg-rr99.6%
frac-2neg99.6%
div-inv99.6%
metadata-eval99.6%
metadata-eval99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
frac-2neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-*r/99.6%
metadata-eval99.6%
unpow1/299.6%
exp-prod99.7%
*-commutative99.7%
exp-neg99.7%
distribute-lft-neg-in99.7%
metadata-eval99.7%
associate-*r/99.7%
*-commutative99.7%
Simplified99.7%
pow1/299.7%
pow-exp99.7%
Applied egg-rr99.7%
*-un-lft-identity99.7%
exp-prod99.7%
e-exp-199.7%
*-commutative99.7%
associate-/l*99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (/ (pow (exp -0.5) (/ x s)) (exp (* (/ x s) 0.5))))))
float code(float x, float s) {
return 1.0f / (1.0f + (powf(expf(-0.5f), (x / s)) / expf(((x / s) * 0.5f))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + ((exp((-0.5e0)) ** (x / s)) / exp(((x / s) * 0.5e0))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32((exp(Float32(-0.5)) ^ Float32(x / s)) / exp(Float32(Float32(x / s) * Float32(0.5)))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + ((exp(single(-0.5)) ^ (x / s)) / exp(((x / s) * single(0.5))))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{{\left(e^{-0.5}\right)}^{\left(\frac{x}{s}\right)}}{e^{\frac{x}{s} \cdot 0.5}}}
\end{array}
Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt48.4%
sqrt-unprod61.1%
sqr-neg61.1%
sqrt-unprod15.0%
add-sqr-sqrt29.8%
add-sqr-sqrt29.8%
associate-/r*29.7%
add-sqr-sqrt15.0%
sqrt-unprod28.0%
sqr-neg28.0%
sqrt-unprod13.0%
add-sqr-sqrt26.0%
Applied egg-rr99.6%
frac-2neg99.6%
div-inv99.6%
metadata-eval99.6%
metadata-eval99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
frac-2neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-*r/99.6%
metadata-eval99.6%
unpow1/299.6%
exp-prod99.7%
*-commutative99.7%
exp-neg99.7%
distribute-lft-neg-in99.7%
metadata-eval99.7%
associate-*r/99.7%
*-commutative99.7%
Simplified99.7%
pow1/299.7%
pow-exp99.7%
Applied egg-rr99.7%
Taylor expanded in x around inf 99.7%
exp-prod99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (/ (exp (/ (* -0.5 x) s)) (exp (* (/ x s) 0.5))))))
float code(float x, float s) {
return 1.0f / (1.0f + (expf(((-0.5f * x) / s)) / expf(((x / s) * 0.5f))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp((((-0.5e0) * x) / s)) / exp(((x / s) * 0.5e0))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(exp(Float32(Float32(Float32(-0.5) * x) / s)) / exp(Float32(Float32(x / s) * Float32(0.5)))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(((single(-0.5) * x) / s)) / exp(((x / s) * single(0.5))))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{e^{\frac{-0.5 \cdot x}{s}}}{e^{\frac{x}{s} \cdot 0.5}}}
\end{array}
Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt48.4%
sqrt-unprod61.1%
sqr-neg61.1%
sqrt-unprod15.0%
add-sqr-sqrt29.8%
add-sqr-sqrt29.8%
associate-/r*29.7%
add-sqr-sqrt15.0%
sqrt-unprod28.0%
sqr-neg28.0%
sqrt-unprod13.0%
add-sqr-sqrt26.0%
Applied egg-rr99.6%
frac-2neg99.6%
div-inv99.6%
metadata-eval99.6%
metadata-eval99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
frac-2neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-*r/99.6%
metadata-eval99.6%
unpow1/299.6%
exp-prod99.7%
*-commutative99.7%
exp-neg99.7%
distribute-lft-neg-in99.7%
metadata-eval99.7%
associate-*r/99.7%
*-commutative99.7%
Simplified99.7%
pow1/299.7%
pow-exp99.7%
Applied egg-rr99.7%
Final simplification99.7%
(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.7%
Final simplification99.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -100.0)
0.5
(if (<= t_0 1.0)
(+ 0.5 (/ (* x 0.25) s))
(if (<= t_0 INFINITY)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (/ x s)))
(/ 1.0 (/ x s)))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -100.0f) {
tmp = 0.5f;
} else if (t_0 <= 1.0f) {
tmp = 0.5f + ((x * 0.25f) / s);
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (x / s));
} else {
tmp = 1.0f / (x / s);
}
return tmp;
}
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-100.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(1.0)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); elseif (t_0 <= Float32(Inf)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(x / s))); else tmp = Float32(Float32(1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-100.0)) tmp = single(0.5); elseif (t_0 <= single(1.0)) tmp = single(0.5) + ((x * single(0.25)) / s); elseif (t_0 <= single(Inf)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (x / s)); else tmp = single(1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t_0 \leq -100:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t_0 \leq 1:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{elif}\;t_0 \leq \infty:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -100Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -100 < (/.f32 (neg.f32 x) s) < 1Initial program 99.5%
Taylor expanded in x around 0 95.7%
associate-*r/95.7%
Simplified95.7%
if 1 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 99.6%
Taylor expanded in x around 0 44.9%
mul-1-neg44.9%
unsub-neg44.9%
Simplified44.9%
sub-neg44.9%
flip-+36.8%
metadata-eval36.8%
distribute-neg-frac36.8%
distribute-neg-frac36.8%
distribute-neg-frac36.8%
Applied egg-rr36.8%
Taylor expanded in x around inf 36.7%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 46.3%
mul-1-neg46.3%
unsub-neg46.3%
Simplified46.3%
sub-neg46.3%
flip-+42.6%
metadata-eval42.6%
distribute-neg-frac42.6%
distribute-neg-frac42.6%
distribute-neg-frac42.6%
Applied egg-rr42.6%
distribute-frac-neg42.6%
distribute-frac-neg42.6%
sqr-neg42.6%
clear-num42.6%
frac-2neg42.6%
frac-times44.0%
*-un-lft-identity44.0%
add-sqr-sqrt28.8%
sqrt-unprod45.4%
sqr-neg45.4%
sqrt-unprod16.3%
add-sqr-sqrt44.9%
Applied egg-rr44.9%
Taylor expanded in x around inf 21.7%
Final simplification51.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -2.0)
0.5
(if (<= t_0 INFINITY)
(/ 1.0 (/ (- 4.0 (* x (/ (/ x s) 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.0f) {
tmp = 0.5f;
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - (x * ((x / s) / s))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (x / s);
}
return tmp;
}
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-2.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(Inf)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x * Float32(Float32(x / s) / 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.0)) tmp = single(0.5); elseif (t_0 <= single(Inf)) tmp = single(1.0) / ((single(4.0) - (x * ((x / s) / 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:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t_0 \leq \infty:\\
\;\;\;\;\frac{1}{\frac{4 - x \cdot \frac{\frac{x}{s}}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 99.6%
Taylor expanded in x around 0 66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
sub-neg66.7%
flip-+62.2%
metadata-eval62.2%
distribute-neg-frac62.2%
distribute-neg-frac62.2%
distribute-neg-frac62.2%
Applied egg-rr62.2%
distribute-frac-neg62.2%
distribute-frac-neg62.2%
sqr-neg62.2%
clear-num62.2%
frac-2neg62.2%
frac-times64.3%
*-un-lft-identity64.3%
add-sqr-sqrt43.1%
sqrt-unprod64.8%
sqr-neg64.8%
sqrt-unprod21.3%
add-sqr-sqrt64.1%
Applied egg-rr64.1%
div-inv66.7%
*-commutative66.7%
associate-/r*66.7%
clear-num66.7%
add-sqr-sqrt-0.0%
sqrt-unprod61.5%
sqr-neg61.5%
sqrt-unprod67.0%
add-sqr-sqrt67.0%
Applied egg-rr67.0%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 46.3%
mul-1-neg46.3%
unsub-neg46.3%
Simplified46.3%
sub-neg46.3%
flip-+42.6%
metadata-eval42.6%
distribute-neg-frac42.6%
distribute-neg-frac42.6%
distribute-neg-frac42.6%
Applied egg-rr42.6%
distribute-frac-neg42.6%
distribute-frac-neg42.6%
sqr-neg42.6%
clear-num42.6%
frac-2neg42.6%
frac-times44.0%
*-un-lft-identity44.0%
add-sqr-sqrt28.8%
sqrt-unprod45.4%
sqr-neg45.4%
sqrt-unprod16.3%
add-sqr-sqrt44.9%
Applied egg-rr44.9%
Taylor expanded in x around inf 21.7%
Final simplification54.1%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -100.0)
0.5
(if (<= t_0 1.0) (+ 0.5 (/ (* x 0.25) s)) (/ 1.0 t_0)))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -100.0f) {
tmp = 0.5f;
} else if (t_0 <= 1.0f) {
tmp = 0.5f + ((x * 0.25f) / 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 <= (-100.0e0)) then
tmp = 0.5e0
else if (t_0 <= 1.0e0) then
tmp = 0.5e0 + ((x * 0.25e0) / 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(-100.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(1.0)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / 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(-100.0)) tmp = single(0.5); elseif (t_0 <= single(1.0)) tmp = single(0.5) + ((x * single(0.25)) / 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 -100:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t_0 \leq 1:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -100Initial program 100.0%
Taylor expanded in x around 0 28.1%
if -100 < (/.f32 (neg.f32 x) s) < 1Initial program 99.5%
Taylor expanded in x around 0 95.7%
associate-*r/95.7%
Simplified95.7%
if 1 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 44.9%
mul-1-neg44.9%
unsub-neg44.9%
Simplified44.9%
Taylor expanded in x around inf 44.9%
mul-1-neg44.9%
distribute-frac-neg44.9%
Simplified44.9%
Final simplification54.9%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.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) <= (-2.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(-2.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(-2.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 -2:\\
\;\;\;\;0.5\\
\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 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
Final simplification53.9%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ (- x) s))) (if (<= t_0 1.0) 0.5 (/ 1.0 t_0))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= 1.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 <= 1.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(1.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(1.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 1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 1Initial program 99.8%
Taylor expanded in x around 0 55.2%
if 1 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 44.9%
mul-1-neg44.9%
unsub-neg44.9%
Simplified44.9%
Taylor expanded in x around inf 44.9%
mul-1-neg44.9%
distribute-frac-neg44.9%
Simplified44.9%
Final simplification51.4%
(FPCore (x s) :precision binary32 (if (<= x -2.0000000233721948e-7) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.0000000233721948e-7f) {
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 <= (-2.0000000233721948e-7)) 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(-2.0000000233721948e-7)) 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(-2.0000000233721948e-7)) 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 -2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.00000002e-7Initial program 99.8%
Taylor expanded in x around 0 51.2%
mul-1-neg51.2%
unsub-neg51.2%
Simplified51.2%
sub-neg51.2%
flip-+40.5%
metadata-eval40.5%
distribute-neg-frac40.5%
distribute-neg-frac40.5%
distribute-neg-frac40.5%
Applied egg-rr40.5%
distribute-frac-neg40.5%
distribute-frac-neg40.5%
sqr-neg40.5%
clear-num40.5%
frac-2neg40.5%
frac-times40.5%
*-un-lft-identity40.5%
add-sqr-sqrt40.5%
sqrt-unprod40.5%
sqr-neg40.5%
sqrt-unprod-0.0%
add-sqr-sqrt40.1%
Applied egg-rr40.1%
Taylor expanded in x around inf 50.8%
if -2.00000002e-7 < x Initial program 99.7%
Taylor expanded in x around 0 51.4%
Final simplification51.2%
(FPCore (x s) :precision binary32 (if (<= x -2.0000000233721948e-7) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.0000000233721948e-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 <= (-2.0000000233721948e-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(-2.0000000233721948e-7)) 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(-2.0000000233721948e-7)) tmp = -s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.00000002e-7Initial program 99.8%
Taylor expanded in x around 0 51.2%
mul-1-neg51.2%
unsub-neg51.2%
Simplified51.2%
Taylor expanded in x around inf 43.9%
associate-*r/43.9%
neg-mul-143.9%
Simplified43.9%
if -2.00000002e-7 < x Initial program 99.7%
Taylor expanded in x around 0 51.4%
Final simplification49.0%
(FPCore (x s) :precision binary32 (if (<= x -2.0000000233721948e-7) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.0000000233721948e-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 <= (-2.0000000233721948e-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(-2.0000000233721948e-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(-2.0000000233721948e-7)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.00000002e-7Initial program 99.8%
Taylor expanded in x around 0 51.2%
mul-1-neg51.2%
unsub-neg51.2%
Simplified51.2%
sub-neg51.2%
flip-+40.5%
metadata-eval40.5%
distribute-neg-frac40.5%
distribute-neg-frac40.5%
distribute-neg-frac40.5%
Applied egg-rr40.5%
distribute-frac-neg40.5%
distribute-frac-neg40.5%
sqr-neg40.5%
clear-num40.5%
frac-2neg40.5%
frac-times40.5%
*-un-lft-identity40.5%
add-sqr-sqrt40.5%
sqrt-unprod40.5%
sqr-neg40.5%
sqrt-unprod-0.0%
add-sqr-sqrt40.1%
Applied egg-rr40.1%
Taylor expanded in x around inf 43.4%
if -2.00000002e-7 < x Initial program 99.7%
Taylor expanded in x around 0 51.4%
Final simplification48.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.7%
Taylor expanded in x around 0 37.4%
Final simplification37.4%
herbie shell --seed 2023301
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))