
(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 13 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 (if (<= (exp a) 2e-33) (/ b (+ 1.0 (exp a))) (log1p (+ a (exp b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-33) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log1p((a + exp(b)));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 2e-33) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log1p((a + Math.exp(b)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 2e-33: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log1p((a + math.exp(b))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2e-33) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = log1p(Float64(a + 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], 2e-33], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(a + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(a + e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.0000000000000001e-33Initial program 10.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in b around 0 100.0%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 2.0000000000000001e-33 < (exp.f64 a) Initial program 62.9%
Taylor expanded in a around 0 61.6%
+-commutative61.6%
Simplified61.6%
Taylor expanded in b around inf 61.6%
log1p-def96.8%
Simplified96.8%
Final simplification97.7%
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 47.8%
Taylor expanded in b around 0 71.7%
Final simplification71.7%
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 47.8%
Taylor expanded in b around 0 71.6%
log1p-def71.7%
Simplified71.7%
Final simplification71.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 1e-107) (/ b (+ 1.0 (exp a))) (log1p (exp b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 1e-107) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log1p(exp(b));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 1e-107) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log1p(Math.exp(b));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 1e-107: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log1p(math.exp(b)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 1e-107) tmp = Float64(b / Float64(1.0 + exp(a))); 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], 1e-107], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $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 10^{-107}:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 1e-107Initial program 10.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in b around 0 100.0%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 1e-107 < (exp.f64 a) Initial program 62.9%
Taylor expanded in a around 0 60.3%
log1p-def60.8%
Simplified60.8%
Final simplification72.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log1p (+ (exp a) (expm1 b))))
assert(a < b);
double code(double a, double b) {
return log1p((exp(a) + expm1(b)));
}
assert a < b;
public static double code(double a, double b) {
return Math.log1p((Math.exp(a) + Math.expm1(b)));
}
[a, b] = sort([a, b]) def code(a, b): return math.log1p((math.exp(a) + math.expm1(b)))
a, b = sort([a, b]) function code(a, b) return log1p(Float64(exp(a) + expm1(b))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[1 + N[(N[Exp[a], $MachinePrecision] + N[(Exp[b] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)
\end{array}
Initial program 47.8%
add-sqr-sqrt46.6%
pow246.6%
metadata-eval46.6%
pow-to-exp46.6%
metadata-eval46.6%
Applied egg-rr46.6%
exp-to-pow46.6%
pow246.6%
log1p-expm1-u46.6%
add-sqr-sqrt47.8%
log1p-udef47.8%
expm1-udef47.8%
add-exp-log47.8%
Applied egg-rr47.8%
log1p-def47.8%
associate--l+47.9%
expm1-def72.2%
Simplified72.2%
Final simplification72.2%
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 (+ 2.0 (+ a b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.0) {
tmp = 0.5 * b;
} else {
tmp = log((2.0 + (a + b)));
}
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((2.0d0 + (a + b)))
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((2.0 + (a + b)));
}
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((2.0 + (a + b))) 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(2.0 + Float64(a + b))); 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((2.0 + (a + b)));
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[(2.0 + N[(a + b), $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(2 + \left(a + b\right)\right)\\
\end{array}
\end{array}
if a < -1Initial program 10.7%
Taylor expanded in a around 0 4.1%
Taylor expanded in b around 0 5.0%
Taylor expanded in b around inf 18.8%
if -1 < a Initial program 62.9%
Taylor expanded in b around 0 59.0%
associate-+r+59.0%
+-commutative59.0%
Simplified59.0%
Taylor expanded in a around 0 58.2%
Final simplification46.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -250.0) (* 0.5 b) (+ (log 2.0) (* 0.5 b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -250.0) {
tmp = 0.5 * b;
} else {
tmp = log(2.0) + (0.5 * b);
}
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 <= (-250.0d0)) then
tmp = 0.5d0 * b
else
tmp = log(2.0d0) + (0.5d0 * b)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -250.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log(2.0) + (0.5 * b);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -250.0: tmp = 0.5 * b else: tmp = math.log(2.0) + (0.5 * b) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -250.0) tmp = Float64(0.5 * b); else tmp = Float64(log(2.0) + Float64(0.5 * b)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -250.0)
tmp = 0.5 * b;
else
tmp = log(2.0) + (0.5 * b);
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, -250.0], N[(0.5 * b), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(0.5 * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -250:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log 2 + 0.5 \cdot b\\
\end{array}
\end{array}
if a < -250Initial program 10.7%
Taylor expanded in a around 0 4.1%
Taylor expanded in b around 0 5.0%
Taylor expanded in b around inf 18.8%
if -250 < a Initial program 62.9%
Taylor expanded in a around 0 60.3%
Taylor expanded in b around 0 58.5%
Final simplification47.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -76.0) (/ b (+ 1.0 (exp a))) (+ (log 2.0) (* 0.5 b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -76.0) {
tmp = b / (1.0 + exp(a));
} else {
tmp = log(2.0) + (0.5 * b);
}
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 <= (-76.0d0)) then
tmp = b / (1.0d0 + exp(a))
else
tmp = log(2.0d0) + (0.5d0 * b)
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -76.0) {
tmp = b / (1.0 + Math.exp(a));
} else {
tmp = Math.log(2.0) + (0.5 * b);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -76.0: tmp = b / (1.0 + math.exp(a)) else: tmp = math.log(2.0) + (0.5 * b) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -76.0) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = Float64(log(2.0) + Float64(0.5 * b)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -76.0)
tmp = b / (1.0 + exp(a));
else
tmp = log(2.0) + (0.5 * b);
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, -76.0], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(0.5 * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -76:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\log 2 + 0.5 \cdot b\\
\end{array}
\end{array}
if a < -76Initial program 10.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in b around 0 100.0%
log1p-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if -76 < a Initial program 62.9%
Taylor expanded in a around 0 60.3%
Taylor expanded in b around 0 58.5%
Final simplification70.5%
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 (+ 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((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((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((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((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(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((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[(a + 2.0), $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(a + 2\right)\\
\end{array}
\end{array}
if a < -1Initial program 10.7%
Taylor expanded in a around 0 4.1%
Taylor expanded in b around 0 5.0%
Taylor expanded in b around inf 18.8%
if -1 < a Initial program 62.9%
Taylor expanded in b around 0 59.0%
associate-+r+59.0%
+-commutative59.0%
Simplified59.0%
Taylor expanded in a around 0 58.2%
Taylor expanded in b around 0 59.0%
Final simplification47.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -120.0) (* 0.5 b) (log (+ b 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -120.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 <= (-120.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 <= -120.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 <= -120.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 <= -120.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 <= -120.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, -120.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 -120:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if a < -120Initial program 10.7%
Taylor expanded in a around 0 4.1%
Taylor expanded in b around 0 5.0%
Taylor expanded in b around inf 18.8%
if -120 < a Initial program 62.9%
Taylor expanded in a around 0 60.3%
Taylor expanded in b around 0 57.4%
Final simplification46.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -140.0) (* 0.5 b) (log1p (+ 1.0 b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -140.0) {
tmp = 0.5 * b;
} else {
tmp = log1p((1.0 + b));
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -140.0) {
tmp = 0.5 * b;
} else {
tmp = Math.log1p((1.0 + b));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -140.0: tmp = 0.5 * b else: tmp = math.log1p((1.0 + b)) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -140.0) tmp = Float64(0.5 * b); else tmp = log1p(Float64(1.0 + b)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[a, -140.0], N[(0.5 * b), $MachinePrecision], N[Log[1 + N[(1.0 + b), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -140:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(1 + b\right)\\
\end{array}
\end{array}
if a < -140Initial program 10.7%
Taylor expanded in a around 0 4.1%
Taylor expanded in b around 0 5.0%
Taylor expanded in b around inf 18.8%
if -140 < a Initial program 62.9%
Taylor expanded in a around 0 60.3%
Taylor expanded in b around 0 57.4%
log1p-expm1-u57.4%
expm1-udef57.4%
add-exp-log57.4%
Applied egg-rr57.4%
+-commutative57.4%
associate--l+57.4%
metadata-eval57.4%
Simplified57.4%
Final simplification46.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -125.0) (* 0.5 b) (log 2.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -125.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 <= (-125.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 <= -125.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 <= -125.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 <= -125.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 <= -125.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, -125.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 -125:\\
\;\;\;\;0.5 \cdot b\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -125Initial program 10.7%
Taylor expanded in a around 0 4.1%
Taylor expanded in b around 0 5.0%
Taylor expanded in b around inf 18.8%
if -125 < a Initial program 62.9%
Taylor expanded in a around 0 60.3%
Taylor expanded in b around 0 58.2%
Final simplification46.8%
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 47.8%
Taylor expanded in a around 0 44.0%
Taylor expanded in b around 0 43.0%
Taylor expanded in b around inf 8.0%
Final simplification8.0%
herbie shell --seed 2024011
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))