src/HOL/Nominal/Examples/SN.thy
author berghofe
Fri, 28 Apr 2006 15:58:30 +0200
changeset 19496 79dbe35c6cba
parent 19218 47b05ebe106b
child 19564 d3e2f532459a
permissions -rw-r--r--
Capitalized theory names.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18263
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
     1
(* $Id$ *)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
     2
19496
79dbe35c6cba Capitalized theory names.
berghofe
parents: 19218
diff changeset
     3
theory SN
79dbe35c6cba Capitalized theory names.
berghofe
parents: 19218
diff changeset
     4
imports Lam_substs Accessible_Part
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
     5
begin
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
     6
18269
3f36e2165e51 some small tuning
urbanc
parents: 18263
diff changeset
     7
text {* Strong Normalisation proof from the Proofs and Types book *}
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
     8
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
     9
section {* Beta Reduction *}
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    10
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    11
lemma subst_rename[rule_format]: 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    12
  shows "c\<sharp>t1 \<longrightarrow> (t1[a::=t2] = ([(c,a)]\<bullet>t1)[c::=t2])"
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
    13
apply(nominal_induct t1 avoiding: a c t2 rule: lam.induct)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    14
apply(auto simp add: calc_atm fresh_atm abs_fresh)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    15
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    16
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    17
lemma forget: 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    18
  assumes a: "a\<sharp>t1"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    19
  shows "t1[a::=t2] = t1"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    20
  using a
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
    21
apply (nominal_induct t1 avoiding: a t2 rule: lam.induct)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    22
apply(auto simp add: abs_fresh fresh_atm)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    23
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    24
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    25
lemma fresh_fact: 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    26
  fixes a::"name"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    27
  assumes a: "a\<sharp>t1"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    28
  and     b: "a\<sharp>t2"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    29
  shows "a\<sharp>(t1[b::=t2])"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    30
using a b
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
    31
apply(nominal_induct t1 avoiding: a b t2 rule: lam.induct)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    32
apply(auto simp add: abs_fresh fresh_atm)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    33
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    34
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
    35
lemma subst_lemma:  
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    36
  assumes a: "x\<noteq>y"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    37
  and     b: "x\<sharp>L"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    38
  shows "M[x::=N][y::=L] = M[y::=L][x::=N[y::=L]]"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    39
using a b
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
    40
by (nominal_induct M avoiding: x y N L rule: lam.induct)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    41
   (auto simp add: fresh_fact forget)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    42
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    43
lemma id_subs: "t[x::=Var x] = t"
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
    44
apply(nominal_induct t avoiding: x rule: lam.induct)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    45
apply(simp_all add: fresh_atm)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    46
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    47
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    48
consts
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    49
  Beta :: "(lam\<times>lam) set"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    50
syntax 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    51
  "_Beta"       :: "lam\<Rightarrow>lam\<Rightarrow>bool" (" _ \<longrightarrow>\<^isub>\<beta> _" [80,80] 80)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    52
  "_Beta_star"  :: "lam\<Rightarrow>lam\<Rightarrow>bool" (" _ \<longrightarrow>\<^isub>\<beta>\<^sup>* _" [80,80] 80)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    53
translations 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    54
  "t1 \<longrightarrow>\<^isub>\<beta> t2" \<rightleftharpoons> "(t1,t2) \<in> Beta"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    55
  "t1 \<longrightarrow>\<^isub>\<beta>\<^sup>* t2" \<rightleftharpoons> "(t1,t2) \<in> Beta\<^sup>*"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    56
inductive Beta
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    57
  intros
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    58
  b1[intro!]: "s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> (App s1 t)\<longrightarrow>\<^isub>\<beta>(App s2 t)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    59
  b2[intro!]: "s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> (App t s1)\<longrightarrow>\<^isub>\<beta>(App t s2)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    60
  b3[intro!]: "s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> (Lam [a].s1)\<longrightarrow>\<^isub>\<beta> (Lam [(a::name)].s2)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    61
  b4[intro!]: "(App (Lam [(a::name)].s1) s2)\<longrightarrow>\<^isub>\<beta>(s1[a::=s2])"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    62
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    63
lemma eqvt_beta: 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    64
  fixes pi :: "name prm"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    65
  and   t  :: "lam"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    66
  and   s  :: "lam"
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    67
  assumes a: "t\<longrightarrow>\<^isub>\<beta>s"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    68
  shows "(pi\<bullet>t)\<longrightarrow>\<^isub>\<beta>(pi\<bullet>s)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    69
  using a by (induct, auto)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    70
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    71
lemma beta_induct[consumes 1, case_names b1 b2 b3 b4]:
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    72
  fixes  P :: "'a::fs_name\<Rightarrow>lam \<Rightarrow> lam \<Rightarrow>bool"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    73
  and    t :: "lam"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    74
  and    s :: "lam"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    75
  and    x :: "'a::fs_name"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
    76
  assumes a: "t\<longrightarrow>\<^isub>\<beta>s"
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    77
  and a1:    "\<And>t s1 s2 x. s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> (\<And>z. P z s1 s2) \<Longrightarrow> P x (App s1 t) (App s2 t)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    78
  and a2:    "\<And>t s1 s2 x. s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> (\<And>z. P z s1 s2) \<Longrightarrow> P x (App t s1) (App t s2)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    79
  and a3:    "\<And>a s1 s2 x. a\<sharp>x \<Longrightarrow> s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> (\<And>z. P z s1 s2) \<Longrightarrow> P x (Lam [a].s1) (Lam [a].s2)"
19218
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
    80
  and a4:    "\<And>a t1 s1 x. a\<sharp>x \<Longrightarrow> P x (App (Lam [a].t1) s1) (t1[a::=s1])"
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    81
  shows "P x t s"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    82
proof -
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    83
  from a have "\<And>(pi::name prm) x. P x (pi\<bullet>t) (pi\<bullet>s)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    84
  proof (induct)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    85
    case b1 thus ?case using a1 by (simp, blast intro: eqvt_beta)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    86
  next
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    87
    case b2 thus ?case using a2 by (simp, blast intro: eqvt_beta)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    88
  next
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    89
    case (b3 a s1 s2)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    90
    have j1: "s1 \<longrightarrow>\<^isub>\<beta> s2" by fact
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    91
    have j2: "\<And>x (pi::name prm). P x (pi\<bullet>s1) (pi\<bullet>s2)" by fact
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    92
    show ?case 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    93
    proof (simp)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    94
      have f: "\<exists>c::name. c\<sharp>(pi\<bullet>a,pi\<bullet>s1,pi\<bullet>s2,x)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    95
	by (rule at_exists_fresh[OF at_name_inst], simp add: fs_name1)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    96
      then obtain c::"name" 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    97
	where f1: "c\<noteq>(pi\<bullet>a)" and f2: "c\<sharp>x" and f3: "c\<sharp>(pi\<bullet>s1)" and f4: "c\<sharp>(pi\<bullet>s2)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    98
	by (force simp add: fresh_prod fresh_atm)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
    99
      have x: "P x (Lam [c].(([(c,pi\<bullet>a)]@pi)\<bullet>s1)) (Lam [c].(([(c,pi\<bullet>a)]@pi)\<bullet>s2))"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   100
	using a3 f2 j1 j2 by (simp, blast intro: eqvt_beta)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   101
      have alpha1: "(Lam [c].([(c,pi\<bullet>a)]\<bullet>(pi\<bullet>s1))) = (Lam [(pi\<bullet>a)].(pi\<bullet>s1))" using f1 f3
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   102
	by (simp add: lam.inject alpha)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   103
      have alpha2: "(Lam [c].([(c,pi\<bullet>a)]\<bullet>(pi\<bullet>s2))) = (Lam [(pi\<bullet>a)].(pi\<bullet>s2))" using f1 f3
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   104
	by (simp add: lam.inject alpha)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   105
      show " P x (Lam [(pi\<bullet>a)].(pi\<bullet>s1)) (Lam [(pi\<bullet>a)].(pi\<bullet>s2))"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   106
	using x alpha1 alpha2 by (simp only: pt_name2)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   107
    qed
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   108
  next
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   109
    case (b4 a s1 s2)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   110
    show ?case
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   111
    proof (simp add: subst_eqvt)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   112
      have f: "\<exists>c::name. c\<sharp>(pi\<bullet>a,pi\<bullet>s1,pi\<bullet>s2,x)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   113
	by (rule at_exists_fresh[OF at_name_inst], simp add: fs_name1)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   114
      then obtain c::"name" 
19218
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   115
	where f1: "c\<noteq>(pi\<bullet>a)" and f2: "c\<sharp>x" and f3: "c\<sharp>(pi\<bullet>s1)" and f4: "c\<sharp>(pi\<bullet>s2)"
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   116
	by (force simp add: fresh_prod fresh_atm)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   117
      have x: "P x (App (Lam [c].(([(c,pi\<bullet>a)]@pi)\<bullet>s1)) (pi\<bullet>s2)) ((([(c,pi\<bullet>a)]@pi)\<bullet>s1)[c::=(pi\<bullet>s2)])"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   118
	using a4 f2 by (blast intro!: eqvt_beta)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   119
      have alpha1: "(Lam [c].([(c,pi\<bullet>a)]\<bullet>(pi\<bullet>s1))) = (Lam [(pi\<bullet>a)].(pi\<bullet>s1))" using f1 f3
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   120
	by (simp add: lam.inject alpha)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   121
      have alpha2: "(([(c,pi\<bullet>a)]@pi)\<bullet>s1)[c::=(pi\<bullet>s2)] = (pi\<bullet>s1)[(pi\<bullet>a)::=(pi\<bullet>s2)]"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   122
	using f3 by (simp only: subst_rename[symmetric] pt_name2)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   123
      show "P x (App (Lam [(pi\<bullet>a)].(pi\<bullet>s1)) (pi\<bullet>s2)) ((pi\<bullet>s1)[(pi\<bullet>a)::=(pi\<bullet>s2)])"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   124
	using x alpha1 alpha2 by (simp only: pt_name2)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   125
    qed
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   126
  qed
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   127
  hence "P x (([]::name prm)\<bullet>t) (([]::name prm)\<bullet>s)" by blast 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   128
  thus ?thesis by simp
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   129
qed
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   130
18378
urbanc
parents: 18348
diff changeset
   131
lemma supp_beta: 
urbanc
parents: 18348
diff changeset
   132
  assumes a: "t\<longrightarrow>\<^isub>\<beta> s"
urbanc
parents: 18348
diff changeset
   133
  shows "(supp s)\<subseteq>((supp t)::name set)"
urbanc
parents: 18348
diff changeset
   134
using a
urbanc
parents: 18348
diff changeset
   135
by (induct)
urbanc
parents: 18348
diff changeset
   136
   (auto intro!: simp add: abs_supp lam.supp subst_supp)
urbanc
parents: 18348
diff changeset
   137
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   138
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   139
lemma beta_abs: "Lam [a].t\<longrightarrow>\<^isub>\<beta> t'\<Longrightarrow>\<exists>t''. t'=Lam [a].t'' \<and> t\<longrightarrow>\<^isub>\<beta> t''"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   140
apply(ind_cases "Lam [a].t  \<longrightarrow>\<^isub>\<beta> t'")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   141
apply(auto simp add: lam.distinct lam.inject)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   142
apply(auto simp add: alpha)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   143
apply(rule_tac x="[(a,aa)]\<bullet>s2" in exI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   144
apply(rule conjI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   145
apply(rule sym)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   146
apply(rule pt_bij2[OF pt_name_inst, OF at_name_inst])
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   147
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   148
apply(rule pt_name3)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   149
apply(simp add: at_ds5[OF at_name_inst])
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   150
apply(rule conjI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   151
apply(simp add: pt_fresh_left[OF pt_name_inst, OF at_name_inst] calc_atm)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   152
apply(force dest!: supp_beta simp add: fresh_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   153
apply(force intro!: eqvt_beta)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   154
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   155
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   156
lemma beta_subst: 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   157
  assumes a: "M \<longrightarrow>\<^isub>\<beta> M'"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   158
  shows "M[x::=N]\<longrightarrow>\<^isub>\<beta> M'[x::=N]" 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   159
using a
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   160
apply(nominal_induct M M' avoiding: x N rule: beta_induct)
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   161
apply(auto simp add: fresh_atm subst_lemma)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   162
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   163
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   164
section {* types *}
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   165
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   166
datatype ty =
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   167
    TVar "string"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   168
  | TArr "ty" "ty" (infix "\<rightarrow>" 200)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   169
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   170
primrec
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   171
 "pi\<bullet>(TVar s) = TVar s"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   172
 "pi\<bullet>(\<tau> \<rightarrow> \<sigma>) = (\<tau> \<rightarrow> \<sigma>)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   173
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   174
lemma perm_ty[simp]:
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   175
  fixes pi ::"name prm"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   176
  and   \<tau>  ::"ty"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   177
  shows "pi\<bullet>\<tau> = \<tau>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   178
  by (cases \<tau>, simp_all)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   179
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   180
lemma fresh_ty:
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   181
  fixes a ::"name"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   182
  and   \<tau>  ::"ty"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   183
  shows "a\<sharp>\<tau>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   184
  by (simp add: fresh_def supp_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   185
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   186
instance ty :: pt_name
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   187
apply(intro_classes)   
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   188
apply(simp_all)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   189
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   190
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   191
instance ty :: fs_name
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   192
apply(intro_classes)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   193
apply(simp add: supp_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   194
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   195
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   196
(* valid contexts *)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   197
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   198
consts
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   199
  "dom_ty" :: "(name\<times>ty) list \<Rightarrow> (name list)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   200
primrec
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   201
  "dom_ty []    = []"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   202
  "dom_ty (x#\<Gamma>) = (fst x)#(dom_ty \<Gamma>)" 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   203
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   204
consts
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   205
  ctxts :: "((name\<times>ty) list) set" 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   206
  valid :: "(name\<times>ty) list \<Rightarrow> bool"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   207
translations
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   208
  "valid \<Gamma>" \<rightleftharpoons> "\<Gamma> \<in> ctxts"  
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   209
inductive ctxts
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   210
intros
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   211
v1[intro]: "valid []"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   212
v2[intro]: "\<lbrakk>valid \<Gamma>;a\<sharp>\<Gamma>\<rbrakk>\<Longrightarrow> valid ((a,\<sigma>)#\<Gamma>)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   213
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   214
lemma valid_eqvt:
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   215
  fixes   pi:: "name prm"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   216
  assumes a: "valid \<Gamma>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   217
  shows   "valid (pi\<bullet>\<Gamma>)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   218
using a
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   219
apply(induct)
18654
94782c7c4247 tuned proofs
urbanc
parents: 18611
diff changeset
   220
apply(auto simp add: fresh_eqvt)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   221
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   222
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   223
(* typing judgements *)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   224
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   225
lemma fresh_context[rule_format]: 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   226
  fixes  \<Gamma> :: "(name\<times>ty)list"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   227
  and    a :: "name"
18378
urbanc
parents: 18348
diff changeset
   228
  assumes a: "a\<sharp>\<Gamma>"
urbanc
parents: 18348
diff changeset
   229
  shows "\<not>(\<exists>\<tau>::ty. (a,\<tau>)\<in>set \<Gamma>)"
urbanc
parents: 18348
diff changeset
   230
using a
urbanc
parents: 18348
diff changeset
   231
apply(induct \<Gamma>)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   232
apply(auto simp add: fresh_prod fresh_list_cons fresh_atm)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   233
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   234
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   235
lemma valid_elim: 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   236
  fixes  \<Gamma> :: "(name\<times>ty)list"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   237
  and    pi:: "name prm"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   238
  and    a :: "name"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   239
  and    \<tau> :: "ty"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   240
  shows "valid ((a,\<tau>)#\<Gamma>) \<Longrightarrow> valid \<Gamma> \<and> a\<sharp>\<Gamma>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   241
apply(ind_cases "valid ((a,\<tau>)#\<Gamma>)", simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   242
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   243
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   244
lemma valid_unicity[rule_format]: 
18378
urbanc
parents: 18348
diff changeset
   245
  assumes a: "valid \<Gamma>"
urbanc
parents: 18348
diff changeset
   246
  and     b: "(c,\<sigma>)\<in>set \<Gamma>"
urbanc
parents: 18348
diff changeset
   247
  and     c: "(c,\<tau>)\<in>set \<Gamma>"
urbanc
parents: 18348
diff changeset
   248
  shows "\<sigma>=\<tau>" 
urbanc
parents: 18348
diff changeset
   249
using a b c
urbanc
parents: 18348
diff changeset
   250
apply(induct \<Gamma>)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   251
apply(auto dest!: valid_elim fresh_context)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   252
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   253
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   254
consts
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   255
  typing :: "(((name\<times>ty) list)\<times>lam\<times>ty) set" 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   256
syntax
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   257
  "_typing_judge" :: "(name\<times>ty) list\<Rightarrow>lam\<Rightarrow>ty\<Rightarrow>bool" (" _ \<turnstile> _ : _ " [80,80,80] 80) 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   258
translations
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   259
  "\<Gamma> \<turnstile> t : \<tau>" \<rightleftharpoons> "(\<Gamma>,t,\<tau>) \<in> typing"  
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   260
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   261
inductive typing
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   262
intros
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   263
t1[intro]: "\<lbrakk>valid \<Gamma>; (a,\<tau>)\<in>set \<Gamma>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> Var a : \<tau>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   264
t2[intro]: "\<lbrakk>\<Gamma> \<turnstile> t1 : \<tau>\<rightarrow>\<sigma>; \<Gamma> \<turnstile> t2 : \<tau>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> App t1 t2 : \<sigma>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   265
t3[intro]: "\<lbrakk>a\<sharp>\<Gamma>;((a,\<tau>)#\<Gamma>) \<turnstile> t : \<sigma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [a].t : \<tau>\<rightarrow>\<sigma>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   266
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   267
lemma eqvt_typing: 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   268
  fixes  \<Gamma> :: "(name\<times>ty) list"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   269
  and    t :: "lam"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   270
  and    \<tau> :: "ty"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   271
  and    pi:: "name prm"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   272
  assumes a: "\<Gamma> \<turnstile> t : \<tau>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   273
  shows "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>t) : \<tau>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   274
using a
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   275
proof (induct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   276
  case (t1 \<Gamma> \<tau> a)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   277
  have "valid (pi\<bullet>\<Gamma>)" by (rule valid_eqvt)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   278
  moreover
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   279
  have "(pi\<bullet>(a,\<tau>))\<in>((pi::name prm)\<bullet>set \<Gamma>)" by (rule pt_set_bij2[OF pt_name_inst, OF at_name_inst])
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   280
  ultimately show "(pi\<bullet>\<Gamma>) \<turnstile> ((pi::name prm)\<bullet>Var a) : \<tau>"
18654
94782c7c4247 tuned proofs
urbanc
parents: 18611
diff changeset
   281
    using typing.t1 by (force simp add: pt_list_set_pi[OF pt_name_inst, symmetric])
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   282
next 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   283
  case (t3 \<Gamma> \<sigma> \<tau> a t)
18654
94782c7c4247 tuned proofs
urbanc
parents: 18611
diff changeset
   284
  moreover have "(pi\<bullet>a)\<sharp>(pi\<bullet>\<Gamma>)" by (simp add: fresh_eqvt)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   285
  ultimately show "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>Lam [a].t) :\<tau>\<rightarrow>\<sigma>" by force 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   286
qed (auto)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   287
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   288
lemma typing_induct[consumes 1, case_names t1 t2 t3]:
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   289
  fixes  P :: "'a::fs_name\<Rightarrow>(name\<times>ty) list \<Rightarrow> lam \<Rightarrow> ty \<Rightarrow>bool"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   290
  and    \<Gamma> :: "(name\<times>ty) list"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   291
  and    t :: "lam"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   292
  and    \<tau> :: "ty"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   293
  and    x :: "'a::fs_name"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   294
  assumes a: "\<Gamma> \<turnstile> t : \<tau>"
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   295
  and a1:    "\<And>\<Gamma> (a::name) \<tau> x. valid \<Gamma> \<Longrightarrow> (a,\<tau>) \<in> set \<Gamma> \<Longrightarrow> P x \<Gamma> (Var a) \<tau>"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   296
  and a2:    "\<And>\<Gamma> \<tau> \<sigma> t1 t2 x. 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   297
              \<Gamma> \<turnstile> t1 : \<tau>\<rightarrow>\<sigma> \<Longrightarrow> (\<And>z. P z \<Gamma> t1 (\<tau>\<rightarrow>\<sigma>)) \<Longrightarrow> \<Gamma> \<turnstile> t2 : \<tau> \<Longrightarrow> (\<And>z. P z \<Gamma> t2 \<tau>)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   298
              \<Longrightarrow> P x \<Gamma> (App t1 t2) \<sigma>"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   299
  and a3:    "\<And>a \<Gamma> \<tau> \<sigma> t x. a\<sharp>x \<Longrightarrow> a\<sharp>\<Gamma> \<Longrightarrow> ((a,\<tau>) # \<Gamma>) \<turnstile> t : \<sigma> \<Longrightarrow> (\<And>z. P z ((a,\<tau>)#\<Gamma>) t \<sigma>)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   300
              \<Longrightarrow> P x \<Gamma> (Lam [a].t) (\<tau>\<rightarrow>\<sigma>)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   301
  shows "P x \<Gamma> t \<tau>"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   302
proof -
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   303
  from a have "\<And>(pi::name prm) x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>t) \<tau>"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   304
  proof (induct)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   305
    case (t1 \<Gamma> \<tau> a)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   306
    have j1: "valid \<Gamma>" by fact
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   307
    have j2: "(a,\<tau>)\<in>set \<Gamma>" by fact
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   308
    from j1 have j3: "valid (pi\<bullet>\<Gamma>)" by (rule valid_eqvt)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   309
    from j2 have "pi\<bullet>(a,\<tau>)\<in>pi\<bullet>(set \<Gamma>)" by (simp only: pt_set_bij[OF pt_name_inst, OF at_name_inst])  
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   310
    hence j4: "(pi\<bullet>a,\<tau>)\<in>set (pi\<bullet>\<Gamma>)" by (simp add: pt_list_set_pi[OF pt_name_inst])
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   311
    show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(Var a)) \<tau>" using a1 j3 j4 by simp
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   312
  next
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   313
    case (t2 \<Gamma> \<sigma> \<tau> t1 t2)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   314
    thus ?case using a2 by (simp, blast intro: eqvt_typing)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   315
  next
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   316
    case (t3 \<Gamma> \<sigma> \<tau> a t)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   317
    have k1: "a\<sharp>\<Gamma>" by fact
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   318
    have k2: "((a,\<tau>)#\<Gamma>)\<turnstile>t:\<sigma>" by fact
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   319
    have k3: "\<And>(pi::name prm) (x::'a::fs_name). P x (pi \<bullet>((a,\<tau>)#\<Gamma>)) (pi\<bullet>t) \<sigma>" by fact
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   320
    have f: "\<exists>c::name. c\<sharp>(pi\<bullet>a,pi\<bullet>t,pi\<bullet>\<Gamma>,x)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   321
      by (rule at_exists_fresh[OF at_name_inst], simp add: fs_name1)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   322
    then obtain c::"name" 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   323
      where f1: "c\<noteq>(pi\<bullet>a)" and f2: "c\<sharp>x" and f3: "c\<sharp>(pi\<bullet>t)" and f4: "c\<sharp>(pi\<bullet>\<Gamma>)"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   324
      by (force simp add: fresh_prod at_fresh[OF at_name_inst])
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   325
    from k1 have k1a: "(pi\<bullet>a)\<sharp>(pi\<bullet>\<Gamma>)" 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   326
      by (simp add: pt_fresh_left[OF pt_name_inst, OF at_name_inst] 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   327
                    pt_rev_pi[OF pt_name_inst, OF at_name_inst])
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   328
    have l1: "(([(c,pi\<bullet>a)]@pi)\<bullet>\<Gamma>) = (pi\<bullet>\<Gamma>)" using f4 k1a 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   329
      by (simp only: pt2[OF pt_name_inst], rule pt_fresh_fresh[OF pt_name_inst, OF at_name_inst])
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   330
    have "\<And>x. P x (([(c,pi\<bullet>a)]@pi)\<bullet>((a,\<tau>)#\<Gamma>)) (([(c,pi\<bullet>a)]@pi)\<bullet>t) \<sigma>" using k3 by force
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   331
    hence l2: "\<And>x. P x ((c, \<tau>)#(pi\<bullet>\<Gamma>)) (([(c,pi\<bullet>a)]@pi)\<bullet>t) \<sigma>" using f1 l1
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   332
      by (force simp add: pt2[OF pt_name_inst]  at_calc[OF at_name_inst])
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   333
    have "(([(c,pi\<bullet>a)]@pi)\<bullet>((a,\<tau>)#\<Gamma>)) \<turnstile> (([(c,pi\<bullet>a)]@pi)\<bullet>t) : \<sigma>" using k2 by (rule eqvt_typing)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   334
    hence l3: "((c, \<tau>)#(pi\<bullet>\<Gamma>)) \<turnstile> (([(c,pi\<bullet>a)]@pi)\<bullet>t) : \<sigma>" using l1 f1 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   335
      by (force simp add: pt2[OF pt_name_inst]  at_calc[OF at_name_inst])
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   336
    have l4: "P x (pi\<bullet>\<Gamma>) (Lam [c].(([(c,pi\<bullet>a)]@pi)\<bullet>t)) (\<tau> \<rightarrow> \<sigma>)" using f2 f4 l2 l3 a3 by auto
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   337
    have alpha: "(Lam [c].([(c,pi\<bullet>a)]\<bullet>(pi\<bullet>t))) = (Lam [(pi\<bullet>a)].(pi\<bullet>t))" using f1 f3
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   338
      by (simp add: lam.inject alpha)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   339
    show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(Lam [a].t)) (\<tau> \<rightarrow> \<sigma>)" using l4 alpha 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   340
      by (simp only: pt2[OF pt_name_inst], simp)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   341
  qed
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   342
  hence "P x (([]::name prm)\<bullet>\<Gamma>) (([]::name prm)\<bullet>t) \<tau>" by blast
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   343
  thus "P x \<Gamma> t \<tau>" by simp
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   344
qed
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   345
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   346
constdefs
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   347
  "sub" :: "(name\<times>ty) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" (" _ \<lless> _ " [80,80] 80)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   348
  "\<Gamma>1 \<lless> \<Gamma>2 \<equiv> \<forall>a \<sigma>. (a,\<sigma>)\<in>set \<Gamma>1 \<longrightarrow>  (a,\<sigma>)\<in>set \<Gamma>2"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   349
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   350
lemma weakening: 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   351
  assumes a: "\<Gamma>1 \<turnstile> t : \<sigma>" 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   352
  and     b: "valid \<Gamma>2" 
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   353
  and     c: "\<Gamma>1 \<lless> \<Gamma>2"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   354
  shows "\<Gamma>2 \<turnstile> t:\<sigma>"
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   355
using a b c
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   356
apply(nominal_induct \<Gamma>1 t \<sigma> avoiding: \<Gamma>2 rule: typing_induct)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   357
apply(auto simp add: sub_def)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   358
(* FIXME: before using meta-connectives and the new induction *)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   359
(* method, this was completely automatic *)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   360
apply(atomize)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   361
apply(auto)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   362
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   363
18378
urbanc
parents: 18348
diff changeset
   364
lemma in_ctxt: 
urbanc
parents: 18348
diff changeset
   365
  assumes a: "(a,\<tau>)\<in>set \<Gamma>"
urbanc
parents: 18348
diff changeset
   366
  shows "a\<in>set(dom_ty \<Gamma>)"
urbanc
parents: 18348
diff changeset
   367
using a
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   368
apply(induct \<Gamma>, auto)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   369
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   370
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   371
lemma free_vars: 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   372
  assumes a: "\<Gamma> \<turnstile> t : \<tau>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   373
  shows " (supp t)\<subseteq>set(dom_ty \<Gamma>)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   374
using a
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   375
apply(nominal_induct \<Gamma> t \<tau> rule: typing_induct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   376
apply(auto simp add: lam.supp abs_supp supp_atm in_ctxt)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   377
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   378
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   379
lemma t1_elim: "\<Gamma> \<turnstile> Var a : \<tau> \<Longrightarrow> valid \<Gamma> \<and> (a,\<tau>) \<in> set \<Gamma>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   380
apply(ind_cases "\<Gamma> \<turnstile> Var a : \<tau>")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   381
apply(auto simp add: lam.inject lam.distinct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   382
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   383
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   384
lemma t2_elim: "\<Gamma> \<turnstile> App t1 t2 : \<sigma> \<Longrightarrow> \<exists>\<tau>. (\<Gamma> \<turnstile> t1 : \<tau>\<rightarrow>\<sigma> \<and> \<Gamma> \<turnstile> t2 : \<tau>)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   385
apply(ind_cases "\<Gamma> \<turnstile> App t1 t2 : \<sigma>")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   386
apply(auto simp add: lam.inject lam.distinct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   387
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   388
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   389
lemma t3_elim: "\<lbrakk>\<Gamma> \<turnstile> Lam [a].t : \<sigma>;a\<sharp>\<Gamma>\<rbrakk>\<Longrightarrow> \<exists>\<tau> \<tau>'. \<sigma>=\<tau>\<rightarrow>\<tau>' \<and> ((a,\<tau>)#\<Gamma>) \<turnstile> t : \<tau>'"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   390
apply(ind_cases "\<Gamma> \<turnstile> Lam [a].t : \<sigma>")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   391
apply(auto simp add: lam.distinct lam.inject alpha) 
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   392
apply(drule_tac pi="[(a,aa)]::name prm" in eqvt_typing)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   393
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   394
apply(subgoal_tac "([(a,aa)]::name prm)\<bullet>\<Gamma> = \<Gamma>")(*A*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   395
apply(force simp add: calc_atm)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   396
(*A*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   397
apply(force intro!: pt_fresh_fresh[OF pt_name_inst, OF at_name_inst])
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   398
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   399
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   400
lemma typing_valid: 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   401
  assumes a: "\<Gamma> \<turnstile> t : \<tau>" 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   402
  shows "valid \<Gamma>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   403
using a by (induct, auto dest!: valid_elim)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   404
18378
urbanc
parents: 18348
diff changeset
   405
lemma ty_subs:
urbanc
parents: 18348
diff changeset
   406
  assumes a: "((c,\<sigma>)#\<Gamma>) \<turnstile> t1:\<tau>"
urbanc
parents: 18348
diff changeset
   407
  and     b: "\<Gamma>\<turnstile> t2:\<sigma>"
urbanc
parents: 18348
diff changeset
   408
  shows  "\<Gamma> \<turnstile> t1[c::=t2]:\<tau>"
urbanc
parents: 18348
diff changeset
   409
using a b
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
   410
proof(nominal_induct t1 avoiding: \<Gamma> \<sigma> \<tau> c t2 rule: lam.induct)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   411
  case (Var a) 
18378
urbanc
parents: 18348
diff changeset
   412
  have a1: "\<Gamma> \<turnstile>t2:\<sigma>" by fact
urbanc
parents: 18348
diff changeset
   413
  have a2: "((c,\<sigma>)#\<Gamma>) \<turnstile> Var a:\<tau>" by fact
urbanc
parents: 18348
diff changeset
   414
  hence a21: "(a,\<tau>)\<in>set((c,\<sigma>)#\<Gamma>)" and a22: "valid((c,\<sigma>)#\<Gamma>)" by (auto dest: t1_elim)
urbanc
parents: 18348
diff changeset
   415
  from a22 have a23: "valid \<Gamma>" and a24: "c\<sharp>\<Gamma>" by (auto dest: valid_elim) 
urbanc
parents: 18348
diff changeset
   416
  from a24 have a25: "\<not>(\<exists>\<tau>. (c,\<tau>)\<in>set \<Gamma>)" by (rule fresh_context)
urbanc
parents: 18348
diff changeset
   417
  show "\<Gamma>\<turnstile>(Var a)[c::=t2] : \<tau>"
urbanc
parents: 18348
diff changeset
   418
  proof (cases "a=c", simp_all)
urbanc
parents: 18348
diff changeset
   419
    assume case1: "a=c"
urbanc
parents: 18348
diff changeset
   420
    show "\<Gamma> \<turnstile> t2:\<tau>" using a1
urbanc
parents: 18348
diff changeset
   421
    proof (cases "\<sigma>=\<tau>")
urbanc
parents: 18348
diff changeset
   422
      assume "\<sigma>=\<tau>" thus ?thesis using a1 by simp 
urbanc
parents: 18348
diff changeset
   423
    next
urbanc
parents: 18348
diff changeset
   424
      assume a3: "\<sigma>\<noteq>\<tau>"
urbanc
parents: 18348
diff changeset
   425
      show ?thesis
urbanc
parents: 18348
diff changeset
   426
      proof (rule ccontr)
urbanc
parents: 18348
diff changeset
   427
	from a3 a21 have "(a,\<tau>)\<in>set \<Gamma>" by force
urbanc
parents: 18348
diff changeset
   428
	with case1 a25 show False by force 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   429
      qed
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   430
    qed
18378
urbanc
parents: 18348
diff changeset
   431
  next
urbanc
parents: 18348
diff changeset
   432
    assume case2: "a\<noteq>c"
urbanc
parents: 18348
diff changeset
   433
    with a21 have a26: "(a,\<tau>)\<in>set \<Gamma>" by force 
urbanc
parents: 18348
diff changeset
   434
    from a23 a26 show "\<Gamma> \<turnstile> Var a:\<tau>" by force
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   435
  qed
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   436
next
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   437
  case (App s1 s2)
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   438
  have ih_s1: "\<And>c \<sigma> \<tau> t2 \<Gamma>. ((c,\<sigma>)#\<Gamma>) \<turnstile> s1:\<tau> \<Longrightarrow> \<Gamma>\<turnstile> t2: \<sigma> \<Longrightarrow> \<Gamma> \<turnstile> s1[c::=t2]:\<tau>" by fact
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   439
  have ih_s2: "\<And>c \<sigma> \<tau> t2 \<Gamma>. ((c,\<sigma>)#\<Gamma>) \<turnstile> s2:\<tau> \<Longrightarrow> \<Gamma>\<turnstile> t2: \<sigma> \<Longrightarrow> \<Gamma> \<turnstile> s2[c::=t2]:\<tau>" by fact
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   440
  have "((c,\<sigma>)#\<Gamma>)\<turnstile>App s1 s2 : \<tau>" by fact
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   441
  hence "\<exists>\<tau>'. ((c,\<sigma>)#\<Gamma>)\<turnstile>s1:\<tau>'\<rightarrow>\<tau> \<and> ((c,\<sigma>)#\<Gamma>)\<turnstile>s2:\<tau>'" by (rule t2_elim) 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   442
  then obtain \<tau>' where "((c,\<sigma>)#\<Gamma>)\<turnstile>s1:\<tau>'\<rightarrow>\<tau>" and "((c,\<sigma>)#\<Gamma>)\<turnstile>s2:\<tau>'" by blast
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   443
  moreover
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   444
  have "\<Gamma> \<turnstile>t2:\<sigma>" by fact
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   445
  ultimately show "\<Gamma> \<turnstile>  (App s1 s2)[c::=t2] : \<tau>" using ih_s1 ih_s2 by (simp, blast)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   446
next
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   447
  case (Lam a s)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   448
  have "a\<sharp>\<Gamma>" "a\<sharp>\<sigma>" "a\<sharp>\<tau>" "a\<sharp>c" "a\<sharp>t2" by fact 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   449
  hence f1: "a\<sharp>\<Gamma>" and f2: "a\<noteq>c" and f2': "c\<sharp>a" and f3: "a\<sharp>t2" and f4: "a\<sharp>((c,\<sigma>)#\<Gamma>)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   450
    by (auto simp add: fresh_atm fresh_prod fresh_list_cons)
18378
urbanc
parents: 18348
diff changeset
   451
  have c1: "((c,\<sigma>)#\<Gamma>)\<turnstile>Lam [a].s : \<tau>" by fact
urbanc
parents: 18348
diff changeset
   452
  hence "\<exists>\<tau>1 \<tau>2. \<tau>=\<tau>1\<rightarrow>\<tau>2 \<and> ((a,\<tau>1)#(c,\<sigma>)#\<Gamma>) \<turnstile> s : \<tau>2" using f4 by (auto dest: t3_elim) 
urbanc
parents: 18348
diff changeset
   453
  then obtain \<tau>1 \<tau>2 where c11: "\<tau>=\<tau>1\<rightarrow>\<tau>2" and c12: "((a,\<tau>1)#(c,\<sigma>)#\<Gamma>) \<turnstile> s : \<tau>2" by force
urbanc
parents: 18348
diff changeset
   454
  from c12 have "valid ((a,\<tau>1)#(c,\<sigma>)#\<Gamma>)" by (rule typing_valid)
urbanc
parents: 18348
diff changeset
   455
  hence ca: "valid \<Gamma>" and cb: "a\<sharp>\<Gamma>" and cc: "c\<sharp>\<Gamma>" 
urbanc
parents: 18348
diff changeset
   456
    by (auto dest: valid_elim simp add: fresh_list_cons) 
urbanc
parents: 18348
diff changeset
   457
  from c12 have c14: "((c,\<sigma>)#(a,\<tau>1)#\<Gamma>) \<turnstile> s : \<tau>2"
urbanc
parents: 18348
diff changeset
   458
  proof -
urbanc
parents: 18348
diff changeset
   459
    have c2: "((a,\<tau>1)#(c,\<sigma>)#\<Gamma>) \<lless> ((c,\<sigma>)#(a,\<tau>1)#\<Gamma>)" by (force simp add: sub_def)
urbanc
parents: 18348
diff changeset
   460
    have c3: "valid ((c,\<sigma>)#(a,\<tau>1)#\<Gamma>)"
urbanc
parents: 18348
diff changeset
   461
      by (rule v2, rule v2, auto simp add: fresh_list_cons fresh_prod ca cb cc f2' fresh_ty)
urbanc
parents: 18348
diff changeset
   462
    from c12 c2 c3 show ?thesis by (force intro: weakening)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   463
  qed
18378
urbanc
parents: 18348
diff changeset
   464
  assume c8: "\<Gamma> \<turnstile> t2 : \<sigma>"
urbanc
parents: 18348
diff changeset
   465
  have c81: "((a,\<tau>1)#\<Gamma>)\<turnstile>t2 :\<sigma>"
urbanc
parents: 18348
diff changeset
   466
  proof -
urbanc
parents: 18348
diff changeset
   467
    have c82: "\<Gamma> \<lless> ((a,\<tau>1)#\<Gamma>)" by (force simp add: sub_def)
urbanc
parents: 18348
diff changeset
   468
    have c83: "valid ((a,\<tau>1)#\<Gamma>)" using f1 ca by force
urbanc
parents: 18348
diff changeset
   469
    with c8 c82 c83 show ?thesis by (force intro: weakening)
urbanc
parents: 18348
diff changeset
   470
  qed
urbanc
parents: 18348
diff changeset
   471
  show "\<Gamma> \<turnstile> (Lam [a].s)[c::=t2] : \<tau>"
urbanc
parents: 18348
diff changeset
   472
    using c11 prems c14 c81 f1 by force
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   473
qed
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   474
18378
urbanc
parents: 18348
diff changeset
   475
lemma subject: 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   476
  assumes a: "t1\<longrightarrow>\<^isub>\<beta>t2"
18378
urbanc
parents: 18348
diff changeset
   477
  and     b: "\<Gamma> \<turnstile> t1:\<tau>"
urbanc
parents: 18348
diff changeset
   478
  shows "\<Gamma> \<turnstile> t2:\<tau>"
urbanc
parents: 18348
diff changeset
   479
using a b
urbanc
parents: 18348
diff changeset
   480
proof (nominal_induct t1 t2 avoiding: \<Gamma> \<tau> rule: beta_induct)
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   481
  case (b1 t s1 s2) --"App-case left"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   482
  have ih: "\<And>\<Gamma> \<tau>. \<Gamma> \<turnstile> s1:\<tau> \<Longrightarrow> \<Gamma> \<turnstile> s2 : \<tau>" by fact
18378
urbanc
parents: 18348
diff changeset
   483
  have "\<Gamma> \<turnstile> App s1 t : \<tau>" by fact 
urbanc
parents: 18348
diff changeset
   484
  hence "\<exists>\<sigma>. \<Gamma> \<turnstile> s1 : \<sigma>\<rightarrow>\<tau> \<and> \<Gamma> \<turnstile> t : \<sigma>" by (rule t2_elim)
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   485
  then obtain \<sigma> where "\<Gamma> \<turnstile> s1 : \<sigma>\<rightarrow>\<tau>" and "\<Gamma> \<turnstile> t : \<sigma>" by blast
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   486
  with ih show "\<Gamma> \<turnstile> App s2 t : \<tau>" by blast
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   487
next
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   488
  case (b2 t s1 s2) --"App-case right"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   489
  have ih: "\<And>\<Gamma> \<tau>. \<Gamma> \<turnstile> s1 : \<tau> \<Longrightarrow> \<Gamma> \<turnstile> s2 : \<tau>" by fact 
18378
urbanc
parents: 18348
diff changeset
   490
  have "\<Gamma> \<turnstile> App t s1 : \<tau>" by fact
urbanc
parents: 18348
diff changeset
   491
  hence "\<exists>\<sigma>. \<Gamma> \<turnstile> t : \<sigma>\<rightarrow>\<tau> \<and> \<Gamma> \<turnstile> s1 : \<sigma>" by (rule t2_elim)
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   492
  then obtain \<sigma> where "\<Gamma> \<turnstile> t : \<sigma>\<rightarrow>\<tau>" and "\<Gamma> \<turnstile> s1 : \<sigma>" by blast
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   493
  with ih show "\<Gamma> \<turnstile> App t s2 : \<tau>" by blast
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   494
next
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   495
  case (b3 a s1 s2) --"Lam-case"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   496
  have fr: "a\<sharp>\<Gamma>" "a\<sharp>\<tau>" by fact
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   497
  have ih: "\<And>\<Gamma> \<tau>. \<Gamma> \<turnstile> s1 : \<tau> \<Longrightarrow> \<Gamma> \<turnstile> s2 : \<tau>" by fact
18378
urbanc
parents: 18348
diff changeset
   498
  have "\<Gamma> \<turnstile> Lam [a].s1 : \<tau>" by fact
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   499
  with fr have "\<exists>\<tau>1 \<tau>2. \<tau>=\<tau>1\<rightarrow>\<tau>2 \<and> ((a,\<tau>1)#\<Gamma>) \<turnstile> s1 : \<tau>2" by (simp add: t3_elim)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   500
  then obtain \<tau>1 \<tau>2 where "\<tau>=\<tau>1\<rightarrow>\<tau>2" and "((a,\<tau>1)#\<Gamma>) \<turnstile> s1 : \<tau>2" by blast
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   501
  with ih show "\<Gamma> \<turnstile> Lam [a].s2 : \<tau>" using fr by blast
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   502
next
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   503
  case (b4 a s1 s2) --"Beta-redex"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   504
  have fr: "a\<sharp>\<Gamma>" by fact
18378
urbanc
parents: 18348
diff changeset
   505
  have "\<Gamma> \<turnstile> App (Lam [a].s1) s2 : \<tau>" by fact
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   506
  hence "\<exists>\<sigma>. (\<Gamma> \<turnstile> (Lam [a].s1) : \<sigma>\<rightarrow>\<tau> \<and> \<Gamma> \<turnstile> s2 : \<sigma>)" by (simp add: t2_elim)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   507
  then obtain \<sigma> where a1: "\<Gamma> \<turnstile> (Lam [a].s1) : \<sigma>\<rightarrow>\<tau>" and a2: "\<Gamma> \<turnstile> s2 : \<sigma>" by blast
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   508
  from a1 have "((a,\<sigma>)#\<Gamma>) \<turnstile> s1 : \<tau>" using fr by (blast dest!: t3_elim)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   509
  with a2 show "\<Gamma> \<turnstile> s1[a::=s2] : \<tau>" by (simp add: ty_subs)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   510
qed
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   511
18378
urbanc
parents: 18348
diff changeset
   512
lemma subject_automatic: 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   513
  assumes a: "t1\<longrightarrow>\<^isub>\<beta>t2"
18378
urbanc
parents: 18348
diff changeset
   514
  and     b: "\<Gamma> \<turnstile> t1:\<tau>"
urbanc
parents: 18348
diff changeset
   515
  shows "\<Gamma> \<turnstile> t2:\<tau>"
urbanc
parents: 18348
diff changeset
   516
using a b
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   517
apply(nominal_induct t1 t2 avoiding: \<Gamma> \<tau> rule: beta_induct)
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   518
apply(auto dest!: t2_elim t3_elim intro: ty_subs)
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   519
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   520
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   521
subsection {* some facts about beta *}
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   522
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   523
constdefs
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   524
  "NORMAL" :: "lam \<Rightarrow> bool"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   525
  "NORMAL t \<equiv> \<not>(\<exists>t'. t\<longrightarrow>\<^isub>\<beta> t')"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   526
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   527
lemma NORMAL_Var:
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   528
  shows "NORMAL (Var a)"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   529
proof -
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   530
  { assume "\<exists>t'. (Var a) \<longrightarrow>\<^isub>\<beta> t'"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   531
    then obtain t' where "(Var a) \<longrightarrow>\<^isub>\<beta> t'" by blast
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   532
    hence False by (cases, auto) 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   533
  }
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   534
  thus "NORMAL (Var a)" by (force simp add: NORMAL_def)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   535
qed
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   536
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   537
constdefs
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   538
  "SN" :: "lam \<Rightarrow> bool"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   539
  "SN t \<equiv> t\<in>termi Beta"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   540
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   541
lemma SN_preserved: "\<lbrakk>SN(t1);t1\<longrightarrow>\<^isub>\<beta> t2\<rbrakk>\<Longrightarrow>SN(t2)"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   542
apply(simp add: SN_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   543
apply(drule_tac a="t2" in acc_downward)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   544
apply(auto)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   545
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   546
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   547
lemma SN_intro: "(\<forall>t2. t1\<longrightarrow>\<^isub>\<beta>t2 \<longrightarrow> SN(t2))\<Longrightarrow>SN(t1)"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   548
apply(simp add: SN_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   549
apply(rule accI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   550
apply(auto)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   551
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   552
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   553
section {* Candidates *}
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   554
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   555
consts
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   556
  RED :: "ty \<Rightarrow> lam set"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   557
primrec
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   558
 "RED (TVar X) = {t. SN(t)}"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   559
 "RED (\<tau>\<rightarrow>\<sigma>) =   {t. \<forall>u. (u\<in>RED \<tau> \<longrightarrow> (App t u)\<in>RED \<sigma>)}"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   560
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   561
constdefs
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   562
  NEUT :: "lam \<Rightarrow> bool"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   563
  "NEUT t \<equiv> (\<exists>a. t=Var a)\<or>(\<exists>t1 t2. t=App t1 t2)" 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   564
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   565
(* a slight hack to get the first element of applications *)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   566
consts
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   567
  FST :: "(lam\<times>lam) set"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   568
syntax 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   569
  "FST_judge"   :: "lam\<Rightarrow>lam\<Rightarrow>bool" (" _ \<guillemotright> _" [80,80] 80)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   570
translations 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   571
  "t1 \<guillemotright> t2" \<rightleftharpoons> "(t1,t2) \<in> FST"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   572
inductive FST
18378
urbanc
parents: 18348
diff changeset
   573
  intros
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   574
fst[intro!]:  "(App t s) \<guillemotright> t"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   575
18378
urbanc
parents: 18348
diff changeset
   576
lemma fst_elim[elim!]: 
urbanc
parents: 18348
diff changeset
   577
  shows "(App t s) \<guillemotright> t' \<Longrightarrow> t=t'"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   578
apply(ind_cases "App t s \<guillemotright> t'")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   579
apply(simp add: lam.inject)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   580
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   581
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   582
lemma qq3: "SN(App t s)\<Longrightarrow>SN(t)"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   583
apply(simp add: SN_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   584
apply(subgoal_tac "\<forall>z. (App t s \<guillemotright> z) \<longrightarrow> z\<in>termi Beta")(*A*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   585
apply(force)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   586
(*A*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   587
apply(erule acc_induct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   588
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   589
apply(ind_cases "x \<guillemotright> z")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   590
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   591
apply(rule accI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   592
apply(auto intro: b1)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   593
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   594
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   595
section {* Candidates *}
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   596
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   597
constdefs
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   598
  "CR1" :: "ty \<Rightarrow> bool"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   599
  "CR1 \<tau> \<equiv> \<forall> t. (t\<in>RED \<tau> \<longrightarrow> SN(t))"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   600
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   601
  "CR2" :: "ty \<Rightarrow> bool"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   602
  "CR2 \<tau> \<equiv> \<forall>t t'. (t\<in>RED \<tau> \<and> t \<longrightarrow>\<^isub>\<beta> t') \<longrightarrow> t'\<in>RED \<tau>"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   603
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   604
  "CR3_RED" :: "lam \<Rightarrow> ty \<Rightarrow> bool"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   605
  "CR3_RED t \<tau> \<equiv> \<forall>t'. t\<longrightarrow>\<^isub>\<beta> t' \<longrightarrow>  t'\<in>RED \<tau>" 
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   606
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   607
  "CR3" :: "ty \<Rightarrow> bool"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   608
  "CR3 \<tau> \<equiv> \<forall>t. (NEUT t \<and> CR3_RED t \<tau>) \<longrightarrow> t\<in>RED \<tau>"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   609
   
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   610
  "CR4" :: "ty \<Rightarrow> bool"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   611
  "CR4 \<tau> \<equiv> \<forall>t. (NEUT t \<and> NORMAL t) \<longrightarrow>t\<in>RED \<tau>"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   612
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   613
lemma CR3_CR4: "CR3 \<tau> \<Longrightarrow> CR4 \<tau>"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   614
apply(simp (no_asm_use) add: CR3_def CR3_RED_def CR4_def NORMAL_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   615
apply(blast)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   616
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   617
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   618
lemma sub_ind: 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   619
  "SN(u)\<Longrightarrow>(u\<in>RED \<tau>\<longrightarrow>(\<forall>t. (NEUT t\<and>CR2 \<tau>\<and>CR3 \<sigma>\<and>CR3_RED t (\<tau>\<rightarrow>\<sigma>))\<longrightarrow>(App t u)\<in>RED \<sigma>))"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   620
apply(simp add: SN_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   621
apply(erule acc_induct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   622
apply(auto)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   623
apply(simp add: CR3_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   624
apply(rotate_tac 5)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   625
apply(drule_tac x="App t x" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   626
apply(drule mp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   627
apply(rule conjI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   628
apply(force simp only: NEUT_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   629
apply(simp (no_asm) add: CR3_RED_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   630
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   631
apply(ind_cases "App t x \<longrightarrow>\<^isub>\<beta> t'")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   632
apply(simp_all add: lam.inject)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   633
apply(simp only:  CR3_RED_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   634
apply(drule_tac x="s2" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   635
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   636
apply(drule_tac x="s2" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   637
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   638
apply(drule mp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   639
apply(simp (no_asm_use) add: CR2_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   640
apply(blast)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   641
apply(drule_tac x="ta" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   642
apply(force)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   643
apply(auto simp only: NEUT_def lam.inject lam.distinct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   644
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   645
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   646
lemma RED_props: 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   647
  shows "CR1 \<tau>" and "CR2 \<tau>" and "CR3 \<tau>"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   648
proof (induct \<tau>)
18611
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   649
  case (TVar a)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   650
  { case 1 show "CR1 (TVar a)" by (simp add: CR1_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   651
  next
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   652
    case 2 show "CR2 (TVar a)" by (force intro: SN_preserved simp add: CR2_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   653
  next
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   654
    case 3 show "CR3 (TVar a)" by (force intro: SN_intro simp add: CR3_def CR3_RED_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   655
  }
18599
e01112713fdc changed PRO_RED proof to conform with the new induction rules
urbanc
parents: 18383
diff changeset
   656
next
18611
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   657
  case (TArr \<tau>1 \<tau>2)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   658
  { case 1
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   659
    have ih_CR3_\<tau>1: "CR3 \<tau>1" by fact
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   660
    have ih_CR1_\<tau>2: "CR1 \<tau>2" by fact
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   661
    show "CR1 (\<tau>1 \<rightarrow> \<tau>2)"
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   662
    proof (simp add: CR1_def, intro strip)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   663
      fix t
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   664
      assume a: "\<forall>u. u \<in> RED \<tau>1 \<longrightarrow> App t u \<in> RED \<tau>2"
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   665
      from ih_CR3_\<tau>1 have "CR4 \<tau>1" by (simp add: CR3_CR4) 
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   666
      moreover
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   667
      have "NEUT (Var a)" by (force simp add: NEUT_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   668
      moreover
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   669
      have "NORMAL (Var a)" by (rule NORMAL_Var)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   670
      ultimately have "(Var a)\<in> RED \<tau>1" by (simp add: CR4_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   671
      with a have "App t (Var a) \<in> RED \<tau>2" by simp
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   672
      hence "SN (App t (Var a))" using ih_CR1_\<tau>2 by (simp add: CR1_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   673
      thus "SN(t)" by (rule qq3)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   674
    qed
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   675
  next
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   676
    case 2
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   677
    have ih_CR1_\<tau>1: "CR1 \<tau>1" by fact
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   678
    have ih_CR2_\<tau>2: "CR2 \<tau>2" by fact
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   679
    show "CR2 (\<tau>1 \<rightarrow> \<tau>2)"
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   680
    proof (simp add: CR2_def, intro strip)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   681
      fix t1 t2 u
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   682
      assume "(\<forall>u. u \<in> RED \<tau>1 \<longrightarrow> App t1 u \<in> RED \<tau>2) \<and>  t1 \<longrightarrow>\<^isub>\<beta> t2" 
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   683
	and  "u \<in> RED \<tau>1"
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   684
      hence "t1 \<longrightarrow>\<^isub>\<beta> t2" and "App t1 u \<in> RED \<tau>2" by simp_all
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   685
      thus "App t2 u \<in> RED \<tau>2" using ih_CR2_\<tau>2 by (force simp add: CR2_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   686
    qed
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   687
  next
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   688
    case 3
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   689
    have ih_CR1_\<tau>1: "CR1 \<tau>1" by fact
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   690
    have ih_CR2_\<tau>1: "CR2 \<tau>1" by fact
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   691
    have ih_CR3_\<tau>2: "CR3 \<tau>2" by fact
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   692
    show "CR3 (\<tau>1 \<rightarrow> \<tau>2)"
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   693
    proof (simp add: CR3_def, intro strip)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   694
      fix t u
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   695
      assume a1: "u \<in> RED \<tau>1"
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   696
      assume a2: "NEUT t \<and> CR3_RED t (\<tau>1 \<rightarrow> \<tau>2)"
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   697
      from a1 have "SN(u)" using ih_CR1_\<tau>1 by (simp add: CR1_def)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   698
      hence "u\<in>RED \<tau>1\<longrightarrow>(\<forall>t. (NEUT t\<and>CR2 \<tau>1\<and>CR3 \<tau>2\<and>CR3_RED t (\<tau>1\<rightarrow>\<tau>2))\<longrightarrow>(App t u)\<in>RED \<tau>2)" 
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   699
	by (rule sub_ind)
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   700
      with a1 a2 show "(App t u)\<in>RED \<tau>2" using ih_CR2_\<tau>1 ih_CR3_\<tau>2 by simp
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   701
    qed
687c9bffbca1 another change for the new induct-method
urbanc
parents: 18599
diff changeset
   702
  }
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   703
qed
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   704
    
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   705
lemma double_acc_aux:
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   706
  assumes a_acc: "a \<in> acc r"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   707
  and b_acc: "b \<in> acc r"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   708
  and hyp: "\<And>x z.
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   709
    (\<And>y. (y, x) \<in> r \<Longrightarrow> y \<in> acc r) \<Longrightarrow>
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   710
    (\<And>y. (y, x) \<in> r \<Longrightarrow> P y z) \<Longrightarrow>
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   711
    (\<And>u. (u, z) \<in> r \<Longrightarrow> u \<in> acc r) \<Longrightarrow>
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   712
    (\<And>u. (u, z) \<in> r \<Longrightarrow> P x u) \<Longrightarrow> P x z"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   713
  shows "P a b"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   714
proof -
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   715
  from a_acc
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   716
  have r: "\<And>b. b \<in> acc r \<Longrightarrow> P a b"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   717
  proof (induct a rule: acc.induct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   718
    case (accI x)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   719
    note accI' = accI
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   720
    have "b \<in> acc r" .
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   721
    thus ?case
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   722
    proof (induct b rule: acc.induct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   723
      case (accI y)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   724
      show ?case
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   725
	apply (rule hyp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   726
	apply (erule accI')
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   727
	apply (erule accI')
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   728
	apply (rule acc.accI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   729
	apply (erule accI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   730
	apply (erule accI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   731
	apply (erule accI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   732
	done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   733
    qed
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   734
  qed
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   735
  from b_acc show ?thesis by (rule r)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   736
qed
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   737
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   738
lemma double_acc:
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   739
  "\<lbrakk>a \<in> acc r; b \<in> acc r; \<forall>x z. ((\<forall>y. (y, x)\<in>r\<longrightarrow>P y z)\<and>(\<forall>u. (u, z)\<in>r\<longrightarrow>P x u))\<longrightarrow>P x z\<rbrakk>\<Longrightarrow>P a b"
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   740
apply(rule_tac r="r" in double_acc_aux)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   741
apply(assumption)+
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   742
apply(blast)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   743
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   744
18263
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   745
lemma abs_RED: "(\<forall>s\<in>RED \<tau>. t[x::=s]\<in>RED \<sigma>)\<longrightarrow>Lam [x].t\<in>RED (\<tau>\<rightarrow>\<sigma>)"
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   746
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   747
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   748
apply(subgoal_tac "t\<in>termi Beta")(*1*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   749
apply(erule rev_mp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   750
apply(subgoal_tac "u \<in> RED \<tau>")(*A*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   751
apply(erule rev_mp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   752
apply(rule_tac a="t" and b="u" in double_acc)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   753
apply(assumption)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   754
apply(subgoal_tac "CR1 \<tau>")(*A*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   755
apply(simp add: CR1_def SN_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   756
(*A*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   757
apply(force simp add: RED_props)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   758
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   759
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   760
apply(subgoal_tac "CR3 \<sigma>")(*B*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   761
apply(simp add: CR3_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   762
apply(rotate_tac 6)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   763
apply(drule_tac x="App(Lam[x].xa ) z" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   764
apply(drule mp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   765
apply(rule conjI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   766
apply(force simp add: NEUT_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   767
apply(simp add: CR3_RED_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   768
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   769
apply(ind_cases "App(Lam[x].xa) z \<longrightarrow>\<^isub>\<beta> t'")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   770
apply(auto simp add: lam.inject lam.distinct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   771
apply(drule beta_abs)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   772
apply(auto)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   773
apply(drule_tac x="t''" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   774
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   775
apply(drule mp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   776
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   777
apply(drule_tac x="s" in bspec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   778
apply(assumption)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   779
apply(subgoal_tac "xa [ x ::= s ] \<longrightarrow>\<^isub>\<beta>  t'' [ x ::= s ]")(*B*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   780
apply(subgoal_tac "CR2 \<sigma>")(*C*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   781
apply(simp (no_asm_use) add: CR2_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   782
apply(blast)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   783
(*C*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   784
apply(force simp add: RED_props)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   785
(*B*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   786
apply(force intro!: beta_subst)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   787
apply(assumption)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   788
apply(rotate_tac 3)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   789
apply(drule_tac x="s2" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   790
apply(subgoal_tac "s2\<in>RED \<tau>")(*D*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   791
apply(simp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   792
(*D*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   793
apply(subgoal_tac "CR2 \<tau>")(*E*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   794
apply(simp (no_asm_use) add: CR2_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   795
apply(blast)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   796
(*E*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   797
apply(force simp add: RED_props)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   798
apply(simp add: alpha)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   799
apply(erule disjE)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   800
apply(force)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   801
apply(auto)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   802
apply(simp add: subst_rename)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   803
apply(drule_tac x="z" in bspec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   804
apply(assumption)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   805
(*B*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   806
apply(force simp add: RED_props)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   807
(*1*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   808
apply(drule_tac x="Var x" in bspec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   809
apply(subgoal_tac "CR3 \<tau>")(*2*) 
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   810
apply(drule CR3_CR4)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   811
apply(simp add: CR4_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   812
apply(drule_tac x="Var x" in spec)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   813
apply(drule mp)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   814
apply(rule conjI)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   815
apply(force simp add: NEUT_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   816
apply(simp add: NORMAL_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   817
apply(clarify)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   818
apply(ind_cases "Var x \<longrightarrow>\<^isub>\<beta> t'")
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   819
apply(auto simp add: lam.inject lam.distinct)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   820
apply(force simp add: RED_props)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   821
apply(simp add: id_subs)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   822
apply(subgoal_tac "CR1 \<sigma>")(*3*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   823
apply(simp add: CR1_def SN_def)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   824
(*3*)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   825
apply(force simp add: RED_props)
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   826
done
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   827
18378
urbanc
parents: 18348
diff changeset
   828
lemma fresh_domain: 
urbanc
parents: 18348
diff changeset
   829
  assumes a: "a\<sharp>\<theta>"
urbanc
parents: 18348
diff changeset
   830
  shows "a\<notin>set(domain \<theta>)"
urbanc
parents: 18348
diff changeset
   831
using a
urbanc
parents: 18348
diff changeset
   832
apply(induct \<theta>)
18263
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   833
apply(auto simp add: fresh_prod fresh_list_cons fresh_atm)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   834
done
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   835
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   836
lemma fresh_at: 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   837
  assumes a: "a\<in>set(domain \<theta>)" 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   838
  and     b: "c\<sharp>\<theta>" 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   839
  shows "c\<sharp>(\<theta><a>)"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   840
using a b
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   841
apply(induct \<theta>)   
18263
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   842
apply(auto simp add: fresh_prod fresh_list_cons)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   843
done
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   844
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   845
lemma psubst_subst: 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   846
  assumes a: "c\<sharp>\<theta>"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   847
  shows "(t[<\<theta>>])[c::=s] = t[<((c,s)#\<theta>)>]"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   848
using a
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
   849
apply(nominal_induct t avoiding: \<theta> c s rule: lam.induct)
18263
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   850
apply(auto dest: fresh_domain)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   851
apply(drule fresh_at)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   852
apply(assumption)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   853
apply(rule forget)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   854
apply(assumption)
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
   855
apply(subgoal_tac "name\<sharp>((c,s)#\<theta>)")(*A*)
18313
e61d2424863d initial cleanup to use the new induction method
urbanc
parents: 18269
diff changeset
   856
apply(simp)
18263
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   857
(*A*)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   858
apply(simp add: fresh_list_cons fresh_prod)
7f75925498da cleaned up all examples so that they work with the
urbanc
parents: 18106
diff changeset
   859
done
18106
836135c8acb2 Initial commit.
urbanc
parents:
diff changeset
   860
lemma all_RED: 
18345
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   861
  assumes a: "\<Gamma>\<turnstile>t:\<tau>"
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   862
  and     b: "\<forall>a \<sigma>. (a,\<sigma>)\<in>set(\<Gamma>) \<longrightarrow> (a\<in>set(domain \<theta>)\<and>\<theta><a>\<in>RED \<sigma>)" 
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   863
  shows "t[<\<theta>>]\<in>RED \<tau>"
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   864
using a b
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
   865
proof(nominal_induct t avoiding: \<Gamma> \<tau> \<theta> rule: lam.induct)
18345
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   866
  case (Lam a t) --"lambda case"
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   867
  have ih: "\<And>\<Gamma> \<tau> \<theta>. \<Gamma> \<turnstile> t:\<tau> \<Longrightarrow> 
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   868
                    (\<forall>c \<sigma>. (c,\<sigma>)\<in>set \<Gamma> \<longrightarrow> c\<in>set (domain \<theta>) \<and>  \<theta><c>\<in>RED \<sigma>) 
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   869
                    \<Longrightarrow> t[<\<theta>>]\<in>RED \<tau>" 
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   870
  and  \<theta>_cond: "\<forall>c \<sigma>. (c,\<sigma>)\<in>set \<Gamma> \<longrightarrow> c\<in>set (domain \<theta>) \<and>  \<theta><c>\<in>RED \<sigma>" 
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   871
  and fresh: "a\<sharp>\<Gamma>" "a\<sharp>\<theta>" 
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   872
  and "\<Gamma> \<turnstile> Lam [a].t:\<tau>" by fact
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   873
  hence "\<exists>\<tau>1 \<tau>2. \<tau>=\<tau>1\<rightarrow>\<tau>2 \<and> ((a,\<tau>1)#\<Gamma>)\<turnstile>t:\<tau>2" using t3_elim fresh by simp
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   874
  then obtain \<tau>1 \<tau>2 where \<tau>_inst: "\<tau>=\<tau>1\<rightarrow>\<tau>2" and typing: "((a,\<tau>1)#\<Gamma>)\<turnstile>t:\<tau>2" by blast
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   875
  from ih have "\<forall>s\<in>RED \<tau>1. t[<\<theta>>][a::=s] \<in> RED \<tau>2" using fresh typing \<theta>_cond
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   876
    by (force dest: fresh_context simp add: psubst_subst)
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   877
  hence "(Lam [a].(t[<\<theta>>])) \<in> RED (\<tau>1 \<rightarrow> \<tau>2)" by (simp only: abs_RED)
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   878
  thus "(Lam [a].t)[<\<theta>>] \<in> RED \<tau>" using fresh \<tau>_inst by simp
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   879
qed (force dest!: t1_elim t2_elim)+
d37fb71754fe added an Isar-proof for the abs_ALL lemma
urbanc
parents: 18313
diff changeset
   880
19218
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   881
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   882
lemma all_RED: 
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   883
  assumes a: "\<Gamma>\<turnstile>t:\<tau>"
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   884
  and     b: "\<forall>a \<sigma>. (a,\<sigma>)\<in>set(\<Gamma>) \<longrightarrow> (a\<in>set(domain \<theta>)\<and>\<theta><a>\<in>RED \<sigma>)" 
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   885
  shows "t[<\<theta>>]\<in>RED \<tau>"
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   886
using a b
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   887
proof(nominal_induct t avoiding: \<Gamma> \<tau> \<theta> rule: lam.induct)
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   888
  case (Lam a t) --"lambda case"
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   889
  have ih: "\<And>\<Gamma> \<tau> \<theta>. \<lbrakk>\<Gamma> \<turnstile> t:\<tau>; \<forall>c \<sigma>. (c,\<sigma>)\<in>set \<Gamma> \<longrightarrow> c\<in>set (domain \<theta>) \<and>  \<theta><c>\<in>RED \<sigma>\<rbrakk> 
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   890
                    \<Longrightarrow> t[<\<theta>>]\<in>RED \<tau>" 
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   891
  and  \<theta>_cond: "\<forall>c \<sigma>. (c,\<sigma>)\<in>set \<Gamma> \<longrightarrow> c\<in>set (domain \<theta>) \<and>  \<theta><c>\<in>RED \<sigma>" 
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   892
  and fresh: "a\<sharp>\<Gamma>" "a\<sharp>\<theta>" 
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   893
  and "\<Gamma> \<turnstile> Lam [a].t:\<tau>" by fact
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   894
  hence "\<exists>\<tau>1 \<tau>2. \<tau>=\<tau>1\<rightarrow>\<tau>2 \<and> ((a,\<tau>1)#\<Gamma>)\<turnstile>t:\<tau>2" using t3_elim fresh by simp
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   895
  then obtain \<tau>1 \<tau>2 where \<tau>_inst: "\<tau>=\<tau>1\<rightarrow>\<tau>2" and typing: "((a,\<tau>1)#\<Gamma>)\<turnstile>t:\<tau>2" by blast
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   896
  from ih have "\<forall>s\<in>RED \<tau>1. t[<\<theta>>][a::=s] \<in> RED \<tau>2" using fresh typing \<theta>_cond
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   897
    by (force dest: fresh_context simp add: psubst_subst)
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   898
  hence "(Lam [a].(t[<\<theta>>])) \<in> RED (\<tau>1 \<rightarrow> \<tau>2)" by (simp only: abs_RED)
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   899
  thus "(Lam [a].t)[<\<theta>>] \<in> RED \<tau>" using fresh \<tau>_inst by simp
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   900
qed (force dest!: t1_elim t2_elim)+
47b05ebe106b deleted some proofs "on comment"
urbanc
parents: 18659
diff changeset
   901
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   902
(* identity substitution generated from a context \<Gamma> *)
18382
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   903
consts
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   904
  "id" :: "(name\<times>ty) list \<Rightarrow> (name\<times>lam) list"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   905
primrec
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   906
  "id []    = []"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   907
  "id (x#\<Gamma>) = ((fst x),Var (fst x))#(id \<Gamma>)"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   908
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   909
lemma id_var:
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   910
  assumes a: "a \<in> set (domain (id \<Gamma>))"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   911
  shows "(id \<Gamma>)<a> = Var a"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   912
using a
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   913
apply(induct \<Gamma>, auto)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   914
done
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   915
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   916
lemma id_fresh:
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   917
  fixes a::"name"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   918
  assumes a: "a\<sharp>\<Gamma>"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   919
  shows "a\<sharp>(id \<Gamma>)"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   920
using a
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   921
apply(induct \<Gamma>)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   922
apply(auto simp add: fresh_list_nil fresh_list_cons fresh_prod)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   923
done
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   924
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   925
lemma id_apply:  
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   926
  shows "t[<(id \<Gamma>)>] = t"
18659
2ff0ae57431d changes to make use of the new induction principle proved by
urbanc
parents: 18654
diff changeset
   927
apply(nominal_induct t avoiding: \<Gamma> rule: lam.induct)
18382
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   928
apply(auto)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   929
apply(simp add: id_var)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   930
apply(drule id_fresh)+
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   931
apply(simp)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   932
done
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   933
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   934
lemma id_mem:
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   935
  assumes a: "(a,\<tau>)\<in>set \<Gamma>"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   936
  shows "a \<in> set (domain (id \<Gamma>))"
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   937
using a
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   938
apply(induct \<Gamma>, auto)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   939
done
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   940
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   941
lemma id_prop:
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   942
  shows "\<forall>a \<sigma>. (a,\<sigma>)\<in>set(\<Gamma>) \<longrightarrow> (a\<in>set(domain (id \<Gamma>))\<and>(id \<Gamma>)<a>\<in>RED \<sigma>)"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   943
apply(auto)
18382
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   944
apply(simp add: id_mem)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   945
apply(frule id_mem)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   946
apply(simp add: id_var)
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   947
apply(subgoal_tac "CR3 \<sigma>")(*A*)
18382
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   948
apply(drule CR3_CR4)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   949
apply(simp add: CR4_def)
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   950
apply(drule_tac x="Var a" in spec)
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   951
apply(force simp add: NEUT_def NORMAL_Var)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   952
(*A*)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   953
apply(rule RED_props)
18382
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   954
done
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   955
18383
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   956
lemma typing_implies_RED:  
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   957
  assumes a: "\<Gamma>\<turnstile>t:\<tau>"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   958
  shows "t \<in> RED \<tau>"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   959
proof -
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   960
  have "t[<id \<Gamma>>]\<in>RED \<tau>" 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   961
  proof -
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   962
    have "\<forall>a \<sigma>. (a,\<sigma>)\<in>set(\<Gamma>) \<longrightarrow> (a\<in>set(domain (id \<Gamma>))\<and>(id \<Gamma>)<a>\<in>RED \<sigma>)" by (rule id_prop)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   963
    with a show ?thesis by (rule all_RED)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   964
  qed
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   965
  thus"t \<in> RED \<tau>" by (simp add: id_apply)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   966
qed
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   967
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   968
lemma typing_implies_SN: 
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   969
  assumes a: "\<Gamma>\<turnstile>t:\<tau>"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   970
  shows "SN(t)"
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   971
proof -
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   972
  from a have "t \<in> RED \<tau>" by (rule typing_implies_RED)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   973
  moreover
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   974
  have "CR1 \<tau>" by (rule RED_props)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   975
  ultimately show "SN(t)" by (simp add: CR1_def)
5f40a59a798b ISAR-fied some proofs
urbanc
parents: 18382
diff changeset
   976
qed
18382
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   977
44578c918349 completed the sn proof and changed the manual
urbanc
parents: 18378
diff changeset
   978
end