-
Notifications
You must be signed in to change notification settings - Fork 3
/
leancop21_sic.pl
90 lines (76 loc) · 3.31 KB
/
leancop21_sic.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
%% File: leancop21_sic.pl - Version: 2.1 - Date: 30 Aug 2008
%%
%% "Make everything as simple as possible, but not simpler."
%% [Albert Einstein]
%%
%% Purpose: leanCoP: A Lean Connection Prover for Classical Logic
%%
%% Author: Jens Otten
%% Web: www.leancop.de
%%
%% Usage: prove(M,P). % where M is a set of clauses and P is
%% % the returned connection proof
%% % e.g. M=[[q(a)],[-p],[p,-q(X)]]
%% % and P=[[q(a)],[[-(q(a)),p],[[-(p)]]]]
%% prove(F,P). % where F is a first-order formula and
%% % P is the returned connection proof
%% % e.g. F=((p,all X:(p=>q(X)))=>all Y:q(Y))
%% % and P=[[q(a)],[[-(q(a)),p],[[-(p)]]]]
%% prove2(F,S,P). % where F is a formula, S is a subset of
%% % [nodef,def,conj,reo(I),scut,cut,comp(J)]
%% % (with numbers I,J) defining attributes
%% % and P is the returned connection proof
%%
%% Copyright: (c) 1999-2008 by Jens Otten
%% License: GNU General Public License
:- use_module(library(lists)). % load module for lists
:- use_module(library(terms)). % load module for terms
:- [def_mm]. % load program for clausal form translation
:- dynamic(pathlim/0). :- dynamic(lit/4).
%%% prove matrix M / formula F
prove(F,Proof) :- prove2(F,[cut,comp(7)],Proof).
prove2(F,Set,Proof) :-
(F=[_|_] -> M=F ; make_matrix(F,M,Set)),
retractall(lit(_,_,_,_)), (member([-(#)],M) -> S=conj ; S=pos),
assert_clauses(M,S), prove(1,Set,Proof).
prove(PathLim,Set,Proof) :-
\+member(scut,Set) -> prove([-(#)],[],PathLim,[],Set,[Proof]) ;
lit(#,_,C,_) -> prove(C,[-(#)],PathLim,[],Set,Proof1),
Proof=[C|Proof1].
prove(PathLim,Set,Proof) :-
member(comp(Limit),Set), PathLim=Limit -> prove(1,[],Proof) ;
(member(comp(_),Set);retract(pathlim)) ->
PathLim1 is PathLim+1, prove(PathLim1,Set,Proof).
%%% leanCoP core prover
prove([],_,_,_,_,[]).
prove([Lit|Cla],Path,PathLim,Lem,Set,Proof) :-
Proof=[[[NegLit|Cla1]|Proof1]|Proof2],
\+ (member(LitC,[Lit|Cla]), member(LitP,Path), LitC==LitP),
(-NegLit=Lit;-Lit=NegLit) ->
( member(LitL,Lem), Lit==LitL, Cla1=[], Proof1=[]
;
member(NegL,Path), unify_with_occurs_check(NegL,NegLit),
Cla1=[], Proof1=[]
;
lit(NegLit,NegL,Cla1,Grnd1),
unify_with_occurs_check(NegL,NegLit),
( Grnd1=g -> true ; length(Path,K), K<PathLim -> true ;
\+ pathlim -> assert(pathlim), fail ),
prove(Cla1,[Lit|Path],PathLim,Lem,Set,Proof1)
),
( member(cut,Set) -> ! ; true ),
prove(Cla,Path,PathLim,[Lit|Lem],Set,Proof2).
%%% write clauses into Prolog's database
assert_clauses([],_).
assert_clauses([C|M],Set) :-
(Set\=conj, \+member(-_,C) -> C1=[#|C] ; C1=C),
(ground(C) -> G=g ; G=n), assert_clauses2(C1,[],G),
assert_clauses(M,Set).
assert_clauses2([],_,_).
assert_clauses2([L|C],C1,G) :-
assert_renvar([L],[L2]), append(C1,C,C2), append(C1,[L],C3),
assert(lit(L2,L,C2,G)), assert_clauses2(C,C3,G).
assert_renvar([],[]).
assert_renvar([F|FunL],[F1|FunL1]) :-
( var(F) -> true ; F=..[Fu|Arg], assert_renvar(Arg,Arg1),
F1=..[Fu|Arg1] ), assert_renvar(FunL,FunL1).