
(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 (+ (exp (/ x (- s))) 1.0)))
float code(float x, float s) {
return 1.0f / (expf((x / -s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (exp((x / -s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32(exp(Float32(x / Float32(-s))) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / (exp((x / -s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{e^{\frac{x}{-s}} + 1}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -2000.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 9.999999933815813e+36)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ 2.0 (/ x s))))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -2000.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= 9.999999933815813e+36f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / (2.0f + (x / s)));
} 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 <= (-2000.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else if (t_0 <= 9.999999933815813e+36) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / (2.0e0 + (x / s)))
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(-2000.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (t_0 <= Float32(9.999999933815813e+36)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x / Float32(s * Float32(s / x)))) / 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(-2000.0)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (t_0 <= single(9.999999933815813e+36)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / (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 -2000:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq 9.999999933815813 \cdot 10^{+36}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2e3Initial program 100.0%
Taylor expanded in x around 0 5.1%
neg-mul-15.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
sub-neg5.1%
associate-*r/5.1%
metadata-eval5.1%
distribute-neg-frac5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2e3 < (/.f32 (neg.f32 x) s) < 9.99999993e36Initial program 99.6%
Taylor expanded in x around 0 52.4%
neg-mul-152.4%
unsub-neg52.4%
Simplified52.4%
sub-neg52.4%
flip-+75.2%
metadata-eval75.2%
distribute-neg-frac275.2%
distribute-neg-frac275.2%
distribute-neg-frac275.2%
Applied egg-rr75.2%
distribute-frac-neg275.2%
distribute-frac-neg275.2%
sqr-neg75.2%
clear-num75.2%
frac-times80.0%
*-un-lft-identity80.0%
Applied egg-rr80.0%
if 9.99999993e36 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 93.1%
associate-*r/93.1%
neg-mul-193.1%
Simplified93.1%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod93.1%
add-sqr-sqrt93.1%
*-un-lft-identity93.1%
Applied egg-rr93.1%
*-lft-identity93.1%
Simplified93.1%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification66.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -2000.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 9.999999933815813e+36)
(/ 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 <= -2000.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= 9.999999933815813e+36f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (2.0f + (x / s)));
} 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 <= (-2000.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else if (t_0 <= 9.999999933815813e+36) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (2.0e0 + (x / s)))
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(-2000.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (t_0 <= Float32(9.999999933815813e+36)) 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(-2000.0)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (t_0 <= single(9.999999933815813e+36)) 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 -2000:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq 9.999999933815813 \cdot 10^{+36}:\\
\;\;\;\;\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) < -2e3Initial program 100.0%
Taylor expanded in x around 0 5.1%
neg-mul-15.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
sub-neg5.1%
associate-*r/5.1%
metadata-eval5.1%
distribute-neg-frac5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2e3 < (/.f32 (neg.f32 x) s) < 9.99999993e36Initial program 99.6%
Taylor expanded in x around 0 52.4%
neg-mul-152.4%
unsub-neg52.4%
Simplified52.4%
clear-num52.4%
associate-/r/52.4%
Applied egg-rr52.4%
associate-*l/52.4%
*-un-lft-identity52.4%
clear-num52.4%
Applied egg-rr52.4%
sub-neg52.4%
flip-+75.2%
metadata-eval75.2%
clear-num75.2%
clear-num75.2%
clear-num75.2%
Applied egg-rr75.2%
sqr-neg75.2%
sub-neg75.2%
remove-double-neg75.2%
Simplified75.2%
if 9.99999993e36 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 93.1%
associate-*r/93.1%
neg-mul-193.1%
Simplified93.1%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod93.1%
add-sqr-sqrt93.1%
*-un-lft-identity93.1%
Applied egg-rr93.1%
*-lft-identity93.1%
Simplified93.1%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification64.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.05000000074505806) (/ (/ 1.0 x) (/ 2.0 x)) (/ -1.0 (* x (* (/ 1.0 (* x s)) (- x (* s 2.0)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.05000000074505806f) {
tmp = (1.0f / x) / (2.0f / x);
} else {
tmp = -1.0f / (x * ((1.0f / (x * s)) * (x - (s * 2.0f))));
}
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.05000000074505806e0) then
tmp = (1.0e0 / x) / (2.0e0 / x)
else
tmp = (-1.0e0) / (x * ((1.0e0 / (x * s)) * (x - (s * 2.0e0))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(0.05000000074505806)) tmp = Float32(Float32(Float32(1.0) / x) / Float32(Float32(2.0) / x)); else tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(Float32(1.0) / Float32(x * s)) * Float32(x - Float32(s * Float32(2.0)))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(0.05000000074505806)) tmp = (single(1.0) / x) / (single(2.0) / x); else tmp = single(-1.0) / (x * ((single(1.0) / (x * s)) * (x - (s * single(2.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 0.05000000074505806:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \left(\frac{1}{x \cdot s} \cdot \left(x - s \cdot 2\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.0500000007Initial program 99.9%
Taylor expanded in x around 0 45.4%
neg-mul-145.4%
unsub-neg45.4%
Simplified45.4%
Taylor expanded in x around inf 45.2%
sub-neg45.2%
associate-*r/45.2%
metadata-eval45.2%
distribute-neg-frac45.2%
metadata-eval45.2%
Simplified45.2%
Taylor expanded in x around 0 54.9%
inv-pow54.9%
unpow-prod-down55.0%
inv-pow55.0%
Applied egg-rr55.0%
unpow-155.0%
associate-*r/55.1%
*-rgt-identity55.1%
Simplified55.1%
if 0.0500000007 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 43.8%
neg-mul-143.8%
unsub-neg43.8%
Simplified43.8%
Taylor expanded in x around inf 43.8%
sub-neg43.8%
associate-*r/43.8%
metadata-eval43.8%
distribute-neg-frac43.8%
metadata-eval43.8%
Simplified43.8%
frac-add53.1%
div-inv56.4%
fma-define56.4%
Applied egg-rr56.4%
*-commutative56.4%
neg-mul-156.4%
fmm-def56.4%
*-commutative56.4%
Simplified56.4%
Final simplification55.6%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.05000000074505806) (/ (/ 1.0 x) (/ 2.0 x)) (/ -1.0 (* x (/ (- x (* s 2.0)) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.05000000074505806f) {
tmp = (1.0f / x) / (2.0f / x);
} 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) <= 0.05000000074505806e0) then
tmp = (1.0e0 / x) / (2.0e0 / x)
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(0.05000000074505806)) tmp = Float32(Float32(Float32(1.0) / x) / Float32(Float32(2.0) / x)); 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(0.05000000074505806)) tmp = (single(1.0) / x) / (single(2.0) / x); 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 0.05000000074505806:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.0500000007Initial program 99.9%
Taylor expanded in x around 0 45.4%
neg-mul-145.4%
unsub-neg45.4%
Simplified45.4%
Taylor expanded in x around inf 45.2%
sub-neg45.2%
associate-*r/45.2%
metadata-eval45.2%
distribute-neg-frac45.2%
metadata-eval45.2%
Simplified45.2%
Taylor expanded in x around 0 54.9%
inv-pow54.9%
unpow-prod-down55.0%
inv-pow55.0%
Applied egg-rr55.0%
unpow-155.0%
associate-*r/55.1%
*-rgt-identity55.1%
Simplified55.1%
if 0.0500000007 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 43.8%
neg-mul-143.8%
unsub-neg43.8%
Simplified43.8%
Taylor expanded in x around inf 43.8%
sub-neg43.8%
associate-*r/43.8%
metadata-eval43.8%
distribute-neg-frac43.8%
metadata-eval43.8%
Simplified43.8%
frac-add53.1%
div-inv56.4%
fma-define56.4%
Applied egg-rr56.4%
*-commutative56.4%
neg-mul-156.4%
fmm-def56.4%
*-commutative56.4%
Simplified56.4%
un-div-inv53.1%
*-commutative53.1%
*-commutative53.1%
Applied egg-rr53.1%
Final simplification54.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 40.0) (/ (/ 1.0 x) (/ 2.0 x)) (/ 1.0 (* x (/ (+ x (* s 2.0)) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 40.0f) {
tmp = (1.0f / x) / (2.0f / x);
} 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) <= 40.0e0) then
tmp = (1.0e0 / x) / (2.0e0 / x)
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(40.0)) tmp = Float32(Float32(Float32(1.0) / x) / Float32(Float32(2.0) / x)); 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(40.0)) tmp = (single(1.0) / x) / (single(2.0) / x); 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 40:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x + s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 40Initial program 99.8%
Taylor expanded in x around 0 45.0%
neg-mul-145.0%
unsub-neg45.0%
Simplified45.0%
Taylor expanded in x around inf 44.9%
sub-neg44.9%
associate-*r/44.9%
metadata-eval44.9%
distribute-neg-frac44.9%
metadata-eval44.9%
Simplified44.9%
Taylor expanded in x around 0 54.3%
inv-pow54.3%
unpow-prod-down54.4%
inv-pow54.4%
Applied egg-rr54.4%
unpow-154.4%
associate-*r/54.4%
*-rgt-identity54.4%
Simplified54.4%
if 40 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 44.3%
neg-mul-144.3%
unsub-neg44.3%
Simplified44.3%
Taylor expanded in x around inf 44.3%
sub-neg44.3%
associate-*r/44.3%
metadata-eval44.3%
distribute-neg-frac44.3%
metadata-eval44.3%
Simplified44.3%
+-commutative44.3%
clear-num44.3%
frac-add53.9%
*-un-lft-identity53.9%
frac-2neg53.9%
metadata-eval53.9%
add-sqr-sqrt-0.0%
sqrt-unprod53.9%
sqr-neg53.9%
sqrt-unprod53.9%
add-sqr-sqrt53.9%
/-rgt-identity53.9%
frac-2neg53.9%
metadata-eval53.9%
add-sqr-sqrt-0.0%
sqrt-unprod67.1%
sqr-neg67.1%
sqrt-unprod53.9%
add-sqr-sqrt53.9%
/-rgt-identity53.9%
Applied egg-rr53.9%
Final simplification54.2%
(FPCore (x s) :precision binary32 (if (<= (- x) 1.9999999996399175e-23) (/ (/ 1.0 x) (/ 2.0 x)) (/ 1.0 (/ (* x (- (* s 2.0) x)) (* x s)))))
float code(float x, float s) {
float tmp;
if (-x <= 1.9999999996399175e-23f) {
tmp = (1.0f / x) / (2.0f / x);
} 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 <= 1.9999999996399175e-23) then
tmp = (1.0e0 / x) / (2.0e0 / x)
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(1.9999999996399175e-23)) tmp = Float32(Float32(Float32(1.0) / x) / Float32(Float32(2.0) / x)); else tmp = Float32(Float32(1.0) / Float32(Float32(x * 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 <= single(1.9999999996399175e-23)) tmp = (single(1.0) / x) / (single(2.0) / x); 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}\;-x \leq 1.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(s \cdot 2 - x\right)}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 2e-23Initial program 99.9%
Taylor expanded in x around 0 41.1%
neg-mul-141.1%
unsub-neg41.1%
Simplified41.1%
Taylor expanded in x around inf 41.0%
sub-neg41.0%
associate-*r/41.0%
metadata-eval41.0%
distribute-neg-frac41.0%
metadata-eval41.0%
Simplified41.0%
Taylor expanded in x around 0 52.1%
inv-pow52.1%
unpow-prod-down52.2%
inv-pow52.2%
Applied egg-rr52.2%
unpow-152.2%
associate-*r/52.3%
*-rgt-identity52.3%
Simplified52.3%
if 2e-23 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 49.2%
neg-mul-149.2%
unsub-neg49.2%
Simplified49.2%
Taylor expanded in x around inf 49.2%
sub-neg49.2%
associate-*r/49.2%
metadata-eval49.2%
distribute-neg-frac49.2%
metadata-eval49.2%
Simplified49.2%
frac-add55.3%
div-inv57.2%
fma-define57.2%
Applied egg-rr57.2%
*-commutative57.2%
neg-mul-157.2%
fmm-def57.2%
*-commutative57.2%
Simplified57.2%
*-commutative57.2%
un-div-inv55.3%
associate-*l/59.0%
*-commutative59.0%
*-commutative59.0%
Applied egg-rr59.0%
Final simplification55.2%
(FPCore (x s) :precision binary32 (if (<= (- x) 1.4999999523982838e-21) (/ (/ 1.0 x) (/ 2.0 x)) (* (* x s) (/ (/ 1.0 x) (- (* s 2.0) x)))))
float code(float x, float s) {
float tmp;
if (-x <= 1.4999999523982838e-21f) {
tmp = (1.0f / x) / (2.0f / x);
} else {
tmp = (x * s) * ((1.0f / x) / ((s * 2.0f) - x));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= 1.4999999523982838e-21) then
tmp = (1.0e0 / x) / (2.0e0 / x)
else
tmp = (x * s) * ((1.0e0 / x) / ((s * 2.0e0) - x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(1.4999999523982838e-21)) tmp = Float32(Float32(Float32(1.0) / x) / Float32(Float32(2.0) / x)); else tmp = Float32(Float32(x * s) * Float32(Float32(Float32(1.0) / x) / Float32(Float32(s * Float32(2.0)) - x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(1.4999999523982838e-21)) tmp = (single(1.0) / x) / (single(2.0) / x); else tmp = (x * s) * ((single(1.0) / x) / ((s * single(2.0)) - x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 1.4999999523982838 \cdot 10^{-21}:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot s\right) \cdot \frac{\frac{1}{x}}{s \cdot 2 - x}\\
\end{array}
\end{array}
if (neg.f32 x) < 1.5e-21Initial program 99.8%
Taylor expanded in x around 0 42.1%
neg-mul-142.1%
unsub-neg42.1%
Simplified42.1%
Taylor expanded in x around inf 42.0%
sub-neg42.0%
associate-*r/42.0%
metadata-eval42.0%
distribute-neg-frac42.0%
metadata-eval42.0%
Simplified42.0%
Taylor expanded in x around 0 51.9%
inv-pow51.9%
unpow-prod-down52.0%
inv-pow52.0%
Applied egg-rr52.0%
unpow-152.0%
associate-*r/52.0%
*-rgt-identity52.0%
Simplified52.0%
if 1.5e-21 < (neg.f32 x) Initial program 99.7%
Taylor expanded in x around 0 48.3%
neg-mul-148.3%
unsub-neg48.3%
Simplified48.3%
Taylor expanded in x around inf 48.3%
sub-neg48.3%
associate-*r/48.3%
metadata-eval48.3%
distribute-neg-frac48.3%
metadata-eval48.3%
Simplified48.3%
frac-add54.2%
div-inv57.4%
fma-define57.4%
Applied egg-rr57.4%
*-commutative57.4%
neg-mul-157.4%
fmm-def57.4%
*-commutative57.4%
Simplified57.4%
associate-/r*54.9%
*-un-lft-identity54.9%
*-commutative54.9%
times-frac56.5%
clear-num53.3%
/-rgt-identity53.3%
*-commutative53.3%
*-commutative53.3%
Applied egg-rr53.3%
Final simplification52.6%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2000.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (+ (- 3.0 (/ x s)) -1.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2000.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / ((3.0f - (x / s)) + -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 / -s) <= (-2000.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / ((3.0e0 - (x / s)) + (-1.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-2000.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(3.0) - Float32(x / s)) + Float32(-1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-2000.0)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / ((single(3.0) - (x / s)) + single(-1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -2000:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(3 - \frac{x}{s}\right) + -1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2e3Initial program 100.0%
Taylor expanded in x around 0 5.1%
neg-mul-15.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
sub-neg5.1%
associate-*r/5.1%
metadata-eval5.1%
distribute-neg-frac5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2e3 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 63.4%
neg-mul-163.4%
unsub-neg63.4%
Simplified63.4%
expm1-log1p-u63.3%
Applied egg-rr63.3%
expm1-undefine63.3%
sub-neg63.3%
log1p-undefine63.2%
rem-exp-log63.4%
associate-+r-63.4%
metadata-eval63.4%
metadata-eval63.4%
Simplified63.4%
Final simplification52.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2000.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2000.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) <= (-2000.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(-2000.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(-2000.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 -2000:\\
\;\;\;\;\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) < -2e3Initial program 100.0%
Taylor expanded in x around 0 5.1%
neg-mul-15.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
sub-neg5.1%
associate-*r/5.1%
metadata-eval5.1%
distribute-neg-frac5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2e3 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 63.4%
neg-mul-163.4%
unsub-neg63.4%
Simplified63.4%
Final simplification52.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.4000000059604645) 0.5 (/ -1.0 (* x (/ 1.0 s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.4000000059604645f) {
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) <= 0.4000000059604645e0) 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(0.4000000059604645)) 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(0.4000000059604645)) 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 0.4000000059604645:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.400000006Initial program 99.9%
Taylor expanded in x around 0 54.9%
if 0.400000006 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 43.8%
neg-mul-143.8%
unsub-neg43.8%
Simplified43.8%
Taylor expanded in x around inf 43.8%
sub-neg43.8%
associate-*r/43.8%
metadata-eval43.8%
distribute-neg-frac43.8%
metadata-eval43.8%
Simplified43.8%
Taylor expanded in x around inf 43.8%
Final simplification50.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.4000000059604645) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.4000000059604645f) {
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.4000000059604645e0) 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.4000000059604645)) 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.4000000059604645)) 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.4000000059604645:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.400000006Initial program 99.9%
Taylor expanded in x around 0 54.9%
if 0.400000006 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 43.8%
neg-mul-143.8%
unsub-neg43.8%
Simplified43.8%
Taylor expanded in x around inf 43.8%
associate-*r/43.8%
neg-mul-143.8%
Simplified43.8%
Final simplification50.2%
(FPCore (x s) :precision binary32 (if (<= (- x) 1.199999957179898e-7) 0.5 (/ 1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 1.199999957179898e-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 <= 1.199999957179898e-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(1.199999957179898e-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(1.199999957179898e-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 1.199999957179898 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 1.19999996e-7Initial program 99.7%
Taylor expanded in x around 0 47.9%
if 1.19999996e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 54.8%
neg-mul-154.8%
unsub-neg54.8%
Simplified54.8%
Taylor expanded in x around inf 51.2%
associate-*r/51.2%
neg-mul-151.2%
Simplified51.2%
add-sqr-sqrt-0.0%
sqrt-unprod67.1%
sqr-neg67.1%
sqrt-unprod50.9%
add-sqr-sqrt50.9%
*-un-lft-identity50.9%
Applied egg-rr50.9%
*-lft-identity50.9%
Simplified50.9%
clear-num54.3%
inv-pow54.3%
Applied egg-rr54.3%
unpow-154.3%
Simplified54.3%
(FPCore (x s) :precision binary32 (if (<= x -4.999999969612645e-9) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999969612645e-9f) {
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 <= (-4.999999969612645e-9)) 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(-4.999999969612645e-9)) 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(-4.999999969612645e-9)) tmp = -s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999997e-9Initial program 99.8%
Taylor expanded in x around 0 52.2%
neg-mul-152.2%
unsub-neg52.2%
Simplified52.2%
Taylor expanded in x around inf 48.8%
associate-*r/48.8%
neg-mul-148.8%
Simplified48.8%
if -4.99999997e-9 < x Initial program 99.8%
Taylor expanded in x around 0 49.1%
(FPCore (x s) :precision binary32 (if (<= x -1.199999957179898e-7) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.199999957179898e-7f) {
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.199999957179898e-7)) 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.199999957179898e-7)) 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(-1.199999957179898e-7)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.199999957179898 \cdot 10^{-7}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.19999996e-7Initial program 100.0%
Taylor expanded in x around 0 54.8%
neg-mul-154.8%
unsub-neg54.8%
Simplified54.8%
Taylor expanded in x around inf 51.2%
associate-*r/51.2%
neg-mul-151.2%
Simplified51.2%
add-sqr-sqrt-0.0%
sqrt-unprod67.1%
sqr-neg67.1%
sqrt-unprod50.9%
add-sqr-sqrt50.9%
*-un-lft-identity50.9%
Applied egg-rr50.9%
*-lft-identity50.9%
Simplified50.9%
if -1.19999996e-7 < x Initial program 99.7%
Taylor expanded in x around 0 47.9%
(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 34.5%
herbie shell --seed 2024172
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))