[r1813]: trunk / Toss / Solver / SolverTest.ml  Maximize  Restore  History

Download this file

458 lines (422 with data), 19.8 kB

  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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
open Solver.M
open OUnit
let formula_of_string s =
FormulaParser.parse_formula Lexer.lex (Lexing.from_string s)
let real_expr_of_string s =
FormulaParser.parse_real_expr Lexer.lex (Lexing.from_string s)
let struc_of_string s =
StructureParser.parse_structure Lexer.lex (Lexing.from_string s)
let eval_eq struc_s phi_s aset_s =
let res = ref "" in
let (struc, phi) = (struc_of_string struc_s, formula_of_string phi_s) in
res := Assignments.str (evaluate struc phi);
assert_equal ~printer:(fun x -> x) aset_s !res
let eval_real_eq var_s struc_s expr_s aset_s =
let (struc, expr) = (struc_of_string struc_s, real_expr_of_string expr_s) in
assert_equal ~printer:(fun x -> x)
aset_s (Assignments.str (evaluate_real var_s expr struc))
let real_val_eq struc_s expr_s x =
let (struc, expr) = (struc_of_string struc_s, real_expr_of_string expr_s) in
assert_equal ~printer:(fun x -> string_of_float x)
x (get_real_val expr struc)
let rel_str rel struc_str =
let s = struc_of_string struc_str in
Structure.rel_str s rel (Structure.rel_graph rel s)
let tests = "Solver" >::: [
"eval: first-order quantifier free" >::
(fun () ->
eval_eq "[ | P { (a1) }; R:1 {} | ]" "P(x0)" "{ x0->1 }";
eval_eq "[ | P:1 {}; R { (a1) } | ]" "P(x0)" "{}";
eval_eq "[ | R { (a, b); (a, c) } | ]" "x = y"
"{ y->1{ x->1 } , y->2{ x->2 } , y->3{ x->3 } }";
eval_eq "[ | R { (a, b); (b, c) }; P { b } | ]" "P(x) and x = y"
"{ y->2{ x->2 } }";
eval_eq "[ | R { (a, b); (a, c) } | ]" "R(x, y) and x = y"
"{}";
eval_eq "[ | R { (a, a); (a, b) } | ]" "R(x, y) and x = y"
"{ y->1{ x->1 } }";
eval_eq "[ | R { (a, b); (a, c) } | ]" "not x = y"
"{ y->1{ x->2, x->3 } , y->2{ x->1, x->3 } , y->3{ x->1, x->2 } }";
eval_eq "[ | R { (a, a); (a, c) } | ]" "R (x, y) and not x = y"
"{ y->2{ x->1 } }";
eval_eq "[ e1 | R:1 {e2} ; .c = e1 | ]" "x = .c" "{ .c->1{ x->1 } }";
eval_eq "[ e1, e2 | .c = e1 ; .d = e2 | ]" ".c = .d" "{}";
);
"eval: first-order with quantifiers" >::
(fun () ->
eval_eq "[ | R { (a, b); (a, c) } | ]" "ex x R (x, y)"
"{ y->2, y->3 }";
eval_eq "[ | R { (a, b); (b, c) }; P { b } | ]"
"ex x ( P(x) and not (ex y R(x, y)) )"
"{}";
);
(*
"eval: mso quantifier free basic" >::
(fun () ->
eval_eq "[ | P { a } | ]" "|X(x)"
"{ x->1{ X->(inc {1} excl {}) } }";
eval_eq "[ | P { a } | ]" "not (|X(x))"
"{ x->1{ X->(inc {} excl {1}) } }";
eval_eq "[ | P { a } | ]" "|X(x) and |Y(x)"
"{ x->1{ Y->(inc {1} excl {}){ X->(inc {1} excl {}) } } }";
eval_eq "[ | P { a } | ]" "|X(x) and not (|Y(x))"
"{ x->1{ Y->(inc {} excl {1}){ X->(inc {1} excl {}) } } }";
eval_eq "[ | P { a } | ]" "|X(x) and x = y and not (|X(x))"
"{}";
eval_eq "[ | P { a } | ]" "|X(x) and |Y(x) and (x = y and not (|Y(x)))"
"{}";
eval_eq "[ | P { a } | ]" "|X(x) and (|X(x) or |Y(x))"
"{ x->1{ X->(inc {1} excl {}) } }";
);
"eval: mso quantifier free" >::
(fun () ->
eval_eq "[ | P { a } | ]" "(|X2(t)) and ((|X(t)) or ((|C(t))))"
("{ t->1{ X2->(inc {1} excl {}){ X->(inc {} excl {}){ C->(inc {1}" ^
" excl {}) }, X->(inc {1} excl {}) } } }");
eval_eq "[ | P { a } | ]"
"(|X2(t)) and ((|X(t)) or ((|C(t)) or (|X(t))))"
("{ t->1{ X2->(inc {1} excl {}){ X->(inc {} excl {}){ C->(inc {1}" ^
" excl {}) }, X->(inc {1} excl {}) } } }");
eval_eq "[ | P { a } | ]"
"(((|X2(t)) and ((|X(t)) or (((|C(t)) or (|X(t))) and ((not |C(t))
or (not (|X(t)))))) and ((not (|X(t))) or ((|C(t)) and (|X(t))) or
((not (|C(t))) and (not (|X(t)))))))"
"{ t->1{ X2->(inc {1} excl {}){ C->(inc {1} excl {}) } } }";
);
"eval: mso with only first-order quantifiers" >::
(fun () ->
eval_eq "[ | P { a } | ]"
"(not |X2(t)) or ((|X2(t)) and (|X3(t))) and
all s (|X3(s) or not P(s))"
("{ t->1{ X3->(inc {} excl {}){ X2->(inc {} excl {1}) }," ^
" X3->(inc {1} excl {}) } }");
);
"eval: mso with quantifiers" >::
(fun () ->
eval_eq "[ | R { (a, b); (a, c) } | ]" "tc in x, y R(x, y)"
"{ y->1{ x->1 } , y->2{ x->1, x->2 } , y->3{ x->1, x->3 } }";
eval_eq "[ | R { (a, b); (b, c) } | ]" "tc in x, y R(x, y)"
"{ y->1{ x->1 } , y->2{ x->1, x->2 } , y->3 }";
eval_eq "[ | R { (a,b); (b,c); (c,d); (d,e); (e,f); (f,g); (g,h) } | ]"
"x != y and not R(x, y) and tc in x, y R(x, y)"
("{ y->3{ x->1 } , y->4{ x->1, x->2 } , y->5{ x->1, x->2, x->3 } ," ^
" y->6{ x->1, x->2, x->3, x->4 } , y->7{ x->1, x->2, x->3, x->4," ^
" x->5 } , y->8{ x->1, x->2, x->3, x->4, x->5, x->6 } }");
eval_eq "[ | R { (a,b); (b,c); (c,d); (d,e); (e,f); (f,g); (g,h) } | ]"
"x != y and not R(x, y) and tc 4 x, y R(x, y)"
("{ y->3{ x->1 } , y->4{ x->1, x->2 } , y->5{ x->1, x->2, x->3 } ," ^
" y->6{ x->2, x->3, x->4 } , y->7{ x->3, x->4," ^
" x->5 } , y->8{ x->4, x->5, x->6 } }");
eval_eq "[ | R { (a,b); (b,c); (c,d); (d,e); (e,f); (f,g); (g,h) } | ]"
"x != y and not R(x, y) and tc 7 x, y R(x, y)"
("{ y->3{ x->1 } , y->4{ x->1, x->2 } , y->5{ x->1, x->2, x->3 } ," ^
" y->6{ x->1, x->2, x->3, x->4 } , y->7{ x->1, x->2, x->3, x->4," ^
" x->5 } , y->8{ x->1, x->2, x->3, x->4, x->5, x->6 } }");
);
*)
"eval: fixed-points" >::
(fun () ->
eval_eq "[a, b | P (a) | ]" "lfp |T(x) = P(x)" "{ x->1 }";
eval_eq "[ | P:1 {} | ]" "lfp |T(x) = P(x)" "{}";
eval_eq "[ | R { (a, b); (b, c) } | ]"
"lfp |T(x) = (x = y or ex z (|T(z) and R (x, z)))"
"{ y->1{ x->1 } , y->2{ x->1, x->2 } , y->3 }";
eval_eq "[ | R { (a, b); (b, a); (b, c) } | ]"
"gfp |T(x) = (x != y and |T(x) and all z (R (x, z) -> |T(z)))"
"{ y->1{ x->3 } , y->2{ x->3 } }";
eval_eq "[ | R { (a, b); (a, c) } | ]" "tc x, y R(x, y)"
"{ y->1{ x->1 } , y->2{ x->1, x->2 } , y->3{ x->1, x->3 } }";
eval_eq "[ | R { (a, b); (b, c) } | ]" "tc x, y R(x, y)"
"{ y->1{ x->1 } , y->2{ x->1, x->2 } , y->3 }";
eval_eq "[ | R { (a,b); (b,c); (c,d); (d,e); (e,f); (f,g); (g,h) } | ]"
"x != y and not R(x, y) and tc x, y R(x, y)"
("{ y->3{ x->1 } , y->4{ x->1, x->2 } , y->5{ x->1, x->2, x->3 } ," ^
" y->6{ x->1, x->2, x->3, x->4 } , y->7{ x->1, x->2, x->3, x->4," ^
" x->5 } , y->8{ x->1, x->2, x->3, x->4, x->5, x->6 } }");
);
"eval: with real values" >::
(fun () ->
eval_eq "[ | P { x } | ] " "ex :x ((:x^2 + 3*:x + 2 < 0) and (:x < 0))"
"T";
eval_eq "[ | P { x } | f { x -> 1, y -> 2, z -> 3 } ]" ":f(x) > 2"
"{ x->3 }";
eval_eq "[ | P { x } | f { x -> 1, y -> 2, z -> 3 } ]"
"ex :x (:x^2 + :x * :f(x) + 2 < 0)"
"{ x->3 }";
eval_eq "[ | R { (a, a); (a, b) } | ] " ":(all y (R (x, y))) > 0"
"{ x->1 }";
eval_eq "[ 1 - 4 | | - ]"
"all a, b( :nbr(a) * :nbr(b) = :nbr(z) ->(:nbr(a) = 1 or :nbr(b) = 1) )"
"{ z->1, z->2, z->3 }";
);
"convert: second-order to QBF" >::
(fun () ->
let qbf_str_eq struc_s phi_s qbf_s =
let phi, struc = formula_of_string phi_s, struc_of_string struc_s in
LOG 1 "%s" (Formula.str phi);
let (qbf_res, rev_ids) = Solver.so_to_qbf struc phi in
let name (rel, arr) = (String.sub rel 1 (String.length rel - 1)) ^ "." ^
(String.concat "." (Array.to_list (Array.map string_of_int arr))) in
let names_tbl = Hashtbl.create (Hashtbl.length rev_ids) in
Hashtbl.iter (fun k v -> Hashtbl.add names_tbl k (name v)) rev_ids;
let qbf_res_s = BoolFormula.qbf_str ~names:names_tbl qbf_res in
LOG 1 "QBF %s BF %s" qbf_res_s (
let bf = BoolFormula.simplify (BoolFormula.sat_of_qbf qbf_res) in
(BoolFormula.str ~names:names_tbl bf) );
assert_equal ~printer:(fun x -> x) qbf_s qbf_res_s in
qbf_str_eq "[ a, b | T { a } | ]" "ex |R all x, y (T(x) or |R (x, y))"
"(ex R.2.2, R.2.1 (R.2.2 and R.2.1))";
qbf_str_eq "[ a, b | T { a } | ]"
"all |Q all x, y (T(x) or Q(y) or (x = y))" "false";
qbf_str_eq "[ a, b, c | E { (a,b); (b,c); (c,a) } | ]"
("ex |R, |G all x, y ( (|R(x) or |G(x)) and (" ^
" E(x,y) -> not ( (|R(x) and |R(y)) " ^ " or (|G(x) and |G(y)))))")
("(ex R.3, R.1, R.2 (ex G.3, G.1, G.2 ((R.3 or G.3) and (R.1 or G.1) and (R.2 or G.2) and (not ((R.3 and R.1) or (G.3 and G.1))) and (not ((R.3 and R.2) or (G.3 and G.2))) and (not ((R.1 and R.2) or (G.1 and G.2))))))");
);
"eval: second-order" >::
(fun () ->
let phi = "all |Q ex |R all x, y (|R (x, y) <-> (|Q(x) and not T(y)))" in
let struc = "[ a, b | T { a } | ]" in
eval_eq struc phi "T";
let formula = ("ex |B, |R all |Q all x (|B(x,x) and not " ^
"(|R(x) and |Q(x)) and (|R(x) or |Q(x)))") in
let struc = "[ a, b | T { a } | ]" in
eval_eq struc formula "{}";
);
"eval: game heuristic tests" >::
(fun () ->
let heur_phi = "(((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or
(C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u
((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s)
and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and
R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))))
and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and (not P(v)) and (not P(w))
and (not P(x)) and (not P(y)) and (not P(z))" ^
"and (not ex v, w, x, y, z ((((C(y, z) and C(x, y) and C(w, x) and
C(v, w)) or (R(y, z) and R(x, y) and R(w, x) and R(v, w)) or
ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z)
and C(t, y) and C(s, x) and C(r, w))) or ex r, s, t, u ((C(z, u) and
R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and
R(v, r)))) and P(z) and P(y) and P(x) and P(w) and P(v)))))" in
let _ () = Formula.print (FormulaOps.tnf_fv (formula_of_string heur_phi)) in
eval_eq "[ | | ] \"
... ... ... ...
P ... ... ... ...
... ... ... ...
... ... ... ...
... ... ... ...
...P Q..Q Q.. ...
... ... ... ...
...Q Q..Q P..P ...
... ... ... ...
Q..Q P..Q P.. ...
... ... ... ...
...P Q..P ...P ...
... ... ... ...
...P ... P.. ...
... ... ... ...
... ... ...Q ...
\"" heur_phi
("{ z->5{ y->12{ x->19{ w->26{ v->33 } } } } ," ^
" z->6{ y->5{ x->4{ w->3{ v->2 } } } } ," ^
" z->7{ y->6{ x->5{ w->4{ v->3 } } } } ," ^
" z->8{ y->7{ x->6{ w->5{ v->4 } } } } ," ^
" z->32{ y->39{ x->46{ w->53{ v->60 } } } } ," ^
" z->48{ y->47{ x->46{ w->45{ v->44 } } } } ," ^
" z->53{ y->44{ x->35{ w->26{ v->17 } } } } ," ^
" z->58{ y->50{ x->42{ w->34{ v->26 } } } } ," ^
" z->62{ y->53{ x->44{ w->35{ v->26 } } } } ," ^
" z->63{ y->54{ x->45{ w->36{ v->27 } } } } }");
);
"eval real: basic" >::
(fun () ->
eval_real_eq "r" "[ | R { (a, a); (a, b) } | ] " ":(all y (R (x, y)))"
"{ x->1{ ((1.) + ((-1.)*r) = 0) } , x->2{ ((0.) + ((-1.)*r) = 0) } }";
);
"get real val" >::
(fun () ->
real_val_eq "[ | R { (a, a); (a, b) } | ] "
":(ex x (R (x, x))) + 1" 2.;
real_val_eq "[ | P { x } | f { x->1, y->2, z->3 } ]"
"Sum (x | true : :f(x)^2)" 14.;
real_val_eq "[ | R { (a, a); (a, b) } | ] "
"Sum (x | true : :(all y (R (x, y))))" 1.;
real_val_eq "[ | R { (a, a); (a, b) } | ] "
"Sum (x | all y (R (x, y)) : 1)" 1.;
real_val_eq "[ | P { x } | f { x->1, y->2, z->3 } ]"
"Sum (x, y | P(x) : :f(x) * :f(y))" 6.;
real_val_eq "[ | P { x } | f { x->1, y->2, z->3 } ]"
"Sum (x, y | true : :f(x) * :f(y))" 36.;
real_val_eq "[ | R { (a, a); (a, b) } | ] "
"Sum (x, y | R (x, y) : 1)" 2.;
real_val_eq "[ a, b | .c = b | f { a->1, b->2 } ]" ":f(.c)" 2.;
);
"structure with rels parsing" >::
(fun () ->
let test p s res = assert_equal ~printer:(fun x -> x) res (rel_str p s) in
test "P" "[ 1 - 5 | | - ] with P(a) = :nbr(a)= 2" "P (e2)";
test "P" "[ 1 - 5 | | - ] with P(a) = :nbr(a)= 2 with :y(a) = 10*&a"
"P (e2)";
test "P" ("[ 1 - 10 | | - ] with P(z) = &z > 1 and " ^
"all x, y (&x * &y = &z -> (&x = 1 or &y = 1))")
"P {e2; e3; e5; e7}";
test "P" ("[ 1 - 3 | | - ] with E(x, y) = &y = &x + 1; " ^
"P(x, y) = &x != &y and tc x, y E(x, y)")
"P {(e1, e2); (e1, e3); (e2, e3)}";
test "S" ("[ 1 - 10 | | - ] with P(z) = &z > 1 and " ^
"all x, y (&x * &y = &z -> (&x = 1 or &y = 1));" ^
"E(x, y) = P(x) and P(y) and &x < &y and " ^
" all z (&x < &z and &z < &y -> not P(z));" ^
"S(x, y) = x != y and tc x, y E(x, y)")
"S {(e2, e3); (e2, e5); (e2, e7); (e3, e5); (e3, e7); (e5, e7)}";
);
]
let bigtests = "SolverBig" >::: [
"eval: bigger tc tests" >::
(fun () ->
(*let diag_phi_mso =
"let d1(x, y) = ex z ((R(x, z) and C(z, y)) or (R(y, z) and C(z, x))) in
let d2(x, y) = ex z ((R(x, z) and C(y, z)) or (R(y, z) and C(x, z))) in
let w(x) = wP(x) or wR(x) or wN(x) or wB(x) or wQ(x) or wK(x) in
let b(x) = bP(x) or bR(x) or bN(x) or bB(x) or bQ(x) or bK(x) in
let fd1(x, y) = tc in x,y (d1(x, y) and not w(y) and not b(y)) in
let fd2(x, y) = tc in x,y (d2(x, y) and not w(y) and not b(y)) in
let Diag1 (x, y) = ex z (fd1 (x, z) and (z = y or d1 (z, y))) in
let Diag2 (x, y) = ex z (fd2 (x, z) and (z = y or d2 (z, y))) in
wB(x) and (Diag1 (x, y) or Diag2 (x, y))" in
eval_eq "[ | | ] \"
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... wB.
\"" diag_phi_mso
"{ y->3{ x->3 } , y->6{ x->3 } , y->8{ x->3 } , y->9{ x->3 } }";*)
let diag_phi =
"let d1(x, y) = ex z ((R(x, z) and C(z, y)) or (R(y, z) and C(z, x))) in
let d2(x, y) = ex z ((R(x, z) and C(y, z)) or (R(y, z) and C(x, z))) in
let w(x) = wP(x) or wR(x) or wN(x) or wB(x) or wQ(x) or wK(x) in
let b(x) = bP(x) or bR(x) or bN(x) or bB(x) or bQ(x) or bK(x) in
let fd1(x, y) = tc x,y (d1(x, y) and not w(y) and not b(y)) in
let fd2(x, y) = tc x,y (d2(x, y) and not w(y) and not b(y)) in
let Diag1 (x, y) = ex z (fd1 (x, z) and (z = y or d1 (z, y))) in
let Diag2 (x, y) = ex z (fd2 (x, z) and (z = y or d2 (z, y))) in
wB(x) and (Diag1 (x, y) or Diag2 (x, y))" in
eval_eq "[ | | ] \"
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... wB. ...
\"" diag_phi
("{ y->3{ x->3 } , y->8{ x->3 } , y->10{ x->3 } , " ^
"y->13{ x->3 } , y->17{ x->3 } , y->24{ x->3 } }");
let chess_phi = "
let D1(x, y) = ex z ( (R(x, z) and C(z, y)) or (R(y, z) and C(z, x)) ) in
let D2(x, y) = ex z ( (R(x, z) and C(y, z)) or (R(y, z) and C(x, z)) ) in
let IsFirst(x) = not ex z C(z, x) in
let IsSecond(x) = ex y (C(y, x) and IsFirst(y)) in
let IsEight(x) = not ex z C(x, z) in
let IsSeventh(x) = ex y (C(x, y) and IsEight(y)) in
let IsA1(x) = not ex z R(z, x) and IsFirst(x) in
let IsH1(x) = not ex z R(x, z) and IsFirst(x) in
let IsA8(x) = not ex z R(z, x) and IsEight(x) in
let IsH8(x) = not ex z R(x, z) and IsEight(x) in
let w(x) = wP(x) or wR(x) or wN(x) or wB(x) or wQ(x) or wK(x) in
let b(x) = bP(x) or bR(x) or bN(x) or bB(x) or bQ(x) or bK(x) in
let DoubleC(x, y) = ex z ((C(x, z) and C(z, y)) or (C(y, z) and C(z, x))) in
let DoubleR(x, y) = ex z ((R(x, z) and R(z, y)) or (R(y, z) and R(z, x))) in
let KnightRCC(x, y) = ex z ((R(x, z) or R(z, x)) and DoubleC(z, y)) in
let KnightCRR(x, y) = ex z ((C(x, z) or C(z, x)) and DoubleR(z, y)) in
let Knight(x, y) = KnightRCC(x, y) or KnightCRR(x, y) in
let FreeD1 (x, y) = tc x, y (D1 (x, y) and not w(y) and not b(y)) in
let FreeD2 (x, y) = tc x, y (D2 (x, y) and not w(y) and not b(y)) in
let Diag1 (x, y) = ex z (FreeD1 (x, z) and (z = y or D1 (z, y))) in
let Diag2 (x, y) = ex z (FreeD2 (x, z) and (z = y or D2 (z, y))) in
let Diag (x, y) = Diag1 (x, y) or Diag2 (x, y) in
let FreeC (x, y) = tc x, y ((C(x, y) or C(y, x)) and not w(y) and not b(y)) in
let FreeR (x, y) = tc x, y ((R(x, y) or R(y, x)) and not w(y) and not b(y)) in
let Col (x, y) = ex z (FreeC (x, z) and (z = y or (C(z, y) or C(y, z)))) in
let Row (x, y) = ex z (FreeR (x, z) and (z = y or (R(z, y) or R(y, z)))) in
let Line (x, y) = Col (x, y) or Row (x, y) in
let Near(x, y) = C(x,y) or C(y,x) or R(x,y) or R(y,x) or D1(x, y) or D2(x, y) in
let wPBeats (x) = ex y (wP(y) and ex z ((R(y, z) or R(z, y)) and C(z, x))) in
let bPBeats (x) = ex y (bP(y) and ex z ((R(y, z) or R(z, y)) and C(x, z))) in
let wDiagBeats (x) = ex y ((wQ(y) or wB(y)) and Diag(y, x)) in
let bDiagBeats (x) = ex y ((bQ(y) or bB(y)) and Diag(y, x)) in
let wLineBeats (x) = ex y ((wQ(y) or wR(y)) and Line(y, x)) in
let bLineBeats (x) = ex y ((bQ(y) or bR(y)) and Line(y, x)) in
let wFBeats(x)= wDiagBeats(x) or wLineBeats(x) or ex y(wN(y) and Knight(y,x)) in
let bFBeats(x)= bDiagBeats(x) or bLineBeats(x) or ex y(bN(y) and Knight(y,x)) in
let wBeats(x) = wFBeats(x) or wPBeats(x) or ex y (wK(y) and Near(y, x)) in
let bBeats(x) = bFBeats(x) or bPBeats(x) or ex y (bK(y) and Near(y, x)) in
let CheckW() = ex x (wK(x) and bBeats(x)) in
let CheckB() = ex x (bK(x) and wBeats(x)) in " in
eval_eq "[ | | ] \"
... ... ... ...
bR bN.bB bQ.bK bB.bN bR.
... ... ... ...
bP.bP bP.bP bP.bP bP.bP
... ... ... ...
... ... ... ...
... ... ... ...
... ... ... ...
... ... ... ...
... ... ... ...
... ... ... ...
... ... ... ...
... ... ... ...
wP wP.wP wP.wP wP.wP wP.
... ... ... ...
wR.wN wB.wQ wK.wB wN.wR
\"" (chess_phi ^ "IsA8(x) and not CheckW()") "{ x->57 }";
);
(*"eval: four points problem" >::
(fun () ->
eval_eq "[ | P {x}; Q {y}; Z {z}; S {v} | ]"
("ex :px, :py, :qx, :qy, :zx, :zy, :sx, :sz all X ex :rt,:rb,:rl,:rr" ^
" all x(
(P(x) -> (|X(x) <-> (:px>:rl and :px<:rr and :py>:rb and :py<:rt))) and
(Q(x) -> (|X(x) <-> (:qx>:rl and :qx<:rr and :qy>:rb and :qy<:rt))) and
(Z(x) -> (|X(x) <-> (:zx>:rl and :zx<:rr and :zy>:rb and :zy<:rt))) and
(S(x) -> (|X(x) <-> (:sx>:rl and :sx<:rr and :sy>:rb and :sy<:rt))))")
"";
);
"eval: four coloring problem" >::
(fun () ->
let four_color_f = "all a, b, c, d
(C(a,b) and C(c, d) and R(a,c) and R(b,d) -> (
not (a in C1 and b in C1 and c in C1 and d in C1) and
not (a in C2 and b in C2 and c in C2 and d in C2) and
not (a in C3 and b in C3 and c in C3 and d in C3) and
not (a in C4 and b in C4 and c in C4 and d in C4) ))" in
let rec linear_order name do_pref i =
let elem j =
if do_pref then
name ^ (string_of_int j)
else (string_of_int j) ^ name in
let rec all_from j =
let str = "(" ^ (elem j) ^ ", " ^ (elem i) ^ ")" in
if j = i - 1 then str else str ^ ", " ^ (all_from (j+1)) in
if i = 2 then "(" ^ (elem 1) ^ ", " ^ (elem 2) ^ ")" else
(linear_order name do_pref (i-1)) ^ ", " ^ (all_from 1) in
let grid n =
let rec upto i = if i = 1 then [1] else (upto (i-1)) @ [i] in
let col i = linear_order (string_of_int i) true n in
let row i = linear_order (string_of_int i) false n in
let cols = String.concat "; " (List.map col (upto n)) in
let rows = String.concat "; " (List.map row (upto n)) in
"[ | C { " ^ cols ^ " }; R { " ^ rows ^ " } | ]" in
eval_eq (grid 2) four_color_f "";
);*)
]

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks