
(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 14 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 (sqrt (pow (+ 1.0 (exp (- b a))) -2.0)))
double code(double a, double b) {
return sqrt(pow((1.0 + exp((b - a))), -2.0));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = sqrt(((1.0d0 + exp((b - a))) ** (-2.0d0)))
end function
public static double code(double a, double b) {
return Math.sqrt(Math.pow((1.0 + Math.exp((b - a))), -2.0));
}
def code(a, b): return math.sqrt(math.pow((1.0 + math.exp((b - a))), -2.0))
function code(a, b) return sqrt((Float64(1.0 + exp(Float64(b - a))) ^ -2.0)) end
function tmp = code(a, b) tmp = sqrt(((1.0 + exp((b - a))) ^ -2.0)); end
code[a_, b_] := N[Sqrt[N[Power[N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{\left(1 + e^{b - a}\right)}^{-2}}
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
add-sqr-sqrt99.4%
sqrt-unprod100.0%
inv-pow100.0%
inv-pow100.0%
pow-prod-up100.0%
metadata-eval100.0%
Applied egg-rr100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0002) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0002) {
tmp = 1.0 / (1.0 + exp(-a));
} 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.0002d0) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
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.0002) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0002: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0002) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); 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.0002) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0002], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $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.0002:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-4Initial program 97.3%
*-lft-identity97.3%
associate-*l/97.3%
associate-/r/97.3%
remove-double-neg97.3%
unsub-neg97.3%
div-sub1.3%
*-lft-identity1.3%
associate-*l/1.3%
lft-mult-inverse97.3%
sub-neg97.3%
distribute-frac-neg97.3%
remove-double-neg97.3%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 98.7%
if 2.0000000000000001e-4 < (exp.f64 a) Initial program 98.3%
*-lft-identity98.3%
associate-*l/98.3%
associate-/r/98.3%
remove-double-neg98.3%
unsub-neg98.3%
div-sub98.3%
*-lft-identity98.3%
associate-*l/98.3%
lft-mult-inverse99.4%
sub-neg99.4%
distribute-frac-neg99.4%
remove-double-neg99.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 98.4%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0002) (/ (exp a) 2.0) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0002) {
tmp = exp(a) / 2.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.0002d0) then
tmp = exp(a) / 2.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.0002) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0002: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0002) tmp = Float64(exp(a) / 2.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.0002) tmp = exp(a) / 2.0; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0002], N[(N[Exp[a], $MachinePrecision] / 2.0), $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.0002:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-4Initial program 97.3%
Taylor expanded in b around 0 98.7%
Taylor expanded in a around 0 97.6%
add-cube-cbrt97.6%
associate-/l*97.6%
pow297.6%
metadata-eval97.6%
Applied egg-rr97.6%
associate-*r/97.6%
unpow297.6%
rem-3cbrt-lft97.6%
Simplified97.6%
if 2.0000000000000001e-4 < (exp.f64 a) Initial program 98.3%
*-lft-identity98.3%
associate-*l/98.3%
associate-/r/98.3%
remove-double-neg98.3%
unsub-neg98.3%
div-sub98.3%
*-lft-identity98.3%
associate-*l/98.3%
lft-mult-inverse99.4%
sub-neg99.4%
distribute-frac-neg99.4%
remove-double-neg99.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 98.4%
(FPCore (a b) :precision binary64 (if (<= b 8.8e+102) (/ (exp a) 2.0) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 8.8e+102) {
tmp = exp(a) / 2.0;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 8.8d+102) then
tmp = exp(a) / 2.0d0
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 8.8e+102) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8.8e+102: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 8.8e+102) tmp = Float64(exp(a) / 2.0); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8.8e+102) tmp = exp(a) / 2.0; else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8.8e+102], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.8 \cdot 10^{+102}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 8.8000000000000003e102Initial program 98.0%
Taylor expanded in b around 0 75.8%
Taylor expanded in a around 0 74.4%
add-cube-cbrt74.4%
associate-/l*74.4%
pow274.4%
metadata-eval74.4%
Applied egg-rr74.4%
associate-*r/74.4%
unpow274.4%
rem-3cbrt-lft74.4%
Simplified74.4%
if 8.8000000000000003e102 < b Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub58.8%
*-lft-identity58.8%
associate-*l/58.8%
lft-mult-inverse98.0%
sub-neg98.0%
distribute-frac-neg98.0%
remove-double-neg98.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
(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}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= b 6.4e+94) (/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0)))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 6.4e+94) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 6.4d+94) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 6.4e+94) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6.4e+94: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 6.4e+94) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6.4e+94) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6.4e+94], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.4 \cdot 10^{+94}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 6.40000000000000028e94Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub72.7%
*-lft-identity72.7%
associate-*l/72.7%
lft-mult-inverse99.0%
sub-neg99.0%
distribute-frac-neg99.0%
remove-double-neg99.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 77.4%
Taylor expanded in a around 0 70.4%
if 6.40000000000000028e94 < b Initial program 98.1%
*-lft-identity98.1%
associate-*l/98.1%
associate-/r/98.1%
remove-double-neg98.1%
unsub-neg98.1%
div-sub59.3%
*-lft-identity59.3%
associate-*l/59.3%
lft-mult-inverse98.1%
sub-neg98.1%
distribute-frac-neg98.1%
remove-double-neg98.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 95.0%
*-commutative95.0%
Simplified95.0%
Final simplification75.6%
(FPCore (a b) :precision binary64 (if (<= b 1.2e+153) (/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0)))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.2e+153) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (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 <= 1.2d+153) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.2e+153) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.2e+153: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.2e+153) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.2e+153) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.2e+153], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.2 \cdot 10^{+153}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.19999999999999996e153Initial program 98.1%
*-lft-identity98.1%
associate-*l/98.1%
associate-/r/98.1%
remove-double-neg98.1%
unsub-neg98.1%
div-sub70.7%
*-lft-identity70.7%
associate-*l/70.7%
lft-mult-inverse99.0%
sub-neg99.0%
distribute-frac-neg99.0%
remove-double-neg99.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 76.5%
Taylor expanded in a around 0 69.0%
if 1.19999999999999996e153 < b Initial program 97.6%
*-lft-identity97.6%
associate-*l/97.6%
associate-/r/97.6%
remove-double-neg97.6%
unsub-neg97.6%
div-sub65.9%
*-lft-identity65.9%
associate-*l/65.9%
lft-mult-inverse97.6%
sub-neg97.6%
distribute-frac-neg97.6%
remove-double-neg97.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification74.0%
(FPCore (a b) :precision binary64 (if (<= b 1.9e+154) (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.9e+154) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (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 <= 1.9d+154) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.9e+154) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.9e+154: tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.9e+154) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.9e+154) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.9e+154], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.8999999999999999e154Initial program 98.1%
*-lft-identity98.1%
associate-*l/98.1%
associate-/r/98.1%
remove-double-neg98.1%
unsub-neg98.1%
div-sub70.7%
*-lft-identity70.7%
associate-*l/70.7%
lft-mult-inverse99.0%
sub-neg99.0%
distribute-frac-neg99.0%
remove-double-neg99.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 76.5%
Taylor expanded in a around 0 66.5%
if 1.8999999999999999e154 < b Initial program 97.6%
*-lft-identity97.6%
associate-*l/97.6%
associate-/r/97.6%
remove-double-neg97.6%
unsub-neg97.6%
div-sub65.9%
*-lft-identity65.9%
associate-*l/65.9%
lft-mult-inverse97.6%
sub-neg97.6%
distribute-frac-neg97.6%
remove-double-neg97.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification71.9%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
def code(a, b): return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
Taylor expanded in a around 0 58.7%
Final simplification58.7%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (* a 0.5)))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * (a * 0.5)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * (a * 0.5d0)))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * (a * 0.5)));
}
def code(a, b): return 1.0 / (2.0 + (a * (a * 0.5)))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(a * 0.5)))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * (a * 0.5))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(a \cdot 0.5\right)}
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
Taylor expanded in a around 0 58.7%
Taylor expanded in a around inf 58.2%
Final simplification58.2%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (- 1.0 a))))
double code(double a, double b) {
return 1.0 / (1.0 + (1.0 - a));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + (1.0d0 - a))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + (1.0 - a));
}
def code(a, b): return 1.0 / (1.0 + (1.0 - a))
function code(a, b) return Float64(1.0 / Float64(1.0 + Float64(1.0 - a))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + (1.0 - a)); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + \left(1 - a\right)}
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
Taylor expanded in a around 0 41.2%
neg-mul-141.2%
unsub-neg41.2%
Simplified41.2%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
Taylor expanded in a around 0 41.2%
neg-mul-141.2%
unsub-neg41.2%
Simplified41.2%
(FPCore (a b) :precision binary64 (+ 0.5 (* a 0.25)))
double code(double a, double b) {
return 0.5 + (a * 0.25);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0 + (a * 0.25d0)
end function
public static double code(double a, double b) {
return 0.5 + (a * 0.25);
}
def code(a, b): return 0.5 + (a * 0.25)
function code(a, b) return Float64(0.5 + Float64(a * 0.25)) end
function tmp = code(a, b) tmp = 0.5 + (a * 0.25); end
code[a_, b_] := N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + a \cdot 0.25
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 69.7%
Taylor expanded in a around 0 40.4%
*-commutative40.4%
Simplified40.4%
(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 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.9%
*-lft-identity69.9%
associate-*l/69.9%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 80.7%
Taylor expanded in b around 0 40.3%
(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 2024181
(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))))