
(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 10 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 (exp (- (log1p (exp (/ (- x) s))))))
float code(float x, float s) {
return expf(-log1pf(expf((-x / s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(Float32(-x) / s))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{\frac{-x}{s}}\right)}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
div-inv99.8%
add-sqr-sqrt50.3%
sqrt-unprod60.9%
sqr-neg60.9%
sqrt-unprod12.0%
add-sqr-sqrt25.5%
div-inv25.5%
pow125.5%
pow125.5%
add-sqr-sqrt25.5%
pow225.5%
metadata-eval25.5%
pow-flip25.5%
Applied egg-rr99.9%
add-exp-log99.8%
log-rec99.8%
log1p-udef99.9%
add-exp-log99.9%
sqrt-pow299.9%
metadata-eval99.9%
inv-pow99.9%
neg-log99.9%
add-log-exp99.9%
distribute-neg-frac99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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(Float32(-x) / 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.0)
(+ 1.0 (/ s x))
(if (<= t_0 9.999999680285692e+37)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ 2.0 (/ x s))))
(/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -2.0f) {
tmp = 1.0f + (s / x);
} else if (t_0 <= 9.999999680285692e+37f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / (2.0f + (x / s)));
} 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 <= (-2.0e0)) then
tmp = 1.0e0 + (s / x)
else if (t_0 <= 9.999999680285692e+37) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / (2.0e0 + (x / s)))
else
tmp = (-1.0e0) / (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(-2.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (t_0 <= Float32(9.999999680285692e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x / Float32(s * Float32(s / x)))) / Float32(Float32(2.0) + 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(-2.0)) tmp = single(1.0) + (s / x); elseif (t_0 <= single(9.999999680285692e+37)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / (single(2.0) + (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 -2:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.9%
frac-2neg93.9%
metadata-eval93.9%
div-inv93.9%
+-commutative93.9%
distribute-neg-in93.9%
distribute-frac-neg93.9%
add-sqr-sqrt-0.0%
sqrt-unprod92.5%
sqr-neg92.5%
sqrt-unprod94.3%
add-sqr-sqrt94.3%
metadata-eval94.3%
Applied egg-rr94.3%
metadata-eval94.3%
sub-neg94.3%
associate-*r/94.3%
metadata-eval94.3%
sub-neg94.3%
metadata-eval94.3%
Simplified94.3%
Taylor expanded in x around inf 94.3%
if -2 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 99.7%
Taylor expanded in x around 0 50.0%
mul-1-neg50.0%
unsub-neg50.0%
Simplified50.0%
sub-neg50.0%
flip-+69.8%
metadata-eval69.8%
distribute-neg-frac69.8%
distribute-neg-frac69.8%
distribute-neg-frac69.8%
Applied egg-rr69.8%
distribute-frac-neg69.8%
distribute-frac-neg69.8%
sqr-neg69.8%
clear-num69.8%
frac-times73.4%
*-un-lft-identity73.4%
Applied egg-rr73.4%
if 9.99999968e37 < (/.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%
associate-/r/88.6%
add-sqr-sqrt88.6%
sqrt-unprod97.3%
sqr-neg97.3%
sqrt-unprod-0.0%
add-sqr-sqrt88.6%
Applied egg-rr88.6%
associate-/r/100.0%
frac-2neg100.0%
metadata-eval100.0%
distribute-frac-neg100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Final simplification84.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -10.0)
(+ 1.0 (/ s x))
(if (<= t_0 0.10000000149011612)
(+ 0.5 (/ (* x 0.25) s))
(/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -10.0f) {
tmp = 1.0f + (s / x);
} else if (t_0 <= 0.10000000149011612f) {
tmp = 0.5f + ((x * 0.25f) / s);
} 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 <= (-10.0e0)) then
tmp = 1.0e0 + (s / x)
else if (t_0 <= 0.10000000149011612e0) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = (-1.0e0) / (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(-10.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (t_0 <= Float32(0.10000000149011612)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / 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(-10.0)) tmp = single(1.0) + (s / x); elseif (t_0 <= single(0.10000000149011612)) tmp = single(0.5) + ((x * single(0.25)) / 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 -10:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t_0 \leq 0.10000000149011612:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 94.5%
frac-2neg94.5%
metadata-eval94.5%
div-inv94.5%
+-commutative94.5%
distribute-neg-in94.5%
distribute-frac-neg94.5%
add-sqr-sqrt-0.0%
sqrt-unprod93.2%
sqr-neg93.2%
sqrt-unprod95.0%
add-sqr-sqrt95.0%
metadata-eval95.0%
Applied egg-rr95.0%
metadata-eval95.0%
sub-neg95.0%
associate-*r/95.0%
metadata-eval95.0%
sub-neg95.0%
metadata-eval95.0%
Simplified95.0%
Taylor expanded in x around inf 95.0%
if -10 < (/.f32 (neg.f32 x) s) < 0.100000001Initial program 99.5%
Taylor expanded in x around 0 97.4%
associate-*r/97.4%
Simplified97.4%
if 0.100000001 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 38.5%
mul-1-neg38.5%
unsub-neg38.5%
Simplified38.5%
Taylor expanded in x around inf 38.5%
mul-1-neg38.5%
distribute-frac-neg38.5%
Simplified38.5%
associate-/r/35.0%
add-sqr-sqrt35.0%
sqrt-unprod43.8%
sqr-neg43.8%
sqrt-unprod-0.0%
add-sqr-sqrt34.8%
Applied egg-rr34.8%
associate-/r/38.3%
frac-2neg38.3%
metadata-eval38.3%
distribute-frac-neg38.3%
add-sqr-sqrt38.3%
sqrt-unprod44.5%
sqr-neg44.5%
sqrt-unprod-0.0%
add-sqr-sqrt38.5%
Applied egg-rr38.5%
Final simplification73.3%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -2.0)
(+ 1.0 (/ s x))
(if (<= t_0 0.10000000149011612) 0.5 (/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -2.0f) {
tmp = 1.0f + (s / x);
} else if (t_0 <= 0.10000000149011612f) {
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) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-2.0e0)) then
tmp = 1.0e0 + (s / x)
else if (t_0 <= 0.10000000149011612e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (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(-2.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (t_0 <= Float32(0.10000000149011612)) tmp = Float32(0.5); 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(1.0) + (s / x); elseif (t_0 <= single(0.10000000149011612)) tmp = single(0.5); 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:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t_0 \leq 0.10000000149011612:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.9%
frac-2neg93.9%
metadata-eval93.9%
div-inv93.9%
+-commutative93.9%
distribute-neg-in93.9%
distribute-frac-neg93.9%
add-sqr-sqrt-0.0%
sqrt-unprod92.5%
sqr-neg92.5%
sqrt-unprod94.3%
add-sqr-sqrt94.3%
metadata-eval94.3%
Applied egg-rr94.3%
metadata-eval94.3%
sub-neg94.3%
associate-*r/94.3%
metadata-eval94.3%
sub-neg94.3%
metadata-eval94.3%
Simplified94.3%
Taylor expanded in x around inf 94.3%
if -2 < (/.f32 (neg.f32 x) s) < 0.100000001Initial program 99.5%
Taylor expanded in x around 0 91.6%
if 0.100000001 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 38.5%
mul-1-neg38.5%
unsub-neg38.5%
Simplified38.5%
Taylor expanded in x around inf 38.5%
mul-1-neg38.5%
distribute-frac-neg38.5%
Simplified38.5%
associate-/r/35.0%
add-sqr-sqrt35.0%
sqrt-unprod43.8%
sqr-neg43.8%
sqrt-unprod-0.0%
add-sqr-sqrt34.8%
Applied egg-rr34.8%
associate-/r/38.3%
frac-2neg38.3%
metadata-eval38.3%
distribute-frac-neg38.3%
add-sqr-sqrt38.3%
sqrt-unprod44.5%
sqr-neg44.5%
sqrt-unprod-0.0%
add-sqr-sqrt38.5%
Applied egg-rr38.5%
Final simplification71.7%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) (+ 1.0 (/ s x)) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 1.0f + (s / 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 + (s / 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(Float32(-x) / s) <= Float32(-2.0)) tmp = Float32(Float32(1.0) + Float32(s / 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) + (s / 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:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.9%
frac-2neg93.9%
metadata-eval93.9%
div-inv93.9%
+-commutative93.9%
distribute-neg-in93.9%
distribute-frac-neg93.9%
add-sqr-sqrt-0.0%
sqrt-unprod92.5%
sqr-neg92.5%
sqrt-unprod94.3%
add-sqr-sqrt94.3%
metadata-eval94.3%
Applied egg-rr94.3%
metadata-eval94.3%
sub-neg94.3%
associate-*r/94.3%
metadata-eval94.3%
sub-neg94.3%
metadata-eval94.3%
Simplified94.3%
Taylor expanded in x around inf 94.3%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 59.8%
mul-1-neg59.8%
unsub-neg59.8%
Simplified59.8%
Final simplification72.9%
(FPCore (x s) :precision binary32 (if (<= x -2.000000026702864e-10) (/ (- s) x) (if (<= x 3.999999999279835e-23) 0.5 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -2.000000026702864e-10f) {
tmp = -s / x;
} else if (x <= 3.999999999279835e-23f) {
tmp = 0.5f;
} else {
tmp = 1.0f + (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 <= (-2.000000026702864e-10)) then
tmp = -s / x
else if (x <= 3.999999999279835e-23) then
tmp = 0.5e0
else
tmp = 1.0e0 + (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-2.000000026702864e-10)) tmp = Float32(Float32(-s) / x); elseif (x <= Float32(3.999999999279835e-23)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) + Float32(s / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-2.000000026702864e-10)) tmp = -s / x; elseif (x <= single(3.999999999279835e-23)) tmp = single(0.5); else tmp = single(1.0) + (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.000000026702864 \cdot 10^{-10}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{elif}\;x \leq 3.999999999279835 \cdot 10^{-23}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{s}{x}\\
\end{array}
\end{array}
if x < -2.00000003e-10Initial program 100.0%
Taylor expanded in x around 0 46.5%
mul-1-neg46.5%
unsub-neg46.5%
Simplified46.5%
Taylor expanded in x around inf 42.1%
associate-*r/42.1%
neg-mul-142.1%
Simplified42.1%
if -2.00000003e-10 < x < 4e-23Initial program 99.6%
Taylor expanded in x around 0 66.5%
if 4e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 94.1%
frac-2neg94.1%
metadata-eval94.1%
div-inv94.1%
+-commutative94.1%
distribute-neg-in94.1%
distribute-frac-neg94.1%
add-sqr-sqrt-0.0%
sqrt-unprod93.0%
sqr-neg93.0%
sqrt-unprod93.0%
add-sqr-sqrt93.0%
metadata-eval93.0%
Applied egg-rr93.0%
metadata-eval93.0%
sub-neg93.0%
associate-*r/93.0%
metadata-eval93.0%
sub-neg93.0%
metadata-eval93.0%
Simplified93.0%
Taylor expanded in x around inf 88.5%
Final simplification67.6%
(FPCore (x s) :precision binary32 (if (<= x -2.000000026702864e-10) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.000000026702864e-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 <= (-2.000000026702864e-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(-2.000000026702864e-10)) 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.000000026702864e-10)) tmp = -s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.000000026702864 \cdot 10^{-10}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.00000003e-10Initial program 100.0%
Taylor expanded in x around 0 46.5%
mul-1-neg46.5%
unsub-neg46.5%
Simplified46.5%
Taylor expanded in x around inf 42.1%
associate-*r/42.1%
neg-mul-142.1%
Simplified42.1%
if -2.00000003e-10 < x Initial program 99.8%
Taylor expanded in x around 0 46.5%
Final simplification45.1%
(FPCore (x s) :precision binary32 (if (<= x -2.000000026702864e-10) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.000000026702864e-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 <= (-2.000000026702864e-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(-2.000000026702864e-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(-2.000000026702864e-10)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.000000026702864 \cdot 10^{-10}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.00000003e-10Initial program 100.0%
Taylor expanded in x around 0 46.5%
mul-1-neg46.5%
unsub-neg46.5%
Simplified46.5%
Taylor expanded in x around inf 46.5%
mul-1-neg46.5%
distribute-frac-neg46.5%
Simplified46.5%
associate-/r/42.1%
add-sqr-sqrt42.1%
sqrt-unprod53.5%
sqr-neg53.5%
sqrt-unprod-0.0%
add-sqr-sqrt42.0%
Applied egg-rr42.0%
Taylor expanded in x around 0 42.0%
if -2.00000003e-10 < x Initial program 99.8%
Taylor expanded in x around 0 46.5%
Final simplification45.1%
(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 34.0%
Final simplification34.0%
herbie shell --seed 2023334
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))