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
69
+
subst_alt_list::"alt_list \<Rightarrow> term \<Rightarrow> var \<Rightarrow> alt_list"and
70
+
subst_alt::"alt \<Rightarrow> term \<Rightarrow> var \<Rightarrow> alt"where
71
+
66
72
"subst_term (Var y) e x = (if x = y then e else Var y)"
67
73
|"subst_term (App e1 e2) e x = App (subst_term e1 e x) (subst_term e2 e x)"
68
74
|"subst_term (TApp e1 \<tau>) e x = TApp (subst_term e1 e x) \<tau>"
69
75
|"subst_term (Ctor D) _ _ = Ctor D"
76
+
|"subst_term (Case t alts) e x = Case (subst_term t e x) (subst_alt_list alts e x)"
70
77
|"atom y \<sharp> (e, x) \<Longrightarrow> subst_term (\<lambda> y:\<tau>. e2) e x = (\<lambda> y:\<tau>. subst_term e2 e x)"
71
78
|"atom y \<sharp> (e, x) \<Longrightarrow> subst_term (\<Lambda> y:k. e2) e x = (\<Lambda> y:k. subst_term e2 e x)"
72
79
|"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)"
80
+
81
+
|"subst_alt_list ANil _ _ = ANil"
82
+
|"subst_alt_list (ACons alt alts) e x = ACons (subst_alt alt e x) (subst_alt_list alts e x)"
83
+
84
+
|"atom y \<sharp> (e, x) \<Longrightarrow> subst_alt (MatchVar y t) e x = MatchVar y (subst_term t e x)"
85
+
|"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)"
73
86
proof(goal_cases)
74
-
case(3Px)
75
-
thenobtainteywhereP:"x = (t, e, y)"by(metisprod.exhaust)
87
+
88
+
(* this is adapted and simplified from here: https://www.joachim-breitner.de/thesis/isa/Substitution.thy *)
89
+
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)"
115
187
|"subst_term_type (TApp e \<tau>2) \<tau> a = TApp (subst_term_type e \<tau> a) (subst_type \<tau>2 \<tau> a)"
188
+
|"subst_term_type (Case e alts) \<tau> a = Case (subst_term_type e \<tau> a) (subst_alt_list_type alts \<tau> a)"
116
189
|"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)"
117
190
|"atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (\<Lambda> b:k. e2) \<tau> a = (\<Lambda> b:k. subst_term_type e2 \<tau> a)"
118
191
|"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)"
192
+
193
+
|"subst_alt_list_type ANil _ _ = ANil"
194
+
|"subst_alt_list_type (ACons alt alts) \<tau> a = ACons (subst_alt_type alt \<tau> a) (subst_alt_list_type alts \<tau> a)"
195
+
196
+
|"atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_alt_type (MatchVar y e) \<tau> a = MatchVar y (subst_term_type e \<tau> a)"
197
+
|"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 *)
201
+
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