
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-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)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
return 1.0f / (1.0f + expf((-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)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp((-x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (- (/ x s)))))))
float code(float x, float s) {
return expf(-log1pf(expf(-(x / s))));
}
function code(x, s) return exp(Float32(-log1p(exp(Float32(-Float32(x / s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}
\end{array}
Initial program 99.9%
inv-powN/A
pow-to-expN/A
*-commutativeN/A
log-powN/A
inv-powN/A
exp-lowering-exp.f32N/A
log-recN/A
neg-lowering-neg.f32N/A
accelerator-lowering-log1p.f32N/A
exp-lowering-exp.f32N/A
distribute-frac-negN/A
neg-lowering-neg.f32N/A
/-lowering-/.f3299.9
Applied egg-rr99.9%
(FPCore (x s) :precision binary32 (if (<= (exp (- (/ x s))) 4.0) 0.5 (* s (/ -1.0 x))))
float code(float x, float s) {
float tmp;
if (expf(-(x / s)) <= 4.0f) {
tmp = 0.5f;
} else {
tmp = s * (-1.0f / x);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (exp(-(x / s)) <= 4.0e0) then
tmp = 0.5e0
else
tmp = s * ((-1.0e0) / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (exp(Float32(-Float32(x / s))) <= Float32(4.0)) tmp = Float32(0.5); else tmp = Float32(s * Float32(Float32(-1.0) / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (exp(-(x / s)) <= single(4.0)) tmp = single(0.5); else tmp = s * (single(-1.0) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-\frac{x}{s}} \leq 4:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;s \cdot \frac{-1}{x}\\
\end{array}
\end{array}
if (exp.f32 (/.f32 (neg.f32 x) s)) < 4Initial program 99.8%
Taylor expanded in x around 0
Simplified55.5%
if 4 < (exp.f32 (/.f32 (neg.f32 x) s)) Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f3239.1
Simplified39.1%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f32N/A
mul-1-negN/A
neg-lowering-neg.f3233.9
Simplified33.9%
div-invN/A
*-commutativeN/A
*-lowering-*.f32N/A
metadata-evalN/A
frac-2negN/A
/-lowering-/.f3233.9
Applied egg-rr33.9%
Final simplification47.1%
(FPCore (x s) :precision binary32 (if (<= (exp (- (/ x s))) 4.0) 0.5 (/ s (- x))))
float code(float x, float s) {
float tmp;
if (expf(-(x / s)) <= 4.0f) {
tmp = 0.5f;
} else {
tmp = s / -x;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (exp(-(x / s)) <= 4.0e0) then
tmp = 0.5e0
else
tmp = s / -x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (exp(Float32(-Float32(x / s))) <= Float32(4.0)) tmp = Float32(0.5); else tmp = Float32(s / Float32(-x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (exp(-(x / s)) <= single(4.0)) tmp = single(0.5); else tmp = s / -x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-\frac{x}{s}} \leq 4:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{-x}\\
\end{array}
\end{array}
if (exp.f32 (/.f32 (neg.f32 x) s)) < 4Initial program 99.8%
Taylor expanded in x around 0
Simplified55.5%
if 4 < (exp.f32 (/.f32 (neg.f32 x) s)) Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f3239.1
Simplified39.1%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f32N/A
mul-1-negN/A
neg-lowering-neg.f3233.9
Simplified33.9%
Final simplification47.1%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (- (/ x s))))))
float code(float x, float s) {
return 1.0f / (1.0f + expf(-(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)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(-Float32(x / s))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + exp(-(x / s))); end
\begin{array}{l}
\\
\frac{1}{1 + e^{-\frac{x}{s}}}
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x s)
:precision binary32
(if (<= (- (/ x s)) -10.0)
0.5
(/
1.0
(fma
x
(fma (/ (fma (/ x s) -0.16666666666666666 0.5) s) (/ x s) (/ -1.0 s))
2.0))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= -10.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / fmaf(x, fmaf((fmaf((x / s), -0.16666666666666666f, 0.5f) / s), (x / s), (-1.0f / s)), 2.0f);
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(-10.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / fma(x, fma(Float32(fma(Float32(x / s), Float32(-0.16666666666666666), Float32(0.5)) / s), Float32(x / s), Float32(Float32(-1.0) / s)), Float32(2.0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq -10:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{x}{s}, -0.16666666666666666, 0.5\right)}{s}, \frac{x}{s}, \frac{-1}{s}\right), 2\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
Taylor expanded in x around 0
Simplified28.1%
if -10 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified89.2%
*-commutativeN/A
associate-*r/N/A
times-fracN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f3294.6
Applied egg-rr94.6%
Final simplification72.3%
(FPCore (x s)
:precision binary32
(let* ((t_0 (- (/ x s))))
(if (<= t_0 -10.0)
0.5
(if (<= t_0 99999997952.0)
(/ 1.0 (fma x (/ (fma (/ x s) 0.5 -1.0) s) 2.0))
(/ (* (* s (* s s)) -6.0) (* x (* x x)))))))
float code(float x, float s) {
float t_0 = -(x / s);
float tmp;
if (t_0 <= -10.0f) {
tmp = 0.5f;
} else if (t_0 <= 99999997952.0f) {
tmp = 1.0f / fmaf(x, (fmaf((x / s), 0.5f, -1.0f) / s), 2.0f);
} else {
tmp = ((s * (s * s)) * -6.0f) / (x * (x * x));
}
return tmp;
}
function code(x, s) t_0 = Float32(-Float32(x / s)) tmp = Float32(0.0) if (t_0 <= Float32(-10.0)) tmp = Float32(0.5); elseif (t_0 <= Float32(99999997952.0)) tmp = Float32(Float32(1.0) / fma(x, Float32(fma(Float32(x / s), Float32(0.5), Float32(-1.0)) / s), Float32(2.0))); else tmp = Float32(Float32(Float32(s * Float32(s * s)) * Float32(-6.0)) / Float32(x * Float32(x * x))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\frac{x}{s}\\
\mathbf{if}\;t\_0 \leq -10:\\
\;\;\;\;0.5\\
\mathbf{elif}\;t\_0 \leq 99999997952:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{\mathsf{fma}\left(\frac{x}{s}, 0.5, -1\right)}{s}, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(s \cdot \left(s \cdot s\right)\right) \cdot -6}{x \cdot \left(x \cdot x\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -10Initial program 100.0%
Taylor expanded in x around 0
Simplified28.1%
if -10 < (/.f32 (neg.f32 x) s) < 99999998000Initial program 99.6%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
accelerator-lowering-fma.f32N/A
Simplified82.8%
associate-*l/N/A
associate-/l*N/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f3288.2
Applied egg-rr88.2%
if 99999998000 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified99.0%
*-commutativeN/A
associate-*r/N/A
times-fracN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f3299.0
Applied egg-rr99.0%
Taylor expanded in x around inf
associate-*r/N/A
/-lowering-/.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3296.3
Simplified96.3%
Final simplification70.8%
(FPCore (x s)
:precision binary32
(if (<= (- x) 1.2000000072537151e-35)
0.5
(/
1.0
(fma
x
(fma
(/ x (* s s))
(fma x (* -0.16666666666666666 (/ 1.0 s)) 0.5)
(/ -1.0 s))
2.0))))
float code(float x, float s) {
float tmp;
if (-x <= 1.2000000072537151e-35f) {
tmp = 0.5f;
} else {
tmp = 1.0f / fmaf(x, fmaf((x / (s * s)), fmaf(x, (-0.16666666666666666f * (1.0f / s)), 0.5f), (-1.0f / s)), 2.0f);
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(1.2000000072537151e-35)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / fma(x, fma(Float32(x / Float32(s * s)), fma(x, Float32(Float32(-0.16666666666666666) * Float32(Float32(1.0) / s)), Float32(0.5)), Float32(Float32(-1.0) / s)), Float32(2.0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 1.2000000072537151 \cdot 10^{-35}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{x}{s \cdot s}, \mathsf{fma}\left(x, -0.16666666666666666 \cdot \frac{1}{s}, 0.5\right), \frac{-1}{s}\right), 2\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 1.20000001e-35Initial program 99.9%
Taylor expanded in x around 0
Simplified47.2%
if 1.20000001e-35 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified94.7%
*-commutativeN/A
div-invN/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f32N/A
/-lowering-/.f3294.7
Applied egg-rr94.7%
Final simplification71.3%
(FPCore (x s)
:precision binary32
(if (<= (- x) 1.2000000072537151e-35)
0.5
(/
1.0
(fma
x
(fma (/ x (* s s)) (fma -0.16666666666666666 (/ x s) 0.5) (/ -1.0 s))
2.0))))
float code(float x, float s) {
float tmp;
if (-x <= 1.2000000072537151e-35f) {
tmp = 0.5f;
} else {
tmp = 1.0f / fmaf(x, fmaf((x / (s * s)), fmaf(-0.16666666666666666f, (x / s), 0.5f), (-1.0f / s)), 2.0f);
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(1.2000000072537151e-35)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / fma(x, fma(Float32(x / Float32(s * s)), fma(Float32(-0.16666666666666666), Float32(x / s), Float32(0.5)), Float32(Float32(-1.0) / s)), Float32(2.0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 1.2000000072537151 \cdot 10^{-35}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \mathsf{fma}\left(\frac{x}{s \cdot s}, \mathsf{fma}\left(-0.16666666666666666, \frac{x}{s}, 0.5\right), \frac{-1}{s}\right), 2\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 1.20000001e-35Initial program 99.9%
Taylor expanded in x around 0
Simplified47.2%
if 1.20000001e-35 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified94.7%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 0.5) 0.5 (/ 1.0 (fma x (* x (/ (* x -0.16666666666666666) (* s (* s s)))) 2.0))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 0.5f) {
tmp = 0.5f;
} else {
tmp = 1.0f / fmaf(x, (x * ((x * -0.16666666666666666f) / (s * (s * s)))), 2.0f);
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(0.5)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / fma(x, Float32(x * Float32(Float32(x * Float32(-0.16666666666666666)) / Float32(s * Float32(s * s)))), Float32(2.0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 0.5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, x \cdot \frac{x \cdot -0.16666666666666666}{s \cdot \left(s \cdot s\right)}, 2\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 0.5Initial program 99.8%
Taylor expanded in x around 0
Simplified55.6%
if 0.5 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified94.2%
Taylor expanded in x around inf
associate-*r/N/A
/-lowering-/.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3290.8
Simplified90.8%
associate-*l*N/A
associate-/l*N/A
*-lowering-*.f32N/A
/-lowering-/.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f3295.8
Applied egg-rr95.8%
Final simplification71.3%
(FPCore (x s)
:precision binary32
(if (<= (- x) -1.500000029312222e-25)
0.5
(if (<= (- x) 2.0000000233721948e-7)
(/ 1.0 (fma x (/ (fma (/ x s) 0.5 -1.0) s) 2.0))
(/ (* (* (* s s) (* s s)) -18.0) (* x (* x (* x x)))))))
float code(float x, float s) {
float tmp;
if (-x <= -1.500000029312222e-25f) {
tmp = 0.5f;
} else if (-x <= 2.0000000233721948e-7f) {
tmp = 1.0f / fmaf(x, (fmaf((x / s), 0.5f, -1.0f) / s), 2.0f);
} else {
tmp = (((s * s) * (s * s)) * -18.0f) / (x * (x * (x * x)));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-1.500000029312222e-25)) tmp = Float32(0.5); elseif (Float32(-x) <= Float32(2.0000000233721948e-7)) tmp = Float32(Float32(1.0) / fma(x, Float32(fma(Float32(x / s), Float32(0.5), Float32(-1.0)) / s), Float32(2.0))); else tmp = Float32(Float32(Float32(Float32(s * s) * Float32(s * s)) * Float32(-18.0)) / Float32(x * Float32(x * Float32(x * x)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -1.500000029312222 \cdot 10^{-25}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;-x \leq 2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{\mathsf{fma}\left(\frac{x}{s}, 0.5, -1\right)}{s}, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(s \cdot s\right) \cdot \left(s \cdot s\right)\right) \cdot -18}{x \cdot \left(x \cdot \left(x \cdot x\right)\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.50000003e-25Initial program 99.9%
Taylor expanded in x around 0
Simplified37.0%
if -1.50000003e-25 < (neg.f32 x) < 2.00000002e-7Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
accelerator-lowering-fma.f32N/A
Simplified76.9%
associate-*l/N/A
associate-/l*N/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f3286.3
Applied egg-rr86.3%
if 2.00000002e-7 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified94.8%
*-commutativeN/A
associate-*r/N/A
times-fracN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f3294.8
Applied egg-rr94.8%
Taylor expanded in x around inf
/-lowering-/.f32N/A
Simplified94.3%
Taylor expanded in s around inf
associate-*r/N/A
/-lowering-/.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
metadata-evalN/A
pow-sqrN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
metadata-evalN/A
pow-plusN/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3296.2
Simplified96.2%
Final simplification71.1%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 1.0) 0.5 (/ (* (* s (* s s)) -6.0) (* x (* x x)))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 1.0f) {
tmp = 0.5f;
} else {
tmp = ((s * (s * s)) * -6.0f) / (x * (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 / s) <= 1.0e0) then
tmp = 0.5e0
else
tmp = ((s * (s * s)) * (-6.0e0)) / (x * (x * x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(s * Float32(s * s)) * Float32(-6.0)) / Float32(x * Float32(x * x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(1.0)) tmp = single(0.5); else tmp = ((s * (s * s)) * single(-6.0)) / (x * (x * x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(s \cdot \left(s \cdot s\right)\right) \cdot -6}{x \cdot \left(x \cdot x\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 1Initial program 99.8%
Taylor expanded in x around 0
Simplified55.5%
if 1 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified94.6%
*-commutativeN/A
associate-*r/N/A
times-fracN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f3292.8
Applied egg-rr92.8%
Taylor expanded in x around inf
associate-*r/N/A
/-lowering-/.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3286.0
Simplified86.0%
Final simplification67.3%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 1.0) 0.5 (/ (* s (* (* s s) -6.0)) (* x (* x x)))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 1.0f) {
tmp = 0.5f;
} else {
tmp = (s * ((s * s) * -6.0f)) / (x * (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 / s) <= 1.0e0) then
tmp = 0.5e0
else
tmp = (s * ((s * s) * (-6.0e0))) / (x * (x * x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(s * Float32(Float32(s * s) * Float32(-6.0))) / Float32(x * Float32(x * x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(1.0)) tmp = single(0.5); else tmp = (s * ((s * s) * single(-6.0))) / (x * (x * x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{s \cdot \left(\left(s \cdot s\right) \cdot -6\right)}{x \cdot \left(x \cdot x\right)}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 1Initial program 99.8%
Taylor expanded in x around 0
Simplified55.5%
if 1 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f32N/A
Simplified94.6%
Taylor expanded in x around inf
associate-*r/N/A
/-lowering-/.f32N/A
*-commutativeN/A
cube-multN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3286.0
Simplified86.0%
Final simplification67.3%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 1000.0) 0.5 (/ (* 2.0 (* s s)) (* x x))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 1000.0f) {
tmp = 0.5f;
} else {
tmp = (2.0f * (s * 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 / s) <= 1000.0e0) then
tmp = 0.5e0
else
tmp = (2.0e0 * (s * s)) / (x * x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(1000.0)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(2.0) * Float32(s * s)) / Float32(x * x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(1000.0)) tmp = single(0.5); else tmp = (single(2.0) * (s * s)) / (x * x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 1000:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \left(s \cdot s\right)}{x \cdot x}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 1e3Initial program 99.8%
Taylor expanded in x around 0
Simplified54.8%
if 1e3 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
accelerator-lowering-fma.f32N/A
Simplified72.0%
Taylor expanded in x around inf
associate-*r/N/A
/-lowering-/.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3277.2
Simplified77.2%
Final simplification63.3%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 500000000.0) 0.5 (* 2.0 (* s (/ s (* x x))))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 500000000.0f) {
tmp = 0.5f;
} else {
tmp = 2.0f * (s * (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 / s) <= 500000000.0e0) then
tmp = 0.5e0
else
tmp = 2.0e0 * (s * (s / (x * x)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(500000000.0)) tmp = Float32(0.5); else tmp = Float32(Float32(2.0) * Float32(s * Float32(s / Float32(x * x)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(500000000.0)) tmp = single(0.5); else tmp = single(2.0) * (s * (s / (x * x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 500000000:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(s \cdot \frac{s}{x \cdot x}\right)\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 5e8Initial program 99.8%
Taylor expanded in x around 0
Simplified52.8%
if 5e8 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
times-fracN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-outN/A
accelerator-lowering-fma.f32N/A
Simplified76.9%
Taylor expanded in x around inf
*-lowering-*.f32N/A
/-lowering-/.f3276.9
Simplified76.9%
Taylor expanded in x around inf
*-lowering-*.f32N/A
unpow2N/A
associate-/l*N/A
*-lowering-*.f32N/A
/-lowering-/.f32N/A
unpow2N/A
*-lowering-*.f3275.3
Simplified75.3%
Final simplification60.7%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) -1.0) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= -1.0f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (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 (-(x / s) <= (-1.0e0)) then
tmp = 0.5e0
else
tmp = 1.0e0 / (2.0e0 - (x / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(-1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(-1.0)) tmp = single(0.5); else tmp = single(1.0) / (single(2.0) - (x / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq -1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < -1Initial program 100.0%
Taylor expanded in x around 0
Simplified28.2%
if -1 < (/.f32 (neg.f32 x) s) Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f3262.4
Simplified62.4%
Final simplification50.8%
(FPCore (x s) :precision binary32 (if (<= (- (/ x s)) 1.0) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-(x / s) <= 1.0f) {
tmp = 0.5f;
} else {
tmp = -1.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 (-(x / s) <= 1.0e0) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-Float32(x / s)) <= Float32(1.0)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-(x / s) <= single(1.0)) tmp = single(0.5); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-\frac{x}{s} \leq 1:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (/.f32 (neg.f32 x) s) < 1Initial program 99.8%
Taylor expanded in x around 0
Simplified55.5%
if 1 < (/.f32 (neg.f32 x) s) Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f32N/A
/-lowering-/.f3239.1
Simplified39.1%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f32N/A
mul-1-negN/A
neg-lowering-neg.f3233.9
Simplified33.9%
clear-numN/A
metadata-evalN/A
distribute-frac-negN/A
frac-2negN/A
/-lowering-/.f32N/A
/-lowering-/.f3239.1
Applied egg-rr39.1%
Final simplification49.1%
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
return 0.5f;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0
end function
function code(x, s) return Float32(0.5) end
function tmp = code(x, s) tmp = single(0.5); end
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Simplified36.5%
herbie shell --seed 2024204
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))