
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
(FPCore (a b) :precision binary64 (exp (fma (log (+ (exp a) (exp b))) -1.0 a)))
double code(double a, double b) {
return exp(fma(log((exp(a) + exp(b))), -1.0, a));
}
function code(a, b) return exp(fma(log(Float64(exp(a) + exp(b))), -1.0, a)) end
code[a_, b_] := N[Exp[N[(N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -1.0 + a), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}
\end{array}
Initial program 99.6%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6499.6
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Initial program 99.6%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.99995) (/ 1.0 (+ (/ (+ 1.0 b) (exp a)) 1.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.99995) {
tmp = 1.0 / (((1.0 + b) / exp(a)) + 1.0);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.99995d0) then
tmp = 1.0d0 / (((1.0d0 + b) / exp(a)) + 1.0d0)
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.99995) {
tmp = 1.0 / (((1.0 + b) / Math.exp(a)) + 1.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.99995: tmp = 1.0 / (((1.0 + b) / math.exp(a)) + 1.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.99995) tmp = Float64(1.0 / Float64(Float64(Float64(1.0 + b) / exp(a)) + 1.0)); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.99995) tmp = 1.0 / (((1.0 + b) / exp(a)) + 1.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.99995], N[(1.0 / N[(N[(N[(1.0 + b), $MachinePrecision] / N[Exp[a], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.99995:\\
\;\;\;\;\frac{1}{\frac{1 + b}{e^{a}} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999950000000000006Initial program 100.0%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-rgt-identityN/A
associate-*r/N/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
rec-expN/A
mul-1-negN/A
lower-exp.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
if 0.999950000000000006 < (exp.f64 a) Initial program 99.4%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6498.7
Applied rewrites98.7%
Final simplification99.1%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.99995) (/ 1.0 (+ (exp (- a)) 1.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.99995) {
tmp = 1.0 / (exp(-a) + 1.0);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.99995d0) then
tmp = 1.0d0 / (exp(-a) + 1.0d0)
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.99995) {
tmp = 1.0 / (Math.exp(-a) + 1.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.99995: tmp = 1.0 / (math.exp(-a) + 1.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.99995) tmp = Float64(1.0 / Float64(exp(Float64(-a)) + 1.0)); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.99995) tmp = 1.0 / (exp(-a) + 1.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.99995], N[(1.0 / N[(N[Exp[(-a)], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.99995:\\
\;\;\;\;\frac{1}{e^{-a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999950000000000006Initial program 100.0%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-rgt-identityN/A
associate-*r/N/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
rec-expN/A
mul-1-negN/A
lower-exp.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
if 0.999950000000000006 < (exp.f64 a) Initial program 99.4%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6498.7
Applied rewrites98.7%
Final simplification99.1%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.99995) (/ (exp a) (+ 1.0 1.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.99995) {
tmp = exp(a) / (1.0 + 1.0);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.99995d0) then
tmp = exp(a) / (1.0d0 + 1.0d0)
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.99995) {
tmp = Math.exp(a) / (1.0 + 1.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.99995: tmp = math.exp(a) / (1.0 + 1.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.99995) tmp = Float64(exp(a) / Float64(1.0 + 1.0)); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.99995) tmp = exp(a) / (1.0 + 1.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.99995], N[(N[Exp[a], $MachinePrecision] / N[(1.0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.99995:\\
\;\;\;\;\frac{e^{a}}{1 + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999950000000000006Initial program 100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
Taylor expanded in a around 0
Applied rewrites97.1%
if 0.999950000000000006 < (exp.f64 a) Initial program 99.4%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6498.7
Applied rewrites98.7%
Final simplification98.3%
(FPCore (a b)
:precision binary64
(if (<= a -2.8e+47)
(/
1.0
(fma
(+ 1.0 b)
(fma (fma (fma -0.16666666666666666 a 0.5) a -1.0) a 1.0)
1.0))
(/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -2.8e+47) {
tmp = 1.0 / fma((1.0 + b), fma(fma(fma(-0.16666666666666666, a, 0.5), a, -1.0), a, 1.0), 1.0);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -2.8e+47) tmp = Float64(1.0 / fma(Float64(1.0 + b), fma(fma(fma(-0.16666666666666666, a, 0.5), a, -1.0), a, 1.0), 1.0)); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
code[a_, b_] := If[LessEqual[a, -2.8e+47], N[(1.0 / N[(N[(1.0 + b), $MachinePrecision] * N[(N[(N[(-0.16666666666666666 * a + 0.5), $MachinePrecision] * a + -1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.8 \cdot 10^{+47}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(1 + b, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, a, 0.5\right), a, -1\right), a, 1\right), 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -2.79999999999999988e47Initial program 100.0%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-rgt-identityN/A
associate-*r/N/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
rec-expN/A
mul-1-negN/A
lower-exp.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
Applied rewrites84.2%
if -2.79999999999999988e47 < a Initial program 99.5%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6493.8
Applied rewrites93.8%
Final simplification91.6%
(FPCore (a b)
:precision binary64
(if (<= b 7e+64)
(/
(+ 1.0 a)
(+ (fma (fma (fma 0.16666666666666666 a 0.5) a 1.0) a 1.0) 1.0))
(/
1.0
(fma
(fma (/ (fma 0.027777777777777776 (* b b) -0.25) -0.5) b 1.0)
b
2.0))))
double code(double a, double b) {
double tmp;
if (b <= 7e+64) {
tmp = (1.0 + a) / (fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0) + 1.0);
} else {
tmp = 1.0 / fma(fma((fma(0.027777777777777776, (b * b), -0.25) / -0.5), b, 1.0), b, 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 7e+64) tmp = Float64(Float64(1.0 + a) / Float64(fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0) + 1.0)); else tmp = Float64(1.0 / fma(fma(Float64(fma(0.027777777777777776, Float64(b * b), -0.25) / -0.5), b, 1.0), b, 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[b, 7e+64], N[(N[(1.0 + a), $MachinePrecision] / N[(N[(N[(N[(0.16666666666666666 * a + 0.5), $MachinePrecision] * a + 1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(N[(0.027777777777777776 * N[(b * b), $MachinePrecision] + -0.25), $MachinePrecision] / -0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+64}:\\
\;\;\;\;\frac{1 + a}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(0.027777777777777776, b \cdot b, -0.25\right)}{-0.5}, b, 1\right), b, 2\right)}\\
\end{array}
\end{array}
if b < 6.9999999999999997e64Initial program 99.5%
Taylor expanded in b around 0
Applied rewrites75.6%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6474.7
Applied rewrites74.7%
Taylor expanded in a around 0
lower-+.f6465.3
Applied rewrites65.3%
if 6.9999999999999997e64 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites84.4%
Applied rewrites84.4%
Taylor expanded in b around 0
Applied rewrites91.5%
(FPCore (a b)
:precision binary64
(if (<= b 7e+64)
(/
(+ 1.0 a)
(+ (fma (fma (fma 0.16666666666666666 a 0.5) a 1.0) a 1.0) 1.0))
(/ 1.0 (* (* (* 0.16666666666666666 b) b) b))))
double code(double a, double b) {
double tmp;
if (b <= 7e+64) {
tmp = (1.0 + a) / (fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0) + 1.0);
} else {
tmp = 1.0 / (((0.16666666666666666 * b) * b) * b);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 7e+64) tmp = Float64(Float64(1.0 + a) / Float64(fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0) + 1.0)); else tmp = Float64(1.0 / Float64(Float64(Float64(0.16666666666666666 * b) * b) * b)); end return tmp end
code[a_, b_] := If[LessEqual[b, 7e+64], N[(N[(1.0 + a), $MachinePrecision] / N[(N[(N[(N[(0.16666666666666666 * a + 0.5), $MachinePrecision] * a + 1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(0.16666666666666666 * b), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+64}:\\
\;\;\;\;\frac{1 + a}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(0.16666666666666666 \cdot b\right) \cdot b\right) \cdot b}\\
\end{array}
\end{array}
if b < 6.9999999999999997e64Initial program 99.5%
Taylor expanded in b around 0
Applied rewrites75.6%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6474.7
Applied rewrites74.7%
Taylor expanded in a around 0
lower-+.f6465.3
Applied rewrites65.3%
if 6.9999999999999997e64 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites84.4%
Taylor expanded in b around inf
Applied rewrites84.4%
Taylor expanded in b around inf
Applied rewrites84.4%
(FPCore (a b) :precision binary64 (if (<= b 7e+64) (/ 1.0 (+ (fma (fma (fma 0.16666666666666666 a 0.5) a 1.0) a 1.0) 1.0)) (/ 1.0 (* (* (* 0.16666666666666666 b) b) b))))
double code(double a, double b) {
double tmp;
if (b <= 7e+64) {
tmp = 1.0 / (fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0) + 1.0);
} else {
tmp = 1.0 / (((0.16666666666666666 * b) * b) * b);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 7e+64) tmp = Float64(1.0 / Float64(fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0) + 1.0)); else tmp = Float64(1.0 / Float64(Float64(Float64(0.16666666666666666 * b) * b) * b)); end return tmp end
code[a_, b_] := If[LessEqual[b, 7e+64], N[(1.0 / N[(N[(N[(N[(0.16666666666666666 * a + 0.5), $MachinePrecision] * a + 1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(0.16666666666666666 * b), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+64}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(0.16666666666666666 \cdot b\right) \cdot b\right) \cdot b}\\
\end{array}
\end{array}
if b < 6.9999999999999997e64Initial program 99.5%
Taylor expanded in b around 0
Applied rewrites75.6%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6474.7
Applied rewrites74.7%
Taylor expanded in a around 0
Applied rewrites64.4%
if 6.9999999999999997e64 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites84.4%
Taylor expanded in b around inf
Applied rewrites84.4%
Taylor expanded in b around inf
Applied rewrites84.4%
(FPCore (a b)
:precision binary64
(if (<= b -1.25)
0.5
(if (<= b 7.8e+153)
(/ 1.0 (fma (+ 1.0 b) (- 1.0 a) 1.0))
(/ 1.0 (* (* b b) 0.5)))))
double code(double a, double b) {
double tmp;
if (b <= -1.25) {
tmp = 0.5;
} else if (b <= 7.8e+153) {
tmp = 1.0 / fma((1.0 + b), (1.0 - a), 1.0);
} else {
tmp = 1.0 / ((b * b) * 0.5);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= -1.25) tmp = 0.5; elseif (b <= 7.8e+153) tmp = Float64(1.0 / fma(Float64(1.0 + b), Float64(1.0 - a), 1.0)); else tmp = Float64(1.0 / Float64(Float64(b * b) * 0.5)); end return tmp end
code[a_, b_] := If[LessEqual[b, -1.25], 0.5, If[LessEqual[b, 7.8e+153], N[(1.0 / N[(N[(1.0 + b), $MachinePrecision] * N[(1.0 - a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.25:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 7.8 \cdot 10^{+153}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(1 + b, 1 - a, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b \cdot b\right) \cdot 0.5}\\
\end{array}
\end{array}
if b < -1.25Initial program 97.7%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6497.7
Applied rewrites97.7%
Taylor expanded in b around 0
Applied rewrites18.4%
if -1.25 < b < 7.79999999999999966e153Initial program 100.0%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
*-rgt-identityN/A
associate-*r/N/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
rec-expN/A
mul-1-negN/A
lower-exp.f64N/A
mul-1-negN/A
lower-neg.f6485.0
Applied rewrites85.0%
Taylor expanded in a around 0
Applied rewrites52.6%
if 7.79999999999999966e153 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
Taylor expanded in b around inf
Applied rewrites100.0%
Final simplification53.0%
(FPCore (a b) :precision binary64 (if (<= b 7e+64) (/ 1.0 (+ (fma (fma 0.5 a 1.0) a 1.0) 1.0)) (/ 1.0 (* (* (* 0.16666666666666666 b) b) b))))
double code(double a, double b) {
double tmp;
if (b <= 7e+64) {
tmp = 1.0 / (fma(fma(0.5, a, 1.0), a, 1.0) + 1.0);
} else {
tmp = 1.0 / (((0.16666666666666666 * b) * b) * b);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 7e+64) tmp = Float64(1.0 / Float64(fma(fma(0.5, a, 1.0), a, 1.0) + 1.0)); else tmp = Float64(1.0 / Float64(Float64(Float64(0.16666666666666666 * b) * b) * b)); end return tmp end
code[a_, b_] := If[LessEqual[b, 7e+64], N[(1.0 / N[(N[(N[(0.5 * a + 1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(0.16666666666666666 * b), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+64}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, a, 1\right), a, 1\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(0.16666666666666666 \cdot b\right) \cdot b\right) \cdot b}\\
\end{array}
\end{array}
if b < 6.9999999999999997e64Initial program 99.5%
Taylor expanded in b around 0
Applied rewrites75.6%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6474.7
Applied rewrites74.7%
Taylor expanded in a around 0
Applied rewrites64.4%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6461.6
Applied rewrites61.6%
if 6.9999999999999997e64 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites84.4%
Taylor expanded in b around inf
Applied rewrites84.4%
Taylor expanded in b around inf
Applied rewrites84.4%
(FPCore (a b) :precision binary64 (if (<= b 7.5e+30) (/ 1.0 (+ (+ 1.0 a) 1.0)) (/ 1.0 (* (* (* 0.16666666666666666 b) b) b))))
double code(double a, double b) {
double tmp;
if (b <= 7.5e+30) {
tmp = 1.0 / ((1.0 + a) + 1.0);
} else {
tmp = 1.0 / (((0.16666666666666666 * b) * b) * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 7.5d+30) then
tmp = 1.0d0 / ((1.0d0 + a) + 1.0d0)
else
tmp = 1.0d0 / (((0.16666666666666666d0 * b) * b) * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 7.5e+30) {
tmp = 1.0 / ((1.0 + a) + 1.0);
} else {
tmp = 1.0 / (((0.16666666666666666 * b) * b) * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 7.5e+30: tmp = 1.0 / ((1.0 + a) + 1.0) else: tmp = 1.0 / (((0.16666666666666666 * b) * b) * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 7.5e+30) tmp = Float64(1.0 / Float64(Float64(1.0 + a) + 1.0)); else tmp = Float64(1.0 / Float64(Float64(Float64(0.16666666666666666 * b) * b) * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 7.5e+30) tmp = 1.0 / ((1.0 + a) + 1.0); else tmp = 1.0 / (((0.16666666666666666 * b) * b) * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 7.5e+30], N[(1.0 / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(0.16666666666666666 * b), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.5 \cdot 10^{+30}:\\
\;\;\;\;\frac{1}{\left(1 + a\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(0.16666666666666666 \cdot b\right) \cdot b\right) \cdot b}\\
\end{array}
\end{array}
if b < 7.49999999999999973e30Initial program 99.5%
Taylor expanded in b around 0
Applied rewrites77.2%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6476.3
Applied rewrites76.3%
Taylor expanded in a around 0
Applied rewrites66.1%
Taylor expanded in a around 0
lower-+.f6448.7
Applied rewrites48.7%
if 7.49999999999999973e30 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites75.2%
Taylor expanded in b around inf
Applied rewrites75.2%
Taylor expanded in b around inf
Applied rewrites75.2%
(FPCore (a b) :precision binary64 (if (<= b 2.2e+37) (/ 1.0 (+ (+ 1.0 a) 1.0)) (/ 1.0 (* (* b b) 0.5))))
double code(double a, double b) {
double tmp;
if (b <= 2.2e+37) {
tmp = 1.0 / ((1.0 + a) + 1.0);
} else {
tmp = 1.0 / ((b * b) * 0.5);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.2d+37) then
tmp = 1.0d0 / ((1.0d0 + a) + 1.0d0)
else
tmp = 1.0d0 / ((b * b) * 0.5d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.2e+37) {
tmp = 1.0 / ((1.0 + a) + 1.0);
} else {
tmp = 1.0 / ((b * b) * 0.5);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.2e+37: tmp = 1.0 / ((1.0 + a) + 1.0) else: tmp = 1.0 / ((b * b) * 0.5) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.2e+37) tmp = Float64(1.0 / Float64(Float64(1.0 + a) + 1.0)); else tmp = Float64(1.0 / Float64(Float64(b * b) * 0.5)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.2e+37) tmp = 1.0 / ((1.0 + a) + 1.0); else tmp = 1.0 / ((b * b) * 0.5); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.2e+37], N[(1.0 / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.2 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\left(1 + a\right) + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b \cdot b\right) \cdot 0.5}\\
\end{array}
\end{array}
if b < 2.2000000000000001e37Initial program 99.5%
Taylor expanded in b around 0
Applied rewrites77.3%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6476.4
Applied rewrites76.4%
Taylor expanded in a around 0
Applied rewrites65.8%
Taylor expanded in a around 0
lower-+.f6448.4
Applied rewrites48.4%
if 2.2000000000000001e37 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites58.0%
Taylor expanded in b around inf
Applied rewrites58.0%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (+ 1.0 a) 1.0)))
double code(double a, double b) {
return 1.0 / ((1.0 + a) + 1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / ((1.0d0 + a) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / ((1.0 + a) + 1.0);
}
def code(a, b): return 1.0 / ((1.0 + a) + 1.0)
function code(a, b) return Float64(1.0 / Float64(Float64(1.0 + a) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / ((1.0 + a) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(1 + a\right) + 1}
\end{array}
Initial program 99.6%
Taylor expanded in b around 0
Applied rewrites66.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6465.3
Applied rewrites65.3%
Taylor expanded in a around 0
Applied rewrites54.6%
Taylor expanded in a around 0
lower-+.f6437.9
Applied rewrites37.9%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.6%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6478.6
Applied rewrites78.6%
Taylor expanded in b around 0
Applied rewrites37.4%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
herbie shell --seed 2024278
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (+ 1 (exp (- b a)))))
(/ (exp a) (+ (exp a) (exp b))))