-
Notifications
You must be signed in to change notification settings - Fork 0
/
eye3.pl
151 lines (139 loc) · 3.5 KB
/
eye3.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
% ------------------
% eye3 -- Jos De Roo
% ------------------
%
% See https://github.com/eyereasoner/eye3
%
:- use_module(library(iso_ext)).
:- use_module(library(terms)).
:- op(1150,xfx,=>).
:- op(1200,xfx,<=).
:- dynamic((=>)/2).
:- dynamic(answer/1).
:- dynamic(brake/0).
:- dynamic(proof/3).
:- dynamic(var_nr/1).
term_expansion((Head <= Body),(Head :- Body)).
version_info('eye3 v1.2.2 (2024-11-26)').
% main goal
main :-
bb_put(closure,0),
bb_put(limit,-1),
( (_ => _)
-> write(':- op(1150,xfx,=>).'),
nl,
nl
; version_info(Version),
write(Version),
nl
),
run,
halt(0).
% run eye3 abstract machine
%
% 1/ select rule P => C
% 2/ prove P and if it fails backtrack to 1/
% 3/ if C = true assert answer(P)
% else if C = false stop with return code 2
% else if ~C assert C, retract brake
% 4/ backtrack to 2/ and if it fails go to 5/
% 5/ if brake
% if not stable start again at 1/
% else write all answers as P => true and stop
% else assert brake and start again at 1/
%
run :-
( (Prem => Conc), % 1/
copy_term((Prem => Conc),Rule),
labelvars(Rule,all),
Prem, % 2/
( Conc = true % 3/
-> labelvars(Prem,all),
( \+answer(Prem)
-> assertz(answer(Prem))
; true
)
; ( Conc = false
-> write('% inference fuse, return code 2'),
nl,
writeq(Prem),
write(' => false.'),
nl,
halt(2)
; \+Conc,
labelvars(Conc,some),
astep(Conc),
assertz(proof(Rule,Prem,Conc)),
retract(brake)
)
),
fail % 4/
; ( brake % 5/
-> ( bb_get(closure,Closure),
bb_get(limit,Limit),
Closure < Limit,
NewClosure is Closure+1,
bb_put(closure,NewClosure),
run
; answer(Prem),
writeq(Prem),
write(' => true.'),
nl,
fail
; ( proof(_,_,_)
-> nl,
write('% Explain the reasoning'),
nl,
proof(Rule,Prem,Conc),
writeq('http://www.w3.org/2000/10/swap/log#proves'((Rule,Prem),Conc)),
write('.'),
nl,
fail
; true
)
; true
)
; assertz(brake),
run
)
).
% create witnesses
labelvars(Term,Mode) :-
( retract(var_nr(Current))
-> true
; Current = 0
),
labelvars(Term,Current,Next,Mode),
assertz(var_nr(Next)).
labelvars(Term,N0,N,Mode) :-
term_variables(Term,Vars),
labellist(Vars,N0,N,Mode).
labellist([],N,N,_).
labellist([A|Vars],N0,N,Mode) :-
( Mode = all
-> A = '$VAR'(N0)
; number_codes(N0,J),
atom_codes(I,J),
atom_concat('_:sk_',I,A)
),
N1 is N0+1,
labellist(Vars,N1,N,Mode).
% assert new step
astep((B,C)) :-
astep(B),
astep(C).
astep(A) :-
( \+A
-> assertz(A)
; true
).
% stable(+Level)
% fail if the deductive closure at Level is not yet stable
stable(Level) :-
bb_get(limit,Limit),
( Limit < Level
-> bb_put(limit,Level)
; true
),
bb_get(closure,Closure),
Level =< Closure.