
(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 (exp (- (/ (fabs x) s))))) (/ (/ t_0 (+ t_0 1.0)) (fma s t_0 s))))
float code(float x, float s) {
float t_0 = expf(-(fabsf(x) / s));
return (t_0 / (t_0 + 1.0f)) / fmaf(s, t_0, s);
}
function code(x, s) t_0 = exp(Float32(-Float32(abs(x) / s))) return Float32(Float32(t_0 / Float32(t_0 + Float32(1.0))) / fma(s, t_0, s)) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\frac{\left|x\right|}{s}}\\
\frac{\frac{t\_0}{t\_0 + 1}}{\mathsf{fma}\left(s, t\_0, s\right)}
\end{array}
\end{array}
Initial program 99.8%
lift-fabs.f32N/A
remove-double-negN/A
lift-neg.f32N/A
remove-double-negN/A
frac-2negN/A
frac-2negN/A
lift-/.f32N/A
lift-exp.f32N/A
Applied egg-rr99.8%
Final simplification99.8%
(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.0)
(/ 0.5 (/ (fma s (fma s 2.0 (fabs x)) (* 0.5 (* x x))) s))
(/ (fma (/ x s) (/ (* x -0.0625) 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.0f) {
tmp = 0.5f / (fmaf(s, fmaf(s, 2.0f, fabsf(x)), (0.5f * (x * x))) / s);
} else {
tmp = fmaf((x / s), ((x * -0.0625f) / 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.0)) tmp = Float32(Float32(0.5) / Float32(fma(s, fma(s, Float32(2.0), abs(x)), Float32(Float32(0.5) * Float32(x * x))) / s)); else tmp = Float32(fma(Float32(x / s), Float32(Float32(x * Float32(-0.0625)) / 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:\\
\;\;\;\;\frac{0.5}{\frac{\mathsf{fma}\left(s, \mathsf{fma}\left(s, 2, \left|x\right|\right), 0.5 \cdot \left(x \cdot x\right)\right)}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{s}, \frac{x \cdot -0.0625}{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.0Initial program 100.0%
Taylor expanded in s around inf
Simplified100.0%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr100.0%
Taylor expanded in s around -inf
Simplified73.7%
Taylor expanded in s around 0
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-fabs.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3263.1
Simplified63.1%
if 0.0 < (/.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.2%
Taylor expanded in s around inf
lower-/.f32N/A
Simplified70.9%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
+-commutativeN/A
lift-/.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
times-fracN/A
lower-fma.f32N/A
lower-/.f32N/A
lower-/.f32N/A
lower-*.f3291.9
Applied egg-rr91.9%
Final simplification70.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.0)
(/ 0.5 (/ (fma x (* x 0.5) (* (fabs x) s)) s))
(/ (fma (/ x s) (/ (* x -0.0625) 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.0f) {
tmp = 0.5f / (fmaf(x, (x * 0.5f), (fabsf(x) * s)) / s);
} else {
tmp = fmaf((x / s), ((x * -0.0625f) / 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.0)) tmp = Float32(Float32(0.5) / Float32(fma(x, Float32(x * Float32(0.5)), Float32(abs(x) * s)) / s)); else tmp = Float32(fma(Float32(x / s), Float32(Float32(x * Float32(-0.0625)) / 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:\\
\;\;\;\;\frac{0.5}{\frac{\mathsf{fma}\left(x, x \cdot 0.5, \left|x\right| \cdot s\right)}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{s}, \frac{x \cdot -0.0625}{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.0Initial program 100.0%
Taylor expanded in s around inf
Simplified100.0%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr100.0%
Taylor expanded in s around -inf
Simplified73.7%
Taylor expanded in s around 0
lower-/.f32N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f32N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-fabs.f3263.1
Simplified63.1%
if 0.0 < (/.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.2%
Taylor expanded in s around inf
lower-/.f32N/A
Simplified70.9%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
+-commutativeN/A
lift-/.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
times-fracN/A
lower-fma.f32N/A
lower-/.f32N/A
lower-/.f32N/A
lower-*.f3291.9
Applied egg-rr91.9%
Final simplification70.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.0)
(/ 0.5 (/ (fma x (* x 0.5) (* (fabs x) s)) 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.0f) {
tmp = 0.5f / (fmaf(x, (x * 0.5f), (fabsf(x) * s)) / 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.0)) tmp = Float32(Float32(0.5) / Float32(fma(x, Float32(x * Float32(0.5)), Float32(abs(x) * s)) / 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:\\
\;\;\;\;\frac{0.5}{\frac{\mathsf{fma}\left(x, x \cdot 0.5, \left|x\right| \cdot s\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.0Initial program 100.0%
Taylor expanded in s around inf
Simplified100.0%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr100.0%
Taylor expanded in s around -inf
Simplified73.7%
Taylor expanded in s around 0
lower-/.f32N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f32N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-fabs.f3263.1
Simplified63.1%
if 0.0 < (/.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.2%
Taylor expanded in s around inf
lower-/.f3289.3
Simplified89.3%
Final simplification70.2%
(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.0)
(/ 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.0f) {
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.0e0) 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.0)) 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.0)) 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:\\
\;\;\;\;\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.0Initial program 100.0%
Taylor expanded in s around inf
Simplified100.0%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr100.0%
Taylor expanded in s around -inf
Simplified73.7%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3263.1
Simplified63.1%
if 0.0 < (/.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.2%
Taylor expanded in s around inf
lower-/.f3289.3
Simplified89.3%
Final simplification70.2%
(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.0) (/ 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.0f) {
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.0e0) 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.0)) 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.0)) 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:\\
\;\;\;\;\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.0Initial program 100.0%
Taylor expanded in s around inf
Simplified100.0%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr100.0%
Taylor expanded in s around -inf
Simplified73.7%
Taylor expanded in x around inf
lower-/.f32N/A
unpow2N/A
lower-*.f3260.4
Simplified60.4%
if 0.0 < (/.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.2%
Taylor expanded in s around inf
lower-/.f3289.3
Simplified89.3%
Final simplification68.2%
(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.0) (/ 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.0f) {
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.0e0) 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.0)) 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.0)) 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:\\
\;\;\;\;\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.0Initial program 100.0%
Taylor expanded in s around inf
Simplified100.0%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr100.0%
Taylor expanded in s around inf
lower-*.f32N/A
distribute-rgt-outN/A
metadata-evalN/A
*-rgt-identityN/A
lower-+.f32N/A
lower-/.f32N/A
lower-fabs.f3242.9
Simplified42.9%
Taylor expanded in s around 0
lower-fabs.f329.9
Simplified9.9%
if 0.0 < (/.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.2%
Taylor expanded in s around inf
lower-/.f3289.3
Simplified89.3%
Final simplification31.3%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (- (/ (fabs x) s))))) (/ t_0 (* (fma t_0 s s) (+ t_0 1.0)))))
float code(float x, float s) {
float t_0 = expf(-(fabsf(x) / s));
return t_0 / (fmaf(t_0, s, s) * (t_0 + 1.0f));
}
function code(x, s) t_0 = exp(Float32(-Float32(abs(x) / s))) return Float32(t_0 / Float32(fma(t_0, s, s) * Float32(t_0 + Float32(1.0)))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-\frac{\left|x\right|}{s}}\\
\frac{t\_0}{\mathsf{fma}\left(t\_0, s, s\right) \cdot \left(t\_0 + 1\right)}
\end{array}
\end{array}
Initial program 99.8%
lift-fabs.f32N/A
remove-double-negN/A
lift-neg.f32N/A
remove-double-negN/A
frac-2negN/A
frac-2negN/A
lift-/.f32N/A
lift-exp.f32N/A
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
lower-fma.f3299.8
lift-/.f32N/A
lift-neg.f32N/A
distribute-frac-negN/A
lower-neg.f32N/A
lower-/.f3299.8
Applied egg-rr99.8%
Final simplification99.8%
(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%
lift-fabs.f32N/A
remove-double-negN/A
lift-neg.f32N/A
remove-double-negN/A
frac-2negN/A
frac-2negN/A
lift-/.f32N/A
lift-exp.f32N/A
Applied egg-rr99.8%
lift-fabs.f32N/A
lift-/.f32N/A
lift-neg.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-/.f32N/A
lift-neg.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
Applied egg-rr99.8%
Taylor expanded in x around 0
+-commutativeN/A
exp-sumN/A
*-commutativeN/A
neg-mul-1N/A
exp-to-powN/A
neg-mul-1N/A
neg-mul-1N/A
Simplified99.8%
Taylor expanded in s around 0
lower-/.f32N/A
associate-*r*N/A
distribute-rgt-inN/A
*-lft-identityN/A
associate-*l*N/A
*-commutativeN/A
distribute-rgt-inN/A
lower-*.f32N/A
Simplified99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (* (+ (exp (/ (fabs x) s)) 1.0) 2.0)))
float code(float x, float s) {
return (1.0f / s) / ((expf((fabsf(x) / s)) + 1.0f) * 2.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / ((exp((abs(x) / s)) + 1.0e0) * 2.0e0)
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(exp(Float32(abs(x) / s)) + Float32(1.0)) * Float32(2.0))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / ((exp((abs(x) / s)) + single(1.0)) * single(2.0)); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{\left(e^{\frac{\left|x\right|}{s}} + 1\right) \cdot 2}
\end{array}
Initial program 99.8%
lift-fabs.f32N/A
remove-double-negN/A
lift-neg.f32N/A
remove-double-negN/A
frac-2negN/A
frac-2negN/A
lift-/.f32N/A
lift-exp.f32N/A
Applied egg-rr99.8%
lift-fabs.f32N/A
lift-/.f32N/A
lift-neg.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-/.f32N/A
lift-neg.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
Applied egg-rr99.8%
Taylor expanded in x around 0
+-commutativeN/A
exp-sumN/A
*-commutativeN/A
neg-mul-1N/A
exp-to-powN/A
neg-mul-1N/A
neg-mul-1N/A
Simplified99.8%
Taylor expanded in s around inf
Simplified95.4%
Final simplification95.4%
(FPCore (x s) :precision binary32 (/ 0.5 (fma s (exp (/ (fabs x) s)) s)))
float code(float x, float s) {
return 0.5f / fmaf(s, expf((fabsf(x) / s)), s);
}
function code(x, s) return Float32(Float32(0.5) / fma(s, exp(Float32(abs(x) / s)), s)) end
\begin{array}{l}
\\
\frac{0.5}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Initial program 99.8%
Taylor expanded in s around inf
Simplified95.4%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr95.4%
Taylor expanded in s around 0
distribute-rgt-inN/A
exp-negN/A
lft-mult-inverseN/A
*-lft-identityN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f32N/A
lower-exp.f32N/A
lower-/.f32N/A
lower-fabs.f3295.4
Simplified95.4%
(FPCore (x s)
:precision binary32
(if (<= (fabs x) 2.0000000390829628e-24)
(/ (fma (/ x s) (/ (* x -0.0625) s) 0.25) s)
(if (<= (fabs x) 0.05000000074505806)
(/ 0.5 (* s (- (- -2.0) (* (* x x) (/ -0.5 (* s s))))))
(/
0.5
(*
s
(-
(/
(+
(fabs x)
(/
(-
(/ (fma (* x (* x (fabs x))) 0.16666666666666666 0.0) s)
(* (* x x) -0.5))
s))
s)
-2.0))))))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 2.0000000390829628e-24f) {
tmp = fmaf((x / s), ((x * -0.0625f) / s), 0.25f) / s;
} else if (fabsf(x) <= 0.05000000074505806f) {
tmp = 0.5f / (s * (-(-2.0f) - ((x * x) * (-0.5f / (s * s)))));
} else {
tmp = 0.5f / (s * (((fabsf(x) + (((fmaf((x * (x * fabsf(x))), 0.16666666666666666f, 0.0f) / s) - ((x * x) * -0.5f)) / s)) / s) - -2.0f));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(2.0000000390829628e-24)) tmp = Float32(fma(Float32(x / s), Float32(Float32(x * Float32(-0.0625)) / s), Float32(0.25)) / s); elseif (abs(x) <= Float32(0.05000000074505806)) tmp = Float32(Float32(0.5) / Float32(s * Float32(Float32(-Float32(-2.0)) - Float32(Float32(x * x) * Float32(Float32(-0.5) / Float32(s * s)))))); else tmp = Float32(Float32(0.5) / Float32(s * Float32(Float32(Float32(abs(x) + Float32(Float32(Float32(fma(Float32(x * Float32(x * abs(x))), Float32(0.16666666666666666), Float32(0.0)) / s) - Float32(Float32(x * x) * Float32(-0.5))) / s)) / s) - Float32(-2.0)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 2.0000000390829628 \cdot 10^{-24}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{s}, \frac{x \cdot -0.0625}{s}, 0.25\right)}{s}\\
\mathbf{elif}\;\left|x\right| \leq 0.05000000074505806:\\
\;\;\;\;\frac{0.5}{s \cdot \left(\left(--2\right) - \left(x \cdot x\right) \cdot \frac{-0.5}{s \cdot s}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{s \cdot \left(\frac{\left|x\right| + \frac{\frac{\mathsf{fma}\left(x \cdot \left(x \cdot \left|x\right|\right), 0.16666666666666666, 0\right)}{s} - \left(x \cdot x\right) \cdot -0.5}{s}}{s} - -2\right)}\\
\end{array}
\end{array}
if (fabs.f32 x) < 2.00000004e-24Initial program 99.3%
Taylor expanded in s around inf
lower-/.f32N/A
Simplified48.1%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
+-commutativeN/A
lift-/.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
times-fracN/A
lower-fma.f32N/A
lower-/.f32N/A
lower-/.f32N/A
lower-*.f3275.4
Applied egg-rr75.4%
if 2.00000004e-24 < (fabs.f32 x) < 0.0500000007Initial program 99.7%
Taylor expanded in s around inf
Simplified92.8%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr92.8%
Taylor expanded in s around -inf
Simplified52.1%
Taylor expanded in x around inf
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-*r/N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f32N/A
unpow2N/A
lower-*.f3284.3
Simplified84.3%
if 0.0500000007 < (fabs.f32 x) Initial program 100.0%
Taylor expanded in s around inf
Simplified100.0%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr100.0%
Taylor expanded in s around -inf
Simplified94.2%
Final simplification88.0%
(FPCore (x s) :precision binary32 (if (<= (- (fabs x)) -1.9999999996399175e-23) (/ 0.5 (* s (- (- -2.0) (* (* x x) (/ -0.5 (* s s)))))) (/ (fma (/ x s) (/ (* x -0.0625) s) 0.25) s)))
float code(float x, float s) {
float tmp;
if (-fabsf(x) <= -1.9999999996399175e-23f) {
tmp = 0.5f / (s * (-(-2.0f) - ((x * x) * (-0.5f / (s * s)))));
} else {
tmp = fmaf((x / s), ((x * -0.0625f) / s), 0.25f) / s;
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-abs(x)) <= Float32(-1.9999999996399175e-23)) tmp = Float32(Float32(0.5) / Float32(s * Float32(Float32(-Float32(-2.0)) - Float32(Float32(x * x) * Float32(Float32(-0.5) / Float32(s * s)))))); else tmp = Float32(fma(Float32(x / s), Float32(Float32(x * Float32(-0.0625)) / s), Float32(0.25)) / s); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\left|x\right| \leq -1.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;\frac{0.5}{s \cdot \left(\left(--2\right) - \left(x \cdot x\right) \cdot \frac{-0.5}{s \cdot s}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{s}, \frac{x \cdot -0.0625}{s}, 0.25\right)}{s}\\
\end{array}
\end{array}
if (neg.f32 (fabs.f32 x)) < -2e-23Initial program 99.9%
Taylor expanded in s around inf
Simplified97.8%
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-/.f32N/A
lift-exp.f32N/A
lift-+.f32N/A
lift-*.f32N/A
associate-/r*N/A
div-invN/A
Applied egg-rr97.9%
Taylor expanded in s around -inf
Simplified77.6%
Taylor expanded in x around inf
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-*r/N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f32N/A
unpow2N/A
lower-*.f3287.3
Simplified87.3%
if -2e-23 < (neg.f32 (fabs.f32 x)) Initial program 99.3%
Taylor expanded in s around inf
lower-/.f32N/A
Simplified49.0%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
+-commutativeN/A
lift-/.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
times-fracN/A
lower-fma.f32N/A
lower-/.f32N/A
lower-/.f32N/A
lower-*.f3275.9
Applied egg-rr75.9%
Final simplification84.8%
(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
lower-/.f3227.3
Simplified27.3%
herbie shell --seed 2024219
(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))))))