
(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 18 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}
(FPCore (x s)
:precision binary32
(let* ((t_0 (sqrt (/ (fabs x) s))))
(/
(exp (- (log1p (exp (/ (fabs x) (- s))))))
(fma s (pow (exp t_0) t_0) s))))
float code(float x, float s) {
float t_0 = sqrtf((fabsf(x) / s));
return expf(-log1pf(expf((fabsf(x) / -s)))) / fmaf(s, powf(expf(t_0), t_0), s);
}
function code(x, s) t_0 = sqrt(Float32(abs(x) / s)) return Float32(exp(Float32(-log1p(exp(Float32(abs(x) / Float32(-s)))))) / fma(s, (exp(t_0) ^ t_0), s)) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{\left|x\right|}{s}}\\
\frac{e^{-\mathsf{log1p}\left(e^{\frac{\left|x\right|}{-s}}\right)}}{\mathsf{fma}\left(s, {\left(e^{t_0}\right)}^{t_0}, s\right)}
\end{array}
\end{array}
Initial program 99.6%
Simplified99.7%
add-sqr-sqrt99.7%
exp-prod99.8%
Applied egg-rr99.8%
add-exp-log99.8%
log-rec99.8%
log1p-udef99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ (/ 1.0 (+ (exp (/ (fabs x) (- s))) 1.0)) (fma s (pow (exp (sqrt (/ (fabs x) s))) (sqrt (/ x s))) s)))
float code(float x, float s) {
return (1.0f / (expf((fabsf(x) / -s)) + 1.0f)) / fmaf(s, powf(expf(sqrtf((fabsf(x) / s))), sqrtf((x / s))), s);
}
function code(x, s) return Float32(Float32(Float32(1.0) / Float32(exp(Float32(abs(x) / Float32(-s))) + Float32(1.0))) / fma(s, (exp(sqrt(Float32(abs(x) / s))) ^ sqrt(Float32(x / s))), s)) end
\begin{array}{l}
\\
\frac{\frac{1}{e^{\frac{\left|x\right|}{-s}} + 1}}{\mathsf{fma}\left(s, {\left(e^{\sqrt{\frac{\left|x\right|}{s}}}\right)}^{\left(\sqrt{\frac{x}{s}}\right)}, s\right)}
\end{array}
Initial program 99.6%
Simplified99.7%
add-sqr-sqrt99.7%
exp-prod99.8%
Applied egg-rr99.8%
expm1-log1p-u99.7%
expm1-udef99.6%
Applied egg-rr99.6%
expm1-def99.7%
expm1-log1p99.8%
unpow199.8%
sqr-pow56.9%
fabs-sqr56.9%
sqr-pow56.9%
unpow156.9%
Simplified56.9%
Final simplification56.9%
(FPCore (x s) :precision binary32 (/ 1.0 (* (fma s (exp (/ x s)) s) (+ 1.0 (exp (/ (- x) s))))))
float code(float x, float s) {
return 1.0f / (fmaf(s, expf((x / s)), s) * (1.0f + expf((-x / s))));
}
function code(x, s) return Float32(Float32(1.0) / Float32(fma(s, exp(Float32(x / s)), s) * Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))))) end
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) \cdot \left(1 + e^{\frac{-x}{s}}\right)}
\end{array}
Initial program 99.6%
Simplified99.7%
add-sqr-sqrt99.7%
exp-prod99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.7%
+-commutative99.7%
fma-udef99.7%
*-commutative99.7%
unpow199.7%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow63.1%
unpow163.1%
neg-mul-163.1%
unpow163.1%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow99.7%
unpow199.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (* s (* (+ 1.0 (exp (/ (- x) s))) (+ 1.0 (exp (/ x s)))))))
float code(float x, float s) {
return 1.0f / (s * ((1.0f + expf((-x / s))) * (1.0f + expf((x / s)))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * ((1.0e0 + exp((-x / s))) * (1.0e0 + exp((x / s)))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))) * Float32(Float32(1.0) + exp(Float32(x / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * ((single(1.0) + exp((-x / s))) * (single(1.0) + exp((x / s))))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(1 + e^{\frac{x}{s}}\right)\right)}
\end{array}
Initial program 99.6%
Simplified99.7%
add-sqr-sqrt99.7%
exp-prod99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.7%
+-commutative99.7%
fma-udef99.7%
*-commutative99.7%
unpow199.7%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow63.1%
unpow163.1%
neg-mul-163.1%
unpow163.1%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow99.7%
unpow199.7%
Simplified99.7%
Taylor expanded in s around 0 99.7%
distribute-frac-neg99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (* (+ 1.0 (exp (/ (- x) s))) (+ s (* s (exp (/ x s)))))))
float code(float x, float s) {
return 1.0f / ((1.0f + expf((-x / s))) * (s + (s * 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))) * (s + (s * exp((x / s)))))
end function
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
function tmp = code(x, s) tmp = single(1.0) / ((single(1.0) + exp((-x / s))) * (s + (s * exp((x / s))))); end
\begin{array}{l}
\\
\frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(s + s \cdot e^{\frac{x}{s}}\right)}
\end{array}
Initial program 99.6%
Simplified99.7%
add-sqr-sqrt99.7%
exp-prod99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.7%
+-commutative99.7%
fma-udef99.7%
*-commutative99.7%
unpow199.7%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow63.1%
unpow163.1%
neg-mul-163.1%
unpow163.1%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow99.7%
unpow199.7%
Simplified99.7%
fma-udef99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (* 2.0 (+ s (* s (exp (/ (fabs x) s)))))))
float code(float x, float s) {
return 1.0f / (2.0f * (s + (s * expf((fabsf(x) / s)))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (2.0e0 * (s + (s * exp((abs(x) / s)))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(2.0) * Float32(s + Float32(s * exp(Float32(abs(x) / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(2.0) * (s + (s * exp((abs(x) / s))))); end
\begin{array}{l}
\\
\frac{1}{2 \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}
\end{array}
Initial program 99.6%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in s around inf 94.7%
Final simplification94.7%
(FPCore (x s) :precision binary32 (/ 1.0 (* (fma s (exp (/ x s)) s) 2.0)))
float code(float x, float s) {
return 1.0f / (fmaf(s, expf((x / s)), s) * 2.0f);
}
function code(x, s) return Float32(Float32(1.0) / Float32(fma(s, exp(Float32(x / s)), s) * Float32(2.0))) end
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) \cdot 2}
\end{array}
Initial program 99.6%
Simplified99.7%
add-sqr-sqrt99.7%
exp-prod99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.7%
+-commutative99.7%
fma-udef99.7%
*-commutative99.7%
unpow199.7%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow63.1%
unpow163.1%
neg-mul-163.1%
unpow163.1%
sqr-pow52.6%
fabs-sqr52.6%
sqr-pow99.7%
unpow199.7%
Simplified99.7%
Taylor expanded in x around 0 60.1%
Final simplification60.1%
(FPCore (x s) :precision binary32 (/ (exp (- (/ (fabs x) s))) (* s 4.0)))
float code(float x, float s) {
return expf(-(fabsf(x) / s)) / (s * 4.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = exp(-(abs(x) / s)) / (s * 4.0e0)
end function
function code(x, s) return Float32(exp(Float32(-Float32(abs(x) / s))) / Float32(s * Float32(4.0))) end
function tmp = code(x, s) tmp = exp(-(abs(x) / s)) / (s * single(4.0)); end
\begin{array}{l}
\\
\frac{e^{-\frac{\left|x\right|}{s}}}{s \cdot 4}
\end{array}
Initial program 99.6%
Taylor expanded in s around inf 94.3%
*-commutative94.3%
Simplified94.3%
Final simplification94.3%
(FPCore (x s)
:precision binary32
(let* ((t_0 (* x (/ x s))))
(if (<= x 0.012000000104308128)
(/
1.0
(*
(+ 1.0 (+ 1.0 (- (* 0.5 (* (/ x s) (/ x s))) (/ x s))))
(+ s (* s (exp (/ x s))))))
(/ 1.0 (+ (cbrt (* t_0 (* t_0 t_0))) (* s 4.0))))))
float code(float x, float s) {
float t_0 = x * (x / s);
float tmp;
if (x <= 0.012000000104308128f) {
tmp = 1.0f / ((1.0f + (1.0f + ((0.5f * ((x / s) * (x / s))) - (x / s)))) * (s + (s * expf((x / s)))));
} else {
tmp = 1.0f / (cbrtf((t_0 * (t_0 * t_0))) + (s * 4.0f));
}
return tmp;
}
function code(x, s) t_0 = Float32(x * Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(0.012000000104308128)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x / s) * Float32(x / s))) - Float32(x / s)))) * Float32(s + Float32(s * exp(Float32(x / s)))))); else tmp = Float32(Float32(1.0) / Float32(cbrt(Float32(t_0 * Float32(t_0 * t_0))) + Float32(s * Float32(4.0)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{x}{s}\\
\mathbf{if}\;x \leq 0.012000000104308128:\\
\;\;\;\;\frac{1}{\left(1 + \left(1 + \left(0.5 \cdot \left(\frac{x}{s} \cdot \frac{x}{s}\right) - \frac{x}{s}\right)\right)\right) \cdot \left(s + s \cdot e^{\frac{x}{s}}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)} + s \cdot 4}\\
\end{array}
\end{array}
if x < 0.0120000001Initial program 99.5%
Simplified99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in s around inf 70.7%
+-commutative70.7%
neg-mul-170.7%
unsub-neg70.7%
unpow270.7%
unpow270.7%
times-frac79.3%
unpow179.3%
sqr-pow33.1%
fabs-sqr33.1%
sqr-pow95.1%
unpow195.1%
unpow195.1%
sqr-pow33.1%
fabs-sqr33.1%
sqr-pow79.3%
unpow179.3%
Simplified94.6%
expm1-log1p-u94.6%
expm1-udef78.4%
Applied egg-rr78.4%
expm1-def94.6%
expm1-log1p94.6%
unpow194.6%
sqr-pow33.1%
fabs-sqr33.1%
sqr-pow81.9%
unpow181.9%
Simplified81.9%
if 0.0120000001 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 24.6%
+-commutative24.6%
+-commutative24.6%
mul-1-neg24.6%
distribute-lft1-in73.9%
metadata-eval73.9%
associate-*r/73.9%
mul-1-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
associate-+l+73.9%
Simplified73.9%
add-cbrt-cube100.0%
div-inv100.0%
clear-num100.0%
div-inv100.0%
clear-num100.0%
div-inv100.0%
clear-num100.0%
Applied egg-rr100.0%
Final simplification86.8%
(FPCore (x s) :precision binary32 (let* ((t_0 (* x (/ x s)))) (/ 1.0 (+ (cbrt (* t_0 (* t_0 t_0))) (* s 4.0)))))
float code(float x, float s) {
float t_0 = x * (x / s);
return 1.0f / (cbrtf((t_0 * (t_0 * t_0))) + (s * 4.0f));
}
function code(x, s) t_0 = Float32(x * Float32(x / s)) return Float32(Float32(1.0) / Float32(cbrt(Float32(t_0 * Float32(t_0 * t_0))) + Float32(s * Float32(4.0)))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{x}{s}\\
\frac{1}{\sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)} + s \cdot 4}
\end{array}
\end{array}
Initial program 99.6%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in s around -inf 40.2%
+-commutative40.2%
+-commutative40.2%
mul-1-neg40.2%
distribute-lft1-in64.8%
metadata-eval64.8%
associate-*r/64.8%
mul-1-neg64.8%
remove-double-neg64.8%
+-commutative64.8%
associate-+l+64.8%
Simplified65.6%
add-cbrt-cube80.3%
div-inv80.3%
clear-num80.3%
div-inv80.3%
clear-num80.3%
div-inv80.3%
clear-num80.3%
Applied egg-rr80.3%
Final simplification80.3%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ s (* x x))))
(if (<= x 0.003000000026077032)
(/
1.0
(*
(+ 1.0 (+ 1.0 (- (* 0.5 (* (/ x s) (/ x s))) (/ x s))))
(+ s (+ x s))))
(cbrt (* t_0 (* t_0 t_0))))))
float code(float x, float s) {
float t_0 = s / (x * x);
float tmp;
if (x <= 0.003000000026077032f) {
tmp = 1.0f / ((1.0f + (1.0f + ((0.5f * ((x / s) * (x / s))) - (x / s)))) * (s + (x + s)));
} else {
tmp = cbrtf((t_0 * (t_0 * t_0)));
}
return tmp;
}
function code(x, s) t_0 = Float32(s / Float32(x * x)) tmp = Float32(0.0) if (x <= Float32(0.003000000026077032)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x / s) * Float32(x / s))) - Float32(x / s)))) * Float32(s + Float32(x + s)))); else tmp = cbrt(Float32(t_0 * Float32(t_0 * t_0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{s}{x \cdot x}\\
\mathbf{if}\;x \leq 0.003000000026077032:\\
\;\;\;\;\frac{1}{\left(1 + \left(1 + \left(0.5 \cdot \left(\frac{x}{s} \cdot \frac{x}{s}\right) - \frac{x}{s}\right)\right)\right) \cdot \left(s + \left(x + s\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)}\\
\end{array}
\end{array}
if x < 0.00300000003Initial program 99.5%
Simplified99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in s around inf 70.4%
+-commutative70.4%
neg-mul-170.4%
unsub-neg70.4%
unpow270.4%
unpow270.4%
times-frac79.1%
unpow179.1%
sqr-pow32.4%
fabs-sqr32.4%
sqr-pow95.1%
unpow195.1%
unpow195.1%
sqr-pow32.4%
fabs-sqr32.4%
sqr-pow79.1%
unpow179.1%
Simplified94.6%
Taylor expanded in s around inf 71.7%
+-commutative71.7%
unpow171.7%
sqr-pow22.1%
fabs-sqr22.1%
sqr-pow72.4%
unpow172.4%
Simplified72.4%
if 0.00300000003 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 25.4%
+-commutative25.4%
+-commutative25.4%
mul-1-neg25.4%
distribute-lft1-in73.3%
metadata-eval73.3%
associate-*r/73.3%
mul-1-neg73.3%
remove-double-neg73.3%
+-commutative73.3%
associate-+l+73.3%
Simplified73.3%
Taylor expanded in x around inf 70.5%
unpow270.5%
Simplified70.5%
add-cbrt-cube96.2%
Applied egg-rr96.2%
associate-*l*96.2%
Simplified96.2%
Final simplification79.0%
(FPCore (x s)
:precision binary32
(if (<= x 2000000.0)
(/
1.0
(* (+ 1.0 (+ 1.0 (- (* 0.5 (* (/ x s) (/ x s))) (/ x s)))) (+ s (+ x s))))
(/ s (cbrt (* (* x x) (* (* x x) (* x x)))))))
float code(float x, float s) {
float tmp;
if (x <= 2000000.0f) {
tmp = 1.0f / ((1.0f + (1.0f + ((0.5f * ((x / s) * (x / s))) - (x / s)))) * (s + (x + s)));
} else {
tmp = s / cbrtf(((x * x) * ((x * x) * (x * x))));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (x <= Float32(2000000.0)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x / s) * Float32(x / s))) - Float32(x / s)))) * Float32(s + Float32(x + s)))); else tmp = Float32(s / cbrt(Float32(Float32(x * x) * Float32(Float32(x * x) * Float32(x * x))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2000000:\\
\;\;\;\;\frac{1}{\left(1 + \left(1 + \left(0.5 \cdot \left(\frac{x}{s} \cdot \frac{x}{s}\right) - \frac{x}{s}\right)\right)\right) \cdot \left(s + \left(x + s\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{\sqrt[3]{\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)}}\\
\end{array}
\end{array}
if x < 2e6Initial program 99.5%
Simplified99.6%
Taylor expanded in x around 0 99.6%
Taylor expanded in s around inf 71.8%
+-commutative71.8%
neg-mul-171.8%
unsub-neg71.8%
unpow271.8%
unpow271.8%
times-frac79.9%
unpow179.9%
sqr-pow36.3%
fabs-sqr36.3%
sqr-pow94.9%
unpow194.9%
unpow194.9%
sqr-pow36.3%
fabs-sqr36.3%
sqr-pow79.9%
unpow179.9%
Simplified94.4%
Taylor expanded in s around inf 70.8%
+-commutative70.8%
unpow170.8%
sqr-pow24.4%
fabs-sqr24.4%
sqr-pow71.4%
unpow171.4%
Simplified71.4%
if 2e6 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 22.6%
+-commutative22.6%
+-commutative22.6%
mul-1-neg22.6%
distribute-lft1-in81.2%
metadata-eval81.2%
associate-*r/81.2%
mul-1-neg81.2%
remove-double-neg81.2%
+-commutative81.2%
associate-+l+81.2%
Simplified81.2%
Taylor expanded in x around inf 80.4%
unpow280.4%
Simplified80.4%
add-cbrt-cube100.0%
Applied egg-rr100.0%
Final simplification77.9%
(FPCore (x s)
:precision binary32
(if (<= x 50000000188416.0)
(/
1.0
(* (+ 1.0 (+ 1.0 (- (* 0.5 (* (/ x s) (/ x s))) (/ x s)))) (+ s (+ x s))))
(/ 1.0 (+ (* x (/ x s)) (* s 4.0)))))
float code(float x, float s) {
float tmp;
if (x <= 50000000188416.0f) {
tmp = 1.0f / ((1.0f + (1.0f + ((0.5f * ((x / s) * (x / s))) - (x / s)))) * (s + (x + s)));
} else {
tmp = 1.0f / ((x * (x / s)) + (s * 4.0f));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 50000000188416.0e0) then
tmp = 1.0e0 / ((1.0e0 + (1.0e0 + ((0.5e0 * ((x / s) * (x / s))) - (x / s)))) * (s + (x + s)))
else
tmp = 1.0e0 / ((x * (x / s)) + (s * 4.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(50000000188416.0)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x / s) * Float32(x / s))) - Float32(x / s)))) * Float32(s + Float32(x + s)))); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(x / s)) + Float32(s * Float32(4.0)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(50000000188416.0)) tmp = single(1.0) / ((single(1.0) + (single(1.0) + ((single(0.5) * ((x / s) * (x / s))) - (x / s)))) * (s + (x + s))); else tmp = single(1.0) / ((x * (x / s)) + (s * single(4.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 50000000188416:\\
\;\;\;\;\frac{1}{\left(1 + \left(1 + \left(0.5 \cdot \left(\frac{x}{s} \cdot \frac{x}{s}\right) - \frac{x}{s}\right)\right)\right) \cdot \left(s + \left(x + s\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s} + s \cdot 4}\\
\end{array}
\end{array}
if x < 5.00000002e13Initial program 99.5%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in s around inf 72.7%
+-commutative72.7%
neg-mul-172.7%
unsub-neg72.7%
unpow272.7%
unpow272.7%
times-frac80.2%
unpow180.2%
sqr-pow40.2%
fabs-sqr40.2%
sqr-pow93.9%
unpow193.9%
unpow193.9%
sqr-pow40.2%
fabs-sqr40.2%
sqr-pow80.2%
unpow180.2%
Simplified93.5%
Taylor expanded in s around inf 71.4%
+-commutative71.4%
unpow171.4%
sqr-pow28.9%
fabs-sqr28.9%
sqr-pow72.0%
unpow172.0%
Simplified72.0%
if 5.00000002e13 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 15.0%
+-commutative15.0%
+-commutative15.0%
mul-1-neg15.0%
distribute-lft1-in100.0%
metadata-eval100.0%
associate-*r/100.0%
mul-1-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
associate-+l+100.0%
Simplified100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Final simplification76.4%
(FPCore (x s) :precision binary32 (if (<= x 10000000000.0) (/ 1.0 (* (+ 1.0 (+ 1.0 (- (* 0.5 (* (/ x s) (/ x s))) (/ x s)))) (+ s s))) (/ 1.0 (+ (* x (/ x s)) (* s 4.0)))))
float code(float x, float s) {
float tmp;
if (x <= 10000000000.0f) {
tmp = 1.0f / ((1.0f + (1.0f + ((0.5f * ((x / s) * (x / s))) - (x / s)))) * (s + s));
} else {
tmp = 1.0f / ((x * (x / s)) + (s * 4.0f));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 10000000000.0e0) then
tmp = 1.0e0 / ((1.0e0 + (1.0e0 + ((0.5e0 * ((x / s) * (x / s))) - (x / s)))) * (s + s))
else
tmp = 1.0e0 / ((x * (x / s)) + (s * 4.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(10000000000.0)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + Float32(Float32(1.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x / s) * Float32(x / s))) - Float32(x / s)))) * Float32(s + s))); else tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(x / s)) + Float32(s * Float32(4.0)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(10000000000.0)) tmp = single(1.0) / ((single(1.0) + (single(1.0) + ((single(0.5) * ((x / s) * (x / s))) - (x / s)))) * (s + s)); else tmp = single(1.0) / ((x * (x / s)) + (s * single(4.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10000000000:\\
\;\;\;\;\frac{1}{\left(1 + \left(1 + \left(0.5 \cdot \left(\frac{x}{s} \cdot \frac{x}{s}\right) - \frac{x}{s}\right)\right)\right) \cdot \left(s + s\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s} + s \cdot 4}\\
\end{array}
\end{array}
if x < 1e10Initial program 99.5%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in s around inf 72.4%
+-commutative72.4%
neg-mul-172.4%
unsub-neg72.4%
unpow272.4%
unpow272.4%
times-frac80.1%
unpow180.1%
sqr-pow39.0%
fabs-sqr39.0%
sqr-pow94.2%
unpow194.2%
unpow194.2%
sqr-pow39.0%
fabs-sqr39.0%
sqr-pow80.1%
unpow180.1%
Simplified93.8%
Taylor expanded in s around inf 67.1%
if 1e10 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 20.4%
+-commutative20.4%
+-commutative20.4%
mul-1-neg20.4%
distribute-lft1-in94.3%
metadata-eval94.3%
associate-*r/94.3%
mul-1-neg94.3%
remove-double-neg94.3%
+-commutative94.3%
associate-+l+94.3%
Simplified94.3%
associate-/r/94.3%
Applied egg-rr94.3%
Final simplification72.0%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (* x (/ x s)) (* s 4.0))))
float code(float x, float s) {
return 1.0f / ((x * (x / s)) + (s * 4.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((x * (x / s)) + (s * 4.0e0))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(x * Float32(x / s)) + Float32(s * Float32(4.0)))) end
function tmp = code(x, s) tmp = single(1.0) / ((x * (x / s)) + (s * single(4.0))); end
\begin{array}{l}
\\
\frac{1}{x \cdot \frac{x}{s} + s \cdot 4}
\end{array}
Initial program 99.6%
Simplified99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in s around -inf 40.2%
+-commutative40.2%
+-commutative40.2%
mul-1-neg40.2%
distribute-lft1-in64.8%
metadata-eval64.8%
associate-*r/64.8%
mul-1-neg64.8%
remove-double-neg64.8%
+-commutative64.8%
associate-+l+64.8%
Simplified65.6%
associate-/r/65.6%
Applied egg-rr65.6%
Final simplification65.6%
(FPCore (x s) :precision binary32 (if (<= x 0.006000000052154064) (/ 0.25 s) (* s (/ 1.0 (* x x)))))
float code(float x, float s) {
float tmp;
if (x <= 0.006000000052154064f) {
tmp = 0.25f / s;
} else {
tmp = s * (1.0f / (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 <= 0.006000000052154064e0) then
tmp = 0.25e0 / s
else
tmp = s * (1.0e0 / (x * x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.006000000052154064)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(s * Float32(Float32(1.0) / Float32(x * x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.006000000052154064)) tmp = single(0.25) / s; else tmp = s * (single(1.0) / (x * x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.006000000052154064:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;s \cdot \frac{1}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.00600000005Initial program 99.5%
Simplified99.5%
Taylor expanded in s around inf 34.2%
if 0.00600000005 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 24.4%
+-commutative24.4%
+-commutative24.4%
mul-1-neg24.4%
distribute-lft1-in72.9%
metadata-eval72.9%
associate-*r/72.9%
mul-1-neg72.9%
remove-double-neg72.9%
+-commutative72.9%
associate-+l+72.9%
Simplified72.9%
Taylor expanded in x around inf 71.3%
unpow271.3%
Simplified71.3%
div-inv71.3%
Applied egg-rr71.3%
Final simplification44.3%
(FPCore (x s) :precision binary32 (if (<= x 0.006000000052154064) (/ 0.25 s) (/ s (* x x))))
float code(float x, float s) {
float tmp;
if (x <= 0.006000000052154064f) {
tmp = 0.25f / s;
} else {
tmp = 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 <= 0.006000000052154064e0) then
tmp = 0.25e0 / s
else
tmp = s / (x * x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.006000000052154064)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(s / Float32(x * x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.006000000052154064)) tmp = single(0.25) / s; else tmp = s / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.006000000052154064:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.00600000005Initial program 99.5%
Simplified99.5%
Taylor expanded in s around inf 34.2%
if 0.00600000005 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 24.4%
+-commutative24.4%
+-commutative24.4%
mul-1-neg24.4%
distribute-lft1-in72.9%
metadata-eval72.9%
associate-*r/72.9%
mul-1-neg72.9%
remove-double-neg72.9%
+-commutative72.9%
associate-+l+72.9%
Simplified72.9%
Taylor expanded in x around inf 71.3%
unpow271.3%
Simplified71.3%
Final simplification44.3%
(FPCore (x s) :precision binary32 (/ 0.25 s))
float code(float x, float s) {
return 0.25f / s;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.25e0 / s
end function
function code(x, s) return Float32(Float32(0.25) / s) end
function tmp = code(x, s) tmp = single(0.25) / s; end
\begin{array}{l}
\\
\frac{0.25}{s}
\end{array}
Initial program 99.6%
Simplified99.6%
Taylor expanded in s around inf 26.1%
Final simplification26.1%
herbie shell --seed 2023278
(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))))))