55(********************* Actual formalization ************************)
66
77lemma ty_refl : "\<lbrakk>wf \<Gamma> ; T closed_in \<Gamma> \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> T <: T"
8- proof ( binder_induction T arbitrary : \<Gamma> avoiding : "dom \<Gamma>" rule : Type .strong_induct)
9- case ( TyVar x \<Gamma> )
8+ proof ( binder_induction T arbitrary : \<Gamma> avoiding : "dom \<Gamma>" rule : sftypeP .strong_induct)
9+ case ( TVr x \<Gamma> )
1010 then show ?case by blast
1111qed ( auto simp : Diff_single_insert SA_All wf_Cons )
1212
@@ -83,24 +83,22 @@ proof (induction \<Delta>)
8383 then show ?case unfolding 1 using Cons 2 by auto
8484qed auto
8585
86- (* todo for A: look at this and the next *)
87- (* TODO: Automatically derive these from strong induction *)
8886lemma SA_AllE1 [ consumes 2 , case_names SA_Trans_TVar SA_All ]:
8987 assumes "\<Gamma> \<turnstile> \<forall>X<:S\<^sub>1. S\<^sub>2 <: T" "X \<notin> dom \<Gamma>"
9088 and Top : "\<And>\<Gamma>. \<lbrakk>wf \<Gamma>; \<forall>X<:S\<^sub>1. S\<^sub>2 closed_in \<Gamma> \<rbrakk> \<Longrightarrow> R \<Gamma> (\<forall>X<:S\<^sub>1. S\<^sub>2) Top"
9189 and Forall : "\<And>\<Gamma> T\<^sub>1 T\<^sub>2. \<lbrakk> \<Gamma> \<turnstile> T\<^sub>1 <: S\<^sub>1 ; \<Gamma>,, X<:T\<^sub>1 \<turnstile> S\<^sub>2 <: T\<^sub>2 \<rbrakk> \<Longrightarrow> R \<Gamma> (\<forall>X<:S\<^sub>1. S\<^sub>2) (\<forall>X<:T\<^sub>1 . T\<^sub>2)"
9290 shows "R \<Gamma> (\<forall>X<:S\<^sub>1. S\<^sub>2) T"
9391using assms ( 1 , 2 ) proof ( binder_induction \<Gamma> "\<forall>X<:S\<^sub>1. S\<^sub>2" T avoiding : \<Gamma> "\<forall>X<:S\<^sub>1. S\<^sub>2" T rule : ty.strong_induct )
9492 case ( SA_All \<Gamma> T \<^sub >1 R \<^sub >1 Y R \<^sub >2 T \<^sub >2 )
95- have 1 : "\<forall>Y<:T\<^sub>1 . T\<^sub>2 = \<forall>X<:T\<^sub>1. rrename_Type (id(Y:=X,X:=Y)) T\<^sub>2"
93+ have 1 : "\<forall>Y<:T\<^sub>1 . T\<^sub>2 = \<forall>X<:T\<^sub>1. rrename_sftypeP (id(Y:=X,X:=Y)) T\<^sub>2"
9694 apply ( rule Forall_swap )
9795 using SA_All ( 6 , 9 ) well_scoped ( 2 ) by fastforce
98- have fresh : "X \<notin> FFVars_Type T\<^sub>1"
96+ have fresh : "X \<notin> FFVars_sftypeP T\<^sub>1"
9997 by ( meson SA_All ( 4 , 9 ) in_mono well_scoped ( 1 ))
100- have same : "R\<^sub>1 = S\<^sub>1" using SA_All ( 8 ) Type_inject ( 3 ) by blast
101- have x : "\<forall>Y<:S\<^sub>1. R\<^sub>2 = \<forall>X<:S\<^sub>1. rrename_Type (id(Y:=X,X:=Y)) R\<^sub>2"
98+ have same : "R\<^sub>1 = S\<^sub>1" using SA_All ( 8 ) sftypeP_inject ( 3 ) by blast
99+ have x : "\<forall>Y<:S\<^sub>1. R\<^sub>2 = \<forall>X<:S\<^sub>1. rrename_sftypeP (id(Y:=X,X:=Y)) R\<^sub>2"
102100 apply ( rule Forall_swap )
103- by ( metis ( no_types , lifting ) SA_All ( 8 ) assms ( 1 , 2 ) in_mono sup.bounded_iff Type .set( 4 ) well_scoped ( 1 ))
101+ by ( metis ( no_types , lifting ) SA_All ( 8 ) assms ( 1 , 2 ) in_mono sup.bounded_iff sftypeP .set( 4 ) well_scoped ( 1 ))
104102 show ?case unfolding 1
105103 apply ( rule Forall )
106104 using same SA_All ( 4 ) apply simp
@@ -120,27 +118,27 @@ qed (auto simp: Top)
120118
121119lemma SA_AllE2 [ consumes 2 , case_names SA_Trans_TVar SA_All ]:
122120 assumes "\<Gamma> \<turnstile> S <: \<forall>X<:T\<^sub>1. T\<^sub>2" "X \<notin> dom \<Gamma>"
123- and TyVar : "\<And>\<Gamma> x U. \<lbrakk> x<:U \<in> \<Gamma> ; \<Gamma> \<turnstile> U <: \<forall> X <: T\<^sub>1 . T\<^sub>2 ; R \<Gamma> U (\<forall>X<:T\<^sub>1. T\<^sub>2) \<rbrakk> \<Longrightarrow> R \<Gamma> (TyVar x) (\<forall> X <: T\<^sub>1 . T\<^sub>2)"
121+ and TVr : "\<And>\<Gamma> x U. \<lbrakk> x<:U \<in> \<Gamma> ; \<Gamma> \<turnstile> U <: \<forall> X <: T\<^sub>1 . T\<^sub>2 ; R \<Gamma> U (\<forall>X<:T\<^sub>1. T\<^sub>2) \<rbrakk> \<Longrightarrow> R \<Gamma> (TVr x) (\<forall> X <: T\<^sub>1 . T\<^sub>2)"
124122 and Forall : "\<And>\<Gamma> S\<^sub>1 S\<^sub>2. \<lbrakk> \<Gamma> \<turnstile> T\<^sub>1 <: S\<^sub>1 ; \<Gamma>,, X<:T\<^sub>1 \<turnstile> S\<^sub>2 <: T\<^sub>2 \<rbrakk> \<Longrightarrow> R \<Gamma> (\<forall>X<:S\<^sub>1. S\<^sub>2) (\<forall> X <: T\<^sub>1 . T\<^sub>2)"
125123 shows "R \<Gamma> S (\<forall>X<:T\<^sub>1. T\<^sub>2)"
126124using assms ( 1 , 2 ) proof ( binder_induction \<Gamma> S "\<forall>X<:T\<^sub>1. T\<^sub>2" avoiding : \<Gamma> S "\<forall>X<:T\<^sub>1. T\<^sub>2" rule : ty.strong_induct )
127125 case ( SA_All \<Gamma> R \<^sub >1 S \<^sub >1 Y S \<^sub >2 R \<^sub >2 )
128- have 1 : "\<forall>Y<:S\<^sub>1. S\<^sub>2 = \<forall>X<:S\<^sub>1. rrename_Type (id(Y:=X,X:=Y)) S\<^sub>2"
126+ have 1 : "\<forall>Y<:S\<^sub>1. S\<^sub>2 = \<forall>X<:S\<^sub>1. rrename_sftypeP (id(Y:=X,X:=Y)) S\<^sub>2"
129127 apply ( rule Forall_swap )
130128 using SA_All ( 6 , 9 ) well_scoped ( 1 ) by fastforce
131129 have fresh : "X \<notin> dom \<Gamma>" "Y \<notin> dom \<Gamma>"
132130 using SA_All ( 9 ) apply blast
133131 by ( metis SA_All ( 6 ) fst_conv wf_ConsE wf_context )
134- have fresh2 : "X \<notin> FFVars_Type T\<^sub>1" "Y \<notin> FFVars_Type T\<^sub>1"
135- apply ( metis SA_All ( 4 , 8 ) in_mono fresh ( 1 ) Type_inject ( 3 ) well_scoped ( 1 ))
136- by ( metis SA_All ( 4 , 8 ) in_mono fresh ( 2 ) Type_inject ( 3 ) well_scoped ( 1 ))
137- have same : "R\<^sub>1 = T\<^sub>1" using SA_All ( 8 ) Type_inject ( 3 ) by blast
138- have x : "\<forall>Y<:T\<^sub>1 . R\<^sub>2 = \<forall>X<:T\<^sub>1. rrename_Type (id(Y:=X,X:=Y)) R\<^sub>2"
132+ have fresh2 : "X \<notin> FFVars_sftypeP T\<^sub>1" "Y \<notin> FFVars_sftypeP T\<^sub>1"
133+ apply ( metis SA_All ( 4 , 8 ) in_mono fresh ( 1 ) sftypeP_inject ( 3 ) well_scoped ( 1 ))
134+ by ( metis SA_All ( 4 , 8 ) in_mono fresh ( 2 ) sftypeP_inject ( 3 ) well_scoped ( 1 ))
135+ have same : "R\<^sub>1 = T\<^sub>1" using SA_All ( 8 ) sftypeP_inject ( 3 ) by blast
136+ have x : "\<forall>Y<:T\<^sub>1 . R\<^sub>2 = \<forall>X<:T\<^sub>1. rrename_sftypeP (id(Y:=X,X:=Y)) R\<^sub>2"
139137 apply ( rule Forall_swap )
140- by ( metis SA_All ( 8 ) Un_iff assms ( 1 , 2 ) in_mono Type .set( 4 ) well_scoped ( 2 ))
138+ by ( metis SA_All ( 8 ) Un_iff assms ( 1 , 2 ) in_mono sftypeP .set( 4 ) well_scoped ( 2 ))
141139 show ?case unfolding 1
142140 apply ( rule Forall )
143- apply ( metis SA_All ( 4 , 8 ) Type_inject ( 3 ))
141+ apply ( metis SA_All ( 4 , 8 ) sftypeP_inject ( 3 ))
144142 apply ( rule iffD2 [ OF arg_cong3 [ OF _ refl , of _ _ _ _ ty ], rotated - 1 ])
145143 apply ( rule ty.equiv )
146144 apply ( rule bij_swap supp_swap_bound infinite_var )+
@@ -151,9 +149,9 @@ using assms(1,2) proof (binder_induction \<Gamma> S "\<forall>X<:T\<^sub>1. T\<^
151149 apply ( rule arg_cong3 [ of _ _ _ _ _ _ extend ])
152150 using fresh apply ( metis bij_swap SA_All ( 4 ) Un_iff context_map_cong_id fun_upd_apply id_apply infinite_var supp_swap_bound wf_FFVars wf_context )
153151 apply simp
154- using fresh2 unfolding same apply ( metis bij_swap fun_upd_apply id_apply infinite_var supp_swap_bound Type .rrename_cong_ids)
152+ using fresh2 unfolding same apply ( metis bij_swap fun_upd_apply id_apply infinite_var supp_swap_bound sftypeP .rrename_cong_ids)
155153 using SA_All ( 8 ) x Forall_inject_same unfolding same by simp
156- qed ( auto simp : TyVar )
154+ qed ( auto simp : TVr )
157155
158156lemma ty_transitivity : "\<lbrakk> \<Gamma> \<turnstile> S <: Q ; \<Gamma> \<turnstile> Q <: T \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> S <: T"
159157 and ty_narrowing : "\<lbrakk> (\<Gamma> ,, X <: Q),, \<Delta> \<turnstile> M <: N ; \<Gamma> \<turnstile> R <: Q \<rbrakk> \<Longrightarrow> (\<Gamma>,, X <: R),, \<Delta> \<turnstile> M <: N"
@@ -162,25 +160,25 @@ proof -
162160 ty_trans : "\<lbrakk> \<Gamma> \<turnstile> S <: Q ; \<Gamma> \<turnstile> Q <: T \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> S <: T"
163161 and ty_narrow : "\<lbrakk> (\<Gamma>,, X <: Q),, \<Delta> \<turnstile> M <: N ; \<Gamma> \<turnstile> R <: Q ; wf (\<Gamma>,, X <: R,, \<Delta>) ;
164162 M closed_in (\<Gamma>,, X <: R,, \<Delta>) ; N closed_in (\<Gamma>,, X <: R,, \<Delta>) \<rbrakk> \<Longrightarrow> (\<Gamma>,, X <: R),, \<Delta> \<turnstile> M <: N"
165- proof ( binder_induction Q arbitrary : \<Gamma> \<Delta> S T M N X R avoiding : X "dom \<Gamma>" "dom \<Delta>" rule : Type .strong_induct)
166- case ( TyVar Y \<Gamma> \<Delta> S T M N X R )
163+ proof ( binder_induction Q arbitrary : \<Gamma> \<Delta> S T M N X R avoiding : X "dom \<Gamma>" "dom \<Delta>" rule : sftypeP .strong_induct)
164+ case ( TVr Y \<Gamma> \<Delta> S T M N X R )
167165 {
168166 fix \<Gamma> S T
169- show ty_trans : "\<Gamma> \<turnstile> S <: TyVar Y \<Longrightarrow> \<Gamma> \<turnstile> TyVar Y <: T \<Longrightarrow> \<Gamma> \<turnstile> S <: T"
170- by ( induction \<Gamma> S "TyVar Y" rule : ty.induct ) auto
167+ show ty_trans : "\<Gamma> \<turnstile> S <: TVr Y \<Longrightarrow> \<Gamma> \<turnstile> TVr Y <: T \<Longrightarrow> \<Gamma> \<turnstile> S <: T"
168+ by ( induction \<Gamma> S "TVr Y" rule : ty.induct ) auto
171169 } note ty_trans = this
172170 {
173171 case 2
174172 then show ?case
175- proof ( binder_induction "\<Gamma>,, X <: TyVar Y,, \<Delta>" M N arbitrary : \<Delta> avoiding : X "dom \<Gamma>" "dom \<Delta>" rule : ty.strong_induct )
173+ proof ( binder_induction "\<Gamma>,, X <: TVr Y,, \<Delta>" M N arbitrary : \<Delta> avoiding : X "dom \<Gamma>" "dom \<Delta>" rule : ty.strong_induct )
176174 case ( SA_Trans_TVar Z U T \<Delta>' )
177175 show ?case
178176 proof ( cases "X = Z" )
179177 case True
180- then have u : "U = TyVar Y" using SA_Trans_TVar ( 1 , 2 ) context_determ wf_context by blast
181- have "TyVar Y closed_in (\<Gamma>,, Z <: R,, \<Delta>')" using SA_Trans_TVar ( 2 ) True u well_scoped ( 1 ) by fastforce
182- then have "\<Gamma>,, Z <: R ,, \<Delta>' \<turnstile> TyVar Y <: T" using SA_Trans_TVar True u by auto
183- moreover have "\<Gamma>,, Z <: R,, \<Delta>' \<turnstile> R <: TyVar Y" using ty_weakening [ OF ty_weakening_extend [ OF SA_Trans_TVar ( 4 )]]
178+ then have u : "U = TVr Y" using SA_Trans_TVar ( 1 , 2 ) context_determ wf_context by blast
179+ have "TVr Y closed_in (\<Gamma>,, Z <: R,, \<Delta>')" using SA_Trans_TVar ( 2 ) True u well_scoped ( 1 ) by fastforce
180+ then have "\<Gamma>,, Z <: R ,, \<Delta>' \<turnstile> TVr Y <: T" using SA_Trans_TVar True u by auto
181+ moreover have "\<Gamma>,, Z <: R,, \<Delta>' \<turnstile> R <: TVr Y" using ty_weakening [ OF ty_weakening_extend [ OF SA_Trans_TVar ( 4 )]]
184182 by ( metis SA_Trans_TVar ( 5 ) True wf_ConsE wf_concatD )
185183 ultimately have "\<Gamma>,, Z <: R,, \<Delta>' \<turnstile> R <: T" using ty_trans by blast
186184 then show ?thesis unfolding True u using ty.SA_Trans_TVar by auto
@@ -254,7 +252,7 @@ proof -
254252 then show ?thesis by ( meson left ( 1 , 3 ) ty.SA_Arrow ty.SA_Top well_scoped ( 1 ))
255253 next
256254 case right : ( SA_Arrow U \<^sub >1 R \<^sub >1 R \<^sub >2 U \<^sub >2 )
257- then show ?thesis using left by ( metis Fun ( 1 , 3 ) SA_Arrow Type_inject ( 2 ))
255+ then show ?thesis using left by ( metis Fun ( 1 , 3 ) SA_Arrow sftypeP_inject ( 2 ))
258256 qed auto
259257 qed auto
260258 } note ty_trans = this
@@ -396,10 +394,10 @@ proof -
396394qed
397395
398396theorem ty_transitivity2 : "\<lbrakk> \<Gamma> \<turnstile> S <: Q ; \<Gamma> \<turnstile> Q <: T \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> S <: T"
399- proof ( binder_induction Q arbitrary : \<Gamma> S T avoiding : "dom \<Gamma>" rule : Type .strong_induct)
400- case ( TyVar x \<Gamma> S T )
397+ proof ( binder_induction Q arbitrary : \<Gamma> S T avoiding : "dom \<Gamma>" rule : sftypeP .strong_induct)
398+ case ( TVr x \<Gamma> S T )
401399 then show ?case
402- by ( induction \<Gamma> S "TyVar x" ) auto
400+ by ( induction \<Gamma> S "TVr x" ) auto
403401next
404402 case ( Fun x1 x2 \<Gamma> S T )
405403 from Fun ( 4 , 3 ) show ?case
413411 case ( SA_Arrow \<Gamma> U \<^sub >1 R \<^sub >1 R \<^sub >2 U \<^sub >2 )
414412 show ?case
415413 apply ( rule ty.SA_Arrow )
416- apply ( metis Fun ( 1 ) SA_Arrow ( 1 , 5 , 6 , 8 ) Type_inject ( 2 ))
417- by ( metis Fun ( 2 ) SA_Arrow ( 3 , 5 , 7 , 8 ) Type_inject ( 2 ))
414+ apply ( metis Fun ( 1 ) SA_Arrow ( 1 , 5 , 6 , 8 ) sftypeP_inject ( 2 ))
415+ by ( metis Fun ( 2 ) SA_Arrow ( 3 , 5 , 7 , 8 ) sftypeP_inject ( 2 ))
418416 qed auto
419417 qed auto
420418next
437435 qed blast
438436qed auto
439437
440- (*
438+
441439corollary ty_narrowing2 : "\<lbrakk> \<Gamma>,, X <: Q,, \<Delta> \<turnstile> M <: N ; \<Gamma> \<turnstile> R <: Q \<rbrakk> \<Longrightarrow> \<Gamma>,, X <: R,, \<Delta> \<turnstile> M <: N"
442440 using ty_narrowing_aux ty_transitivity2 by blast
443- *)
441+
444442
445443end
0 commit comments