
(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 (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 49.7%
add-sqr-sqrt48.6%
log-prod49.0%
Applied egg-rr49.0%
log-prod48.6%
rem-square-sqrt49.7%
log1p-expm149.7%
expm1-def49.7%
rem-exp-log49.7%
associate--l+50.3%
expm1-def72.3%
Simplified72.3%
Final simplification72.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 5e-78) (/ b (+ (exp a) 1.0)) (log (+ (exp a) (exp b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 5e-78) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log((exp(a) + exp(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 (exp(a) <= 5d-78) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log((exp(a) + exp(b)))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 5e-78) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log((Math.exp(a) + Math.exp(b)));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 5e-78: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log((math.exp(a) + math.exp(b))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 5e-78) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log(Float64(exp(a) + exp(b))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 5e-78)
tmp = b / (exp(a) + 1.0);
else
tmp = log((exp(a) + exp(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[N[Exp[a], $MachinePrecision], 5e-78], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 4.9999999999999996e-78Initial program 10.4%
Taylor expanded in b around 0 98.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 98.6%
if 4.9999999999999996e-78 < (exp.f64 a) Initial program 62.8%
Final simplification71.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-8) (/ b (+ (exp a) 1.0)) (log1p (+ a (exp b)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-8) {
tmp = b / (exp(a) + 1.0);
} 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-8) {
tmp = b / (Math.exp(a) + 1.0);
} 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-8: tmp = b / (math.exp(a) + 1.0) 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-8) tmp = Float64(b / Float64(exp(a) + 1.0)); 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-8], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $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^{-8}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(a + e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2e-8Initial program 11.2%
Taylor expanded in b around 0 98.1%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 97.1%
if 2e-8 < (exp.f64 a) Initial program 62.8%
Taylor expanded in a around 0 61.8%
associate-+r+61.8%
+-commutative61.8%
Simplified61.8%
Taylor expanded in b around inf 61.8%
log1p-def98.3%
Simplified98.3%
Final simplification98.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 5e-297) (/ b (+ (exp a) 1.0)) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 5e-297) {
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) <= 5e-297) {
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) <= 5e-297: 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) <= 5e-297) 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], 5e-297], 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 5 \cdot 10^{-297}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 5e-297Initial program 10.5%
Taylor expanded in b around 0 100.0%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 5e-297 < (exp.f64 a) Initial program 62.5%
Taylor expanded in b around 0 59.7%
log1p-def60.4%
Simplified60.4%
Final simplification70.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 5e-78) (/ b (+ (exp a) 1.0)) (log1p (exp b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 5e-78) {
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) <= 5e-78) {
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) <= 5e-78: 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) <= 5e-78) 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], 5e-78], 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 5 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 4.9999999999999996e-78Initial program 10.4%
Taylor expanded in b around 0 98.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 98.6%
if 4.9999999999999996e-78 < (exp.f64 a) Initial program 62.8%
Taylor expanded in a around 0 60.2%
log1p-def60.2%
Simplified60.2%
Final simplification69.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 5e-78) (/ b (+ (exp a) 1.0)) (log (+ b (+ 2.0 (* 0.5 (* b b)))))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 5e-78) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log((b + (2.0 + (0.5 * (b * 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 (exp(a) <= 5d-78) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log((b + (2.0d0 + (0.5d0 * (b * b)))))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 5e-78) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log((b + (2.0 + (0.5 * (b * b)))));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if math.exp(a) <= 5e-78: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log((b + (2.0 + (0.5 * (b * b))))) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 5e-78) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log(Float64(b + Float64(2.0 + Float64(0.5 * Float64(b * b))))); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (exp(a) <= 5e-78)
tmp = b / (exp(a) + 1.0);
else
tmp = log((b + (2.0 + (0.5 * (b * 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[N[Exp[a], $MachinePrecision], 5e-78], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[N[(b + N[(2.0 + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + \left(2 + 0.5 \cdot \left(b \cdot b\right)\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 4.9999999999999996e-78Initial program 10.4%
Taylor expanded in b around 0 98.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 98.6%
if 4.9999999999999996e-78 < (exp.f64 a) Initial program 62.8%
Taylor expanded in b around 0 60.3%
+-commutative60.3%
associate-+r+60.3%
associate-+l+60.3%
+-commutative60.3%
associate-+l+60.3%
fma-def60.3%
unpow260.3%
Simplified60.3%
Taylor expanded in a around 0 58.2%
unpow258.2%
Simplified58.2%
Final simplification68.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-8) (/ b (+ (exp a) 1.0)) (log (+ b (+ a 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-8) {
tmp = b / (exp(a) + 1.0);
} 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) <= 2d-8) then
tmp = b / (exp(a) + 1.0d0)
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) <= 2e-8) {
tmp = b / (Math.exp(a) + 1.0);
} 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) <= 2e-8: tmp = b / (math.exp(a) + 1.0) 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) <= 2e-8) tmp = Float64(b / Float64(exp(a) + 1.0)); 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) <= 2e-8)
tmp = b / (exp(a) + 1.0);
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], 2e-8], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $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 2 \cdot 10^{-8}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + \left(a + 2\right)\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2e-8Initial program 11.2%
Taylor expanded in b around 0 98.1%
log1p-def100.0%
Simplified100.0%
Taylor expanded in b around inf 97.1%
if 2e-8 < (exp.f64 a) Initial program 62.8%
Taylor expanded in b around 0 58.9%
associate-+r+58.9%
+-commutative58.9%
associate-+l+58.9%
Simplified58.9%
Taylor expanded in a around 0 57.9%
+-commutative57.9%
+-commutative57.9%
associate-+l+57.9%
Simplified57.9%
Final simplification67.9%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log1p (+ (exp a) b)))
assert(a < b);
double code(double a, double b) {
return log1p((exp(a) + b));
}
assert a < b;
public static double code(double a, double b) {
return Math.log1p((Math.exp(a) + b));
}
[a, b] = sort([a, b]) def code(a, b): return math.log1p((math.exp(a) + b))
a, b = sort([a, b]) function code(a, b) return log1p(Float64(exp(a) + 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] + b), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(e^{a} + b\right)
\end{array}
Initial program 49.7%
Taylor expanded in b around 0 46.3%
associate-+r+46.3%
+-commutative46.3%
associate-+l+46.3%
Simplified46.3%
Taylor expanded in a around inf 46.3%
log1p-def68.5%
+-commutative68.5%
Simplified68.5%
Final simplification68.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (* b 0.5) (log 2.0)))
assert(a < b);
double code(double a, double b) {
return (b * 0.5) + log(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 * 0.5d0) + log(2.0d0)
end function
assert a < b;
public static double code(double a, double b) {
return (b * 0.5) + Math.log(2.0);
}
[a, b] = sort([a, b]) def code(a, b): return (b * 0.5) + math.log(2.0)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(b * 0.5) + log(2.0)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (b * 0.5) + log(2.0);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(b * 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
b \cdot 0.5 + \log 2
\end{array}
Initial program 49.7%
Taylor expanded in b around 0 47.4%
+-commutative47.4%
associate-+r+47.4%
associate-+l+47.4%
+-commutative47.4%
associate-+l+47.4%
fma-def47.4%
unpow247.4%
Simplified47.4%
Taylor expanded in a around 0 44.6%
unpow244.6%
Simplified44.6%
Taylor expanded in b around 0 44.4%
Final simplification44.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log (+ b 2.0)))
assert(a < b);
double code(double a, double b) {
return log((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 = log((b + 2.0d0))
end function
assert a < b;
public static double code(double a, double b) {
return Math.log((b + 2.0));
}
[a, b] = sort([a, b]) def code(a, b): return math.log((b + 2.0))
a, b = sort([a, b]) function code(a, b) return log(Float64(b + 2.0)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = log((b + 2.0));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[N[(b + 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\log \left(b + 2\right)
\end{array}
Initial program 49.7%
Taylor expanded in b around 0 46.3%
associate-+r+46.3%
+-commutative46.3%
associate-+l+46.3%
Simplified46.3%
Taylor expanded in a around 0 43.5%
+-commutative43.5%
Simplified43.5%
Final simplification43.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log 2.0))
assert(a < b);
double code(double a, double b) {
return log(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 = log(2.0d0)
end function
assert a < b;
public static double code(double a, double b) {
return Math.log(2.0);
}
[a, b] = sort([a, b]) def code(a, b): return math.log(2.0)
a, b = sort([a, b]) function code(a, b) return log(2.0) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = log(2.0);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[2.0], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\log 2
\end{array}
Initial program 49.7%
Taylor expanded in b around 0 47.4%
+-commutative47.4%
associate-+r+47.4%
associate-+l+47.4%
+-commutative47.4%
associate-+l+47.4%
fma-def47.4%
unpow247.4%
Simplified47.4%
Taylor expanded in a around 0 44.6%
unpow244.6%
Simplified44.6%
Taylor expanded in b around 0 44.4%
Final simplification44.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ a (+ b 2.0)))
assert(a < b);
double code(double a, double b) {
return a / (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 = a / (b + 2.0d0)
end function
assert a < b;
public static double code(double a, double b) {
return a / (b + 2.0);
}
[a, b] = sort([a, b]) def code(a, b): return a / (b + 2.0)
a, b = sort([a, b]) function code(a, b) return Float64(a / Float64(b + 2.0)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = a / (b + 2.0);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(a / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{a}{b + 2}
\end{array}
Initial program 49.7%
Taylor expanded in b around 0 46.3%
associate-+r+46.3%
+-commutative46.3%
associate-+l+46.3%
Simplified46.3%
Taylor expanded in a around 0 43.9%
Taylor expanded in a around inf 3.9%
+-commutative3.9%
Simplified3.9%
Final simplification3.9%
herbie shell --seed 2023174
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))