
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0))) (/ t_0 (* (* s t_1) t_1))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
float t_1 = 1.0f + t_0;
return t_0 / ((s * t_1) * t_1);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: t_1
t_0 = exp((-abs(x) / s))
t_1 = 1.0e0 + t_0
code = t_0 / ((s * t_1) * t_1)
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) t_1 = Float32(Float32(1.0) + t_0) return Float32(t_0 / Float32(Float32(s * t_1) * t_1)) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); t_1 = single(1.0) + t_0; tmp = t_0 / ((s * t_1) * t_1); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t_0\\
\frac{t_0}{\left(s \cdot t_1\right) \cdot t_1}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0))) (/ t_0 (* (* s t_1) t_1))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
float t_1 = 1.0f + t_0;
return t_0 / ((s * t_1) * t_1);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: t_1
t_0 = exp((-abs(x) / s))
t_1 = 1.0e0 + t_0
code = t_0 / ((s * t_1) * t_1)
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) t_1 = Float32(Float32(1.0) + t_0) return Float32(t_0 / Float32(Float32(s * t_1) * t_1)) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); t_1 = single(1.0) + t_0; tmp = t_0 / ((s * t_1) * t_1); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t_0\\
\frac{t_0}{\left(s \cdot t_1\right) \cdot t_1}
\end{array}
\end{array}
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ 1.0 (* (+ 1.0 (exp (/ (- x) s))) (fma s (exp (/ x s)) s))))
x = abs(x);
float code(float x, float s) {
return 1.0f / ((1.0f + expf((-x / s))) * fmaf(s, expf((x / s)), s));
}
x = abs(x) function code(x, s) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))) * fma(s, exp(Float32(x / s)), s))) end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}
\end{array}
Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.9%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-frac-neg99.8%
expm1-log1p-u99.8%
expm1-udef99.8%
Applied egg-rr99.8%
expm1-def99.8%
expm1-log1p99.8%
unpow199.8%
sqr-pow49.9%
fabs-sqr49.9%
sqr-pow98.1%
unpow198.1%
Simplified98.1%
Taylor expanded in s around 0 98.1%
+-commutative98.1%
distribute-lft-in98.1%
*-rgt-identity98.1%
fma-udef98.1%
unpow198.1%
sqr-pow49.9%
fabs-sqr49.9%
sqr-pow99.8%
unpow199.8%
Simplified99.8%
Final simplification99.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= (fabs x) 0.4000000059604645) (pow (/ (+ 3.0 (- (exp (/ x s)) (/ x s))) (/ 1.0 s)) -1.0) (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 0.4000000059604645f) {
tmp = powf(((3.0f + (expf((x / s)) - (x / s))) / (1.0f / s)), -1.0f);
} else {
tmp = -0.25f * (expf((-x / s)) / x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (abs(x) <= 0.4000000059604645e0) then
tmp = ((3.0e0 + (exp((x / s)) - (x / s))) / (1.0e0 / s)) ** (-1.0e0)
else
tmp = (-0.25e0) * (exp((-x / s)) / x)
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(0.4000000059604645)) tmp = Float32(Float32(Float32(3.0) + Float32(exp(Float32(x / s)) - Float32(x / s))) / Float32(Float32(1.0) / s)) ^ Float32(-1.0); else tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x)); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (abs(x) <= single(0.4000000059604645)) tmp = ((single(3.0) + (exp((x / s)) - (x / s))) / (single(1.0) / s)) ^ single(-1.0); else tmp = single(-0.25) * (exp((-x / s)) / x); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.4000000059604645:\\
\;\;\;\;{\left(\frac{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}{\frac{1}{s}}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\
\end{array}
\end{array}
if (fabs.f32 x) < 0.400000006Initial program 99.6%
Simplified99.7%
Taylor expanded in s around inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Taylor expanded in x around 0 95.8%
associate--l+95.9%
unpow195.9%
sqr-pow55.0%
fabs-sqr55.0%
sqr-pow67.9%
unpow167.9%
unpow167.9%
sqr-pow55.1%
fabs-sqr55.1%
sqr-pow68.9%
unpow168.9%
Simplified68.9%
associate-+r-68.9%
Applied egg-rr68.9%
clear-num69.0%
inv-pow69.0%
associate--l+69.0%
Applied egg-rr69.0%
if 0.400000006 < (fabs.f32 x) Initial program 100.0%
Taylor expanded in s around inf 100.0%
Taylor expanded in s around 0 100.0%
mul-1-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg100.0%
mul-1-neg100.0%
associate-*r/100.0%
neg-mul-1100.0%
unpow1100.0%
sqr-pow43.1%
fabs-sqr43.1%
sqr-pow44.9%
unpow144.9%
unpow144.9%
sqr-pow43.1%
fabs-sqr43.1%
sqr-pow44.9%
unpow144.9%
Simplified44.9%
Final simplification56.7%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= (fabs x) 0.4000000059604645) (/ 1.0 (* s (+ 2.0 (+ (exp (/ x s)) (- 1.0 (/ x s)))))) (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 0.4000000059604645f) {
tmp = 1.0f / (s * (2.0f + (expf((x / s)) + (1.0f - (x / s)))));
} else {
tmp = -0.25f * (expf((-x / s)) / x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (abs(x) <= 0.4000000059604645e0) then
tmp = 1.0e0 / (s * (2.0e0 + (exp((x / s)) + (1.0e0 - (x / s)))))
else
tmp = (-0.25e0) * (exp((-x / s)) / x)
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(0.4000000059604645)) tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(2.0) + Float32(exp(Float32(x / s)) + Float32(Float32(1.0) - Float32(x / s)))))); else tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x)); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (abs(x) <= single(0.4000000059604645)) tmp = single(1.0) / (s * (single(2.0) + (exp((x / s)) + (single(1.0) - (x / s))))); else tmp = single(-0.25) * (exp((-x / s)) / x); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.4000000059604645:\\
\;\;\;\;\frac{1}{s \cdot \left(2 + \left(e^{\frac{x}{s}} + \left(1 - \frac{x}{s}\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\
\end{array}
\end{array}
if (fabs.f32 x) < 0.400000006Initial program 99.6%
Simplified99.7%
Taylor expanded in s around inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
expm1-log1p-u93.6%
expm1-udef93.5%
associate-/l/93.5%
Applied egg-rr93.5%
expm1-def93.6%
expm1-log1p95.9%
*-commutative95.9%
+-commutative95.9%
+-commutative95.9%
associate-+l+95.9%
unpow195.9%
sqr-pow55.0%
fabs-sqr55.0%
sqr-pow67.9%
unpow167.9%
unpow167.9%
sqr-pow55.1%
fabs-sqr55.1%
sqr-pow69.0%
unpow169.0%
Simplified69.0%
if 0.400000006 < (fabs.f32 x) Initial program 100.0%
Taylor expanded in s around inf 100.0%
Taylor expanded in s around 0 100.0%
mul-1-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg100.0%
mul-1-neg100.0%
associate-*r/100.0%
neg-mul-1100.0%
unpow1100.0%
sqr-pow43.1%
fabs-sqr43.1%
sqr-pow44.9%
unpow144.9%
unpow144.9%
sqr-pow43.1%
fabs-sqr43.1%
sqr-pow44.9%
unpow144.9%
Simplified44.9%
Final simplification56.7%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ 1.0 (* (+ 1.0 (exp (/ (- x) s))) (+ s (* s (exp (/ x s)))))))
x = abs(x);
float code(float x, float s) {
return 1.0f / ((1.0f + expf((-x / s))) * (s + (s * expf((x / s)))));
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((1.0e0 + exp((-x / s))) * (s + (s * exp((x / s)))))
end function
x = abs(x) function code(x, s) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))) * Float32(s + Float32(s * exp(Float32(x / s)))))) end
x = abs(x) function tmp = code(x, s) tmp = single(1.0) / ((single(1.0) + exp((-x / s))) * (s + (s * exp((x / s))))); end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(s + s \cdot e^{\frac{x}{s}}\right)}
\end{array}
Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.9%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-frac-neg99.8%
expm1-log1p-u99.8%
expm1-udef99.8%
Applied egg-rr99.8%
expm1-def99.8%
expm1-log1p99.8%
unpow199.8%
sqr-pow49.9%
fabs-sqr49.9%
sqr-pow98.1%
unpow198.1%
Simplified98.1%
expm1-log1p-u98.1%
expm1-udef87.2%
Applied egg-rr87.2%
expm1-def98.1%
expm1-log1p98.1%
unpow198.1%
sqr-pow49.9%
fabs-sqr49.9%
sqr-pow99.8%
unpow199.8%
Simplified99.8%
Final simplification99.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ 1.0 (* (+ 1.0 (exp (/ x s))) (* s (+ 1.0 (exp (/ (- x) s)))))))
x = abs(x);
float code(float x, float s) {
return 1.0f / ((1.0f + expf((x / s))) * (s * (1.0f + expf((-x / s)))));
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((1.0e0 + exp((x / s))) * (s * (1.0e0 + exp((-x / s)))))
end function
x = abs(x) function code(x, s) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(x / s))) * Float32(s * Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))))) end
x = abs(x) function tmp = code(x, s) tmp = single(1.0) / ((single(1.0) + exp((x / s))) * (s * (single(1.0) + exp((-x / s))))); end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{\left(1 + e^{\frac{x}{s}}\right) \cdot \left(s \cdot \left(1 + e^{\frac{-x}{s}}\right)\right)}
\end{array}
Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.9%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-frac-neg99.8%
expm1-log1p-u99.8%
expm1-udef99.8%
Applied egg-rr99.8%
expm1-def99.8%
expm1-log1p99.8%
unpow199.8%
sqr-pow49.9%
fabs-sqr49.9%
sqr-pow98.1%
unpow198.1%
Simplified98.1%
Taylor expanded in s around 0 98.1%
+-commutative98.1%
distribute-lft-in98.1%
*-rgt-identity98.1%
fma-udef98.1%
unpow198.1%
sqr-pow49.9%
fabs-sqr49.9%
sqr-pow99.8%
unpow199.8%
Simplified99.8%
Taylor expanded in s around 0 99.8%
Final simplification99.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 0.4000000059604645) (/ 1.0 (* s (+ 3.0 (- (exp (/ x s)) (/ x s))))) (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 0.4000000059604645f) {
tmp = 1.0f / (s * (3.0f + (expf((x / s)) - (x / s))));
} else {
tmp = -0.25f * (expf((-x / s)) / x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 0.4000000059604645e0) then
tmp = 1.0e0 / (s * (3.0e0 + (exp((x / s)) - (x / s))))
else
tmp = (-0.25e0) * (exp((-x / s)) / x)
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.4000000059604645)) tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(3.0) + Float32(exp(Float32(x / s)) - Float32(x / s))))); else tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x)); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.4000000059604645)) tmp = single(1.0) / (s * (single(3.0) + (exp((x / s)) - (x / s)))); else tmp = single(-0.25) * (exp((-x / s)) / x); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.4000000059604645:\\
\;\;\;\;\frac{1}{s \cdot \left(3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\
\end{array}
\end{array}
if x < 0.400000006Initial program 99.7%
Simplified99.3%
Taylor expanded in s around inf 83.4%
mul-1-neg83.4%
unsub-neg83.4%
Simplified83.4%
Taylor expanded in x around 0 83.4%
associate--l+83.4%
unpow183.4%
sqr-pow34.7%
fabs-sqr34.7%
sqr-pow58.3%
unpow158.3%
unpow158.3%
sqr-pow34.7%
fabs-sqr34.7%
sqr-pow58.9%
unpow158.9%
Simplified58.9%
associate-+r-58.9%
Applied egg-rr58.9%
expm1-log1p-u57.4%
expm1-udef70.5%
associate--l+70.5%
Applied egg-rr70.5%
expm1-def57.4%
expm1-log1p58.9%
associate-/l/59.4%
*-commutative59.4%
Simplified59.4%
if 0.400000006 < x Initial program 100.0%
Taylor expanded in s around inf 100.0%
Taylor expanded in s around 0 100.0%
mul-1-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg100.0%
mul-1-neg100.0%
associate-*r/100.0%
neg-mul-1100.0%
unpow1100.0%
sqr-pow100.0%
fabs-sqr100.0%
sqr-pow100.0%
unpow1100.0%
unpow1100.0%
sqr-pow100.0%
fabs-sqr100.0%
sqr-pow100.0%
unpow1100.0%
Simplified100.0%
Final simplification68.3%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 3.999999999279835e-23) (/ (/ 1.0 s) (+ (/ 1.0 (* (/ s x) (/ s x))) 4.0)) (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 3.999999999279835e-23f) {
tmp = (1.0f / s) / ((1.0f / ((s / x) * (s / x))) + 4.0f);
} else {
tmp = -0.25f * (expf((-x / s)) / x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 3.999999999279835e-23) then
tmp = (1.0e0 / s) / ((1.0e0 / ((s / x) * (s / x))) + 4.0e0)
else
tmp = (-0.25e0) * (exp((-x / s)) / x)
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(3.999999999279835e-23)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(Float32(1.0) / Float32(Float32(s / x) * Float32(s / x))) + Float32(4.0))); else tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x)); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(3.999999999279835e-23)) tmp = (single(1.0) / s) / ((single(1.0) / ((s / x) * (s / x))) + single(4.0)); else tmp = single(-0.25) * (exp((-x / s)) / x); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.999999999279835 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{1}{\frac{s}{x} \cdot \frac{s}{x}} + 4}\\
\mathbf{else}:\\
\;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\
\end{array}
\end{array}
if x < 4e-23Initial program 99.8%
Simplified99.2%
Taylor expanded in s around inf 51.3%
associate-+r+51.3%
distribute-lft1-in51.3%
metadata-eval51.3%
mul0-lft68.8%
associate-+r+68.8%
metadata-eval68.8%
unpow268.8%
sqr-abs68.8%
unpow268.8%
Simplified68.8%
clear-num68.8%
inv-pow68.8%
Applied egg-rr68.8%
unpow-168.8%
times-frac70.8%
Simplified70.8%
if 4e-23 < x Initial program 99.8%
Taylor expanded in s around inf 97.1%
Taylor expanded in s around 0 89.4%
mul-1-neg89.4%
distribute-frac-neg89.4%
distribute-frac-neg89.4%
mul-1-neg89.4%
associate-*r/89.4%
neg-mul-189.4%
unpow189.4%
sqr-pow89.4%
fabs-sqr89.4%
sqr-pow89.4%
unpow189.4%
unpow189.4%
sqr-pow89.4%
fabs-sqr89.4%
sqr-pow89.4%
unpow189.4%
Simplified89.4%
Final simplification78.2%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 1.2800000250130962e-23) (/ (/ 1.0 s) (+ (/ 1.0 (* (/ s x) (/ s x))) 4.0)) (/ (/ 1.0 s) (+ 4.0 (/ (* x x) (* s s))))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 1.2800000250130962e-23f) {
tmp = (1.0f / s) / ((1.0f / ((s / x) * (s / x))) + 4.0f);
} else {
tmp = (1.0f / s) / (4.0f + ((x * x) / (s * s)));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 1.2800000250130962e-23) then
tmp = (1.0e0 / s) / ((1.0e0 / ((s / x) * (s / x))) + 4.0e0)
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) / (s * s)))
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(1.2800000250130962e-23)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(Float32(1.0) / Float32(Float32(s / x) * Float32(s / x))) + Float32(4.0))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(1.2800000250130962e-23)) tmp = (single(1.0) / s) / ((single(1.0) / ((s / x) * (s / x))) + single(4.0)); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) / (s * s))); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.2800000250130962 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{1}{\frac{s}{x} \cdot \frac{s}{x}} + 4}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if x < 1.28000003e-23Initial program 99.8%
Simplified99.2%
Taylor expanded in s around inf 51.0%
associate-+r+51.0%
distribute-lft1-in51.0%
metadata-eval51.0%
mul0-lft68.6%
associate-+r+68.6%
metadata-eval68.6%
unpow268.6%
sqr-abs68.6%
unpow268.6%
Simplified68.6%
clear-num68.6%
inv-pow68.6%
Applied egg-rr68.6%
unpow-168.6%
times-frac70.6%
Simplified70.6%
if 1.28000003e-23 < x Initial program 99.8%
Simplified99.8%
Taylor expanded in s around inf 52.3%
associate-+r+52.3%
distribute-lft1-in52.3%
metadata-eval52.3%
mul0-lft82.4%
associate-+r+82.4%
metadata-eval82.4%
unpow282.4%
sqr-abs82.4%
unpow282.4%
Simplified82.4%
Final simplification75.3%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 1.2800000250130962e-23) (/ (/ 1.0 s) (+ 4.0 (* (/ x s) (/ x s)))) (/ (/ 1.0 s) (+ 4.0 (/ (* x x) (* s s))))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 1.2800000250130962e-23f) {
tmp = (1.0f / s) / (4.0f + ((x / s) * (x / s)));
} else {
tmp = (1.0f / s) / (4.0f + ((x * x) / (s * s)));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 1.2800000250130962e-23) then
tmp = (1.0e0 / s) / (4.0e0 + ((x / s) * (x / s)))
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) / (s * s)))
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(1.2800000250130962e-23)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s)))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(1.2800000250130962e-23)) tmp = (single(1.0) / s) / (single(4.0) + ((x / s) * (x / s))); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) / (s * s))); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.2800000250130962 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if x < 1.28000003e-23Initial program 99.8%
Simplified99.2%
Taylor expanded in s around inf 51.0%
associate-+r+51.0%
distribute-lft1-in51.0%
metadata-eval51.0%
mul0-lft68.6%
associate-+r+68.6%
metadata-eval68.6%
unpow268.6%
sqr-abs68.6%
unpow268.6%
Simplified68.6%
times-frac70.6%
Applied egg-rr70.6%
if 1.28000003e-23 < x Initial program 99.8%
Simplified99.8%
Taylor expanded in s around inf 52.3%
associate-+r+52.3%
distribute-lft1-in52.3%
metadata-eval52.3%
mul0-lft82.4%
associate-+r+82.4%
metadata-eval82.4%
unpow282.4%
sqr-abs82.4%
unpow282.4%
Simplified82.4%
Final simplification75.3%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ 4.0 (* (/ x s) (/ x s)))))
x = abs(x);
float code(float x, float s) {
return (1.0f / s) / (4.0f + ((x / s) * (x / s)));
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (4.0e0 + ((x / s) * (x / s)))
end function
x = abs(x) function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s)))) end
x = abs(x) function tmp = code(x, s) tmp = (single(1.0) / s) / (single(4.0) + ((x / s) * (x / s))); end
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \frac{x}{s}}
\end{array}
Initial program 99.8%
Simplified99.5%
Taylor expanded in s around inf 51.5%
associate-+r+51.5%
distribute-lft1-in51.5%
metadata-eval51.5%
mul0-lft74.1%
associate-+r+74.1%
metadata-eval74.1%
unpow274.1%
sqr-abs74.1%
unpow274.1%
Simplified74.1%
times-frac71.7%
Applied egg-rr71.7%
Final simplification71.7%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 2.499999993688107e-7) (/ 0.25 s) (/ s (* x x))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 2.499999993688107e-7f) {
tmp = 0.25f / s;
} else {
tmp = s / (x * x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 2.499999993688107e-7) then
tmp = 0.25e0 / s
else
tmp = s / (x * x)
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(2.499999993688107e-7)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(s / Float32(x * x)); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(2.499999993688107e-7)) tmp = single(0.25) / s; else tmp = s / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.499999993688107 \cdot 10^{-7}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < 2.49999999e-7Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.7%
Simplified99.8%
Taylor expanded in s around inf 27.7%
if 2.49999999e-7 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in s around inf 43.1%
associate-+r+43.1%
distribute-lft1-in43.1%
metadata-eval43.1%
mul0-lft88.0%
associate-+r+88.0%
metadata-eval88.0%
unpow288.0%
sqr-abs88.0%
unpow288.0%
Simplified88.0%
Taylor expanded in s around 0 61.3%
unpow261.3%
Simplified61.3%
Final simplification36.7%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ -1.0 x))
x = abs(x);
float code(float x, float s) {
return -1.0f / x;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (-1.0e0) / x
end function
x = abs(x) function code(x, s) return Float32(Float32(-1.0) / x) end
x = abs(x) function tmp = code(x, s) tmp = single(-1.0) / x; end
\begin{array}{l}
x = |x|\\
\\
\frac{-1}{x}
\end{array}
Initial program 99.8%
Simplified99.5%
Taylor expanded in s around inf 74.9%
mul-1-neg74.9%
unsub-neg74.9%
Simplified74.9%
Taylor expanded in s around 0 6.9%
unpow16.9%
sqr-pow3.2%
fabs-sqr3.2%
sqr-pow7.8%
unpow17.8%
Simplified7.8%
Final simplification7.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ 0.25 s))
x = abs(x);
float code(float x, float s) {
return 0.25f / s;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.25e0 / s
end function
x = abs(x) function code(x, s) return Float32(Float32(0.25) / s) end
x = abs(x) function tmp = code(x, s) tmp = single(0.25) / s; end
\begin{array}{l}
x = |x|\\
\\
\frac{0.25}{s}
\end{array}
Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.9%
Taylor expanded in s around inf 21.4%
Final simplification21.4%
herbie shell --seed 2023238
(FPCore (x s)
:name "Logistic distribution"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ (exp (/ (- (fabs x)) s)) (* (* s (+ 1.0 (exp (/ (- (fabs x)) s)))) (+ 1.0 (exp (/ (- (fabs x)) s))))))