
(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(-Float32(x / s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
add-exp-log99.8%
log-rec99.8%
log1p-expm1-u99.8%
log1p-define99.9%
expm1-log1p-u99.9%
rec-exp99.9%
distribute-neg-frac299.9%
Applied egg-rr99.9%
Final simplification99.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(-Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp(-(x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{-\frac{x}{s}}}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (+ 2.0 (/ x s))))
(if (<= x -50000000188416.0)
(/ -1.0 (/ -1.0 (/ x (* x t_0))))
(if (<= x -5.000000136226006e-28)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) t_0))
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))))
float code(float x, float s) {
float t_0 = 2.0f + (x / s);
float tmp;
if (x <= -50000000188416.0f) {
tmp = -1.0f / (-1.0f / (x / (x * t_0)));
} else if (x <= -5.000000136226006e-28f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / t_0);
} 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) :: t_0
real(4) :: tmp
t_0 = 2.0e0 + (x / s)
if (x <= (-50000000188416.0e0)) then
tmp = (-1.0e0) / ((-1.0e0) / (x / (x * t_0)))
else if (x <= (-5.000000136226006e-28)) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / t_0)
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(2.0) + Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-50000000188416.0)) tmp = Float32(Float32(-1.0) / Float32(Float32(-1.0) / Float32(x / Float32(x * t_0)))); elseif (x <= Float32(-5.000000136226006e-28)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / t_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) t_0 = single(2.0) + (x / s); tmp = single(0.0); if (x <= single(-50000000188416.0)) tmp = single(-1.0) / (single(-1.0) / (x / (x * t_0))); elseif (x <= single(-5.000000136226006e-28)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / t_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}
t_0 := 2 + \frac{x}{s}\\
\mathbf{if}\;x \leq -50000000188416:\\
\;\;\;\;\frac{-1}{\frac{-1}{\frac{x}{x \cdot t\_0}}}\\
\mathbf{elif}\;x \leq -5.000000136226006 \cdot 10^{-28}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{t\_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -5.00000002e13Initial program 100.0%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
unsub-neg78.2%
Simplified78.2%
Taylor expanded in x around inf 78.2%
associate-*r/78.2%
metadata-eval78.2%
Simplified78.2%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
unsub-neg78.2%
Simplified78.2%
associate-*r/97.9%
clear-num97.9%
sub-neg97.9%
distribute-frac-neg297.9%
add-sqr-sqrt-0.0%
sqrt-unprod97.9%
sqr-neg97.9%
sqrt-unprod97.9%
add-sqr-sqrt97.9%
Applied egg-rr97.9%
if -5.00000002e13 < x < -5.00000014e-28Initial program 99.6%
Taylor expanded in x around 0 33.9%
neg-mul-133.9%
unsub-neg33.9%
Simplified33.9%
sub-neg33.9%
flip-+60.2%
metadata-eval60.2%
distribute-neg-frac260.2%
distribute-neg-frac260.2%
distribute-neg-frac260.2%
Applied egg-rr60.2%
if -5.00000014e-28 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.4%
+-commutative95.4%
Simplified95.4%
Final simplification86.5%
(FPCore (x s) :precision binary32 (if (<= x -3.99999992980668e-13) (/ -1.0 (/ -1.0 (/ x (* x (+ 2.0 (/ x s)))))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -3.99999992980668e-13f) {
tmp = -1.0f / (-1.0f / (x / (x * (2.0f + (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 <= (-3.99999992980668e-13)) then
tmp = (-1.0e0) / ((-1.0e0) / (x / (x * (2.0e0 + (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(-3.99999992980668e-13)) tmp = Float32(Float32(-1.0) / Float32(Float32(-1.0) / Float32(x / Float32(x * Float32(Float32(2.0) + 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(-3.99999992980668e-13)) tmp = single(-1.0) / (single(-1.0) / (x / (x * (single(2.0) + (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 -3.99999992980668 \cdot 10^{-13}:\\
\;\;\;\;\frac{-1}{\frac{-1}{\frac{x}{x \cdot \left(2 + \frac{x}{s}\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -3.99999993e-13Initial program 99.8%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 45.7%
associate-*r/45.7%
metadata-eval45.7%
Simplified45.7%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
associate-*r/58.8%
clear-num58.8%
sub-neg58.8%
distribute-frac-neg258.8%
add-sqr-sqrt-0.0%
sqrt-unprod73.7%
sqr-neg73.7%
sqrt-unprod58.2%
add-sqr-sqrt58.2%
Applied egg-rr58.2%
if -3.99999993e-13 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 92.6%
+-commutative92.6%
Simplified92.6%
Final simplification80.5%
(FPCore (x s) :precision binary32 (if (<= x -3.99999992980668e-13) (/ 1.0 (/ (* x (+ 2.0 (/ x s))) x)) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -3.99999992980668e-13f) {
tmp = 1.0f / ((x * (2.0f + (x / 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 <= (-3.99999992980668e-13)) then
tmp = 1.0e0 / ((x * (2.0e0 + (x / 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(-3.99999992980668e-13)) tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(2.0) + Float32(x / 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(-3.99999992980668e-13)) tmp = single(1.0) / ((x * (single(2.0) + (x / 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 -3.99999992980668 \cdot 10^{-13}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -3.99999993e-13Initial program 99.8%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 45.7%
associate-*r/45.7%
metadata-eval45.7%
Simplified45.7%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
associate-*r/58.8%
sub-neg58.8%
distribute-frac-neg258.8%
add-sqr-sqrt-0.0%
sqrt-unprod73.7%
sqr-neg73.7%
sqrt-unprod58.2%
add-sqr-sqrt58.2%
Applied egg-rr58.2%
if -3.99999993e-13 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 92.6%
+-commutative92.6%
Simplified92.6%
Final simplification80.5%
(FPCore (x s) :precision binary32 (if (<= x -5.000000136226006e-28) (/ 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 <= -5.000000136226006e-28f) {
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 <= (-5.000000136226006e-28)) 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(-5.000000136226006e-28)) 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(-5.000000136226006e-28)) 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 -5.000000136226006 \cdot 10^{-28}:\\
\;\;\;\;\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 < -5.00000014e-28Initial program 99.7%
Taylor expanded in x around 0 51.0%
neg-mul-151.0%
unsub-neg51.0%
Simplified51.0%
clear-num51.0%
inv-pow51.0%
Applied egg-rr51.0%
unpow-151.0%
Simplified51.0%
if -5.00000014e-28 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.4%
+-commutative95.4%
Simplified95.4%
Final simplification76.2%
(FPCore (x s) :precision binary32 (if (<= x 9.999999998199587e-24) (/ 1.0 (+ 2.0 (/ -1.0 (/ s x)))) 0.5))
float code(float x, float s) {
float tmp;
if (x <= 9.999999998199587e-24f) {
tmp = 1.0f / (2.0f + (-1.0f / (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 <= 9.999999998199587e-24) then
tmp = 1.0e0 / (2.0e0 + ((-1.0e0) / (s / x)))
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(9.999999998199587e-24)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(-1.0) / 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(9.999999998199587e-24)) tmp = single(1.0) / (single(2.0) + (single(-1.0) / (s / x))); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.999999998199587 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < 1e-23Initial program 99.7%
Taylor expanded in x around 0 63.1%
neg-mul-163.1%
unsub-neg63.1%
Simplified63.1%
clear-num63.1%
inv-pow63.1%
Applied egg-rr63.1%
unpow-163.1%
Simplified63.1%
if 1e-23 < x Initial program 99.9%
Taylor expanded in x around 0 35.2%
Final simplification51.8%
(FPCore (x s) :precision binary32 (if (<= x 9.999999998199587e-24) (/ 1.0 (- 2.0 (/ x s))) 0.5))
float code(float x, float s) {
float tmp;
if (x <= 9.999999998199587e-24f) {
tmp = 1.0f / (2.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 <= 9.999999998199587e-24) then
tmp = 1.0e0 / (2.0e0 - (x / s))
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(9.999999998199587e-24)) tmp = Float32(Float32(1.0) / Float32(Float32(2.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(9.999999998199587e-24)) tmp = single(1.0) / (single(2.0) - (x / s)); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.999999998199587 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < 1e-23Initial program 99.7%
Taylor expanded in x around 0 63.1%
neg-mul-163.1%
unsub-neg63.1%
Simplified63.1%
if 1e-23 < x Initial program 99.9%
Taylor expanded in x around 0 35.2%
(FPCore (x s) :precision binary32 (if (<= x -3.99999992980668e-13) (/ -1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -3.99999992980668e-13f) {
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 <= (-3.99999992980668e-13)) 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(-3.99999992980668e-13)) 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(-3.99999992980668e-13)) 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 -3.99999992980668 \cdot 10^{-13}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -3.99999993e-13Initial program 99.8%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 45.4%
mul-1-neg45.4%
distribute-frac-neg245.4%
Simplified45.4%
if -3.99999993e-13 < x Initial program 99.8%
Taylor expanded in x around 0 53.8%
Final simplification50.9%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-6) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-6f) {
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 <= (-9.999999747378752e-6)) 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(-9.999999747378752e-6)) 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(-9.999999747378752e-6)) 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 -9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-6Initial program 100.0%
Taylor expanded in x around 0 52.4%
neg-mul-152.4%
unsub-neg52.4%
Simplified52.4%
Taylor expanded in x around inf 46.8%
associate-*r/46.8%
neg-mul-146.8%
Simplified46.8%
add-sqr-sqrt-0.0%
sqrt-unprod62.1%
sqr-neg62.1%
sqrt-unprod46.5%
add-sqr-sqrt46.5%
clear-num52.1%
inv-pow52.1%
Applied egg-rr52.1%
unpow-152.1%
Simplified52.1%
if -9.99999975e-6 < x Initial program 99.7%
Taylor expanded in x around 0 50.1%
(FPCore (x s) :precision binary32 (if (<= x -3.99999992980668e-13) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -3.99999992980668e-13f) {
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 <= (-3.99999992980668e-13)) 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(-3.99999992980668e-13)) 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(-3.99999992980668e-13)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.99999992980668 \cdot 10^{-13}:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -3.99999993e-13Initial program 99.8%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 40.8%
associate-*r/40.8%
neg-mul-140.8%
Simplified40.8%
if -3.99999993e-13 < x Initial program 99.8%
Taylor expanded in x around 0 53.8%
Final simplification49.3%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-6) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-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 <= (-9.999999747378752e-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(-9.999999747378752e-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(-9.999999747378752e-6)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-6Initial program 100.0%
Taylor expanded in x around 0 52.4%
neg-mul-152.4%
unsub-neg52.4%
Simplified52.4%
Taylor expanded in x around inf 46.8%
associate-*r/46.8%
neg-mul-146.8%
Simplified46.8%
div-inv46.8%
add-sqr-sqrt-0.0%
sqrt-unprod62.1%
sqr-neg62.1%
sqrt-unprod46.5%
add-sqr-sqrt46.5%
Applied egg-rr46.5%
associate-*r/46.5%
*-rgt-identity46.5%
Simplified46.5%
if -9.99999975e-6 < x Initial program 99.7%
Taylor expanded in x around 0 50.1%
(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 37.4%
herbie shell --seed 2024150
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))