
(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 (/ 1.0 (+ 1.0 (/ 1.0 (exp (/ x s))))))
float code(float x, float s) {
return 1.0f / (1.0f + (1.0f / expf((x / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (1.0e0 / exp((x / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / exp(Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (single(1.0) / exp((x / s)))); end
\begin{array}{l}
\\
\frac{1}{1 + \frac{1}{e^{\frac{x}{s}}}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.9%
Applied egg-rr99.9%
Final simplification99.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(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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (if (<= (- x) 9.999999887266023e-27) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (- (* 0.5 (/ x (/ (* s s) x))) (/ x s))))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999887266023e-27f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + ((0.5f * (x / ((s * s) / 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 <= 9.999999887266023e-27) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + ((0.5e0 * (x / ((s * s) / x))) - (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(9.999999887266023e-27)) 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(Float32(0.5) * Float32(x / Float32(Float32(s * s) / x))) - Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(9.999999887266023e-27)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + ((single(0.5) * (x / ((s * s) / x))) - (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999887266023 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \frac{x}{\frac{s \cdot s}{x}} - \frac{x}{s}\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 9.99999989e-27Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.8%
if 9.99999989e-27 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 83.7%
mul-1-neg83.7%
unsub-neg83.7%
unpow283.7%
unpow283.7%
times-frac75.4%
Simplified75.4%
clear-num75.4%
frac-times79.9%
*-un-lft-identity79.9%
Applied egg-rr79.9%
associate-*l/87.3%
Applied egg-rr87.3%
Final simplification91.1%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -20.0)
(/ 1.0 (+ 1.0 (/ s x)))
(if (<= t_0 1.0) (+ 0.5 (* (/ x s) 0.25)) (* 2.0 (* (/ s x) (/ s x)))))))
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 <= 1.0f) {
tmp = 0.5f + ((x / s) * 0.25f);
} else {
tmp = 2.0f * ((s / x) * (s / x));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-20.0e0)) then
tmp = 1.0e0 / (1.0e0 + (s / x))
else if (t_0 <= 1.0e0) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = 2.0e0 * ((s / x) * (s / x))
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(1.0)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); else tmp = Float32(Float32(2.0) * Float32(Float32(s / x) * Float32(s / x))); 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(1.0)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(2.0) * ((s / x) * (s / x)); 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 1:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\frac{s}{x} \cdot \frac{s}{x}\right)\\
\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 96.3%
Taylor expanded in x around inf 96.3%
if -20 < (/.f32 (neg.f32 x) s) < 1Initial program 99.7%
Taylor expanded in x around 0 95.6%
*-commutative95.6%
Simplified95.6%
if 1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 79.7%
mul-1-neg79.7%
unsub-neg79.7%
unpow279.7%
unpow279.7%
times-frac71.3%
Simplified71.3%
Taylor expanded in x around inf 79.6%
unpow279.6%
unpow279.6%
Simplified79.6%
times-frac69.2%
Applied egg-rr69.2%
Final simplification85.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -20.0)
(/ 1.0 (+ 1.0 (/ s x)))
(if (<= t_0 2.5) (+ 0.5 (* (/ x s) 0.25)) (* 2.0 (/ (* s s) (* x x)))))))
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 <= 2.5f) {
tmp = 0.5f + ((x / s) * 0.25f);
} else {
tmp = 2.0f * ((s * s) / (x * x));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = -x / s
if (t_0 <= (-20.0e0)) then
tmp = 1.0e0 / (1.0e0 + (s / x))
else if (t_0 <= 2.5e0) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = 2.0e0 * ((s * s) / (x * x))
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(2.5)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); else tmp = Float32(Float32(2.0) * Float32(Float32(s * s) / Float32(x * x))); 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(2.5)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(2.0) * ((s * s) / (x * x)); 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 2.5:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{s \cdot s}{x \cdot x}\\
\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 96.3%
Taylor expanded in x around inf 96.3%
if -20 < (/.f32 (neg.f32 x) s) < 2.5Initial program 99.7%
Taylor expanded in x around 0 94.2%
*-commutative94.2%
Simplified94.2%
if 2.5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 80.5%
mul-1-neg80.5%
unsub-neg80.5%
unpow280.5%
unpow280.5%
times-frac71.7%
Simplified71.7%
Taylor expanded in x around inf 80.4%
unpow280.4%
unpow280.4%
Simplified80.4%
Final simplification89.7%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 10.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (* x (/ (* x 0.5) (* s s)))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 10.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + (x * ((x * 0.5f) / (s * s))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((-x / s) <= 10.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + (x * ((x * 0.5e0) / (s * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(10.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(x * Float32(0.5)) / Float32(s * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(10.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + (x * ((x * single(0.5)) / (s * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 10:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{x \cdot 0.5}{s \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 10Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.3%
if 10 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 82.7%
mul-1-neg82.7%
unsub-neg82.7%
unpow282.7%
unpow282.7%
times-frac73.2%
Simplified73.2%
clear-num73.2%
frac-times78.4%
*-un-lft-identity78.4%
Applied egg-rr78.4%
associate-*l/86.9%
Applied egg-rr86.9%
Taylor expanded in x around inf 82.7%
unpow282.7%
associate-/l*86.9%
unpow286.9%
associate-*r/78.4%
associate-*r/78.4%
*-commutative78.4%
associate-*r/86.9%
unpow286.9%
associate-/r/86.9%
unpow286.9%
Simplified86.9%
Final simplification90.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -20.0)
(- 1.0 (/ s x))
(if (<= t_0 1.0) (+ 0.5 (* (/ x s) 0.25)) (/ 1.0 t_0)))))
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 <= 1.0f) {
tmp = 0.5f + ((x / s) * 0.25f);
} else {
tmp = 1.0f / t_0;
}
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 <= 1.0e0) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = 1.0e0 / t_0
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(1.0)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); else tmp = Float32(Float32(1.0) / t_0); 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(1.0)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(1.0) / t_0; 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 1:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\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 96.3%
Taylor expanded in x around inf 96.3%
+-commutative96.3%
mul-1-neg96.3%
unsub-neg96.3%
Simplified96.3%
if -20 < (/.f32 (neg.f32 x) s) < 1Initial program 99.7%
Taylor expanded in x around 0 95.6%
*-commutative95.6%
Simplified95.6%
if 1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 40.6%
mul-1-neg40.6%
unsub-neg40.6%
Simplified40.6%
Taylor expanded in x around inf 40.6%
neg-mul-140.6%
distribute-neg-frac40.6%
Simplified40.6%
Final simplification74.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -20.0)
(/ 1.0 (+ 1.0 (/ s x)))
(if (<= t_0 1.0) (+ 0.5 (* (/ x s) 0.25)) (/ 1.0 t_0)))))
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 <= 1.0f) {
tmp = 0.5f + ((x / s) * 0.25f);
} else {
tmp = 1.0f / t_0;
}
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 <= 1.0e0) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = 1.0e0 / t_0
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(1.0)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); else tmp = Float32(Float32(1.0) / t_0); 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(1.0)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(1.0) / t_0; 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 1:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\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 96.3%
Taylor expanded in x around inf 96.3%
if -20 < (/.f32 (neg.f32 x) s) < 1Initial program 99.7%
Taylor expanded in x around 0 95.6%
*-commutative95.6%
Simplified95.6%
if 1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 40.6%
mul-1-neg40.6%
unsub-neg40.6%
Simplified40.6%
Taylor expanded in x around inf 40.6%
neg-mul-140.6%
distribute-neg-frac40.6%
Simplified40.6%
Final simplification74.6%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ (- x) s))) (if (<= t_0 -2.0) (- 1.0 (/ s x)) (if (<= t_0 1.0) 0.5 (/ 1.0 t_0)))))
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 <= 1.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / t_0;
}
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 <= 1.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / t_0
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(1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / t_0); 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(1.0)) tmp = single(0.5); else tmp = single(1.0) / t_0; 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 1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\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 95.7%
Taylor expanded in x around inf 95.6%
+-commutative95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
if -2 < (/.f32 (neg.f32 x) s) < 1Initial program 99.7%
Taylor expanded in x around 0 89.6%
if 1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 40.6%
mul-1-neg40.6%
unsub-neg40.6%
Simplified40.6%
Taylor expanded in x around inf 40.6%
neg-mul-140.6%
distribute-neg-frac40.6%
Simplified40.6%
Final simplification72.9%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 20000.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (* 2.0 (/ (* s s) (* x x)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 20000.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 2.0f * ((s * s) / (x * x));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((-x / s) <= 20000.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 2.0e0 * ((s * s) / (x * x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(20000.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(2.0) * Float32(Float32(s * s) / Float32(x * x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(20000.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(2.0) * ((s * s) / (x * x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 20000:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{s \cdot s}{x \cdot x}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 2e4Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 90.7%
if 2e4 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 87.0%
mul-1-neg87.0%
unsub-neg87.0%
unpow287.0%
unpow287.0%
times-frac76.8%
Simplified76.8%
Taylor expanded in x around inf 87.0%
unpow287.0%
unpow287.0%
Simplified87.0%
Final simplification89.4%
(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 95.7%
Taylor expanded in x around inf 95.6%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 61.3%
mul-1-neg61.3%
unsub-neg61.3%
Simplified61.3%
Final simplification74.1%
(FPCore (x s) :precision binary32 (if (<= x -9.99999993922529e-9) (/ (- s) x) (if (<= x 2.0000000072549875e-15) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -9.99999993922529e-9f) {
tmp = -s / x;
} else if (x <= 2.0000000072549875e-15f) {
tmp = 0.5f;
} else {
tmp = 1.0f - (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.99999993922529e-9)) then
tmp = -s / x
else if (x <= 2.0000000072549875e-15) then
tmp = 0.5e0
else
tmp = 1.0e0 - (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.99999993922529e-9)) tmp = Float32(Float32(-s) / x); elseif (x <= Float32(2.0000000072549875e-15)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) - Float32(s / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.99999993922529e-9)) tmp = -s / x; elseif (x <= single(2.0000000072549875e-15)) tmp = single(0.5); else tmp = single(1.0) - (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.99999993922529 \cdot 10^{-9}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{elif}\;x \leq 2.0000000072549875 \cdot 10^{-15}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -9.99999994e-9Initial program 100.0%
Taylor expanded in x around 0 50.1%
mul-1-neg50.1%
unsub-neg50.1%
Simplified50.1%
Taylor expanded in x around inf 46.3%
mul-1-neg46.3%
distribute-neg-frac46.3%
Simplified46.3%
if -9.99999994e-9 < x < 2.00000001e-15Initial program 99.5%
Taylor expanded in x around 0 63.8%
if 2.00000001e-15 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.0%
Taylor expanded in x around inf 92.5%
+-commutative92.5%
mul-1-neg92.5%
unsub-neg92.5%
Simplified92.5%
Final simplification69.3%
(FPCore (x s) :precision binary32 (if (<= x -9.99999993922529e-9) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.99999993922529e-9f) {
tmp = -s / x;
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-9.99999993922529e-9)) then
tmp = -s / x
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.99999993922529e-9)) tmp = Float32(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(-9.99999993922529e-9)) tmp = -s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.99999993922529 \cdot 10^{-9}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999994e-9Initial program 100.0%
Taylor expanded in x around 0 50.1%
mul-1-neg50.1%
unsub-neg50.1%
Simplified50.1%
Taylor expanded in x around inf 46.3%
mul-1-neg46.3%
distribute-neg-frac46.3%
Simplified46.3%
if -9.99999994e-9 < x Initial program 99.8%
Taylor expanded in x around 0 46.3%
Final simplification46.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.6%
Final simplification34.6%
herbie shell --seed 2023228
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))