Tutorial/Tutorial3.thy
author Christian Urban <urbanc@in.tum.de>
Fri, 21 Jan 2011 22:02:34 +0100
changeset 2690 f325eefe803e
child 2691 abb6c3ac2df2
permissions -rw-r--r--
substitution lemma in 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.
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  One way to do this in Isar is to use blocks. A block is some sequent
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  or reasoning steps enclosed in curly braces
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
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
    have "statement"
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
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
   \<lbrakk>A; B\<rbrakk> \<Longrightarrow> "C" 
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
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  If we know that P1, P2 and P3 cover all the cases, that is P1 \<or> P2 \<or> P3 is
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  true, then we have 'ultimately' established the property "smth" 
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
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
section {* EXERCISE 7 *}
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
text {*
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  Fill in the cases 1.2 and 1.3 and the equational reasoning 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  in the lambda-case.
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
*}
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 forget:
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  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
    69
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
    70
   (auto simp add: lam.fresh fresh_at_base)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
lemma fresh_fact:
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  assumes a: "atom z \<sharp> s"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  and b: "z = y \<or> atom z \<sharp> t"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  shows "atom z \<sharp> t[y ::= s]"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
using a b
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
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
    78
   (auto simp add: lam.fresh fresh_at_base)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
lemma 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  assumes a: "x \<noteq> y"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  and     b: "atom x \<sharp> L"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  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
    85
using a b
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
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
    87
  case (Var z)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  have a1: "x \<noteq> y" by fact
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  have a2: "atom x \<sharp> L" by fact
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  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
    91
  proof -
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    { -- {* Case 1.1 *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
      assume c1: "z = x"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
      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
    95
      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
    96
      have "?LHS = ?RHS" using "(1)" "(2)" by simp
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
    moreover 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
    { -- {* Case 1.2 *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
      assume c2: "z = y" "z \<noteq> x" 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
      
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
      have "?LHS = ?RHS" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
    moreover 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
    { -- {* Case 1.3 *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
      assume c3: "z \<noteq> x" "z \<noteq> y"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
      
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
      have "?LHS = ?RHS" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
    }
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
    ultimately show "?LHS = ?RHS" by blast
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  qed
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
next
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  case (Lam z M1) -- {* case 2: lambdas *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  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
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  have a1: "x \<noteq> y" by fact
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  have a2: "atom x \<sharp> L" by fact
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  have fs: "atom z \<sharp> x" "atom z \<sharp> y" "atom z \<sharp> N" "atom z \<sharp> L" by fact+
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  then have b: "atom z \<sharp> N[y::=L]" by (simp add: fresh_fact)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  show "(Lam [z].M1)[x::=N][y::=L] = (Lam [z].M1)[y::=L][x::=N[y::=L]]" (is "?LHS=?RHS") 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  proof - 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
    have "?LHS = \<dots>" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
    also have "\<dots> = ?RHS" sorry
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
    finally show "?LHS = ?RHS" by simp
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  qed
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
next
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  case (App M1 M2) -- {* case 3: applications *}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  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
   129
qed
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
text {* 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  Again the strong induction principle enables Isabelle to find
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  the proof of the substitution lemma automatically. 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
*}
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
lemma substitution_lemma_version:  
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  assumes asm: "x \<noteq> y" "atom x \<sharp> L"
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  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
   139
  using asm 
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
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
   141
   (auto simp add: fresh_fact forget)
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
f325eefe803e substitution lemma in separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
end