Skip to content

Commit 916fcf4

Browse files
committed
Refactor AVL
1 parent e76c39d commit 916fcf4

1 file changed

Lines changed: 88 additions & 80 deletions

File tree

  • theories/Storage/Instances

theories/Storage/Instances/AVL.v

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,100 @@ From Coq Require Import
55
Require Import Classes.
66

77
Module Type Make (E : OrderedType).
8-
Include FMapAVL.Make E.
8+
Module M := FMapAVL.Make E.
9+
10+
Definition t := M.t.
911

1012
Parameter dec_eq_is_eq : forall a b, E.eq a b <-> a = b.
1113

12-
Lemma fmap_new_empty {ValT : Type} k : find k (@empty ValT) = None.
13-
Proof.
14-
remember (find k (empty ValT)) as maybe_v.
15-
destruct maybe_v as [v|].
16-
- exfalso.
17-
specialize (@empty_1 ValT k v) as H.
18-
symmetry in Heqmaybe_v. now apply find_2 in Heqmaybe_v.
19-
- reflexivity.
20-
Qed.
14+
Section defn.
15+
Context {ValT : Type}.
16+
17+
Lemma fmap_new_empty k : M.find k (@M.empty ValT) = None.
18+
Proof.
19+
remember (M.find k (M.empty ValT)) as maybe_v.
20+
destruct maybe_v as [v|].
21+
- exfalso.
22+
specialize (@M.empty_1 ValT k v) as H.
23+
symmetry in Heqmaybe_v. now apply M.find_2 in Heqmaybe_v.
24+
- reflexivity.
25+
Qed.
2126

22-
Lemma fmap_keep {ValT : Type} s k (v : ValT) : find k (add k v s) = Some v.
23-
Proof.
24-
specialize (@add_1 ValT s k k v (E.eq_refl k)) as H.
25-
now apply find_1.
26-
Qed.
27+
Lemma fmap_keep s k (v : ValT) : M.find k (M.add k v s) = Some v.
28+
Proof.
29+
specialize (@M.add_1 ValT s k k v (E.eq_refl k)) as H.
30+
now apply M.find_1.
31+
Qed.
2732

28-
Lemma fmap_distinct {ValT : Type} s k1 k2 (v2 : ValT) :
29-
k1 <> k2 ->
30-
find k1 s = find k1 (add k2 v2 s).
31-
Proof.
32-
intros Hk.
33-
assert (Hk' : ~E.eq k2 k1). {
34-
intros Habsurd.
35-
apply not_eq_sym in Hk.
36-
now apply dec_eq_is_eq in Habsurd.
37-
}
38-
apply Raw.Proofs.find_find.
39-
intros v. split.
40-
- intros H.
41-
apply find_1.
42-
apply find_2 in H.
43-
now apply add_2.
44-
- intros H.
45-
apply find_1.
46-
apply find_2 in H.
47-
eapply add_3; eauto.
48-
Qed.
33+
Lemma fmap_distinct s k1 k2 (v2 : ValT) :
34+
k1 <> k2 ->
35+
M.find k1 s = M.find k1 (M.add k2 v2 s).
36+
Proof.
37+
intros Hk.
38+
assert (Hk' : ~E.eq k2 k1). {
39+
intros Habsurd.
40+
apply not_eq_sym in Hk.
41+
now apply dec_eq_is_eq in Habsurd.
42+
}
43+
apply M.Raw.Proofs.find_find.
44+
intros v. split.
45+
- intros H.
46+
apply M.find_1.
47+
apply M.find_2 in H.
48+
now apply M.add_2.
49+
- intros H.
50+
apply M.find_1.
51+
apply M.find_2 in H.
52+
eapply M.add_3; eauto.
53+
Qed.
4954

50-
Lemma fmap_delete_keep {ValT : Type} s k:
51-
@find ValT k (remove k s) = None.
52-
Proof.
53-
specialize (@remove_1 ValT s k k (E.eq_refl k)) as H.
54-
remember (remove (elt:=ValT) k s) as s'.
55-
unfold find, remove, In in H.
56-
destruct s' as [s' bst'].
57-
apply Raw.Proofs.not_find_iff.
58-
- assumption.
59-
- now rewrite Raw.Proofs.In_alt in H.
60-
Qed.
55+
Lemma fmap_delete_keep s k:
56+
@M.find ValT k (M.remove k s) = None.
57+
Proof.
58+
specialize (@M.remove_1 ValT s k k (E.eq_refl k)) as H.
59+
remember (M.remove k s) as s'.
60+
unfold M.find, M.remove, M.In in H.
61+
destruct s' as [s' bst'].
62+
apply M.Raw.Proofs.not_find_iff.
63+
- assumption.
64+
- now rewrite M.Raw.Proofs.In_alt in H.
65+
Qed.
6166

62-
Lemma fmap_delete_distinct {ValT : Type} (s : t ValT) k1 k2 :
63-
k1 <> k2 ->
64-
find k1 s = find k1 (remove k2 s).
65-
Proof.
66-
intros Hk.
67-
assert (Hk' : ~E.eq k2 k1). {
68-
intros Habsurd.
69-
apply not_eq_sym in Hk.
70-
now apply dec_eq_is_eq in Habsurd.
71-
}
72-
apply Raw.Proofs.find_find.
73-
intros v1. split.
74-
- intros H.
75-
apply find_1.
76-
apply find_2 in H.
77-
now apply remove_2.
78-
- intros H.
79-
apply find_1.
80-
apply find_2 in H.
81-
eapply remove_3; eauto.
82-
Qed.
67+
Lemma fmap_delete_distinct (s : t ValT) k1 k2 :
68+
k1 <> k2 ->
69+
M.find k1 s = M.find k1 (M.remove k2 s).
70+
Proof.
71+
intros Hk.
72+
assert (Hk' : ~E.eq k2 k1). {
73+
intros Habsurd.
74+
apply not_eq_sym in Hk.
75+
now apply dec_eq_is_eq in Habsurd.
76+
}
77+
apply M.Raw.Proofs.find_find.
78+
intros v1. split.
79+
- intros H.
80+
apply M.find_1.
81+
apply M.find_2 in H.
82+
now apply M.remove_2.
83+
- intros H.
84+
apply M.find_1.
85+
apply M.find_2 in H.
86+
eapply M.remove_3; eauto.
87+
Qed.
8388

84-
Global Instance fmapStorage {Val : Type} : @Storage E.t Val (t Val) :=
85-
{|
86-
new := @empty Val;
87-
get := @find Val;
88-
put := @add Val;
89-
delete := @remove Val;
90-
new_empty := @fmap_new_empty Val;
91-
keep := @fmap_keep Val;
92-
distinct := @fmap_distinct Val;
93-
delete_keep := @fmap_delete_keep Val;
94-
delete_distinct := @fmap_delete_distinct Val;
95-
|}.
89+
Global Instance fmapStorage : @Storage E.t ValT (t ValT) :=
90+
{|
91+
new := @M.empty ValT;
92+
get := @M.find ValT;
93+
put := @M.add ValT;
94+
delete := @M.remove ValT;
95+
new_empty := fmap_new_empty;
96+
keep := fmap_keep;
97+
distinct := fmap_distinct;
98+
delete_keep := fmap_delete_keep;
99+
delete_distinct := fmap_delete_distinct;
100+
|}.
101+
End defn.
96102
End Make.
103+
104+
Print Module Make.

0 commit comments

Comments
 (0)