
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (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-prod82.8%
neg-mul-182.8%
exp-prod82.8%
pow-pow99.9%
div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
distribute-frac-neg299.8%
unpow-199.8%
exp-to-pow99.8%
log1p-undefine99.8%
*-commutative99.8%
neg-mul-199.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (pow (exp -1.0) (/ x s)) 1.0)))
float code(float x, float s) {
return 1.0f / (powf(expf(-1.0f), (x / s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((exp((-1.0e0)) ** (x / s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32((exp(Float32(-1.0)) ^ Float32(x / s)) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / ((exp(single(-1.0)) ^ (x / s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{{\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)} + 1}
\end{array}
Initial program 99.8%
div-inv99.8%
exp-prod82.8%
neg-mul-182.8%
exp-prod82.8%
pow-pow99.9%
div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (exp (/ (- x) s)) 1.0)))
float code(float x, float s) {
return 1.0f / (expf((-x / s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (exp((-x / s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32(exp(Float32(Float32(-x) / s)) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / (exp((-x / s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{e^{\frac{-x}{s}} + 1}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(if (<= (- x) -1.9999999774532045e-26)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= (- x) 8.500000346269318e+20)
(/ 1.0 (/ (+ 4.0 (* x (/ (/ x s) s))) (+ (/ x s) 2.0)))
(/ -1.0 (* x (/ (- x (* s 2.0)) (* x s)))))))
float code(float x, float s) {
float tmp;
if (-x <= -1.9999999774532045e-26f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (-x <= 8.500000346269318e+20f) {
tmp = 1.0f / ((4.0f + (x * ((x / s) / s))) / ((x / s) + 2.0f));
} 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 <= (-1.9999999774532045e-26)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else if (-x <= 8.500000346269318e+20) then
tmp = 1.0e0 / ((4.0e0 + (x * ((x / s) / s))) / ((x / s) + 2.0e0))
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(-1.9999999774532045e-26)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (Float32(-x) <= Float32(8.500000346269318e+20)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) + Float32(x * Float32(Float32(x / s) / s))) / Float32(Float32(x / s) + Float32(2.0)))); 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 <= single(-1.9999999774532045e-26)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (-x <= single(8.500000346269318e+20)) tmp = single(1.0) / ((single(4.0) + (x * ((x / s) / s))) / ((x / s) + single(2.0))); 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}\;-x \leq -1.9999999774532045 \cdot 10^{-26}:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;-x \leq 8.500000346269318 \cdot 10^{+20}:\\
\;\;\;\;\frac{1}{\frac{4 + x \cdot \frac{\frac{x}{s}}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.99999998e-26Initial program 100.0%
Taylor expanded in x around 0 14.2%
mul-1-neg14.2%
unsub-neg14.2%
Simplified14.2%
Taylor expanded in x around inf 14.2%
sub-neg14.2%
associate-*r/14.2%
metadata-eval14.2%
distribute-neg-frac14.2%
metadata-eval14.2%
Simplified14.2%
Taylor expanded in x around 0 34.5%
if -1.99999998e-26 < (neg.f32 x) < 8.50000035e20Initial program 99.7%
Taylor expanded in x around 0 47.9%
mul-1-neg47.9%
unsub-neg47.9%
Simplified47.9%
sub-neg47.9%
neg-mul-147.9%
rem-log-exp92.0%
pow-exp92.0%
flip-+36.7%
metadata-eval36.7%
pow-exp36.7%
rem-log-exp36.7%
neg-mul-136.7%
pow-exp36.7%
rem-log-exp37.6%
neg-mul-137.6%
distribute-neg-frac237.6%
distribute-neg-frac237.6%
pow-exp37.6%
rem-log-exp60.5%
neg-mul-160.5%
distribute-neg-frac260.5%
Applied egg-rr60.5%
associate-*l/60.5%
neg-mul-160.5%
times-frac65.2%
add-sqr-sqrt-0.0%
sqrt-unprod64.6%
sqr-neg64.6%
sqrt-unprod65.1%
add-sqr-sqrt65.1%
Applied egg-rr65.1%
if 8.50000035e20 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 73.8%
mul-1-neg73.8%
unsub-neg73.8%
Simplified73.8%
Taylor expanded in x around inf 73.8%
sub-neg73.8%
associate-*r/73.8%
metadata-eval73.8%
distribute-neg-frac73.8%
metadata-eval73.8%
Simplified73.8%
frac-add73.8%
*-commutative73.8%
neg-mul-173.8%
fma-define73.8%
Applied egg-rr73.8%
fma-undefine73.8%
unsub-neg73.8%
*-commutative73.8%
Simplified73.8%
Final simplification52.7%
(FPCore (x s)
:precision binary32
(if (<= (- x) -1.000000046701102e-34)
0.5
(if (<= (- x) 8.500000346269318e+20)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ (/ x s) 2.0)))
(/ -1.0 (* x (/ (- x (* s 2.0)) (* x s)))))))
float code(float x, float s) {
float tmp;
if (-x <= -1.000000046701102e-34f) {
tmp = 0.5f;
} else if (-x <= 8.500000346269318e+20f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / ((x / s) + 2.0f));
} 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 <= (-1.000000046701102e-34)) then
tmp = 0.5e0
else if (-x <= 8.500000346269318e+20) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / ((x / s) + 2.0e0))
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(-1.000000046701102e-34)) tmp = Float32(0.5); elseif (Float32(-x) <= Float32(8.500000346269318e+20)) 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 * 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 <= single(-1.000000046701102e-34)) tmp = single(0.5); elseif (-x <= single(8.500000346269318e+20)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / ((x / s) + single(2.0))); 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}\;-x \leq -1.000000046701102 \cdot 10^{-34}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;-x \leq 8.500000346269318 \cdot 10^{+20}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.00000005e-34Initial program 100.0%
Taylor expanded in x around 0 39.2%
if -1.00000005e-34 < (neg.f32 x) < 8.50000035e20Initial program 99.6%
Taylor expanded in x around 0 44.3%
mul-1-neg44.3%
unsub-neg44.3%
Simplified44.3%
sub-neg44.3%
neg-mul-144.3%
rem-log-exp94.4%
pow-exp94.4%
flip-+31.7%
metadata-eval31.7%
pow-exp31.7%
rem-log-exp31.7%
neg-mul-131.7%
pow-exp31.7%
rem-log-exp32.7%
neg-mul-132.7%
distribute-neg-frac232.7%
distribute-neg-frac232.7%
pow-exp32.7%
rem-log-exp58.6%
neg-mul-158.6%
distribute-neg-frac258.6%
Applied egg-rr58.6%
distribute-frac-neg258.6%
distribute-frac-neg258.6%
sqr-neg58.6%
clear-num58.6%
frac-times60.4%
*-un-lft-identity60.4%
Applied egg-rr60.4%
if 8.50000035e20 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 73.8%
mul-1-neg73.8%
unsub-neg73.8%
Simplified73.8%
Taylor expanded in x around inf 73.8%
sub-neg73.8%
associate-*r/73.8%
metadata-eval73.8%
distribute-neg-frac73.8%
metadata-eval73.8%
Simplified73.8%
frac-add73.8%
*-commutative73.8%
neg-mul-173.8%
fma-define73.8%
Applied egg-rr73.8%
fma-undefine73.8%
unsub-neg73.8%
*-commutative73.8%
Simplified73.8%
Final simplification51.4%
(FPCore (x s)
:precision binary32
(if (<= (- x) 4.999999873689376e-5)
0.5
(if (<= (- x) 8.500000346269318e+20)
(/ -1.0 (/ (- (* (/ x s) (/ x s)) 4.0) (/ x s)))
(/ -1.0 (* x (/ (- x (* s 2.0)) (* x s)))))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999873689376e-5f) {
tmp = 0.5f;
} else if (-x <= 8.500000346269318e+20f) {
tmp = -1.0f / ((((x / s) * (x / s)) - 4.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 <= 4.999999873689376e-5) then
tmp = 0.5e0
else if (-x <= 8.500000346269318e+20) then
tmp = (-1.0e0) / ((((x / s) * (x / s)) - 4.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(4.999999873689376e-5)) tmp = Float32(0.5); elseif (Float32(-x) <= Float32(8.500000346269318e+20)) tmp = Float32(Float32(-1.0) / Float32(Float32(Float32(Float32(x / s) * Float32(x / s)) - Float32(4.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 <= single(4.999999873689376e-5)) tmp = single(0.5); elseif (-x <= single(8.500000346269318e+20)) tmp = single(-1.0) / ((((x / s) * (x / s)) - single(4.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}\;-x \leq 4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;-x \leq 8.500000346269318 \cdot 10^{+20}:\\
\;\;\;\;\frac{-1}{\frac{\frac{x}{s} \cdot \frac{x}{s} - 4}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 4.99999987e-5Initial program 99.8%
Taylor expanded in x around 0 44.5%
if 4.99999987e-5 < (neg.f32 x) < 8.50000035e20Initial program 99.8%
Taylor expanded in x around 0 24.8%
mul-1-neg24.8%
unsub-neg24.8%
Simplified24.8%
sub-neg24.8%
neg-mul-124.8%
rem-log-exp98.1%
pow-exp98.1%
flip-+0.3%
metadata-eval0.3%
pow-exp0.3%
rem-log-exp0.3%
neg-mul-10.3%
pow-exp0.3%
rem-log-exp1.3%
neg-mul-11.3%
distribute-neg-frac21.3%
distribute-neg-frac21.3%
pow-exp1.3%
rem-log-exp53.9%
neg-mul-153.9%
distribute-neg-frac253.9%
Applied egg-rr53.9%
Taylor expanded in x around inf 53.9%
if 8.50000035e20 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 73.8%
mul-1-neg73.8%
unsub-neg73.8%
Simplified73.8%
Taylor expanded in x around inf 73.8%
sub-neg73.8%
associate-*r/73.8%
metadata-eval73.8%
distribute-neg-frac73.8%
metadata-eval73.8%
Simplified73.8%
frac-add73.8%
*-commutative73.8%
neg-mul-173.8%
fma-define73.8%
Applied egg-rr73.8%
fma-undefine73.8%
unsub-neg73.8%
*-commutative73.8%
Simplified73.8%
Final simplification49.4%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.999999898305949e-32) 0.5 (/ -1.0 (* x (/ (- x (* s 2.0)) (* x s))))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999898305949e-32f) {
tmp = 0.5f;
} 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 <= 4.999999898305949e-32) then
tmp = 0.5e0
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(4.999999898305949e-32)) tmp = Float32(0.5); 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 <= single(4.999999898305949e-32)) tmp = single(0.5); 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}\;-x \leq 4.999999898305949 \cdot 10^{-32}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 4.9999999e-32Initial program 99.9%
Taylor expanded in x around 0 44.1%
if 4.9999999e-32 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 45.8%
mul-1-neg45.8%
unsub-neg45.8%
Simplified45.8%
Taylor expanded in x around inf 45.7%
sub-neg45.7%
associate-*r/45.7%
metadata-eval45.7%
distribute-neg-frac45.7%
metadata-eval45.7%
Simplified45.7%
frac-add47.6%
*-commutative47.6%
neg-mul-147.6%
fma-define47.6%
Applied egg-rr47.6%
fma-undefine47.6%
unsub-neg47.6%
*-commutative47.6%
Simplified47.6%
Final simplification45.7%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.000000046701102e-34) 0.5 (/ -1.0 (/ (- x (* s 2.0)) s))))
float code(float x, float s) {
float tmp;
if (-x <= -1.000000046701102e-34f) {
tmp = 0.5f;
} else {
tmp = -1.0f / ((x - (s * 2.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 <= (-1.000000046701102e-34)) then
tmp = 0.5e0
else
tmp = (-1.0e0) / ((x - (s * 2.0e0)) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-1.000000046701102e-34)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(Float32(x - Float32(s * Float32(2.0))) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-1.000000046701102e-34)) tmp = single(0.5); else tmp = single(-1.0) / ((x - (s * single(2.0))) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -1.000000046701102 \cdot 10^{-34}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x - s \cdot 2}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.00000005e-34Initial program 100.0%
Taylor expanded in x around 0 39.2%
if -1.00000005e-34 < (neg.f32 x) Initial program 99.7%
Taylor expanded in x around 0 50.7%
mul-1-neg50.7%
unsub-neg50.7%
Simplified50.7%
Taylor expanded in s around 0 50.7%
*-commutative50.7%
Simplified50.7%
Final simplification45.0%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.000000046701102e-34) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -1.000000046701102e-34f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (2.0f - (x / s));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= (-1.000000046701102e-34)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 - (x / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-1.000000046701102e-34)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-1.000000046701102e-34)) tmp = single(0.5); else tmp = single(1.0) / (single(2.0) - (x / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -1.000000046701102 \cdot 10^{-34}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.00000005e-34Initial program 100.0%
Taylor expanded in x around 0 39.2%
if -1.00000005e-34 < (neg.f32 x) Initial program 99.7%
Taylor expanded in x around 0 50.7%
mul-1-neg50.7%
unsub-neg50.7%
Simplified50.7%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.999999873689376e-5) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999873689376e-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 <= 4.999999873689376e-5) 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(4.999999873689376e-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 <= single(4.999999873689376e-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}\;-x \leq 4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 4.99999987e-5Initial program 99.8%
Taylor expanded in x around 0 44.5%
if 4.99999987e-5 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 43.1%
mul-1-neg43.1%
unsub-neg43.1%
Simplified43.1%
Taylor expanded in x around inf 43.1%
mul-1-neg43.1%
distribute-frac-neg243.1%
Simplified43.1%
Final simplification44.1%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.999999873689376e-5) 0.5 (/ 1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999873689376e-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 <= 4.999999873689376e-5) 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(4.999999873689376e-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 <= single(4.999999873689376e-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}\;-x \leq 4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 4.99999987e-5Initial program 99.8%
Taylor expanded in x around 0 44.5%
if 4.99999987e-5 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 43.1%
mul-1-neg43.1%
unsub-neg43.1%
Simplified43.1%
sub-neg43.1%
neg-mul-143.1%
rem-log-exp98.8%
pow-exp98.8%
flip-+0.2%
metadata-eval0.2%
pow-exp0.2%
rem-log-exp0.2%
neg-mul-10.2%
pow-exp0.2%
rem-log-exp0.8%
neg-mul-10.8%
distribute-neg-frac20.8%
distribute-neg-frac20.8%
pow-exp0.8%
rem-log-exp45.7%
neg-mul-145.7%
distribute-neg-frac245.7%
Applied egg-rr45.7%
distribute-frac-neg245.7%
distribute-frac-neg245.7%
sqr-neg45.7%
clear-num45.7%
frac-2neg45.7%
frac-times45.7%
*-un-lft-identity45.7%
add-sqr-sqrt-0.0%
sqrt-unprod45.6%
sqr-neg45.6%
sqrt-unprod45.6%
add-sqr-sqrt45.6%
Applied egg-rr45.6%
Taylor expanded in x around inf 43.0%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.999999873689376e-5) 0.5 (/ s (- x))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999873689376e-5f) {
tmp = 0.5f;
} else {
tmp = 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-5) then
tmp = 0.5e0
else
tmp = s / -x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(4.999999873689376e-5)) tmp = Float32(0.5); else tmp = Float32(s / Float32(-x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(4.999999873689376e-5)) tmp = single(0.5); else tmp = s / -x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{-x}\\
\end{array}
\end{array}
if (neg.f32 x) < 4.99999987e-5Initial program 99.8%
Taylor expanded in x around 0 44.5%
if 4.99999987e-5 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 43.1%
mul-1-neg43.1%
unsub-neg43.1%
Simplified43.1%
Taylor expanded in x around inf 39.2%
mul-1-neg39.2%
distribute-neg-frac239.2%
Simplified39.2%
(FPCore (x s) :precision binary32 (if (<= x -0.0005000000237487257) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0005000000237487257f) {
tmp = s / x;
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-0.0005000000237487257e0)) then
tmp = s / x
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.0005000000237487257)) tmp = Float32(s / x); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.0005000000237487257)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -5.00000024e-4Initial program 99.9%
Taylor expanded in x around 0 43.1%
mul-1-neg43.1%
unsub-neg43.1%
Simplified43.1%
sub-neg43.1%
neg-mul-143.1%
rem-log-exp98.8%
pow-exp98.8%
flip-+0.2%
metadata-eval0.2%
pow-exp0.2%
rem-log-exp0.2%
neg-mul-10.2%
pow-exp0.2%
rem-log-exp0.8%
neg-mul-10.8%
distribute-neg-frac20.8%
distribute-neg-frac20.8%
pow-exp0.8%
rem-log-exp45.7%
neg-mul-145.7%
distribute-neg-frac245.7%
Applied egg-rr45.7%
distribute-frac-neg245.7%
distribute-frac-neg245.7%
sqr-neg45.7%
clear-num45.7%
frac-2neg45.7%
frac-times45.7%
*-un-lft-identity45.7%
add-sqr-sqrt-0.0%
sqrt-unprod45.6%
sqr-neg45.6%
sqrt-unprod45.6%
add-sqr-sqrt45.6%
Applied egg-rr45.6%
Taylor expanded in x around inf 39.1%
if -5.00000024e-4 < x Initial program 99.8%
Taylor expanded in x around 0 44.5%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 33.3%
herbie shell --seed 2024096
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))