title: including a negative number in the log sum of exponents, in python
body: <p>I want to use numpy's <code>logsumexp()</code> in python 2.7.
  The formula I need to solve looks like this:</p>
  
  <pre><code>log ( 1 + e^a1 + e^a2 + e^a3 + ... e^an - e^ax )
  </code></pre>
  
  <p>The last term which is a negative number just has to be appended on.
  Excluding this last term, I would do the following:</p>
  
  <pre><code>myarray = numpy.array([0, a1, a2, a3, ..., an])
  </code></pre>
  
  <p>That way, with the first element being <code>0</code>, then <code>e^0 = 1</code> and so I have my first term, which is <code>1</code>. Then I would just use</p>
  
  <pre><code>  result = numpy.logsumexp(myarray)
  </code></pre>
  
  <p>and I would get the correct result.</p>
  
  <p>But now I have to append a <code>-e^ax</code>, and because it's negative, I can't simply append <code>ax</code> to the end of <code>myarray</code>. I also can't append <code>-ax</code> because that's just wrong, it would mean that I'm adding <code>1/e^ax</code>, instead of <code>-e^ax</code>.</p>
  
  <p>Is there any direct way to append this so that I can still use <code>logsumexp()</code>? The only reason I'm insisting on using <code>logsumexp()</code> rather than separately using <code>numpy.exp()</code> and <code>numpy.sum()</code> and <code>numpy.log()</code> is because I have the impression that <code>logsumexp</code> also incorporates stability within it in order to prevent underflows (correct me if I'm wrong). However if there's no other way around then I guess I have no choice.</p>