
(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 11 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 (/ (/ 1.0 (+ 2.0 (* 2.0 (cosh (/ (fabs x) s))))) s))
float code(float x, float s) {
return (1.0f / (2.0f + (2.0f * coshf((fabsf(x) / s))))) / s;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / (2.0e0 + (2.0e0 * cosh((abs(x) / s))))) / s
end function
function code(x, s) return Float32(Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(2.0) * cosh(Float32(abs(x) / s))))) / s) end
function tmp = code(x, s) tmp = (single(1.0) / (single(2.0) + (single(2.0) * cosh((abs(x) / s))))) / s; end
\begin{array}{l}
\\
\frac{\frac{1}{2 + 2 \cdot \cosh \left(\frac{\left|x\right|}{s}\right)}}{s}
\end{array}
Initial program 99.7%
Simplified0
Applied egg-rr0
(FPCore (x s) :precision binary32 (/ 1.0 (* s (+ 2.0 (* (cosh (/ (fabs x) s)) 2.0)))))
float code(float x, float s) {
return 1.0f / (s * (2.0f + (coshf((fabsf(x) / s)) * 2.0f)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * (2.0e0 + (cosh((abs(x) / s)) * 2.0e0)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(2.0) + Float32(cosh(Float32(abs(x) / s)) * Float32(2.0))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * (single(2.0) + (cosh((abs(x) / s)) * single(2.0)))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(2 + \cosh \left(\frac{\left|x\right|}{s}\right) \cdot 2\right)}
\end{array}
Initial program 99.7%
Simplified0
Applied egg-rr0
Applied egg-rr0
(FPCore (x s) :precision binary32 (/ (/ 0.25 (exp (/ (fabs x) s))) s))
float code(float x, float s) {
return (0.25f / expf((fabsf(x) / s))) / s;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (0.25e0 / exp((abs(x) / s))) / s
end function
function code(x, s) return Float32(Float32(Float32(0.25) / exp(Float32(abs(x) / s))) / s) end
function tmp = code(x, s) tmp = (single(0.25) / exp((abs(x) / s))) / s; end
\begin{array}{l}
\\
\frac{\frac{0.25}{e^{\frac{\left|x\right|}{s}}}}{s}
\end{array}
Initial program 99.7%
Taylor expanded in s around inf 0
Simplified0
Taylor expanded in x around 0 0
Simplified0
(FPCore (x s) :precision binary32 (if (<= x 7.99999999855967e-23) (/ (+ 0.25 (/ -0.0625 (/ (/ s x) (/ x s)))) s) (/ (/ 1.0 (+ (/ (* x x) (* s s)) 4.0)) s)))
float code(float x, float s) {
float tmp;
if (x <= 7.99999999855967e-23f) {
tmp = (0.25f + (-0.0625f / ((s / x) / (x / s)))) / s;
} else {
tmp = (1.0f / (((x * x) / (s * s)) + 4.0f)) / s;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 7.99999999855967e-23) then
tmp = (0.25e0 + ((-0.0625e0) / ((s / x) / (x / s)))) / s
else
tmp = (1.0e0 / (((x * x) / (s * s)) + 4.0e0)) / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(7.99999999855967e-23)) tmp = Float32(Float32(Float32(0.25) + Float32(Float32(-0.0625) / Float32(Float32(s / x) / Float32(x / s)))) / s); else tmp = Float32(Float32(Float32(1.0) / Float32(Float32(Float32(x * x) / Float32(s * s)) + Float32(4.0))) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(7.99999999855967e-23)) tmp = (single(0.25) + (single(-0.0625) / ((s / x) / (x / s)))) / s; else tmp = (single(1.0) / (((x * x) / (s * s)) + single(4.0))) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.99999999855967 \cdot 10^{-23}:\\
\;\;\;\;\frac{0.25 + \frac{-0.0625}{\frac{\frac{s}{x}}{\frac{x}{s}}}}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{x \cdot x}{s \cdot s} + 4}}{s}\\
\end{array}
\end{array}
if x < 8e-23Initial program 99.6%
Taylor expanded in s around inf 0
Simplified0
Applied egg-rr0
if 8e-23 < x Initial program 99.8%
Simplified0
Applied egg-rr0
Taylor expanded in s around inf 0
Simplified0
(FPCore (x s) :precision binary32 (if (<= x 0.0020000000949949026) (/ 0.25 s) (/ 1.0 (/ (* 3.0 (* x x)) s))))
float code(float x, float s) {
float tmp;
if (x <= 0.0020000000949949026f) {
tmp = 0.25f / s;
} else {
tmp = 1.0f / ((3.0f * (x * x)) / s);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 0.0020000000949949026e0) then
tmp = 0.25e0 / s
else
tmp = 1.0e0 / ((3.0e0 * (x * x)) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.0020000000949949026)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(3.0) * Float32(x * x)) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.0020000000949949026)) tmp = single(0.25) / s; else tmp = single(1.0) / ((single(3.0) * (x * x)) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0020000000949949026:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{3 \cdot \left(x \cdot x\right)}{s}}\\
\end{array}
\end{array}
if x < 0.00200000009Initial program 99.6%
Taylor expanded in s around inf 0
Simplified0
if 0.00200000009 < x Initial program 100.0%
Taylor expanded in s around -inf 0
Simplified0
Taylor expanded in s around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
(FPCore (x s) :precision binary32 (if (<= x 0.0020000000949949026) (/ 0.25 s) (/ 1.0 (* 3.0 (/ (* x x) s)))))
float code(float x, float s) {
float tmp;
if (x <= 0.0020000000949949026f) {
tmp = 0.25f / s;
} else {
tmp = 1.0f / (3.0f * ((x * x) / s));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 0.0020000000949949026e0) then
tmp = 0.25e0 / s
else
tmp = 1.0e0 / (3.0e0 * ((x * x) / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.0020000000949949026)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(1.0) / Float32(Float32(3.0) * Float32(Float32(x * x) / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.0020000000949949026)) tmp = single(0.25) / s; else tmp = single(1.0) / (single(3.0) * ((x * x) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0020000000949949026:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{3 \cdot \frac{x \cdot x}{s}}\\
\end{array}
\end{array}
if x < 0.00200000009Initial program 99.6%
Taylor expanded in s around inf 0
Simplified0
if 0.00200000009 < x Initial program 100.0%
Taylor expanded in s around -inf 0
Simplified0
Taylor expanded in s around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
(FPCore (x s) :precision binary32 (if (<= x 0.0020000000949949026) (/ 0.25 s) (* 0.3333333333333333 (/ 1.0 (/ x (/ s x))))))
float code(float x, float s) {
float tmp;
if (x <= 0.0020000000949949026f) {
tmp = 0.25f / s;
} else {
tmp = 0.3333333333333333f * (1.0f / (x / (s / 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.0020000000949949026e0) then
tmp = 0.25e0 / s
else
tmp = 0.3333333333333333e0 * (1.0e0 / (x / (s / x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.0020000000949949026)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(0.3333333333333333) * Float32(Float32(1.0) / Float32(x / Float32(s / x)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.0020000000949949026)) tmp = single(0.25) / s; else tmp = single(0.3333333333333333) * (single(1.0) / (x / (s / x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0020000000949949026:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;0.3333333333333333 \cdot \frac{1}{\frac{x}{\frac{s}{x}}}\\
\end{array}
\end{array}
if x < 0.00200000009Initial program 99.6%
Taylor expanded in s around inf 0
Simplified0
if 0.00200000009 < x Initial program 100.0%
Taylor expanded in s around -inf 0
Simplified0
Taylor expanded in s around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
Applied egg-rr0
(FPCore (x s) :precision binary32 (/ 1.0 (* s (+ (/ (/ (* x x) s) s) 4.0))))
float code(float x, float s) {
return 1.0f / (s * ((((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 / (s * ((((x * x) / s) / s) + 4.0e0))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(Float32(x * x) / s) / s) + Float32(4.0)))) end
function tmp = code(x, s) tmp = single(1.0) / (s * ((((x * x) / s) / s) + single(4.0))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(\frac{\frac{x \cdot x}{s}}{s} + 4\right)}
\end{array}
Initial program 99.7%
Simplified0
Applied egg-rr0
Applied egg-rr0
Taylor expanded in s around inf 0
Simplified0
(FPCore (x s) :precision binary32 (if (<= x 0.0020000000949949026) (/ 0.25 s) (/ 0.3333333333333333 (/ (* x x) s))))
float code(float x, float s) {
float tmp;
if (x <= 0.0020000000949949026f) {
tmp = 0.25f / s;
} else {
tmp = 0.3333333333333333f / ((x * x) / s);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 0.0020000000949949026e0) then
tmp = 0.25e0 / s
else
tmp = 0.3333333333333333e0 / ((x * x) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.0020000000949949026)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(0.3333333333333333) / Float32(Float32(x * x) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.0020000000949949026)) tmp = single(0.25) / s; else tmp = single(0.3333333333333333) / ((x * x) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0020000000949949026:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333}{\frac{x \cdot x}{s}}\\
\end{array}
\end{array}
if x < 0.00200000009Initial program 99.6%
Taylor expanded in s around inf 0
Simplified0
if 0.00200000009 < x Initial program 100.0%
Taylor expanded in s around -inf 0
Simplified0
Taylor expanded in s around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
Applied egg-rr0
(FPCore (x s) :precision binary32 (if (<= x 0.0020000000949949026) (/ 0.25 s) (* 0.3333333333333333 (/ s (* x x)))))
float code(float x, float s) {
float tmp;
if (x <= 0.0020000000949949026f) {
tmp = 0.25f / s;
} else {
tmp = 0.3333333333333333f * (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.0020000000949949026e0) then
tmp = 0.25e0 / s
else
tmp = 0.3333333333333333e0 * (s / (x * x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.0020000000949949026)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(0.3333333333333333) * Float32(s / Float32(x * x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.0020000000949949026)) tmp = single(0.25) / s; else tmp = single(0.3333333333333333) * (s / (x * x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0020000000949949026:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;0.3333333333333333 \cdot \frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.00200000009Initial program 99.6%
Taylor expanded in s around inf 0
Simplified0
if 0.00200000009 < x Initial program 100.0%
Taylor expanded in s around -inf 0
Simplified0
Taylor expanded in s around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
(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.7%
Taylor expanded in s around inf 0
Simplified0
herbie shell --seed 2024111
(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))))))