
(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 15 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 (/ 1.0 (+ 1.0 (pow (exp (* (/ x s) 0.5)) -2.0))))
float code(float x, float s) {
return 1.0f / (1.0f + powf(expf(((x / s) * 0.5f)), -2.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (1.0e0 + (exp(((x / s) * 0.5e0)) ** (-2.0e0)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(Float32(x / s) * Float32(0.5))) ^ Float32(-2.0)))) end
function tmp = code(x, s) tmp = single(1.0) / (single(1.0) + (exp(((x / s) * single(0.5))) ^ single(-2.0))); end
\begin{array}{l}
\\
\frac{1}{1 + {\left(e^{\frac{x}{s} \cdot 0.5}\right)}^{-2}}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
inv-pow99.8%
add-sqr-sqrt99.9%
unpow-prod-down99.9%
Applied egg-rr99.9%
pow-sqr99.9%
metadata-eval99.9%
Simplified99.9%
pow1/299.9%
pow-exp99.9%
Applied egg-rr99.9%
(FPCore (x s) :precision binary32 (if (<= x -1.000000031374395e-22) (/ (/ (pow s 2.0) (- s)) x) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -1.000000031374395e-22f) {
tmp = (powf(s, 2.0f) / -s) / x;
} else {
tmp = 1.0f / (1.0f + (1.0f / (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 <= (-1.000000031374395e-22)) then
tmp = ((s ** 2.0e0) / -s) / x
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.000000031374395e-22)) tmp = Float32(Float32((s ^ Float32(2.0)) / Float32(-s)) / x); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-1.000000031374395e-22)) tmp = ((s ^ single(2.0)) / -s) / x; else tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;\frac{\frac{{s}^{2}}{-s}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -1.00000003e-22Initial program 99.9%
Taylor expanded in x around 0 47.2%
neg-mul-147.2%
unsub-neg47.2%
Simplified47.2%
Taylor expanded in x around inf 36.7%
associate-*r/36.7%
neg-mul-136.7%
Simplified36.7%
neg-sub036.7%
flip--54.4%
metadata-eval54.4%
pow254.4%
add-sqr-sqrt54.4%
sqrt-unprod12.7%
sqr-neg12.7%
sqrt-unprod-0.0%
add-sqr-sqrt53.0%
sub-neg53.0%
neg-sub053.0%
add-sqr-sqrt-0.0%
sqrt-unprod12.7%
sqr-neg12.7%
sqrt-unprod54.4%
add-sqr-sqrt54.4%
Applied egg-rr54.4%
neg-sub054.4%
Simplified54.4%
if -1.00000003e-22 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 94.4%
+-commutative94.4%
Simplified94.4%
Final simplification78.3%
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (+ 1.0 (expm1 (/ x (- s)))))))
float code(float x, float s) {
return 1.0f / (1.0f + (1.0f + expm1f((x / -s))));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) + expm1(Float32(x / Float32(-s)))))) end
\begin{array}{l}
\\
\frac{1}{1 + \left(1 + \mathsf{expm1}\left(\frac{x}{-s}\right)\right)}
\end{array}
Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
inv-pow99.8%
pow-exp99.8%
*-commutative99.8%
pow-exp99.8%
expm1-log1p-u99.8%
log1p-define99.8%
expm1-undefine99.8%
add-exp-log99.8%
pow-exp99.8%
*-commutative99.8%
pow-exp99.8%
inv-pow99.8%
rec-exp99.8%
distribute-neg-frac299.8%
Applied egg-rr99.8%
associate--l+99.8%
expm1-define99.9%
Simplified99.9%
(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(x / Float32(-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.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (if (<= x -1.000000031374395e-22) (/ 1.0 (* x (* (- (* s 2.0) x) (/ 1.0 (* x s))))) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
float tmp;
if (x <= -1.000000031374395e-22f) {
tmp = 1.0f / (x * (((s * 2.0f) - x) * (1.0f / (x * s))));
} else {
tmp = 1.0f / (1.0f + (1.0f / (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 <= (-1.000000031374395e-22)) then
tmp = 1.0e0 / (x * (((s * 2.0e0) - x) * (1.0e0 / (x * s))))
else
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-1.000000031374395e-22)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) * Float32(Float32(1.0) / Float32(x * s))))); else tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-1.000000031374395e-22)) tmp = single(1.0) / (x * (((s * single(2.0)) - x) * (single(1.0) / (x * s)))); else tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;\frac{1}{x \cdot \left(\left(s \cdot 2 - x\right) \cdot \frac{1}{x \cdot s}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\end{array}
\end{array}
if x < -1.00000003e-22Initial program 99.9%
Taylor expanded in x around 0 47.2%
neg-mul-147.2%
unsub-neg47.2%
Simplified47.2%
Taylor expanded in x around inf 47.1%
associate-*r/47.1%
metadata-eval47.1%
Simplified47.1%
frac-sub51.6%
div-inv54.0%
*-rgt-identity54.0%
Applied egg-rr54.0%
if -1.00000003e-22 < x Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 94.4%
+-commutative94.4%
Simplified94.4%
Final simplification78.2%
(FPCore (x s) :precision binary32 (if (<= (- x) 2.4999999718165057e-27) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if (-x <= 2.4999999718165057e-27f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / (x * (((s * 2.0f) - x) / (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 <= 2.4999999718165057e-27) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / (x * (((s * 2.0e0) - x) / (x * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(2.4999999718165057e-27)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) / Float32(x * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(2.4999999718165057e-27)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / (x * (((s * single(2.0)) - x) / (x * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 2.4999999718165057 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot 2 - x}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 2.49999997e-27Initial program 99.8%
distribute-frac-neg99.8%
exp-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 96.0%
+-commutative96.0%
Simplified96.0%
if 2.49999997e-27 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 48.2%
neg-mul-148.2%
unsub-neg48.2%
Simplified48.2%
Taylor expanded in x around inf 48.1%
associate-*r/48.1%
metadata-eval48.1%
Simplified48.1%
frac-sub52.9%
*-rgt-identity52.9%
Applied egg-rr52.9%
Final simplification77.4%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.000000023742228e-33) (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s))))) (/ 1.0 (+ (- 3.0 (/ x s)) -1.0))))
float code(float x, float s) {
float tmp;
if (-x <= -1.000000023742228e-33f) {
tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
} else {
tmp = 1.0f / ((3.0f - (x / s)) + -1.0f);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= (-1.000000023742228e-33)) then
tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
else
tmp = 1.0e0 / ((3.0e0 - (x / s)) + (-1.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-1.000000023742228e-33)) tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(Float32(Float32(3.0) - Float32(x / s)) + Float32(-1.0))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-1.000000023742228e-33)) tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s)))); else tmp = single(1.0) / ((single(3.0) - (x / s)) + single(-1.0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -1.000000023742228 \cdot 10^{-33}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(3 - \frac{x}{s}\right) + -1}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.00000002e-33Initial program 99.9%
distribute-frac-neg99.9%
exp-neg99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 96.3%
+-commutative96.3%
Simplified96.3%
if -1.00000002e-33 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 57.9%
neg-mul-157.9%
unsub-neg57.9%
Simplified57.9%
expm1-log1p-u57.8%
Applied egg-rr57.8%
expm1-undefine57.8%
sub-neg57.8%
log1p-undefine57.8%
rem-exp-log57.9%
associate-+r-57.9%
metadata-eval57.9%
metadata-eval57.9%
Simplified57.9%
Final simplification75.5%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.5000000601271012e-26) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (+ 2.0 (* x (/ -1.0 s))))))
float code(float x, float s) {
float tmp;
if (-x <= -1.5000000601271012e-26f) {
tmp = 1.0f / (x * (2.0f / x));
} else {
tmp = 1.0f / (2.0f + (x * (-1.0f / 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.5000000601271012e-26)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / (2.0e0 + (x * ((-1.0e0) / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-1.5000000601271012e-26)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); else tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(x * Float32(Float32(-1.0) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(-1.5000000601271012e-26)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / (single(2.0) + (x * (single(-1.0) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -1.5000000601271012 \cdot 10^{-26}:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.50000006e-26Initial program 99.9%
Taylor expanded in x around 0 12.8%
neg-mul-112.8%
unsub-neg12.8%
Simplified12.8%
Taylor expanded in x around inf 12.8%
associate-*r/12.8%
metadata-eval12.8%
Simplified12.8%
Taylor expanded in x around 0 32.8%
if -1.50000006e-26 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 59.4%
neg-mul-159.4%
unsub-neg59.4%
Simplified59.4%
clear-num59.4%
associate-/r/59.4%
Applied egg-rr59.4%
Final simplification48.4%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.5000000601271012e-26) (/ 1.0 (* x (/ 2.0 x))) (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -1.5000000601271012e-26f) {
tmp = 1.0f / (x * (2.0f / x));
} 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 <= (-1.5000000601271012e-26)) then
tmp = 1.0e0 / (x * (2.0e0 / x))
else
tmp = 1.0e0 / (2.0e0 - (x / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(-1.5000000601271012e-26)) tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(2.0) / x))); 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 <= single(-1.5000000601271012e-26)) tmp = single(1.0) / (x * (single(2.0) / x)); else tmp = single(1.0) / (single(2.0) - (x / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq -1.5000000601271012 \cdot 10^{-26}:\\
\;\;\;\;\frac{1}{x \cdot \frac{2}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.50000006e-26Initial program 99.9%
Taylor expanded in x around 0 12.8%
neg-mul-112.8%
unsub-neg12.8%
Simplified12.8%
Taylor expanded in x around inf 12.8%
associate-*r/12.8%
metadata-eval12.8%
Simplified12.8%
Taylor expanded in x around 0 32.8%
if -1.50000006e-26 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 59.4%
neg-mul-159.4%
unsub-neg59.4%
Simplified59.4%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.004999999888241291) 0.5 (/ 1.0 (* x (/ -1.0 s)))))
float code(float x, float s) {
float tmp;
if (-x <= 0.004999999888241291f) {
tmp = 0.5f;
} else {
tmp = 1.0f / (x * (-1.0f / s));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (-x <= 0.004999999888241291e0) then
tmp = 0.5e0
else
tmp = 1.0e0 / (x * ((-1.0e0) / s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(0.004999999888241291)) tmp = Float32(0.5); else tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(-1.0) / s))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(0.004999999888241291)) tmp = single(0.5); else tmp = single(1.0) / (x * (single(-1.0) / s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 0.004999999888241291:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{-1}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 0.00499999989Initial program 99.8%
Taylor expanded in x around 0 45.2%
if 0.00499999989 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 51.6%
neg-mul-151.6%
unsub-neg51.6%
Simplified51.6%
Taylor expanded in x around inf 51.6%
associate-*r/51.6%
metadata-eval51.6%
Simplified51.6%
Taylor expanded in x around inf 51.6%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.004999999888241291) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 0.004999999888241291f) {
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 <= 0.004999999888241291e0) 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(-x) <= Float32(0.004999999888241291)) 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 <= single(0.004999999888241291)) tmp = single(0.5); else tmp = single(-1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 0.004999999888241291:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 0.00499999989Initial program 99.8%
Taylor expanded in x around 0 45.2%
if 0.00499999989 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 51.6%
neg-mul-151.6%
unsub-neg51.6%
Simplified51.6%
Taylor expanded in x around inf 51.6%
mul-1-neg51.6%
distribute-frac-neg251.6%
Simplified51.6%
Final simplification47.1%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.009999999776482582) 0.5 (/ 1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 0.009999999776482582f) {
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 <= 0.009999999776482582e0) 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(-x) <= Float32(0.009999999776482582)) 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 <= single(0.009999999776482582)) tmp = single(0.5); else tmp = single(1.0) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 0.009999999776482582:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 0.00999999978Initial program 99.8%
Taylor expanded in x around 0 45.1%
if 0.00999999978 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 52.1%
neg-mul-152.1%
unsub-neg52.1%
Simplified52.1%
Taylor expanded in x around inf 46.7%
associate-*r/46.7%
neg-mul-146.7%
Simplified46.7%
clear-num52.1%
inv-pow52.1%
add-sqr-sqrt-0.0%
sqrt-unprod61.1%
sqr-neg61.1%
sqrt-unprod52.1%
add-sqr-sqrt52.1%
Applied egg-rr52.1%
unpow-152.1%
Simplified52.1%
(FPCore (x s) :precision binary32 (if (<= x -0.004999999888241291) (/ (- s) x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.004999999888241291f) {
tmp = -s / x;
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-0.004999999888241291e0)) then
tmp = -s / x
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.004999999888241291)) tmp = Float32(Float32(-s) / x); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.004999999888241291)) tmp = -s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.004999999888241291:\\
\;\;\;\;\frac{-s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.00499999989Initial program 100.0%
Taylor expanded in x around 0 51.6%
neg-mul-151.6%
unsub-neg51.6%
Simplified51.6%
Taylor expanded in x around inf 46.3%
associate-*r/46.3%
neg-mul-146.3%
Simplified46.3%
if -0.00499999989 < x Initial program 99.8%
Taylor expanded in x around 0 45.2%
(FPCore (x s) :precision binary32 (if (<= x -0.019999999552965164) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.019999999552965164f) {
tmp = s / x;
} else {
tmp = 0.5f;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-0.019999999552965164e0)) then
tmp = s / x
else
tmp = 0.5e0
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.019999999552965164)) tmp = Float32(s / x); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.019999999552965164)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.019999999552965164:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.0199999996Initial program 100.0%
Taylor expanded in x around 0 52.1%
neg-mul-152.1%
unsub-neg52.1%
Simplified52.1%
Taylor expanded in x around inf 46.7%
associate-*r/46.7%
neg-mul-146.7%
Simplified46.7%
add-sqr-sqrt-0.0%
sqrt-unprod59.0%
sqr-neg59.0%
sqrt-unprod46.7%
add-sqr-sqrt46.7%
*-un-lft-identity46.7%
Applied egg-rr46.7%
*-lft-identity46.7%
Simplified46.7%
if -0.0199999996 < x Initial program 99.8%
Taylor expanded in x around 0 45.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.8%
Taylor expanded in x around 0 33.9%
herbie shell --seed 2024139
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))