
(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 (/ 1.0 (+ 1.0 (exp (/ (* (/ -1.0 (sqrt s)) x) (sqrt s))))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((((-1.0f / sqrtf(s)) * x) / sqrtf(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) / sqrt(s)) * x) / sqrt(s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(Float32(Float32(-1.0) / sqrt(s)) * x) / sqrt(s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((((single(-1.0) / sqrt(s)) * x) / sqrt(s)))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{\frac{-1}{\sqrt{s}} \cdot x}{\sqrt{s}}}}
\end{array}
Initial program 99.8%
neg-mul-199.8%
add-sqr-sqrt99.8%
times-frac99.8%
Applied egg-rr99.8%
associate-*r/99.8%
Simplified99.8%
(FPCore (x s) :precision binary32 (if (<= x -1.999999936531045e-19) (/ (/ (- (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.999999936531045e-19f) {
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.999999936531045e-19)) 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.999999936531045e-19)) tmp = Float32(Float32(Float32(-(s ^ Float32(2.0))) / 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.999999936531045e-19)) 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.999999936531045 \cdot 10^{-19}:\\
\;\;\;\;\frac{\frac{-{s}^{2}}{s}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -1.99999994e-19Initial program 99.9%
Taylor expanded in x around 0 58.7%
neg-mul-158.7%
unsub-neg58.7%
Simplified58.7%
Taylor expanded in x around inf 48.9%
associate-*r/48.9%
neg-mul-148.9%
Simplified48.9%
neg-sub048.9%
flip--69.3%
metadata-eval69.3%
pow269.3%
add-sqr-sqrt69.3%
sqrt-unprod15.1%
sqr-neg15.1%
sqrt-unprod-0.0%
add-sqr-sqrt68.1%
sub-neg68.1%
neg-sub068.1%
add-sqr-sqrt-0.0%
sqrt-unprod15.1%
sqr-neg15.1%
sqrt-unprod69.3%
add-sqr-sqrt69.3%
Applied egg-rr69.3%
sub0-neg69.3%
Simplified69.3%
if -1.99999994e-19 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.6%
(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 -5.999999809593135e-22) (/ 1.0 (* x (* (- (* s 2.0) x) (/ 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.999999809593135e-22f) {
tmp = 1.0f / (x * (((s * 2.0f) - x) * (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.999999809593135e-22)) then
tmp = 1.0e0 / (x * (((s * 2.0e0) - x) * (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.999999809593135e-22)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) * 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.999999809593135e-22)) tmp = single(1.0) / (x * (((s * single(2.0)) - x) * (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.999999809593135 \cdot 10^{-22}:\\
\;\;\;\;\frac{1}{x \cdot \left(\left(s \cdot 2 - x\right) \cdot \frac{1}{s \cdot x}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -5.9999998e-22Initial program 99.8%
Taylor expanded in x around 0 58.8%
neg-mul-158.8%
unsub-neg58.8%
Simplified58.8%
Taylor expanded in x around inf 58.6%
sub-neg58.6%
associate-*r/58.6%
metadata-eval58.6%
distribute-neg-frac58.6%
metadata-eval58.6%
Simplified58.6%
frac-add62.4%
div-inv65.8%
fma-define65.8%
Applied egg-rr65.8%
*-commutative65.8%
neg-mul-165.8%
fmm-def65.8%
*-commutative65.8%
Simplified65.8%
if -5.9999998e-22 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 94.6%
Final simplification83.6%
(FPCore (x s) :precision binary32 (if (<= x -1.9999999996399175e-23) (/ 1.0 (* x (/ (+ x (* 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.9999999996399175e-23f) {
tmp = 1.0f / (x * ((x + (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.9999999996399175e-23)) then
tmp = 1.0e0 / (x * ((x + (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.9999999996399175e-23)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(x + 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.9999999996399175e-23)) tmp = single(1.0) / (x * ((x + (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.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x + s \cdot 2}{s \cdot x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -2e-23Initial program 99.8%
Taylor expanded in x around 0 59.0%
neg-mul-159.0%
unsub-neg59.0%
Simplified59.0%
Taylor expanded in x around inf 58.8%
sub-neg58.8%
associate-*r/58.8%
metadata-eval58.8%
distribute-neg-frac58.8%
metadata-eval58.8%
Simplified58.8%
+-commutative58.8%
frac-2neg58.8%
metadata-eval58.8%
frac-add63.1%
*-un-lft-identity63.1%
add-sqr-sqrt-0.0%
sqrt-unprod52.6%
sqr-neg52.6%
sqrt-unprod52.6%
add-sqr-sqrt52.6%
add-sqr-sqrt-0.0%
sqrt-unprod76.2%
sqr-neg76.2%
sqrt-unprod61.8%
add-sqr-sqrt61.8%
Applied egg-rr61.8%
if -2e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.7%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (/ 1.0 (* x (/ -1.0 s))) (if (<= x 5.000000156871975e-23) (+ 0.5 (/ (* x 0.25) s)) 1.0)))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
tmp = 1.0f / (x * (-1.0f / s));
} else if (x <= 5.000000156871975e-23f) {
tmp = 0.5f + ((x * 0.25f) / s);
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-4.999999873689376e-5)) then
tmp = 1.0e0 / (x * ((-1.0e0) / s))
else if (x <= 5.000000156871975e-23) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999873689376e-5)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(-1.0) / s))); elseif (x <= Float32(5.000000156871975e-23)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-5)) tmp = single(1.0) / (x * (single(-1.0) / s)); elseif (x <= single(5.000000156871975e-23)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{x \cdot \frac{-1}{s}}\\
\mathbf{elif}\;x \leq 5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 63.1%
neg-mul-163.1%
unsub-neg63.1%
Simplified63.1%
Taylor expanded in x around inf 63.1%
sub-neg63.1%
associate-*r/63.1%
metadata-eval63.1%
distribute-neg-frac63.1%
metadata-eval63.1%
Simplified63.1%
Taylor expanded in x around inf 63.1%
if -4.99999987e-5 < x < 5.00000016e-23Initial program 99.5%
Taylor expanded in x around 0 74.2%
associate-*r/74.2%
Simplified74.2%
if 5.00000016e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.2%
Taylor expanded in x around inf 91.3%
Final simplification78.0%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (/ 1.0 (/ x s)) (if (<= x 5.000000156871975e-23) (+ 0.5 (/ (* x 0.25) s)) 1.0)))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
tmp = 1.0f / (x / s);
} else if (x <= 5.000000156871975e-23f) {
tmp = 0.5f + ((x * 0.25f) / s);
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-4.999999873689376e-5)) then
tmp = 1.0e0 / (x / s)
else if (x <= 5.000000156871975e-23) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999873689376e-5)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(5.000000156871975e-23)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-5)) tmp = single(1.0) / (x / s); elseif (x <= single(5.000000156871975e-23)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 63.1%
neg-mul-163.1%
unsub-neg63.1%
Simplified63.1%
Taylor expanded in x around inf 57.5%
associate-*r/57.5%
neg-mul-157.5%
Simplified57.5%
clear-num63.1%
inv-pow63.1%
add-sqr-sqrt-0.0%
sqrt-unprod74.3%
sqr-neg74.3%
sqrt-unprod63.1%
add-sqr-sqrt63.1%
Applied egg-rr63.1%
unpow-163.1%
Simplified63.1%
if -4.99999987e-5 < x < 5.00000016e-23Initial program 99.5%
Taylor expanded in x around 0 74.2%
associate-*r/74.2%
Simplified74.2%
if 5.00000016e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.2%
Taylor expanded in x around inf 91.3%
Final simplification78.0%
(FPCore (x s) :precision binary32 (if (<= x -5.000000179695649e-37) (/ 1.0 (- 2.0 (/ x s))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -5.000000179695649e-37f) {
tmp = 1.0f / (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 <= (-5.000000179695649e-37)) then
tmp = 1.0e0 / (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(-5.000000179695649e-37)) tmp = Float32(Float32(1.0) / 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(-5.000000179695649e-37)) tmp = single(1.0) / (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 -5.000000179695649 \cdot 10^{-37}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -5.00000018e-37Initial program 99.7%
Taylor expanded in x around 0 63.5%
neg-mul-163.5%
unsub-neg63.5%
Simplified63.5%
if -5.00000018e-37 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.5%
(FPCore (x s) :precision binary32 (if (<= x 5.000000156871975e-23) (/ 1.0 (- 2.0 (/ x s))) 1.0))
float code(float x, float s) {
float tmp;
if (x <= 5.000000156871975e-23f) {
tmp = 1.0f / (2.0f - (x / s));
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 5.000000156871975e-23) then
tmp = 1.0e0 / (2.0e0 - (x / s))
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(5.000000156871975e-23)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s))); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(5.000000156871975e-23)) tmp = single(1.0) / (single(2.0) - (x / s)); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 5.00000016e-23Initial program 99.7%
Taylor expanded in x around 0 67.7%
neg-mul-167.7%
unsub-neg67.7%
Simplified67.7%
if 5.00000016e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.2%
Taylor expanded in x around inf 91.3%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (/ 1.0 (/ x s)) (if (<= x 5.000000156871975e-23) 0.5 1.0)))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
tmp = 1.0f / (x / s);
} else if (x <= 5.000000156871975e-23f) {
tmp = 0.5f;
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-4.999999873689376e-5)) then
tmp = 1.0e0 / (x / s)
else if (x <= 5.000000156871975e-23) then
tmp = 0.5e0
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999873689376e-5)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(5.000000156871975e-23)) tmp = Float32(0.5); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-5)) tmp = single(1.0) / (x / s); elseif (x <= single(5.000000156871975e-23)) tmp = single(0.5); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 63.1%
neg-mul-163.1%
unsub-neg63.1%
Simplified63.1%
Taylor expanded in x around inf 57.5%
associate-*r/57.5%
neg-mul-157.5%
Simplified57.5%
clear-num63.1%
inv-pow63.1%
add-sqr-sqrt-0.0%
sqrt-unprod74.3%
sqr-neg74.3%
sqrt-unprod63.1%
add-sqr-sqrt63.1%
Applied egg-rr63.1%
unpow-163.1%
Simplified63.1%
if -4.99999987e-5 < x < 5.00000016e-23Initial program 99.5%
Taylor expanded in x around 0 70.4%
if 5.00000016e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.2%
Taylor expanded in x around inf 91.3%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (* s (/ 1.0 x)) (if (<= x 5.000000156871975e-23) 0.5 1.0)))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
tmp = s * (1.0f / x);
} else if (x <= 5.000000156871975e-23f) {
tmp = 0.5f;
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-4.999999873689376e-5)) then
tmp = s * (1.0e0 / x)
else if (x <= 5.000000156871975e-23) then
tmp = 0.5e0
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999873689376e-5)) tmp = Float32(s * Float32(Float32(1.0) / x)); elseif (x <= Float32(5.000000156871975e-23)) tmp = Float32(0.5); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-5)) tmp = s * (single(1.0) / x); elseif (x <= single(5.000000156871975e-23)) tmp = single(0.5); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{elif}\;x \leq 5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 63.1%
neg-mul-163.1%
unsub-neg63.1%
Simplified63.1%
Taylor expanded in x around inf 57.5%
associate-*r/57.5%
neg-mul-157.5%
Simplified57.5%
add-sqr-sqrt-0.0%
sqrt-unprod70.7%
sqr-neg70.7%
sqrt-unprod57.5%
add-sqr-sqrt57.5%
div-inv57.5%
Applied egg-rr57.5%
if -4.99999987e-5 < x < 5.00000016e-23Initial program 99.5%
Taylor expanded in x around 0 70.4%
if 5.00000016e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.2%
Taylor expanded in x around inf 91.3%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (/ s x) (if (<= x 5.000000156871975e-23) 0.5 1.0)))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
tmp = s / x;
} else if (x <= 5.000000156871975e-23f) {
tmp = 0.5f;
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-4.999999873689376e-5)) then
tmp = s / x
else if (x <= 5.000000156871975e-23) then
tmp = 0.5e0
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999873689376e-5)) tmp = Float32(s / x); elseif (x <= Float32(5.000000156871975e-23)) tmp = Float32(0.5); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-5)) tmp = s / x; elseif (x <= single(5.000000156871975e-23)) tmp = single(0.5); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{elif}\;x \leq 5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 63.1%
neg-mul-163.1%
unsub-neg63.1%
Simplified63.1%
Taylor expanded in x around inf 57.5%
associate-*r/57.5%
neg-mul-157.5%
Simplified57.5%
neg-sub057.5%
sub-neg57.5%
add-sqr-sqrt-0.0%
sqrt-unprod70.7%
sqr-neg70.7%
sqrt-unprod57.5%
add-sqr-sqrt57.5%
Applied egg-rr57.5%
+-lft-identity57.5%
Simplified57.5%
if -4.99999987e-5 < x < 5.00000016e-23Initial program 99.5%
Taylor expanded in x around 0 70.4%
if 5.00000016e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.2%
Taylor expanded in x around inf 91.3%
(FPCore (x s) :precision binary32 (if (<= x 5.000000156871975e-23) 0.5 1.0))
float code(float x, float s) {
float tmp;
if (x <= 5.000000156871975e-23f) {
tmp = 0.5f;
} else {
tmp = 1.0f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 5.000000156871975e-23) then
tmp = 0.5e0
else
tmp = 1.0e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(5.000000156871975e-23)) tmp = Float32(0.5); else tmp = Float32(1.0); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(5.000000156871975e-23)) tmp = single(0.5); else tmp = single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 5.00000016e-23Initial program 99.7%
Taylor expanded in x around 0 37.7%
if 5.00000016e-23 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.2%
Taylor expanded in x around inf 91.3%
(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 36.1%
herbie shell --seed 2024180
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))