
(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}
NOTE: x should be positive before calling this function
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= (fabs x) 9.999999747378752e-5)
(/ 1.0 (/ s (exp (- (/ x s) (* 2.0 (log1p t_0))))))
(/ (/ 1.0 s) (+ t_0 3.0)))))x = abs(x);
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (fabsf(x) <= 9.999999747378752e-5f) {
tmp = 1.0f / (s / expf(((x / s) - (2.0f * log1pf(t_0)))));
} else {
tmp = (1.0f / s) / (t_0 + 3.0f);
}
return tmp;
}
x = abs(x) function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (abs(x) <= Float32(9.999999747378752e-5)) tmp = Float32(Float32(1.0) / Float32(s / exp(Float32(Float32(x / s) - Float32(Float32(2.0) * log1p(t_0)))))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(t_0 + Float32(3.0))); end return tmp end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;\left|x\right| \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{s}{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(t_0\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{t_0 + 3}\\
\end{array}
\end{array}
if (fabs.f32 x) < 9.99999975e-5Initial program 99.2%
*-un-lft-identity99.2%
associate-*l*99.2%
times-frac99.2%
Applied egg-rr84.8%
associate-*l/84.8%
*-un-lft-identity84.8%
clear-num84.8%
add-exp-log84.9%
log-div84.9%
add-log-exp99.2%
log-pow99.2%
log1p-udef99.4%
Applied egg-rr99.4%
if 9.99999975e-5 < (fabs.f32 x) Initial program 100.0%
Simplified100.0%
Taylor expanded in s around inf 100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
associate-/l/100.0%
+-commutative100.0%
metadata-eval100.0%
add-sqr-sqrt49.0%
fabs-sqr49.0%
add-sqr-sqrt51.3%
Applied egg-rr51.3%
expm1-def51.3%
expm1-log1p51.3%
associate-/r*51.3%
*-lft-identity51.3%
associate-*l/51.3%
associate-*r/51.3%
*-rgt-identity51.3%
Simplified51.3%
Final simplification72.2%
NOTE: x should be positive before calling this function
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= (fabs x) 9.999999747378752e-5)
(/ (exp (- (/ x s) (* 2.0 (log1p t_0)))) s)
(/ (/ 1.0 s) (+ t_0 3.0)))))x = abs(x);
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (fabsf(x) <= 9.999999747378752e-5f) {
tmp = expf(((x / s) - (2.0f * log1pf(t_0)))) / s;
} else {
tmp = (1.0f / s) / (t_0 + 3.0f);
}
return tmp;
}
x = abs(x) function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (abs(x) <= Float32(9.999999747378752e-5)) tmp = Float32(exp(Float32(Float32(x / s) - Float32(Float32(2.0) * log1p(t_0)))) / s); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(t_0 + Float32(3.0))); end return tmp end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;\left|x\right| \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(t_0\right)}}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{t_0 + 3}\\
\end{array}
\end{array}
if (fabs.f32 x) < 9.99999975e-5Initial program 99.2%
*-un-lft-identity99.2%
associate-*l*99.2%
times-frac99.2%
Applied egg-rr84.8%
associate-*l/84.8%
*-un-lft-identity84.8%
add-exp-log84.8%
log-div84.9%
add-log-exp99.2%
log-pow99.2%
log1p-udef99.4%
Applied egg-rr99.4%
if 9.99999975e-5 < (fabs.f32 x) Initial program 100.0%
Simplified100.0%
Taylor expanded in s around inf 100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
associate-/l/100.0%
+-commutative100.0%
metadata-eval100.0%
add-sqr-sqrt49.0%
fabs-sqr49.0%
add-sqr-sqrt51.3%
Applied egg-rr51.3%
expm1-def51.3%
expm1-log1p51.3%
associate-/r*51.3%
*-lft-identity51.3%
associate-*l/51.3%
associate-*r/51.3%
*-rgt-identity51.3%
Simplified51.3%
Final simplification72.2%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (exp (/ (fabs x) s)) (+ (exp (/ (- x) s)) 2.0))))
x = abs(x);
float code(float x, float s) {
return (1.0f / s) / (expf((fabsf(x) / s)) + (expf((-x / s)) + 2.0f));
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (exp((abs(x) / s)) + (exp((-x / s)) + 2.0e0))
end function
x = abs(x) function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(exp(Float32(abs(x) / s)) + Float32(exp(Float32(Float32(-x) / s)) + Float32(2.0)))) end
x = abs(x) function tmp = code(x, s) tmp = (single(1.0) / s) / (exp((abs(x) / s)) + (exp((-x / s)) + single(2.0))); end
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{-x}{s}} + 2\right)}
\end{array}
Initial program 99.7%
Simplified99.8%
remove-double-neg99.8%
distribute-frac-neg99.8%
frac-2neg99.8%
exp-neg99.8%
div-inv99.8%
exp-prod96.4%
add-sqr-sqrt96.4%
sqrt-unprod96.4%
sqr-neg96.4%
sqrt-unprod35.7%
add-sqr-sqrt95.8%
exp-prod94.7%
div-inv94.7%
add-sqr-sqrt44.0%
fabs-sqr44.0%
add-sqr-sqrt97.0%
add-sqr-sqrt-0.0%
sqrt-unprod95.0%
sqr-neg95.0%
sqrt-unprod97.4%
add-sqr-sqrt97.4%
Applied egg-rr97.4%
rec-exp97.4%
distribute-neg-frac97.4%
Simplified97.4%
Final simplification97.4%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- x) s)))) (/ t_0 (* s (pow (+ 1.0 t_0) 2.0)))))
x = abs(x);
float code(float x, float s) {
float t_0 = expf((-x / s));
return t_0 / (s * powf((1.0f + t_0), 2.0f));
}
NOTE: x should be positive before calling this function
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 = t_0 / (s * ((1.0e0 + t_0) ** 2.0e0))
end function
x = abs(x) function code(x, s) t_0 = exp(Float32(Float32(-x) / s)) return Float32(t_0 / Float32(s * (Float32(Float32(1.0) + t_0) ^ Float32(2.0)))) end
x = abs(x) function tmp = code(x, s) t_0 = exp((-x / s)); tmp = t_0 / (s * ((single(1.0) + t_0) ^ single(2.0))); end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := e^{\frac{-x}{s}}\\
\frac{t_0}{s \cdot {\left(1 + t_0\right)}^{2}}
\end{array}
\end{array}
Initial program 99.7%
Taylor expanded in s around 0 99.6%
associate-*r/99.6%
mul-1-neg99.6%
Simplified99.6%
distribute-frac-neg99.6%
exp-neg99.7%
add-sqr-sqrt46.7%
fabs-sqr46.7%
add-sqr-sqrt96.9%
Applied egg-rr96.9%
rec-exp96.9%
distribute-neg-frac96.9%
Simplified96.9%
distribute-frac-neg99.6%
exp-neg99.7%
add-sqr-sqrt46.7%
fabs-sqr46.7%
add-sqr-sqrt96.9%
Applied egg-rr60.6%
rec-exp96.9%
distribute-neg-frac96.9%
Simplified60.6%
Final simplification60.6%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ (/ 1.0 s) (expm1 (log1p (+ (exp (/ x s)) 3.0)))))
x = abs(x);
float code(float x, float s) {
return (1.0f / s) / expm1f(log1pf((expf((x / s)) + 3.0f)));
}
x = abs(x) function code(x, s) return Float32(Float32(Float32(1.0) / s) / expm1(log1p(Float32(exp(Float32(x / s)) + Float32(3.0))))) end
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{1}{s}}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{x}{s}} + 3\right)\right)}
\end{array}
Initial program 99.7%
Simplified99.8%
Taylor expanded in s around inf 95.8%
expm1-log1p-u95.9%
+-commutative95.9%
metadata-eval95.9%
add-sqr-sqrt44.5%
fabs-sqr44.5%
add-sqr-sqrt57.8%
Applied egg-rr57.8%
Final simplification57.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (* (/ 1.0 s) (/ 1.0 (+ (exp (/ x s)) 3.0))))
x = abs(x);
float code(float x, float s) {
return (1.0f / s) * (1.0f / (expf((x / s)) + 3.0f));
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) * (1.0e0 / (exp((x / s)) + 3.0e0))
end function
x = abs(x) function code(x, s) return Float32(Float32(Float32(1.0) / s) * Float32(Float32(1.0) / Float32(exp(Float32(x / s)) + Float32(3.0)))) end
x = abs(x) function tmp = code(x, s) tmp = (single(1.0) / s) * (single(1.0) / (exp((x / s)) + single(3.0))); end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{s} \cdot \frac{1}{e^{\frac{x}{s}} + 3}
\end{array}
Initial program 99.7%
Simplified99.8%
Taylor expanded in s around inf 95.8%
div-inv95.8%
+-commutative95.8%
metadata-eval95.8%
add-sqr-sqrt44.5%
fabs-sqr44.5%
add-sqr-sqrt57.8%
Applied egg-rr57.8%
Final simplification57.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (exp (/ x s)) 3.0)))
x = abs(x);
float code(float x, float s) {
return (1.0f / s) / (expf((x / s)) + 3.0f);
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (exp((x / s)) + 3.0e0)
end function
x = abs(x) function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(exp(Float32(x / s)) + Float32(3.0))) end
x = abs(x) function tmp = code(x, s) tmp = (single(1.0) / s) / (exp((x / s)) + single(3.0)); end
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{1}{s}}{e^{\frac{x}{s}} + 3}
\end{array}
Initial program 99.7%
Simplified99.8%
Taylor expanded in s around inf 95.8%
expm1-log1p-u94.6%
expm1-udef94.6%
associate-/l/94.6%
+-commutative94.6%
metadata-eval94.6%
add-sqr-sqrt44.0%
fabs-sqr44.0%
add-sqr-sqrt56.6%
Applied egg-rr56.6%
expm1-def56.6%
expm1-log1p57.8%
associate-/r*57.8%
*-lft-identity57.8%
associate-*l/57.8%
associate-*r/57.8%
*-rgt-identity57.8%
Simplified57.8%
Final simplification57.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ (/ 1.0 (+ (exp (/ x s)) 3.0)) s))
x = abs(x);
float code(float x, float s) {
return (1.0f / (expf((x / s)) + 3.0f)) / s;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / (exp((x / s)) + 3.0e0)) / s
end function
x = abs(x) function code(x, s) return Float32(Float32(Float32(1.0) / Float32(exp(Float32(x / s)) + Float32(3.0))) / s) end
x = abs(x) function tmp = code(x, s) tmp = (single(1.0) / (exp((x / s)) + single(3.0))) / s; end
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{1}{e^{\frac{x}{s}} + 3}}{s}
\end{array}
Initial program 99.7%
Simplified99.8%
Taylor expanded in s around inf 95.8%
div-inv95.8%
+-commutative95.8%
metadata-eval95.8%
add-sqr-sqrt44.5%
fabs-sqr44.5%
add-sqr-sqrt57.8%
Applied egg-rr57.8%
associate-*l/57.8%
*-un-lft-identity57.8%
Applied egg-rr57.8%
Final simplification57.8%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 4.999999999099794e-24) (/ 1.0 (* s (+ (/ x (* s (/ s x))) 4.0))) (/ (/ 1.0 s) (+ 4.0 (/ (* x x) (* s s))))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 4.999999999099794e-24f) {
tmp = 1.0f / (s * ((x / (s * (s / x))) + 4.0f));
} else {
tmp = (1.0f / s) / (4.0f + ((x * x) / (s * s)));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 4.999999999099794e-24) then
tmp = 1.0e0 / (s * ((x / (s * (s / x))) + 4.0e0))
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) / (s * s)))
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(4.999999999099794e-24)) tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(x / Float32(s * Float32(s / x))) + Float32(4.0)))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(4.999999999099794e-24)) tmp = single(1.0) / (s * ((x / (s * (s / x))) + single(4.0))); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) / (s * s))); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.999999999099794 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s \cdot \frac{s}{x}} + 4\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if x < 5e-24Initial program 99.5%
Simplified99.8%
Taylor expanded in s around inf 55.2%
unpow255.2%
sqr-abs55.2%
unpow255.2%
distribute-lft1-in55.2%
metadata-eval55.2%
mul0-lft77.0%
metadata-eval77.0%
Simplified77.0%
clear-num77.0%
inv-pow77.0%
Applied egg-rr77.0%
unpow-177.0%
unpow277.0%
associate-/l*75.3%
unpow275.3%
Simplified75.3%
expm1-log1p-u73.1%
expm1-udef78.5%
associate-/r/78.5%
fma-def78.5%
associate-/l*79.1%
Applied egg-rr79.1%
expm1-def73.7%
expm1-log1p76.1%
associate-/l/76.1%
*-commutative76.1%
fma-udef76.1%
associate-*l/76.1%
*-lft-identity76.1%
associate-/l/79.8%
Simplified79.8%
if 5e-24 < x Initial program 99.8%
Simplified99.7%
Taylor expanded in s around inf 59.3%
unpow259.3%
sqr-abs59.3%
unpow259.3%
distribute-lft1-in59.3%
metadata-eval59.3%
mul0-lft85.0%
metadata-eval85.0%
Simplified85.0%
Final simplification82.0%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ 1.0 (* s (+ (/ x (* s (/ s x))) 4.0))))
x = abs(x);
float code(float x, float s) {
return 1.0f / (s * ((x / (s * (s / x))) + 4.0f));
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * ((x / (s * (s / x))) + 4.0e0))
end function
x = abs(x) function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(x / Float32(s * Float32(s / x))) + Float32(4.0)))) end
x = abs(x) function tmp = code(x, s) tmp = single(1.0) / (s * ((x / (s * (s / x))) + single(4.0))); end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{s \cdot \left(\frac{x}{s \cdot \frac{s}{x}} + 4\right)}
\end{array}
Initial program 99.7%
Simplified99.8%
Taylor expanded in s around inf 56.9%
unpow256.9%
sqr-abs56.9%
unpow256.9%
distribute-lft1-in56.9%
metadata-eval56.9%
mul0-lft80.3%
metadata-eval80.3%
Simplified80.3%
clear-num80.3%
inv-pow80.3%
Applied egg-rr80.3%
unpow-180.3%
unpow280.3%
associate-/l*76.7%
unpow276.7%
Simplified76.7%
expm1-log1p-u75.2%
expm1-udef81.8%
associate-/r/81.8%
fma-def81.8%
associate-/l*82.2%
Applied egg-rr82.2%
expm1-def75.5%
expm1-log1p77.2%
associate-/l/77.2%
*-commutative77.2%
fma-udef77.2%
associate-*l/77.2%
*-lft-identity77.2%
associate-/l/79.4%
Simplified79.4%
Final simplification79.4%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 9.999999747378752e-5) (/ 0.25 s) (/ 1.0 (* x (/ x s)))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 9.999999747378752e-5f) {
tmp = 0.25f / s;
} else {
tmp = 1.0f / (x * (x / s));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 9.999999747378752e-5) then
tmp = 0.25e0 / s
else
tmp = 1.0e0 / (x * (x / s))
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(9.999999747378752e-5)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(1.0) / Float32(x * Float32(x / s))); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(9.999999747378752e-5)) tmp = single(0.25) / s; else tmp = single(1.0) / (x * (x / s)); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\
\end{array}
\end{array}
if x < 9.99999975e-5Initial program 99.5%
Taylor expanded in s around inf 35.4%
if 9.99999975e-5 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in s around inf 46.8%
unpow246.8%
sqr-abs46.8%
unpow246.8%
distribute-lft1-in46.8%
metadata-eval46.8%
mul0-lft84.8%
metadata-eval84.8%
Simplified84.8%
Taylor expanded in s around 0 69.6%
unpow269.6%
Simplified69.6%
clear-num74.3%
inv-pow74.3%
associate-/l*74.3%
Applied egg-rr74.3%
unpow-174.3%
associate-/r/74.3%
Simplified74.3%
Final simplification46.2%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (if (<= x 9.999999747378752e-5) (/ 0.25 s) (/ s (* x x))))
x = abs(x);
float code(float x, float s) {
float tmp;
if (x <= 9.999999747378752e-5f) {
tmp = 0.25f / s;
} else {
tmp = s / (x * x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 9.999999747378752e-5) then
tmp = 0.25e0 / s
else
tmp = s / (x * x)
end if
code = tmp
end function
x = abs(x) function code(x, s) tmp = Float32(0.0) if (x <= Float32(9.999999747378752e-5)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(s / Float32(x * x)); end return tmp end
x = abs(x) function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(9.999999747378752e-5)) tmp = single(0.25) / s; else tmp = s / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < 9.99999975e-5Initial program 99.5%
Taylor expanded in s around inf 35.4%
if 9.99999975e-5 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in s around inf 46.8%
unpow246.8%
sqr-abs46.8%
unpow246.8%
distribute-lft1-in46.8%
metadata-eval46.8%
mul0-lft84.8%
metadata-eval84.8%
Simplified84.8%
Taylor expanded in s around 0 69.6%
unpow269.6%
Simplified69.6%
Final simplification44.9%
NOTE: x should be positive before calling this function (FPCore (x s) :precision binary32 (/ 0.25 s))
x = abs(x);
float code(float x, float s) {
return 0.25f / s;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.25e0 / s
end function
x = abs(x) function code(x, s) return Float32(Float32(0.25) / s) end
x = abs(x) function tmp = code(x, s) tmp = single(0.25) / s; end
\begin{array}{l}
x = |x|\\
\\
\frac{0.25}{s}
\end{array}
Initial program 99.7%
Taylor expanded in s around inf 26.8%
Final simplification26.8%
herbie shell --seed 2023252
(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))))))