-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathnpbc_checkScript.sml
More file actions
6002 lines (5657 loc) · 170 KB
/
npbc_checkScript.sml
File metadata and controls
6002 lines (5657 loc) · 170 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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
Pseudo-boolean constraints proof format and checker
*)
Theory npbc_check
Libs
preamble
Ancestors
pbc npbc mlstring mlint mlvector mllist spt_to_vec integer
val _ = numLib.temp_prefer_num();
(* Proof steps are classified in a hierachy of three descending levels
"Core" steps csteps
|
|--> "SAT" steps ssteps
|
|--> "Logical" steps lsteps
lstep: These steps preserve logical implication for F = C U D
Includes cutting planes and contradiction proof steps
Deletions allowed in D only
sstep: These steps preserve satisfiability of F = C U D
Includes redundancy, and redundancy subproofs can only use lsteps
cstep: These steps manipulate the core
Includes objective updates, core transfer, checked deletion, dominance
*)
(* pbp = pseudo-boolean proof format
Below, nums represent ConstraintIds, which are 1-indexed (although 0s internally work fine) *)
(* A constraint to be added by a cutting planes proof *)
Datatype:
div_ty =
| Cd | Dd | Nd | Md
End
Datatype:
constr =
| Id num (* Constraints can refer to earlier IDs *)
| Add constr constr (* Add two constraints *)
| Mul constr num (* Multiply by a constant factor *)
| Div div_ty constr num (* Divide by a constant factor *)
| Minus constr num (* Subtract from RHS *)
| Sat constr (* Saturation *)
| Lit (num lit) (* Literal axiom lit ≥ 0 (superseded by triv but used in parsing) *)
| Weak constr (var list) (* Addition of literal axioms until "var" disappears *)
| Triv ((num # num lit) app_list) (* Literal axiom corresponds to [1,l] ≥ 0 *)
End
(* Steps that preserve logical implication *)
Datatype:
lstep =
| Delete (num list) (* Ids to delete *)
| Cutting constr (* Adds a constraint using cutting planes, written in reverse polish notation *)
| Rup npbc (num list) (* Add a constraint by RUP *)
| Con npbc (lstep list) num
(* Prove constraint by contradiction, indicated by the id *)
| ImplyAdd num npbc
(* Prove constraint by implication from the id *)
| Check num npbc
(* Debugging / other steps are parsed as no ops *)
| NoOp (* Other steps are parsed as no ops *)
End
Definition lstep_ok_def[simp]:
(lstep_ok (Con c pfs n) ⇔
compact c ∧ (EVERY lstep_ok pfs)) ∧
(lstep_ok (Rup c ls) ⇔ compact c) ∧
(lstep_ok _ ⇔ T)
Termination
WF_REL_TAC ‘measure lstep_size’ \\ rw []
End
(*
The type of PB formulas represented as a finite map
num -> pbc
*)
Type pbf = ``:(npbc # bool) spt``;
(* b = T forces all operations to respect/use the core directly *)
Definition lookup_core_only_def:
lookup_core_only b fml n =
case lookup n fml of
NONE => NONE
| SOME (x,b') =>
if ¬b ∨ b' then SOME x
else NONE
End
Definition map_app_list_def:
(map_app_list f (List ls) = List (MAP f ls)) ∧
(map_app_list f (Append l r) = Append (map_app_list f l) (map_app_list f r)) ∧
(map_app_list f Nil = Nil)
End
Definition mul_triv_def:
mul_triv ls k = map_app_list (λ(x:num,y). (x * k,y) ) ls
End
Definition fuse_weaken_def:
(fuse_weaken vs (Weak c rs) = Weak c (vs ++ rs)) ∧
(fuse_weaken vs p = Weak p vs)
End
Definition to_triv_def:
(to_triv (Add l r) =
let ll = to_triv l in
let rr = to_triv r in
case ll of
Triv lt =>
(case rr of
Triv rt => Triv (SmartAppend lt rt)
| Add re (Triv rt) => Add re (Triv (SmartAppend lt rt))
| _ => Add rr ll)
| Add le (Triv lt) =>
(case rr of
Triv rt => Add le (Triv (SmartAppend lt rt))
| Add re (Triv rt) => Add (Add le re) (Triv (SmartAppend lt rt))
| _ => Add (Add le rr) (Triv lt))
| _ => Add ll rr) ∧
(to_triv (Mul c k) =
let cc = to_triv c in
case cc of
Triv ls => Triv (mul_triv ls k)
| _ => Mul cc k) ∧
(to_triv (Div dt c k) = Div dt (to_triv c) k) ∧
(to_triv (Minus c k) = Minus (to_triv c) k) ∧
(to_triv (Sat c) = Sat (to_triv c)) ∧
(to_triv (Weak c vs) = fuse_weaken vs (to_triv c)) ∧
(to_triv (Lit l) = Triv (List [(1,l)])) ∧
(to_triv c = c)
End
Definition sing_lit_def:
sing_lit (k:num,l) =
case l of Pos v => (&k:int,v)
| Neg v => (-&k:int,v)
End
(* TODO: might be possible to speedup *)
Definition clean_triv_def:
clean_triv ls =
FOLDR (λpc1 c2.
npbc$add ([pc1],0) c2) ([],0)
(FILTER (λh. FST h ≠ 0)
(sort (λx y. SND x ≤ SND y)
(MAP sing_lit (append ls))))
End
(* TODO: copied from scpog *)
Definition mk_strict_aux_def:
(mk_strict_aux x [] acc = x::acc) ∧
(mk_strict_aux x (y::ys) acc =
if x = y then
mk_strict_aux x ys acc
else mk_strict_aux y ys (x::acc))
End
Definition mk_strict_def:
mk_strict ls =
case ls of
[] => []
| (x::xs) => mk_strict_aux x xs []
End
Definition mk_strict_sorted_num_def:
mk_strict_sorted_num ls =
mk_strict (sort (\x y:num. y ≤ x) ls)
End
Definition weaken_sorted_def:
weaken_sorted c vs =
weaken c (mk_strict_sorted_num vs)
End
Definition do_divide_def:
do_divide dty c k =
case dty of
Cd => var_divide c k
| Dd => divide c k
| Md => var_mir c k
| Nd => mir c k
End
Definition check_cutting_def:
(check_cutting b (fml:pbf) (Id n) =
lookup_core_only b fml n) ∧
(check_cutting b fml (Add c1 c2) =
OPTION_MAP2 add (check_cutting b fml c1) (check_cutting b fml c2)) ∧
(check_cutting b fml (Mul c k) =
OPTION_MAP (λc. multiply c k) (check_cutting b fml c)) ∧
(check_cutting b fml (Div dty c k) =
if k ≠ 0 then
OPTION_MAP (λc. do_divide dty c k) (check_cutting b fml c)
else NONE) ∧
(check_cutting b fml (Minus c k) =
OPTION_MAP (λc. minus c k) (check_cutting b fml c)) ∧
(check_cutting b fml (Sat c) =
OPTION_MAP saturate (check_cutting b fml c)) ∧
(check_cutting b fml (Lit l) =
case l of
Pos v => SOME ([(1,v)],0)
| Neg v => SOME ([(-1,v)],0)) ∧
(check_cutting b fml (Triv ls) = SOME (clean_triv ls)) ∧
(check_cutting b fml (Weak c var) =
OPTION_MAP (λc. weaken_sorted c var) (check_cutting b fml c))
End
Definition check_contradiction_fml_def:
check_contradiction_fml b (fml:pbf) n =
case lookup_core_only b fml n of
NONE => F
| SOME c =>
check_contradiction c
End
(* Insertion into derived set, unless we're in core only mode *)
Definition insert_fml_def:
insert_fml b fml id c =
(insert id (c,b) fml,
id+1)
End
Definition rup_pass1_def:
rup_pass1 assg [] acc ys = (acc,ys) ∧
rup_pass1 assg ((i:int,n:num)::xs) acc ys =
let k = Num (ABS i) in
case FLOOKUP assg n of
| NONE => rup_pass1 assg xs (acc + k) ((k,i,n)::ys)
| SOME T => rup_pass1 assg xs (if i < 0 then acc else acc + k) ys
| SOME F => rup_pass1 assg xs (if i < 0 then acc + k else acc) ys
End
Definition rup_pass2_def:
rup_pass2 assg max [] l = SOME assg ∧
rup_pass2 assg max ((k:num,i:int,n:num)::ys) l =
if max < l + k then
rup_pass2 (assg |+ (n,0 ≤ i)) max ys l
else
rup_pass2 assg max ys l
End
(* Reduce c according to the assignment,
return NONE if it gives a contradiction
otherwise return the updated assignment using units in (ls,n) *)
Definition update_assg_def:
update_assg assg (ls,n:int) =
if n ≤ 0
then SOME assg
else
let n = Num(ABS n) in
let (max,ls1) = rup_pass1 assg ls 0 [] in
if max < n then NONE else
rup_pass2 assg max ls1 n
End
(* Here, assg could be a finite map of variables to T/F
assg' should be assg updated with all units under assg
id = 0 is special for nc
*)
Definition get_rup_constraint_def:
get_rup_constraint b fml n nc =
if n = 0 then SOME nc
else
lookup_core_only b fml n
End
Definition check_rup_def:
(check_rup b nc fml (assg: num |-> bool) [] = F) ∧
(check_rup b nc fml assg (n::ns) =
case get_rup_constraint b fml n nc of
NONE => F
| SOME c =>
case update_assg assg c of
| NONE => T
| SOME assg' => check_rup b nc fml assg' ns)
End
Definition check_lstep_def:
(check_lstep lstep b (fml:pbf) (id:num) =
case lstep of
| Delete ls =>
if EVERY (λid. lookup_core_only T fml id = NONE) ls
then SOME (FOLDL (λa b. delete b a) fml ls,id)
else NONE
| Cutting constr =>
(case check_cutting b fml (to_triv constr) of
NONE => NONE
| SOME c =>
SOME (insert_fml b fml id c))
| Rup c ls =>
if check_rup b (not c) fml FEMPTY ls then
SOME (insert_fml b fml id c)
else NONE
| Con c pf n =>
let (fml_not_c,id1) = insert_fml b fml id (not c) in
(case check_lsteps pf b fml_not_c id1 of
SOME (fml',id') =>
if check_contradiction_fml b fml' n
then SOME (insert_fml b fml id' c)
else NONE
| _ => NONE)
| ImplyAdd n c =>
(case lookup_core_only b fml n of NONE => NONE
| SOME c' =>
if imp c' c then SOME(insert_fml b fml id c)
else NONE)
| Check n c =>
(case lookup_core_only b fml n of NONE => NONE
| SOME c' =>
if c = c' then SOME(fml,id)
else NONE)
| NoOp => SOME(fml,id)) ∧
(check_lsteps [] b fml id = SOME (fml,id)) ∧
(check_lsteps (step::steps) b fml id =
case check_lstep step b fml id of
SOME(fml',id') =>
check_lsteps steps b fml' id'
| res => res)
Termination
WF_REL_TAC ‘measure (
sum_size (lstep_size o FST)
(list_size lstep_size o FST) )’
End
Theorem satisfies_SUBSET:
Y ⊆ X ⇒
(satisfies w X ⇒ satisfies w Y)
Proof
rw[satisfies_def]>>
metis_tac[SUBSET_DEF]
QED
Definition core_only_fml_def:
core_only_fml b fml =
if b then
{v | ∃n. lookup n fml = SOME(v,b)}
else
{v | ∃n b. lookup n fml = SOME(v,b)}
End
Theorem FOLDR_add_sound:
∀ls c.
satisfies_npbc w c ⇒
satisfies_npbc w (FOLDR (λpc1 c2. add ([pc1],0) c2) c ls)
Proof
Induct>>
rw[]>>
match_mp_tac add_thm>>
simp[satisfies_npbc_def]
QED
Theorem clean_triv_thm:
satisfies_npbc w (clean_triv ls)
Proof
rw[clean_triv_def]>>
irule FOLDR_add_sound>>
simp[satisfies_npbc_def]
QED
Theorem check_cutting_correct:
∀fml n c w.
check_cutting b fml n = SOME c ∧
satisfies w (core_only_fml b fml) ⇒
satisfies_npbc w c
Proof
Induct_on`n`
>~[`Id`]
>- (
rw[check_cutting_def]>>
fs[lookup_core_only_def,core_only_fml_def]>>
every_case_tac>>
fs[satisfies_def,satisfies_npbc_def,range_def,PULL_EXISTS]>>
metis_tac[])
>~[`Add`]
>- (
rw[check_cutting_def]>>
match_mp_tac add_thm>>
metis_tac[])
>~[`Mul`]
>- (
rw[check_cutting_def]>>
match_mp_tac multiply_thm>>
metis_tac[])
>~[`Div`]
>- (
rw[check_cutting_def]>>
simp[oneline do_divide_def]>>
every_case_tac>>fs[]
>- metis_tac[var_divide_thm]
>- metis_tac[divide_thm]
>- metis_tac[mir_thm]
>- metis_tac[var_mir_thm])
>~[`Minus`]
>- (
rw[check_cutting_def]>>
metis_tac[minus_thm])
>~[`Sat`]
>- (
rw[check_cutting_def]>>
match_mp_tac saturate_thm>>
metis_tac[])
>~[`Lit`]
>- (
rw[check_cutting_def,AllCaseEqs()]>>
EVAL_TAC>>simp[])
>~[`Weak`]
>- (
rw[check_cutting_def]>>
simp[weaken_sorted_def]>>
match_mp_tac weaken_thm>>
metis_tac[])
>~[`Triv`]
>- (
rw[check_cutting_def]>>
metis_tac[clean_triv_thm])
QED
Theorem FOLDR_add_compact:
∀ls c.
compact c ∧ EVERY (λh. FST h ≠ 0) ls ⇒
compact (FOLDR (λpc1 c2. add ([pc1],0) c2) c ls)
Proof
Induct>>
rw[]>>
match_mp_tac compact_add>>
simp[]
QED
Theorem clean_triv_compact:
compact (clean_triv ls)
Proof
rw[clean_triv_def]>>
irule FOLDR_add_compact>>
simp[EVERY_FILTER]
QED
Theorem check_cutting_compact:
∀n c.
(∀c. c ∈ core_only_fml b fml ⇒ compact c) ∧
check_cutting b fml n = SOME c ⇒
compact c
Proof
Induct_on`n`>>rw[check_cutting_def]
>- (
(*Id case*)
fs[core_only_fml_def,lookup_core_only_def]>>
every_case_tac>>gvs[]>>
metis_tac[])
>- (
(* add case *)
metis_tac[compact_add])
>- (
(* multiply case *)
metis_tac[compact_multiply])
>- (
simp[oneline do_divide_def]>>
every_case_tac
>- metis_tac[compact_var_divide]
>- metis_tac[compact_divide]
>- metis_tac[compact_mir]
>- metis_tac[compact_var_mir])
>- metis_tac[compact_minus]
>- metis_tac[compact_saturate]
>- (
(* literal case *)
Cases_on`l`>>fs[check_cutting_def]>>rveq>>
EVAL_TAC)
>- (
(* weaken case *)
simp[weaken_sorted_def]>>
metis_tac[compact_weaken])
>-
metis_tac[clean_triv_compact]
QED
Definition id_ok_def:
id_ok fml id = ∀n:num. id ≤ n ⇒ n ∉ domain fml
End
Theorem sat_implies_refl[simp]:
fml ⊨ fml
Proof
rw[sat_implies_def]
QED
Theorem range_FOLDL_delete:
∀ls v.
range (FOLDL (λa b. delete b a) v ls) ⊆ range v
Proof
Induct>>rw[]>>
first_x_assum (qspec_then`delete h v` mp_tac)>>rw[]>>
match_mp_tac SUBSET_TRANS>>
asm_exists_tac>>simp[]>>
simp[range_delete]
QED
Theorem sat_implies_subset:
s ⊆ t ⇒
t ⊨ s
Proof
rw[sat_implies_def,satisfies_def,SUBSET_DEF]>>
metis_tac[]
QED
Theorem satisfiable_subset:
satisfiable t ∧ s ⊆ t ⇒
satisfiable s
Proof
rw[satisfiable_def,SUBSET_DEF,satisfies_def]>>
metis_tac[]
QED
Theorem id_ok_insert_1:
id_ok fml id ⇒
id_ok (insert id c fml) (id+1n)
Proof
rw[id_ok_def]
QED
Theorem domain_FOLDL_delete:
∀ls v.
domain (FOLDL (λa b. delete b a) v ls) =
(domain v) DIFF set ls
Proof
Induct>>rw[]>>
simp[DIFF_INSERT]
QED
Theorem id_ok_FOLDL_delete:
∀l fml.
id_ok fml id ⇒
id_ok (FOLDL (λa b. delete b a) fml l) id
Proof
Induct \\ fs[] \\ rw[]
\\ first_x_assum irule
\\ fs [id_ok_def,domain_delete]
QED
Theorem lookup_FOLDL_delete:
∀ls v.
lookup n (FOLDL (λa b. delete b a) v ls) =
if MEM n ls then NONE else lookup n v
Proof
Induct>>rw[]>>
first_x_assum (qspec_then`delete h v` mp_tac)>>rw[]>>
fs[lookup_delete]
QED
Theorem check_contradiction_fml_unsat:
check_contradiction_fml b fml n ⇒
unsatisfiable (core_only_fml b fml)
Proof
rw[check_contradiction_fml_def,core_only_fml_def,lookup_core_only_def]>>
every_case_tac>>fs[]>>
drule check_contradiction_unsat>>
rw[unsatisfiable_def,satisfiable_def,range_def,satisfies_def]>>
metis_tac[]
QED
Theorem core_only_fml_insert:
id ∉ domain fml ⇒
core_only_fml b (insert id (c,b) fml) =
c INSERT core_only_fml b fml
Proof
rw[core_only_fml_def,EXTENSION,lookup_insert]>>
eq_tac>>rw[]>>
every_case_tac>>fs[domain_lookup]>>
metis_tac[]
QED
Definition agree_assg_def:
agree_assg assg w ⇔
∀x b.
FLOOKUP assg x = SOME b ⇒
w x = b
End
Theorem rup_pass1_thm:
∀assg xs acc ys acc1 ys1 w.
rup_pass1 assg xs acc ys = (acc1,ys1) ∧ agree_assg assg w ⇒
SUM (MAP (eval_term w) xs) + acc ≤ acc1 ∧
(∀n i k. MEM (n,i,k) ys1 ⇒ MEM (n,i,k) ys ∨ n = Num (ABS i)) ∧
∃xs1.
SUM (MAP (eval_term w) xs1) + lslack (MAP SND ys1) + acc ≤ acc1 + lslack (MAP SND ys) ∧
SUM (MAP (eval_term w) xs) + SUM (MAP (eval_term w) (MAP SND ys)) =
SUM (MAP (eval_term w) xs1) + SUM (MAP (eval_term w) (MAP SND ys1))
Proof
Induct_on ‘xs’ \\ fs [rup_pass1_def]
>- (rw [] \\ qexists_tac ‘[]’ \\ gvs [])
\\ PairCases \\ fs [rup_pass1_def]
\\ rpt gen_tac \\ gvs [AllCaseEqs()] \\ strip_tac \\ gvs []
>- (last_x_assum dxrule_all \\ fs [lslack_def] \\ strip_tac \\ gvs []
\\ conj_tac >- (Cases_on ‘w h1’ \\ gvs [] \\ metis_tac [])
\\ conj_tac >- metis_tac []
\\ qexists_tac ‘xs1’ \\ gvs [])
\\ last_x_assum drule_all \\ strip_tac \\ fs []
\\ gvs [agree_assg_def] \\ res_tac \\ gvs []
\\ IF_CASES_TAC \\ gvs []
>- (qexists_tac ‘xs1’ \\ gvs [])
>- (qexists_tac ‘(h0,h1)::xs1’ \\ gvs [])
>- (qexists_tac ‘(h0,h1)::xs1’ \\ gvs [])
>- (qexists_tac ‘xs1’ \\ gvs [])
QED
Theorem rup_pass2_thm:
∀assg d1 slack ls1 d hc.
agree_assg assg w ∧
c1 ≤ d + SUM (MAP (eval_term w) (MAP SND ls1)) ∧
d + lslack (MAP SND ls1) ≤ max ∧
(∀n i k. MEM (n,i,k) ls1 ⇒ n = Num (ABS i)) ∧
rup_pass2 assg max ls1 c1 = SOME assg1
⇒
agree_assg assg1 w
Proof
Induct_on ‘ls1’ \\ fs [rup_pass2_def] \\ PairCases
\\ gvs [rup_pass2_def] \\ rpt gen_tac \\ strip_tac
\\ qabbrev_tac ‘x = if h1 < 0 then 1 − b2n (w h2) else b2n (w h2)’
\\ ‘x ≤ 1’ by (rw [Abbr‘x’] \\ Cases_on ‘w h2’ \\ gvs [])
\\ reverse (Cases_on ‘max < c1 + h0’) \\ gvs []
\\ last_x_assum irule \\ fs []
\\ gvs [SF DNF_ss,SF SFY_ss]
\\ fs [lslack_def] \\ fs [GSYM lslack_def]
\\ qexists_tac ‘d + Num (ABS h1)’ \\ gvs []
\\ ‘c1 ≤ d + (Num (ABS h1) + SUM (MAP (eval_term w) (MAP SND ls1)))’ by
(Cases_on ‘x’ \\ gvs [ADD1] \\ Cases_on ‘n’ \\ gvs []) \\ fs []
\\ first_x_assum $ irule_at $ Pos hd \\ fs []
\\ gvs [agree_assg_def,FLOOKUP_SIMP] \\ rw [] \\ gvs []
\\ rpt $ qpat_x_assum ‘∀x._’ kall_tac
\\ dxrule_all LESS_EQ_LESS_TRANS \\ strip_tac
\\ ‘d + lslack (MAP SND ls1) < c1’ by gvs []
\\ Cases_on ‘x = 1’ >- (Cases_on ‘w h2’ \\ gvs [AllCaseEqs()] \\ intLib.COOPER_TAC)
\\ ‘x = 0’ by gvs [] \\ gvs []
\\ ‘SUM (MAP (eval_term w) (MAP SND ls1)) ≤ lslack (MAP SND ls1)’ by fs [lslack_thm]
\\ gvs []
QED
Theorem update_assg_NONE:
update_assg assg c = NONE ⇒
∀w. agree_assg assg w ⇒
¬ satisfies_npbc w c
Proof
PairCases_on ‘c’
\\ rw[update_assg_def]
\\ pairarg_tac \\ gvs []
\\ drule_all rup_pass1_thm \\ strip_tac
\\ gvs [AllCaseEqs()]
>- (
gvs [satisfies_npbc_def,INT_NOT_LE]>>
intLib.ARITH_TAC)
\\ CCONTR_TAC \\ gvs [lslack_def]
(* two subgoals *)
\\ (qsuff_tac
‘∀assg m ls1 c1. rup_pass2 assg m ls1 c1 ≠ NONE’
>- (strip_tac \\ gvs [])
\\ rpt $ pop_assum kall_tac
\\ Induct_on ‘ls1’ \\ gvs [rup_pass2_def]
\\ gvs [FORALL_PROD]
\\ gvs [rup_pass2_def] \\ rw [])
QED
Theorem update_assg_SOME:
update_assg assg c = SOME assg' ⇒
∀w. agree_assg assg w ∧ satisfies_npbc w c ⇒
agree_assg assg' w
Proof
PairCases_on ‘c’
\\ rw[update_assg_def]
\\ pairarg_tac \\ gvs []
\\ drule_all rup_pass1_thm \\ strip_tac
\\ gvs [AllCaseEqs()]
\\ gvs [satisfies_npbc_def,EVAL “lslack []”]
\\ irule rup_pass2_thm
\\ last_x_assum $ irule_at Any
\\ gvs [SF SFY_ss]
\\ intLib.ARITH_TAC
QED
Theorem check_rup_unsat:
∀ns assg.
check_rup b nc fml assg ns ∧
agree_assg assg w ⇒
¬(satisfies_npbc w nc ∧
satisfies w (core_only_fml b fml))
Proof
Induct>>rw[check_rup_def]>>
gvs[get_rup_constraint_def,AllCasePreds(),AllCaseEqs()]
>- (
drule update_assg_NONE>>
disch_then drule>>
fs[lookup_core_only_def,core_only_fml_def]>>
every_case_tac>>fs[satisfies_def,PULL_EXISTS]>>
metis_tac[])
>- (
drule update_assg_SOME>>
disch_then drule>>
Cases_on`satisfies_npbc w x`>>rw[]
>-
metis_tac[]>>
fs[lookup_core_only_def,core_only_fml_def]>>
every_case_tac>>fs[satisfies_def,PULL_EXISTS]>>
metis_tac[])
>- (
drule update_assg_NONE>>
disch_then drule>>
fs[lookup_core_only_def,core_only_fml_def]>>
every_case_tac>>fs[satisfies_def,PULL_EXISTS]>>
metis_tac[])
>- (
drule update_assg_SOME>>
disch_then drule>>
Cases_on`satisfies_npbc w c`>>rw[]
>-
metis_tac[]>>
fs[lookup_core_only_def,core_only_fml_def]>>
every_case_tac>>fs[satisfies_def,PULL_EXISTS]>>
metis_tac[])
QED
(* if b = F, then the core should be untouched,
otherwise the core can grow *)
Theorem check_lstep_correct:
(∀step b fml id.
id_ok fml id ⇒
case check_lstep step b fml id of
SOME (fml',id') =>
id ≤ id' ∧
id_ok fml' id' ∧
(∀n x.
(lookup n fml = SOME (x,T) ⇒
lookup n fml' = SOME (x,T))) ∧
(¬b ⇒
(∀n x.
(lookup n fml' = SOME (x,T) ⇒
lookup n fml = SOME (x,T)))) ∧
(core_only_fml b fml) ⊨ (core_only_fml b fml')
| NONE => T) ∧
(∀steps b fml id.
id_ok fml id ⇒
case check_lsteps steps b fml id of
| SOME (fml',id') =>
id ≤ id' ∧
id_ok fml' id' ∧
(∀n x.
lookup n fml = SOME (x,T) ⇒
lookup n fml' = SOME (x,T)) ∧
(¬b ⇒
(∀n x.
(lookup n fml' = SOME (x,T) ⇒
lookup n fml = SOME (x,T)))) ∧
(core_only_fml b fml) ⊨ (core_only_fml b fml')
| NONE => T)
Proof
ho_match_mp_tac check_lstep_ind \\
reverse (rpt strip_tac)
>- (
simp[Once check_lstep_def]>>
every_case_tac>>gs[]>>
fs[sat_implies_def,satisfiable_def]>>
metis_tac[])
>- simp[Once check_lstep_def]
\\ Cases_on ‘∃n c. step = Check n c’
>- (
rw[check_lstep_def] \\ every_case_tac \\ fs [] \\ metis_tac[sat_implies_refl])
\\ Cases_on ‘∃n. step = Delete n’
THEN1 (
simp[check_lstep_def] \\
Cases_on`step` \\ fs[] \\
every_case_tac \\ rw []
>- metis_tac[id_ok_FOLDL_delete]
>- (
fs[lookup_FOLDL_delete,EVERY_MEM,lookup_core_only_def,AllCaseEqs()]>>
metis_tac[option_CLAUSES,PAIR,SND])
>- fs[lookup_FOLDL_delete]
>- (
match_mp_tac sat_implies_subset>>
simp[core_only_fml_def,SUBSET_DEF]>>rw[]>>
fs[lookup_FOLDL_delete]>>
metis_tac[]))
\\ Cases_on ‘step = NoOp’ >- simp[check_lstep_def]
\\ Cases_on ‘∃c. step = Cutting c’
THEN1 (
simp[check_lstep_def] \\
Cases_on`step` \\ fs[] \\
every_case_tac \\ simp [] \\
gvs[insert_fml_def]>>
drule check_cutting_correct>>
DEP_REWRITE_TAC[core_only_fml_insert] >> fs[id_ok_def]>>
rw[]>>fs[sat_implies_def,core_only_fml_def]
>- (
rw[lookup_insert]>>fs[]>>
first_x_assum(qspec_then`id` mp_tac)>>
fs[domain_lookup])>>
gvs[lookup_insert,AllCaseEqs()])
\\ Cases_on `∃c ls. step = Rup c ls`
THEN1 (
fs[check_lstep_def] \\
every_case_tac \\
gvs[insert_fml_def]
\\ CONJ_TAC >- fs[id_ok_def]
\\ CONJ_TAC >- (
rw[lookup_insert]>>fs[id_ok_def]>>
last_x_assum(qspec_then`id` mp_tac)>>simp[]>>
metis_tac[domain_lookup])
\\ CONJ_TAC >- (
rw[]>>gvs[lookup_insert,AllCaseEqs()])
\\ drule check_rup_unsat
\\ simp[agree_assg_def]
\\ rw[] \\ fs[sat_implies_def]
\\ rw[]
\\ gvs[id_ok_def,core_only_fml_insert]
\\ metis_tac[not_thm])
(* Proof by contradiction *)
\\ Cases_on ‘∃c steps n. step = Con c steps n’
THEN1 (
gvs[check_lstep_def,insert_fml_def]
\\ last_x_assum mp_tac
\\ impl_tac >- (
fs[id_ok_def,SUBSET_DEF]>>rw[]>>
metis_tac[])
\\ TOP_CASE_TAC \\ gvs[AllCaseEqs()]
\\ TOP_CASE_TAC \\ fs[]
\\ strip_tac
\\ rpt(TOP_CASE_TAC \\ fs[])
\\ gvs[]
\\ CONJ_TAC >- fs[id_ok_def]
\\ CONJ_TAC >- (
rw[lookup_insert]>>fs[id_ok_def]>>
last_x_assum(qspec_then`n'` mp_tac)>>simp[]>>
metis_tac[domain_lookup])
\\ CONJ_TAC >- (
rw[]>>gvs[lookup_insert,AllCaseEqs()])
\\ drule check_contradiction_fml_unsat
\\ rw[] \\ fs[unsatisfiable_def,sat_implies_def]
\\ rw[]
\\ gvs[id_ok_def,core_only_fml_insert]
\\ CCONTR_TAC \\ fs[GSYM not_thm]
\\ first_x_assum(qspec_then`w` mp_tac)
\\ impl_tac >- metis_tac[not_thm]
\\ metis_tac[satisfies_def,satisfiable_def])
\\ Cases_on ‘∃c n. step = ImplyAdd n c’
THEN1 (
fs[check_lstep_def] \\
every_case_tac \\
gvs[insert_fml_def]>>
drule imp_thm>>
DEP_REWRITE_TAC[core_only_fml_insert] >> fs[id_ok_def]>>
rw[]>>fs[sat_implies_def,core_only_fml_def]
>- (
rw[lookup_insert]>>fs[]>>
first_x_assum(qspec_then`id` mp_tac)>>
fs[domain_lookup])
>- gvs[lookup_insert,AllCaseEqs()]
>- (
fs[lookup_core_only_def,core_only_fml_def]>>
every_case_tac>>fs[satisfies_def,PULL_EXISTS]>>
metis_tac[]))
THEN1 (
rw[Once check_lstep_def]
\\ every_case_tac \\ gvs [])
QED
(* TODO
Theorem check_lstep_compact:
(∀step b core fml id fml' core' id'.
(∀c. c ∈ range fml ⇒ compact c) ∧ lstep_ok step ∧
check_lstep step b core fml id = SOME(fml',core',id') ⇒
(∀c. c ∈ range fml' ⇒ compact c)) ∧
(∀steps b core fml id fml' core' id'.
(∀c. c ∈ range fml ⇒ compact c) ∧ EVERY lstep_ok steps ∧
check_lsteps steps b core fml id = SOME(fml',core',id') ⇒
(∀c. c ∈ range fml' ⇒ compact c))
Proof
ho_match_mp_tac check_lstep_ind
\\ rpt strip_tac
>- (
Cases_on`step`>>fs[check_lstep_def]
>- metis_tac[range_FOLDL_delete,SUBSET_DEF]
>- (
gvs[insert_fml_def,AllCaseEqs()]>>
drule range_insert_2>>rw[]>>
metis_tac[check_cutting_compact])
\\ gvs[AllCaseEqs(),insert_fml_def]
\\ imp_res_tac range_insert_2 \\ gvs [] )
>- fs[Once check_lstep_def]
>- (
qpat_x_assum`_ = SOME _` mp_tac>>
simp[Once check_lstep_def]>>
every_case_tac>>fs[])
QED
*)
Type subst_raw = ``:(num , bool + num lit) alist``;
(*
The subproof type is complicated and explained as follows:
1) At the outermost layer, we have an alist indexed by
num option:
NONE -> no scope
SOME n -> the n-th scope
2) Within each of the scopes we again have an alist indexed by
((num + num) # num) option:
NONE -> "top-level" step in that scope
SOME (INL n, id) -> database proofgoal n, contradiction at id
SOME (INR n, id) -> # proofgoal n, contradiction at id
*)
Type subproof = ``:((((num + num) # num) option, (lstep list)) alist)``;
Type scope = ``:(num option, subproof) alist``;
(* Steps that preserve satisfiability modulo
a preserved set of variables *)
Datatype:
sstep =
| Lstep lstep (* Id representing a contradiction *)
| Red npbc subst_raw scope (num option)
End
Definition list_list_insert_def:
list_list_insert [] ys = LN ∧
list_list_insert xs [] = LN ∧
list_list_insert (x::xs) (y::ys) = insert x y (list_list_insert xs ys)
End
Theorem lookup_list_list_insert:
∀xs ys. lookup n (list_list_insert xs ys) = ALOOKUP (ZIP(xs,ys)) n
Proof
Induct_on ‘xs’ \\ Cases_on ‘ys’ \\ fs [list_list_insert_def,ZIP_def]
\\ rw [lookup_insert]
QED
Type ord_s = ``:aspo # (num # bool) option vector # (num # bool) option vector
# (bool option) vector # unit option vector``;
(* This characterizes the redundancy used in ord_s *)
Definition good_ord_s_def:
good_ord_s (((f,g,us,vs,as),xs),us_xs,vs_xs,xsv,asv) <=>
us_xs = spt_to_vec (list_list_insert us xs) ∧
vs_xs = spt_to_vec (list_list_insert vs xs) ∧
xsv = spt_to_vec (fromAList xs) ∧
asv = spt_to_vec (fromAList (MAP (\n. n,()) as))
End
Definition dom_subst_def:
(dom_subst hs w (NONE: ord_s option) = ([],[])) ∧
(dom_subst hs w (SOME (((f,g,us,vs,as),xs),us_xs,vs_xs,xsv, asv)) =
let ww = (λn.
case vec_lookup us_xs n of
SOME (v,b) =>
SOME (
mk_bit_lit b
(case w v of
NONE => INR (Pos v)
| SOME res => res))
| NONE =>
OPTION_MAP (INR o mk_lit) (vec_lookup vs_xs n)) in
(MAP (subst ww) f,
if hs then MAP (subst ww) g else []))
End
(* The list of # subgoals for redundancy
internally implicitly numbered by the list order, i.e.,
#0, #1, ...,
and the list of scopes (just one). *)
Definition red_subgoals_def:
red_subgoals ord s def obj hs =
let (fs,gs) = dom_subst hs s ord in
let c0 = subst s def in (**)
let cobj =
case obj of NONE => []
| SOME l => [[not (obj_constraint s l)]] in
([not c0]::(MAP (λc. [not c]) fs) ++ cobj,
[gs])
End
(* Apply a substitution where needed *)
Definition extract_clauses_def:
(extract_clauses f b fml rsubs [] acc =
SOME (REVERSE acc)) ∧
(extract_clauses f b fml rsubs (cpf::pfs) acc =
case cpf of
(NONE,pf) =>
extract_clauses f b fml rsubs pfs ((NONE,pf)::acc)
| (SOME (INL n,i),pf) =>
(case lookup_core_only b fml n of
NONE => NONE
| SOME c =>
extract_clauses f b fml rsubs pfs
((SOME ([not (subst f c)],i),pf)::acc))
| (SOME (INR u,i),pf) =>
if u < LENGTH rsubs then
extract_clauses f b fml rsubs pfs ((SOME (EL u rsubs,i),pf)::acc)
else
NONE)
End