
(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 17 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%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
add-exp-log99.8%
log-rec99.8%
log1p-expm1-u99.8%
log1p-define99.8%
expm1-log1p-u99.8%
rec-exp99.8%
distribute-neg-frac99.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
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -20.0)
(- 1.0 (/ s x))
(if (<= t_0 0.004999999888241291)
(+ 0.5 (/ (* x 0.25) s))
(/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -20.0f) {
tmp = 1.0f - (s / x);
} else if (t_0 <= 0.004999999888241291f) {
tmp = 0.5f + ((x * 0.25f) / 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 <= (-20.0e0)) then
tmp = 1.0e0 - (s / x)
else if (t_0 <= 0.004999999888241291e0) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-20.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (t_0 <= Float32(0.004999999888241291)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / 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(-20.0)) tmp = single(1.0) - (s / x); elseif (t_0 <= single(0.004999999888241291)) tmp = single(0.5) + ((x * single(0.25)) / 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 -20:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 0.004999999888241291:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in x around inf 98.3%
neg-mul-198.3%
unsub-neg98.3%
Simplified98.3%
if -20 < (/.f32 (neg.f32 x) s) < 0.00499999989Initial program 99.7%
Taylor expanded in x around 0 98.2%
associate-*r/98.2%
Simplified98.2%
if 0.00499999989 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 37.0%
mul-1-neg37.0%
unsub-neg37.0%
Simplified37.0%
Taylor expanded in x around inf 36.9%
mul-1-neg36.9%
distribute-frac-neg36.9%
Simplified36.9%
Final simplification75.3%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -20.0)
(/ 1.0 (+ 1.0 (/ s x)))
(if (<= t_0 0.004999999888241291)
(+ 0.5 (/ (* x 0.25) s))
(/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -20.0f) {
tmp = 1.0f / (1.0f + (s / x));
} else if (t_0 <= 0.004999999888241291f) {
tmp = 0.5f + ((x * 0.25f) / 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 <= (-20.0e0)) then
tmp = 1.0e0 / (1.0e0 + (s / x))
else if (t_0 <= 0.004999999888241291e0) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(-x) / s) tmp = Float32(0.0) if (t_0 <= Float32(-20.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / x))); elseif (t_0 <= Float32(0.004999999888241291)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / 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(-20.0)) tmp = single(1.0) / (single(1.0) + (s / x)); elseif (t_0 <= single(0.004999999888241291)) tmp = single(0.5) + ((x * single(0.25)) / 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 -20:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\mathbf{elif}\;t\_0 \leq 0.004999999888241291:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in x around inf 98.3%
if -20 < (/.f32 (neg.f32 x) s) < 0.00499999989Initial program 99.7%
Taylor expanded in x around 0 98.2%
associate-*r/98.2%
Simplified98.2%
if 0.00499999989 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 37.0%
mul-1-neg37.0%
unsub-neg37.0%
Simplified37.0%
Taylor expanded in x around inf 36.9%
mul-1-neg36.9%
distribute-frac-neg36.9%
Simplified36.9%
Final simplification75.3%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -2.0)
(- 1.0 (/ s x))
(if (<= t_0 0.004999999888241291) 0.5 (/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -2.0f) {
tmp = 1.0f - (s / x);
} else if (t_0 <= 0.004999999888241291f) {
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) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-2.0e0)) then
tmp = 1.0e0 - (s / x)
else if (t_0 <= 0.004999999888241291e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
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(s / x)); elseif (t_0 <= Float32(0.004999999888241291)) tmp = Float32(0.5); 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(1.0) - (s / x); elseif (t_0 <= single(0.004999999888241291)) tmp = single(0.5); 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:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;t\_0 \leq 0.004999999888241291:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
Taylor expanded in x around inf 97.6%
neg-mul-197.6%
unsub-neg97.6%
Simplified97.6%
if -2 < (/.f32 (neg.f32 x) s) < 0.00499999989Initial program 99.8%
Taylor expanded in x around 0 91.8%
if 0.00499999989 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 37.0%
mul-1-neg37.0%
unsub-neg37.0%
Simplified37.0%
Taylor expanded in x around inf 36.9%
mul-1-neg36.9%
distribute-frac-neg36.9%
Simplified36.9%
Final simplification73.6%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) (/ 1.0 (+ 1.0 (/ 1.0 (- 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (* (/ x s) (+ (/ x s) -1.0))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f - (x / s))));
} else {
tmp = 1.0f / (2.0f + ((x / s) * ((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) <= (-2.0e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 - (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((x / s) * ((x / s) + (-1.0e0))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-2.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(2.0) + Float32(Float32(x / s) * Float32(Float32(x / s) + Float32(-1.0))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(-2.0)) 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) * ((x / s) + single(-1.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -2:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 - \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{x}{s} \cdot \left(\frac{x}{s} + -1\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
frac-2neg97.7%
metadata-eval97.7%
div-inv97.7%
distribute-neg-in97.7%
distribute-frac-neg97.7%
add-sqr-sqrt-0.0%
sqrt-unprod96.8%
sqr-neg96.8%
sqrt-unprod97.8%
add-sqr-sqrt97.8%
metadata-eval97.8%
Applied egg-rr97.8%
mul-1-neg97.8%
distribute-neg-frac297.8%
neg-sub097.8%
+-commutative97.8%
associate--r+97.8%
metadata-eval97.8%
Simplified97.8%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 40.7%
+-commutative40.7%
Simplified40.7%
Taylor expanded in x around 0 77.0%
+-commutative77.0%
unpow277.0%
unpow277.0%
times-frac78.4%
distribute-rgt-out78.4%
Simplified78.4%
Final simplification86.2%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) (/ 1.0 (+ 1.0 (/ 1.0 (- 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (* x (/ (+ (/ x s) -1.0) s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f - (x / s))));
} else {
tmp = 1.0f / (2.0f + (x * (((x / s) + -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 = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 - (x / s))))
else
tmp = 1.0e0 / (2.0e0 + (x * (((x / s) + (-1.0e0)) / 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(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 * Float32(Float32(Float32(x / s) + 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(1.0) / (single(1.0) + (single(1.0) / (single(1.0) - (x / s)))); else tmp = single(1.0) / (single(2.0) + (x * (((x / s) + single(-1.0)) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -2:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 - \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{\frac{x}{s} + -1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
frac-2neg97.7%
metadata-eval97.7%
div-inv97.7%
distribute-neg-in97.7%
distribute-frac-neg97.7%
add-sqr-sqrt-0.0%
sqrt-unprod96.8%
sqr-neg96.8%
sqrt-unprod97.8%
add-sqr-sqrt97.8%
metadata-eval97.8%
Applied egg-rr97.8%
mul-1-neg97.8%
distribute-neg-frac297.8%
neg-sub097.8%
+-commutative97.8%
associate--r+97.8%
metadata-eval97.8%
Simplified97.8%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 40.7%
+-commutative40.7%
Simplified40.7%
Taylor expanded in x around 0 77.0%
+-commutative77.0%
unpow277.0%
unpow277.0%
times-frac78.4%
distribute-rgt-out78.4%
Simplified78.4%
*-commutative78.4%
clear-num78.4%
*-un-lft-identity78.4%
associate-*l/78.4%
un-div-inv78.4%
associate-*l/78.4%
*-un-lft-identity78.4%
Applied egg-rr78.4%
associate-/r/82.9%
+-commutative82.9%
Simplified82.9%
Final simplification88.9%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -0.10000000149011612) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -0.10000000149011612f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} 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) <= (-0.10000000149011612e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
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(Float32(-x) / s) <= Float32(-0.10000000149011612)) 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(-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(-0.10000000149011612)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); 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 -0.10000000149011612:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -0.100000001Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.2%
+-commutative97.2%
Simplified97.2%
if -0.100000001 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 59.8%
mul-1-neg59.8%
unsub-neg59.8%
Simplified59.8%
expm1-log1p-u59.7%
Applied egg-rr59.7%
expm1-undefine59.7%
sub-neg59.7%
log1p-undefine59.7%
rem-exp-log59.8%
associate-+r-59.8%
metadata-eval59.8%
metadata-eval59.8%
Simplified59.8%
Final simplification75.0%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) (/ 1.0 (+ 1.0 (/ 1.0 (- 1.0 (/ x s))))) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f - (x / s))));
} 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) <= (-2.0e0)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 - (x / s))))
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(Float32(-x) / s) <= Float32(-2.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(-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(-2.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) - (x / s)))); 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 -2:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 - \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
frac-2neg97.7%
metadata-eval97.7%
div-inv97.7%
distribute-neg-in97.7%
distribute-frac-neg97.7%
add-sqr-sqrt-0.0%
sqrt-unprod96.8%
sqr-neg96.8%
sqrt-unprod97.8%
add-sqr-sqrt97.8%
metadata-eval97.8%
Applied egg-rr97.8%
mul-1-neg97.8%
distribute-neg-frac297.8%
neg-sub097.8%
+-commutative97.8%
associate--r+97.8%
metadata-eval97.8%
Simplified97.8%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 59.7%
mul-1-neg59.7%
unsub-neg59.7%
Simplified59.7%
expm1-log1p-u59.6%
Applied egg-rr59.6%
expm1-undefine59.6%
sub-neg59.6%
log1p-undefine59.6%
rem-exp-log59.7%
associate-+r-59.8%
metadata-eval59.8%
metadata-eval59.8%
Simplified59.8%
Final simplification75.1%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 0.004999999888241291) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (* (/ x s) (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 0.004999999888241291f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((x / s) * (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.004999999888241291e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((x / s) * (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(0.004999999888241291)) 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(Float32(x / s) * Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(0.004999999888241291)) 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) * (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 0.004999999888241291:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{x}{s} \cdot \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.00499999989Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
if 0.00499999989 < (/.f32 (neg.f32 x) s) Initial program 99.6%
distribute-frac-neg99.6%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 6.7%
+-commutative6.7%
Simplified6.7%
Taylor expanded in x around 0 72.5%
+-commutative72.5%
unpow272.5%
unpow272.5%
times-frac66.7%
distribute-rgt-out66.7%
Simplified66.7%
Taylor expanded in x around inf 66.6%
Final simplification86.1%
(FPCore (x s) :precision binary32 (if (<= (- x) -4.99999991225835e-15) (- 1.0 (/ s x)) (if (<= (- x) 1.0) 0.5 (/ 1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -4.99999991225835e-15f) {
tmp = 1.0f - (s / x);
} else if (-x <= 1.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 <= (-4.99999991225835e-15)) then
tmp = 1.0e0 - (s / x)
else if (-x <= 1.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(-4.99999991225835e-15)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (Float32(-x) <= Float32(1.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 <= single(-4.99999991225835e-15)) tmp = single(1.0) - (s / x); elseif (-x <= single(1.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}\;-x \leq -4.99999991225835 \cdot 10^{-15}:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;-x \leq 1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -4.99999991e-15Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
Taylor expanded in x around inf 94.3%
neg-mul-194.3%
unsub-neg94.3%
Simplified94.3%
if -4.99999991e-15 < (neg.f32 x) < 1Initial program 99.5%
Taylor expanded in x around 0 59.6%
if 1 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 49.1%
mul-1-neg49.1%
unsub-neg49.1%
Simplified49.1%
Taylor expanded in x around inf 49.1%
mul-1-neg49.1%
distribute-frac-neg49.1%
Simplified49.1%
associate-/r/41.4%
add-sqr-sqrt41.4%
sqrt-unprod57.4%
sqr-neg57.4%
sqrt-unprod-0.0%
add-sqr-sqrt41.4%
Applied egg-rr41.4%
associate-*l/41.4%
*-un-lft-identity41.4%
clear-num49.1%
Applied egg-rr49.1%
Final simplification70.5%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) (/ 1.0 (+ 1.0 (/ s x))) (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 1.0f / (1.0f + (s / 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) <= (-2.0e0)) then
tmp = 1.0e0 / (1.0e0 + (s / 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(Float32(-x) / s) <= Float32(-2.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / 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(-2.0)) tmp = single(1.0) / (single(1.0) + (s / 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 -2:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
Taylor expanded in x around inf 97.7%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 59.7%
mul-1-neg59.7%
unsub-neg59.7%
Simplified59.7%
expm1-log1p-u59.6%
Applied egg-rr59.6%
expm1-undefine59.6%
sub-neg59.6%
log1p-undefine59.6%
rem-exp-log59.7%
associate-+r-59.8%
metadata-eval59.8%
metadata-eval59.8%
Simplified59.8%
Final simplification75.0%
(FPCore (x s) :precision binary32 (if (<= (- x) -4.99999991225835e-15) (- 1.0 (/ s x)) (if (<= (- x) 9.999999747378752e-6) 0.5 (/ s (- x)))))
float code(float x, float s) {
float tmp;
if (-x <= -4.99999991225835e-15f) {
tmp = 1.0f - (s / x);
} else if (-x <= 9.999999747378752e-6f) {
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.99999991225835e-15)) then
tmp = 1.0e0 - (s / x)
else if (-x <= 9.999999747378752e-6) 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.99999991225835e-15)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999747378752e-6)) 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.99999991225835e-15)) tmp = single(1.0) - (s / x); elseif (-x <= single(9.999999747378752e-6)) tmp = single(0.5); else tmp = s / -x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -4.99999991225835 \cdot 10^{-15}:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{-x}\\
\end{array}
\end{array}
if (neg.f32 x) < -4.99999991e-15Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
Taylor expanded in x around inf 94.3%
neg-mul-194.3%
unsub-neg94.3%
Simplified94.3%
if -4.99999991e-15 < (neg.f32 x) < 9.99999975e-6Initial program 99.5%
Taylor expanded in x around 0 67.2%
if 9.99999975e-6 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 43.5%
mul-1-neg43.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 36.9%
mul-1-neg36.9%
distribute-neg-frac236.9%
Simplified36.9%
Final simplification68.6%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) (/ 1.0 (+ 1.0 (/ s x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 1.0f / (1.0f + (s / 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 / (1.0e0 + (s / 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(Float32(-x) / s) <= Float32(-2.0)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / 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) / (single(1.0) + (s / 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}{1 + \frac{s}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.7%
+-commutative97.7%
Simplified97.7%
Taylor expanded in x around inf 97.7%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 59.7%
mul-1-neg59.7%
unsub-neg59.7%
Simplified59.7%
Final simplification75.0%
(FPCore (x s) :precision binary32 (if (<= (- x) 9.999999747378752e-6) 0.5 (/ s (- x))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999747378752e-6f) {
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 <= 9.999999747378752e-6) 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(9.999999747378752e-6)) 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(9.999999747378752e-6)) tmp = single(0.5); else tmp = s / -x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{-x}\\
\end{array}
\end{array}
if (neg.f32 x) < 9.99999975e-6Initial program 99.8%
Taylor expanded in x around 0 46.3%
if 9.99999975e-6 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 43.5%
mul-1-neg43.5%
unsub-neg43.5%
Simplified43.5%
Taylor expanded in x around inf 36.9%
mul-1-neg36.9%
distribute-neg-frac236.9%
Simplified36.9%
Final simplification43.5%
(FPCore (x s) :precision binary32 (if (<= x -1.0) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.0f) {
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.0e0)) 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.0)) 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(-1.0)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around 0 49.1%
mul-1-neg49.1%
unsub-neg49.1%
Simplified49.1%
Taylor expanded in x around inf 49.1%
mul-1-neg49.1%
distribute-frac-neg49.1%
Simplified49.1%
associate-/r/41.4%
add-sqr-sqrt41.4%
sqrt-unprod57.4%
sqr-neg57.4%
sqrt-unprod-0.0%
add-sqr-sqrt41.4%
Applied egg-rr41.4%
Taylor expanded in x around 0 41.4%
if -1 < x Initial program 99.7%
Taylor expanded in x around 0 44.0%
Final simplification43.3%
(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 34.3%
Final simplification34.3%
herbie shell --seed 2024043
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))