Web pdp-10.trailing-edge.com

Trailing-Edge - PDP-10 Archives - decuslib20-01 - decus/20-0020/tautol.log
```100'  NAME--TAUTOLOG
110'
120'  DESCRIPTION--TAKES A FORMULA OF THE PROPOSITIONAL CALCULUS AND,
130'  AT THE USER'S OPTION, EITHER (0) DETERMINES IF THE FORMULA
140'  IS A TAUTOLOGY OR (1) PRINTS THE TRUTH TABLE FOR THE FORMULA.
150'  UNDER OPTION (0), IF THE FORMULA IS NOT A TAUTOLOGY THE
160'  PROGRAM PRINTS AN INVALIDATING ASSIGNMENT TO THE VARIABLES
170'  OCURRING IN THE FORMULA. A FORMULA CAN INVOLVE THE PROPOSITIONAL
180'  VARIABLES A,B,C,.....,S,T AND THE CONNECTIVES:
190'  - (NOT), & (AND), V (OR), => (IF .... THEN), <=> (IF AND
200'  ONLY IF), AND / (NOT BOTH).
210'  ABBREVIATIONS OF THE FORMULAS ARE ALLOWED, WITH BINARY
220'  CONNECTIVES BEING ASSOCIATED TO THE RIGHT OBSERVING THE
230'  PRIORITIES ESTABLISHED BY THE ORDER OF THE CONNECTIVES IN THE
240'  ABOVE LIST.
250'
260'  SOURCE--UNKNOWN
270'
280'  INSTRUCTIONS--TYPE THE OPTION 0 OR 1 AS DATA IN
290'  LINE 380 AND THE FORMULA AS DATA IN LINE 400 AND THEN
300'  TYPE "RUN". E.G., TO PRINT THE TRUTH TABLE OF THE FORMULA
310'  P => Q V -R TYPE THE FOLLOWING:
320'     380 DATA 1
330'     400 DATA "P => Q V -R"
340'
350'
360'  *  *  *  *  *  *  *  MAIN PROGRAM  *  *  *  *  *  *  *  *  *  *
370'
380 DATA 1
400 DATA  "P => Q V -R"
420 CHANGE F\$ TO F
430 PRINT "THE FORMULA"
440 PRINT "     ";F\$
450 LET L = F(0)
460 REM
470 REM  **********  INITIALIZATION  **********
480 REM
490 DIM A(100), B(100), C(100), F(100), G(127)
500 DIM N(100), S(120), V(20), V\$(21)
520 LET G(0) = 9
530 DATA 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9
540 DATA 9,11,9,9,9,9,9,3,9,1,8,9,9,9,2,9,7,9,9,9,9,9,9,9,9,9,9,9,9,6
550 DATA 5,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
560 DATA 10,10,10,10,9,4,9,9,9,9,9,9,9,9,9,9,9,9,9,9
570 DATA 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9
590 DATA A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,F
600 LET P = S = N = F1 = 0
610 REM
620 REM  **********  COMPILATION  **********
630 REM
640 FOR I = 1 TO L
650 LET C = G(F(I))
660 IF C > 11 THEN 930
670 ON C GOTO 680,680,810,810,770,730,810,850,990,910,1210
680 REM    PUT  (  OR  -  INTO SYMBOL CELLAR
690 IF F1 = 1 THEN 1180
700 LET S = S+1
710 LET S(S) = C
720 GOTO 1210
730 REM    CHECK FOR REST OF  =>  AND  <=>
740 IF I = L THEN 990
750 LET I = I+1
760 IF F(I) <> 61 THEN 990
770 IF I = L THEN 990
780 LET I = I+1
790 IF F(I) <> 62 THEN 990
800 REM    HANDLE BINARY CONNECTIVES
810 IF F1 = 0 THEN 1180
820 LET F1 = 0
830 GOSUB 1010
840 GOTO 690
850 REM    HANDLE  )
860 IF F1 = 0 THEN 1180
870 GOSUB 1010
880 IF S = 0 THEN 1180
890 LET S = S-1
900 GOTO 1210
910 REM    HANDLE NEW VARIABLES
920 LET C = G(F(I)) = F(I)
930 REM    HANDLE OLD VARIABLES
940 IF F1 = 1 THEN 1180
950 LET N = N+1
960 LET N(N) = C+36
970 LET F1 = 1
980 GOTO 1210
990 PRINT "CONTAINS AN ILLEGAL CHARACTER"
1000 STOP
1010 REM     SUBROUTINE TO COMPILE INSTRUCTIONS
1020 IF S = 0 THEN 1160
1030 LET D = S(S)
1040 IF D = 1 THEN 1160
1050 IF D >= C THEN 1160
1060 LET P = P+1
1070 LET C(P) = D
1080 IF D = 2 THEN 1170
1090 IF N < 2 THEN 1180
1100 LET N = N-1
1110 LET B(P) = N(N+1)
1120 LET A(P) = N(N)
1130 LET N(N) = P
1140 LET S = S-1
1150 GOTO 1010
1160 RETURN
1170 IF N > 0 THEN 1120
1180 PRINT "IS NOT WELL-FORMED."
1190 STOP
1200 REM    END OF COMPILATION LOOP
1210 NEXT I
1220 REM
1230 REM    CLEAN OUT SYMBOL CELLAR AND CHECK FOR ERRORS
1240 IF F1 = 0 THEN 1180
1250 IF S = 0 THEN 1290
1260 LET C = 8
1270 GOSUB 1010
1280 IF S > 0 THEN 1180
1290 IF N <> 1 THEN 1180
1300 LET R = N(1)
1310 REM
1320 REM
1330 REM  ********** SET UP FOR PRINTING  **********
1340 REM
1350 REM     FIND VARIABLES OCCURRING IN FORMULA
1360 LET V = 0
1370 FOR I = 65 TO 84
1380 IF G(I) = 10 THEN 1410
1390 LET V = V+1
1400 LET V(V) = I+36
1410 NEXT I
1420 REM    SET TABS
1430 LET T9 = 6
1440 IF V < 11 THEN 1460
1450 LET T9 = INT(60/V)
1460 IF T = 0 THEN 1720
1470 IF V > 8 THEN 1510
1480 PRINT "HAS THE TRUTH TABLE"
1490 GOSUB 1560
1500 GOTO 1720
1510 PRINT "WOULD GENERATE A TRUTH TABLE OF OVER 500 LINES.  HOWEVER";
1520 PRINT " THIS FORMULA"
1530 LET T = 0
1540 GOTO 1720
1550 REM
1560 REM    SUBROUTINE TO PRINT VARIABLES
1570 PRINT
1580 FOR J = 1 TO V
1590 PRINT V\$(V(J)-100); TAB(T9*J);
1600 NEXT J
1610 PRINT "FORMULA"
1620 RETURN
1630 REM
1640 REM     SUBROUTINE TO PRINT TRUTH VALUES
1650 FOR J = 1 TO V
1660 PRINT V\$(20+S(V(J))); TAB(T9*J);
1670 NEXT J
1680 PRINT "   "; V\$(20+S(R))
1690 RETURN
1700 REM
1710 REM
1720 REM  **********  CALCULATION OF TRUTH TABLE  **********
1730 REM
1740 FOR Q = 0 TO 2^V-1
1750 LET X = Q
1760 FOR I = V TO 1 STEP -1
1770 LET Y = INT(X/2)
1780 LET S(V(I)) = X - Y*2
1790 LET X = Y
1800 NEXT I
1810 FOR I = 1 TO P
1820 ON C(I) GOTO 1830,1830,1850,1870,1890,1910,1930
1830 LET S(I) = 1 - S(A(I))
1840 GOTO 1940
1850 LET S(I) = SGN( S(A(I)) + S(B(I)) )
1860 GOTO 1940
1870 LET S(I) = S(A(I)) * S(B(I))
1880 GOTO 1940
1890 LET S(I) = ( 1 - S(A(I)) ) * S(B(I))
1900 GOTO 1940
1910 LET S(I) = ABS( S(A(I)) - S(B(I)) )
1920 GOTO 1940
1930 LET S(I) = 1 - SGN( S(A(I)) + S(B(I)) )
1940 NEXT I
1950 IF T = 1 THEN 2060
1960 IF S(R) = 1 THEN 2010
1970 NEXT Q
1980 IF T = 1 THEN 2000
1990 PRINT "IS A TAUTOLOGY."
2000 STOP
2010 PRINT "IS NOT A TAUTOLOGY.  AN INVALIDATING ASSIGNMENT TO THE";
2020 PRINT " VARIABLES IS:"
2030 GOSUB 1560
2040 GOSUB 1640
2050 STOP
2060 GOSUB 1640
2070 GOTO 1970
2080 END

```