Accurate way to compute the sum of exponentials
-
04-11-2019 - |
Question
In my work, I had to essentially compute the following quantity.
Given a sequence of positive floating point numbers $\{a_i\}_{i=1}^n$, such that
$$6000 \leq a_i \leq 7000$$
I needed to compute the following quantity (for some $n>1$, but for now can assume $n=1000$):
$$\log_2\left(\frac{\sum_{i=1}^n 2^{a_i}}{n}\right)$$
Direct computation is infeasible as the exponents are too large. So I rewrote the above expression as $$a_1 + \log\left(\frac{1+\sum_{i=2}^n 2^{a_i-a_1}}{n}\right)$$
This also seemed a bit daunting but was better than what I had. My question was, is there a better way/algorithm to compute the above quantity? I appreciate any help on this.
The following observation might help:
$$\frac{\sum_{i=1}^n a_i}{n}\leq \log_2\left(\frac{\sum_{i=1}^n 2^{a_i}}{n}\right)\leq \max_{1 \leq i \leq n} a_i$$
No correct solution