
(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 18 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (/ x (- s)))))))
float code(float x, float s) {
return expf(-log1pf(expf((x / -s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(x / Float32(-s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{\frac{x}{-s}}\right)}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ -1.0 (+ (exp (/ x (- s))) 2.0))))
float code(float x, float s) {
return 1.0f / (-1.0f + (expf((x / -s)) + 2.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((-1.0e0) + (exp((x / -s)) + 2.0e0))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(exp(Float32(x / Float32(-s))) + Float32(2.0)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(-1.0) + (exp((x / -s)) + single(2.0))); end
\begin{array}{l}
\\
\frac{1}{-1 + \left(e^{\frac{x}{-s}} + 2\right)}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
inv-pow99.8%
pow-exp99.8%
*-commutative99.8%
pow-exp99.8%
expm1-log1p-u99.8%
expm1-undefine99.8%
pow-exp99.8%
*-commutative99.8%
pow-exp99.8%
inv-pow99.8%
rec-exp99.8%
distribute-neg-frac299.8%
Applied egg-rr99.8%
sub-neg99.8%
metadata-eval99.8%
+-commutative99.8%
log1p-undefine99.7%
rem-exp-log99.8%
associate-+r+99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(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.8%
Applied egg-rr99.8%
Final simplification99.8%
(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 -0.03999999910593033)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= t_0 4.999999840142846e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ 2.0 (/ x s))))
(/ 1.0 (* (/ x s) 3.0))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -0.03999999910593033f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (t_0 <= 4.999999840142846e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (2.0f + (x / s)));
} else {
tmp = 1.0f / ((x / s) * 3.0f);
}
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 <= (-0.03999999910593033e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (t_0 <= 4.999999840142846e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (2.0e0 + (x / s)))
else
tmp = 1.0e0 / ((x / s) * 3.0e0)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-0.03999999910593033)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); 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(2.0) + Float32(x / s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(x / s) * Float32(3.0))); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(-0.03999999910593033)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (t_0 <= single(4.999999840142846e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (single(2.0) + (x / s))); else tmp = single(1.0) / ((x / s) * single(3.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -0.03999999910593033:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;t\_0 \leq 4.999999840142846 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{2 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s} \cdot 3}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -0.0399999991Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 94.1%
+-commutative94.1%
Simplified94.1%
if -0.0399999991 < (/.f32 (neg.f32 x) s) < 4.99999984e37Initial program 99.7%
Taylor expanded in x around 0 54.5%
mul-1-neg54.5%
unsub-neg54.5%
Simplified54.5%
*-un-lft-identity54.5%
cancel-sign-sub-inv54.5%
metadata-eval54.5%
add-log-exp96.3%
pow-exp96.3%
flip-+49.3%
metadata-eval49.3%
pow-exp49.3%
add-log-exp49.3%
neg-mul-149.3%
pow-exp49.3%
add-log-exp50.0%
neg-mul-150.0%
distribute-neg-frac250.0%
distribute-neg-frac250.0%
pow-exp50.0%
Applied egg-rr75.1%
if 4.99999984e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 98.2%
mul-1-neg98.2%
unsub-neg98.2%
Simplified98.2%
Taylor expanded in x around inf 98.2%
associate-*r/98.2%
metadata-eval98.2%
Simplified98.2%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
distribute-frac-neg2-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
fma-define-0.0%
add-sqr-sqrt98.2%
Applied egg-rr100.0%
+-commutative100.0%
fma-undefine100.0%
*-rgt-identity100.0%
associate-+l+100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Final simplification86.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 20.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* x (/ (+ s (* x 0.5)) (* x (* s 0.5)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 20.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (x * ((s + (x * 0.5f)) / (x * (s * 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 / -s) <= 20.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (x * ((s + (x * 0.5e0)) / (x * (s * 0.5e0))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(20.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(s + Float32(x * Float32(0.5))) / Float32(x * Float32(s * Float32(0.5)))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(20.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (x * ((s + (x * single(0.5))) / (x * (s * single(0.5))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 20:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s + x \cdot 0.5}{x \cdot \left(s \cdot 0.5\right)}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 20Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 93.6%
+-commutative93.6%
Simplified93.6%
if 20 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 45.9%
mul-1-neg45.9%
unsub-neg45.9%
Simplified45.9%
Taylor expanded in x around inf 45.9%
associate-*r/45.9%
metadata-eval45.9%
Simplified45.9%
sub-neg45.9%
distribute-frac-neg245.9%
add-sqr-sqrt-0.0%
sqrt-unprod72.7%
sqr-neg72.7%
sqrt-unprod45.9%
add-sqr-sqrt45.9%
/-rgt-identity45.9%
clear-num45.9%
clear-num45.9%
frac-add53.7%
*-un-lft-identity53.7%
div-inv53.7%
metadata-eval53.7%
div-inv53.7%
metadata-eval53.7%
Applied egg-rr53.7%
*-rgt-identity53.7%
associate-*l*53.7%
*-commutative53.7%
Simplified53.7%
Final simplification78.7%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.019999999552965164) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.019999999552965164f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (x * (((s * 2.0f) - x) / (x * s)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= 0.019999999552965164e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (x * (((s * 2.0e0) - x) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(0.019999999552965164)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(0.019999999552965164)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (x * (((s * single(2.0)) - x) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 0.019999999552965164:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot 2 - x}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.0199999996Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 95.7%
+-commutative95.7%
Simplified95.7%
if 0.0199999996 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 45.3%
mul-1-neg45.3%
unsub-neg45.3%
Simplified45.3%
Taylor expanded in x around inf 45.3%
associate-*r/45.3%
metadata-eval45.3%
Simplified45.3%
frac-sub51.6%
div-inv57.7%
fma-neg57.7%
*-rgt-identity57.7%
Applied egg-rr57.7%
associate-*r/51.6%
*-rgt-identity51.6%
fma-undefine51.6%
*-commutative51.6%
unsub-neg51.6%
*-commutative51.6%
Simplified51.6%
Final simplification78.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / (-1.0f + (3.0f - (x / s)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= (-2.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-2.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-2.0)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -2:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
Taylor expanded in x around 0 5.1%
mul-1-neg5.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
associate-*r/5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 64.8%
mul-1-neg64.8%
unsub-neg64.8%
Simplified64.8%
expm1-log1p-u64.8%
Applied egg-rr64.8%
expm1-undefine64.8%
sub-neg64.8%
log1p-undefine64.8%
rem-exp-log64.8%
associate-+r-64.8%
metadata-eval64.8%
metadata-eval64.8%
Simplified64.8%
Final simplification51.4%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.999999999099794e-24) 0.5 (* s (/ x (* x (- (* s 2.0) x))))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999999099794e-24f) {
tmp = 0.5f;
} else {
tmp = s * (x / (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 <= 4.999999999099794e-24) then
tmp = 0.5e0
else
tmp = s * (x / (x * ((s * 2.0e0) - x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(4.999999999099794e-24)) tmp = Float32(0.5); else tmp = Float32(s * Float32(x / Float32(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(4.999999999099794e-24)) tmp = single(0.5); else tmp = s * (x / (x * ((s * single(2.0)) - x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 4.999999999099794 \cdot 10^{-24}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;s \cdot \frac{x}{x \cdot \left(s \cdot 2 - x\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 5e-24Initial program 99.8%
Taylor expanded in x around 0 50.5%
if 5e-24 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 50.3%
mul-1-neg50.3%
unsub-neg50.3%
Simplified50.3%
Taylor expanded in x around inf 50.3%
associate-*r/50.3%
metadata-eval50.3%
Simplified50.3%
associate-/r*46.0%
frac-sub49.4%
associate-/r/53.0%
fma-neg53.0%
*-rgt-identity53.0%
Applied egg-rr53.0%
associate-*r*51.4%
*-commutative51.4%
associate-/l/52.3%
associate-*l/53.3%
*-commutative53.3%
*-rgt-identity53.3%
*-commutative53.3%
fma-undefine53.3%
*-commutative53.3%
unsub-neg53.3%
*-commutative53.3%
Simplified53.3%
Final simplification51.6%
(FPCore (x s) :precision binary32 (if (<= (- x) 2.00000006274879e-22) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (* s (/ x (* x (- (* s 2.0) x))))))
float code(float x, float s) {
float tmp;
if (-x <= 2.00000006274879e-22f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = s * (x / (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 <= 2.00000006274879e-22) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = s * (x / (x * ((s * 2.0e0) - x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(2.00000006274879e-22)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(s * Float32(x / Float32(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(2.00000006274879e-22)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = s * (x / (x * ((s * single(2.0)) - x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 2.00000006274879 \cdot 10^{-22}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;s \cdot \frac{x}{x \cdot \left(s \cdot 2 - x\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 2.00000006e-22Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.6%
+-commutative93.6%
Simplified93.6%
if 2.00000006e-22 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 49.8%
mul-1-neg49.8%
unsub-neg49.8%
Simplified49.8%
Taylor expanded in x around inf 49.8%
associate-*r/49.8%
metadata-eval49.8%
Simplified49.8%
associate-/r*45.5%
frac-sub48.9%
associate-/r/52.6%
fma-neg52.6%
*-rgt-identity52.6%
Applied egg-rr52.6%
associate-*r*51.0%
*-commutative51.0%
associate-/l/51.9%
associate-*l/52.9%
*-commutative52.9%
*-rgt-identity52.9%
*-commutative52.9%
fma-undefine52.9%
*-commutative52.9%
unsub-neg52.9%
*-commutative52.9%
Simplified52.9%
Final simplification77.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 20.0) 0.5 (/ 1.0 (* (/ x s) 3.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 20.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((x / s) * 3.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) <= 20.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((x / s) * 3.0e0)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(20.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(x / s) * Float32(3.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(20.0)) tmp = single(0.5); else tmp = single(1.0) / ((x / s) * single(3.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 20:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s} \cdot 3}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 20Initial program 99.7%
Taylor expanded in x around 0 52.1%
if 20 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 45.9%
mul-1-neg45.9%
unsub-neg45.9%
Simplified45.9%
Taylor expanded in x around inf 45.9%
associate-*r/45.9%
metadata-eval45.9%
Simplified45.9%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
distribute-frac-neg2-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
fma-define-0.0%
add-sqr-sqrt45.9%
Applied egg-rr46.9%
+-commutative46.9%
fma-undefine46.9%
*-rgt-identity46.9%
associate-+l+46.9%
+-commutative46.9%
Simplified46.9%
Taylor expanded in x around inf 46.9%
Final simplification50.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 20.0) 0.5 (/ 1.0 (* x (/ 3.0 s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 20.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (x * (3.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) <= 20.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x * (3.0e0 / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(20.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(3.0) / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(20.0)) tmp = single(0.5); else tmp = single(1.0) / (x * (single(3.0) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 20:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{3}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 20Initial program 99.7%
Taylor expanded in x around 0 52.1%
if 20 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 45.9%
mul-1-neg45.9%
unsub-neg45.9%
Simplified45.9%
Taylor expanded in x around inf 45.9%
associate-*r/45.9%
metadata-eval45.9%
Simplified45.9%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
distribute-frac-neg2-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
fma-define-0.0%
add-sqr-sqrt45.9%
Applied egg-rr46.9%
+-commutative46.9%
fma-undefine46.9%
*-rgt-identity46.9%
associate-+l+46.9%
+-commutative46.9%
Simplified46.9%
Taylor expanded in s around 0 46.9%
Final simplification50.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2.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) <= (-2.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(-2.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(-2.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 -2:\\
\;\;\;\;\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) < -2Initial program 99.9%
Taylor expanded in x around 0 5.1%
mul-1-neg5.1%
unsub-neg5.1%
Simplified5.1%
Taylor expanded in x around inf 5.1%
associate-*r/5.1%
metadata-eval5.1%
Simplified5.1%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 64.8%
mul-1-neg64.8%
unsub-neg64.8%
Simplified64.8%
Final simplification51.3%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.0f) {
tmp = 0.5f;
} else {
tmp = -1.0f / (x / s);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= 2.0e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(2.0)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(2.0)) tmp = single(0.5); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.8%
Taylor expanded in x around 0 52.6%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 45.4%
mul-1-neg45.4%
unsub-neg45.4%
Simplified45.4%
Taylor expanded in x around inf 45.3%
mul-1-neg45.3%
distribute-frac-neg245.3%
Simplified45.3%
Final simplification49.8%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (* s (/ 0.3333333333333333 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
tmp = s * (0.3333333333333333f / 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.999999873689376e-5)) then
tmp = s * (0.3333333333333333e0 / x)
else
tmp = 0.5e0
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(0.3333333333333333) / x)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-5)) tmp = s * (single(0.3333333333333333) / x); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{0.3333333333333333}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 56.5%
mul-1-neg56.5%
unsub-neg56.5%
Simplified56.5%
Taylor expanded in x around inf 56.5%
associate-*r/56.5%
metadata-eval56.5%
Simplified56.5%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
distribute-frac-neg2-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
fma-define-0.0%
add-sqr-sqrt56.5%
Applied egg-rr57.7%
+-commutative57.7%
fma-undefine57.7%
*-rgt-identity57.7%
associate-+l+57.7%
+-commutative57.7%
Simplified57.7%
Taylor expanded in x around inf 51.6%
associate-*r/51.6%
*-commutative51.6%
associate-*r/51.6%
Simplified51.6%
if -4.99999987e-5 < x Initial program 99.7%
Taylor expanded in x around 0 46.8%
Final simplification48.2%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (* (/ s x) 0.3333333333333333) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
tmp = (s / x) * 0.3333333333333333f;
} 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.999999873689376e-5)) then
tmp = (s / x) * 0.3333333333333333e0
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999873689376e-5)) tmp = Float32(Float32(s / x) * Float32(0.3333333333333333)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-5)) tmp = (s / x) * single(0.3333333333333333); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{x} \cdot 0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 56.5%
mul-1-neg56.5%
unsub-neg56.5%
Simplified56.5%
Taylor expanded in x around inf 56.5%
associate-*r/56.5%
metadata-eval56.5%
Simplified56.5%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
distribute-frac-neg2-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod-0.0%
sqr-neg-0.0%
sqrt-unprod-0.0%
add-sqr-sqrt-0.0%
fma-define-0.0%
add-sqr-sqrt56.5%
Applied egg-rr57.7%
+-commutative57.7%
fma-undefine57.7%
*-rgt-identity57.7%
associate-+l+57.7%
+-commutative57.7%
Simplified57.7%
Taylor expanded in x around inf 51.6%
*-commutative51.6%
Simplified51.6%
if -4.99999987e-5 < x Initial program 99.7%
Taylor expanded in x around 0 46.8%
Final simplification48.2%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-5) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-5f) {
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.999999873689376e-5)) 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.999999873689376e-5)) 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(-4.999999873689376e-5)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999987e-5Initial program 100.0%
Taylor expanded in x around 0 56.5%
mul-1-neg56.5%
unsub-neg56.5%
Simplified56.5%
Taylor expanded in x around inf 50.4%
associate-*r/50.4%
neg-mul-150.4%
Simplified50.4%
if -4.99999987e-5 < x Initial program 99.7%
Taylor expanded in x around 0 46.8%
Final simplification47.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 35.1%
Final simplification35.1%
herbie shell --seed 2024080
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))