The complexity of carry-free addition

908 views Asked by At

Two binary numbers can be represented in the usual "regular, redundant" representation (i.e. introduce another digit, say 2, to obtain a non-unique representation such that any two consecutive 2's have a zero in between), so that addition becomes carry-free. I have heard that the complexity is O(k), where k is the length of the shorter of the two numbers. But what is the algorithm itself? It doesn't seem to appear on the web anywhere. I know you can add 1 to such a representation in constant time so that the result maintains regularity. But I don't know how to generalize this.

1

There are 1 answers

0
nicholas On

I see this is an old post, and the poster does not have much recent activity here but thought I'd put forward the answer anyway.

In order to represent this circuit as a traditional equation, let's set forth some notation. Each 'bit' in RBR notation actually consists of two bits, so to refer to these right and left bits, I will use [0] and [1] respectively. To refer to a certain 'bit' position I will use braces {0},{1},{2},...{n}.

Addition of two or three single bits can result in a two-bit sum (the MSB is traditionally called the carry bit). These can also be referenced by [0] and [1], the latter being the carry bit. For example:
(0+1+1)[0]=0, (0+1+1)[1]=1, (0+0+1)[0]=1, (0+0+1)[1]=0

Now without much further, the general algorithm for adding numbers z = x + y is given by:
z{n}[0] = ((x{n-1}[1] + x{n-1}[0] + y{n-1}[1])[0] + (y{n-1}[0]) + (x{n-2}[1] + x{n-2}[0] + y{n-2}[1])[1])[1]

z{n}[1] = ((x{n}[1] + x{n}[0] + y{n}[1])[0] + (y{n}[0]) + (x{n-1}[1] + x{n-1}[0] + y{n-1}[1])[1])[0]

You will note that there is some carrying going on here, but the algorithm achieves O(n) because the carrying is limited to two orders. Also note the special considerations for z{0} and z{1}, which are defined in the circuit diagram in the aforementioned link.