
(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 (pow (exp -1.0) (/ x s)))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-1.0f), (x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp((-1.0e0)) ** (x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-1.0)) ^ Float32(x / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-1.0)) ^ (x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}
\end{array}
Initial program 99.9%
div-inv99.9%
exp-prod85.1%
neg-mul-185.1%
exp-prod85.1%
pow-pow99.9%
div-inv99.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.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -0.006000000052154064)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= t_0 4.999999840142846e+37)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
(/ 1.0 (* (/ x s) 3.0))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -0.006000000052154064f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (t_0 <= 4.999999840142846e+37f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / ((x / s) * 3.0f);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = x / -s
if (t_0 <= (-0.006000000052154064e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (t_0 <= 4.999999840142846e+37) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
else
tmp = 1.0e0 / ((x / s) * 3.0e0)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-0.006000000052154064)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); elseif (t_0 <= Float32(4.999999840142846e+37)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(x / s) + Float32(2.0)))); else tmp = Float32(Float32(1.0) / Float32(Float32(x / s) * Float32(3.0))); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(-0.006000000052154064)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (t_0 <= single(4.999999840142846e+37)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((x / s) + single(2.0))); else tmp = single(1.0) / ((x / s) * single(3.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -0.006000000052154064:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;t\_0 \leq 4.999999840142846 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s} \cdot 3}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -0.00600000005Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 89.7%
if -0.00600000005 < (/.f32 (neg.f32 x) s) < 4.99999984e37Initial program 99.7%
Taylor expanded in x around 0 59.5%
mul-1-neg59.5%
unsub-neg59.5%
Simplified59.5%
*-un-lft-identity59.5%
cancel-sign-sub-inv59.5%
metadata-eval59.5%
add-log-exp95.3%
pow-exp95.3%
flip-+55.1%
metadata-eval55.1%
pow-exp55.1%
add-log-exp55.1%
neg-mul-155.1%
pow-exp55.1%
add-log-exp55.7%
neg-mul-155.7%
distribute-neg-frac255.7%
distribute-neg-frac255.7%
pow-exp55.7%
Applied egg-rr77.3%
if 4.99999984e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
Taylor expanded in x around inf 98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt98.4%
distribute-frac-neg298.4%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod98.4%
add-sqr-sqrt98.4%
Applied egg-rr100.0%
+-commutative100.0%
fma-undefine100.0%
*-rgt-identity100.0%
associate-+l+100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Final simplification86.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.0020000000949949026) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* x (* (- (* s 2.0) x) (/ 1.0 (* x s)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.0020000000949949026f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (x * (((s * 2.0f) - x) * (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.0020000000949949026e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (x * (((s * 2.0e0) - x) * (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.0020000000949949026)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) * Float32(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.0020000000949949026)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (x * (((s * single(2.0)) - x) * (single(1.0) / (x * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 0.0020000000949949026:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(\left(s \cdot 2 - x\right) \cdot \frac{1}{x \cdot s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.00200000009Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 92.7%
if 0.00200000009 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 54.5%
mul-1-neg54.5%
unsub-neg54.5%
Simplified54.5%
Taylor expanded in x around inf 54.5%
associate-*r/54.5%
metadata-eval54.5%
Simplified54.5%
frac-sub59.5%
div-inv65.3%
*-commutative65.3%
*-rgt-identity65.3%
Applied egg-rr65.3%
Final simplification82.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.0020000000949949026) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* (- (* s 2.0) x) (/ x (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.0020000000949949026f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (((s * 2.0f) - x) * (x / (x * s)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= 0.0020000000949949026e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (((s * 2.0e0) - x) * (x / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(0.0020000000949949026)) 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(Float32(Float32(s * Float32(2.0)) - x) * Float32(x / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(0.0020000000949949026)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (((s * single(2.0)) - x) * (x / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 0.0020000000949949026:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(s \cdot 2 - x\right) \cdot \frac{x}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.00200000009Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 92.7%
if 0.00200000009 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 54.5%
mul-1-neg54.5%
unsub-neg54.5%
Simplified54.5%
Taylor expanded in x around inf 54.5%
associate-*r/54.5%
metadata-eval54.5%
Simplified54.5%
frac-sub59.5%
associate-*r/60.0%
*-commutative60.0%
*-rgt-identity60.0%
Applied egg-rr60.0%
*-commutative60.0%
associate-/l*59.5%
*-commutative59.5%
Simplified59.5%
Final simplification80.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 10.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (/ (* x 3.0) s))))
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 * 3.0f) / s);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= 10.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / ((x * 3.0e0) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(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(Float32(x * Float32(3.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) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / ((x * single(3.0)) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 10:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot 3}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 10Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 90.3%
if 10 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 55.7%
mul-1-neg55.7%
unsub-neg55.7%
Simplified55.7%
Taylor expanded in x around inf 55.7%
associate-*r/55.7%
metadata-eval55.7%
Simplified55.7%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt55.7%
distribute-frac-neg255.7%
add-sqr-sqrt-0.0%
sqrt-unprod76.7%
sqr-neg76.7%
sqrt-unprod55.7%
add-sqr-sqrt55.7%
Applied egg-rr56.8%
+-commutative56.8%
fma-undefine56.8%
*-rgt-identity56.8%
associate-+l+56.8%
+-commutative56.8%
Simplified56.8%
Taylor expanded in x around inf 56.8%
associate-*r/56.8%
*-commutative56.8%
Simplified56.8%
Final simplification79.3%
(FPCore (x s) :precision binary32 (if (<= x -1.999999936531045e-21) (/ 1.0 (/ (* x (- (* s 2.0) x)) (* x s))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -1.999999936531045e-21f) {
tmp = 1.0f / ((x * ((s * 2.0f) - x)) / (x * s));
} else {
tmp = 1.0f / (1.0f + (1.0f / (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 <= (-1.999999936531045e-21)) then
tmp = 1.0e0 / ((x * ((s * 2.0e0) - x)) / (x * s))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.999999936531045e-21)) tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(s * Float32(2.0)) - x)) / Float32(x * s))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-1.999999936531045e-21)) tmp = single(1.0) / ((x * ((s * single(2.0)) - x)) / (x * s)); else tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.999999936531045 \cdot 10^{-21}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(s \cdot 2 - x\right)}{x \cdot s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -1.9999999e-21Initial program 99.7%
Taylor expanded in x around 0 57.3%
mul-1-neg57.3%
unsub-neg57.3%
Simplified57.3%
Taylor expanded in x around inf 57.3%
associate-*r/57.3%
metadata-eval57.3%
Simplified57.3%
*-commutative57.3%
frac-sub60.3%
associate-*l/62.9%
*-commutative62.9%
*-rgt-identity62.9%
Applied egg-rr62.9%
if -1.9999999e-21 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 91.5%
Final simplification81.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / (-1.0f + (3.0f - (x / s)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= (-1.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-1.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-1.0)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -1:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 99.9%
Taylor expanded in x around 0 5.5%
mul-1-neg5.5%
unsub-neg5.5%
Simplified5.5%
Taylor expanded in x around inf 5.5%
associate-*r/5.5%
metadata-eval5.5%
Simplified5.5%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 70.6%
mul-1-neg70.6%
unsub-neg70.6%
Simplified70.6%
expm1-log1p-u70.5%
Applied egg-rr70.5%
expm1-undefine70.6%
sub-neg70.6%
log1p-undefine70.6%
rem-exp-log70.6%
associate-+r-70.6%
metadata-eval70.6%
metadata-eval70.6%
Simplified70.6%
Final simplification53.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 10.0) 0.5 (/ 1.0 (* (/ x s) 3.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 10.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) <= 10.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(10.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(10.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 10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s} \cdot 3}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 10Initial program 99.8%
Taylor expanded in x around 0 49.4%
if 10 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 55.7%
mul-1-neg55.7%
unsub-neg55.7%
Simplified55.7%
Taylor expanded in x around inf 55.7%
associate-*r/55.7%
metadata-eval55.7%
Simplified55.7%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt55.7%
distribute-frac-neg255.7%
add-sqr-sqrt-0.0%
sqrt-unprod76.7%
sqr-neg76.7%
sqrt-unprod55.7%
add-sqr-sqrt55.7%
Applied egg-rr56.8%
+-commutative56.8%
fma-undefine56.8%
*-rgt-identity56.8%
associate-+l+56.8%
+-commutative56.8%
Simplified56.8%
Taylor expanded in x around inf 56.8%
Final simplification51.8%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 10.0) 0.5 (/ 1.0 (* x (/ 3.0 s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (x * (3.0f / s));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= 10.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x * (3.0e0 / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(3.0) / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(10.0)) tmp = single(0.5); else tmp = single(1.0) / (x * (single(3.0) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{3}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 10Initial program 99.8%
Taylor expanded in x around 0 49.4%
if 10 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 55.7%
mul-1-neg55.7%
unsub-neg55.7%
Simplified55.7%
Taylor expanded in x around inf 55.7%
associate-*r/55.7%
metadata-eval55.7%
Simplified55.7%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt55.7%
distribute-frac-neg255.7%
add-sqr-sqrt-0.0%
sqrt-unprod76.7%
sqr-neg76.7%
sqrt-unprod55.7%
add-sqr-sqrt55.7%
Applied egg-rr56.8%
+-commutative56.8%
fma-undefine56.8%
*-rgt-identity56.8%
associate-+l+56.8%
+-commutative56.8%
Simplified56.8%
Taylor expanded in s around 0 56.8%
Final simplification51.8%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.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) <= (-1.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(-1.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(-1.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 -1:\\
\;\;\;\;\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) < -1Initial program 99.9%
Taylor expanded in x around 0 5.5%
mul-1-neg5.5%
unsub-neg5.5%
Simplified5.5%
Taylor expanded in x around inf 5.5%
associate-*r/5.5%
metadata-eval5.5%
Simplified5.5%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 70.6%
mul-1-neg70.6%
unsub-neg70.6%
Simplified70.6%
Final simplification53.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.0f) {
tmp = 0.5f;
} else {
tmp = -1.0f / (x / s);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= 2.0e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(2.0)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(2.0)) tmp = single(0.5); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 50.1%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 54.2%
mul-1-neg54.2%
unsub-neg54.2%
Simplified54.2%
Taylor expanded in x around inf 54.2%
associate-*r/54.2%
mul-1-neg54.2%
Simplified54.2%
Final simplification51.5%
(FPCore (x s) :precision binary32 (if (<= x -0.20000000298023224) (* 0.3333333333333333 (/ s x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.20000000298023224f) {
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 <= (-0.20000000298023224e0)) 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(-0.20000000298023224)) 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(-0.20000000298023224)) 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 -0.20000000298023224:\\
\;\;\;\;0.3333333333333333 \cdot \frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.200000003Initial program 100.0%
Taylor expanded in x around 0 72.3%
mul-1-neg72.3%
unsub-neg72.3%
Simplified72.3%
Taylor expanded in x around inf 72.3%
associate-*r/72.3%
metadata-eval72.3%
Simplified72.3%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt72.3%
distribute-frac-neg272.3%
add-sqr-sqrt-0.0%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod72.3%
add-sqr-sqrt72.3%
Applied egg-rr73.7%
+-commutative73.7%
fma-undefine73.7%
*-rgt-identity73.7%
associate-+l+73.7%
+-commutative73.7%
Simplified73.7%
Taylor expanded in x around inf 67.1%
*-commutative67.1%
Simplified67.1%
if -0.200000003 < x Initial program 99.8%
Taylor expanded in x around 0 44.5%
Final simplification50.0%
(FPCore (x s) :precision binary32 (if (<= x -0.20000000298023224) (/ (* s 0.3333333333333333) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.20000000298023224f) {
tmp = (s * 0.3333333333333333f) / x;
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-0.20000000298023224e0)) then
tmp = (s * 0.3333333333333333e0) / x
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.20000000298023224)) tmp = Float32(Float32(s * Float32(0.3333333333333333)) / x); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.20000000298023224)) tmp = (s * single(0.3333333333333333)) / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.20000000298023224:\\
\;\;\;\;\frac{s \cdot 0.3333333333333333}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.200000003Initial program 100.0%
Taylor expanded in x around 0 72.3%
mul-1-neg72.3%
unsub-neg72.3%
Simplified72.3%
Taylor expanded in x around inf 72.3%
associate-*r/72.3%
metadata-eval72.3%
Simplified72.3%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt72.3%
distribute-frac-neg272.3%
add-sqr-sqrt-0.0%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod72.3%
add-sqr-sqrt72.3%
Applied egg-rr73.7%
+-commutative73.7%
fma-undefine73.7%
*-rgt-identity73.7%
associate-+l+73.7%
+-commutative73.7%
Simplified73.7%
Taylor expanded in x around inf 67.1%
associate-*r/67.1%
*-commutative67.1%
Simplified67.1%
if -0.200000003 < x Initial program 99.8%
Taylor expanded in x around 0 44.5%
Final simplification50.0%
(FPCore (x s) :precision binary32 (if (<= x -1.0000000116860974e-7) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.0000000116860974e-7f) {
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.0000000116860974e-7)) 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.0000000116860974e-7)) 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(-1.0000000116860974e-7)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000116860974 \cdot 10^{-7}:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.00000001e-7Initial program 99.9%
Taylor expanded in x around 0 64.6%
mul-1-neg64.6%
unsub-neg64.6%
Simplified64.6%
Taylor expanded in x around inf 58.2%
associate-*r/58.2%
neg-mul-158.2%
Simplified58.2%
if -1.00000001e-7 < x Initial program 99.8%
Taylor expanded in x around 0 46.3%
Final simplification49.6%
(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.9%
Taylor expanded in x around 0 35.3%
Final simplification35.3%
herbie shell --seed 2024075
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))