-4

Imagine we know the summation of a list of numbers (that is computed by dynamic programming):

a+b+c+d+...

How can we compute the sum of exponentials of these numbers without re-iterating over all numbers:

Math.exp(a)+Math.exp(b)+Math.exp(c)+...

Just a side note, if needed: The numbers are the probabilities of the paths in a lattice structure. The summation of the probabilities of all paths is computed by dynamic programming. However, I need the exponential sum without re-iterating over the lattice structure.

malaguena
  • 1
  • 1
  • 4

1 Answers1

1

Use a stream:

int[] numbers;  // given some numbers
double expSum = IntStream.of(numbers).mapToDouble(Math::exp).sum();
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • The problem is that OP doesn't have the numbers. The desired solution has to magically guess the individual numbers from a given sum... – f1sh Aug 17 '17 at 09:49
  • This is not possible in dynamic programming. The result is the summation of a list of numbers but without having the numbers separately. All partial solutions are kept in the lattice structure. – malaguena Aug 17 '17 at 09:51