
(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 14 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 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.3%
Simplified99.5%
Final simplification99.5%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (exp (/ (fabs x) s)) (+ (exp (/ (- x) s)) 2.0))))
float code(float x, float s) {
return (1.0f / s) / (expf((fabsf(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((abs(x) / s)) + (exp((-x / s)) + 2.0e0))
end function
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
function tmp = code(x, s) tmp = (single(1.0) / s) / (exp((abs(x) / s)) + (exp((-x / s)) + single(2.0))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{-x}{s}} + 2\right)}
\end{array}
Initial program 99.4%
Simplified99.5%
remove-double-neg59.1%
distribute-frac-neg59.1%
frac-2neg59.1%
exp-neg59.1%
div-inv59.1%
exp-prod57.1%
add-sqr-sqrt57.1%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod30.1%
add-sqr-sqrt86.5%
exp-prod96.3%
div-inv96.3%
add-sqr-sqrt45.7%
fabs-sqr45.7%
add-sqr-sqrt56.0%
add-sqr-sqrt-0.0%
sqrt-unprod96.0%
sqr-neg96.0%
sqrt-unprod99.5%
add-sqr-sqrt99.5%
Applied egg-rr98.2%
rec-exp99.5%
distribute-neg-frac99.5%
Simplified98.2%
Final simplification98.2%
(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 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.3%
Simplified99.5%
fma-udef99.5%
Applied egg-rr59.1%
remove-double-neg59.1%
distribute-frac-neg59.1%
frac-2neg59.1%
exp-neg59.1%
div-inv59.1%
exp-prod57.1%
add-sqr-sqrt57.1%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod30.1%
add-sqr-sqrt86.5%
exp-prod96.3%
div-inv96.3%
add-sqr-sqrt45.7%
fabs-sqr45.7%
add-sqr-sqrt56.0%
add-sqr-sqrt-0.0%
sqrt-unprod96.0%
sqr-neg96.0%
sqrt-unprod99.5%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x s) :precision binary32 (/ 1.0 (* s (* (+ 1.0 (exp (/ x s))) (+ 1.0 (exp (/ (- x) s)))))))
float code(float x, float s) {
return 1.0f / (s * ((1.0f + 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 * ((1.0e0 + exp((x / s))) * (1.0e0 + exp((-x / s)))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(1.0) + exp(Float32(x / s))) * Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * ((single(1.0) + exp((x / s))) * (single(1.0) + exp((-x / s))))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(\left(1 + e^{\frac{x}{s}}\right) \cdot \left(1 + e^{\frac{-x}{s}}\right)\right)}
\end{array}
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.3%
Simplified99.5%
fma-udef99.5%
Applied egg-rr59.1%
remove-double-neg59.1%
distribute-frac-neg59.1%
frac-2neg59.1%
exp-neg59.1%
div-inv59.1%
exp-prod57.1%
add-sqr-sqrt57.1%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod30.1%
add-sqr-sqrt86.5%
exp-prod96.3%
div-inv96.3%
add-sqr-sqrt45.7%
fabs-sqr45.7%
add-sqr-sqrt56.0%
add-sqr-sqrt-0.0%
sqrt-unprod96.0%
sqr-neg96.0%
sqrt-unprod99.5%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
rec-exp99.5%
distribute-neg-frac99.5%
Simplified99.5%
Taylor expanded in s around 0 99.4%
Taylor expanded in x around inf 99.4%
associate-*r*99.4%
+-commutative99.4%
*-commutative99.4%
mul-1-neg99.4%
distribute-frac-neg99.4%
associate-*l*99.4%
Simplified99.4%
Final simplification99.4%
(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 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.3%
Simplified99.5%
fma-udef99.5%
Applied egg-rr59.1%
remove-double-neg59.1%
distribute-frac-neg59.1%
frac-2neg59.1%
exp-neg59.1%
div-inv59.1%
exp-prod57.1%
add-sqr-sqrt57.1%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod30.1%
add-sqr-sqrt86.5%
exp-prod96.3%
div-inv96.3%
add-sqr-sqrt45.7%
fabs-sqr45.7%
add-sqr-sqrt56.0%
add-sqr-sqrt-0.0%
sqrt-unprod96.0%
sqr-neg96.0%
sqrt-unprod99.5%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
rec-exp99.5%
distribute-neg-frac99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x s) :precision binary32 (/ 1.0 (* (+ s (* s (exp (/ x s)))) (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
return 1.0f / ((s + (s * expf((x / s)))) * (1.0f + (1.0f / (1.0f + (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 + (1.0e0 / (1.0e0 + (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) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / ((s + (s * exp((x / s)))) * (single(1.0) + (single(1.0) / (single(1.0) + (x / s))))); end
\begin{array}{l}
\\
\frac{1}{\left(s + s \cdot e^{\frac{x}{s}}\right) \cdot \left(1 + \frac{1}{1 + \frac{x}{s}}\right)}
\end{array}
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.3%
Simplified99.5%
fma-udef99.5%
Applied egg-rr59.1%
remove-double-neg59.1%
distribute-frac-neg59.1%
frac-2neg59.1%
exp-neg59.1%
div-inv59.1%
exp-prod57.1%
add-sqr-sqrt57.1%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod30.1%
add-sqr-sqrt86.5%
exp-prod96.3%
div-inv96.3%
add-sqr-sqrt45.7%
fabs-sqr45.7%
add-sqr-sqrt56.0%
add-sqr-sqrt-0.0%
sqrt-unprod96.0%
sqr-neg96.0%
sqrt-unprod99.5%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 57.9%
Final simplification57.9%
(FPCore (x s) :precision binary32 (/ 1.0 (* s (+ 2.0 (* 2.0 (exp (/ x s)))))))
float code(float x, float s) {
return 1.0f / (s * (2.0f + (2.0f * expf((x / s)))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * (2.0e0 + (2.0e0 * exp((x / s)))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(2.0) + Float32(Float32(2.0) * exp(Float32(x / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * (single(2.0) + (single(2.0) * exp((x / s))))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(2 + 2 \cdot e^{\frac{x}{s}}\right)}
\end{array}
Initial program 99.4%
Simplified99.5%
expm1-log1p-u97.6%
expm1-udef97.6%
Applied egg-rr55.1%
expm1-def55.1%
expm1-log1p56.4%
associate-+r+56.4%
count-256.4%
Simplified56.4%
Taylor expanded in s around 0 56.4%
Final simplification56.4%
(FPCore (x s)
:precision binary32
(let* ((t_0 (+ (* 2.0 (/ x s)) 4.0)))
(if (<= x 1.9999999996399175e-23)
(/ (/ 1.0 s) (+ (/ x (* s (/ s x))) t_0))
(/ (/ 1.0 s) (+ t_0 (/ (* x x) (* s s)))))))
float code(float x, float s) {
float t_0 = (2.0f * (x / s)) + 4.0f;
float tmp;
if (x <= 1.9999999996399175e-23f) {
tmp = (1.0f / s) / ((x / (s * (s / x))) + t_0);
} else {
tmp = (1.0f / s) / (t_0 + ((x * x) / (s * s)));
}
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 = (2.0e0 * (x / s)) + 4.0e0
if (x <= 1.9999999996399175e-23) then
tmp = (1.0e0 / s) / ((x / (s * (s / x))) + t_0)
else
tmp = (1.0e0 / s) / (t_0 + ((x * x) / (s * s)))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(Float32(2.0) * Float32(x / s)) + Float32(4.0)) tmp = Float32(0.0) if (x <= Float32(1.9999999996399175e-23)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(x / Float32(s * Float32(s / x))) + t_0)); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(t_0 + Float32(Float32(x * x) / Float32(s * s)))); end return tmp end
function tmp_2 = code(x, s) t_0 = (single(2.0) * (x / s)) + single(4.0); tmp = single(0.0); if (x <= single(1.9999999996399175e-23)) tmp = (single(1.0) / s) / ((x / (s * (s / x))) + t_0); else tmp = (single(1.0) / s) / (t_0 + ((x * x) / (s * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \frac{x}{s} + 4\\
\mathbf{if}\;x \leq 1.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{x}{s \cdot \frac{s}{x}} + t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{t_0 + \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if x < 2e-23Initial program 99.1%
Simplified99.3%
expm1-log1p-u96.7%
expm1-udef96.7%
Applied egg-rr31.4%
expm1-def31.5%
expm1-log1p33.4%
associate-+r+33.4%
count-233.4%
Simplified33.4%
Taylor expanded in x around 0 54.5%
+-commutative54.5%
+-commutative54.5%
associate-+l+54.5%
unpow254.5%
unpow254.5%
times-frac53.4%
+-commutative53.4%
*-commutative53.4%
fma-def53.4%
Simplified53.4%
fma-udef53.4%
Applied egg-rr53.4%
clear-num53.4%
frac-times58.1%
*-un-lft-identity58.1%
Applied egg-rr58.1%
if 2e-23 < x Initial program 99.7%
Simplified99.9%
expm1-log1p-u99.0%
expm1-udef99.0%
Applied egg-rr95.3%
expm1-def95.3%
expm1-log1p95.5%
associate-+r+95.5%
count-295.5%
Simplified95.5%
Taylor expanded in x around 0 79.9%
+-commutative79.9%
+-commutative79.9%
associate-+l+79.9%
unpow279.9%
unpow279.9%
times-frac71.9%
+-commutative71.9%
*-commutative71.9%
fma-def71.9%
Simplified71.9%
fma-udef71.9%
Applied egg-rr71.9%
frac-times79.9%
Applied egg-rr79.9%
Final simplification66.2%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (/ x (* s (/ s x))) (+ (* 2.0 (/ x s)) 4.0))))
float code(float x, float s) {
return (1.0f / s) / ((x / (s * (s / x))) + ((2.0f * (x / s)) + 4.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / ((x / (s * (s / x))) + ((2.0e0 * (x / s)) + 4.0e0))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(x / Float32(s * Float32(s / x))) + Float32(Float32(Float32(2.0) * Float32(x / s)) + Float32(4.0)))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / ((x / (s * (s / x))) + ((single(2.0) * (x / s)) + single(4.0))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{\frac{x}{s \cdot \frac{s}{x}} + \left(2 \cdot \frac{x}{s} + 4\right)}
\end{array}
Initial program 99.4%
Simplified99.5%
expm1-log1p-u97.6%
expm1-udef97.6%
Applied egg-rr55.1%
expm1-def55.1%
expm1-log1p56.4%
associate-+r+56.4%
count-256.4%
Simplified56.4%
Taylor expanded in x around 0 63.9%
+-commutative63.9%
+-commutative63.9%
associate-+l+63.9%
unpow263.9%
unpow263.9%
times-frac60.3%
+-commutative60.3%
*-commutative60.3%
fma-def60.3%
Simplified60.3%
fma-udef60.3%
Applied egg-rr60.3%
clear-num60.3%
frac-times64.3%
*-un-lft-identity64.3%
Applied egg-rr64.3%
Final simplification64.3%
(FPCore (x s) :precision binary32 (if (<= s 1.400000027358074e-24) (/ (/ 1.0 s) (/ (* x x) (* s s))) (/ (/ 1.0 s) (+ 4.0 (* (/ x s) (+ 2.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (s <= 1.400000027358074e-24f) {
tmp = (1.0f / s) / ((x * x) / (s * s));
} else {
tmp = (1.0f / s) / (4.0f + ((x / s) * (2.0f + (x / s))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (s <= 1.400000027358074e-24) then
tmp = (1.0e0 / s) / ((x * x) / (s * s))
else
tmp = (1.0e0 / s) / (4.0e0 + ((x / s) * (2.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (s <= Float32(1.400000027358074e-24)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(x * x) / Float32(s * s))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(Float32(2.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (s <= single(1.400000027358074e-24)) tmp = (single(1.0) / s) / ((x * x) / (s * s)); else tmp = (single(1.0) / s) / (single(4.0) + ((x / s) * (single(2.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 1.400000027358074 \cdot 10^{-24}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{x \cdot x}{s \cdot s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \left(2 + \frac{x}{s}\right)}\\
\end{array}
\end{array}
if s < 1.40000003e-24Initial program 98.7%
Simplified98.8%
expm1-log1p-u97.6%
expm1-udef97.6%
Applied egg-rr46.7%
expm1-def46.7%
expm1-log1p47.1%
associate-+r+47.1%
count-247.1%
Simplified47.1%
Taylor expanded in x around 0 59.1%
+-commutative59.1%
+-commutative59.1%
associate-+l+59.1%
unpow259.1%
unpow259.1%
times-frac47.7%
+-commutative47.7%
*-commutative47.7%
fma-def47.7%
Simplified47.7%
fma-udef47.7%
Applied egg-rr47.7%
Taylor expanded in x around inf 77.4%
unpow277.4%
unpow277.4%
Simplified77.4%
if 1.40000003e-24 < s Initial program 99.7%
Simplified99.9%
expm1-log1p-u97.6%
expm1-udef97.6%
Applied egg-rr59.9%
expm1-def60.0%
expm1-log1p61.7%
associate-+r+61.7%
count-261.7%
Simplified61.7%
Taylor expanded in x around 0 66.6%
+-commutative66.6%
+-commutative66.6%
associate-+l+66.6%
unpow266.6%
unpow266.6%
times-frac67.4%
+-commutative67.4%
*-commutative67.4%
fma-def67.4%
Simplified67.4%
Taylor expanded in x around 0 66.6%
+-commutative66.6%
unpow266.6%
unpow266.6%
times-frac67.4%
unpow267.4%
*-commutative67.4%
associate-+l+67.4%
unpow267.4%
times-frac66.6%
unpow266.6%
unpow266.6%
*-commutative66.6%
+-commutative66.6%
unpow266.6%
unpow266.6%
times-frac67.4%
distribute-rgt-out79.7%
Simplified79.7%
Final simplification78.9%
(FPCore (x s) :precision binary32 (if (<= x 1.999999936531045e-20) (/ 0.25 s) (/ (/ 1.0 s) (/ (* x x) (* s s)))))
float code(float x, float s) {
float tmp;
if (x <= 1.999999936531045e-20f) {
tmp = 0.25f / s;
} else {
tmp = (1.0f / s) / ((x * x) / (s * 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.999999936531045e-20) then
tmp = 0.25e0 / s
else
tmp = (1.0e0 / s) / ((x * x) / (s * s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(1.999999936531045e-20)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(x * x) / Float32(s * s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(1.999999936531045e-20)) tmp = single(0.25) / s; else tmp = (single(1.0) / s) / ((x * x) / (s * s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.999999936531045 \cdot 10^{-20}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if x < 1.99999994e-20Initial program 99.2%
Taylor expanded in s around inf 33.7%
if 1.99999994e-20 < x Initial program 99.7%
Simplified99.9%
expm1-log1p-u99.2%
expm1-udef99.2%
Applied egg-rr95.7%
expm1-def95.7%
expm1-log1p95.8%
associate-+r+95.8%
count-295.8%
Simplified95.8%
Taylor expanded in x around 0 80.4%
+-commutative80.4%
+-commutative80.4%
associate-+l+80.4%
unpow280.4%
unpow280.4%
times-frac73.0%
+-commutative73.0%
*-commutative73.0%
fma-def73.0%
Simplified73.0%
fma-udef73.0%
Applied egg-rr73.0%
Taylor expanded in x around inf 70.2%
unpow270.2%
unpow270.2%
Simplified70.2%
Final simplification46.5%
(FPCore (x s) :precision binary32 (if (<= x 0.0005000000237487257) (/ 0.25 s) (/ s (* x x))))
float code(float x, float s) {
float tmp;
if (x <= 0.0005000000237487257f) {
tmp = 0.25f / 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 <= 0.0005000000237487257e0) then
tmp = 0.25e0 / s
else
tmp = s / (x * x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.0005000000237487257)) tmp = Float32(Float32(0.25) / 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(0.0005000000237487257)) tmp = single(0.25) / s; else tmp = s / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0005000000237487257:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < 5.00000024e-4Initial program 99.2%
Taylor expanded in s around inf 35.3%
if 5.00000024e-4 < x Initial program 99.9%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef99.9%
Applied egg-rr98.8%
expm1-def98.8%
expm1-log1p98.8%
associate-+r+98.8%
count-298.8%
Simplified98.8%
Taylor expanded in x around 0 82.1%
+-commutative82.1%
+-commutative82.1%
associate-+l+82.1%
unpow282.1%
unpow282.1%
times-frac82.1%
+-commutative82.1%
*-commutative82.1%
fma-def82.1%
Simplified82.1%
Taylor expanded in s around 0 65.8%
unpow265.8%
Simplified65.8%
Final simplification42.5%
(FPCore (x s) :precision binary32 (if (<= x 0.09600000083446503) (/ 0.25 s) (/ 0.5 x)))
float code(float x, float s) {
float tmp;
if (x <= 0.09600000083446503f) {
tmp = 0.25f / s;
} else {
tmp = 0.5f / 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.09600000083446503e0) then
tmp = 0.25e0 / s
else
tmp = 0.5e0 / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.09600000083446503)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(0.5) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.09600000083446503)) tmp = single(0.25) / s; else tmp = single(0.5) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.09600000083446503:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < 0.0960000008Initial program 99.2%
Taylor expanded in s around inf 34.9%
if 0.0960000008 < x Initial program 99.9%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef99.9%
Applied egg-rr98.8%
expm1-def98.8%
expm1-log1p98.8%
associate-+r+98.8%
count-298.8%
Simplified98.8%
Taylor expanded in x around 0 45.7%
Taylor expanded in s around 0 11.2%
Final simplification29.6%
(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 28.2%
Final simplification28.2%
herbie shell --seed 2023257
(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))))))