dawrehxyz

mafioso

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