
(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 10 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}
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (let* ((t_0 (exp (/ x_m (- s))))) (/ t_0 (* s (pow (+ t_0 1.0) 2.0)))))
x_m = fabs(x);
float code(float x_m, float s) {
float t_0 = expf((x_m / -s));
return t_0 / (s * powf((t_0 + 1.0f), 2.0f));
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((x_m / -s))
code = t_0 / (s * ((t_0 + 1.0e0) ** 2.0e0))
end function
x_m = abs(x) function code(x_m, s) t_0 = exp(Float32(x_m / Float32(-s))) return Float32(t_0 / Float32(s * (Float32(t_0 + Float32(1.0)) ^ Float32(2.0)))) end
x_m = abs(x); function tmp = code(x_m, s) t_0 = exp((x_m / -s)); tmp = t_0 / (s * ((t_0 + single(1.0)) ^ single(2.0))); end
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := e^{\frac{x\_m}{-s}}\\
\frac{t\_0}{s \cdot {\left(t\_0 + 1\right)}^{2}}
\end{array}
\end{array}
Initial program 99.5%
fabs-neg99.5%
distribute-frac-neg99.5%
distribute-frac-neg299.5%
fabs-neg99.5%
*-commutative99.5%
fabs-neg99.5%
+-commutative99.5%
fabs-neg99.5%
Simplified99.6%
Taylor expanded in x around 0 99.6%
unpow299.6%
distribute-lft-in99.6%
mul-1-neg99.6%
rec-exp99.6%
distribute-lft-in99.6%
associate-*r/99.6%
mul-1-neg99.6%
Simplified99.6%
distribute-frac-neg99.6%
exp-neg99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt95.6%
add-sqr-sqrt49.3%
sqrt-unprod99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt50.5%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt99.6%
sqr-neg99.6%
distribute-frac-neg99.6%
distribute-frac-neg99.6%
sqrt-unprod-0.0%
add-sqr-sqrt91.5%
Applied egg-rr95.6%
rec-exp95.7%
distribute-frac-neg95.7%
Simplified95.7%
distribute-frac-neg99.6%
exp-neg99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt95.6%
add-sqr-sqrt49.3%
sqrt-unprod99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt50.5%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt99.6%
sqr-neg99.6%
distribute-frac-neg99.6%
distribute-frac-neg99.6%
sqrt-unprod-0.0%
add-sqr-sqrt91.5%
Applied egg-rr65.6%
rec-exp95.7%
distribute-frac-neg95.7%
Simplified66.0%
Final simplification66.0%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (if (<= (fabs x_m) 1.0) (/ (exp (+ (/ x_m s) (* -2.0 (log1p (exp (/ x_m s)))))) s) (/ (exp (/ x_m (- s))) (* s 4.0))))
x_m = fabs(x);
float code(float x_m, float s) {
float tmp;
if (fabsf(x_m) <= 1.0f) {
tmp = expf(((x_m / s) + (-2.0f * log1pf(expf((x_m / s)))))) / s;
} else {
tmp = expf((x_m / -s)) / (s * 4.0f);
}
return tmp;
}
x_m = abs(x) function code(x_m, s) tmp = Float32(0.0) if (abs(x_m) <= Float32(1.0)) tmp = Float32(exp(Float32(Float32(x_m / s) + Float32(Float32(-2.0) * log1p(exp(Float32(x_m / s)))))) / s); else tmp = Float32(exp(Float32(x_m / Float32(-s))) / Float32(s * Float32(4.0))); end return tmp end
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;\left|x\_m\right| \leq 1:\\
\;\;\;\;\frac{e^{\frac{x\_m}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{x\_m}{s}}\right)}}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{x\_m}{-s}}}{s \cdot 4}\\
\end{array}
\end{array}
if (fabs.f32 x) < 1Initial program 99.1%
fabs-neg99.1%
distribute-frac-neg99.1%
distribute-frac-neg299.1%
fabs-neg99.1%
*-commutative99.1%
fabs-neg99.1%
+-commutative99.1%
fabs-neg99.1%
Simplified99.2%
Applied egg-rr71.9%
*-lft-identity71.9%
*-commutative71.9%
exp-to-pow71.9%
log1p-undefine72.0%
*-commutative72.0%
rem-exp-log68.2%
prod-exp67.4%
exp-diff94.1%
associate--r+94.4%
exp-diff94.9%
cancel-sign-sub-inv94.9%
metadata-eval94.9%
Simplified98.8%
if 1 < (fabs.f32 x) Initial program 100.0%
fabs-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
fabs-neg100.0%
*-commutative100.0%
fabs-neg100.0%
+-commutative100.0%
fabs-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
distribute-lft-in100.0%
mul-1-neg100.0%
rec-exp100.0%
distribute-lft-in100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt46.3%
fabs-sqr46.3%
add-sqr-sqrt100.0%
add-sqr-sqrt46.3%
sqrt-unprod100.0%
add-sqr-sqrt46.3%
fabs-sqr46.3%
add-sqr-sqrt46.3%
add-sqr-sqrt46.3%
fabs-sqr46.3%
add-sqr-sqrt100.0%
sqr-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg100.0%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
rec-exp100.0%
distribute-frac-neg100.0%
Simplified100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt46.3%
fabs-sqr46.3%
add-sqr-sqrt100.0%
add-sqr-sqrt46.3%
sqrt-unprod100.0%
add-sqr-sqrt46.3%
fabs-sqr46.3%
add-sqr-sqrt46.3%
add-sqr-sqrt46.3%
fabs-sqr46.3%
add-sqr-sqrt100.0%
sqr-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg100.0%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
Applied egg-rr46.3%
rec-exp100.0%
distribute-frac-neg100.0%
Simplified46.3%
Taylor expanded in s around inf 48.0%
*-commutative48.0%
Simplified48.0%
Final simplification74.8%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (if (<= (- (fabs x_m)) -50000.0) (/ (exp (/ x_m (- s))) (* s 4.0)) (/ (+ 0.5 (/ (* x_m 0.25) s)) (* s (+ (exp (/ x_m s)) 1.0)))))
x_m = fabs(x);
float code(float x_m, float s) {
float tmp;
if (-fabsf(x_m) <= -50000.0f) {
tmp = expf((x_m / -s)) / (s * 4.0f);
} else {
tmp = (0.5f + ((x_m * 0.25f) / s)) / (s * (expf((x_m / s)) + 1.0f));
}
return tmp;
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
real(4) :: tmp
if (-abs(x_m) <= (-50000.0e0)) then
tmp = exp((x_m / -s)) / (s * 4.0e0)
else
tmp = (0.5e0 + ((x_m * 0.25e0) / s)) / (s * (exp((x_m / s)) + 1.0e0))
end if
code = tmp
end function
x_m = abs(x) function code(x_m, s) tmp = Float32(0.0) if (Float32(-abs(x_m)) <= Float32(-50000.0)) tmp = Float32(exp(Float32(x_m / Float32(-s))) / Float32(s * Float32(4.0))); else tmp = Float32(Float32(Float32(0.5) + Float32(Float32(x_m * Float32(0.25)) / s)) / Float32(s * Float32(exp(Float32(x_m / s)) + Float32(1.0)))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, s) tmp = single(0.0); if (-abs(x_m) <= single(-50000.0)) tmp = exp((x_m / -s)) / (s * single(4.0)); else tmp = (single(0.5) + ((x_m * single(0.25)) / s)) / (s * (exp((x_m / s)) + single(1.0))); end tmp_2 = tmp; end
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;-\left|x\_m\right| \leq -50000:\\
\;\;\;\;\frac{e^{\frac{x\_m}{-s}}}{s \cdot 4}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 + \frac{x\_m \cdot 0.25}{s}}{s \cdot \left(e^{\frac{x\_m}{s}} + 1\right)}\\
\end{array}
\end{array}
if (neg.f32 (fabs.f32 x)) < -5e4Initial program 100.0%
fabs-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
fabs-neg100.0%
*-commutative100.0%
fabs-neg100.0%
+-commutative100.0%
fabs-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
distribute-lft-in100.0%
mul-1-neg100.0%
rec-exp100.0%
distribute-lft-in100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt100.0%
add-sqr-sqrt47.7%
sqrt-unprod100.0%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt47.7%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt100.0%
sqr-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg100.0%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
rec-exp100.0%
distribute-frac-neg100.0%
Simplified100.0%
distribute-frac-neg100.0%
exp-neg100.0%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt100.0%
add-sqr-sqrt47.7%
sqrt-unprod100.0%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt47.7%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt100.0%
sqr-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg100.0%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
Applied egg-rr47.7%
rec-exp100.0%
distribute-frac-neg100.0%
Simplified47.7%
Taylor expanded in s around inf 49.3%
*-commutative49.3%
Simplified49.3%
if -5e4 < (neg.f32 (fabs.f32 x)) Initial program 99.2%
fabs-neg99.2%
distribute-frac-neg99.2%
distribute-frac-neg299.2%
fabs-neg99.2%
*-commutative99.2%
fabs-neg99.2%
+-commutative99.2%
fabs-neg99.2%
Simplified99.3%
Applied egg-rr71.4%
associate-*l/71.4%
*-lft-identity71.4%
Simplified71.4%
Taylor expanded in s around inf 59.1%
*-un-lft-identity59.1%
associate-/l/72.5%
associate--l+72.6%
associate-*r/72.6%
associate-*r/72.6%
sub-div72.6%
Applied egg-rr72.6%
associate-*r/72.6%
*-commutative72.6%
*-lft-identity72.6%
distribute-rgt-out--72.6%
metadata-eval72.6%
Simplified72.6%
Final simplification62.8%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (/ 0.5 (* s (+ (exp (/ x_m s)) 1.0))))
x_m = fabs(x);
float code(float x_m, float s) {
return 0.5f / (s * (expf((x_m / s)) + 1.0f));
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
code = 0.5e0 / (s * (exp((x_m / s)) + 1.0e0))
end function
x_m = abs(x) function code(x_m, s) return Float32(Float32(0.5) / Float32(s * Float32(exp(Float32(x_m / s)) + Float32(1.0)))) end
x_m = abs(x); function tmp = code(x_m, s) tmp = single(0.5) / (s * (exp((x_m / s)) + single(1.0))); end
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{0.5}{s \cdot \left(e^{\frac{x\_m}{s}} + 1\right)}
\end{array}
Initial program 99.5%
fabs-neg99.5%
distribute-frac-neg99.5%
distribute-frac-neg299.5%
fabs-neg99.5%
*-commutative99.5%
fabs-neg99.5%
+-commutative99.5%
fabs-neg99.5%
Simplified99.6%
Applied egg-rr63.4%
associate-*l/63.5%
*-lft-identity63.5%
Simplified63.5%
Taylor expanded in x around 0 60.4%
Taylor expanded in s around 0 60.4%
Final simplification60.4%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (/ (exp (/ x_m (- s))) (* s 4.0)))
x_m = fabs(x);
float code(float x_m, float s) {
return expf((x_m / -s)) / (s * 4.0f);
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
code = exp((x_m / -s)) / (s * 4.0e0)
end function
x_m = abs(x) function code(x_m, s) return Float32(exp(Float32(x_m / Float32(-s))) / Float32(s * Float32(4.0))) end
x_m = abs(x); function tmp = code(x_m, s) tmp = exp((x_m / -s)) / (s * single(4.0)); end
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{e^{\frac{x\_m}{-s}}}{s \cdot 4}
\end{array}
Initial program 99.5%
fabs-neg99.5%
distribute-frac-neg99.5%
distribute-frac-neg299.5%
fabs-neg99.5%
*-commutative99.5%
fabs-neg99.5%
+-commutative99.5%
fabs-neg99.5%
Simplified99.6%
Taylor expanded in x around 0 99.6%
unpow299.6%
distribute-lft-in99.6%
mul-1-neg99.6%
rec-exp99.6%
distribute-lft-in99.6%
associate-*r/99.6%
mul-1-neg99.6%
Simplified99.6%
distribute-frac-neg99.6%
exp-neg99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt95.6%
add-sqr-sqrt49.3%
sqrt-unprod99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt50.5%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt99.6%
sqr-neg99.6%
distribute-frac-neg99.6%
distribute-frac-neg99.6%
sqrt-unprod-0.0%
add-sqr-sqrt91.5%
Applied egg-rr95.6%
rec-exp95.7%
distribute-frac-neg95.7%
Simplified95.7%
distribute-frac-neg99.6%
exp-neg99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt95.6%
add-sqr-sqrt49.3%
sqrt-unprod99.6%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt50.5%
add-sqr-sqrt49.3%
fabs-sqr49.3%
add-sqr-sqrt99.6%
sqr-neg99.6%
distribute-frac-neg99.6%
distribute-frac-neg99.6%
sqrt-unprod-0.0%
add-sqr-sqrt91.5%
Applied egg-rr65.6%
rec-exp95.7%
distribute-frac-neg95.7%
Simplified66.0%
Taylor expanded in s around inf 59.5%
*-commutative59.5%
Simplified59.5%
Final simplification59.5%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (if (<= x_m 1600000006029312.0) (/ (- (+ 0.25 (/ (* x_m -0.125) s)) (* 0.5 (* (/ x_m s) -0.25))) s) (/ 1.0 (* s (/ (+ 2.0 (/ x_m s)) 0.5)))))
x_m = fabs(x);
float code(float x_m, float s) {
float tmp;
if (x_m <= 1600000006029312.0f) {
tmp = ((0.25f + ((x_m * -0.125f) / s)) - (0.5f * ((x_m / s) * -0.25f))) / s;
} else {
tmp = 1.0f / (s * ((2.0f + (x_m / s)) / 0.5f));
}
return tmp;
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
real(4) :: tmp
if (x_m <= 1600000006029312.0e0) then
tmp = ((0.25e0 + ((x_m * (-0.125e0)) / s)) - (0.5e0 * ((x_m / s) * (-0.25e0)))) / s
else
tmp = 1.0e0 / (s * ((2.0e0 + (x_m / s)) / 0.5e0))
end if
code = tmp
end function
x_m = abs(x) function code(x_m, s) tmp = Float32(0.0) if (x_m <= Float32(1600000006029312.0)) tmp = Float32(Float32(Float32(Float32(0.25) + Float32(Float32(x_m * Float32(-0.125)) / s)) - Float32(Float32(0.5) * Float32(Float32(x_m / s) * Float32(-0.25)))) / s); else tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(2.0) + Float32(x_m / s)) / Float32(0.5)))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, s) tmp = single(0.0); if (x_m <= single(1600000006029312.0)) tmp = ((single(0.25) + ((x_m * single(-0.125)) / s)) - (single(0.5) * ((x_m / s) * single(-0.25)))) / s; else tmp = single(1.0) / (s * ((single(2.0) + (x_m / s)) / single(0.5))); end tmp_2 = tmp; end
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1600000006029312:\\
\;\;\;\;\frac{\left(0.25 + \frac{x\_m \cdot -0.125}{s}\right) - 0.5 \cdot \left(\frac{x\_m}{s} \cdot -0.25\right)}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \frac{2 + \frac{x\_m}{s}}{0.5}}\\
\end{array}
\end{array}
if x < 1.60000001e15Initial program 99.4%
fabs-neg99.4%
distribute-frac-neg99.4%
distribute-frac-neg299.4%
fabs-neg99.4%
*-commutative99.4%
fabs-neg99.4%
+-commutative99.4%
fabs-neg99.4%
Simplified99.5%
Applied egg-rr73.8%
associate-*l/73.8%
*-lft-identity73.8%
Simplified73.8%
Taylor expanded in s around inf 42.3%
Taylor expanded in s around -inf 69.7%
mul-1-neg69.7%
*-commutative69.7%
distribute-rgt-out--69.7%
metadata-eval69.7%
*-commutative69.7%
associate-*r/69.6%
*-commutative69.6%
associate-*r/69.7%
*-commutative69.7%
Simplified69.7%
if 1.60000001e15 < x Initial program 100.0%
fabs-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
fabs-neg100.0%
*-commutative100.0%
fabs-neg100.0%
+-commutative100.0%
fabs-neg100.0%
Simplified100.0%
Applied egg-rr-0.0%
associate-*l/-0.0%
*-lft-identity-0.0%
Simplified-0.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 80.7%
+-commutative80.7%
Simplified80.7%
clear-num80.7%
inv-pow80.7%
+-commutative80.7%
Applied egg-rr80.7%
unpow-180.7%
associate-/r/80.7%
Simplified80.7%
Final simplification71.2%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (if (<= x_m 0.0020000000949949026) (/ 0.25 s) (/ (/ 0.5 s) (/ x_m s))))
x_m = fabs(x);
float code(float x_m, float s) {
float tmp;
if (x_m <= 0.0020000000949949026f) {
tmp = 0.25f / s;
} else {
tmp = (0.5f / s) / (x_m / s);
}
return tmp;
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
real(4) :: tmp
if (x_m <= 0.0020000000949949026e0) then
tmp = 0.25e0 / s
else
tmp = (0.5e0 / s) / (x_m / s)
end if
code = tmp
end function
x_m = abs(x) function code(x_m, s) tmp = Float32(0.0) if (x_m <= Float32(0.0020000000949949026)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(0.5) / s) / Float32(x_m / s)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, s) tmp = single(0.0); if (x_m <= single(0.0020000000949949026)) tmp = single(0.25) / s; else tmp = (single(0.5) / s) / (x_m / s); end tmp_2 = tmp; end
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.0020000000949949026:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{s}}{\frac{x\_m}{s}}\\
\end{array}
\end{array}
if x < 0.00200000009Initial program 99.4%
fabs-neg99.4%
distribute-frac-neg99.4%
distribute-frac-neg299.4%
fabs-neg99.4%
*-commutative99.4%
fabs-neg99.4%
+-commutative99.4%
fabs-neg99.4%
Simplified99.5%
Taylor expanded in s around inf 35.3%
if 0.00200000009 < x Initial program 100.0%
fabs-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
fabs-neg100.0%
*-commutative100.0%
fabs-neg100.0%
+-commutative100.0%
fabs-neg100.0%
Simplified100.0%
Applied egg-rr-0.0%
associate-*l/-0.0%
*-lft-identity-0.0%
Simplified-0.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 58.3%
+-commutative58.3%
Simplified58.3%
Taylor expanded in x around inf 58.3%
Final simplification40.6%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (* (/ 0.5 s) (/ 1.0 (+ 2.0 (/ x_m s)))))
x_m = fabs(x);
float code(float x_m, float s) {
return (0.5f / s) * (1.0f / (2.0f + (x_m / s)));
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
code = (0.5e0 / s) * (1.0e0 / (2.0e0 + (x_m / s)))
end function
x_m = abs(x) function code(x_m, s) return Float32(Float32(Float32(0.5) / s) * Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(x_m / s)))) end
x_m = abs(x); function tmp = code(x_m, s) tmp = (single(0.5) / s) * (single(1.0) / (single(2.0) + (x_m / s))); end
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{0.5}{s} \cdot \frac{1}{2 + \frac{x\_m}{s}}
\end{array}
Initial program 99.5%
fabs-neg99.5%
distribute-frac-neg99.5%
distribute-frac-neg299.5%
fabs-neg99.5%
*-commutative99.5%
fabs-neg99.5%
+-commutative99.5%
fabs-neg99.5%
Simplified99.6%
Applied egg-rr63.4%
associate-*l/63.5%
*-lft-identity63.5%
Simplified63.5%
Taylor expanded in x around 0 60.4%
Taylor expanded in x around 0 50.5%
+-commutative50.5%
Simplified50.5%
div-inv50.5%
+-commutative50.5%
Applied egg-rr50.5%
Final simplification50.5%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (/ (/ 0.5 s) (+ 2.0 (/ x_m s))))
x_m = fabs(x);
float code(float x_m, float s) {
return (0.5f / s) / (2.0f + (x_m / s));
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
code = (0.5e0 / s) / (2.0e0 + (x_m / s))
end function
x_m = abs(x) function code(x_m, s) return Float32(Float32(Float32(0.5) / s) / Float32(Float32(2.0) + Float32(x_m / s))) end
x_m = abs(x); function tmp = code(x_m, s) tmp = (single(0.5) / s) / (single(2.0) + (x_m / s)); end
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{0.5}{s}}{2 + \frac{x\_m}{s}}
\end{array}
Initial program 99.5%
fabs-neg99.5%
distribute-frac-neg99.5%
distribute-frac-neg299.5%
fabs-neg99.5%
*-commutative99.5%
fabs-neg99.5%
+-commutative99.5%
fabs-neg99.5%
Simplified99.6%
Applied egg-rr63.4%
associate-*l/63.5%
*-lft-identity63.5%
Simplified63.5%
Taylor expanded in x around 0 60.4%
Taylor expanded in x around 0 50.5%
+-commutative50.5%
Simplified50.5%
Final simplification50.5%
x_m = (fabs.f32 x) (FPCore (x_m s) :precision binary32 (/ 0.25 s))
x_m = fabs(x);
float code(float x_m, float s) {
return 0.25f / s;
}
x_m = abs(x)
real(4) function code(x_m, s)
real(4), intent (in) :: x_m
real(4), intent (in) :: s
code = 0.25e0 / s
end function
x_m = abs(x) function code(x_m, s) return Float32(Float32(0.25) / s) end
x_m = abs(x); function tmp = code(x_m, s) tmp = single(0.25) / s; end
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{0.25}{s}
\end{array}
Initial program 99.5%
fabs-neg99.5%
distribute-frac-neg99.5%
distribute-frac-neg299.5%
fabs-neg99.5%
*-commutative99.5%
fabs-neg99.5%
+-commutative99.5%
fabs-neg99.5%
Simplified99.6%
Taylor expanded in s around inf 28.2%
Final simplification28.2%
herbie shell --seed 2024078
(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))))))