
(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(x / Float32(-s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{\frac{x}{-s}}\right)}
\end{array}
Initial program 99.7%
div-inv99.7%
exp-prod76.4%
neg-mul-176.4%
exp-prod76.4%
pow-pow99.7%
div-inv99.7%
Applied egg-rr99.7%
add-exp-log99.7%
log-rec99.7%
log1p-define99.8%
add-exp-log99.8%
log-pow99.8%
rem-log-exp99.8%
pow-exp99.8%
inv-pow99.8%
add-exp-log99.8%
neg-log99.8%
add-log-exp99.8%
distribute-neg-frac299.8%
Applied egg-rr99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow (exp -0.5) (* 2.0 (/ x s))))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(-0.5f), (2.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((-0.5e0)) ** (2.0e0 * (x / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-0.5)) ^ Float32(Float32(2.0) * Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(single(-0.5)) ^ (single(2.0) * (x / s)))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{-0.5}\right)}^{\left(2 \cdot \frac{x}{s}\right)}}
\end{array}
Initial program 99.7%
div-inv99.7%
exp-prod76.4%
neg-mul-176.4%
exp-prod76.4%
pow-pow99.7%
div-inv99.7%
Applied egg-rr99.7%
add-sqr-sqrt99.7%
unpow-prod-down99.7%
Applied egg-rr99.7%
pow-sqr99.7%
*-commutative99.7%
Simplified99.7%
+-commutative99.7%
add-sqr-sqrt99.7%
fma-define99.7%
pow-unpow99.7%
sqrt-pow199.7%
metadata-eval99.7%
pow199.7%
pow1/299.7%
pow-exp99.7%
metadata-eval99.7%
pow-unpow99.7%
sqrt-pow199.7%
metadata-eval99.7%
pow199.7%
pow1/299.7%
pow-exp99.7%
metadata-eval99.7%
Applied egg-rr99.7%
fma-undefine99.7%
pow-sqr99.7%
Simplified99.7%
Final simplification99.7%
(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.7%
Final simplification99.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -20.0)
(/ (- x s) x)
(if (<= t_0 0.0010000000474974513)
(+ 0.5 (/ (* x 0.25) s))
(+ -1.0 (- 1.0 (/ s x)))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -20.0f) {
tmp = (x - s) / x;
} else if (t_0 <= 0.0010000000474974513f) {
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) :: t_0
real(4) :: tmp
t_0 = x / -s
if (t_0 <= (-20.0e0)) then
tmp = (x - s) / x
else if (t_0 <= 0.0010000000474974513e0) 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) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-20.0)) tmp = Float32(Float32(x - s) / x); elseif (t_0 <= Float32(0.0010000000474974513)) 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) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(-20.0)) tmp = (x - s) / x; elseif (t_0 <= single(0.0010000000474974513)) 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}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -20:\\
\;\;\;\;\frac{x - s}{x}\\
\mathbf{elif}\;t\_0 \leq 0.0010000000474974513:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(1 - \frac{s}{x}\right)\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
exp-prod100.0%
Applied egg-rr100.0%
exp-1-e100.0%
Simplified100.0%
Taylor expanded in x around 0 94.3%
+-commutative94.3%
log-E94.3%
*-rgt-identity94.3%
Simplified94.3%
Taylor expanded in x around inf 94.3%
mul-1-neg94.3%
unsub-neg94.3%
Simplified94.3%
Taylor expanded in x around 0 94.4%
if -20 < (/.f32 (neg.f32 x) s) < 0.00100000005Initial program 99.6%
Taylor expanded in x around 0 96.6%
associate-*r/96.6%
*-commutative96.6%
Simplified96.6%
if 0.00100000005 < (/.f32 (neg.f32 x) s) Initial program 99.5%
Taylor expanded in x around 0 40.6%
mul-1-neg40.6%
unsub-neg40.6%
Simplified40.6%
Taylor expanded in x around inf 37.1%
associate-*r/37.1%
mul-1-neg37.1%
Simplified37.1%
expm1-log1p-u37.1%
expm1-undefine78.6%
associate-/r/78.6%
add-sqr-sqrt78.6%
sqrt-unprod76.1%
sqr-neg76.1%
sqrt-unprod-0.0%
add-sqr-sqrt76.7%
frac-2neg76.7%
metadata-eval76.7%
add-sqr-sqrt76.7%
sqrt-unprod74.6%
sqr-neg74.6%
sqrt-unprod-0.0%
add-sqr-sqrt78.6%
Applied egg-rr78.6%
sub-neg78.6%
log1p-undefine78.6%
rem-exp-log78.6%
associate-*l/78.6%
associate-*r/78.6%
mul-1-neg78.6%
unsub-neg78.6%
metadata-eval78.6%
Simplified78.6%
Final simplification88.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -20.0)
(/ (- x s) x)
(if (<= t_0 4.999999873689376e-6)
(+ 0.5 (/ (* x 0.25) s))
(/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -20.0f) {
tmp = (x - s) / x;
} else if (t_0 <= 4.999999873689376e-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) :: t_0
real(4) :: tmp
t_0 = x / -s
if (t_0 <= (-20.0e0)) then
tmp = (x - s) / x
else if (t_0 <= 4.999999873689376e-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) t_0 = Float32(x / Float32(-s)) tmp = Float32(0.0) if (t_0 <= Float32(-20.0)) tmp = Float32(Float32(x - s) / x); elseif (t_0 <= Float32(4.999999873689376e-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) t_0 = x / -s; tmp = single(0.0); if (t_0 <= single(-20.0)) tmp = (x - s) / x; elseif (t_0 <= single(4.999999873689376e-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}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -20:\\
\;\;\;\;\frac{x - s}{x}\\
\mathbf{elif}\;t\_0 \leq 4.999999873689376 \cdot 10^{-6}:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -20Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
exp-prod100.0%
Applied egg-rr100.0%
exp-1-e100.0%
Simplified100.0%
Taylor expanded in x around 0 94.3%
+-commutative94.3%
log-E94.3%
*-rgt-identity94.3%
Simplified94.3%
Taylor expanded in x around inf 94.3%
mul-1-neg94.3%
unsub-neg94.3%
Simplified94.3%
Taylor expanded in x around 0 94.4%
if -20 < (/.f32 (neg.f32 x) s) < 4.99999987e-6Initial program 99.7%
Taylor expanded in x around 0 96.4%
associate-*r/96.4%
*-commutative96.4%
Simplified96.4%
if 4.99999987e-6 < (/.f32 (neg.f32 x) s) Initial program 99.5%
Taylor expanded in x around 0 42.2%
mul-1-neg42.2%
unsub-neg42.2%
Simplified42.2%
Taylor expanded in x around inf 36.5%
associate-*r/36.5%
mul-1-neg36.5%
Simplified36.5%
Final simplification70.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ x (- s))))
(if (<= t_0 -80.0)
(/ (- x s) x)
(if (<= t_0 4.999999980020986e-13) 0.5 (/ -1.0 (/ x s))))))
float code(float x, float s) {
float t_0 = x / -s;
float tmp;
if (t_0 <= -80.0f) {
tmp = (x - s) / x;
} else if (t_0 <= 4.999999980020986e-13f) {
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) :: t_0
real(4) :: tmp
t_0 = x / -s
if (t_0 <= (-80.0e0)) then
tmp = (x - s) / x
else if (t_0 <= 4.999999980020986e-13) then
tmp = 0.5e0
else
tmp = (-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(-80.0)) tmp = Float32(Float32(x - s) / x); elseif (t_0 <= Float32(4.999999980020986e-13)) tmp = Float32(0.5); else tmp = 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(-80.0)) tmp = (x - s) / x; elseif (t_0 <= single(4.999999980020986e-13)) tmp = single(0.5); else tmp = 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 -80:\\
\;\;\;\;\frac{x - s}{x}\\
\mathbf{elif}\;t\_0 \leq 4.999999980020986 \cdot 10^{-13}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -80Initial program 100.0%
distribute-frac-neg100.0%
exp-neg100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
exp-prod100.0%
Applied egg-rr100.0%
exp-1-e100.0%
Simplified100.0%
Taylor expanded in x around 0 95.9%
+-commutative95.9%
log-E95.9%
*-rgt-identity95.9%
Simplified95.9%
Taylor expanded in x around inf 95.8%
mul-1-neg95.8%
unsub-neg95.8%
Simplified95.8%
Taylor expanded in x around 0 95.9%
if -80 < (/.f32 (neg.f32 x) s) < 4.99999998e-13Initial program 99.7%
Taylor expanded in x around 0 78.6%
if 4.99999998e-13 < (/.f32 (neg.f32 x) s) Initial program 99.4%
Taylor expanded in x around 0 43.2%
mul-1-neg43.2%
unsub-neg43.2%
Simplified43.2%
Taylor expanded in x around inf 36.1%
associate-*r/36.1%
mul-1-neg36.1%
Simplified36.1%
Final simplification67.5%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 4.999999873689376e-5) (/ 1.0 (+ (+ 2.0 (/ 1.0 (+ 1.0 (/ x s)))) -1.0)) (+ -1.0 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if ((x / -s) <= 4.999999873689376e-5f) {
tmp = 1.0f / ((2.0f + (1.0f / (1.0f + (x / s)))) + -1.0f);
} 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) <= 4.999999873689376e-5) then
tmp = 1.0e0 / ((2.0e0 + (1.0e0 / (1.0e0 + (x / s)))) + (-1.0e0))
else
tmp = (-1.0e0) + (1.0e0 - (s / x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(x / Float32(-s)) <= Float32(4.999999873689376e-5)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(2.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))) + Float32(-1.0))); 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(4.999999873689376e-5)) tmp = single(1.0) / ((single(2.0) + (single(1.0) / (single(1.0) + (x / s)))) + single(-1.0)); 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 4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\left(2 + \frac{1}{1 + \frac{x}{s}}\right) + -1}\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(1 - \frac{s}{x}\right)\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 4.99999987e-5Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
exp-prod99.9%
Applied egg-rr99.9%
exp-1-e99.9%
Simplified99.9%
Taylor expanded in x around 0 93.6%
+-commutative93.6%
log-E93.6%
*-rgt-identity93.6%
Simplified93.6%
expm1-log1p-u93.6%
expm1-undefine93.6%
Applied egg-rr93.6%
sub-neg93.6%
log1p-undefine93.6%
rem-exp-log93.6%
associate-+r+93.6%
metadata-eval93.6%
+-commutative93.6%
metadata-eval93.6%
Simplified93.6%
if 4.99999987e-5 < (/.f32 (neg.f32 x) s) Initial program 99.5%
Taylor expanded in x around 0 41.6%
mul-1-neg41.6%
unsub-neg41.6%
Simplified41.6%
Taylor expanded in x around inf 36.7%
associate-*r/36.7%
mul-1-neg36.7%
Simplified36.7%
expm1-log1p-u36.7%
expm1-undefine77.5%
associate-/r/77.5%
add-sqr-sqrt77.5%
sqrt-unprod74.7%
sqr-neg74.7%
sqrt-unprod-0.0%
add-sqr-sqrt75.3%
frac-2neg75.3%
metadata-eval75.3%
add-sqr-sqrt75.3%
sqrt-unprod73.1%
sqr-neg73.1%
sqrt-unprod-0.0%
add-sqr-sqrt77.5%
Applied egg-rr77.5%
sub-neg77.5%
log1p-undefine77.5%
rem-exp-log77.5%
associate-*l/77.5%
associate-*r/77.5%
mul-1-neg77.5%
unsub-neg77.5%
metadata-eval77.5%
Simplified77.5%
Final simplification87.0%
(FPCore (x s) :precision binary32 (if (<= (/ x (- s)) 4.999999873689376e-5) (/ 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) <= 4.999999873689376e-5f) {
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) <= 4.999999873689376e-5) 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(x / Float32(-s)) <= Float32(4.999999873689376e-5)) 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(4.999999873689376e-5)) 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 4.999999873689376 \cdot 10^{-5}:\\
\;\;\;\;\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) < 4.99999987e-5Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 93.6%
if 4.99999987e-5 < (/.f32 (neg.f32 x) s) Initial program 99.5%
Taylor expanded in x around 0 41.6%
mul-1-neg41.6%
unsub-neg41.6%
Simplified41.6%
Taylor expanded in x around inf 36.7%
associate-*r/36.7%
mul-1-neg36.7%
Simplified36.7%
expm1-log1p-u36.7%
expm1-undefine77.5%
associate-/r/77.5%
add-sqr-sqrt77.5%
sqrt-unprod74.7%
sqr-neg74.7%
sqrt-unprod-0.0%
add-sqr-sqrt75.3%
frac-2neg75.3%
metadata-eval75.3%
add-sqr-sqrt75.3%
sqrt-unprod73.1%
sqr-neg73.1%
sqrt-unprod-0.0%
add-sqr-sqrt77.5%
Applied egg-rr77.5%
sub-neg77.5%
log1p-undefine77.5%
rem-exp-log77.5%
associate-*l/77.5%
associate-*r/77.5%
mul-1-neg77.5%
unsub-neg77.5%
metadata-eval77.5%
Simplified77.5%
Final simplification87.0%
(FPCore (x s) :precision binary32 (if (<= x -399999991808.0) (/ 1.0 (/ x s)) (if (<= x 4.999999918875795e-18) 0.5 (/ (- x s) x))))
float code(float x, float s) {
float tmp;
if (x <= -399999991808.0f) {
tmp = 1.0f / (x / s);
} else if (x <= 4.999999918875795e-18f) {
tmp = 0.5f;
} else {
tmp = (x - 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 <= (-399999991808.0e0)) then
tmp = 1.0e0 / (x / s)
else if (x <= 4.999999918875795e-18) then
tmp = 0.5e0
else
tmp = (x - s) / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-399999991808.0)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(4.999999918875795e-18)) tmp = Float32(0.5); else tmp = Float32(Float32(x - s) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-399999991808.0)) tmp = single(1.0) / (x / s); elseif (x <= single(4.999999918875795e-18)) tmp = single(0.5); else tmp = (x - s) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -399999991808:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 4.999999918875795 \cdot 10^{-18}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - s}{x}\\
\end{array}
\end{array}
if x < -399999992000Initial program 100.0%
Taylor expanded in x around 0 74.8%
mul-1-neg74.8%
unsub-neg74.8%
Simplified74.8%
Taylor expanded in x around inf 74.8%
associate-*r/74.8%
mul-1-neg74.8%
Simplified74.8%
distribute-frac-neg74.8%
distribute-frac-neg274.8%
inv-pow74.8%
add-sqr-sqrt74.8%
sqrt-pow174.8%
add-sqr-sqrt-0.0%
sqrt-unprod71.1%
sqr-neg71.1%
sqrt-unprod71.1%
add-sqr-sqrt71.1%
metadata-eval71.1%
sqrt-pow171.1%
add-sqr-sqrt-0.0%
sqrt-unprod71.1%
sqr-neg71.1%
sqrt-unprod71.1%
add-sqr-sqrt71.1%
metadata-eval71.1%
Applied egg-rr71.1%
pow-sqr74.8%
metadata-eval74.8%
unpow-174.8%
Simplified74.8%
if -399999992000 < x < 4.99999992e-18Initial program 99.4%
Taylor expanded in x around 0 38.7%
if 4.99999992e-18 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
exp-prod100.0%
Applied egg-rr100.0%
exp-1-e100.0%
Simplified100.0%
Taylor expanded in x around 0 95.2%
+-commutative95.2%
log-E95.2%
*-rgt-identity95.2%
Simplified95.2%
Taylor expanded in x around inf 88.2%
mul-1-neg88.2%
unsub-neg88.2%
Simplified88.2%
Taylor expanded in x around 0 88.2%
(FPCore (x s) :precision binary32 (if (<= x -399999991808.0) (/ 1.0 (/ x s)) (if (<= x 4.999999918875795e-18) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -399999991808.0f) {
tmp = 1.0f / (x / s);
} else if (x <= 4.999999918875795e-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 <= (-399999991808.0e0)) then
tmp = 1.0e0 / (x / s)
else if (x <= 4.999999918875795e-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(-399999991808.0)) tmp = Float32(Float32(1.0) / Float32(x / s)); elseif (x <= Float32(4.999999918875795e-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(-399999991808.0)) tmp = single(1.0) / (x / s); elseif (x <= single(4.999999918875795e-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 -399999991808:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 4.999999918875795 \cdot 10^{-18}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -399999992000Initial program 100.0%
Taylor expanded in x around 0 74.8%
mul-1-neg74.8%
unsub-neg74.8%
Simplified74.8%
Taylor expanded in x around inf 74.8%
associate-*r/74.8%
mul-1-neg74.8%
Simplified74.8%
distribute-frac-neg74.8%
distribute-frac-neg274.8%
inv-pow74.8%
add-sqr-sqrt74.8%
sqrt-pow174.8%
add-sqr-sqrt-0.0%
sqrt-unprod71.1%
sqr-neg71.1%
sqrt-unprod71.1%
add-sqr-sqrt71.1%
metadata-eval71.1%
sqrt-pow171.1%
add-sqr-sqrt-0.0%
sqrt-unprod71.1%
sqr-neg71.1%
sqrt-unprod71.1%
add-sqr-sqrt71.1%
metadata-eval71.1%
Applied egg-rr71.1%
pow-sqr74.8%
metadata-eval74.8%
unpow-174.8%
Simplified74.8%
if -399999992000 < x < 4.99999992e-18Initial program 99.4%
Taylor expanded in x around 0 38.7%
if 4.99999992e-18 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
exp-prod100.0%
Applied egg-rr100.0%
exp-1-e100.0%
Simplified100.0%
Taylor expanded in x around 0 95.2%
+-commutative95.2%
log-E95.2%
*-rgt-identity95.2%
Simplified95.2%
Taylor expanded in x around inf 88.2%
mul-1-neg88.2%
unsub-neg88.2%
Simplified88.2%
(FPCore (x s) :precision binary32 (if (<= x -20000000.0) (* s (/ -1.0 x)) (if (<= x 1.0000000195414814e-25) 0.5 (- 1.0 (/ s x)))))
float code(float x, float s) {
float tmp;
if (x <= -20000000.0f) {
tmp = s * (-1.0f / x);
} else if (x <= 1.0000000195414814e-25f) {
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 <= (-20000000.0e0)) then
tmp = s * ((-1.0e0) / x)
else if (x <= 1.0000000195414814e-25) 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(-20000000.0)) tmp = Float32(s * Float32(Float32(-1.0) / x)); elseif (x <= Float32(1.0000000195414814e-25)) 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(-20000000.0)) tmp = s * (single(-1.0) / x); elseif (x <= single(1.0000000195414814e-25)) 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 -20000000:\\
\;\;\;\;s \cdot \frac{-1}{x}\\
\mathbf{elif}\;x \leq 1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{s}{x}\\
\end{array}
\end{array}
if x < -2e7Initial program 100.0%
Taylor expanded in x around 0 68.1%
mul-1-neg68.1%
unsub-neg68.1%
Simplified68.1%
Taylor expanded in x around inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
associate-/r/60.4%
add-sqr-sqrt60.4%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod-0.0%
add-sqr-sqrt60.4%
frac-2neg60.4%
metadata-eval60.4%
add-sqr-sqrt60.4%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod-0.0%
add-sqr-sqrt60.4%
Applied egg-rr60.4%
if -2e7 < x < 1.00000002e-25Initial program 99.4%
Taylor expanded in x around 0 38.9%
if 1.00000002e-25 < x Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
exp-prod99.9%
Applied egg-rr99.9%
exp-1-e99.9%
Simplified99.9%
Taylor expanded in x around 0 95.3%
+-commutative95.3%
log-E95.3%
*-rgt-identity95.3%
Simplified95.3%
Taylor expanded in x around inf 83.4%
mul-1-neg83.4%
unsub-neg83.4%
Simplified83.4%
Final simplification62.4%
(FPCore (x s) :precision binary32 (if (<= x -20000000.0) (* s (/ -1.0 x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -20000000.0f) {
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 <= (-20000000.0e0)) 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(-20000000.0)) 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(-20000000.0)) 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 -20000000:\\
\;\;\;\;s \cdot \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2e7Initial program 100.0%
Taylor expanded in x around 0 68.1%
mul-1-neg68.1%
unsub-neg68.1%
Simplified68.1%
Taylor expanded in x around inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
associate-/r/60.4%
add-sqr-sqrt60.4%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod-0.0%
add-sqr-sqrt60.4%
frac-2neg60.4%
metadata-eval60.4%
add-sqr-sqrt60.4%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod-0.0%
add-sqr-sqrt60.4%
Applied egg-rr60.4%
if -2e7 < x Initial program 99.7%
Taylor expanded in x around 0 36.2%
Final simplification40.6%
(FPCore (x s) :precision binary32 (if (<= x -20000000.0) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -20000000.0f) {
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 <= (-20000000.0e0)) 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(-20000000.0)) 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(-20000000.0)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -20000000:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -2e7Initial program 100.0%
Taylor expanded in x around 0 68.1%
mul-1-neg68.1%
unsub-neg68.1%
Simplified68.1%
Taylor expanded in x around inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
associate-/r/60.4%
add-sqr-sqrt60.4%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod-0.0%
add-sqr-sqrt60.4%
frac-2neg60.4%
metadata-eval60.4%
add-sqr-sqrt60.4%
sqrt-unprod75.9%
sqr-neg75.9%
sqrt-unprod-0.0%
add-sqr-sqrt60.4%
Applied egg-rr60.4%
associate-*l/60.4%
neg-mul-160.4%
add-sqr-sqrt-0.0%
sqrt-unprod65.3%
sqr-neg65.3%
sqrt-unprod60.4%
add-sqr-sqrt60.4%
Applied egg-rr60.4%
if -2e7 < x Initial program 99.7%
Taylor expanded in x around 0 36.2%
(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 30.9%
herbie shell --seed 2024107
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))