
(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 13 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 (/ x s)))) (/ 1.0 (* s (+ t_0 (+ 2.0 (/ 1.0 t_0)))))))
float code(float x, float s) {
float t_0 = expf((x / s));
return 1.0f / (s * (t_0 + (2.0f + (1.0f / t_0))));
}
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 = 1.0e0 / (s * (t_0 + (2.0e0 + (1.0e0 / t_0))))
end function
function code(x, s) t_0 = exp(Float32(x / s)) return Float32(Float32(1.0) / Float32(s * Float32(t_0 + Float32(Float32(2.0) + Float32(Float32(1.0) / t_0))))) end
function tmp = code(x, s) t_0 = exp((x / s)); tmp = single(1.0) / (s * (t_0 + (single(2.0) + (single(1.0) / t_0)))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\frac{1}{s \cdot \left(t_0 + \left(2 + \frac{1}{t_0}\right)\right)}
\end{array}
\end{array}
Initial program 99.4%
Simplified99.2%
Applied egg-rr97.3%
expm1-def97.3%
expm1-log1p97.3%
+-commutative97.3%
Simplified97.3%
div-inv97.3%
exp-prod88.4%
add-sqr-sqrt88.4%
sqrt-unprod88.4%
sqr-neg88.4%
sqrt-unprod-0.0%
add-sqr-sqrt63.6%
exp-prod64.6%
div-inv64.6%
distribute-frac-neg64.6%
exp-neg64.6%
div-inv64.6%
exp-prod63.6%
Applied egg-rr99.2%
Taylor expanded in s around 0 99.6%
Final simplification99.6%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (exp (/ (- x) s)) (+ (exp (/ x s)) 2.0))))
float code(float x, float s) {
return (1.0f / s) / (expf((-x / s)) + (expf((x / s)) + 2.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (exp((-x / s)) + (exp((x / s)) + 2.0e0))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(exp(Float32(Float32(-x) / s)) + Float32(exp(Float32(x / s)) + Float32(2.0)))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (exp((-x / s)) + (exp((x / s)) + single(2.0))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{e^{\frac{-x}{s}} + \left(e^{\frac{x}{s}} + 2\right)}
\end{array}
Initial program 99.4%
Simplified99.2%
Applied egg-rr97.3%
expm1-def97.3%
expm1-log1p97.3%
+-commutative97.3%
Simplified97.3%
div-inv97.3%
exp-prod88.4%
add-sqr-sqrt88.4%
sqrt-unprod88.4%
sqr-neg88.4%
sqrt-unprod-0.0%
add-sqr-sqrt63.6%
exp-prod64.6%
div-inv64.6%
distribute-frac-neg64.6%
exp-neg64.6%
div-inv64.6%
exp-prod63.6%
Applied egg-rr99.2%
rec-exp99.2%
distribute-neg-frac99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x s) :precision binary32 (/ 1.0 (* s (+ 3.0 (exp (/ (fabs x) s))))))
float code(float x, float s) {
return 1.0f / (s * (3.0f + expf((fabsf(x) / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * (3.0e0 + exp((abs(x) / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(3.0) + exp(Float32(abs(x) / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * (single(3.0) + exp((abs(x) / s)))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(3 + e^{\frac{\left|x\right|}{s}}\right)}
\end{array}
Initial program 99.4%
Simplified99.2%
Applied egg-rr97.3%
expm1-def97.3%
expm1-log1p97.3%
+-commutative97.3%
Simplified97.3%
Taylor expanded in x around 0 96.5%
Final simplification96.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -5.999999821029131e-35)
(/ 1.0 (* s (+ 1.0 (+ 2.0 (/ 1.0 t_0)))))
(/ 1.0 (* s (+ t_0 3.0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -5.999999821029131e-35f) {
tmp = 1.0f / (s * (1.0f + (2.0f + (1.0f / t_0))));
} else {
tmp = 1.0f / (s * (t_0 + 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 = exp((x / s))
if (x <= (-5.999999821029131e-35)) then
tmp = 1.0e0 / (s * (1.0e0 + (2.0e0 + (1.0e0 / t_0))))
else
tmp = 1.0e0 / (s * (t_0 + 3.0e0))
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-5.999999821029131e-35)) tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(1.0) + Float32(Float32(2.0) + Float32(Float32(1.0) / t_0))))); else tmp = Float32(Float32(1.0) / Float32(s * Float32(t_0 + Float32(3.0)))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-5.999999821029131e-35)) tmp = single(1.0) / (s * (single(1.0) + (single(2.0) + (single(1.0) / t_0)))); else tmp = single(1.0) / (s * (t_0 + single(3.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -5.999999821029131 \cdot 10^{-35}:\\
\;\;\;\;\frac{1}{s \cdot \left(1 + \left(2 + \frac{1}{t_0}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(t_0 + 3\right)}\\
\end{array}
\end{array}
if x < -5.99999982e-35Initial program 99.1%
Simplified99.3%
Applied egg-rr99.2%
expm1-def99.2%
expm1-log1p99.3%
+-commutative99.3%
Simplified99.3%
div-inv99.3%
exp-prod78.0%
add-sqr-sqrt78.0%
sqrt-unprod78.0%
sqr-neg78.0%
sqrt-unprod-0.0%
add-sqr-sqrt22.6%
exp-prod22.4%
div-inv22.4%
distribute-frac-neg22.4%
exp-neg22.4%
div-inv22.4%
exp-prod22.6%
Applied egg-rr99.3%
Taylor expanded in s around 0 99.3%
Taylor expanded in x around 0 95.0%
if -5.99999982e-35 < x Initial program 99.7%
Simplified99.1%
Applied egg-rr95.8%
expm1-def95.8%
expm1-log1p95.8%
+-commutative95.8%
Simplified95.8%
div-inv95.8%
exp-prod96.9%
add-sqr-sqrt96.9%
sqrt-unprod96.9%
sqr-neg96.9%
sqrt-unprod-0.0%
add-sqr-sqrt96.9%
exp-prod99.1%
div-inv99.1%
distribute-frac-neg99.1%
exp-neg99.1%
div-inv99.1%
exp-prod96.9%
Applied egg-rr99.1%
Taylor expanded in s around 0 99.8%
Taylor expanded in x around 0 97.6%
Final simplification96.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -5.999999821029131e-35)
(/ (/ 1.0 s) (+ (/ 1.0 t_0) 3.0))
(/ 1.0 (* s (+ t_0 3.0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -5.999999821029131e-35f) {
tmp = (1.0f / s) / ((1.0f / t_0) + 3.0f);
} else {
tmp = 1.0f / (s * (t_0 + 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 = exp((x / s))
if (x <= (-5.999999821029131e-35)) then
tmp = (1.0e0 / s) / ((1.0e0 / t_0) + 3.0e0)
else
tmp = 1.0e0 / (s * (t_0 + 3.0e0))
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-5.999999821029131e-35)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(Float32(1.0) / t_0) + Float32(3.0))); else tmp = Float32(Float32(1.0) / Float32(s * Float32(t_0 + Float32(3.0)))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-5.999999821029131e-35)) tmp = (single(1.0) / s) / ((single(1.0) / t_0) + single(3.0)); else tmp = single(1.0) / (s * (t_0 + single(3.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -5.999999821029131 \cdot 10^{-35}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{1}{t_0} + 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(t_0 + 3\right)}\\
\end{array}
\end{array}
if x < -5.99999982e-35Initial program 99.1%
Simplified99.3%
Applied egg-rr99.2%
expm1-def99.2%
expm1-log1p99.3%
+-commutative99.3%
Simplified99.3%
div-inv99.3%
exp-prod78.0%
add-sqr-sqrt78.0%
sqrt-unprod78.0%
sqr-neg78.0%
sqrt-unprod-0.0%
add-sqr-sqrt22.6%
exp-prod22.4%
div-inv22.4%
distribute-frac-neg22.4%
exp-neg22.4%
div-inv22.4%
exp-prod22.6%
Applied egg-rr99.3%
Taylor expanded in x around 0 95.0%
if -5.99999982e-35 < x Initial program 99.7%
Simplified99.1%
Applied egg-rr95.8%
expm1-def95.8%
expm1-log1p95.8%
+-commutative95.8%
Simplified95.8%
div-inv95.8%
exp-prod96.9%
add-sqr-sqrt96.9%
sqrt-unprod96.9%
sqr-neg96.9%
sqrt-unprod-0.0%
add-sqr-sqrt96.9%
exp-prod99.1%
div-inv99.1%
distribute-frac-neg99.1%
exp-neg99.1%
div-inv99.1%
exp-prod96.9%
Applied egg-rr99.1%
Taylor expanded in s around 0 99.8%
Taylor expanded in x around 0 97.6%
Final simplification96.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -1.0000000031710769e-30)
(/ t_0 (* s 4.0))
(/ 1.0 (* s (+ t_0 3.0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -1.0000000031710769e-30f) {
tmp = t_0 / (s * 4.0f);
} else {
tmp = 1.0f / (s * (t_0 + 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 = exp((x / s))
if (x <= (-1.0000000031710769e-30)) then
tmp = t_0 / (s * 4.0e0)
else
tmp = 1.0e0 / (s * (t_0 + 3.0e0))
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-1.0000000031710769e-30)) tmp = Float32(t_0 / Float32(s * Float32(4.0))); else tmp = Float32(Float32(1.0) / Float32(s * Float32(t_0 + Float32(3.0)))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-1.0000000031710769e-30)) tmp = t_0 / (s * single(4.0)); else tmp = single(1.0) / (s * (t_0 + single(3.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -1.0000000031710769 \cdot 10^{-30}:\\
\;\;\;\;\frac{t_0}{s \cdot 4}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(t_0 + 3\right)}\\
\end{array}
\end{array}
if x < -1e-30Initial program 99.1%
expm1-log1p-u97.9%
expm1-udef95.9%
Applied egg-rr95.9%
expm1-def97.9%
expm1-log1p99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in x around 0 90.9%
if -1e-30 < x Initial program 99.6%
Simplified99.1%
Applied egg-rr95.9%
expm1-def95.9%
expm1-log1p95.9%
+-commutative95.9%
Simplified95.9%
div-inv95.9%
exp-prod96.5%
add-sqr-sqrt96.5%
sqrt-unprod96.5%
sqr-neg96.5%
sqrt-unprod-0.0%
add-sqr-sqrt96.5%
exp-prod98.5%
div-inv98.5%
distribute-frac-neg98.5%
exp-neg98.5%
div-inv98.5%
exp-prod96.5%
Applied egg-rr99.1%
Taylor expanded in s around 0 99.8%
Taylor expanded in x around 0 97.2%
Final simplification94.4%
(FPCore (x s) :precision binary32 (if (<= x -1.0000000031710769e-30) (/ (exp (/ x s)) (* s 4.0)) (/ 1.0 (+ (* s 4.0) (* x (/ x s))))))
float code(float x, float s) {
float tmp;
if (x <= -1.0000000031710769e-30f) {
tmp = expf((x / s)) / (s * 4.0f);
} else {
tmp = 1.0f / ((s * 4.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 <= (-1.0000000031710769e-30)) then
tmp = exp((x / s)) / (s * 4.0e0)
else
tmp = 1.0e0 / ((s * 4.0e0) + (x * (x / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.0000000031710769e-30)) tmp = Float32(exp(Float32(x / s)) / Float32(s * Float32(4.0))); else tmp = Float32(Float32(1.0) / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(x / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-1.0000000031710769e-30)) tmp = exp((x / s)) / (s * single(4.0)); else tmp = single(1.0) / ((s * single(4.0)) + (x * (x / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000031710769 \cdot 10^{-30}:\\
\;\;\;\;\frac{e^{\frac{x}{s}}}{s \cdot 4}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot 4 + x \cdot \frac{x}{s}}\\
\end{array}
\end{array}
if x < -1e-30Initial program 99.1%
expm1-log1p-u97.9%
expm1-udef95.9%
Applied egg-rr95.9%
expm1-def97.9%
expm1-log1p99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in x around 0 90.9%
if -1e-30 < x Initial program 99.6%
*-lft-identity99.6%
associate-*r/99.6%
associate-/l*99.7%
distribute-frac-neg99.7%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in s around inf 29.6%
Simplified29.6%
Taylor expanded in x around 0 72.1%
fma-def72.1%
unpow272.1%
Simplified72.1%
fma-udef72.1%
*-commutative72.1%
associate-/l*72.5%
div-inv72.5%
clear-num72.5%
Applied egg-rr72.5%
Final simplification80.4%
(FPCore (x s) :precision binary32 (if (or (<= x -0.0020000000949949026) (not (<= x 4.000000053405728e-10))) (/ 1.0 (* x (/ x s))) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -0.0020000000949949026f) || !(x <= 4.000000053405728e-10f)) {
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 <= (-0.0020000000949949026e0)) .or. (.not. (x <= 4.000000053405728e-10))) 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(-0.0020000000949949026)) || !(x <= Float32(4.000000053405728e-10))) 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(-0.0020000000949949026)) || ~((x <= single(4.000000053405728e-10)))) 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 -0.0020000000949949026 \lor \neg \left(x \leq 4.000000053405728 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -0.00200000009 or 4.00000005e-10 < 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 2.6%
Simplified2.6%
Taylor expanded in x around inf 2.6%
associate-*r/2.6%
unpow22.6%
associate-*r*2.6%
Simplified2.6%
Taylor expanded in x around 0 79.3%
unpow279.3%
associate-*r/79.3%
Simplified79.3%
if -0.00200000009 < x < 4.00000005e-10Initial program 98.9%
Taylor expanded in s around inf 53.4%
Final simplification67.8%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ 1.0 (* x (/ x s))) (if (<= x 4.000000053405728e-10) (/ 0.25 s) (/ 1.0 (/ x (/ s x))))))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
tmp = 1.0f / (x * (x / s));
} else if (x <= 4.000000053405728e-10f) {
tmp = 0.25f / s;
} else {
tmp = 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 = 1.0e0 / (x * (x / s))
else if (x <= 4.000000053405728e-10) then
tmp = 0.25e0 / s
else
tmp = 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(1.0) / Float32(x * Float32(x / s))); elseif (x <= Float32(4.000000053405728e-10)) tmp = Float32(Float32(0.25) / s); else tmp = 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(1.0) / (x * (x / s)); elseif (x <= single(4.000000053405728e-10)) tmp = single(0.25) / s; else tmp = single(1.0) / (x / (s / x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0020000000949949026:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\mathbf{elif}\;x \leq 4.000000053405728 \cdot 10^{-10}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{\frac{s}{x}}}\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-/l*99.7%
distribute-frac-neg99.7%
exp-neg99.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in s around inf 2.8%
Simplified2.8%
Taylor expanded in x around inf 2.8%
associate-*r/2.8%
unpow22.8%
associate-*r*2.8%
Simplified2.8%
Taylor expanded in x around 0 77.4%
unpow277.4%
associate-*r/77.4%
Simplified77.4%
if -0.00200000009 < x < 4.00000005e-10Initial program 98.9%
Taylor expanded in s around inf 53.4%
if 4.00000005e-10 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 2.4%
Simplified2.4%
Taylor expanded in x around inf 80.9%
unpow280.9%
associate-/l*80.9%
Simplified80.9%
Final simplification67.8%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ 1.0 (* x (/ x s))) (if (<= x 4.000000053405728e-10) (/ 0.25 s) (/ 1.0 (/ (* x x) s)))))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
tmp = 1.0f / (x * (x / s));
} else if (x <= 4.000000053405728e-10f) {
tmp = 0.25f / s;
} else {
tmp = 1.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 = 1.0e0 / (x * (x / s))
else if (x <= 4.000000053405728e-10) then
tmp = 0.25e0 / s
else
tmp = 1.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(1.0) / Float32(x * Float32(x / s))); elseif (x <= Float32(4.000000053405728e-10)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(1.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(1.0) / (x * (x / s)); elseif (x <= single(4.000000053405728e-10)) tmp = single(0.25) / s; else tmp = single(1.0) / ((x * x) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0020000000949949026:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\mathbf{elif}\;x \leq 4.000000053405728 \cdot 10^{-10}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x}{s}}\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-/l*99.7%
distribute-frac-neg99.7%
exp-neg99.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in s around inf 2.8%
Simplified2.8%
Taylor expanded in x around inf 2.8%
associate-*r/2.8%
unpow22.8%
associate-*r*2.8%
Simplified2.8%
Taylor expanded in x around 0 77.4%
unpow277.4%
associate-*r/77.4%
Simplified77.4%
if -0.00200000009 < x < 4.00000005e-10Initial program 98.9%
Taylor expanded in s around inf 53.4%
if 4.00000005e-10 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 2.4%
Simplified2.4%
Taylor expanded in x around inf 80.9%
unpow280.9%
Simplified80.9%
Final simplification67.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (* s 4.0) (* x (/ x s)))))
float code(float x, float s) {
return 1.0f / ((s * 4.0f) + (x * (x / 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)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(x / s)))) end
function tmp = code(x, s) tmp = single(1.0) / ((s * single(4.0)) + (x * (x / s))); end
\begin{array}{l}
\\
\frac{1}{s \cdot 4 + x \cdot \frac{x}{s}}
\end{array}
Initial program 99.4%
*-lft-identity99.4%
associate-*r/99.4%
associate-/l*99.4%
distribute-frac-neg99.4%
exp-neg99.3%
associate-/r/99.4%
/-rgt-identity99.4%
associate-*l*99.4%
Simplified99.5%
Taylor expanded in s around inf 26.0%
Simplified26.0%
Taylor expanded in x around 0 68.6%
fma-def68.6%
unpow268.6%
Simplified68.6%
fma-udef68.6%
*-commutative68.6%
associate-/l*69.0%
div-inv69.0%
clear-num69.0%
Applied egg-rr69.0%
Final simplification69.0%
(FPCore (x s) :precision binary32 (if (or (<= x -0.0020000000949949026) (not (<= x 4.000000053405728e-10))) (/ s (* x x)) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -0.0020000000949949026f) || !(x <= 4.000000053405728e-10f)) {
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 <= (-0.0020000000949949026e0)) .or. (.not. (x <= 4.000000053405728e-10))) 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(-0.0020000000949949026)) || !(x <= Float32(4.000000053405728e-10))) 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(-0.0020000000949949026)) || ~((x <= single(4.000000053405728e-10)))) 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 -0.0020000000949949026 \lor \neg \left(x \leq 4.000000053405728 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{s}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -0.00200000009 or 4.00000005e-10 < 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 2.6%
Simplified2.6%
Taylor expanded in x around inf 77.5%
unpow277.5%
associate-/r*77.1%
Simplified77.1%
Taylor expanded in s around 0 77.5%
unpow277.5%
Simplified77.5%
if -0.00200000009 < x < 4.00000005e-10Initial program 98.9%
Taylor expanded in s around inf 53.4%
Final simplification66.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.4%
Taylor expanded in s around inf 26.3%
Final simplification26.3%
herbie shell --seed 2023188
(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))))))