Nominal/activities/nominal-ijcar08/Lambda.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Tue, 07 Jan 2025 12:42:42 +0000
changeset 653 2807ec31d144
parent 418 18a6039148df
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
418
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory Lambda 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
  imports "Nominal" 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
atom_decl name
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
section {* Alpha-Equated Lambda-Terms *}
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
nominal_datatype lam =
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  Var "name"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
| App "lam" "lam" 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
| Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._")
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
section {* Capture-Avoiding Substitution *}
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
consts subst :: "lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam"  ("_[_::=_]")
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
nominal_primrec
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
  "(Var x)[y::=s] = (if x=y then s else (Var x))"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  "(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
  "x\<sharp>(y,s) \<Longrightarrow> (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
apply(finite_guess)+
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
apply(rule TrueI)+
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
apply(simp add: abs_fresh)+
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
apply(fresh_guess)+
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
done
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
lemma  subst_eqvt[eqvt]:
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
  fixes pi::"name prm"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  shows "pi\<bullet>(t1[x::=t2]) = (pi\<bullet>t1)[(pi\<bullet>x)::=(pi\<bullet>t2)]"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
by (nominal_induct t1 avoiding: x t2 rule: lam.strong_induct)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
   (auto simp add: perm_bij fresh_atm fresh_bij)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
lemma forget: 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  assumes a: "x\<sharp>L"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  shows "L[x::=P] = L"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  using a 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
by (nominal_induct L avoiding: x P rule: lam.strong_induct)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
   (auto simp add: abs_fresh fresh_atm)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
lemma fresh_fact:
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  fixes z::"name"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  shows "\<lbrakk>z\<sharp>s; (z=y \<or> z\<sharp>t)\<rbrakk> \<Longrightarrow> z\<sharp>t[y::=s]"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
by (nominal_induct t avoiding: z y s rule: lam.strong_induct)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
   (auto simp add: abs_fresh fresh_prod fresh_atm)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
lemma subst_rename: 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
  assumes a: "y\<sharp>t"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  shows "t[x::=s] = ([(y,x)]\<bullet>t)[y::=s]"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
using a 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
by (nominal_induct t avoiding: x y s rule: lam.strong_induct)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
     (auto simp add: calc_atm fresh_atm abs_fresh)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
text {* 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  The purpose of the two lemmas below is to work
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  around some quirks in Isabelle's handling of 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
  meta_quantifiers and meta_implications. 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  *} 
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
lemma meta_impCE:
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
  assumes major: "P ==> PROP Q"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
    and 1: "~ P ==> R"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
    and 2: "PROP Q ==> R"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
  shows R
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
proof (cases P)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
  assume P
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  then have "PROP Q" by (rule major)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  then show R by (rule 2)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
next
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  assume "~ P"
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
  then show R by (rule 1)
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
qed
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
declare meta_allE [elim]
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
    and meta_impCE [elim!]
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
end    
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
   
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
  
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
  
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
  
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
18a6039148df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87