Giter Club home page Giter Club logo

log-of-sum-and-subtraction's Introduction

Methods for calculating precise logarithm of a sum and subtraction of very large or very small numbers

Disclosed are methods to compute the precise value of the logarithm of a sum and the logarithm of a subtraction of very large or very small numbers.

A number of practical problems can result in having too big or small values in intermediate values of a calculation. Then one tries to take logarithm of these values and operate on logarithms instead.

In the case: log (p โ€ข q) = log p + log q is very easy to compute, but the problem is then to compute (or approximate) the value of log (a + b) from the value of log a and log b.

Let us assume that log a and log b are known, and that we want to approximate log (a + b). Most basic solution would be calculating sum_log = log(exp(a_log) + exp(b_log), where a_log = log a and b_log = log b and therefore sum_log = log(a + b). But the method I propose requires calling only one exp() and one log(), instead of two exp() and one log() in the basic solution. Additionally, the proposed method has the critical advantage of not overflowing in case of large numbers of a and b.

The method is based on the notion that ln(a + b) = ln{exp[ln(a) - ln(b)] + 1} + ln(b).

In a similar manner we can compute the logarithm of subtraction, based on the notion that ln(a - b) = ln{exp[ln(a) - ln(b)] - 1} + ln(b), if a > b.

Overview of files

  • Methods for calculating logarithm of sum or subtraction.
  • Examples comparing the methods with a naive solution which will produce overflow.
  • See also the included pdf file for more detail.

Analytics

log-of-sum-and-subtraction's People

Contributors

levitation avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

listato

log-of-sum-and-subtraction's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.