
(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 (/ 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.9%
div-inv99.9%
exp-prod86.3%
neg-mul-186.3%
exp-prod86.3%
pow-pow99.9%
div-inv99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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.9%
distribute-frac-neg99.9%
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.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -4.0)
(- 1.0 (/ s x))
(if (<= t_0 0.5) (+ 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 <= -4.0f) {
tmp = 1.0f - (s / x);
} else if (t_0 <= 0.5f) {
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 <= (-4.0e0)) then
tmp = 1.0e0 - (s / x)
else if (t_0 <= 0.5e0) 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(-4.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (t_0 <= Float32(0.5)) 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(-4.0)) tmp = single(1.0) - (s / x); elseif (t_0 <= single(0.5)) 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 -4:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;t_0 \leq 0.5:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -4Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.4%
+-commutative96.4%
Simplified96.4%
Taylor expanded in x around inf 96.4%
+-commutative96.4%
neg-mul-196.4%
unsub-neg96.4%
Simplified96.4%
if -4 < (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0 97.5%
*-commutative97.5%
Simplified97.5%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 46.3%
mul-1-neg46.3%
unsub-neg46.3%
Simplified46.3%
Taylor expanded in x around inf 46.3%
mul-1-neg46.3%
distribute-frac-neg46.3%
Simplified46.3%
Final simplification79.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ (- x) s)))
(if (<= t_0 -4.0)
(- 1.0 (/ s x))
(if (<= t_0 5.0) (+ 0.5 (* (/ x s) 0.25)) (+ 1.0 (+ -1.0 (/ s x)))))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -4.0f) {
tmp = 1.0f - (s / x);
} else if (t_0 <= 5.0f) {
tmp = 0.5f + ((x / s) * 0.25f);
} else {
tmp = 1.0f + (-1.0f + (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 <= (-4.0e0)) then
tmp = 1.0e0 - (s / x)
else if (t_0 <= 5.0e0) then
tmp = 0.5e0 + ((x / s) * 0.25e0)
else
tmp = 1.0e0 + ((-1.0e0) + (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(-4.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (t_0 <= Float32(5.0)) tmp = Float32(Float32(0.5) + Float32(Float32(x / s) * Float32(0.25))); else tmp = Float32(Float32(1.0) + Float32(Float32(-1.0) + 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(-4.0)) tmp = single(1.0) - (s / x); elseif (t_0 <= single(5.0)) tmp = single(0.5) + ((x / s) * single(0.25)); else tmp = single(1.0) + (single(-1.0) + (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{s}\\
\mathbf{if}\;t_0 \leq -4:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;t_0 \leq 5:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;1 + \left(-1 + \frac{s}{x}\right)\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -4Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.4%
+-commutative96.4%
Simplified96.4%
Taylor expanded in x around inf 96.4%
+-commutative96.4%
neg-mul-196.4%
unsub-neg96.4%
Simplified96.4%
if -4 < (/.f32 (neg.f32 x) s) < 5Initial program 99.7%
Taylor expanded in x around 0 94.4%
*-commutative94.4%
Simplified94.4%
if 5 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 46.8%
mul-1-neg46.8%
unsub-neg46.8%
Simplified46.8%
Taylor expanded in x around inf 44.8%
associate-*r/44.8%
neg-mul-144.8%
Simplified44.8%
div-inv44.8%
add-sqr-sqrt-0.0%
sqrt-unprod69.5%
sqr-neg69.5%
sqrt-unprod44.7%
add-sqr-sqrt44.7%
Applied egg-rr44.7%
div-inv44.7%
expm1-log1p-u44.7%
expm1-udef92.3%
log1p-udef92.3%
+-commutative92.3%
add-exp-log92.3%
+-commutative92.3%
Applied egg-rr92.3%
associate--l+92.3%
Simplified92.3%
Final simplification94.5%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ (- x) s))) (if (<= t_0 -4.0) (- 1.0 (/ s x)) (if (<= t_0 0.5) 0.5 (/ 1.0 t_0)))))
float code(float x, float s) {
float t_0 = -x / s;
float tmp;
if (t_0 <= -4.0f) {
tmp = 1.0f - (s / x);
} else if (t_0 <= 0.5f) {
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 <= (-4.0e0)) then
tmp = 1.0e0 - (s / x)
else if (t_0 <= 0.5e0) 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(-4.0)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (t_0 <= Float32(0.5)) 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(-4.0)) tmp = single(1.0) - (s / x); elseif (t_0 <= single(0.5)) 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 -4:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;t_0 \leq 0.5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -4Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 96.4%
+-commutative96.4%
Simplified96.4%
Taylor expanded in x around inf 96.4%
+-commutative96.4%
neg-mul-196.4%
unsub-neg96.4%
Simplified96.4%
if -4 < (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0 88.4%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0 46.3%
mul-1-neg46.3%
unsub-neg46.3%
Simplified46.3%
Taylor expanded in x around inf 46.3%
mul-1-neg46.3%
distribute-frac-neg46.3%
Simplified46.3%
Final simplification77.5%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 50.0) (/ 1.0 (+ 1.0 (/ -1.0 (+ -1.0 (/ x s))))) (+ 1.0 (+ -1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 50.0f) {
tmp = 1.0f / (1.0f + (-1.0f / (-1.0f + (x / s))));
} else {
tmp = 1.0f + (-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 / s) <= 50.0e0) then
tmp = 1.0e0 / (1.0e0 + ((-1.0e0) / ((-1.0e0) + (x / s))))
else
tmp = 1.0e0 + ((-1.0e0) + (s / x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(50.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(s / x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(50.0)) tmp = single(1.0) / (single(1.0) + (single(-1.0) / (single(-1.0) + (x / s)))); else tmp = single(1.0) + (single(-1.0) + (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 50:\\
\;\;\;\;\frac{1}{1 + \frac{-1}{-1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(-1 + \frac{s}{x}\right)\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 50Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 94.2%
+-commutative94.2%
Simplified94.2%
*-un-lft-identity94.2%
frac-2neg94.2%
metadata-eval94.2%
distribute-neg-in94.2%
distribute-frac-neg94.2%
add-sqr-sqrt13.7%
sqrt-unprod91.0%
sqr-neg91.0%
sqrt-unprod79.5%
add-sqr-sqrt92.1%
metadata-eval92.1%
Applied egg-rr92.1%
*-lft-identity92.1%
Simplified92.1%
if 50 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 47.2%
mul-1-neg47.2%
unsub-neg47.2%
Simplified47.2%
Taylor expanded in x around inf 45.2%
associate-*r/45.2%
neg-mul-145.2%
Simplified45.2%
div-inv45.2%
add-sqr-sqrt-0.0%
sqrt-unprod70.3%
sqr-neg70.3%
sqrt-unprod45.2%
add-sqr-sqrt45.2%
Applied egg-rr45.2%
div-inv45.2%
expm1-log1p-u45.2%
expm1-udef93.3%
log1p-udef93.3%
+-commutative93.3%
add-exp-log93.3%
+-commutative93.3%
Applied egg-rr93.3%
associate--l+93.3%
Simplified93.3%
Final simplification92.5%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 50.0) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (+ 1.0 (+ -1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 50.0f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f + (-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 / s) <= 50.0e0) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 + ((-1.0e0) + (s / x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(50.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(s / x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(50.0)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) + (single(-1.0) + (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 50:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(-1 + \frac{s}{x}\right)\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 50Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 94.2%
+-commutative94.2%
Simplified94.2%
if 50 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 47.2%
mul-1-neg47.2%
unsub-neg47.2%
Simplified47.2%
Taylor expanded in x around inf 45.2%
associate-*r/45.2%
neg-mul-145.2%
Simplified45.2%
div-inv45.2%
add-sqr-sqrt-0.0%
sqrt-unprod70.3%
sqr-neg70.3%
sqrt-unprod45.2%
add-sqr-sqrt45.2%
Applied egg-rr45.2%
div-inv45.2%
expm1-log1p-u45.2%
expm1-udef93.3%
log1p-udef93.3%
+-commutative93.3%
add-exp-log93.3%
+-commutative93.3%
Applied egg-rr93.3%
associate--l+93.3%
Simplified93.3%
Final simplification93.9%
(FPCore (x s) :precision binary32 (if (<= x -3.9999998989515007e-5) (* s (/ 1.0 x)) (if (<= x 1.99999996490334e-13) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -3.9999998989515007e-5f) {
tmp = s * (1.0f / x);
} else if (x <= 1.99999996490334e-13f) {
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 <= (-3.9999998989515007e-5)) then
tmp = s * (1.0e0 / x)
else if (x <= 1.99999996490334e-13) 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(-3.9999998989515007e-5)) tmp = Float32(s * Float32(Float32(1.0) / x)); elseif (x <= Float32(1.99999996490334e-13)) 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(-3.9999998989515007e-5)) tmp = s * (single(1.0) / x); elseif (x <= single(1.99999996490334e-13)) 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 -3.9999998989515007 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{elif}\;x \leq 1.99999996490334 \cdot 10^{-13}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -3.9999999e-5Initial program 100.0%
Taylor expanded in x around 0 59.3%
mul-1-neg59.3%
unsub-neg59.3%
Simplified59.3%
Taylor expanded in x around inf 56.5%
associate-*r/56.5%
neg-mul-156.5%
Simplified56.5%
div-inv56.5%
add-sqr-sqrt-0.0%
sqrt-unprod69.7%
sqr-neg69.7%
sqrt-unprod56.5%
add-sqr-sqrt56.5%
Applied egg-rr56.5%
if -3.9999999e-5 < x < 1.99999996e-13Initial program 99.7%
Taylor expanded in x around 0 60.7%
if 1.99999996e-13 < x Initial 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 94.6%
+-commutative94.6%
neg-mul-194.6%
unsub-neg94.6%
Simplified94.6%
Final simplification73.4%
(FPCore (x s) :precision binary32 (if (<= x -3.9999998989515007e-5) (/ 1.0 (/ x s)) (if (<= x 1.99999996490334e-13) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -3.9999998989515007e-5f) {
tmp = 1.0f / (x / s);
} else if (x <= 1.99999996490334e-13f) {
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 <= (-3.9999998989515007e-5)) then
tmp = 1.0e0 / (x / s)
else if (x <= 1.99999996490334e-13) 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(-3.9999998989515007e-5)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(1.99999996490334e-13)) 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(-3.9999998989515007e-5)) tmp = single(1.0) / (x / s); elseif (x <= single(1.99999996490334e-13)) 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 -3.9999998989515007 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 1.99999996490334 \cdot 10^{-13}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -3.9999999e-5Initial program 100.0%
Taylor expanded in x around 0 59.3%
mul-1-neg59.3%
unsub-neg59.3%
Simplified59.3%
Taylor expanded in x around inf 56.5%
associate-*r/56.5%
neg-mul-156.5%
Simplified56.5%
add-sqr-sqrt-0.0%
sqrt-unprod69.7%
sqr-neg69.7%
sqrt-unprod56.5%
add-sqr-sqrt56.5%
clear-num59.3%
inv-pow59.3%
Applied egg-rr59.3%
unpow-159.3%
Simplified59.3%
if -3.9999999e-5 < x < 1.99999996e-13Initial program 99.7%
Taylor expanded in x around 0 60.7%
if 1.99999996e-13 < x Initial 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 94.6%
+-commutative94.6%
neg-mul-194.6%
unsub-neg94.6%
Simplified94.6%
Final simplification74.1%
(FPCore (x s) :precision binary32 (if (<= x -3.9999998989515007e-5) (* s (/ 1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -3.9999998989515007e-5f) {
tmp = s * (1.0f / 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 <= (-3.9999998989515007e-5)) then
tmp = s * (1.0e0 / x)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-3.9999998989515007e-5)) tmp = Float32(s * Float32(Float32(1.0) / x)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-3.9999998989515007e-5)) tmp = s * (single(1.0) / x); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9999998989515007 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -3.9999999e-5Initial program 100.0%
Taylor expanded in x around 0 59.3%
mul-1-neg59.3%
unsub-neg59.3%
Simplified59.3%
Taylor expanded in x around inf 56.5%
associate-*r/56.5%
neg-mul-156.5%
Simplified56.5%
div-inv56.5%
add-sqr-sqrt-0.0%
sqrt-unprod69.7%
sqr-neg69.7%
sqrt-unprod56.5%
add-sqr-sqrt56.5%
Applied egg-rr56.5%
if -3.9999999e-5 < x Initial program 99.8%
Taylor expanded in x around 0 44.2%
Final simplification47.3%
(FPCore (x s) :precision binary32 (if (<= x -3.9999998989515007e-5) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -3.9999998989515007e-5f) {
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 <= (-3.9999998989515007e-5)) 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(-3.9999998989515007e-5)) 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(-3.9999998989515007e-5)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9999998989515007 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -3.9999999e-5Initial program 100.0%
Taylor expanded in x around 0 59.3%
mul-1-neg59.3%
unsub-neg59.3%
Simplified59.3%
Taylor expanded in x around inf 56.5%
associate-*r/56.5%
neg-mul-156.5%
Simplified56.5%
div-inv56.5%
add-sqr-sqrt-0.0%
sqrt-unprod69.7%
sqr-neg69.7%
sqrt-unprod56.5%
add-sqr-sqrt56.5%
Applied egg-rr56.5%
Taylor expanded in s around 0 56.5%
if -3.9999999e-5 < x Initial program 99.8%
Taylor expanded in x around 0 44.2%
Final simplification47.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.9%
Taylor expanded in x around 0 34.8%
Final simplification34.8%
herbie shell --seed 2023229
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))