Tutorial/Tutorial3.thy
author Christian Urban <urbanc@in.tum.de>
Fri, 21 Jan 2011 22:23:44 +0100
changeset 2691 abb6c3ac2df2
parent 2690 f325eefe803e
child 2699 0424e7a7e99f
permissions -rw-r--r--
separated type preservation and progress into a separate file
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory Tutorial3
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports Lambda
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
section {* Formalising Barendregt's Proof of the Substitution Lemma *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
text {*
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  Barendregt's proof needs in the variable case a case distinction.
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
     9
  One way to do this in Isar is to use blocks. A block consist of some
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    10
  assumptions and reasoning steps enclosed in curly braces, like
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  { \<dots>
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
    have "statement"
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    14
    have "last_statement_in_the_block"
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  Such a block can contain local assumptions like
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  { assume "A"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
    assume "B"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
    \<dots>
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
    have "C" by \<dots>
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  Where "C" is the last have-statement in this block. The behaviour 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  of such a block to the 'outside' is the implication
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    28
   A \<Longrightarrow> B \<Longrightarrow> C 
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  Now if we want to prove a property "smth" using the case-distinctions
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  P1, P2 and P3 then we can use the following reasoning:
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
    { assume "P1"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
      \<dots>
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
      have "smth"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
    moreover
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
    { assume "P2"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
      \<dots>
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
      have "smth"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
    moreover
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
    { assume "P3"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
      \<dots>
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
      have "smth"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
    ultimately have "smth" by blast
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  The blocks establish the implications
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
    P1 \<Longrightarrow> smth
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
    P2 \<Longrightarrow> smth
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
    P3 \<Longrightarrow> smth
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    55
  If we know that P1, P2 and P3 cover all the cases, that is P1 \<or> P2 \<or> P3 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    56
  holds, then we have 'ultimately' established the property "smth" 
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
*}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    60
subsection {* Two preliminary facts *}
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
lemma forget:
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  shows "atom x \<sharp> t \<Longrightarrow> t[x ::= s] = t"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
by (nominal_induct t avoiding: x s rule: lam.strong_induct)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
   (auto simp add: lam.fresh fresh_at_base)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
lemma fresh_fact:
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  assumes a: "atom z \<sharp> s"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  and b: "z = y \<or> atom z \<sharp> t"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  shows "atom z \<sharp> t[y ::= s]"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
using a b
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
by (nominal_induct t avoiding: z y s rule: lam.strong_induct)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
   (auto simp add: lam.fresh fresh_at_base)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    76
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    77
section {* EXERCISE 7 *}
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    78
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    79
text {*
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    80
  Fill in the cases 1.2 and 1.3 and the equational reasoning 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    81
  in the lambda-case.
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    82
*}
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
    83
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
lemma 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  assumes a: "x \<noteq> y"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  and     b: "atom x \<sharp> L"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  shows "M[x::=N][y::=L] = M[y::=L][x::=N[y::=L]]"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
using a b
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
proof (nominal_induct M avoiding: x y N L rule: lam.strong_induct)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  case (Var z)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  have a1: "x \<noteq> y" by fact
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  have a2: "atom x \<sharp> L" by fact
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  show "Var z[x::=N][y::=L] = Var z[y::=L][x::=N[y::=L]]" (is "?LHS = ?RHS")
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  proof -
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
    { -- {* Case 1.1 *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
      assume c1: "z = x"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
      have "(1)": "?LHS = N[y::=L]" using c1 by simp
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
      have "(2)": "?RHS = N[y::=L]" using c1 a1 by simp
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
      have "?LHS = ?RHS" using "(1)" "(2)" by simp
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
    moreover 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    { -- {* Case 1.2 *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
      assume c2: "z = y" "z \<noteq> x" 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
      
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
      have "?LHS = ?RHS" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    moreover 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
    { -- {* Case 1.3 *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
      assume c3: "z \<noteq> x" "z \<noteq> y"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
      
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
      have "?LHS = ?RHS" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
    ultimately show "?LHS = ?RHS" by blast
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  qed
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
next
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  case (Lam z M1) -- {* case 2: lambdas *}
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
   117
  have ih: "\<lbrakk>x \<noteq> y; atom x \<sharp> L\<rbrakk> \<Longrightarrow> M1[x ::= N][y ::= L] = M1[y ::= L][x ::= N[y ::= L]]" by fact
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  have a1: "x \<noteq> y" by fact
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  have a2: "atom x \<sharp> L" by fact
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
   120
  have fs: "atom z \<sharp> x" "atom z \<sharp> y" "atom z \<sharp> N" "atom z \<sharp> L" by fact+   -- {* !! *}
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  then have b: "atom z \<sharp> N[y::=L]" by (simp add: fresh_fact)
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
   122
  show "(Lam [z].M1)[x ::= N][y ::= L] = (Lam [z].M1)[y ::= L][x ::= N[y ::= L]]" (is "?LHS=?RHS") 
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  proof - 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
    have "?LHS = \<dots>" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
    also have "\<dots> = ?RHS" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
    finally show "?LHS = ?RHS" by simp
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  qed
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
next
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  case (App M1 M2) -- {* case 3: applications *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  then show "(App M1 M2)[x::=N][y::=L] = (App M1 M2)[y::=L][x::=N[y::=L]]" by simp
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
qed
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
text {* 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  Again the strong induction principle enables Isabelle to find
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2690
diff changeset
   136
  the proof of the substitution lemma completely automatically. 
2690
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
*}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
lemma substitution_lemma_version:  
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  assumes asm: "x \<noteq> y" "atom x \<sharp> L"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  shows "M[x::=N][y::=L] = M[y::=L][x::=N[y::=L]]"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  using asm 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
by (nominal_induct M avoiding: x y N L rule: lam.strong_induct)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
   (auto simp add: fresh_fact forget)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
end