
(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 (exp (- (log1p (exp (- (/ x s)))))))
float code(float x, float s) {
return expf(-log1pf(expf(-(x / s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(-Float32(x / s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}
\end{array}
Initial program 99.7%
div-inv99.7%
exp-prod83.4%
neg-mul-183.4%
exp-prod83.4%
pow-pow99.7%
div-inv99.7%
Applied egg-rr99.7%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow (exp -2.0) (/ (* x 0.5) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-2.0f), ((x * 0.5f) / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp((-2.0e0)) ** ((x * 0.5e0) / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-2.0)) ^ Float32(Float32(x * Float32(0.5)) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-2.0)) ^ ((x * single(0.5)) / s))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-2}\right)}^{\left(\frac{x \cdot 0.5}{s}\right)}}
\end{array}
Initial program 99.7%
distribute-frac-neg99.7%
exp-neg99.7%
Applied egg-rr99.7%
inv-pow99.7%
pow-exp99.7%
*-commutative99.7%
pow-exp99.7%
sqr-pow99.7%
pow-prod-down99.7%
prod-exp99.8%
metadata-eval99.8%
div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
*-commutative99.8%
associate-*r/99.8%
Simplified99.8%
Final simplification99.8%
(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.7%
Final simplification99.7%
(FPCore (x s)
:precision binary32
(if (<= x -4.000000060189865e+30)
(/ 1.0 (/ x s))
(if (<= x -5.00000011871114e-34)
(/ 1.0 (/ (- 4.0 (* x (/ (/ x s) s))) (+ (/ x s) 2.0)))
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))))))
float code(float x, float s) {
float tmp;
if (x <= -4.000000060189865e+30f) {
tmp = 1.0f / (x / s);
} else if (x <= -5.00000011871114e-34f) {
tmp = 1.0f / ((4.0f - (x * ((x / s) / s))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-4.000000060189865e+30)) then
tmp = 1.0e0 / (x / s)
else if (x <= (-5.00000011871114e-34)) then
tmp = 1.0e0 / ((4.0e0 - (x * ((x / s) / s))) / ((x / s) + 2.0e0))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.000000060189865e+30)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(-5.00000011871114e-34)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x * Float32(Float32(x / s) / s))) / Float32(Float32(x / s) + Float32(2.0)))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.000000060189865e+30)) tmp = single(1.0) / (x / s); elseif (x <= single(-5.00000011871114e-34)) tmp = single(1.0) / ((single(4.0) - (x * ((x / s) / s))) / ((x / s) + single(2.0))); else tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.000000060189865 \cdot 10^{+30}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq -5.00000011871114 \cdot 10^{-34}:\\
\;\;\;\;\frac{1}{\frac{4 - x \cdot \frac{\frac{x}{s}}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -4.00000006e30Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 85.6%
associate-*r/85.6%
neg-mul-185.6%
Simplified85.6%
add-sqr-sqrt-0.0%
sqrt-unprod85.6%
sqr-neg85.6%
sqrt-unprod85.6%
add-sqr-sqrt85.6%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
if -4.00000006e30 < x < -5.00000012e-34Initial program 99.4%
Taylor expanded in x around 0 37.8%
neg-mul-137.8%
unsub-neg37.8%
Simplified37.8%
*-un-lft-identity37.8%
cancel-sign-sub-inv37.8%
metadata-eval37.8%
add-log-exp93.3%
pow-exp93.3%
flip-+17.8%
metadata-eval17.8%
pow-exp17.8%
add-log-exp17.8%
neg-mul-117.8%
pow-exp17.8%
add-log-exp18.6%
neg-mul-118.6%
distribute-neg-frac218.6%
distribute-neg-frac218.6%
pow-exp18.6%
Applied egg-rr57.5%
distribute-frac-neg257.5%
distribute-frac-neg57.5%
associate-*r/57.5%
add-sqr-sqrt-0.0%
sqrt-unprod61.4%
sqr-neg61.4%
sqrt-unprod56.7%
add-sqr-sqrt56.7%
clear-num56.7%
clear-num56.7%
Applied egg-rr56.7%
*-commutative56.7%
*-un-lft-identity56.7%
times-frac62.3%
add-sqr-sqrt62.3%
sqrt-unprod61.7%
sqr-neg61.7%
sqrt-unprod-0.0%
add-sqr-sqrt63.1%
Applied egg-rr63.1%
if -5.00000012e-34 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 96.4%
+-commutative96.4%
Simplified96.4%
Final simplification83.8%
(FPCore (x s)
:precision binary32
(if (<= x -4.000000060189865e+30)
(/ 1.0 (/ x s))
(if (<= x -5.00000011871114e-34)
(/ 1.0 (/ (- 4.0 (/ x (* s (/ s x)))) (+ (/ x s) 2.0)))
(/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))))))
float code(float x, float s) {
float tmp;
if (x <= -4.000000060189865e+30f) {
tmp = 1.0f / (x / s);
} else if (x <= -5.00000011871114e-34f) {
tmp = 1.0f / ((4.0f - (x / (s * (s / x)))) / ((x / s) + 2.0f));
} else {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-4.000000060189865e+30)) then
tmp = 1.0e0 / (x / s)
else if (x <= (-5.00000011871114e-34)) then
tmp = 1.0e0 / ((4.0e0 - (x / (s * (s / x)))) / ((x / s) + 2.0e0))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-4.000000060189865e+30)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(-5.00000011871114e-34)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(x / Float32(s * Float32(s / x)))) / Float32(Float32(x / s) + Float32(2.0)))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-4.000000060189865e+30)) tmp = single(1.0) / (x / s); elseif (x <= single(-5.00000011871114e-34)) tmp = single(1.0) / ((single(4.0) - (x / (s * (s / x)))) / ((x / s) + single(2.0))); else tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.000000060189865 \cdot 10^{+30}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq -5.00000011871114 \cdot 10^{-34}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s \cdot \frac{s}{x}}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -4.00000006e30Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 85.6%
associate-*r/85.6%
neg-mul-185.6%
Simplified85.6%
add-sqr-sqrt-0.0%
sqrt-unprod85.6%
sqr-neg85.6%
sqrt-unprod85.6%
add-sqr-sqrt85.6%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
if -4.00000006e30 < x < -5.00000012e-34Initial program 99.4%
Taylor expanded in x around 0 37.8%
neg-mul-137.8%
unsub-neg37.8%
Simplified37.8%
*-un-lft-identity37.8%
cancel-sign-sub-inv37.8%
metadata-eval37.8%
add-log-exp93.3%
pow-exp93.3%
flip-+17.8%
metadata-eval17.8%
pow-exp17.8%
add-log-exp17.8%
neg-mul-117.8%
pow-exp17.8%
add-log-exp18.6%
neg-mul-118.6%
distribute-neg-frac218.6%
distribute-neg-frac218.6%
pow-exp18.6%
Applied egg-rr57.5%
clear-num57.5%
frac-times60.3%
*-un-lft-identity60.3%
add-sqr-sqrt-0.0%
sqrt-unprod61.4%
sqr-neg61.4%
sqrt-unprod59.5%
add-sqr-sqrt59.5%
add-sqr-sqrt-0.0%
sqrt-unprod61.6%
sqr-neg61.6%
sqrt-unprod60.3%
add-sqr-sqrt60.3%
Applied egg-rr60.3%
if -5.00000012e-34 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 96.4%
+-commutative96.4%
Simplified96.4%
Final simplification82.7%
(FPCore (x s)
:precision binary32
(if (<= x -0.0020000000949949026)
(/ 1.0 (/ x s))
(if (<= x 3.99999987306209e-19)
(+ 0.5 (/ (* x 0.25) s))
(/ 1.0 (+ 1.0 (/ s x))))))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
tmp = 1.0f / (x / s);
} else if (x <= 3.99999987306209e-19f) {
tmp = 0.5f + ((x * 0.25f) / 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 <= (-0.0020000000949949026e0)) then
tmp = 1.0e0 / (x / s)
else if (x <= 3.99999987306209e-19) then
tmp = 0.5e0 + ((x * 0.25e0) / 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(-0.0020000000949949026)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(3.99999987306209e-19)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / 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(-0.0020000000949949026)) tmp = single(1.0) / (x / s); elseif (x <= single(3.99999987306209e-19)) tmp = single(0.5) + ((x * single(0.25)) / 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 -0.0020000000949949026:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 3.99999987306209 \cdot 10^{-19}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 100.0%
Taylor expanded in x around 0 46.1%
neg-mul-146.1%
unsub-neg46.1%
Simplified46.1%
Taylor expanded in x around inf 40.9%
associate-*r/40.9%
neg-mul-140.9%
Simplified40.9%
add-sqr-sqrt-0.0%
sqrt-unprod51.4%
sqr-neg51.4%
sqrt-unprod40.9%
add-sqr-sqrt40.9%
clear-num46.1%
inv-pow46.1%
Applied egg-rr46.1%
unpow-146.1%
Simplified46.1%
if -0.00200000009 < x < 3.99999987e-19Initial program 99.2%
Taylor expanded in x around 0 58.8%
associate-*r/58.8%
Simplified58.8%
if 3.99999987e-19 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
Taylor expanded in x around inf 90.4%
Final simplification68.6%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ 1.0 (/ x s)) (if (<= x 2.000000026702864e-10) (+ 0.5 (/ (* x 0.25) s)) (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
tmp = 1.0f / (x / s);
} else if (x <= 2.000000026702864e-10f) {
tmp = 0.5f + ((x * 0.25f) / s);
} 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 <= (-0.0020000000949949026e0)) then
tmp = 1.0e0 / (x / s)
else if (x <= 2.000000026702864e-10) then
tmp = 0.5e0 + ((x * 0.25e0) / s)
else
tmp = 1.0e0 - (s / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.0020000000949949026)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(2.000000026702864e-10)) tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s)); 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(-0.0020000000949949026)) tmp = single(1.0) / (x / s); elseif (x <= single(2.000000026702864e-10)) tmp = single(0.5) + ((x * single(0.25)) / s); else tmp = single(1.0) - (s / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0020000000949949026:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 2.000000026702864 \cdot 10^{-10}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 100.0%
Taylor expanded in x around 0 46.1%
neg-mul-146.1%
unsub-neg46.1%
Simplified46.1%
Taylor expanded in x around inf 40.9%
associate-*r/40.9%
neg-mul-140.9%
Simplified40.9%
add-sqr-sqrt-0.0%
sqrt-unprod51.4%
sqr-neg51.4%
sqrt-unprod40.9%
add-sqr-sqrt40.9%
clear-num46.1%
inv-pow46.1%
Applied egg-rr46.1%
unpow-146.1%
Simplified46.1%
if -0.00200000009 < x < 2.00000003e-10Initial program 99.3%
Taylor expanded in x around 0 57.9%
associate-*r/57.9%
Simplified57.9%
if 2.00000003e-10 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
Taylor expanded in x around inf 95.1%
mul-1-neg95.1%
unsub-neg95.1%
Simplified95.1%
Final simplification68.1%
(FPCore (x s) :precision binary32 (if (<= x -5.00000011871114e-34) (/ 1.0 (- 2.0 (/ x s))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -5.00000011871114e-34f) {
tmp = 1.0f / (2.0f - (x / s));
} else {
tmp = 1.0f / (1.0f + (1.0f / (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 <= (-5.00000011871114e-34)) then
tmp = 1.0e0 / (2.0e0 - (x / s))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-5.00000011871114e-34)) tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-5.00000011871114e-34)) tmp = single(1.0) / (single(2.0) - (x / s)); else tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.00000011871114 \cdot 10^{-34}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -5.00000012e-34Initial program 99.4%
Taylor expanded in x around 0 45.1%
neg-mul-145.1%
unsub-neg45.1%
Simplified45.1%
if -5.00000012e-34 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 96.4%
+-commutative96.4%
Simplified96.4%
Final simplification74.1%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ 1.0 (/ x s)) (if (<= x 2.000000026702864e-10) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
tmp = 1.0f / (x / s);
} else if (x <= 2.000000026702864e-10f) {
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 <= (-0.0020000000949949026e0)) then
tmp = 1.0e0 / (x / s)
else if (x <= 2.000000026702864e-10) 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(-0.0020000000949949026)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(2.000000026702864e-10)) 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(-0.0020000000949949026)) tmp = single(1.0) / (x / s); elseif (x <= single(2.000000026702864e-10)) 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 -0.0020000000949949026:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 2.000000026702864 \cdot 10^{-10}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 100.0%
Taylor expanded in x around 0 46.1%
neg-mul-146.1%
unsub-neg46.1%
Simplified46.1%
Taylor expanded in x around inf 40.9%
associate-*r/40.9%
neg-mul-140.9%
Simplified40.9%
add-sqr-sqrt-0.0%
sqrt-unprod51.4%
sqr-neg51.4%
sqrt-unprod40.9%
add-sqr-sqrt40.9%
clear-num46.1%
inv-pow46.1%
Applied egg-rr46.1%
unpow-146.1%
Simplified46.1%
if -0.00200000009 < x < 2.00000003e-10Initial program 99.3%
Taylor expanded in x around 0 56.6%
if 2.00000003e-10 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
Taylor expanded in x around inf 95.1%
mul-1-neg95.1%
unsub-neg95.1%
Simplified95.1%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ s x) (if (<= x 2.000000026702864e-10) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
tmp = s / x;
} else if (x <= 2.000000026702864e-10f) {
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 <= (-0.0020000000949949026e0)) then
tmp = s / x
else if (x <= 2.000000026702864e-10) 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(-0.0020000000949949026)) tmp = Float32(s / x); elseif (x <= Float32(2.000000026702864e-10)) 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(-0.0020000000949949026)) tmp = s / x; elseif (x <= single(2.000000026702864e-10)) 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 -0.0020000000949949026:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{elif}\;x \leq 2.000000026702864 \cdot 10^{-10}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 100.0%
Taylor expanded in x around 0 46.1%
neg-mul-146.1%
unsub-neg46.1%
Simplified46.1%
Taylor expanded in x around inf 40.9%
associate-*r/40.9%
neg-mul-140.9%
Simplified40.9%
add-sqr-sqrt-0.0%
sqrt-unprod51.4%
sqr-neg51.4%
sqrt-unprod40.9%
add-sqr-sqrt40.9%
div-inv40.9%
Applied egg-rr40.9%
associate-*r/40.9%
*-rgt-identity40.9%
Simplified40.9%
if -0.00200000009 < x < 2.00000003e-10Initial program 99.3%
Taylor expanded in x around 0 56.6%
if 2.00000003e-10 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
Taylor expanded in x around inf 95.1%
mul-1-neg95.1%
unsub-neg95.1%
Simplified95.1%
(FPCore (x s) :precision binary32 (if (<= x 3.99999987306209e-19) (/ 1.0 (/ (- (* s 2.0) x) s)) (/ 1.0 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= 3.99999987306209e-19f) {
tmp = 1.0f / (((s * 2.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 <= 3.99999987306209e-19) then
tmp = 1.0e0 / (((s * 2.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 (x <= Float32(3.99999987306209e-19)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(s * Float32(2.0)) - 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 <= single(3.99999987306209e-19)) tmp = single(1.0) / (((s * single(2.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}\;x \leq 3.99999987306209 \cdot 10^{-19}:\\
\;\;\;\;\frac{1}{\frac{s \cdot 2 - x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < 3.99999987e-19Initial program 99.6%
Taylor expanded in x around 0 52.6%
neg-mul-152.6%
unsub-neg52.6%
Simplified52.6%
Taylor expanded in s around 0 52.6%
*-commutative52.6%
Simplified52.6%
if 3.99999987e-19 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
Taylor expanded in x around inf 90.4%
(FPCore (x s) :precision binary32 (if (<= x 3.99999987306209e-19) (/ 1.0 (- 2.0 (/ x s))) (/ 1.0 (+ 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= 3.99999987306209e-19f) {
tmp = 1.0f / (2.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 <= 3.99999987306209e-19) then
tmp = 1.0e0 / (2.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 (x <= Float32(3.99999987306209e-19)) tmp = Float32(Float32(1.0) / Float32(Float32(2.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 <= single(3.99999987306209e-19)) tmp = single(1.0) / (single(2.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}\;x \leq 3.99999987306209 \cdot 10^{-19}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{s}{x}}\\
\end{array}
\end{array}
if x < 3.99999987e-19Initial program 99.6%
Taylor expanded in x around 0 52.6%
neg-mul-152.6%
unsub-neg52.6%
Simplified52.6%
if 3.99999987e-19 < x Initial program 100.0%
distribute-frac-neg100.0%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
Taylor expanded in x around inf 90.4%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
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 <= (-0.0020000000949949026e0)) 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(-0.0020000000949949026)) 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(-0.0020000000949949026)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0020000000949949026:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 100.0%
Taylor expanded in x around 0 46.1%
neg-mul-146.1%
unsub-neg46.1%
Simplified46.1%
Taylor expanded in x around inf 40.9%
associate-*r/40.9%
neg-mul-140.9%
Simplified40.9%
add-sqr-sqrt-0.0%
sqrt-unprod51.4%
sqr-neg51.4%
sqrt-unprod40.9%
add-sqr-sqrt40.9%
div-inv40.9%
Applied egg-rr40.9%
associate-*r/40.9%
*-rgt-identity40.9%
Simplified40.9%
if -0.00200000009 < x Initial program 99.6%
Taylor expanded in x around 0 43.5%
(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.7%
Taylor expanded in x around 0 33.8%
herbie shell --seed 2024144
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))