
(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 19 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (- (/ x s)))))))
float code(float x, float s) {
return expf(-log1pf(expf(-(x / s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(-Float32(x / s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}
\end{array}
Initial program 99.8%
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
log-powN/A
inv-powN/A
lift-/.f32N/A
lower-exp.f32N/A
lift-/.f32N/A
log-recN/A
lower-neg.f32N/A
lift-+.f32N/A
lower-log1p.f3299.8
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow (exp -2.0) (/ x (* s 2.0))))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-2.0f), (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((-2.0e0)) ** (x / (s * 2.0e0))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-2.0)) ^ Float32(x / Float32(s * Float32(2.0)))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-2.0)) ^ (x / (s * single(2.0))))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-2}\right)}^{\left(\frac{x}{s \cdot 2}\right)}}
\end{array}
Initial program 99.8%
distribute-frac-negN/A
neg-mul-1N/A
exp-prodN/A
lower-pow.f32N/A
lower-exp.f32N/A
lower-/.f3299.7
Applied egg-rr99.7%
lift-exp.f32N/A
lift-/.f32N/A
sqr-powN/A
pow-prod-downN/A
lower-pow.f32N/A
lift-exp.f32N/A
lift-exp.f32N/A
prod-expN/A
metadata-evalN/A
metadata-evalN/A
lower-exp.f32N/A
metadata-evalN/A
lift-/.f32N/A
associate-/l/N/A
lower-/.f32N/A
lower-*.f3299.8
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(if (<= (/ 1.0 (+ (exp (- (/ x s))) 1.0)) 0.0)
(/
1.0
(fma x (/ (* x (fma 0.5 s (* x -0.16666666666666666))) (* s (* s s))) 2.0))
0.5))
float code(float x, float s) {
float tmp;
if ((1.0f / (expf(-(x / s)) + 1.0f)) <= 0.0f) {
tmp = 1.0f / fmaf(x, ((x * fmaf(0.5f, s, (x * -0.16666666666666666f))) / (s * (s * s))), 2.0f);
} else {
tmp = 0.5f;
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(1.0) / Float32(exp(Float32(-Float32(x / s))) + Float32(1.0))) <= Float32(0.0)) tmp = Float32(Float32(1.0) / fma(x, Float32(Float32(x * fma(Float32(0.5), s, Float32(x * Float32(-0.16666666666666666)))) / Float32(s * Float32(s * s))), Float32(2.0))); else tmp = Float32(0.5); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{e^{-\frac{x}{s}} + 1} \leq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{x \cdot \mathsf{fma}\left(0.5, s, x \cdot -0.16666666666666666\right)}{s \cdot \left(s \cdot s\right)}, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 x) s)))) < 0.0Initial program 100.0%
lift-neg.f32N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
lower-/.f32N/A
lift-neg.f32N/A
distribute-frac-neg2N/A
remove-double-negN/A
lower-/.f32100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f32N/A
Simplified95.8%
Taylor expanded in s around 0
lower-/.f32N/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3292.3
Simplified92.3%
if 0.0 < (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 x) s)))) Initial program 99.7%
Taylor expanded in x around 0
Simplified52.2%
Final simplification65.8%
(FPCore (x s) :precision binary32 (if (<= (/ 1.0 (+ (exp (- (/ x s))) 1.0)) 0.0) (/ 1.0 (fma x (/ (* -0.16666666666666666 (* x x)) (* s (* s s))) 2.0)) 0.5))
float code(float x, float s) {
float tmp;
if ((1.0f / (expf(-(x / s)) + 1.0f)) <= 0.0f) {
tmp = 1.0f / fmaf(x, ((-0.16666666666666666f * (x * x)) / (s * (s * s))), 2.0f);
} else {
tmp = 0.5f;
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(1.0) / Float32(exp(Float32(-Float32(x / s))) + Float32(1.0))) <= Float32(0.0)) tmp = Float32(Float32(1.0) / fma(x, Float32(Float32(Float32(-0.16666666666666666) * Float32(x * x)) / Float32(s * Float32(s * s))), Float32(2.0))); else tmp = Float32(0.5); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{e^{-\frac{x}{s}} + 1} \leq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{-0.16666666666666666 \cdot \left(x \cdot x\right)}{s \cdot \left(s \cdot s\right)}, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 x) s)))) < 0.0Initial program 100.0%
lift-neg.f32N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
lower-/.f32N/A
lift-neg.f32N/A
distribute-frac-neg2N/A
remove-double-negN/A
lower-/.f32100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f32N/A
Simplified95.8%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3292.3
Simplified92.3%
if 0.0 < (/.f32 #s(literal 1 binary32) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 x) s)))) Initial program 99.7%
Taylor expanded in x around 0
Simplified52.2%
Final simplification65.8%
(FPCore (x s) :precision binary32 (if (<= (exp (- (/ x s))) 9.999999848243207e+30) 0.5 (/ (* s (* s 2.0)) (* x x))))
float code(float x, float s) {
float tmp;
if (expf(-(x / s)) <= 9.999999848243207e+30f) {
tmp = 0.5f;
} else {
tmp = (s * (s * 2.0f)) / (x * x);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (exp(-(x / s)) <= 9.999999848243207e+30) then
tmp = 0.5e0
else
tmp = (s * (s * 2.0e0)) / (x * x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (exp(Float32(-Float32(x / s))) <= Float32(9.999999848243207e+30)) tmp = Float32(0.5); else tmp = Float32(Float32(s * Float32(s * Float32(2.0))) / Float32(x * x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (exp(-(x / s)) <= single(9.999999848243207e+30)) tmp = single(0.5); else tmp = (s * (s * single(2.0))) / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-\frac{x}{s}} \leq 9.999999848243207 \cdot 10^{+30}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s \cdot \left(s \cdot 2\right)}{x \cdot x}\\
\end{array}
\end{array}
if (exp.f32 (/.f32 (neg.f32 x) s)) < 9.99999985e30Initial program 99.7%
Taylor expanded in x around 0
Simplified52.2%
if 9.99999985e30 < (exp.f32 (/.f32 (neg.f32 x) s)) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified67.2%
Taylor expanded in s around 0
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
unpow2N/A
lower-*.f3279.6
Simplified79.6%
lift-*.f32N/A
lift-neg.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
lift-/.f32N/A
/-rgt-identityN/A
clear-numN/A
lift-/.f32N/A
clear-numN/A
lift-*.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
times-fracN/A
Applied egg-rr66.1%
Taylor expanded in s around 0
associate-*r/N/A
lower-/.f32N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f3278.5
Simplified78.5%
Final simplification61.1%
(FPCore (x s) :precision binary32 (if (<= (exp (- (/ x s))) 9.999999848243207e+30) 0.5 (/ (* 2.0 (* s s)) (* x x))))
float code(float x, float s) {
float tmp;
if (expf(-(x / s)) <= 9.999999848243207e+30f) {
tmp = 0.5f;
} else {
tmp = (2.0f * (s * s)) / (x * x);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (exp(-(x / s)) <= 9.999999848243207e+30) then
tmp = 0.5e0
else
tmp = (2.0e0 * (s * s)) / (x * x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (exp(Float32(-Float32(x / s))) <= Float32(9.999999848243207e+30)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(2.0) * Float32(s * s)) / Float32(x * x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (exp(-(x / s)) <= single(9.999999848243207e+30)) tmp = single(0.5); else tmp = (single(2.0) * (s * s)) / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-\frac{x}{s}} \leq 9.999999848243207 \cdot 10^{+30}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \left(s \cdot s\right)}{x \cdot x}\\
\end{array}
\end{array}
if (exp.f32 (/.f32 (neg.f32 x) s)) < 9.99999985e30Initial program 99.7%
Taylor expanded in x around 0
Simplified52.2%
if 9.99999985e30 < (exp.f32 (/.f32 (neg.f32 x) s)) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified67.2%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3278.5
Simplified78.5%
Final simplification61.1%
(FPCore (x s) :precision binary32 (if (<= (exp (- (/ x s))) 4.0) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (expf(-(x / s)) <= 4.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 (exp(-(x / s)) <= 4.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 (exp(Float32(-Float32(x / s))) <= Float32(4.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 (exp(-(x / s)) <= single(4.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}\;e^{-\frac{x}{s}} \leq 4:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (exp.f32 (/.f32 (neg.f32 x) s)) < 4Initial program 99.9%
Taylor expanded in x around 0
Simplified53.8%
if 4 < (exp.f32 (/.f32 (neg.f32 x) s)) Initial program 99.6%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified63.5%
Taylor expanded in s around 0
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
unpow2N/A
lower-*.f3274.5
Simplified74.5%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f32N/A
mul-1-negN/A
lower-neg.f3230.1
Simplified30.1%
distribute-frac-neg2N/A
clear-numN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f32N/A
lower-/.f3233.1
Applied egg-rr33.1%
Final simplification46.2%
(FPCore (x s) :precision binary32 (if (<= (exp (- (/ x s))) 4.0) 0.5 (- (/ s x))))
float code(float x, float s) {
float tmp;
if (expf(-(x / s)) <= 4.0f) {
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 (exp(-(x / s)) <= 4.0e0) then
tmp = 0.5e0
else
tmp = -(s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (exp(Float32(-Float32(x / s))) <= Float32(4.0)) tmp = Float32(0.5); else tmp = Float32(-Float32(s / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (exp(-(x / s)) <= single(4.0)) tmp = single(0.5); else tmp = -(s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-\frac{x}{s}} \leq 4:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;-\frac{s}{x}\\
\end{array}
\end{array}
if (exp.f32 (/.f32 (neg.f32 x) s)) < 4Initial program 99.9%
Taylor expanded in x around 0
Simplified53.8%
if 4 < (exp.f32 (/.f32 (neg.f32 x) s)) Initial program 99.6%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified63.5%
Taylor expanded in s around 0
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
unpow2N/A
lower-*.f3274.5
Simplified74.5%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f32N/A
mul-1-negN/A
lower-neg.f3230.1
Simplified30.1%
Final simplification45.1%
(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(-Float32(x / 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
(if (<= (- (/ x s)) 5.0)
0.5
(/
1.0
(fma
x
(fma
x
(fma -0.16666666666666666 (/ x (* s (* s s))) (/ 0.5 (* s s)))
(/ -1.0 s))
2.0))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 5.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / fmaf(x, fmaf(x, fmaf(-0.16666666666666666f, (x / (s * (s * s))), (0.5f / (s * s))), (-1.0f / s)), 2.0f);
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(5.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / fma(x, fma(x, fma(Float32(-0.16666666666666666), Float32(x / Float32(s * Float32(s * s))), Float32(Float32(0.5) / Float32(s * s))), Float32(Float32(-1.0) / s)), Float32(2.0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(-0.16666666666666666, \frac{x}{s \cdot \left(s \cdot s\right)}, \frac{0.5}{s \cdot s}\right), \frac{-1}{s}\right), 2\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 5Initial program 99.9%
Taylor expanded in x around 0
Simplified53.4%
if 5 < (/.f32 (neg.f32 x) s) Initial program 99.6%
lift-neg.f32N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
lower-/.f32N/A
lift-neg.f32N/A
distribute-frac-neg2N/A
remove-double-negN/A
lower-/.f3299.5
Applied egg-rr99.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f32N/A
Simplified91.3%
Final simplification67.0%
(FPCore (x s)
:precision binary32
(if (<= (- (/ x s)) 100.0)
0.5
(/
1.0
(fma
x
(/ (fma s (- (* x 0.5) s) (* -0.16666666666666666 (* x x))) (* s (* s s)))
2.0))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 100.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / fmaf(x, (fmaf(s, ((x * 0.5f) - s), (-0.16666666666666666f * (x * x))) / (s * (s * s))), 2.0f);
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(100.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / fma(x, Float32(fma(s, Float32(Float32(x * Float32(0.5)) - s), Float32(Float32(-0.16666666666666666) * Float32(x * x))) / Float32(s * Float32(s * s))), Float32(2.0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 100:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{\mathsf{fma}\left(s, x \cdot 0.5 - s, -0.16666666666666666 \cdot \left(x \cdot x\right)\right)}{s \cdot \left(s \cdot s\right)}, 2\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 100Initial program 99.7%
Taylor expanded in x around 0
Simplified52.2%
if 100 < (/.f32 (neg.f32 x) s) Initial program 100.0%
lift-neg.f32N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
lower-/.f32N/A
lift-neg.f32N/A
distribute-frac-neg2N/A
remove-double-negN/A
lower-/.f32100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f32N/A
Simplified95.8%
Taylor expanded in s around 0
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3292.3
Simplified92.3%
Final simplification65.8%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 100.0) 0.5 (* (/ (* s s) (* x x)) (/ s (fma x -0.16666666666666666 (* s 0.5))))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 100.0f) {
tmp = 0.5f;
} else {
tmp = ((s * s) / (x * x)) * (s / fmaf(x, -0.16666666666666666f, (s * 0.5f)));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(100.0)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(s * s) / Float32(x * x)) * Float32(s / fma(x, Float32(-0.16666666666666666), Float32(s * Float32(0.5))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 100:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s \cdot s}{x \cdot x} \cdot \frac{s}{\mathsf{fma}\left(x, -0.16666666666666666, s \cdot 0.5\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 100Initial program 99.7%
Taylor expanded in x around 0
Simplified52.2%
if 100 < (/.f32 (neg.f32 x) s) Initial program 100.0%
lift-neg.f32N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
lower-/.f32N/A
lift-neg.f32N/A
distribute-frac-neg2N/A
remove-double-negN/A
lower-/.f32100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f32N/A
Simplified95.8%
Taylor expanded in s around 0
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-/.f32N/A
cube-multN/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3279.7
Simplified79.7%
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
clear-numN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
lower-/.f3287.0
Applied egg-rr87.0%
Final simplification64.0%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 100.0) 0.5 (* (/ (* s s) x) (/ s (* x (fma x -0.16666666666666666 (* s 0.5)))))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 100.0f) {
tmp = 0.5f;
} else {
tmp = ((s * s) / x) * (s / (x * fmaf(x, -0.16666666666666666f, (s * 0.5f))));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(100.0)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(s * s) / x) * Float32(s / Float32(x * fma(x, Float32(-0.16666666666666666), Float32(s * Float32(0.5)))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 100:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s \cdot s}{x} \cdot \frac{s}{x \cdot \mathsf{fma}\left(x, -0.16666666666666666, s \cdot 0.5\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 100Initial program 99.7%
Taylor expanded in x around 0
Simplified52.2%
if 100 < (/.f32 (neg.f32 x) s) Initial program 100.0%
lift-neg.f32N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
lower-/.f32N/A
lift-neg.f32N/A
distribute-frac-neg2N/A
remove-double-negN/A
lower-/.f32100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f32N/A
Simplified95.8%
Taylor expanded in s around 0
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-/.f32N/A
cube-multN/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3279.7
Simplified79.7%
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
clear-numN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
times-fracN/A
Applied egg-rr87.0%
Final simplification64.0%
(FPCore (x s)
:precision binary32
(if (<= (- x) -5.00000011871114e-34)
0.5
(if (<= (- x) 5.000000018137469e-16)
(/ 1.0 (fma x (/ (fma (/ x s) 0.5 -1.0) s) 2.0))
(/ (* (* s (* s s)) -6.0) (* x (* x x))))))
float code(float x, float s) {
float tmp;
if (-x <= -5.00000011871114e-34f) {
tmp = 0.5f;
} else if (-x <= 5.000000018137469e-16f) {
tmp = 1.0f / fmaf(x, (fmaf((x / s), 0.5f, -1.0f) / s), 2.0f);
} else {
tmp = ((s * (s * s)) * -6.0f) / (x * (x * x));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-5.00000011871114e-34)) tmp = Float32(0.5); elseif (Float32(-x) <= Float32(5.000000018137469e-16)) tmp = Float32(Float32(1.0) / fma(x, Float32(fma(Float32(x / s), Float32(0.5), Float32(-1.0)) / s), Float32(2.0))); else tmp = Float32(Float32(Float32(s * Float32(s * s)) * Float32(-6.0)) / Float32(x * Float32(x * x))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -5.00000011871114 \cdot 10^{-34}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;-x \leq 5.000000018137469 \cdot 10^{-16}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{\mathsf{fma}\left(\frac{x}{s}, 0.5, -1\right)}{s}, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(s \cdot \left(s \cdot s\right)\right) \cdot -6}{x \cdot \left(x \cdot x\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < -5.00000012e-34Initial program 100.0%
Taylor expanded in x around 0
Simplified39.0%
if -5.00000012e-34 < (neg.f32 x) < 5.00000002e-16Initial program 99.4%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified74.5%
lift-/.f32N/A
lift-fma.f32N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f32N/A
lower-/.f3286.2
lift-fma.f32N/A
*-commutativeN/A
lower-fma.f3286.2
Applied egg-rr86.2%
if 5.00000002e-16 < (neg.f32 x) Initial program 99.8%
lift-neg.f32N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
lower-/.f32N/A
lift-neg.f32N/A
distribute-frac-neg2N/A
remove-double-negN/A
lower-/.f3299.7
Applied egg-rr99.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f32N/A
Simplified92.2%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f32N/A
*-commutativeN/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3291.8
Simplified91.8%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 25.0) 0.5 (/ 1.0 (* 0.5 (* x (/ x (* s s)))))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 25.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (0.5f * (x * (x / (s * 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) <= 25.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (0.5e0 * (x * (x / (s * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(25.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(0.5) * Float32(x * Float32(x / Float32(s * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(25.0)) tmp = single(0.5); else tmp = single(1.0) / (single(0.5) * (x * (x / (s * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 25:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{0.5 \cdot \left(x \cdot \frac{x}{s \cdot s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 25Initial program 99.8%
Taylor expanded in x around 0
Simplified52.9%
if 25 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified65.3%
Taylor expanded in x around inf
lower-*.f32N/A
unpow2N/A
associate-/l*N/A
lower-*.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f3281.5
Simplified81.5%
Final simplification63.0%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 25.0) 0.5 (/ (/ (* s s) (fma x 0.5 (- s))) x)))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 25.0f) {
tmp = 0.5f;
} else {
tmp = ((s * s) / fmaf(x, 0.5f, -s)) / x;
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(25.0)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(s * s) / fma(x, Float32(0.5), Float32(-s))) / x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 25:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{s \cdot s}{\mathsf{fma}\left(x, 0.5, -s\right)}}{x}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 25Initial program 99.8%
Taylor expanded in x around 0
Simplified52.9%
if 25 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified65.3%
Taylor expanded in s around 0
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
unpow2N/A
lower-*.f3277.2
Simplified77.2%
lift-*.f32N/A
lift-neg.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
lift-/.f32N/A
/-rgt-identityN/A
clear-numN/A
lift-/.f32N/A
clear-numN/A
lift-*.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
times-fracN/A
Applied egg-rr64.2%
lift-neg.f32N/A
lift-fma.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
lift-/.f32N/A
associate-*r/N/A
lift-*.f32N/A
lower-/.f3279.6
Applied egg-rr79.6%
Final simplification62.3%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 800.0) 0.5 (* 2.0 (* s (/ s (* x x))))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 800.0f) {
tmp = 0.5f;
} else {
tmp = 2.0f * (s * (s / (x * x)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-(x / s) <= 800.0e0) then
tmp = 0.5e0
else
tmp = 2.0e0 * (s * (s / (x * x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(800.0)) tmp = Float32(0.5); else tmp = Float32(Float32(2.0) * Float32(s * Float32(s / Float32(x * x)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(800.0)) tmp = single(0.5); else tmp = single(2.0) * (s * (s / (x * x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 800:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(s \cdot \frac{s}{x \cdot x}\right)\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 800Initial program 99.7%
Taylor expanded in x around 0
Simplified51.1%
if 800 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
lower-fma.f32N/A
Simplified70.1%
Taylor expanded in s around 0
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
unpow2N/A
lower-*.f3282.2
Simplified82.2%
Taylor expanded in x around inf
lower-*.f32N/A
unpow2N/A
associate-/l*N/A
lower-*.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f3268.8
Simplified68.8%
Final simplification56.9%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) -1.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= -1.0f) {
tmp = 0.5f;
} 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) <= (-1.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 - (x / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(-1.0)) tmp = Float32(0.5); 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(-1.0)) tmp = single(0.5); 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 -1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0
Simplified28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f3258.4
Simplified58.4%
Final simplification47.4%
(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
Simplified36.6%
herbie shell --seed 2024207
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))