好吧我正在编写一个程序来读取包含逻辑序列的一堆文本文件,例如:
[and(p,q), and(r,s)].
and(p,s).
[
[1, and(p,q), premise],
[2, and(r,s), premise],
[3, p, andel1(1)],
[4, s, andel2(2)],
[5, and(p,s), andint(3,4)]
].
然后检查证明是否有效。到目前为止一切顺利,我已经编写了所有可以考虑的谓词,这些谓词不包含假设的规则,并且它有效。这是迄今为止的代码:
verify(InputFileName) :- see(InputFileName),
read(Prems), read(Goal), read(Proof),
seen,
valid_proof(Prems, Goal, Proof).
valid_proof(_Prems, _Goal, Proof) :-
valid_proof_(Proof, Proof).
valid_proof_(_, []).
valid_proof_(Proof, [Line|Lines]) :-
valid_line(Proof, Line),
valid_proof_(Proof, Lines).
valid_line(_Proof, [_N, _S, premise]).
valid_line(Proof, [_Ln3, U, impel(Ln2, Ln1)]) :-
member([Ln1, imp(O, U), _], Proof),
member([Ln2, O, _], Proof).
valid_line(Proof, [_, and(A,B), andint(Ln,Lm)]) :-
member([Ln, A, _], Proof),
member([Lm, B, _], Proof).
valid_line(Proof, [_, A, andel1(N)]) :-
member([N, and(A,_B), _], Proof).
valid_line(Proof, [_, B, andel2(N)]) :-
member([N, and(_A,B), _], Proof).
valid_line(Proof, [_, or(A,_B), orint1(N)]) :-
member([N, A, _], Proof).
valid_line(Proof, [_, or(_A,B), orint2(N)]) :-
member([N, B, _], Proof).
valid_line(Proof, [_, A, copy(N)]) :-
member([N, A, _], Proof).
valid_line(Proof, [_, neg(O), mt(N1, N2)]) :-
member([N1, imp(O,U), _], Proof),
member([N2, neg(U), _], Proof).
valid_line(Proof, [_, O, negnegel(N)]) :-
member([N, neg(neg(O)), _], Proof).
valid_line(Proof, [_, neg(neg(O)), negnegint(N)]) :-
member([N, O, _], Proof).
valid_line(Proof, [_, or(O, neg(O)), lem]) :-
member([_, _, _], Proof).
问题是我现在必须解决问题,使用假设对证据做同样的事情,例如:
[q].
imp(p,q).
[
[1, q, premise],
[
[2, p, assumption],
[3, q, copy(1)]
],
[4, imp(p,q), impint(2,3)]
].
我无法使用与其他模式相同的模式来实现,因为现在它是列表中的列表。所以像这样:
valid_line(Proof, [_, imp(O, U), impint(N1, N2)]) :-
member([N1, O, assumption], Proof),
member([N2, U, _], Proof),
N1 < N2.
不行。所以我有点卡住,我不知道如何继续。