Nominal/Ex/TypeSchemes.thy
author Christian Urban <urbanc@in.tum.de>
Mon, 20 Sep 2010 21:52:45 +0800
changeset 2480 ac7dff1194e8
parent 2468 7b1470b55936
child 2486 b4ea19604b0b
permissions -rw-r--r--
introduced a general procedure for structural inductions; simplified reflexivity proof
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory TypeSchemes
2454
9ffee4eb1ae1 renamed NewParser to Nominal2
Christian Urban <urbanc@in.tum.de>
parents: 2451
diff changeset
     2
imports "../Nominal2"
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
section {*** Type Schemes ***}
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
atom_decl name
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents: 2308
diff changeset
     8
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
     9
declare [[STEPS = 100]]
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
nominal_datatype ty =
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  Var "name"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
| Fun "ty" "ty"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
and tys =
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2424
diff changeset
    15
  All xs::"name fset" ty::"ty" bind (res) xs in ty
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2424
diff changeset
    16
2468
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    17
thm ty_tys.distinct
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    18
thm ty_tys.induct
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    19
thm ty_tys.exhaust
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    20
thm ty_tys.fv_defs
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    21
thm ty_tys.bn_defs
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    22
thm ty_tys.perm_simps
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    23
thm ty_tys.eq_iff
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    24
thm ty_tys.fv_bn_eqvt
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    25
thm ty_tys.size_eqvt
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    26
thm ty_tys.supports
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    27
thm ty_tys.fsupp
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
2308
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2181
diff changeset
    29
nominal_datatype ty2 =
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2181
diff changeset
    30
  Var2 "name"
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2181
diff changeset
    31
| Fun2 "ty2" "ty2"
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2181
diff changeset
    32
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2181
diff changeset
    33
nominal_datatype tys2 =
2434
92dc6cfa3a95 automatic lifting
Christian Urban <urbanc@in.tum.de>
parents: 2424
diff changeset
    34
  All2 xs::"name fset" ty::"ty2" bind (res) xs in ty
2337
b151399bd2c3 fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents: 2308
diff changeset
    35
2468
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    36
thm tys2.distinct
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    37
thm tys2.induct
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    38
thm tys2.exhaust
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    39
thm tys2.fv_defs
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    40
thm tys2.bn_defs
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    41
thm tys2.perm_simps
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    42
thm tys2.eq_iff
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    43
thm tys2.fv_bn_eqvt
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    44
thm tys2.size_eqvt
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    45
thm tys2.supports
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    46
thm tys2.fsupp
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    47
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    48
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2468
diff changeset
    49
2468
7b1470b55936 moved a proof to Abs
Christian Urban <urbanc@in.tum.de>
parents: 2454
diff changeset
    50
text {* *}
2308
387fcbd33820 fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents: 2181
diff changeset
    51
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    52
(*
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
ML {* Sign.of_sort @{theory} (@{typ ty}, @{sort fs}) *}
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
lemma strong_induct:
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  assumes a1: "\<And>name b. P b (Var name)"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  and     a2: "\<And>t1 t2 b. \<lbrakk>\<And>c. P c t1; \<And>c. P c t2\<rbrakk> \<Longrightarrow> P b (Fun t1 t2)"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  and     a3: "\<And>fset t b. \<lbrakk>\<And>c. P c t; fset_to_set (fmap atom fset) \<sharp>* b\<rbrakk> \<Longrightarrow> P' b (All fset t)"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  shows "P (a :: 'a :: pt) t \<and> P' (d :: 'b :: {fs}) ts "
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
proof -
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  have " (\<forall>p a. P a (p \<bullet> t)) \<and> (\<forall>p d. P' d (p \<bullet> ts))"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    apply (rule ty_tys.induct)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    apply (simp add: a1)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
    apply (simp)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
    apply (rule allI)+
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    apply (rule a2)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
    apply simp
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
    apply simp
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    apply (rule allI)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
    apply (rule allI)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
    apply(subgoal_tac "\<exists>pa. ((pa \<bullet> (fset_to_set (fmap atom (p \<bullet> fset)))) \<sharp>* d \<and> supp (p \<bullet> All fset ty) \<sharp>* pa)")
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
    apply clarify
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    apply(rule_tac t="p \<bullet> All fset ty" and 
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
                   s="pa \<bullet> (p \<bullet> All fset ty)" in subst)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
    apply (rule supp_perm_eq)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    apply assumption
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
    apply (simp only: ty_tys.perm)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
    apply (rule a3)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
    apply(erule_tac x="(pa + p)" in allE)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
    apply simp
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
    apply (simp add: eqvts eqvts_raw)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
    apply (rule at_set_avoiding2)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
    apply (simp add: fin_fset_to_set)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
    apply (simp add: finite_supp)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
    apply (simp add: eqvts finite_supp)
1933
9eab1dfc14d2 moved lemmas from FSet.thy to do with atom to Nominal2_Base, and to do with 'a::at set to Nominal2_Atoms; moved Nominal2_Eqvt.thy one up to be loaded before Nominal2_Atoms
Christian Urban <urbanc@in.tum.de>
parents: 1795
diff changeset
    86
    apply (rule_tac p=" -p" in permute_boolE)
9eab1dfc14d2 moved lemmas from FSet.thy to do with atom to Nominal2_Base, and to do with 'a::at set to Nominal2_Atoms; moved Nominal2_Eqvt.thy one up to be loaded before Nominal2_Atoms
Christian Urban <urbanc@in.tum.de>
parents: 1795
diff changeset
    87
    apply(simp add: eqvts)
9eab1dfc14d2 moved lemmas from FSet.thy to do with atom to Nominal2_Base, and to do with 'a::at set to Nominal2_Atoms; moved Nominal2_Eqvt.thy one up to be loaded before Nominal2_Atoms
Christian Urban <urbanc@in.tum.de>
parents: 1795
diff changeset
    88
    apply(simp add: permute_fun_def atom_eqvt)
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
    apply (simp add: fresh_star_def)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
    apply clarify
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
    apply (simp add: fresh_def)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    apply (simp add: ty_tys_supp)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
    done
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  then have "P a (0 \<bullet> t) \<and> P' d (0 \<bullet> ts)" by blast
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  then show ?thesis by simp
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
qed
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
lemma
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  shows "All {|a, b|} (Fun (Var a) (Var b)) = All {|b, a|} (Fun (Var a) (Var b))"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  apply(simp add: ty_tys.eq_iff)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  apply(rule_tac x="0::perm" in exI)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  apply(simp add: alphas)
2040
94e24da9ae75 Move TypeSchemes to NewParser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1933
diff changeset
   103
  apply(simp add: fresh_star_def fresh_zero_perm supp_at_base)
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  done
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
lemma
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  shows "All {|a, b|} (Fun (Var a) (Var b)) = All {|a, b|} (Fun (Var b) (Var a))"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  apply(simp add: ty_tys.eq_iff)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  apply(rule_tac x="(atom a \<rightleftharpoons> atom b)" in exI)
2040
94e24da9ae75 Move TypeSchemes to NewParser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1933
diff changeset
   110
  apply(simp add: alphas fresh_star_def eqvts supp_at_base)
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  done
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
lemma
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  shows "All {|a, b, c|} (Fun (Var a) (Var b)) = All {|a, b|} (Fun (Var a) (Var b))"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  apply(simp add: ty_tys.eq_iff)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  apply(rule_tac x="0::perm" in exI)
2040
94e24da9ae75 Move TypeSchemes to NewParser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1933
diff changeset
   117
  apply(simp add: alphas fresh_star_def eqvts ty_tys.eq_iff supp_at_base)
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
done
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
lemma
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  assumes a: "a \<noteq> b"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  shows "\<not>(All {|a, b|} (Fun (Var a) (Var b)) = All {|c|} (Fun (Var c) (Var c)))"
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  using a
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  apply(simp add: ty_tys.eq_iff)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  apply(clarify)
2040
94e24da9ae75 Move TypeSchemes to NewParser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1933
diff changeset
   126
  apply(simp add: alphas fresh_star_def eqvts ty_tys.eq_iff supp_at_base)
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  apply auto
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  done
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
2179
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   130
fun
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   131
  lookup :: "(name \<times> ty) list \<Rightarrow> name \<Rightarrow> ty"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   132
where
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   133
  "lookup [] n = Var n"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   134
| "lookup ((p, s) # t) n = (if p = n then s else lookup t n)"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   135
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   136
locale subst_loc =
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   137
fixes
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   138
    subst  :: "(name \<times> ty) list \<Rightarrow> ty \<Rightarrow> ty"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   139
and substs :: "(name \<times> ty) list \<Rightarrow> tys \<Rightarrow> tys"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   140
assumes
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   141
    s1: "subst \<theta> (Var n) = lookup \<theta> n"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   142
and s2: "subst \<theta> (Fun l r) = Fun (subst \<theta> l) (subst \<theta> r)"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   143
and s3: "fset_to_set (fmap atom xs) \<sharp>* \<theta> \<Longrightarrow> substs \<theta> (All xs t) = All xs (subst \<theta> t)"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   144
begin
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   145
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   146
lemma subst_ty:
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   147
  assumes x: "atom x \<sharp> t"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   148
  shows "subst [(x, S)] t = t"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   149
  using x
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   150
  apply (induct t rule: ty_tys.induct[of _ "\<lambda>t. True" _ , simplified])
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   151
  by (simp_all add: s1 s2 fresh_def ty_tys.fv[simplified ty_tys.supp] supp_at_base)
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   152
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   153
lemma subst_tyS:
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   154
  shows "atom x \<sharp> T \<longrightarrow> substs [(x, S)] T = T"
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   155
  apply (rule strong_induct[of
2180
d8750d1aaed9 Simplified the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2179
diff changeset
   156
    "\<lambda>a t. True" "\<lambda>(x, S) T. (atom x \<sharp> T \<longrightarrow> substs [(x, S)] T = T)" _ "t" "(x, S)", simplified])
d8750d1aaed9 Simplified the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2179
diff changeset
   157
  apply clarify
2179
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   158
  apply (subst s3)
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   159
  apply (simp add: fresh_star_def fresh_Cons fresh_Nil)
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   160
  apply (subst subst_ty)
2180
d8750d1aaed9 Simplified the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2179
diff changeset
   161
  apply (simp_all add: fresh_star_prod_elim)
2179
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   162
  apply (drule fresh_star_atom)
2180
d8750d1aaed9 Simplified the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2179
diff changeset
   163
  apply (simp add: fresh_def ty_tys.fv[simplified ty_tys.supp])
d8750d1aaed9 Simplified the proof
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2179
diff changeset
   164
  apply (subgoal_tac "atom a \<notin> fset_to_set (fmap atom fset)")
2179
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   165
  apply blast
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   166
  apply (metis supp_finite_atom_set finite_fset)
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   167
  done
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   168
2181
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   169
lemma subst_lemma_pre:
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   170
  "z \<sharp> (N,L) \<longrightarrow> z \<sharp> (subst [(y, L)] N)"
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   171
  apply (induct N rule: ty_tys.induct[of _ "\<lambda>t. True" _ , simplified])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   172
  apply (simp add: s1)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   173
  apply (auto simp add: fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   174
  apply (auto simp add: fresh_def ty_tys.fv[simplified ty_tys.supp])[3]
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   175
  apply (simp add: s2)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   176
  apply (auto simp add: fresh_def ty_tys.fv[simplified ty_tys.supp])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   177
  done
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   178
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   179
lemma substs_lemma_pre:
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   180
  "atom z \<sharp> (N,L) \<longrightarrow> atom z \<sharp> (substs [(y, L)] N)"
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   181
  apply (rule strong_induct[of
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   182
    "\<lambda>a t. True" "\<lambda>(z, y, L) N. (atom z \<sharp> (N, L) \<longrightarrow> atom z \<sharp> (substs [(y, L)] N))" _ _ "(z, y, L)", simplified])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   183
  apply clarify
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   184
  apply (subst s3)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   185
  apply (simp add: fresh_star_def fresh_Cons fresh_Nil fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   186
  apply (simp_all add: fresh_star_prod_elim fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   187
  apply clarify
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   188
  apply (drule fresh_star_atom)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   189
  apply (drule fresh_star_atom)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   190
  apply (simp add: fresh_def)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   191
  apply (simp only: ty_tys.fv[simplified ty_tys.supp])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   192
  apply (subgoal_tac "atom a \<notin> supp (subst [(aa, b)] t)")
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   193
  apply blast
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   194
  apply (subgoal_tac "atom a \<notin> supp t")
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   195
  apply (fold fresh_def)[1]
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   196
  apply (rule mp[OF subst_lemma_pre])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   197
  apply (simp add: fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   198
  apply (subgoal_tac "atom a \<notin> (fset_to_set (fmap atom fset))")
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   199
  apply blast
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   200
  apply (metis supp_finite_atom_set finite_fset)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   201
  done
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   202
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   203
lemma subst_lemma:
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   204
  shows "x \<noteq> y \<and> atom x \<sharp> L \<longrightarrow>
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   205
    subst [(y, L)] (subst [(x, N)] M) =
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   206
    subst [(x, (subst [(y, L)] N))] (subst [(y, L)] M)"
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   207
  apply (induct M rule: ty_tys.induct[of _ "\<lambda>t. True" _ , simplified])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   208
  apply (simp_all add: s1 s2)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   209
  apply clarify
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   210
  apply (subst (2) subst_ty)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   211
  apply simp_all
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   212
  done
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   213
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   214
lemma substs_lemma:
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   215
  shows "x \<noteq> y \<and> atom x \<sharp> L \<longrightarrow>
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   216
    substs [(y, L)] (substs [(x, N)] M) =
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   217
    substs [(x, (subst [(y, L)] N))] (substs [(y, L)] M)"
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   218
  apply (rule strong_induct[of
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   219
    "\<lambda>a t. True" "\<lambda>(x, y, N, L) M. x \<noteq> y \<and> atom x \<sharp> L \<longrightarrow>
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   220
    substs [(y, L)] (substs [(x, N)] M) =
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   221
    substs [(x, (subst [(y, L)] N))] (substs [(y, L)] M)" _ _ "(x, y, N, L)", simplified])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   222
  apply clarify
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   223
  apply (simp_all add: fresh_star_prod_elim fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   224
  apply (subst s3)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   225
  apply (unfold fresh_star_def)[1]
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   226
  apply (simp add: fresh_Cons fresh_Nil fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   227
  apply (subst s3)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   228
  apply (unfold fresh_star_def)[1]
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   229
  apply (simp add: fresh_Cons fresh_Nil fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   230
  apply (subst s3)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   231
  apply (unfold fresh_star_def)[1]
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   232
  apply (simp add: fresh_Cons fresh_Nil fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   233
  apply (subst s3)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   234
  apply (unfold fresh_star_def)[1]
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   235
  apply (simp add: fresh_Cons fresh_Nil fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   236
  apply (rule ballI)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   237
  apply (rule mp[OF subst_lemma_pre])
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   238
  apply (simp add: fresh_Pair)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   239
  apply (subst subst_lemma)
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   240
  apply simp_all
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   241
  done
b997c22805ae Substitution Lemma for TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2180
diff changeset
   242
2179
7687f97eca53 A lemma about substitution in TypeSchemes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   243
end
1795
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
*)
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
e39453c8b186 tuned type-schemes example
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
end