
(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 9 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}
(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}
Initial program 97.0%
Final simplification97.0%
(FPCore (a b) :precision binary64 (if (<= (exp b) 2.0) (log (+ (exp a) (+ b 1.0))) (/ b (+ (exp a) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(b) <= 2.0) {
tmp = log((exp(a) + (b + 1.0)));
} else {
tmp = b / (exp(a) + 1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(b) <= 2.0d0) then
tmp = log((exp(a) + (b + 1.0d0)))
else
tmp = b / (exp(a) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(b) <= 2.0) {
tmp = Math.log((Math.exp(a) + (b + 1.0)));
} else {
tmp = b / (Math.exp(a) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(b) <= 2.0: tmp = math.log((math.exp(a) + (b + 1.0))) else: tmp = b / (math.exp(a) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(b) <= 2.0) tmp = log(Float64(exp(a) + Float64(b + 1.0))); else tmp = Float64(b / Float64(exp(a) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(b) <= 2.0) tmp = log((exp(a) + (b + 1.0))); else tmp = b / (exp(a) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[b], $MachinePrecision], 2.0], N[Log[N[(N[Exp[a], $MachinePrecision] + N[(b + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 2:\\
\;\;\;\;\log \left(e^{a} + \left(b + 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\end{array}
\end{array}
if (exp.f64 b) < 2Initial program 97.3%
Taylor expanded in b around 0 74.7%
associate-+r+74.7%
+-commutative74.7%
Simplified74.7%
if 2 < (exp.f64 b) Initial program 67.7%
Taylor expanded in b around 0 15.3%
associate-+r+15.3%
+-commutative15.3%
Simplified15.3%
Taylor expanded in b around 0 72.9%
log1p-define72.9%
+-commutative72.9%
Simplified72.9%
Taylor expanded in b around inf 72.9%
Final simplification74.7%
(FPCore (a b) :precision binary64 (if (<= (exp b) 1.0000001) (log1p (exp a)) (/ b (+ (exp a) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(b) <= 1.0000001) {
tmp = log1p(exp(a));
} else {
tmp = b / (exp(a) + 1.0);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (Math.exp(b) <= 1.0000001) {
tmp = Math.log1p(Math.exp(a));
} else {
tmp = b / (Math.exp(a) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(b) <= 1.0000001: tmp = math.log1p(math.exp(a)) else: tmp = b / (math.exp(a) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(b) <= 1.0000001) tmp = log1p(exp(a)); else tmp = Float64(b / Float64(exp(a) + 1.0)); end return tmp end
code[a_, b_] := If[LessEqual[N[Exp[b], $MachinePrecision], 1.0000001], N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 1.0000001:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\end{array}
\end{array}
if (exp.f64 b) < 1.00000010000000006Initial program 97.4%
Taylor expanded in b around 0 75.3%
log1p-define75.4%
Simplified75.4%
if 1.00000010000000006 < (exp.f64 b) Initial program 73.5%
Taylor expanded in b around 0 32.8%
associate-+r+32.8%
+-commutative32.8%
Simplified32.8%
Taylor expanded in b around 0 76.3%
log1p-define76.3%
+-commutative76.3%
Simplified76.3%
Taylor expanded in b around inf 66.0%
Final simplification75.3%
(FPCore (a b) :precision binary64 (if (<= a -1.4) (* b 0.5) (+ (log 2.0) (* a 0.5))))
double code(double a, double b) {
double tmp;
if (a <= -1.4) {
tmp = b * 0.5;
} else {
tmp = log(2.0) + (a * 0.5);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.4d0)) then
tmp = b * 0.5d0
else
tmp = log(2.0d0) + (a * 0.5d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.4) {
tmp = b * 0.5;
} else {
tmp = Math.log(2.0) + (a * 0.5);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.4: tmp = b * 0.5 else: tmp = math.log(2.0) + (a * 0.5) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.4) tmp = Float64(b * 0.5); else tmp = Float64(log(2.0) + Float64(a * 0.5)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.4) tmp = b * 0.5; else tmp = log(2.0) + (a * 0.5); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.4], N[(b * 0.5), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.4:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log 2 + a \cdot 0.5\\
\end{array}
\end{array}
if a < -1.3999999999999999Initial program 96.6%
Taylor expanded in a around 0 5.0%
log1p-define5.0%
Simplified5.0%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 6.7%
if -1.3999999999999999 < a Initial program 97.1%
Taylor expanded in b around 0 66.6%
log1p-define66.6%
Simplified66.6%
Taylor expanded in a around 0 65.5%
*-commutative65.5%
Simplified65.5%
Final simplification47.8%
(FPCore (a b) :precision binary64 (if (<= a -1.4) (/ b (+ (exp a) 1.0)) (+ (log 2.0) (* a 0.5))))
double code(double a, double b) {
double tmp;
if (a <= -1.4) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log(2.0) + (a * 0.5);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.4d0)) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log(2.0d0) + (a * 0.5d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.4) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log(2.0) + (a * 0.5);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.4: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log(2.0) + (a * 0.5) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.4) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = Float64(log(2.0) + Float64(a * 0.5)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.4) tmp = b / (exp(a) + 1.0); else tmp = log(2.0) + (a * 0.5); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.4], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.4:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log 2 + a \cdot 0.5\\
\end{array}
\end{array}
if a < -1.3999999999999999Initial program 96.6%
Taylor expanded in b around 0 93.0%
associate-+r+93.0%
+-commutative93.0%
Simplified93.0%
Taylor expanded in b around 0 13.0%
log1p-define13.4%
+-commutative13.4%
Simplified13.4%
Taylor expanded in b around inf 12.6%
if -1.3999999999999999 < a Initial program 97.1%
Taylor expanded in b around 0 66.6%
log1p-define66.6%
Simplified66.6%
Taylor expanded in a around 0 65.5%
*-commutative65.5%
Simplified65.5%
Final simplification49.6%
(FPCore (a b) :precision binary64 (if (<= a -50.0) (* b 0.5) (log (+ b 2.0))))
double code(double a, double b) {
double tmp;
if (a <= -50.0) {
tmp = b * 0.5;
} else {
tmp = log((b + 2.0));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-50.0d0)) then
tmp = b * 0.5d0
else
tmp = log((b + 2.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -50.0) {
tmp = b * 0.5;
} else {
tmp = Math.log((b + 2.0));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -50.0: tmp = b * 0.5 else: tmp = math.log((b + 2.0)) return tmp
function code(a, b) tmp = 0.0 if (a <= -50.0) tmp = Float64(b * 0.5); else tmp = log(Float64(b + 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -50.0) tmp = b * 0.5; else tmp = log((b + 2.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -50.0], N[(b * 0.5), $MachinePrecision], N[Log[N[(b + 2.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -50:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if a < -50Initial program 97.5%
Taylor expanded in a around 0 4.9%
log1p-define4.9%
Simplified4.9%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 6.8%
if -50 < a Initial program 96.7%
Taylor expanded in a around 0 94.2%
Taylor expanded in b around 0 64.0%
+-commutative64.0%
Simplified64.0%
Final simplification47.0%
(FPCore (a b) :precision binary64 (if (<= a -50.0) (* b 0.5) (log1p (+ b 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -50.0) {
tmp = b * 0.5;
} else {
tmp = log1p((b + 1.0));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -50.0) {
tmp = b * 0.5;
} else {
tmp = Math.log1p((b + 1.0));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -50.0: tmp = b * 0.5 else: tmp = math.log1p((b + 1.0)) return tmp
function code(a, b) tmp = 0.0 if (a <= -50.0) tmp = Float64(b * 0.5); else tmp = log1p(Float64(b + 1.0)); end return tmp end
code[a_, b_] := If[LessEqual[a, -50.0], N[(b * 0.5), $MachinePrecision], N[Log[1 + N[(b + 1.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -50:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(b + 1\right)\\
\end{array}
\end{array}
if a < -50Initial program 97.5%
Taylor expanded in a around 0 4.9%
log1p-define4.9%
Simplified4.9%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 6.8%
if -50 < a Initial program 96.7%
Taylor expanded in a around 0 94.2%
Taylor expanded in b around 0 64.0%
+-commutative64.0%
Simplified64.0%
log1p-expm1-u64.0%
expm1-undefine64.0%
add-exp-log64.0%
Applied egg-rr64.0%
associate--l+64.0%
metadata-eval64.0%
Simplified64.0%
Final simplification47.0%
(FPCore (a b) :precision binary64 (if (<= a -50.0) (* b 0.5) (log 2.0)))
double code(double a, double b) {
double tmp;
if (a <= -50.0) {
tmp = b * 0.5;
} else {
tmp = log(2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-50.0d0)) then
tmp = b * 0.5d0
else
tmp = log(2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -50.0) {
tmp = b * 0.5;
} else {
tmp = Math.log(2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -50.0: tmp = b * 0.5 else: tmp = math.log(2.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -50.0) tmp = Float64(b * 0.5); else tmp = log(2.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -50.0) tmp = b * 0.5; else tmp = log(2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -50.0], N[(b * 0.5), $MachinePrecision], N[Log[2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -50:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if a < -50Initial program 97.5%
Taylor expanded in a around 0 4.9%
log1p-define4.9%
Simplified4.9%
Taylor expanded in b around 0 4.1%
*-commutative4.1%
Simplified4.1%
Taylor expanded in b around inf 6.8%
if -50 < a Initial program 96.7%
Taylor expanded in b around 0 66.4%
log1p-define66.5%
Simplified66.5%
Taylor expanded in a around 0 64.4%
Final simplification47.3%
(FPCore (a b) :precision binary64 (* b 0.5))
double code(double a, double b) {
return b * 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = b * 0.5d0
end function
public static double code(double a, double b) {
return b * 0.5;
}
def code(a, b): return b * 0.5
function code(a, b) return Float64(b * 0.5) end
function tmp = code(a, b) tmp = b * 0.5; end
code[a_, b_] := N[(b * 0.5), $MachinePrecision]
\begin{array}{l}
\\
b \cdot 0.5
\end{array}
Initial program 97.0%
Taylor expanded in a around 0 67.7%
log1p-define67.7%
Simplified67.7%
Taylor expanded in b around 0 46.8%
*-commutative46.8%
Simplified46.8%
Taylor expanded in b around inf 4.3%
Final simplification4.3%
herbie shell --seed 2024052
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))