Advertisement
dawrehxyz

LogicLab1DONE

Oct 10th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 3.57 KB | None | 0 0
  1. validateGoalWithLastRow([ProofHead|[]], Goal) :-
  2.     [_,Fact,_] = ProofHead,
  3.     Goal = Fact,!.
  4. validateGoalWithLastRow([_|ProofTail], Goal) :-
  5.     validateGoalWithLastRow(ProofTail, Goal),!.
  6.  
  7. main :-
  8.     open('invalid28.txt',read,Stream),
  9.     read(Stream,Premises),
  10.     read(Stream,Goal),
  11.     read(Stream,Proof),
  12.     close(Stream),
  13.     validateGoalWithLastRow(Proof,Goal),
  14.     validateProof(Premises,Goal,Proof,[],false),!.
  15.  
  16. validateProof(_,_,[],_,_).
  17. validateProof(Premises,Goal,[[RowNr,Fact,assumption]|ProofTail],VerifiedRows,true) :-
  18.     validateProof(Premises,Goal,ProofTail,[[RowNr,Fact]|VerifiedRows],false).
  19. validateProof(Premises,Goal,[[RowNr,Fact,Rule]|ProofTail],VerifiedRows,false) :-
  20.     examineRow([RowNr,Fact,Rule],Premises,Goal,VerifiedRows),
  21.     validateProof(Premises,Goal,ProofTail,[[RowNr,Fact]|VerifiedRows],false).
  22. validateProof(Premises,Goal,[ProofHead|ProofTail],VerifiedRows,false) :-
  23.     validateProof(Premises,Goal,ProofHead,VerifiedRows,true),
  24.     [[RowNr,Fact,assumption]|NewTail] = ProofHead,
  25.     last(ProofHead,[RowNr2,Fact2,_]),
  26.     NewVerifiedRows = [[RowNr, RowNr2, Fact, Fact2] | VerifiedRows],
  27.     validateProof(Premises,Goal,ProofTail,NewVerifiedRows,false).
  28.  
  29. % [RowNr,Fact,premise] check if the fact is amongst our Premises.
  30. examineRow([_,Fact,premise],Premises,_,_) :-
  31.     member(Fact,Premises),!.
  32.  
  33. % [RowNr,Fact,impel(X,Y)] check if the elimination of implication is performed correctly
  34. % accordingly to " p, p->q", remember that p needs to be stated first as X and p->q second as Y.
  35. % Implication Elimination
  36. examineRow([_,Fact,impel(X,Y)],_,_,VerifiedRows) :-
  37.     member([X,Q], VerifiedRows),!,
  38.     member([Y,imp(Q,Fact)],VerifiedRows),!.
  39.  
  40. %Copy(X).
  41. examineRow([_,Fact,copy(X)],_,_,VerifiedRows) :-
  42.     member([X,Fact], VerifiedRows).
  43.  
  44. %Implication Introduction
  45. examineRow([_, imp(P,Q), impint(X,Y)],_,_,VerifiedRows) :-
  46.     member([X,Y,P,Q],VerifiedRows).
  47.  
  48. %Contradiction check, check if Q is at row X and then check if neg(Q) is at row Y.
  49. %Negation Elimination
  50. examineRow([_, cont, negel(X,Y)],_,_,VerifiedRows) :-
  51.     member([X,Q], VerifiedRows),
  52.     member([Y,neg(Q)], VerifiedRows).
  53.  
  54. %OREL Or Elimination
  55. examineRow([_, Whatever, orel(A,B,C,D,E)],_,_,VerifiedRows) :-
  56.     member([A, or(Q,R)], VerifiedRows),
  57.     member([B,C,Q,Whatever], VerifiedRows),
  58.     member([D,E,R,Whatever], VerifiedRows).
  59.  
  60. %PBC
  61. examineRow([_, Q, pbc(X,Y)],_,_,VerifiedRows) :-
  62.     member([X,Y,neg(Q),cont], VerifiedRows).
  63.  
  64.  
  65. /*fffffffffffffffffffffffffffffffffffffffffffff*/
  66.  
  67. %And Introduction
  68. examineRow([_, and(P,Q), andint(X,Y)],_,_,VerifiedRows) :-
  69.     member([X, P], VerifiedRows),
  70.     member([Y, Q], VerifiedRows).
  71.  
  72. %And elimination 1
  73. examineRow([_, P, andel1(X)],_,_,VerifiedRows) :-
  74.     member([X, and(P,_)], VerifiedRows).
  75.  
  76. %And Elimination 2
  77. examineRow([_, Q, andel2(X)],_,_,VerifiedRows) :-
  78.     member([X, and(_,Q)], VerifiedRows).
  79.  
  80. %Or Introduction 1
  81. examineRow([_, or(P,_), orint1(X)],_,_,VerifiedRows) :-
  82.     member([X, P], VerifiedRows).
  83.  
  84. %Or introduction 2
  85. examineRow([_, or(_,Q), orint2(X)],_,_,VerifiedRows) :-
  86.     member([X, Q], VerifiedRows).
  87.  
  88. %LEM
  89. examineRow([_, or(Q,neg(Q)), lem],_,_,_).
  90.  
  91. %MT
  92. examineRow([_, neg(Q), mt(X,Y)],_,_,VerifiedRows) :-
  93.     member([X, imp(Q,P)], VerifiedRows),
  94.     member([Y, neg(P)], VerifiedRows).
  95.  
  96. %negation introduction
  97. examineRow([_, neg(P), negint(X,Y)],_,_,VerifiedRows) :-
  98.     member([X,Y,P,cont], VerifiedRows).
  99.  
  100. examineRow([_, _, contel(X)],_,_,VerifiedRows) :-
  101.     member([X, cont], VerifiedRows).
  102.  
  103. examineRow([_, neg(neg(P)), negnegint(X)],_,_,VerifiedRows) :-
  104.     member([X, P], VerifiedRows).
  105.  
  106. examineRow([_, P, negnegel(X)],_,_,VerifiedRows) :-
  107.     member([X, neg(neg(P))], VerifiedRows).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement