
(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 (let* ((t_0 (exp (/ (fabs x) (- s))))) (/ t_0 (+ s (/ (* s (+ t_0 2.0)) (exp (/ (fabs x) s)))))))
float code(float x, float s) {
float t_0 = expf((fabsf(x) / -s));
return t_0 / (s + ((s * (t_0 + 2.0f)) / expf((fabsf(x) / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((abs(x) / -s))
code = t_0 / (s + ((s * (t_0 + 2.0e0)) / exp((abs(x) / s))))
end function
function code(x, s) t_0 = exp(Float32(abs(x) / Float32(-s))) return Float32(t_0 / Float32(s + Float32(Float32(s * Float32(t_0 + Float32(2.0))) / exp(Float32(abs(x) / s))))) end
function tmp = code(x, s) t_0 = exp((abs(x) / -s)); tmp = t_0 / (s + ((s * (t_0 + single(2.0))) / exp((abs(x) / s)))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{\left|x\right|}{-s}}\\
\frac{t_0}{s + \frac{s \cdot \left(t_0 + 2\right)}{e^{\frac{\left|x\right|}{s}}}}
\end{array}
\end{array}
Initial program 99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (* (+ 1.0 (log (exp (exp (/ (- (fabs x)) s))))) (+ s (* s (exp (/ (fabs x) s)))))))
float code(float x, float s) {
return 1.0f / ((1.0f + logf(expf(expf((-fabsf(x) / s))))) * (s + (s * expf((fabsf(x) / s)))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((1.0e0 + log(exp(exp((-abs(x) / s))))) * (s + (s * exp((abs(x) / s)))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + log(exp(exp(Float32(Float32(-abs(x)) / s))))) * Float32(s + Float32(s * exp(Float32(abs(x) / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / ((single(1.0) + log(exp(exp((-abs(x) / s))))) * (s + (s * exp((abs(x) / s))))); end
\begin{array}{l}
\\
\frac{1}{\left(1 + \log \left(e^{e^{\frac{-\left|x\right|}{s}}}\right)\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-frac-neg99.8%
add-log-exp99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (* s (* (+ 1.0 (exp (/ (- (fabs x)) s))) (+ (exp (/ (fabs x) s)) 1.0)))))
float code(float x, float s) {
return 1.0f / (s * ((1.0f + expf((-fabsf(x) / s))) * (expf((fabsf(x) / s)) + 1.0f)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * ((1.0e0 + exp((-abs(x) / s))) * (exp((abs(x) / s)) + 1.0e0)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(1.0) + exp(Float32(Float32(-abs(x)) / s))) * Float32(exp(Float32(abs(x) / s)) + Float32(1.0))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * ((single(1.0) + exp((-abs(x) / s))) * (exp((abs(x) / s)) + single(1.0)))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(e^{\frac{\left|x\right|}{s}} + 1\right)\right)}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in s around 0 99.8%
*-commutative99.8%
+-commutative99.8%
neg-mul-199.8%
distribute-frac-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (* (+ s (* s (exp (/ (fabs x) s)))) (+ 1.0 (exp (/ (- (fabs x)) s))))))
float code(float x, float s) {
return 1.0f / ((s + (s * expf((fabsf(x) / s)))) * (1.0f + expf((-fabsf(x) / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((s + (s * exp((abs(x) / s)))) * (1.0e0 + exp((-abs(x) / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(s + Float32(s * exp(Float32(abs(x) / s)))) * Float32(Float32(1.0) + exp(Float32(Float32(-abs(x)) / s))))) end
function tmp = code(x, s) tmp = single(1.0) / ((s + (s * exp((abs(x) / s)))) * (single(1.0) + exp((-abs(x) / s)))); end
\begin{array}{l}
\\
\frac{1}{\left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-frac-neg99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ (* (exp (fma -2.0 (log 2.0) 0.0)) (exp (* (/ x (/ s x)) (/ -0.25 s)))) s))
float code(float x, float s) {
return (expf(fmaf(-2.0f, logf(2.0f), 0.0f)) * expf(((x / (s / x)) * (-0.25f / s)))) / s;
}
function code(x, s) return Float32(Float32(exp(fma(Float32(-2.0), log(Float32(2.0)), Float32(0.0))) * exp(Float32(Float32(x / Float32(s / x)) * Float32(Float32(-0.25) / s)))) / s) end
\begin{array}{l}
\\
\frac{e^{\mathsf{fma}\left(-2, \log 2, 0\right)} \cdot e^{\frac{x}{\frac{s}{x}} \cdot \frac{-0.25}{s}}}{s}
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
add-exp-log98.1%
distribute-frac-neg98.1%
log-div98.1%
add-log-exp98.1%
distribute-frac-neg98.1%
*-commutative98.1%
log-prod97.5%
Applied egg-rr97.5%
associate--r+97.8%
exp-diff97.9%
Simplified99.8%
Taylor expanded in s around inf 58.5%
mul-1-neg58.5%
distribute-frac-neg58.5%
associate-+r+58.5%
+-commutative58.5%
associate-+r+58.5%
Simplified90.1%
exp-sum90.1%
times-frac94.1%
associate-/l*97.4%
Applied egg-rr97.4%
Final simplification97.4%
(FPCore (x s) :precision binary32 (/ (exp (fma (* (/ x s) (/ x s)) -0.25 (* -2.0 (log 2.0)))) s))
float code(float x, float s) {
return expf(fmaf(((x / s) * (x / s)), -0.25f, (-2.0f * logf(2.0f)))) / s;
}
function code(x, s) return Float32(exp(fma(Float32(Float32(x / s) * Float32(x / s)), Float32(-0.25), Float32(Float32(-2.0) * log(Float32(2.0))))) / s) end
\begin{array}{l}
\\
\frac{e^{\mathsf{fma}\left(\frac{x}{s} \cdot \frac{x}{s}, -0.25, -2 \cdot \log 2\right)}}{s}
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
add-exp-log98.1%
distribute-frac-neg98.1%
log-div98.1%
add-log-exp98.1%
distribute-frac-neg98.1%
*-commutative98.1%
log-prod97.5%
Applied egg-rr97.5%
associate--r+97.8%
exp-diff97.9%
Simplified99.8%
Taylor expanded in s around inf 58.5%
mul-1-neg58.5%
distribute-frac-neg58.5%
associate-+r+58.5%
+-commutative58.5%
associate-+r+58.5%
Simplified90.1%
Taylor expanded in x around inf 90.5%
sub-neg90.5%
exp-sum90.5%
distribute-lft-neg-in90.5%
metadata-eval90.5%
associate-*r/90.1%
*-commutative90.1%
unpow290.1%
associate-*r*90.1%
unpow290.1%
times-frac97.4%
associate-*r/97.4%
associate-*l*97.4%
associate-/r/97.4%
*-commutative97.4%
exp-sum97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (x s) :precision binary32 (if (<= (fabs x) 4.999999943633011e-27) (/ 1.0 (+ (* s 4.0) (* x (/ 1.0 (/ s x))))) (/ (exp (/ (- (fabs x)) s)) s)))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 4.999999943633011e-27f) {
tmp = 1.0f / ((s * 4.0f) + (x * (1.0f / (s / x))));
} else {
tmp = expf((-fabsf(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 (abs(x) <= 4.999999943633011e-27) then
tmp = 1.0e0 / ((s * 4.0e0) + (x * (1.0e0 / (s / x))))
else
tmp = exp((-abs(x) / s)) / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(4.999999943633011e-27)) tmp = Float32(Float32(1.0) / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(Float32(1.0) / Float32(s / x))))); else tmp = Float32(exp(Float32(Float32(-abs(x)) / s)) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (abs(x) <= single(4.999999943633011e-27)) tmp = single(1.0) / ((s * single(4.0)) + (x * (single(1.0) / (s / x)))); else tmp = exp((-abs(x) / s)) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 4.999999943633011 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{s \cdot 4 + x \cdot \frac{1}{\frac{s}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\
\end{array}
\end{array}
if (fabs.f32 x) < 4.99999994e-27Initial program 99.4%
Simplified99.5%
Taylor expanded in x around 0 99.7%
Taylor expanded in s around -inf 88.8%
+-commutative88.8%
mul-1-neg88.8%
distribute-lft1-in88.8%
metadata-eval88.8%
associate-*r/88.8%
mul-1-neg88.8%
remove-double-neg88.8%
associate-+r+88.8%
Simplified88.8%
add-exp-log88.8%
associate-/l*90.0%
Applied egg-rr90.0%
add-exp-log90.0%
div-inv90.0%
Applied egg-rr90.0%
if 4.99999994e-27 < (fabs.f32 x) Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
add-exp-log99.3%
distribute-frac-neg99.3%
log-div99.2%
add-log-exp99.2%
distribute-frac-neg99.2%
*-commutative99.2%
log-prod99.1%
Applied egg-rr99.1%
associate--r+99.2%
exp-diff99.2%
Simplified99.8%
Taylor expanded in s around 0 91.4%
mul-1-neg91.4%
distribute-frac-neg91.4%
Simplified91.4%
Final simplification91.2%
(FPCore (x s) :precision binary32 (/ 0.5 (fma s (exp (/ (fabs x) s)) s)))
float code(float x, float s) {
return 0.5f / fmaf(s, expf((fabsf(x) / s)), s);
}
function code(x, s) return Float32(Float32(0.5) / fma(s, exp(Float32(abs(x) / s)), s)) end
\begin{array}{l}
\\
\frac{0.5}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in s around inf 95.8%
Final simplification95.8%
(FPCore (x s)
:precision binary32
(let* ((t_0 (/ s (* x x))))
(if (<= (fabs x) 0.004999999888241291)
(/ 1.0 (* s (+ (* (/ x s) (/ x s)) 4.0)))
(cbrt (* t_0 (* t_0 t_0))))))
float code(float x, float s) {
float t_0 = s / (x * x);
float tmp;
if (fabsf(x) <= 0.004999999888241291f) {
tmp = 1.0f / (s * (((x / s) * (x / s)) + 4.0f));
} else {
tmp = cbrtf((t_0 * (t_0 * t_0)));
}
return tmp;
}
function code(x, s) t_0 = Float32(s / Float32(x * x)) tmp = Float32(0.0) if (abs(x) <= Float32(0.004999999888241291)) tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(x / s) * Float32(x / s)) + Float32(4.0)))); else tmp = cbrt(Float32(t_0 * Float32(t_0 * t_0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{s}{x \cdot x}\\
\mathbf{if}\;\left|x\right| \leq 0.004999999888241291:\\
\;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s} \cdot \frac{x}{s} + 4\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)}\\
\end{array}
\end{array}
if (fabs.f32 x) < 0.00499999989Initial program 99.4%
Simplified99.5%
Taylor expanded in s around 0 99.4%
*-commutative99.4%
+-commutative99.4%
neg-mul-199.4%
distribute-frac-neg99.4%
Simplified99.4%
Taylor expanded in s around -inf 45.8%
+-commutative45.8%
Simplified62.9%
if 0.00499999989 < (fabs.f32 x) Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 26.8%
+-commutative26.8%
mul-1-neg26.8%
distribute-lft1-in71.3%
metadata-eval71.3%
associate-*r/71.3%
mul-1-neg71.3%
remove-double-neg71.3%
associate-+r+71.3%
Simplified72.0%
Taylor expanded in s around 0 70.0%
unpow270.0%
Simplified70.0%
add-cbrt-cube96.2%
Applied egg-rr96.2%
associate-*l*96.2%
Simplified96.2%
Final simplification81.9%
(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 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in s around inf 95.5%
Final simplification95.5%
(FPCore (x s) :precision binary32 (let* ((t_0 (/ x (/ s x)))) (/ 1.0 (+ (* s 4.0) (cbrt (* t_0 (* t_0 t_0)))))))
float code(float x, float s) {
float t_0 = x / (s / x);
return 1.0f / ((s * 4.0f) + cbrtf((t_0 * (t_0 * t_0))));
}
function code(x, s) t_0 = Float32(x / Float32(s / x)) return Float32(Float32(1.0) / Float32(Float32(s * Float32(4.0)) + cbrt(Float32(t_0 * Float32(t_0 * t_0))))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{\frac{s}{x}}\\
\frac{1}{s \cdot 4 + \sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)}}
\end{array}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in s around -inf 39.2%
+-commutative39.2%
mul-1-neg39.2%
distribute-lft1-in64.6%
metadata-eval64.6%
associate-*r/64.6%
mul-1-neg64.6%
remove-double-neg64.6%
associate-+r+64.6%
Simplified65.0%
add-cbrt-cube81.7%
associate-/l*81.7%
associate-/l*81.7%
associate-/l*81.8%
Applied egg-rr81.8%
Final simplification81.8%
(FPCore (x s) :precision binary32 (/ 1.0 (* s (+ (* (/ x s) (/ x s)) 4.0))))
float code(float x, float s) {
return 1.0f / (s * (((x / s) * (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) * (x / s)) + 4.0e0))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(x / s) * Float32(x / s)) + Float32(4.0)))) end
function tmp = code(x, s) tmp = single(1.0) / (s * (((x / s) * (x / s)) + single(4.0))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(\frac{x}{s} \cdot \frac{x}{s} + 4\right)}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in s around 0 99.8%
*-commutative99.8%
+-commutative99.8%
neg-mul-199.8%
distribute-frac-neg99.8%
Simplified99.8%
Taylor expanded in s around -inf 20.6%
+-commutative20.6%
Simplified76.0%
Final simplification76.0%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (* s 4.0) (* x (/ x s)))))
float code(float x, float s) {
return 1.0f / ((s * 4.0f) + (x * (x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((s * 4.0e0) + (x * (x / s)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(s * Float32(4.0)) + Float32(x * Float32(x / s)))) end
function tmp = code(x, s) tmp = single(1.0) / ((s * single(4.0)) + (x * (x / s))); end
\begin{array}{l}
\\
\frac{1}{s \cdot 4 + x \cdot \frac{x}{s}}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in s around -inf 39.2%
+-commutative39.2%
mul-1-neg39.2%
distribute-lft1-in64.6%
metadata-eval64.6%
associate-*r/64.6%
mul-1-neg64.6%
remove-double-neg64.6%
associate-+r+64.6%
Simplified65.0%
expm1-log1p-u63.5%
expm1-udef82.7%
+-commutative82.7%
associate-/l*83.0%
+-rgt-identity83.0%
Applied egg-rr83.0%
expm1-def63.8%
expm1-log1p65.3%
associate-/r/65.3%
Simplified65.3%
Final simplification65.3%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (/ x (/ s x)) (* s 4.0))))
float code(float x, float s) {
return 1.0f / ((x / (s / x)) + (s * 4.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((x / (s / x)) + (s * 4.0e0))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(x / Float32(s / x)) + Float32(s * Float32(4.0)))) end
function tmp = code(x, s) tmp = single(1.0) / ((x / (s / x)) + (s * single(4.0))); end
\begin{array}{l}
\\
\frac{1}{\frac{x}{\frac{s}{x}} + s \cdot 4}
\end{array}
Initial program 99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in s around -inf 39.2%
+-commutative39.2%
mul-1-neg39.2%
distribute-lft1-in64.6%
metadata-eval64.6%
associate-*r/64.6%
mul-1-neg64.6%
remove-double-neg64.6%
associate-+r+64.6%
Simplified65.0%
*-un-lft-identity65.0%
+-commutative65.0%
associate-/l*65.3%
+-rgt-identity65.3%
Applied egg-rr65.3%
Final simplification65.3%
(FPCore (x s) :precision binary32 (if (<= x 0.00011999999696854502) (/ 0.25 s) (/ s (* x x))))
float code(float x, float s) {
float tmp;
if (x <= 0.00011999999696854502f) {
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.00011999999696854502e0) 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.00011999999696854502)) 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.00011999999696854502)) 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.00011999999696854502:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < 1.19999997e-4Initial program 99.6%
Simplified99.7%
Taylor expanded in s around inf 36.5%
if 1.19999997e-4 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in s around -inf 20.7%
+-commutative20.7%
mul-1-neg20.7%
distribute-lft1-in66.7%
metadata-eval66.7%
associate-*r/66.7%
mul-1-neg66.7%
remove-double-neg66.7%
associate-+r+66.7%
Simplified67.9%
Taylor expanded in s around 0 67.4%
unpow267.4%
Simplified67.4%
Final simplification47.0%
(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.8%
Simplified99.8%
Taylor expanded in s around inf 25.7%
Final simplification25.7%
herbie shell --seed 2023297
(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))))))