
(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 14 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 (/ (fabs x) s))) (/ -1.0 (* (+ s (* s (exp t_0))) (- -1.0 (exp (- t_0)))))))
float code(float x, float s) {
float t_0 = fabsf(x) / s;
return -1.0f / ((s + (s * expf(t_0))) * (-1.0f - expf(-t_0)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = abs(x) / s
code = (-1.0e0) / ((s + (s * exp(t_0))) * ((-1.0e0) - exp(-t_0)))
end function
function code(x, s) t_0 = Float32(abs(x) / s) return Float32(Float32(-1.0) / Float32(Float32(s + Float32(s * exp(t_0))) * Float32(Float32(-1.0) - exp(Float32(-t_0))))) end
function tmp = code(x, s) t_0 = abs(x) / s; tmp = single(-1.0) / ((s + (s * exp(t_0))) * (single(-1.0) - exp(-t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left|x\right|}{s}\\
\frac{-1}{\left(s + s \cdot e^{t\_0}\right) \cdot \left(-1 - e^{-t\_0}\right)}
\end{array}
\end{array}
Initial program 99.8%
associate-/l/N/A
/-lowering-/.f32N/A
Applied egg-rr99.9%
Taylor expanded in x around 0
exp-negN/A
associate-/r*N/A
/-lowering-/.f32N/A
*-commutativeN/A
associate-*l*N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*r*N/A
Simplified99.9%
+-lowering-+.f32N/A
*-lowering-*.f32N/A
exp-lowering-exp.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f3299.9
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (- (/ (fabs x) s)))) (t_1 (+ t_0 1.0)))
(if (<= (/ t_0 (* t_1 (* s t_1))) 0.004999999888241291)
(/ t_0 s)
(/ (fma (/ (* x -0.0625) s) (/ x s) 0.25) s))))
float code(float x, float s) {
float t_0 = expf(-(fabsf(x) / s));
float t_1 = t_0 + 1.0f;
float tmp;
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291f) {
tmp = t_0 / s;
} else {
tmp = fmaf(((x * -0.0625f) / s), (x / s), 0.25f) / s;
}
return tmp;
}
function code(x, s) t_0 = exp(Float32(-Float32(abs(x) / s))) t_1 = Float32(t_0 + Float32(1.0)) tmp = Float32(0.0) if (Float32(t_0 / Float32(t_1 * Float32(s * t_1))) <= Float32(0.004999999888241291)) tmp = Float32(t_0 / s); else tmp = Float32(fma(Float32(Float32(x * Float32(-0.0625)) / s), Float32(x / s), Float32(0.25)) / s); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\frac{\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 0.004999999888241291:\\
\;\;\;\;\frac{t\_0}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x \cdot -0.0625}{s}, \frac{x}{s}, 0.25\right)}{s}\\
\end{array}
\end{array}
if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 0.00499999989Initial program 99.9%
associate-/l/N/A
/-lowering-/.f32N/A
Applied egg-rr99.9%
div-invN/A
*-rgt-identityN/A
distribute-lft-inN/A
times-fracN/A
un-div-invN/A
pow2N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
*-commutativeN/A
Applied egg-rr99.9%
Taylor expanded in s around 0
neg-mul-1N/A
neg-lowering-neg.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f3299.9
Simplified99.9%
if 0.00499999989 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) Initial program 99.6%
Taylor expanded in s around inf
/-lowering-/.f32N/A
Simplified81.8%
+-commutativeN/A
associate-*l*N/A
*-commutativeN/A
times-fracN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-lowering-*.f32N/A
/-lowering-/.f3293.9
Applied egg-rr93.9%
Final simplification98.3%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (- (/ (fabs x) s)))) (t_1 (+ t_0 1.0)))
(if (<= (/ t_0 (* t_1 (* s t_1))) 0.004999999888241291)
(/ 0.5 (/ (fma (fabs x) s (* 0.5 (* x x))) s))
(/ 0.25 s))))
float code(float x, float s) {
float t_0 = expf(-(fabsf(x) / s));
float t_1 = t_0 + 1.0f;
float tmp;
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291f) {
tmp = 0.5f / (fmaf(fabsf(x), s, (0.5f * (x * x))) / s);
} else {
tmp = 0.25f / s;
}
return tmp;
}
function code(x, s) t_0 = exp(Float32(-Float32(abs(x) / s))) t_1 = Float32(t_0 + Float32(1.0)) tmp = Float32(0.0) if (Float32(t_0 / Float32(t_1 * Float32(s * t_1))) <= Float32(0.004999999888241291)) tmp = Float32(Float32(0.5) / Float32(fma(abs(x), s, Float32(Float32(0.5) * Float32(x * x))) / s)); else tmp = Float32(Float32(0.25) / s); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\frac{\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 0.004999999888241291:\\
\;\;\;\;\frac{0.5}{\frac{\mathsf{fma}\left(\left|x\right|, s, 0.5 \cdot \left(x \cdot x\right)\right)}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 0.00499999989Initial program 99.9%
associate-/r*N/A
clear-numN/A
associate-/l/N/A
associate-/r*N/A
flip3-+N/A
clear-numN/A
Applied egg-rr99.9%
Taylor expanded in s around inf
Simplified99.6%
Taylor expanded in s around inf
*-lowering-*.f32N/A
associate-+r+N/A
+-lowering-+.f32N/A
neg-mul-1N/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f32N/A
Simplified1.9%
Taylor expanded in s around 0
/-lowering-/.f32N/A
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
distribute-rgt-outN/A
metadata-evalN/A
*-rgt-identityN/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
fabs-lowering-fabs.f32N/A
distribute-lft1-inN/A
metadata-evalN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3257.4
Simplified57.4%
if 0.00499999989 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) Initial program 99.6%
Taylor expanded in s around inf
/-lowering-/.f3291.5
Simplified91.5%
Final simplification66.4%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (- (/ (fabs x) s)))) (t_1 (+ t_0 1.0)))
(if (<= (/ t_0 (* t_1 (* s t_1))) 0.004999999888241291)
(/ 0.5 (/ (* 0.5 (* x x)) s))
(/ 0.25 s))))
float code(float x, float s) {
float t_0 = expf(-(fabsf(x) / s));
float t_1 = t_0 + 1.0f;
float tmp;
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291f) {
tmp = 0.5f / ((0.5f * (x * x)) / s);
} else {
tmp = 0.25f / 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) :: t_1
real(4) :: tmp
t_0 = exp(-(abs(x) / s))
t_1 = t_0 + 1.0e0
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291e0) then
tmp = 0.5e0 / ((0.5e0 * (x * x)) / s)
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(-Float32(abs(x) / s))) t_1 = Float32(t_0 + Float32(1.0)) tmp = Float32(0.0) if (Float32(t_0 / Float32(t_1 * Float32(s * t_1))) <= Float32(0.004999999888241291)) tmp = Float32(Float32(0.5) / Float32(Float32(Float32(0.5) * Float32(x * x)) / s)); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) t_0 = exp(-(abs(x) / s)); t_1 = t_0 + single(1.0); tmp = single(0.0); if ((t_0 / (t_1 * (s * t_1))) <= single(0.004999999888241291)) tmp = single(0.5) / ((single(0.5) * (x * x)) / s); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\frac{\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 0.004999999888241291:\\
\;\;\;\;\frac{0.5}{\frac{0.5 \cdot \left(x \cdot x\right)}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 0.00499999989Initial program 99.9%
associate-/r*N/A
clear-numN/A
associate-/l/N/A
associate-/r*N/A
flip3-+N/A
clear-numN/A
Applied egg-rr99.9%
Taylor expanded in s around inf
Simplified99.6%
Taylor expanded in s around inf
*-lowering-*.f32N/A
associate-+r+N/A
+-lowering-+.f32N/A
neg-mul-1N/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f32N/A
Simplified1.9%
Taylor expanded in s around 0
/-lowering-/.f32N/A
distribute-lft1-inN/A
metadata-evalN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3257.4
Simplified57.4%
if 0.00499999989 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) Initial program 99.6%
Taylor expanded in s around inf
/-lowering-/.f3291.5
Simplified91.5%
Final simplification66.4%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (- (/ (fabs x) s)))) (t_1 (+ t_0 1.0)))
(if (<= (/ t_0 (* t_1 (* s t_1))) 0.004999999888241291)
(/ s (* x x))
(/ 0.25 s))))
float code(float x, float s) {
float t_0 = expf(-(fabsf(x) / s));
float t_1 = t_0 + 1.0f;
float tmp;
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291f) {
tmp = s / (x * x);
} else {
tmp = 0.25f / 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) :: t_1
real(4) :: tmp
t_0 = exp(-(abs(x) / s))
t_1 = t_0 + 1.0e0
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291e0) then
tmp = s / (x * x)
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(-Float32(abs(x) / s))) t_1 = Float32(t_0 + Float32(1.0)) tmp = Float32(0.0) if (Float32(t_0 / Float32(t_1 * Float32(s * t_1))) <= Float32(0.004999999888241291)) tmp = Float32(s / Float32(x * x)); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) t_0 = exp(-(abs(x) / s)); t_1 = t_0 + single(1.0); tmp = single(0.0); if ((t_0 / (t_1 * (s * t_1))) <= single(0.004999999888241291)) tmp = s / (x * x); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\frac{\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 0.004999999888241291:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 0.00499999989Initial program 99.9%
associate-/r*N/A
clear-numN/A
associate-/l/N/A
associate-/r*N/A
flip3-+N/A
clear-numN/A
Applied egg-rr99.9%
Taylor expanded in s around inf
Simplified99.6%
Taylor expanded in s around inf
*-lowering-*.f32N/A
associate-+r+N/A
+-lowering-+.f32N/A
neg-mul-1N/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f32N/A
Simplified1.9%
Taylor expanded in s around 0
associate-*r/N/A
distribute-lft1-inN/A
metadata-evalN/A
times-fracN/A
metadata-evalN/A
*-lft-identityN/A
/-lowering-/.f32N/A
unpow2N/A
*-lowering-*.f3255.1
Simplified55.1%
if 0.00499999989 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) Initial program 99.6%
Taylor expanded in s around inf
/-lowering-/.f3291.5
Simplified91.5%
Final simplification64.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (- (/ (fabs x) s)))) (t_1 (+ t_0 1.0)))
(if (<= (/ t_0 (* t_1 (* s t_1))) 0.004999999888241291)
(/ 0.5 (fabs x))
(/ 0.25 s))))
float code(float x, float s) {
float t_0 = expf(-(fabsf(x) / s));
float t_1 = t_0 + 1.0f;
float tmp;
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291f) {
tmp = 0.5f / fabsf(x);
} else {
tmp = 0.25f / 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) :: t_1
real(4) :: tmp
t_0 = exp(-(abs(x) / s))
t_1 = t_0 + 1.0e0
if ((t_0 / (t_1 * (s * t_1))) <= 0.004999999888241291e0) then
tmp = 0.5e0 / abs(x)
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(-Float32(abs(x) / s))) t_1 = Float32(t_0 + Float32(1.0)) tmp = Float32(0.0) if (Float32(t_0 / Float32(t_1 * Float32(s * t_1))) <= Float32(0.004999999888241291)) tmp = Float32(Float32(0.5) / abs(x)); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) t_0 = exp(-(abs(x) / s)); t_1 = t_0 + single(1.0); tmp = single(0.0); if ((t_0 / (t_1 * (s * t_1))) <= single(0.004999999888241291)) tmp = single(0.5) / abs(x); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\frac{\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 0.004999999888241291:\\
\;\;\;\;\frac{0.5}{\left|x\right|}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 0.00499999989Initial program 99.9%
associate-/r*N/A
clear-numN/A
associate-/l/N/A
associate-/r*N/A
flip3-+N/A
clear-numN/A
Applied egg-rr99.9%
Taylor expanded in s around inf
Simplified99.6%
Taylor expanded in s around inf
distribute-lft-inN/A
distribute-rgt-outN/A
metadata-evalN/A
*-rgt-identityN/A
distribute-lft-inN/A
*-lowering-*.f32N/A
+-commutativeN/A
+-lowering-+.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f3240.0
Simplified40.0%
Taylor expanded in s around 0
fabs-lowering-fabs.f329.5
Simplified9.5%
if 0.00499999989 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) Initial program 99.6%
Taylor expanded in s around inf
/-lowering-/.f3291.5
Simplified91.5%
Final simplification30.9%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ (fabs x) s))) (/ -1.0 (* (fma s (exp t_0) s) (- -1.0 (exp (- t_0)))))))
float code(float x, float s) {
float t_0 = fabsf(x) / s;
return -1.0f / (fmaf(s, expf(t_0), s) * (-1.0f - expf(-t_0)));
}
function code(x, s) t_0 = Float32(abs(x) / s) return Float32(Float32(-1.0) / Float32(fma(s, exp(t_0), s) * Float32(Float32(-1.0) - exp(Float32(-t_0))))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left|x\right|}{s}\\
\frac{-1}{\mathsf{fma}\left(s, e^{t\_0}, s\right) \cdot \left(-1 - e^{-t\_0}\right)}
\end{array}
\end{array}
Initial program 99.8%
associate-/l/N/A
/-lowering-/.f32N/A
Applied egg-rr99.9%
Taylor expanded in x around 0
exp-negN/A
associate-/r*N/A
/-lowering-/.f32N/A
*-commutativeN/A
associate-*l*N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*r*N/A
Simplified99.9%
Final simplification99.9%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ (fabs x) s))) (/ (* (exp (- t_0)) (pow (- 2.0 t_0) -2.0)) s)))
float code(float x, float s) {
float t_0 = fabsf(x) / s;
return (expf(-t_0) * powf((2.0f - t_0), -2.0f)) / s;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = abs(x) / s
code = (exp(-t_0) * ((2.0e0 - t_0) ** (-2.0e0))) / s
end function
function code(x, s) t_0 = Float32(abs(x) / s) return Float32(Float32(exp(Float32(-t_0)) * (Float32(Float32(2.0) - t_0) ^ Float32(-2.0))) / s) end
function tmp = code(x, s) t_0 = abs(x) / s; tmp = (exp(-t_0) * ((single(2.0) - t_0) ^ single(-2.0))) / s; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left|x\right|}{s}\\
\frac{e^{-t\_0} \cdot {\left(2 - t\_0\right)}^{-2}}{s}
\end{array}
\end{array}
Initial program 99.8%
Applied egg-rr99.8%
Taylor expanded in s around inf
neg-mul-1N/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f3297.3
Simplified97.3%
Final simplification97.3%
(FPCore (x s) :precision binary32 (* 0.5 (/ 1.0 (fma s (exp (/ (fabs x) s)) s))))
float code(float x, float s) {
return 0.5f * (1.0f / fmaf(s, expf((fabsf(x) / s)), s));
}
function code(x, s) return Float32(Float32(0.5) * Float32(Float32(1.0) / fma(s, exp(Float32(abs(x) / s)), s))) end
\begin{array}{l}
\\
0.5 \cdot \frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Initial program 99.8%
Taylor expanded in s around inf
Simplified96.4%
Taylor expanded in x around 0
associate-*r/N/A
neg-mul-1N/A
distribute-lft-inN/A
neg-mul-1N/A
*-rgt-identityN/A
associate-*r/N/A
*-lowering-*.f32N/A
exp-negN/A
associate-/l/N/A
Simplified96.5%
(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.8%
Taylor expanded in s around inf
*-commutativeN/A
*-lowering-*.f3296.2
Simplified96.2%
Final simplification96.2%
(FPCore (x s)
:precision binary32
(if (<= (fabs x) 4.999999969612645e-9)
(/
1.0
(*
s
(+
(fma x (/ x (* s s)) (/ (* (fabs x) 2.0) s))
(fma (fabs x) (/ -2.0 s) 4.0))))
(/
0.5
(*
s
(-
(/
(-
(fabs x)
(/
(fma
(* x x)
-0.5
(/ (fma (* (fabs x) 0.16666666666666666) (* x x) 0.0) (- s)))
s))
s)
-2.0)))))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 4.999999969612645e-9f) {
tmp = 1.0f / (s * (fmaf(x, (x / (s * s)), ((fabsf(x) * 2.0f) / s)) + fmaf(fabsf(x), (-2.0f / s), 4.0f)));
} else {
tmp = 0.5f / (s * (((fabsf(x) - (fmaf((x * x), -0.5f, (fmaf((fabsf(x) * 0.16666666666666666f), (x * x), 0.0f) / -s)) / s)) / s) - -2.0f));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(4.999999969612645e-9)) tmp = Float32(Float32(1.0) / Float32(s * Float32(fma(x, Float32(x / Float32(s * s)), Float32(Float32(abs(x) * Float32(2.0)) / s)) + fma(abs(x), Float32(Float32(-2.0) / s), Float32(4.0))))); else tmp = Float32(Float32(0.5) / Float32(s * Float32(Float32(Float32(abs(x) - Float32(fma(Float32(x * x), Float32(-0.5), Float32(fma(Float32(abs(x) * Float32(0.16666666666666666)), Float32(x * x), Float32(0.0)) / Float32(-s))) / s)) / s) - Float32(-2.0)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;\frac{1}{s \cdot \left(\mathsf{fma}\left(x, \frac{x}{s \cdot s}, \frac{\left|x\right| \cdot 2}{s}\right) + \mathsf{fma}\left(\left|x\right|, \frac{-2}{s}, 4\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{s \cdot \left(\frac{\left|x\right| - \frac{\mathsf{fma}\left(x \cdot x, -0.5, \frac{\mathsf{fma}\left(\left|x\right| \cdot 0.16666666666666666, x \cdot x, 0\right)}{-s}\right)}{s}}{s} - -2\right)}\\
\end{array}
\end{array}
if (fabs.f32 x) < 4.99999997e-9Initial program 99.6%
associate-/l/N/A
/-lowering-/.f32N/A
Applied egg-rr99.7%
Taylor expanded in x around 0
exp-negN/A
associate-/r*N/A
/-lowering-/.f32N/A
*-commutativeN/A
associate-*l*N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*r*N/A
Simplified99.6%
+-lowering-+.f32N/A
*-lowering-*.f32N/A
exp-lowering-exp.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f3299.8
Applied egg-rr99.8%
Taylor expanded in s around inf
Simplified78.6%
if 4.99999997e-9 < (fabs.f32 x) Initial program 100.0%
associate-/r*N/A
clear-numN/A
associate-/l/N/A
associate-/r*N/A
flip3-+N/A
clear-numN/A
Applied egg-rr100.0%
Taylor expanded in s around inf
Simplified100.0%
Taylor expanded in s around -inf
Simplified87.8%
Final simplification84.2%
(FPCore (x s) :precision binary32 (if (<= (fabs x) 1.2500000392179937e-23) (/ (fma (/ (* x -0.0625) s) (/ x s) 0.25) s) (/ -1.0 (* s (- -4.0 (/ (* x x) (* s s)))))))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 1.2500000392179937e-23f) {
tmp = fmaf(((x * -0.0625f) / s), (x / s), 0.25f) / s;
} else {
tmp = -1.0f / (s * (-4.0f - ((x * x) / (s * s))));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(1.2500000392179937e-23)) tmp = Float32(fma(Float32(Float32(x * Float32(-0.0625)) / s), Float32(x / s), Float32(0.25)) / s); else tmp = Float32(Float32(-1.0) / Float32(s * Float32(Float32(-4.0) - Float32(Float32(x * x) / Float32(s * s))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1.2500000392179937 \cdot 10^{-23}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x \cdot -0.0625}{s}, \frac{x}{s}, 0.25\right)}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{s \cdot \left(-4 - \frac{x \cdot x}{s \cdot s}\right)}\\
\end{array}
\end{array}
if (fabs.f32 x) < 1.25000004e-23Initial program 99.7%
Taylor expanded in s around inf
/-lowering-/.f32N/A
Simplified65.2%
+-commutativeN/A
associate-*l*N/A
*-commutativeN/A
times-fracN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-lowering-*.f32N/A
/-lowering-/.f3282.7
Applied egg-rr82.7%
if 1.25000004e-23 < (fabs.f32 x) Initial program 99.9%
associate-/l/N/A
/-lowering-/.f32N/A
Applied egg-rr99.9%
Taylor expanded in x around 0
exp-negN/A
associate-/r*N/A
/-lowering-/.f32N/A
*-commutativeN/A
associate-*l*N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*r*N/A
Simplified99.9%
+-lowering-+.f32N/A
*-lowering-*.f32N/A
exp-lowering-exp.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f3299.9
Applied egg-rr99.9%
Taylor expanded in s around -inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f32N/A
Simplified80.3%
Final simplification80.8%
(FPCore (x s) :precision binary32 (/ -1.0 (* s (- -4.0 (/ (* x x) (* s s))))))
float code(float x, float s) {
return -1.0f / (s * (-4.0f - ((x * x) / (s * s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (-1.0e0) / (s * ((-4.0e0) - ((x * x) / (s * s))))
end function
function code(x, s) return Float32(Float32(-1.0) / Float32(s * Float32(Float32(-4.0) - Float32(Float32(x * x) / Float32(s * s))))) end
function tmp = code(x, s) tmp = single(-1.0) / (s * (single(-4.0) - ((x * x) / (s * s)))); end
\begin{array}{l}
\\
\frac{-1}{s \cdot \left(-4 - \frac{x \cdot x}{s \cdot s}\right)}
\end{array}
Initial program 99.8%
associate-/l/N/A
/-lowering-/.f32N/A
Applied egg-rr99.9%
Taylor expanded in x around 0
exp-negN/A
associate-/r*N/A
/-lowering-/.f32N/A
*-commutativeN/A
associate-*l*N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*r*N/A
Simplified99.9%
+-lowering-+.f32N/A
*-lowering-*.f32N/A
exp-lowering-exp.f32N/A
/-lowering-/.f32N/A
fabs-lowering-fabs.f3299.9
Applied egg-rr99.9%
Taylor expanded in s around -inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f32N/A
Simplified77.6%
Final simplification77.6%
(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.8%
Taylor expanded in s around inf
/-lowering-/.f3227.3
Simplified27.3%
herbie shell --seed 2024199
(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))))))