
(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 11 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.7%
(FPCore (x s)
:precision binary32
(if (<= (- x) -9.999999960041972e-12)
(- 1.0 (/ s x))
(if (<= (- x) 4.999999987376214e-7)
(+ 0.5 (/ (* x 0.25) s))
(/ 1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -9.999999960041972e-12f) {
tmp = 1.0f - (s / x);
} else if (-x <= 4.999999987376214e-7f) {
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) :: tmp
if (-x <= (-9.999999960041972e-12)) then
tmp = 1.0e0 - (s / x)
else if (-x <= 4.999999987376214e-7) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-9.999999960041972e-12)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (Float32(-x) <= Float32(4.999999987376214e-7)) 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) tmp = single(0.0); if (-x <= single(-9.999999960041972e-12)) tmp = single(1.0) - (s / x); elseif (-x <= single(4.999999987376214e-7)) 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}
\mathbf{if}\;-x \leq -9.999999960041972 \cdot 10^{-12}:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;-x \leq 4.999999987376214 \cdot 10^{-7}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -9.99999996e-12Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around inf 97.7%
neg-mul-197.7%
unsub-neg97.7%
Simplified97.7%
if -9.99999996e-12 < (neg.f32 x) < 4.99999999e-7Initial program 99.3%
Taylor expanded in x around 0 64.5%
associate-*r/64.5%
Simplified64.5%
if 4.99999999e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 54.5%
neg-mul-154.5%
unsub-neg54.5%
Simplified54.5%
Taylor expanded in x around inf 49.7%
associate-*r/49.7%
neg-mul-149.7%
Simplified49.7%
add-sqr-sqrt-0.0%
sqrt-unprod60.2%
sqr-neg60.2%
sqrt-unprod49.7%
add-sqr-sqrt49.7%
clear-num54.5%
inv-pow54.5%
Applied egg-rr54.5%
unpow-154.5%
Simplified54.5%
Final simplification73.6%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.999999898305949e-32) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999898305949e-32f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (x * (((s * 2.0f) - x) / (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 <= 4.999999898305949e-32) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (x * (((s * 2.0e0) - x) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(4.999999898305949e-32)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(4.999999898305949e-32)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (x * (((s * single(2.0)) - x) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 4.999999898305949 \cdot 10^{-32}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot 2 - x}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 4.9999999e-32Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.9%
+-commutative93.9%
Simplified93.9%
if 4.9999999e-32 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 50.7%
neg-mul-150.7%
unsub-neg50.7%
Simplified50.7%
Taylor expanded in x around inf 50.6%
sub-neg50.6%
associate-*r/50.6%
metadata-eval50.6%
distribute-neg-frac50.6%
metadata-eval50.6%
Simplified50.6%
frac-add58.5%
associate-*r/57.6%
fma-define57.6%
*-commutative57.6%
neg-mul-157.6%
Applied egg-rr57.6%
associate-/l*58.5%
fma-neg58.5%
*-commutative58.5%
Simplified58.5%
Final simplification79.0%
(FPCore (x s)
:precision binary32
(if (<= x -4.999999987376214e-7)
(/ 1.0 (/ x s))
(if (<= x 4.9999998413276127e-20)
(+ 0.5 (/ (* x 0.25) s))
(/ 1.0 (+ 1.0 (/ s x))))))
float code(float x, float s) {
float tmp;
if (x <= -4.999999987376214e-7f) {
tmp = 1.0f / (x / s);
} else if (x <= 4.9999998413276127e-20f) {
tmp = 0.5f + ((x * 0.25f) / s);
} else {
tmp = 1.0f / (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 <= (-4.999999987376214e-7)) then
tmp = 1.0e0 / (x / s)
else if (x <= 4.9999998413276127e-20) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 / (1.0e0 + (s / x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999987376214e-7)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(4.9999998413276127e-20)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999987376214e-7)) tmp = single(1.0) / (x / s); elseif (x <= single(4.9999998413276127e-20)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(1.0) / (single(1.0) + (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999987376214 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 4.9999998413276127 \cdot 10^{-20}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < -4.99999999e-7Initial program 100.0%
Taylor expanded in x around 0 54.5%
neg-mul-154.5%
unsub-neg54.5%
Simplified54.5%
Taylor expanded in x around inf 49.7%
associate-*r/49.7%
neg-mul-149.7%
Simplified49.7%
add-sqr-sqrt-0.0%
sqrt-unprod60.2%
sqr-neg60.2%
sqrt-unprod49.7%
add-sqr-sqrt49.7%
clear-num54.5%
inv-pow54.5%
Applied egg-rr54.5%
unpow-154.5%
Simplified54.5%
if -4.99999999e-7 < x < 4.99999984e-20Initial program 99.3%
Taylor expanded in x around 0 65.5%
associate-*r/65.5%
Simplified65.5%
if 4.99999984e-20 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.2%
+-commutative98.2%
Simplified98.2%
Taylor expanded in x around inf 94.7%
Final simplification73.7%
(FPCore (x s) :precision binary32 (if (<= (- x) -9.999999960041972e-12) (- 1.0 (/ s x)) (if (<= (- x) 4.999999987376214e-7) 0.5 (/ 1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -9.999999960041972e-12f) {
tmp = 1.0f - (s / x);
} else if (-x <= 4.999999987376214e-7f) {
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 <= (-9.999999960041972e-12)) then
tmp = 1.0e0 - (s / x)
else if (-x <= 4.999999987376214e-7) 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(-9.999999960041972e-12)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (Float32(-x) <= Float32(4.999999987376214e-7)) 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 <= single(-9.999999960041972e-12)) tmp = single(1.0) - (s / x); elseif (-x <= single(4.999999987376214e-7)) tmp = single(0.5); else tmp = single(1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -9.999999960041972 \cdot 10^{-12}:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;-x \leq 4.999999987376214 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -9.99999996e-12Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around inf 97.7%
neg-mul-197.7%
unsub-neg97.7%
Simplified97.7%
if -9.99999996e-12 < (neg.f32 x) < 4.99999999e-7Initial program 99.3%
Taylor expanded in x around 0 61.6%
if 4.99999999e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 54.5%
neg-mul-154.5%
unsub-neg54.5%
Simplified54.5%
Taylor expanded in x around inf 49.7%
associate-*r/49.7%
neg-mul-149.7%
Simplified49.7%
add-sqr-sqrt-0.0%
sqrt-unprod60.2%
sqr-neg60.2%
sqrt-unprod49.7%
add-sqr-sqrt49.7%
clear-num54.5%
inv-pow54.5%
Applied egg-rr54.5%
unpow-154.5%
Simplified54.5%
(FPCore (x s) :precision binary32 (if (<= (- x) 5.0999999517501353e-23) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ (/ (* s s) s) x)))
float code(float x, float s) {
float tmp;
if (-x <= 5.0999999517501353e-23f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = ((s * s) / 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 <= 5.0999999517501353e-23) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = ((s * s) / s) / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(5.0999999517501353e-23)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(Float32(s * s) / s) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(5.0999999517501353e-23)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = ((s * s) / s) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 5.0999999517501353 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{s \cdot s}{s}}{x}\\
\end{array}
\end{array}
if (neg.f32 x) < 5.09999995e-23Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 90.1%
+-commutative90.1%
Simplified90.1%
if 5.09999995e-23 < (neg.f32 x) Initial program 99.7%
Taylor expanded in x around 0 50.4%
neg-mul-150.4%
unsub-neg50.4%
Simplified50.4%
Taylor expanded in x around inf 38.6%
associate-*r/38.6%
neg-mul-138.6%
Simplified38.6%
neg-sub038.6%
flip--58.0%
metadata-eval58.0%
pow258.0%
add-sqr-sqrt58.0%
sqrt-unprod21.4%
sqr-neg21.4%
sqrt-unprod-0.0%
add-sqr-sqrt56.2%
sub-neg56.2%
neg-sub056.2%
add-sqr-sqrt-0.0%
sqrt-unprod21.4%
sqr-neg21.4%
sqrt-unprod58.0%
add-sqr-sqrt58.0%
Applied egg-rr58.0%
sub0-neg58.0%
Simplified58.0%
add-sqr-sqrt36.6%
sqrt-unprod65.4%
sqr-neg65.4%
sqrt-unprod56.2%
add-sqr-sqrt56.2%
unpow256.2%
Applied egg-rr56.2%
Final simplification77.8%
(FPCore (x s) :precision binary32 (if (<= x -4.999999987376214e-7) (/ s x) (if (<= x 4.99999991225835e-15) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -4.999999987376214e-7f) {
tmp = s / x;
} else if (x <= 4.99999991225835e-15f) {
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 <= (-4.999999987376214e-7)) then
tmp = s / x
else if (x <= 4.99999991225835e-15) 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(-4.999999987376214e-7)) tmp = Float32(s / x); elseif (x <= Float32(4.99999991225835e-15)) 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(-4.999999987376214e-7)) tmp = s / x; elseif (x <= single(4.99999991225835e-15)) 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 -4.999999987376214 \cdot 10^{-7}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{elif}\;x \leq 4.99999991225835 \cdot 10^{-15}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -4.99999999e-7Initial program 100.0%
Taylor expanded in x around 0 54.5%
neg-mul-154.5%
unsub-neg54.5%
Simplified54.5%
Taylor expanded in x around inf 49.7%
associate-*r/49.7%
neg-mul-149.7%
Simplified49.7%
neg-sub049.7%
sub-neg49.7%
add-sqr-sqrt-0.0%
sqrt-unprod60.2%
sqr-neg60.2%
sqrt-unprod49.7%
add-sqr-sqrt49.7%
Applied egg-rr49.7%
+-lft-identity49.7%
Simplified49.7%
if -4.99999999e-7 < x < 4.99999991e-15Initial program 99.3%
Taylor expanded in x around 0 61.6%
if 4.99999991e-15 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around inf 97.7%
neg-mul-197.7%
unsub-neg97.7%
Simplified97.7%
(FPCore (x s) :precision binary32 (if (<= x 1.0000000195414814e-24) (/ 1.0 (/ (- (* s 2.0) x) s)) (/ 1.0 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= 1.0000000195414814e-24f) {
tmp = 1.0f / (((s * 2.0f) - x) / s);
} else {
tmp = 1.0f / (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 <= 1.0000000195414814e-24) then
tmp = 1.0e0 / (((s * 2.0e0) - x) / s)
else
tmp = 1.0e0 / (1.0e0 + (s / x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(1.0000000195414814e-24)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(s * Float32(2.0)) - x) / s)); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(1.0000000195414814e-24)) tmp = single(1.0) / (((s * single(2.0)) - x) / s); else tmp = single(1.0) / (single(1.0) + (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.0000000195414814 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{\frac{s \cdot 2 - x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < 1.00000002e-24Initial program 99.6%
Taylor expanded in x around 0 60.4%
neg-mul-160.4%
unsub-neg60.4%
Simplified60.4%
Taylor expanded in x around inf 60.2%
sub-neg60.2%
associate-*r/60.2%
metadata-eval60.2%
distribute-neg-frac60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in s around 0 60.4%
neg-mul-160.4%
+-commutative60.4%
*-commutative60.4%
sub-neg60.4%
Simplified60.4%
if 1.00000002e-24 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.2%
+-commutative98.2%
Simplified98.2%
Taylor expanded in x around inf 92.4%
(FPCore (x s) :precision binary32 (if (<= x 1.0000000195414814e-24) (/ 1.0 (- 2.0 (/ x s))) (/ 1.0 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= 1.0000000195414814e-24f) {
tmp = 1.0f / (2.0f - (x / s));
} else {
tmp = 1.0f / (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 <= 1.0000000195414814e-24) then
tmp = 1.0e0 / (2.0e0 - (x / s))
else
tmp = 1.0e0 / (1.0e0 + (s / x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(1.0000000195414814e-24)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(1.0000000195414814e-24)) tmp = single(1.0) / (single(2.0) - (x / s)); else tmp = single(1.0) / (single(1.0) + (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.0000000195414814 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < 1.00000002e-24Initial program 99.6%
Taylor expanded in x around 0 60.4%
neg-mul-160.4%
unsub-neg60.4%
Simplified60.4%
if 1.00000002e-24 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.2%
+-commutative98.2%
Simplified98.2%
Taylor expanded in x around inf 92.4%
(FPCore (x s) :precision binary32 (if (<= x -4.999999987376214e-7) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999987376214e-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 <= (-4.999999987376214e-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(-4.999999987376214e-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(-4.999999987376214e-7)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999987376214 \cdot 10^{-7}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999999e-7Initial program 100.0%
Taylor expanded in x around 0 54.5%
neg-mul-154.5%
unsub-neg54.5%
Simplified54.5%
Taylor expanded in x around inf 49.7%
associate-*r/49.7%
neg-mul-149.7%
Simplified49.7%
neg-sub049.7%
sub-neg49.7%
add-sqr-sqrt-0.0%
sqrt-unprod60.2%
sqr-neg60.2%
sqrt-unprod49.7%
add-sqr-sqrt49.7%
Applied egg-rr49.7%
+-lft-identity49.7%
Simplified49.7%
if -4.99999999e-7 < x Initial program 99.6%
Taylor expanded in x around 0 45.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 35.7%
herbie shell --seed 2024147
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))