ArticleslgStudy

computer science

BKM algorithm

BKM algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand BKM algorithm rather than just read about it. In short: The BKM algorithm is a shift-and-add algorithm for computing elementary functions, first published in 1994 by Jean-Claude Bajard, Sylvanus Kla, and Jean-Michel Muller. BKM is based on computing complex logarithms (L-mode) and exponentials (E-mode) using a method similar to the algorithm Henry Briggs used to compute logarithms.

Key takeaways

  • BKM algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect BKM algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of BKM algorithm from memory before moving on to harder problems.

Reference excerpt

The BKM algorithm is a shift-and-add algorithm for computing elementary functions, first published in 1994 by Jean-Claude Bajard, Sylvanus Kla, and Jean-Michel Muller. BKM is based on computing complex logarithms (L-mode) and exponentials (E-mode) using a method similar to the algorithm Henry Briggs used to compute logarithms. By using a precomputed table of logarithms of negative powers of two, the BKM algorithm computes elementary functions using only integer add, shift, and compare operations. BKM is similar to CORDIC, but uses a table of logarithms rather than a table of arctangents. On each iteration, a choice of coefficient is made from a set of nine complex numbers, 1, 0, −1, i, −i, 1+i, 1−i, −1+i, −1−i, rather than only −1 or +1 as used by CORDIC. BKM provides a simpler method of computing some elementary functions, and unlike CORDIC, BKM needs no result scaling factor. The convergence rate of BKM is approximately one bit per iteration, like CORDIC, but BKM requires more precomputed table elements for the same precision because the table stores logarithms of complex operands. As with other algorithms in the shift-and-add class, BKM is particularly well-suited to hardware implementation. The relative performance of software BKM implementation in comparison to other methods such as polynomial or rational approximations will depend on the availability of fast multi-bit shifts (i.e. a barrel shifter) or hardware floating point arithmetic.

Overview In order to solve the equation

ln⁡(x)=y the BKM algorithm takes advantage of a basic property of logarithms

ln⁡(ab)=ln⁡(a)+ln⁡(b) Using Pi notation, this identity generalizes to

ln⁡(∏k=0nak)=∑k=0nln⁡(ak) Because any number can be represented by a product, this allows us to choose any set of values ak which multiply to give the value we started with. In computer systems, it's much faster to multiply and divide by multiples of 2, but because not every number is a multiple of 2, using ak=1+2m is a better option than a more simple choice of ak=2m. Since we want to start with large changes and get more accurate as k increases, we can more specifically use ak=1+2−k, allowing the product to approach any value between 1 and ~4.768, depending on which subset of ak we use in the final product. At this point, the above equation looks like this:

ln⁡(∏k∈K⊂ℤ0+1+2−k)=∑k∈K⊂ℤ0+ln⁡(1+2−k) This choice of ak reduces the computational complexity of the product from repeated multiplication to simple addition and bit-shifting depending on the implementation. Finally, by storing the values ln⁡(1+2−k) in a table, calculating the solution is also a simple matter of addition. Iteratively, this gives us two separate sequences. One sequence approaches the input value x while the other approaches the output value ln⁡(x)=y: xk={1if k=0xk−1⋅(1+2−k)if xk would be≤xxk−1otherwise Given this recursive definition and because xk is strictly increasing, it can be shown by induction and convergence that

limk→∞xk=x for any 1≤x≲4.768. For calculating the output, we first create the reference table

Ak=ln⁡(1+2−k) Then the output is computed iteratively by the definition yk={0if k=0yk−1+Akif xk would be≤xyk−1otherwise The conditions in this iteration are the same as the conditions for the input. Similar to the input, this sequence is also strictly increasing, so it can be shown that

limk→∞yk=y for any 0≤y≲1.562. Because the algorithm above calculates both the input and output simultaneously, it's possible to modify it slightly so that y is the known value and x is the value we want to calculate, thereby calculating the exponential instead of the logarithm. Since x becomes an unknown in this case, the conditional changes from

…if xk would be≤x to

…if yk would be≤y

Logarithm function To calculate the logarithm function (L-mode), the algorithm in each iteration tests if xn⋅(1+2−n)≤x. If so, it calculates xn+1 and yn+1. After N iterations the value of the function is known with an error of Δln⁡(x)≤2−N. Example program for natural logarithm in C++ (see A_e for table):

Logarithms for bases other than e can be calculated with similar effort. Example program for binary logarithm in C++ (see A_2 for table):

The allowed argument range is the same for both examples (1 ≤ Argument ≤ 4.768462058...). In the case of the base-2 logarithm the exponent can be split off in advance (to get the integer part) so that the algorithm can be applied to the remainder (between 1 and 2). Since the argument is smaller than 2.384231..., the iteration of k can start with 1. Working in either base, the multiplication by s can be replaced with direct modification of the floating point exponent, subtracting 1 from it during each iteration. This results in the algorithm using only addition and no multiplication.

Exponential function To calculate the exponential function (E-mode), the algorithm in each iteration tests if yn+ln⁡(1+2−n)≤y. If so, it calculates xn+1 and yn+1. After N iterations the value of the function is known with an error of Δexp⁡(x)≤2−N. Example program in C++ (see A_e for table):

Tables for examples

Notes

References

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with BKM algorithm

Start with the simplest possible case. Write down what BKM algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to BKM algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about BKM algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of BKM algorithm

In research
BKM algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses BKM algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
BKM algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1994 in science, 1994 introductions, Computer arithmetic, so understanding it makes those chapters shorter.
In everyday life
Look for BKM algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “BKM algorithm” →

How to study BKM algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what BKM algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain BKM algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is BKM algorithm in simple terms?

The BKM algorithm is a shift-and-add algorithm for computing elementary functions, first published in 1994 by Jean-Claude Bajard, Sylvanus Kla, and Jean-Michel Muller. BKM is based on computing complex logarithms (L-mode) and exponentials (E-mode) using a method similar to the algorithm Henry Brigg…

Why does BKM algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study BKM algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on BKM algorithm.

Tags

  • 1994 in science
  • 1994 introductions
  • Computer arithmetic
  • Digit-by-digit algorithms
  • Shift-and-add algorithms

Keep exploring