
(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 15 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%
div-inv99.8%
exp-prod83.4%
neg-mul-183.4%
exp-prod83.4%
pow-pow99.7%
div-inv99.7%
Applied egg-rr99.7%
add-exp-log99.8%
log-rec99.7%
log1p-expm1-u99.7%
log1p-define99.8%
expm1-log1p-u99.8%
pow-exp99.8%
neg-mul-199.8%
distribute-neg-frac299.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))) (t_1 (+ 2.0 (/ x s))))
(if (<= t_0 -10.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 1.0000000150474662e+29)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) t_1))
(/ 1.0 (/ (* x t_1) x))))))
float code(float x, float s) {
float t_0 = x / -s;
float t_1 = 2.0f + (x / s);
float tmp;
if (t_0 <= -10.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= 1.0000000150474662e+29f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / t_1);
} else {
tmp = 1.0f / ((x * t_1) / x);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: t_1
real(4) :: tmp
t_0 = x / -s
t_1 = 2.0e0 + (x / s)
if (t_0 <= (-10.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else if (t_0 <= 1.0000000150474662e+29) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / t_1)
else
tmp = 1.0e0 / ((x * t_1) / x)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) t_1 = Float32(Float32(2.0) + Float32(x / s)) tmp = Float32(0.0) if (t_0 <= Float32(-10.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (t_0 <= Float32(1.0000000150474662e+29)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / t_1)); else tmp = Float32(Float32(1.0) / Float32(Float32(x * t_1) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; t_1 = single(2.0) + (x / s); tmp = single(0.0); if (t_0 <= single(-10.0)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (t_0 <= single(1.0000000150474662e+29)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / t_1); else tmp = single(1.0) / ((x * t_1) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
t_1 := 2 + \frac{x}{s}\\
\mathbf{if}\;t\_0 \leq -10:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq 1.0000000150474662 \cdot 10^{+29}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{t\_1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot t\_1}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
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 -10 < (/.f32 (neg.f32 x) s) < 1.00000002e29Initial program 99.5%
Taylor expanded in x around 0 61.3%
mul-1-neg61.3%
unsub-neg61.3%
Simplified61.3%
sub-neg61.3%
neg-mul-161.3%
rem-log-exp92.6%
pow-exp92.6%
flip-+58.2%
metadata-eval58.2%
pow-exp58.2%
rem-log-exp58.2%
neg-mul-158.2%
pow-exp58.2%
rem-log-exp58.9%
neg-mul-158.9%
distribute-neg-frac258.9%
distribute-neg-frac258.9%
pow-exp58.9%
rem-log-exp73.8%
neg-mul-173.8%
distribute-neg-frac273.8%
Applied egg-rr73.8%
if 1.00000002e29 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 86.3%
mul-1-neg86.3%
unsub-neg86.3%
Simplified86.3%
Taylor expanded in x around inf 86.3%
associate-*r/86.3%
metadata-eval86.3%
Simplified86.3%
Taylor expanded in x around 0 86.3%
mul-1-neg86.3%
unsub-neg86.3%
Simplified86.3%
associate-*r/100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Final simplification60.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 10.0)
0.5
(if (<= t_0 1.9999999556392617e+23)
(/ 1.0 (* x (/ (+ s (* x 0.5)) (* x (* s 0.5)))))
(/ 1.0 (/ (* x (+ 2.0 (/ x s))) x))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= 10.0f) {
tmp = 0.5f;
} else if (t_0 <= 1.9999999556392617e+23f) {
tmp = 1.0f / (x * ((s + (x * 0.5f)) / (x * (s * 0.5f))));
} else {
tmp = 1.0f / ((x * (2.0f + (x / s))) / x);
}
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 <= 10.0e0) then
tmp = 0.5e0
else if (t_0 <= 1.9999999556392617e+23) then
tmp = 1.0e0 / (x * ((s + (x * 0.5e0)) / (x * (s * 0.5e0))))
else
tmp = 1.0e0 / ((x * (2.0e0 + (x / s))) / x)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(10.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(1.9999999556392617e+23)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(s + Float32(x * Float32(0.5))) / Float32(x * Float32(s * Float32(0.5)))))); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(2.0) + Float32(x / s))) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(10.0)) tmp = single(0.5); elseif (t_0 <= single(1.9999999556392617e+23)) tmp = single(1.0) / (x * ((s + (x * single(0.5))) / (x * (s * single(0.5))))); else tmp = single(1.0) / ((x * (single(2.0) + (x / s))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 10:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 1.9999999556392617 \cdot 10^{+23}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s + x \cdot 0.5}{x \cdot \left(s \cdot 0.5\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 10Initial program 99.8%
Taylor expanded in x around 0 53.7%
if 10 < (/.f32 (neg.f32 x) s) < 1.99999996e23Initial program 99.2%
Taylor expanded in x around 0 8.1%
mul-1-neg8.1%
unsub-neg8.1%
Simplified8.1%
Taylor expanded in x around inf 8.1%
associate-*r/8.1%
metadata-eval8.1%
Simplified8.1%
frac-sub34.2%
sub-neg34.2%
*-rgt-identity34.2%
add-sqr-sqrt34.2%
sqrt-unprod34.2%
sqr-neg34.2%
sqrt-unprod-0.0%
add-sqr-sqrt34.1%
*-rgt-identity34.1%
frac-add8.0%
clear-num8.0%
frac-add34.2%
*-un-lft-identity34.2%
div-inv34.2%
metadata-eval34.2%
div-inv34.2%
metadata-eval34.2%
Applied egg-rr34.2%
*-rgt-identity34.2%
associate-*l*34.2%
Simplified34.2%
if 1.99999996e23 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 68.3%
mul-1-neg68.3%
unsub-neg68.3%
Simplified68.3%
Taylor expanded in x around inf 68.3%
associate-*r/68.3%
metadata-eval68.3%
Simplified68.3%
Taylor expanded in x around 0 68.3%
mul-1-neg68.3%
unsub-neg68.3%
Simplified68.3%
associate-*r/85.8%
sub-neg85.8%
distribute-frac-neg285.8%
add-sqr-sqrt-0.0%
sqrt-unprod94.7%
sqr-neg94.7%
sqrt-unprod85.8%
add-sqr-sqrt85.8%
Applied egg-rr85.8%
Final simplification57.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 10.0)
0.5
(if (<= t_0 4.999999889098154e+21)
(/ 1.0 (* x (/ (+ x (* s -2.0)) (* x s))))
(/ 1.0 (/ (* x (+ 2.0 (/ x s))) x))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= 10.0f) {
tmp = 0.5f;
} else if (t_0 <= 4.999999889098154e+21f) {
tmp = 1.0f / (x * ((x + (s * -2.0f)) / (x * s)));
} else {
tmp = 1.0f / ((x * (2.0f + (x / s))) / x);
}
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 <= 10.0e0) then
tmp = 0.5e0
else if (t_0 <= 4.999999889098154e+21) then
tmp = 1.0e0 / (x * ((x + (s * (-2.0e0))) / (x * s)))
else
tmp = 1.0e0 / ((x * (2.0e0 + (x / s))) / x)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(10.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(4.999999889098154e+21)) 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(x * Float32(Float32(2.0) + Float32(x / s))) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(10.0)) tmp = single(0.5); elseif (t_0 <= single(4.999999889098154e+21)) tmp = single(1.0) / (x * ((x + (s * single(-2.0))) / (x * s))); else tmp = single(1.0) / ((x * (single(2.0) + (x / s))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 10:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 4.999999889098154 \cdot 10^{+21}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x + s \cdot -2}{x \cdot s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 10Initial program 99.8%
Taylor expanded in x around 0 53.7%
if 10 < (/.f32 (neg.f32 x) s) < 4.99999989e21Initial program 99.1%
Taylor expanded in x around 0 7.9%
mul-1-neg7.9%
unsub-neg7.9%
Simplified7.9%
Taylor expanded in x around inf 7.9%
associate-*r/7.9%
metadata-eval7.9%
Simplified7.9%
frac-sub36.6%
sub-neg36.6%
*-rgt-identity36.6%
add-sqr-sqrt36.6%
sqrt-unprod36.6%
sqr-neg36.6%
sqrt-unprod-0.0%
add-sqr-sqrt36.6%
*-rgt-identity36.6%
frac-add7.8%
frac-2neg7.8%
frac-2neg7.8%
metadata-eval7.8%
frac-add36.6%
Applied egg-rr36.6%
if 4.99999989e21 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 65.0%
mul-1-neg65.0%
unsub-neg65.0%
Simplified65.0%
Taylor expanded in x around inf 65.0%
associate-*r/65.0%
metadata-eval65.0%
Simplified65.0%
Taylor expanded in x around 0 65.0%
mul-1-neg65.0%
unsub-neg65.0%
Simplified65.0%
associate-*r/81.6%
sub-neg81.6%
distribute-frac-neg281.6%
add-sqr-sqrt-0.0%
sqrt-unprod91.6%
sqr-neg91.6%
sqrt-unprod81.6%
add-sqr-sqrt81.6%
Applied egg-rr81.6%
Final simplification57.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 100.0) 0.5 (/ 1.0 (/ (* x (+ 2.0 (/ x s))) x))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 100.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((x * (2.0f + (x / 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 / -s) <= 100.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((x * (2.0e0 + (x / s))) / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(100.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(2.0) + Float32(x / s))) / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(100.0)) tmp = single(0.5); else tmp = single(1.0) / ((x * (single(2.0) + (x / s))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 100:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(2 + \frac{x}{s}\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 100Initial program 99.6%
Taylor expanded in x around 0 53.2%
if 100 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 45.7%
mul-1-neg45.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 45.7%
associate-*r/45.7%
metadata-eval45.7%
Simplified45.7%
Taylor expanded in x around 0 45.7%
mul-1-neg45.7%
unsub-neg45.7%
Simplified45.7%
associate-*r/56.7%
sub-neg56.7%
distribute-frac-neg256.7%
add-sqr-sqrt-0.0%
sqrt-unprod78.3%
sqr-neg78.3%
sqrt-unprod56.7%
add-sqr-sqrt56.7%
Applied egg-rr56.7%
Final simplification54.3%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -10.0) (/ 1.0 (* x (/ 2.0 x))) (/ -1.0 (/ (- x (* s 2.0)) s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -10.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = -1.0f / ((x - (s * 2.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) <= (-10.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = (-1.0e0) / ((x - (s * 2.0e0)) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-10.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(-1.0) / Float32(Float32(x - Float32(s * Float32(2.0))) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-10.0)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(-1.0) / ((x - (s * single(2.0))) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -10:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x - s \cdot 2}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
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 -10 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 67.3%
mul-1-neg67.3%
unsub-neg67.3%
Simplified67.3%
Taylor expanded in s around 0 67.3%
Final simplification52.6%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 60.0) 0.5 (/ 1.0 (* (/ x s) 3.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 60.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) <= 60.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(60.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(60.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 60:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s} \cdot 3}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 60Initial program 99.7%
Taylor expanded in x around 0 53.5%
if 60 < (/.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-2neg45.3%
div-inv45.3%
add-sqr-sqrt45.3%
sqrt-unprod48.7%
sqr-neg48.7%
sqrt-unprod-0.0%
add-sqr-sqrt45.3%
*-un-lft-identity45.3%
prod-diff45.3%
metadata-eval45.3%
associate-/r/45.3%
clear-num45.3%
distribute-frac-neg245.3%
add-sqr-sqrt-0.0%
sqrt-unprod69.1%
sqr-neg69.1%
sqrt-unprod45.2%
add-sqr-sqrt45.2%
Applied egg-rr48.7%
+-commutative48.7%
fma-undefine48.7%
*-rgt-identity48.7%
associate-+l+48.7%
fma-undefine48.7%
*-rgt-identity48.7%
metadata-eval48.7%
distribute-rgt-neg-in48.7%
unsub-neg48.7%
metadata-eval48.7%
distribute-lft-neg-in48.7%
associate-*r/48.7%
metadata-eval48.7%
distribute-neg-frac48.7%
metadata-eval48.7%
associate-*l/48.7%
metadata-eval48.7%
Simplified48.7%
Taylor expanded in x around inf 48.7%
Final simplification52.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -10.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -10.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) <= (-10.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(-10.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(-10.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 -10:\\
\;\;\;\;\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) < -10Initial program 100.0%
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 -10 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 67.3%
mul-1-neg67.3%
unsub-neg67.3%
Simplified67.3%
Final simplification52.6%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.20000000298023224) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.20000000298023224f) {
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.20000000298023224e0) 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.20000000298023224)) 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.20000000298023224)) 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.20000000298023224:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.200000003Initial program 99.8%
Taylor expanded in x around 0 54.1%
if 0.200000003 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 44.2%
mul-1-neg44.2%
unsub-neg44.2%
Simplified44.2%
Taylor expanded in x around inf 44.2%
mul-1-neg44.2%
distribute-neg-frac44.2%
Simplified44.2%
Final simplification50.9%
(FPCore (x s) :precision binary32 (if (<= x -1.0) (* 0.3333333333333333 (/ s x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.0f) {
tmp = 0.3333333333333333f * (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.0e0)) then
tmp = 0.3333333333333333e0 * (s / x)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = Float32(Float32(0.3333333333333333) * 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.0)) tmp = single(0.3333333333333333) * (s / x); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;0.3333333333333333 \cdot \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around 0 61.7%
mul-1-neg61.7%
unsub-neg61.7%
Simplified61.7%
Taylor expanded in x around inf 61.7%
associate-*r/61.7%
metadata-eval61.7%
Simplified61.7%
frac-2neg61.7%
div-inv61.7%
add-sqr-sqrt61.7%
sqrt-unprod61.7%
sqr-neg61.7%
sqrt-unprod-0.0%
add-sqr-sqrt61.7%
*-un-lft-identity61.7%
prod-diff61.7%
metadata-eval61.7%
associate-/r/61.7%
clear-num61.7%
distribute-frac-neg261.7%
add-sqr-sqrt-0.0%
sqrt-unprod65.3%
sqr-neg65.3%
sqrt-unprod61.7%
add-sqr-sqrt61.7%
Applied egg-rr66.7%
+-commutative66.7%
fma-undefine66.7%
*-rgt-identity66.7%
associate-+l+66.7%
fma-undefine66.7%
*-rgt-identity66.7%
metadata-eval66.7%
distribute-rgt-neg-in66.7%
unsub-neg66.7%
metadata-eval66.7%
distribute-lft-neg-in66.7%
associate-*r/66.7%
metadata-eval66.7%
distribute-neg-frac66.7%
metadata-eval66.7%
associate-*l/66.7%
metadata-eval66.7%
Simplified66.7%
Taylor expanded in x around inf 55.1%
if -1 < x Initial program 99.7%
Taylor expanded in x around 0 47.6%
Final simplification49.2%
(FPCore (x s) :precision binary32 (if (<= x -1.0) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.0f) {
tmp = 1.0f / (x / s);
} 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.0e0)) then
tmp = 1.0e0 / (x / s)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = Float32(Float32(1.0) / Float32(x / s)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-1.0)) tmp = single(1.0) / (x / s); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around 0 61.7%
mul-1-neg61.7%
unsub-neg61.7%
Simplified61.7%
Taylor expanded in x around inf 61.7%
associate-*r/61.7%
metadata-eval61.7%
Simplified61.7%
frac-sub61.7%
sub-neg61.7%
*-rgt-identity61.7%
add-sqr-sqrt61.7%
sqrt-unprod68.9%
sqr-neg68.9%
sqrt-unprod-0.0%
add-sqr-sqrt61.7%
*-rgt-identity61.7%
frac-add61.7%
frac-2neg61.7%
frac-2neg61.7%
metadata-eval61.7%
frac-add61.7%
Applied egg-rr61.7%
Taylor expanded in x around inf 61.7%
if -1 < x Initial program 99.7%
Taylor expanded in x around 0 47.6%
Final simplification50.6%
(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 99.9%
Taylor expanded in x around 0 59.2%
mul-1-neg59.2%
unsub-neg59.2%
Simplified59.2%
Taylor expanded in x around inf 51.4%
associate-*r/51.4%
neg-mul-151.4%
Simplified51.4%
if -4.99999987e-5 < x Initial program 99.7%
Taylor expanded in x around 0 48.1%
Final simplification48.9%
(FPCore (x s) :precision binary32 (if (<= x -1.0) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.0f) {
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.0e0)) 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.0)) 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.0)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around 0 61.7%
mul-1-neg61.7%
unsub-neg61.7%
Simplified61.7%
Taylor expanded in x around inf 61.7%
associate-*r/61.7%
metadata-eval61.7%
Simplified61.7%
frac-sub61.7%
sub-neg61.7%
*-rgt-identity61.7%
add-sqr-sqrt61.7%
sqrt-unprod68.9%
sqr-neg68.9%
sqrt-unprod-0.0%
add-sqr-sqrt61.7%
*-rgt-identity61.7%
frac-add61.7%
frac-2neg61.7%
frac-2neg61.7%
metadata-eval61.7%
frac-add61.7%
Applied egg-rr61.7%
Taylor expanded in x around inf 53.4%
if -1 < x Initial program 99.7%
Taylor expanded in x around 0 47.6%
Final simplification48.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 38.5%
Final simplification38.5%
herbie shell --seed 2024076
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))