Web pdp-10.trailing-edge.com

Trailing-Edge - PDP-10 Archives - decuslib20-01 - decus/20-0020/divide.alg
There are 2 other files named divide.alg in the archive. Click here to see a list.
```100'  NAME--DIVIDE
110'
120'  DESCRIPTION--PERFORMS SYNTHETIC DIVISION
130'
140'  SOURCE--UNKNOWN
150'
160' INSTRUCTIONS--TYPE "RUN" AND FOLLOW INSTRUCTIONS
170'
180'
190'  *  *  *  *  *  *  *  *  MAIN PROGRAM  *  *  *  *  *  *  *  *  *  *
200'
210'  DIMENSION OF THE MATRIX AND THEN THE MATRIX VALUES ENTERED BY ROWS.
220 DEF FNN(X) = (X + 1)^2
230 DEF FND(X) = X
240 REM  LINES 1010 TO 1630 EXPAND AND SIMPLIFY FNN(X) AND FND(X).
250 LET D(1) = 8
260 LET D(2) = 7
270 DIM C(3, 22)
280 LET K = 2
290 REM  LINES 1110 TO 1210 FIND F(L, M).
300 FOR L = 0 TO D(K)
310 FOR M = L TO D(K)
320 IF L > 0 THEN 380
330 IF K = 2 THEN 360
340 LET F(L, M) = FNN(M)
350 GOTO 390
360 LET F(L, M) = FND(M)
370 GOTO 390
380 LET F(L, M) = (F(L - 1, M) - F(L - 1, L - 1))/(M - L + 1)
390 NEXT M
400 NEXT L
410 REM  LINES 1310 TO 1380 LOWER D(K).
420 IF F(D(K), D(K)) <> 0 THEN 510
430 LET D(K) = D(K) - 1
440 IF D(K) >= 0 THEN 420
450 IF K = 1 THEN 480
460 PRINT "FND(X) = 0."
470 STOP
480 PRINT 0
490 STOP
500 REM  LINES 1410 TO 1490 FIND U(L, M).
510 FOR L = 0 TO D(K)
520 LET U(L, 0) = 0
530 FOR M = 1 TO D(K)
540 LET U(L, M) = M^L
550 FOR N = 0 TO M - 1
560 LET U(L, M) = (U(L, M) - U(L, N))/(M - N)
570 NEXT N
580 NEXT M
590 NEXT L
600 REM  LINES 1510 TO 1560 FIND C(K, L).
610 FOR L = D(K) TO 0 STEP -1
620 LET C(K, L) = F(L, L)
630 FOR M = L + 1 TO D(K)
640 LET C(K, L) = C(K, L) - U(M, L)*C(K, M)
650 NEXT M
660 NEXT L
670 LET K = K - 1
680 IF K = 1 THEN 300
690 LET P = ABS(C(2, D(2)))
700 REM  LINES 2010 TO 2140 DIVIDE FNN(X) BY FND(X).
710 LET D(3) = D(1) - D(2)
720 IF D(3) < 0 THEN 930
730 FOR K = D(3) TO 0 STEP -1
740 LET C(3, K) = C(1, K + D(2))*SGN(C(2, D(2)))
750 FOR L = 0 TO K + D(2) - 1
760 LET C(1, L) = C(1, L)*P
770 IF L < K THEN 790
780 LET C(1, L) = C(1, L) - C(3, K)*C(2, L - K)
790 NEXT L
800 NEXT K
810 LET D(1) = D(2) - 1
820 FOR K = 0 TO D(1)
830 LET C(1, K) = C(1, K)/P^(D(3) + 1)
840 NEXT K
850 REM  LINES 3010 TO 3630 PRINT THE ANSWER.
860 LET K = 3
870 GOSUB 1080
880 PRINT
890 IF D(1) = -1 THEN 1690
900 IF C(1, D(1)) <> 0 THEN 930
910 LET D(1) = D(1) - 1
920 GOTO 890
930 LET R(1) = SGN(C(1, D(1)))
940 LET R(2) = SGN(C(2, D(2)))
950 IF R(1)*R(2) < 0 THEN 990
960 IF D(3) < 0 THEN 1000
970 PRINT "+";
980 GOTO 1000
990 PRINT "-";
1000 PRINT "(";
1010 LET K = 1
1020 GOSUB 1080
1030 PRINT ")/(";
1040 LET K = 2
1050 GOSUB 1080
1060 PRINT ")"
1070 STOP
1080 FOR L = D(K) TO 0 STEP -1
1090 IF C(K, L) = 0 THEN 1470
1100 IF K = 3 THEN 1120
1110 LET C(K, L) = R(K)*C(K, L)
1120 IF C(K, L) < 0 THEN 1180
1130 IF L = D(K) THEN 1160
1140 PRINT "+";
1150 GOTO 1190
1160 PRINT " ";
1170 GOTO 1190
1180 PRINT "-";
1190 LET Z = ABS(C(K, L))
1200 IF K < 3 THEN 1350
1210 LET Q = P^(D(3) - L + 1)
1220 LET S = 2
1230 GOTO 1330
1240 IF Z/S <> INT(Z/S) THEN 1290
1250 IF Q/S <> INT(Q/S) THEN 1290
1260 LET Z = Z/S
1270 LET Q = Q/S
1280 GOTO 1240
1290 IF S = 2 THEN 1320
1300 LET S = S + 2
1310 GOTO 1330
1320 LET S = 3
1330 IF S > P THEN 1350
1340 IF S <= Z THEN 1240
1350 IF L = 0 THEN 1370
1360 IF Z = 1 THEN 1400
1370 PRINT Z;
1380 IF L = 0 THEN 1430
1390 PRINT "*";
1400 PRINT "X";
1410 IF L = 1 THEN 1430
1420 PRINT "^"L;
1430 IF K < 3 THEN 1470
1440 IF Q = 1 THEN 1460
1450 PRINT "/"Q;
1460 PRINT
1470 NEXT L
1480 RETURN
1490 REM  LINES 4010 TO 4190 PRINT THE INSTRUCTIONS.
1500 PRINT "THIS PROGRAM DOES SYNTHETIC DIVISION."
1510 PRINT
1520 PRINT "DELETE LINE 10."
1530 PRINT
1540 PRINT "INSERT THE FOLLOWING:"
1550 PRINT "20 DEF FNN(X) = ***NUMERATOR***"
1560 PRINT "30 DEF FND(X) = ***DENOMINATOR***"
1570 PRINT
1580 PRINT "FNN(X) MUST BE A POLYNOMIAL"
1590 PRINT "WHOSE COEFFICIENTS ARE INTEGERS AND WHOSE DEGREE <= 8."
1600 PRINT "FND(X) MUST BE A POLYNOMIAL"
1610 PRINT "WHOSE COEFFICIENTS ARE INTEGERS AND WHOSE DEGREE <= 7."
1620 PRINT
1630 PRINT "YOU DON'T HAVE TO GIVE FNN(X) OR FND(X) IN EXPANDED FORM."
1640 PRINT
1650 PRINT "IF FND(X) = 1, THE PROGRAM EXPANDS AND SIMPLIFIES FNN(X)."
1660 PRINT
1670 PRINT "IF FNN(X) AND FND(X) ARE CONSTANT FUNCTIONS,"
1680 PRINT "THE PROGRAM REDUCES THE FRACTION TO LOWEST TERMS."
1690 END

```