You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
subst_term::"term => term \<Rightarrow> var => term"and
190
+
subst_alt_list::"alt_list \<Rightarrow> term \<Rightarrow> var \<Rightarrow> alt_list"and
191
+
subst_alt::"alt \<Rightarrow> term \<Rightarrow> var \<Rightarrow> alt"where
192
+
187
193
"subst_term (Var y) e x = (if x = y then e else Var y)"
188
194
|"subst_term (App e1 e2) e x = App (subst_term e1 e x) (subst_term e2 e x)"
189
195
|"subst_term (TApp e1 \<tau>) e x = TApp (subst_term e1 e x) \<tau>"
190
196
|"subst_term (Ctor D) _ _ = Ctor D"
197
+
|"subst_term (Case t alts) e x = Case (subst_term t e x) (subst_alt_list alts e x)"
191
198
|"atom y \<sharp> (e, x) \<Longrightarrow> subst_term (\<lambda> y:\<tau>. e2) e x = (\<lambda> y:\<tau>. subst_term e2 e x)"
192
199
|"atom y \<sharp> (e, x) \<Longrightarrow> subst_term (\<Lambda> y:k. e2) e x = (\<Lambda> y:k. subst_term e2 e x)"
193
200
|"atom y \<sharp> (e, x) \<Longrightarrow> subst_term (Let y \<tau> e1 e2) e x = Let y \<tau> (subst_term e1 e x) (subst_term e2 e x)"
201
+
202
+
|"subst_alt_list ANil _ _ = ANil"
203
+
|"subst_alt_list (ACons alt alts) e x = ACons (subst_alt alt e x) (subst_alt_list alts e x)"
204
+
205
+
|"atom y \<sharp> (e, x) \<Longrightarrow> subst_alt (MatchVar y t) e x = MatchVar y (subst_term t e x)"
206
+
|"set (map atom tys @ map atom vals) \<sharp>* (e, x) \<Longrightarrow> subst_alt (MatchCtor D tys vals t) e x = MatchCtor D tys vals (subst_term t e x)"
194
207
proof(goal_cases)
195
-
case(3Px)
196
-
thenobtainteywhereP:"x = (t, e, y)"by(metisprod.exhaust)
208
+
209
+
(* this is adapted and simplified from here: https://www.joachim-breitner.de/thesis/isa/Substitution.thy *)
210
+
haveeqvt_at_term:"\<And>e y z . eqvt_at subst_term_subst_alt_list_subst_alt_sumC (Inl (e, y, z)) \<Longrightarrow> eqvt_at (\<lambda>(a, b, c). subst_term a b c) (e, y, z)"
have"(\<Lambda> y : k . subst_term e2 e x) = (\<Lambda> y' : k' . subst_term e2' e' x')"usingAbs_sumC[OF61(5,6)eqvt_at_term[OF61(1)]eqvt_at_term[OF61(2)]]61(7)byfastforce
have"Let y \<tau> (subst_term e1 e x) (subst_term e2 e x) = Let y' \<tau>' (subst_term e1' e' x') (subst_term e2' e' x')"usingAbs_sumC[OF67(9,10)eqvt_at_term[OF67(2)]eqvt_at_term[OF67(4)]]67(11)byfastforce
have"MatchVar y (subst_term t e x) = MatchVar y' (subst_term t' e' x')"usingAbs_sumC[OF79(5,6)eqvt_at_term[OF79(1)]eqvt_at_term[OF79(2)]]79(7)byfastforce
have"MatchCtor D tys vals (subst_term t e x) = MatchCtor D' tys' vals' (subst_term t' e' x')"usingAbs_sumC_star[OF81(5,6)eqvt_at_term[OF81(1)]eqvt_at_term[OF81(2)]]81(7)byfastforce
|"subst_term_type (App e1 e2) \<tau> a = App (subst_term_type e1 \<tau> a) (subst_term_type e2 \<tau> a)"
236
308
|"subst_term_type (TApp e \<tau>2) \<tau> a = TApp (subst_term_type e \<tau> a) (subst_type \<tau>2 \<tau> a)"
309
+
|"subst_term_type (Case e alts) \<tau> a = Case (subst_term_type e \<tau> a) (subst_alt_list_type alts \<tau> a)"
237
310
|"atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (\<lambda> y:\<tau>'. e2) \<tau> a = (\<lambda> y:(subst_type \<tau>' \<tau> a). subst_term_type e2 \<tau> a)"
238
311
|"atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (\<Lambda> b:k. e2) \<tau> a = (\<Lambda> b:k. subst_term_type e2 \<tau> a)"
239
312
|"atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (Let y \<tau>' e1 e2) \<tau> a = Let y (subst_type \<tau>' \<tau> a) (subst_term_type e1 \<tau> a) (subst_term_type e2 \<tau> a)"
313
+
314
+
|"subst_alt_list_type ANil _ _ = ANil"
315
+
|"subst_alt_list_type (ACons alt alts) \<tau> a = ACons (subst_alt_type alt \<tau> a) (subst_alt_list_type alts \<tau> a)"
316
+
317
+
|"atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_alt_type (MatchVar y e) \<tau> a = MatchVar y (subst_term_type e \<tau> a)"
318
+
|"set (map atom tys @ map atom vals) \<sharp>* (\<tau>, a) \<Longrightarrow> subst_alt_type (MatchCtor D tys vals e) \<tau> a = MatchCtor D tys vals (subst_term_type e \<tau> a)"
(* this is adapted and simplified from here: https://www.joachim-breitner.de/thesis/isa/Substitution.thy *)
322
+
haveeqvt_at_term:"\<And>e y z . eqvt_at subst_term_type_subst_alt_list_type_subst_alt_type_sumC (Inl (e, y, z)) \<Longrightarrow> eqvt_at (\<lambda>(a, b, c). subst_term_type a b c) (e, y, z)"
have"(\<Lambda> b : k . subst_term_type e2 \<tau> a) = (\<Lambda> b' : k' . subst_term_type e2' \<tau>' a')"usingAbs_sumC[OF61(5,6)eqvt_at_term[OF61(1)]eqvt_at_term[OF61(2)]]61(7)byfastforce
have"MatchVar y (subst_term_type e \<tau> a) = MatchVar y' (subst_term_type e' \<tau>' a')"usingAbs_sumC[OF79(5,6)eqvt_at_term[OF79(1)]eqvt_at_term[OF79(2)]]79(7)byfastforce
have"MatchCtor D tys vals (subst_term_type e \<tau> a) = MatchCtor D' tys' vals' (subst_term_type e' \<tau>' a')"usingAbs_sumC_star[OF81(5,6)eqvt_at_term[OF81(1)]eqvt_at_term[OF81(2)]]81(7)byfastforce
shows"[ys]lst. f (e2, e, x) = [ys']lst. f (e2', e', x')"
71
+
proof-
72
+
have1:"set ys \<sharp>* ([ys]lst. f (e2, e, x))"by(simpadd:Abs_fresh_star(3))
73
+
have2:"\<And>p. supp p \<sharp>* (e, x) \<Longrightarrow> p \<bullet> ([ys]lst. f (e2, e, x)) = [p \<bullet> ys]lst. f (p \<bullet> e2, e, x)"usingeqvt_at(1)by(simpadd:eqvt_at_def,simpadd:fresh_star_Pairperm_supp_eq)
74
+
have3:"\<And>p. supp p \<sharp>* (e, x) \<Longrightarrow> p \<bullet> ([ys']lst. f (e2', e, x)) = [p \<bullet> ys']lst. f (p \<bullet> e2', e, x)"usingeqvt_at(2)equal(2,3)by(simpadd:eqvt_at_def,simpadd:fresh_star_Pairperm_supp_eq)
75
+
show?thesisusingAbs_lst_fcb2[wheref="\<lambda>a b c. [a]lst. f (b, e, x)",OFequal(1)1fresh(1)_23]fresh(2)equal(2,3)bysimp
76
+
qed
77
+
65
78
lemmaAbs_fresh_var:
66
79
fixesy::"'a::at"ande::"'b::fs"
67
80
obtainsc::"'a"ande'::"'b"where"([[atom y]]lst. e = [[atom c]]lst. e') \<and> atom y \<sharp> [[atom c]]lst. e'"
0 commit comments