Download Exploring Math

Transcript
Chapter 7 Decimal and Other Number Systems 43
d10=: bv10i 365 1966
d10
0 3 6 5
1 9 9 6
+/d10
1 12 15 11
N +/d10
2 3 6 1
Exercises
8. Use bv10i to compute the table of decimal representations of the list of
numbers a,b,c, where a=:365 and b=:1996 and c=:29. From this table
compute the standard representation of the sum a+b+c.
9. Use ar=:bv10i a and br=:bv10i b and cr=:bv10i c to obtain the decimal
representations of the numbers of Exercise 1, and use them in expressions to
obtain the standard decimal representation of the sum b.
In the table produced in Ex. 8, each of the shorter lists (that is, 3 6 5 and 2 9) are
padded with zeroes on the left, a change that does not change the values of the
numbers they represent. In Ex. 9 the representations are not so padded, and the
lists of differing lengths cannot be added directly. They may be added as
illustrated below:
ar;br;cr
+-----+-------+---+
|3 6 5|1 9 9 6|2 9|
+-----+-------+---+
bv10&> ar;br;cr
365 1996 29
bv10i bv10&> ar;br;cr
0 3 6 5
1 9 9 6
0 0 2 9
N +/ bv10i bv10&> ar;br;cr
2 3 9 0
a+b+c
2390
Padding can also be provided more directly, using the fact that the simple opening
of a boxed list pads it, albeit on the wrong side:
>ar;br;cr
3 6 5 0
1 9 9 6
2 9 0 0
pad=:|."1@:(|.&>)
pad ar;br;cr
0 3 6 5