
(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 12 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 (* s (+ (+ 2.0 (exp (/ (fabs x) s))) (exp (/ (- (fabs x)) s))))))
float code(float x, float s) {
return 1.0f / (s * ((2.0f + expf((fabsf(x) / s))) + expf((-fabsf(x) / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * ((2.0e0 + exp((abs(x) / s))) + exp((-abs(x) / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(2.0) + exp(Float32(abs(x) / s))) + exp(Float32(Float32(-abs(x)) / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * ((single(2.0) + exp((abs(x) / s))) + exp((-abs(x) / s)))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(\left(2 + e^{\frac{\left|x\right|}{s}}\right) + e^{\frac{-\left|x\right|}{s}}\right)}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*r/99.6%
associate-*l*99.6%
times-frac99.6%
associate-*r/99.6%
associate-/l*99.6%
distribute-frac-neg99.6%
exp-neg99.6%
Simplified99.7%
Taylor expanded in s around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
distribute-frac-neg99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ (exp (fma -2.0 (log 2.0) (* (/ x s) (/ (* x -0.25) s)))) s))
float code(float x, float s) {
return expf(fmaf(-2.0f, logf(2.0f), ((x / s) * ((x * -0.25f) / s)))) / s;
}
function code(x, s) return Float32(exp(fma(Float32(-2.0), log(Float32(2.0)), Float32(Float32(x / s) * Float32(Float32(x * Float32(-0.25)) / s)))) / s) end
\begin{array}{l}
\\
\frac{e^{\mathsf{fma}\left(-2, \log 2, \frac{x}{s} \cdot \frac{x \cdot -0.25}{s}\right)}}{s}
\end{array}
Initial program 99.6%
associate-*l*99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
add-exp-log98.0%
log-div98.0%
add-log-exp98.0%
*-commutative98.0%
log-prod97.8%
Applied egg-rr97.8%
associate--r+97.8%
exp-diff98.0%
Simplified99.7%
Taylor expanded in s around inf 56.5%
+-commutative56.5%
mul-1-neg56.5%
distribute-frac-neg56.5%
Simplified90.5%
Taylor expanded in x around 0 90.5%
unpow290.5%
associate-*r/90.5%
*-commutative90.5%
associate-*l*90.5%
unpow290.5%
times-frac95.9%
Simplified95.9%
Final simplification95.9%
(FPCore (x s) :precision binary32 (/ 1.0 (* 2.0 (fma s (exp (/ (fabs x) s)) s))))
float code(float x, float s) {
return 1.0f / (2.0f * fmaf(s, expf((fabsf(x) / s)), s));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(2.0) * fma(s, exp(Float32(abs(x) / s)), s))) end
\begin{array}{l}
\\
\frac{1}{2 \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*r/99.6%
associate-/l*99.6%
distribute-frac-neg99.6%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
associate-*l*99.6%
Simplified99.6%
Taylor expanded in s around inf 94.3%
Final simplification94.3%
(FPCore (x s) :precision binary32 (if (<= (fabs x) 4.999999841327613e-21) (/ 1.0 (fma s 4.0 (* x (/ x s)))) (/ (exp (/ (- (fabs x)) s)) s)))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 4.999999841327613e-21f) {
tmp = 1.0f / fmaf(s, 4.0f, (x * (x / s)));
} else {
tmp = expf((-fabsf(x) / s)) / s;
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(4.999999841327613e-21)) tmp = Float32(Float32(1.0) / fma(s, Float32(4.0), Float32(x * Float32(x / s)))); else tmp = Float32(exp(Float32(Float32(-abs(x)) / s)) / s); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 4.999999841327613 \cdot 10^{-21}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(s, 4, x \cdot \frac{x}{s}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\
\end{array}
\end{array}
if (fabs.f32 x) < 4.99999984e-21Initial program 99.1%
*-lft-identity99.1%
associate-*r/99.1%
associate-*l*99.0%
times-frac99.1%
associate-*r/99.3%
associate-/l*99.0%
distribute-frac-neg99.0%
exp-neg99.0%
Simplified99.3%
Taylor expanded in s around 0 99.4%
+-commutative99.4%
mul-1-neg99.4%
distribute-frac-neg99.4%
Simplified99.4%
Taylor expanded in s around inf 76.7%
associate-+r+76.7%
distribute-lft1-in76.7%
metadata-eval76.7%
mul0-lft76.7%
unpow276.7%
sqr-abs76.7%
unpow276.7%
remove-double-neg76.7%
mul-1-neg76.7%
*-commutative76.7%
metadata-eval76.7%
distribute-rgt-out--76.7%
neg-mul-176.7%
associate-*r/76.7%
associate-*r/76.7%
Simplified78.7%
if 4.99999984e-21 < (fabs.f32 x) Initial program 99.7%
associate-*l*99.7%
+-commutative99.7%
+-commutative99.7%
Simplified99.7%
add-exp-log99.4%
log-div99.4%
add-log-exp99.4%
*-commutative99.4%
log-prod99.4%
Applied egg-rr99.4%
associate--r+99.4%
exp-diff99.5%
Simplified99.8%
Taylor expanded in s around 0 94.9%
mul-1-neg94.9%
distribute-frac-neg94.9%
Simplified94.9%
Final simplification91.5%
(FPCore (x s) :precision binary32 (if (<= s 4.999999999099794e-24) (/ (exp (/ (- (fabs x)) s)) s) (/ (exp (+ (* -2.0 (log 2.0)) (/ -0.25 (/ (* s s) (* x x))))) s)))
float code(float x, float s) {
float tmp;
if (s <= 4.999999999099794e-24f) {
tmp = expf((-fabsf(x) / s)) / s;
} else {
tmp = expf(((-2.0f * logf(2.0f)) + (-0.25f / ((s * s) / (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 (s <= 4.999999999099794e-24) then
tmp = exp((-abs(x) / s)) / s
else
tmp = exp((((-2.0e0) * log(2.0e0)) + ((-0.25e0) / ((s * s) / (x * x))))) / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (s <= Float32(4.999999999099794e-24)) tmp = Float32(exp(Float32(Float32(-abs(x)) / s)) / s); else tmp = Float32(exp(Float32(Float32(Float32(-2.0) * log(Float32(2.0))) + Float32(Float32(-0.25) / Float32(Float32(s * s) / Float32(x * x))))) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (s <= single(4.999999999099794e-24)) tmp = exp((-abs(x) / s)) / s; else tmp = exp(((single(-2.0) * log(single(2.0))) + (single(-0.25) / ((s * s) / (x * x))))) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 4.999999999099794 \cdot 10^{-24}:\\
\;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{-2 \cdot \log 2 + \frac{-0.25}{\frac{s \cdot s}{x \cdot x}}}}{s}\\
\end{array}
\end{array}
if s < 5e-24Initial program 99.7%
associate-*l*99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
add-exp-log98.6%
log-div98.6%
add-log-exp98.6%
*-commutative98.6%
log-prod98.4%
Applied egg-rr98.4%
associate--r+98.4%
exp-diff98.6%
Simplified99.7%
Taylor expanded in s around 0 93.0%
mul-1-neg93.0%
distribute-frac-neg93.0%
Simplified93.0%
if 5e-24 < s Initial program 99.5%
associate-*l*99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
add-exp-log97.6%
log-div97.6%
add-log-exp97.6%
*-commutative97.6%
log-prod97.4%
Applied egg-rr97.4%
associate--r+97.4%
exp-diff97.6%
Simplified99.7%
Taylor expanded in s around inf 67.9%
+-commutative67.9%
mul-1-neg67.9%
distribute-frac-neg67.9%
Simplified96.5%
fma-udef96.5%
associate-/l*96.5%
Applied egg-rr96.5%
Final simplification95.1%
(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(Float32(1.0) / 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{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*r/99.6%
associate-*l*99.6%
times-frac99.6%
associate-*r/99.6%
associate-/l*99.6%
distribute-frac-neg99.6%
exp-neg99.6%
Simplified99.7%
Taylor expanded in s around inf 51.3%
associate-+r+51.3%
distribute-lft1-in51.3%
metadata-eval51.3%
mul0-lft79.4%
associate-+r+79.4%
unpow279.4%
sqr-abs79.4%
unpow279.4%
metadata-eval79.4%
Simplified79.4%
Final simplification79.4%
(FPCore (x s) :precision binary32 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001))) (/ 1.0 (* x (/ x s))) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
tmp = 1.0f / (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) :: tmp
if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
tmp = 1.0e0 / (x * (x / s))
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001))) tmp = Float32(Float32(1.0) / Float32(x * Float32(x / s))); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001)))) tmp = single(1.0) / (x * (x / s)); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000006e-8 or 7.9999998e-4 < x Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-/l*99.9%
distribute-frac-neg99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in s around inf 4.6%
associate-+r+4.6%
distribute-rgt-out4.6%
metadata-eval4.6%
associate-+r+4.6%
mul-1-neg4.6%
unsub-neg4.6%
fma-def4.6%
unpow24.6%
sqr-abs4.6%
*-commutative4.6%
unpow24.6%
sqr-abs4.6%
Simplified4.6%
Taylor expanded in x around inf 4.4%
unpow24.4%
associate-/l*4.4%
associate-/r/4.4%
Simplified4.4%
*-un-lft-identity4.4%
mul0-rgt4.4%
associate-+r-4.4%
associate-*r*4.4%
associate-*l/4.4%
*-commutative4.4%
Applied egg-rr4.4%
*-lft-identity4.4%
+-lft-identity4.4%
*-lft-identity4.4%
associate-*l*4.4%
*-commutative4.4%
distribute-rgt-out--71.9%
metadata-eval71.9%
*-rgt-identity71.9%
Simplified71.9%
if -5.00000006e-8 < x < 7.9999998e-4Initial program 99.1%
*-lft-identity99.1%
associate-*r/99.1%
associate-*l*99.0%
times-frac99.0%
associate-*r/99.2%
associate-/l*99.0%
distribute-frac-neg99.0%
exp-neg99.1%
Simplified99.3%
Taylor expanded in s around inf 52.2%
Final simplification64.2%
(FPCore (x s) :precision binary32 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001))) (/ 1.0 (/ x (/ s x))) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
tmp = 1.0f / (x / (s / 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) :: tmp
if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
tmp = 1.0e0 / (x / (s / x))
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001))) tmp = Float32(Float32(1.0) / Float32(x / Float32(s / x))); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001)))) tmp = single(1.0) / (x / (s / x)); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{1}{\frac{x}{\frac{s}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000006e-8 or 7.9999998e-4 < x Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-/l*99.9%
distribute-frac-neg99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in s around inf 4.6%
associate-+r+4.6%
distribute-rgt-out4.6%
metadata-eval4.6%
associate-+r+4.6%
mul-1-neg4.6%
unsub-neg4.6%
fma-def4.6%
unpow24.6%
sqr-abs4.6%
*-commutative4.6%
unpow24.6%
sqr-abs4.6%
Simplified4.6%
Taylor expanded in x around inf 70.1%
unpow270.1%
Simplified70.1%
div-inv70.1%
Applied egg-rr70.1%
div-inv70.1%
associate-/r*70.1%
clear-num71.9%
Applied egg-rr71.9%
if -5.00000006e-8 < x < 7.9999998e-4Initial program 99.1%
*-lft-identity99.1%
associate-*r/99.1%
associate-*l*99.0%
times-frac99.0%
associate-*r/99.2%
associate-/l*99.0%
distribute-frac-neg99.0%
exp-neg99.1%
Simplified99.3%
Taylor expanded in s around inf 52.2%
Final simplification64.2%
(FPCore (x s) :precision binary32 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001))) (/ 1.0 (/ (* x x) s)) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
tmp = 1.0f / ((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) :: tmp
if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
tmp = 1.0e0 / ((x * x) / s)
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001))) tmp = Float32(Float32(1.0) / Float32(Float32(x * x) / s)); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001)))) tmp = single(1.0) / ((x * x) / s); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{1}{\frac{x \cdot x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000006e-8 or 7.9999998e-4 < x Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-/l*99.9%
distribute-frac-neg99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in s around inf 4.6%
associate-+r+4.6%
distribute-rgt-out4.6%
metadata-eval4.6%
associate-+r+4.6%
mul-1-neg4.6%
unsub-neg4.6%
fma-def4.6%
unpow24.6%
sqr-abs4.6%
*-commutative4.6%
unpow24.6%
sqr-abs4.6%
Simplified4.6%
Taylor expanded in x around inf 70.1%
unpow270.1%
Simplified70.1%
div-inv70.1%
Applied egg-rr70.1%
div-inv70.1%
clear-num71.9%
Applied egg-rr71.9%
if -5.00000006e-8 < x < 7.9999998e-4Initial program 99.1%
*-lft-identity99.1%
associate-*r/99.1%
associate-*l*99.0%
times-frac99.0%
associate-*r/99.2%
associate-/l*99.0%
distribute-frac-neg99.0%
exp-neg99.1%
Simplified99.3%
Taylor expanded in s around inf 52.2%
Final simplification64.2%
(FPCore (x s) :precision binary32 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001))) (/ s (* x x)) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
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) :: tmp
if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
tmp = s / (x * x)
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001))) tmp = Float32(s / Float32(x * x)); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001)))) tmp = s / (x * x); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{s}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000006e-8 or 7.9999998e-4 < x Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-/l*99.9%
distribute-frac-neg99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in s around inf 4.6%
associate-+r+4.6%
distribute-rgt-out4.6%
metadata-eval4.6%
associate-+r+4.6%
mul-1-neg4.6%
unsub-neg4.6%
fma-def4.6%
unpow24.6%
sqr-abs4.6%
*-commutative4.6%
unpow24.6%
sqr-abs4.6%
Simplified4.6%
Taylor expanded in x around inf 70.1%
unpow270.1%
Simplified70.1%
if -5.00000006e-8 < x < 7.9999998e-4Initial program 99.1%
*-lft-identity99.1%
associate-*r/99.1%
associate-*l*99.0%
times-frac99.0%
associate-*r/99.2%
associate-/l*99.0%
distribute-frac-neg99.0%
exp-neg99.1%
Simplified99.3%
Taylor expanded in s around inf 52.2%
Final simplification63.1%
(FPCore (x s) :precision binary32 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001))) (/ (/ s x) x) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
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) :: tmp
if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
tmp = (s / x) / x
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001))) tmp = Float32(Float32(s / x) / x); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001)))) tmp = (s / x) / x; else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{\frac{s}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000006e-8 or 7.9999998e-4 < x Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-/l*99.9%
distribute-frac-neg99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in s around inf 4.6%
associate-+r+4.6%
distribute-rgt-out4.6%
metadata-eval4.6%
associate-+r+4.6%
mul-1-neg4.6%
unsub-neg4.6%
fma-def4.6%
unpow24.6%
sqr-abs4.6%
*-commutative4.6%
unpow24.6%
sqr-abs4.6%
Simplified4.6%
Taylor expanded in x around inf 70.1%
unpow270.1%
Simplified70.1%
div-inv70.1%
Applied egg-rr70.1%
div-inv70.1%
associate-/r*70.1%
Applied egg-rr70.1%
if -5.00000006e-8 < x < 7.9999998e-4Initial program 99.1%
*-lft-identity99.1%
associate-*r/99.1%
associate-*l*99.0%
times-frac99.0%
associate-*r/99.2%
associate-/l*99.0%
distribute-frac-neg99.0%
exp-neg99.1%
Simplified99.3%
Taylor expanded in s around inf 52.2%
Final simplification63.1%
(FPCore (x s) :precision binary32 (/ 0.25 s))
float code(float x, float s) {
return 0.25f / s;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.25e0 / s
end function
function code(x, s) return Float32(Float32(0.25) / s) end
function tmp = code(x, s) tmp = single(0.25) / s; end
\begin{array}{l}
\\
\frac{0.25}{s}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*r/99.6%
associate-*l*99.6%
times-frac99.6%
associate-*r/99.6%
associate-/l*99.6%
distribute-frac-neg99.6%
exp-neg99.6%
Simplified99.7%
Taylor expanded in s around inf 23.4%
Final simplification23.4%
herbie shell --seed 2023187
(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))))))