Binary Addition on Cellular Automata

8
Complex Syst ems 5 (1991) 479-486 Binary Addition on Cellular Automata Bhavin Sheth Prantik Nag Robert W.H ellwarth University of South ern California, Los Angeles, CA 90089-0484, USA Abstract. A cellular auto mata app roach to fast addition of binar y numb ers is pr es ent ed. This approach utilizes the intrinsically parallel natur e of the cellular auto maton to add binary numb ers r epres ent ed as on/ off pix els on thecomputer screen. Numb ers n- bit long are added serially pairwise until the final sum is obtained. This approach can easily be generalized to numb ers of any base, but is constrained by the numb er of planes available on the Cellular Aut om at a Machine. The concept of cellular auto mata was in troduced by von Neumann and Ulam to model physical, chemical, and biological systems. Tod ay cellular automa ta are used for several differ ent purp oses. One such appli cation of cellular auto mata is in thea rea of computation. It has been shown that cel- lular automata can be used as gene ral purpose computers and may therefore be used as gene ral paradigms for parallel compu tation [3]. This pap er con- centrates on the ca pabilities of cellular automata for binary addition. The approach given in thi s pap er to solving this problem is int ended to emphasize the simplicity of cellular auto mata in implem enting elementary math ematic al oper ations. The oper ation of binary addition was implem ent ed on a Cellular Automat a Machine (CAM) designed by the Informati on Mechanics Group of the Massachusetts Institute of Technology. The rul es discussed in the paper may assume a knowledge of the language constructs used (see [1]). The approach given has cer tain unique features. The CAM screen may be filled up almost entirely with bin ary numb ers, thus allowing as many as 256 numb ers, each having a len gth of up to 256 bits, to be added. These limitations are solely machine dependent, since CAM only allows a screen of 256 x 256 pixels. It must be mentioned here that the approach does not take care of overflow. To unders tand this approach, it might help to visualize the numbers as beads on an abacus. Thet opmost pair of numb ers are added first , and the sum ob tained is then added to the numb er app earing beneath them . This goes on until all the numb ers are ex ha usted, after which all that remains is the final sum of all the numb ers. Henceforth the final sum is added with 0 until stopped. In adding two numb ers , the corresponding

Transcript of Binary Addition on Cellular Automata

Page 1: Binary Addition on Cellular Automata

Complex Systems 5 (1991) 479-486

Binary Addition on Cellular Automata

Bhavin ShethPrantik Nag

Robert W . H ellwarthUniversity of Southern California, Los Angeles, CA 90089-0484, USA

Abstract. A cellular auto mata approach to fast addit ion of binarynumbers is pr esented. This approach utilizes the intrinsically parallelnature of the cellular auto maton to add binary numbers representedas on/off pixels on the computer screen . Numbers n- bit long are addedserially pairwise until the final sum is ob tained . This approach caneas ily be genera lized to numbers of any base, but is const rained bythe number of plan es available on the Cellular Automata Machin e.

The concept of cellular auto mata was introduced by von Neumann andUlam to mod el physical , chemical, an d biologi cal systems. Today cellularauto mata are used for several different purposes. One such application ofcellul ar automata is in the area of computat ion. It has been shown that cel­lular aut omata can be used as general purpose compute rs and may thereforebe used as general para digms for par allel computat ion [3]. This paper con­centrates on the capabilit ies of cellular automata for bin ary addition . Theapproach given in this pap er to solving this pr oblem is intended to emphasizethe simplicity of cellular automata in implementing elementary mathematicaloperations. The operation of bin ar y addit ion was implemented on a Cellul arAutomata Machine (CAM) designed by the Information Mechanics Group ofthe Massachusetts Institute of Technology. The rul es discussed in the pap ermay assume a knowledge of the language const ruc ts used (see [1]).

The approach given has certain unique features. The CAM screen maybe filled up almost ent irely with bin ary numbers, thus allowing as many as256 numbers, each having a length of up to 256 bits , t o be added. Theselimitations ar e solely machine depend ent , since CAM only allows a screen of256 x 256 pixels. It must be mentioned here that the appro ach does not takecare of overflow. To unders tand this approach, it might help to visualize thenumbers as beads on an ab acus. The topmost pair of numbers are addedfirst , and the sum obtained is then added to the number appearing beneaththem . This goes on until all the numbers are exhausted, afte r which allthat remains is the final sum of all the numbers . Henceforth the final sumis added with 0 until stoppe d. In adding two numbers , the corresponding

Page 2: Binary Addition on Cellular Automata

480 Bhavin Sheth , Prantik Nag, and Robert W. Hellwarth

Figure 1: The numbers 1012 a nd 0112 are to be added. The row ofones on plane 2 can be seen clearly. T he numbe r 0012 lies in the rowright below t he nu mber 1012 and on t he same row as t he ones onpla ne 2.

Figure 2: The numbers are shown . P lane 2 is hidden by an appropr ia tecolor map . (See below for t he color map.)

bit s are added in par allel and the carr ies are obtained . These carr ies areadded to the par tial sum obtained in the next ste p. Once again carries willbe obtained , and will be added to t he next higher bits in the following step.This procedure repeats 255 t imes, by which time the sum is obtained .

A binary number is represented as a series of on /off pixels on the display.A binary '1' will app ear as a one on plane 0 and zeros on the other threeplanes. A binary '0' will be a zero on all four planes. A binary numb er isrepresented length-wise on the screen, with th e left-most bit being the mostsignificant bit.

Let us first examine the addit ion of two bin ary numb ers.The presence of th e row of ones on plane 2 serves to distinguish between

the two numbers. After the completion of the first step, the number atthe top disappears . This disappear ance of the number is taken care of by

Page 3: Binary Addition on Cellular Automata

Binary Addition on Cellular Automat a

Figure 3: The first step is executed. The corresponding bits are addedand the carr ies are saved and will be added to the numb er in thefollowing steps . P lane 0 at pr esent has 0110, while plane 1 has 0010,which will be added to the number 0110. Not e th at the carries will beshifted to the right by one bit, bu t will be added to the appropriatebits by the use of EAST.

11t,

J

Figure 4: The carries are added. P lane 0 now has 0100, while plane1 now has 0100.

481

the st at emen t NORTH CENTER XOR &CENTER AND >PLNO. T he row of ones onpl ane 2 di sa pp ears at the end of t he second st ep, it s p urpose served.

The rule is shown b elow.

NEW-EXPERIMENTN/VONN &/CENTERS

ADD-Rl &R2NORTH CENTER XOR &CENTER AND >PLNO

NORTH CENTER AND >PLNlCENTER >PLN2 ;

Page 4: Binary Addition on Cellular Automata

482 Bhavin Sheth, Prantik Nag, and Rob ert W. Hellwarth

Figure 5: The final result , 10002 . Th e number will be on plane o.Note that the carries too may be hidden if desired. Also note thatth e planes have been shifted to the middle of the screen for clarity. Inany case the answer would still have been correct .

MAKE-TABLE ADDJR1&R2

: CARRY-PROPAGATECENTER EAST ' XOR > AUXOCENTER EAST' AND > AUXl ;MAKE-TABLE CARRY-PROPAGATE

BINCYCLEREG-TABS STEP AUX-TABS 255 STEPS;MAKE-CYCLE BINCYCLE

As can be seen , the rule has two parts. Add Rl & R2, which takes one st ep ,adds the two binary numbers represented in the adjacent rows. The carr iesare neglect ed and are st ored in plan e 1 in the same position . These carr iesare later added by the Carry Propagate part . The Carry Propagate partadds the carry from bit i- I to bi t i, for 0 :::; i :::; n. The same binar yoperation found by Add Rl& R2 is used . The final sum is retained even aft erthe addition is complete, owing to the property of the XOR operator. Toadd more than two binary numbers , some mo difica t ions were mad e to theinitial pattern file and to the rul e.

First , t he row of ones on plane 2 keeps movin g down once the two binarynumbers are ad ded . Hence the statement

NORTH > PLN2

Thus, in intermediate ste ps, the row has the partial sum of all t he numbersabove it. At the end of the final ste p, it possesses the final sum of all thenumbers, as in the rule that added two binary numbers.

Not e that all t he numb ers ab ove this row that stores the intermediatesum-this row has the ones on plan e 2- should be deleted . However , the

Page 5: Binary Addition on Cellular Automata

Bin ary Addition on Cellular Automata

Figure 6: T he bright pixels at the bottom port ion of the screen are allones on plane 3. The numbers to be added are 011012, 110102, and111112. The uppermost row of ones on plane 3 also happen to haveones on plane 2.

483

numbers below this row should be main tain ed since they are st ill to be added.The initial pattern file is changed somewha t to accommodate this fact. Thepart of the screen below the row that has t he sum has ones on plane 3. Thisis to distinguish t he numbers that have not been added from the numberstha t have already been added. In the beginning, only one number lies abovethis row. Just as t he row that keeps the interm ediate sum keeps going down,so must the block of ones on plane 3. This is taken car e of by the st at ement

NORTH >PLN3

This spat ial differenti at ion between the numbers is used in

CENTER &CENTER' &CENTER NOT AND ANDNORTH CENTER XOR &CENTER AND OR >PLNO

and in

CENTER ' CENTER AND &CENTER' NOT CENTER EASTXOR AND DR >AUXO

The rul e, in its ent irety, is given below.

NEW-EXPERIMENTN/VONN &/CENTERS

ADD--R.l&R2CENTER &CENTER' &CENTER NOT AND AND

NORTH CENTER XOR &CENTER AND OR >PLNONORTH CENTER &CENTER AND AND >PLNl

NORTH >PLN2NORTH ' >PLN3

MAKE-TABLE ADD--R.l&R2

Page 6: Binary Addition on Cellular Automata

484

(a)

(b)

(c)

(d)

Bhavin Sheth , Prantik Nag, and Robert W. Hellwarth

Figure 7: Some of the int ermediate steps .

Page 7: Binary Addition on Cellular Automata

Binary A ddit ion on Cellular Automata 485

( e)

(f )

(g)

Fi gure 7: Continued.

: CARRY-PROPAGATE&CENTER ' CENTER AND &CENTER' NOT

CENTER EAST ' XOR AND OR >AUXO&CENTER' NOT CENTER EAST ' AND AND >AUX1

CENTER >AUX2CENTER' >AUX3

MAKE-TABLE CARRY-PROPAGATE

BINCYCLE

Page 8: Binary Addition on Cellular Automata

486 Bhavin Sheth , Prantik Nag, and Robert W. Hellwarth

Figure 8: T he final sum, 10001102 .

REG-TABS STEP AUX-TABS 255 STEPSMAKE-CYCLE BINCYCLE

This rul e adds severa l binary numbers. The numb ers may be thought of aspartial product s obtained from mult iplica tio n .

The rows of ones on planes 1 and 3 can be mad e invisible by the use ofan appr opriate color map. The following color map may be used:

ALPHA >GREENALPHA' >BLUE

ALPHA ALPHA' AND >REDo > I NTEN

Conclusion

The experiment demonstrated that binary addit ion can be mod eled as acellular automaton rul e.

Acknowledgments

This resear ch was supported by the U.S. Air Force Office of Scientific Re­search un der contract F49 620-91-C-0018, and by the Nat ional Science Foun­dation under grant ECS -8821507.

References

[1] T . Toffoli and N. Margolus , Cellular Autom ata Machines (Cambr idge, MITPress , 1987).

[2] A. Califano, N. Margolus, and T . Toffoli, CAM-6 User 's Guide, Version 2.1(1986).

[3] Stephen Wolfram, Reviews of Modern Ph ysics, 55 (1983) 601-644.