Tutorial/Tutorial1.thy
author Christian Urban <urbanc@in.tum.de>
Fri, 21 Jan 2011 00:55:28 +0100
changeset 2688 87b735f86060
parent 2687 d0fb94035969
child 2689 ddc05a611005
permissions -rw-r--r--
a bit tuning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
header {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
     4
  Nominal Isabelle Tutorial at POPL'11
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
     5
  ====================================
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  Nominal Isabelle is a definitional extension of Isabelle/HOL, which
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  means it does not add any new axioms to higher-order logic. It merely
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  adds new definitions and an infrastructure for 'nominal resoning'.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    12
  The jEdit Interface
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    13
  -------------------
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    15
  The Isabelle theorem prover comes with an interface for the jEdit. 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  Unlike many other theorem prover interfaces (e.g. ProofGeneral) where you 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  try to advance a 'checked' region in a proof script, this interface immediately 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  checks the whole buffer. The text you type is also immediately checked
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  as you type. Malformed text or unfinished proofs are highlighted in red 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  with a little red 'stop' signal on the left-hand side. If you drag the 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  'red-box' cursor over a line, the Output window gives further feedback. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  Note: If a section is not parsed correctly, the work-around is to cut it 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  out and paste it back into the text (cut-out: Ctrl + X; paste in: Ctrl + V;
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  Cmd is Ctrl on the Mac)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  Nominal Isabelle and the interface can be started on the command line with
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
     isabelle jedit -l HOL-Nominal2
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
     isabelle jedit -l HOL-Nominal2 A.thy B.thy ...
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  Symbols
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  ------- 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  Symbols can considerably improve the readability of your statements and proofs. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  They can be input by just typing 'name-of-symbol' where 'name-of-symbol' is the 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  usual latex name of that symbol. A little window will then appear in which 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  you can select the symbol. With `Escape' you can ignore any suggestion.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  There are some handy short-cuts for frequently used symbols. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  For example 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
      short-cut  symbol
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
          =>      \<Rightarrow>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
          ==>     \<Longrightarrow>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
          -->     \<longrightarrow>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
          !       \<forall>        
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
          ?       \<exists>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
          /\      \<and>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
          \/      \<or>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
          ~       \<not>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
          ~=      \<noteq>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
          :       \<in>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
          ~:      \<notin>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  For nominal two important symbols are
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
          \<sharp>       sharp     (freshness)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
          \<bullet>       bullet    (permutations)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
theory Tutorial1
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
imports Lambda
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
begin
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
section {* Theories *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  All formal developments in Isabelle are part of a theory. A theory 
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    72
  needs to have a name and must import some pre-existing theory. The 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    73
  imported theory will normally be the theory Nominal2 (which  contains 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    74
  many useful concepts like set-theory, lists, nominal theory etc).
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  For the purpose of the tutorial we import the theory Lambda.thy which
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    76
  contains already some useful definitions for (alpha-equated) lambda 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    77
  terms.
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
section {* Types *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
text {*
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    85
  Isabelle is based on simple types including some polymorphism. It also 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    86
  includes overloading, which means that sometimes explicit type annotations 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    87
  need to be given.
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
    89
    - Base types include: nat, bool, string, lam (defined in the Lambda theory)
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
    - Type formers include: 'a list, ('a \<times> 'b), 'c set   
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
    - Type variables are written like in ML with an apostrophe: 'a, 'b, \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  Types known to Isabelle can be queried using the command "typ".
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
typ nat
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
typ bool
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
typ string           
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   101
typ lam           -- {* alpha-equated lambda terms defined in Lambda.thy *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   102
typ name          -- {* type of (object) variables defined in Lambda.thy *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   103
typ "('a \<times> 'b)"   -- {* pair type *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   104
typ "'c set"      -- {* set type *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   105
typ "'a list"     -- {* list type *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   106
typ "lam \<Rightarrow> nat"   -- {* type of functions from lambda terms to natural numbers *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   109
text {* Some malformed types - note the "stop" signal on the left margin *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
(*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
typ boolean     -- {* undeclared type *} 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
typ set         -- {* type argument missing *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
*)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
section {* Terms *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
   Every term in Isabelle needs to be well-typed. However they can have 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
   polymorphic type. Whether a term is accepted can be queried using
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
   the command "term". 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
term c                 -- {* a variable of polymorphic type *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
term "1::nat"          -- {* the constant 1 in natural numbers *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
term 1                 -- {* the constant 1 with polymorphic type *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
term "{1, 2, 3::nat}"  -- {* the set containing natural numbers 1, 2 and 3 *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
term "[1, 2, 3]"       -- {* the list containing the polymorphic numbers 1, 2 and 3 *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
term "(True, ''c'')"   -- {* a pair consisting of the boolean true and the string "c" *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
term "Suc 0"           -- {* successor of 0, in other words 1::nat *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
term "Lam [x].Var x"   -- {* a lambda-term *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
term "App t1 t2"       -- {* another lambda-term *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
term "x::name"         -- {* an (object) variable of type name *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
term "atom (x::name)"  -- {* atom is an overloded function *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  Lam [x].Var is the syntax we made up for lambda abstractions. You can have
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   139
  your own syntax, if you prefer (but \<lambda> is already taken up for Isabelle's
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   140
  functions). We also came up with "name". If you prefer, you can call
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   141
  it "ident" or have more than one type for (object language) variables.
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   143
  Isabelle provides some useful colour feedback about its constants (black), 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  free variables (blue) and bound variables (green).
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
term "True"    -- {* a constant that is defined in HOL...written in black *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
term "true"    -- {* not recognised as a constant, therefore it is interpreted
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
                     as a free variable, written in blue *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
term "\<forall>x. P x" -- {* x is bound (green), P is free (blue) *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
text {* Formulae in Isabelle/HOL are terms of type bool *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
term "True"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
term "True \<and> False"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
term "True \<or> B"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
term "{1,2,3} = {3,2,1}"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
term "\<forall>x. P x"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
term "A \<longrightarrow> B"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   161
term "atom a \<sharp> t"   -- {* freshness in Nominal *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
  When working with Isabelle, one deals with an object logic (that is HOL) and 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  Isabelle's rule framework (called Pure). Occasionally one has to pay attention 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  to this fact. But for the moment we ignore this completely.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
term "A \<longrightarrow> B"  -- {* versus *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
term "A \<Longrightarrow> B"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
term "\<forall>x. P x"  -- {* versus *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
term "\<And>x. P x"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
section {* Inductive Definitions: Transitive Closures of Beta-Reduction *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
text {*
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   180
  The theory Lmabda already contains a definition for beta-reduction, written
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   181
*}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   183
term "t \<longrightarrow>b t'"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents: 2686
diff changeset
   185
text {*
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  In this section we want to define inductively the transitive closure of
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  beta-reduction.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  Inductive definitions in Isabelle start with the keyword "inductive" and a predicate 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
  name.  One can optionally provide a type for the predicate. Clauses of the inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
  predicate are introduced by "where" and more than two clauses need to be 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
  separated by "|". One can also give a name to each clause and indicate that it 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  should be added to the hints database ("[intro]"). A typical clause has some 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  premises and a conclusion. This is written in Isabelle as:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
   "premise \<Longrightarrow> conclusion"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
   "premise1 \<Longrightarrow> premise2 \<Longrightarrow> \<dots> premisen \<Longrightarrow> conclusion"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  There is an alternative way of writing the latter clause as
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
   "\<lbrakk>premise1; premise2; \<dots> premisen\<rbrakk> \<Longrightarrow> conclusion"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  If no premise is present, then one just writes
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
   "conclusion"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
  Below we give two definitions for the transitive closure
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
  beta_star1 :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<longrightarrow>b* _" [60, 60] 60)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  bs1_refl: "t \<longrightarrow>b* t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
| bs1_trans: "\<lbrakk>t1 \<longrightarrow>b t2; t2 \<longrightarrow>b* t3\<rbrakk> \<Longrightarrow> t1 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  beta_star2 :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<longrightarrow>b** _" [60, 60] 60)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  bs2_refl: "t \<longrightarrow>b** t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
| bs2_step: "t1 \<longrightarrow>b t2 \<Longrightarrow> t1 \<longrightarrow>b** t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
| bs2_trans: "\<lbrakk>t1 \<longrightarrow>b** t2; t2 \<longrightarrow>b** t3\<rbrakk> \<Longrightarrow> t1 \<longrightarrow>b** t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
section {* Theorems *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  A central concept in Isabelle is that of theorems. Isabelle's theorem
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
  database can be queried using 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
thm bs1_refl
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
thm bs2_trans
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
thm conjI
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
thm conjunct1
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  Notice that theorems usually contain schematic variables (e.g. ?P, ?Q, \<dots>). 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
  These schematic variables can be substituted with any term (of the right type 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
  of course). 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
  When defining the predicates beta_star, Isabelle provides us automatically 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
  with the following theorems that state how they can be introduced and what 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  constitutes an induction over them. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
thm beta_star1.intros
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
thm beta_star2.induct
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
section {* Lemmas / Theorems / Corollaries *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
  Whether to use lemma, theorem or corollary makes no semantic difference 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  in Isabelle. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  A lemma starts with "lemma" and consists of a statement ("shows \<dots>") and 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  optionally a lemma name, some type-information for variables ("fixes \<dots>") 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
  and some assumptions ("assumes \<dots>"). 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
  Lemmas also need to have a proof, but ignore this 'detail' for the moment.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
  Examples are
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
lemma alpha_equ:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
  shows "Lam [x].Var x = Lam [y].Var y"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
  by (simp add: lam.eq_iff Abs1_eq_iff lam.fresh fresh_at_base)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
lemma Lam_freshness:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
  assumes a: "x \<noteq> y"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
  and     b: "atom y \<sharp> Lam [x].t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
  shows "atom y \<sharp> t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
  using a b by (simp add: lam.fresh Abs_fresh_iff) 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
lemma neutral_element:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
  fixes x::"nat"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
  shows "x + 0 = x"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
  by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
  Note that in the last statement, the explicit type annotation is important 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
  in order for Isabelle to be able to figure out what 0 stands for (e.g. a 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
  natural number, a vector, etc) and which lemmas to apply.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
section {* Isar Proofs *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
  Isar is a language for writing formal proofs that can be understood by humans 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
  and by Isabelle. An Isar proof can be thought of as a sequence of 'stepping stones' 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
  that start with some assumptions and lead to the goal to be established. Every such 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
  stepping stone is introduced by "have" followed by the statement of the stepping 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
  stone. An exception is the goal to be proved, which need to be introduced with "show".
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
      have "statement"  \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
      show "goal_to_be_proved" \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
  Since proofs usually do not proceed in a linear fashion, labels can be given 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
  to every stepping stone and they can be used later to explicitly refer to this 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
  corresponding stepping stone ("using").
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
      have label: "statement1"  \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
      \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
      have "later_statement" using label \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
  Each stepping stone (or have-statement) needs to have a justification. The 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
  simplest justification is "sorry" which admits any stepping stone, even false 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
  ones (this is good during the development of proofs). 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
      have "outrageous_false_statement" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
  Assumptions can be 'justified' using "by fact". 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
      have "assumption" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
  Derived facts can be justified using 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
      have "statement" by simp    -- simplification 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
      have "statement" by auto    -- proof search and simplification 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
      have "statement" by blast   -- only proof search 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
  If facts or lemmas are needed in order to justify a have-statement, then
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
  one can feed these facts into the proof by using "using label \<dots>" or 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
  "using theorem-name \<dots>". More than one label at a time is allowed. For
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
  example
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
      have "statement" using label1 label2 theorem_name by auto
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
  Induction proofs in Isar are set up by indicating over which predicate(s) 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
  the induction proceeds ("using a b") followed by the command "proof (induct)". 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
  In this way, Isabelle uses defaults for which induction should be performed. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
  These defaults can be overridden by giving more information, like the variable 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
  over which a structural induction should proceed, or a specific induction principle, 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
  such as well-founded inductions. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
  After the induction is set up, the proof proceeds by cases. In Isar these 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
  cases can be given in any order. Most commonly they are started with "case" and the 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
  name of the case, and optionally some legible names for the variables used inside 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
  the case. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
  In each "case", we need to establish a statement introduced by "show". Once 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
  this has been done, the next case can be started using "next". When all cases 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
  are completed, the proof can be finished using "qed".
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
  This means a typical induction proof has the following pattern
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
     proof (induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
       case \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
       \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
       show \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
     next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
       case \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
       \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
       show \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
     \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
     qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
subsection {* Exercise I *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
  Remove the sorries in the proof below and fill in the proper
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
  justifications. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
lemma
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
  assumes a: "t1 \<longrightarrow>b* t2" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
  shows "t1 \<longrightarrow>b** t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
  using a
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
proof (induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
  case (bs1_refl t)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
  show "t \<longrightarrow>b** t" using bs2_refl by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
  case (bs1_trans t1 t2 t3)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
  have beta: "t1 \<longrightarrow>b t2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
  have ih: "t2 \<longrightarrow>b** t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
  have a: "t1 \<longrightarrow>b** t2" using beta bs2_step by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
  show "t1 \<longrightarrow>b** t3" using a ih bs2_trans by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
subsection {* Exercise II *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
  Again remove the sorries in the proof below and fill in the proper
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
  justifications. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
lemma bs1_trans2:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
  assumes a: "t1 \<longrightarrow>b* t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
  and     b: "t2 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
  shows "t1 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
proof (induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
  case (bs1_refl t1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
  have a: "t1 \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
  show "t1 \<longrightarrow>b* t3" using a by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
  case (bs1_trans t1 t2 t3')
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
  have ih1: "t1 \<longrightarrow>b t2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
  have ih2: "t3' \<longrightarrow>b* t3 \<Longrightarrow> t2 \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
  have asm: "t3' \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
  have a: "t2 \<longrightarrow>b* t3" using ih2 asm by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
  show "t1 \<longrightarrow>b* t3" using ih1 a beta_star1.bs1_trans by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
lemma
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
  assumes a: "t1 \<longrightarrow>b** t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
  shows "t1 \<longrightarrow>b* t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
using a
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
proof (induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
  case (bs2_refl t)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
  show "t \<longrightarrow>b* t" using bs1_refl by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
  case (bs2_step t1 t2)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
  have ih: "t1 \<longrightarrow>b t2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
  have a: "t2 \<longrightarrow>b* t2" using bs1_refl by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
  show "t1 \<longrightarrow>b* t2" using ih a bs1_trans by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
  case (bs2_trans t1 t2 t3)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
  have ih1: "t1 \<longrightarrow>b* t2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
  have ih2: "t2 \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
  show "t1 \<longrightarrow>b* t3" using ih1 ih2 bs1_trans2 by blast  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
  Just like gotos in the Basic programming language, labels often reduce 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
  the readability of proofs. Therefore one can use in Isar the notation
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
  "then have" in order to feed a have-statement to the proof of 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
  the next have-statement. This is used in teh second case below.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
  assumes a: "t1 \<longrightarrow>b* t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
  and     b: "t2 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
  shows "t1 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
proof (induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
  case (bs1_refl t1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
  show "t1 \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
  case (bs1_trans t1 t2 t3')
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
  have ih1: "t1 \<longrightarrow>b t2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
  have ih2: "t3' \<longrightarrow>b* t3 \<Longrightarrow> t2 \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
  have "t3' \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
  then have "t2 \<longrightarrow>b* t3" using ih2 by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
  then show "t1 \<longrightarrow>b* t3" using ih1 beta_star1.bs1_trans by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
  The label ih2 cannot be got rid of in this way, because it is used 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
  two lines below and we cannot rearange them. We can still avoid the
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
  label by feeding a sequence of facts into a proof using the 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
  "moreover"-chaining mechanism:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
   have "statement_1" \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
   moreover
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
   have "statement_2" \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
   \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
   moreover
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
   have "statement_n" \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
   ultimately have "statement" \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
  In this chain, all "statement_i" can be used in the proof of the final 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
  "statement". With this we can simplify our proof further to:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
  assumes a: "t1 \<longrightarrow>b* t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
  and     b: "t2 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
  shows "t1 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
proof (induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
  case (bs1_refl t1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
  show "t1 \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
  case (bs1_trans t1 t2 t3')
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
  have "t3' \<longrightarrow>b* t3 \<Longrightarrow> t2 \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
  moreover
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
  have "t3' \<longrightarrow>b* t3" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
  ultimately 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
  have "t2 \<longrightarrow>b* t3" by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
  moreover 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
  have "t1 \<longrightarrow>b t2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
  ultimately show "t1 \<longrightarrow>b* t3" using beta_star1.bs1_trans by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
  While automatic proof procedures in Isabelle are not able to prove statements
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
  like "P = NP" assuming usual definitions for P and NP, they can automatically
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
  discharge the lemmas we just proved. For this we only have to set up the induction
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
  and auto will take care of the rest. This means we can write:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
lemma
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
  assumes a: "t1 \<longrightarrow>b* t2" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
  shows "t1 \<longrightarrow>b** t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
  using a
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
by (induct) (auto intro: beta_star2.intros)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
  assumes a: "t1 \<longrightarrow>b* t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
  and     b: "t2 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
  shows "t1 \<longrightarrow>b* t3"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
by (induct) (auto intro: beta_star1.intros)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
lemma
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
  assumes a: "t1 \<longrightarrow>b** t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
  shows "t1 \<longrightarrow>b* t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
using a
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
by (induct) (auto intro: bs1_trans2 beta_star1.intros)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
  eval :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<Down> _" [60, 60] 60) 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
  e_Lam:  "Lam [x].t \<Down> Lam [x].t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
| e_App:  "\<lbrakk>t1 \<Down> Lam [x].t; t2 \<Down> v'; t[x::=v'] \<Down> v\<rbrakk> \<Longrightarrow> App t1 t2 \<Down> v"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
declare eval.intros[intro]
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
  Values are also defined using inductive. In our case values
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
  are just lambda-abstractions. *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
  val :: "lam \<Rightarrow> bool" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
  v_Lam[intro]:   "val (Lam [x].t)"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   534
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   536
section {* Datatypes: Evaluation Contexts *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   537
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   538
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   539
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
  Datatypes can be defined in Isabelle as follows: we have to provide the name 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
  of the datatype and list its type-constructors. Each type-constructor needs 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
  to have the information about the types of its arguments, and optionally 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
  can also contain some information about pretty syntax. For example, we like
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
  to write "\<box>" for holes.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
datatype ctx = 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
    Hole ("\<box>")  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
  | CAppL "ctx" "lam"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
  | CAppR "lam" "ctx"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   551
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   552
text {* Now Isabelle knows about: *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   553
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
typ ctx
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
term "\<box>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
term "CAppL"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
term "CAppL \<box> (Var x)"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   560
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
  1.) MINI EXERCISE
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   562
  -----------------
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
  Try and see what happens if you apply a Hole to a Hole? 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   566
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   567
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
type_synonym ctxs = "ctx list"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   569
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   570
inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
  machine :: "lam \<Rightarrow> ctxs \<Rightarrow>lam \<Rightarrow> ctxs \<Rightarrow> bool" ("<_,_> \<mapsto> <_,_>" [60, 60, 60, 60] 60)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
  m1[intro]: "<App t1 t2,Es> \<mapsto> <t1,(CAppL \<box> t2) # Es>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
| m2[intro]: "val v \<Longrightarrow> <v,(CAppL \<box> t2) # Es> \<mapsto> <t2,(CAppR v \<box>) # Es>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
| m3[intro]: "val v \<Longrightarrow> <v,(CAppR (Lam [x].t) \<box>) # Es> \<mapsto> <t[x ::= v],Es>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   578
text {*
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
  Since the machine defined above only performs a single reduction,
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
  we need to define the transitive closure of this machine. *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
inductive 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
  machines :: "lam \<Rightarrow> ctxs \<Rightarrow> lam \<Rightarrow> ctxs \<Rightarrow> bool" ("<_,_> \<mapsto>* <_,_>" [60, 60, 60, 60] 60)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   584
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   585
  ms1[intro]: "<t,Es> \<mapsto>* <t,Es>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
| ms2[intro]: "\<lbrakk><t1,Es1> \<mapsto> <t2,Es2>; <t2,Es2> \<mapsto>* <t3,Es3>\<rbrakk> \<Longrightarrow> <t1,Es1> \<mapsto>* <t3,Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   587
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   588
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   589
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   590
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   592
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   593
proof(induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   594
  case (ms1 e1 Es1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
  have c: "<e1, Es1> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   596
  show "<e1, Es1> \<mapsto>* <e3, Es3>" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   598
  case (ms2 e1 Es1 e2 Es2 e2' Es2') 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
  have ih: "<e2', Es2'> \<mapsto>* <e3, Es3> \<Longrightarrow> <e2, Es2> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
  have d1: "<e2', Es2'> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   601
  have d2: "<e1, Es1> \<mapsto> <e2, Es2>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
  show "<e1, Es1> \<mapsto>* <e3, Es3>" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607
  Just like gotos in the Basic programming language, labels can reduce 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
  the readability of proofs. Therefore one can use in Isar the notation
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
  "then have" in order to feed a have-statement to the proof of 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   610
  the next have-statement. In the proof below this has been used
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   611
  in order to get rid of the labels c and d1. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   613
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   614
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
proof(induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
  case (ms1 e1 Es1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
  show "<e1, Es1> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
  case (ms2 e1 Es1 e2 Es2 e2' Es2')
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
  have ih: "<e2', Es2'> \<mapsto>* <e3, Es3> \<Longrightarrow> <e2, Es2> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
  have "<e2', Es2'> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
  then have d3: "<e2, Es2> \<mapsto>* <e3, Es3>" using ih by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
  have d2: "<e1, Es1> \<mapsto> <e2, Es2>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
  show "<e1, Es1> \<mapsto>* <e3, Es3>" using d2 d3 by auto
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   630
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
proof(induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
  case (ms1 e1 Es1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   638
  show "<e1, Es1> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
  case (ms2 e1 Es1 e2 Es2 e2' Es2')
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
  have ih: "<e2', Es2'> \<mapsto>* <e3, Es3> \<Longrightarrow> <e2, Es2> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
  have "<e2', Es2'> \<mapsto>* <e3, Es3>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
  then have "<e2, Es2> \<mapsto>* <e3, Es3>" using ih by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
  moreover
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
  have "<e1, Es1> \<mapsto> <e2, Es2>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
  ultimately show "<e1, Es1> \<mapsto>* <e3, Es3>" by auto
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
lemma ms3[intro]:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
using a b by (induct) (auto)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
lemma eval_to_val:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   657
  assumes a: "t \<Down> t'"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   658
  shows "val t'"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
using a by (induct) (auto)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
theorem 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
  assumes a: "t \<Down> t'"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
  shows "<t, []> \<mapsto>* <t', []>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
using a 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
proof (induct)
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   667
  case (e_Lam x t) 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   668
  -- {* no assumptions *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   669
  show "<Lam [x].t, []> \<mapsto>* <Lam [x].t, []>" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
next
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   671
  case (e_App t1 x t t2 v' v) 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   672
  -- {* all assumptions in this case *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   673
  have a1: "t1 \<Down> Lam [x].t" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
  have ih1: "<t1, []> \<mapsto>* <Lam [x].t, []>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
  have a2: "t2 \<Down> v'" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
  have ih2: "<t2, []> \<mapsto>* <v', []>" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
  have a3: "t[x::=v'] \<Down> v" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
  have ih3: "<t[x::=v'], []> \<mapsto>* <v, []>" by fact
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   679
  -- {* your reasoning *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
  show "<App t1 t2, []> \<mapsto>* <v, []>" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   681
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   683
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   684
  Again the automatic tools in Isabelle can discharge automatically 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   685
  of the routine work in these proofs. We can write: 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   686
*}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   687
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   688
theorem eval_implies_machines_ctx:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   689
  assumes a: "t \<Down> t'"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   690
  shows "<t, Es> \<mapsto>* <t', Es>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   691
using a
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   692
by (induct arbitrary: Es)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   693
   (metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   694
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   695
corollary eval_implies_machines:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   696
  assumes a: "t \<Down> t'"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   697
  shows "<t, []> \<mapsto>* <t', []>"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   698
using a eval_implies_machines_ctx by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   699
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   700
section {* Types *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   701
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   702
nominal_datatype ty =
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   703
  tVar "string"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   704
| tArr "ty" "ty" ("_ \<rightarrow> _" [100, 100] 100)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   705
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   706
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   707
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   708
  Having defined them as nominal datatypes gives us additional
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   709
  definitions and theorems that come with types (see below).
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   710
 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   711
  We next define the type of typing contexts, a predicate that
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   712
  defines valid contexts (i.e. lists that contain only unique
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
  variables) and the typing judgement.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   715
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
type_synonym ty_ctx = "(name \<times> ty) list"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   719
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720
inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   721
  valid :: "ty_ctx \<Rightarrow> bool"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   722
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   723
  v1[intro]: "valid []"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   724
| v2[intro]: "\<lbrakk>valid \<Gamma>; atom x \<sharp> \<Gamma>\<rbrakk>\<Longrightarrow> valid ((x, T) # \<Gamma>)"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   725
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   726
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   727
inductive
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   728
  typing :: "ty_ctx \<Rightarrow> lam \<Rightarrow> ty \<Rightarrow> bool" ("_ \<turnstile> _ : _" [60, 60, 60] 60) 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   729
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   730
  t_Var[intro]:  "\<lbrakk>valid \<Gamma>; (x, T) \<in> set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var x : T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   731
| t_App[intro]:  "\<lbrakk>\<Gamma> \<turnstile> t1 : T1 \<rightarrow> T2; \<Gamma> \<turnstile> t2 : T1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App t1 t2 : T2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   732
| t_Lam[intro]:  "\<lbrakk>atom x \<sharp> \<Gamma>; (x, T1) # \<Gamma> \<turnstile> t : T2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].t : T1 \<rightarrow> T2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   733
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   734
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
text {*
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   736
  The predicate atom x \<sharp> \<Gamma>, read as x fresh for \<Gamma>, is defined by 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   737
  Nominal Isabelle. Freshness is defined for lambda-terms, products, 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   738
  lists etc. For example we have:
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   739
  *}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   740
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   741
lemma
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
  fixes x::"name"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   743
  shows "atom x \<sharp> Lam [x].t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   744
  and   "atom x \<sharp> (t1, t2) \<Longrightarrow> atom x \<sharp> App t1 t2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   745
  and   "atom x \<sharp> Var y \<Longrightarrow> atom x \<sharp> y" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   746
  and   "\<lbrakk>atom x \<sharp> t1; atom x \<sharp> t2\<rbrakk> \<Longrightarrow> atom x \<sharp> (t1, t2)"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   747
  and   "\<lbrakk>atom x \<sharp> l1; atom x \<sharp> l2\<rbrakk> \<Longrightarrow> atom x \<sharp> (l1 @ l2)"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   748
  and   "atom x \<sharp> y \<Longrightarrow> x \<noteq> y"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   749
  by (simp_all add: lam.fresh fresh_append fresh_at_base) 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   750
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   751
text {* 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   752
  We can also prove that every variable is fresh for a type. 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   753
*}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   754
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   755
lemma ty_fresh:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   756
  fixes x::"name"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   757
  and   T::"ty"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   758
  shows "atom x \<sharp> T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   759
by (induct T rule: ty.induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   760
   (simp_all add: ty.fresh pure_fresh)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   761
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   762
text {* 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   763
  In order to state the weakening lemma in a convenient form, we 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   764
  using the following abbreviation. Abbreviations behave like 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   765
  definitions, except that they are always automatically folded 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   766
  and unfolded.
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   767
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   768
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   769
abbreviation
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   770
  "sub_ty_ctx" :: "ty_ctx \<Rightarrow> ty_ctx \<Rightarrow> bool" ("_ \<sqsubseteq> _" [60, 60] 60) 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   771
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   772
  "\<Gamma>1 \<sqsubseteq> \<Gamma>2 \<equiv> \<forall>x. x \<in> set \<Gamma>1 \<longrightarrow> x \<in> set \<Gamma>2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   773
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   774
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   775
subsection {* EXERCISE 4 *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   776
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   777
text {*
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   778
  Fill in the details and give a proof of the weakening lemma. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   779
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   780
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   781
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   782
  assumes a: "\<Gamma>1 \<turnstile> t : T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   783
  and     b: "valid \<Gamma>2" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   784
  and     c: "\<Gamma>1 \<sqsubseteq> \<Gamma>2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   785
  shows "\<Gamma>2 \<turnstile> t : T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   786
using a b c
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   787
proof (induct arbitrary: \<Gamma>2)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   788
  case (t_Var \<Gamma>1 x T)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   789
  have a1: "valid \<Gamma>1" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   790
  have a2: "(x, T) \<in> set \<Gamma>1" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   791
  have a3: "valid \<Gamma>2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   792
  have a4: "\<Gamma>1 \<sqsubseteq> \<Gamma>2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   793
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   794
  show "\<Gamma>2 \<turnstile> Var x : T" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   795
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   796
  case (t_Lam x \<Gamma>1 T1 t T2) 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   797
  have ih: "\<And>\<Gamma>3. \<lbrakk>valid \<Gamma>3; (x, T1) # \<Gamma>1 \<sqsubseteq> \<Gamma>3\<rbrakk> \<Longrightarrow> \<Gamma>3 \<turnstile> t : T2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   798
  have a0: "atom x \<sharp> \<Gamma>1" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   799
  have a1: "valid \<Gamma>2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   800
  have a2: "\<Gamma>1 \<sqsubseteq> \<Gamma>2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   801
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   802
  show "\<Gamma>2 \<turnstile> Lam [x].t : T1 \<rightarrow> T2" sorry
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   803
qed (auto) -- {* the application case *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   804
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   805
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   806
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   807
  Despite the frequent claim that the weakening lemma is trivial,
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   808
  routine or obvious, the proof in the lambda-case does not go 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   809
  through smoothly. Painful variable renamings seem to be necessary. 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   810
  But the proof using renamings is horribly complicated (see below). 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   811
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   812
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   813
equivariance valid
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   814
equivariance typing
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   815
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   816
lemma weakening_NOT_TO_BE_TRIED_AT_HOME: 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   817
  assumes a: "\<Gamma>1 \<turnstile> t : T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   818
  and     b: "valid \<Gamma>2" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   819
  and     c: "\<Gamma>1 \<sqsubseteq> \<Gamma>2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   820
  shows "\<Gamma>2 \<turnstile> t : T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   821
using a b c
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   822
proof (induct arbitrary: \<Gamma>2)
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   823
  -- {* lambda case *}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   824
  case (t_Lam x \<Gamma>1 T1 t T2) 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   825
  have fc0: "atom x \<sharp> \<Gamma>1" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   826
  have ih: "\<And>\<Gamma>3. \<lbrakk>valid \<Gamma>3; (x, T1) # \<Gamma>1 \<sqsubseteq> \<Gamma>3\<rbrakk> \<Longrightarrow> \<Gamma>3 \<turnstile> t : T2" by fact
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   827
  -- {* we choose a fresh variable *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   828
  obtain c::"name" where fc1: "atom c \<sharp> (x, t, \<Gamma>1, \<Gamma>2)" by (rule obtain_fresh)
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   829
  -- {* we alpha-rename the abstraction *}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   830
  have "Lam [c].((c \<leftrightarrow> x) \<bullet> t) = Lam [x].t" using fc1
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   831
    by (auto simp add: lam.eq_iff Abs1_eq_iff flip_def)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   832
  moreover
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   833
  -- {* we can then alpha rename the goal *}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   834
  have "\<Gamma>2 \<turnstile> Lam [c].((c \<leftrightarrow> x) \<bullet> t) : T1 \<rightarrow> T2" 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   835
  proof - 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   836
    -- {* we need to establish 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   837
           *   (x, T1) # \<Gamma>1 \<sqsubseteq> (x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2) and 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   838
           **  valid ((x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2)) *}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   839
    have *: "(x, T1) # \<Gamma>1 \<sqsubseteq> (x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2)" 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   840
    proof -
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   841
      have "\<Gamma>1 \<sqsubseteq> \<Gamma>2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   842
      then have "(c \<leftrightarrow> x) \<bullet> ((x, T1) # \<Gamma>1 \<sqsubseteq> (x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2))" using fc0 fc1
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   843
        by (perm_simp) (simp add: flip_fresh_fresh)
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   844
      then show "(x, T1) # \<Gamma>1 \<sqsubseteq> (x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2)" by (rule permute_boolE)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   845
    qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   846
    moreover 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   847
    have **: "valid ((x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2))" 
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   848
    proof -
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   849
      have "valid \<Gamma>2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   850
      then show "valid ((x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2))" using fc1
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   851
        by (auto simp add: fresh_permute_left atom_eqvt valid.eqvt)	
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   852
    qed
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   853
    -- {* these two facts give us by induction hypothesis the following *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   854
    ultimately have "(x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2) \<turnstile> t : T2" using ih by simp 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   855
    -- {* we now apply renamings to get to our goal *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   856
    then have "(c \<leftrightarrow> x) \<bullet> ((x, T1) # ((c \<leftrightarrow> x) \<bullet> \<Gamma>2) \<turnstile> t : T2)" by (rule permute_boolI)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   857
    then have "(c, T1) # \<Gamma>2 \<turnstile> ((c \<leftrightarrow> x) \<bullet> t) : T2" using fc1
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   858
      by (perm_simp) (simp add: flip_fresh_fresh ty_fresh)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   859
    then show "\<Gamma>2 \<turnstile> Lam [c].((c \<leftrightarrow> x) \<bullet> t) : T1 \<rightarrow> T2" using fc1 by auto
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   860
  qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   861
  ultimately show "\<Gamma>2 \<turnstile> Lam [x].t : T1 \<rightarrow> T2" by simp
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   862
qed (auto) -- {* var and app cases, luckily, are automatic *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   863
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   864
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   865
text {* 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   866
  The remedy is to use a stronger induction principle that
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   867
  has the usual "variable convention" already build in. The
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   868
  following command derives this induction principle for us.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   869
  (We shall explain what happens here later.)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   870
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   871
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   872
nominal_inductive typing
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   873
  avoids t_Lam: "x"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   874
  unfolding fresh_star_def
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   875
  by (simp_all add: fresh_Pair lam.fresh ty_fresh)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   876
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   877
text {* Compare the two induction principles *}
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   878
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   879
thm typing.induct
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   880
thm typing.strong_induct -- {* has the additional assumption {atom x} \<sharp> c *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   881
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   882
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   883
  We can use the stronger induction principle by replacing
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   884
  the line
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   885
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   886
      proof (induct arbitrary: \<Gamma>2)
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   887
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   888
  with 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   889
  
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   890
      proof (nominal_induct avoiding: \<Gamma>2 rule: typing.strong_induct)
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   891
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   892
  Try now the proof.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   893
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   894
  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   895
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   896
lemma weakening: 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   897
  assumes a: "\<Gamma>1 \<turnstile> t : T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   898
  and     b: "valid \<Gamma>2" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   899
  and     c: "\<Gamma>1 \<sqsubseteq> \<Gamma>2"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   900
  shows "\<Gamma>2 \<turnstile> t : T"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   901
using a b c
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   902
proof (nominal_induct avoiding: \<Gamma>2 rule: typing.strong_induct)
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   903
  case (t_Var \<Gamma>1 x T)  -- {* variable case is as before *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   904
  have "\<Gamma>1 \<sqsubseteq> \<Gamma>2" by fact 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   905
  moreover  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   906
  have "valid \<Gamma>2" by fact 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   907
  moreover 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   908
  have "(x, T)\<in> set \<Gamma>1" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   909
  ultimately show "\<Gamma>2 \<turnstile> Var x : T" by auto
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   910
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   911
  case (t_Lam x \<Gamma>1 T1 t T2) 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   912
  have vc: "atom x \<sharp> \<Gamma>2" by fact  -- {* additional fact afforded by the stron induction *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   913
  have ih: "\<And>\<Gamma>3. \<lbrakk>valid \<Gamma>3; (x, T1) # \<Gamma>1 \<sqsubseteq> \<Gamma>3\<rbrakk> \<Longrightarrow> \<Gamma>3 \<turnstile> t : T2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   914
  have a0: "atom x \<sharp> \<Gamma>1" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   915
  have a1: "valid \<Gamma>2" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   916
  have a2: "\<Gamma>1 \<sqsubseteq> \<Gamma>2" by fact
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   917
  have "valid ((x, T1) # \<Gamma>2)" using a1 vc by auto
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   918
  moreover
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   919
  have "(x, T1) # \<Gamma>1 \<sqsubseteq> (x, T1) # \<Gamma>2" using a2 by auto
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   920
  ultimately 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   921
  have "(x, T1) # \<Gamma>2 \<turnstile> t : T2" using ih by simp 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   922
  then show "\<Gamma>2 \<turnstile> Lam [x].t : T1 \<rightarrow> T2" using vc by auto
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   923
qed (auto) -- {* app case *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   924
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   925
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   926
section {* Function Definitions: Filling a Lambda-Term into a Context *}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   927
 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   928
text {*
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   929
  Many functions over datatypes can be defined by recursion on the
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   930
  structure. For this purpose, Isabelle provides "fun". To use it one needs 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   931
  to give a name for the function, its type, optionally some pretty-syntax 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   932
  and then some equations defining the function. Like in "inductive",
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   933
  "fun" expects that more than one such equation is separated by "|".
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   934
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   935
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   936
fun
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   937
  filling :: "ctx \<Rightarrow> lam \<Rightarrow> lam" ("_\<lbrakk>_\<rbrakk>" [100, 100] 100)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   938
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   939
  "\<box>\<lbrakk>t\<rbrakk> = t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   940
| "(CAppL E t')\<lbrakk>t\<rbrakk> = App (E\<lbrakk>t\<rbrakk>) t'"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   941
| "(CAppR t' E)\<lbrakk>t\<rbrakk> = App t' (E\<lbrakk>t\<rbrakk>)"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   942
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   943
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   944
  After this definition Isabelle will be able to simplify
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   945
  statements like: 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   946
*}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   947
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   948
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   949
  shows "(CAppL \<box> (Var x))\<lbrakk>Var y\<rbrakk> = App (Var y) (Var x)"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   950
  by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   951
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   952
fun 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   953
 ctx_compose :: "ctx \<Rightarrow> ctx \<Rightarrow> ctx" ("_ \<odot> _" [99,98] 99)
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   954
where
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   955
  "\<box> \<odot> E' = E'"
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   956
| "(CAppL E t') \<odot> E' = CAppL (E \<odot> E') t'"
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   957
| "(CAppR t' E) \<odot> E' = CAppR t' (E \<odot> E')"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   958
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   959
fun
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   960
  ctx_composes :: "ctxs \<Rightarrow> ctx" ("_\<down>" [110] 110)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   961
where
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   962
    "[]\<down> = \<box>"
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   963
  | "(E # Es)\<down> = (Es\<down>) \<odot> E"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   964
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   965
text {*  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   966
  Notice that we not just have given a pretty syntax for the functions, but
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   967
  also some precedences. The numbers inside the [\<dots>] stand for the precedences
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   968
  of the arguments; the one next to it the precedence of the whole term.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   969
  
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   970
  This means we have to write (Es1 \<odot> Es2) \<odot> Es3 otherwise Es1 \<odot> Es2 \<odot> Es3 is
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   971
  interpreted as Es1 \<odot> (Es2 \<odot> Es3).
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   972
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   973
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   974
section {* Structural Inductions over Contexts *}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   975
 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   976
text {*
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   977
  So far we have had a look at an induction over an inductive predicate. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   978
  Another important induction principle is structural inductions for 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   979
  datatypes. To illustrate structural inductions we prove some facts
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   980
  about context composition, some of which we will need later on.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   981
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   982
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   983
subsection {* EXERCISE 5 *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   984
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   985
text {* Complete the proof and remove the sorries. *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   986
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   987
lemma ctx_compose:
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   988
  shows "(E1 \<odot> E2)\<lbrakk>t\<rbrakk> = E1\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   989
proof (induct E1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   990
  case Hole
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   991
  show "(\<box> \<odot> E2)\<lbrakk>t\<rbrakk> = \<box>\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" sorry
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   992
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   993
  case (CAppL E1 t')
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   994
  have ih: "(E1 \<odot> E2)\<lbrakk>t\<rbrakk> = E1\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" by fact
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   995
  show "((CAppL E1 t') \<odot> E2)\<lbrakk>t\<rbrakk> = (CAppL E1 t')\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" sorry
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   996
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   997
  case (CAppR t' E1)
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   998
  have ih: "(E1 \<odot> E2)\<lbrakk>t\<rbrakk> = E1\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" by fact
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   999
  show "((CAppR t' E1) \<odot> E2)\<lbrakk>t\<rbrakk> = (CAppR t' E1)\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" sorry
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1000
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1001
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1002
lemma neut_hole:
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1003
  shows "E \<odot> \<box> = E"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1004
by (induct E) (simp_all)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1005
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1006
lemma odot_assoc:
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1007
  fixes E1 E2 E3::"ctx"
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1008
  shows "(E1 \<odot> E2) \<odot> E3 = E1 \<odot> (E2 \<odot> E3)"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1009
by (induct E1) (simp_all)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1010
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1011
lemma
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1012
  shows "(Es1 @ Es2)\<down> = (Es2\<down>) \<odot> (Es1\<down>)"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1013
proof (induct Es1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1014
  case Nil
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1015
  show "([] @ Es2)\<down> = Es2\<down> \<odot> []\<down>" sorry
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1016
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1017
  case (Cons E Es1)
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1018
  have ih: "(Es1 @ Es2)\<down> = Es2\<down> \<odot> Es1\<down>" by fact
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1019
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1020
  show "((E # Es1) @ Es2)\<down> = Es2\<down> \<odot> (E # Es1)\<down>" sorry
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1021
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1022
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1023
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1024
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1025
  The last proof involves several steps of equational reasoning.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1026
  Isar provides some convenient means to express such equational 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1027
  reasoning in a much cleaner fashion using the "also have" 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1028
  construction. 
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1029
*}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1030
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1031
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1032
lemma 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1033
  shows "(Es1 @ Es2)\<down> = (Es2\<down>) \<odot> (Es1\<down>)"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1034
proof (induct Es1)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1035
  case Nil
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1036
  show "([] @ Es2)\<down> = Es2\<down> \<odot> []\<down>" using neut_hole by simp
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1037
next
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1038
  case (Cons E Es1)
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1039
  have ih: "(Es1 @ Es2)\<down> = Es2\<down> \<odot> Es1\<down>" by fact
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1040
  have "((E # Es1) @ Es2)\<down> = (Es1 @ Es2)\<down> \<odot> E" by simp
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1041
  also have "\<dots> = (Es2\<down> \<odot> Es1\<down>) \<odot> E" using ih by simp
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1042
  also have "\<dots> = Es2\<down> \<odot> (Es1\<down> \<odot> E)" using odot_assoc by simp
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1043
  also have "\<dots> = Es2\<down> \<odot> (E # Es1)\<down>" by simp
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1044
  finally show "((E # Es1) @ Es2)\<down> = Es2\<down> \<odot> (E # Es1)\<down>" by simp
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1045
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1046
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1047
text {******************************************************************
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1048
  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1049
  Formalising Barendregt's Proof of the Substitution Lemma
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1050
  --------------------------------------------------------
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1051
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1052
  Barendregt's proof needs in the variable case a case distinction.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1053
  One way to do this in Isar is to use blocks. A block is some sequent
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1054
  or reasoning steps enclosed in curly braces
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1055
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1056
  { \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1057
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1058
    have "statement"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1059
  }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1060
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1061
  Such a block can contain local assumptions like
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1062
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1063
  { assume "A"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1064
    assume "B"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1065
    \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1066
    have "C" by \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1067
  }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1068
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1069
  Where "C" is the last have-statement in this block. The behaviour 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1070
  of such a block to the 'outside' is the implication
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1071
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1072
   \<lbrakk>A; B\<rbrakk> \<Longrightarrow> "C" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1073
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1074
  Now if we want to prove a property "smth" using the case-distinctions
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1075
  P1, P2 and P3 then we can use the following reasoning:
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1076
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1077
    { assume "P1"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1078
      \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1079
      have "smth"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1080
    }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1081
    moreover
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1082
    { assume "P2"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1083
      \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1084
      have "smth"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1085
    }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1086
    moreover
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1087
    { assume "P3"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1088
      \<dots>
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1089
      have "smth"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1090
    }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1091
    ultimately have "smth" by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1092
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1093
  The blocks establish the implications
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1094
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1095
    P1 \<Longrightarrow> smth
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1096
    P2 \<Longrightarrow> smth
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1097
    P3 \<Longrightarrow> smth
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1098
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1099
  If we know that P1, P2 and P3 cover all the cases, that is P1 \<or> P2 \<or> P3 is
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1100
  true, then we have 'ultimately' established the property "smth" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1101
  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1102
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1103
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1104
section {* EXERCISE 7 *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1105
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1106
text {*
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1107
  Fill in the cases 1.2 and 1.3 and the equational reasoning 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1108
  in the lambda-case.
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1109
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1110
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1111
lemma forget:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1112
  shows "atom x \<sharp> t \<Longrightarrow> t[x ::= s] = t"
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1113
by (nominal_induct t avoiding: x s rule: lam.strong_induct)
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1114
   (auto simp add: lam.fresh fresh_at_base)
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1115
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1116
lemma fresh_fact:
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1117
  fixes z::"name"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1118
  assumes a: "atom z \<sharp> s"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1119
  and b: "z = y \<or> atom z \<sharp> t"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1120
  shows "atom z \<sharp> t[y ::= s]"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1121
using a b
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1122
by (nominal_induct t avoiding: z y s rule: lam.strong_induct)
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1123
   (auto simp add: lam.fresh fresh_at_base)
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1124
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1125
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1126
lemma 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1127
  assumes a: "x \<noteq> y"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1128
  and     b: "atom x \<sharp> L"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1129
  shows "M[x::=N][y::=L] = M[y::=L][x::=N[y::=L]]"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1130
using a b
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1131
proof (nominal_induct M avoiding: x y N L rule: lam.strong_induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1132
  case (Var z)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1133
  have a1: "x \<noteq> y" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1134
  have a2: "atom x \<sharp> L" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1135
  show "Var z[x::=N][y::=L] = Var z[y::=L][x::=N[y::=L]]" (is "?LHS = ?RHS")
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1136
  proof -
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1137
    { -- {* Case 1.1 *}
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1138
      assume c1: "z = x"
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1139
      have "(1)": "?LHS = N[y::=L]" using c1 by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1140
      have "(2)": "?RHS = N[y::=L]" using c1 a1 by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1141
      have "?LHS = ?RHS" using "(1)" "(2)" by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1142
    }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1143
    moreover 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1144
    { -- {* Case 1.2 *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1145
      assume c2: "z = y" "z \<noteq> x" 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1146
      
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1147
      have "?LHS = ?RHS" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1148
    }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1149
    moreover 
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1150
    { -- {* Case 1.3 *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1151
      assume c3: "z \<noteq> x" "z \<noteq> y"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1152
      
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1153
      have "?LHS = ?RHS" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1154
    }
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1155
    ultimately show "?LHS = ?RHS" by blast
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1156
  qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1157
next
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1158
  case (Lam z M1) -- {* case 2: lambdas *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1159
  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
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1160
  have a1: "x \<noteq> y" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1161
  have a2: "atom x \<sharp> L" by fact
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1162
  have fs: "atom z \<sharp> x" "atom z \<sharp> y" "atom z \<sharp> N" "atom z \<sharp> L" by fact+
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1163
  then have b: "atom z \<sharp> N[y::=L]" by (simp add: fresh_fact)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1164
  show "(Lam [z].M1)[x::=N][y::=L] = (Lam [z].M1)[y::=L][x::=N[y::=L]]" (is "?LHS=?RHS") 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1165
  proof - 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1166
    have "?LHS = \<dots>" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1167
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1168
    also have "\<dots> = ?RHS" sorry
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1169
    finally show "?LHS = ?RHS" by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1170
  qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1171
next
2688
87b735f86060 a bit tuning
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
  1172
  case (App M1 M2) -- {* case 3: applications *}
2686
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1173
  then show "(App M1 M2)[x::=N][y::=L] = (App M1 M2)[y::=L][x::=N[y::=L]]" by simp
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1174
qed
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1175
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1176
text {* 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1177
  Again the strong induction principle enables Isabelle to find
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1178
  the proof of the substitution lemma automatically. 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1179
*}
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1180
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1181
lemma substitution_lemma_version:  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1182
  assumes asm: "x \<noteq> y" "atom x \<sharp> L"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1183
  shows "M[x::=N][y::=L] = M[y::=L][x::=N[y::=L]]"
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1184
  using asm 
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1185
by (nominal_induct M avoiding: x y N L rule: lam.strong_induct)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1186
   (auto simp add: fresh_fact forget)
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1187
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1188
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1189
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1190
end  
52e1e98edb34 added a very rough version of the tutorial; all seems to work
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1191