| Alternative 1 | |
|---|---|
| Accuracy | 94.1% |
| Cost | 19788 |

(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ b (+ (exp a) 1.0))))
(if (<= b -1e+79)
(* (pow a 3.0) (* b (- -0.020833333333333332)))
(if (<= b -24.0)
t_0
(if (<= b 720.0)
(log1p (+ (exp a) (expm1 b)))
(if (<= b 2.4e+79) t_0 (log1p (exp b))))))))double code(double a, double b) {
return log((exp(a) + exp(b)));
}
double code(double a, double b) {
double t_0 = b / (exp(a) + 1.0);
double tmp;
if (b <= -1e+79) {
tmp = pow(a, 3.0) * (b * -(-0.020833333333333332));
} else if (b <= -24.0) {
tmp = t_0;
} else if (b <= 720.0) {
tmp = log1p((exp(a) + expm1(b)));
} else if (b <= 2.4e+79) {
tmp = t_0;
} else {
tmp = log1p(exp(b));
}
return tmp;
}
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
public static double code(double a, double b) {
double t_0 = b / (Math.exp(a) + 1.0);
double tmp;
if (b <= -1e+79) {
tmp = Math.pow(a, 3.0) * (b * -(-0.020833333333333332));
} else if (b <= -24.0) {
tmp = t_0;
} else if (b <= 720.0) {
tmp = Math.log1p((Math.exp(a) + Math.expm1(b)));
} else if (b <= 2.4e+79) {
tmp = t_0;
} else {
tmp = Math.log1p(Math.exp(b));
}
return tmp;
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
def code(a, b): t_0 = b / (math.exp(a) + 1.0) tmp = 0 if b <= -1e+79: tmp = math.pow(a, 3.0) * (b * -(-0.020833333333333332)) elif b <= -24.0: tmp = t_0 elif b <= 720.0: tmp = math.log1p((math.exp(a) + math.expm1(b))) elif b <= 2.4e+79: tmp = t_0 else: tmp = math.log1p(math.exp(b)) return tmp
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function code(a, b) t_0 = Float64(b / Float64(exp(a) + 1.0)) tmp = 0.0 if (b <= -1e+79) tmp = Float64((a ^ 3.0) * Float64(b * Float64(-(-0.020833333333333332)))); elseif (b <= -24.0) tmp = t_0; elseif (b <= 720.0) tmp = log1p(Float64(exp(a) + expm1(b))); elseif (b <= 2.4e+79) tmp = t_0; else tmp = log1p(exp(b)); end return tmp end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := Block[{t$95$0 = N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e+79], N[(N[Power[a, 3.0], $MachinePrecision] * N[(b * (--0.020833333333333332)), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -24.0], t$95$0, If[LessEqual[b, 720.0], N[Log[1 + N[(N[Exp[a], $MachinePrecision] + N[(Exp[b] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[b, 2.4e+79], t$95$0, N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision]]]]]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
t_0 := \frac{b}{e^{a} + 1}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+79}:\\
\;\;\;\;{a}^{3} \cdot \left(b \cdot \left(--0.020833333333333332\right)\right)\\
\mathbf{elif}\;b \leq -24:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 720:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{+79}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if b < -9.99999999999999967e78Initial program 17.2%
Taylor expanded in b around 0 11.6%
Simplified11.6%
[Start]11.6% | \[ \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}
\] |
|---|---|
log1p-def [=>]11.6% | \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}}
\] |
Taylor expanded in a around 0 5.3%
Taylor expanded in a around inf 5.3%
Taylor expanded in a around inf 17.8%
Simplified17.8%
[Start]17.8% | \[ -1 \cdot \left({a}^{3} \cdot \left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + -0.5 \cdot \left(0.125 \cdot b + -0.125 \cdot b\right)\right)\right)\right)
\] |
|---|---|
mul-1-neg [=>]17.8% | \[ \color{blue}{-{a}^{3} \cdot \left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + -0.5 \cdot \left(0.125 \cdot b + -0.125 \cdot b\right)\right)\right)}
\] |
*-commutative [=>]17.8% | \[ -\color{blue}{\left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + -0.5 \cdot \left(0.125 \cdot b + -0.125 \cdot b\right)\right)\right) \cdot {a}^{3}}
\] |
distribute-rgt-neg-in [=>]17.8% | \[ \color{blue}{\left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + -0.5 \cdot \left(0.125 \cdot b + -0.125 \cdot b\right)\right)\right) \cdot \left(-{a}^{3}\right)}
\] |
distribute-rgt-out [=>]17.8% | \[ \left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + -0.5 \cdot \color{blue}{\left(b \cdot \left(0.125 + -0.125\right)\right)}\right)\right) \cdot \left(-{a}^{3}\right)
\] |
metadata-eval [=>]17.8% | \[ \left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + -0.5 \cdot \left(b \cdot \color{blue}{0}\right)\right)\right) \cdot \left(-{a}^{3}\right)
\] |
mul0-rgt [=>]17.8% | \[ \left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + -0.5 \cdot \color{blue}{0}\right)\right) \cdot \left(-{a}^{3}\right)
\] |
metadata-eval [=>]17.8% | \[ \left(0.041666666666666664 \cdot b + \left(-0.0625 \cdot b + \color{blue}{0}\right)\right) \cdot \left(-{a}^{3}\right)
\] |
+-rgt-identity [=>]17.8% | \[ \left(0.041666666666666664 \cdot b + \color{blue}{-0.0625 \cdot b}\right) \cdot \left(-{a}^{3}\right)
\] |
distribute-rgt-out [=>]17.8% | \[ \color{blue}{\left(b \cdot \left(0.041666666666666664 + -0.0625\right)\right)} \cdot \left(-{a}^{3}\right)
\] |
metadata-eval [=>]17.8% | \[ \left(b \cdot \color{blue}{-0.020833333333333332}\right) \cdot \left(-{a}^{3}\right)
\] |
if -9.99999999999999967e78 < b < -24 or 720 < b < 2.39999999999999986e79Initial program 15.8%
Taylor expanded in b around 0 40.3%
Simplified40.3%
[Start]40.3% | \[ \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}
\] |
|---|---|
log1p-def [=>]40.3% | \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}}
\] |
Taylor expanded in b around inf 27.9%
if -24 < b < 720Initial program 69.9%
Applied egg-rr69.9%
[Start]69.9% | \[ \log \left(e^{a} + e^{b}\right)
\] |
|---|---|
log1p-expm1-u [=>]69.9% | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{a} + e^{b}\right)\right)\right)}
\] |
expm1-udef [=>]69.9% | \[ \mathsf{log1p}\left(\color{blue}{e^{\log \left(e^{a} + e^{b}\right)} - 1}\right)
\] |
add-exp-log [<=]69.9% | \[ \mathsf{log1p}\left(\color{blue}{\left(e^{a} + e^{b}\right)} - 1\right)
\] |
Simplified91.2%
[Start]69.9% | \[ \mathsf{log1p}\left(\left(e^{a} + e^{b}\right) - 1\right)
\] |
|---|---|
associate--l+ [=>]69.9% | \[ \mathsf{log1p}\left(\color{blue}{e^{a} + \left(e^{b} - 1\right)}\right)
\] |
expm1-def [=>]91.2% | \[ \mathsf{log1p}\left(e^{a} + \color{blue}{\mathsf{expm1}\left(b\right)}\right)
\] |
if 2.39999999999999986e79 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ \log \left(1 + e^{b}\right)
\] |
|---|---|
log1p-def [=>]100.0% | \[ \color{blue}{\mathsf{log1p}\left(e^{b}\right)}
\] |
Final simplification67.2%
| Alternative 1 | |
|---|---|
| Accuracy | 94.1% |
| Cost | 19788 |
| Alternative 2 | |
|---|---|
| Accuracy | 86.5% |
| Cost | 32452 |
| Alternative 3 | |
|---|---|
| Accuracy | 93.7% |
| Cost | 19912 |
| Alternative 4 | |
|---|---|
| Accuracy | 65.3% |
| Cost | 13260 |
| Alternative 5 | |
|---|---|
| Accuracy | 80.6% |
| Cost | 12996 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.8% |
| Cost | 7628 |
| Alternative 7 | |
|---|---|
| Accuracy | 65.0% |
| Cost | 7628 |
| Alternative 8 | |
|---|---|
| Accuracy | 62.0% |
| Cost | 7432 |
| Alternative 9 | |
|---|---|
| Accuracy | 62.0% |
| Cost | 7112 |
| Alternative 10 | |
|---|---|
| Accuracy | 31.6% |
| Cost | 6852 |
| Alternative 11 | |
|---|---|
| Accuracy | 33.1% |
| Cost | 6852 |
| Alternative 12 | |
|---|---|
| Accuracy | 57.9% |
| Cost | 6852 |
| Alternative 13 | |
|---|---|
| Accuracy | 31.3% |
| Cost | 6596 |
| Alternative 14 | |
|---|---|
| Accuracy | 15.4% |
| Cost | 580 |
| Alternative 15 | |
|---|---|
| Accuracy | 10.4% |
| Cost | 192 |
herbie shell --seed 2023255
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))