
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (/ 1.0 (pow E (/ x s))))))
float code(float x, float s) {
return 1.0f / (1.0f + (1.0f / powf(((float) M_E), (x / s))));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / (Float32(exp(1)) ^ Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(2.71828182845904523536) ^ (x / s)))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{1}{{e}^{\left(\frac{x}{s}\right)}}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
exp-prod99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow E (/ x (- s))))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(((float) M_E), (x / -s)));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(x / Float32(-s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(2.71828182845904523536) ^ (x / -s))); end
\begin{array}{l}
\\
\frac{1}{1 + {e}^{\left(\frac{x}{-s}\right)}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
exp-prod99.9%
Applied egg-rr99.9%
pow-flip99.9%
exp-1-e99.9%
distribute-neg-frac299.9%
Applied egg-rr99.9%
Final simplification99.9%
(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(x / Float32(-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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -1.0)
(+ 1.0 (/ s x))
(if (<= t_0 4.999999840142846e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
(/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -1.0f) {
tmp = 1.0f + (s / x);
} else if (t_0 <= 4.999999840142846e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} 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 <= (-1.0e0)) then
tmp = 1.0e0 + (s / x)
else if (t_0 <= 4.999999840142846e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-1.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); 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(x / s) + Float32(2.0)))); 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(-1.0)) tmp = single(1.0) + (s / x); elseif (t_0 <= single(4.999999840142846e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((x / s) + single(2.0))); 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 -1:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 4.999999840142846 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.0%
Taylor expanded in x around inf 94.9%
mul-1-neg94.9%
unsub-neg94.9%
Simplified94.9%
sub-neg94.9%
distribute-frac-neg94.9%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod95.2%
add-sqr-sqrt95.2%
+-commutative95.2%
Applied egg-rr95.2%
if -1 < (/.f32 (neg.f32 x) s) < 4.99999984e37Initial program 99.7%
Taylor expanded in x around 0 45.9%
mul-1-neg45.9%
unsub-neg45.9%
Simplified45.9%
*-un-lft-identity45.9%
cancel-sign-sub-inv45.9%
metadata-eval45.9%
add-log-exp94.5%
pow-exp94.5%
flip-+39.6%
metadata-eval39.6%
pow-exp39.6%
add-log-exp39.6%
neg-mul-139.6%
pow-exp39.6%
add-log-exp40.1%
neg-mul-140.1%
distribute-neg-frac240.1%
distribute-neg-frac240.1%
pow-exp40.1%
Applied egg-rr79.9%
if 4.99999984e37 < (/.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%
associate-*r/100.0%
neg-mul-1100.0%
Simplified100.0%
Final simplification87.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -10.0)
(+ 1.0 (/ s x))
(if (<= t_0 0.5) (+ 0.5 (* (/ x s) 0.25)) (/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -10.0f) {
tmp = 1.0f + (s / x);
} else if (t_0 <= 0.5f) {
tmp = 0.5f + ((x / s) * 0.25f);
} 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 = 1.0e0 + (s / x)
else if (t_0 <= 0.5e0) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-10.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (t_0 <= Float32(0.5)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); 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(1.0) + (s / x); elseif (t_0 <= single(0.5)) tmp = single(0.5) + ((x / s) * single(0.25)); 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:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.6%
Taylor expanded in x around inf 95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
sub-neg95.6%
distribute-frac-neg95.6%
add-sqr-sqrt-0.0%
sqrt-unprod96.7%
sqr-neg96.7%
sqrt-unprod95.9%
add-sqr-sqrt95.9%
+-commutative95.9%
Applied egg-rr95.9%
if -10 < (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0 94.3%
*-commutative94.3%
Simplified94.3%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 32.3%
mul-1-neg32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in x around inf 32.2%
associate-*r/32.2%
neg-mul-132.2%
Simplified32.2%
Final simplification70.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -10.0)
(+ 1.0 (/ s x))
(if (<= t_0 0.5) (+ 0.5 (* (/ x s) 0.25)) (/ 1.0 (* x (/ -1.0 s)))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -10.0f) {
tmp = 1.0f + (s / x);
} else if (t_0 <= 0.5f) {
tmp = 0.5f + ((x / s) * 0.25f);
} else {
tmp = 1.0f / (x * (-1.0f / s));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = x / -s
if (t_0 <= (-10.0e0)) then
tmp = 1.0e0 + (s / x)
else if (t_0 <= 0.5e0) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = 1.0e0 / (x * ((-1.0e0) / s))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-10.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (t_0 <= Float32(0.5)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(-1.0) / 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(1.0) + (s / x); elseif (t_0 <= single(0.5)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(1.0) / (x * (single(-1.0) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -10:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.6%
Taylor expanded in x around inf 95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
sub-neg95.6%
distribute-frac-neg95.6%
add-sqr-sqrt-0.0%
sqrt-unprod96.7%
sqr-neg96.7%
sqrt-unprod95.9%
add-sqr-sqrt95.9%
+-commutative95.9%
Applied egg-rr95.9%
if -10 < (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0 94.3%
*-commutative94.3%
Simplified94.3%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 32.3%
mul-1-neg32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in x around inf 32.3%
associate-*r/32.3%
metadata-eval32.3%
Simplified32.3%
Taylor expanded in x around inf 32.2%
Final simplification70.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 10.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) <= 10.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) <= 10.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(10.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(10.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 10:\\
\;\;\;\;\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) < 10Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 92.8%
if 10 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 32.5%
mul-1-neg32.5%
unsub-neg32.5%
Simplified32.5%
Taylor expanded in x around inf 32.5%
associate-*r/32.5%
metadata-eval32.5%
Simplified32.5%
sub-neg32.5%
clear-num32.5%
distribute-frac-neg232.5%
add-sqr-sqrt-0.0%
sqrt-unprod59.1%
sqr-neg59.1%
sqrt-unprod32.5%
add-sqr-sqrt32.5%
frac-2neg32.5%
metadata-eval32.5%
frac-add39.1%
*-un-lft-identity39.1%
add-sqr-sqrt-0.0%
sqrt-unprod39.1%
sqr-neg39.1%
sqrt-unprod39.1%
add-sqr-sqrt39.1%
div-inv39.1%
metadata-eval39.1%
div-inv39.1%
metadata-eval39.1%
add-sqr-sqrt-0.0%
sqrt-unprod59.2%
Applied egg-rr39.1%
associate-*l*39.1%
metadata-eval39.1%
associate-*l*39.1%
Simplified39.1%
Final simplification72.5%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ x (- s)))) (if (<= t_0 -10.0) (+ 1.0 (/ s x)) (if (<= t_0 0.5) 0.5 (/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -10.0f) {
tmp = 1.0f + (s / x);
} else if (t_0 <= 0.5f) {
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) :: t_0
real(4) :: tmp
t_0 = x / -s
if (t_0 <= (-10.0e0)) then
tmp = 1.0e0 + (s / x)
else if (t_0 <= 0.5e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-10.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); elseif (t_0 <= Float32(0.5)) tmp = Float32(0.5); 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(1.0) + (s / x); elseif (t_0 <= single(0.5)) tmp = single(0.5); 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:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.6%
Taylor expanded in x around inf 95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
sub-neg95.6%
distribute-frac-neg95.6%
add-sqr-sqrt-0.0%
sqrt-unprod96.7%
sqr-neg96.7%
sqrt-unprod95.9%
add-sqr-sqrt95.9%
+-commutative95.9%
Applied egg-rr95.9%
if -10 < (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0 84.1%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 32.3%
mul-1-neg32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in x around inf 32.2%
associate-*r/32.2%
neg-mul-132.2%
Simplified32.2%
Final simplification68.6%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 100.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* x (/ (+ x (* s 2.0)) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 100.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (x * ((x + (s * 2.0f)) / (x * s)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= 100.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (x * ((x + (s * 2.0e0)) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(100.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(x + Float32(s * Float32(2.0))) / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(100.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (x * ((x + (s * single(2.0))) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 100:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x + s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 100Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 92.3%
if 100 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 32.7%
mul-1-neg32.7%
unsub-neg32.7%
Simplified32.7%
Taylor expanded in x around inf 32.7%
associate-*r/32.7%
metadata-eval32.7%
Simplified32.7%
sub-neg32.7%
distribute-frac-neg232.7%
add-sqr-sqrt-0.0%
sqrt-unprod59.7%
sqr-neg59.7%
sqrt-unprod32.7%
add-sqr-sqrt32.7%
clear-num32.7%
frac-add39.5%
/-rgt-identity39.5%
*-rgt-identity39.5%
/-rgt-identity39.5%
Applied egg-rr39.5%
Final simplification72.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (+ 1.0 (/ s x)) (/ 1.0 (+ -1.0 (+ -1.0 (- 4.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 1.0f + (s / x);
} else {
tmp = 1.0f / (-1.0f + (-1.0f + (4.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 = 1.0e0 + (s / x)
else
tmp = 1.0e0 / ((-1.0e0) + ((-1.0e0) + (4.0e0 - (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-1.0)) tmp = Float32(Float32(1.0) + Float32(s / x)); else tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(-1.0) + Float32(Float32(4.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(1.0) + (s / x); else tmp = single(1.0) / (single(-1.0) + (single(-1.0) + (single(4.0) - (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -1:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(-1 + \left(4 - \frac{x}{s}\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.0%
Taylor expanded in x around inf 94.9%
mul-1-neg94.9%
unsub-neg94.9%
Simplified94.9%
sub-neg94.9%
distribute-frac-neg94.9%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod95.2%
add-sqr-sqrt95.2%
+-commutative95.2%
Applied egg-rr95.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 53.9%
mul-1-neg53.9%
unsub-neg53.9%
Simplified53.9%
expm1-log1p-u53.8%
Applied egg-rr53.8%
expm1-undefine53.8%
sub-neg53.8%
log1p-undefine53.8%
rem-exp-log53.8%
associate-+r-53.9%
metadata-eval53.9%
metadata-eval53.9%
Simplified53.9%
expm1-log1p-u53.8%
Applied egg-rr53.8%
expm1-undefine53.8%
log1p-undefine53.8%
+-commutative53.8%
rem-exp-log53.9%
sub-neg53.9%
+-commutative53.9%
associate-+r-53.9%
metadata-eval53.9%
metadata-eval53.9%
Simplified53.9%
Final simplification70.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (+ 1.0 (/ s x)) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 1.0f + (s / 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) <= (-1.0e0)) then
tmp = 1.0e0 + (s / 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(-1.0)) tmp = Float32(Float32(1.0) + Float32(s / 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(-1.0)) tmp = single(1.0) + (s / 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 -1:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.0%
Taylor expanded in x around inf 94.9%
mul-1-neg94.9%
unsub-neg94.9%
Simplified94.9%
sub-neg94.9%
distribute-frac-neg94.9%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod95.2%
add-sqr-sqrt95.2%
+-commutative95.2%
Applied egg-rr95.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 53.9%
mul-1-neg53.9%
unsub-neg53.9%
Simplified53.9%
expm1-log1p-u53.8%
Applied egg-rr53.8%
expm1-undefine53.8%
sub-neg53.8%
log1p-undefine53.8%
rem-exp-log53.8%
associate-+r-53.9%
metadata-eval53.9%
metadata-eval53.9%
Simplified53.9%
Final simplification70.0%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-6) (/ (- s) x) (if (<= x 2.99999994735501e-14) 0.5 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-6f) {
tmp = -s / x;
} else if (x <= 2.99999994735501e-14f) {
tmp = 0.5f;
} else {
tmp = 1.0f + (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 <= (-4.999999873689376e-6)) then
tmp = -s / x
else if (x <= 2.99999994735501e-14) then
tmp = 0.5e0
else
tmp = 1.0e0 + (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999873689376e-6)) tmp = Float32(Float32(-s) / x); elseif (x <= Float32(2.99999994735501e-14)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) + Float32(s / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-6)) tmp = -s / x; elseif (x <= single(2.99999994735501e-14)) tmp = single(0.5); else tmp = single(1.0) + (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999873689376 \cdot 10^{-6}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{elif}\;x \leq 2.99999994735501 \cdot 10^{-14}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{s}{x}\\
\end{array}
\end{array}
if x < -4.99999987e-6Initial program 100.0%
Taylor expanded in x around 0 38.3%
mul-1-neg38.3%
unsub-neg38.3%
Simplified38.3%
Taylor expanded in x around inf 35.3%
associate-*r/35.3%
neg-mul-135.3%
Simplified35.3%
if -4.99999987e-6 < x < 2.99999995e-14Initial program 99.5%
Taylor expanded in x around 0 57.6%
if 2.99999995e-14 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
Taylor expanded in x around inf 92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
sub-neg92.2%
distribute-frac-neg92.2%
add-sqr-sqrt-0.0%
sqrt-unprod93.2%
sqr-neg93.2%
sqrt-unprod93.2%
add-sqr-sqrt93.2%
+-commutative93.2%
Applied egg-rr93.2%
Final simplification63.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (+ 1.0 (/ s x)) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 1.0f + (s / 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) <= (-1.0e0)) then
tmp = 1.0e0 + (s / 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(-1.0)) tmp = Float32(Float32(1.0) + Float32(s / 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(-1.0)) tmp = single(1.0) + (s / 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 -1:\\
\;\;\;\;1 + \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.0%
Taylor expanded in x around inf 94.9%
mul-1-neg94.9%
unsub-neg94.9%
Simplified94.9%
sub-neg94.9%
distribute-frac-neg94.9%
add-sqr-sqrt-0.0%
sqrt-unprod96.1%
sqr-neg96.1%
sqrt-unprod95.2%
add-sqr-sqrt95.2%
+-commutative95.2%
Applied egg-rr95.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 53.9%
mul-1-neg53.9%
unsub-neg53.9%
Simplified53.9%
Final simplification70.0%
(FPCore (x s) :precision binary32 (if (<= x -4.999999873689376e-6) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999873689376e-6f) {
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-6)) 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-6)) tmp = Float32(Float32(-s) / x); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999873689376e-6)) 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^{-6}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999987e-6Initial program 100.0%
Taylor expanded in x around 0 38.3%
mul-1-neg38.3%
unsub-neg38.3%
Simplified38.3%
Taylor expanded in x around inf 35.3%
associate-*r/35.3%
neg-mul-135.3%
Simplified35.3%
if -4.99999987e-6 < x Initial program 99.8%
Taylor expanded in x around 0 43.9%
Final simplification41.3%
(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.5%
Final simplification32.5%
herbie shell --seed 2024095
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))