
(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 17 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 (exp (/ (fabs x) (- s))))) (/ t_0 (* (+ t_0 1.0) (+ s (/ s (exp (/ (fabs x) s))))))))
float code(float x, float s) {
float t_0 = expf((fabsf(x) / -s));
return t_0 / ((t_0 + 1.0f) * (s + (s / expf((fabsf(x) / s)))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((abs(x) / -s))
code = t_0 / ((t_0 + 1.0e0) * (s + (s / exp((abs(x) / s)))))
end function
function code(x, s) t_0 = exp(Float32(abs(x) / Float32(-s))) return Float32(t_0 / Float32(Float32(t_0 + Float32(1.0)) * Float32(s + Float32(s / exp(Float32(abs(x) / s)))))) end
function tmp = code(x, s) t_0 = exp((abs(x) / -s)); tmp = t_0 / ((t_0 + single(1.0)) * (s + (s / exp((abs(x) / s))))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{\left|x\right|}{-s}}\\
\frac{t\_0}{\left(t\_0 + 1\right) \cdot \left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\right)}
\end{array}
\end{array}
Initial program 99.3%
*-commutative99.3%
fabs-neg99.3%
distribute-lft-in99.4%
*-rgt-identity99.4%
fabs-neg99.4%
distribute-rgt-in99.4%
cancel-sign-sub99.4%
Simplified99.3%
Final simplification99.3%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x s)))) (/ (exp (/ (- x (* s (log1p t_0))) s)) (+ s (* s t_0)))))
float code(float x, float s) {
float t_0 = expf((x / s));
return expf(((x - (s * log1pf(t_0))) / s)) / (s + (s * t_0));
}
function code(x, s) t_0 = exp(Float32(x / s)) return Float32(exp(Float32(Float32(x - Float32(s * log1p(t_0))) / s)) / Float32(s + Float32(s * t_0))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\frac{e^{\frac{x - s \cdot \mathsf{log1p}\left(t\_0\right)}{s}}}{s + s \cdot t\_0}
\end{array}
\end{array}
Initial program 99.3%
*-commutative99.3%
Simplified99.3%
Applied egg-rr85.7%
associate-*r/85.6%
*-rgt-identity85.6%
Simplified85.6%
fma-undefine85.6%
Applied egg-rr85.6%
Taylor expanded in s around 0 99.3%
mul-1-neg99.3%
unsub-neg99.3%
log1p-define99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x s) :precision binary32 (if (<= (fabs x) 0.00019999999494757503) (/ (exp (- (/ x s) (* (log1p (exp (/ x s))) 2.0))) s) (/ (/ (exp (/ x (- s))) s) 4.0)))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 0.00019999999494757503f) {
tmp = expf(((x / s) - (log1pf(expf((x / s))) * 2.0f))) / s;
} else {
tmp = (expf((x / -s)) / s) / 4.0f;
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(0.00019999999494757503)) tmp = Float32(exp(Float32(Float32(x / s) - Float32(log1p(exp(Float32(x / s))) * Float32(2.0)))) / s); else tmp = Float32(Float32(exp(Float32(x / Float32(-s))) / s) / Float32(4.0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.00019999999494757503:\\
\;\;\;\;\frac{e^{\frac{x}{s} - \mathsf{log1p}\left(e^{\frac{x}{s}}\right) \cdot 2}}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{e^{\frac{x}{-s}}}{s}}{4}\\
\end{array}
\end{array}
if (fabs.f32 x) < 1.99999995e-4Initial program 98.4%
*-commutative98.4%
Simplified98.4%
Applied egg-rr93.0%
exp-diff73.0%
add-exp-log77.8%
*-commutative77.8%
+-commutative77.8%
associate-/r*77.8%
Applied egg-rr77.8%
add-exp-log77.9%
log-div77.9%
add-log-exp97.6%
log-pow98.3%
log1p-define98.5%
Applied egg-rr98.5%
if 1.99999995e-4 < (fabs.f32 x) Initial program 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
associate-/r*100.0%
mul-1-neg100.0%
distribute-neg-frac2100.0%
+-commutative100.0%
mul-1-neg100.0%
distribute-neg-frac2100.0%
Simplified100.0%
distribute-frac-neg2100.0%
exp-neg100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod-0.0%
add-sqr-sqrt3.1%
div-inv3.1%
exp-prod3.1%
add-sqr-sqrt1.7%
fabs-sqr1.7%
add-sqr-sqrt47.9%
add-sqr-sqrt-0.0%
sqrt-unprod55.2%
sqr-neg55.2%
sqrt-unprod55.2%
add-sqr-sqrt55.2%
exp-prod55.2%
div-inv55.2%
Applied egg-rr55.2%
rec-exp55.2%
distribute-frac-neg55.2%
Simplified55.2%
Taylor expanded in s around inf 55.2%
Final simplification74.0%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x (- s))))) (/ (/ t_0 s) (pow (+ t_0 1.0) 2.0))))
float code(float x, float s) {
float t_0 = expf((x / -s));
return (t_0 / s) / powf((t_0 + 1.0f), 2.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((x / -s))
code = (t_0 / s) / ((t_0 + 1.0e0) ** 2.0e0)
end function
function code(x, s) t_0 = exp(Float32(x / Float32(-s))) return Float32(Float32(t_0 / s) / (Float32(t_0 + Float32(1.0)) ^ Float32(2.0))) end
function tmp = code(x, s) t_0 = exp((x / -s)); tmp = (t_0 / s) / ((t_0 + single(1.0)) ^ single(2.0)); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{-s}}\\
\frac{\frac{t\_0}{s}}{{\left(t\_0 + 1\right)}^{2}}
\end{array}
\end{array}
Initial program 99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in x around 0 99.3%
associate-/r*99.3%
mul-1-neg99.3%
distribute-neg-frac299.3%
+-commutative99.3%
mul-1-neg99.3%
distribute-neg-frac299.3%
Simplified99.3%
distribute-frac-neg299.3%
exp-neg99.2%
add-sqr-sqrt99.1%
sqrt-unprod92.5%
sqr-neg92.5%
sqrt-unprod-0.0%
add-sqr-sqrt23.0%
div-inv23.0%
exp-prod23.4%
add-sqr-sqrt13.2%
fabs-sqr13.2%
add-sqr-sqrt51.3%
add-sqr-sqrt21.0%
sqrt-unprod56.0%
sqr-neg56.0%
sqrt-unprod56.0%
add-sqr-sqrt56.0%
exp-prod62.9%
div-inv62.9%
Applied egg-rr62.9%
rec-exp63.0%
distribute-frac-neg63.0%
Simplified63.0%
distribute-frac-neg299.3%
exp-neg99.2%
add-sqr-sqrt99.1%
sqrt-unprod92.5%
sqr-neg92.5%
sqrt-unprod-0.0%
add-sqr-sqrt23.0%
div-inv23.0%
exp-prod23.4%
add-sqr-sqrt13.2%
fabs-sqr13.2%
add-sqr-sqrt51.3%
add-sqr-sqrt21.0%
sqrt-unprod56.0%
sqr-neg56.0%
sqrt-unprod56.0%
add-sqr-sqrt56.0%
exp-prod62.9%
div-inv62.9%
Applied egg-rr65.6%
rec-exp63.0%
distribute-frac-neg63.0%
Simplified65.7%
Final simplification65.7%
(FPCore (x s) :precision binary32 (exp (- (* -0.25 (pow (/ x s) 2.0)) (log (* s 4.0)))))
float code(float x, float s) {
return expf(((-0.25f * powf((x / s), 2.0f)) - logf((s * 4.0f))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = exp((((-0.25e0) * ((x / s) ** 2.0e0)) - log((s * 4.0e0))))
end function
function code(x, s) return exp(Float32(Float32(Float32(-0.25) * (Float32(x / s) ^ Float32(2.0))) - log(Float32(s * Float32(4.0))))) end
function tmp = code(x, s) tmp = exp(((single(-0.25) * ((x / s) ^ single(2.0))) - log((s * single(4.0))))); end
\begin{array}{l}
\\
e^{-0.25 \cdot {\left(\frac{x}{s}\right)}^{2} - \log \left(s \cdot 4\right)}
\end{array}
Initial program 99.3%
*-commutative99.3%
Simplified99.3%
Applied egg-rr83.3%
Taylor expanded in x around 0 88.5%
unpow288.5%
unpow288.5%
times-frac94.8%
unpow294.8%
*-commutative94.8%
Simplified94.8%
Final simplification94.8%
(FPCore (x s) :precision binary32 (/ 0.5 (fma s (exp (/ x s)) s)))
float code(float x, float s) {
return 0.5f / fmaf(s, expf((x / s)), s);
}
function code(x, s) return Float32(Float32(0.5) / fma(s, exp(Float32(x / s)), s)) end
\begin{array}{l}
\\
\frac{0.5}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}
\end{array}
Initial program 99.3%
*-commutative99.3%
Simplified99.3%
Applied egg-rr85.7%
associate-*r/85.6%
*-rgt-identity85.6%
Simplified85.6%
Taylor expanded in x around 0 62.1%
mul-1-neg62.1%
Simplified62.1%
Taylor expanded in s around 0 62.0%
neg-mul-162.0%
*-commutative62.0%
exp-to-pow62.0%
metadata-eval62.0%
+-commutative62.0%
distribute-lft-in62.0%
*-rgt-identity62.0%
fma-define62.1%
Simplified62.1%
Final simplification62.1%
(FPCore (x s) :precision binary32 (/ (/ (exp (/ x (- s))) s) 4.0))
float code(float x, float s) {
return (expf((x / -s)) / s) / 4.0f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (exp((x / -s)) / s) / 4.0e0
end function
function code(x, s) return Float32(Float32(exp(Float32(x / Float32(-s))) / s) / Float32(4.0)) end
function tmp = code(x, s) tmp = (exp((x / -s)) / s) / single(4.0); end
\begin{array}{l}
\\
\frac{\frac{e^{\frac{x}{-s}}}{s}}{4}
\end{array}
Initial program 99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in x around 0 99.3%
associate-/r*99.3%
mul-1-neg99.3%
distribute-neg-frac299.3%
+-commutative99.3%
mul-1-neg99.3%
distribute-neg-frac299.3%
Simplified99.3%
distribute-frac-neg299.3%
exp-neg99.2%
add-sqr-sqrt99.1%
sqrt-unprod92.5%
sqr-neg92.5%
sqrt-unprod-0.0%
add-sqr-sqrt23.0%
div-inv23.0%
exp-prod23.4%
add-sqr-sqrt13.2%
fabs-sqr13.2%
add-sqr-sqrt51.3%
add-sqr-sqrt21.0%
sqrt-unprod56.0%
sqr-neg56.0%
sqrt-unprod56.0%
add-sqr-sqrt56.0%
exp-prod62.9%
div-inv62.9%
Applied egg-rr62.9%
rec-exp63.0%
distribute-frac-neg63.0%
Simplified63.0%
Taylor expanded in s around inf 61.2%
Final simplification61.2%
(FPCore (x s)
:precision binary32
(let* ((t_0 (+ (/ x s) 1.0)))
(if (<= s 9.999999682655225e-22)
(/ t_0 (+ (* s 4.0) (* x (+ 4.0 (/ x (* s (* x s)))))))
(/ t_0 (+ (* s 4.0) (* x (+ (/ x s) 4.0)))))))
float code(float x, float s) {
float t_0 = (x / s) + 1.0f;
float tmp;
if (s <= 9.999999682655225e-22f) {
tmp = t_0 / ((s * 4.0f) + (x * (4.0f + (x / (s * (x * s))))));
} else {
tmp = t_0 / ((s * 4.0f) + (x * ((x / s) + 4.0f)));
}
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) + 1.0e0
if (s <= 9.999999682655225e-22) then
tmp = t_0 / ((s * 4.0e0) + (x * (4.0e0 + (x / (s * (x * s))))))
else
tmp = t_0 / ((s * 4.0e0) + (x * ((x / s) + 4.0e0)))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(x / s) + Float32(1.0)) tmp = Float32(0.0) if (s <= Float32(9.999999682655225e-22)) tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(4.0) + Float32(x / Float32(s * Float32(x * s))))))); else tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(x / s) + Float32(4.0))))); end return tmp end
function tmp_2 = code(x, s) t_0 = (x / s) + single(1.0); tmp = single(0.0); if (s <= single(9.999999682655225e-22)) tmp = t_0 / ((s * single(4.0)) + (x * (single(4.0) + (x / (s * (x * s)))))); else tmp = t_0 / ((s * single(4.0)) + (x * ((x / s) + single(4.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{s} + 1\\
\mathbf{if}\;s \leq 9.999999682655225 \cdot 10^{-22}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(4 + \frac{x}{s \cdot \left(x \cdot s\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(\frac{x}{s} + 4\right)}\\
\end{array}
\end{array}
if s < 9.9999997e-22Initial program 98.8%
*-commutative98.8%
Simplified98.8%
div-inv98.8%
div-inv98.7%
div-inv98.8%
add-sqr-sqrt-0.0%
sqrt-unprod11.1%
sqr-neg11.1%
sqrt-unprod10.7%
add-sqr-sqrt10.7%
add-sqr-sqrt6.2%
fabs-sqr6.2%
add-sqr-sqrt52.0%
*-commutative52.0%
associate-*l*51.9%
Applied egg-rr52.0%
associate-*r/52.0%
*-rgt-identity52.0%
+-commutative52.0%
Simplified52.0%
Taylor expanded in x around 0 47.7%
Taylor expanded in x around 0 18.3%
Applied egg-rr43.3%
if 9.9999997e-22 < s Initial program 99.7%
*-commutative99.7%
Simplified99.7%
div-inv99.7%
div-inv99.7%
div-inv99.7%
add-sqr-sqrt-0.0%
sqrt-unprod32.8%
sqr-neg32.8%
sqrt-unprod32.8%
add-sqr-sqrt32.8%
add-sqr-sqrt18.5%
fabs-sqr18.5%
add-sqr-sqrt65.1%
*-commutative65.1%
associate-*l*65.2%
Applied egg-rr66.2%
associate-*r/66.1%
*-rgt-identity66.1%
+-commutative66.1%
Simplified66.1%
Taylor expanded in x around 0 65.1%
Taylor expanded in x around 0 59.5%
Applied egg-rr60.3%
Final simplification52.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (+ (/ x s) 1.0)))
(if (<= x 4.999999999099794e-24)
(/ t_0 (+ (* s 4.0) (* x (+ (/ x s) 4.0))))
(/ t_0 (+ (* s 4.0) (* x (+ 4.0 (/ (* x x) (* s s)))))))))
float code(float x, float s) {
float t_0 = (x / s) + 1.0f;
float tmp;
if (x <= 4.999999999099794e-24f) {
tmp = t_0 / ((s * 4.0f) + (x * ((x / s) + 4.0f)));
} else {
tmp = t_0 / ((s * 4.0f) + (x * (4.0f + ((x * x) / (s * 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) + 1.0e0
if (x <= 4.999999999099794e-24) then
tmp = t_0 / ((s * 4.0e0) + (x * ((x / s) + 4.0e0)))
else
tmp = t_0 / ((s * 4.0e0) + (x * (4.0e0 + ((x * x) / (s * s)))))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(x / s) + Float32(1.0)) tmp = Float32(0.0) if (x <= Float32(4.999999999099794e-24)) tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(x / s) + Float32(4.0))))); else tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))))); end return tmp end
function tmp_2 = code(x, s) t_0 = (x / s) + single(1.0); tmp = single(0.0); if (x <= single(4.999999999099794e-24)) tmp = t_0 / ((s * single(4.0)) + (x * ((x / s) + single(4.0)))); else tmp = t_0 / ((s * single(4.0)) + (x * (single(4.0) + ((x * x) / (s * s))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{s} + 1\\
\mathbf{if}\;x \leq 4.999999999099794 \cdot 10^{-24}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(\frac{x}{s} + 4\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(4 + \frac{x \cdot x}{s \cdot s}\right)}\\
\end{array}
\end{array}
if x < 5e-24Initial program 98.9%
*-commutative98.9%
Simplified98.9%
div-inv98.8%
div-inv98.7%
div-inv98.8%
add-sqr-sqrt-0.0%
sqrt-unprod30.9%
sqr-neg30.9%
sqrt-unprod30.6%
add-sqr-sqrt30.6%
add-sqr-sqrt12.7%
fabs-sqr12.7%
add-sqr-sqrt95.5%
*-commutative95.5%
associate-*l*95.6%
Applied egg-rr96.1%
associate-*r/96.2%
*-rgt-identity96.2%
+-commutative96.2%
Simplified96.2%
Taylor expanded in x around 0 91.8%
Taylor expanded in x around 0 46.3%
Applied egg-rr47.3%
if 5e-24 < x Initial program 99.9%
*-commutative99.9%
Simplified99.9%
div-inv99.9%
div-inv99.9%
div-inv99.9%
add-sqr-sqrt-0.0%
sqrt-unprod13.5%
sqr-neg13.5%
sqrt-unprod13.5%
add-sqr-sqrt13.5%
add-sqr-sqrt13.5%
fabs-sqr13.5%
add-sqr-sqrt13.5%
*-commutative13.5%
associate-*l*13.5%
Applied egg-rr14.0%
associate-*r/14.0%
*-rgt-identity14.0%
+-commutative14.0%
Simplified14.0%
Taylor expanded in x around 0 13.9%
Taylor expanded in x around 0 35.1%
Applied egg-rr55.3%
Final simplification50.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (+ (/ x s) 1.0)))
(if (<= s 2.8999998943650185e-34)
(/ t_0 (+ (* s 4.0) (* x (+ 4.0 (/ 2.0 (* x s))))))
(/ t_0 (+ (* s 4.0) (* x (+ 4.0 (* (/ x s) 3.0))))))))
float code(float x, float s) {
float t_0 = (x / s) + 1.0f;
float tmp;
if (s <= 2.8999998943650185e-34f) {
tmp = t_0 / ((s * 4.0f) + (x * (4.0f + (2.0f / (x * s)))));
} else {
tmp = t_0 / ((s * 4.0f) + (x * (4.0f + ((x / s) * 3.0f))));
}
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) + 1.0e0
if (s <= 2.8999998943650185e-34) then
tmp = t_0 / ((s * 4.0e0) + (x * (4.0e0 + (2.0e0 / (x * s)))))
else
tmp = t_0 / ((s * 4.0e0) + (x * (4.0e0 + ((x / s) * 3.0e0))))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(x / s) + Float32(1.0)) tmp = Float32(0.0) if (s <= Float32(2.8999998943650185e-34)) tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(4.0) + Float32(Float32(2.0) / Float32(x * s)))))); else tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(3.0)))))); end return tmp end
function tmp_2 = code(x, s) t_0 = (x / s) + single(1.0); tmp = single(0.0); if (s <= single(2.8999998943650185e-34)) tmp = t_0 / ((s * single(4.0)) + (x * (single(4.0) + (single(2.0) / (x * s))))); else tmp = t_0 / ((s * single(4.0)) + (x * (single(4.0) + ((x / s) * single(3.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{s} + 1\\
\mathbf{if}\;s \leq 2.8999998943650185 \cdot 10^{-34}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(4 + \frac{2}{x \cdot s}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(4 + \frac{x}{s} \cdot 3\right)}\\
\end{array}
\end{array}
if s < 2.89999989e-34Initial program 100.0%
*-commutative100.0%
Simplified100.0%
div-inv100.0%
div-inv100.0%
div-inv100.0%
add-sqr-sqrt-0.0%
sqrt-unprod3.8%
sqr-neg3.8%
sqrt-unprod3.6%
add-sqr-sqrt3.6%
add-sqr-sqrt1.8%
fabs-sqr1.8%
add-sqr-sqrt43.8%
*-commutative43.8%
associate-*l*43.8%
Applied egg-rr41.9%
associate-*r/41.9%
*-rgt-identity41.9%
+-commutative41.9%
Simplified41.9%
Taylor expanded in x around 0 40.2%
Taylor expanded in x around 0 5.5%
Applied egg-rr47.0%
distribute-frac-neg247.0%
distribute-neg-frac47.0%
metadata-eval47.0%
Simplified47.0%
if 2.89999989e-34 < s Initial program 99.2%
*-commutative99.2%
Simplified99.2%
div-inv99.2%
div-inv99.2%
div-inv99.2%
add-sqr-sqrt-0.0%
sqrt-unprod25.9%
sqr-neg25.9%
sqrt-unprod25.7%
add-sqr-sqrt25.7%
add-sqr-sqrt14.6%
fabs-sqr14.6%
add-sqr-sqrt61.5%
*-commutative61.5%
associate-*l*61.5%
Applied egg-rr62.4%
associate-*r/62.4%
*-rgt-identity62.4%
+-commutative62.4%
Simplified62.4%
Taylor expanded in x around 0 59.8%
Taylor expanded in x around 0 46.3%
Final simplification46.4%
(FPCore (x s)
:precision binary32
(let* ((t_0 (+ (/ x s) 1.0)))
(if (<= s 2.8999998943650185e-34)
(/ t_0 (+ (* s 4.0) (* x (+ 4.0 (/ 2.0 (* x s))))))
(/ t_0 (+ (* s 4.0) (* x (+ (/ x s) 4.0)))))))
float code(float x, float s) {
float t_0 = (x / s) + 1.0f;
float tmp;
if (s <= 2.8999998943650185e-34f) {
tmp = t_0 / ((s * 4.0f) + (x * (4.0f + (2.0f / (x * s)))));
} else {
tmp = t_0 / ((s * 4.0f) + (x * ((x / s) + 4.0f)));
}
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) + 1.0e0
if (s <= 2.8999998943650185e-34) then
tmp = t_0 / ((s * 4.0e0) + (x * (4.0e0 + (2.0e0 / (x * s)))))
else
tmp = t_0 / ((s * 4.0e0) + (x * ((x / s) + 4.0e0)))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(x / s) + Float32(1.0)) tmp = Float32(0.0) if (s <= Float32(2.8999998943650185e-34)) tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(4.0) + Float32(Float32(2.0) / Float32(x * s)))))); else tmp = Float32(t_0 / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(x / s) + Float32(4.0))))); end return tmp end
function tmp_2 = code(x, s) t_0 = (x / s) + single(1.0); tmp = single(0.0); if (s <= single(2.8999998943650185e-34)) tmp = t_0 / ((s * single(4.0)) + (x * (single(4.0) + (single(2.0) / (x * s))))); else tmp = t_0 / ((s * single(4.0)) + (x * ((x / s) + single(4.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{s} + 1\\
\mathbf{if}\;s \leq 2.8999998943650185 \cdot 10^{-34}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(4 + \frac{2}{x \cdot s}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{s \cdot 4 + x \cdot \left(\frac{x}{s} + 4\right)}\\
\end{array}
\end{array}
if s < 2.89999989e-34Initial program 100.0%
*-commutative100.0%
Simplified100.0%
div-inv100.0%
div-inv100.0%
div-inv100.0%
add-sqr-sqrt-0.0%
sqrt-unprod3.8%
sqr-neg3.8%
sqrt-unprod3.6%
add-sqr-sqrt3.6%
add-sqr-sqrt1.8%
fabs-sqr1.8%
add-sqr-sqrt43.8%
*-commutative43.8%
associate-*l*43.8%
Applied egg-rr41.9%
associate-*r/41.9%
*-rgt-identity41.9%
+-commutative41.9%
Simplified41.9%
Taylor expanded in x around 0 40.2%
Taylor expanded in x around 0 5.5%
Applied egg-rr47.0%
distribute-frac-neg247.0%
distribute-neg-frac47.0%
metadata-eval47.0%
Simplified47.0%
if 2.89999989e-34 < s Initial program 99.2%
*-commutative99.2%
Simplified99.2%
div-inv99.2%
div-inv99.2%
div-inv99.2%
add-sqr-sqrt-0.0%
sqrt-unprod25.9%
sqr-neg25.9%
sqrt-unprod25.7%
add-sqr-sqrt25.7%
add-sqr-sqrt14.6%
fabs-sqr14.6%
add-sqr-sqrt61.5%
*-commutative61.5%
associate-*l*61.5%
Applied egg-rr62.4%
associate-*r/62.4%
*-rgt-identity62.4%
+-commutative62.4%
Simplified62.4%
Taylor expanded in x around 0 59.8%
Taylor expanded in x around 0 46.3%
Applied egg-rr47.1%
Final simplification47.1%
(FPCore (x s) :precision binary32 (if (<= x 5000000.0) (/ (+ (/ x s) 1.0) (* s (+ 4.0 (* (/ x s) 4.0)))) (/ 0.3333333333333333 x)))
float code(float x, float s) {
float tmp;
if (x <= 5000000.0f) {
tmp = ((x / s) + 1.0f) / (s * (4.0f + ((x / s) * 4.0f)));
} else {
tmp = 0.3333333333333333f / x;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 5000000.0e0) then
tmp = ((x / s) + 1.0e0) / (s * (4.0e0 + ((x / s) * 4.0e0)))
else
tmp = 0.3333333333333333e0 / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(5000000.0)) tmp = Float32(Float32(Float32(x / s) + Float32(1.0)) / Float32(s * Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(4.0))))); else tmp = Float32(Float32(0.3333333333333333) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(5000000.0)) tmp = ((x / s) + single(1.0)) / (s * (single(4.0) + ((x / s) * single(4.0)))); else tmp = single(0.3333333333333333) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5000000:\\
\;\;\;\;\frac{\frac{x}{s} + 1}{s \cdot \left(4 + \frac{x}{s} \cdot 4\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333}{x}\\
\end{array}
\end{array}
if x < 5e6Initial program 99.1%
*-commutative99.1%
Simplified99.1%
div-inv99.1%
div-inv99.0%
div-inv99.1%
add-sqr-sqrt-0.0%
sqrt-unprod29.4%
sqr-neg29.4%
sqrt-unprod29.1%
add-sqr-sqrt29.1%
add-sqr-sqrt16.1%
fabs-sqr16.1%
add-sqr-sqrt76.5%
*-commutative76.5%
associate-*l*76.5%
Applied egg-rr78.2%
associate-*r/78.2%
*-rgt-identity78.2%
+-commutative78.2%
Simplified78.2%
Taylor expanded in x around 0 74.9%
Taylor expanded in x around 0 43.5%
Taylor expanded in s around inf 33.6%
if 5e6 < x Initial program 100.0%
*-commutative100.0%
Simplified100.0%
div-inv100.0%
div-inv100.0%
div-inv100.0%
add-sqr-sqrt-0.0%
sqrt-unprod3.1%
sqr-neg3.1%
sqrt-unprod3.1%
add-sqr-sqrt3.1%
add-sqr-sqrt3.1%
fabs-sqr3.1%
add-sqr-sqrt3.1%
*-commutative3.1%
associate-*l*3.1%
Applied egg-rr-0.0%
associate-*r/-0.0%
*-rgt-identity-0.0%
+-commutative-0.0%
Simplified-0.0%
Taylor expanded in x around 0 0.3%
Taylor expanded in x around 0 34.1%
Taylor expanded in x around inf 11.4%
Final simplification28.4%
(FPCore (x s) :precision binary32 (/ (+ (/ x s) 1.0) (+ (* s 4.0) (* x (+ 4.0 (* (/ x s) 3.0))))))
float code(float x, float s) {
return ((x / s) + 1.0f) / ((s * 4.0f) + (x * (4.0f + ((x / s) * 3.0f))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = ((x / s) + 1.0e0) / ((s * 4.0e0) + (x * (4.0e0 + ((x / s) * 3.0e0))))
end function
function code(x, s) return Float32(Float32(Float32(x / s) + Float32(1.0)) / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(3.0)))))) end
function tmp = code(x, s) tmp = ((x / s) + single(1.0)) / ((s * single(4.0)) + (x * (single(4.0) + ((x / s) * single(3.0))))); end
\begin{array}{l}
\\
\frac{\frac{x}{s} + 1}{s \cdot 4 + x \cdot \left(4 + \frac{x}{s} \cdot 3\right)}
\end{array}
Initial program 99.3%
*-commutative99.3%
Simplified99.3%
div-inv99.3%
div-inv99.3%
div-inv99.3%
add-sqr-sqrt-0.0%
sqrt-unprod23.2%
sqr-neg23.2%
sqrt-unprod23.0%
add-sqr-sqrt23.0%
add-sqr-sqrt13.0%
fabs-sqr13.0%
add-sqr-sqrt59.3%
*-commutative59.3%
associate-*l*59.3%
Applied egg-rr59.9%
associate-*r/59.9%
*-rgt-identity59.9%
+-commutative59.9%
Simplified59.9%
Taylor expanded in x around 0 57.4%
Taylor expanded in x around 0 41.3%
Final simplification41.3%
(FPCore (x s) :precision binary32 (/ (+ (/ x s) 1.0) (+ (* s 4.0) (+ x (* x (* x s))))))
float code(float x, float s) {
return ((x / s) + 1.0f) / ((s * 4.0f) + (x + (x * (x * s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = ((x / s) + 1.0e0) / ((s * 4.0e0) + (x + (x * (x * s))))
end function
function code(x, s) return Float32(Float32(Float32(x / s) + Float32(1.0)) / Float32(Float32(s * Float32(4.0)) + Float32(x + Float32(x * Float32(x * s))))) end
function tmp = code(x, s) tmp = ((x / s) + single(1.0)) / ((s * single(4.0)) + (x + (x * (x * s)))); end
\begin{array}{l}
\\
\frac{\frac{x}{s} + 1}{s \cdot 4 + \left(x + x \cdot \left(x \cdot s\right)\right)}
\end{array}
Initial program 99.3%
*-commutative99.3%
Simplified99.3%
div-inv99.3%
div-inv99.3%
div-inv99.3%
add-sqr-sqrt-0.0%
sqrt-unprod23.2%
sqr-neg23.2%
sqrt-unprod23.0%
add-sqr-sqrt23.0%
add-sqr-sqrt13.0%
fabs-sqr13.0%
add-sqr-sqrt59.3%
*-commutative59.3%
associate-*l*59.3%
Applied egg-rr59.9%
associate-*r/59.9%
*-rgt-identity59.9%
+-commutative59.9%
Simplified59.9%
Taylor expanded in x around 0 57.4%
Taylor expanded in x around 0 41.3%
Applied egg-rr29.5%
Final simplification29.5%
(FPCore (x s) :precision binary32 (if (<= x 0.00019999999494757503) (/ 0.25 s) (/ (+ 0.3333333333333333 (/ (* s -0.1111111111111111) x)) x)))
float code(float x, float s) {
float tmp;
if (x <= 0.00019999999494757503f) {
tmp = 0.25f / s;
} else {
tmp = (0.3333333333333333f + ((s * -0.1111111111111111f) / 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.00019999999494757503e0) then
tmp = 0.25e0 / s
else
tmp = (0.3333333333333333e0 + ((s * (-0.1111111111111111e0)) / x)) / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.00019999999494757503)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(0.3333333333333333) + Float32(Float32(s * Float32(-0.1111111111111111)) / x)) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.00019999999494757503)) tmp = single(0.25) / s; else tmp = (single(0.3333333333333333) + ((s * single(-0.1111111111111111)) / x)) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00019999999494757503:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333 + \frac{s \cdot -0.1111111111111111}{x}}{x}\\
\end{array}
\end{array}
if x < 1.99999995e-4Initial program 99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in s around inf 36.1%
if 1.99999995e-4 < x Initial program 100.0%
*-commutative100.0%
Simplified100.0%
div-inv100.0%
div-inv100.0%
div-inv100.0%
add-sqr-sqrt-0.0%
sqrt-unprod3.1%
sqr-neg3.1%
sqrt-unprod3.1%
add-sqr-sqrt3.1%
add-sqr-sqrt3.1%
fabs-sqr3.1%
add-sqr-sqrt3.1%
*-commutative3.1%
associate-*l*3.1%
Applied egg-rr-0.0%
associate-*r/-0.0%
*-rgt-identity-0.0%
+-commutative-0.0%
Simplified-0.0%
Taylor expanded in x around 0 0.8%
Taylor expanded in x around 0 31.3%
Taylor expanded in x around inf 10.3%
associate--l+10.3%
associate-*r/10.3%
associate-*r/10.3%
div-sub10.3%
distribute-rgt-out--10.3%
metadata-eval10.3%
Simplified10.3%
Final simplification28.2%
(FPCore (x s) :precision binary32 (if (<= x 0.00019999999494757503) (/ 0.25 s) (/ 0.3333333333333333 x)))
float code(float x, float s) {
float tmp;
if (x <= 0.00019999999494757503f) {
tmp = 0.25f / s;
} else {
tmp = 0.3333333333333333f / 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.00019999999494757503e0) then
tmp = 0.25e0 / s
else
tmp = 0.3333333333333333e0 / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.00019999999494757503)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(0.3333333333333333) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.00019999999494757503)) tmp = single(0.25) / s; else tmp = single(0.3333333333333333) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00019999999494757503:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333}{x}\\
\end{array}
\end{array}
if x < 1.99999995e-4Initial program 99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in s around inf 36.1%
if 1.99999995e-4 < x Initial program 100.0%
*-commutative100.0%
Simplified100.0%
div-inv100.0%
div-inv100.0%
div-inv100.0%
add-sqr-sqrt-0.0%
sqrt-unprod3.1%
sqr-neg3.1%
sqrt-unprod3.1%
add-sqr-sqrt3.1%
add-sqr-sqrt3.1%
fabs-sqr3.1%
add-sqr-sqrt3.1%
*-commutative3.1%
associate-*l*3.1%
Applied egg-rr-0.0%
associate-*r/-0.0%
*-rgt-identity-0.0%
+-commutative-0.0%
Simplified-0.0%
Taylor expanded in x around 0 0.8%
Taylor expanded in x around 0 31.3%
Taylor expanded in x around inf 10.3%
Final simplification28.2%
(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.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in s around inf 26.5%
Final simplification26.5%
herbie shell --seed 2024076
(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))))))