-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwavl_noauto.v
1095 lines (986 loc) · 37.2 KB
/
wavl_noauto.v
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
(*** Weak AVL Trees ***)
(*+
See "Rank-Balanced Trees" by Haeupler, Sen, Tarjan
[http://www.cs.princeton.edu/~sssix/papers/rb-trees-talg.pdf].
*)
(* A non-automated (actually, semi-automated) version of wavl.v, with no
tailored specific solver tactics. Note that the general "boom" and "ss"
automation tactics are still used throughout. *)
Set Ltac Profiling.
Reset Ltac Profile.
Require Import mindless.elist.
Require Import mindless.ezbool.
Require Import mindless.utils.
Require Import mindless.hypiter.
Generalizable All Variables.
Set Default Goal Selector "all".
Context {A : Set}.
Context {ordA : Ordered A}.
Context {compare : A -> A -> comparison}.
Context {compare_spec : forall x y, CompareSpecT (eq x y) (lt x y) (lt y x) (compare x y)}.
Notation "x =<> y" := (compare_spec x y) (at level 70, only parsing).
Notation EL := ##(list A).
Notation EZ := ##Z.
Notation EB := ##bool.
Open Scope E_scope.
Inductive wavltree (k : EZ)(pg lg rg : EB)(c : EL) : Set :=
| Node(g : bool)(d : A)
(_: #g = pg)
`(_: c = lc++[d]++rc)
`(lw : wavltree (k - #1 - ^lg) lg llg lrg lc)
`(rw : wavltree (k - #1 - ^rg) rg rlg rrg rc)
(leaf_rule: k = #1 -> lg = #false \/ rg = #false)
(_: Esorted c)
| Missing(_: c = [])(_: k = - #1)(_: lg = #false)(_: rg = #false).
(**********************************************************************)
(*Tactic notations to make the proofs more readable:*)
Tactic Notation "??" constr(H) :=
(tryif (is_var H; try (clear H;
fail 1))
then case_eq H
else case H);
dintros.
Tactic Notation "??" constr(H) "on" constr(H') :=
case H with (1:=H'); dintros.
Tactic Notation "just" tactic1(tac) := let x := tac in exact x.
Ltac left_child w :=
lazymatch type of w with
wavltree _ _ _ _ (?C++[_]++_) =>
lazymatch goal with
L:wavltree _ _ _ _ C |- _ => L
end
end.
Notation "'left_child' w" := ltac:(just left_child w)
(at level 199, no associativity, only parsing).
Ltac right_child w :=
lazymatch type of w with
wavltree _ _ _ _ (_++[_]++?C) =>
lazymatch goal with
R:wavltree _ _ _ _ C |- _ => R
end
end.
Notation "'right_child' w" := ltac:(just right_child w)
(at level 199, no associativity, only parsing).
Ltac datum w :=
lazymatch type of w with
wavltree _ _ _ _ (_++[?D]++_) => D
end.
Notation "'datum' w" := ltac:(just datum w)
(at level 199, no associativity, only parsing).
Ltac gap w :=
lazymatch type of w with
wavltree _ # ?G _ _ _ => G
end.
Notation "'gap' w" := ltac:(just gap w)
(at level 199, no associativity, only parsing).
Notation "'pick' x" := ltac:(just pick x)
(at level 199, no associativity, only parsing).
(**********************************************************************)
Section Lemmas.
Lemma wavl_min_rank`(w : wavltree k g lg rg c) : k >= - #1.
Proof.
induction w. boom.
Qed.
Lemma wavl_node_min_rank`(w : wavltree k g lg rg c) : c <> [] -> k >= #0.
Proof.
?? w. 1:pose proof (wavl_min_rank (left_child w)). boom.
Qed.
Lemma wavl_node_nonempty`(w : wavltree k g lg rg c) : k >= #0 -> c <> [].
Proof.
?? w. boom.
Qed.
Lemma missing_contents`(w : wavltree (- #1) g lg rg c) : c = [].
Proof.
pose proof (wavl_node_min_rank w) as H.
?? w. boom.
Qed.
Lemma missing_rank`(w : wavltree k g lg rg []) : k = - #1.
Proof.
?? w.
- fnenil.
- reflexivity.
Qed.
Lemma wavl_is_sorted`(w : wavltree k g lg rg c) : Esorted c.
Proof.
?? w.
- assumption.
- repeat econstructor.
Qed.
End Lemmas.
Ltac bang_setup_tactic ::= idtac;
let f H :=
(lazymatch type of H with
| wavltree _ _ _ _ _ =>
first [apply missing_rank in H
|apply wavl_node_min_rank in H; [|assumption||fnenil]
|apply wavl_min_rank in H]
| _ => idtac
end) in
allhyps_introing f.
Ltac ss_setup_tactic := idtac;
let f H := (try apply wavl_is_sorted in H) in
allhyps_introing f.
Ltac ss := ss_setup_tactic; unerase; solve[solve_sorted].
(**********************************************************************)
Section Check_Leaf_Rule.
Local Set Asymmetric Patterns.
Local Definition is_leaf`(w : wavltree k g lg rg c) : bool :=
match w with
| Node _ _ _ _ _ _ _ _ (Missing _ _ _ _) _ _ (Missing _ _ _ _) _ _ => true
| _ => false
end.
Local Ltac destruct_match := idtac;
match goal with |- context[match ?X with _ => _ end] => destruct X end.
Local Lemma leaf_rule_works`(w : wavltree k g lg rg c) : k = #0 <-> is_leaf w = true.
Proof.
unfold is_leaf.
repeat destruct_match.
boom.
Qed.
End Check_Leaf_Rule.
(**********************************************************************)
Section Find.
Inductive findResult(x : A)(c : EL) : Set :=
| Found`(_: c = lc++[x]++rc)
| NotFound(_: ENotIn x c).
Fixpoint find(x : A)`(w : wavltree k g lg rg c) : findResult x c.
Proof.
?? w.
- ?? (x =<> (datum w)).
+ eapply Found. reflexivity.
+ ?? (find x) on (left_child w).
* eapply Found. rootify x. reflexivity.
* eapply NotFound. ss.
+ ?? (find x) on (right_child w).
* eapply Found. rootify x. reflexivity.
* eapply NotFound. ss.
- eapply NotFound. ss.
Qed.
End Find.
Section SetGap.
Definition setgap`(w : wavltree k ig lg rg c)(og : bool) : wavltree k #og lg rg c.
Proof.
?? w.
- eapply Node. reflexivity + eassumption.
- eapply Missing. reflexivity.
Qed.
End SetGap.
Section GetGap.
Definition getgap`(w : wavltree k g lg rg c) : { g' | c <> [] -> #g' = g}.
Proof.
?? w.
- eexists. reflexivity.
- exists false. boom.
Qed.
Definition getgap2`(w : wavltree k g lg rg c) : { g' | k >= #0 -> #g' = g}.
Proof.
?? w.
- eexists. reflexivity.
- exists false. boom.
Qed.
End GetGap.
Section IsGap.
Notation "x ?= y" := (Bool.bool_dec x y) (only parsing).
Definition isgap`(w : wavltree k g lg rg c)(g' : bool) : {k >= #0 /\ #g' = g} + {k= - #1 \/ #g' <> g}.
Proof.
?? w.
- ?? (g' ?= (gap w)).
+ left. boom.
+ right. boom.
- right. boom.
Qed.
End IsGap.
Section IsMissing.
Definition isMissing`(w : wavltree k g lg rg c) : {c = [] /\ k = - #1} + {c <> [] /\ k >= #0}.
Proof.
?? w.
- right. boom.
- left. boom.
Qed.
End IsMissing.
Ltac start_node := eapply Node; [reflexivity|reflexivity|..].
Ltac missing := eapply Missing; [reflexivity|boom|reflexivity|reflexivity].
Ltac use w := idtac; force refine w by boom.
Ltac use_regap w := idtac; force refine (setgap w _) by boom.
Ltac use_node := idtac;
lazymatch goal with
w: wavltree _ _ _ _ ?C |- wavltree _ _ _ _ ?C => use w + use_regap w
end.
Ltac finish := idtac;
match goal with
| |- Esorted _ => ss
| _ => boom
end.
Section Insert_Rotations.
Definition irot1`(lw : wavltree k #false llg lrg lc)(x : A)`(rw : wavltree (k - #2) #true rlg rrg rc)
: llg = Enegb lrg -> Esorted(lc++[x]++rc) -> forall g, wavltree k #g #false #false (lc++[x]++rc).
Proof.
(* lw is higher than rw (k > k-2), so it makes sense to examine lw first *)
?? lw.
- (* The right child of lw, rw0, needs to be combined somehow with rw. rw0
might be at the same height or 1 above rw, so that needs to be
determined first. But, if we first examine rw0 before examining its
gap, we can eliminate the case when it is missing *)
?? (right_child lw).
+ (* rw0 is not missing, so examine its gap now *)
?? (gap (right_child lw)).
* (* rw0 has a gap, so it is at k-2, the same as rw, which means the two
can be combined easily with the result not havng a gap, so still
fitting under k, rooted where lw already is *)
rootify (datum lw). start_node.
-- exact (left_child lw).
-- rootify x. start_node.
++ use_regap (right_child lw).
++ use_regap rw.
++ finish.
++ finish.
-- finish.
-- finish.
* (* rw0 has no gap, so we have to split it up with its left child lw1
pairing with lw0, the regapped left child of lw, and its right
child rw1 pairing with regapped rw, with the new root where rw0
is *)
rootify (datum (right_child lw)). start_node.
-- start_node.
++ use_regap (left_child lw).
++ use (left_child (right_child lw)).
++ finish.
++ finish.
-- start_node.
++ use (right_child (right_child lw)).
++ use_regap rw.
++ finish.
++ finish.
-- finish.
-- finish.
+ (* rw0 is missing - note that its sequence is now [] *)
assert (k = #1) as -> by boom. rsimp.
(* note that his implies rw is missing as well, because its height is -1 *)
apply missing_contents in rw as ->.
rootify (datum lw). start_node.
* use (left_child lw).
* start_node.
-- missing.
-- missing.
-- finish.
-- finish.
* finish.
* finish.
- (* lw is missing, but that's not possible because rw is lower, so there is
a contradiction *)
boom.
Qed.
Definition irot2`(lw : wavltree (k - #2) #true llg lrg lc)(x : A)`(rw : wavltree k #false rlg rrg rc)
: Enegb rlg = rrg -> Esorted(lc++[x]++rc) -> forall g, wavltree k #g #false #false (lc++[x]++rc).
Proof.
?? rw.
- ?? (left_child rw).
+ ?? (gap (left_child rw)).
* rootify (datum rw). start_node.
-- start_node.
++ use_node. (*use_regap lw.*)
++ use_node. (*use_regap (left_child rw).*)
++ finish.
++ finish.
-- use_node. (*use (right_child rw).*)
-- finish.
-- finish.
* rootify (datum (left_child rw)). start_node.
-- start_node.
++ use_node. (*use_regap lw.*)
++ use_node. (*use (left_child (left_child rw)).*)
++ finish.
++ finish.
-- start_node.
++ use_node. (*use (right_child (left_child rw)).*)
++ use_node. (*use_regap (right_child rw).*)
++ finish.
++ finish.
-- finish.
-- finish.
+ assert (k = #1) as -> by boom. rsimp. apply missing_contents in lw as ->.
rootify (datum rw). start_node.
* start_node.
-- missing.
-- missing.
-- finish.
-- finish.
* use_node. (*use (right_child rw).*)
* finish.
* finish.
- boom.
Qed.
End Insert_Rotations.
Ltac unerase_gaps :=
subst;
let f H :=
try
lazymatch type of H with
wavltree _ ?G _ _ _ =>
is_var G;
case (getgap H);
let X := fresh in
let G' := fresh in
intros G' X;
first [specialize (X ltac:(assumption||fnenil))
|specialize (X (wavl_node_nonempty H ltac:(boom)))];
rewrite <-X in *;
clear X G;
rename G' into G
end in
allhyps_td f. (*cannot be allhyps_introing because of rewrite?*)
Section Insert.
Inductive insertedHow(ik ok : EZ)(ig og olg org : EB) : Set :=
| ISameK(_: ok = ik)(_: og = ig)
| IWasMissing(_: ik = - #1)(_: ok = #0)(_: og = #false)
| IHigherK(_: ik >= #0)(_: ok = ik + #1)(_: olg = Enegb org)(_: og = #false).
Inductive insertResult(x: A)(k : EZ)(g lg rg : EB)(c : EL) : Set :=
| Inserted`(_: c = lc++rc)
`(ow: wavltree ok og olg org (lc++[x]++rc))
`(_: insertedHow k ok g og olg org)
| FoundByInsert`(_: c = lc++[x]++rc).
Lemma nilnilnil : [] = [] ++ [] :> EL.
Proof.
rewrite Eapp_nil_l.
reflexivity.
Qed.
Ltac tree_with x := idtac;
match goal with
H:wavltree _ _ _ _ ?C |- _ =>
lazymatch C with context[x] => H end
end.
Notation "'tree_with' x" := ltac:(just tree_with x)
(at level 199, no associativity, only parsing).
Fixpoint insert(x : A)`(w : wavltree k g lg rg c) : insertResult x k g lg rg c.
Proof.
?? w.
- ?? (x =<> (datum w)).
+ eapply FoundByInsert. reflexivity.
+ ?? (insert x) on (left_child w).
* ?? (pick insertedHow).
-- assoc 0. eapply Inserted.
++ reflexivity.
++ rootify (datum w). start_node.
** use_node. (*use (tree_with x).*)
** use_node. (*use (right_child w).*)
** finish.
** finish.
++ eapply ISameK. boom.
-- ?? (isMissing (right_child w)).
++ assoc 0. eapply Inserted.
** reflexivity.
** rootify (datum w). start_node.
--- use_node. (*use (tree_with x).*)
--- missing.
--- finish.
--- finish.
** eapply IHigherK. boom.
++ assoc 0. eapply Inserted.
** reflexivity.
** rootify (datum w). start_node.
--- use_node. (*use (tree_with x).*)
--- use_node. (*use (right_child w).*)
--- finish.
--- finish.
** eapply ISameK. boom.
-- unerase_gaps. ?? (gap (left_child w)).
++ assoc 0. eapply Inserted.
** reflexivity.
** rootify (datum w). start_node.
--- use_node. (*use (tree_with x).*)
--- use_node. (*use (right_child w).*)
--- finish.
--- finish.
** eapply ISameK. boom.
++ ?? (isgap (right_child w) false).
** assoc 0. eapply Inserted.
--- reflexivity.
--- rootify (datum w). start_node.
+++ use_node. (*use (tree_with x).*)
+++ use_node. (*use_regap (right_child w).*)
+++ finish.
+++ finish.
--- eapply IHigherK. boom.
** assoc 0. eapply Inserted.
--- reflexivity.
--- rootify (datum w). eapply irot1.
+++ use_node. (*use (tree_with x).*)
+++ use_node. (*use (right_child w).*)
+++ finish.
+++ finish.
--- eapply ISameK. boom.
* rootify x. eapply FoundByInsert. reflexivity.
+ ?? (insert x) on (right_child w).
* ?? (pick insertedHow).
-- assoc 2. eapply Inserted.
++ reflexivity.
++ rootify (datum w). start_node.
** use_node. (*use (left_child w).*)
** use_node. (*use (tree_with x).*)
** finish.
** finish.
++ eapply ISameK. boom.
-- ?? (isMissing (left_child w)).
++ assoc 2. eapply Inserted.
** reflexivity.
** rootify (datum w). start_node.
--- missing.
--- use_node. (*use (tree_with x).*)
--- finish.
--- finish.
** eapply IHigherK. boom.
++ assoc 2. eapply Inserted.
** reflexivity.
** rootify (datum w). start_node.
--- use_node. (*use (left_child w).*)
--- use_node. (*use (tree_with x).*)
--- finish.
--- finish.
** eapply ISameK. boom.
-- unerase_gaps. ?? (gap (right_child w)).
++ assoc 2. eapply Inserted.
** reflexivity.
** rootify (datum w). start_node.
--- use_node. (*use (left_child w).*)
--- use_node. (*use (tree_with x).*)
--- finish.
--- finish.
** eapply ISameK. boom.
++ ?? (isgap (left_child w) false).
** assoc 2. eapply Inserted.
--- reflexivity.
--- rootify (datum w). start_node. all: [>use_node|use_node|..].
(* +++ use_regap (left_child w).
+++ use (tree_with x). *)
+++ finish.
+++ finish.
--- eapply IHigherK. boom.
** assoc 2. eapply Inserted.
--- reflexivity.
--- rootify (datum w). eapply irot2.
+++ use_node. (*use (left_child w).*)
+++ use_node. (*use (tree_with x).*)
+++ finish.
+++ finish.
--- eapply ISameK. boom.
* rootify x. eapply FoundByInsert. reflexivity.
- eapply Inserted.
+ eapply nilnilnil.
+ start_node.
* missing.
* missing.
* finish.
* finish.
+ eapply IWasMissing. boom.
Qed.
End Insert.
(**********************************************************************)
Section TryLowering.
Inductive tryLoweringResult(k : EZ)(g lg rg : EB)(c : EL) : Set :=
| TLlowered(_: lg = #true)(_: rg = #true)(ow: wavltree (k - #1) g #false #false c)
| TLtooLow(_: lg = #false \/ rg = #false).
Definition tryLowering`(w : wavltree k g lg rg c) : tryLoweringResult k g lg rg c.
Proof.
?? w.
- ?? (isgap (left_child w) true).
+ ?? (isgap (right_child w) true).
* eapply TLlowered.
-- reflexivity.
-- reflexivity.
-- start_node.
++ use_node. (*use_regap (left_child w).*)
++ use_node. (*use_regap (right_child w).*)
++ finish.
++ finish.
* eapply TLtooLow. boom.
+ eapply TLtooLow. boom.
- eapply TLtooLow. boom.
Qed.
End TryLowering.
Inductive deletedHow(ik ok : EZ)(ig og : EB) : Set :=
| DSameK(_: ok = ik)(_: og = ig)
| DLowerK(_: ok = ik - #1)(_: og = #true).
Inductive delpair(k : EZ)(g : EB)(c : EL) : Set :=
| Delout`(dh : deletedHow k ok g og)`(ow : wavltree ok og olg org c).
Section Delete_Rotations.
Definition drot1`(lw : wavltree (k - #3) #true llg lrg lc)(x : A)`(rw : wavltree (k - #1) #false rlg rrg rc)
: rlg = #false \/ rrg = #false -> Esorted(lc++[x]++rc) -> forall g, delpair k #g (lc++[x]++rc).
Proof.
?? rw.
- ?? (left_child rw).
+ ?? (isgap (right_child rw) false).
* eapply Delout.
-- apply DSameK.
++ reflexivity.
++ reflexivity.
-- rootify (datum rw). start_node.
++ start_node.
** use_node. (*use lw.*)
** use_node. (*use (left_child rw).*)
** finish.
** finish.
++ use_node. (*use_regap (right_child rw).*)
++ finish.
++ finish.
* eapply Delout.
-- apply DSameK.
++ reflexivity.
++ reflexivity.
-- rootify (datum (left_child rw)). start_node.
++ start_node. 1-2:use_node.
(* ** use_node. (*use_regap lw.*)
** use_node. (*use (left_child (left_child rw)).*)*)
** finish.
** finish.
++ start_node.
** use_node. (*use (right_child (left_child rw)).*)
** use_node. (*use_regap (right_child rw).*)
** finish.
** finish.
++ finish.
++ finish.
+ assert (k = #2) as -> by boom. rsimp. apply missing_contents in lw as ->.
eapply Delout.
* apply DSameK.
-- reflexivity.
-- reflexivity.
* rootify (datum rw). start_node.
-- start_node.
++ missing.
++ missing.
++ finish.
++ finish.
-- use_node. (*use_regap (right_child rw).*)
-- finish.
-- finish.
- boom.
Qed.
Definition drot2`(lw : wavltree (k - #1) #false llg lrg lc)(x : A)`(rw : wavltree (k - #3) #true rlg rrg rc)
: llg = #false \/ lrg = #false -> Esorted(lc++[x]++rc) -> forall g, delpair k #g (lc++[x]++rc).
Proof.
?? lw.
- ?? (right_child lw).
+ ?? (isgap (left_child lw) false).
* eapply Delout.
-- apply DSameK.
++ reflexivity.
++ reflexivity.
-- rootify (datum lw). start_node.
++ use_node. (*use_regap (left_child lw).*)
++ rootify x. start_node.
** use_node. (*use (right_child lw).*)
** use_node. (*use rw.*)
** finish.
** finish.
++ finish.
++ finish.
* eapply Delout.
-- apply DSameK.
++ reflexivity.
++ reflexivity.
-- rootify (datum (right_child lw)). start_node.
++ start_node. 1-2:use_node.
(* ** use_node. (*use_regap (left_child lw).*)
** use_node. (*use (left_child (right_child lw)).*)*)
** finish.
** finish.
++ start_node.
** use_node. (*use (right_child (right_child lw)).*)
** use_node. (*use_regap rw.*)
** finish.
** finish.
++ finish.
++ finish.
+ assert (k = #2) as -> by boom. rsimp. apply missing_contents in rw as ->.
eapply Delout.
* apply DSameK.
-- reflexivity.
-- reflexivity.
* rootify (datum lw). start_node.
-- use_node. (*use_regap (left_child lw).*)
-- start_node.
++ missing.
++ missing.
++ finish.
++ finish.
-- finish.
-- finish.
- boom.
Qed.
End Delete_Rotations.
Section Delete_Minimum.
Inductive delminResult(k : EZ)(g : EB)(c : EL) : Set :=
MinDeleted(min : A)`(_: c = [min]++rc)(dp : delpair k g rc).
Fixpoint delmin`(w : wavltree k g lg rg c) : k >= #0 -> delminResult k g c.
Proof.
?? w.
- ?? (isMissing (left_child w)).
+ eapply MinDeleted.
* rewrite Eapp_nil_l. reflexivity.
* eapply Delout.
-- apply DLowerK.
++ reflexivity.
++ reflexivity.
-- use_node. (*use_regap rw.*)
+ ?? delmin on (left_child w).
* boom.
* ?? (pick delpair). ?? (pick deletedHow).
-- eapply MinDeleted.
++ assoc 0. reflexivity.
++ eapply Delout.
** apply DSameK.
--- reflexivity.
--- reflexivity.
** start_node.
--- use_node. (*use ow.*)
--- use_node. (*use rw.*)
--- finish.
--- finish.
-- ?? (isgap (right_child w) false).
++ ?? (isgap (left_child w) true).
** ?? (tryLowering (right_child w)).
--- eapply MinDeleted.
+++ assoc 0. reflexivity.
+++ eapply Delout.
*** apply DLowerK.
---- reflexivity.
---- reflexivity.
*** start_node.
---- use_node. (*use ow.*)
---- use_node. (*use ow0.*)
---- finish.
---- finish.
--- eapply MinDeleted.
+++ assoc 0. reflexivity.
+++ eapply drot1.
*** use_node. (*use ow.*)
*** use_node. (*use rw.*)
*** finish.
*** finish.
** eapply MinDeleted.
--- assoc 0. reflexivity.
--- eapply Delout.
+++ apply DSameK.
*** reflexivity.
*** reflexivity.
+++ start_node.
*** use_node. (*use ow.*)
*** use_node. (*use rw.*)
*** finish.
*** finish.
++ unerase_gaps. eapply MinDeleted.
** assoc 0. reflexivity.
** eapply Delout.
--- apply DLowerK.
+++ reflexivity.
+++ reflexivity.
--- start_node.
+++ use_node. (*use_regap ow.*)
+++ use_node. (*use_regap rw.*)
+++ finish.
+++ finish.
- boom.
Qed.
End Delete_Minimum.
Section Delete_Maximum.
Inductive delmaxResult(k : EZ)(g : EB)(c : EL) : Set :=
MaxDeleted(max : A)`(_: c = lc++[max])(dp : delpair k g lc).
Fixpoint delmax`(w : wavltree k g lg rg c) : k >= #0 -> delmaxResult k g c.
Proof.
?? w.
- ?? (isMissing (right_child w)).
+ eapply MaxDeleted.
* rewrite Eapp_nil_r. reflexivity.
* eapply Delout.
-- apply DLowerK.
++ reflexivity.
++ reflexivity.
-- use_node. (*use_regap lw.*)
+ ?? delmax on (right_child w).
* boom.
* ?? (pick delpair). ?? (pick deletedHow).
-- eapply MaxDeleted.
++ assoc 2. reflexivity.
++ eapply Delout.
** apply DSameK.
--- reflexivity.
--- reflexivity.
** start_node.
--- use_node. (*use lw.*)
--- use_node. (*use ow.*)
--- finish.
--- finish.
-- ?? (isgap (left_child w) false).
++ ?? (isgap (right_child w) true).
** ?? (tryLowering (left_child w)).
--- eapply MaxDeleted.
+++ assoc 2. reflexivity.
+++ eapply Delout.
*** apply DLowerK.
---- reflexivity.
---- reflexivity.
*** start_node.
---- use_node. (*use ow0.*)
---- use_node. (*use ow.*)
---- finish.
---- finish.
--- eapply MaxDeleted.
+++ assoc 2. reflexivity.
+++ eapply drot2.
*** use_node. (*use lw.*)
*** use_node. (*use ow.*)
*** finish.
*** finish.
** eapply MaxDeleted.
--- assoc 2. reflexivity.
--- eapply Delout.
+++ apply DSameK.
*** reflexivity.
*** reflexivity.
+++ start_node.
*** use_node. (*use lw.*)
*** use_node. (*use ow.*)
*** finish.
*** finish.
++ unerase_gaps. eapply MaxDeleted.
** assoc 2. reflexivity.
** eapply Delout.
--- apply DLowerK.
+++ reflexivity.
+++ reflexivity.
--- start_node.
+++ use_node. (*use_regap lw.*)
+++ use_node. (*use_regap ow.*)
+++ finish.
+++ finish.
- boom.
Qed.
End Delete_Maximum.
Section Delete.
Inductive deleteResult(x : A)(k : EZ)(g : EB)(c : EL) : Set :=
| Deleted`(_: c = lc++[x]++rc)(dp : delpair k g (lc++rc))
| DNotFound(_: ENotIn x c).
Fixpoint delete(x : A)`(w : wavltree k g lg rg c) : deleteResult x k g c.
Proof.
?? w.
- ?? (x =<> (datum w)).
+ ?? (isMissing (left_child w)).
* eapply Deleted.
-- reflexivity.
-- eapply Delout.
++ apply DLowerK.
** reflexivity.
** reflexivity.
++ rewrite Eapp_nil_l. use_node. (*use_regap rw.*)
* ?? (isMissing (right_child w)).
-- eapply Deleted.
++ reflexivity.
++ eapply Delout.
** apply DLowerK.
--- reflexivity.
--- reflexivity.
** rewrite Eapp_nil_r. use_node. (*use_regap lw.*)
-- unerase_gaps. ?? (gap (left_child w)).
++ ?? (delmin (right_child w)).
** boom.
** ?? (pick delpair). ?? (pick deletedHow).
--- eapply Deleted.
+++ reflexivity.
+++ eapply Delout.
*** apply DSameK.
---- reflexivity.
---- reflexivity.
*** start_node.
---- use_node. (*use lw.*)
---- use_node. (*use ow.*)
---- finish.
---- finish.
--- eapply Deleted.
+++ reflexivity.
+++ eapply Delout.
*** apply DLowerK.
---- reflexivity.
---- reflexivity.
*** start_node.
---- use_node. (*use_regap lw.*)
---- use_node. (*use_regap ow.*)
---- finish.
---- finish.
++ ?? (delmax (left_child w)).
** boom.
** ?? (pick delpair). ?? (pick deletedHow).
--- eapply Deleted.
+++ reflexivity.
+++ eapply Delout.
*** apply DSameK.
---- reflexivity.
---- reflexivity.
*** assoc 0. start_node.
---- use_node. (*use ow.*)
---- use_node. (*use rw.*)
---- finish.
---- finish.
--- eapply Deleted.
+++ reflexivity.
+++ eapply Delout.
*** apply DSameK.
---- reflexivity.
---- reflexivity.
*** assoc 0. start_node.
---- use_node. (*use ow.*)
---- use_node. (*use rw.*)
---- finish.
---- finish.
+ ?? (delete x) on (left_child w).
* ?? (pick delpair). ?? (pick deletedHow).
-- eapply Deleted.
++ rootify x. reflexivity.
++ eapply Delout.
** apply DSameK.
--- reflexivity.
--- reflexivity.
** rootify d. start_node.
--- use_node. (*use ow.*)
--- use_node. (*use rw.*)
--- finish.
--- finish.
-- unerase_gaps. ?? (gap (left_child w)).
++ unerase_gaps. ?? (gap (right_child w)).
** eapply Deleted.
--- rootify x. reflexivity.
--- eapply Delout.
+++ apply DLowerK.
*** reflexivity.
*** reflexivity.
+++ rootify d. start_node.
*** use_node. (*use ow.*)
*** use_node. (*use_regap rw.*)
*** finish.
*** finish.
** ?? (tryLowering (right_child w)).
--- eapply Deleted.
+++ rootify x. reflexivity.
+++ eapply Delout.
*** apply DLowerK.
---- reflexivity.
---- reflexivity.
*** rootify d. start_node.
---- use_node. (*use ow.*)
---- use_node. (*use ow0.*)
---- finish.
---- finish.
--- eapply Deleted.
+++ rootify x. reflexivity.
+++ rootify d. eapply drot1.
*** use_node. (*use ow.*)
*** use_node. (*use rw.*)
*** finish.
*** finish.
++ ?? (isMissing (right_child w)).
** eapply Deleted.
--- rootify x. reflexivity.
--- rootify d. eapply Delout.
+++ apply DLowerK.
*** reflexivity.
*** reflexivity.
+++ start_node.
*** use_node. (*use_regap ow.*)
*** missing.
*** finish.
*** finish.
** eapply Deleted.
--- rootify x. reflexivity.
--- eapply Delout.
+++ apply DSameK.
*** reflexivity.
*** reflexivity.
+++ rootify d. start_node.
*** use_node. (*use ow.*)
*** use_node. (*use rw.*)