Computers and Calculators: How They Compute Logarithms

BY Mark Howell 21 June 20245 MINS READ
article cover

There are many functions on a scientific or graphing calculator that we are introduced to as high school students that, we are told, just work. You select the function, put in the value that you need to calculate, hit “=” or “ENTER”, and SHABAM! You have the correct answer to some arbitrary number of digits that you are ensured are all 100% accurate.

Pictured: The natural log of 2 to (an arbitrary) 32 digits on the built-in Microsoft calculator.
This is wonderful! Necessary, even, because if our calculators and computers calculated logarithms inaccurately, as well as exponentials, trig functions, and square roots, a lot of scientific and engineering work would be broken and end in catastrophe. But how do we know that the value on the calculator is, in fact, accurate? How did the calculator crunch the input number and give us the output?
I remember this question being asked in high school, and the answer being no more than a handwave. To be fair to Algebra II teachers, the answer is beyond the scope of algebra and lies in calculus. But it is an answer worth knowing, and it’s an answer that is very knowable, even if you don’t have a background in calculus. Calculus is the method for deriving the formula used in calculators and computers, but the formula itself is a pretty simple polynomial.

The Geometric Series

Most of us were introduced to polynomial equations in algebra. For a quick refresher, a polynomial is an expression involving at least one variable (usually x) and addition, subtraction, multiplication, division, and integer power operators.
Here are a few examples:

  • Line: $y = 5 + 2x$

  • Parabola: $y = 1 - x - x^{2}$

  • Quartic: $y = 4 - 2x - 5x^{2} + \frac{1}{2}x^{3} + x^{4}$
    While these equations of polynomials contain a finite number of terms, we can have polynomials with an infinite number of terms. These are called series, and one of the simplest types of series is called a geometric series. A geometric series contains an initial term, usually denoted by the variable a, and each successive term is multiplied by a ratio, usually denoted by r.
    The general formula for a geometric series is:
    $s = a + ar + ar^2 + ar^3 + ...$
    One special geometric series relevant to logarithms is when a = 1 and r = -x, leading to a series known as the polynomial series for natural logarithms.

Getting a Series for the Natural Logarithm

“This is all very interesting, but what does this have to do with computing logarithms?” It turns out that the function $\frac{1}{1+x}$ and the natural logarithm are directly related. Specifically, the area under the curve from $t = 0$ to any value $x$ is the natural logarithm of $1+x$. In mathematical symbols, this is rendered as:
$ln(1+x) = \int_{0}^{x} \frac{1}{1+t} dt$
While the understanding of the calculus involved is beyond the scope of this article, taking integrals can get us the series that effectively computes the natural logarithm.
Here is a series derived for the natural logarithm:
$ln(1+x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + ...$
This series converges quickly for $|x| < 1$ and $|x| < \frac{1}{2}$. However, larger values of x can be addressed by strategically reducing them using properties of logarithms.

Properties of Logarithms

Luckily, logarithms are special functions with useful properties that help reduce arguments for calculation:

  1. Multiplication in the input is equivalent to addition of the outputs.
    $ln(ab) = ln(a) + ln(b)$

  2. Exponentiation in the input becomes multiplication in the output.
    $ln(a^b) = b \cdot ln(a)$
    Using these properties, even large logarithmic inputs can be broken down into smaller parts that fit within the convergence range of the series.

The Better Formula

While the polynomial series for $ln(1+x)$ is good, there's a better series that converges much faster:
$ln(x) = 2 \sum_{n=0}^{\infty} \frac{1}{2n+1} \biggl( \frac{x-1}{x+1} \biggr)^{2n+1}$
This series skips a degree for each term, making it faster. For example, calculating to double-floating-point precision (11 decimal places), the new series might need only 12 terms compared to 36 for the older series.

Pictured: A comparison of the 3-term approximations for the two series to $\ln(x)$. The latter series converges faster.

Remember these 3 key ideas for your startup:

  1. Understand the Basics: Grasp the concept of how series and polynomials work, as they lay the foundation of many complex algorithms. This insight can be a game-changer for solving intricate problems efficiently.

  2. Leverage Properties: Utilizing properties of logarithms to simplify complex computations can enhance productivity and reduce computational load on your systems.

  3. Efficient Calculations: Opt for optimized algorithms, like the faster converging polynomials, for quicker and more accurate results, ensuring robustness in your mathematical computations which is critical for tech and data-driven startups.
    Edworking is the best and smartest decision for SMEs and startups to be more productive. Edworking is a FREE superapp of productivity that includes all you need for work powered by AI in the same superapp, connecting Task Management, Docs, Chat, Videocall, and File Management. Save money today by not paying for Slack, Trello, Dropbox, Zoom, and Notion.
    For an in-depth comparison of some leading productivity tools, check out this article on Microsoft Teams vs. Slack vs. Edworking. If you’re keen to explore alternatives to Google Keep for note-taking, see this list of top 5 Google Keep alternatives.
    For more details, see the original source.

article cover
About the Author: Mark Howell Linkedin

Mark Howell is a talented content writer for Edworking's blog, consistently producing high-quality articles on a daily basis. As a Sales Representative, he brings a unique perspective to his writing, providing valuable insights and actionable advice for readers in the education industry. With a keen eye for detail and a passion for sharing knowledge, Mark is an indispensable member of the Edworking team. His expertise in task management ensures that he is always on top of his assignments and meets strict deadlines. Furthermore, Mark's skills in project management enable him to collaborate effectively with colleagues, contributing to the team's overall success and growth. As a reliable and diligent professional, Mark Howell continues to elevate Edworking's blog and brand with his well-researched and engaging content.

Trendy NewsSee All Articles
CoverVisual Prompt Injections: Essential Guide for StartupsThe Beginner's Guide to Visual Prompt Injections explores vulnerabilities in AI models like GPT-4V, highlighting security risks for startups and offering strategies to mitigate potential data compromises.
BY Mark Howell 2 mo ago
CoverGraph-Based AI: Pioneering Future Innovation PathwaysGraph-based AI, developed by MIT's Markus J. Buehler, bridges unrelated fields, revealing shared complexity patterns, accelerating innovation by uncovering novel ideas and designs, fostering unprecedented growth opportunities.
BY Mark Howell 2 mo ago
CoverRevolutionary Image Protection: Watermark Anything with Localized MessagesWatermark Anything enables embedding multiple localized watermarks in images, balancing imperceptibility and robustness. It uses Python, PyTorch, and CUDA, with COCO dataset, under CC-BY-NC license.
BY Mark Howell 2 mo ago
CoverJungle Music's Role in Shaping 90s Video Game SoundtracksJungle music in the 90s revolutionized video game soundtracks, enhancing fast-paced gameplay on PlayStation and Nintendo 64, and fostering a cultural revolution through its energetic beats and immersive experiences.
BY Mark Howell 2 mo ago
CoverMastering Probability-Generating Functions: A Guide for EntrepreneursProbability-generating functions (pgfs) are mathematical tools used in probability theory for data analysis, risk management, and predictive modeling, crucial for startups and SMEs in strategic decision-making.
BY Mark Howell 31 October 2024
CoverMastering Tokenization: Key to Successful AI ApplicationsTokenization is crucial in NLP for AI apps, influencing data processing. Understanding tokenizers enhances AI performance, ensuring meaningful interactions and minimizing Garbage In, Garbage Out issues.
BY Mark Howell 23 October 2024
CoverReviving Connection: What We Lost with the Decline of Letter WritingThe shift from handwritten letters to digital communication has reduced personal connection, depth, and attentiveness, impacting how we communicate and relate in both personal and business contexts.
BY Mark Howell 23 October 2024
CoverLichess Move: Behind-the-Scenes Technical BreakdownWhen you make a move on lichess.org, it triggers real-time data exchanges via WebSocket, updates game state, and ensures seamless gameplay using Redis Pub/Sub and MongoDB.
BY Mark Howell 23 October 2024
Try EdworkingA new way to work from  anywhere, for everyone for Free!
Sign up Now