
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = log((exp(a) + exp(b))); end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{a} + e^{b}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = log((exp(a) + exp(b))); end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{a} + e^{b}\right)
\end{array}
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ (exp b) (exp a))))
(if (<= t_0 1.5)
(/ b (+ (exp a) 1.0))
(if (<= t_0 50000000000000.0) (log t_0) (/ b (exp (* 2.0 a)))))))assert(a < b);
double code(double a, double b) {
double t_0 = exp(b) + exp(a);
double tmp;
if (t_0 <= 1.5) {
tmp = b / (exp(a) + 1.0);
} else if (t_0 <= 50000000000000.0) {
tmp = log(t_0);
} else {
tmp = b / exp((2.0 * a));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = exp(b) + exp(a)
if (t_0 <= 1.5d0) then
tmp = b / (exp(a) + 1.0d0)
else if (t_0 <= 50000000000000.0d0) then
tmp = log(t_0)
else
tmp = b / exp((2.0d0 * a))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double t_0 = Math.exp(b) + Math.exp(a);
double tmp;
if (t_0 <= 1.5) {
tmp = b / (Math.exp(a) + 1.0);
} else if (t_0 <= 50000000000000.0) {
tmp = Math.log(t_0);
} else {
tmp = b / Math.exp((2.0 * a));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): t_0 = math.exp(b) + math.exp(a) tmp = 0 if t_0 <= 1.5: tmp = b / (math.exp(a) + 1.0) elif t_0 <= 50000000000000.0: tmp = math.log(t_0) else: tmp = b / math.exp((2.0 * a)) return tmp
a, b = sort([a, b]) function code(a, b) t_0 = Float64(exp(b) + exp(a)) tmp = 0.0 if (t_0 <= 1.5) tmp = Float64(b / Float64(exp(a) + 1.0)); elseif (t_0 <= 50000000000000.0) tmp = log(t_0); else tmp = Float64(b / exp(Float64(2.0 * a))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
t_0 = exp(b) + exp(a);
tmp = 0.0;
if (t_0 <= 1.5)
tmp = b / (exp(a) + 1.0);
elseif (t_0 <= 50000000000000.0)
tmp = log(t_0);
else
tmp = b / exp((2.0 * a));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[b], $MachinePrecision] + N[Exp[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1.5], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 50000000000000.0], N[Log[t$95$0], $MachinePrecision], N[(b / N[Exp[N[(2.0 * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := e^{b} + e^{a}\\
\mathbf{if}\;t\_0 \leq 1.5:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{elif}\;t\_0 \leq 50000000000000:\\
\;\;\;\;\log t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{e^{2 \cdot a}}\\
\end{array}
\end{array}
if (+.f64 (exp.f64 a) (exp.f64 b)) < 1.5Initial program 7.6%
Taylor expanded in b around 0 46.7%
log1p-def47.4%
Simplified47.4%
Taylor expanded in b around inf 46.7%
if 1.5 < (+.f64 (exp.f64 a) (exp.f64 b)) < 5e13Initial program 99.9%
if 5e13 < (+.f64 (exp.f64 a) (exp.f64 b)) Initial program 3.2%
Taylor expanded in b around 0 12.5%
log1p-def12.5%
Simplified12.5%
expm1-log1p-u12.5%
Applied egg-rr12.5%
*-un-lft-identity12.5%
add-cube-cbrt12.5%
times-frac12.5%
pow212.5%
expm1-log1p-u12.5%
expm1-log1p-u12.5%
Applied egg-rr12.5%
Simplified24.6%
Taylor expanded in b around inf 61.2%
unpow261.2%
prod-exp61.2%
count-261.2%
Simplified61.2%
Final simplification72.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp b) 2.0) (+ (log1p (exp a)) (/ b (+ (exp a) 1.0))) (/ b (exp (* 2.0 a)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(b) <= 2.0) {
tmp = log1p(exp(a)) + (b / (exp(a) + 1.0));
} else {
tmp = b / exp((2.0 * a));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(b) <= 2.0) {
tmp = Math.log1p(Math.exp(a)) + (b / (Math.exp(a) + 1.0));
} else {
tmp = b / Math.exp((2.0 * a));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(b) <= 2.0: tmp = math.log1p(math.exp(a)) + (b / (math.exp(a) + 1.0)) else: tmp = b / math.exp((2.0 * a)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(b) <= 2.0) tmp = Float64(log1p(exp(a)) + Float64(b / Float64(exp(a) + 1.0))); else tmp = Float64(b / exp(Float64(2.0 * a))); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[b], $MachinePrecision], 2.0], N[(N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision] + N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / N[Exp[N[(2.0 * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 2:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{e^{2 \cdot a}}\\
\end{array}
\end{array}
if (exp.f64 b) < 2Initial program 52.5%
Taylor expanded in b around 0 71.7%
log1p-def72.1%
Simplified72.1%
if 2 < (exp.f64 b) Initial program 3.2%
Taylor expanded in b around 0 18.8%
log1p-def18.8%
Simplified18.8%
expm1-log1p-u18.8%
Applied egg-rr18.8%
*-un-lft-identity18.8%
add-cube-cbrt18.8%
times-frac18.8%
pow218.8%
expm1-log1p-u18.8%
expm1-log1p-u18.8%
Applied egg-rr18.8%
Simplified38.8%
Taylor expanded in b around inf 100.0%
unpow2100.0%
prod-exp100.0%
count-2100.0%
Simplified100.0%
Final simplification72.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 5e-71) (/ b (+ (exp a) 1.0)) (log (+ (exp a) (+ b 1.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 5e-71) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log((exp(a) + (b + 1.0)));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 5d-71) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log((exp(a) + (b + 1.0d0)))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 5e-71) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log((Math.exp(a) + (b + 1.0)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 5e-71: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log((math.exp(a) + (b + 1.0))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 5e-71) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log(Float64(exp(a) + Float64(b + 1.0))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 5e-71)
tmp = b / (exp(a) + 1.0);
else
tmp = log((exp(a) + (b + 1.0)));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 5e-71], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Exp[a], $MachinePrecision] + N[(b + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-71}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + \left(b + 1\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 4.99999999999999998e-71Initial program 8.7%
Taylor expanded in b around 0 96.9%
log1p-def98.5%
Simplified98.5%
Taylor expanded in b around inf 96.9%
if 4.99999999999999998e-71 < (exp.f64 a) Initial program 65.4%
Taylor expanded in b around 0 62.1%
associate-+r+62.1%
+-commutative62.1%
Simplified62.1%
Final simplification70.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ b (+ (exp a) 1.0)) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log1p(exp(a));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log1p(Math.exp(a));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log1p(math.exp(a)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log1p(exp(a)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 8.7%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
if 0.0 < (exp.f64 a) Initial program 65.1%
Taylor expanded in b around 0 62.4%
log1p-def62.9%
Simplified62.9%
Final simplification71.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ b (+ (exp a) 1.0)) (log1p (exp b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log1p(exp(b));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log1p(Math.exp(b));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log1p(math.exp(b)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log1p(exp(b)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 8.7%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
if 0.0 < (exp.f64 a) Initial program 65.1%
Taylor expanded in a around 0 62.8%
log1p-def62.8%
Simplified62.8%
Final simplification71.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ b (+ (exp a) 1.0)) (+ (* b 0.5) (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = (b * 0.5) + log(2.0);
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.0d0) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = (b * 0.5d0) + log(2.0d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = (b * 0.5) + Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (math.exp(a) + 1.0) else: tmp = (b * 0.5) + math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = Float64(Float64(b * 0.5) + log(2.0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 0.0)
tmp = b / (exp(a) + 1.0);
else
tmp = (b * 0.5) + log(2.0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(b * 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 8.7%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
if 0.0 < (exp.f64 a) Initial program 65.1%
Taylor expanded in b around 0 62.7%
log1p-def63.2%
Simplified63.2%
Taylor expanded in a around 0 61.3%
+-commutative61.3%
Simplified61.3%
Final simplification70.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -175.0) (/ b 2.0) (+ (* b 0.5) (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -175.0) {
tmp = b / 2.0;
} else {
tmp = (b * 0.5) + log(2.0);
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-175.0d0)) then
tmp = b / 2.0d0
else
tmp = (b * 0.5d0) + log(2.0d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -175.0) {
tmp = b / 2.0;
} else {
tmp = (b * 0.5) + Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -175.0: tmp = b / 2.0 else: tmp = (b * 0.5) + math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -175.0) tmp = Float64(b / 2.0); else tmp = Float64(Float64(b * 0.5) + log(2.0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -175.0)
tmp = b / 2.0;
else
tmp = (b * 0.5) + log(2.0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -175.0], N[(b / 2.0), $MachinePrecision], N[(N[(b * 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -175:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\end{array}
if a < -175Initial program 8.7%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
Taylor expanded in a around 0 18.5%
if -175 < a Initial program 65.1%
Taylor expanded in b around 0 62.7%
log1p-def63.2%
Simplified63.2%
Taylor expanded in a around 0 61.3%
+-commutative61.3%
Simplified61.3%
Final simplification51.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.0) (/ b 2.0) (log (+ 2.0 a))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = b / 2.0;
} else {
tmp = log((2.0 + a));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.0d0)) then
tmp = b / 2.0d0
else
tmp = log((2.0d0 + a))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = b / 2.0;
} else {
tmp = Math.log((2.0 + a));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -1.0: tmp = b / 2.0 else: tmp = math.log((2.0 + a)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -1.0) tmp = Float64(b / 2.0); else tmp = log(Float64(2.0 + a)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -1.0)
tmp = b / 2.0;
else
tmp = log((2.0 + a));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -1.0], N[(b / 2.0), $MachinePrecision], N[Log[N[(2.0 + a), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;\log \left(2 + a\right)\\
\end{array}
\end{array}
if a < -1Initial program 8.7%
Taylor expanded in b around 0 96.9%
log1p-def98.5%
Simplified98.5%
Taylor expanded in b around inf 96.9%
Taylor expanded in a around 0 18.3%
if -1 < a Initial program 65.4%
Taylor expanded in b around 0 62.7%
Taylor expanded in a around 0 62.1%
+-commutative62.1%
Simplified62.1%
Final simplification51.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -170.0) (/ b 2.0) (log (+ b 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -170.0) {
tmp = b / 2.0;
} else {
tmp = log((b + 2.0));
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-170.0d0)) then
tmp = b / 2.0d0
else
tmp = log((b + 2.0d0))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -170.0) {
tmp = b / 2.0;
} else {
tmp = Math.log((b + 2.0));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -170.0: tmp = b / 2.0 else: tmp = math.log((b + 2.0)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -170.0) tmp = Float64(b / 2.0); else tmp = log(Float64(b + 2.0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -170.0)
tmp = b / 2.0;
else
tmp = log((b + 2.0));
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -170.0], N[(b / 2.0), $MachinePrecision], N[Log[N[(b + 2.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -170:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if a < -170Initial program 8.7%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
Taylor expanded in a around 0 18.5%
if -170 < a Initial program 65.1%
Taylor expanded in a around 0 62.8%
Taylor expanded in b around 0 60.4%
+-commutative60.4%
Simplified60.4%
Final simplification50.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -190.0) (/ b 2.0) (+ b (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -190.0) {
tmp = b / 2.0;
} else {
tmp = b + log(2.0);
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-190.0d0)) then
tmp = b / 2.0d0
else
tmp = b + log(2.0d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -190.0) {
tmp = b / 2.0;
} else {
tmp = b + Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -190.0: tmp = b / 2.0 else: tmp = b + math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -190.0) tmp = Float64(b / 2.0); else tmp = Float64(b + log(2.0)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -190.0)
tmp = b / 2.0;
else
tmp = b + log(2.0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -190.0], N[(b / 2.0), $MachinePrecision], N[(b + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -190:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;b + \log 2\\
\end{array}
\end{array}
if a < -190Initial program 8.7%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
Taylor expanded in a around 0 18.5%
if -190 < a Initial program 65.1%
Taylor expanded in b around 0 62.7%
log1p-def63.2%
Simplified63.2%
expm1-log1p-u63.2%
Applied egg-rr63.2%
*-un-lft-identity63.2%
add-cube-cbrt63.2%
times-frac63.2%
pow263.2%
expm1-log1p-u63.2%
expm1-log1p-u63.2%
Applied egg-rr63.2%
Simplified62.3%
Taylor expanded in a around 0 60.9%
+-commutative60.9%
Simplified60.9%
Final simplification50.9%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -165.0) (/ b 2.0) (log 2.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -165.0) {
tmp = b / 2.0;
} else {
tmp = log(2.0);
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-165.0d0)) then
tmp = b / 2.0d0
else
tmp = log(2.0d0)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -165.0) {
tmp = b / 2.0;
} else {
tmp = Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -165.0: tmp = b / 2.0 else: tmp = math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -165.0) tmp = Float64(b / 2.0); else tmp = log(2.0); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -165.0)
tmp = b / 2.0;
else
tmp = log(2.0);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -165.0], N[(b / 2.0), $MachinePrecision], N[Log[2.0], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -165:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -165Initial program 8.7%
Taylor expanded in b around 0 98.4%
log1p-def98.4%
Simplified98.4%
Taylor expanded in b around inf 98.4%
Taylor expanded in a around 0 18.5%
if -165 < a Initial program 65.1%
Taylor expanded in b around 0 62.4%
log1p-def62.9%
Simplified62.9%
Taylor expanded in a around 0 61.0%
Final simplification51.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ b 2.0))
assert(a < b);
double code(double a, double b) {
return b / 2.0;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = b / 2.0d0
end function
assert a < b;
public static double code(double a, double b) {
return b / 2.0;
}
[a, b] = sort([a, b]) def code(a, b): return b / 2.0
a, b = sort([a, b]) function code(a, b) return Float64(b / 2.0) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = b / 2.0;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(b / 2.0), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{b}{2}
\end{array}
Initial program 51.9%
Taylor expanded in b around 0 71.1%
log1p-def71.5%
Simplified71.5%
Taylor expanded in b around inf 25.9%
Taylor expanded in a around 0 7.2%
Final simplification7.2%
herbie shell --seed 2024027
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))