
(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 16 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(x / Float32(-s)))))) end
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{\frac{x}{-s}}\right)}
\end{array}
Initial program 99.7%
div-inv99.7%
exp-prod81.4%
neg-mul-181.4%
exp-prod81.4%
pow-pow99.7%
div-inv99.7%
Applied egg-rr99.7%
add-exp-log99.7%
log-rec99.7%
log1p-define99.8%
add-exp-log99.9%
pow-exp99.8%
rem-log-exp99.8%
neg-mul-199.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (pow (exp -1.0) (/ x s)) 1.0)))
float code(float x, float s) {
return 1.0f / (powf(expf(-1.0f), (x / s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((exp((-1.0e0)) ** (x / s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32((exp(Float32(-1.0)) ^ Float32(x / s)) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / ((exp(single(-1.0)) ^ (x / s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{{\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)} + 1}
\end{array}
Initial program 99.7%
div-inv99.7%
exp-prod81.4%
neg-mul-181.4%
exp-prod81.4%
pow-pow99.7%
div-inv99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (+ (exp (/ x (- s))) 1.0)))
float code(float x, float s) {
return 1.0f / (expf((x / -s)) + 1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (exp((x / -s)) + 1.0e0)
end function
function code(x, s) return Float32(Float32(1.0) / Float32(exp(Float32(x / Float32(-s))) + Float32(1.0))) end
function tmp = code(x, s) tmp = single(1.0) / (exp((x / -s)) + single(1.0)); end
\begin{array}{l}
\\
\frac{1}{e^{\frac{x}{-s}} + 1}
\end{array}
Initial program 99.7%
Final simplification99.7%
(FPCore (x s)
:precision binary32
(if (<= (- x) -1.4999999988791435e-32)
0.5
(if (<= (- x) 19999999961012896000.0)
(/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
(* (/ 1.0 (* x (- (* s 2.0) x))) (* x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -1.4999999988791435e-32f) {
tmp = 0.5f;
} else if (-x <= 19999999961012896000.0f) {
tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
} 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 <= (-1.4999999988791435e-32)) then
tmp = 0.5e0
else if (-x <= 19999999961012896000.0e0) then
tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
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(-1.4999999988791435e-32)) tmp = Float32(0.5); elseif (Float32(-x) <= Float32(19999999961012896000.0)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(x / s) + Float32(2.0)))); else tmp = Float32(Float32(Float32(1.0) / Float32(x * 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(-1.4999999988791435e-32)) tmp = single(0.5); elseif (-x <= single(19999999961012896000.0)) tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((x / s) + single(2.0))); 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 -1.4999999988791435 \cdot 10^{-32}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;-x \leq 19999999961012896000:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(s \cdot 2 - x\right)} \cdot \left(x \cdot s\right)\\
\end{array}
\end{array}
if (neg.f32 x) < -1.5e-32Initial program 99.9%
Taylor expanded in x around 0 35.1%
if -1.5e-32 < (neg.f32 x) < 2e19Initial program 99.4%
Taylor expanded in x around 0 53.3%
mul-1-neg53.3%
unsub-neg53.3%
Simplified53.3%
sub-neg53.3%
neg-mul-153.3%
rem-log-exp95.8%
pow-exp95.8%
flip-+40.3%
metadata-eval40.3%
pow-exp40.3%
rem-log-exp40.3%
neg-mul-140.3%
pow-exp40.3%
rem-log-exp41.2%
neg-mul-141.2%
pow-exp41.2%
rem-log-exp63.7%
neg-mul-163.7%
Applied egg-rr63.7%
if 2e19 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 81.9%
mul-1-neg81.9%
unsub-neg81.9%
Simplified81.9%
Taylor expanded in x around inf 81.9%
associate-*r/81.9%
metadata-eval81.9%
Simplified81.9%
associate-/r*79.4%
frac-sub79.4%
associate-/r/93.7%
*-rgt-identity93.7%
*-commutative93.7%
Applied egg-rr93.7%
associate-/l/100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Final simplification54.3%
(FPCore (x s) :precision binary32 (if (<= (- x) 5.000000136226006e-28) 0.5 (/ -1.0 (* x (* (- (* s 2.0) x) (/ (/ -1.0 x) s))))))
float code(float x, float s) {
float tmp;
if (-x <= 5.000000136226006e-28f) {
tmp = 0.5f;
} else {
tmp = -1.0f / (x * (((s * 2.0f) - x) * ((-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 <= 5.000000136226006e-28) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x * (((s * 2.0e0) - x) * (((-1.0e0) / x) / s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(5.000000136226006e-28)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) * Float32(Float32(Float32(-1.0) / x) / s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(5.000000136226006e-28)) tmp = single(0.5); else tmp = single(-1.0) / (x * (((s * single(2.0)) - x) * ((single(-1.0) / x) / s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 5.000000136226006 \cdot 10^{-28}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \left(\left(s \cdot 2 - x\right) \cdot \frac{\frac{-1}{x}}{s}\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 5.00000014e-28Initial program 99.7%
Taylor expanded in x around 0 44.8%
if 5.00000014e-28 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 50.1%
mul-1-neg50.1%
unsub-neg50.1%
Simplified50.1%
Taylor expanded in x around inf 50.0%
associate-*r/50.0%
metadata-eval50.0%
Simplified50.0%
frac-sub56.0%
div-inv57.7%
*-rgt-identity57.7%
*-commutative57.7%
Applied egg-rr57.7%
Taylor expanded in x around 0 57.7%
*-commutative57.7%
associate-/r*57.8%
Simplified57.8%
Final simplification50.0%
(FPCore (x s) :precision binary32 (if (<= (- x) 5.000000136226006e-28) 0.5 (/ -1.0 (* x (* (- (* s 2.0) x) (/ -1.0 (* x s)))))))
float code(float x, float s) {
float tmp;
if (-x <= 5.000000136226006e-28f) {
tmp = 0.5f;
} else {
tmp = -1.0f / (x * (((s * 2.0f) - x) * (-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 <= 5.000000136226006e-28) then
tmp = 0.5e0
else
tmp = (-1.0e0) / (x * (((s * 2.0e0) - x) * ((-1.0e0) / (x * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(5.000000136226006e-28)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(x * Float32(Float32(Float32(s * Float32(2.0)) - x) * Float32(Float32(-1.0) / Float32(x * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (-x <= single(5.000000136226006e-28)) tmp = single(0.5); else tmp = single(-1.0) / (x * (((s * single(2.0)) - x) * (single(-1.0) / (x * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 5.000000136226006 \cdot 10^{-28}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \left(\left(s \cdot 2 - x\right) \cdot \frac{-1}{x \cdot s}\right)}\\
\end{array}
\end{array}
if (neg.f32 x) < 5.00000014e-28Initial program 99.7%
Taylor expanded in x around 0 44.8%
if 5.00000014e-28 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 50.1%
mul-1-neg50.1%
unsub-neg50.1%
Simplified50.1%
Taylor expanded in x around inf 50.0%
associate-*r/50.0%
metadata-eval50.0%
Simplified50.0%
frac-sub56.0%
div-inv57.7%
*-rgt-identity57.7%
*-commutative57.7%
Applied egg-rr57.7%
Final simplification50.0%
(FPCore (x s) :precision binary32 (if (<= (- x) 1.000000031374395e-22) 0.5 (/ -1.0 (/ (* x (- x (* s 2.0))) (* x s)))))
float code(float x, float s) {
float tmp;
if (-x <= 1.000000031374395e-22f) {
tmp = 0.5f;
} else {
tmp = -1.0f / ((x * (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 (-x <= 1.000000031374395e-22) then
tmp = 0.5e0
else
tmp = (-1.0e0) / ((x * (x - (s * 2.0e0))) / (x * s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (Float32(-x) <= Float32(1.000000031374395e-22)) tmp = Float32(0.5); else tmp = Float32(Float32(-1.0) / Float32(Float32(x * Float32(x - Float32(s * Float32(2.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(0.5); else tmp = single(-1.0) / ((x * (x - (s * single(2.0)))) / (x * s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-x \leq 1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x \cdot \left(x - s \cdot 2\right)}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 1.00000003e-22Initial program 99.6%
Taylor expanded in x around 0 45.7%
if 1.00000003e-22 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 49.1%
mul-1-neg49.1%
unsub-neg49.1%
Simplified49.1%
Taylor expanded in x around inf 49.1%
associate-*r/49.1%
metadata-eval49.1%
Simplified49.1%
*-commutative49.1%
frac-sub52.0%
associate-*l/57.5%
*-rgt-identity57.5%
*-commutative57.5%
Applied egg-rr57.5%
Final simplification50.0%
(FPCore (x s) :precision binary32 (if (<= (- x) 5.000000136226006e-28) 0.5 (/ 1.0 (* x (/ (- (* s 2.0) x) (* x s))))))
float code(float x, float s) {
float tmp;
if (-x <= 5.000000136226006e-28f) {
tmp = 0.5f;
} 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 <= 5.000000136226006e-28) then
tmp = 0.5e0
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(5.000000136226006e-28)) tmp = Float32(0.5); 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(5.000000136226006e-28)) tmp = single(0.5); 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 5.000000136226006 \cdot 10^{-28}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{s \cdot 2 - x}{x \cdot s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 5.00000014e-28Initial program 99.7%
Taylor expanded in x around 0 44.8%
if 5.00000014e-28 < (neg.f32 x) Initial program 99.8%
Taylor expanded in x around 0 50.1%
mul-1-neg50.1%
unsub-neg50.1%
Simplified50.1%
Taylor expanded in x around inf 50.0%
associate-*r/50.0%
metadata-eval50.0%
Simplified50.0%
frac-sub56.0%
*-rgt-identity56.0%
*-commutative56.0%
Applied egg-rr56.0%
(FPCore (x s) :precision binary32 (if (<= (- x) 4.9999998413276127e-20) 0.5 (* (/ 1.0 (* x (- (* s 2.0) x))) (* x s))))
float code(float x, float s) {
float tmp;
if (-x <= 4.9999998413276127e-20f) {
tmp = 0.5f;
} 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 <= 4.9999998413276127e-20) then
tmp = 0.5e0
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(4.9999998413276127e-20)) tmp = Float32(0.5); else tmp = Float32(Float32(Float32(1.0) / Float32(x * 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(4.9999998413276127e-20)) tmp = single(0.5); 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 4.9999998413276127 \cdot 10^{-20}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(s \cdot 2 - x\right)} \cdot \left(x \cdot s\right)\\
\end{array}
\end{array}
if (neg.f32 x) < 4.99999984e-20Initial program 99.6%
Taylor expanded in x around 0 46.0%
if 4.99999984e-20 < (neg.f32 x) Initial program 99.9%
Taylor expanded in x around 0 48.7%
mul-1-neg48.7%
unsub-neg48.7%
Simplified48.7%
Taylor expanded in x around inf 48.7%
associate-*r/48.7%
metadata-eval48.7%
Simplified48.7%
associate-/r*45.5%
frac-sub47.5%
associate-/r/52.0%
*-rgt-identity52.0%
*-commutative52.0%
Applied egg-rr52.0%
associate-/l/54.0%
*-commutative54.0%
*-commutative54.0%
Simplified54.0%
Final simplification48.7%
(FPCore (x s) :precision binary32 (if (<= (- x) -1.4999999988791435e-32) 0.5 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
float tmp;
if (-x <= -1.4999999988791435e-32f) {
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 <= (-1.4999999988791435e-32)) 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(-x) <= Float32(-1.4999999988791435e-32)) 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 <= single(-1.4999999988791435e-32)) 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}\;-x \leq -1.4999999988791435 \cdot 10^{-32}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < -1.5e-32Initial program 99.9%
Taylor expanded in x around 0 35.1%
if -1.5e-32 < (neg.f32 x) Initial program 99.6%
Taylor expanded in x around 0 59.2%
mul-1-neg59.2%
unsub-neg59.2%
Simplified59.2%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.0010000000474974513) 0.5 (/ -1.0 (* x (/ 1.0 s)))))
float code(float x, float s) {
float tmp;
if (-x <= 0.0010000000474974513f) {
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.0010000000474974513e0) 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.0010000000474974513)) 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.0010000000474974513)) 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.0010000000474974513:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x \cdot \frac{1}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 0.00100000005Initial program 99.6%
Taylor expanded in x around 0 43.7%
if 0.00100000005 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 55.5%
mul-1-neg55.5%
unsub-neg55.5%
Simplified55.5%
Taylor expanded in x around inf 55.5%
associate-*r/55.5%
metadata-eval55.5%
Simplified55.5%
Taylor expanded in x around inf 55.5%
Final simplification46.6%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.0010000000474974513) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 0.0010000000474974513f) {
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.0010000000474974513e0) 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.0010000000474974513)) 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.0010000000474974513)) 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.0010000000474974513:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 0.00100000005Initial program 99.6%
Taylor expanded in x around 0 43.7%
if 0.00100000005 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 55.5%
mul-1-neg55.5%
unsub-neg55.5%
Simplified55.5%
Taylor expanded in x around inf 55.5%
neg-mul-155.5%
distribute-neg-frac255.5%
Simplified55.5%
Final simplification46.6%
(FPCore (x s) :precision binary32 (if (<= (- x) 0.07999999821186066) 0.5 (/ 1.0 (/ x s))))
float code(float x, float s) {
float tmp;
if (-x <= 0.07999999821186066f) {
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.07999999821186066e0) 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.07999999821186066)) 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.07999999821186066)) 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.07999999821186066:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\
\end{array}
\end{array}
if (neg.f32 x) < 0.0799999982Initial program 99.6%
Taylor expanded in x around 0 43.4%
if 0.0799999982 < (neg.f32 x) Initial program 100.0%
Taylor expanded in x around 0 56.7%
mul-1-neg56.7%
unsub-neg56.7%
Simplified56.7%
Taylor expanded in x around inf 56.7%
neg-mul-156.7%
distribute-neg-frac256.7%
Simplified56.7%
inv-pow56.7%
add-sqr-sqrt-0.0%
sqrt-unprod62.5%
sqr-neg62.5%
sqrt-unprod56.7%
add-sqr-sqrt56.7%
Applied egg-rr56.7%
unpow-156.7%
Simplified56.7%
(FPCore (x s) :precision binary32 (if (<= x -0.0020000000949949026) (/ s (- x)) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.0020000000949949026f) {
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.0020000000949949026e0)) 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.0020000000949949026)) tmp = Float32(s / Float32(-x)); else tmp = Float32(0.5); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.0020000000949949026)) tmp = s / -x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0020000000949949026:\\
\;\;\;\;\frac{s}{-x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.00200000009Initial program 100.0%
Taylor expanded in x around 0 55.5%
mul-1-neg55.5%
unsub-neg55.5%
Simplified55.5%
Taylor expanded in x around inf 50.9%
associate-*r/50.9%
mul-1-neg50.9%
Simplified50.9%
if -0.00200000009 < x Initial program 99.6%
Taylor expanded in x around 0 43.7%
Final simplification45.4%
(FPCore (x s) :precision binary32 (if (<= x -0.07999999821186066) (/ s x) 0.5))
float code(float x, float s) {
float tmp;
if (x <= -0.07999999821186066f) {
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.07999999821186066e0)) 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.07999999821186066)) 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.07999999821186066)) tmp = s / x; else tmp = single(0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.07999999821186066:\\
\;\;\;\;\frac{s}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if x < -0.0799999982Initial program 100.0%
Taylor expanded in x around 0 56.7%
mul-1-neg56.7%
unsub-neg56.7%
Simplified56.7%
Taylor expanded in x around inf 56.7%
neg-mul-156.7%
distribute-neg-frac256.7%
Simplified56.7%
clear-num52.0%
add-sqr-sqrt-0.0%
sqrt-unprod61.4%
sqr-neg61.4%
sqrt-unprod52.0%
add-sqr-sqrt52.0%
div-inv52.0%
Applied egg-rr52.0%
associate-*r/52.0%
*-rgt-identity52.0%
Simplified52.0%
if -0.0799999982 < x Initial program 99.6%
Taylor expanded in x around 0 43.4%
(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.7%
Taylor expanded in x around 0 34.5%
herbie shell --seed 2024087
(FPCore (x s)
:name "Logistic function"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ 1.0 (+ 1.0 (exp (/ (- x) s)))))