Sidney B. Langl Department of Chemical Engineering University of Colorado Boulder and Robert L. Peck Phelps Dodge Electronic Products Corporation North Haven, Connecticut
I
I 1
I
Application of Binary and Ternary Arithmetic to Weighing Problems
O n e of the most anciently used and also one of the most frequently measured physical properties is r eight.^ This determination is generally made by comparing the unknown weight with a combination of precision known weights. Most sets of weights in use today are based on a decimal ~ y s t e m . ~Typical values in such sets are ,53-2-1-21, 5-2-2-1-21, or 5-2-1-1-21, where the 21 indicates a sum of smaller weights totaling one. The purpose of this paper is to illustrate some of the advantages of the use of a ternary system of weights on a two-pan balance or the use of a binary system of weights on a single-pan balance. This objective has a twofold aim: (1) an understanding of the ternary nature of a two-pan balance and the binary nature of a single-pan balance should be helpful in the use of such devices; and (2) the use of weight sets based on other than decimal numbers might be ronsidered in the design - of new weighing svst,ems. The unique char&ierist,ics of single- and double-pan balances have been known to students of number theory for a long time. A puznle originating with Bachet4 concerned with a double-pan balance was given to the authors in the following form: A blacksmith had a 4Wh. rock with which he weighed objects on a doublepan beam bdance. One day he dropped therock and it fihattered into fmlr pieces. I t was then pointed out to him by a person who had weighed the individual pieces that, by placing the proper pieces of rock in either balance pan, he could weigh any integral quantity from 1 to 40 lb. What were the weights of the four piece3 of rock?
The solution of this problem involves simple concepts of ternary arithmetic. This paper contains a theoretical section in which the necessary concepts of binary and ternary arithmetic are developed, a section illustrating the binary and ternary nature of weighing devices, and a section describing the application of the methods developed to the problems of weighing. An appendix contains
binary and ternary trut,h tahles covering a range from 1 to over 200,000. Number Systems
A number system and its corresponding arithmetic operations can be developed using any positive integer as a base. Most commonly, a decimal base or base integer of 10 is used. I n the decimal system the right-most digit represents units, the next digit to the left represents tens, the next digit to the left represents hundreds, and so on. Thus any integer, N, is expressed in the decimal system by the coefficients in t,he following snmmation: N
=
C ai(lO)'
(1)
i=O
where the a i ' s are selected from the set of the 10 digits, 0 through 9.
The number, N, is then written . . . azalao. Numbers between 0 and 1 can be expressed by the coefficients of eqn. (2) :
where the
a-i's
are select,ed from the set of digits, 0 through 9.
Thus a fraction is written 0. a - ~ a - ~ a - .~... Because most digital computers utilize a bistable element as a memory device, a number system using 2 as a base (binary arithmetic) is necessary. The decimal integer, N, and the integer plus a decimal fraction, N F, can he expressed in binary arithmetic by t,he coefficients in the following formulas, respectively:
+
and 1 Prevent address: LawrenceRadiation Laboratory, Chemistry Deoartment. Livermore. California.
where in accordance with common usage. a National Bureau of Standards Handhook77, "Precision Measurements and Calibration," U S . Government Printing Orfice, Washington, D. C., 1961, Vol. 111, pp. 588-706. 'HARDY,G . H., AND WRIGHT, E. If.,"An Introduction to the Theory of Numbers," Clarendon Press, Oxford, 1954, pp. 11.5 117. 48
/
Journol of Chemicol Education
the ai's w e selected from the set of 0 and 1.
~h~~ the decimal number 9 can be as 1 . 23 + 0 . 2" 0 . 2' 1 . 2O and expressed inbinary notation lool. Other integers are in binary notation in Table 1.
+
Table 1. Number Systems. Binary S stem z 6 = 3 2 2 r16 2'=8
P
0
2'=4
2'=2
zO=l
N o r m a l Ternary System
33=27 3 2 = 9
3l.3
0
The extension of the arguments to a number system of any hasp, 8,yields the equations:
and
where t,he ai's are R distinct ehnrart,en;.
Integers to the base B are written . . . aa al a. and fractions, .a-I a - a-z ~ . . .. Weighing problems are often associated with a ternary or base 3 number syst,em. The normal or o n e sided ternary system will be considered to use as a*,t.he set of digits 0, 1, and 2. Examples of decimal integers expressed in the normal ternary notation are given in Table 1. It will he more convenient to deal with integers N multiplied by scaling factors than to work with fractions. The scaling factors will be equal to the artual value of the smallest weight used.
3O. 0
Two-sided Ternary System 33=27 3=* 3'=3 3O=l 0 0 0 0
ing devices becomes apparent when the solution to the blacksmith weighing problem is examined. The weights of the four pieces of rock are 1, 3, 9, and 27 lhs. The weight of an unknown object can be determined by placing it in t,he left pan of a balance and finding the proper combinat,ion of the four rocks, distributed in the left or right pans, necessary for balance. The values of the weight.^, 1, 3, 9, and 27, are the zeroth, first, second, and third powers of 3, respectively. Thus, a two-pan balance is a device that operates on a modified ternary number system. This system, which we will t.erm the two-sided ternary system, differs from the normal ternary system in that the coefficients are selected from the set of a*which consists of the numbers -1, 0, and + 1 iristead of 0, 1, and 2. The - sign indicates a weight on the same side of the balance as the urd i,
wherc i, is the
decimal system of weighing has no rules other than the trival one: If the unknown weight on the left-hand pan of the balance is too heavy, additional weights must be added to the right. The use of a systematic procedure in weighing may both increase efficiency and make weighing operations more amenable to aut,omatic control.
Weighing with ternary weights is done in the following manner, assuming that the unknown weight is on the left-hand pan: 1 . Beginning with the smallest weight, add weights in itirl.ees-
ing order to the right-hand pan until the righehand pat) hecome8 heavier or drops. Remove the next lower-valned weight from the right-hand pan. If the righehand pan rises, replace the weight and repent Step 2. If the right-hand pan does not rise, add the weight tn the left-hand pm. If the righehand pan rises, remove the weight from the balance and repeat Step 2; otherwise, leave the weight on the left-hand pan and repeat Step 2. If balance is obtained during any of the preceding s t e v . the sequence is stopped.
2.
If AfN is subtracted from the two members of eqn. (4), it is found that:
8.
4.
5.
where bi=ai-
1 =
- 1,0,1
Thus the two-sided ternary system is a modification of the normal ternary system and can be used to express all positive (as well as negative) integers. Therefore, any unknown integral weight can be balanced, and balanced uniquely, by the appropriate combination of weights having the values of the integral powers of three. I t is obvious that the weights having the values of powers of three provide the minimum set necessary for weighing on a two-pan balance. The set of weights, 3' , 3' , 3% I . . . , 3', is sufficient to weigh any integer amount from 1 to (3J+L -1). The two-sided ternary system for the set of weights, 1, 3, 9, and 27 is illustrated in Table 1. It may also be noted that the binary system provides the minimum set of weight,s for a single-pan balance. I n this case, the weights must take on the values of the int,egral powers of two. The set of weights, 20, 21, Z2, . . . , ZJ, can be used to weigh any integer amount from 1 to 2'+' -1. Again, it is noted that the combination of weights necessary to total a given sum is unique.
6.
These rules are followed until balwnce is obtained or the smallest weight has been moved.
Weighing with a single-pan system and a binary set o j weights is accomplished as follows: 1. Beginning with the srndlest weight, add we-ights in inweas-
ing order until the pan drops. 2. Remove the next lower-valued weight. 3. If the pan rises replace the weight, and repeat Step 2. 4. If the pan does not rise, remove the weight from the balance and repeat Step 2. 5. If balance is obtained removing any weight, the seqoence is stopped.
The sequence is followed until balance has been obtained or the smallest weight has been moved. Here is a proof of the rules for the ternary weighing operat,ions. By means of Step 1, w series of weights
is obt,ained whirh is greater t,han the unknown weight,
Application to Weighing Problems
From the preceding discussion it is apparent that weighing devices are based on either binary or ternary logic. Table 2 lists the comparison of the decimal, binary, and ternary weights that would be used for weighing amounts from 1 mg to about 100 g. A eomparison of the number of weights required for the decimal system and the ternary system illustrates that the decimal system requires approximately twice the number of weights or sums of weights of the ternary set. This is because of a duplication of weights or combinations of weights in the decimal system not necessary in the ternary or binary systems. On first consideration, the values of the decimal weights appear to be much less cumbersome in use than the values of the ternary and binary systems. That this consideration is invalid can be demonstrated by the establishment of a logical and systematic set of rules for making weighings with binary or ternary weights and the derivation of truth tables for performing the summations of weights on a balance. By contrast, the 50
/
Journal of Chemical Education
Table 2.
Number
Comparison of Decimal, Binary, and Ternary Weight Sets. Decimal
Binary
I
1mg
1 mg
2 3 4
2
2 4
5 10
a
5
16
Ternary 1mg
3
9 27 81
N . Also N is greater than the summation:
The necessity for the inclusion of the weight, 3", is thus demonstrated. Steps 2-5 are used to determine a value of "a" such that the sum:
is a minimum subject to the restriction that it be greater than or equal to N. The parameter "a" must take on one of the three discrete values 1 , O , or -1, corresponding to the weight 3"-I being on the rightrhand pan, removed from the balance, or on the lefbhand pan. Because the summation:
the total of all weights less than 3"-', is less than 3"-', this sum cannot affect the determination of 'la." Ry similar arguments, a paramenter "a" can be determined for the weight, 3"-=, etc. A more heuristic proof can he obtained by an examination of the truth table (Table 1). It can be seen that the last weight added brackets a set of weights. The state of the second largest weight brackets a smaller set of values and so on. The success of the weighing scheme, of course, is due to the fact that a given integer is formed from a unique set of weights proportional to the integral powers of three. Similar arguments can be used to prove the validity of the binary system. In this case, a value of the p* rameter "a" must be selected to minimize the sum:
subject to the restriction that the sum is equal to or greater than N, the unknown weight. Permissible values of "a" are 0 or 1, corresponding to the weight, 2n-', being absent. from or on the balance pan. The uniqueness of the binary or ternary weight combinations allows the use of simple truth tables for totaling the weights. Typical truth tables covering a range of more than five orders of magnitude are given in the appendix. These t.ables could be modified to include weight calibration correction factom6 Because of the use of truth t,ables, the weights need only be identified by a numerical, alphabetical, or color designation. This factor may facilitate faster and more accurate work by less-skilled personnel. The use of decimal weights requires that the total of the weights on the balance be calculated by the operator. A ternary or binary set of weights could be directly calibrated against a set of decimal standard weights. This approach has the serious disadvantage that, in a
single set of ternary or binary weights, no internal checks are po~sible.~This fact is true because ternary and binary sets contain no redundancies, in contrast to decimal weights. However, a better approach might take advantage of the fact that successive values of ternary or binary weights differ in magnitude by factors of three or two, respectively. Thus, three separate sets of ternary or two sets of binary weights can be intercompared or simultaneously calibrated against one or more standards. Consider, for example, the calibration of three sets of weights having the nominal values, 1, 3, 9, and 27, by means of a standard 81weight. Pairs of 27-weights can be compared, and the sum of the three 27-weights can be compared with the standard 81-weight. Numerous combinations of smaller weights could be used to replace larger weights in other comparisons. Statistical schemes analogous to those used with decimal weights could be derived. Expanding science and technology are creating many new weighing problems. Problems such as the determination of the quantity of fuel in a rocket, the measurement of mass in a low- or zero-gravity environment, or industrial weighing operations controlled by computers may require new techniques and reconsideration of basic principles. The concepts of binary and ternary arithmetic may prove to be as important. in the design of new weighing systems as they are as an aid in understanding our current devices. Acknowledgments
The authors are very grateful for the helpful suggestions and comments of Eugene C. Barrows and Dr. F. Steckel. The authors are extremely appreciative to H. B. Basker for his suggestions of a much-improved form of the truth tables in the appendix.
Table 3.
Binary System Weights, Z0 to Z5.
Table 4.
Binary System Weights, 2"o
2".
are not often used. ' National Bnrean of Standards Handbook 77, op. eil.
Volume 44, Number I, January 1967
/
51
Appendix:
Truth Tables for Weighing
Table 1 could easily be extended for the binary and ternary systems to cover a range from 1 mg to 100 g. However, for 18 binary weights, 2" - 1 = 262143 entries (covering a range from 1 mg to 262.143 g) would he required. The ternary table for 12 weights, would have 1/2(315 - 1 ) = 265720 entries (covering a range from 1 mg to 265.720 g). These tables would be extremely cumbersome to use because of their lengths. A simpler approach would be to use three 6-weight tables for the binary system and three &weight tables far the ternary system requiring a total of 192 and 245 entries, reqpectively. The tables (Tables 3-8) and examples illustrating their m e follow. I n the binary tables, a sign indicates the presence of a weight, a 0 indicates its absence. In the ternary tables, the unknown will be sssumed to he in the sign indicatm the presence lefthand pan. A of a weight in the right-hand pan, 8. - sign indicates the presence of s. weight in the left-hand pan, and s. 0 denotes the absence of a weight from the balance. The correction factors for true weight can be easily added to the totals columns by the user. The user must also multiply the tot& columns by the actual weight of the 2' or 3 O weieht (this weieht heine the scaline factor).
Table 5.
Binary System Weights,
Table 6.
Modified Ternary System Weights, 3O to 33.
Table 7.
Moditied Ternary System Weights,
212 to
2''.
+
+
Ezumple 1 A singlepan balance is being used and 20 = 1 mg. The weights 2'7, ZL6,214, 2% ",, 27, 26, 24, and are necessary to counter-balance the unknown. Whst is the weight of the unknown? Fmm Table 3, the presence of 2' and 20 gives a suhtotal of 17; from Table 4, the presence of ZLQ.Z8. 2'. and 23 rives a subtotal of 1472: from ~abljble'5,the presence of 2", ZLS,and ZL4,give3 ai suhtotal of 180224. The sum of the three subtotals times the actual weight of the 2"eight is (180224 1472 17) 0.001 = 181.713 g.
+
+
Ezample B A double-pan balance is heing used and 3" 1 mg. The unknown is on the lefehand pan; the weights 3", 3', 35,3', and 3 O are on the right-hand pan; and 3Io,38,3') 3¶,and 3' me an the lefehmd
- - -
pan; and the scales are balanced. Whst is the weight OF the unknown? From Table 6, 3= 0, 32 -, 3l -, and 3" gives a subtotal of -11. From Table 7, 3' 0, 3< -, 36 and 34 gives IL subtotal of -405. Frum Table 8, 3'1 -t 31° -, 30 and 38 - gives a subtotal of 131220. The algebraic sum of the three subtotals times the aetuxl weight of the 3 O weight is (131220 - 40.5 - 11) 0.001 = 130.804 g.
- - - +, - + - - +, +
+,
Table 8.
52
/
Journal of Chemical Education
Modified Ternary System Weights, 38 to 311.
to 3'.