
(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 (exp (- (log1p (exp (/ x (- s)))))))
float code(float x, float s) {
return expf(-log1pf(expf((x / -s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(x / Float32(-s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{\frac{x}{-s}}\right)}
\end{array}
Initial program 99.8%
div-inv99.8%
exp-prod83.8%
neg-mul-183.8%
exp-prod83.8%
pow-pow99.8%
div-inv99.8%
Applied egg-rr99.8%
add-exp-log99.8%
log-rec99.8%
log1p-expm1-u99.8%
log1p-define99.9%
pow-exp99.9%
expm1-log1p-u99.9%
neg-mul-199.9%
distribute-neg-frac299.9%
Applied egg-rr99.9%
(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.8%
div-inv99.8%
exp-prod83.8%
neg-mul-183.8%
exp-prod83.8%
pow-pow99.8%
div-inv99.8%
Applied egg-rr99.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 2.0)
0.5
(if (<= t_0 999999984306749400.0)
(/ (/ (pow s 2.0) (- s)) x)
(if (<= t_0 INFINITY)
(/ 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 <= 2.0f) {
tmp = 0.5f;
} else if (t_0 <= 999999984306749400.0f) {
tmp = (powf(s, 2.0f) / -s) / x;
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (x / s);
}
return tmp;
}
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(2.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(999999984306749400.0)) tmp = Float32(Float32((s ^ Float32(2.0)) / Float32(-s)) / x); elseif (t_0 <= Float32(Inf)) 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(2.0)) tmp = single(0.5); elseif (t_0 <= single(999999984306749400.0)) tmp = ((s ^ single(2.0)) / -s) / x; elseif (t_0 <= single(Inf)) 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 2:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 999999984306749400:\\
\;\;\;\;\frac{\frac{{s}^{2}}{-s}}{x}\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\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) < 2Initial program 99.9%
Taylor expanded in x around 0 48.9%
if 2 < (/.f32 (neg.f32 x) s) < 9.99999984e17Initial program 99.2%
Taylor expanded in x around 0 8.2%
neg-mul-18.2%
unsub-neg8.2%
Simplified8.2%
Taylor expanded in x around inf 8.1%
associate-*r/8.1%
neg-mul-18.1%
Simplified8.1%
neg-sub08.1%
flip--46.5%
metadata-eval46.5%
pow246.5%
add-sqr-sqrt46.5%
sqrt-unprod4.8%
sqr-neg4.8%
sqrt-unprod-0.0%
add-sqr-sqrt45.8%
sub-neg45.8%
neg-sub045.8%
add-sqr-sqrt-0.0%
sqrt-unprod4.8%
sqr-neg4.8%
sqrt-unprod46.5%
add-sqr-sqrt46.5%
Applied egg-rr46.5%
sub0-neg46.5%
Simplified46.5%
if 9.99999984e17 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 100.0%
Taylor expanded in x around 0 49.8%
neg-mul-149.8%
unsub-neg49.8%
Simplified49.8%
sub-neg49.8%
neg-mul-149.8%
rem-log-exp100.0%
pow-exp100.0%
flip-+-0.0%
metadata-eval-0.0%
pow-exp-0.0%
rem-log-exp-0.0%
neg-mul-1-0.0%
pow-exp-0.0%
rem-log-exp0.1%
neg-mul-10.1%
distribute-neg-frac20.1%
distribute-neg-frac20.1%
pow-exp0.1%
rem-log-exp57.1%
neg-mul-157.1%
distribute-neg-frac257.1%
Applied egg-rr57.1%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 35.2%
neg-mul-135.2%
unsub-neg35.2%
Simplified35.2%
Taylor expanded in x around inf 15.2%
associate-*r/15.2%
neg-mul-115.2%
Simplified15.2%
clear-num16.1%
inv-pow16.1%
add-sqr-sqrt-0.0%
sqrt-unprod27.4%
sqr-neg27.4%
sqrt-unprod17.9%
add-sqr-sqrt17.9%
Applied egg-rr17.9%
unpow-117.9%
Simplified17.9%
Final simplification50.4%
(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 0.20000000298023224)
0.5
(if (<= t_0 999999984306749400.0)
(/ 1.0 (* x (/ (+ s (* x -0.5)) (* x (* s 0.5)))))
(if (<= t_0 INFINITY)
(/ 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 <= 0.20000000298023224f) {
tmp = 0.5f;
} else if (t_0 <= 999999984306749400.0f) {
tmp = 1.0f / (x * ((s + (x * -0.5f)) / (x * (s * 0.5f))));
} else if (t_0 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (x / s);
}
return tmp;
}
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(0.20000000298023224)) tmp = Float32(0.5); elseif (t_0 <= Float32(999999984306749400.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(Inf)) 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(0.20000000298023224)) tmp = single(0.5); elseif (t_0 <= single(999999984306749400.0)) tmp = single(1.0) / (x * ((s + (x * single(-0.5))) / (x * (s * single(0.5))))); elseif (t_0 <= single(Inf)) 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 0.20000000298023224:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 999999984306749400:\\
\;\;\;\;\frac{1}{x \cdot \frac{s + x \cdot -0.5}{x \cdot \left(s \cdot 0.5\right)}}\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\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) < 0.200000003Initial program 99.9%
Taylor expanded in x around 0 49.0%
if 0.200000003 < (/.f32 (neg.f32 x) s) < 9.99999984e17Initial program 99.2%
Taylor expanded in x around 0 8.8%
neg-mul-18.8%
unsub-neg8.8%
Simplified8.8%
Taylor expanded in x around inf 8.8%
associate-*r/8.8%
metadata-eval8.8%
Simplified8.8%
sub-neg8.8%
distribute-frac-neg28.8%
add-sqr-sqrt-0.0%
sqrt-unprod45.0%
sqr-neg45.0%
sqrt-unprod7.7%
add-sqr-sqrt7.7%
/-rgt-identity7.7%
clear-num7.7%
clear-num7.7%
frac-2neg7.7%
metadata-eval7.7%
frac-add39.7%
*-un-lft-identity39.7%
add-sqr-sqrt-0.0%
sqrt-unprod39.3%
sqr-neg39.3%
sqrt-unprod39.3%
add-sqr-sqrt39.3%
div-inv39.3%
metadata-eval39.3%
div-inv39.3%
metadata-eval39.3%
Applied egg-rr40.8%
associate-*l*40.8%
metadata-eval40.8%
associate-*l*40.8%
Simplified40.8%
if 9.99999984e17 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 100.0%
Taylor expanded in x around 0 49.8%
neg-mul-149.8%
unsub-neg49.8%
Simplified49.8%
sub-neg49.8%
neg-mul-149.8%
rem-log-exp100.0%
pow-exp100.0%
flip-+-0.0%
metadata-eval-0.0%
pow-exp-0.0%
rem-log-exp-0.0%
neg-mul-1-0.0%
pow-exp-0.0%
rem-log-exp0.1%
neg-mul-10.1%
distribute-neg-frac20.1%
distribute-neg-frac20.1%
pow-exp0.1%
rem-log-exp57.1%
neg-mul-157.1%
distribute-neg-frac257.1%
Applied egg-rr57.1%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 35.2%
neg-mul-135.2%
unsub-neg35.2%
Simplified35.2%
Taylor expanded in x around inf 15.2%
associate-*r/15.2%
neg-mul-115.2%
Simplified15.2%
clear-num16.1%
inv-pow16.1%
add-sqr-sqrt-0.0%
sqrt-unprod27.4%
sqr-neg27.4%
sqrt-unprod17.9%
add-sqr-sqrt17.9%
Applied egg-rr17.9%
unpow-117.9%
Simplified17.9%
Final simplification49.7%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 0.20000000298023224) 0.5 (/ 1.0 (* x (/ (+ s (* x -0.5)) (* x (* s 0.5)))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 0.20000000298023224f) {
tmp = 0.5f;
} 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) <= 0.20000000298023224e0) then
tmp = 0.5e0
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(0.20000000298023224)) tmp = Float32(0.5); 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(0.20000000298023224)) tmp = single(0.5); 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 0.20000000298023224:\\
\;\;\;\;0.5\\
\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) < 0.200000003Initial program 99.9%
Taylor expanded in x around 0 49.0%
if 0.200000003 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 34.3%
neg-mul-134.3%
unsub-neg34.3%
Simplified34.3%
Taylor expanded in x around inf 35.2%
associate-*r/35.2%
metadata-eval35.2%
Simplified35.2%
sub-neg35.2%
distribute-frac-neg235.2%
add-sqr-sqrt-0.0%
sqrt-unprod61.7%
sqr-neg61.7%
sqrt-unprod34.8%
add-sqr-sqrt34.8%
/-rgt-identity34.8%
clear-num34.8%
clear-num34.8%
frac-2neg34.8%
metadata-eval34.8%
frac-add47.8%
*-un-lft-identity47.8%
add-sqr-sqrt-0.0%
sqrt-unprod47.7%
sqr-neg47.7%
sqrt-unprod47.7%
add-sqr-sqrt47.7%
div-inv47.7%
metadata-eval47.7%
div-inv47.7%
metadata-eval47.7%
Applied egg-rr48.2%
associate-*l*48.2%
metadata-eval48.2%
associate-*l*48.2%
Simplified48.2%
Final simplification48.7%
(FPCore (x s) :precision binary32 (if (<= (- x) 3.499999888929329e-21) 0.5 (* (/ 1.0 (* x (- (* s 2.0) x))) (* x s))))
float code(float x, float s) {
float tmp;
if (-x <= 3.499999888929329e-21f) {
tmp = 0.5f;
} else {
tmp = (1.0f / (x * ((s * 2.0f) - 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 <= 3.499999888929329e-21) then
tmp = 0.5e0
else
tmp = (1.0e0 / (x * ((s * 2.0e0) - x))) * (x * s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(3.499999888929329e-21)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(1.0) / Float32(x * Float32(Float32(s * Float32(2.0)) - x))) * Float32(x * s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(3.499999888929329e-21)) tmp = single(0.5); else tmp = (single(1.0) / (x * ((s * single(2.0)) - x))) * (x * s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 3.499999888929329 \cdot 10^{-21}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(s \cdot 2 - x\right)} \cdot \left(x \cdot s\right)\\
\end{array}
\end{array}
if (neg.f32 x) < 3.49999989e-21Initial program 99.8%
Taylor expanded in x around 0 45.2%
if 3.49999989e-21 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 41.6%
neg-mul-141.6%
unsub-neg41.6%
Simplified41.6%
Taylor expanded in x around inf 42.4%
associate-*r/42.4%
metadata-eval42.4%
Simplified42.4%
associate-/r*40.1%
frac-sub46.0%
associate-/r/49.1%
*-rgt-identity49.1%
*-commutative49.1%
fmm-def49.1%
Applied egg-rr49.1%
associate-/l/50.1%
*-commutative50.1%
fmm-undef50.1%
*-commutative50.1%
Simplified50.1%
Final simplification46.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -20.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (+ 2.0 (* x (/ -1.0 s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -20.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / (2.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) :: tmp
if ((x / -s) <= (-20.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / (2.0e0 + (x * ((-1.0e0) / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-20.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 * Float32(Float32(-1.0) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-20.0)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / (single(2.0) + (x * (single(-1.0) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -20:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -20Initial program 100.0%
Taylor expanded in x around 0 5.2%
neg-mul-15.2%
unsub-neg5.2%
Simplified5.2%
Taylor expanded in x around inf 5.2%
associate-*r/5.2%
metadata-eval5.2%
Simplified5.2%
Taylor expanded in x around 0 28.1%
if -20 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 57.0%
neg-mul-157.0%
unsub-neg57.0%
Simplified57.0%
clear-num57.0%
associate-/r/57.6%
Applied egg-rr57.6%
Final simplification45.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -20.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) <= -20.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) <= (-20.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(-20.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(-20.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 -20:\\
\;\;\;\;\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) < -20Initial program 100.0%
Taylor expanded in x around 0 5.2%
neg-mul-15.2%
unsub-neg5.2%
Simplified5.2%
Taylor expanded in x around inf 5.2%
associate-*r/5.2%
metadata-eval5.2%
Simplified5.2%
Taylor expanded in x around 0 28.1%
if -20 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 57.0%
neg-mul-157.0%
unsub-neg57.0%
Simplified57.0%
expm1-log1p-u57.0%
Applied egg-rr57.0%
expm1-undefine57.0%
sub-neg57.0%
log1p-undefine56.9%
rem-exp-log57.0%
associate-+r-57.1%
metadata-eval57.1%
metadata-eval57.1%
Simplified57.1%
Final simplification44.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -20.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -20.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) <= (-20.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(-20.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(-20.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 -20:\\
\;\;\;\;\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) < -20Initial program 100.0%
Taylor expanded in x around 0 5.2%
neg-mul-15.2%
unsub-neg5.2%
Simplified5.2%
Taylor expanded in x around inf 5.2%
associate-*r/5.2%
metadata-eval5.2%
Simplified5.2%
Taylor expanded in x around 0 28.1%
if -20 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 57.0%
neg-mul-157.0%
unsub-neg57.0%
Simplified57.0%
Final simplification44.8%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 2.0) 0.5 (/ 1.0 (* x (/ -1.0 s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 2.0f) {
tmp = 0.5f;
} 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) :: tmp
if ((x / -s) <= 2.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x * ((-1.0e0) / 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 * Float32(Float32(-1.0) / 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 * (single(-1.0) / 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}{x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 48.9%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 34.4%
neg-mul-134.4%
unsub-neg34.4%
Simplified34.4%
Taylor expanded in x around inf 35.3%
associate-*r/35.3%
metadata-eval35.3%
Simplified35.3%
Taylor expanded in x around inf 35.2%
Final simplification44.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 48.9%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 34.4%
neg-mul-134.4%
unsub-neg34.4%
Simplified34.4%
Taylor expanded in x around inf 34.4%
associate-*r/34.4%
neg-mul-134.4%
Simplified34.4%
Final simplification43.7%
(FPCore (x s) :precision binary32 (if (<= x -2.800000054037355e-8) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.800000054037355e-8f) {
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 <= (-2.800000054037355e-8)) 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(-2.800000054037355e-8)) 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(-2.800000054037355e-8)) 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 -2.800000054037355 \cdot 10^{-8}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.80000005e-8Initial program 100.0%
Taylor expanded in x around 0 42.8%
neg-mul-142.8%
unsub-neg42.8%
Simplified42.8%
Taylor expanded in x around inf 39.5%
associate-*r/39.5%
neg-mul-139.5%
Simplified39.5%
clear-num42.8%
inv-pow42.8%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod42.5%
add-sqr-sqrt42.5%
Applied egg-rr42.5%
unpow-142.5%
Simplified42.5%
if -2.80000005e-8 < x Initial program 99.8%
Taylor expanded in x around 0 43.9%
(FPCore (x s) :precision binary32 (if (<= x -1.999999987845058e-8) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.999999987845058e-8f) {
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.999999987845058e-8)) 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.999999987845058e-8)) 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.999999987845058e-8)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.999999987845058 \cdot 10^{-8}:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.99999999e-8Initial program 99.8%
Taylor expanded in x around 0 42.3%
neg-mul-142.3%
unsub-neg42.3%
Simplified42.3%
Taylor expanded in x around inf 39.1%
associate-*r/39.1%
neg-mul-139.1%
Simplified39.1%
if -1.99999999e-8 < x Initial program 99.8%
Taylor expanded in x around 0 44.1%
Final simplification42.7%
(FPCore (x s) :precision binary32 (if (<= x -2.800000054037355e-8) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -2.800000054037355e-8f) {
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 <= (-2.800000054037355e-8)) 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(-2.800000054037355e-8)) 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(-2.800000054037355e-8)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.800000054037355 \cdot 10^{-8}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2.80000005e-8Initial program 100.0%
Taylor expanded in x around 0 42.8%
neg-mul-142.8%
unsub-neg42.8%
Simplified42.8%
Taylor expanded in x around inf 39.5%
associate-*r/39.5%
neg-mul-139.5%
Simplified39.5%
add-sqr-sqrt-0.0%
sqrt-unprod58.4%
sqr-neg58.4%
sqrt-unprod39.2%
add-sqr-sqrt39.2%
div-inv39.2%
Applied egg-rr39.2%
associate-*r/39.2%
*-rgt-identity39.2%
Simplified39.2%
if -2.80000005e-8 < x Initial program 99.8%
Taylor expanded in x around 0 43.9%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 33.7%
herbie shell --seed 2024181
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))