Addition chains in Coq

Our framework

Let (M,o,u) be a monoid; for each x in M, and each natural integer n, let us denote by x^n the n-th power of x.

We are interested in efficient algorithms for computing x^n; the best known of these algorithms is the so-called "binary algorithm"

Let us take the number of multiplications and squarings as an efficiency measure for the computation of x^n; It is well known that the binary algorithm needs l squarings and m-1 multiplications, where l is the floor logarithm of n (in base 2), and m is the number of 1 in the binary representation of n.

For instance, if n=87, the binary representation of n is 1010111, so we need 6 squarings and 4 multiplications.

What are addition chains ?

Let us consider the followings steps for computing x^87:
x, x^2, x^3, x^6, x^7, x^10, x^20, x^40, x^80, x^87.

Each intermediate value is obtained by the multiplication of two preceding values (this includes the squaring operation); we count 9 multiplications, i.e. 1 less than the binary algorithm.

An addition chain is a increasing sequence (1,...,n) of natural numbers, such that every term of this sequence is the sum of two preceding terms. A *-addition chain is a chain where each term is the sum of the immediately preceding term and any preceding term.

For instance (1,2,3,5,10,13,15,23,46,92) is an addition chain, but not a *-addition chain, and (1,2,3,6,7,10,20,40,80,90,92) is a *-chain.

Since, in every monoid, x^(n+p)=(x^n)o(x^p), the optimization problem for powering can be reduced to the generation of an addition chain giving a minimal number of multiplications (and squarings), i.e an addition chain of minimal length.

You can find a presentation on addition chains, given at TAPSOFT'91, with emphasis on the algorithmic complexity of this approach.

We present here a proof in Coq of an algorithm for generating addition-chains; the reader is invited to read first an informal presentation , then to read to documentation of the main module.