dawrehxyz

PrologLab1

Oct 9th, 2016
6,221
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 2.28 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('valid05.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. examineRow([_,Fact,impel(X,Y)],_,_,VerifiedRows) :-
  36.     member([X,Q], VerifiedRows),!,
  37.     member([Y,imp(Q,Fact)],VerifiedRows),!.
  38.  
  39. %Copy(X).
  40. examineRow([_,Fact,copy(X)],_,_,VerifiedRows) :-
  41.     member([X,Fact], VerifiedRows).
  42.  
  43. %Implication Introduction
  44. examineRow([_, imp(P,Q), impint(X,Y)],_,_,VerifiedRows) :-
  45.     member([X,Y,P,Q],VerifiedRows).
  46.  
  47. %Contradiction check, check if Q is at row X and then check if neg(Q) is at row Y.
  48. examineRow([_, cont, negel(X,Y)],_,_,VerifiedRows) :-
  49.     member([X,Q], VerifiedRows),
  50.     member([Y,neg(Q)], VerifiedRows).
  51.  
  52. examineRow([_, Whatever, orel(A,B,C,D,E)],_,_,VerifiedRows) :-
  53.     member([A, or(Q,R)], VerifiedRows),
  54.     member([B,C,Q,Whatever], VerifiedRows),
  55.     member([D,E,R,Whatever], VerifiedRows).
  56.  
  57. examineRow([_, Q, pbc(X,Y)],_,_,VerifiedRows) :-
  58.     member([X,Y,neg(Q),cont], VerifiedRows).
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment