
(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 18 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))))
(+
(* b (fma (* b -0.5) (pow t_0 -2.0) (/ (fma b 0.5 1.0) t_0)))
(log1p (exp a)))))assert(a < b);
double code(double a, double b) {
double t_0 = 1.0 + exp(a);
return (b * fma((b * -0.5), pow(t_0, -2.0), (fma(b, 0.5, 1.0) / t_0))) + log1p(exp(a));
}
a, b = sort([a, b]) function code(a, b) t_0 = Float64(1.0 + exp(a)) return Float64(Float64(b * fma(Float64(b * -0.5), (t_0 ^ -2.0), Float64(fma(b, 0.5, 1.0) / t_0))) + log1p(exp(a))) 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[(b * N[(N[(b * -0.5), $MachinePrecision] * N[Power[t$95$0, -2.0], $MachinePrecision] + N[(N[(b * 0.5 + 1.0), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := 1 + e^{a}\\
b \cdot \mathsf{fma}\left(b \cdot -0.5, {t\_0}^{-2}, \frac{\mathsf{fma}\left(b, 0.5, 1\right)}{t\_0}\right) + \mathsf{log1p}\left(e^{a}\right)
\end{array}
\end{array}
Initial program 52.4%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified72.5%
Applied egg-rr72.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (+ (exp a) (exp b)) 1.1) (/ b (+ 1.0 (exp a))) (log1p (exp b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if ((exp(a) + exp(b)) <= 1.1) {
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) + Math.exp(b)) <= 1.1) {
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) + math.exp(b)) <= 1.1: 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 (Float64(exp(a) + exp(b)) <= 1.1) 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[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision], 1.1], 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} + e^{b} \leq 1.1:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\end{array}
if (+.f64 (exp.f64 a) (exp.f64 b)) < 1.1000000000000001Initial program 9.2%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified50.0%
Applied egg-rr50.0%
Taylor expanded in b around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6450.2
Simplified50.2%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6449.0
Simplified49.0%
if 1.1000000000000001 < (+.f64 (exp.f64 a) (exp.f64 b)) Initial program 97.5%
Taylor expanded in a around 0
lower-log1p.f64N/A
lower-exp.f6495.1
Simplified95.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (+ (exp a) (exp b)) 1.5) (/ b (+ 1.0 (exp a))) (fma a (fma b -0.25 0.5) (fma b (fma b 0.125 0.5) (log 2.0)))))
assert(a < b);
double code(double a, double b) {
double tmp;
if ((exp(a) + exp(b)) <= 1.5) {
tmp = b / (1.0 + exp(a));
} else {
tmp = fma(a, fma(b, -0.25, 0.5), fma(b, fma(b, 0.125, 0.5), log(2.0)));
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (Float64(exp(a) + exp(b)) <= 1.5) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = fma(a, fma(b, -0.25, 0.5), fma(b, fma(b, 0.125, 0.5), log(2.0))); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision], 1.5], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(b * -0.25 + 0.5), $MachinePrecision] + N[(b * N[(b * 0.125 + 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} + e^{b} \leq 1.5:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, \mathsf{fma}\left(b, -0.25, 0.5\right), \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.125, 0.5\right), \log 2\right)\right)\\
\end{array}
\end{array}
if (+.f64 (exp.f64 a) (exp.f64 b)) < 1.5Initial program 9.9%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified49.8%
Applied egg-rr49.8%
Taylor expanded in b around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6449.9
Simplified49.9%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6448.6
Simplified48.6%
if 1.5 < (+.f64 (exp.f64 a) (exp.f64 b)) Initial program 97.5%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified96.7%
Taylor expanded in a around 0
distribute-rgt-outN/A
metadata-evalN/A
mul0-rgtN/A
metadata-evalN/A
metadata-evalN/A
mul0-rgtN/A
metadata-evalN/A
distribute-rgt-outN/A
+-commutativeN/A
associate-+l+N/A
Simplified95.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (+ (exp a) (exp b)) 1.1) (/ b (+ 1.0 (exp a))) (fma b (fma b 0.125 0.5) (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if ((exp(a) + exp(b)) <= 1.1) {
tmp = b / (1.0 + exp(a));
} else {
tmp = fma(b, fma(b, 0.125, 0.5), log(2.0));
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (Float64(exp(a) + exp(b)) <= 1.1) tmp = Float64(b / Float64(1.0 + exp(a))); else tmp = fma(b, fma(b, 0.125, 0.5), log(2.0)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision], 1.1], N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(b * 0.125 + 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} + e^{b} \leq 1.1:\\
\;\;\;\;\frac{b}{1 + e^{a}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.125, 0.5\right), \log 2\right)\\
\end{array}
\end{array}
if (+.f64 (exp.f64 a) (exp.f64 b)) < 1.1000000000000001Initial program 9.2%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified50.0%
Applied egg-rr50.0%
Taylor expanded in b around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6450.2
Simplified50.2%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6449.0
Simplified49.0%
if 1.1000000000000001 < (+.f64 (exp.f64 a) (exp.f64 b)) Initial program 97.5%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified96.1%
Taylor expanded in a around 0
+-commutativeN/A
distribute-rgt-outN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f6493.6
Simplified93.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (+ (exp a) (exp b)) 1.1) (fma (* b b) (* b -0.16666666666666666) b) (fma b (fma b 0.125 0.5) (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if ((exp(a) + exp(b)) <= 1.1) {
tmp = fma((b * b), (b * -0.16666666666666666), b);
} else {
tmp = fma(b, fma(b, 0.125, 0.5), log(2.0));
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (Float64(exp(a) + exp(b)) <= 1.1) tmp = fma(Float64(b * b), Float64(b * -0.16666666666666666), b); else tmp = fma(b, fma(b, 0.125, 0.5), log(2.0)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision], 1.1], N[(N[(b * b), $MachinePrecision] * N[(b * -0.16666666666666666), $MachinePrecision] + b), $MachinePrecision], N[(b * N[(b * 0.125 + 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} + e^{b} \leq 1.1:\\
\;\;\;\;\mathsf{fma}\left(b \cdot b, b \cdot -0.16666666666666666, b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.125, 0.5\right), \log 2\right)\\
\end{array}
\end{array}
if (+.f64 (exp.f64 a) (exp.f64 b)) < 1.1000000000000001Initial program 9.2%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f645.5
Simplified5.5%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f645.2
Simplified5.2%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6447.8
Simplified47.8%
if 1.1000000000000001 < (+.f64 (exp.f64 a) (exp.f64 b)) Initial program 97.5%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified96.1%
Taylor expanded in a around 0
+-commutativeN/A
distribute-rgt-outN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f6493.6
Simplified93.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (+ (exp a) (exp b)) 1.1) (fma (* b b) (* b -0.16666666666666666) b) (fma a (fma a 0.125 0.5) (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if ((exp(a) + exp(b)) <= 1.1) {
tmp = fma((b * b), (b * -0.16666666666666666), b);
} else {
tmp = fma(a, fma(a, 0.125, 0.5), log(2.0));
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (Float64(exp(a) + exp(b)) <= 1.1) tmp = fma(Float64(b * b), Float64(b * -0.16666666666666666), b); else tmp = fma(a, fma(a, 0.125, 0.5), log(2.0)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision], 1.1], N[(N[(b * b), $MachinePrecision] * N[(b * -0.16666666666666666), $MachinePrecision] + b), $MachinePrecision], N[(a * N[(a * 0.125 + 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} + e^{b} \leq 1.1:\\
\;\;\;\;\mathsf{fma}\left(b \cdot b, b \cdot -0.16666666666666666, b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.125, 0.5\right), \log 2\right)\\
\end{array}
\end{array}
if (+.f64 (exp.f64 a) (exp.f64 b)) < 1.1000000000000001Initial program 9.2%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f645.5
Simplified5.5%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f645.2
Simplified5.2%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6447.8
Simplified47.8%
if 1.1000000000000001 < (+.f64 (exp.f64 a) (exp.f64 b)) Initial program 97.5%
Taylor expanded in b around 0
lower-log1p.f64N/A
lower-exp.f6495.6
Simplified95.6%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f6494.7
Simplified94.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (log1p (exp a)) (/ b (+ 1.0 (exp a)))))
assert(a < b);
double code(double a, double b) {
return log1p(exp(a)) + (b / (1.0 + exp(a)));
}
assert a < b;
public static double code(double a, double b) {
return Math.log1p(Math.exp(a)) + (b / (1.0 + Math.exp(a)));
}
[a, b] = sort([a, b]) def code(a, b): return math.log1p(math.exp(a)) + (b / (1.0 + math.exp(a)))
a, b = sort([a, b]) function code(a, b) return Float64(log1p(exp(a)) + Float64(b / Float64(1.0 + exp(a)))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision] + N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(e^{a}\right) + \frac{b}{1 + e^{a}}
\end{array}
Initial program 52.4%
Taylor expanded in b around 0
*-rgt-identityN/A
associate-*r/N/A
lower-+.f64N/A
lower-log1p.f64N/A
lower-exp.f64N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6472.5
Simplified72.5%
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 8.2%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Simplified100.0%
Applied egg-rr100.0%
Taylor expanded in b around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Simplified100.0%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Simplified100.0%
if 0.0 < (exp.f64 a) Initial program 66.5%
Taylor expanded in b around 0
lower-log1p.f64N/A
lower-exp.f6463.5
Simplified63.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log1p (* b (+ (fma b 0.5 1.0) (/ (exp a) b)))))
assert(a < b);
double code(double a, double b) {
return log1p((b * (fma(b, 0.5, 1.0) + (exp(a) / b))));
}
a, b = sort([a, b]) function code(a, b) return log1p(Float64(b * Float64(fma(b, 0.5, 1.0) + 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[(b * N[(N[(b * 0.5 + 1.0), $MachinePrecision] + N[(N[Exp[a], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(b \cdot \left(\mathsf{fma}\left(b, 0.5, 1\right) + \frac{e^{a}}{b}\right)\right)
\end{array}
Initial program 52.4%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f6449.6
Simplified49.6%
lift-fma.f64N/A
lift-exp.f64N/A
lift-fma.f64N/A
lower-log1p.f6472.2
Applied egg-rr72.2%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-+r+N/A
distribute-rgt-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
lft-mult-inverseN/A
associate-/r/N/A
*-rgt-identityN/A
associate-*r/N/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
Simplified72.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-9) (fma (* b b) (* b -0.16666666666666666) b) (fma b 0.5 (log 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-9) {
tmp = fma((b * b), (b * -0.16666666666666666), b);
} else {
tmp = fma(b, 0.5, log(2.0));
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2e-9) tmp = fma(Float64(b * b), Float64(b * -0.16666666666666666), b); else tmp = fma(b, 0.5, log(2.0)); 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-9], N[(N[(b * b), $MachinePrecision] * N[(b * -0.16666666666666666), $MachinePrecision] + b), $MachinePrecision], N[(b * 0.5 + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot b, b \cdot -0.16666666666666666, b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, 0.5, \log 2\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.00000000000000012e-9Initial program 9.0%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f648.1
Simplified8.1%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f647.5
Simplified7.5%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6495.7
Simplified95.7%
if 2.00000000000000012e-9 < (exp.f64 a) Initial program 66.8%
Taylor expanded in a around 0
lower-+.f64N/A
lower-exp.f6463.7
Simplified63.7%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f6461.7
Simplified61.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log1p (fma b (fma b 0.5 1.0) (exp a))))
assert(a < b);
double code(double a, double b) {
return log1p(fma(b, fma(b, 0.5, 1.0), exp(a)));
}
a, b = sort([a, b]) function code(a, b) return log1p(fma(b, fma(b, 0.5, 1.0), exp(a))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[1 + N[(b * N[(b * 0.5 + 1.0), $MachinePrecision] + N[Exp[a], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.5, 1\right), e^{a}\right)\right)
\end{array}
Initial program 52.4%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f6449.6
Simplified49.6%
lift-fma.f64N/A
lift-exp.f64N/A
lift-fma.f64N/A
lower-log1p.f6472.2
Applied egg-rr72.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-9) (fma (* b b) (* b -0.16666666666666666) b) (log1p (+ b 1.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-9) {
tmp = fma((b * b), (b * -0.16666666666666666), b);
} else {
tmp = log1p((b + 1.0));
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2e-9) tmp = fma(Float64(b * b), Float64(b * -0.16666666666666666), b); else tmp = log1p(Float64(b + 1.0)); 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-9], N[(N[(b * b), $MachinePrecision] * N[(b * -0.16666666666666666), $MachinePrecision] + b), $MachinePrecision], N[Log[1 + N[(b + 1.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot b, b \cdot -0.16666666666666666, b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(b + 1\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.00000000000000012e-9Initial program 9.0%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f648.1
Simplified8.1%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f647.5
Simplified7.5%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6495.7
Simplified95.7%
if 2.00000000000000012e-9 < (exp.f64 a) Initial program 66.8%
Taylor expanded in b around 0
lower-+.f6462.3
Simplified62.3%
lift-exp.f64N/A
associate-+r+N/A
+-commutativeN/A
associate-+l+N/A
lower-log1p.f64N/A
lower-+.f6462.3
Applied egg-rr62.3%
Taylor expanded in a around 0
lower-+.f6460.7
Simplified60.7%
Final simplification69.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-9) (fma (* b b) (* b -0.16666666666666666) b) (log (+ b 2.0))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-9) {
tmp = fma((b * b), (b * -0.16666666666666666), b);
} else {
tmp = log((b + 2.0));
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2e-9) tmp = fma(Float64(b * b), Float64(b * -0.16666666666666666), b); else tmp = log(Float64(b + 2.0)); 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-9], N[(N[(b * b), $MachinePrecision] * N[(b * -0.16666666666666666), $MachinePrecision] + b), $MachinePrecision], N[Log[N[(b + 2.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot b, b \cdot -0.16666666666666666, b\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.00000000000000012e-9Initial program 9.0%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f648.1
Simplified8.1%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f647.5
Simplified7.5%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6495.7
Simplified95.7%
if 2.00000000000000012e-9 < (exp.f64 a) Initial program 66.8%
Taylor expanded in a around 0
lower-+.f64N/A
lower-exp.f6463.7
Simplified63.7%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f6460.7
Simplified60.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= (exp a) 2e-9) (fma (* b b) (* b -0.16666666666666666) b) (log1p 1.0)))
assert(a < b);
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-9) {
tmp = fma((b * b), (b * -0.16666666666666666), b);
} else {
tmp = log1p(1.0);
}
return tmp;
}
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (exp(a) <= 2e-9) tmp = fma(Float64(b * b), Float64(b * -0.16666666666666666), b); else tmp = log1p(1.0); 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-9], N[(N[(b * b), $MachinePrecision] * N[(b * -0.16666666666666666), $MachinePrecision] + b), $MachinePrecision], N[Log[1 + 1.0], $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot b, b \cdot -0.16666666666666666, b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(1\right)\\
\end{array}
\end{array}
if (exp.f64 a) < 2.00000000000000012e-9Initial program 9.0%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f648.1
Simplified8.1%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f647.5
Simplified7.5%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6495.7
Simplified95.7%
if 2.00000000000000012e-9 < (exp.f64 a) Initial program 66.8%
Taylor expanded in b around 0
lower-log1p.f64N/A
lower-exp.f6463.5
Simplified63.5%
Taylor expanded in a around 0
Simplified61.9%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log1p (+ b (exp a))))
assert(a < b);
double code(double a, double b) {
return log1p((b + exp(a)));
}
assert a < b;
public static double code(double a, double b) {
return Math.log1p((b + Math.exp(a)));
}
[a, b] = sort([a, b]) def code(a, b): return math.log1p((b + math.exp(a)))
a, b = sort([a, b]) function code(a, b) return log1p(Float64(b + exp(a))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[1 + N[(b + N[Exp[a], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{log1p}\left(b + e^{a}\right)
\end{array}
Initial program 52.4%
Taylor expanded in b around 0
lower-+.f6448.6
Simplified48.6%
lift-exp.f64N/A
associate-+r+N/A
+-commutativeN/A
associate-+l+N/A
lower-log1p.f64N/A
lower-+.f6471.0
Applied egg-rr71.0%
Final simplification71.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (fma (fma b 0.125 -0.16666666666666666) (* b (* b b)) b))
assert(a < b);
double code(double a, double b) {
return fma(fma(b, 0.125, -0.16666666666666666), (b * (b * b)), b);
}
a, b = sort([a, b]) function code(a, b) return fma(fma(b, 0.125, -0.16666666666666666), Float64(b * Float64(b * b)), b) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(b * 0.125 + -0.16666666666666666), $MachinePrecision] * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{fma}\left(\mathsf{fma}\left(b, 0.125, -0.16666666666666666\right), b \cdot \left(b \cdot b\right), b\right)
\end{array}
Initial program 52.4%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f6449.6
Simplified49.6%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f644.3
Simplified4.3%
Taylor expanded in b around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
*-lft-identityN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6426.4
Simplified26.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (fma (* b b) (* b -0.16666666666666666) b))
assert(a < b);
double code(double a, double b) {
return fma((b * b), (b * -0.16666666666666666), b);
}
a, b = sort([a, b]) function code(a, b) return fma(Float64(b * b), Float64(b * -0.16666666666666666), b) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(b * b), $MachinePrecision] * N[(b * -0.16666666666666666), $MachinePrecision] + b), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{fma}\left(b \cdot b, b \cdot -0.16666666666666666, b\right)
\end{array}
Initial program 52.4%
Taylor expanded in b around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-exp.f6449.6
Simplified49.6%
Taylor expanded in b around inf
distribute-lft-inN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f644.3
Simplified4.3%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6426.4
Simplified26.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* b 0.5))
assert(a < b);
double code(double a, double b) {
return b * 0.5;
}
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
end function
assert a < b;
public static double code(double a, double b) {
return b * 0.5;
}
[a, b] = sort([a, b]) def code(a, b): return b * 0.5
a, b = sort([a, b]) function code(a, b) return Float64(b * 0.5) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = b * 0.5;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(b * 0.5), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
b \cdot 0.5
\end{array}
Initial program 52.4%
Taylor expanded in a around 0
lower-+.f64N/A
lower-exp.f6448.7
Simplified48.7%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f6447.2
Simplified47.2%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f647.3
Simplified7.3%
herbie shell --seed 2024207
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))