
(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 16 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 (/ 1.0 (pow E (/ x s))))))
float code(float x, float s) {
return 1.0f / (1.0f + (1.0f / powf(((float) M_E), (x / s))));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / (Float32(exp(1)) ^ Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(2.71828182845904523536) ^ (x / s)))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{1}{{e}^{\left(\frac{x}{s}\right)}}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
exp-prod99.9%
Applied egg-rr99.9%
exp-1-e99.9%
Simplified99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow E (/ x (- s))))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(((float) M_E), (x / -s)));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(x / Float32(-s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(2.71828182845904523536) ^ (x / -s))); end
\begin{array}{l}
\\
\frac{1}{1 + {e}^{\left(\frac{x}{-s}\right)}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
exp-prod99.9%
Applied egg-rr99.9%
exp-1-e99.9%
Simplified99.9%
pow-flip99.9%
distribute-neg-frac299.9%
Applied egg-rr99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (/ 1.0 (exp (/ x s))))))
float code(float x, float s) {
return 1.0f / (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 + (1.0e0 / exp((x / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / exp(Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(1.0) / exp((x / s)))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{1}{e^{\frac{x}{s}}}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.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 (/ s x))
(if (<= t_0 4.999999840142846e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
(/ -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 + (s / x);
} else if (t_0 <= 4.999999840142846e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} 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) :: t_0
real(4) :: tmp
t_0 = x / -s
if (t_0 <= (-1.0e0)) then
tmp = 1.0e0 + (s / x)
else if (t_0 <= 4.999999840142846e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
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(s / x)); elseif (t_0 <= Float32(4.999999840142846e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / 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(-1.0)) tmp = single(1.0) + (s / x); elseif (t_0 <= single(4.999999840142846e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((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 -1:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 4.999999840142846 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.0%
Taylor expanded in x around inf 94.9%
mul-1-neg94.9%
unsub-neg94.9%
Simplified94.9%
sub-neg94.9%
distribute-frac-neg94.9%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod95.2%
add-sqr-sqrt95.2%
+-commutative95.2%
Applied egg-rr95.2%
if -1 < (/.f32 (neg.f32 x) s) < 4.99999984e37Initial program 99.7%
Taylor expanded in x around 0 45.9%
mul-1-neg45.9%
unsub-neg45.9%
Simplified45.9%
*-un-lft-identity45.9%
cancel-sign-sub-inv45.9%
metadata-eval45.9%
add-log-exp94.5%
pow-exp94.5%
flip-+39.6%
metadata-eval39.6%
pow-exp39.6%
add-log-exp39.6%
neg-mul-139.6%
pow-exp39.6%
add-log-exp40.1%
neg-mul-140.1%
distribute-neg-frac40.1%
distribute-neg-frac40.1%
pow-exp40.1%
Applied egg-rr79.9%
if 4.99999984e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
distribute-neg-frac2100.0%
Simplified100.0%
Final simplification87.7%
(FPCore (x s) :precision binary32 (if (<= x -2.0000000544904023e-27) (/ 1.0 (* x (/ (- (* x 0.5) s) (* s (* x -0.5))))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -2.0000000544904023e-27f) {
tmp = 1.0f / (x * (((x * 0.5f) - s) / (s * (x * -0.5f))));
} 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 <= (-2.0000000544904023e-27)) then
tmp = 1.0e0 / (x * (((x * 0.5e0) - s) / (s * (x * (-0.5e0)))))
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(-2.0000000544904023e-27)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(x * Float32(0.5)) - s) / Float32(s * Float32(x * Float32(-0.5)))))); 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(-2.0000000544904023e-27)) tmp = single(1.0) / (x * (((x * single(0.5)) - s) / (s * (x * single(-0.5))))); 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 -2.0000000544904023 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x \cdot 0.5 - s}{s \cdot \left(x \cdot -0.5\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -2.00000005e-27Initial program 99.7%
Taylor expanded in x around 0 37.6%
mul-1-neg37.6%
unsub-neg37.6%
Simplified37.6%
Taylor expanded in x around inf 37.5%
sub-neg37.5%
associate-*r/37.5%
metadata-eval37.5%
distribute-neg-frac37.5%
metadata-eval37.5%
Simplified37.5%
clear-num37.5%
clear-num37.5%
frac-add41.9%
*-un-lft-identity41.9%
div-inv41.9%
metadata-eval41.9%
div-inv41.9%
metadata-eval41.9%
div-inv41.9%
metadata-eval41.9%
div-inv41.9%
metadata-eval41.9%
Applied egg-rr41.9%
*-rgt-identity41.9%
+-commutative41.9%
*-commutative41.9%
mul-1-neg41.9%
unsub-neg41.9%
*-commutative41.9%
associate-*l*41.9%
*-commutative41.9%
associate-*l*41.9%
metadata-eval41.9%
Simplified41.9%
if -2.00000005e-27 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.2%
(FPCore (x s)
:precision binary32
(if (<= (- x) -9.999999682655225e-20)
(+ 1.0 (/ s x))
(if (<= (- x) 9.999999974752427e-7)
(+ 0.5 (* (/ x s) 0.25))
(/ 1.0 (* x (/ -1.0 s))))))
float code(float x, float s) {
float tmp;
if (-x <= -9.999999682655225e-20f) {
tmp = 1.0f + (s / x);
} else if (-x <= 9.999999974752427e-7f) {
tmp = 0.5f + ((x / s) * 0.25f);
} 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 <= (-9.999999682655225e-20)) then
tmp = 1.0e0 + (s / x)
else if (-x <= 9.999999974752427e-7) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
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(-9.999999682655225e-20)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999974752427e-7)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); 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 <= single(-9.999999682655225e-20)) tmp = single(1.0) + (s / x); elseif (-x <= single(9.999999974752427e-7)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(1.0) / (x * (single(-1.0) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -9.999999682655225 \cdot 10^{-20}:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -9.99999968e-20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
Taylor expanded in x around inf 86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
sub-neg86.9%
distribute-frac-neg86.9%
add-sqr-sqrt-0.0%
sqrt-unprod88.4%
sqr-neg88.4%
sqrt-unprod88.4%
add-sqr-sqrt88.4%
+-commutative88.4%
Applied egg-rr88.4%
if -9.99999968e-20 < (neg.f32 x) < 9.99999997e-7Initial program 99.5%
Taylor expanded in x around 0 62.0%
if 9.99999997e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 38.3%
mul-1-neg38.3%
unsub-neg38.3%
Simplified38.3%
Taylor expanded in x around inf 38.3%
sub-neg38.3%
associate-*r/38.3%
metadata-eval38.3%
distribute-neg-frac38.3%
metadata-eval38.3%
Simplified38.3%
Taylor expanded in x around inf 38.3%
Final simplification65.4%
(FPCore (x s)
:precision binary32
(if (<= (- x) -9.999999682655225e-20)
(+ 1.0 (/ s x))
(if (<= (- x) 9.999999974752427e-7)
(+ 0.5 (* (/ x s) 0.25))
(/ -1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -9.999999682655225e-20f) {
tmp = 1.0f + (s / x);
} else if (-x <= 9.999999974752427e-7f) {
tmp = 0.5f + ((x / s) * 0.25f);
} 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 <= (-9.999999682655225e-20)) then
tmp = 1.0e0 + (s / x)
else if (-x <= 9.999999974752427e-7) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-9.999999682655225e-20)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999974752427e-7)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); 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(-9.999999682655225e-20)) tmp = single(1.0) + (s / x); elseif (-x <= single(9.999999974752427e-7)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -9.999999682655225 \cdot 10^{-20}:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -9.99999968e-20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
Taylor expanded in x around inf 86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
sub-neg86.9%
distribute-frac-neg86.9%
add-sqr-sqrt-0.0%
sqrt-unprod88.4%
sqr-neg88.4%
sqrt-unprod88.4%
add-sqr-sqrt88.4%
+-commutative88.4%
Applied egg-rr88.4%
if -9.99999968e-20 < (neg.f32 x) < 9.99999997e-7Initial program 99.5%
Taylor expanded in x around 0 62.0%
if 9.99999997e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 38.3%
mul-1-neg38.3%
unsub-neg38.3%
Simplified38.3%
Taylor expanded in x around inf 38.3%
mul-1-neg38.3%
distribute-neg-frac238.3%
Simplified38.3%
Final simplification65.4%
(FPCore (x s) :precision binary32 (if (<= x -2.0000000544904023e-27) (/ 1.0 (* x (/ (+ x (* s 2.0)) (* x s)))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -2.0000000544904023e-27f) {
tmp = 1.0f / (x * ((x + (s * 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 <= (-2.0000000544904023e-27)) then
tmp = 1.0e0 / (x * ((x + (s * 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(-2.0000000544904023e-27)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(x + Float32(s * 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(-2.0000000544904023e-27)) tmp = single(1.0) / (x * ((x + (s * 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 -2.0000000544904023 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x + s \cdot 2}{x \cdot s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -2.00000005e-27Initial program 99.7%
Taylor expanded in x around 0 37.6%
mul-1-neg37.6%
unsub-neg37.6%
Simplified37.6%
Taylor expanded in x around inf 37.5%
sub-neg37.5%
associate-*r/37.5%
metadata-eval37.5%
distribute-neg-frac37.5%
metadata-eval37.5%
Simplified37.5%
+-commutative37.5%
frac-2neg37.5%
metadata-eval37.5%
frac-add42.1%
*-un-lft-identity42.1%
add-sqr-sqrt-0.0%
sqrt-unprod35.0%
sqr-neg35.0%
sqrt-unprod35.0%
add-sqr-sqrt35.0%
add-sqr-sqrt-0.0%
sqrt-unprod59.3%
sqr-neg59.3%
sqrt-unprod41.1%
add-sqr-sqrt41.2%
Applied egg-rr41.2%
if -2.00000005e-27 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.2%
Final simplification71.5%
(FPCore (x s) :precision binary32 (if (<= (- x) -2.99999994735501e-14) (+ 1.0 (/ s x)) (if (<= (- x) 9.999999974752427e-7) 0.5 (/ -1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -2.99999994735501e-14f) {
tmp = 1.0f + (s / x);
} else if (-x <= 9.999999974752427e-7f) {
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 <= (-2.99999994735501e-14)) then
tmp = 1.0e0 + (s / x)
else if (-x <= 9.999999974752427e-7) 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(-2.99999994735501e-14)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999974752427e-7)) 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(-2.99999994735501e-14)) tmp = single(1.0) + (s / x); elseif (-x <= single(9.999999974752427e-7)) 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 -2.99999994735501 \cdot 10^{-14}:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -2.99999995e-14Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
Taylor expanded in x around inf 92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
sub-neg92.2%
distribute-frac-neg92.2%
add-sqr-sqrt-0.0%
sqrt-unprod93.2%
sqr-neg93.2%
sqrt-unprod93.2%
add-sqr-sqrt93.2%
+-commutative93.2%
Applied egg-rr93.2%
if -2.99999995e-14 < (neg.f32 x) < 9.99999997e-7Initial program 99.5%
Taylor expanded in x around 0 57.6%
if 9.99999997e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 38.3%
mul-1-neg38.3%
unsub-neg38.3%
Simplified38.3%
Taylor expanded in x around inf 38.3%
mul-1-neg38.3%
distribute-neg-frac238.3%
Simplified38.3%
Final simplification64.4%
(FPCore (x s) :precision binary32 (if (<= (- x) -2.99999994735501e-14) (+ 1.0 (/ s x)) (if (<= (- x) 9.999999974752427e-7) 0.5 (/ s (- x)))))
float code(float x, float s) {
float tmp;
if (-x <= -2.99999994735501e-14f) {
tmp = 1.0f + (s / x);
} else if (-x <= 9.999999974752427e-7f) {
tmp = 0.5f;
} else {
tmp = 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 <= (-2.99999994735501e-14)) then
tmp = 1.0e0 + (s / x)
else if (-x <= 9.999999974752427e-7) then
tmp = 0.5e0
else
tmp = s / -x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-2.99999994735501e-14)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999974752427e-7)) tmp = Float32(0.5); else tmp = Float32(s / Float32(-x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-2.99999994735501e-14)) tmp = single(1.0) + (s / x); elseif (-x <= single(9.999999974752427e-7)) tmp = single(0.5); else tmp = s / -x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -2.99999994735501 \cdot 10^{-14}:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{-x}\\
\end{array}
\end{array}
if (neg.f32 x) < -2.99999995e-14Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
Taylor expanded in x around inf 92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
sub-neg92.2%
distribute-frac-neg92.2%
add-sqr-sqrt-0.0%
sqrt-unprod93.2%
sqr-neg93.2%
sqrt-unprod93.2%
add-sqr-sqrt93.2%
+-commutative93.2%
Applied egg-rr93.2%
if -2.99999995e-14 < (neg.f32 x) < 9.99999997e-7Initial program 99.5%
Taylor expanded in x around 0 57.6%
if 9.99999997e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 38.3%
mul-1-neg38.3%
unsub-neg38.3%
Simplified38.3%
Taylor expanded in x around inf 35.3%
mul-1-neg35.3%
distribute-neg-frac235.3%
Simplified35.3%
Final simplification63.5%
(FPCore (x s) :precision binary32 (if (<= x -1.6000000081769018e-37) (/ 1.0 (+ -1.0 (- 3.0 (/ x s)))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -1.6000000081769018e-37f) {
tmp = 1.0f / (-1.0f + (3.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 <= (-1.6000000081769018e-37)) then
tmp = 1.0e0 / ((-1.0e0) + (3.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(-1.6000000081769018e-37)) tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.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(-1.6000000081769018e-37)) tmp = single(1.0) / (single(-1.0) + (single(3.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 -1.6000000081769018 \cdot 10^{-37}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -1.60000001e-37Initial program 99.7%
Taylor expanded in x around 0 41.0%
mul-1-neg41.0%
unsub-neg41.0%
Simplified41.0%
expm1-log1p-u41.0%
expm1-undefine41.0%
Applied egg-rr41.0%
sub-neg41.0%
metadata-eval41.0%
+-commutative41.0%
log1p-undefine41.0%
rem-exp-log41.0%
associate-+r-41.0%
metadata-eval41.0%
Simplified41.0%
if -1.60000001e-37 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 94.3%
(FPCore (x s) :precision binary32 (if (<= x 4.9999998413276127e-20) (/ 1.0 (+ -1.0 (- 3.0 (/ x s)))) (+ 1.0 (/ s x))))
float code(float x, float s) {
float tmp;
if (x <= 4.9999998413276127e-20f) {
tmp = 1.0f / (-1.0f + (3.0f - (x / 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 <= 4.9999998413276127e-20) then
tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
else
tmp = 1.0e0 + (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(4.9999998413276127e-20)) tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / 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(4.9999998413276127e-20)) tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s))); else tmp = single(1.0) + (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.9999998413276127 \cdot 10^{-20}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{s}{x}\\
\end{array}
\end{array}
if x < 4.99999984e-20Initial program 99.7%
Taylor expanded in x around 0 49.0%
mul-1-neg49.0%
unsub-neg49.0%
Simplified49.0%
expm1-log1p-u48.8%
expm1-undefine48.8%
Applied egg-rr48.8%
sub-neg48.8%
metadata-eval48.8%
+-commutative48.8%
log1p-undefine48.8%
rem-exp-log48.9%
associate-+r-49.0%
metadata-eval49.0%
Simplified49.0%
if 4.99999984e-20 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
Taylor expanded in x around inf 86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
sub-neg86.9%
distribute-frac-neg86.9%
add-sqr-sqrt-0.0%
sqrt-unprod88.4%
sqr-neg88.4%
sqrt-unprod88.4%
add-sqr-sqrt88.4%
+-commutative88.4%
Applied egg-rr88.4%
Final simplification64.9%
(FPCore (x s) :precision binary32 (if (<= x 4.9999998413276127e-20) (/ 1.0 (- 2.0 (/ x s))) (+ 1.0 (/ s x))))
float code(float x, float s) {
float tmp;
if (x <= 4.9999998413276127e-20f) {
tmp = 1.0f / (2.0f - (x / 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 <= 4.9999998413276127e-20) then
tmp = 1.0e0 / (2.0e0 - (x / s))
else
tmp = 1.0e0 + (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(4.9999998413276127e-20)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / 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(4.9999998413276127e-20)) tmp = single(1.0) / (single(2.0) - (x / s)); else tmp = single(1.0) + (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.9999998413276127 \cdot 10^{-20}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{s}{x}\\
\end{array}
\end{array}
if x < 4.99999984e-20Initial program 99.7%
Taylor expanded in x around 0 49.0%
mul-1-neg49.0%
unsub-neg49.0%
Simplified49.0%
if 4.99999984e-20 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
Taylor expanded in x around inf 86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
sub-neg86.9%
distribute-frac-neg86.9%
add-sqr-sqrt-0.0%
sqrt-unprod88.4%
sqr-neg88.4%
sqrt-unprod88.4%
add-sqr-sqrt88.4%
+-commutative88.4%
Applied egg-rr88.4%
Final simplification64.9%
(FPCore (x s) :precision binary32 (if (<= (- x) 9.999999974752427e-7) 0.5 (/ s (- x))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999974752427e-7f) {
tmp = 0.5f;
} else {
tmp = 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 <= 9.999999974752427e-7) then
tmp = 0.5e0
else
tmp = s / -x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(9.999999974752427e-7)) tmp = Float32(0.5); else tmp = Float32(s / Float32(-x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(9.999999974752427e-7)) tmp = single(0.5); else tmp = s / -x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{-x}\\
\end{array}
\end{array}
if (neg.f32 x) < 9.99999997e-7Initial program 99.8%
Taylor expanded in x around 0 43.9%
if 9.99999997e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 38.3%
mul-1-neg38.3%
unsub-neg38.3%
Simplified38.3%
Taylor expanded in x around inf 35.3%
mul-1-neg35.3%
distribute-neg-frac235.3%
Simplified35.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 32.5%
herbie shell --seed 2024095
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))