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