-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTL.pl
106 lines (90 loc) · 2.08 KB
/
CTL.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
% Computation Tree Logic Tester
% Bastian Fredriksson (Christmas -13)
% Unit test
test:-
directory_files('./tests', DirectoryFiles),
subtract(DirectoryFiles, [.,..], Files),
run_tests(Files).
run_tests([]).
run_tests([File|Files]):-
% Valid samples should begin with lowercase 'v'.
sub_atom(File, 0, 1, _, v),
string_to_atom('./tests/', Dir),
atom_concat(Dir, File, Path),
write('Valid formula: '), write(File), nl,
verify(Path),
run_tests(Files).
run_tests([File|Files]):-
% Invalid samples should begin with lowercase 'i'.
sub_atom(File, 0, 1, _, i),
string_to_atom('./tests/', Dir),
atom_concat(Dir, File, Path),
write('Invalid formula: '), write(File), nl,
\+verify(Path),
run_tests(Files).
% Load model, initial state and formula from file.
% T = Transitions
% L = Labeling
% S = State
% F = CTL Formula
verify(Input):-
see(Input),
read(T),
read(L),
read(S),
read(F),
seen,
check(T, L, S, [], F).
% AX
check(T, L, S, U, ax(F)):-
member([S, States], T),
check_all(T, L, States, U, F).
% EX
check(T, L, S, U, ex(F)):-
member([S, States], T),
member(Candidate, States),
check(T, L, Candidate, U, F).
% AG
check(T, L, S, U, ag(F)):-
member(S, U); % Path checked
check(T, L, S, [], F),
check(T, L, S, [S|U], ax(ag(F))).
% EG
check(T, L, S, U, eg(F)):-
member(S, U);
check(T, L, S, [], F),
check(T, L, S, [S|U], ex(eg(F))),
!.
% AF
check(T, L, S, U, af(F)):-
\+member(S, U),
check(T, L, S, [], F);
\+member(S, U),
check(T, L, S, [S|U], ax(af(F))).
% EF
check(T, L, S, U, ef(F)):-
\+member(S, U),
check(T, L, S, [], F);
\+member(S, U),
check(T, L, S, [S|U], ex(ef(F))).
% AND
check(T, L, S, [], and(F,G)):-
check(T, L, S, [], F),
check(T, L, S, [], G).
% OR
check(T, L, S, [], or(F, G)):-
check(T, L, S, [], F);
check(T, L, S, [], G).
% M, S |- ¬F
check(_, L, S, [], neg(F)):-
member([S, Atoms], L),
\+member(F, Atoms).
% M, S |- F
check(_, L, S, [], F):-
member([S, Atoms], L),
member(F, Atoms).
check_all(_, _, [], _, _). % All states checked.
check_all(T, L, [State|States], U, F):-
check(T, L, State, U, F),
!,
check_all(T, L, States, U, F).