
(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}
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (fabs x) (- s)))) (t_1 (+ t_0 1.0))) (/ t_0 (* s (* t_1 t_1)))))
float code(float x, float s) {
float t_0 = expf((fabsf(x) / -s));
float t_1 = t_0 + 1.0f;
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 = t_0 + 1.0e0
code = t_0 / (s * (t_1 * t_1))
end function
function code(x, s) t_0 = exp(Float32(abs(x) / Float32(-s))) t_1 = Float32(t_0 + Float32(1.0)) return Float32(t_0 / Float32(s * Float32(t_1 * t_1))) end
function tmp = code(x, s) t_0 = exp((abs(x) / -s)); t_1 = t_0 + single(1.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 := t\_0 + 1\\
\frac{t\_0}{s \cdot \left(t\_1 \cdot t\_1\right)}
\end{array}
\end{array}
Initial program 98.9%
fabs-neg98.9%
distribute-frac-neg98.9%
distribute-frac-neg298.9%
fabs-neg98.9%
*-commutative98.9%
fabs-neg98.9%
+-commutative98.9%
fabs-neg98.9%
Simplified99.0%
Final simplification99.0%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x (- s))))) (/ (/ t_0 (+ 1.0 t_0)) (+ s (/ s (exp (/ x s)))))))
float code(float x, float s) {
float t_0 = expf((x / -s));
return (t_0 / (1.0f + t_0)) / (s + (s / expf((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((x / -s))
code = (t_0 / (1.0e0 + t_0)) / (s + (s / exp((x / s))))
end function
function code(x, s) t_0 = exp(Float32(x / Float32(-s))) return Float32(Float32(t_0 / Float32(Float32(1.0) + t_0)) / Float32(s + Float32(s / exp(Float32(x / s))))) end
function tmp = code(x, s) t_0 = exp((x / -s)); tmp = (t_0 / (single(1.0) + t_0)) / (s + (s / exp((x / s)))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{-s}}\\
\frac{\frac{t\_0}{1 + t\_0}}{s + \frac{s}{e^{\frac{x}{s}}}}
\end{array}
\end{array}
Initial program 98.9%
Simplified98.9%
Taylor expanded in x around 0 98.9%
associate-/r*99.0%
Simplified61.3%
Final simplification61.3%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x (- s))))) (/ (/ t_0 s) (pow (+ 1.0 t_0) 2.0))))
float code(float x, float s) {
float t_0 = expf((x / -s));
return (t_0 / s) / powf((1.0f + t_0), 2.0f);
}
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
function code(x, s) t_0 = exp(Float32(x / Float32(-s))) return Float32(Float32(t_0 / s) / (Float32(Float32(1.0) + t_0) ^ Float32(2.0))) end
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}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{-s}}\\
\frac{\frac{t\_0}{s}}{{\left(1 + t\_0\right)}^{2}}
\end{array}
\end{array}
Initial program 98.9%
fabs-neg98.9%
distribute-frac-neg98.9%
distribute-frac-neg298.9%
fabs-neg98.9%
*-commutative98.9%
fabs-neg98.9%
+-commutative98.9%
fabs-neg98.9%
Simplified99.0%
Taylor expanded in x around 0 99.0%
associate-/r*98.9%
exp-prod98.9%
rem-square-sqrt48.1%
fabs-sqr48.1%
rem-square-sqrt60.4%
exp-prod60.4%
neg-mul-160.4%
distribute-neg-frac260.4%
Simplified61.3%
Final simplification61.3%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x (- s))))) (/ (/ t_0 (+ 1.0 t_0)) (+ s (/ s (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float t_0 = expf((x / -s));
return (t_0 / (1.0f + t_0)) / (s + (s / (1.0f + (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((x / -s))
code = (t_0 / (1.0e0 + t_0)) / (s + (s / (1.0e0 + (x / s))))
end function
function code(x, s) t_0 = exp(Float32(x / Float32(-s))) return Float32(Float32(t_0 / Float32(Float32(1.0) + t_0)) / Float32(s + Float32(s / Float32(Float32(1.0) + Float32(x / s))))) end
function tmp = code(x, s) t_0 = exp((x / -s)); tmp = (t_0 / (single(1.0) + t_0)) / (s + (s / (single(1.0) + (x / s)))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{-s}}\\
\frac{\frac{t\_0}{1 + t\_0}}{s + \frac{s}{1 + \frac{x}{s}}}
\end{array}
\end{array}
Initial program 98.9%
Simplified98.9%
Taylor expanded in x around 0 98.9%
associate-/r*99.0%
Simplified61.3%
Taylor expanded in x around 0 58.5%
+-commutative58.5%
Simplified58.5%
Final simplification58.5%
(FPCore (x s) :precision binary32 (/ (/ 1.0 (+ 1.0 (exp (/ x s)))) (+ s (/ s (+ 1.0 (/ x s))))))
float code(float x, float s) {
return (1.0f / (1.0f + expf((x / s)))) / (s + (s / (1.0f + (x / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / (1.0e0 + exp((x / s)))) / (s + (s / (1.0e0 + (x / s))))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(x / s)))) / Float32(s + Float32(s / Float32(Float32(1.0) + Float32(x / s))))) end
function tmp = code(x, s) tmp = (single(1.0) / (single(1.0) + exp((x / s)))) / (s + (s / (single(1.0) + (x / s)))); end
\begin{array}{l}
\\
\frac{\frac{1}{1 + e^{\frac{x}{s}}}}{s + \frac{s}{1 + \frac{x}{s}}}
\end{array}
Initial program 98.9%
Simplified98.9%
Taylor expanded in x around 0 98.9%
associate-/r*99.0%
Simplified61.3%
Taylor expanded in x around 0 58.5%
+-commutative58.5%
Simplified58.5%
distribute-frac-neg258.5%
rec-exp58.5%
Applied egg-rr58.5%
Taylor expanded in x around inf 58.5%
distribute-rgt-in22.3%
*-lft-identity22.3%
mul-1-neg22.3%
rec-exp22.3%
lft-mult-inverse60.1%
+-commutative60.1%
Simplified60.1%
Final simplification60.1%
(FPCore (x s) :precision binary32 (/ (/ (exp (/ x (- s))) s) (+ 4.0 (/ (* x -4.0) s))))
float code(float x, float s) {
return (expf((x / -s)) / s) / (4.0f + ((x * -4.0f) / s));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (exp((x / -s)) / s) / (4.0e0 + ((x * (-4.0e0)) / s))
end function
function code(x, s) return Float32(Float32(exp(Float32(x / Float32(-s))) / s) / Float32(Float32(4.0) + Float32(Float32(x * Float32(-4.0)) / s))) end
function tmp = code(x, s) tmp = (exp((x / -s)) / s) / (single(4.0) + ((x * single(-4.0)) / s)); end
\begin{array}{l}
\\
\frac{\frac{e^{\frac{x}{-s}}}{s}}{4 + \frac{x \cdot -4}{s}}
\end{array}
Initial program 98.9%
fabs-neg98.9%
distribute-frac-neg98.9%
distribute-frac-neg298.9%
fabs-neg98.9%
*-commutative98.9%
fabs-neg98.9%
+-commutative98.9%
fabs-neg98.9%
Simplified99.0%
Taylor expanded in x around 0 99.0%
associate-/r*98.9%
exp-prod98.9%
rem-square-sqrt48.1%
fabs-sqr48.1%
rem-square-sqrt60.4%
exp-prod60.4%
neg-mul-160.4%
distribute-neg-frac260.4%
Simplified61.3%
Taylor expanded in x around 0 58.6%
associate-*r/58.6%
*-commutative58.6%
Simplified58.6%
(FPCore (x s) :precision binary32 (/ (/ (exp (/ x (- s))) s) 4.0))
float code(float x, float s) {
return (expf((x / -s)) / s) / 4.0f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (exp((x / -s)) / s) / 4.0e0
end function
function code(x, s) return Float32(Float32(exp(Float32(x / Float32(-s))) / s) / Float32(4.0)) end
function tmp = code(x, s) tmp = (exp((x / -s)) / s) / single(4.0); end
\begin{array}{l}
\\
\frac{\frac{e^{\frac{x}{-s}}}{s}}{4}
\end{array}
Initial program 98.9%
fabs-neg98.9%
distribute-frac-neg98.9%
distribute-frac-neg298.9%
fabs-neg98.9%
*-commutative98.9%
fabs-neg98.9%
+-commutative98.9%
fabs-neg98.9%
Simplified99.0%
Taylor expanded in x around 0 99.0%
associate-/r*98.9%
exp-prod98.9%
rem-square-sqrt48.1%
fabs-sqr48.1%
rem-square-sqrt60.4%
exp-prod60.4%
neg-mul-160.4%
distribute-neg-frac260.4%
Simplified61.3%
Taylor expanded in x around 0 58.6%
associate-*r/58.6%
*-commutative58.6%
Simplified58.6%
Taylor expanded in x around 0 58.0%
(FPCore (x s) :precision binary32 (if (<= s 2.9999998795923744e-13) (/ (/ 1.0 s) (+ 4.0 (* x (/ -4.0 s)))) (/ (+ 0.5 (/ (* x -0.25) s)) (+ (* s 2.0) (* x (+ (* (/ x s) 0.5) -1.0))))))
float code(float x, float s) {
float tmp;
if (s <= 2.9999998795923744e-13f) {
tmp = (1.0f / s) / (4.0f + (x * (-4.0f / s)));
} else {
tmp = (0.5f + ((x * -0.25f) / s)) / ((s * 2.0f) + (x * (((x / s) * 0.5f) + -1.0f)));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (s <= 2.9999998795923744e-13) then
tmp = (1.0e0 / s) / (4.0e0 + (x * ((-4.0e0) / s)))
else
tmp = (0.5e0 + ((x * (-0.25e0)) / s)) / ((s * 2.0e0) + (x * (((x / s) * 0.5e0) + (-1.0e0))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (s <= Float32(2.9999998795923744e-13)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(x * Float32(Float32(-4.0) / s)))); else tmp = Float32(Float32(Float32(0.5) + Float32(Float32(x * Float32(-0.25)) / s)) / Float32(Float32(s * Float32(2.0)) + Float32(x * Float32(Float32(Float32(x / s) * Float32(0.5)) + Float32(-1.0))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (s <= single(2.9999998795923744e-13)) tmp = (single(1.0) / s) / (single(4.0) + (x * (single(-4.0) / s))); else tmp = (single(0.5) + ((x * single(-0.25)) / s)) / ((s * single(2.0)) + (x * (((x / s) * single(0.5)) + single(-1.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 2.9999998795923744 \cdot 10^{-13}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + x \cdot \frac{-4}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 + \frac{x \cdot -0.25}{s}}{s \cdot 2 + x \cdot \left(\frac{x}{s} \cdot 0.5 + -1\right)}\\
\end{array}
\end{array}
if s < 2.99999988e-13Initial program 98.5%
fabs-neg98.5%
distribute-frac-neg98.5%
distribute-frac-neg298.5%
fabs-neg98.5%
*-commutative98.5%
fabs-neg98.5%
+-commutative98.5%
fabs-neg98.5%
Simplified98.6%
Taylor expanded in x around 0 98.6%
associate-/r*98.6%
exp-prod98.6%
rem-square-sqrt48.2%
fabs-sqr48.2%
rem-square-sqrt56.8%
exp-prod56.8%
neg-mul-156.8%
distribute-neg-frac256.8%
Simplified56.9%
Taylor expanded in x around 0 55.5%
associate-*r/55.5%
*-commutative55.5%
Simplified55.5%
Taylor expanded in x around 0 49.9%
Taylor expanded in x around 0 49.9%
associate-*r/49.9%
*-commutative49.9%
associate-*r/50.5%
Simplified50.5%
if 2.99999988e-13 < s Initial program 99.6%
Simplified99.5%
Taylor expanded in x around 0 99.5%
associate-/r*99.6%
Simplified69.9%
Taylor expanded in x around 0 66.8%
associate-*r/66.8%
Simplified66.8%
Taylor expanded in x around 0 63.8%
Final simplification54.9%
(FPCore (x s) :precision binary32 (if (<= s 2.9999998795923744e-13) (/ (/ 1.0 s) (+ 4.0 (* x (/ -4.0 s)))) (/ (+ 0.5 (/ (* x -0.25) s)) (+ s (+ s (* x (+ (* (/ x s) 0.5) -1.0)))))))
float code(float x, float s) {
float tmp;
if (s <= 2.9999998795923744e-13f) {
tmp = (1.0f / s) / (4.0f + (x * (-4.0f / s)));
} else {
tmp = (0.5f + ((x * -0.25f) / s)) / (s + (s + (x * (((x / s) * 0.5f) + -1.0f))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (s <= 2.9999998795923744e-13) then
tmp = (1.0e0 / s) / (4.0e0 + (x * ((-4.0e0) / s)))
else
tmp = (0.5e0 + ((x * (-0.25e0)) / s)) / (s + (s + (x * (((x / s) * 0.5e0) + (-1.0e0)))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (s <= Float32(2.9999998795923744e-13)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(x * Float32(Float32(-4.0) / s)))); else tmp = Float32(Float32(Float32(0.5) + Float32(Float32(x * Float32(-0.25)) / s)) / Float32(s + Float32(s + Float32(x * Float32(Float32(Float32(x / s) * Float32(0.5)) + Float32(-1.0)))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (s <= single(2.9999998795923744e-13)) tmp = (single(1.0) / s) / (single(4.0) + (x * (single(-4.0) / s))); else tmp = (single(0.5) + ((x * single(-0.25)) / s)) / (s + (s + (x * (((x / s) * single(0.5)) + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;s \leq 2.9999998795923744 \cdot 10^{-13}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + x \cdot \frac{-4}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 + \frac{x \cdot -0.25}{s}}{s + \left(s + x \cdot \left(\frac{x}{s} \cdot 0.5 + -1\right)\right)}\\
\end{array}
\end{array}
if s < 2.99999988e-13Initial program 98.5%
fabs-neg98.5%
distribute-frac-neg98.5%
distribute-frac-neg298.5%
fabs-neg98.5%
*-commutative98.5%
fabs-neg98.5%
+-commutative98.5%
fabs-neg98.5%
Simplified98.6%
Taylor expanded in x around 0 98.6%
associate-/r*98.6%
exp-prod98.6%
rem-square-sqrt48.2%
fabs-sqr48.2%
rem-square-sqrt56.8%
exp-prod56.8%
neg-mul-156.8%
distribute-neg-frac256.8%
Simplified56.9%
Taylor expanded in x around 0 55.5%
associate-*r/55.5%
*-commutative55.5%
Simplified55.5%
Taylor expanded in x around 0 49.9%
Taylor expanded in x around 0 49.9%
associate-*r/49.9%
*-commutative49.9%
associate-*r/50.5%
Simplified50.5%
if 2.99999988e-13 < s Initial program 99.6%
Simplified99.5%
Taylor expanded in x around 0 99.5%
associate-/r*99.6%
Simplified69.9%
Taylor expanded in x around 0 66.8%
associate-*r/66.8%
Simplified66.8%
Taylor expanded in x around 0 63.7%
Final simplification54.9%
(FPCore (x s) :precision binary32 (if (<= x 2.0) (/ 0.25 s) (/ (/ 1.0 s) (* (/ x s) -4.0))))
float code(float x, float s) {
float tmp;
if (x <= 2.0f) {
tmp = 0.25f / s;
} else {
tmp = (1.0f / s) / ((x / s) * -4.0f);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 2.0e0) then
tmp = 0.25e0 / s
else
tmp = (1.0e0 / s) / ((x / s) * (-4.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(2.0)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(x / s) * Float32(-4.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(2.0)) tmp = single(0.25) / s; else tmp = (single(1.0) / s) / ((x / s) * single(-4.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{x}{s} \cdot -4}\\
\end{array}
\end{array}
if x < 2Initial program 98.6%
fabs-neg98.6%
distribute-frac-neg98.6%
distribute-frac-neg298.6%
fabs-neg98.6%
*-commutative98.6%
fabs-neg98.6%
+-commutative98.6%
fabs-neg98.6%
Simplified98.7%
Taylor expanded in s around inf 31.8%
if 2 < 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%
associate-/r*100.0%
exp-prod100.0%
rem-square-sqrt100.0%
fabs-sqr100.0%
rem-square-sqrt100.0%
exp-prod100.0%
neg-mul-1100.0%
distribute-neg-frac2100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
associate-*r/100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 54.9%
Taylor expanded in x around inf 54.9%
*-commutative54.9%
Simplified54.9%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ 4.0 (* x (/ -4.0 s)))))
float code(float x, float s) {
return (1.0f / s) / (4.0f + (x * (-4.0f / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (4.0e0 + (x * ((-4.0e0) / s)))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(x * Float32(Float32(-4.0) / s)))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (single(4.0) + (x * (single(-4.0) / s))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{4 + x \cdot \frac{-4}{s}}
\end{array}
Initial program 98.9%
fabs-neg98.9%
distribute-frac-neg98.9%
distribute-frac-neg298.9%
fabs-neg98.9%
*-commutative98.9%
fabs-neg98.9%
+-commutative98.9%
fabs-neg98.9%
Simplified99.0%
Taylor expanded in x around 0 99.0%
associate-/r*98.9%
exp-prod98.9%
rem-square-sqrt48.1%
fabs-sqr48.1%
rem-square-sqrt60.4%
exp-prod60.4%
neg-mul-160.4%
distribute-neg-frac260.4%
Simplified61.3%
Taylor expanded in x around 0 58.6%
associate-*r/58.6%
*-commutative58.6%
Simplified58.6%
Taylor expanded in x around 0 49.9%
Taylor expanded in x around 0 49.9%
associate-*r/49.9%
*-commutative49.9%
associate-*r/50.2%
Simplified50.2%
(FPCore (x s) :precision binary32 (if (<= x 2.0) (/ 0.25 s) (/ -0.25 x)))
float code(float x, float s) {
float tmp;
if (x <= 2.0f) {
tmp = 0.25f / s;
} else {
tmp = -0.25f / x;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 2.0e0) then
tmp = 0.25e0 / s
else
tmp = (-0.25e0) / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(2.0)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(-0.25) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(2.0)) tmp = single(0.25) / s; else tmp = single(-0.25) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.25}{x}\\
\end{array}
\end{array}
if x < 2Initial program 98.6%
fabs-neg98.6%
distribute-frac-neg98.6%
distribute-frac-neg298.6%
fabs-neg98.6%
*-commutative98.6%
fabs-neg98.6%
+-commutative98.6%
fabs-neg98.6%
Simplified98.7%
Taylor expanded in s around inf 31.8%
if 2 < 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%
associate-/r*100.0%
exp-prod100.0%
rem-square-sqrt100.0%
fabs-sqr100.0%
rem-square-sqrt100.0%
exp-prod100.0%
neg-mul-1100.0%
distribute-neg-frac2100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
associate-*r/100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 54.9%
Taylor expanded in s around 0 11.0%
(FPCore (x s) :precision binary32 (/ -0.25 x))
float code(float x, float s) {
return -0.25f / x;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (-0.25e0) / x
end function
function code(x, s) return Float32(Float32(-0.25) / x) end
function tmp = code(x, s) tmp = single(-0.25) / x; end
\begin{array}{l}
\\
\frac{-0.25}{x}
\end{array}
Initial program 98.9%
fabs-neg98.9%
distribute-frac-neg98.9%
distribute-frac-neg298.9%
fabs-neg98.9%
*-commutative98.9%
fabs-neg98.9%
+-commutative98.9%
fabs-neg98.9%
Simplified99.0%
Taylor expanded in x around 0 99.0%
associate-/r*98.9%
exp-prod98.9%
rem-square-sqrt48.1%
fabs-sqr48.1%
rem-square-sqrt60.4%
exp-prod60.4%
neg-mul-160.4%
distribute-neg-frac260.4%
Simplified61.3%
Taylor expanded in x around 0 58.6%
associate-*r/58.6%
*-commutative58.6%
Simplified58.6%
Taylor expanded in x around 0 49.9%
Taylor expanded in s around 0 9.0%
herbie shell --seed 2024143
(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))))))