# list manipulation – Symbolic add of 32Bit Registers

I would like to perform multiple 32bit word register additions (mod 32 add. with variables of Boolean type shuffled with symbolic type).

For this task I implemented a ripple adder function:

`````` (* Ripple addition of 2 Bit Register function *)
sum(a_, b_, c_) := (a && b && c) || (a && ! b && ! c) || (! a && b && ! c) || (! a && ! b && c)
carry(a_, b_, c_) := (a && b) || (a && c) || (b && c)

rippleAdd(x_, y_, cin_) := Module({r, c},
Table(Which(i == 1 && j == 1, Subscript(r, i) = BooleanMinimize(sum(x((i)), y((i)), cin)),
i == 1 && j == 2, c = BooleanMinimize(carry(x((i)), y((i)), cin)),
i > 1 && j == 1, Subscript(r, i) = BooleanMinimize(sum(x((i)), y((i)), c)),
i > 1 && j == 2, c = BooleanMinimize(carry(x((i)), y((i)), c))
), {i, 1, Length(x)}, {j, 1, 2});
Array(Subscript(r, #) &, {Length(x)})
);
``````

This does work quite well if I feed it Boolean type variables, but as soon as I try to use it with symbolic registers it goes really slow. (e.g. can be used for adding up to two symbolic registers <16bit word).

I found that by using BooleanMinimize function at each computation of the sum & carry bit this will simplify the terms when Boolean type bits are shuffled in.

I am new to Mathematica and was wondering if there are better ways of performing the task (better use of Mathematica built in functions, parallelization possibilities if for example carry look ahead is used instead, or maybe I am asking too much and by nature of the problem this will bog down as multiple symbols/ operations are propagated to the next bit).

Thank you, any information is well received.

Posted on