
(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 16 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 (* (+ 1.0 (exp (/ (fabs x) (- s)))) (fma s (exp (/ (fabs x) s)) s))))
float code(float x, float s) {
return 1.0f / ((1.0f + expf((fabsf(x) / -s))) * fmaf(s, expf((fabsf(x) / s)), s));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(abs(x) / Float32(-s)))) * fma(s, exp(Float32(abs(x) / s)), s))) end
\begin{array}{l}
\\
\frac{1}{\left(1 + e^{\frac{\left|x\right|}{-s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*r/98.8%
associate-/l*98.8%
distribute-frac-neg98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
associate-*l*98.8%
Simplified98.9%
Final simplification98.9%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x s)))) (/ 1.0 (* (+ 1.0 (/ 1.0 t_0)) (+ s (* s t_0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
return 1.0f / ((1.0f + (1.0f / t_0)) * (s + (s * 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 / ((1.0e0 + (1.0e0 / t_0)) * (s + (s * t_0)))
end function
function code(x, s) t_0 = exp(Float32(x / s)) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + Float32(Float32(1.0) / t_0)) * Float32(s + Float32(s * t_0)))) end
function tmp = code(x, s) t_0 = exp((x / s)); tmp = single(1.0) / ((single(1.0) + (single(1.0) / t_0)) * (s + (s * t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\frac{1}{\left(1 + \frac{1}{t_0}\right) \cdot \left(s + s \cdot t_0\right)}
\end{array}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*r/98.8%
associate-/l*98.8%
distribute-frac-neg98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
associate-*l*98.8%
Simplified98.9%
fma-udef98.9%
Applied egg-rr62.1%
*-un-lft-identity62.1%
neg-mul-162.1%
times-frac62.1%
metadata-eval62.1%
metadata-eval62.1%
times-frac62.1%
neg-mul-162.1%
*-un-lft-identity62.1%
distribute-frac-neg62.1%
exp-neg62.1%
div-inv62.1%
exp-prod59.4%
add-sqr-sqrt59.4%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod-0.0%
add-sqr-sqrt85.1%
exp-prod94.5%
div-inv94.5%
neg-mul-194.5%
*-un-lft-identity94.5%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (x s) :precision binary32 (/ 1.0 (* (+ s (* s (exp (/ x s)))) (+ 1.0 (exp (/ (- x) s))))))
float code(float x, float s) {
return 1.0f / ((s + (s * expf((x / s)))) * (1.0f + expf((-x / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((s + (s * exp((x / s)))) * (1.0e0 + exp((-x / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(s + Float32(s * exp(Float32(x / s)))) * Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))))) end
function tmp = code(x, s) tmp = single(1.0) / ((s + (s * exp((x / s)))) * (single(1.0) + exp((-x / s)))); end
\begin{array}{l}
\\
\frac{1}{\left(s + s \cdot e^{\frac{x}{s}}\right) \cdot \left(1 + e^{\frac{-x}{s}}\right)}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*r/98.8%
associate-/l*98.8%
distribute-frac-neg98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
associate-*l*98.8%
Simplified98.9%
fma-udef98.9%
Applied egg-rr62.1%
*-un-lft-identity62.1%
neg-mul-162.1%
times-frac62.1%
metadata-eval62.1%
metadata-eval62.1%
times-frac62.1%
neg-mul-162.1%
*-un-lft-identity62.1%
distribute-frac-neg62.1%
exp-neg62.1%
div-inv62.1%
exp-prod59.4%
add-sqr-sqrt59.4%
sqrt-unprod59.4%
sqr-neg59.4%
sqrt-unprod-0.0%
add-sqr-sqrt85.1%
exp-prod94.5%
div-inv94.5%
neg-mul-194.5%
*-un-lft-identity94.5%
Applied egg-rr98.9%
rec-exp98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (exp (/ (fabs x) s)) 3.0)))
float code(float x, float s) {
return (1.0f / s) / (expf((fabsf(x) / s)) + 3.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)) + 3.0e0)
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(exp(Float32(abs(x) / s)) + Float32(3.0))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (exp((abs(x) / s)) + single(3.0)); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + 3}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*r/98.8%
associate-*l*98.9%
times-frac98.4%
associate-*r/98.5%
associate-/l*98.4%
distribute-frac-neg98.4%
exp-neg98.4%
Simplified98.5%
Taylor expanded in s around inf 94.5%
Final simplification94.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 98.8%
associate-*l*98.9%
+-commutative98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in s around inf 92.2%
Final simplification92.2%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x 4.0000000126843074e-29)
(* (/ 1.0 s) (/ t_0 (+ 4.0 (* (/ x s) 4.0))))
(/ 1.0 (* (+ s (* s t_0)) 2.0)))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= 4.0000000126843074e-29f) {
tmp = (1.0f / s) * (t_0 / (4.0f + ((x / s) * 4.0f)));
} else {
tmp = 1.0f / ((s + (s * t_0)) * 2.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 <= 4.0000000126843074e-29) then
tmp = (1.0e0 / s) * (t_0 / (4.0e0 + ((x / s) * 4.0e0)))
else
tmp = 1.0e0 / ((s + (s * t_0)) * 2.0e0)
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(4.0000000126843074e-29)) tmp = Float32(Float32(Float32(1.0) / s) * Float32(t_0 / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(4.0))))); else tmp = Float32(Float32(1.0) / Float32(Float32(s + Float32(s * t_0)) * Float32(2.0))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(4.0000000126843074e-29)) tmp = (single(1.0) / s) * (t_0 / (single(4.0) + ((x / s) * single(4.0)))); else tmp = single(1.0) / ((s + (s * t_0)) * single(2.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq 4.0000000126843074 \cdot 10^{-29}:\\
\;\;\;\;\frac{1}{s} \cdot \frac{t_0}{4 + \frac{x}{s} \cdot 4}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(s + s \cdot t_0\right) \cdot 2}\\
\end{array}
\end{array}
if x < 4.00000001e-29Initial program 98.4%
associate-*l*98.5%
+-commutative98.5%
+-commutative98.5%
Simplified98.5%
*-un-lft-identity98.5%
times-frac98.4%
Applied egg-rr98.3%
Taylor expanded in x around 0 93.5%
if 4.00000001e-29 < x Initial program 99.4%
*-lft-identity99.4%
associate-*r/99.4%
associate-/l*99.4%
distribute-frac-neg99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
associate-*l*99.4%
Simplified99.5%
fma-udef99.5%
Applied egg-rr99.5%
Taylor expanded in s around inf 92.7%
Final simplification93.1%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -9.999999796611898e-32)
(* (/ t_0 s) 0.25)
(/ (/ 1.0 s) (+ 2.0 (* t_0 2.0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -9.999999796611898e-32f) {
tmp = (t_0 / s) * 0.25f;
} else {
tmp = (1.0f / s) / (2.0f + (t_0 * 2.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 <= (-9.999999796611898e-32)) then
tmp = (t_0 / s) * 0.25e0
else
tmp = (1.0e0 / s) / (2.0e0 + (t_0 * 2.0e0))
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-9.999999796611898e-32)) tmp = Float32(Float32(t_0 / s) * Float32(0.25)); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(2.0) + Float32(t_0 * Float32(2.0)))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-9.999999796611898e-32)) tmp = (t_0 / s) * single(0.25); else tmp = (single(1.0) / s) / (single(2.0) + (t_0 * single(2.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -9.999999796611898 \cdot 10^{-32}:\\
\;\;\;\;\frac{t_0}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{2 + t_0 \cdot 2}\\
\end{array}
\end{array}
if x < -9.9999998e-32Initial program 98.2%
associate-*l*98.2%
+-commutative98.2%
+-commutative98.2%
Simplified98.2%
add-sqr-sqrt98.1%
Applied egg-rr98.0%
unpow298.0%
Simplified98.0%
div-inv98.0%
unpow-prod-down98.0%
pow298.0%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
Taylor expanded in x around 0 92.5%
if -9.9999998e-32 < x Initial program 99.4%
*-lft-identity99.4%
associate-*r/99.4%
associate-*l*99.4%
times-frac98.7%
associate-*r/98.7%
associate-/l*98.7%
distribute-frac-neg98.7%
exp-neg98.7%
Simplified98.8%
expm1-log1p-u96.3%
expm1-udef95.1%
Applied egg-rr90.6%
expm1-def90.9%
expm1-log1p92.4%
associate-/r*92.4%
*-lft-identity92.4%
associate-*l/91.6%
associate-*r/91.6%
*-rgt-identity91.6%
+-commutative91.6%
+-commutative91.6%
associate-+l+91.6%
count-291.6%
Simplified91.6%
Final simplification92.0%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -9.999999796611898e-32)
(* (/ t_0 s) 0.25)
(/ 1.0 (* (+ s (* s t_0)) 2.0)))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -9.999999796611898e-32f) {
tmp = (t_0 / s) * 0.25f;
} else {
tmp = 1.0f / ((s + (s * t_0)) * 2.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 <= (-9.999999796611898e-32)) then
tmp = (t_0 / s) * 0.25e0
else
tmp = 1.0e0 / ((s + (s * t_0)) * 2.0e0)
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-9.999999796611898e-32)) tmp = Float32(Float32(t_0 / s) * Float32(0.25)); else tmp = Float32(Float32(1.0) / Float32(Float32(s + Float32(s * t_0)) * Float32(2.0))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-9.999999796611898e-32)) tmp = (t_0 / s) * single(0.25); else tmp = single(1.0) / ((s + (s * t_0)) * single(2.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -9.999999796611898 \cdot 10^{-32}:\\
\;\;\;\;\frac{t_0}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(s + s \cdot t_0\right) \cdot 2}\\
\end{array}
\end{array}
if x < -9.9999998e-32Initial program 98.2%
associate-*l*98.2%
+-commutative98.2%
+-commutative98.2%
Simplified98.2%
add-sqr-sqrt98.1%
Applied egg-rr98.0%
unpow298.0%
Simplified98.0%
div-inv98.0%
unpow-prod-down98.0%
pow298.0%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
Taylor expanded in x around 0 92.5%
if -9.9999998e-32 < x Initial program 99.4%
*-lft-identity99.4%
associate-*r/99.4%
associate-/l*99.4%
distribute-frac-neg99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
associate-*l*99.4%
Simplified99.5%
fma-udef99.5%
Applied egg-rr99.5%
Taylor expanded in s around inf 92.3%
Final simplification92.4%
(FPCore (x s) :precision binary32 (if (<= x -9.999999796611898e-32) (* (/ (exp (/ x s)) s) 0.25) (/ 1.0 (fma x (/ x s) (* s 4.0)))))
float code(float x, float s) {
float tmp;
if (x <= -9.999999796611898e-32f) {
tmp = (expf((x / s)) / s) * 0.25f;
} else {
tmp = 1.0f / fmaf(x, (x / s), (s * 4.0f));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999796611898e-32)) tmp = Float32(Float32(exp(Float32(x / s)) / s) * Float32(0.25)); else tmp = Float32(Float32(1.0) / fma(x, Float32(x / s), Float32(s * Float32(4.0)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999796611898 \cdot 10^{-32}:\\
\;\;\;\;\frac{e^{\frac{x}{s}}}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}\\
\end{array}
\end{array}
if x < -9.9999998e-32Initial program 98.2%
associate-*l*98.2%
+-commutative98.2%
+-commutative98.2%
Simplified98.2%
add-sqr-sqrt98.1%
Applied egg-rr98.0%
unpow298.0%
Simplified98.0%
div-inv98.0%
unpow-prod-down98.0%
pow298.0%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
Taylor expanded in x around 0 92.5%
if -9.9999998e-32 < x Initial program 99.4%
*-lft-identity99.4%
associate-*r/99.4%
associate-/l*99.4%
distribute-frac-neg99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
associate-*l*99.4%
Simplified99.5%
Taylor expanded in s around inf 34.9%
associate-+r+34.9%
distribute-rgt-out34.9%
metadata-eval34.9%
associate-+r+34.9%
mul-1-neg34.9%
unsub-neg34.9%
fma-def34.9%
unpow234.9%
sqr-abs34.9%
*-commutative34.9%
unpow234.9%
sqr-abs34.9%
Simplified34.9%
fma-udef34.9%
associate-/l*35.0%
Applied egg-rr35.0%
*-un-lft-identity35.0%
mul0-rgt35.0%
+-commutative35.0%
fma-def35.0%
div-inv35.0%
clear-num35.0%
associate-/l*35.6%
div-inv35.6%
clear-num35.6%
Applied egg-rr35.6%
*-lft-identity35.6%
+-rgt-identity35.6%
fma-udef35.6%
associate-*r/34.7%
unpow234.7%
*-commutative34.7%
+-commutative34.7%
associate-*r/34.9%
unpow234.9%
associate--l+34.9%
unpow234.9%
associate-*r/34.7%
unpow234.7%
associate-*r/35.6%
*-lft-identity35.6%
distribute-rgt-out--72.9%
metadata-eval72.9%
Simplified72.9%
Final simplification82.0%
(FPCore (x s) :precision binary32 (if (<= x 0.0015999999595806003) (* (/ (exp (/ x s)) s) 0.25) (/ 1.0 (* x (/ x s)))))
float code(float x, float s) {
float tmp;
if (x <= 0.0015999999595806003f) {
tmp = (expf((x / s)) / s) * 0.25f;
} 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.0015999999595806003e0) then
tmp = (exp((x / s)) / s) * 0.25e0
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.0015999999595806003)) tmp = Float32(Float32(exp(Float32(x / s)) / s) * Float32(0.25)); else tmp = Float32(Float32(1.0) / Float32(x * Float32(x / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.0015999999595806003)) tmp = (exp((x / s)) / s) * single(0.25); else tmp = single(1.0) / (x * (x / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0015999999595806003:\\
\;\;\;\;\frac{e^{\frac{x}{s}}}{s} \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\end{array}
\end{array}
if x < 0.00159999996Initial program 98.4%
associate-*l*98.5%
+-commutative98.5%
+-commutative98.5%
Simplified98.5%
add-sqr-sqrt98.1%
Applied egg-rr88.9%
unpow288.9%
Simplified88.9%
div-inv88.9%
unpow-prod-down88.5%
pow288.5%
add-sqr-sqrt88.8%
Applied egg-rr88.8%
Taylor expanded in x around 0 80.8%
if 0.00159999996 < 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 3.5%
associate-+r+3.5%
distribute-rgt-out3.5%
metadata-eval3.5%
associate-+r+3.5%
mul-1-neg3.5%
unsub-neg3.5%
fma-def3.5%
unpow23.5%
sqr-abs3.5%
*-commutative3.5%
unpow23.5%
sqr-abs3.5%
Simplified3.5%
expm1-log1p-u3.5%
expm1-udef22.6%
mul0-rgt22.6%
associate-+r-22.6%
associate-/l*22.6%
associate-/l*22.6%
Applied egg-rr22.6%
expm1-def3.5%
expm1-log1p3.5%
/-rgt-identity3.5%
/-rgt-identity3.5%
+-lft-identity3.5%
fma-def3.5%
+-commutative3.5%
fma-def3.5%
associate-/r/3.5%
associate-/r/3.5%
Simplified3.5%
Taylor expanded in s around 0 32.3%
sub-neg32.3%
mul-1-neg32.3%
distribute-rgt-out77.3%
metadata-eval77.3%
*-rgt-identity77.3%
unpow277.3%
associate-*r/77.3%
Simplified77.3%
Final simplification79.9%
(FPCore (x s)
:precision binary32
(let* ((t_0 (* x (/ x s))))
(if (or (<= x -5000000000.0) (not (<= x 10.0)))
(/ 1.0 t_0)
(/ 1.0 (- (+ (* s 4.0) (* 2.0 t_0)) t_0)))))
float code(float x, float s) {
float t_0 = x * (x / s);
float tmp;
if ((x <= -5000000000.0f) || !(x <= 10.0f)) {
tmp = 1.0f / t_0;
} else {
tmp = 1.0f / (((s * 4.0f) + (2.0f * t_0)) - t_0);
}
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 = x * (x / s)
if ((x <= (-5000000000.0e0)) .or. (.not. (x <= 10.0e0))) then
tmp = 1.0e0 / t_0
else
tmp = 1.0e0 / (((s * 4.0e0) + (2.0e0 * t_0)) - t_0)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(x * Float32(x / s)) tmp = Float32(0.0) if ((x <= Float32(-5000000000.0)) || !(x <= Float32(10.0))) tmp = Float32(Float32(1.0) / t_0); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(s * Float32(4.0)) + Float32(Float32(2.0) * t_0)) - t_0)); end return tmp end
function tmp_2 = code(x, s) t_0 = x * (x / s); tmp = single(0.0); if ((x <= single(-5000000000.0)) || ~((x <= single(10.0)))) tmp = single(1.0) / t_0; else tmp = single(1.0) / (((s * single(4.0)) + (single(2.0) * t_0)) - t_0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{x}{s}\\
\mathbf{if}\;x \leq -5000000000 \lor \neg \left(x \leq 10\right):\\
\;\;\;\;\frac{1}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(s \cdot 4 + 2 \cdot t_0\right) - t_0}\\
\end{array}
\end{array}
if x < -5e9 or 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.1%
associate-+r+2.1%
distribute-rgt-out2.1%
metadata-eval2.1%
associate-+r+2.1%
mul-1-neg2.1%
unsub-neg2.1%
fma-def2.1%
unpow22.1%
sqr-abs2.1%
*-commutative2.1%
unpow22.1%
sqr-abs2.1%
Simplified2.1%
expm1-log1p-u2.1%
expm1-udef16.5%
mul0-rgt16.5%
associate-+r-16.5%
associate-/l*16.5%
associate-/l*16.5%
Applied egg-rr16.5%
expm1-def2.1%
expm1-log1p2.1%
/-rgt-identity2.1%
/-rgt-identity2.1%
+-lft-identity2.1%
fma-def2.1%
+-commutative2.1%
fma-def2.1%
associate-/r/2.1%
associate-/r/2.1%
Simplified2.1%
Taylor expanded in s around 0 31.7%
sub-neg31.7%
mul-1-neg31.7%
distribute-rgt-out85.6%
metadata-eval85.6%
*-rgt-identity85.6%
unpow285.6%
associate-*r/85.6%
Simplified85.6%
if -5e9 < x < 10Initial program 97.9%
*-lft-identity97.9%
associate-*r/97.9%
associate-/l*97.8%
distribute-frac-neg97.8%
exp-neg97.8%
associate-/r/97.8%
/-rgt-identity97.8%
associate-*l*97.8%
Simplified98.0%
Taylor expanded in s around inf 50.4%
associate-+r+50.4%
distribute-rgt-out50.4%
metadata-eval50.4%
associate-+r+50.4%
mul-1-neg50.4%
unsub-neg50.4%
fma-def50.4%
unpow250.4%
sqr-abs50.4%
*-commutative50.4%
unpow250.4%
sqr-abs50.4%
Simplified50.4%
expm1-log1p-u47.5%
expm1-udef64.2%
mul0-rgt64.2%
associate-+r-64.2%
associate-/l*64.3%
associate-/l*64.8%
Applied egg-rr64.8%
expm1-def48.2%
expm1-log1p51.4%
/-rgt-identity51.4%
/-rgt-identity51.4%
+-lft-identity51.4%
fma-def51.4%
+-commutative51.4%
fma-def51.4%
associate-/r/51.4%
associate-/r/51.4%
Simplified51.4%
fma-udef51.4%
*-commutative51.4%
Applied egg-rr51.4%
Final simplification66.8%
(FPCore (x s)
:precision binary32
(if (<= x -50000.0)
(/ 1.0 (* x (/ x s)))
(if (<= x 1999999991808.0)
(/ 1.0 (+ (* s 4.0) (/ (- (* 2.0 (* x x)) (* x x)) s)))
(/ s (* x x)))))
float code(float x, float s) {
float tmp;
if (x <= -50000.0f) {
tmp = 1.0f / (x * (x / s));
} else if (x <= 1999999991808.0f) {
tmp = 1.0f / ((s * 4.0f) + (((2.0f * (x * x)) - (x * x)) / s));
} else {
tmp = 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 <= (-50000.0e0)) then
tmp = 1.0e0 / (x * (x / s))
else if (x <= 1999999991808.0e0) then
tmp = 1.0e0 / ((s * 4.0e0) + (((2.0e0 * (x * x)) - (x * x)) / s))
else
tmp = s / (x * x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-50000.0)) tmp = Float32(Float32(1.0) / Float32(x * Float32(x / s))); elseif (x <= Float32(1999999991808.0)) tmp = Float32(Float32(1.0) / Float32(Float32(s * Float32(4.0)) + Float32(Float32(Float32(Float32(2.0) * Float32(x * x)) - Float32(x * x)) / s))); else tmp = Float32(s / Float32(x * x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-50000.0)) tmp = single(1.0) / (x * (x / s)); elseif (x <= single(1999999991808.0)) tmp = single(1.0) / ((s * single(4.0)) + (((single(2.0) * (x * x)) - (x * x)) / s)); else tmp = s / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -50000:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\mathbf{elif}\;x \leq 1999999991808:\\
\;\;\;\;\frac{1}{s \cdot 4 + \frac{2 \cdot \left(x \cdot x\right) - x \cdot x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < -5e4Initial 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.6%
associate-+r+2.6%
distribute-rgt-out2.6%
metadata-eval2.6%
associate-+r+2.6%
mul-1-neg2.6%
unsub-neg2.6%
fma-def2.6%
unpow22.6%
sqr-abs2.6%
*-commutative2.6%
unpow22.6%
sqr-abs2.6%
Simplified2.6%
expm1-log1p-u2.6%
expm1-udef21.1%
mul0-rgt21.1%
associate-+r-21.1%
associate-/l*21.1%
associate-/l*21.1%
Applied egg-rr21.1%
expm1-def2.6%
expm1-log1p2.6%
/-rgt-identity2.6%
/-rgt-identity2.6%
+-lft-identity2.6%
fma-def2.6%
+-commutative2.6%
fma-def2.6%
associate-/r/2.6%
associate-/r/2.6%
Simplified2.6%
Taylor expanded in s around 0 27.2%
sub-neg27.2%
mul-1-neg27.2%
distribute-rgt-out81.5%
metadata-eval81.5%
*-rgt-identity81.5%
unpow281.5%
associate-*r/81.5%
Simplified81.5%
if -5e4 < x < 1999999990000Initial program 98.0%
*-lft-identity98.0%
associate-*r/98.0%
associate-/l*98.0%
distribute-frac-neg98.0%
exp-neg98.0%
associate-/r/98.0%
/-rgt-identity98.0%
associate-*l*98.0%
Simplified98.2%
Taylor expanded in s around inf 46.9%
associate-+r+46.9%
distribute-rgt-out46.9%
metadata-eval46.9%
associate-+r+46.9%
mul-1-neg46.9%
unsub-neg46.9%
fma-def46.9%
unpow246.9%
sqr-abs46.9%
*-commutative46.9%
unpow246.9%
sqr-abs46.9%
Simplified46.9%
fma-udef46.9%
associate-/l*47.0%
Applied egg-rr47.0%
*-un-lft-identity47.0%
mul0-rgt47.0%
+-commutative47.0%
fma-def47.0%
div-inv47.0%
clear-num47.0%
associate-/l*47.8%
div-inv47.8%
clear-num47.8%
Applied egg-rr47.8%
*-lft-identity47.8%
+-rgt-identity47.8%
fma-udef47.8%
associate-*r/46.7%
unpow246.7%
*-commutative46.7%
+-commutative46.7%
associate-+r-46.7%
*-commutative46.7%
associate-*r/46.7%
associate-*r/46.9%
unpow246.9%
div-sub51.5%
unpow251.5%
unpow251.5%
Simplified51.5%
if 1999999990000 < 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 0.6%
associate-+r+0.6%
distribute-rgt-out0.6%
metadata-eval0.6%
associate-+r+0.6%
mul-1-neg0.6%
unsub-neg0.6%
fma-def0.6%
unpow20.6%
sqr-abs0.6%
*-commutative0.6%
unpow20.6%
sqr-abs0.6%
Simplified0.6%
Taylor expanded in x around inf 96.2%
unpow296.2%
Simplified96.2%
Final simplification66.2%
(FPCore (x s) :precision binary32 (if (or (<= x -9.999999717180685e-10) (not (<= x 0.0015999999595806003))) (/ 1.0 (* x (/ x s))) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -9.999999717180685e-10f) || !(x <= 0.0015999999595806003f)) {
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 <= (-9.999999717180685e-10)) .or. (.not. (x <= 0.0015999999595806003e0))) 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(-9.999999717180685e-10)) || !(x <= Float32(0.0015999999595806003))) 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(-9.999999717180685e-10)) || ~((x <= single(0.0015999999595806003)))) 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 -9.999999717180685 \cdot 10^{-10} \lor \neg \left(x \leq 0.0015999999595806003\right):\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -9.99999972e-10 or 0.00159999996 < x Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in s around inf 3.9%
associate-+r+3.9%
distribute-rgt-out3.9%
metadata-eval3.9%
associate-+r+3.9%
mul-1-neg3.9%
unsub-neg3.9%
fma-def3.9%
unpow23.9%
sqr-abs3.9%
*-commutative3.9%
unpow23.9%
sqr-abs3.9%
Simplified3.9%
expm1-log1p-u3.9%
expm1-udef27.2%
mul0-rgt27.2%
associate-+r-27.2%
associate-/l*27.2%
associate-/l*27.2%
Applied egg-rr27.2%
expm1-def3.9%
expm1-log1p3.9%
/-rgt-identity3.9%
/-rgt-identity3.9%
+-lft-identity3.9%
fma-def3.9%
+-commutative3.9%
fma-def3.9%
associate-/r/3.9%
associate-/r/3.9%
Simplified3.9%
Taylor expanded in s around 0 27.4%
sub-neg27.4%
mul-1-neg27.4%
distribute-rgt-out70.4%
metadata-eval70.4%
*-rgt-identity70.4%
unpow270.4%
associate-*r/70.4%
Simplified70.4%
if -9.99999972e-10 < x < 0.00159999996Initial program 97.6%
associate-*l*97.6%
+-commutative97.6%
+-commutative97.6%
Simplified97.6%
Taylor expanded in s around inf 58.5%
Final simplification65.2%
(FPCore (x s) :precision binary32 (if (<= x -9.999999717180685e-10) (/ s (* x x)) (if (<= x 0.0015999999595806003) (/ 0.25 s) (* s (/ 1.0 (* x x))))))
float code(float x, float s) {
float tmp;
if (x <= -9.999999717180685e-10f) {
tmp = s / (x * x);
} else if (x <= 0.0015999999595806003f) {
tmp = 0.25f / s;
} else {
tmp = s * (1.0f / (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 <= (-9.999999717180685e-10)) then
tmp = s / (x * x)
else if (x <= 0.0015999999595806003e0) then
tmp = 0.25e0 / s
else
tmp = s * (1.0e0 / (x * x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-9.999999717180685e-10)) tmp = Float32(s / Float32(x * x)); elseif (x <= Float32(0.0015999999595806003)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(s * Float32(Float32(1.0) / Float32(x * x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-9.999999717180685e-10)) tmp = s / (x * x); elseif (x <= single(0.0015999999595806003)) tmp = single(0.25) / s; else tmp = s * (single(1.0) / (x * x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.999999717180685 \cdot 10^{-10}:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\mathbf{elif}\;x \leq 0.0015999999595806003:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;s \cdot \frac{1}{x \cdot x}\\
\end{array}
\end{array}
if x < -9.99999972e-10Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in s around inf 4.2%
associate-+r+4.2%
distribute-rgt-out4.2%
metadata-eval4.2%
associate-+r+4.2%
mul-1-neg4.2%
unsub-neg4.2%
fma-def4.2%
unpow24.2%
sqr-abs4.2%
*-commutative4.2%
unpow24.2%
sqr-abs4.2%
Simplified4.2%
Taylor expanded in x around inf 62.7%
unpow262.7%
Simplified62.7%
if -9.99999972e-10 < x < 0.00159999996Initial program 97.6%
associate-*l*97.6%
+-commutative97.6%
+-commutative97.6%
Simplified97.6%
Taylor expanded in s around inf 58.5%
if 0.00159999996 < 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 3.5%
associate-+r+3.5%
distribute-rgt-out3.5%
metadata-eval3.5%
associate-+r+3.5%
mul-1-neg3.5%
unsub-neg3.5%
fma-def3.5%
unpow23.5%
sqr-abs3.5%
*-commutative3.5%
unpow23.5%
sqr-abs3.5%
Simplified3.5%
Taylor expanded in x around inf 75.8%
unpow275.8%
Simplified75.8%
div-inv75.8%
Applied egg-rr75.8%
Final simplification64.4%
(FPCore (x s) :precision binary32 (if (or (<= x -9.999999717180685e-10) (not (<= x 0.0015999999595806003))) (/ s (* x x)) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -9.999999717180685e-10f) || !(x <= 0.0015999999595806003f)) {
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 <= (-9.999999717180685e-10)) .or. (.not. (x <= 0.0015999999595806003e0))) 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(-9.999999717180685e-10)) || !(x <= Float32(0.0015999999595806003))) 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(-9.999999717180685e-10)) || ~((x <= single(0.0015999999595806003)))) 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 -9.999999717180685 \cdot 10^{-10} \lor \neg \left(x \leq 0.0015999999595806003\right):\\
\;\;\;\;\frac{s}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -9.99999972e-10 or 0.00159999996 < x Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-/l*99.8%
distribute-frac-neg99.8%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in s around inf 3.9%
associate-+r+3.9%
distribute-rgt-out3.9%
metadata-eval3.9%
associate-+r+3.9%
mul-1-neg3.9%
unsub-neg3.9%
fma-def3.9%
unpow23.9%
sqr-abs3.9%
*-commutative3.9%
unpow23.9%
sqr-abs3.9%
Simplified3.9%
Taylor expanded in x around inf 69.0%
unpow269.0%
Simplified69.0%
if -9.99999972e-10 < x < 0.00159999996Initial program 97.6%
associate-*l*97.6%
+-commutative97.6%
+-commutative97.6%
Simplified97.6%
Taylor expanded in s around inf 58.5%
Final simplification64.4%
(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 98.8%
associate-*l*98.9%
+-commutative98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in s around inf 28.3%
Final simplification28.3%
herbie shell --seed 2023174
(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))))))