Re: Multiplication programs from last month

See all articles from Sinc-Link v9 n1
Author(s): Steve Gunhouse
Publication: Sinc-Link
Pub Details: Sinc-Link v9 n1 (Volume 9, Issue 1)
Date: January/February 1991
Pages: 19-20

One of our members, Steven Gunhouse, has written me a letter which, in part, is a follow-up to two mathematics routines I put in the last Sept/Oct newsletter issue. Excuse my red face!! (I have retyped it because of faint printing. GFC.)

“……I note several typos and some other errors in your “Multiplication Accuracy” program. Line 70 should be N instead of M, line 90 should be “LET B = VAL X$(M)”, line 110 should read “LET I = INT (A(C)/10)”. Those are probably all typos, but there should be an extra line for the printing that reads:

185 IF A(1)<>0 THEN PRINT A(1);

Otherwise, the first digit of something like 99*99 won’t be printed. One other typo is the lack of a semicolon in line 200. With all of those corrections, the program should now be accurate, if somewhat slow.

Of course there is no reason why it has to be quite so slow. Since you have an available accuracy of 8 digits, that means you could multiply two 4-digit numbers with complete accuracy, and doing four digits at a time could take 1/16th of the time. Then again, the output becomes more difficult.

As a mathematician, I did write such a routine, including the correct output, about 2 years ago. I will include it with this letter. Oh, and formally, it is not really accuracy but precision. The computer has about 9 digits of precision; saying it has 9 digits of accuracy requires knowing that your original numbers were accurate. I know, a minor detail, but my grade 9 science teacher required us to distinguish between the two. (Generally, math teachers presume all numbers to be accurate, but science doesn’t have that luxury.)

About the Russian Peasant Multiplication; in reality, that is almost the same way that a computer would multiply. In other words, it is equivalent to the algorithm for binary multiplication. The only reason it is slow is because it’s in BASIC. If you compare speeds for the Russian Peasant program as opposed to the Multiplication Accuracy program, there probably isn’t that much difference. I am not sure how much of a speed the string VALs and the output routine make.

I am glad to see all of the charting stuff as well. Of course, if you are making a chart on the screen, color might also be nice as well as pattern. With the examples used, this would not be difficult to implement.

I looked over Bob’s article as well, but since I only have a V2 (LKDOS EPROM), it doesn’t matter much. I’m surprised about his remark concerning LPRINT CHR$ 12, as I don’t need an extra LPRINT. Is this something specific to V3, or his interface, or his printer? I don’t recall anything like that back when I used a Fastext 80, so I tend to believe it is one of the first two. I also note that my current printer has two extra pitches – semicondensed and semicondensed elongated. I’m surprised he didn’t test out other features, such as italics, emphasis, or underline. I suppose his main point is that the margin and line length settings would change for each size change. Actually he didn’t bother to change the line lengths.

Well, that is enough rambling for now. Though perhaps I will throw in another fractal for good measure. This one is known as the dragon spiral. Most fractals of dimension between 1 and 2 are made by drawing lines…..”

5 REM Multiplication Precision in 4 digit blocks
7 PRINT AT 1,3;"Precision Multiplication"''
8 PRINT TAB 6;"by Steven Gunhouse"
10 INPUT "First Number?"'a$
15 LET a$=" "+a$
16 REM the extra spaces are necessary in case there would be <4 digits in the first block
20 INPUT "Second Number?"'b$
25 LET b$=" "+b$
30 LET a=INT (LEN a$/4)
35 LET b=INT (LEN b$/4)
40 DIM a(a)
45 DIM b(b)
50 FOR i=LEN a$ TO 4 STEP -4
55 LET a(INT (i/4))=VAL a$(i-3 TO i)
60 NEXT i
70 FOR i=LEN b$ TO 4 STEP -4
75 LET b(INT (i/4))=VAL b$(i-3 TO i)
80 NEXT i
90 DIM c(a+b)
100 FOR i=a TO 1 STEP -1
105 LET t1=0
110 FOR j=b TO 1 STEP -1
115 LET c(i+j)=t1+c(i+j)+a(i)*b(j)
120 LET t1=INT (c(i+j)/1e4)
125 LET c(i+j)=c(i+j)-t1*1e4
130 NEXT j
140 LET c(i)=t1
150 NEXT i
200 PRINT a$(4 TO );"x";b$(4 TO );"="
205 LET i=1
210 IF c(1)=0 THEN LET i=2
215 PRINT c(i);
220 FOR j=i+1 TO a+b
225 LET t$=STR$ c(j)
230 PRINT ("000"+t$)(LEN t$ TO );
235 REM Must add extra zeros if t$ is too small (<1000)
240 NEXT j
250 PRINT '"Done."
990 INPUT "Another Number? ";y$: IF y$="Y" OR y$="y" THEN GO TO 1
999 STOP
9999 RANDOMIZE USR 100: SAVE "mult.B4" LINE 1
Digitised portrait (top)
Digitised portrait (top)
Digitised portrait (middle)
Digitised portrait (middle)
Digitised portrait (bottom)
Digitised portrait (bottom)

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.