Tutorial/Lambda.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 19 Mar 2016 21:06:48 +0000
branchNominal2-Isabelle2016
changeset 3243 c4f31f1564b7
parent 3236 e2da10806a34
permissions -rw-r--r--
updated to Isabelle 2016
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory Lambda
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports "../Nominal/Nominal2" 
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
section {* Definitions for Lambda Terms *}
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents: 2684
diff changeset
     7
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
text {* type of variables *}
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
atom_decl name
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
subsection {* Alpha-Equated Lambda Terms *}
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
nominal_datatype lam =
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  Var "name"
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
| App "lam" "lam"
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    18
| Lam x::"name" l::"lam" binds x in l ("Lam [_]. _" [100, 100] 100)
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
text {* some automatically derived theorems *}
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
thm lam.distinct
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
thm lam.eq_iff
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
thm lam.fresh
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
thm lam.size
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
thm lam.exhaust 
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
thm lam.strong_exhaust
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
thm lam.induct
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
thm lam.strong_induct
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
subsection {* Height Function *}
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
3235
5ebd327ffb96 changed nominal_primrec into the more appropriate nominal_function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3197
diff changeset
    35
nominal_function
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  height :: "lam \<Rightarrow> int"
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
where
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  "height (Var x) = 1"
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
| "height (App t1 t2) = max (height t1) (height t2) + 1"
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
| "height (Lam [x].t) = height t + 1"
3197
25d11b449e92 definition of an auxiliary graph in nominal-primrec definitions
Christian Urban <urbanc@in.tum.de>
parents: 3192
diff changeset
    41
apply(simp add: eqvt_def height_graph_aux_def)
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    42
apply(rule TrueI)
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
apply(rule_tac y="x" in lam.exhaust)
3192
14c7d7e29c44 added a simproc for alpha-equivalence to the simplifier
Christian Urban <urbanc@in.tum.de>
parents: 3183
diff changeset
    44
using [[simproc del: alpha_lst]]
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    45
apply(auto)
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    46
apply(erule_tac c="()" in Abs_lst1_fcb2)
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    47
apply(simp_all add: fresh_def pure_supp eqvt_at_def fresh_star_def)
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
done
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
3236
e2da10806a34 changed nominal_primrec to nominal_function and termination to nominal_termination
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3235
diff changeset
    50
nominal_termination (eqvt)
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    51
  by lexicographic_order
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents: 2684
diff changeset
    54
subsection {* Capture-Avoiding Substitution *}
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
3235
5ebd327ffb96 changed nominal_primrec into the more appropriate nominal_function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3197
diff changeset
    56
nominal_function
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  subst :: "lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam"  ("_ [_ ::= _]" [90,90,90] 90)
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
where
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  "(Var x)[y ::= s] = (if x = y then s else (Var x))"
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
| "(App t1 t2)[y ::= s] = App (t1[y ::= s]) (t2[y ::= s])"
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
| "atom x \<sharp> (y, s) \<Longrightarrow> (Lam [x]. t)[y ::= s] = Lam [x].(t[y ::= s])"
3197
25d11b449e92 definition of an auxiliary graph in nominal-primrec definitions
Christian Urban <urbanc@in.tum.de>
parents: 3192
diff changeset
    62
  unfolding eqvt_def subst_graph_aux_def
25d11b449e92 definition of an auxiliary graph in nominal-primrec definitions
Christian Urban <urbanc@in.tum.de>
parents: 3192
diff changeset
    63
  apply(simp)
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    64
  apply(rule TrueI)
3192
14c7d7e29c44 added a simproc for alpha-equivalence to the simplifier
Christian Urban <urbanc@in.tum.de>
parents: 3183
diff changeset
    65
  using [[simproc del: alpha_lst]]
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    66
  apply(auto)
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    67
  apply(rule_tac y="a" and c="(aa, b)" in lam.strong_exhaust)
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    68
  apply(blast)+
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    69
  apply(simp_all add: fresh_star_def fresh_Pair_elim)
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    70
  apply(erule_tac c="(ya,sa)" in Abs_lst1_fcb2)
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    71
  apply(simp_all add: Abs_fresh_iff)
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    72
  apply(simp add: fresh_star_def fresh_Pair)
3183
313e6f2cdd89 added permutation simplification to the simplifier; this makes the simplifier more powerful, but it potentially loops more often
Christian Urban <urbanc@in.tum.de>
parents: 3132
diff changeset
    73
  apply(simp add: eqvt_at_def)
313e6f2cdd89 added permutation simplification to the simplifier; this makes the simplifier more powerful, but it potentially loops more often
Christian Urban <urbanc@in.tum.de>
parents: 3132
diff changeset
    74
  apply(simp add: perm_supp_eq fresh_star_Pair)
313e6f2cdd89 added permutation simplification to the simplifier; this makes the simplifier more powerful, but it potentially loops more often
Christian Urban <urbanc@in.tum.de>
parents: 3132
diff changeset
    75
  apply(simp add: eqvt_at_def)
313e6f2cdd89 added permutation simplification to the simplifier; this makes the simplifier more powerful, but it potentially loops more often
Christian Urban <urbanc@in.tum.de>
parents: 3132
diff changeset
    76
  apply(simp add: perm_supp_eq fresh_star_Pair)
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
done
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
3236
e2da10806a34 changed nominal_primrec to nominal_function and termination to nominal_termination
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3235
diff changeset
    79
nominal_termination (eqvt)
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2718
diff changeset
    80
  by lexicographic_order
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    82
lemma fresh_fact:
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    83
  assumes a: "atom z \<sharp> s"
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    84
  and b: "z = y \<or> atom z \<sharp> t"
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    85
  shows "atom z \<sharp> t[y ::= s]"
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    86
using a b
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    87
by (nominal_induct t avoiding: z y s rule: lam.strong_induct)
3183
313e6f2cdd89 added permutation simplification to the simplifier; this makes the simplifier more powerful, but it potentially loops more often
Christian Urban <urbanc@in.tum.de>
parents: 3132
diff changeset
    88
   (auto simp add: fresh_at_base)
2684
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
end
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
d72a7168f1cb base file for the tutorial (contains definitions for heigt, subst and beta-reduction)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94