
(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-prod85.4%
neg-mul-185.4%
exp-prod85.4%
pow-pow99.7%
div-inv99.7%
Applied egg-rr99.7%
add-exp-log99.8%
log-rec99.8%
log1p-expm1-u99.8%
log1p-define99.9%
expm1-log1p-u99.9%
pow-exp99.9%
neg-mul-199.9%
distribute-neg-frac299.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.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -1.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 INFINITY)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ 2.0 (/ x s))))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -1.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (2.0f + (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(-1.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(Float32(x / s) * Float32(x / s))) / Float32(Float32(2.0) + Float32(x / s)))); else tmp = Float32(Float32(1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(-1.0)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (t_0 <= single(Inf)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (single(2.0) + (x / s))); else tmp = single(1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -1:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 5.7%
neg-mul-15.7%
unsub-neg5.7%
Simplified5.7%
Taylor expanded in x around inf 5.7%
associate-*r/5.7%
metadata-eval5.7%
Simplified5.7%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 99.7%
Taylor expanded in x around 0 66.1%
neg-mul-166.1%
unsub-neg66.1%
Simplified66.1%
sub-neg66.1%
neg-mul-166.1%
rem-log-exp95.4%
pow-exp95.4%
flip-+38.7%
metadata-eval38.7%
pow-exp38.7%
rem-log-exp38.7%
neg-mul-138.7%
pow-exp38.7%
rem-log-exp39.1%
neg-mul-139.1%
distribute-neg-frac239.1%
distribute-neg-frac239.1%
pow-exp39.1%
rem-log-exp60.1%
neg-mul-160.1%
distribute-neg-frac260.1%
Applied egg-rr60.1%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 42.7%
neg-mul-142.7%
unsub-neg42.7%
Simplified42.7%
Taylor expanded in x around inf 19.7%
associate-*r/19.7%
neg-mul-119.7%
Simplified19.7%
clear-num21.0%
inv-pow21.0%
add-sqr-sqrt-0.0%
sqrt-unprod29.2%
sqr-neg29.2%
sqrt-unprod22.3%
add-sqr-sqrt22.3%
Applied egg-rr22.3%
unpow-122.3%
Simplified22.3%
Final simplification47.8%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.0020000000949949026) 0.5 (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.0020000000949949026f) {
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) <= 0.0020000000949949026e0) 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(0.0020000000949949026)) 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(0.0020000000949949026)) 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 0.0020000000949949026:\\
\;\;\;\;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) < 0.00200000009Initial program 99.8%
Taylor expanded in x around 0 52.0%
if 0.00200000009 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 46.9%
neg-mul-146.9%
unsub-neg46.9%
Simplified46.9%
Taylor expanded in x around inf 47.6%
associate-*r/47.6%
metadata-eval47.6%
Simplified47.6%
sub-neg47.6%
distribute-frac-neg247.6%
add-sqr-sqrt-0.0%
sqrt-unprod66.5%
sqr-neg66.5%
sqrt-unprod46.5%
add-sqr-sqrt46.5%
frac-2neg46.5%
metadata-eval46.5%
frac-add54.2%
add-sqr-sqrt-0.0%
sqrt-unprod53.0%
sqr-neg53.0%
sqrt-unprod53.0%
add-sqr-sqrt53.0%
*-commutative53.0%
add-sqr-sqrt-0.0%
sqrt-unprod67.3%
sqr-neg67.3%
sqrt-unprod55.0%
add-sqr-sqrt55.0%
Applied egg-rr55.0%
Final simplification53.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 20.0) 0.5 (/ 1.0 (* x (/ (- x (* s -2.0)) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 20.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (x * ((x - (s * -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) <= 20.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x * ((x - (s * (-2.0e0))) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(20.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(x - Float32(s * Float32(-2.0))) / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(20.0)) tmp = single(0.5); else tmp = single(1.0) / (x * ((x - (s * single(-2.0))) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 20:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x - s \cdot -2}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 20Initial program 99.8%
Taylor expanded in x around 0 50.9%
if 20 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 47.9%
neg-mul-147.9%
unsub-neg47.9%
Simplified47.9%
Taylor expanded in x around inf 48.6%
associate-*r/48.6%
metadata-eval48.6%
Simplified48.6%
sub-neg48.6%
frac-2neg48.6%
distribute-frac-neg248.6%
add-sqr-sqrt-0.0%
sqrt-unprod70.1%
sqr-neg70.1%
sqrt-unprod48.6%
add-sqr-sqrt48.6%
/-rgt-identity48.6%
clear-num48.6%
frac-add56.8%
metadata-eval56.8%
Applied egg-rr56.8%
*-rgt-identity56.8%
unsub-neg56.8%
*-commutative56.8%
distribute-lft-neg-in56.8%
distribute-rgt-neg-in56.8%
Simplified56.8%
Final simplification53.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (* x (/ 1.0 s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 1.0f / (x * (2.0f / 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 / -s) <= (-1.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / 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(-s)) <= Float32(-1.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 * Float32(Float32(1.0) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-1.0)) tmp = single(1.0) / (x * (single(2.0) / 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}\;\frac{x}{-s} \leq -1:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - x \cdot \frac{1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 5.7%
neg-mul-15.7%
unsub-neg5.7%
Simplified5.7%
Taylor expanded in x around inf 5.7%
associate-*r/5.7%
metadata-eval5.7%
Simplified5.7%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 66.1%
neg-mul-166.1%
unsub-neg66.1%
Simplified66.1%
clear-num66.1%
associate-/r/66.5%
Applied egg-rr66.5%
Final simplification51.7%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.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) <= (-1.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(-1.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(-1.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 -1:\\
\;\;\;\;\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) < -1Initial program 100.0%
Taylor expanded in x around 0 5.7%
neg-mul-15.7%
unsub-neg5.7%
Simplified5.7%
Taylor expanded in x around inf 5.7%
associate-*r/5.7%
metadata-eval5.7%
Simplified5.7%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 66.1%
neg-mul-166.1%
unsub-neg66.1%
Simplified66.1%
Final simplification51.4%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0) 0.5 (/ -1.0 (* x (/ 1.0 s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.0f) {
tmp = 0.5f;
} else {
tmp = -1.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 / -s) <= 2.0e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x * (1.0e0 / 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(0.5); else tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(1.0) / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(2.0)) tmp = single(0.5); else tmp = single(-1.0) / (x * (single(1.0) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.8%
Taylor expanded in x around 0 51.6%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 46.9%
neg-mul-146.9%
unsub-neg46.9%
Simplified46.9%
Taylor expanded in x around inf 47.7%
associate-*r/47.7%
metadata-eval47.7%
Simplified47.7%
Taylor expanded in x around inf 47.7%
Final simplification50.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.0f) {
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) <= 2.0e0) 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(2.0)) 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(2.0)) 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 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.8%
Taylor expanded in x around 0 51.6%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 46.9%
neg-mul-146.9%
unsub-neg46.9%
Simplified46.9%
Taylor expanded in x around inf 46.9%
associate-*r/46.9%
neg-mul-146.9%
Simplified46.9%
Final simplification49.9%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.0010000000474974513) 0.5 (/ 1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 0.0010000000474974513f) {
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 <= 0.0010000000474974513e0) 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(0.0010000000474974513)) 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(0.0010000000474974513)) 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 0.0010000000474974513:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 0.00100000005Initial program 99.7%
Taylor expanded in x around 0 46.2%
if 0.00100000005 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 59.1%
neg-mul-159.1%
unsub-neg59.1%
Simplified59.1%
Taylor expanded in x around inf 54.2%
associate-*r/54.2%
neg-mul-154.2%
Simplified54.2%
clear-num59.1%
inv-pow59.1%
add-sqr-sqrt-0.0%
sqrt-unprod70.7%
sqr-neg70.7%
sqrt-unprod59.1%
add-sqr-sqrt59.1%
Applied egg-rr59.1%
unpow-159.1%
Simplified59.1%
(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(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 99.9%
Taylor expanded in x around 0 55.3%
neg-mul-155.3%
unsub-neg55.3%
Simplified55.3%
Taylor expanded in x around inf 50.8%
associate-*r/50.8%
neg-mul-150.8%
Simplified50.8%
if -1.99999999e-6 < x Initial program 99.7%
Taylor expanded in x around 0 47.4%
(FPCore (x s) :precision binary32 (if (<= x -0.0010000000474974513) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0010000000474974513f) {
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.0010000000474974513e0)) 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.0010000000474974513)) 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.0010000000474974513)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0010000000474974513:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.00100000005Initial program 100.0%
Taylor expanded in x around 0 59.1%
neg-mul-159.1%
unsub-neg59.1%
Simplified59.1%
Taylor expanded in x around inf 54.2%
associate-*r/54.2%
neg-mul-154.2%
Simplified54.2%
add-sqr-sqrt-0.0%
sqrt-unprod68.8%
sqr-neg68.8%
sqrt-unprod54.2%
add-sqr-sqrt54.2%
div-inv54.2%
Applied egg-rr54.2%
associate-*r/54.2%
*-rgt-identity54.2%
Simplified54.2%
if -0.00100000005 < 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.3%
herbie shell --seed 2024165
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))