
(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 14 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.9%
div-inv99.9%
exp-prod88.1%
neg-mul-188.1%
exp-prod88.1%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow (exp -1.0) (/ x s)))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-1.0f), (x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp((-1.0e0)) ** (x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-1.0)) ^ Float32(x / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-1.0)) ^ (x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}
\end{array}
Initial program 99.9%
div-inv99.9%
exp-prod88.1%
neg-mul-188.1%
exp-prod88.1%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
(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.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(if (<= x -4.999999721059845e+27)
(/ 1.0 (+ 2.0 (/ -1.0 (/ s x))))
(if (<= x -4.999999955487895e-38)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ (/ x s) 2.0)))
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))))))
float code(float x, float s) {
float tmp;
if (x <= -4.999999721059845e+27f) {
tmp = 1.0f / (2.0f + (-1.0f / (s / x)));
} else if (x <= -4.999999955487895e-38f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / ((x / s) + 2.0f));
} 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 <= (-4.999999721059845e+27)) then
tmp = 1.0e0 / (2.0e0 + ((-1.0e0) / (s / x)))
else if (x <= (-4.999999955487895e-38)) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / ((x / s) + 2.0e0))
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(-4.999999721059845e+27)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(-1.0) / Float32(s / x)))); elseif (x <= Float32(-4.999999955487895e-38)) 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(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(-4.999999721059845e+27)) tmp = single(1.0) / (single(2.0) + (single(-1.0) / (s / x))); elseif (x <= single(-4.999999955487895e-38)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / ((x / s) + single(2.0))); 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 -4.999999721059845 \cdot 10^{+27}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\mathbf{elif}\;x \leq -4.999999955487895 \cdot 10^{-38}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -4.99999972e27Initial program 100.0%
Taylor expanded in x around 0 86.6%
neg-mul-186.6%
unsub-neg86.6%
Simplified86.6%
clear-num86.6%
inv-pow86.6%
Applied egg-rr86.6%
unpow-186.6%
Simplified86.6%
if -4.99999972e27 < x < -4.99999996e-38Initial program 99.7%
Taylor expanded in x around 0 43.5%
neg-mul-143.5%
unsub-neg43.5%
Simplified43.5%
*-un-lft-identity43.5%
cancel-sign-sub-inv43.5%
metadata-eval43.5%
add-log-exp95.1%
pow-exp95.1%
flip-+25.1%
metadata-eval25.1%
pow-exp25.1%
add-log-exp25.1%
neg-mul-125.1%
pow-exp25.1%
add-log-exp25.9%
neg-mul-125.9%
distribute-neg-frac225.9%
distribute-neg-frac225.9%
pow-exp25.9%
Applied egg-rr58.2%
clear-num58.2%
frac-times62.8%
*-un-lft-identity62.8%
add-sqr-sqrt-0.0%
sqrt-unprod59.8%
sqr-neg59.8%
sqrt-unprod62.7%
add-sqr-sqrt62.7%
add-sqr-sqrt-0.0%
sqrt-unprod59.8%
sqr-neg59.8%
sqrt-unprod62.8%
add-sqr-sqrt62.8%
Applied egg-rr62.8%
if -4.99999996e-38 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.6%
+-commutative97.6%
Simplified97.6%
Final simplification82.8%
(FPCore (x s)
:precision binary32
(if (<= x -4.999999721059845e+27)
(/ 1.0 (+ 2.0 (/ -1.0 (/ s x))))
(if (<= x -5.00000006675716e-11)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (/ x s)))
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))))))
float code(float x, float s) {
float tmp;
if (x <= -4.999999721059845e+27f) {
tmp = 1.0f / (2.0f + (-1.0f / (s / x)));
} else if (x <= -5.00000006675716e-11f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (x / s));
} 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 <= (-4.999999721059845e+27)) then
tmp = 1.0e0 / (2.0e0 + ((-1.0e0) / (s / x)))
else if (x <= (-5.00000006675716e-11)) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (x / s))
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(-4.999999721059845e+27)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(-1.0) / Float32(s / x)))); elseif (x <= Float32(-5.00000006675716e-11)) 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(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(-4.999999721059845e+27)) tmp = single(1.0) / (single(2.0) + (single(-1.0) / (s / x))); elseif (x <= single(-5.00000006675716e-11)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (x / s)); 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 -4.999999721059845 \cdot 10^{+27}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\mathbf{elif}\;x \leq -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -4.99999972e27Initial program 100.0%
Taylor expanded in x around 0 86.6%
neg-mul-186.6%
unsub-neg86.6%
Simplified86.6%
clear-num86.6%
inv-pow86.6%
Applied egg-rr86.6%
unpow-186.6%
Simplified86.6%
if -4.99999972e27 < x < -5.00000007e-11Initial program 100.0%
Taylor expanded in x around 0 28.3%
neg-mul-128.3%
unsub-neg28.3%
Simplified28.3%
*-un-lft-identity28.3%
cancel-sign-sub-inv28.3%
metadata-eval28.3%
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-exp1.0%
neg-mul-11.0%
distribute-neg-frac21.0%
distribute-neg-frac21.0%
pow-exp1.0%
Applied egg-rr51.7%
Taylor expanded in x around inf 51.7%
if -5.00000007e-11 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 91.1%
+-commutative91.1%
Simplified91.1%
Final simplification80.9%
(FPCore (x s)
:precision binary32
(if (<= x -5.00000006675716e-11)
(/ 1.0 (/ x s))
(if (<= x 1.000000031374395e-22)
(+ 0.5 (/ (* x 0.25) s))
(/ 1.0 (+ 1.0 (/ s x))))))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
tmp = 1.0f / (x / s);
} else if (x <= 1.000000031374395e-22f) {
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 <= (-5.00000006675716e-11)) then
tmp = 1.0e0 / (x / s)
else if (x <= 1.000000031374395e-22) 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(-5.00000006675716e-11)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(1.000000031374395e-22)) 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(-5.00000006675716e-11)) tmp = single(1.0) / (x / s); elseif (x <= single(1.000000031374395e-22)) 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 -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 100.0%
Taylor expanded in x around 0 46.6%
neg-mul-146.6%
unsub-neg46.6%
Simplified46.6%
Taylor expanded in x around inf 40.0%
associate-*r/40.0%
neg-mul-140.0%
Simplified40.0%
add-sqr-sqrt-0.0%
sqrt-unprod54.5%
sqr-neg54.5%
sqrt-unprod40.0%
add-sqr-sqrt40.0%
clear-num46.6%
inv-pow46.6%
Applied egg-rr46.6%
unpow-146.6%
Simplified46.6%
if -5.00000007e-11 < x < 1.00000003e-22Initial program 99.5%
Taylor expanded in x around 0 81.0%
associate-*r/81.0%
Simplified81.0%
if 1.00000003e-22 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in x around inf 93.9%
Final simplification73.4%
(FPCore (x s) :precision binary32 (if (<= x -5.00000006675716e-11) (/ 1.0 (/ x s)) (if (<= x 1.000000031374395e-22) (+ 0.5 (/ (* x 0.25) s)) (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
tmp = 1.0f / (x / s);
} else if (x <= 1.000000031374395e-22f) {
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 <= (-5.00000006675716e-11)) then
tmp = 1.0e0 / (x / s)
else if (x <= 1.000000031374395e-22) 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(-5.00000006675716e-11)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(1.000000031374395e-22)) 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(-5.00000006675716e-11)) tmp = single(1.0) / (x / s); elseif (x <= single(1.000000031374395e-22)) 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 -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 100.0%
Taylor expanded in x around 0 46.6%
neg-mul-146.6%
unsub-neg46.6%
Simplified46.6%
Taylor expanded in x around inf 40.0%
associate-*r/40.0%
neg-mul-140.0%
Simplified40.0%
add-sqr-sqrt-0.0%
sqrt-unprod54.5%
sqr-neg54.5%
sqrt-unprod40.0%
add-sqr-sqrt40.0%
clear-num46.6%
inv-pow46.6%
Applied egg-rr46.6%
unpow-146.6%
Simplified46.6%
if -5.00000007e-11 < x < 1.00000003e-22Initial program 99.5%
Taylor expanded in x around 0 81.0%
associate-*r/81.0%
Simplified81.0%
if 1.00000003e-22 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in x around inf 93.3%
neg-mul-193.3%
unsub-neg93.3%
Simplified93.3%
Final simplification73.2%
(FPCore (x s) :precision binary32 (if (<= x -4.999999955487895e-38) (/ 1.0 (+ 2.0 (/ -1.0 (/ s x)))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -4.999999955487895e-38f) {
tmp = 1.0f / (2.0f + (-1.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 <= (-4.999999955487895e-38)) then
tmp = 1.0e0 / (2.0e0 + ((-1.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(-4.999999955487895e-38)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(-1.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(-4.999999955487895e-38)) tmp = single(1.0) / (single(2.0) + (single(-1.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 -4.999999955487895 \cdot 10^{-38}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -4.99999996e-38Initial program 99.8%
Taylor expanded in x around 0 53.2%
neg-mul-153.2%
unsub-neg53.2%
Simplified53.2%
clear-num53.2%
inv-pow53.2%
Applied egg-rr53.2%
unpow-153.2%
Simplified53.2%
if -4.99999996e-38 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.6%
+-commutative97.6%
Simplified97.6%
Final simplification75.2%
(FPCore (x s) :precision binary32 (if (<= x -5.00000006675716e-11) (/ 1.0 (/ x s)) (if (<= x 1.000000031374395e-22) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
tmp = 1.0f / (x / s);
} else if (x <= 1.000000031374395e-22f) {
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 <= (-5.00000006675716e-11)) then
tmp = 1.0e0 / (x / s)
else if (x <= 1.000000031374395e-22) 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(-5.00000006675716e-11)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(1.000000031374395e-22)) 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(-5.00000006675716e-11)) tmp = single(1.0) / (x / s); elseif (x <= single(1.000000031374395e-22)) 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 -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 100.0%
Taylor expanded in x around 0 46.6%
neg-mul-146.6%
unsub-neg46.6%
Simplified46.6%
Taylor expanded in x around inf 40.0%
associate-*r/40.0%
neg-mul-140.0%
Simplified40.0%
add-sqr-sqrt-0.0%
sqrt-unprod54.5%
sqr-neg54.5%
sqrt-unprod40.0%
add-sqr-sqrt40.0%
clear-num46.6%
inv-pow46.6%
Applied egg-rr46.6%
unpow-146.6%
Simplified46.6%
if -5.00000007e-11 < x < 1.00000003e-22Initial program 99.5%
Taylor expanded in x around 0 76.9%
if 1.00000003e-22 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in x around inf 93.3%
neg-mul-193.3%
unsub-neg93.3%
Simplified93.3%
(FPCore (x s) :precision binary32 (if (<= x -5.00000006675716e-11) (/ s x) (if (<= x 1.000000031374395e-22) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
tmp = s / x;
} else if (x <= 1.000000031374395e-22f) {
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 <= (-5.00000006675716e-11)) then
tmp = s / x
else if (x <= 1.000000031374395e-22) 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(-5.00000006675716e-11)) tmp = Float32(s / x); elseif (x <= Float32(1.000000031374395e-22)) 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(-5.00000006675716e-11)) tmp = s / x; elseif (x <= single(1.000000031374395e-22)) 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 -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{elif}\;x \leq 1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 100.0%
Taylor expanded in x around 0 46.6%
neg-mul-146.6%
unsub-neg46.6%
Simplified46.6%
Taylor expanded in x around inf 40.0%
associate-*r/40.0%
neg-mul-140.0%
Simplified40.0%
neg-sub040.0%
sub-neg40.0%
add-sqr-sqrt-0.0%
sqrt-unprod54.5%
sqr-neg54.5%
sqrt-unprod40.0%
add-sqr-sqrt40.0%
Applied egg-rr40.0%
+-lft-identity40.0%
Simplified40.0%
if -5.00000007e-11 < x < 1.00000003e-22Initial program 99.5%
Taylor expanded in x around 0 76.9%
if 1.00000003e-22 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in x around inf 93.3%
neg-mul-193.3%
unsub-neg93.3%
Simplified93.3%
(FPCore (x s) :precision binary32 (if (<= x 1.000000031374395e-22) (/ 1.0 (+ 2.0 (/ -1.0 (/ s x)))) (/ 1.0 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= 1.000000031374395e-22f) {
tmp = 1.0f / (2.0f + (-1.0f / (s / x)));
} 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.000000031374395e-22) then
tmp = 1.0e0 / (2.0e0 + ((-1.0e0) / (s / x)))
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.000000031374395e-22)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(-1.0) / Float32(s / x)))); 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.000000031374395e-22)) tmp = single(1.0) / (single(2.0) + (single(-1.0) / (s / x))); 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.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < 1.00000003e-22Initial program 99.8%
Taylor expanded in x around 0 60.3%
neg-mul-160.3%
unsub-neg60.3%
Simplified60.3%
clear-num60.3%
inv-pow60.3%
Applied egg-rr60.3%
unpow-160.3%
Simplified60.3%
if 1.00000003e-22 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in x around inf 93.9%
Final simplification72.7%
(FPCore (x s) :precision binary32 (if (<= x 1.000000031374395e-22) (/ 1.0 (- 2.0 (/ x s))) (/ 1.0 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= 1.000000031374395e-22f) {
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.000000031374395e-22) 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.000000031374395e-22)) 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.000000031374395e-22)) 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.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < 1.00000003e-22Initial program 99.8%
Taylor expanded in x around 0 60.3%
neg-mul-160.3%
unsub-neg60.3%
Simplified60.3%
if 1.00000003e-22 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in x around inf 93.9%
(FPCore (x s) :precision binary32 (if (<= x -5.00000006675716e-11) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -5.00000006675716e-11f) {
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 <= (-5.00000006675716e-11)) 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(-5.00000006675716e-11)) 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(-5.00000006675716e-11)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000007e-11Initial program 100.0%
Taylor expanded in x around 0 46.6%
neg-mul-146.6%
unsub-neg46.6%
Simplified46.6%
Taylor expanded in x around inf 40.0%
associate-*r/40.0%
neg-mul-140.0%
Simplified40.0%
neg-sub040.0%
sub-neg40.0%
add-sqr-sqrt-0.0%
sqrt-unprod54.5%
sqr-neg54.5%
sqrt-unprod40.0%
add-sqr-sqrt40.0%
Applied egg-rr40.0%
+-lft-identity40.0%
Simplified40.0%
if -5.00000007e-11 < x Initial program 99.8%
Taylor expanded in x around 0 50.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.9%
Taylor expanded in x around 0 34.9%
herbie shell --seed 2024185
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))