dawrehxyz icon

PrologLab1

dawrehxyz | PRO | 10/09/16 09:49:50 PM UTC | 0 ⭐ | 7130 👁️ | Never ⏰ | []
Prolog |

2.28 KB

|

None

|

0 👍

/

0 👎

validateGoalWithLastRow([ProofHead|[]], Goal) :-
    [_,Fact,_] = ProofHead,
    Goal = Fact,!.
validateGoalWithLastRow([_|ProofTail], Goal) :-
    validateGoalWithLastRow(ProofTail, Goal),!.
 
main :-
    open('valid05.txt',read,Stream),
    read(Stream,Premises),
    read(Stream,Goal),
    read(Stream,Proof),
    close(Stream),
    validateGoalWithLastRow(Proof,Goal),
    validateProof(Premises,Goal,Proof,[],false),!.
 
validateProof(_,_,[],_,_).
validateProof(Premises,Goal,[[RowNr,Fact,assumption]|ProofTail],VerifiedRows,true) :-
    validateProof(Premises,Goal,ProofTail,[[RowNr,Fact]|VerifiedRows],false).
validateProof(Premises,Goal,[[RowNr,Fact,Rule]|ProofTail],VerifiedRows,false) :-
    examineRow([RowNr,Fact,Rule],Premises,Goal,VerifiedRows),
    validateProof(Premises,Goal,ProofTail,[[RowNr,Fact]|VerifiedRows],false).
validateProof(Premises,Goal,[ProofHead|ProofTail],VerifiedRows,false) :-
    validateProof(Premises,Goal,ProofHead,VerifiedRows,true),
    [[RowNr,Fact,assumption]|NewTail] = ProofHead,
    last(ProofHead,[RowNr2,Fact2,_]),
    NewVerifiedRows = [[RowNr, RowNr2, Fact, Fact2] | VerifiedRows],
    validateProof(Premises,Goal,ProofTail,NewVerifiedRows,false).
 
% [RowNr,Fact,premise] check if the fact is amongst our Premises.
examineRow([_,Fact,premise],Premises,_,_) :-
    member(Fact,Premises),!.
 
% [RowNr,Fact,impel(X,Y)] check if the elimination of implication is performed correctly
% accordingly to " p, p->q", remember that p needs to be stated first as X and p->q second as Y.
examineRow([_,Fact,impel(X,Y)],_,_,VerifiedRows) :-
    member([X,Q], VerifiedRows),!,
    member([Y,imp(Q,Fact)],VerifiedRows),!.
 
%Copy(X).
examineRow([_,Fact,copy(X)],_,_,VerifiedRows) :-
    member([X,Fact], VerifiedRows).
 
%Implication Introduction
examineRow([_, imp(P,Q), impint(X,Y)],_,_,VerifiedRows) :-
    member([X,Y,P,Q],VerifiedRows).
 
%Contradiction check, check if Q is at row X and then check if neg(Q) is at row Y.
examineRow([_, cont, negel(X,Y)],_,_,VerifiedRows) :-
    member([X,Q], VerifiedRows),
    member([Y,neg(Q)], VerifiedRows).
 
examineRow([_, Whatever, orel(A,B,C,D,E)],_,_,VerifiedRows) :-
    member([A, or(Q,R)], VerifiedRows),
    member([B,C,Q,Whatever], VerifiedRows),
    member([D,E,R,Whatever], VerifiedRows).
 
examineRow([_, Q, pbc(X,Y)],_,_,VerifiedRows) :-
    member([X,Y,neg(Q),cont], VerifiedRows).

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎