Nominal/Ex/CoreHaskell.thy
changeset 2093 751d1349329b
parent 2083 9568f9f31822
child 2095 ae94bae5bb93
equal deleted inserted replaced
2092:c0ab7451b20d 2093:751d1349329b
       
     1 theory CoreHaskell
       
     2 imports "../NewParser"
       
     3 begin
       
     4 
       
     5 (* core haskell *)
       
     6 
       
     7 atom_decl var
       
     8 atom_decl cvar
       
     9 atom_decl tvar
       
    10 
       
    11 nominal_datatype tkind =
       
    12   KStar
       
    13 | KFun "tkind" "tkind"
       
    14 and ckind =
       
    15   CKEq "ty" "ty"
       
    16 and ty =
       
    17   TVar "tvar"
       
    18 | TC "string"
       
    19 | TApp "ty" "ty"
       
    20 | TFun "string" "ty_lst"
       
    21 | TAll tv::"tvar" "tkind" T::"ty"  bind tv in T
       
    22 | TEq "ckind" "ty"
       
    23 and ty_lst =
       
    24   TsNil
       
    25 | TsCons "ty" "ty_lst"
       
    26 and co =
       
    27   CVar "cvar"
       
    28 | CConst "string"
       
    29 | CApp "co" "co"
       
    30 | CFun "string" "co_lst"
       
    31 | CAll cv::"cvar" "ckind" C::"co"  bind cv in C
       
    32 | CEq "ckind" "co"
       
    33 | CRefl "ty"
       
    34 | CSym "co"
       
    35 | CCir "co" "co"
       
    36 | CAt "co" "ty"
       
    37 | CLeft "co"
       
    38 | CRight "co"
       
    39 | CSim "co" "co"
       
    40 | CRightc "co"
       
    41 | CLeftc "co"
       
    42 | CCoe "co" "co"
       
    43 and co_lst =
       
    44   CsNil
       
    45 | CsCons "co" "co_lst"
       
    46 and trm =
       
    47   Var "var"
       
    48 | K "string"
       
    49 | LAMT tv::"tvar" "tkind" t::"trm" bind tv in t
       
    50 | LAMC cv::"cvar" "ckind" t::"trm" bind cv in t
       
    51 | AppT "trm" "ty"
       
    52 | AppC "trm" "co"
       
    53 | Lam v::"var" "ty" t::"trm"       bind v in t
       
    54 | App "trm" "trm"
       
    55 | Let x::"var" "ty" "trm" t::"trm" bind x in t
       
    56 | Case "trm" "assoc_lst"
       
    57 | Cast "trm" "ty"                  --"ty is supposed to be a coercion type only"
       
    58 and assoc_lst =
       
    59   ANil
       
    60 | ACons p::"pat" t::"trm" "assoc_lst" bind "bv p" in t
       
    61 and pat =
       
    62   Kpat "string" "tvars" "cvars" "vars"
       
    63 and vars =
       
    64   VsNil
       
    65 | VsCons "var" "ty" "vars"
       
    66 and tvars =
       
    67   TvsNil
       
    68 | TvsCons "tvar" "tkind" "tvars"
       
    69 and cvars =
       
    70   CvsNil
       
    71 | CvsCons "cvar" "ckind" "cvars"
       
    72 binder
       
    73     bv :: "pat \<Rightarrow> atom list"
       
    74 and bv_vs :: "vars \<Rightarrow> atom list"
       
    75 and bv_tvs :: "tvars \<Rightarrow> atom list"
       
    76 and bv_cvs :: "cvars \<Rightarrow> atom list"
       
    77 where
       
    78   "bv (Kpat s tvts tvcs vs) = append (bv_tvs tvts) (append (bv_cvs tvcs) (bv_vs vs))"
       
    79 | "bv_vs VsNil = []"
       
    80 | "bv_vs (VsCons v k t) = (atom v) # bv_vs t"
       
    81 | "bv_tvs TvsNil = []"
       
    82 | "bv_tvs (TvsCons v k t) = (atom v) # bv_tvs t"
       
    83 | "bv_cvs CvsNil = []"
       
    84 | "bv_cvs (CvsCons v k t) = (atom v) # bv_cvs t"
       
    85 
       
    86 lemmas fv_supp=tkind_ckind_ty_ty_lst_co_co_lst_trm_assoc_lst_pat_vars_tvars_cvars.supp(1-9,11,13,15)
       
    87 lemmas supp=tkind_ckind_ty_ty_lst_co_co_lst_trm_assoc_lst_pat_vars_tvars_cvars.fv[simplified fv_supp]
       
    88 lemmas perm=tkind_ckind_ty_ty_lst_co_co_lst_trm_assoc_lst_pat_vars_tvars_cvars.perm
       
    89 lemmas eq_iff=tkind_ckind_ty_ty_lst_co_co_lst_trm_assoc_lst_pat_vars_tvars_cvars.eq_iff
       
    90 lemmas inducts=tkind_ckind_ty_ty_lst_co_co_lst_trm_assoc_lst_pat_vars_tvars_cvars.inducts
       
    91 
       
    92 lemmas alpha_inducts=alpha_tkind_raw_alpha_ckind_raw_alpha_ty_raw_alpha_ty_lst_raw_alpha_co_raw_alpha_co_lst_raw_alpha_trm_raw_alpha_assoc_lst_raw_alpha_pat_raw_alpha_vars_raw_alpha_tvars_raw_alpha_cvars_raw_alpha_bv_raw_alpha_bv_vs_raw_alpha_bv_tvs_raw_alpha_bv_cvs_raw.inducts
       
    93 lemmas alpha_intros=alpha_tkind_raw_alpha_ckind_raw_alpha_ty_raw_alpha_ty_lst_raw_alpha_co_raw_alpha_co_lst_raw_alpha_trm_raw_alpha_assoc_lst_raw_alpha_pat_raw_alpha_vars_raw_alpha_tvars_raw_alpha_cvars_raw_alpha_bv_raw_alpha_bv_vs_raw_alpha_bv_tvs_raw_alpha_bv_cvs_raw.intros
       
    94 
       
    95 lemma fresh_star_minus_perm: "as \<sharp>* - p = as \<sharp>* (p :: perm)"
       
    96   unfolding fresh_star_def Ball_def
       
    97   by auto (simp_all add: fresh_minus_perm)
       
    98 
       
    99 primrec permute_bv_vs_raw
       
   100 where "permute_bv_vs_raw p VsNil_raw = VsNil_raw"
       
   101 |     "permute_bv_vs_raw p (VsCons_raw v t l) = VsCons_raw (p \<bullet> v) t (permute_bv_vs_raw p l)"
       
   102 primrec permute_bv_cvs_raw
       
   103 where "permute_bv_cvs_raw p CvsNil_raw = CvsNil_raw"
       
   104 |     "permute_bv_cvs_raw p (CvsCons_raw v t l) = CvsCons_raw (p \<bullet> v) t (permute_bv_cvs_raw p l)"
       
   105 primrec permute_bv_tvs_raw
       
   106 where "permute_bv_tvs_raw p TvsNil_raw = TvsNil_raw"
       
   107 |     "permute_bv_tvs_raw p (TvsCons_raw v t l) = TvsCons_raw (p \<bullet> v) t (permute_bv_tvs_raw p l)"
       
   108 primrec permute_bv_raw
       
   109 where "permute_bv_raw p (Kpat_raw c l1 l2 l3) =
       
   110      Kpat_raw c (permute_bv_tvs_raw p l1) (permute_bv_cvs_raw p l2) (permute_bv_vs_raw p l3)"
       
   111 
       
   112 quotient_definition "permute_bv_vs :: perm \<Rightarrow> vars \<Rightarrow> vars"
       
   113 is "permute_bv_vs_raw"
       
   114 quotient_definition "permute_bv_cvs :: perm \<Rightarrow> cvars \<Rightarrow> cvars"
       
   115 is "permute_bv_cvs_raw"
       
   116 quotient_definition "permute_bv_tvs :: perm \<Rightarrow> tvars \<Rightarrow> tvars"
       
   117 is "permute_bv_tvs_raw"
       
   118 quotient_definition "permute_bv :: perm \<Rightarrow> pat \<Rightarrow> pat"
       
   119 is "permute_bv_raw"
       
   120 
       
   121 lemma rsp_pre:
       
   122  "alpha_tvars_raw d a \<Longrightarrow> alpha_tvars_raw (permute_bv_tvs_raw x d) (permute_bv_tvs_raw x a)"
       
   123  "alpha_cvars_raw e b \<Longrightarrow> alpha_cvars_raw (permute_bv_cvs_raw x e) (permute_bv_cvs_raw x b)"
       
   124  "alpha_vars_raw f c \<Longrightarrow> alpha_vars_raw (permute_bv_vs_raw x f) (permute_bv_vs_raw x c)"
       
   125  apply (erule_tac [!] alpha_inducts)
       
   126  apply (simp_all only: alpha_intros perm permute_bv_tvs_raw.simps permute_bv_cvs_raw.simps permute_bv_vs_raw.simps)
       
   127  done
       
   128 
       
   129 lemma [quot_respect]:
       
   130  "(op = ===> alpha_pat_raw ===> alpha_pat_raw) permute_bv_raw permute_bv_raw"
       
   131  "(op = ===> alpha_tvars_raw ===> alpha_tvars_raw) permute_bv_tvs_raw permute_bv_tvs_raw"
       
   132  "(op = ===> alpha_cvars_raw ===> alpha_cvars_raw) permute_bv_cvs_raw permute_bv_cvs_raw"
       
   133  "(op = ===> alpha_vars_raw ===> alpha_vars_raw) permute_bv_vs_raw permute_bv_vs_raw"
       
   134  apply (simp_all add: rsp_pre)
       
   135  apply clarify
       
   136  apply (erule_tac alpha_inducts)
       
   137  apply (simp_all)
       
   138  apply (rule alpha_intros)
       
   139  apply (simp_all add: rsp_pre)
       
   140  done
       
   141 
       
   142 thm permute_bv_raw.simps[no_vars]
       
   143  permute_bv_vs_raw.simps[quot_lifted]
       
   144  permute_bv_cvs_raw.simps[quot_lifted]
       
   145  permute_bv_tvs_raw.simps[quot_lifted]
       
   146 
       
   147 lemma permute_bv_pre:
       
   148   "permute_bv p (Kpat c l1 l2 l3) =
       
   149    Kpat c (permute_bv_tvs p l1) (permute_bv_cvs p l2) (permute_bv_vs p l3)"
       
   150   by (lifting permute_bv_raw.simps)
       
   151 
       
   152 lemmas permute_bv[simp] =
       
   153  permute_bv_pre
       
   154  permute_bv_vs_raw.simps[quot_lifted]
       
   155  permute_bv_cvs_raw.simps[quot_lifted]
       
   156  permute_bv_tvs_raw.simps[quot_lifted]
       
   157 
       
   158 lemma perm_bv1:
       
   159   "p \<bullet> bv_cvs b = bv_cvs (permute_bv_cvs p b)"
       
   160   "p \<bullet> bv_tvs c = bv_tvs (permute_bv_tvs p c)"
       
   161   "p \<bullet> bv_vs d = bv_vs (permute_bv_vs p d)"
       
   162   apply(induct b rule: inducts(12))
       
   163   apply(simp_all add:permute_bv eqvts)
       
   164   apply(induct c rule: inducts(11))
       
   165   apply(simp_all add:permute_bv eqvts)
       
   166   apply(induct d rule: inducts(10))
       
   167   apply(simp_all add:permute_bv eqvts)
       
   168   done
       
   169 
       
   170 lemma perm_bv2:
       
   171   "p \<bullet> bv l = bv (permute_bv p l)"
       
   172   apply(induct l rule: inducts(9))
       
   173   apply(simp_all add:permute_bv)
       
   174   apply(simp add: perm_bv1[symmetric])
       
   175   apply(simp add: eqvts)
       
   176   done
       
   177 
       
   178 lemma alpha_perm_bn1:
       
   179  "alpha_bv_tvs tvars (permute_bv_tvs q tvars)"
       
   180  "alpha_bv_cvs cvars (permute_bv_cvs q cvars)"
       
   181  "alpha_bv_vs vars (permute_bv_vs q vars)"
       
   182   apply(induct tvars rule: inducts(11))
       
   183   apply(simp_all add:permute_bv eqvts eq_iff)
       
   184   apply(induct cvars rule: inducts(12))
       
   185   apply(simp_all add:permute_bv eqvts eq_iff)
       
   186   apply(induct vars rule: inducts(10))
       
   187   apply(simp_all add:permute_bv eqvts eq_iff)
       
   188   done
       
   189 
       
   190 lemma alpha_perm_bn:
       
   191   "alpha_bv pat (permute_bv q pat)"
       
   192   apply(induct pat rule: inducts(9))
       
   193   apply(simp_all add:permute_bv eqvts eq_iff alpha_perm_bn1)
       
   194   done
       
   195 
       
   196 lemma ACons_subst:
       
   197   "supp (Abs_lst (bv pat) trm) \<sharp>* q \<Longrightarrow> (ACons pat trm al) = ACons (permute_bv q pat) (q \<bullet> trm) al"
       
   198   apply (simp only: eq_iff)
       
   199   apply (simp add: alpha_perm_bn)
       
   200   apply (rule_tac x="q" in exI)
       
   201   apply (simp add: alphas)
       
   202   apply (simp add: perm_bv2[symmetric])
       
   203   apply (simp add: eqvts[symmetric])
       
   204   apply (simp add: supp_abs)
       
   205   apply (simp add: fv_supp)
       
   206   apply (rule supp_perm_eq[symmetric])
       
   207   apply (subst supp_finite_atom_set)
       
   208   apply (rule finite_Diff)
       
   209   apply (simp add: finite_supp)
       
   210   apply (assumption)
       
   211   done
       
   212 
       
   213 lemma permute_bv_zero1:
       
   214   "permute_bv_cvs 0 b = b"
       
   215   "permute_bv_tvs 0 c = c"
       
   216   "permute_bv_vs 0 d = d"
       
   217   apply(induct b rule: inducts(12))
       
   218   apply(simp_all add:permute_bv eqvts)
       
   219   apply(induct c rule: inducts(11))
       
   220   apply(simp_all add:permute_bv eqvts)
       
   221   apply(induct d rule: inducts(10))
       
   222   apply(simp_all add:permute_bv eqvts)
       
   223   done
       
   224 
       
   225 lemma permute_bv_zero2:
       
   226   "permute_bv 0 a = a"
       
   227   apply(induct a rule: inducts(9))
       
   228   apply(simp_all add:permute_bv eqvts permute_bv_zero1)
       
   229   done
       
   230 
       
   231 lemma fv_alpha1: "fv_bv_tvs x \<sharp>* pa \<Longrightarrow> alpha_bv_tvs (pa \<bullet> x) x"
       
   232   apply (induct x rule: inducts(11))
       
   233   apply (simp_all add: eq_iff fresh_star_union)
       
   234   done
       
   235 
       
   236 lemma fv_alpha2: "fv_bv_cvs x \<sharp>* pa \<Longrightarrow> alpha_bv_cvs (pa \<bullet> x) x"
       
   237 apply (induct x rule: inducts(12))
       
   238 apply (rule TrueI)+
       
   239 apply (simp_all add: eq_iff fresh_star_union)
       
   240 apply (subst supp_perm_eq)
       
   241 apply (simp_all add: fv_supp)
       
   242 done
       
   243 
       
   244 lemma fv_alpha3: "fv_bv_vs x \<sharp>* pa \<Longrightarrow> alpha_bv_vs (pa \<bullet> x) x"
       
   245 apply (induct x rule: inducts(10))
       
   246 apply (rule TrueI)+
       
   247 apply (simp_all add: fresh_star_union eq_iff)
       
   248 apply (subst supp_perm_eq)
       
   249 apply (simp_all add: fv_supp)
       
   250 done
       
   251 
       
   252 lemma fv_alpha: "fv_bv x \<sharp>* pa \<Longrightarrow> alpha_bv (pa \<bullet> x) x"
       
   253 apply (induct x rule: inducts(9))
       
   254 apply (rule TrueI)+
       
   255 apply (simp_all add: eq_iff fresh_star_union)
       
   256 apply (simp add: fv_alpha1 fv_alpha2 fv_alpha3)
       
   257 apply (subst supp_perm_eq)
       
   258 apply (simp_all add: fv_supp)
       
   259 done
       
   260 
       
   261 lemma fin1: "finite (fv_bv_tvs x)"
       
   262 apply (induct x rule: inducts(11))
       
   263 apply (simp_all add: fv_supp finite_supp)
       
   264 done
       
   265 
       
   266 lemma fin2: "finite (fv_bv_cvs x)"
       
   267 apply (induct x rule: inducts(12))
       
   268 apply (simp_all add: fv_supp finite_supp)
       
   269 done
       
   270 
       
   271 lemma fin3: "finite (fv_bv_vs x)"
       
   272 apply (induct x rule: inducts(10))
       
   273 apply (simp_all add: fv_supp finite_supp)
       
   274 done
       
   275 
       
   276 lemma fin_fv_bv: "finite (fv_bv x)"
       
   277 apply (induct x rule: inducts(9))
       
   278 apply (rule TrueI)+
       
   279 defer
       
   280 apply (rule TrueI)+
       
   281 apply (simp add: fin1 fin2 fin3)
       
   282 apply (rule finite_supp)
       
   283 done
       
   284 
       
   285 lemma finb1: "finite (set (bv_tvs x))"
       
   286 apply (induct x rule: inducts(11))
       
   287 apply (simp_all add: fv_supp finite_supp)
       
   288 done
       
   289 
       
   290 lemma finb2: "finite (set (bv_cvs x))"
       
   291 apply (induct x rule: inducts(12))
       
   292 apply (simp_all add: fv_supp finite_supp)
       
   293 done
       
   294 
       
   295 lemma finb3: "finite (set (bv_vs x))"
       
   296 apply (induct x rule: inducts(10))
       
   297 apply (simp_all add: fv_supp finite_supp)
       
   298 done
       
   299 
       
   300 lemma fin_bv: "finite (set (bv x))"
       
   301 apply (induct x rule: inducts(9))
       
   302 apply (simp_all add: finb1 finb2 finb3)
       
   303 done
       
   304 
       
   305 lemma strong_induction_principle:
       
   306   assumes a01: "\<And>b. P1 b KStar"
       
   307   and a02: "\<And>tkind1 tkind2 b. \<lbrakk>\<And>c. P1 c tkind1; \<And>c. P1 c tkind2\<rbrakk> \<Longrightarrow> P1 b (KFun tkind1 tkind2)"
       
   308   and a03: "\<And>ty1 ty2 b. \<lbrakk>\<And>c. P3 c ty1; \<And>c. P3 c ty2\<rbrakk> \<Longrightarrow> P2 b (CKEq ty1 ty2)"
       
   309   and a04: "\<And>tvar b. P3 b (TVar tvar)"
       
   310   and a05: "\<And>string b. P3 b (TC string)"
       
   311   and a06: "\<And>ty1 ty2 b. \<lbrakk>\<And>c. P3 c ty1; \<And>c. P3 c ty2\<rbrakk> \<Longrightarrow> P3 b (TApp ty1 ty2)"
       
   312   and a07: "\<And>string ty_lst b. \<lbrakk>\<And>c. P4 c ty_lst\<rbrakk> \<Longrightarrow> P3 b (TFun string ty_lst)"
       
   313   and a08: "\<And>tvar tkind ty b. \<lbrakk>\<And>c. P1 c tkind; \<And>c. P3 c ty; atom tvar \<sharp> b\<rbrakk>
       
   314     \<Longrightarrow> P3 b (TAll tvar tkind ty)"
       
   315   and a09: "\<And>ck ty b. \<lbrakk>\<And>c. P2 c ck; \<And>c. P3 c ty\<rbrakk> \<Longrightarrow> P3 b (TEq ck ty)"
       
   316   and a10: "\<And>b. P4 b TsNil"
       
   317   and a11: "\<And>ty ty_lst b. \<lbrakk>\<And>c. P3 c ty; \<And>c. P4 c ty_lst\<rbrakk> \<Longrightarrow> P4 b (TsCons ty ty_lst)"
       
   318   and a12: "\<And>string b. P5 b (CVar string)"
       
   319   and a12a:"\<And>str b. P5 b (CConst str)"
       
   320   and a13: "\<And>co1 co2 b. \<lbrakk>\<And>c. P5 c co1; \<And>c. P5 c co2\<rbrakk> \<Longrightarrow> P5 b (CApp co1 co2)"
       
   321   and a14: "\<And>string co_lst b. \<lbrakk>\<And>c. P6 c co_lst\<rbrakk> \<Longrightarrow> P5 b (CFun string co_lst)"
       
   322   and a15: "\<And>tvar ckind co b. \<lbrakk>\<And>c. P2 c ckind; \<And>c. P5 c co; atom tvar \<sharp> b\<rbrakk>
       
   323     \<Longrightarrow> P5 b (CAll tvar ckind co)"
       
   324   and a16: "\<And>ck co b. \<lbrakk>\<And>c. P2 c ck; \<And>c. P5 c co\<rbrakk> \<Longrightarrow> P5 b (CEq ck co)"
       
   325   and a17: "\<And>ty b. \<lbrakk>\<And>c. P3 c ty\<rbrakk> \<Longrightarrow> P5 b (CRefl ty)"
       
   326   and a17a: "\<And>co b. \<lbrakk>\<And>c. P5 c co\<rbrakk> \<Longrightarrow> P5 b (CSym co)"
       
   327   and a18: "\<And>co1 co2 b. \<lbrakk>\<And>c. P5 c co1; \<And>c. P5 c co2\<rbrakk> \<Longrightarrow> P5 b (CCir co1 co2)"
       
   328   and a18a:"\<And>co ty b. \<lbrakk>\<And>c. P5 c co; \<And>c. P3 c ty\<rbrakk> \<Longrightarrow> P5 b (CAt co ty)"
       
   329   and a19: "\<And>co b. \<lbrakk>\<And>c. P5 c co\<rbrakk> \<Longrightarrow> P5 b (CLeft co)"
       
   330   and a20: "\<And>co b. \<lbrakk>\<And>c. P5 c co\<rbrakk> \<Longrightarrow> P5 b (CRight co)"
       
   331   and a21: "\<And>co1 co2 b. \<lbrakk>\<And>c. P5 c co1; \<And>c. P5 c co2\<rbrakk> \<Longrightarrow> P5 b (CSim co1 co2)"
       
   332   and a22: "\<And>co b. \<lbrakk>\<And>c. P5 c co\<rbrakk> \<Longrightarrow> P5 b (CRightc co)"
       
   333   and a23: "\<And>co b. \<lbrakk>\<And>c. P5 c co\<rbrakk> \<Longrightarrow> P5 b (CLeftc co)"
       
   334   and a24: "\<And>co1 co2 b. \<lbrakk>\<And>c. P5 c co1; \<And>c. P5 c co2\<rbrakk> \<Longrightarrow> P5 b (CCoe co1 co2)"
       
   335   and a25: "\<And>b. P6 b CsNil"
       
   336   and a26: "\<And>co co_lst b. \<lbrakk>\<And>c. P5 c co; \<And>c. P6 c co_lst\<rbrakk> \<Longrightarrow> P6 b (CsCons co co_lst)"
       
   337   and a27: "\<And>var b. P7 b (Var var)"
       
   338   and a28: "\<And>string b. P7 b (K string)"
       
   339   and a29: "\<And>tvar tkind trm b. \<lbrakk>\<And>c. P1 c tkind; \<And>c. P7 c trm; atom tvar \<sharp> b\<rbrakk>
       
   340     \<Longrightarrow> P7 b (LAMT tvar tkind trm)"
       
   341   and a30: "\<And>tvar ckind trm b. \<lbrakk>\<And>c. P2 c ckind; \<And>c. P7 c trm; atom tvar \<sharp> b\<rbrakk>
       
   342     \<Longrightarrow> P7 b (LAMC tvar ckind trm)"
       
   343   and a31: "\<And>trm ty b. \<lbrakk>\<And>c. P7 c trm; \<And>c. P3 c ty\<rbrakk> \<Longrightarrow> P7 b (AppT trm ty)"
       
   344   and a31a:"\<And>trm co b. \<lbrakk>\<And>c. P7 c trm; \<And>c. P5 c co\<rbrakk> \<Longrightarrow> P7 b (AppC trm co)"
       
   345   and a32: "\<And>var ty trm b. \<lbrakk>\<And>c. P3 c ty; \<And>c. P7 c trm; atom var \<sharp> b\<rbrakk> \<Longrightarrow> P7 b (Lam var ty trm)"
       
   346   and a33: "\<And>trm1 trm2 b. \<lbrakk>\<And>c. P7 c trm1; \<And>c. P7 c trm2\<rbrakk> \<Longrightarrow> P7 b (App trm1 trm2)"
       
   347   and a34: "\<And>var ty trm1 trm2 b. \<lbrakk>\<And>c. P3 c ty; \<And>c. P7 c trm1; \<And>c. P7 c trm2; atom var \<sharp> b\<rbrakk>
       
   348     \<Longrightarrow> P7 b (Let var ty trm1 trm2)"
       
   349   and a35: "\<And>trm assoc_lst b. \<lbrakk>\<And>c. P7 c trm; \<And>c. P8 c assoc_lst\<rbrakk> \<Longrightarrow> P7 b (Case trm assoc_lst)"
       
   350   and a36: "\<And>trm ty b. \<lbrakk>\<And>c. P7 c trm; \<And>c. P3 c ty\<rbrakk> \<Longrightarrow> P7 b (Cast trm ty)"
       
   351   and a37: "\<And>b. P8 b ANil"
       
   352   and a38: "\<And>pat trm assoc_lst b. \<lbrakk>\<And>c. P9 c pat; \<And>c. P7 c trm; \<And>c. P8 c assoc_lst; set (bv (pat)) \<sharp>* b\<rbrakk>
       
   353     \<Longrightarrow> P8 b (ACons pat trm assoc_lst)"
       
   354   and a39: "\<And>string tvars cvars vars b. \<lbrakk>\<And>c. P11 c tvars; \<And>c. P12 c cvars; \<And>c. P10 c vars\<rbrakk>
       
   355     \<Longrightarrow> P9 b (Kpat string tvars cvars vars)"
       
   356   and a40: "\<And>b. P10 b VsNil"
       
   357   and a41: "\<And>var ty vars b. \<lbrakk>\<And>c. P3 c ty; \<And>c. P10 c vars\<rbrakk> \<Longrightarrow> P10 b (VsCons var ty vars)"
       
   358   and a42: "\<And>b. P11 b TvsNil"
       
   359   and a43: "\<And>tvar tkind tvars b. \<lbrakk>\<And>c. P1 c tkind; \<And>c. P11 c tvars\<rbrakk>
       
   360     \<Longrightarrow> P11 b (TvsCons tvar tkind tvars)"
       
   361   and a44: "\<And>b. P12 b CvsNil"
       
   362   and a45: "\<And>tvar ckind cvars b. \<lbrakk>\<And>c. P2 c ckind; \<And>c. P12 c cvars\<rbrakk>
       
   363     \<Longrightarrow> P12 b (CvsCons tvar ckind cvars)"
       
   364   shows "P1 (a :: 'a :: pt) tkind \<and>
       
   365          P2 (b :: 'b :: pt) ckind \<and>
       
   366          P3 (c :: 'c :: {pt,fs}) ty \<and>
       
   367          P4 (d :: 'd :: pt) ty_lst \<and>
       
   368          P5 (e :: 'e :: {pt,fs}) co \<and>
       
   369          P6 (f :: 'f :: pt) co_lst \<and>
       
   370          P7 (g :: 'g :: {pt,fs}) trm \<and>
       
   371          P8 (h :: 'h :: {pt,fs}) assoc_lst \<and>
       
   372          P9 (i :: 'i :: pt) pat \<and>
       
   373          P10 (j :: 'j :: pt) vars \<and>
       
   374          P11 (k :: 'k :: pt) tvars \<and>
       
   375          P12 (l :: 'l :: pt) cvars"
       
   376 proof -
       
   377   have a1: "(\<forall>p a. P1 a (p \<bullet> tkind))" and "(\<forall>p b. P2 b (p \<bullet> ckind))" and "(\<forall>p c. P3 c (p \<bullet> ty))" and "(\<forall>p d. P4 d (p \<bullet> ty_lst))" and "(\<forall>p e. P5 e (p \<bullet> co))" and " (\<forall>p f. P6 f (p \<bullet> co_lst))" and "(\<forall>p g. P7 g (p \<bullet> trm))" and "(\<forall>p h. P8 h (p \<bullet> assoc_lst))" and a1:"(\<forall>p q i. P9 i (permute_bv p (q \<bullet> pat)))" and a2:"(\<forall>p q j. P10 j (permute_bv_vs q (p \<bullet> vars)))" and a3:"(\<forall>p q k. P11 k ( permute_bv_tvs q (p \<bullet> tvars)))" and a4:"(\<forall>p q l. P12 l (permute_bv_cvs q (p \<bullet> cvars)))"
       
   378     apply (induct rule: tkind_ckind_ty_ty_lst_co_co_lst_trm_assoc_lst_pat_vars_tvars_cvars.inducts)
       
   379     apply (tactic {* ALLGOALS (REPEAT o rtac allI) *})
       
   380     apply (tactic {* ALLGOALS (TRY o SOLVED' (simp_tac @{simpset} THEN_ALL_NEW resolve_tac @{thms assms} THEN_ALL_NEW asm_full_simp_tac @{simpset})) *})
       
   381 
       
   382 (* GOAL1 *)
       
   383     apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (atom (p \<bullet> tvar))) \<sharp> c \<and>
       
   384                        supp (Abs (p \<bullet> {atom tvar}) (p \<bullet> ty)) \<sharp>* pa)")
       
   385     apply clarify
       
   386     apply (simp only: perm)
       
   387     apply(rule_tac t="TAll (p \<bullet> tvar) (p \<bullet> tkind) (p \<bullet> ty)"
       
   388                and s="TAll (pa \<bullet> p \<bullet> tvar) (p \<bullet> tkind) (pa \<bullet> p \<bullet> ty)" in subst)
       
   389     apply (simp add: eq_iff)
       
   390     apply (rule_tac x="-pa" in exI)
       
   391     apply (simp add: alphas eqvts eqvts_raw supp_abs fv_supp)
       
   392     apply (rule_tac t="supp (pa \<bullet> p \<bullet> ty) - {atom (pa \<bullet> p \<bullet> tvar)}"
       
   393                 and s="pa \<bullet> (p \<bullet> supp ty - {p \<bullet> atom tvar})" in subst)
       
   394     apply (simp add: eqvts)
       
   395     apply (simp add: eqvts[symmetric])
       
   396     apply (rule conjI)
       
   397     apply (rule supp_perm_eq)
       
   398     apply (simp add: eqvts)
       
   399     apply (subst supp_finite_atom_set)
       
   400     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   401     apply (simp add: eqvts)
       
   402     apply (simp add: eqvts)
       
   403     apply (subst supp_perm_eq)
       
   404     apply (subst supp_finite_atom_set)
       
   405     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   406     apply (simp add: eqvts)
       
   407     apply assumption
       
   408     apply (simp add: fresh_star_minus_perm)
       
   409     apply (rule a08)
       
   410     apply simp
       
   411     apply(rotate_tac 1)
       
   412     apply(erule_tac x="(pa + p)" in allE)
       
   413     apply simp
       
   414     apply (simp add: eqvts eqvts_raw)
       
   415     apply (rule at_set_avoiding2_atom)
       
   416     apply (simp add: finite_supp)
       
   417     apply (simp add: finite_supp)
       
   418     apply (simp add: fresh_def)
       
   419     apply (simp only: supp_abs eqvts)
       
   420     apply blast
       
   421 
       
   422 (* GOAL2 *)
       
   423     apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (atom (p \<bullet> cvar))) \<sharp> e \<and>
       
   424                        supp (Abs (p \<bullet> {atom cvar}) (p \<bullet> co)) \<sharp>* pa)")
       
   425     apply clarify
       
   426     apply (simp only: perm)
       
   427     apply(rule_tac t="CAll (p \<bullet> cvar) (p \<bullet> ckind) (p \<bullet> co)"
       
   428                and s="CAll (pa \<bullet> p \<bullet> cvar) (p \<bullet> ckind) (pa \<bullet> p \<bullet> co)" in subst)
       
   429     apply (simp add: eq_iff)
       
   430     apply (rule_tac x="-pa" in exI)
       
   431     apply (simp add: alphas eqvts eqvts_raw supp_abs fv_supp)
       
   432     apply (rule_tac t="supp (pa \<bullet> p \<bullet> co) - {atom (pa \<bullet> p \<bullet> cvar)}"
       
   433                 and s="pa \<bullet> (p \<bullet> supp co - {p \<bullet> atom cvar})" in subst)
       
   434     apply (simp add: eqvts)
       
   435     apply (simp add: eqvts[symmetric])
       
   436     apply (rule conjI)
       
   437     apply (rule supp_perm_eq)
       
   438     apply (simp add: eqvts)
       
   439     apply (subst supp_finite_atom_set)
       
   440     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   441     apply (simp add: eqvts)
       
   442     apply (simp add: eqvts)
       
   443     apply (subst supp_perm_eq)
       
   444     apply (subst supp_finite_atom_set)
       
   445     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   446     apply (simp add: eqvts)
       
   447     apply assumption
       
   448     apply (simp add: fresh_star_minus_perm)
       
   449     apply (rule a15)
       
   450     apply simp
       
   451     apply(rotate_tac 1)
       
   452     apply(erule_tac x="(pa + p)" in allE)
       
   453     apply simp
       
   454     apply (simp add: eqvts eqvts_raw)
       
   455     apply (rule at_set_avoiding2_atom)
       
   456     apply (simp add: finite_supp)
       
   457     apply (simp add: finite_supp)
       
   458     apply (simp add: fresh_def)
       
   459     apply (simp only: supp_abs eqvts)
       
   460     apply blast
       
   461 
       
   462 
       
   463 (* GOAL3 a copy-and-paste of Goal2 with consts and variable names changed *)
       
   464     apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (atom (p \<bullet> tvar))) \<sharp> g \<and>
       
   465                        supp (Abs (p \<bullet> {atom tvar}) (p \<bullet> trm)) \<sharp>* pa)")
       
   466     apply clarify
       
   467     apply (simp only: perm)
       
   468     apply(rule_tac t="LAMT (p \<bullet> tvar) (p \<bullet> tkind) (p \<bullet> trm)"
       
   469                and s="LAMT (pa \<bullet> p \<bullet> tvar) (p \<bullet> tkind) (pa \<bullet> p \<bullet> trm)" in subst)
       
   470     apply (simp add: eq_iff)
       
   471     apply (rule_tac x="-pa" in exI)
       
   472     apply (simp add: alphas eqvts eqvts_raw supp_abs fv_supp)
       
   473     apply (rule_tac t="supp (pa \<bullet> p \<bullet> trm) - {atom (pa \<bullet> p \<bullet> tvar)}"
       
   474                 and s="pa \<bullet> (p \<bullet> supp trm - {p \<bullet> atom tvar})" in subst)
       
   475     apply (simp add: eqvts)
       
   476     apply (simp add: eqvts[symmetric])
       
   477     apply (rule conjI)
       
   478     apply (rule supp_perm_eq)
       
   479     apply (simp add: eqvts)
       
   480     apply (subst supp_finite_atom_set)
       
   481     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   482     apply (simp add: eqvts)
       
   483     apply (simp add: eqvts)
       
   484     apply (subst supp_perm_eq)
       
   485     apply (subst supp_finite_atom_set)
       
   486     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   487     apply (simp add: eqvts)
       
   488     apply assumption
       
   489     apply (simp add: fresh_star_minus_perm)
       
   490     apply (rule a29)
       
   491     apply simp
       
   492     apply(rotate_tac 1)
       
   493     apply(erule_tac x="(pa + p)" in allE)
       
   494     apply simp
       
   495     apply (simp add: eqvts eqvts_raw)
       
   496     apply (rule at_set_avoiding2_atom)
       
   497     apply (simp add: finite_supp)
       
   498     apply (simp add: finite_supp)
       
   499     apply (simp add: fresh_def)
       
   500     apply (simp only: supp_abs eqvts)
       
   501     apply blast
       
   502 
       
   503 (* GOAL4 a copy-and-paste *)
       
   504     apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (atom (p \<bullet> cvar))) \<sharp> g \<and>
       
   505                        supp (Abs (p \<bullet> {atom cvar}) (p \<bullet> trm)) \<sharp>* pa)")
       
   506     apply clarify
       
   507     apply (simp only: perm)
       
   508     apply(rule_tac t="LAMC (p \<bullet> cvar) (p \<bullet> ckind) (p \<bullet> trm)"
       
   509                and s="LAMC (pa \<bullet> p \<bullet> cvar) (p \<bullet> ckind) (pa \<bullet> p \<bullet> trm)" in subst)
       
   510     apply (simp add: eq_iff)
       
   511     apply (rule_tac x="-pa" in exI)
       
   512     apply (simp add: alphas eqvts eqvts_raw supp_abs fv_supp)
       
   513     apply (rule_tac t="supp (pa \<bullet> p \<bullet> trm) - {atom (pa \<bullet> p \<bullet> cvar)}"
       
   514                 and s="pa \<bullet> (p \<bullet> supp trm - {p \<bullet> atom cvar})" in subst)
       
   515     apply (simp add: eqvts)
       
   516     apply (simp add: eqvts[symmetric])
       
   517     apply (rule conjI)
       
   518     apply (rule supp_perm_eq)
       
   519     apply (simp add: eqvts)
       
   520     apply (subst supp_finite_atom_set)
       
   521     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   522     apply (simp add: eqvts)
       
   523     apply (simp add: eqvts)
       
   524     apply (subst supp_perm_eq)
       
   525     apply (subst supp_finite_atom_set)
       
   526     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   527     apply (simp add: eqvts)
       
   528     apply assumption
       
   529     apply (simp add: fresh_star_minus_perm)
       
   530     apply (rule a30)
       
   531     apply simp
       
   532     apply(rotate_tac 1)
       
   533     apply(erule_tac x="(pa + p)" in allE)
       
   534     apply simp
       
   535     apply (simp add: eqvts eqvts_raw)
       
   536     apply (rule at_set_avoiding2_atom)
       
   537     apply (simp add: finite_supp)
       
   538     apply (simp add: finite_supp)
       
   539     apply (simp add: fresh_def)
       
   540     apply (simp only: supp_abs eqvts)
       
   541     apply blast
       
   542 
       
   543 
       
   544 (* GOAL5 a copy-and-paste *)
       
   545     apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (atom (p \<bullet> var))) \<sharp> g \<and>
       
   546                        supp (Abs (p \<bullet> {atom var}) (p \<bullet> trm)) \<sharp>* pa)")
       
   547     apply clarify
       
   548     apply (simp only: perm)
       
   549     apply(rule_tac t="Lam (p \<bullet> var) (p \<bullet> ty) (p \<bullet> trm)"
       
   550                and s="Lam (pa \<bullet> p \<bullet> var) (p \<bullet> ty) (pa \<bullet> p \<bullet> trm)" in subst)
       
   551     apply (simp add: eq_iff)
       
   552     apply (rule_tac x="-pa" in exI)
       
   553     apply (simp add: alphas eqvts eqvts_raw supp_abs fv_supp)
       
   554     apply (rule_tac t="supp (pa \<bullet> p \<bullet> trm) - {atom (pa \<bullet> p \<bullet> var)}"
       
   555                 and s="pa \<bullet> (p \<bullet> supp trm - {p \<bullet> atom var})" in subst)
       
   556     apply (simp add: eqvts)
       
   557     apply (simp add: eqvts[symmetric])
       
   558     apply (rule conjI)
       
   559     apply (rule supp_perm_eq)
       
   560     apply (simp add: eqvts)
       
   561     apply (subst supp_finite_atom_set)
       
   562     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   563     apply (simp add: eqvts)
       
   564     apply (simp add: eqvts)
       
   565     apply (subst supp_perm_eq)
       
   566     apply (subst supp_finite_atom_set)
       
   567     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   568     apply (simp add: eqvts)
       
   569     apply assumption
       
   570     apply (simp add: fresh_star_minus_perm)
       
   571     apply (rule a32)
       
   572     apply simp
       
   573     apply(rotate_tac 1)
       
   574     apply(erule_tac x="(pa + p)" in allE)
       
   575     apply simp
       
   576     apply (simp add: eqvts eqvts_raw)
       
   577     apply (rule at_set_avoiding2_atom)
       
   578     apply (simp add: finite_supp)
       
   579     apply (simp add: finite_supp)
       
   580     apply (simp add: fresh_def)
       
   581     apply (simp only: supp_abs eqvts)
       
   582     apply blast
       
   583 
       
   584 
       
   585 (* GOAL6 a copy-and-paste *)
       
   586     apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (atom (p \<bullet> var))) \<sharp> g \<and>
       
   587                        supp (Abs (p \<bullet> {atom var}) (p \<bullet> trm2)) \<sharp>* pa)")
       
   588     apply clarify
       
   589     apply (simp only: perm)
       
   590     apply(rule_tac t="Let (p \<bullet> var) (p \<bullet> ty) (p \<bullet> trm1) (p \<bullet> trm2)"
       
   591                and s="Let (pa \<bullet> p \<bullet> var) (p \<bullet> ty) (p \<bullet> trm1) (pa \<bullet> p \<bullet> trm2)" in subst)
       
   592     apply (simp add: eq_iff)
       
   593     apply (rule_tac x="-pa" in exI)
       
   594     apply (simp add: alphas eqvts eqvts_raw supp_abs fv_supp)
       
   595     apply (rule_tac t="supp (pa \<bullet> p \<bullet> trm2) - {atom (pa \<bullet> p \<bullet> var)}"
       
   596                 and s="pa \<bullet> (p \<bullet> supp trm2 - {p \<bullet> atom var})" in subst)
       
   597     apply (simp add: eqvts)
       
   598     apply (simp add: eqvts[symmetric])
       
   599     apply (rule conjI)
       
   600     apply (rule supp_perm_eq)
       
   601     apply (simp add: eqvts)
       
   602     apply (subst supp_finite_atom_set)
       
   603     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   604     apply (simp add: eqvts)
       
   605     apply (simp add: eqvts)
       
   606     apply (subst supp_perm_eq)
       
   607     apply (subst supp_finite_atom_set)
       
   608     apply (simp add: eqvts[symmetric] finite_eqvt[symmetric] finite_supp)
       
   609     apply (simp add: eqvts)
       
   610     apply assumption
       
   611     apply (simp add: fresh_star_minus_perm)
       
   612     apply (rule a34)
       
   613     apply simp
       
   614     apply simp
       
   615     apply(rotate_tac 2)
       
   616     apply(erule_tac x="(pa + p)" in allE)
       
   617     apply simp
       
   618     apply (simp add: eqvts eqvts_raw)
       
   619     apply (rule at_set_avoiding2_atom)
       
   620     apply (simp add: finite_supp)
       
   621     apply (simp add: finite_supp)
       
   622     apply (simp add: fresh_def)
       
   623     apply (simp only: supp_abs eqvts)
       
   624     apply blast
       
   625 
       
   626 (* MAIN ACons Goal *)
       
   627     apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (set (bv (p \<bullet> pat)))) \<sharp>* h \<and>
       
   628                        supp (Abs_lst (p \<bullet> (bv pat)) (p \<bullet> trm)) \<sharp>* pa)")
       
   629     apply clarify
       
   630     apply (simp only: perm eqvts)
       
   631     apply (subst ACons_subst)
       
   632     apply assumption
       
   633     apply (rule a38)
       
   634     apply simp
       
   635     apply(rotate_tac 1)
       
   636     apply(erule_tac x="(pa + p)" in allE)
       
   637     apply simp
       
   638     apply simp
       
   639     apply (simp add: perm_bv2[symmetric])
       
   640     apply (simp add: eqvts eqvts_raw)
       
   641     apply (rule at_set_avoiding2)
       
   642     apply (simp add: fin_bv)
       
   643     apply (simp add: finite_supp)
       
   644     apply (simp add: supp_abs)
       
   645     apply (simp add: finite_supp)
       
   646     apply (simp add: fresh_star_def fresh_def supp_abs eqvts)
       
   647     done
       
   648   then have b: "P1 a (0 \<bullet> tkind)" and "P2 b (0 \<bullet> ckind)" "P3 c (0 \<bullet> ty)" and "P4 d (0 \<bullet> ty_lst)" and "P5 e (0 \<bullet> co)" and "P6 f (0 \<bullet> co_lst)" and "P7 g (0 \<bullet> trm)" and "P8 h (0 \<bullet> assoc_lst)" by (blast+)
       
   649   moreover have "P9  i (permute_bv 0 (0 \<bullet> pat))" and "P10 j (permute_bv_vs 0 (0 \<bullet> vars))" and "P11 k (permute_bv_tvs 0 (0 \<bullet> tvars))" and "P12 l (permute_bv_cvs 0 (0 \<bullet> cvars))" using a1 a2 a3 a4 by (blast+)
       
   650   ultimately show ?thesis by (simp_all add: permute_bv_zero1 permute_bv_zero2)
       
   651 qed
       
   652 
       
   653 section {* test about equivariance for alpha *}
       
   654 
       
   655 (* this should not be an equivariance rule *)
       
   656 (* for the moment, we force it to be       *)
       
   657 
       
   658 (*declare permute_pure[eqvt]*)
       
   659 (*setup {* Context.theory_map (Nominal_ThmDecls.add_thm @{thm "permute_pure"}) *)
       
   660 
       
   661 thm eqvts
       
   662 thm eqvts_raw
       
   663 
       
   664 declare permute_tkind_raw_permute_ckind_raw_permute_ty_raw_permute_ty_lst_raw_permute_co_raw_permute_co_lst_raw_permute_trm_raw_permute_assoc_lst_raw_permute_pat_raw_permute_vars_raw_permute_tvars_raw_permute_cvars_raw.simps[eqvt]
       
   665 declare alpha_gen_eqvt[eqvt]
       
   666 
       
   667 equivariance alpha_tkind_raw
       
   668 
       
   669 thm eqvts
       
   670 thm eqvts_raw
       
   671 
       
   672 end
       
   673