
(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 18 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(x / Float32(-s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{\frac{x}{-s}}\right)}
\end{array}
Initial program 99.8%
div-inv99.8%
exp-prod82.6%
neg-mul-182.6%
exp-prod82.6%
pow-pow99.8%
div-inv99.8%
Applied egg-rr99.8%
add-exp-log99.8%
log-rec99.7%
log1p-expm1-u99.7%
log1p-define99.9%
expm1-log1p-u99.9%
pow-exp99.9%
neg-mul-199.9%
distribute-neg-frac299.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (pow (exp -1.0) (/ x s)) 1.0)))
float code(float x, float s) {
return 1.0f / (powf(expf(-1.0f), (x / s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((exp((-1.0e0)) ** (x / s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32((exp(Float32(-1.0)) ^ Float32(x / s)) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / ((exp(single(-1.0)) ^ (x / s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{{\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)} + 1}
\end{array}
Initial program 99.8%
div-inv99.8%
exp-prod82.6%
neg-mul-182.6%
exp-prod82.6%
pow-pow99.8%
div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (exp (/ x (- s))) 1.0)))
float code(float x, float s) {
return 1.0f / (expf((x / -s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (exp((x / -s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32(exp(Float32(x / Float32(-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 -1.0)
(/ 1.0 (* x (/ 2.0 x)))
(if (<= t_0 4.999999966907906e+36)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
(/ -1.0 (* (* x (- (* s 2.0) x)) (/ -1.0 (* x s))))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -1.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else if (t_0 <= 4.999999966907906e+36f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} else {
tmp = -1.0f / ((x * ((s * 2.0f) - x)) * (-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 <= (-1.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else if (t_0 <= 4.999999966907906e+36) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
else
tmp = (-1.0e0) / ((x * ((s * 2.0e0) - x)) * ((-1.0e0) / (x * s)))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-1.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); elseif (t_0 <= Float32(4.999999966907906e+36)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(x / s) + Float32(2.0)))); else tmp = Float32(Float32(-1.0) / Float32(Float32(x * Float32(Float32(s * Float32(2.0)) - x)) * 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(-1.0)) tmp = single(1.0) / (x * (single(2.0) / x)); elseif (t_0 <= single(4.999999966907906e+36)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((x / s) + single(2.0))); else tmp = single(-1.0) / ((x * ((s * single(2.0)) - x)) * (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 -1:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{elif}\;t\_0 \leq 4.999999966907906 \cdot 10^{+36}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\left(x \cdot \left(s \cdot 2 - x\right)\right) \cdot \frac{-1}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 5.5%
mul-1-neg5.5%
unsub-neg5.5%
Simplified5.5%
Taylor expanded in x around inf 5.5%
associate-*r/5.5%
metadata-eval5.5%
Simplified5.5%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) < 4.99999997e36Initial program 99.6%
Taylor expanded in x around 0 58.4%
mul-1-neg58.4%
unsub-neg58.4%
Simplified58.4%
sub-neg58.4%
neg-mul-158.4%
rem-log-exp96.2%
pow-exp96.2%
flip-+53.8%
metadata-eval53.8%
pow-exp53.8%
rem-log-exp53.8%
neg-mul-153.8%
pow-exp53.8%
rem-log-exp54.4%
neg-mul-154.4%
distribute-neg-frac254.4%
distribute-neg-frac254.4%
pow-exp54.4%
rem-log-exp77.9%
neg-mul-177.9%
distribute-neg-frac277.9%
Applied egg-rr77.9%
if 4.99999997e36 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 85.3%
mul-1-neg85.3%
unsub-neg85.3%
Simplified85.3%
Taylor expanded in x around inf 85.3%
associate-*r/85.3%
metadata-eval85.3%
Simplified85.3%
*-commutative85.3%
frac-sub85.3%
associate-*l/96.9%
*-rgt-identity96.9%
*-commutative96.9%
Applied egg-rr96.9%
div-inv100.0%
*-commutative100.0%
Applied egg-rr100.0%
Final simplification63.6%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 1.9999999494757503e-5) 0.5 (/ -1.0 (* (* x (- (* s 2.0) x)) (/ -1.0 (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 1.9999999494757503e-5f) {
tmp = 0.5f;
} else {
tmp = -1.0f / ((x * ((s * 2.0f) - x)) * (-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) <= 1.9999999494757503e-5) then
tmp = 0.5e0
else
tmp = (-1.0e0) / ((x * ((s * 2.0e0) - x)) * ((-1.0e0) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(1.9999999494757503e-5)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(Float32(x * Float32(Float32(s * Float32(2.0)) - x)) * 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(1.9999999494757503e-5)) tmp = single(0.5); else tmp = single(-1.0) / ((x * ((s * single(2.0)) - x)) * (single(-1.0) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 1.9999999494757503 \cdot 10^{-5}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\left(x \cdot \left(s \cdot 2 - x\right)\right) \cdot \frac{-1}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 1.99999995e-5Initial program 99.8%
Taylor expanded in x around 0 58.0%
if 1.99999995e-5 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 36.0%
mul-1-neg36.0%
unsub-neg36.0%
Simplified36.0%
Taylor expanded in x around inf 35.9%
associate-*r/35.9%
metadata-eval35.9%
Simplified35.9%
*-commutative35.9%
frac-sub46.0%
associate-*l/51.6%
*-rgt-identity51.6%
*-commutative51.6%
Applied egg-rr51.6%
div-inv55.6%
*-commutative55.6%
Applied egg-rr55.6%
Final simplification57.1%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 1.9999999494757503e-5) 0.5 (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 1.9999999494757503e-5f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (x * (((s * 2.0f) - 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 / -s) <= 1.9999999494757503e-5) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x * (((s * 2.0e0) - x) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(1.9999999494757503e-5)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(1.9999999494757503e-5)) tmp = single(0.5); else tmp = single(1.0) / (x * (((s * single(2.0)) - x) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 1.9999999494757503 \cdot 10^{-5}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot 2 - x}{x \cdot s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 1.99999995e-5Initial program 99.8%
Taylor expanded in x around 0 58.0%
if 1.99999995e-5 < (/.f32 (neg.f32 x) s) Initial program 99.6%
Taylor expanded in x around 0 36.0%
mul-1-neg36.0%
unsub-neg36.0%
Simplified36.0%
Taylor expanded in x around inf 35.9%
associate-*r/35.9%
metadata-eval35.9%
Simplified35.9%
frac-sub46.0%
*-rgt-identity46.0%
*-commutative46.0%
Applied egg-rr46.0%
Final simplification53.4%
(FPCore (x s) :precision binary32 (if (<= (- x) 9.999999682655225e-20) 0.5 (* (* x s) (/ (/ 1.0 x) (- (* s 2.0) x)))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999682655225e-20f) {
tmp = 0.5f;
} else {
tmp = (x * s) * ((1.0f / x) / ((s * 2.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 <= 9.999999682655225e-20) then
tmp = 0.5e0
else
tmp = (x * s) * ((1.0e0 / x) / ((s * 2.0e0) - x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(9.999999682655225e-20)) tmp = Float32(0.5); else tmp = Float32(Float32(x * s) * Float32(Float32(Float32(1.0) / x) / Float32(Float32(s * Float32(2.0)) - x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(9.999999682655225e-20)) tmp = single(0.5); else tmp = (x * s) * ((single(1.0) / x) / ((s * single(2.0)) - x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999682655225 \cdot 10^{-20}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot s\right) \cdot \frac{\frac{1}{x}}{s \cdot 2 - x}\\
\end{array}
\end{array}
if (neg.f32 x) < 9.99999968e-20Initial program 99.8%
Taylor expanded in x around 0 53.5%
if 9.99999968e-20 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 42.5%
mul-1-neg42.5%
unsub-neg42.5%
Simplified42.5%
Taylor expanded in x around inf 42.5%
associate-*r/42.5%
metadata-eval42.5%
Simplified42.5%
associate-/r*40.2%
frac-sub43.1%
associate-/r/52.6%
*-rgt-identity52.6%
*-commutative52.6%
Applied egg-rr52.6%
Final simplification53.1%
(FPCore (x s) :precision binary32 (if (<= (- x) 1.9999999996399175e-23) 0.5 (/ 1.0 (/ (* x (- (* s 2.0) x)) (* x s)))))
float code(float x, float s) {
float tmp;
if (-x <= 1.9999999996399175e-23f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((x * ((s * 2.0f) - 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 <= 1.9999999996399175e-23) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((x * ((s * 2.0e0) - x)) / (x * s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(1.9999999996399175e-23)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(s * Float32(2.0)) - x)) / Float32(x * s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(1.9999999996399175e-23)) tmp = single(0.5); else tmp = single(1.0) / ((x * ((s * single(2.0)) - x)) / (x * s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 1.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(s \cdot 2 - x\right)}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 2e-23Initial program 99.9%
Taylor expanded in x around 0 53.9%
if 2e-23 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 42.8%
mul-1-neg42.8%
unsub-neg42.8%
Simplified42.8%
Taylor expanded in x around inf 42.8%
associate-*r/42.8%
metadata-eval42.8%
Simplified42.8%
*-commutative42.8%
frac-sub47.4%
associate-*l/59.1%
*-rgt-identity59.1%
*-commutative59.1%
Applied egg-rr59.1%
Final simplification55.9%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (/ 1.0 (* x (/ 2.0 x))) (/ -1.0 (/ (- x (* s 2.0)) s))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.0f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = -1.0f / ((x - (s * 2.0f)) / s);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x / -s) <= (-1.0e0)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = (-1.0e0) / ((x - (s * 2.0e0)) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(-1.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(-1.0) / Float32(Float32(x - Float32(s * Float32(2.0))) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(-1.0)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(-1.0) / ((x - (s * single(2.0))) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -1:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x - s \cdot 2}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0 5.5%
mul-1-neg5.5%
unsub-neg5.5%
Simplified5.5%
Taylor expanded in x around inf 5.5%
associate-*r/5.5%
metadata-eval5.5%
Simplified5.5%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 62.3%
mul-1-neg62.3%
unsub-neg62.3%
Simplified62.3%
Taylor expanded in s around 0 62.4%
*-commutative62.4%
Simplified62.4%
Final simplification51.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 20.0) 0.5 (/ 1.0 (* (/ x s) 3.0))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 20.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((x / s) * 3.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) <= 20.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((x / s) * 3.0e0)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(20.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(x / s) * Float32(3.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(20.0)) tmp = single(0.5); else tmp = single(1.0) / ((x / s) * single(3.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 20:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s} \cdot 3}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 20Initial program 99.6%
Taylor expanded in x around 0 57.2%
if 20 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 32.3%
mul-1-neg32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in x around inf 32.3%
associate-*r/32.3%
metadata-eval32.3%
Simplified32.3%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt32.3%
distribute-frac-neg232.3%
add-sqr-sqrt-0.0%
sqrt-unprod57.7%
sqr-neg57.7%
sqrt-unprod32.3%
add-sqr-sqrt32.3%
distribute-frac-neg232.3%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod34.9%
add-sqr-sqrt34.9%
associate-/r/34.9%
Applied egg-rr34.9%
rem-3cbrt-rft34.9%
unpow234.9%
fma-undefine34.9%
+-commutative34.9%
fma-undefine34.9%
*-rgt-identity34.9%
associate-+l+34.9%
fma-undefine34.9%
unpow234.9%
associate-*r*34.9%
unpow234.9%
Simplified34.9%
Taylor expanded in x around inf 34.1%
Final simplification49.4%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 20.0) 0.5 (/ 1.0 (* x (/ 3.0 s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 20.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (x * (3.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) <= 20.0e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x * (3.0e0 / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(20.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(3.0) / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x / -s) <= single(20.0)) tmp = single(0.5); else tmp = single(1.0) / (x * (single(3.0) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 20:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{3}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 20Initial program 99.6%
Taylor expanded in x around 0 57.2%
if 20 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 32.3%
mul-1-neg32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in x around inf 32.3%
associate-*r/32.3%
metadata-eval32.3%
Simplified32.3%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt32.3%
distribute-frac-neg232.3%
add-sqr-sqrt-0.0%
sqrt-unprod57.7%
sqr-neg57.7%
sqrt-unprod32.3%
add-sqr-sqrt32.3%
distribute-frac-neg232.3%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod34.9%
add-sqr-sqrt34.9%
associate-/r/34.9%
Applied egg-rr34.9%
rem-3cbrt-rft34.9%
unpow234.9%
fma-undefine34.9%
+-commutative34.9%
fma-undefine34.9%
*-rgt-identity34.9%
associate-+l+34.9%
fma-undefine34.9%
unpow234.9%
associate-*r*34.9%
unpow234.9%
Simplified34.9%
Taylor expanded in s around 0 34.9%
Final simplification49.6%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) -1.0) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= -1.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) <= (-1.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(-1.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(-1.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 -1:\\
\;\;\;\;\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) < -1Initial program 100.0%
Taylor expanded in x around 0 5.5%
mul-1-neg5.5%
unsub-neg5.5%
Simplified5.5%
Taylor expanded in x around inf 5.5%
associate-*r/5.5%
metadata-eval5.5%
Simplified5.5%
Taylor expanded in x around 0 28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 62.3%
mul-1-neg62.3%
unsub-neg62.3%
Simplified62.3%
Final simplification51.0%
(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(x / Float32(-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.7%
Taylor expanded in x around 0 57.4%
if 2 < (/.f32 (neg.f32 x) s) Initial program 99.9%
Taylor expanded in x around 0 32.1%
mul-1-neg32.1%
unsub-neg32.1%
Simplified32.1%
Taylor expanded in x around inf 32.1%
associate-*r/32.1%
neg-mul-132.1%
Simplified32.1%
Final simplification48.7%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (* s (/ 1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-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 <= (-9.999999747378752e-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(-9.999999747378752e-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(-9.999999747378752e-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 -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 41.6%
mul-1-neg41.6%
unsub-neg41.6%
Simplified41.6%
Taylor expanded in x around inf 38.0%
associate-*r/38.0%
neg-mul-138.0%
Simplified38.0%
clear-num41.6%
associate-/r/38.0%
add-sqr-sqrt-0.0%
sqrt-unprod50.7%
sqr-neg50.7%
sqrt-unprod38.0%
add-sqr-sqrt38.0%
Applied egg-rr38.0%
if -9.99999975e-5 < x Initial program 99.7%
Taylor expanded in x around 0 50.9%
Final simplification47.7%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (* (/ s x) 0.3333333333333333) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-5f) {
tmp = (s / x) * 0.3333333333333333f;
} 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.999999747378752e-5)) then
tmp = (s / x) * 0.3333333333333333e0
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999747378752e-5)) tmp = Float32(Float32(s / x) * Float32(0.3333333333333333)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.999999747378752e-5)) tmp = (s / x) * single(0.3333333333333333); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{x} \cdot 0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 41.6%
mul-1-neg41.6%
unsub-neg41.6%
Simplified41.6%
Taylor expanded in x around inf 41.6%
associate-*r/41.6%
metadata-eval41.6%
Simplified41.6%
add-sqr-sqrt-0.0%
*-un-lft-identity-0.0%
prod-diff-0.0%
associate-/r/-0.0%
clear-num-0.0%
fma-define-0.0%
add-sqr-sqrt41.6%
distribute-frac-neg241.6%
add-sqr-sqrt-0.0%
sqrt-unprod53.4%
sqr-neg53.4%
sqrt-unprod41.6%
add-sqr-sqrt41.6%
distribute-frac-neg241.6%
add-sqr-sqrt-0.0%
sqrt-unprod55.7%
sqr-neg55.7%
sqrt-unprod45.2%
add-sqr-sqrt45.2%
associate-/r/45.2%
Applied egg-rr45.2%
rem-3cbrt-rft45.2%
unpow245.2%
fma-undefine45.2%
+-commutative45.2%
fma-undefine45.2%
*-rgt-identity45.2%
associate-+l+45.2%
fma-undefine45.2%
unpow245.2%
associate-*r*45.2%
unpow245.2%
Simplified45.2%
Taylor expanded in x around inf 39.0%
*-commutative39.0%
Simplified39.0%
if -9.99999975e-5 < x Initial program 99.7%
Taylor expanded in x around 0 50.9%
Final simplification48.0%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (/ 1.0 (/ x s)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-5f) {
tmp = 1.0f / (x / s);
} 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.999999747378752e-5)) then
tmp = 1.0e0 / (x / s)
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999747378752e-5)) tmp = Float32(Float32(1.0) / Float32(x / s)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.999999747378752e-5)) tmp = single(1.0) / (x / s); else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 41.6%
mul-1-neg41.6%
unsub-neg41.6%
Simplified41.6%
Taylor expanded in x around inf 38.0%
associate-*r/38.0%
neg-mul-138.0%
Simplified38.0%
add-sqr-sqrt-0.0%
sqrt-unprod50.7%
sqr-neg50.7%
sqrt-unprod38.0%
add-sqr-sqrt38.0%
div-inv38.0%
Applied egg-rr38.0%
associate-*r/38.0%
*-rgt-identity38.0%
Simplified38.0%
clear-num41.6%
inv-pow41.6%
Applied egg-rr41.6%
unpow-141.6%
Simplified41.6%
if -9.99999975e-5 < x Initial program 99.7%
Taylor expanded in x around 0 50.9%
Final simplification48.6%
(FPCore (x s) :precision binary32 (if (<= x -9.999999747378752e-5) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -9.999999747378752e-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 <= (-9.999999747378752e-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(-9.999999747378752e-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(-9.999999747378752e-5)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -9.99999975e-5Initial program 100.0%
Taylor expanded in x around 0 41.6%
mul-1-neg41.6%
unsub-neg41.6%
Simplified41.6%
Taylor expanded in x around inf 38.0%
associate-*r/38.0%
neg-mul-138.0%
Simplified38.0%
add-sqr-sqrt-0.0%
sqrt-unprod50.7%
sqr-neg50.7%
sqrt-unprod38.0%
add-sqr-sqrt38.0%
div-inv38.0%
Applied egg-rr38.0%
associate-*r/38.0%
*-rgt-identity38.0%
Simplified38.0%
if -9.99999975e-5 < x Initial program 99.7%
Taylor expanded in x around 0 50.9%
Final simplification47.7%
(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 39.9%
Final simplification39.9%
herbie shell --seed 2024067
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))