
(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 14 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 (+ (pow (exp 1.5) (/ (* x -0.6666666666666666) s)) 1.0)))
float code(float x, float s) {
return 1.0f / (powf(expf(1.5f), ((x * -0.6666666666666666f) / s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((exp(1.5e0) ** ((x * (-0.6666666666666666e0)) / s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32((exp(Float32(1.5)) ^ Float32(Float32(x * Float32(-0.6666666666666666)) / s)) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / ((exp(single(1.5)) ^ ((x * single(-0.6666666666666666)) / s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{{\left(e^{1.5}\right)}^{\left(\frac{x \cdot -0.6666666666666666}{s}\right)} + 1}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
add-sqr-sqrt51.9%
sqrt-unprod62.6%
sqr-neg62.6%
sqrt-unprod12.5%
add-sqr-sqrt23.1%
add-cbrt-cube23.1%
pow1/323.1%
pow-flip23.1%
Applied egg-rr99.5%
add-sqr-sqrt99.5%
unpow-prod-down99.5%
sqrt-pow199.5%
metadata-eval99.5%
sqrt-pow199.8%
metadata-eval99.8%
Applied egg-rr99.8%
pow-prod-up99.8%
metadata-eval99.8%
Applied egg-rr99.8%
exp-prod99.8%
*-commutative99.8%
exp-prod99.8%
associate-*l*99.8%
exp-prod99.8%
associate-*l/99.8%
Simplified99.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(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
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -10.0)
0.5
(if (<= t_0 9.999999680285692e+37)
(/ 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 <= -10.0f) {
tmp = 0.5f;
} else if (t_0 <= 9.999999680285692e+37f) {
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 <= (-10.0e0)) then
tmp = 0.5e0
else if (t_0 <= 9.999999680285692e+37) 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(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-10.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(9.999999680285692e+37)) 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(-10.0)) tmp = single(0.5); elseif (t_0 <= single(9.999999680285692e+37)) 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 -10:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\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) < -10Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 99.7%
Taylor expanded in x around 0 50.5%
mul-1-neg50.5%
unsub-neg50.5%
Simplified50.5%
sub-neg50.5%
neg-mul-150.5%
add-log-exp94.4%
log-pow94.4%
metadata-eval94.4%
pow-pow94.4%
flip-+44.7%
Applied egg-rr76.0%
sqr-neg76.0%
clear-num76.0%
frac-times77.6%
*-un-lft-identity77.6%
Applied egg-rr77.6%
if 9.99999968e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
distribute-neg-frac100.0%
Simplified100.0%
neg-mul-1100.0%
associate-/l*100.0%
metadata-eval100.0%
associate-/r*100.0%
clear-num91.4%
div-inv91.4%
associate-*r/91.4%
associate-/l*100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification59.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 2.0)
0.5
(if (<= t_0 9.999999680285692e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (/ x s)))
(/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= 2.0f) {
tmp = 0.5f;
} else if (t_0 <= 9.999999680285692e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (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 <= 2.0e0) then
tmp = 0.5e0
else if (t_0 <= 9.999999680285692e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / (x / s))
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(2.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(9.999999680285692e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / 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(2.0)) tmp = single(0.5); elseif (t_0 <= single(9.999999680285692e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (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 2:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 47.6%
if 2 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 99.6%
Taylor expanded in x around 0 11.6%
mul-1-neg11.6%
unsub-neg11.6%
Simplified11.6%
sub-neg11.6%
neg-mul-111.6%
add-log-exp94.5%
log-pow94.5%
metadata-eval94.5%
pow-pow94.5%
flip-+0.9%
Applied egg-rr59.8%
Taylor expanded in x around inf 59.7%
if 9.99999968e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
distribute-neg-frac100.0%
Simplified100.0%
neg-mul-1100.0%
associate-/l*100.0%
metadata-eval100.0%
associate-/r*100.0%
clear-num91.4%
div-inv91.4%
associate-*r/91.4%
associate-/l*100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification57.3%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -10.0) 0.5 (/ 1.0 (+ (+ (* 0.3333333333333333 (* x (* -3.0 (/ 1.0 s)))) 1.0) 1.0))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (((0.3333333333333333f * (x * (-3.0f * (1.0f / s)))) + 1.0f) + 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) <= (-10.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (((0.3333333333333333e0 * (x * ((-3.0e0) * (1.0e0 / s)))) + 1.0e0) + 1.0e0)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(Float32(0.3333333333333333) * Float32(x * Float32(Float32(-3.0) * Float32(Float32(1.0) / s)))) + Float32(1.0)) + Float32(1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-10.0)) tmp = single(0.5); else tmp = single(1.0) / (((single(0.3333333333333333) * (x * (single(-3.0) * (single(1.0) / s)))) + single(1.0)) + single(1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(0.3333333333333333 \cdot \left(x \cdot \left(-3 \cdot \frac{1}{s}\right)\right) + 1\right) + 1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt16.8%
sqrt-unprod37.8%
sqr-neg37.8%
sqrt-unprod21.6%
add-sqr-sqrt35.3%
add-cbrt-cube35.3%
pow1/335.3%
pow-flip35.3%
Applied egg-rr99.2%
Taylor expanded in s around -inf 61.5%
distribute-rgt-out61.5%
metadata-eval61.5%
Simplified61.5%
div-inv62.2%
associate-*l*62.2%
Applied egg-rr62.2%
Final simplification47.8%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -10.0) 0.5 (/ 1.0 (+ (+ (* 0.3333333333333333 (* (/ x s) -3.0)) 1.0) 1.0))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (((0.3333333333333333f * ((x / s) * -3.0f)) + 1.0f) + 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) <= (-10.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (((0.3333333333333333e0 * ((x / s) * (-3.0e0))) + 1.0e0) + 1.0e0)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(Float32(0.3333333333333333) * Float32(Float32(x / s) * Float32(-3.0))) + Float32(1.0)) + Float32(1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-10.0)) tmp = single(0.5); else tmp = single(1.0) / (((single(0.3333333333333333) * ((x / s) * single(-3.0))) + single(1.0)) + single(1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(0.3333333333333333 \cdot \left(\frac{x}{s} \cdot -3\right) + 1\right) + 1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt16.8%
sqrt-unprod37.8%
sqr-neg37.8%
sqrt-unprod21.6%
add-sqr-sqrt35.3%
add-cbrt-cube35.3%
pow1/335.3%
pow-flip35.3%
Applied egg-rr99.2%
Taylor expanded in s around -inf 61.5%
distribute-rgt-out61.5%
metadata-eval61.5%
Simplified61.5%
Taylor expanded in x around 0 61.5%
Final simplification47.4%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -10.0) 0.5 (/ 1.0 (+ (+ (* 0.3333333333333333 (/ (* x -3.0) s)) 1.0) 1.0))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (((0.3333333333333333f * ((x * -3.0f) / s)) + 1.0f) + 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) <= (-10.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (((0.3333333333333333e0 * ((x * (-3.0e0)) / s)) + 1.0e0) + 1.0e0)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(Float32(0.3333333333333333) * Float32(Float32(x * Float32(-3.0)) / s)) + Float32(1.0)) + Float32(1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-10.0)) tmp = single(0.5); else tmp = single(1.0) / (((single(0.3333333333333333) * ((x * single(-3.0)) / s)) + single(1.0)) + single(1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(0.3333333333333333 \cdot \frac{x \cdot -3}{s} + 1\right) + 1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt16.8%
sqrt-unprod37.8%
sqr-neg37.8%
sqrt-unprod21.6%
add-sqr-sqrt35.3%
add-cbrt-cube35.3%
pow1/335.3%
pow-flip35.3%
Applied egg-rr99.2%
Taylor expanded in s around -inf 61.5%
distribute-rgt-out61.5%
metadata-eval61.5%
Simplified61.5%
Final simplification47.4%
(FPCore (x s)
:precision binary32
(if (<= (/ (- x) s) -10.0)
0.5
(/
1.0
(+ (+ (* x (/ 0.3333333333333333 (* s -0.3333333333333333))) 1.0) 1.0))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (((x * (0.3333333333333333f / (s * -0.3333333333333333f))) + 1.0f) + 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) <= (-10.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (((x * (0.3333333333333333e0 / (s * (-0.3333333333333333e0)))) + 1.0e0) + 1.0e0)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(x * Float32(Float32(0.3333333333333333) / Float32(s * Float32(-0.3333333333333333)))) + Float32(1.0)) + Float32(1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-10.0)) tmp = single(0.5); else tmp = single(1.0) / (((x * (single(0.3333333333333333) / (s * single(-0.3333333333333333)))) + single(1.0)) + single(1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(x \cdot \frac{0.3333333333333333}{s \cdot -0.3333333333333333} + 1\right) + 1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt16.8%
sqrt-unprod37.8%
sqr-neg37.8%
sqrt-unprod21.6%
add-sqr-sqrt35.3%
add-cbrt-cube35.3%
pow1/335.3%
pow-flip35.3%
Applied egg-rr99.2%
Taylor expanded in s around -inf 61.5%
distribute-rgt-out61.5%
metadata-eval61.5%
Simplified61.5%
clear-num61.5%
un-div-inv61.5%
*-un-lft-identity61.5%
*-commutative61.5%
times-frac61.5%
metadata-eval61.5%
Applied egg-rr61.5%
associate-/r*61.5%
metadata-eval61.5%
Simplified61.5%
metadata-eval61.5%
associate-/r*61.5%
associate-*r/61.5%
associate-/r/62.2%
*-commutative62.2%
Applied egg-rr62.2%
Final simplification47.8%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -10.0) 0.5 (/ 1.0 (+ (+ (/ -1.0 (/ s x)) 1.0) 1.0))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (((-1.0f / (s / x)) + 1.0f) + 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) <= (-10.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((((-1.0e0) / (s / x)) + 1.0e0) + 1.0e0)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(Float32(-1.0) / Float32(s / x)) + Float32(1.0)) + Float32(1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-10.0)) tmp = single(0.5); else tmp = single(1.0) / (((single(-1.0) / (s / x)) + single(1.0)) + single(1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\frac{-1}{\frac{s}{x}} + 1\right) + 1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
add-sqr-sqrt16.8%
sqrt-unprod37.8%
sqr-neg37.8%
sqrt-unprod21.6%
add-sqr-sqrt35.3%
add-cbrt-cube35.3%
pow1/335.3%
pow-flip35.3%
Applied egg-rr99.2%
Taylor expanded in s around -inf 61.5%
distribute-rgt-out61.5%
metadata-eval61.5%
Simplified61.5%
clear-num61.5%
un-div-inv61.5%
*-un-lft-identity61.5%
*-commutative61.5%
times-frac61.5%
metadata-eval61.5%
Applied egg-rr61.5%
associate-/r*61.5%
metadata-eval61.5%
Simplified61.5%
Final simplification47.4%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -10.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -10.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) <= (-10.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(-10.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(-10.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 -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 61.5%
mul-1-neg61.5%
unsub-neg61.5%
Simplified61.5%
Final simplification47.4%
(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(Float32(-x) / 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.9%
Taylor expanded in x around 0 47.6%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 42.6%
mul-1-neg42.6%
unsub-neg42.6%
Simplified42.6%
Taylor expanded in x around inf 42.6%
neg-mul-142.6%
distribute-neg-frac42.6%
Simplified42.6%
neg-mul-142.6%
associate-/l*42.6%
metadata-eval42.6%
associate-/r*42.6%
clear-num39.6%
div-inv39.6%
associate-*r/39.6%
associate-/l*42.6%
metadata-eval42.6%
Applied egg-rr42.6%
associate-*l/42.6%
metadata-eval42.6%
Simplified42.6%
Final simplification45.8%
(FPCore (x s) :precision binary32 (if (<= x -0.00019999999494757503) (- (/ s x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.00019999999494757503f) {
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 <= (-0.00019999999494757503e0)) 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(-0.00019999999494757503)) 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(-0.00019999999494757503)) tmp = -(s / x); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00019999999494757503:\\
\;\;\;\;-\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.99999995e-4Initial program 100.0%
Taylor expanded in x around 0 51.8%
mul-1-neg51.8%
unsub-neg51.8%
Simplified51.8%
Taylor expanded in x around inf 47.9%
associate-*r/47.9%
neg-mul-147.9%
Simplified47.9%
if -1.99999995e-4 < x Initial program 99.8%
Taylor expanded in x around 0 43.1%
Final simplification44.5%
(FPCore (x s) :precision binary32 (if (<= x -0.004999999888241291) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.004999999888241291f) {
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 <= (-0.004999999888241291e0)) 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(-0.004999999888241291)) 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(-0.004999999888241291)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.004999999888241291:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.00499999989Initial program 100.0%
Taylor expanded in x around 0 53.3%
mul-1-neg53.3%
unsub-neg53.3%
Simplified53.3%
Taylor expanded in x around inf 53.3%
neg-mul-153.3%
distribute-neg-frac53.3%
Simplified53.3%
clear-num49.2%
add-sqr-sqrt49.2%
sqrt-unprod58.8%
sqr-neg58.8%
sqrt-unprod-0.0%
add-sqr-sqrt49.2%
expm1-log1p-u49.2%
expm1-udef98.7%
Applied egg-rr98.7%
expm1-def49.2%
expm1-log1p49.2%
Simplified49.2%
if -0.00499999989 < x Initial program 99.8%
Taylor expanded in x around 0 42.7%
Final simplification44.5%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 32.6%
Final simplification32.6%
herbie shell --seed 2024011
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))