comparison src/coq/Semantics.v @ 635:75c7a69354d6

Coq formalization uses TDisjoint
author Adam Chlipala <adamc@hcoop.net>
date Tue, 24 Feb 2009 16:08:14 -0500
parents d828b143e147
children 705cb41ac7d0
comparison
equal deleted inserted replaced
634:6302b10dbe0e 635:75c7a69354d6
46 | KName => name 46 | KName => name
47 | KArrow k1 k2 => kDen k1 -> kDen k2 47 | KArrow k1 k2 => kDen k1 -> kDen k2
48 | KRecord k1 => row (kDen k1) 48 | KRecord k1 => row (kDen k1)
49 end. 49 end.
50 50
51 Fixpoint kDefault (k : kind) : kDen k := 51 Definition disjoint T (r1 r2 : row T) :=
52 match k return kDen k with 52 forall n, match r1 n, r2 n with
53 | KType => unit 53 | Some _, Some _ => False
54 | KName => defaultName 54 | _, _ => True
55 | KArrow _ k2 => fun _ => kDefault k2 55 end.
56 | KRecord _ => fun _ => None
57 end.
58 56
59 Fixpoint cDen k (c : con kDen k) {struct c} : kDen k := 57 Fixpoint cDen k (c : con kDen k) {struct c} : kDen k :=
60 match c in con _ k return kDen k with 58 match c in con _ k return kDen k with
61 | CVar _ x => x 59 | CVar _ x => x
62 | Arrow c1 c2 => cDen c1 -> cDen c2 60 | Arrow c1 c2 => cDen c1 -> cDen c2
73 end 71 end
74 | CMap k1 k2 => fun f r n => match r n with 72 | CMap k1 k2 => fun f r n => match r n with
75 | None => None 73 | None => None
76 | Some T => Some (f T) 74 | Some T => Some (f T)
77 end 75 end
78 | CGuarded _ _ c1 c2 c => 76 | TGuarded _ c1 c2 t => disjoint (cDen c1) (cDen c2) -> cDen t
79 if badName (fun n => match (cDen c1) n, (cDen c2) n with
80 | Some _, Some _ => false
81 | _, _ => true
82 end)
83 then kDefault _
84 else cDen c
85 end. 77 end.
86 78
87 Theorem subs_correct : forall k1 (c1 : con kDen k1) k2 (c2 : _ -> con kDen k2) c2', 79 Theorem subs_correct : forall k1 (c1 : con kDen k1) k2 (c2 : _ -> con kDen k2) c2',
88 subs c1 c2 c2' 80 subs c1 c2 c2'
89 -> cDen (c2 (cDen c1)) = cDen c2'. 81 -> cDen (c2 (cDen c1)) = cDen c2'.
91 repeat match goal with 83 repeat match goal with
92 | [ H : _ |- _ ] => rewrite H 84 | [ H : _ |- _ ] => rewrite H
93 end; intuition. 85 end; intuition.
94 Qed. 86 Qed.
95 87
96 Definition disjoint T (r1 r2 : row T) :=
97 forall n, match r1 n, r2 n with
98 | Some _, Some _ => False
99 | _, _ => True
100 end.
101 Definition dvar k (c1 c2 : con kDen (KRecord k)) := 88 Definition dvar k (c1 c2 : con kDen (KRecord k)) :=
102 disjoint (cDen c1) (cDen c2). 89 disjoint (cDen c1) (cDen c2).
103 90
104 Theorem known_badName : forall T (r1 r2 : row T) T' (v1 v2 : T'),
105 disjoint r1 r2
106 -> (if badName (fun n => match r1 n, r2 n with
107 | Some _, Some _ => false
108 | _, _ => true
109 end)
110 then v1
111 else v2) = v2.
112 intros; match goal with
113 | [ |- context[if ?E then _ else _] ] => destruct E
114 end; firstorder;
115 match goal with
116 | [ H : disjoint _ _, x : name |- _ ] =>
117 generalize (H x);
118 repeat match goal with
119 | [ |- context[match ?E with None => _ | Some _ => _ end] ] => destruct E
120 end; tauto || congruence
121 end.
122 Qed.
123
124 Hint Rewrite known_badName using solve [ auto ] : Semantics.
125
126 Scheme deq_mut := Minimality for deq Sort Prop 91 Scheme deq_mut := Minimality for deq Sort Prop
127 with disj_mut := Minimality for disj Sort Prop. 92 with disj_mut := Minimality for disj Sort Prop.
128 93
129 Ltac deq_disj_correct scm := 94 Ltac deq_disj_correct scm :=
130 let t := repeat progress (simpl; intuition; subst; autorewrite with Semantics) in 95 let t := repeat progress (simpl; intuition; subst) in
131 96
132 let rec use_disjoint' notDone E := 97 let rec use_disjoint' notDone E :=
133 match goal with 98 match goal with
134 | [ H : disjoint _ _ |- _ ] => 99 | [ H : disjoint _ _ |- _ ] =>
135 notDone H; generalize (H E); use_disjoint' 100 notDone H; generalize (H E); use_disjoint'
161 | [ _ : context[match cDen ?C ?E with Some _ => _ | None => _ end] |- _ ] => 126 | [ _ : context[match cDen ?C ?E with Some _ => _ | None => _ end] |- _ ] =>
162 use_disjoint E; destruct (cDen C E) 127 use_disjoint E; destruct (cDen C E)
163 | [ |- context[if ?E then _ else _] ] => destruct E 128 | [ |- context[if ?E then _ else _] ] => destruct E
164 end; t). 129 end; t).
165 130
166 Lemma bool_disjoint : forall T (r1 r2 : row T),
167 (forall nm : name,
168 match r1 nm with
169 | Some _ => match r2 nm with
170 | Some _ => false
171 | None => true
172 end
173 | None => true
174 end = true)
175 -> disjoint r1 r2.
176 intros; intro;
177 match goal with
178 | [ H : _, n : name |- _ ] => generalize (H n)
179 end;
180 repeat match goal with
181 | [ |- context[match ?E with Some _ => _ | None => _ end] ] => destruct E
182 end; tauto || discriminate.
183 Qed.
184
185 Implicit Arguments bool_disjoint [T r1 r2].
186
187 Hint Resolve bool_disjoint.
188 Hint Unfold dvar. 131 Hint Unfold dvar.
189 132
190 Theorem deq_correct : forall k (c1 c2 : con kDen k), 133 Theorem deq_correct : forall k (c1 c2 : con kDen k),
191 deq dvar c1 c2 134 deq dvar c1 c2
192 -> cDen c1 = cDen c2. 135 -> cDen c1 = cDen c2.
222 end; rewrite name_eq_dec_refl; 165 end; rewrite name_eq_dec_refl;
223 destruct (r n1); intuition. 166 destruct (r n1); intuition.
224 Qed. 167 Qed.
225 168
226 Implicit Arguments cut_disjoint [v r]. 169 Implicit Arguments cut_disjoint [v r].
227
228 Set Printing All.
229 170
230 Fixpoint eDen t (e : exp dvar tDen t) {struct e} : tDen t := 171 Fixpoint eDen t (e : exp dvar tDen t) {struct e} : tDen t :=
231 match e in exp _ _ t return tDen t with 172 match e in exp _ _ t return tDen t with
232 | Var _ x => x 173 | Var _ x => x
233 | App _ _ e1 e2 => (eDen e1) (eDen e2) 174 | App _ _ e1 e2 => (eDen e1) (eDen e2)
284 end with 225 end with
285 | None => fun _ => (eDen e2) n 226 | None => fun _ => (eDen e2) n
286 | _ => fun x => x 227 | _ => fun x => x
287 end ((eDen e1) n) 228 end ((eDen e1) n)
288 229
289 | Guarded _ c1 c2 _ e1 => 230 | Guarded _ _ _ _ e1 => fun pf => eDen (e1 pf)
290 match badName (fun n => match (cDen c1) n, (cDen c2) n with 231 | GuardedApp _ _ _ _ e1 Hdisj => (eDen e1) (disj_correct Hdisj)
291 | Some _, Some _ => false
292 | _, _ => true
293 end)
294 as BN return (if BN return Set then _ else _) with
295 | inleft _ => tt
296 | inright pf => eDen (e1 (bool_disjoint pf))
297 end
298 end. 232 end.