
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (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-prod82.8%
neg-mul-182.8%
exp-prod82.8%
pow-pow99.9%
div-inv99.8%
Applied egg-rr99.8%
add-exp-log99.8%
log-rec99.8%
log1p-expm1-u99.8%
log1p-define99.8%
pow-exp99.8%
expm1-log1p-u99.8%
neg-mul-199.8%
distribute-neg-frac299.8%
Applied egg-rr99.8%
(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.8%
div-inv99.8%
exp-prod82.8%
neg-mul-182.8%
exp-prod82.8%
pow-pow99.9%
div-inv99.8%
Applied egg-rr99.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
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -2.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 INFINITY)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ (/ x s) 2.0)))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -2.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (x / s);
}
return tmp;
}
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-2.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (t_0 <= Float32(Inf)) 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(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) / (x * (single(2.0) / x)); elseif (t_0 <= single(Inf)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / ((x / s) + single(2.0))); else tmp = single(1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -2:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
Taylor expanded in x around 0 5.1%
mul-1-neg5.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
associate-*r/5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 99.7%
Taylor expanded in x around 0 57.2%
mul-1-neg57.2%
unsub-neg57.2%
Simplified57.2%
sub-neg57.2%
neg-mul-157.2%
rem-log-exp95.6%
pow-exp95.6%
flip-+35.1%
metadata-eval35.1%
pow-exp35.1%
rem-log-exp35.1%
neg-mul-135.1%
pow-exp35.1%
rem-log-exp35.8%
neg-mul-135.8%
distribute-neg-frac235.8%
distribute-neg-frac235.8%
pow-exp35.8%
rem-log-exp59.1%
neg-mul-159.1%
distribute-neg-frac259.1%
Applied egg-rr59.1%
distribute-frac-neg259.1%
distribute-frac-neg259.1%
sqr-neg59.1%
clear-num59.1%
frac-times60.3%
*-un-lft-identity60.3%
Applied egg-rr60.3%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 36.0%
mul-1-neg36.0%
unsub-neg36.0%
Simplified36.0%
sub-neg36.0%
neg-mul-136.0%
rem-log-exp59.3%
pow-exp59.3%
flip-+20.9%
metadata-eval20.9%
pow-exp20.9%
rem-log-exp20.9%
neg-mul-120.9%
pow-exp20.9%
rem-log-exp21.5%
neg-mul-121.5%
distribute-neg-frac221.5%
distribute-neg-frac221.5%
pow-exp21.5%
rem-log-exp36.4%
neg-mul-136.4%
distribute-neg-frac236.4%
Applied egg-rr36.4%
distribute-frac-neg236.4%
distribute-frac-neg236.4%
sqr-neg36.4%
clear-num36.4%
frac-2neg36.4%
frac-times37.1%
*-un-lft-identity37.1%
add-sqr-sqrt-0.0%
sqrt-unprod39.1%
sqr-neg39.1%
sqrt-unprod38.3%
add-sqr-sqrt38.3%
Applied egg-rr38.3%
Taylor expanded in x around inf 18.6%
Final simplification47.2%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 5.0)
0.5
(if (<= t_0 INFINITY)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (/ x s)))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= 5.0f) {
tmp = 0.5f;
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (x / s));
} else {
tmp = 1.0f / (x / s);
}
return tmp;
}
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(5.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(Inf)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(x / s))); else tmp = Float32(Float32(1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(5.0)) tmp = single(0.5); elseif (t_0 <= single(Inf)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (x / s)); else tmp = single(1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 5:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 5Initial program 99.8%
Taylor expanded in x around 0 48.7%
if 5 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 99.9%
Taylor expanded in x around 0 36.2%
mul-1-neg36.2%
unsub-neg36.2%
Simplified36.2%
sub-neg36.2%
neg-mul-136.2%
rem-log-exp99.1%
pow-exp99.1%
flip-+0.1%
metadata-eval0.1%
pow-exp0.1%
rem-log-exp0.1%
neg-mul-10.1%
pow-exp0.1%
rem-log-exp1.2%
neg-mul-11.2%
distribute-neg-frac21.2%
distribute-neg-frac21.2%
pow-exp1.2%
rem-log-exp39.3%
neg-mul-139.3%
distribute-neg-frac239.3%
Applied egg-rr39.3%
Taylor expanded in x around inf 39.3%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 36.0%
mul-1-neg36.0%
unsub-neg36.0%
Simplified36.0%
sub-neg36.0%
neg-mul-136.0%
rem-log-exp59.3%
pow-exp59.3%
flip-+20.9%
metadata-eval20.9%
pow-exp20.9%
rem-log-exp20.9%
neg-mul-120.9%
pow-exp20.9%
rem-log-exp21.5%
neg-mul-121.5%
distribute-neg-frac221.5%
distribute-neg-frac221.5%
pow-exp21.5%
rem-log-exp36.4%
neg-mul-136.4%
distribute-neg-frac236.4%
Applied egg-rr36.4%
distribute-frac-neg236.4%
distribute-frac-neg236.4%
sqr-neg36.4%
clear-num36.4%
frac-2neg36.4%
frac-times37.1%
*-un-lft-identity37.1%
add-sqr-sqrt-0.0%
sqrt-unprod39.1%
sqr-neg39.1%
sqrt-unprod38.3%
add-sqr-sqrt38.3%
Applied egg-rr38.3%
Taylor expanded in x around inf 18.6%
Final simplification45.3%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -0.5) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (/ 1.0 (+ 0.5 (/ (* x -0.25) s)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -0.5f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (1.0f / (0.5f + ((x * -0.25f) / 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) <= (-0.5e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (1.0e0 / (0.5e0 + ((x * (-0.25e0)) / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-0.5)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(1.0) / Float32(Float32(0.5) + Float32(Float32(x * Float32(-0.25)) / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-0.5)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (single(1.0) / (single(0.5) + ((x * single(-0.25)) / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -0.5:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{1}{0.5 + \frac{x \cdot -0.25}{s}}}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -0.5Initial program 100.0%
Taylor expanded in x around 0 5.4%
mul-1-neg5.4%
unsub-neg5.4%
Simplified5.4%
Taylor expanded in x around inf 5.4%
associate-*r/5.4%
metadata-eval5.4%
Simplified5.4%
Taylor expanded in x around 0 28.2%
if -0.5 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 57.3%
mul-1-neg57.3%
unsub-neg57.3%
Simplified57.3%
sub-neg57.3%
neg-mul-157.3%
rem-log-exp96.0%
pow-exp96.0%
flip-+35.1%
metadata-eval35.1%
pow-exp35.1%
rem-log-exp35.1%
neg-mul-135.1%
pow-exp35.1%
rem-log-exp35.7%
neg-mul-135.7%
distribute-neg-frac235.7%
distribute-neg-frac235.7%
pow-exp35.7%
rem-log-exp59.2%
neg-mul-159.2%
distribute-neg-frac259.2%
Applied egg-rr59.2%
div-inv59.2%
cancel-sign-sub-inv59.2%
div-inv59.2%
frac-2neg59.2%
add-sqr-sqrt59.2%
sqrt-unprod47.6%
sqr-neg47.6%
sqrt-unprod-0.0%
add-sqr-sqrt56.5%
flip-+34.0%
metadata-eval34.0%
clear-num34.0%
clear-num34.0%
metadata-eval34.0%
flip-+56.5%
Applied egg-rr59.2%
Taylor expanded in x around 0 83.5%
associate-*r/83.5%
*-commutative83.5%
Simplified83.5%
Final simplification60.8%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0000000233721948e-7) 0.5 (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.0000000233721948e-7f) {
tmp = 0.5f;
} 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 / -s) <= 2.0000000233721948e-7) then
tmp = 0.5e0
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(-s)) <= Float32(2.0000000233721948e-7)) tmp = Float32(0.5); 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 / -s) <= single(2.0000000233721948e-7)) tmp = single(0.5); 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}\;\frac{x}{-s} \leq 2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot 2 - x}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2.00000002e-7Initial program 99.9%
Taylor expanded in x around 0 48.8%
if 2.00000002e-7 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 39.5%
mul-1-neg39.5%
unsub-neg39.5%
Simplified39.5%
Taylor expanded in x around inf 39.4%
associate-*r/39.4%
metadata-eval39.4%
Simplified39.4%
frac-sub43.1%
Applied egg-rr43.1%
Final simplification46.4%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2.0f) {
tmp = 1.0f / (x * (2.0f / 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 / (x * (2.0e0 / 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(-s)) <= Float32(-2.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / 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) / (x * (single(2.0) / 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:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
Taylor expanded in x around 0 5.1%
mul-1-neg5.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
associate-*r/5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 57.2%
mul-1-neg57.2%
unsub-neg57.2%
Simplified57.2%
Final simplification45.4%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.5) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.5f) {
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 / -s) <= 0.5e0) 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(-s)) <= Float32(0.5)) 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 / -s) <= single(0.5)) tmp = single(0.5); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 0.5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0 49.0%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 36.0%
mul-1-neg36.0%
unsub-neg36.0%
Simplified36.0%
Taylor expanded in x around inf 36.0%
mul-1-neg36.0%
distribute-neg-frac36.0%
Simplified36.0%
Final simplification44.2%
(FPCore (x s) :precision binary32 (if (<= x -0.0005000000237487257) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0005000000237487257f) {
tmp = 1.0f / (x / s);
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-0.0005000000237487257e0)) then
tmp = 1.0e0 / (x / s)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.0005000000237487257)) tmp = Float32(Float32(1.0) / Float32(x / s)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.0005000000237487257)) tmp = single(1.0) / (x / s); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000024e-4Initial program 99.9%
Taylor expanded in x around 0 43.1%
mul-1-neg43.1%
unsub-neg43.1%
Simplified43.1%
sub-neg43.1%
neg-mul-143.1%
rem-log-exp98.8%
pow-exp98.8%
flip-+0.2%
metadata-eval0.2%
pow-exp0.2%
rem-log-exp0.2%
neg-mul-10.2%
pow-exp0.2%
rem-log-exp0.8%
neg-mul-10.8%
distribute-neg-frac20.8%
distribute-neg-frac20.8%
pow-exp0.8%
rem-log-exp45.7%
neg-mul-145.7%
distribute-neg-frac245.7%
Applied egg-rr45.7%
distribute-frac-neg245.7%
distribute-frac-neg245.7%
sqr-neg45.7%
clear-num45.7%
frac-2neg45.7%
frac-times45.7%
*-un-lft-identity45.7%
add-sqr-sqrt-0.0%
sqrt-unprod45.6%
sqr-neg45.6%
sqrt-unprod45.6%
add-sqr-sqrt45.6%
Applied egg-rr45.6%
Taylor expanded in x around inf 43.0%
if -5.00000024e-4 < x Initial program 99.8%
Taylor expanded in x around 0 44.5%
(FPCore (x s) :precision binary32 (if (<= x -0.0005000000237487257) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0005000000237487257f) {
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 <= (-0.0005000000237487257e0)) 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(-0.0005000000237487257)) tmp = Float32(s / Float32(-x)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.0005000000237487257)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000024e-4Initial program 99.9%
Taylor expanded in x around 0 43.1%
mul-1-neg43.1%
unsub-neg43.1%
Simplified43.1%
Taylor expanded in x around inf 39.2%
associate-*r/39.2%
neg-mul-139.2%
Simplified39.2%
if -5.00000024e-4 < x Initial program 99.8%
Taylor expanded in x around 0 44.5%
Final simplification42.9%
(FPCore (x s) :precision binary32 (if (<= x -0.0005000000237487257) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0005000000237487257f) {
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 <= (-0.0005000000237487257e0)) 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(-0.0005000000237487257)) 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(-0.0005000000237487257)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000024e-4Initial program 99.9%
Taylor expanded in x around 0 43.1%
mul-1-neg43.1%
unsub-neg43.1%
Simplified43.1%
sub-neg43.1%
neg-mul-143.1%
rem-log-exp98.8%
pow-exp98.8%
flip-+0.2%
metadata-eval0.2%
pow-exp0.2%
rem-log-exp0.2%
neg-mul-10.2%
pow-exp0.2%
rem-log-exp0.8%
neg-mul-10.8%
distribute-neg-frac20.8%
distribute-neg-frac20.8%
pow-exp0.8%
rem-log-exp45.7%
neg-mul-145.7%
distribute-neg-frac245.7%
Applied egg-rr45.7%
distribute-frac-neg245.7%
distribute-frac-neg245.7%
sqr-neg45.7%
clear-num45.7%
frac-2neg45.7%
frac-times45.7%
*-un-lft-identity45.7%
add-sqr-sqrt-0.0%
sqrt-unprod45.6%
sqr-neg45.6%
sqrt-unprod45.6%
add-sqr-sqrt45.6%
Applied egg-rr45.6%
Taylor expanded in x around inf 39.1%
if -5.00000024e-4 < x Initial program 99.8%
Taylor expanded in x around 0 44.5%
(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 33.3%
herbie shell --seed 2024096
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))