
(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 19 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(x / Float32(-s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{\frac{x}{-s}}\right)}
\end{array}
Initial program 99.8%
div-inv99.8%
exp-prod81.4%
neg-mul-181.4%
exp-prod81.4%
pow-pow99.8%
div-inv99.8%
Applied egg-rr99.8%
Applied egg-rr99.9%
(FPCore (x s) :precision binary32 (if (<= x -1.2000000136174153e-17) (/ (/ (pow s 2.0) (- s)) x) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -1.2000000136174153e-17f) {
tmp = (powf(s, 2.0f) / -s) / x;
} else {
tmp = 1.0f / (1.0f + (1.0f / (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 <= (-1.2000000136174153e-17)) then
tmp = ((s ** 2.0e0) / -s) / x
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.2000000136174153e-17)) tmp = Float32(Float32((s ^ Float32(2.0)) / Float32(-s)) / x); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-1.2000000136174153e-17)) tmp = ((s ^ single(2.0)) / -s) / x; else tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2000000136174153 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{{s}^{2}}{-s}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -1.20000001e-17Initial program 99.7%
Taylor expanded in x around 0 40.5%
neg-mul-140.5%
unsub-neg40.5%
Simplified40.5%
Taylor expanded in x around inf 30.7%
associate-*r/30.7%
neg-mul-130.7%
Simplified30.7%
neg-sub030.7%
flip--54.1%
metadata-eval54.1%
pow254.1%
add-sqr-sqrt54.1%
sqrt-unprod11.2%
sqr-neg11.2%
sqrt-unprod-0.0%
add-sqr-sqrt52.5%
sub-neg52.5%
neg-sub052.5%
add-sqr-sqrt-0.0%
sqrt-unprod11.2%
sqr-neg11.2%
sqrt-unprod54.1%
add-sqr-sqrt54.1%
Applied egg-rr54.1%
sub0-neg54.1%
Simplified54.1%
if -1.20000001e-17 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 92.8%
+-commutative92.8%
Simplified92.8%
Final simplification76.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (/ 1.0 (pow E (/ x s))))))
float code(float x, float s) {
return 1.0f / (1.0f + (1.0f / powf(((float) M_E), (x / s))));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / (Float32(exp(1)) ^ Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(2.71828182845904523536) ^ (x / s)))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{1}{{e}^{\left(\frac{x}{s}\right)}}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
*-un-lft-identity99.8%
exp-prod99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow E (/ x (- s))))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(((float) M_E), (x / -s)));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(x / Float32(-s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(2.71828182845904523536) ^ (x / -s))); end
\begin{array}{l}
\\
\frac{1}{1 + {e}^{\left(\frac{x}{-s}\right)}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
*-un-lft-identity99.8%
exp-prod99.8%
Applied egg-rr99.8%
inv-pow99.8%
pow-pow99.8%
exp-1-e99.8%
Applied egg-rr99.8%
*-commutative99.8%
neg-mul-199.8%
distribute-neg-frac299.8%
Simplified99.8%
(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(x / Float32(-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.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(if (<= (- x) -4.000000072010038e-35)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= (- x) 999999986991104.0)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ (/ x s) 2.0)))
(/ 1.0 (+ 2.0 (/ -1.0 (/ s x)))))))
float code(float x, float s) {
float tmp;
if (-x <= -4.000000072010038e-35f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (-x <= 999999986991104.0f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (2.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.000000072010038e-35)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (-x <= 999999986991104.0e0) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / ((x / s) + 2.0e0))
else
tmp = 1.0e0 / (2.0e0 + ((-1.0e0) / (s / x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-4.000000072010038e-35)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); elseif (Float32(-x) <= Float32(999999986991104.0)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x / Float32(s * Float32(s / x)))) / Float32(Float32(x / s) + Float32(2.0)))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.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.000000072010038e-35)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (-x <= single(999999986991104.0)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / ((x / s) + single(2.0))); else tmp = single(1.0) / (single(2.0) + (single(-1.0) / (s / x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -4.000000072010038 \cdot 10^{-35}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;-x \leq 999999986991104:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\end{array}
\end{array}
if (neg.f32 x) < -4.00000007e-35Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.3%
+-commutative95.3%
Simplified95.3%
if -4.00000007e-35 < (neg.f32 x) < 9.99999987e14Initial program 99.4%
Taylor expanded in x around 0 47.2%
neg-mul-147.2%
unsub-neg47.2%
Simplified47.2%
*-un-lft-identity47.2%
cancel-sign-sub-inv47.2%
metadata-eval47.2%
add-log-exp95.1%
pow-exp95.1%
flip-+36.8%
metadata-eval36.8%
pow-exp36.8%
add-log-exp36.8%
neg-mul-136.8%
pow-exp36.8%
add-log-exp37.7%
neg-mul-137.7%
distribute-neg-frac237.7%
distribute-neg-frac237.7%
pow-exp37.7%
Applied egg-rr64.1%
frac-times62.9%
sqr-neg62.9%
frac-times64.1%
clear-num64.1%
frac-times66.6%
*-un-lft-identity66.6%
Applied egg-rr66.6%
if 9.99999987e14 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 67.2%
neg-mul-167.2%
unsub-neg67.2%
Simplified67.2%
clear-num67.2%
inv-pow67.2%
Applied egg-rr67.2%
unpow-167.2%
Simplified67.2%
Final simplification79.6%
(FPCore (x s)
:precision binary32
(if (<= (- x) 9.999999974752427e-7)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= (- x) 999999986991104.0)
(/ -1.0 (/ (- (* (/ x s) (/ x s)) 4.0) (/ x s)))
(/ 1.0 (+ 2.0 (/ -1.0 (/ s x)))))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999974752427e-7f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (-x <= 999999986991104.0f) {
tmp = -1.0f / ((((x / s) * (x / s)) - 4.0f) / (x / s));
} else {
tmp = 1.0f / (2.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 <= 9.999999974752427e-7) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (-x <= 999999986991104.0e0) then
tmp = (-1.0e0) / ((((x / s) * (x / s)) - 4.0e0) / (x / s))
else
tmp = 1.0e0 / (2.0e0 + ((-1.0e0) / (s / x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(9.999999974752427e-7)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); elseif (Float32(-x) <= Float32(999999986991104.0)) tmp = Float32(Float32(-1.0) / Float32(Float32(Float32(Float32(x / s) * Float32(x / s)) - Float32(4.0)) / Float32(x / s))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.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(9.999999974752427e-7)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (-x <= single(999999986991104.0)) tmp = single(-1.0) / ((((x / s) * (x / s)) - single(4.0)) / (x / s)); else tmp = single(1.0) / (single(2.0) + (single(-1.0) / (s / x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;-x \leq 999999986991104:\\
\;\;\;\;\frac{-1}{\frac{\frac{x}{s} \cdot \frac{x}{s} - 4}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\end{array}
\end{array}
if (neg.f32 x) < 9.99999997e-7Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 82.0%
+-commutative82.0%
Simplified82.0%
if 9.99999997e-7 < (neg.f32 x) < 9.99999987e14Initial program 100.0%
Taylor expanded in x around 0 23.5%
neg-mul-123.5%
unsub-neg23.5%
Simplified23.5%
*-un-lft-identity23.5%
cancel-sign-sub-inv23.5%
metadata-eval23.5%
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.9%
neg-mul-10.9%
distribute-neg-frac20.9%
distribute-neg-frac20.9%
pow-exp0.9%
Applied egg-rr61.2%
Taylor expanded in x around inf 61.2%
if 9.99999987e14 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 67.2%
neg-mul-167.2%
unsub-neg67.2%
Simplified67.2%
clear-num67.2%
inv-pow67.2%
Applied egg-rr67.2%
unpow-167.2%
Simplified67.2%
Final simplification76.9%
(FPCore (x s)
:precision binary32
(if (<= x -1.9999999949504854e-6)
(/ 1.0 (* x (/ 1.0 s)))
(if (<= x 1.999999936531045e-20)
(+ 0.5 (/ (* x 0.25) s))
(/ 1.0 (+ 1.0 (/ s x))))))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999949504854e-6f) {
tmp = 1.0f / (x * (1.0f / s));
} else if (x <= 1.999999936531045e-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 <= (-1.9999999949504854e-6)) then
tmp = 1.0e0 / (x * (1.0e0 / s))
else if (x <= 1.999999936531045e-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(-1.9999999949504854e-6)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(1.0) / s))); elseif (x <= Float32(1.999999936531045e-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(-1.9999999949504854e-6)) tmp = single(1.0) / (x * (single(1.0) / s)); elseif (x <= single(1.999999936531045e-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 -1.9999999949504854 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{x \cdot \frac{1}{s}}\\
\mathbf{elif}\;x \leq 1.999999936531045 \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 < -1.99999999e-6Initial program 100.0%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 43.5%
mul-1-neg43.5%
distribute-frac-neg243.5%
Simplified43.5%
add-sqr-sqrt-0.0%
sqrt-unprod59.0%
sqr-neg59.0%
sqrt-unprod43.5%
add-sqr-sqrt43.5%
div-inv43.5%
*-commutative43.5%
Applied egg-rr43.5%
if -1.99999999e-6 < x < 1.99999994e-20Initial program 99.3%
Taylor expanded in x around 0 66.2%
associate-*r/66.2%
Simplified66.2%
if 1.99999994e-20 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.0%
+-commutative97.0%
Simplified97.0%
Taylor expanded in x around inf 90.4%
Final simplification68.5%
(FPCore (x s)
:precision binary32
(if (<= x -1.9999999949504854e-6)
(/ 1.0 (* x (/ 1.0 s)))
(if (<= x 1.9999999920083944e-11)
(+ 0.5 (/ (* x 0.25) s))
(- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999949504854e-6f) {
tmp = 1.0f / (x * (1.0f / s));
} else if (x <= 1.9999999920083944e-11f) {
tmp = 0.5f + ((x * 0.25f) / s);
} 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 <= (-1.9999999949504854e-6)) then
tmp = 1.0e0 / (x * (1.0e0 / s))
else if (x <= 1.9999999920083944e-11) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 - (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.9999999949504854e-6)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(1.0) / s))); elseif (x <= Float32(1.9999999920083944e-11)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); 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(-1.9999999949504854e-6)) tmp = single(1.0) / (x * (single(1.0) / s)); elseif (x <= single(1.9999999920083944e-11)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(1.0) - (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9999999949504854 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{x \cdot \frac{1}{s}}\\
\mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-11}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -1.99999999e-6Initial program 100.0%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 43.5%
mul-1-neg43.5%
distribute-frac-neg243.5%
Simplified43.5%
add-sqr-sqrt-0.0%
sqrt-unprod59.0%
sqr-neg59.0%
sqrt-unprod43.5%
add-sqr-sqrt43.5%
div-inv43.5%
*-commutative43.5%
Applied egg-rr43.5%
if -1.99999999e-6 < x < 1.99999999e-11Initial program 99.4%
Taylor expanded in x around 0 65.1%
associate-*r/65.1%
Simplified65.1%
if 1.99999999e-11 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.7%
+-commutative96.7%
Simplified96.7%
Taylor expanded in x around inf 93.7%
neg-mul-193.7%
unsub-neg93.7%
Simplified93.7%
Final simplification68.2%
(FPCore (x s)
:precision binary32
(if (<= x -1.9999999949504854e-6)
(/ 1.0 (/ x s))
(if (<= x 1.9999999920083944e-11)
(+ 0.5 (/ (* x 0.25) s))
(- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999949504854e-6f) {
tmp = 1.0f / (x / s);
} else if (x <= 1.9999999920083944e-11f) {
tmp = 0.5f + ((x * 0.25f) / s);
} 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 <= (-1.9999999949504854e-6)) then
tmp = 1.0e0 / (x / s)
else if (x <= 1.9999999920083944e-11) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 - (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.9999999949504854e-6)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(1.9999999920083944e-11)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); 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(-1.9999999949504854e-6)) tmp = single(1.0) / (x / s); elseif (x <= single(1.9999999920083944e-11)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(1.0) - (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9999999949504854 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-11}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -1.99999999e-6Initial program 100.0%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 39.4%
associate-*r/39.4%
neg-mul-139.4%
Simplified39.4%
neg-sub039.4%
sub-neg39.4%
add-sqr-sqrt-0.0%
sqrt-unprod57.2%
sqr-neg57.2%
sqrt-unprod39.4%
add-sqr-sqrt39.4%
Applied egg-rr39.4%
+-lft-identity39.4%
Simplified39.4%
clear-num43.5%
inv-pow43.5%
Applied egg-rr43.5%
unpow-143.5%
Simplified43.5%
if -1.99999999e-6 < x < 1.99999999e-11Initial program 99.4%
Taylor expanded in x around 0 65.1%
associate-*r/65.1%
Simplified65.1%
if 1.99999999e-11 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.7%
+-commutative96.7%
Simplified96.7%
Taylor expanded in x around inf 93.7%
neg-mul-193.7%
unsub-neg93.7%
Simplified93.7%
Final simplification68.2%
(FPCore (x s) :precision binary32 (if (<= (- x) -3.999999984016789e-11) (- 1.0 (/ s x)) (if (<= (- x) 9.999999974752427e-7) 0.5 (/ 1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -3.999999984016789e-11f) {
tmp = 1.0f - (s / x);
} else if (-x <= 9.999999974752427e-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 <= (-3.999999984016789e-11)) then
tmp = 1.0e0 - (s / x)
else if (-x <= 9.999999974752427e-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(-3.999999984016789e-11)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999974752427e-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(-3.999999984016789e-11)) tmp = single(1.0) - (s / x); elseif (-x <= single(9.999999974752427e-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 -3.999999984016789 \cdot 10^{-11}:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -3.99999998e-11Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.7%
+-commutative96.7%
Simplified96.7%
Taylor expanded in x around inf 93.7%
neg-mul-193.7%
unsub-neg93.7%
Simplified93.7%
if -3.99999998e-11 < (neg.f32 x) < 9.99999997e-7Initial program 99.4%
Taylor expanded in x around 0 59.5%
if 9.99999997e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 39.4%
associate-*r/39.4%
neg-mul-139.4%
Simplified39.4%
neg-sub039.4%
sub-neg39.4%
add-sqr-sqrt-0.0%
sqrt-unprod57.2%
sqr-neg57.2%
sqrt-unprod39.4%
add-sqr-sqrt39.4%
Applied egg-rr39.4%
+-lft-identity39.4%
Simplified39.4%
clear-num43.5%
inv-pow43.5%
Applied egg-rr43.5%
unpow-143.5%
Simplified43.5%
(FPCore (x s) :precision binary32 (if (<= (- x) -4.000000072010038e-35) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (/ (/ 1.0 s) (/ -1.0 x))))))
float code(float x, float s) {
float tmp;
if (-x <= -4.000000072010038e-35f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((1.0f / s) / (-1.0f / 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.000000072010038e-35)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((1.0e0 / s) / ((-1.0e0) / x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-4.000000072010038e-35)) 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(Float32(2.0) + Float32(Float32(Float32(1.0) / s) / Float32(Float32(-1.0) / x)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-4.000000072010038e-35)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + ((single(1.0) / s) / (single(-1.0) / x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -4.000000072010038 \cdot 10^{-35}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{\frac{1}{s}}{\frac{-1}{x}}}\\
\end{array}
\end{array}
if (neg.f32 x) < -4.00000007e-35Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.3%
+-commutative95.3%
Simplified95.3%
if -4.00000007e-35 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 51.8%
neg-mul-151.8%
unsub-neg51.8%
Simplified51.8%
clear-num51.8%
associate-/r/51.8%
Applied egg-rr51.8%
associate-/r/51.8%
div-inv51.8%
associate-/r*51.8%
Applied egg-rr51.8%
Final simplification71.4%
(FPCore (x s) :precision binary32 (if (<= (- x) -4.000000072010038e-35) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (* x (/ -1.0 s))))))
float code(float x, float s) {
float tmp;
if (-x <= -4.000000072010038e-35f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + (x * (-1.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 <= (-4.000000072010038e-35)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + (x * ((-1.0e0) / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-4.000000072010038e-35)) 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(Float32(2.0) + Float32(x * Float32(Float32(-1.0) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-4.000000072010038e-35)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + (x * (single(-1.0) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -4.000000072010038 \cdot 10^{-35}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -4.00000007e-35Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.3%
+-commutative95.3%
Simplified95.3%
if -4.00000007e-35 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 51.8%
neg-mul-151.8%
unsub-neg51.8%
Simplified51.8%
clear-num51.8%
associate-/r/51.8%
Applied egg-rr51.8%
Final simplification71.4%
(FPCore (x s) :precision binary32 (if (<= x -1.9999999949504854e-6) (* s (/ 1.0 x)) (if (<= x 1.9999999920083944e-11) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999949504854e-6f) {
tmp = s * (1.0f / x);
} else if (x <= 1.9999999920083944e-11f) {
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 <= (-1.9999999949504854e-6)) then
tmp = s * (1.0e0 / x)
else if (x <= 1.9999999920083944e-11) 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(-1.9999999949504854e-6)) tmp = Float32(s * Float32(Float32(1.0) / x)); elseif (x <= Float32(1.9999999920083944e-11)) 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(-1.9999999949504854e-6)) tmp = s * (single(1.0) / x); elseif (x <= single(1.9999999920083944e-11)) 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 -1.9999999949504854 \cdot 10^{-6}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-11}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -1.99999999e-6Initial program 100.0%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 39.4%
associate-*r/39.4%
neg-mul-139.4%
Simplified39.4%
clear-num43.5%
associate-/r/39.4%
add-sqr-sqrt-0.0%
sqrt-unprod57.2%
sqr-neg57.2%
sqrt-unprod39.4%
add-sqr-sqrt39.4%
Applied egg-rr39.4%
if -1.99999999e-6 < x < 1.99999999e-11Initial program 99.4%
Taylor expanded in x around 0 59.5%
if 1.99999999e-11 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.7%
+-commutative96.7%
Simplified96.7%
Taylor expanded in x around inf 93.7%
neg-mul-193.7%
unsub-neg93.7%
Simplified93.7%
Final simplification64.8%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.999999936531045e-20) (/ 1.0 (+ 1.0 (/ s x))) (/ 1.0 (+ 2.0 (* x (/ -1.0 s))))))
float code(float x, float s) {
float tmp;
if (-x <= -1.999999936531045e-20f) {
tmp = 1.0f / (1.0f + (s / x));
} else {
tmp = 1.0f / (2.0f + (x * (-1.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 <= (-1.999999936531045e-20)) then
tmp = 1.0e0 / (1.0e0 + (s / x))
else
tmp = 1.0e0 / (2.0e0 + (x * ((-1.0e0) / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-1.999999936531045e-20)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(x * Float32(Float32(-1.0) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-1.999999936531045e-20)) tmp = single(1.0) / (single(1.0) + (s / x)); else tmp = single(1.0) / (single(2.0) + (x * (single(-1.0) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -1.999999936531045 \cdot 10^{-20}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.99999994e-20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.0%
+-commutative97.0%
Simplified97.0%
Taylor expanded in x around inf 90.4%
if -1.99999994e-20 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 55.6%
neg-mul-155.6%
unsub-neg55.6%
Simplified55.6%
clear-num55.6%
associate-/r/55.6%
Applied egg-rr55.6%
Final simplification68.1%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.999999936531045e-20) (/ 1.0 (+ 1.0 (/ s x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -1.999999936531045e-20f) {
tmp = 1.0f / (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 <= (-1.999999936531045e-20)) then
tmp = 1.0e0 / (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(-x) <= Float32(-1.999999936531045e-20)) tmp = Float32(Float32(1.0) / 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 <= single(-1.999999936531045e-20)) tmp = single(1.0) / (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}\;-x \leq -1.999999936531045 \cdot 10^{-20}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.99999994e-20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.0%
+-commutative97.0%
Simplified97.0%
Taylor expanded in x around inf 90.4%
if -1.99999994e-20 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 55.6%
neg-mul-155.6%
unsub-neg55.6%
Simplified55.6%
(FPCore (x s) :precision binary32 (if (<= x -1.9999999949504854e-6) (* s (/ 1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999949504854e-6f) {
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 <= (-1.9999999949504854e-6)) 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(-1.9999999949504854e-6)) 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(-1.9999999949504854e-6)) 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 -1.9999999949504854 \cdot 10^{-6}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.99999999e-6Initial program 100.0%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 39.4%
associate-*r/39.4%
neg-mul-139.4%
Simplified39.4%
clear-num43.5%
associate-/r/39.4%
add-sqr-sqrt-0.0%
sqrt-unprod57.2%
sqr-neg57.2%
sqrt-unprod39.4%
add-sqr-sqrt39.4%
Applied egg-rr39.4%
if -1.99999999e-6 < x Initial program 99.7%
Taylor expanded in x around 0 46.2%
Final simplification44.3%
(FPCore (x s) :precision binary32 (if (<= x -1.9999999949504854e-6) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999949504854e-6f) {
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 <= (-1.9999999949504854e-6)) 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(-1.9999999949504854e-6)) 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(-1.9999999949504854e-6)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9999999949504854 \cdot 10^{-6}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.99999999e-6Initial program 100.0%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 39.4%
associate-*r/39.4%
neg-mul-139.4%
Simplified39.4%
neg-sub039.4%
sub-neg39.4%
add-sqr-sqrt-0.0%
sqrt-unprod57.2%
sqr-neg57.2%
sqrt-unprod39.4%
add-sqr-sqrt39.4%
Applied egg-rr39.4%
+-lft-identity39.4%
Simplified39.4%
if -1.99999999e-6 < x Initial program 99.7%
Taylor expanded in x around 0 46.2%
(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%
herbie shell --seed 2024166
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))