
(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 10 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 (+ 1.0 (exp a))))
(+
(log t_0)
(+
(* 0.5 (* (pow b 2.0) (- (/ 1.0 t_0) (/ 1.0 (pow t_0 2.0)))))
(/ b t_0)))))assert(a < b);
double code(double a, double b) {
double t_0 = 1.0 + exp(a);
return log(t_0) + ((0.5 * (pow(b, 2.0) * ((1.0 / t_0) - (1.0 / pow(t_0, 2.0))))) + (b / t_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
real(8) :: t_0
t_0 = 1.0d0 + exp(a)
code = log(t_0) + ((0.5d0 * ((b ** 2.0d0) * ((1.0d0 / t_0) - (1.0d0 / (t_0 ** 2.0d0))))) + (b / t_0))
end function
assert a < b;
public static double code(double a, double b) {
double t_0 = 1.0 + Math.exp(a);
return Math.log(t_0) + ((0.5 * (Math.pow(b, 2.0) * ((1.0 / t_0) - (1.0 / Math.pow(t_0, 2.0))))) + (b / t_0));
}
[a, b] = sort([a, b]) def code(a, b): t_0 = 1.0 + math.exp(a) return math.log(t_0) + ((0.5 * (math.pow(b, 2.0) * ((1.0 / t_0) - (1.0 / math.pow(t_0, 2.0))))) + (b / t_0))
a, b = sort([a, b]) function code(a, b) t_0 = Float64(1.0 + exp(a)) return Float64(log(t_0) + Float64(Float64(0.5 * Float64((b ^ 2.0) * Float64(Float64(1.0 / t_0) - Float64(1.0 / (t_0 ^ 2.0))))) + Float64(b / t_0))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
t_0 = 1.0 + exp(a);
tmp = log(t_0) + ((0.5 * ((b ^ 2.0) * ((1.0 / t_0) - (1.0 / (t_0 ^ 2.0))))) + (b / t_0));
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := Block[{t$95$0 = N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]}, N[(N[Log[t$95$0], $MachinePrecision] + N[(N[(0.5 * N[(N[Power[b, 2.0], $MachinePrecision] * N[(N[(1.0 / t$95$0), $MachinePrecision] - N[(1.0 / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := 1 + e^{a}\\
\log t_0 + \left(0.5 \cdot \left({b}^{2} \cdot \left(\frac{1}{t_0} - \frac{1}{{t_0}^{2}}\right)\right) + \frac{b}{t_0}\right)
\end{array}
\end{array}
Initial program 50.5%
Taylor expanded in b around 0 75.0%
Final simplification75.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (/ b (+ 1.0 (exp a))) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
return (b / (1.0 + exp(a))) + log1p(exp(a));
}
assert a < b;
public static double code(double a, double b) {
return (b / (1.0 + Math.exp(a))) + Math.log1p(Math.exp(a));
}
[a, b] = sort([a, b]) def code(a, b): return (b / (1.0 + math.exp(a))) + math.log1p(math.exp(a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(b / Float64(1.0 + exp(a))) + log1p(exp(a))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{b}{1 + e^{a}} + \mathsf{log1p}\left(e^{a}\right)
\end{array}
Initial program 50.5%
Taylor expanded in b around 0 74.7%
log1p-def74.8%
Simplified74.8%
Final simplification74.8%
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 (+ 1.0 (exp a))) (log1p (+ (exp a) b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log1p((exp(a) + b));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log1p((Math.exp(a) + b));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log1p((math.exp(a) + b)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log1p(Float64(exp(a) + 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[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(N[Exp[a], $MachinePrecision] + b), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + b\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 10.2%
Taylor expanded in b around 0 7.9%
associate-+r+7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around 0 98.7%
log1p-def98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in b around inf 98.7%
if 0.0 < (exp.f64 a) Initial program 67.2%
Taylor expanded in b around 0 64.0%
associate-+r+64.0%
+-commutative64.0%
Simplified64.0%
Taylor expanded in a around inf 64.0%
log1p-def64.0%
Simplified64.0%
Final simplification74.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 (+ 1.0 (exp a))) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (1.0 + exp(a));
} 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 / (1.0 + Math.exp(a));
} 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 / (1.0 + math.exp(a)) 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(1.0 + exp(a))); 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[(1.0 + N[Exp[a], $MachinePrecision]), $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}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 10.2%
Taylor expanded in b around 0 7.9%
associate-+r+7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around 0 98.7%
log1p-def98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in b around inf 98.7%
if 0.0 < (exp.f64 a) Initial program 67.2%
Taylor expanded in b around 0 64.7%
log1p-def64.7%
Simplified64.7%
Final simplification74.7%
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 (+ 1.0 (exp a))) (+ (log (+ b 2.0)) (/ a (+ b 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((b + 2.0)) + (a / (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 (exp(a) <= 0.0d0) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log((b + 2.0d0)) + (a / (b + 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 / (1.0 + Math.exp(a));
} else {
tmp = Math.log((b + 2.0)) + (a / (b + 2.0));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log((b + 2.0)) + (a / (b + 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(1.0 + exp(a))); else tmp = Float64(log(Float64(b + 2.0)) + Float64(a / Float64(b + 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 / (1.0 + exp(a));
else
tmp = log((b + 2.0)) + (a / (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[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(b + 2.0), $MachinePrecision]], $MachinePrecision] + N[(a / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right) + \frac{a}{b + 2}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 10.2%
Taylor expanded in b around 0 7.9%
associate-+r+7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around 0 98.7%
log1p-def98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in b around inf 98.7%
if 0.0 < (exp.f64 a) Initial program 67.2%
Taylor expanded in b around 0 64.0%
associate-+r+64.0%
+-commutative64.0%
Simplified64.0%
Taylor expanded in a around 0 64.2%
Final simplification74.3%
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 (+ 1.0 (exp a))) (log (+ b (+ a 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log((b + (a + 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 / (1.0d0 + exp(a))
else
tmp = log((b + (a + 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 / (1.0 + Math.exp(a));
} else {
tmp = Math.log((b + (a + 2.0)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log((b + (a + 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(1.0 + exp(a))); else tmp = log(Float64(b + Float64(a + 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 / (1.0 + exp(a));
else
tmp = log((b + (a + 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[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(b + N[(a + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + \left(a + 2\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 10.2%
Taylor expanded in b around 0 7.9%
associate-+r+7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around 0 98.7%
log1p-def98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in b around inf 98.7%
if 0.0 < (exp.f64 a) Initial program 67.2%
Taylor expanded in b around 0 64.0%
associate-+r+64.0%
+-commutative64.0%
Simplified64.0%
Taylor expanded in a around 0 64.0%
associate-+r+64.0%
Simplified64.0%
Final simplification74.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.0) (* 0.5 b) (log (+ b (+ a 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = 0.5 * b;
} else {
tmp = log((b + (a + 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 <= (-1.0d0)) then
tmp = 0.5d0 * b
else
tmp = log((b + (a + 2.0d0)))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log((b + (a + 2.0)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -1.0: tmp = 0.5 * b else: tmp = math.log((b + (a + 2.0))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -1.0) tmp = Float64(0.5 * b); else tmp = log(Float64(b + Float64(a + 2.0))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -1.0)
tmp = 0.5 * b;
else
tmp = log((b + (a + 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, -1.0], N[(0.5 * b), $MachinePrecision], N[Log[N[(b + N[(a + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + \left(a + 2\right)\right)\\
\end{array}
\end{array}
if a < -1Initial program 10.2%
Taylor expanded in a around 0 4.1%
log1p-def4.1%
Simplified4.1%
Taylor expanded in b around 0 4.5%
+-commutative4.5%
Simplified4.5%
Taylor expanded in b around inf 18.5%
*-commutative18.5%
Simplified18.5%
if -1 < a Initial program 67.2%
Taylor expanded in b around 0 64.0%
associate-+r+64.0%
+-commutative64.0%
Simplified64.0%
Taylor expanded in a around 0 64.0%
associate-+r+64.0%
Simplified64.0%
Final simplification50.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -122.0) (* 0.5 b) (log (+ b 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -122.0) {
tmp = 0.5 * b;
} 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 <= (-122.0d0)) then
tmp = 0.5d0 * b
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 <= -122.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log((b + 2.0));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -122.0: tmp = 0.5 * b else: tmp = math.log((b + 2.0)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -122.0) tmp = Float64(0.5 * b); 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 <= -122.0)
tmp = 0.5 * b;
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, -122.0], N[(0.5 * b), $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 -122:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if a < -122Initial program 10.2%
Taylor expanded in a around 0 4.1%
log1p-def4.1%
Simplified4.1%
Taylor expanded in b around 0 4.5%
+-commutative4.5%
Simplified4.5%
Taylor expanded in b around inf 18.5%
*-commutative18.5%
Simplified18.5%
if -122 < a Initial program 67.2%
Taylor expanded in a around 0 65.7%
Taylor expanded in b around 0 63.2%
Final simplification50.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -85.0) (* 0.5 b) (log 2.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -85.0) {
tmp = 0.5 * b;
} 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 <= (-85.0d0)) then
tmp = 0.5d0 * b
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 <= -85.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log(2.0);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -85.0: tmp = 0.5 * b else: tmp = math.log(2.0) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -85.0) tmp = Float64(0.5 * b); 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 <= -85.0)
tmp = 0.5 * b;
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, -85.0], N[(0.5 * b), $MachinePrecision], N[Log[2.0], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -85:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -85Initial program 10.2%
Taylor expanded in a around 0 4.1%
log1p-def4.1%
Simplified4.1%
Taylor expanded in b around 0 4.5%
+-commutative4.5%
Simplified4.5%
Taylor expanded in b around inf 18.5%
*-commutative18.5%
Simplified18.5%
if -85 < a Initial program 67.2%
Taylor expanded in a around 0 65.7%
log1p-def65.7%
Simplified65.7%
Taylor expanded in b around 0 64.0%
Final simplification50.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* 0.5 b))
assert(a < b);
double code(double a, double b) {
return 0.5 * b;
}
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 = 0.5d0 * b
end function
assert a < b;
public static double code(double a, double b) {
return 0.5 * b;
}
[a, b] = sort([a, b]) def code(a, b): return 0.5 * b
a, b = sort([a, b]) function code(a, b) return Float64(0.5 * b) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = 0.5 * b;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(0.5 * b), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
0.5 \cdot b
\end{array}
Initial program 50.5%
Taylor expanded in a around 0 47.6%
log1p-def47.6%
Simplified47.6%
Taylor expanded in b around 0 46.6%
+-commutative46.6%
Simplified46.6%
Taylor expanded in b around inf 7.8%
*-commutative7.8%
Simplified7.8%
Final simplification7.8%
herbie shell --seed 2023336
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))