src/HOL/Nominal/Examples/Pattern.thy
author wenzelm
Wed, 28 Oct 2009 00:24:38 +0100
changeset 33268 02de0317f66f
parent 33189 82a40677c1f8
child 34915 7894c7dab132
permissions -rw-r--r--
eliminated hard tabulators, guessing at each author's individual tab-width;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33189
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     1
header {* Simply-typed lambda-calculus with let and tuple patterns *}
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     2
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     3
theory Pattern
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     4
imports Nominal
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     5
begin
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     6
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     7
no_syntax
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     8
  "_Map" :: "maplets => 'a ~=> 'b"  ("(1[_])")
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
     9
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    10
atom_decl name
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    11
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    12
nominal_datatype ty =
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    13
    Atom nat
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    14
  | Arrow ty ty  (infixr "\<rightarrow>" 200)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    15
  | TupleT ty ty  (infixr "\<otimes>" 210)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    16
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    17
lemma fresh_type [simp]: "(a::name) \<sharp> (T::ty)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    18
  by (induct T rule: ty.induct) (simp_all add: fresh_nat)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    19
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    20
lemma supp_type [simp]: "supp (T::ty) = ({} :: name set)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    21
  by (induct T rule: ty.induct) (simp_all add: ty.supp supp_nat)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    22
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    23
lemma perm_type: "(pi::name prm) \<bullet> (T::ty) = T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    24
  by (induct T rule: ty.induct) (simp_all add: perm_nat_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    25
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    26
nominal_datatype trm =
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    27
    Var name
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    28
  | Tuple trm trm  ("(1'\<langle>_,/ _'\<rangle>)")
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    29
  | Abs ty "\<guillemotleft>name\<guillemotright>trm"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    30
  | App trm trm  (infixl "\<cdot>" 200)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    31
  | Let ty trm btrm
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    32
and btrm =
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    33
    Base trm
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    34
  | Bind ty "\<guillemotleft>name\<guillemotright>btrm"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    35
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    36
abbreviation
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    37
  Abs_syn :: "name \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm"  ("(3\<lambda>_:_./ _)" [0, 0, 10] 10) 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    38
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    39
  "\<lambda>x:T. t \<equiv> Abs T x t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    40
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    41
datatype pat =
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    42
    PVar name ty
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    43
  | PTuple pat pat  ("(1'\<langle>\<langle>_,/ _'\<rangle>\<rangle>)")
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    44
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    45
(* FIXME: The following should be done automatically by the nominal package *)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    46
overloading pat_perm \<equiv> "perm :: name prm \<Rightarrow> pat \<Rightarrow> pat" (unchecked)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    47
begin
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    48
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    49
primrec pat_perm
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    50
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    51
  "pat_perm pi (PVar x ty) = PVar (pi \<bullet> x) (pi \<bullet> ty)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    52
| "pat_perm pi \<langle>\<langle>p, q\<rangle>\<rangle> = \<langle>\<langle>pat_perm pi p, pat_perm pi q\<rangle>\<rangle>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    53
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    54
end
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    55
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    56
declare pat_perm.simps [eqvt]
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    57
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    58
lemma supp_PVar [simp]: "((supp (PVar x T))::name set) = supp x"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    59
  by (simp add: supp_def perm_fresh_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    60
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    61
lemma supp_PTuple [simp]: "((supp \<langle>\<langle>p, q\<rangle>\<rangle>)::name set) = supp p \<union> supp q"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    62
  by (simp add: supp_def Collect_disj_eq del: disj_not1)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    63
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    64
instance pat :: pt_name
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    65
proof intro_classes
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    66
  case goal1
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    67
  show ?case by (induct x) simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    68
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    69
  case goal2
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    70
  show ?case by (induct x) (simp_all add: pt_name2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    71
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    72
  case goal3
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    73
  then show ?case by (induct x) (simp_all add: pt_name3)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    74
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    75
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    76
instance pat :: fs_name
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    77
proof intro_classes
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    78
  case goal1
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    79
  show ?case by (induct x) (simp_all add: fin_supp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    80
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    81
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    82
(* the following function cannot be defined using nominal_primrec, *)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    83
(* since variable parameters are currently not allowed.            *)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    84
primrec abs_pat :: "pat \<Rightarrow> btrm \<Rightarrow> btrm" ("(3\<lambda>[_]./ _)" [0, 10] 10)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    85
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    86
  "(\<lambda>[PVar x T]. t) = Bind T x t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    87
| "(\<lambda>[\<langle>\<langle>p, q\<rangle>\<rangle>]. t) = (\<lambda>[p]. \<lambda>[q]. t)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    88
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    89
lemma abs_pat_eqvt [eqvt]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    90
  "(pi :: name prm) \<bullet> (\<lambda>[p]. t) = (\<lambda>[pi \<bullet> p]. (pi \<bullet> t))"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    91
  by (induct p arbitrary: t) simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    92
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    93
lemma abs_pat_fresh [simp]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    94
  "(x::name) \<sharp> (\<lambda>[p]. t) = (x \<in> supp p \<or> x \<sharp> t)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    95
  by (induct p arbitrary: t) (simp_all add: abs_fresh supp_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    96
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    97
lemma abs_pat_alpha:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    98
  assumes fresh: "((pi::name prm) \<bullet> supp p::name set) \<sharp>* t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
    99
  and pi: "set pi \<subseteq> supp p \<times> pi \<bullet> supp p"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   100
  shows "(\<lambda>[p]. t) = (\<lambda>[pi \<bullet> p]. pi \<bullet> t)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   101
proof -
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   102
  note pt_name_inst at_name_inst pi
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   103
  moreover have "(supp p::name set) \<sharp>* (\<lambda>[p]. t)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   104
    by (simp add: fresh_star_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   105
  moreover from fresh
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   106
  have "(pi \<bullet> supp p::name set) \<sharp>* (\<lambda>[p]. t)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   107
    by (simp add: fresh_star_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   108
  ultimately have "pi \<bullet> (\<lambda>[p]. t) = (\<lambda>[p]. t)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   109
    by (rule pt_freshs_freshs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   110
  then show ?thesis by (simp add: eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   111
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   112
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   113
primrec pat_vars :: "pat \<Rightarrow> name list"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   114
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   115
  "pat_vars (PVar x T) = [x]"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   116
| "pat_vars \<langle>\<langle>p, q\<rangle>\<rangle> = pat_vars q @ pat_vars p"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   117
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   118
lemma pat_vars_eqvt [eqvt]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   119
  "(pi :: name prm) \<bullet> (pat_vars p) = pat_vars (pi \<bullet> p)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   120
  by (induct p rule: pat.induct) (simp_all add: eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   121
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   122
lemma set_pat_vars_supp: "set (pat_vars p) = supp p"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   123
  by (induct p) (auto simp add: supp_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   124
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   125
lemma distinct_eqvt [eqvt]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   126
  "(pi :: name prm) \<bullet> (distinct (xs::name list)) = distinct (pi \<bullet> xs)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   127
  by (induct xs) (simp_all add: eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   128
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   129
primrec pat_type :: "pat \<Rightarrow> ty"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   130
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   131
  "pat_type (PVar x T) = T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   132
| "pat_type \<langle>\<langle>p, q\<rangle>\<rangle> = pat_type p \<otimes> pat_type q"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   133
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   134
lemma pat_type_eqvt [eqvt]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   135
  "(pi :: name prm) \<bullet> (pat_type p) = pat_type (pi \<bullet> p)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   136
  by (induct p) simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   137
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   138
lemma pat_type_perm_eq: "pat_type ((pi :: name prm) \<bullet> p) = pat_type p"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   139
  by (induct p) (simp_all add: perm_type)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   140
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   141
types ctx = "(name \<times> ty) list"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   142
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   143
inductive
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   144
  ptyping :: "pat \<Rightarrow> ty \<Rightarrow> ctx \<Rightarrow> bool"  ("\<turnstile> _ : _ \<Rightarrow> _" [60, 60, 60] 60)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   145
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   146
  PVar: "\<turnstile> PVar x T : T \<Rightarrow> [(x, T)]"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   147
| PTuple: "\<turnstile> p : T \<Rightarrow> \<Delta>\<^isub>1 \<Longrightarrow> \<turnstile> q : U \<Rightarrow> \<Delta>\<^isub>2 \<Longrightarrow> \<turnstile> \<langle>\<langle>p, q\<rangle>\<rangle> : T \<otimes> U \<Rightarrow> \<Delta>\<^isub>2 @ \<Delta>\<^isub>1"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   148
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   149
lemma pat_vars_ptyping:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   150
  assumes "\<turnstile> p : T \<Rightarrow> \<Delta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   151
  shows "pat_vars p = map fst \<Delta>" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   152
  by induct simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   153
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   154
inductive
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   155
  valid :: "ctx \<Rightarrow> bool"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   156
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   157
  Nil [intro!]: "valid []"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   158
| Cons [intro!]: "valid \<Gamma> \<Longrightarrow> x \<sharp> \<Gamma> \<Longrightarrow> valid ((x, T) # \<Gamma>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   159
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   160
inductive_cases validE[elim!]: "valid ((x, T) # \<Gamma>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   161
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   162
lemma fresh_ctxt_set_eq: "((x::name) \<sharp> (\<Gamma>::ctx)) = (x \<notin> fst ` set \<Gamma>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   163
  by (induct \<Gamma>) (auto simp add: fresh_list_nil fresh_list_cons fresh_prod fresh_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   164
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   165
lemma valid_distinct: "valid \<Gamma> = distinct (map fst \<Gamma>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   166
  by (induct \<Gamma>) (auto simp add: fresh_ctxt_set_eq [symmetric])
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   167
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   168
abbreviation
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   169
  "sub_ctx" :: "ctx \<Rightarrow> ctx \<Rightarrow> bool" ("_ \<sqsubseteq> _") 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   170
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   171
  "\<Gamma>\<^isub>1 \<sqsubseteq> \<Gamma>\<^isub>2 \<equiv> \<forall>x. x \<in> set \<Gamma>\<^isub>1 \<longrightarrow> x \<in> set \<Gamma>\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   172
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   173
abbreviation
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   174
  Let_syn :: "pat \<Rightarrow> trm \<Rightarrow> trm \<Rightarrow> trm"  ("(LET (_ =/ _)/ IN (_))" 10)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   175
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   176
  "LET p = t IN u \<equiv> Let (pat_type p) t (\<lambda>[p]. Base u)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   177
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   178
inductive typing :: "ctx \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow> bool" ("_ \<turnstile> _ : _" [60, 60, 60] 60)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   179
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   180
  Var [intro]: "valid \<Gamma> \<Longrightarrow> (x, T) \<in> set \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Var x : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   181
| Tuple [intro]: "\<Gamma> \<turnstile> t : T \<Longrightarrow> \<Gamma> \<turnstile> u : U \<Longrightarrow> \<Gamma> \<turnstile> \<langle>t, u\<rangle> : T \<otimes> U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   182
| Abs [intro]: "(x, T) # \<Gamma> \<turnstile> t : U \<Longrightarrow> \<Gamma> \<turnstile> (\<lambda>x:T. t) : T \<rightarrow> U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   183
| App [intro]: "\<Gamma> \<turnstile> t : T \<rightarrow> U \<Longrightarrow> \<Gamma> \<turnstile> u : T \<Longrightarrow> \<Gamma> \<turnstile> t \<cdot> u : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   184
| Let: "((supp p)::name set) \<sharp>* t \<Longrightarrow>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   185
    \<Gamma> \<turnstile> t : T \<Longrightarrow> \<turnstile> p : T \<Rightarrow> \<Delta> \<Longrightarrow> \<Delta> @ \<Gamma> \<turnstile> u : U \<Longrightarrow>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   186
    \<Gamma> \<turnstile> (LET p = t IN u) : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   187
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   188
equivariance ptyping
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   189
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   190
equivariance valid
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   191
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   192
equivariance typing
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   193
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   194
lemma valid_typing:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   195
  assumes "\<Gamma> \<turnstile> t : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   196
  shows "valid \<Gamma>" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   197
  by induct auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   198
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   199
lemma pat_var:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   200
  assumes "\<turnstile> p : T \<Rightarrow> \<Delta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   201
  shows "(supp p::name set) = supp \<Delta>" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   202
  by induct (auto simp add: supp_list_nil supp_list_cons supp_prod supp_list_append)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   203
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   204
lemma valid_app_fresh:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   205
  assumes "valid (\<Delta> @ \<Gamma>)" and "(x::name) \<in> supp \<Delta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   206
  shows "x \<sharp> \<Gamma>" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   207
  by (induct \<Delta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   208
    (auto simp add: supp_list_nil supp_list_cons supp_prod supp_atm fresh_list_append)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   209
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   210
lemma pat_freshs:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   211
  assumes "\<turnstile> p : T \<Rightarrow> \<Delta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   212
  shows "(supp p::name set) \<sharp>* c = (supp \<Delta>::name set) \<sharp>* c" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   213
  by (auto simp add: fresh_star_def pat_var)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   214
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   215
lemma valid_app_mono:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   216
  assumes "valid (\<Delta> @ \<Gamma>\<^isub>1)" and "(supp \<Delta>::name set) \<sharp>* \<Gamma>\<^isub>2" and "valid \<Gamma>\<^isub>2" and "\<Gamma>\<^isub>1 \<sqsubseteq> \<Gamma>\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   217
  shows "valid (\<Delta> @ \<Gamma>\<^isub>2)" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   218
  by (induct \<Delta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   219
    (auto simp add: supp_list_cons fresh_star_Un_elim supp_prod
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   220
       fresh_list_append supp_atm fresh_star_insert_elim fresh_star_empty_elim)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   221
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   222
nominal_inductive2 typing
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   223
avoids
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   224
  Abs: "{x}"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   225
| Let: "(supp p)::name set"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   226
  by (auto simp add: fresh_star_def abs_fresh fin_supp pat_var
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   227
    dest!: valid_typing valid_app_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   228
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   229
lemma better_T_Let [intro]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   230
  assumes t: "\<Gamma> \<turnstile> t : T" and p: "\<turnstile> p : T \<Rightarrow> \<Delta>" and u: "\<Delta> @ \<Gamma> \<turnstile> u : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   231
  shows "\<Gamma> \<turnstile> (LET p = t IN u) : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   232
proof -
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   233
  obtain pi::"name prm" where pi: "(pi \<bullet> (supp p::name set)) \<sharp>* (t, Base u, \<Gamma>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   234
    and pi': "set pi \<subseteq> supp p \<times> (pi \<bullet> supp p)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   235
    by (rule at_set_avoiding [OF at_name_inst fin_supp fin_supp])
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   236
  from p u have p_fresh: "(supp p::name set) \<sharp>* \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   237
    by (auto simp add: fresh_star_def pat_var dest!: valid_typing valid_app_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   238
  from pi have p_fresh': "(pi \<bullet> (supp p::name set)) \<sharp>* \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   239
    by (simp add: fresh_star_prod_elim)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   240
  from pi have p_fresh'': "(pi \<bullet> (supp p::name set)) \<sharp>* Base u"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   241
    by (simp add: fresh_star_prod_elim)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   242
  from pi have "(supp (pi \<bullet> p)::name set) \<sharp>* t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   243
    by (simp add: fresh_star_prod_elim eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   244
  moreover note t
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   245
  moreover from p have "pi \<bullet> (\<turnstile> p : T \<Rightarrow> \<Delta>)" by (rule perm_boolI)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   246
  then have "\<turnstile> (pi \<bullet> p) : T \<Rightarrow> (pi \<bullet> \<Delta>)" by (simp add: eqvts perm_type)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   247
  moreover from u have "pi \<bullet> (\<Delta> @ \<Gamma> \<turnstile> u : U)" by (rule perm_boolI)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   248
  with pt_freshs_freshs [OF pt_name_inst at_name_inst pi' p_fresh p_fresh']
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   249
  have "(pi \<bullet> \<Delta>) @ \<Gamma> \<turnstile> (pi \<bullet> u) : U" by (simp add: eqvts perm_type)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   250
  ultimately have "\<Gamma> \<turnstile> (LET (pi \<bullet> p) = t IN (pi \<bullet> u)) : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   251
    by (rule Let)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   252
  then show ?thesis by (simp add: abs_pat_alpha [OF p_fresh'' pi'] pat_type_perm_eq)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   253
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   254
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   255
lemma weakening: 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   256
  assumes "\<Gamma>\<^isub>1 \<turnstile> t : T" and "valid \<Gamma>\<^isub>2" and "\<Gamma>\<^isub>1 \<sqsubseteq> \<Gamma>\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   257
  shows "\<Gamma>\<^isub>2 \<turnstile> t : T" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   258
  apply (nominal_induct \<Gamma>\<^isub>1 t T avoiding: \<Gamma>\<^isub>2 rule: typing.strong_induct)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   259
  apply auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   260
  apply (drule_tac x="(x, T) # \<Gamma>\<^isub>2" in meta_spec)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   261
  apply (auto intro: valid_typing)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   262
  apply (drule_tac x="\<Gamma>\<^isub>2" in meta_spec)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   263
  apply (drule_tac x="\<Delta> @ \<Gamma>\<^isub>2" in meta_spec)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   264
  apply (auto intro: valid_typing)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   265
  apply (rule typing.Let)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   266
  apply assumption+
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   267
  apply (drule meta_mp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   268
  apply (rule valid_app_mono)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   269
  apply (rule valid_typing)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   270
  apply assumption
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   271
  apply (auto simp add: pat_freshs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   272
  done
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   273
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   274
inductive
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   275
  match :: "pat \<Rightarrow> trm \<Rightarrow> (name \<times> trm) list \<Rightarrow> bool"  ("\<turnstile> _ \<rhd> _ \<Rightarrow> _" [50, 50, 50] 50)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   276
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   277
  PVar: "\<turnstile> PVar x T \<rhd> t \<Rightarrow> [(x, t)]"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   278
| PProd: "\<turnstile> p \<rhd> t \<Rightarrow> \<theta> \<Longrightarrow> \<turnstile> q \<rhd> u \<Rightarrow> \<theta>' \<Longrightarrow> \<turnstile> \<langle>\<langle>p, q\<rangle>\<rangle> \<rhd> \<langle>t, u\<rangle> \<Rightarrow> \<theta> @ \<theta>'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   279
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   280
fun
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   281
  lookup :: "(name \<times> trm) list \<Rightarrow> name \<Rightarrow> trm"   
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   282
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   283
  "lookup [] x = Var x"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   284
| "lookup ((y, e) # \<theta>) x = (if x = y then e else lookup \<theta> x)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   285
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   286
lemma lookup_eqvt[eqvt]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   287
  fixes pi :: "name prm"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   288
  and   \<theta> :: "(name \<times> trm) list"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   289
  and   X :: "name"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   290
  shows "pi \<bullet> (lookup \<theta> X) = lookup (pi \<bullet> \<theta>) (pi \<bullet> X)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   291
  by (induct \<theta>) (auto simp add: eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   292
 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   293
nominal_primrec
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   294
  psubst :: "(name \<times> trm) list \<Rightarrow> trm \<Rightarrow> trm"  ("_\<lparr>_\<rparr>" [95,0] 210)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   295
  and psubstb :: "(name \<times> trm) list \<Rightarrow> btrm \<Rightarrow> btrm"  ("_\<lparr>_\<rparr>\<^sub>b" [95,0] 210)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   296
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   297
  "\<theta>\<lparr>Var x\<rparr> = (lookup \<theta> x)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   298
| "\<theta>\<lparr>t \<cdot> u\<rparr> = \<theta>\<lparr>t\<rparr> \<cdot> \<theta>\<lparr>u\<rparr>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   299
| "\<theta>\<lparr>\<langle>t, u\<rangle>\<rparr> = \<langle>\<theta>\<lparr>t\<rparr>, \<theta>\<lparr>u\<rparr>\<rangle>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   300
| "\<theta>\<lparr>Let T t u\<rparr> = Let T (\<theta>\<lparr>t\<rparr>) (\<theta>\<lparr>u\<rparr>\<^sub>b)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   301
| "x \<sharp> \<theta> \<Longrightarrow> \<theta>\<lparr>\<lambda>x:T. t\<rparr> = (\<lambda>x:T. \<theta>\<lparr>t\<rparr>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   302
| "\<theta>\<lparr>Base t\<rparr>\<^sub>b = Base (\<theta>\<lparr>t\<rparr>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   303
| "x \<sharp> \<theta> \<Longrightarrow> \<theta>\<lparr>Bind T x t\<rparr>\<^sub>b = Bind T x (\<theta>\<lparr>t\<rparr>\<^sub>b)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   304
  apply finite_guess+
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   305
  apply (simp add: abs_fresh | fresh_guess)+
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   306
  done
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   307
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   308
lemma lookup_fresh:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   309
  "x = y \<longrightarrow> x \<in> set (map fst \<theta>) \<Longrightarrow> \<forall>(y, t)\<in>set \<theta>. x \<sharp> t \<Longrightarrow> x \<sharp> lookup \<theta> y"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   310
  apply (induct \<theta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   311
  apply (simp_all add: split_paired_all fresh_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   312
  apply (case_tac "x = y")
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   313
  apply (auto simp add: fresh_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   314
  done
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   315
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   316
lemma psubst_fresh:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   317
  assumes "x \<in> set (map fst \<theta>)" and "\<forall>(y, t)\<in>set \<theta>. x \<sharp> t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   318
  shows "x \<sharp> \<theta>\<lparr>t\<rparr>" and "x \<sharp> \<theta>\<lparr>t'\<rparr>\<^sub>b" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   319
  apply (nominal_induct t and t' avoiding: \<theta> rule: trm_btrm.strong_inducts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   320
  apply simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   321
  apply (rule lookup_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   322
  apply (rule impI)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   323
  apply (simp_all add: abs_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   324
  done
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   325
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   326
lemma psubst_eqvt[eqvt]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   327
  fixes pi :: "name prm" 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   328
  shows "pi \<bullet> (\<theta>\<lparr>t\<rparr>) = (pi \<bullet> \<theta>)\<lparr>pi \<bullet> t\<rparr>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   329
  and "pi \<bullet> (\<theta>\<lparr>t'\<rparr>\<^sub>b) = (pi \<bullet> \<theta>)\<lparr>pi \<bullet> t'\<rparr>\<^sub>b"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   330
  by (nominal_induct t and t' avoiding: \<theta> rule: trm_btrm.strong_inducts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   331
    (simp_all add: eqvts fresh_bij)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   332
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   333
abbreviation 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   334
  subst :: "trm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> trm" ("_[_\<mapsto>_]" [100,0,0] 100)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   335
where 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   336
  "t[x\<mapsto>t'] \<equiv> [(x,t')]\<lparr>t\<rparr>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   337
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   338
abbreviation 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   339
  substb :: "btrm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> btrm" ("_[_\<mapsto>_]\<^sub>b" [100,0,0] 100)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   340
where 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   341
  "t[x\<mapsto>t']\<^sub>b \<equiv> [(x,t')]\<lparr>t\<rparr>\<^sub>b"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   342
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   343
lemma lookup_forget:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   344
  "(supp (map fst \<theta>)::name set) \<sharp>* x \<Longrightarrow> lookup \<theta> x = Var x"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   345
  by (induct \<theta>) (auto simp add: split_paired_all fresh_star_def fresh_atm supp_list_cons supp_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   346
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   347
lemma supp_fst: "(x::name) \<in> supp (map fst (\<theta>::(name \<times> trm) list)) \<Longrightarrow> x \<in> supp \<theta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   348
  by (induct \<theta>) (auto simp add: supp_list_nil supp_list_cons supp_prod)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   349
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   350
lemma psubst_forget:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   351
  "(supp (map fst \<theta>)::name set) \<sharp>* t \<Longrightarrow> \<theta>\<lparr>t\<rparr> = t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   352
  "(supp (map fst \<theta>)::name set) \<sharp>* t' \<Longrightarrow> \<theta>\<lparr>t'\<rparr>\<^sub>b = t'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   353
  apply (nominal_induct t and t' avoiding: \<theta> rule: trm_btrm.strong_inducts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   354
  apply (auto simp add: fresh_star_def lookup_forget abs_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   355
  apply (drule_tac x=\<theta> in meta_spec)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   356
  apply (drule meta_mp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   357
  apply (rule ballI)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   358
  apply (drule_tac x=x in bspec)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   359
  apply assumption
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   360
  apply (drule supp_fst)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   361
  apply (auto simp add: fresh_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   362
  apply (drule_tac x=\<theta> in meta_spec)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   363
  apply (drule meta_mp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   364
  apply (rule ballI)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   365
  apply (drule_tac x=x in bspec)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   366
  apply assumption
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   367
  apply (drule supp_fst)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   368
  apply (auto simp add: fresh_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   369
  done
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   370
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   371
lemma psubst_nil: "[]\<lparr>t\<rparr> = t" "[]\<lparr>t'\<rparr>\<^sub>b = t'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   372
  by (induct t and t' rule: trm_btrm.inducts) (simp_all add: fresh_list_nil)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   373
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   374
lemma psubst_cons:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   375
  assumes "(supp (map fst \<theta>)::name set) \<sharp>* u"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   376
  shows "((x, u) # \<theta>)\<lparr>t\<rparr> = \<theta>\<lparr>t[x\<mapsto>u]\<rparr>" and "((x, u) # \<theta>)\<lparr>t'\<rparr>\<^sub>b = \<theta>\<lparr>t'[x\<mapsto>u]\<^sub>b\<rparr>\<^sub>b"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   377
  using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   378
  by (nominal_induct t and t' avoiding: x u \<theta> rule: trm_btrm.strong_inducts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   379
    (simp_all add: fresh_list_nil fresh_list_cons psubst_forget)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   380
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   381
lemma psubst_append:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   382
  "(supp (map fst (\<theta>\<^isub>1 @ \<theta>\<^isub>2))::name set) \<sharp>* map snd (\<theta>\<^isub>1 @ \<theta>\<^isub>2) \<Longrightarrow> (\<theta>\<^isub>1 @ \<theta>\<^isub>2)\<lparr>t\<rparr> = \<theta>\<^isub>2\<lparr>\<theta>\<^isub>1\<lparr>t\<rparr>\<rparr>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   383
  by (induct \<theta>\<^isub>1 arbitrary: t)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   384
    (simp_all add: psubst_nil split_paired_all supp_list_cons psubst_cons fresh_star_def
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   385
      fresh_list_cons fresh_list_append supp_list_append)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   386
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   387
lemma abs_pat_psubst [simp]:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   388
  "(supp p::name set) \<sharp>* \<theta> \<Longrightarrow> \<theta>\<lparr>\<lambda>[p]. t\<rparr>\<^sub>b = (\<lambda>[p]. \<theta>\<lparr>t\<rparr>\<^sub>b)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   389
  by (induct p arbitrary: t) (auto simp add: fresh_star_def supp_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   390
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   391
lemma valid_insert:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   392
  assumes "valid (\<Delta> @ [(x, T)] @ \<Gamma>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   393
  shows "valid (\<Delta> @ \<Gamma>)" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   394
  by (induct \<Delta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   395
    (auto simp add: fresh_list_append fresh_list_cons)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   396
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   397
lemma fresh_set: 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   398
  shows "y \<sharp> xs = (\<forall>x\<in>set xs. y \<sharp> x)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   399
  by (induct xs) (simp_all add: fresh_list_nil fresh_list_cons)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   400
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   401
lemma context_unique:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   402
  assumes "valid \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   403
  and "(x, T) \<in> set \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   404
  and "(x, U) \<in> set \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   405
  shows "T = U" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   406
  by induct (auto simp add: fresh_set fresh_prod fresh_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   407
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   408
lemma subst_type_aux:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   409
  assumes a: "\<Delta> @ [(x, U)] @ \<Gamma> \<turnstile> t : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   410
  and b: "\<Gamma> \<turnstile> u : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   411
  shows "\<Delta> @ \<Gamma> \<turnstile> t[x\<mapsto>u] : T" using a b
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   412
proof (nominal_induct \<Gamma>'\<equiv>"\<Delta> @ [(x, U)] @ \<Gamma>" t T avoiding: x u \<Delta> rule: typing.strong_induct)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   413
  case (Var \<Gamma>' y T x u \<Delta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   414
  then have a1: "valid (\<Delta> @ [(x, U)] @ \<Gamma>)" 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   415
       and  a2: "(y, T) \<in> set (\<Delta> @ [(x, U)] @ \<Gamma>)" 
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   416
       and  a3: "\<Gamma> \<turnstile> u : U" by simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   417
  from a1 have a4: "valid (\<Delta> @ \<Gamma>)" by (rule valid_insert)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   418
  show "\<Delta> @ \<Gamma> \<turnstile> Var y[x\<mapsto>u] : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   419
  proof cases
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   420
    assume eq: "x = y"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   421
    from a1 a2 have "T = U" using eq by (auto intro: context_unique)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   422
    with a3 show "\<Delta> @ \<Gamma> \<turnstile> Var y[x\<mapsto>u] : T" using eq a4 by (auto intro: weakening)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   423
  next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   424
    assume ineq: "x \<noteq> y"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   425
    from a2 have "(y, T) \<in> set (\<Delta> @ \<Gamma>)" using ineq by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   426
    then show "\<Delta> @ \<Gamma> \<turnstile> Var y[x\<mapsto>u] : T" using ineq a4 by auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   427
  qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   428
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   429
  case (Tuple \<Gamma>' t\<^isub>1 T\<^isub>1 t\<^isub>2 T\<^isub>2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   430
  from `\<Gamma> \<turnstile> u : U` `\<Gamma>' = \<Delta> @ [(x, U)] @ \<Gamma>`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   431
  have "\<Delta> @ \<Gamma> \<turnstile> t\<^isub>1[x\<mapsto>u] : T\<^isub>1" by (rule Tuple)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   432
  moreover from `\<Gamma> \<turnstile> u : U` `\<Gamma>' = \<Delta> @ [(x, U)] @ \<Gamma>`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   433
  have "\<Delta> @ \<Gamma> \<turnstile> t\<^isub>2[x\<mapsto>u] : T\<^isub>2" by (rule Tuple)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   434
  ultimately have "\<Delta> @ \<Gamma> \<turnstile> \<langle>t\<^isub>1[x\<mapsto>u], t\<^isub>2[x\<mapsto>u]\<rangle> : T\<^isub>1 \<otimes> T\<^isub>2" ..
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   435
  then show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   436
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   437
  case (Let p t \<Gamma>' T \<Delta>' s S)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   438
  from `\<Gamma> \<turnstile> u : U` `\<Gamma>' = \<Delta> @ [(x, U)] @ \<Gamma>`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   439
  have "\<Delta> @ \<Gamma> \<turnstile> t[x\<mapsto>u] : T" by (rule Let)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   440
  moreover note `\<turnstile> p : T \<Rightarrow> \<Delta>'`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   441
  moreover from `\<Gamma>' = \<Delta> @ [(x, U)] @ \<Gamma>`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   442
  have "\<Delta>' @ \<Gamma>' = (\<Delta>' @ \<Delta>) @ [(x, U)] @ \<Gamma>" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   443
  with `\<Gamma> \<turnstile> u : U` have "(\<Delta>' @ \<Delta>) @ \<Gamma> \<turnstile> s[x\<mapsto>u] : S" by (rule Let)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   444
  then have "\<Delta>' @ \<Delta> @ \<Gamma> \<turnstile> s[x\<mapsto>u] : S" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   445
  ultimately have "\<Delta> @ \<Gamma> \<turnstile> (LET p = t[x\<mapsto>u] IN s[x\<mapsto>u]) : S"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   446
    by (rule better_T_Let)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   447
  moreover from Let have "(supp p::name set) \<sharp>* [(x, u)]"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   448
    by (simp add: fresh_star_def fresh_list_nil fresh_list_cons)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   449
  ultimately show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   450
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   451
  case (Abs y T \<Gamma>' t S)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   452
  from `\<Gamma>' = \<Delta> @ [(x, U)] @ \<Gamma>` have "(y, T) # \<Gamma>' = ((y, T) # \<Delta>) @ [(x, U)] @ \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   453
    by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   454
  with `\<Gamma> \<turnstile> u : U` have "((y, T) # \<Delta>) @ \<Gamma> \<turnstile> t[x\<mapsto>u] : S" by (rule Abs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   455
  then have "(y, T) # \<Delta> @ \<Gamma> \<turnstile> t[x\<mapsto>u] : S" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   456
  then have "\<Delta> @ \<Gamma> \<turnstile> (\<lambda>y:T. t[x\<mapsto>u]) : T \<rightarrow> S"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   457
    by (rule typing.Abs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   458
  moreover from Abs have "y \<sharp> [(x, u)]"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   459
    by (simp add: fresh_list_nil fresh_list_cons)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   460
  ultimately show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   461
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   462
  case (App \<Gamma>' t\<^isub>1 T S t\<^isub>2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   463
  from `\<Gamma> \<turnstile> u : U` `\<Gamma>' = \<Delta> @ [(x, U)] @ \<Gamma>`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   464
  have "\<Delta> @ \<Gamma> \<turnstile> t\<^isub>1[x\<mapsto>u] : T \<rightarrow> S" by (rule App)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   465
  moreover from `\<Gamma> \<turnstile> u : U` `\<Gamma>' = \<Delta> @ [(x, U)] @ \<Gamma>`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   466
  have "\<Delta> @ \<Gamma> \<turnstile> t\<^isub>2[x\<mapsto>u] : T" by (rule App)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   467
  ultimately have "\<Delta> @ \<Gamma> \<turnstile> (t\<^isub>1[x\<mapsto>u]) \<cdot> (t\<^isub>2[x\<mapsto>u]) : S"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   468
    by (rule typing.App)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   469
  then show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   470
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   471
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   472
lemmas subst_type = subst_type_aux [of "[]", simplified]
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   473
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   474
lemma match_supp_fst:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   475
  assumes "\<turnstile> p \<rhd> u \<Rightarrow> \<theta>" shows "(supp (map fst \<theta>)::name set) = supp p" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   476
  by induct (simp_all add: supp_list_nil supp_list_cons supp_list_append)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   477
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   478
lemma match_supp_snd:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   479
  assumes "\<turnstile> p \<rhd> u \<Rightarrow> \<theta>" shows "(supp (map snd \<theta>)::name set) = supp u" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   480
  by induct (simp_all add: supp_list_nil supp_list_cons supp_list_append trm.supp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   481
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   482
lemma match_fresh: "\<turnstile> p \<rhd> u \<Rightarrow> \<theta> \<Longrightarrow> (supp p::name set) \<sharp>* u \<Longrightarrow>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   483
  (supp (map fst \<theta>)::name set) \<sharp>* map snd \<theta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   484
  by (simp add: fresh_star_def fresh_def match_supp_fst match_supp_snd)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   485
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   486
lemma match_type_aux:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   487
  assumes "\<turnstile> p : U \<Rightarrow> \<Delta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   488
  and "\<Gamma>\<^isub>2 \<turnstile> u : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   489
  and "\<Gamma>\<^isub>1 @ \<Delta> @ \<Gamma>\<^isub>2 \<turnstile> t : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   490
  and "\<turnstile> p \<rhd> u \<Rightarrow> \<theta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   491
  and "(supp p::name set) \<sharp>* u"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   492
  shows "\<Gamma>\<^isub>1 @ \<Gamma>\<^isub>2 \<turnstile> \<theta>\<lparr>t\<rparr> : T" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   493
proof (induct arbitrary: \<Gamma>\<^isub>1 \<Gamma>\<^isub>2 t u T \<theta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   494
  case (PVar x U)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   495
  from `\<Gamma>\<^isub>1 @ [(x, U)] @ \<Gamma>\<^isub>2 \<turnstile> t : T` `\<Gamma>\<^isub>2 \<turnstile> u : U`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   496
  have "\<Gamma>\<^isub>1 @ \<Gamma>\<^isub>2 \<turnstile> t[x\<mapsto>u] : T" by (rule subst_type_aux)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   497
  moreover from `\<turnstile> PVar x U \<rhd> u \<Rightarrow> \<theta>` have "\<theta> = [(x, u)]"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   498
    by cases simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   499
  ultimately show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   500
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   501
  case (PTuple p S \<Delta>\<^isub>1 q U \<Delta>\<^isub>2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   502
  from `\<turnstile> \<langle>\<langle>p, q\<rangle>\<rangle> \<rhd> u \<Rightarrow> \<theta>` obtain u\<^isub>1 u\<^isub>2 \<theta>\<^isub>1 \<theta>\<^isub>2
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   503
    where u: "u = \<langle>u\<^isub>1, u\<^isub>2\<rangle>" and \<theta>: "\<theta> = \<theta>\<^isub>1 @ \<theta>\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   504
    and p: "\<turnstile> p \<rhd> u\<^isub>1 \<Rightarrow> \<theta>\<^isub>1" and q: "\<turnstile> q \<rhd> u\<^isub>2 \<Rightarrow> \<theta>\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   505
    by cases simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   506
  with PTuple have "\<Gamma>\<^isub>2 \<turnstile> \<langle>u\<^isub>1, u\<^isub>2\<rangle> : S \<otimes> U" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   507
  then obtain u\<^isub>1: "\<Gamma>\<^isub>2 \<turnstile> u\<^isub>1 : S" and u\<^isub>2: "\<Gamma>\<^isub>2 \<turnstile> u\<^isub>2 : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   508
    by cases (simp_all add: ty.inject trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   509
  note u\<^isub>1
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   510
  moreover from `\<Gamma>\<^isub>1 @ (\<Delta>\<^isub>2 @ \<Delta>\<^isub>1) @ \<Gamma>\<^isub>2 \<turnstile> t : T`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   511
  have "(\<Gamma>\<^isub>1 @ \<Delta>\<^isub>2) @ \<Delta>\<^isub>1 @ \<Gamma>\<^isub>2 \<turnstile> t : T" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   512
  moreover note p
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   513
  moreover from `supp \<langle>\<langle>p, q\<rangle>\<rangle> \<sharp>* u` and u
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   514
  have "(supp p::name set) \<sharp>* u\<^isub>1" by (simp add: fresh_star_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   515
  ultimately have \<theta>\<^isub>1: "(\<Gamma>\<^isub>1 @ \<Delta>\<^isub>2) @ \<Gamma>\<^isub>2 \<turnstile> \<theta>\<^isub>1\<lparr>t\<rparr> : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   516
    by (rule PTuple)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   517
  note u\<^isub>2
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   518
  moreover from \<theta>\<^isub>1
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   519
  have "\<Gamma>\<^isub>1 @ \<Delta>\<^isub>2 @ \<Gamma>\<^isub>2 \<turnstile> \<theta>\<^isub>1\<lparr>t\<rparr> : T" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   520
  moreover note q
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   521
  moreover from `supp \<langle>\<langle>p, q\<rangle>\<rangle> \<sharp>* u` and u
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   522
  have "(supp q::name set) \<sharp>* u\<^isub>2" by (simp add: fresh_star_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   523
  ultimately have "\<Gamma>\<^isub>1 @ \<Gamma>\<^isub>2 \<turnstile> \<theta>\<^isub>2\<lparr>\<theta>\<^isub>1\<lparr>t\<rparr>\<rparr> : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   524
    by (rule PTuple)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   525
  moreover from `\<turnstile> \<langle>\<langle>p, q\<rangle>\<rangle> \<rhd> u \<Rightarrow> \<theta>` `supp \<langle>\<langle>p, q\<rangle>\<rangle> \<sharp>* u`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   526
  have "(supp (map fst \<theta>)::name set) \<sharp>* map snd \<theta>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   527
    by (rule match_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   528
  ultimately show ?case using \<theta> by (simp add: psubst_append)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   529
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   530
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   531
lemmas match_type = match_type_aux [where \<Gamma>\<^isub>1="[]", simplified]
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   532
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   533
inductive eval :: "trm \<Rightarrow> trm \<Rightarrow> bool" ("_ \<longmapsto> _" [60,60] 60)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   534
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   535
  TupleL: "t \<longmapsto> t' \<Longrightarrow> \<langle>t, u\<rangle> \<longmapsto> \<langle>t', u\<rangle>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   536
| TupleR: "u \<longmapsto> u' \<Longrightarrow> \<langle>t, u\<rangle> \<longmapsto> \<langle>t, u'\<rangle>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   537
| Abs: "t \<longmapsto> t' \<Longrightarrow> (\<lambda>x:T. t) \<longmapsto> (\<lambda>x:T. t')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   538
| AppL: "t \<longmapsto> t' \<Longrightarrow> t \<cdot> u \<longmapsto> t' \<cdot> u"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   539
| AppR: "u \<longmapsto> u' \<Longrightarrow> t \<cdot> u \<longmapsto> t \<cdot> u'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   540
| Beta: "x \<sharp> u \<Longrightarrow> (\<lambda>x:T. t) \<cdot> u \<longmapsto> t[x\<mapsto>u]"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   541
| Let: "((supp p)::name set) \<sharp>* t \<Longrightarrow> distinct (pat_vars p) \<Longrightarrow>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   542
    \<turnstile> p \<rhd> t \<Rightarrow> \<theta> \<Longrightarrow> (LET p = t IN u) \<longmapsto> \<theta>\<lparr>u\<rparr>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   543
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   544
equivariance match
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   545
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   546
equivariance eval
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   547
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   548
lemma match_vars:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   549
  assumes "\<turnstile> p \<rhd> t \<Rightarrow> \<theta>" and "x \<in> supp p"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   550
  shows "x \<in> set (map fst \<theta>)" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   551
  by induct (auto simp add: supp_atm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   552
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   553
lemma match_fresh_mono:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   554
  assumes "\<turnstile> p \<rhd> t \<Rightarrow> \<theta>" and "(x::name) \<sharp> t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   555
  shows "\<forall>(y, t)\<in>set \<theta>. x \<sharp> t" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   556
  by induct auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   557
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   558
nominal_inductive2 eval
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   559
avoids
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   560
  Abs: "{x}"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   561
| Beta: "{x}"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   562
| Let: "(supp p)::name set"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   563
  apply (simp_all add: fresh_star_def abs_fresh fin_supp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   564
  apply (rule psubst_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   565
  apply simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   566
  apply simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   567
  apply (rule ballI)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   568
  apply (rule psubst_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   569
  apply (rule match_vars)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   570
  apply assumption+
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   571
  apply (rule match_fresh_mono)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   572
  apply auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   573
  done
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   574
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   575
lemma typing_case_Abs:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   576
  assumes ty: "\<Gamma> \<turnstile> (\<lambda>x:T. t) : S"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   577
  and fresh: "x \<sharp> \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   578
  and R: "\<And>U. S = T \<rightarrow> U \<Longrightarrow> (x, T) # \<Gamma> \<turnstile> t : U \<Longrightarrow> P"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   579
  shows P using ty
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   580
proof cases
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   581
  case (Abs x' T' \<Gamma>' t' U)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   582
  obtain y::name where y: "y \<sharp> (x, \<Gamma>, \<lambda>x':T'. t')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   583
    by (rule exists_fresh) (auto intro: fin_supp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   584
  from `(\<lambda>x:T. t) = (\<lambda>x':T'. t')` [symmetric]
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   585
  have x: "x \<sharp> (\<lambda>x':T'. t')" by (simp add: abs_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   586
  have x': "x' \<sharp> (\<lambda>x':T'. t')" by (simp add: abs_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   587
  from `(x', T') # \<Gamma>' \<turnstile> t' : U` have x'': "x' \<sharp> \<Gamma>'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   588
    by (auto dest: valid_typing)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   589
  have "(\<lambda>x:T. t) = (\<lambda>x':T'. t')" by fact
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   590
  also from x x' y have "\<dots> = [(x, y)] \<bullet> [(x', y)] \<bullet> (\<lambda>x':T'. t')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   591
    by (simp only: perm_fresh_fresh fresh_prod)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   592
  also have "\<dots> = (\<lambda>x:T'. [(x, y)] \<bullet> [(x', y)] \<bullet> t')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   593
    by (simp add: swap_simps perm_fresh_fresh)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   594
  finally have "(\<lambda>x:T. t) = (\<lambda>x:T'. [(x, y)] \<bullet> [(x', y)] \<bullet> t')" .
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   595
  then have T: "T = T'" and t: "[(x, y)] \<bullet> [(x', y)] \<bullet> t' = t"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   596
    by (simp_all add: trm.inject alpha)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   597
  from Abs T have "S = T \<rightarrow> U" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   598
  moreover from `(x', T') # \<Gamma>' \<turnstile> t' : U`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   599
  have "[(x, y)] \<bullet> [(x', y)] \<bullet> ((x', T') # \<Gamma>' \<turnstile> t' : U)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   600
    by (simp add: perm_bool)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   601
  with T t y `\<Gamma> = \<Gamma>'` x'' fresh have "(x, T) # \<Gamma> \<turnstile> t : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   602
    by (simp add: eqvts swap_simps perm_fresh_fresh fresh_prod)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   603
  ultimately show ?thesis by (rule R)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   604
qed simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   605
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   606
nominal_primrec ty_size :: "ty \<Rightarrow> nat"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   607
where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   608
  "ty_size (Atom n) = 0"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   609
| "ty_size (T \<rightarrow> U) = ty_size T + ty_size U + 1"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   610
| "ty_size (T \<otimes> U) = ty_size T + ty_size U + 1"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   611
  by (rule TrueI)+
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   612
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   613
lemma bind_tuple_ineq:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   614
  "ty_size (pat_type p) < ty_size U \<Longrightarrow> Bind U x t \<noteq> (\<lambda>[p]. u)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   615
  by (induct p arbitrary: U x t u) (auto simp add: btrm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   616
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   617
lemma valid_appD: assumes "valid (\<Gamma> @ \<Delta>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   618
  shows "valid \<Gamma>" "valid \<Delta>" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   619
  by (induct \<Gamma>'\<equiv>"\<Gamma> @ \<Delta>" arbitrary: \<Gamma> \<Delta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   620
    (auto simp add: Cons_eq_append_conv fresh_list_append)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   621
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   622
lemma valid_app_freshs: assumes "valid (\<Gamma> @ \<Delta>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   623
  shows "(supp \<Gamma>::name set) \<sharp>* \<Delta>" "(supp \<Delta>::name set) \<sharp>* \<Gamma>" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   624
  by (induct \<Gamma>'\<equiv>"\<Gamma> @ \<Delta>" arbitrary: \<Gamma> \<Delta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   625
    (auto simp add: Cons_eq_append_conv fresh_star_def
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   626
     fresh_list_nil fresh_list_cons supp_list_nil supp_list_cons fresh_list_append
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   627
     supp_prod fresh_prod supp_atm fresh_atm
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   628
     dest: notE [OF iffD1 [OF fresh_def [THEN meta_eq_to_obj_eq]]])
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   629
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   630
lemma perm_mem_left: "(x::name) \<in> ((pi::name prm) \<bullet> A) \<Longrightarrow> (rev pi \<bullet> x) \<in> A"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   631
  by (drule perm_boolI [of _ "rev pi"]) (simp add: eqvts perm_pi_simp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   632
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   633
lemma perm_mem_right: "(rev (pi::name prm) \<bullet> (x::name)) \<in> A \<Longrightarrow> x \<in> (pi \<bullet> A)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   634
  by (drule perm_boolI [of _ pi]) (simp add: eqvts perm_pi_simp)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   635
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   636
lemma perm_cases:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   637
  assumes pi: "set pi \<subseteq> A \<times> A"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   638
  shows "((pi::name prm) \<bullet> B) \<subseteq> A \<union> B"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   639
proof
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   640
  fix x assume "x \<in> pi \<bullet> B"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   641
  then show "x \<in> A \<union> B" using pi
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   642
    apply (induct pi arbitrary: x B rule: rev_induct)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   643
    apply simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   644
    apply (simp add: split_paired_all supp_eqvt)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   645
    apply (drule perm_mem_left)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   646
    apply (simp add: calc_atm split: split_if_asm)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   647
    apply (auto dest: perm_mem_right)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   648
    done
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   649
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   650
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   651
lemma abs_pat_alpha':
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   652
  assumes eq: "(\<lambda>[p]. t) = (\<lambda>[q]. u)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   653
  and ty: "pat_type p = pat_type q"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   654
  and pv: "distinct (pat_vars p)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   655
  and qv: "distinct (pat_vars q)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   656
  shows "\<exists>pi::name prm. p = pi \<bullet> q \<and> t = pi \<bullet> u \<and>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   657
    set pi \<subseteq> (supp p \<union> supp q) \<times> (supp p \<union> supp q)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   658
  using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   659
proof (induct p arbitrary: q t u \<Delta>)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   660
  case (PVar x T)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   661
  note PVar' = this
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   662
  show ?case
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   663
  proof (cases q)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   664
    case (PVar x' T')
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   665
    with `(\<lambda>[PVar x T]. t) = (\<lambda>[q]. u)`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   666
    have "x = x' \<and> t = u \<or> x \<noteq> x' \<and> t = [(x, x')] \<bullet> u \<and> x \<sharp> u"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   667
      by (simp add: btrm.inject alpha)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   668
    then show ?thesis
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   669
    proof
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   670
      assume "x = x' \<and> t = u"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   671
      with PVar PVar' have "PVar x T = ([]::name prm) \<bullet> q \<and>
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33189
diff changeset
   672
        t = ([]::name prm) \<bullet> u \<and>
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33189
diff changeset
   673
        set ([]::name prm) \<subseteq> (supp (PVar x T) \<union> supp q) \<times>
33189
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   674
          (supp (PVar x T) \<union> supp q)" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   675
      then show ?thesis ..
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   676
    next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   677
      assume "x \<noteq> x' \<and> t = [(x, x')] \<bullet> u \<and> x \<sharp> u"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   678
      with PVar PVar' have "PVar x T = [(x, x')] \<bullet> q \<and>
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33189
diff changeset
   679
        t = [(x, x')] \<bullet> u \<and>
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33189
diff changeset
   680
        set [(x, x')] \<subseteq> (supp (PVar x T) \<union> supp q) \<times>
33189
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   681
          (supp (PVar x T) \<union> supp q)"
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33189
diff changeset
   682
        by (simp add: perm_swap swap_simps supp_atm perm_type)
33189
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   683
      then show ?thesis ..
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   684
    qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   685
  next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   686
    case (PTuple p\<^isub>1 p\<^isub>2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   687
    with PVar have "ty_size (pat_type p\<^isub>1) < ty_size T" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   688
    then have "Bind T x t \<noteq> (\<lambda>[p\<^isub>1]. \<lambda>[p\<^isub>2]. u)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   689
      by (rule bind_tuple_ineq)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   690
    moreover from PTuple PVar
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   691
    have "Bind T x t = (\<lambda>[p\<^isub>1]. \<lambda>[p\<^isub>2]. u)" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   692
    ultimately show ?thesis ..
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   693
  qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   694
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   695
  case (PTuple p\<^isub>1 p\<^isub>2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   696
  note PTuple' = this
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   697
  show ?case
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   698
  proof (cases q)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   699
    case (PVar x T)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   700
    with PTuple have "ty_size (pat_type p\<^isub>1) < ty_size T" by auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   701
    then have "Bind T x u \<noteq> (\<lambda>[p\<^isub>1]. \<lambda>[p\<^isub>2]. t)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   702
      by (rule bind_tuple_ineq)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   703
    moreover from PTuple PVar
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   704
    have "Bind T x u = (\<lambda>[p\<^isub>1]. \<lambda>[p\<^isub>2]. t)" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   705
    ultimately show ?thesis ..
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   706
  next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   707
    case (PTuple p\<^isub>1' p\<^isub>2')
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   708
    with PTuple' have "(\<lambda>[p\<^isub>1]. \<lambda>[p\<^isub>2]. t) = (\<lambda>[p\<^isub>1']. \<lambda>[p\<^isub>2']. u)" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   709
    moreover from PTuple PTuple' have "pat_type p\<^isub>1 = pat_type p\<^isub>1'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   710
      by (simp add: ty.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   711
    moreover from PTuple' have "distinct (pat_vars p\<^isub>1)" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   712
    moreover from PTuple PTuple' have "distinct (pat_vars p\<^isub>1')" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   713
    ultimately have "\<exists>pi::name prm. p\<^isub>1 = pi \<bullet> p\<^isub>1' \<and>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   714
      (\<lambda>[p\<^isub>2]. t) = pi \<bullet> (\<lambda>[p\<^isub>2']. u) \<and>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   715
      set pi \<subseteq> (supp p\<^isub>1 \<union> supp p\<^isub>1') \<times> (supp p\<^isub>1 \<union> supp p\<^isub>1')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   716
      by (rule PTuple')
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   717
    then obtain pi::"name prm" where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   718
      "p\<^isub>1 = pi \<bullet> p\<^isub>1'" "(\<lambda>[p\<^isub>2]. t) = pi \<bullet> (\<lambda>[p\<^isub>2']. u)" and
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   719
      pi: "set pi \<subseteq> (supp p\<^isub>1 \<union> supp p\<^isub>1') \<times> (supp p\<^isub>1 \<union> supp p\<^isub>1')" by auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   720
    from `(\<lambda>[p\<^isub>2]. t) = pi \<bullet> (\<lambda>[p\<^isub>2']. u)`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   721
    have "(\<lambda>[p\<^isub>2]. t) = (\<lambda>[pi \<bullet> p\<^isub>2']. pi \<bullet> u)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   722
      by (simp add: eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   723
    moreover from PTuple PTuple' have "pat_type p\<^isub>2 = pat_type (pi \<bullet> p\<^isub>2')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   724
      by (simp add: ty.inject pat_type_perm_eq)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   725
    moreover from PTuple' have "distinct (pat_vars p\<^isub>2)" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   726
    moreover from PTuple PTuple' have "distinct (pat_vars (pi \<bullet> p\<^isub>2'))"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   727
      by (simp add: pat_vars_eqvt [symmetric] distinct_eqvt [symmetric])
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   728
    ultimately have "\<exists>pi'::name prm. p\<^isub>2 = pi' \<bullet> pi \<bullet> p\<^isub>2' \<and>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   729
      t = pi' \<bullet> pi \<bullet> u \<and>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   730
      set pi' \<subseteq> (supp p\<^isub>2 \<union> supp (pi \<bullet> p\<^isub>2')) \<times> (supp p\<^isub>2 \<union> supp (pi \<bullet> p\<^isub>2'))"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   731
      by (rule PTuple')
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   732
    then obtain pi'::"name prm" where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   733
      "p\<^isub>2 = pi' \<bullet> pi \<bullet> p\<^isub>2'" "t = pi' \<bullet> pi \<bullet> u" and
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   734
      pi': "set pi' \<subseteq> (supp p\<^isub>2 \<union> supp (pi \<bullet> p\<^isub>2')) \<times>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   735
        (supp p\<^isub>2 \<union> supp (pi \<bullet> p\<^isub>2'))" by auto
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   736
    from PTuple PTuple' have "pi \<bullet> distinct (pat_vars \<langle>\<langle>p\<^isub>1', p\<^isub>2'\<rangle>\<rangle>)" by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   737
    then have "distinct (pat_vars \<langle>\<langle>pi \<bullet> p\<^isub>1', pi \<bullet> p\<^isub>2'\<rangle>\<rangle>)" by (simp only: eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   738
    with `p\<^isub>1 = pi \<bullet> p\<^isub>1'` PTuple'
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   739
    have fresh: "(supp p\<^isub>2 \<union> supp (pi \<bullet> p\<^isub>2') :: name set) \<sharp>* p\<^isub>1"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   740
      by (auto simp add: set_pat_vars_supp fresh_star_def fresh_def eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   741
    from `p\<^isub>1 = pi \<bullet> p\<^isub>1'` have "pi' \<bullet> (p\<^isub>1 = pi \<bullet> p\<^isub>1')" by (rule perm_boolI)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   742
    with pt_freshs_freshs [OF pt_name_inst at_name_inst pi' fresh fresh]
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   743
    have "p\<^isub>1 = pi' \<bullet> pi \<bullet> p\<^isub>1'" by (simp add: eqvts)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   744
    with `p\<^isub>2 = pi' \<bullet> pi \<bullet> p\<^isub>2'` have "\<langle>\<langle>p\<^isub>1, p\<^isub>2\<rangle>\<rangle> = (pi' @ pi) \<bullet> \<langle>\<langle>p\<^isub>1', p\<^isub>2'\<rangle>\<rangle>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   745
      by (simp add: pt_name2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   746
    moreover
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   747
    have "((supp p\<^isub>2 \<union> (pi \<bullet> supp p\<^isub>2')) \<times> (supp p\<^isub>2 \<union> (pi \<bullet> supp p\<^isub>2'))::(name \<times> name) set) \<subseteq>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   748
      (supp p\<^isub>2 \<union> (supp p\<^isub>1 \<union> supp p\<^isub>1' \<union> supp p\<^isub>2')) \<times> (supp p\<^isub>2 \<union> (supp p\<^isub>1 \<union> supp p\<^isub>1' \<union> supp p\<^isub>2'))"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   749
      by (rule subset_refl Sigma_mono Un_mono perm_cases [OF pi])+
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   750
    with pi' have "set pi' \<subseteq> \<dots>" by (simp add: supp_eqvt [symmetric])
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   751
    with pi have "set (pi' @ pi) \<subseteq> (supp \<langle>\<langle>p\<^isub>1, p\<^isub>2\<rangle>\<rangle> \<union> supp \<langle>\<langle>p\<^isub>1', p\<^isub>2'\<rangle>\<rangle>) \<times>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   752
      (supp \<langle>\<langle>p\<^isub>1, p\<^isub>2\<rangle>\<rangle> \<union> supp \<langle>\<langle>p\<^isub>1', p\<^isub>2'\<rangle>\<rangle>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   753
      by (simp add: Sigma_Un_distrib1 Sigma_Un_distrib2 Un_ac) blast
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   754
    moreover note `t = pi' \<bullet> pi \<bullet> u`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   755
    ultimately have "\<langle>\<langle>p\<^isub>1, p\<^isub>2\<rangle>\<rangle> = (pi' @ pi) \<bullet> q \<and> t = (pi' @ pi) \<bullet> u \<and>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   756
      set (pi' @ pi) \<subseteq> (supp \<langle>\<langle>p\<^isub>1, p\<^isub>2\<rangle>\<rangle> \<union> supp q) \<times>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   757
        (supp \<langle>\<langle>p\<^isub>1, p\<^isub>2\<rangle>\<rangle> \<union> supp q)" using PTuple
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   758
      by (simp add: pt_name2)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   759
    then show ?thesis ..
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   760
  qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   761
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   762
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   763
lemma typing_case_Let:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   764
  assumes ty: "\<Gamma> \<turnstile> (LET p = t IN u) : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   765
  and fresh: "(supp p::name set) \<sharp>* \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   766
  and distinct: "distinct (pat_vars p)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   767
  and R: "\<And>T \<Delta>. \<Gamma> \<turnstile> t : T \<Longrightarrow> \<turnstile> p : T \<Rightarrow> \<Delta> \<Longrightarrow> \<Delta> @ \<Gamma> \<turnstile> u : U \<Longrightarrow> P"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   768
  shows P using ty
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   769
proof cases
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   770
  case (Let p' t' \<Gamma>' T \<Delta> u' U')
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   771
  then have "(supp \<Delta>::name set) \<sharp>* \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   772
    by (auto intro: valid_typing valid_app_freshs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   773
  with Let have "(supp p'::name set) \<sharp>* \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   774
    by (simp add: pat_var)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   775
  with fresh have fresh': "(supp p \<union> supp p' :: name set) \<sharp>* \<Gamma>"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   776
    by (auto simp add: fresh_star_def)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   777
  from Let have "(\<lambda>[p]. Base u) = (\<lambda>[p']. Base u')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   778
    by (simp add: trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   779
  moreover from Let have "pat_type p = pat_type p'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   780
    by (simp add: trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   781
  moreover note distinct
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   782
  moreover from `\<Delta> @ \<Gamma>' \<turnstile> u' : U'` have "valid (\<Delta> @ \<Gamma>')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   783
    by (rule valid_typing)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   784
  then have "valid \<Delta>" by (rule valid_appD)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   785
  with `\<turnstile> p' : T \<Rightarrow> \<Delta>` have "distinct (pat_vars p')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   786
    by (simp add: valid_distinct pat_vars_ptyping)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   787
  ultimately have "\<exists>pi::name prm. p = pi \<bullet> p' \<and> Base u = pi \<bullet> Base u' \<and>
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   788
    set pi \<subseteq> (supp p \<union> supp p') \<times> (supp p \<union> supp p')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   789
    by (rule abs_pat_alpha')
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   790
  then obtain pi::"name prm" where pi: "p = pi \<bullet> p'" "u = pi \<bullet> u'"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   791
    and pi': "set pi \<subseteq> (supp p \<union> supp p') \<times> (supp p \<union> supp p')"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   792
    by (auto simp add: btrm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   793
  from Let have "\<Gamma> \<turnstile> t : T" by (simp add: trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   794
  moreover from `\<turnstile> p' : T \<Rightarrow> \<Delta>` have "\<turnstile> (pi \<bullet> p') : (pi \<bullet> T) \<Rightarrow> (pi \<bullet> \<Delta>)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   795
    by (simp add: ptyping.eqvt)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   796
  with pi have "\<turnstile> p : T \<Rightarrow> (pi \<bullet> \<Delta>)" by (simp add: perm_type)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   797
  moreover from Let
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   798
  have "(pi \<bullet> \<Delta>) @ (pi \<bullet> \<Gamma>) \<turnstile> (pi \<bullet> u') : (pi \<bullet> U)"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   799
    by (simp add: append_eqvt [symmetric] typing.eqvt)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   800
  with pi have "(pi \<bullet> \<Delta>) @ \<Gamma> \<turnstile> u : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   801
    by (simp add: perm_type pt_freshs_freshs
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   802
      [OF pt_name_inst at_name_inst pi' fresh' fresh'])
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   803
  ultimately show ?thesis by (rule R)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   804
qed simp_all
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   805
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   806
lemma preservation:
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   807
  assumes "t \<longmapsto> t'" and "\<Gamma> \<turnstile> t : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   808
  shows "\<Gamma> \<turnstile> t' : T" using assms
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   809
proof (nominal_induct avoiding: \<Gamma> T rule: eval.strong_induct)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   810
  case (TupleL t t' u)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   811
  from `\<Gamma> \<turnstile> \<langle>t, u\<rangle> : T` obtain T\<^isub>1 T\<^isub>2
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   812
    where "T = T\<^isub>1 \<otimes> T\<^isub>2" "\<Gamma> \<turnstile> t : T\<^isub>1" "\<Gamma> \<turnstile> u : T\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   813
    by cases (simp_all add: trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   814
  from `\<Gamma> \<turnstile> t : T\<^isub>1` have "\<Gamma> \<turnstile> t' : T\<^isub>1" by (rule TupleL)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   815
  then have "\<Gamma> \<turnstile> \<langle>t', u\<rangle> : T\<^isub>1 \<otimes> T\<^isub>2" using `\<Gamma> \<turnstile> u : T\<^isub>2`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   816
    by (rule Tuple)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   817
  with `T = T\<^isub>1 \<otimes> T\<^isub>2` show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   818
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   819
  case (TupleR u u' t)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   820
  from `\<Gamma> \<turnstile> \<langle>t, u\<rangle> : T` obtain T\<^isub>1 T\<^isub>2
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   821
    where "T = T\<^isub>1 \<otimes> T\<^isub>2" "\<Gamma> \<turnstile> t : T\<^isub>1" "\<Gamma> \<turnstile> u : T\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   822
    by cases (simp_all add: trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   823
  from `\<Gamma> \<turnstile> u : T\<^isub>2` have "\<Gamma> \<turnstile> u' : T\<^isub>2" by (rule TupleR)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   824
  with `\<Gamma> \<turnstile> t : T\<^isub>1` have "\<Gamma> \<turnstile> \<langle>t, u'\<rangle> : T\<^isub>1 \<otimes> T\<^isub>2"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   825
    by (rule Tuple)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   826
  with `T = T\<^isub>1 \<otimes> T\<^isub>2` show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   827
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   828
  case (Abs t t' x S)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   829
  from `\<Gamma> \<turnstile> (\<lambda>x:S. t) : T` `x \<sharp> \<Gamma>` obtain U where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   830
    T: "T = S \<rightarrow> U" and U: "(x, S) # \<Gamma> \<turnstile> t : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   831
    by (rule typing_case_Abs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   832
  from U have "(x, S) # \<Gamma> \<turnstile> t' : U" by (rule Abs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   833
  then have "\<Gamma> \<turnstile> (\<lambda>x:S. t') : S \<rightarrow> U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   834
    by (rule typing.Abs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   835
  with T show ?case by simp
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   836
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   837
  case (Beta x u S t)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   838
  from `\<Gamma> \<turnstile> (\<lambda>x:S. t) \<cdot> u : T` `x \<sharp> \<Gamma>`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   839
  obtain "(x, S) # \<Gamma> \<turnstile> t : T" and "\<Gamma> \<turnstile> u : S"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   840
    by cases (auto simp add: trm.inject ty.inject elim: typing_case_Abs)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   841
  then show ?case by (rule subst_type)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   842
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   843
  case (Let p t \<theta> u)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   844
  from `\<Gamma> \<turnstile> (LET p = t IN u) : T` `supp p \<sharp>* \<Gamma>` `distinct (pat_vars p)`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   845
  obtain U \<Delta> where "\<turnstile> p : U \<Rightarrow> \<Delta>" "\<Gamma> \<turnstile> t : U" "\<Delta> @ \<Gamma> \<turnstile> u : T"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   846
    by (rule typing_case_Let)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   847
  then show ?case using `\<turnstile> p \<rhd> t \<Rightarrow> \<theta>` `supp p \<sharp>* t`
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   848
    by (rule match_type)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   849
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   850
  case (AppL t t' u)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   851
  from `\<Gamma> \<turnstile> t \<cdot> u : T` obtain U where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   852
    t: "\<Gamma> \<turnstile> t : U \<rightarrow> T" and u: "\<Gamma> \<turnstile> u : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   853
    by cases (auto simp add: trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   854
  from t have "\<Gamma> \<turnstile> t' : U \<rightarrow> T" by (rule AppL)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   855
  then show ?case using u by (rule typing.App)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   856
next
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   857
  case (AppR u u' t)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   858
  from `\<Gamma> \<turnstile> t \<cdot> u : T` obtain U where
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   859
    t: "\<Gamma> \<turnstile> t : U \<rightarrow> T" and u: "\<Gamma> \<turnstile> u : U"
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   860
    by cases (auto simp add: trm.inject)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   861
  from u have "\<Gamma> \<turnstile> u' : U" by (rule AppR)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   862
  with t show ?case by (rule typing.App)
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   863
qed
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   864
82a40677c1f8 Added Pattern.thy to Nominal/Examples.
berghofe
parents:
diff changeset
   865
end