forked from wo/tpg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_prover.js
218 lines (197 loc) · 8.25 KB
/
test_prover.js
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
tests = {
// Recall that Prover takes the /negated/ sentence that is to be proved
// as input; i.e. Prover is really a Refuter.
noRuleApplication: function() {
var parser = new Parser();
var f = parser.parseFormula('p');
var prover = new Prover([f, f.negate()], parser);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.closedBranches.length, 1);
},
addDuplicateInitNodes: function() {
var input = '(a∨b),(¬a∨¬n1),(¬b∨¬n2),¬(a∧n2),¬(b∧n2),a↔¬n2|=a';
var parser = new Parser();
var parsedInput = parser.parseInput(input);
var premises = parsedInput[0];
var conclusion = parsedInput[1];
var initFormulas = premises.concat([conclusion.negate()]);
var prover = new Prover(initFormulas, parser);
prover.pauseLength = 0;
prover.start();
var sentree = new SenTree(prover.tree, parser);
assertEqual(sentree.nodes.length, 16);
},
pruneBranch: function() {
var parser = new Parser();
var f = parser.parseFormula('(¬R∧¬S∧((R∧¬S)∨(¬R∧S))∧(Q∨P))').nnf();
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.closedBranches.length, 2);
},
carefulWithDuplicateBranchesWhenPruningAlternatives: function() {
var input = '(¬∃x(Rx∧¬Fx)→∃x(Rx∧¬Fx))→∃x(Rx∧¬Fx)';
var parser = new Parser();
var f = parser.parseFormula(input).negate();
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.closedBranches.length, 4);
},
refutepandnotp: function() {
var parser = new Parser();
var f = parser.parseFormula('p∧¬p');
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assert(prover.tree.openBranches.length == 0);
},
prooftest2: function() {
var parser = new Parser();
var f = parser.parseFormula('∀x(Fx→Fx)').negate();
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assert(prover.tree.openBranches.length == 0);
},
prooftest4: function() {
var parser = new Parser();
var f = parser.parseFormula('¬∃y∀x(Fy→Fx)');
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 0);
},
dontMarkUsedNodesUnused: function() {
// see commit fd1eaff: When the tree for the below input is found to
// close, some closed branches are removed by pruneBranch. One of these
// branches was originally closed by expanding an earlier beta node.
// Before this fix, that beta node was marked unused (and therefore
// removed from the sentence tree) even though it is also used to close
// another branch that is not removed. Now I check that a node is
// really not used anywhere else before marking it as unused in
// pruneBranch.
var input = 'Ac, ∀x(Ax→Tx), ∀x(Mx→¬Tx), Mb, ∀xIxx, ∀x∀y(Ixy→Iyx), ∀x∀y(Ixy→(Ax→Ay)), ∀x∀y(Ixy→(Mx→My)), ∀x∀y(Ixy→(Tx→Ty)) |= ¬Ibc';
var parser = new Parser();
var parsedInput = parser.parseInput(input);
var premises = parsedInput[0];
var conclusion = parsedInput[1];
var initFormulas = premises.concat([conclusion.negate()]);
var prover = new Prover(initFormulas, parser);
prover.pauseLength = 0;
prover.start();
var nodes = prover.tree.closedBranches[0].nodes;
for (var i=0; i<nodes.length; i++) {
if (nodes[i].formula.string == '(¬Ac ∨ Tc)') {
assert(nodes[i].used != '');
return;
}
}
assert(false)
},
equality1: function() {
// checks that termsNode properties in equality problems are
// adjusted when trees are copied for backtracking
var parser = new Parser();
var f = parser.parseFormula('∀x(g(x)=f(x) ∨ ¬(x=a)) ∧ ∀x(g(f(x))=x) ∧ b=c ∧ Pg(g(a))b → Pac').negate();
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 0);
var numUsed = 0;
var nodes = prover.tree.closedBranches[0].nodes;
for (var i=0; i<nodes.length; i++) {
if (nodes[i].used) numUsed++;
}
assert(numUsed > 10);
},
modalT: function() {
var parser = new Parser();
var f = parser.parseFormula('□p→p').negate();
['universality', 'reflexivity'].forEach(function(c) {
var prover = new Prover([f], parser, [c]);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 0);
var numNodes = c == 'universality' ? 4 : 5;
assertEqual(prover.tree.closedBranches[0].nodes.length, numNodes);
});
var prover = new Prover([f], parser, ['seriality']);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 1);
},
modalEuclidean: function() {
var parser = new Parser();
var f = parser.parseFormula('□p→□□p').negate();
var prover = new Prover([f], parser, ['reflexivity', 'euclidity']);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 0);
},
modalG1: function() {
var parser = new Parser();
var f = parser.parseFormula('◇□p→□◇p').negate();
['universality', 'euclidity'].forEach(function(c) {
var prover = new Prover([f], parser, [c]);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 0);
var numNodes = c == 'universality' ? 7 : 11;
assertEqual(prover.tree.closedBranches[0].nodes.length, numNodes);
});
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 1);
},
// emil: function() {
// var parser = new Parser();
// var f = parser.parseFormula('◇□A→(◇□B→◇□(A∧B))').negate();
// var prover = new Prover([f], parser, ['reflexivity', 'symmetry', 'transitivity']);
// prover.pauseLength = 0;
// prover.start();
// assertEqual(prover.tree.openBranches.length, 0);
// },
transitivityTwice: function() {
var parser = new Parser();
var f = parser.parseFormula('◇□(P∨Q)→□(¬P→◇Q)').negate();
var prover = new Prover([f], parser, ['symmetry', 'transitivity']);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 0);
},
noSerialityLoop: function() {
var parser = new Parser();
var f = parser.parseFormula('◇(p∧□q)→◇(p∧◇q)').negate();
var prover = new Prover([f], parser, ['seriality']);
prover.pauseLength = 0;
prover.start();
assertEqual(prover.tree.openBranches.length, 0);
},
invalidtest1: function() {
var parser = new Parser();
var f = parser.parseFormula('∀x¬Ff(ab)').negate(); // old prover says invalid and stops at the double negation!
var prover = new Prover([f], parser);
prover.pauseLength = 0;
prover.start();
assert(prover.tree.openBranches.length > 0);
},
s5_Fails_should_be_able_to_detect_infinite_tree: function() {
var parser = new Parser();
var f = parser.parseFormula('◇p').negate();
var prover = new Prover([f], parser, ['universality']);
prover.pauseLength = 0;
prover.modelfinder.nextStep = function() { return false; };
prover.onfinished = function(res) {
assertEqual(res, 0);
return true;
}
for (var i=0; i<100; i++) {
prover.stopTimeout = true;
if (prover.nextStep()) break;
}
assert(i<100);
},
}