'===========================================================================
' Subject: SYLLOGISMS                         Date: 04-29-98 (20:18)       
'  Author: Richard Sharvy                     Code: QB, QBasic, PDS        
'  Origin: bsharvy@efn.org                  Packet: ALGOR.ABC
'===========================================================================
'Syllogism
'Webster's: 1. a deductive scheme of a formal argument 
'consisting of a major and a minor premise and a conclusion (as 'every 
'virtue is laudable; kindness is a virtue; therefore, kindness is 
'laudable') 2. a subtle, specious, or crafty argument 3. deductive 
'reasoning

'To use Syllogism, enter a syllogism, one line at a time, and 
'then test conclusions or ask the program to draw a conclusion. A 
'syllogism as (mis)defined here is a (possibly empty) set of numbered 
'premises. No term may occur more than twice. Exactly two terms must 
'occur exactly once: these are the two 'end' terms, which will appear in 
'the conclusion. Furthermore, each premise must have exactly one term in 
'common with its successor, for some ordering of the premises. Example10 
'Socrates is a Greek20 All men are mortal30 All Greeks are men40 No gods 
'are mortal Syllogism will draw a conclusion from such a list, if 
'possible, or test a conclusion of yours. Reference: H. Gensler, 'A 
'Simplified Decision Procedure for Categorical Syllogisms,' Notre Dame J 
'of Formal Logic 14 (1973) 457-466

'Syllogism was written by Richard 
'Sharvy in 1987 or so (he died in 1988). It is written in generic BASIC (for
'a CP/M compiler). 
'I came across a cheapo BASIC compiler for the Mac (Microsoft QuickBasic) 
'a few years later, and compiled the source code as is; other than a junk
'character following each carriage-return, it works fine. The interface 
'style of that Mac application is strict terminal emulation (it can be
'downloaded at http://www.efn.org/~bsharvy/crunchy.html). The source 
'code should be compilable by any BASIC compiler, regardless of platform. 
'http://www.efn.org/~bsharvy/crunchy.html
'----
5 CL$=CHR$(27)+"E
10 PRINT CL$"Syllogism Program 26K Copyright (c) 1988 Richard Sharvy
30 PRINT"2447 Kincaid St., Eugene OR 97405-3055":PRINT
480 DIM A%(63),C%(63),D%(63),G%(63),L%(63),N%(63),O%(63),P%(63),Q%(63)
490 DIM R%(63),B%(63),K%(63),J%(4),T%(7),E%(2),H%(2)
500 DIM A$(3),L$(63),T$(65)
510 DIM G$(2),S$(6),W$(2),X$(7),Y$(7),Z$(7)
520 READ A$(1),A$(2),A$(3),G$(0),G$(1),G$(2)
530 DATA "a ","an ","sm ",undetermined type,general term,designator
550 FOR I%=0 TO 7:READ X$(I%),Y$(I%),Z$(I%):NEXT
570 DATA some,  "  is",,some,"  is not",*
580 DATA all,*  is,,no,*  is,*
590 DATA ,+  is,,,+  is not,*
600 DATA ,+ =,+,,+  =/=,*
740 DIM U$(75),V$(75)
760 I%=0
770 I%=I%+1
771  READ U$(I%),V$(I%)
780  IF U$(I%)<>"ZZZZZ"THEN 770
790 U1%=I%-1
820 DATA socrates,socrates,parmenides,parmenides,epimenides,epimenides
840 DATA mice,mouse,lice,louse,geese,goose
850 DATA children,child,oxen,ox,people,person,teeth,tooth
860 DATA wolves,wolf,wives,wife,selves,self,lives,life,leaves,leaf
870 DATA shelves,shelf,elves,elf,dwarves,dwarf,knives,knife,thieves,thief
880 DATA neckties,necktie,hippies,hippie,yippies,yippie,yuppies,yuppie
890 DATA moonies,moonie,druggies,druggie,cookies,cookie,commies,commie
891 DATA groupies,groupie,tomatoes,tomato
910 DATA alcibiades,alcibiades,thales,thales,aries,aries,athens,athens
920 DATA species,species,feces,feces,geniuses,genius,sorites,sorites
930 DATA crises,crisis,emphases,emphasis,memoranda,memorandum,theses,thesis
940 DATA automata,automaton,formulae,formula,stigmata,stigma,lemmata,lemma
950 DATA vertices,vertex,vortices,vortex,indices,index,codices,codex
960 DATA matrices,matrix
970 DATA gasses,gas,gases,gas,buses,bus,aches,ache,headaches,headache
980 DATA grits,grits,molasses,molasses,gas,gas,christmas,christmas
990 DATA mathematics,mathematics,semantics,semantics,physics,physics
1000 DATA metaphysics,metaphysics,ethics,ethics,linguistics,linguistics
1010 DATA kiwis,kiwi,israelis,israeli
1020 DATA goyim,goy,seraphim,seraph,cherubim,cherub
1025 DATA semen,semen,amen,amen
1030 DATA ZZZZZ,ZZZZZ
1050 MSG%=-1:A%(0)=1:FOR I%=1 TO 63:A%(I%)=I%:NEXT
1070 IF MSG% THEN PRINT"Enter HELP for list of commands
1080 REM---Input line---
1085 PRINT">";
1090 LINE INPUT L1$
1100 L%=LEN(L1$)
1110 IF L%=0 THEN 1070
1120 L2$=RIGHT$(L1$,1)
1121  IF L2$=" "THEN 1160
1130   IF L2$<>"."AND L2$<>"?"AND L2$<>"!"THEN 1181
1140   PRINT TAB(L%)" ^   Punctuation mark ignored
1160  IF L%=1 THEN 1080
1165  L%=L%-1:L1$=LEFT$(L1$,L%):GOTO 1120
1181 IF LEFT$(L1$,1)<>" "THEN 1190
1182  IF L%=1 THEN 1080
1184  L%=L%-1:L1$=RIGHT$(L1$,L%):GOTO 1181
1190 FOR I%=1 TO L%
1191  V%=ASC(MID$(L1$,I%,1))
1192  IF V%=>65 AND V%<=90 THEN MID$(L1$,I%,1)=CHR$(V%+32)
1193  NEXT
1220 IF L1$<>"stop"THEN 1230
1223  PRINT"Enter CONT to continue":STOP
1227  GOTO 1080
1230 IF L1$<>"new"THEN 1270
1240  PRINT"Begin new syllogism
1250  GOSUB 1840
1260  GOTO 1080
1270 IF L1$<>"sample"THEN 1310
1280  GOSUB 1840
1290  GOSUB 8980
1300  GOTO 1080
1310 IF L1$<>"help"THEN 1340
1320  GOSUB 7660
1330  GOTO 1080
1340 IF L1$<>"syntax"THEN 1370
1350  GOSUB 7960
1360  GOTO 1080
1370 IF L1$<>"info"THEN 1430
1380  GOSUB 8290
1390  GOTO 1080
1430 IF L1$<>"dump"THEN 1460
1440  GOSUB 8890
1450  GOTO 1080
1460 IF L1$<>"msg"THEN 1500
1465  MSG%=NOT(MSG%)
1470  PRINT"Messages turned ";
1475  IF MSG% THEN PRINT"on" ELSE PRINT"off
1480  GOTO 1080
1500 IF L1$<>"substitute"THEN 1540
1510  IF L%(0)=0 THEN 1612
1520  GOSUB 9060
1530  GOTO 1080
1540 IF L1$<>"link"AND L1$<>"link*"THEN 1561
1545  IF L%(0)=0 THEN 1612
1550  GOSUB 5070
1560  GOTO 1080
1561 IF L1$<>"list" AND L1$<>"list*" THEN 1570
1562  IF L%(0)=0 THEN 1612
1563  GOSUB 7460
1564  GOTO 1080
1570 REM--scan line L1$ into array S$()
1575 GOSUB 2020
1580 IF T%(1)<>1 THEN 1745
1600  IF T%(2) THEN 1640
1610   IF L%(0) THEN 1620
1612    PRINT"No premises":GOTO 1080
1620   GOSUB 4760 :REM delete line
1630   GOTO 1080
1640  GOSUB 2890 :REM parse the line in S$()
1650  IF D1%<0 THEN 1080
1660  GOSUB 4530 :REM enter line into list
1670  GOSUB 3400 :REM add terms to symbol table
1680  GOTO 1080
1745 IF T%(1)=0 THEN 1070
1750 REM draw/test conclusion
1755 GOSUB 5070  :REM is it a syl?
1760 IF J1%>1 THEN 1080
1770 IF J1%=0 THEN GOSUB 5880 :REM poss. conclusion?
1810  IF J1%>1 THEN 1080
1820  IF T%(2) THEN GOSUB 6630 ELSE GOSUB 6200 :REM test/draw conclusion
1830 GOTO 1080
1840 REM---New---
1850 IF L%(0)=0 THEN 2010
1860 FOR I%=1 TO L1%
1870  D%(I%)=0:T$(I%)="":B%(I%)=0:O%(I%)=0:G%(I%)=0
1920  NEXT
1930 L1%=0:N1%=0
1950 J%=L%(0)
1960 A%(0)=A%(0)-1
1970  A%(A%(0))=J%
1980  J%=L%(J%)
1990  IF J%>0 THEN 1960
2000 L%(0)=0
2010 RETURN
2020 REM---L1$ into array S$()---
2030 REM T%(): 1:line num., 2:"/", 3:quantifier, 4:no/not, 5:is/are, 6:term
2040 REM                     10 SOME  FRIED COCONUTS   ARE  NOT  TASTY
2050 REM                      1   3        6            5    4     6
2080 FOR J%=1 TO 6:S$(J%)="":T%(J%)=0:NEXT
2120 P1%=0:E%(2)=0:J%=1:I%=1
2160 L%=LEN(L1$)
2180 IF I%>L% THEN 2885
2190  S$=MID$(L1$,I%,1)
2200  IF S$=" "THEN I%=I%+1:GOTO 2180
2230 K%=1
2240 IF I%+K%>L% THEN 2290
2250  S$=MID$(L1$,I%+K%,1)
2260  IF S$<>" "THEN K%=K%+1:GOTO 2240
2290 S$=MID$(L1$,I%,K%)  :REM S$ is set to next word
2310 IF J%>1 THEN 2520
2320  IF S$<>"/"THEN 2400
2360  T%(1)=2
2370  GOTO 2840
2400 N%=LEN(S$)
2410 IF N%>4 THEN 2460
2420  N%=1
2430  T$=MID$(S$,N%,1)
2440  IF ASC(T$)<=57 AND ASC(T$)=>48 THEN 2480
2460   PRINT TAB(I%+N%)"^   Invalid numeral or command
2470   GOTO 2885
2480  N%=N%+1
2490  IF N%<=LEN(S$) THEN 2430
2500 T%(1)=1
2510 GOTO 2840
2520 REM Scan
2525 IF S$="somebody"OR S$="something"OR S$="nobody"OR S$="nothing"THEN 2670
2527 IF S$="someone"OR S$="everyone"OR S$="everybody"OR S$="everything"THEN 2670
2530 IF S$<>"all"AND S$<>"some"THEN 2570
2540  IF T%(J%)=6 THEN 2670
2550  T%(J%)=3
2560  GOTO 2840
2570 IF S$<>"no"AND S$<>"not"THEN 2610
2580  IF T%(J%)=6 THEN 2670
2590  T%(J%)=4
2600  GOTO 2840
2610 IF S$<>"is"AND S$<>"are"THEN 2710
2620  IF T%(J%)<>6 THEN 2670
2630  IF T%(J%-1)=5 OR T%(J%-2)=5 THEN 2670
2640   J%=J%+1
2650   T%(J%)=5
2660   GOTO 2840
2670  PRINT TAB(I%+K%-1)"^
2680  PRINT"Reserved word '"S$"' may not occur within a term
2690  T%(1)=0
2700  GOTO 2885
2710 IF T%(J%)=6 THEN 2820
2720 IF T%(J%-1)<>5 AND T%(J%-2)<>5 THEN 2790
2730 IF S$<>"a"AND S$<>"an"AND S$<>"sm"THEN 2780
2740  IF I%=L% THEN 2790
2750  IF S$="a"THEN E%(2)=1 ELSE IF S$="an"THEN E%(2)=2 ELSE E%(2)=3
2760  P1%=1
2770  GOTO 2860
2780 IF S$="the"THEN P1%=2
2790 S$(J%)=S$
2800 T%(J%)=6
2810 GOTO 2860
2820 S$(J%)=S$(J%)+" "+S$
2830 GOTO 2860
2840 S$(J%)=S$
2850 J%=J%+1
2860 I%=K%+I%
2870 IF J%<=6 THEN 2180
2885 RETURN
2890 REM---Parse line in S$()---
2900 D1%=-1
2910 IF S$(2)<>"all"THEN 2990
2920  IF T%(3)<>6 THEN 3350
2930  IF T%(4)<>5 THEN 3330
2940  IF T%(5)<>6 THEN 3370
2950  W$(1)=S$(3)
2960  W$(2)=S$(5)
2970  D1%=2 :REM all A is B
2980  GOTO 3390
2990 IF S$(2)<>"some"THEN 3130
3000  IF T%(3)<>6 THEN 3350
3010  IF T%(4)<>5 THEN 3330
3020  IF S$(5)="not"THEN 3080
3030   IF T%(5)<>6 THEN 3370
3040   W$(1)=S$(3)
3050   W$(2)=S$(5)
3060   D1%=0 :REM Some A is B
3070   GOTO 3390
3080  IF T%(6)<>6 THEN 3370
3090   W$(1)=S$(3)
3100   W$(2)=S$(6)
3110    D1%=1 :REM some A is not B
3120    GOTO 3390
3130 IF S$(2)<>"no"THEN 3210
3140  IF T%(3)<>6 THEN 3350
3150  IF T%(4)<>5 THEN 3330
3160  IF T%(5)<>6 THEN 3370
3170  W$(1)=S$(3)
3180  W$(2)=S$(5)
3190  D1%=3 :REM no A is B
3200  GOTO 3390
3210 IF T%(2)<>6 THEN 3350
3220 IF T%(3)<>5 THEN 3330
3230 W$(1)=S$(2)
3240 IF S$(4)="not"THEN 3290
3250  IF T%(4)<>6 THEN 3370
3260  D1%=4 :REM a is T
3270  W$(2)=S$(4)
3280  GOTO 3390
3290 IF T%(5)<>6 THEN 3370
3300  D1%=5 :REM a is not T
3310  W$(2)=S$(5)
3320  GOTO 3390
3330 PRINT"** Missing copula is/are
3340 GOTO 3380
3350 PRINT"** Subject term bad or missing
3360 GOTO 3380
3370 PRINT"** Predicate term bad or missing
3380 IF MSG% THEN PRINT"Enter SYNTAX for help with statements
3390 RETURN
3400 REM---Add W$(1), W$(2) to table T$()---
3410 IF (D1%MOD 2)=0 THEN 3440
3420  N1%=N1%+1
3430  IF N1%>1 AND MSG% THEN PRINT"Warning: "N1%" negative premises
3440 E%(1)=0
3450 FOR J%=1 TO 2
3460 W$=W$(J%)
3470 IF D1%<4 THEN G%=1 ELSE IF J%=1 THEN G%=2 ELSE G%=P1%
3480 GOSUB 4040
3490 I1%=1
3500 GOSUB 3950
3510 IF I1%<=L1% THEN 3550
3520  IF B1%>0 THEN I1%=B1% ELSE L1%=L1%+1
3530  T$(I1%)=W$
3540  GOTO 3720
3550 IF G%=0 THEN 3660
3570 IF G%(I1%)=0 THEN 3620
3580 IF G%=G%(I1%) THEN 3730
3590  IF NOT MSG% THEN 3600
3592   PRINT"Warning: "G$(G%)" '"W$"'";" has also occurred as a "G$(3-G%)
3600  I1%=I1%+1
3610 GOTO 3500
3620 IF NOT MSG% THEN 3710
3630  PRINT"Note: earlier use of '"W$"'";" taken as the "G$(G%)" used here
3640 GOTO 3710
3660 IF G%(I1%)=0 AND NOT MSG% THEN 3730
3670  PRINT"Note: predicate term '"W$"'";
3680  PRINT" taken as the "G$(G%(I1%))" used earlier
3690 GOTO 3730
3710 IF G%=2 THEN D%(I1%)=O%(I1%)
3720 G%(I1%)=G%
3730 IF E%(J%)>0 THEN 3770
3740  IF B%(I1%)>0 OR W$=W$(J%) THEN 3780
3750   A$=LEFT$(W$,1)
3760 IF A$="a"OR A$="e"OR A$="i"OR A$="o"OR A$="u"THEN E%(J%)=2 ELSE
E%(J%)=1
3770   B%(I1%)=E%(J%)
3780 O%(I1%)=O%(I1%)+1
3790 IF O%(I1%)<3 THEN 3810
3800 IF NOT MSG% THEN 3810
3805  PRINT"Warning: "G$(G%(I1%))" '"W$"' has occurred"O%(I1%)"times
3810 IF J%=2 THEN 3850
3820  P%(A1%)=I1%
3830  IF D1%=>2 THEN D%(I1%)=D%(I1%)+1
3840  GOTO 3900
3850 Q%(A1%)=I1%
3860  IF P%(A1%)<>Q%(A1%) THEN 3880
3870   IF MSG% THEN PRINT"Warning: same term occurs twice in line "S$(1)
3880  IF G%(I1%)=2 THEN D1%=D1%+2
3890  IF D1%=6 OR D1% MOD 2 THEN D%(I1%)=D%(I1%)+1
3900 IF O%(I1%)<>2 OR D%(I1%)>0 THEN 3920
3910  IF MSG% THEN PRINT"Warning: undistributed middle term '"T$(I1%)"'
3920 NEXT J%
3930 R%(A1%)=D1%
3940 RETURN
3950 REM---Search T$() for W$ from I1 to L1---
3960 REM If found, I1=L1; else I1=L1+1. B1 set to 1st empty loc.
3970 B1%=0
3980 IF I1%>L1% THEN 4030
3990 IF T$(I1%)=W$ THEN 4030
4000  IF O%(I1%)=0 AND B1%=0 THEN B1%=I1%
4010  I1%=I1%+1
4020  GOTO 3980
4030 RETURN
4040 REM---Convert W$ to singular---
4050 L%=LEN(W$)
4060 IF L%<4 THEN 4090
4070  S$=LEFT$(W$,4)
4080  IF S$="the "THEN 4520
4090 X$=""
4100 I%=1
4110 N%=1
4120 IF I%>L% THEN 4510
4130  S$=MID$(W$,I%,1)
4140  IF S$<>" "THEN 4170
4150   I%=I%+1
4160   GOTO 4120
4170 M%=1
4180 IF I%+M%>L% THEN 4230
4190  S$=MID$(W$,I%+M%,1)
4200  IF S$=" "THEN 4230
4210   M%=M%+1
4220   GOTO 4180
4230 S$=MID$(W$,I%,M%)
4240 Y$=S$
4250 K%=1
4260 IF Y$<>U$(K%) THEN 4290
4270  Y$=V$(K%)
4280  GOTO 4470
4290  K%=K%+1
4291  IF K%<=U1% THEN 4260
4302 IF LEN(Y$)<3 THEN 4310
4304  IF RIGHT$(Y$,3)<>"men"THEN 4310
4306  Y$=LEFT$(Y$,LEN(Y$)-2)+"an
4308  GOTO 4470
4310 L$=RIGHT$(Y$,1)
4320 IF L$<>"s"THEN 4470
4330  IF LEN(Y$)>1 THEN L$=RIGHT$(Y$,2) ELSE 4470
4340  IF L$="ss"OR L$="us"OR L$="is"OR L$="'s"THEN 4470
4350   Y$=LEFT$(Y$,LEN(Y$)-1)
4360   IF LEN(Y$)>1 THEN L$=RIGHT$(Y$,2) ELSE 4470
4370 IF L$<>"xe"THEN 4400
4380  Y$=LEFT$(Y$,LEN(Y$)-1)
4390  GOTO 4470
4400 IF L$<>"ie"OR LEN(Y$)<=3 THEN 4440
4410  Y$=LEFT$(Y$,LEN(Y$)-2)
4420  Y$=Y$+"y
4430  GOTO 4470
4440 IF LEN(Y$)>2 THEN L$=RIGHT$(Y$,3) ELSE 4470
4450 IF L$<>"sse"AND L$<>"she"AND L$<>"che"THEN 4470
4460  Y$=LEFT$(Y$,LEN(Y$)-1)
4470 IF LEN(X$)=0 THEN X$=Y$ ELSE X$=X$+" "+Y$
4480 N%=N%+1
4490 I%=M%+I%
4500 GOTO 4120
4510 W$=X$
4520 RETURN
4530 REM---Enter line into list---
4540 N%=VAL(S$(1))
4550 S%=LEN(S$(1))+1
4560 L%=LEN(L1$)
4570 L$=MID$(L1$,S%+1,L%-S%)
4580 I%=0
4590 J1%=L%(I%)
4600 IF J1%=0 THEN 4690
4610  IF N%<>N%(J1%) THEN 4660
4620   GOSUB 4890
4630   L$(J1%)=L$
4640   A1%=J1%
4650   GOTO 4750
4660  IF N%<N%(J1%) THEN 4690
4670   I%=J1%
4680   GOTO 4590
4690 A1%=A%(A%(0))
4700 L$(A1%)=L$
4710 N%(A1%)=N%
4720 L%(I%)=A1%
4730 L%(A1%)=J1%
4740 A%(0)=A%(0)+1
4750 RETURN
4760 REM---Delete a line---
4770 N%=VAL(S$(1))
4780 I%=0
4790 J1%=L%(I%)
4800  IF J1%=0 THEN PRINT"Line"N%"not found":GOTO 4880
4810   IF N%=N%(J1%) THEN 4840
4820    I%=L%(I%)
4830    GOTO 4790
4840   A%(0)=A%(0)-1
4850   A%(A%(0))=J1%
4860   L%(I%)=L%(J1%)
4870   GOSUB 4890
4880 RETURN
4890 REM---Decrement table entries---
4900 J%(1)=P%(J1%)
4910 J%(2)=Q%(J1%)
4920 IF R%(J1%) MOD 2 =0 THEN 4960
4930  N1%=N1%-1
4940  J%(4)=1
4950  GOTO 4970
4960 IF G%(Q%(J1%))=2 THEN J%(4)=1 ELSE J%(4)=0
4970 IF R%(J1%)=>2 THEN J%(3)=1 ELSE J%(3)=0
4980 FOR K%=1 TO 2
4990  O%(J%(K%))=O%(J%(K%))-1
5000  IF O%(J%(K%))>0 THEN 5040
5010   T$(J%(K%))=""
5020   B%(J%(K%))=0
5030   G%(J%(K%))=0
5040  D%(J%(K%))=D%(J%(K%))-J%(K%+2)
5050  NEXT
5060 RETURN
5070 REM---See if syllogism---
5080 J1%=0
5090 V1%=0 :REM flag for modern validity
5100 IF L%(0) THEN 5140
5120  J1%=1:GOTO 5870
5140 C%=0
5150 FOR I%=1 TO L1%
5160  IF O%(I%)=0 OR O%(I%)=2 THEN 5250
5170   IF O%(I%)<>1 THEN 5210
5180    C%=C%+1
5190    C%(C%)=I%
5200    GOTO 5250
5210   IF J1%=2 THEN 5240
5220    PRINT"Not a syllogism:
5230    J1%=2
5240   PRINT"   "G$(G%(I%))" '"T$(I%)"' occurs"O%(I%)"times in premises.
5250  NEXT
5260 IF C%=2 THEN 5360
5270  PRINT"Not a syllogism:
5280  J1%=3
5290  IF C%>0 THEN 5320
5300   PRINT"   no terms occur exactly once in premises.
5310   GOTO 5360
5320  PRINT"   "C%"terms occur exactly once in premises.
5330 FOR I%=1 TO C%
5340  PRINT TAB(6)T$(C%(I%))" -- "G$(G%(C%(I%)))
5350  NEXT
5360 IF J1% THEN 5870
5370 I%=L%(0)
5380 L%=0
5390  L%=L%+1
5400  K%(L%)=I%
5410  I%=L%(I%)
5420  IF I% THEN 5390
5430 IF L%=1 THEN 5750
5440 IF D%(C%(1))=0 AND D%(C%(2))=1 THEN T%=C%(2) ELSE T%=C%(1)
5450 I%=1
5460 K%=I%
5470  IF P%(K%(K%))<>T% THEN 5500
5480   T%=Q%(K%(K%))
5490   GOTO 5520
5500  IF Q%(K%(K%))<>T% THEN 5620
5510   T%=P%(K%(K%))
5520   IF K%=I% THEN 5610
5530    N%=1
5540    H%(1)=K%(I%)
5550    FOR M%=I% TO K%-1
5560     N%=3-N%
5570     H%(N%)=K%(M%+1)
5580     K%(M%+1)=H%(3-N%)
5590     NEXT
5600    K%(I%)=H%(N%)
5610   IF J1% THEN 5710 ELSE 5730
5620  K%=K%+1
5630  IF K%<=L% THEN 5470
5640  T%=Q%(K%(I%))
5650  IF J1%>0 THEN 5700
5660   J1%=4
5670   PRINT"Not a syllogism: no way to order premises so that each premise
5690   PRINT"shares exactly one term with its successor; there is a
5700   PRINT"closed loop in the term chain within the premise set--
5710   PRINT N%(K%(I%));
5720   PRINT L$(K%(I%))
5730   I%=I%+1
5740   IF I%<=L% THEN 5460
5750 IF J1%>0 THEN 5870
5760 IF L1$<>"link"AND L1$<>"link*"THEN 5870
5770  PRINT"Premises of syllogism in order of term links:
5780  FOR I%=1 TO L%
5790   PRINT N%(K%(I%));
5800    IF L1$="link"THEN 5850
5810    IF R%(K%(I%))<6 AND G%(Q%(K%(I%)))=2 THEN R%(K%(I%))=R%(K%(I%))+2
5820    IF R%(K%(I%))<4 THEN PRINT X$(R%(K%(I%)))"  ";
5830    PRINT T$(P%(K%(I%)));Y$(R%(K%(I%)))"  "T$(Q%(K%(I%)));Z$(R%(K%(I%)))
5840    GOTO 5860
5850    PRINT L$(K%(I%))
5860  NEXT I%
5870 RETURN
5880 REM---See if conclusion possible---
5890 C1%=C%(1)
5900 C2%=C%(2)
5910 FOR I%=1 TO L1%
5920  IF O%(I%)<2 THEN 6000
5930   IF D%(I%)>0 THEN 5980
5940    IF J1%>0 THEN 5970
5950     PRINT"Undistributed middle terms:
5960     J1%=5
5970    PRINT TAB(5)T$(I%)
5980   IF D%(I%)=1 OR G%(I%)=2 THEN 6000
5990    V1%=I%
6000  NEXT I%
6010 IF N1%<2 THEN 6040
6020  J1%=6
6030  PRINT"More than one negative premise:
6040 IF J1%>0 THEN 6180
6050 IF N1%=0 THEN 6190
6060 IF D%(C1%)>0 OR D%(C2%)>0 THEN 6100
6070  PRINT"Terms '"T$(C1%)"' and '"T$(C2%)"',";" one of which is
6090  GOTO 6150
6100 IF D%(C1%)>0 OR G%(C2%)<2 THEN 6130
6110  PRINT"Term '"T$(C1%)"'
6120  GOTO 6150
6130 IF D%(C2%)>0 OR G%(C1%)<2 THEN 6190
6140  PRINT"Term '"T$(C2%)"'
6150 PRINT"required in predicate of negative conclusion
6160 PRINT"not distributed in the premises.
6170 J1%=7
6180 PRINT"No possible conclusion.
6190 RETURN
6200 REM---Compute conclusion---
6201 IF L%(0)=0 THEN Z$="A is A":GOTO 6580
6210 IF N1%=0 THEN 6400
6220 REM negative conclusion
6230 IF D%(C2%)>0 THEN 6260
6240  Z$="Some "+T$(C2%)+" is not "+A$(B%(C1%))+T$(C1%)
6250  GOTO 6390
6260 IF D%(C1%)>0 THEN 6290
6270  Z$="Some "+T$(C1%)+" is not "+A$(B%(C2%))+T$(C2%)
6280  GOTO 6390
6290 IF G%(C1%)<2 THEN 6320
6300  Z$=T$(C1%)+" is not "+A$(B%(C2%))+T$(C2%)
6310  GOTO 6390
6320 IF G%(C2%)<2 THEN 6350
6330  Z$=T$(C2%)+" is not "+A$(B%(C1%))+T$(C1%)
6340  GOTO 6390
6350 IF B%(C1%)>0 OR B%(C2%)=0 THEN 6380
6360  Z$="No "+T$(C2%)+" is "+A$(B%(C1%))+T$(C1%)
6370  GOTO 6390
6380  Z$="No "+T$(C1%)+" is "+A$(B%(C2%))+T$(C2%)
6390 GOTO 6570
6400 REM affirmative conclusion
6410 IF D%(C1%)=0 THEN 6470
6420  IF G%(C1%)=2 THEN 6450
6430   Z$="All "+T$(C1%)+" is "+T$(C2%)
6440   GOTO 6570
6450   Z$=T$(C1%)+" is "+A$(B%(C2%))+T$(C2%)
6460   GOTO 6570
6470 IF D%(C2%)=0 THEN 6530
6480  IF G%(C2%)=2 THEN 6510
6490   Z$="All "+T$(C2%)+" is "+T$(C1%)
6500   GOTO 6570
6510   Z$=T$(C2%)+" is "+A$(B%(C1%))+T$(C1%)
6520   GOTO 6570
6530 IF B%(C1%)>0 OR B%(C2%)=0 THEN 6560
6540  Z$="Some "+T$(C2%)+" is "+A$(B%(C1%))+T$(C1%)
6550  GOTO 6570
6560  Z$="Some "+T$(C1%)+" is "+A$(B%(C2%))+T$(C2%)
6570 REM Print conclusion
6580 PRINT"  / "Z$
6590 IF V1%=0 THEN 6620
6600  PRINT"  * Aristotle-valid only, i.e. on requirement that term ";
6610  PRINT"'"T$(V1%)"' denotes.
6620 RETURN
6630 REM---test offered conclusion---
6640 REM--conc. poss, line in s$()
6650 GOSUB 2890
6660 IF D1%<0 THEN 7370
6670 IF D1%<4 THEN G1%=1:G2%=1 ELSE G1%=2:G2%=P1%
6690 IF G2%=2 AND D1%<6 AND D1%>3 THEN D1%=D1%+2
6700 W$=W$(1)
6710 GOSUB 4040
6720 IF J1%=0 THEN 6750
6730  W$(1)=W$
6740  GOTO 6840
6750 FOR J%=1 TO 2
6760  IF W$<>T$(C%(J%)) THEN 6810
6770   IF G%(C%(J%))>0 THEN 6800
6780    PRINT"Note: '"T$(C%(J%))"' used in premises taken to be "G$(G1%)
6790    GOTO 6840
6800   IF G1%=G%(C%(J%)) THEN 6840
6810  NEXT J%
6820 PRINT"** Conclusion may not contain "G$(G1%)" '"W$"'.
6830 J%=0
6840 W$=W$(2)
6850 GOSUB 4040
6860 IF J1%=0 THEN 6940
6870  IF W$=W$(1) THEN 6910
6880   PRINT"** Conclusion from no premises must have same subject and predic";
6882    PRINT"ate.
6900   GOTO 7370
6910  IF D1%<>4 OR G2%=0 THEN 7120
6920   PRINT"** Subject is a "G$(2)", predicate is a "G$(1)" -- but
6930   GOTO 6880
6940 IF J%>0 THEN 6970
6950  IF W$=T$(C%(1)) THEN T2%=C%(2) ELSE T2%=C%(1)
6960  GOTO 7070
6970 T1%=C%(J%)
6980 T2%=C%(3-J%)
6990 IF W$<>T$(T2%) THEN 7060
7000  IF G%(T2%)>0 THEN 7040
7010   IF G2%=0 THEN 7090
7020   PRINT"Note: '"T$(T2%)"' used in premises taken to be "G$(G2%)
7030   GOTO 7090
7040  IF G2%=0 THEN 7090
7050  IF G2%=G%(T2%) THEN 7090
7060 PRINT"** Conclusion may not contain "G$(G2%)" '"W$"';
7070 PRINT"** Conclusion must contain "G$(G%(T2%))" '"T$(T2%)"'.
7080 GOTO 7370
7090 IF N1%=0 OR (D1% MOD 2)=1 THEN 7120
7100  PRINT"** Negative conclusion required.
7110  GOTO 7370
7120 IF N1%>0 OR D1% MOD 2 =0 THEN 7150
7130  PRINT"** Affirmative conclusion required.
7140  GOTO 7370
7150 IF J1%=1 THEN 7250
7160 IF D%(T1%)>0 OR D1%<=1 OR D1%=>4 THEN 7200
7170  PRINT"** Term '";T$(T1%);"' not distributed in premises
7180  PRINT"   may not be distributed in conclusion.
7190  GOTO 7370
7200 IF D%(T2%)>0 THEN 7250
7210  IF D1% MOD 2 =0 AND D1%<>6 THEN 7250
7220  PRINT"** Term '";T$(T2%);"' not distributed in premises
7230  GOTO 7180
7250 PRINT"--> VALID!
7260 IF J1%=0 THEN 7300
7270  IF D1%>0 THEN 7370
7280  T$(0)=W$
7290  GOTO 7350
7300 IF D%(T1%)=0 OR D1%=>2 THEN 7330
7310  V1%=T1%
7320  GOTO 7350
7330 IF D%(T2%)>0 AND D1% MOD 2 =0 AND D1%<>4 AND D1%<>6 THEN V1%=T2%
7340 IF V1%=0 THEN 7370
7350 PRINT"    but on Aristotelian interpretation only, i.e. on requirement
7360 PRINT"    that term '"T$(V1%)"' denotes.
7370 RETURN
7460 REM---list---
7530 I%=0
7540 I%=L%(I%)
7550 IF I%=0 THEN 7650
7570 PRINT N%(I%);
7580 IF L1$="list"THEN 7630
7590  IF R%(I%)<6 AND G%(Q%(I%))=2 THEN R%(I%)=R%(I%)+2
7600  IF R%(I%)<4 THEN PRINT X$(R%(I%))"  ";
7610  PRINT T$(P%(I%));Y$(R%(I%));"  ";T$(Q%(I%));Z$(R%(I%))
7620  GOTO 7540
7630 PRINT L$(I%)
7640 GOTO 7540
7650 RETURN
7660 REM---List valid inputs---
7670 PRINT CL$"Valid commands are:
7680 PRINT"  <n> [<statement>]   Insert, delete, or replace premise number <n>
7700 PRINT TAB(28)"Examples:   10  All men are mortal
7704 PRINT TAB(40)"10
7706 PRINT"  DUMP"TAB(20)"Prints symbol table, distribution count, etc.
7707 PRINT"  HELP"TAB(20)"Prints this list
7708 PRINT"  INFO"TAB(20)"Gives information about syllogisms
7710 PRINT"  LIST"TAB(20)"Lists premises
7730 PRINT"  LIST*"TAB(20)"Same, but displays distribution analysis:"
7750 PRINT TAB(25)"distributed positions marked with '*', ";
7760 PRINT TAB(25)"designators marked with '+'
7830 PRINT"  LINK"TAB(20)"Lists premises in order of term-links (if possible)
7850 PRINT"  LINK*"TAB(20)"Same, but in distribution-analysis format
7855 PRINT"  MSG"TAB(20)"Turns on/off printing of certain messages and warnings
7860 PRINT"  NEW"TAB(20)"Erases current syllogism
7865 PRINT"  SAMPLE"TAB(20)"Erases current syllogism and enters sample syllogism
7867 PRINT"  STOP"TAB(20)"Stops entire program
7870 PRINT"  SUBSTITUTE"TAB(20)"Allows uniform substitution of new terms in ";
7880 PRINT"old premises
7900 PRINT"  SYNTAX"TAB(20)"Explains statement syntax, with examples
7943 PRINT"  /"TAB(20)"Asks program to draw conclusion
7946 PRINT"  / <statement>"TAB(20)"Tests <statement> as conclusion
7948 PRINT TAB(25)"Note: this can be done even if there are no premises
7950 RETURN
7960 REM--"syntax"--
7970 PRINT CL$"Valid statement forms:
7980 PRINT"  All   <general term #1>  is/are      <general term #2>
7990 PRINT"  Some  <general term #1>  is/are      <general term #2>
8000 PRINT"  Some  <general term #1>  is/are not  <general term #2>
8010 PRINT"  No    <general term #1>  is/are      <general term #2>
8020 PRINT
8030 PRINT"  <designator>     is/are      <general term>
8040 PRINT"  <designator>     is/are not  <general term>
8050 PRINT"  <designator A>   is/are      <designator B>
8060 PRINT"  <designator A>   is/are not  <designator B>":PRINT
8080 PRINT"Examples:
8090 PRINT"  All tall men are Greek gods"TAB(42)"The teacher of Plato is wise
8110 PRINT"  Some cheese is tasty"TAB(42)"Socrates is not handsome
8130 PRINT"  Some cheese is not soft"TAB(42)"The teacher of Plato is Socrates
8150 PRINT"  No libertarians are cringing wimps"TAB(42)"Socrates is not the";
8160 PRINT" teacher of Thales
8170 PRINT
8180 PRINT"Since e.g. 'Socrates is grunch' is ambiguous ('grunch' could be
8190 PRINT"either a designator or a general term), the program will try to
8200 PRINT"resolve the ambiguity from other uses of the term in the syllogism.
8210 PRINT"The indefinite article 'sm' may be used with mass terms in predicates
8220 PRINT"(e.g. 'This puddle is sm ink') to ensure that the mass term is taken
8230 PRINT"as a general term rather than as a designator.
8240 RETURN
8290 REM---Info---
8293 PRINT CL$"   To use this program, enter a syllogism, one line at a time,
8296 PRINT"and then test conclusions or ask the program to draw a conclusion.
8298 PRINT
8300 PRINT"   A syllogism as (mis)defined here is a (possibly empty) set of
8310 PRINT"numbered premises, each of a form specified in the SYNTAX list.
8320 PRINT"No term may occur more than twice.  Exactly two terms must occur
8330 PRINT"exactly once: these are the two 'end' terms, which will appear in
8340 PRINT"the conclusion.  Furthermore, each premise must have exactly one
8350 PRINT"term in common with its successor, for some ordering of the premises.
8360 PRINT"Example:
8370 PRINT"   10 Socrates is a Greek
8380 PRINT"   20 All men are mortal
8390 PRINT"   30 All Greeks are men
8395 PRINT"   40 No gods are mortal":PRINT
8400 PRINT"Note: using a '/' command to draw or test a conclusion does not
8410 PRINT"require you to stop.  You can continue, adding or deleting premises
8415 PRINT"and drawing and testing more conclusions.":PRINT
8420 PRINT"Reference:  H. Gensler, 'A Simplified Decision Procedure for Categor-
8430 PRINT"   ical Syllogisms,' Notre Dame J. of Formal Logic 14 (1973) 457-466.
8440 RETURN
8890 REM---"Dump" values of variables---
8900 PRINT"Highest symbol table loc. used:"L1%"  Negative premises:"N1%
8910 IF L1%=0 THEN 8970
8920 PRINT"Adr. art. term"TAB(48)"type       occurs    dist. count
8930 FOR I%=1 TO L1%
8940  PRINT I%;TAB(7);A$(B%(I%));TAB(11);T$(I%);TAB(49);G%(I%);TAB(60);
8950  PRINT O%(I%);TAB(71);D%(I%)
8960  NEXT I%
8970 RETURN
8980 REM--sample--
9001 FOR Z8%=1 TO 10:READ L1$:PRINT L1$
9002 GOSUB 2020:GOSUB 2890:GOSUB 4530:GOSUB 3400
9003 NEXT
9004 DATA 10 all mortals are fools
9005 DATA 20 all athenians are men
9006 DATA 30 all philosophers are geniuses
9007 DATA 40 all people with good taste are philosophers
9008 DATA 50 richter is a diamond broker
9009 DATA 60 richter is the most hedonistic person in florida
9010 DATA 70 all men are mortal
9011 DATA 80 no genius is a fool
9012 DATA 90 all diamond brokers are people with good taste
9013 DATA 100 the most hedonistic person in florida is a decision-theorist
9030 RESTORE 9004
9040 IF MSG% THEN PRINT"Suggestion: try the LINK or LINK* command.
9050 RETURN
9060 REM---Substitute terms---
9070 PRINT"Enter address of old term; or 0 for help, -1 to exit, -2 for dump
9080 INPUT I1%
9090 IF I1%=-1 THEN 9470
9100 IF I1%<>-2 THEN 9130
9110  GOSUB 8890
9120  GOTO 9070
9130 IF I1%>0 THEN 9340
9140 PRINT"   This subroutine allows a term in a syllogism to be uniformly
9150 PRINT"replaced by another term.  This is useful e.g. for finding an
9160 PRINT"interpretation which actually makes the premises true, to produce as
9170 PRINT"an obvious example of invalidity an argument having exactly the same
9180 PRINT"logical form.  The substitution does not take place in the premises
9190 PRINT"as originally entered; it takes place in the terms as stored within
9200 PRINT"the program.  Thus, the LINK and LIST commands will display the
9210 PRINT"original premises; to see the changed ones, use the LIST* and LINK*
9215 PRINT"commands.
9220 PRINT"   To find the 'addresses' of the terms, enter -2 to run the DUMP.
9230 PRINT"   Warning: if you replace a term with another one already occurring
9240 PRINT"in the syllogism, the result will not make much sense.  However,
9245 PRINT"this routine does not convert entered term to lower-case or singular.
9250 GOTO 9455
9340 IF I1%<=L1% THEN 9370
9350  PRINT"Address"I1%"too large.  Symbol table only of length"L1%
9360  GOTO 9455
9370 PRINT"Enter new term to replace "G$(G%(I1%))" '"T$(I1%)"'
9380  INPUT W$
9440  T$(I1%)=W$
9450  PRINT"Replaced by '"W$"'
9455 PRINT
9460  GOTO 9070
9470 PRINT"Exit from substitution routine"
9480 RETURN
9999 END
