
(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 13 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-prod87.5%
neg-mul-187.5%
exp-prod87.5%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
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%
Final simplification99.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-prod87.5%
neg-mul-187.5%
exp-prod87.5%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ x (- s))))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((x / -s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((x / -s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(x / Float32(-s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((x / -s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{x}{-s}}}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -2.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 INFINITY)
(/ 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 t_0 = -x / s;
float tmp;
if (t_0 <= -2.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= ((float) INFINITY)) {
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;
}
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-2.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (t_0 <= Float32(Inf)) 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) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(-2.0)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (t_0 <= single(Inf)) 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}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq -2:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\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 (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
Taylor expanded in x around 0 5.1%
mul-1-neg5.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 -2 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 99.8%
Taylor expanded in x around 0 70.0%
mul-1-neg70.0%
unsub-neg70.0%
Simplified70.0%
sub-neg70.0%
neg-mul-170.0%
rem-log-exp97.2%
pow-exp97.2%
flip-+42.0%
metadata-eval42.0%
pow-exp42.0%
rem-log-exp42.0%
neg-mul-142.0%
pow-exp42.0%
rem-log-exp42.3%
neg-mul-142.3%
distribute-neg-frac242.3%
distribute-neg-frac242.3%
pow-exp42.3%
rem-log-exp62.0%
neg-mul-162.0%
distribute-neg-frac262.0%
Applied egg-rr62.0%
clear-num62.0%
frac-times64.4%
*-un-lft-identity64.4%
add-sqr-sqrt-0.0%
sqrt-unprod61.2%
sqr-neg61.2%
sqrt-unprod64.4%
add-sqr-sqrt64.4%
add-sqr-sqrt-0.0%
sqrt-unprod61.2%
sqr-neg61.2%
sqrt-unprod64.4%
add-sqr-sqrt64.4%
Applied egg-rr64.4%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 43.6%
mul-1-neg43.6%
unsub-neg43.6%
Simplified43.6%
Taylor expanded in x around inf 43.2%
associate-*r/43.2%
metadata-eval43.2%
Simplified43.2%
frac-sub37.6%
*-commutative37.6%
Applied egg-rr37.6%
*-rgt-identity37.6%
Simplified37.6%
Final simplification49.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 2.0)
0.5
(if (<= t_0 INFINITY)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (/ x s)))
(/ -1.0 (* x (/ (- x (* s 2.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 <= ((float) INFINITY)) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / (x / s));
} else {
tmp = -1.0f / (x * ((x - (s * 2.0f)) / (x * s)));
}
return tmp;
}
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(2.0)) tmp = 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(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) t_0 = -x / s; tmp = single(0.0); if (t_0 <= single(2.0)) tmp = single(0.5); elseif (t_0 <= single(Inf)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / (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}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2Initial program 99.9%
Taylor expanded in x around 0 52.6%
if 2 < (/.f32 (neg.f32 x) s) < +inf.0Initial program 99.8%
Taylor expanded in x around 0 50.3%
mul-1-neg50.3%
unsub-neg50.3%
Simplified50.3%
sub-neg50.3%
neg-mul-150.3%
rem-log-exp98.9%
pow-exp98.9%
flip-+0.1%
metadata-eval0.1%
pow-exp0.1%
rem-log-exp0.1%
neg-mul-10.1%
pow-exp0.1%
rem-log-exp0.8%
neg-mul-10.8%
distribute-neg-frac20.8%
distribute-neg-frac20.8%
pow-exp0.8%
rem-log-exp35.9%
neg-mul-135.9%
distribute-neg-frac235.9%
Applied egg-rr35.9%
Taylor expanded in x around inf 35.9%
if +inf.0 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 43.6%
mul-1-neg43.6%
unsub-neg43.6%
Simplified43.6%
Taylor expanded in x around inf 43.2%
associate-*r/43.2%
metadata-eval43.2%
Simplified43.2%
frac-sub37.6%
*-commutative37.6%
Applied egg-rr37.6%
*-rgt-identity37.6%
Simplified37.6%
Final simplification47.1%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 2.0000000233721948e-7) 0.5 (/ -1.0 (* x (/ (- x (* s 2.0)) (* x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 2.0000000233721948e-7f) {
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 / s) <= 2.0000000233721948e-7) 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(Float32(-x) / s) <= Float32(2.0000000233721948e-7)) 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 / s) <= single(2.0000000233721948e-7)) 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}\;\frac{-x}{s} \leq 2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{x - s \cdot 2}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2.00000002e-7Initial program 99.9%
Taylor expanded in x around 0 52.6%
if 2.00000002e-7 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 52.4%
mul-1-neg52.4%
unsub-neg52.4%
Simplified52.4%
Taylor expanded in x around inf 52.4%
associate-*r/52.4%
metadata-eval52.4%
Simplified52.4%
frac-sub57.8%
*-commutative57.8%
Applied egg-rr57.8%
*-rgt-identity57.8%
Simplified57.8%
Final simplification54.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -2.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -2.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) <= (-2.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(-2.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(-2.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 -2:\\
\;\;\;\;\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) < -2Initial program 99.9%
Taylor expanded in x around 0 5.1%
mul-1-neg5.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 -2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 70.0%
mul-1-neg70.0%
unsub-neg70.0%
Simplified70.0%
Final simplification53.0%
(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 52.6%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 50.3%
mul-1-neg50.3%
unsub-neg50.3%
Simplified50.3%
Taylor expanded in x around inf 50.3%
associate-*r/50.3%
metadata-eval50.3%
Simplified50.3%
Taylor expanded in x around inf 50.3%
Final simplification51.8%
(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(Float32(-x) / 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 52.6%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 50.3%
mul-1-neg50.3%
unsub-neg50.3%
Simplified50.3%
sub-neg50.3%
neg-mul-150.3%
rem-log-exp98.9%
pow-exp98.9%
flip-+0.1%
metadata-eval0.1%
pow-exp0.1%
rem-log-exp0.1%
neg-mul-10.1%
pow-exp0.1%
rem-log-exp0.8%
neg-mul-10.8%
distribute-neg-frac20.8%
distribute-neg-frac20.8%
pow-exp0.8%
rem-log-exp35.9%
neg-mul-135.9%
distribute-neg-frac235.9%
Applied egg-rr35.9%
Taylor expanded in x around inf 50.3%
associate-*r/50.3%
neg-mul-150.3%
Simplified50.3%
Final simplification51.8%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.0005000000237487257) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 0.0005000000237487257f) {
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 <= 0.0005000000237487257e0) 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(0.0005000000237487257)) 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(0.0005000000237487257)) 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 0.0005000000237487257:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 5.00000024e-4Initial program 99.8%
Taylor expanded in x around 0 48.6%
if 5.00000024e-4 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 59.9%
mul-1-neg59.9%
unsub-neg59.9%
Simplified59.9%
Taylor expanded in x around inf 59.9%
mul-1-neg59.9%
distribute-frac-neg259.9%
Simplified59.9%
Final simplification51.7%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.0005000000237487257) 0.5 (* s (/ -1.0 x))))
float code(float x, float s) {
float tmp;
if (-x <= 0.0005000000237487257f) {
tmp = 0.5f;
} else {
tmp = s * (-1.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 <= 0.0005000000237487257e0) then
tmp = 0.5e0
else
tmp = s * ((-1.0e0) / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(0.0005000000237487257)) tmp = Float32(0.5); else tmp = Float32(s * Float32(Float32(-1.0) / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(0.0005000000237487257)) tmp = single(0.5); else tmp = s * (single(-1.0) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 0.0005000000237487257:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;s \cdot \frac{-1}{x}\\
\end{array}
\end{array}
if (neg.f32 x) < 5.00000024e-4Initial program 99.8%
Taylor expanded in x around 0 48.6%
if 5.00000024e-4 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 59.9%
mul-1-neg59.9%
unsub-neg59.9%
Simplified59.9%
sub-neg59.9%
neg-mul-159.9%
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.3%
neg-mul-10.3%
distribute-neg-frac20.3%
distribute-neg-frac20.3%
pow-exp0.3%
rem-log-exp38.4%
neg-mul-138.4%
distribute-neg-frac238.4%
Applied egg-rr38.4%
Taylor expanded in x around inf 59.9%
associate-*r/59.9%
neg-mul-159.9%
Simplified59.9%
associate-/r/54.5%
Applied egg-rr54.5%
Final simplification50.2%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
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.0020000000949949026e0)) 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.0020000000949949026)) 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(-0.0020000000949949026)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0020000000949949026:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 100.0%
Taylor expanded in x around 0 59.9%
mul-1-neg59.9%
unsub-neg59.9%
Simplified59.9%
Taylor expanded in x around inf 54.5%
associate-*r/54.5%
neg-mul-154.5%
Simplified54.5%
if -0.00200000009 < x Initial program 99.8%
Taylor expanded in x around 0 48.6%
Final simplification50.2%
(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 37.2%
herbie shell --seed 2024103
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))