
(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 18 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (- (/ x s)))))))
float code(float x, float s) {
return expf(-log1pf(expf(-(x / s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(-Float32(x / s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}
\end{array}
Initial program 99.8%
div-inv99.8%
exp-prod83.2%
neg-mul-183.2%
exp-prod83.2%
pow-pow99.8%
div-inv99.8%
Applied egg-rr99.8%
add-exp-log99.8%
log-rec99.8%
log1p-define99.8%
pow-exp99.8%
add-log-exp99.8%
log-pow99.8%
inv-pow99.8%
neg-log99.8%
add-log-exp99.8%
distribute-neg-frac299.8%
Applied egg-rr99.8%
Final simplification99.8%
(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.8%
Applied egg-rr99.8%
*-un-lft-identity99.8%
exp-prod99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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(-Float32(x / 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.8%
Applied egg-rr99.8%
*-un-lft-identity99.8%
exp-prod99.8%
Applied egg-rr99.8%
inv-pow99.8%
pow-pow99.8%
exp-1-e99.8%
Applied egg-rr99.8%
*-commutative99.8%
neg-mul-199.8%
distribute-neg-frac299.8%
Simplified99.8%
Final simplification99.8%
(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.8%
Applied egg-rr99.8%
(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 40.0)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= t_0 1999999968613499000.0)
(/ 1.0 (* x (/ (+ s (* x -0.5)) (* x (* s 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 <= 40.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (t_0 <= 1999999968613499000.0f) {
tmp = 1.0f / (x * ((s + (x * -0.5f)) / (x * (s * 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 <= 40.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (t_0 <= 1999999968613499000.0e0) then
tmp = 1.0e0 / (x * ((s + (x * (-0.5e0))) / (x * (s * 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(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(40.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); elseif (t_0 <= Float32(1999999968613499000.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(s + Float32(x * Float32(-0.5))) / Float32(x * Float32(s * 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(40.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (t_0 <= single(1999999968613499000.0)) tmp = single(1.0) / (x * ((s + (x * single(-0.5))) / (x * (s * 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 40:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;t\_0 \leq 1999999968613499000:\\
\;\;\;\;\frac{1}{x \cdot \frac{s + x \cdot -0.5}{x \cdot \left(s \cdot 0.5\right)}}\\
\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) < 40Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.8%
if 40 < (/.f32 (neg.f32 x) s) < 1.99999997e18Initial program 99.4%
Taylor expanded in x around 0 7.6%
neg-mul-17.6%
unsub-neg7.6%
Simplified7.6%
Taylor expanded in x around inf 7.6%
associate-*r/7.6%
metadata-eval7.6%
Simplified7.6%
frac-sub47.3%
sub-neg47.3%
*-rgt-identity47.3%
add-sqr-sqrt47.3%
sqrt-unprod47.3%
sqr-neg47.3%
sqrt-unprod-0.0%
add-sqr-sqrt47.3%
*-rgt-identity47.3%
frac-add7.4%
frac-2neg7.4%
metadata-eval7.4%
clear-num7.4%
frac-add47.3%
*-un-lft-identity47.3%
add-sqr-sqrt-0.0%
sqrt-unprod47.3%
sqr-neg47.3%
sqrt-unprod47.3%
add-sqr-sqrt47.3%
div-inv47.3%
metadata-eval47.3%
Applied egg-rr47.3%
associate-*l*47.3%
metadata-eval47.3%
associate-*l*47.3%
Simplified47.3%
if 1.99999997e18 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 100.0%
Taylor expanded in x around 0 14.4%
neg-mul-114.4%
unsub-neg14.4%
Simplified14.4%
*-un-lft-identity14.4%
cancel-sign-sub-inv14.4%
metadata-eval14.4%
add-log-exp100.0%
pow-exp100.0%
flip-+-0.0%
metadata-eval-0.0%
pow-exp-0.0%
add-log-exp-0.0%
neg-mul-1-0.0%
pow-exp-0.0%
add-log-exp0.1%
neg-mul-10.1%
distribute-neg-frac20.1%
distribute-neg-frac20.1%
pow-exp0.1%
Applied egg-rr95.8%
Taylor expanded in x around inf 95.8%
if 9.99999968e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 94.1%
associate-*r/94.1%
neg-mul-194.1%
Simplified94.1%
clear-num100.0%
inv-pow100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification91.0%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -0.009999999776482582)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= t_0 9.999999680285692e+37)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ (/ x s) 2.0)))
(/ 1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -0.009999999776482582f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (t_0 <= 9.999999680285692e+37f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / ((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 <= (-0.009999999776482582e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (t_0 <= 9.999999680285692e+37) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / ((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(-0.009999999776482582)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); 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(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(-0.009999999776482582)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (t_0 <= single(9.999999680285692e+37)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / ((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 -0.009999999776482582:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;t\_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -0.00999999978Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 94.6%
if -0.00999999978 < (/.f32 (neg.f32 x) s) < 9.99999968e37Initial program 99.6%
Taylor expanded in x around 0 49.6%
neg-mul-149.6%
unsub-neg49.6%
Simplified49.6%
*-un-lft-identity49.6%
cancel-sign-sub-inv49.6%
metadata-eval49.6%
add-log-exp95.7%
pow-exp95.7%
flip-+43.2%
metadata-eval43.2%
pow-exp43.2%
add-log-exp43.2%
neg-mul-143.2%
pow-exp43.2%
add-log-exp43.8%
neg-mul-143.8%
distribute-neg-frac243.8%
distribute-neg-frac243.8%
pow-exp43.8%
Applied egg-rr78.8%
frac-times75.9%
sqr-neg75.9%
frac-times78.8%
clear-num78.8%
frac-times81.0%
*-un-lft-identity81.0%
Applied egg-rr81.0%
if 9.99999968e37 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 94.1%
associate-*r/94.1%
neg-mul-194.1%
Simplified94.1%
clear-num100.0%
inv-pow100.0%
add-sqr-sqrt-0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification88.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 40.0)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= t_0 1999999968613499000.0)
(/ 1.0 (* x (/ (+ s (* x -0.5)) (* x (* s 0.5)))))
(/ 1.0 (/ (* x (+ (/ x s) 2.0)) x))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= 40.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (t_0 <= 1999999968613499000.0f) {
tmp = 1.0f / (x * ((s + (x * -0.5f)) / (x * (s * 0.5f))));
} else {
tmp = 1.0f / ((x * ((x / s) + 2.0f)) / 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 <= 40.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (t_0 <= 1999999968613499000.0e0) then
tmp = 1.0e0 / (x * ((s + (x * (-0.5e0))) / (x * (s * 0.5e0))))
else
tmp = 1.0e0 / ((x * ((x / s) + 2.0e0)) / 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(40.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); elseif (t_0 <= Float32(1999999968613499000.0)) 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(x / s) + Float32(2.0))) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(40.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (t_0 <= single(1999999968613499000.0)) tmp = single(1.0) / (x * ((s + (x * single(-0.5))) / (x * (s * single(0.5))))); else tmp = single(1.0) / ((x * ((x / s) + single(2.0))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 40:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;t\_0 \leq 1999999968613499000:\\
\;\;\;\;\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(\frac{x}{s} + 2\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 40Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.8%
if 40 < (/.f32 (neg.f32 x) s) < 1.99999997e18Initial program 99.4%
Taylor expanded in x around 0 7.6%
neg-mul-17.6%
unsub-neg7.6%
Simplified7.6%
Taylor expanded in x around inf 7.6%
associate-*r/7.6%
metadata-eval7.6%
Simplified7.6%
frac-sub47.3%
sub-neg47.3%
*-rgt-identity47.3%
add-sqr-sqrt47.3%
sqrt-unprod47.3%
sqr-neg47.3%
sqrt-unprod-0.0%
add-sqr-sqrt47.3%
*-rgt-identity47.3%
frac-add7.4%
frac-2neg7.4%
metadata-eval7.4%
clear-num7.4%
frac-add47.3%
*-un-lft-identity47.3%
add-sqr-sqrt-0.0%
sqrt-unprod47.3%
sqr-neg47.3%
sqrt-unprod47.3%
add-sqr-sqrt47.3%
div-inv47.3%
metadata-eval47.3%
Applied egg-rr47.3%
associate-*l*47.3%
metadata-eval47.3%
associate-*l*47.3%
Simplified47.3%
if 1.99999997e18 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 47.4%
neg-mul-147.4%
unsub-neg47.4%
Simplified47.4%
Taylor expanded in x around inf 47.4%
associate-*r/47.4%
metadata-eval47.4%
Simplified47.4%
Taylor expanded in x around 0 47.4%
mul-1-neg47.4%
sub-neg47.4%
Simplified47.4%
associate-*r/77.2%
sub-neg77.2%
distribute-frac-neg277.2%
add-sqr-sqrt-0.0%
sqrt-unprod91.1%
sqr-neg91.1%
sqrt-unprod77.2%
add-sqr-sqrt77.2%
Applied egg-rr77.2%
Final simplification85.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 40.0)
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
(if (<= t_0 1999999968613499000.0)
(/ 1.0 (* x (/ (- (* s -2.0) x) (* x s))))
(/ 1.0 (/ (* x (+ (/ x s) 2.0)) x))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= 40.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else if (t_0 <= 1999999968613499000.0f) {
tmp = 1.0f / (x * (((s * -2.0f) - x) / (x * s)));
} else {
tmp = 1.0f / ((x * ((x / s) + 2.0f)) / 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 <= 40.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else if (t_0 <= 1999999968613499000.0e0) then
tmp = 1.0e0 / (x * (((s * (-2.0e0)) - x) / (x * s)))
else
tmp = 1.0e0 / ((x * ((x / s) + 2.0e0)) / 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(40.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); elseif (t_0 <= Float32(1999999968613499000.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(-2.0)) - x) / Float32(x * s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(x / s) + Float32(2.0))) / x)); end return tmp end
function tmp_2 = code(x, s) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(40.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); elseif (t_0 <= single(1999999968613499000.0)) tmp = single(1.0) / (x * (((s * single(-2.0)) - x) / (x * s))); else tmp = single(1.0) / ((x * ((x / s) + single(2.0))) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 40:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{elif}\;t\_0 \leq 1999999968613499000:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot -2 - x}{x \cdot s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(\frac{x}{s} + 2\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 40Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.8%
if 40 < (/.f32 (neg.f32 x) s) < 1.99999997e18Initial program 99.4%
Taylor expanded in x around 0 7.6%
neg-mul-17.6%
unsub-neg7.6%
Simplified7.6%
Taylor expanded in x around inf 7.6%
associate-*r/7.6%
metadata-eval7.6%
Simplified7.6%
frac-sub47.3%
sub-neg47.3%
*-rgt-identity47.3%
add-sqr-sqrt47.3%
sqrt-unprod47.3%
sqr-neg47.3%
sqrt-unprod-0.0%
add-sqr-sqrt47.3%
*-rgt-identity47.3%
frac-add7.4%
frac-2neg7.4%
frac-2neg7.4%
metadata-eval7.4%
frac-add47.3%
Applied egg-rr47.3%
*-commutative47.3%
mul-1-neg47.3%
sub-neg47.3%
*-commutative47.3%
Simplified47.3%
if 1.99999997e18 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 47.4%
neg-mul-147.4%
unsub-neg47.4%
Simplified47.4%
Taylor expanded in x around inf 47.4%
associate-*r/47.4%
metadata-eval47.4%
Simplified47.4%
Taylor expanded in x around 0 47.4%
mul-1-neg47.4%
sub-neg47.4%
Simplified47.4%
associate-*r/77.2%
sub-neg77.2%
distribute-frac-neg277.2%
add-sqr-sqrt-0.0%
sqrt-unprod91.1%
sqr-neg91.1%
sqrt-unprod77.2%
add-sqr-sqrt77.2%
Applied egg-rr77.2%
Final simplification85.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 50.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (/ (* x (+ (/ x s) 2.0)) x))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 50.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / ((x * ((x / s) + 2.0f)) / 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) <= 50.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / ((x * ((x / s) + 2.0e0)) / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(50.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(Float32(x / s) + Float32(2.0))) / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(50.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); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 50:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(\frac{x}{s} + 2\right)}{x}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 50Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 93.3%
if 50 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 38.6%
neg-mul-138.6%
unsub-neg38.6%
Simplified38.6%
Taylor expanded in x around inf 38.6%
associate-*r/38.6%
metadata-eval38.6%
Simplified38.6%
Taylor expanded in x around 0 38.6%
mul-1-neg38.6%
sub-neg38.6%
Simplified38.6%
associate-*r/61.8%
sub-neg61.8%
distribute-frac-neg261.8%
add-sqr-sqrt-0.0%
sqrt-unprod82.8%
sqr-neg82.8%
sqrt-unprod61.8%
add-sqr-sqrt61.8%
Applied egg-rr61.8%
Final simplification82.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.0010000000474974513) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.0010000000474974513f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} 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) <= 0.0010000000474974513e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
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(0.0010000000474974513)) 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(2.0) - Float32(x / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(0.0010000000474974513)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); 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 0.0010000000474974513:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.00100000005Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 96.2%
if 0.00100000005 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 37.8%
neg-mul-137.8%
unsub-neg37.8%
Simplified37.8%
Final simplification74.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -10.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (+ (- 3.0 (/ x s)) -1.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -10.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / ((3.0f - (x / s)) + -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 = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / ((3.0e0 - (x / s)) + (-1.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(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(3.0) - Float32(x / s)) + 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(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / ((single(3.0) - (x / s)) + single(-1.0)); 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}{\left(3 - \frac{x}{s}\right) + -1}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
Taylor expanded in x around 0 5.1%
neg-mul-15.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.7%
Taylor expanded in x around 0 58.8%
neg-mul-158.8%
unsub-neg58.8%
Simplified58.8%
expm1-log1p-u58.7%
Applied egg-rr58.7%
expm1-undefine58.7%
sub-neg58.7%
log1p-undefine58.7%
rem-exp-log58.8%
associate-+r-58.8%
metadata-eval58.8%
metadata-eval58.8%
Simplified58.8%
Final simplification46.2%
(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%
neg-mul-15.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.7%
Taylor expanded in x around 0 58.8%
neg-mul-158.8%
unsub-neg58.8%
Simplified58.8%
Final simplification46.2%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.5) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 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) :: tmp
if ((x / -s) <= 0.5e0) 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.5)) 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.5)) 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.5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.5Initial program 99.9%
Taylor expanded in x around 0 49.8%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 37.4%
neg-mul-137.4%
unsub-neg37.4%
Simplified37.4%
Taylor expanded in x around inf 37.4%
associate-*r/37.4%
neg-mul-137.4%
Simplified37.4%
Final simplification45.2%
(FPCore (x s) :precision binary32 (if (<= x -4.999999969612645e-9) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999969612645e-9f) {
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 <= (-4.999999969612645e-9)) 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(-4.999999969612645e-9)) 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(-4.999999969612645e-9)) 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 -4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999997e-9Initial program 100.0%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 43.5%
associate-*r/43.5%
neg-mul-143.5%
Simplified43.5%
clear-num45.7%
inv-pow45.7%
add-sqr-sqrt-0.0%
sqrt-unprod59.6%
sqr-neg59.6%
sqrt-unprod45.7%
add-sqr-sqrt45.7%
Applied egg-rr45.7%
unpow-145.7%
Simplified45.7%
if -4.99999997e-9 < x Initial program 99.7%
Taylor expanded in x around 0 44.8%
(FPCore (x s) :precision binary32 (if (<= x -4.999999969612645e-9) (* s (/ 1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999969612645e-9f) {
tmp = s * (1.0f / 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.999999969612645e-9)) then
tmp = s * (1.0e0 / x)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.999999969612645e-9)) tmp = Float32(s * Float32(Float32(1.0) / x)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.999999969612645e-9)) tmp = s * (single(1.0) / x); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999997e-9Initial program 100.0%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 43.5%
associate-*r/43.5%
neg-mul-143.5%
Simplified43.5%
div-inv43.5%
add-sqr-sqrt-0.0%
sqrt-unprod57.4%
sqr-neg57.4%
sqrt-unprod43.5%
add-sqr-sqrt43.5%
Applied egg-rr43.5%
if -4.99999997e-9 < x Initial program 99.7%
Taylor expanded in x around 0 44.8%
(FPCore (x s) :precision binary32 (if (<= x -4.999999969612645e-9) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -4.999999969612645e-9f) {
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.999999969612645e-9)) 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.999999969612645e-9)) 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(-4.999999969612645e-9)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -4.99999997e-9Initial program 100.0%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
unsub-neg45.7%
Simplified45.7%
Taylor expanded in x around inf 43.5%
associate-*r/43.5%
neg-mul-143.5%
Simplified43.5%
neg-sub043.5%
sub-neg43.5%
add-sqr-sqrt-0.0%
sqrt-unprod57.4%
sqr-neg57.4%
sqrt-unprod43.5%
add-sqr-sqrt43.5%
Applied egg-rr43.5%
+-lft-identity43.5%
Simplified43.5%
if -4.99999997e-9 < x Initial program 99.7%
Taylor expanded in x around 0 44.8%
(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 33.8%
herbie shell --seed 2024137
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))