
(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 (cast (! :precision binary64 (/ 1.0 (+ 1.0 (exp (/ x (- s))))))))
float code(float x, float s) {
double tmp = 1.0 / (1.0 + exp((((double) x) / -((double) s))));
return (float) tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(8) :: tmp
tmp = 1.0d0 / (1.0d0 + exp((real(x, 8) / -real(s, 8))))
code = real(tmp, 4)
end function
function code(x, s) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(Float64(x) / Float64(-Float64(s)))))) return Float32(tmp) end
function tmp_2 = code(x, s) tmp = 1.0 / (1.0 + exp((double(x) / -s))); tmp_2 = single(tmp); end
\begin{array}{l}
\\
\langle \left( \frac{1}{1 + e^{\frac{x}{-s}}} \right)_{\text{binary64}} \rangle_{\text{binary32}}
\end{array}
Initial program 100.0%
Final simplification100.0%
(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%
inv-pow99.8%
metadata-eval99.8%
pow-to-exp99.9%
exp-prod99.8%
sqr-pow99.3%
log1p-def99.3%
remove-double-neg99.3%
frac-2neg99.3%
metadata-eval99.3%
metadata-eval99.3%
Applied egg-rr99.3%
pow-sqr99.8%
metadata-eval99.8%
unpow-199.8%
exp-neg100.0%
Simplified100.0%
Final simplification100.0%
(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.8%
Final simplification99.8%
(FPCore (x s)
:precision binary32
(if (<= (/ (- x) s) -2.0)
0.5
(/
1.0
(+ (- 2.0 (/ x s)) (* 0.5 (* (/ s -1.0) (* (/ x (- s)) (/ (/ x s) s))))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((2.0f - (x / s)) + (0.5f * ((s / -1.0f) * ((x / -s) * ((x / s) / 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 / ((2.0e0 - (x / s)) + (0.5e0 * ((s / (-1.0e0)) * ((x / -s) * ((x / s) / s)))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-2.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(2.0) - Float32(x / s)) + Float32(Float32(0.5) * Float32(Float32(s / Float32(-1.0)) * Float32(Float32(x / Float32(-s)) * Float32(Float32(x / s) / 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) / ((single(2.0) - (x / s)) + (single(0.5) * ((s / single(-1.0)) * ((x / -s) * ((x / s) / 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}{\left(2 - \frac{x}{s}\right) + 0.5 \cdot \left(\frac{s}{-1} \cdot \left(\frac{x}{-s} \cdot \frac{\frac{x}{s}}{s}\right)\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
flip3-+42.5%
metadata-eval42.5%
pow-exp42.4%
neg-mul-142.4%
metadata-eval42.4%
associate-/l*42.4%
associate-*l/42.4%
metadata-eval42.4%
metadata-eval42.4%
metadata-eval42.4%
+-commutative42.4%
Applied egg-rr42.4%
Taylor expanded in x around 0 80.0%
associate-+r+80.0%
mul-1-neg80.0%
sub-neg80.0%
*-commutative80.0%
unpow280.0%
unpow280.0%
Simplified80.0%
clear-num80.0%
rgt-mult-inverse80.0%
frac-2neg80.0%
remove-double-neg80.0%
clear-num80.0%
times-frac82.5%
frac-times82.5%
associate-/r*83.8%
associate-/r*83.8%
associate-*l/83.8%
frac-2neg83.8%
distribute-lft-neg-out83.8%
remove-double-neg83.8%
neg-mul-183.8%
times-frac89.7%
Applied egg-rr89.7%
times-frac89.7%
neg-mul-189.7%
associate-/l/89.7%
*-inverses89.7%
metadata-eval89.7%
associate-/r/89.7%
associate-*l/89.7%
associate-*r/89.7%
metadata-eval89.7%
*-inverses89.7%
associate-/l/89.7%
neg-mul-189.7%
*-commutative89.7%
/-rgt-identity89.7%
associate-/l*89.7%
neg-mul-189.7%
associate-/l/89.7%
*-inverses89.7%
metadata-eval89.7%
metadata-eval89.7%
associate-/l/89.7%
neg-mul-189.7%
Simplified89.7%
Final simplification63.0%
(FPCore (x s) :precision binary32 (if (<= (- x) 9.999999998199587e-24) 0.5 (/ 1.0 (- (- 2.0 (/ x s)) (* 0.5 (* (/ -1.0 (* s s)) (* x x)))))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999998199587e-24f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((2.0f - (x / s)) - (0.5f * ((-1.0f / (s * s)) * (x * 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.999999998199587e-24) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((2.0e0 - (x / s)) - (0.5e0 * (((-1.0e0) / (s * s)) * (x * x))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(9.999999998199587e-24)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(2.0) - Float32(x / s)) - Float32(Float32(0.5) * Float32(Float32(Float32(-1.0) / Float32(s * s)) * Float32(x * x))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(9.999999998199587e-24)) tmp = single(0.5); else tmp = single(1.0) / ((single(2.0) - (x / s)) - (single(0.5) * ((single(-1.0) / (s * s)) * (x * x)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999998199587 \cdot 10^{-24}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(2 - \frac{x}{s}\right) - 0.5 \cdot \left(\frac{-1}{s \cdot s} \cdot \left(x \cdot x\right)\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 1e-23Initial program 99.8%
Taylor expanded in x around 0 47.4%
if 1e-23 < (neg.f32 x) Initial program 99.9%
flip3-+10.0%
metadata-eval10.0%
pow-exp9.9%
neg-mul-19.9%
metadata-eval9.9%
associate-/l*9.9%
associate-*l/9.9%
metadata-eval9.9%
metadata-eval9.9%
metadata-eval9.9%
+-commutative9.9%
Applied egg-rr10.0%
Taylor expanded in x around 0 83.8%
associate-+r+83.8%
mul-1-neg83.8%
sub-neg83.8%
*-commutative83.8%
unpow283.8%
unpow283.8%
Simplified83.8%
frac-2neg83.8%
div-inv83.8%
distribute-rgt-neg-in83.8%
frac-2neg83.8%
metadata-eval83.8%
distribute-rgt-neg-in83.8%
distribute-rgt-neg-in83.8%
remove-double-neg83.8%
Applied egg-rr83.8%
Final simplification60.1%
(FPCore (x s) :precision binary32 (if (<= (- x) 9.999999998199587e-24) 0.5 (/ 1.0 (+ (- 2.0 (/ x s)) (* 0.5 (/ (* x x) (* s s)))))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999998199587e-24f) {
tmp = 0.5f;
} else {
tmp = 1.0f / ((2.0f - (x / s)) + (0.5f * ((x * x) / (s * s))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= 9.999999998199587e-24) then
tmp = 0.5e0
else
tmp = 1.0e0 / ((2.0e0 - (x / s)) + (0.5e0 * ((x * x) / (s * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(9.999999998199587e-24)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(2.0) - Float32(x / s)) + Float32(Float32(0.5) * Float32(Float32(x * x) / Float32(s * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(9.999999998199587e-24)) tmp = single(0.5); else tmp = single(1.0) / ((single(2.0) - (x / s)) + (single(0.5) * ((x * x) / (s * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999998199587 \cdot 10^{-24}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(2 - \frac{x}{s}\right) + 0.5 \cdot \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 1e-23Initial program 99.8%
Taylor expanded in x around 0 47.4%
if 1e-23 < (neg.f32 x) Initial program 99.9%
flip3-+10.0%
metadata-eval10.0%
pow-exp9.9%
neg-mul-19.9%
metadata-eval9.9%
associate-/l*9.9%
associate-*l/9.9%
metadata-eval9.9%
metadata-eval9.9%
metadata-eval9.9%
+-commutative9.9%
Applied egg-rr10.0%
Taylor expanded in x around 0 83.8%
associate-+r+83.8%
mul-1-neg83.8%
sub-neg83.8%
*-commutative83.8%
unpow283.8%
unpow283.8%
Simplified83.8%
Final simplification60.1%
(FPCore (x s) :precision binary32 (if (<= (- x) 9.999999998199587e-24) 0.5 (/ 1.0 (+ 2.0 (* 0.5 (/ (* x x) (* s s)))))))
float code(float x, float s) {
float tmp;
if (-x <= 9.999999998199587e-24f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (2.0f + (0.5f * ((x * x) / (s * s))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= 9.999999998199587e-24) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 + (0.5e0 * ((x * x) / (s * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(9.999999998199587e-24)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(0.5) * Float32(Float32(x * x) / Float32(s * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(9.999999998199587e-24)) tmp = single(0.5); else tmp = single(1.0) / (single(2.0) + (single(0.5) * ((x * x) / (s * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 9.999999998199587 \cdot 10^{-24}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + 0.5 \cdot \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 1e-23Initial program 99.8%
Taylor expanded in x around 0 47.4%
if 1e-23 < (neg.f32 x) Initial program 99.9%
flip3-+10.0%
metadata-eval10.0%
pow-exp9.9%
neg-mul-19.9%
metadata-eval9.9%
associate-/l*9.9%
associate-*l/9.9%
metadata-eval9.9%
metadata-eval9.9%
metadata-eval9.9%
+-commutative9.9%
Applied egg-rr10.0%
Taylor expanded in x around 0 83.8%
associate-+r+83.8%
mul-1-neg83.8%
sub-neg83.8%
*-commutative83.8%
unpow283.8%
unpow283.8%
Simplified83.8%
Taylor expanded in x around 0 82.8%
Final simplification59.7%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) 0.5 (/ 1.0 (+ 2.0 (* x (/ -1.0 s))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 0.5f;
} 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 / s) <= (-2.0e0)) then
tmp = 0.5e0
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(Float32(-x) / s) <= Float32(-2.0)) tmp = Float32(0.5); 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 / s) <= single(-2.0)) tmp = single(0.5); 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}\;\frac{-x}{s} \leq -2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
flip3-+42.5%
metadata-eval42.5%
pow-exp42.4%
neg-mul-142.4%
metadata-eval42.4%
associate-/l*42.4%
associate-*l/42.4%
metadata-eval42.4%
metadata-eval42.4%
metadata-eval42.4%
+-commutative42.4%
Applied egg-rr42.4%
Taylor expanded in s around inf 43.0%
associate--l+43.0%
associate-*r/43.0%
*-commutative43.0%
associate-*r/43.0%
associate-*r/43.0%
distribute-rgt-out--43.0%
metadata-eval43.0%
*-commutative43.0%
neg-mul-143.0%
associate-*l/43.0%
neg-mul-143.0%
associate-*l*43.0%
associate-*l/43.0%
metadata-eval43.0%
*-commutative43.0%
Simplified43.0%
distribute-lft-out--61.6%
*-commutative61.6%
sub-div61.6%
metadata-eval61.6%
Applied egg-rr61.6%
Final simplification47.1%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) 0.5 (/ 1.0 (+ 2.0 (/ -1.0 (/ s x))))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (2.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) <= (-2.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 + ((-1.0e0) / (s / x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-2.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(2.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(-2.0)) tmp = single(0.5); else tmp = single(1.0) / (single(2.0) + (single(-1.0) / (s / x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq -2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{-1}{\frac{s}{x}}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
flip3-+42.5%
metadata-eval42.5%
pow-exp42.4%
neg-mul-142.4%
metadata-eval42.4%
associate-/l*42.4%
associate-*l/42.4%
metadata-eval42.4%
metadata-eval42.4%
metadata-eval42.4%
+-commutative42.4%
Applied egg-rr42.4%
Taylor expanded in s around inf 43.0%
associate--l+43.0%
associate-*r/43.0%
*-commutative43.0%
associate-*r/43.0%
associate-*r/43.0%
distribute-rgt-out--43.0%
metadata-eval43.0%
*-commutative43.0%
neg-mul-143.0%
associate-*l/43.0%
neg-mul-143.0%
associate-*l*43.0%
associate-*l/43.0%
metadata-eval43.0%
*-commutative43.0%
Simplified43.0%
distribute-lft-out--61.6%
sub-div61.6%
metadata-eval61.6%
metadata-eval61.6%
remove-double-neg61.6%
frac-2neg61.6%
div-inv61.6%
clear-num61.6%
metadata-eval61.6%
metadata-eval61.6%
distribute-frac-neg61.6%
frac-2neg61.6%
metadata-eval61.6%
Applied egg-rr61.6%
Final simplification47.1%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) 4.0) 0.5 (/ (* 2.0 (* s s)) (* x x))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= 4.0f) {
tmp = 0.5f;
} else {
tmp = (2.0f * (s * s)) / (x * 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.0e0) then
tmp = 0.5e0
else
tmp = (2.0e0 * (s * s)) / (x * x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(4.0)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(2.0) * Float32(s * s)) / Float32(x * x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((-x / s) <= single(4.0)) tmp = single(0.5); else tmp = (single(2.0) * (s * s)) / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{-x}{s} \leq 4:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \left(s \cdot s\right)}{x \cdot x}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 4Initial program 99.7%
Taylor expanded in x around 0 49.3%
if 4 < (/.f32 (neg.f32 x) s) Initial program 100.0%
flip3-+-0.0%
metadata-eval-0.0%
pow-exp-0.0%
neg-mul-1-0.0%
metadata-eval-0.0%
associate-/l*-0.0%
associate-*l/-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
+-commutative-0.0%
Applied egg-rr-0.0%
Taylor expanded in x around 0 81.3%
associate-+r+81.3%
mul-1-neg81.3%
sub-neg81.3%
*-commutative81.3%
unpow281.3%
unpow281.3%
Simplified81.3%
Taylor expanded in x around inf 79.7%
unpow279.7%
unpow279.7%
associate-*r/79.7%
Simplified79.7%
Final simplification59.1%
(FPCore (x s) :precision binary32 (if (<= (/ (- x) s) -2.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if ((-x / s) <= -2.0f) {
tmp = 0.5f;
} 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) <= (-2.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 - (x / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(Float32(-x) / s) <= Float32(-2.0)) tmp = Float32(0.5); 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(-2.0)) tmp = single(0.5); 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 -2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -2Initial program 99.9%
Taylor expanded in x around 0 28.1%
if -2 < (/.f32 (neg.f32 x) s) Initial program 99.7%
Taylor expanded in x around 0 61.6%
mul-1-neg61.6%
unsub-neg61.6%
Simplified61.6%
Final simplification47.1%
(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(Float32(-x) / 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.8%
Taylor expanded in x around 0 49.4%
if 2 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0 39.8%
mul-1-neg39.8%
unsub-neg39.8%
Simplified39.8%
Taylor expanded in x around inf 39.8%
associate-*r/39.8%
neg-mul-139.8%
Simplified39.8%
associate-/r/34.7%
frac-2neg34.7%
metadata-eval34.7%
remove-double-neg34.7%
Applied egg-rr34.7%
associate-*l/34.7%
associate-/l*39.8%
Applied egg-rr39.8%
Final simplification46.2%
(FPCore (x s) :precision binary32 (if (<= x -1.999999987845058e-8) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -1.999999987845058e-8f) {
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.999999987845058e-8)) 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.999999987845058e-8)) tmp = Float32(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.999999987845058e-8)) tmp = -s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.999999987845058 \cdot 10^{-8}:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -1.99999999e-8Initial program 100.0%
Taylor expanded in x around 0 45.6%
mul-1-neg45.6%
unsub-neg45.6%
Simplified45.6%
Taylor expanded in x around inf 39.6%
associate-*r/39.6%
neg-mul-139.6%
Simplified39.6%
if -1.99999999e-8 < x Initial program 99.8%
Taylor expanded in x around 0 46.4%
Final simplification44.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.8%
Taylor expanded in x around 0 35.3%
Final simplification35.3%
herbie shell --seed 2023297
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))