
(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.8%
Applied egg-rr99.8%
(FPCore (x s) :precision binary32 (if (<= (- x) 2.000000026702864e-10) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ (- (/ (pow s 2.0) s)) x)))
float code(float x, float s) {
float tmp;
if (-x <= 2.000000026702864e-10f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = -(powf(s, 2.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 <= 2.000000026702864e-10) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = -((s ** 2.0e0) / s) / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(2.000000026702864e-10)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(-Float32((s ^ Float32(2.0)) / s)) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(2.000000026702864e-10)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = -((s ^ single(2.0)) / s) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 2.000000026702864 \cdot 10^{-10}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\frac{{s}^{2}}{s}}{x}\\
\end{array}
\end{array}
if (neg.f32 x) < 2.00000003e-10Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 88.8%
+-commutative88.8%
Simplified88.8%
if 2.00000003e-10 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 48.2%
neg-mul-148.2%
unsub-neg48.2%
Simplified48.2%
Taylor expanded in x around inf 42.4%
associate-*r/42.4%
neg-mul-142.4%
Simplified42.4%
neg-sub042.4%
flip--59.1%
metadata-eval59.1%
pow259.1%
add-sqr-sqrt59.1%
sqrt-unprod16.4%
sqr-neg16.4%
sqrt-unprod-0.0%
add-sqr-sqrt58.6%
sub-neg58.6%
neg-sub058.6%
add-sqr-sqrt-0.0%
sqrt-unprod16.4%
sqr-neg16.4%
sqrt-unprod59.1%
add-sqr-sqrt59.1%
Applied egg-rr59.1%
sub0-neg59.1%
Simplified59.1%
Final simplification80.1%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ x (- s))))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((x / -s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + exp((x / -s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(x / Float32(-s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((x / -s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{x}{-s}}}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(if (<= (- x) -2.00000009162741e-18)
(/ 1.0 (+ 1.0 (/ s x)))
(if (<= (- x) 9.999999747378752e-6)
(+ 0.5 (/ (* x 0.25) s))
(/ 1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -2.00000009162741e-18f) {
tmp = 1.0f / (1.0f + (s / x));
} else if (-x <= 9.999999747378752e-6f) {
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) :: tmp
if (-x <= (-2.00000009162741e-18)) then
tmp = 1.0e0 / (1.0e0 + (s / x))
else if (-x <= 9.999999747378752e-6) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-2.00000009162741e-18)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(s / x))); elseif (Float32(-x) <= Float32(9.999999747378752e-6)) 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) tmp = single(0.0); if (-x <= single(-2.00000009162741e-18)) tmp = single(1.0) / (single(1.0) + (s / x)); elseif (-x <= single(9.999999747378752e-6)) 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}
\mathbf{if}\;-x \leq -2.00000009162741 \cdot 10^{-18}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\mathbf{elif}\;-x \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -2.00000009e-18Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in x around inf 90.6%
if -2.00000009e-18 < (neg.f32 x) < 9.99999975e-6Initial program 99.5%
Taylor expanded in x around 0 74.8%
associate-*r/74.8%
Simplified74.8%
if 9.99999975e-6 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
unsub-neg51.4%
Simplified51.4%
Taylor expanded in x around inf 46.1%
associate-*r/46.1%
neg-mul-146.1%
Simplified46.1%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod46.1%
add-sqr-sqrt46.1%
clear-num51.4%
inv-pow51.4%
Applied egg-rr51.4%
unpow-151.4%
Simplified51.4%
Final simplification73.9%
(FPCore (x s)
:precision binary32
(if (<= (- x) -2.00000009162741e-18)
(- 1.0 (/ s x))
(if (<= (- x) 9.999999747378752e-6)
(+ 0.5 (/ (* x 0.25) s))
(/ 1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -2.00000009162741e-18f) {
tmp = 1.0f - (s / x);
} else if (-x <= 9.999999747378752e-6f) {
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) :: tmp
if (-x <= (-2.00000009162741e-18)) then
tmp = 1.0e0 - (s / x)
else if (-x <= 9.999999747378752e-6) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-2.00000009162741e-18)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999747378752e-6)) 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) tmp = single(0.0); if (-x <= single(-2.00000009162741e-18)) tmp = single(1.0) - (s / x); elseif (-x <= single(9.999999747378752e-6)) 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}
\mathbf{if}\;-x \leq -2.00000009162741 \cdot 10^{-18}:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -2.00000009e-18Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in x around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
Simplified89.0%
if -2.00000009e-18 < (neg.f32 x) < 9.99999975e-6Initial program 99.5%
Taylor expanded in x around 0 74.8%
associate-*r/74.8%
Simplified74.8%
if 9.99999975e-6 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
unsub-neg51.4%
Simplified51.4%
Taylor expanded in x around inf 46.1%
associate-*r/46.1%
neg-mul-146.1%
Simplified46.1%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod46.1%
add-sqr-sqrt46.1%
clear-num51.4%
inv-pow51.4%
Applied egg-rr51.4%
unpow-151.4%
Simplified51.4%
Final simplification73.4%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.999999943633011e-27) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if (-x <= 4.999999943633011e-27f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} 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 <= 4.999999943633011e-27) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
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(4.999999943633011e-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(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 <= single(4.999999943633011e-27)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); 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 4.999999943633011 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot 2 - x}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 4.99999994e-27Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 93.5%
+-commutative93.5%
Simplified93.5%
if 4.99999994e-27 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 53.9%
neg-mul-153.9%
unsub-neg53.9%
Simplified53.9%
Taylor expanded in x around inf 54.7%
associate-*r/54.7%
metadata-eval54.7%
Simplified54.7%
frac-sub59.5%
associate-*r/61.5%
fmm-def61.5%
*-rgt-identity61.5%
Applied egg-rr61.5%
associate-/l*59.5%
fmm-def59.5%
*-commutative59.5%
Simplified59.5%
Final simplification79.4%
(FPCore (x s) :precision binary32 (if (<= (- x) -2.00000009162741e-18) (- 1.0 (/ s x)) (if (<= (- x) 9.999999747378752e-6) 0.5 (/ 1.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -2.00000009162741e-18f) {
tmp = 1.0f - (s / x);
} else if (-x <= 9.999999747378752e-6f) {
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 <= (-2.00000009162741e-18)) then
tmp = 1.0e0 - (s / x)
else if (-x <= 9.999999747378752e-6) 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(-2.00000009162741e-18)) tmp = Float32(Float32(1.0) - Float32(s / x)); elseif (Float32(-x) <= Float32(9.999999747378752e-6)) 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(-2.00000009162741e-18)) tmp = single(1.0) - (s / x); elseif (-x <= single(9.999999747378752e-6)) 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 -2.00000009162741 \cdot 10^{-18}:\\
\;\;\;\;1 - \frac{s}{x}\\
\mathbf{elif}\;-x \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -2.00000009e-18Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in x around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
Simplified89.0%
if -2.00000009e-18 < (neg.f32 x) < 9.99999975e-6Initial program 99.5%
Taylor expanded in x around 0 70.5%
if 9.99999975e-6 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
unsub-neg51.4%
Simplified51.4%
Taylor expanded in x around inf 46.1%
associate-*r/46.1%
neg-mul-146.1%
Simplified46.1%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod46.1%
add-sqr-sqrt46.1%
clear-num51.4%
inv-pow51.4%
Applied egg-rr51.4%
unpow-151.4%
Simplified51.4%
(FPCore (x s) :precision binary32 (if (<= (- x) -5.000000136226006e-28) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ 2.0 (* x (/ -1.0 s))))))
float code(float x, float s) {
float tmp;
if (-x <= -5.000000136226006e-28f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (2.0f + (x * (-1.0f / s)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= (-5.000000136226006e-28)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (2.0e0 + (x * ((-1.0e0) / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-5.000000136226006e-28)) 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(-1.0) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-5.000000136226006e-28)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (single(2.0) + (x * (single(-1.0) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -5.000000136226006 \cdot 10^{-28}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -5.00000014e-28Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 94.4%
+-commutative94.4%
Simplified94.4%
if -5.00000014e-28 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 64.2%
neg-mul-164.2%
unsub-neg64.2%
Simplified64.2%
clear-num64.2%
associate-/r/64.8%
Applied egg-rr64.8%
Final simplification77.4%
(FPCore (x s) :precision binary32 (if (<= x -1.9999999494757503e-5) (* s (/ 1.0 x)) (if (<= x 2.00000009162741e-18) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999494757503e-5f) {
tmp = s * (1.0f / x);
} else if (x <= 2.00000009162741e-18f) {
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 <= (-1.9999999494757503e-5)) then
tmp = s * (1.0e0 / x)
else if (x <= 2.00000009162741e-18) 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(-1.9999999494757503e-5)) tmp = Float32(s * Float32(Float32(1.0) / x)); elseif (x <= Float32(2.00000009162741e-18)) 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(-1.9999999494757503e-5)) tmp = s * (single(1.0) / x); elseif (x <= single(2.00000009162741e-18)) 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 -1.9999999494757503 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{elif}\;x \leq 2.00000009162741 \cdot 10^{-18}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -1.99999995e-5Initial program 100.0%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
unsub-neg51.4%
Simplified51.4%
Taylor expanded in x around inf 46.1%
associate-*r/46.1%
neg-mul-146.1%
Simplified46.1%
div-inv46.1%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod46.1%
add-sqr-sqrt46.1%
Applied egg-rr46.1%
if -1.99999995e-5 < x < 2.00000009e-18Initial program 99.5%
Taylor expanded in x around 0 70.5%
if 2.00000009e-18 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in x around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
Simplified89.0%
(FPCore (x s) :precision binary32 (if (<= x 2.00000009162741e-18) (/ 1.0 (+ 2.0 (* x (/ -1.0 s)))) (/ 1.0 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= 2.00000009162741e-18f) {
tmp = 1.0f / (2.0f + (x * (-1.0f / 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 <= 2.00000009162741e-18) then
tmp = 1.0e0 / (2.0e0 + (x * ((-1.0e0) / s)))
else
tmp = 1.0e0 / (1.0e0 + (s / x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(2.00000009162741e-18)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(x * Float32(Float32(-1.0) / 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 <= single(2.00000009162741e-18)) tmp = single(1.0) / (single(2.0) + (x * (single(-1.0) / s))); else tmp = single(1.0) / (single(1.0) + (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.00000009162741 \cdot 10^{-18}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{-1}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < 2.00000009e-18Initial program 99.7%
Taylor expanded in x around 0 64.6%
neg-mul-164.6%
unsub-neg64.6%
Simplified64.6%
clear-num64.6%
associate-/r/65.1%
Applied egg-rr65.1%
if 2.00000009e-18 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in x around inf 90.6%
Final simplification73.6%
(FPCore (x s) :precision binary32 (if (<= (- x) -2.00000009162741e-18) (/ 1.0 (+ 1.0 (/ s x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -2.00000009162741e-18f) {
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 <= (-2.00000009162741e-18)) 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(-x) <= Float32(-2.00000009162741e-18)) 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 <= single(-2.00000009162741e-18)) 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}\;-x \leq -2.00000009162741 \cdot 10^{-18}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -2.00000009e-18Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in x around inf 90.6%
if -2.00000009e-18 < (neg.f32 x) Initial program 99.7%
Taylor expanded in x around 0 64.6%
neg-mul-164.6%
unsub-neg64.6%
Simplified64.6%
(FPCore (x s) :precision binary32 (if (<= x -1.9999999494757503e-5) (* s (/ 1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999494757503e-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 <= (-1.9999999494757503e-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(-1.9999999494757503e-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(-1.9999999494757503e-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 -1.9999999494757503 \cdot 10^{-5}:\\
\;\;\;\;s \cdot \frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.99999995e-5Initial program 100.0%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
unsub-neg51.4%
Simplified51.4%
Taylor expanded in x around inf 46.1%
associate-*r/46.1%
neg-mul-146.1%
Simplified46.1%
div-inv46.1%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod46.1%
add-sqr-sqrt46.1%
Applied egg-rr46.1%
if -1.99999995e-5 < x Initial program 99.7%
Taylor expanded in x around 0 52.8%
(FPCore (x s) :precision binary32 (if (<= x -1.9999999494757503e-5) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.9999999494757503e-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 <= (-1.9999999494757503e-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(-1.9999999494757503e-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(-1.9999999494757503e-5)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9999999494757503 \cdot 10^{-5}:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.99999995e-5Initial program 100.0%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
unsub-neg51.4%
Simplified51.4%
Taylor expanded in x around inf 46.1%
associate-*r/46.1%
neg-mul-146.1%
Simplified46.1%
add-sqr-sqrt-0.0%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod46.1%
add-sqr-sqrt46.1%
*-un-lft-identity46.1%
Applied egg-rr46.1%
*-lft-identity46.1%
Simplified46.1%
if -1.99999995e-5 < x Initial program 99.7%
Taylor expanded in x around 0 52.8%
(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 40.7%
herbie shell --seed 2024160
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))