Tutorial/Tutorial1s.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 07 Jul 2014 10:21:40 +0100
changeset 3237 8ee8f72778ce
parent 3132 87eca760dcba
child 3245 017e33849f4d
permissions -rw-r--r--
changed add.assoc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2694
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
header {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
  Nominal Isabelle Tutorial at POPL'11
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
  ====================================
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  Nominal Isabelle is a definitional extension of Isabelle/HOL, which
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  means it does not add any new axioms to higher-order logic. It just
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  adds new definitions and an infrastructure for 'nominal resoning'.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  The jEdit Interface
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  -------------------
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  The Isabelle theorem prover comes with an interface for jEdit. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  Unlike many other theorem prover interfaces (e.g. ProofGeneral) where you 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  advance a 'checked' region in a proof script, this interface immediately 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  checks the whole buffer. The text you type is also immediately checked. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  Malformed text or unfinished proofs are highlighted in red with a little 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  red 'stop' signal on the left-hand side. If you drag the 'red-box' cursor 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  over a line, the Output window gives further feedback. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
3485111c7d62 cleaned up tutorial1...added solution file
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 
3485111c7d62 cleaned up tutorial1...added solution file
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;
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  Cmd is Ctrl on the Mac)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  Nominal Isabelle and jEdit can be started by typing on the command line
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
     isabelle jedit -l HOL-Nominal2
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
     isabelle jedit -l HOL-Nominal2 A.thy B.thy ...
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  Symbols
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  ------- 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  Symbols can considerably improve the readability of your statements and proofs. 
3485111c7d62 cleaned up tutorial1...added solution file
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 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  usual latex name of that symbol. A little window will then appear in which 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  you can select the symbol. With `Escape' you can ignore any suggestion.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  There are some handy short-cuts for frequently used symbols. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  For example 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
      short-cut  symbol
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
          =>      \<Rightarrow>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
          ==>     \<Longrightarrow>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
          -->     \<longrightarrow>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
          !       \<forall>        
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
          ?       \<exists>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
          /\      \<and>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
          \/      \<or>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
          ~       \<not>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
          ~=      \<noteq>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
          :       \<in>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
          ~:      \<notin>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  For nominal the following two symbols have a special meaning
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
        \<sharp>    sharp     (freshness)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
        \<bullet>    bullet    (permutation application)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
theory Tutorial1s
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
imports Lambda
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
begin
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
section {* Theories *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  All formal developments in Isabelle are part of a theory. A theory 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  needs to have a name and must import some pre-existing theory. The 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  imported theory will normally be Nominal2 (which provides many useful 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  concepts like set-theory, lists, nominal things etc). For the purpose 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  of this tutorial we import the theory Lambda.thy, which contains 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  already some useful definitions for (alpha-equated) lambda terms.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
section {* Types *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  Isabelle is based on simple types including some polymorphism. It also 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  includes overloading, which means that sometimes explicit type annotations 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  need to be given.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
    - Base types include: nat, bool, string, lam (defined in the Lambda theory)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
    - Type formers include: 'a list, ('a \<times> 'b), 'c set   
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    - Type variables are written like in ML with an apostrophe: 'a, 'b, \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  Types known to Isabelle can be queried using the command "typ".
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
typ nat
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
typ bool
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
typ string           
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
typ lam           -- {* alpha-equated lambda terms defined in Lambda.thy *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
typ name          -- {* type of (object) variables defined in Lambda.thy *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
typ "('a \<times> 'b)"   -- {* pair type *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
typ "'c set"      -- {* set type *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
typ "'a list"     -- {* list type *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
typ "lam \<Rightarrow> nat"   -- {* type of functions from lambda terms to natural numbers *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
text {* Some malformed types - note the "stop" signal on the left margin *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
(*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
typ boolean     -- {* undeclared type *} 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
typ set         -- {* type argument missing *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
*)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
section {* Terms *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
   Every term in Isabelle needs to be well-typed. However they can have 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
   polymorphic type. Whether a term is accepted can be queried using
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
   the command "term". 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
term c                 -- {* a variable of polymorphic type *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
term "1::nat"          -- {* the constant 1 in natural numbers *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
term 1                 -- {* the constant 1 with polymorphic type *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
term "{1, 2, 3::nat}"  -- {* the set containing natural numbers 1, 2 and 3 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
term "[1, 2, 3]"       -- {* the list containing the polymorphic numbers 1, 2 and 3 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
term "(True, ''c'')"   -- {* a pair consisting of the boolean true and the string "c" *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
term "Suc 0"           -- {* successor of 0, in other words 1::nat *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
term "Lam [x].Var x"   -- {* a lambda-term *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
term "App t1 t2"       -- {* another lambda-term *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
term "x::name"         -- {* an (object) variable of type name *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
term "atom (x::name)"  -- {* atom is an overloded function *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  Lam [x].Var is the syntax we made up for lambda abstractions. If you
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  prefer, you can have your own syntax (but \<lambda> is already taken up for 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  Isabelle's functions). We also came up with the type "name" for variables. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  You can introduce your own types of object variables using the 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  command atom_decl: 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
atom_decl ident
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
atom_decl ty_var
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  Isabelle provides some useful colour feedback about its constants (black), 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  free variables (blue) and bound variables (green).
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
term "True"    -- {* a constant defined somewhere...written in black *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
term "true"    -- {* not recognised as a constant, therefore it is interpreted
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
                     as a free variable, written in blue *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
term "\<forall>x. P x" -- {* x is bound (green), P is free (blue) *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
text {* Formulae in Isabelle/HOL are terms of type bool *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
term "True"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
term "True \<and> False"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
term "True \<or> B"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
term "{1,2,3} = {3,2,1}"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
term "\<forall>x. P x"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
term "A \<longrightarrow> B"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
term "atom a \<sharp> t"   -- {* freshness in Nominal *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  When working with Isabelle, one deals with an object logic (that is HOL) and 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
  Isabelle's rule framework (called Pure). Occasionally one has to pay attention 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
  to this fact. But for the moment we ignore this completely.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
term "A \<longrightarrow> B"  -- {* versus *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
term "A \<Longrightarrow> B"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
term "\<forall>x. P x"  -- {* versus *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
term "\<And>x. P x"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
section {* Inductive Definitions: Evaluation Relation *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  In this section we want to define inductively the evaluation
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  relation and for cbv-reduction relation.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  Inductive definitions in Isabelle start with the keyword "inductive" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  and a predicate name.  One can optionally provide a type for the predicate. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  Clauses of the inductive predicate are introduced by "where" and more than 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
  two clauses need to be separated by "|". One can also give a name to each 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
  clause and indicate that it should be added to the hints database ("[intro]"). 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
  A typical clause has some premises and a conclusion. This is written in 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  Isabelle as:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
   "premise \<Longrightarrow> conclusion"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
   "premise1 \<Longrightarrow> premise2 \<Longrightarrow> \<dots> premisen \<Longrightarrow> conclusion"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  There is an alternative way of writing the latter clause as
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
   "\<lbrakk>premise1; premise2; \<dots> premisen\<rbrakk> \<Longrightarrow> conclusion"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  If no premise is present, then one just writes
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
   "conclusion"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
  Below we give two definitions for the transitive closure
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
inductive
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  eval :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<Down> _" [60, 60] 60) 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
where
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  e_Lam[intro]:  "Lam [x].t \<Down> Lam [x].t"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
| e_App[intro]:  "\<lbrakk>t1 \<Down> Lam [x].t; t2 \<Down> v'; t[x::=v'] \<Down> v\<rbrakk> \<Longrightarrow> App t1 t2 \<Down> v"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  Values and cbv are also defined using inductive.  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
inductive
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  val :: "lam \<Rightarrow> bool" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
where
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
  v_Lam[intro]:   "val (Lam [x].t)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
section {* Theorems *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  A central concept in Isabelle is that of theorems. Isabelle's theorem
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
  database can be queried using 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
thm e_App
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
thm e_Lam
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
thm conjI
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
thm conjunct1
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  Notice that theorems usually contain schematic variables (e.g. ?P, ?Q, \<dots>). 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
  These schematic variables can be substituted with any term (of the right type 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
  of course). 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
  When defining the predicates beta_star, Isabelle provides us automatically 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
  with the following theorems that state how they can be introduced and what 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  constitutes an induction over them. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
thm eval.intros
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
thm eval.induct
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
section {* Lemmas / Theorems / Corollaries *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
  Whether to use lemma, theorem or corollary makes no semantic difference 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  in Isabelle. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  A lemma starts with "lemma" and consists of a statement ("shows \<dots>") and 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  optionally a lemma name, some type-information for variables ("fixes \<dots>") 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
  and some assumptions ("assumes \<dots>"). 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
  Lemmas also need to have a proof, but ignore this 'detail' for the moment.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
  Examples are
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
lemma alpha_equ:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
  shows "Lam [x].Var x = Lam [y].Var y"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
  by (simp add: lam.eq_iff Abs1_eq_iff lam.fresh fresh_at_base)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
lemma Lam_freshness:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
  assumes a: "atom y \<sharp> Lam [x].t"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
  shows "(y = x) \<or> (y \<noteq> x \<and> atom y \<sharp> t)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
  using a by (auto simp add: lam.fresh Abs_fresh_iff) 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
lemma neutral_element:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
  fixes x::"nat"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
  shows "x + 0 = x"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
  by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  Note that in the last statement, the explicit type annotation is important 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
  in order for Isabelle to be able to figure out what 0 stands for (e.g. a 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
  natural number, a vector, etc) and which lemmas to apply.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
section {* Isar Proofs *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
  Isar is a language for writing formal proofs that can be understood by humans 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
  and by Isabelle. An Isar proof can be thought of as a sequence of 'stepping stones' 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
  that start with some assumptions and lead to the goal to be established. Every such 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
  stepping stone is introduced by "have" followed by the statement of the stepping 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
  stone. An exception is the goal to be proved, which need to be introduced with "show".
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
      have "statement"  \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
      show "goal_to_be_proved" \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
  Since proofs usually do not proceed in a linear fashion, labels can be given 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
  to every stepping stone and they can be used later to explicitly refer to this 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
  corresponding stepping stone ("using").
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
      have label: "statement1"  \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
      \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
      have "later_statement" using label \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
  Each stepping stone (or have-statement) needs to have a justification. The 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
  simplest justification is "sorry" which admits any stepping stone, even false 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
  ones (this is good during the development of proofs). 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
      have "outrageous_false_statement" sorry
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
  Assumptions can be 'justified' using "by fact". 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
      have "assumption" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
  Derived facts can be justified using 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
      have "statement" by simp    -- simplification 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
      have "statement" by auto    -- proof search and simplification 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
      have "statement" by blast   -- only proof search 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
  If facts or lemmas are needed in order to justify a have-statement, then
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
  one can feed these facts into the proof by using "using label \<dots>" or 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
  "using theorem-name \<dots>". More than one label at a time is allowed. For
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
  example
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
      have "statement" using label1 label2 theorem_name by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
  Induction proofs in Isar are set up by indicating over which predicate(s) 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
  the induction proceeds ("using a b") followed by the command "proof (induct)". 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
  In this way, Isabelle uses defaults for which induction should be performed. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
  These defaults can be overridden by giving more information, like the variable 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
  over which a structural induction should proceed, or a specific induction principle, 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
  such as well-founded inductions. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
  After the induction is set up, the proof proceeds by cases. In Isar these 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
  cases can be given in any order. Most commonly they are started with "case" and the 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
  name of the case, and optionally some legible names for the variables used inside 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
  the case. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
  In each "case", we need to establish a statement introduced by "show". Once 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
  this has been done, the next case can be started using "next". When all cases 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
  are completed, the proof can be finished using "qed".
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
  This means a typical induction proof has the following pattern
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
     proof (induct)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
       case \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
       \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
       show \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
     next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
       case \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
       \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
       show \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
     \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
     qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
   Two very simple example proofs are as follows.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
subsection {* EXERCISE 1 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
lemma eval_val:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
  assumes a: "val t"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
  shows "t \<Down> t"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
using a
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
proof (induct)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
  case (v_Lam x t)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
  show "Lam [x]. t \<Down> Lam [x]. t" by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
subsection {* EXERCISE 2 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
text {* Fill the gaps in the proof below. *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
lemma eval_to_val:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
  assumes a: "t \<Down> t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
  shows "val t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
using a
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
proof (induct)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
  case (e_Lam x t)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
  show "val (Lam [x].t)" by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
  case (e_App t1 x t t2 v v')
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
  -- {* all assumptions in this case *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
  have "t1 \<Down> Lam [x].t" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
  have ih1: "val (Lam [x]. t)" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
  have "t2 \<Down> v" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
  have ih2: "val v" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
  have "t [x ::= v] \<Down> v'" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
  have ih3: "val v'" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
  show "val v'" using ih3 by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
section {* Datatypes: Evaluation Contexts*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
  Datatypes can be defined in Isabelle as follows: we have to provide the name 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
  of the datatype and a list its type-constructors. Each type-constructor needs 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
  to have the information about the types of its arguments, and optionally 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
  can also contain some information about pretty syntax. For example, we like
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
  to write "\<box>" for holes.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
datatype ctx = 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
    Hole ("\<box>")  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
  | CAppL "ctx" "lam"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
  | CAppR "lam" "ctx"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
text {* Now Isabelle knows about: *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
typ ctx
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
term "\<box>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
term "CAppL"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
term "CAppL \<box> (Var x)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
subsection {* MINI EXERCISE *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
  Try and see what happens if you apply a Hole to a Hole? 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
section {* Machines for Evaluation *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
type_synonym ctxs = "ctx list"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
inductive
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
  machine :: "lam \<Rightarrow> ctxs \<Rightarrow>lam \<Rightarrow> ctxs \<Rightarrow> bool" ("<_,_> \<mapsto> <_,_>" [60, 60, 60, 60] 60)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
where
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
  m1: "<App t1 t2, Es> \<mapsto> <t1, (CAppL \<box> t2) # Es>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
| m2: "val v \<Longrightarrow> <v, (CAppL \<box> t2) # Es> \<mapsto> <t2, (CAppR v \<box>) # Es>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
| m3: "val v \<Longrightarrow> <v, (CAppR (Lam [x].t) \<box>) # Es> \<mapsto> <t[x ::= v], Es>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
  Since the machine defined above only performs a single reduction,
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
  we need to define the transitive closure of this machine. *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
inductive 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
  machines :: "lam \<Rightarrow> ctxs \<Rightarrow> lam \<Rightarrow> ctxs \<Rightarrow> bool" ("<_,_> \<mapsto>* <_,_>" [60, 60, 60, 60] 60)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
where
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
  ms1: "<t,Es> \<mapsto>* <t,Es>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
| ms2: "\<lbrakk><t1,Es1> \<mapsto> <t2,Es2>; <t2,Es2> \<mapsto>* <t3,Es3>\<rbrakk> \<Longrightarrow> <t1,Es1> \<mapsto>* <t3,Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
declare machine.intros[intro] machines.intros[intro]
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
section {* EXERCISE 3 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
  We need to show that the machines-relation is transitive.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
  Fill in the gaps below.   
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
lemma ms3[intro]:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
using a b
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
proof(induct)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
  case (ms1 e1 Es1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
  have c: "<e1, Es1> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
  then show "<e1, Es1> \<mapsto>* <e3, Es3>" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
  case (ms2 e1 Es1 e2 Es2 e2' Es2') 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
  have ih: "<e2', Es2'> \<mapsto>* <e3, Es3> \<Longrightarrow> <e2, Es2> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
  have d1: "<e2', Es2'> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
  have d2: "<e1, Es1> \<mapsto> <e2, Es2>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
  have d3: "<e2, Es2> \<mapsto>* <e3, Es3>" using ih d1 by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
  show "<e1, Es1> \<mapsto>* <e3, Es3>" using d2 d3 by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
  Just like gotos in the Basic programming language, labels often reduce 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
  the readability of proofs. Therefore one can use in Isar the notation
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
  "then have" in order to feed a have-statement to the proof of 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
  the next have-statement. This is used in teh second case below.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
lemma 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
using a b
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
proof(induct)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
  case (ms1 e1 Es1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
  show "<e1, Es1> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
  case (ms2 e1 Es1 e2 Es2 e2' Es2')
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
  have ih: "<e2', Es2'> \<mapsto>* <e3, Es3> \<Longrightarrow> <e2, Es2> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
  have "<e2', Es2'> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
  then have d3: "<e2, Es2> \<mapsto>* <e3, Es3>" using ih by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
  have d2: "<e1, Es1> \<mapsto> <e2, Es2>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
  show "<e1, Es1> \<mapsto>* <e3, Es3>" using d2 d3 by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
  The label ih2 cannot be got rid of in this way, because it is used 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
  two lines below and we cannot rearange them. We can still avoid the
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
  label by feeding a sequence of facts into a proof using the 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
  "moreover"-chaining mechanism:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
   have "statement_1" \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
   moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
   have "statement_2" \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
   \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
   moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
   have "statement_n" \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
   ultimately have "statement" \<dots>
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
  In this chain, all "statement_i" can be used in the proof of the final 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
  "statement". With this we can simplify our proof further to:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
lemma 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
using a b
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
proof(induct)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
  case (ms1 e1 Es1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
  show "<e1, Es1> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
  case (ms2 e1 Es1 e2 Es2 e2' Es2')
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
  have ih: "<e2', Es2'> \<mapsto>* <e3, Es3> \<Longrightarrow> <e2, Es2> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
  have "<e2', Es2'> \<mapsto>* <e3, Es3>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
  then have "<e2, Es2> \<mapsto>* <e3, Es3>" using ih by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
  moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
  have "<e1, Es1> \<mapsto> <e2, Es2>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
  ultimately show "<e1, Es1> \<mapsto>* <e3, Es3>" by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   534
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   536
  While automatic proof procedures in Isabelle are not able to prove statements
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   537
  like "P = NP" assuming usual definitions for P and NP, they can automatically
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   538
  discharge the lemmas we just proved. For this we only have to set up the induction
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   539
  and auto will take care of the rest. This means we can write:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
lemma 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
  assumes a: "val t"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
  shows "t \<Down> t"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
using a by (induct) (auto)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
lemma 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
  assumes a: "t \<Down> t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
  shows "val t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
using a by (induct) (auto)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   551
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   552
lemma
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   553
  assumes a: "<e1, Es1> \<mapsto>* <e2, Es2>" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
  and     b: "<e2, Es2> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
  shows "<e1, Es1> \<mapsto>* <e3, Es3>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
using a b by (induct) (auto)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
section {* EXERCISE 4 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   560
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   562
  The point of the machine is that it simulates the evaluation
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
  relation. Therefore we like to prove the following:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   566
theorem 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   567
  assumes a: "t \<Down> t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
  shows "<t, Es> \<mapsto>* <t', Es>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   569
using a 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   570
proof (induct arbitrary: Es)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
  case (e_Lam x t Es) 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
  -- {* no assumptions *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
  show "<Lam [x].t, Es> \<mapsto>* <Lam [x].t, Es>" by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
  case (e_App t1 x t t2 v' v Es) 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
  -- {* all assumptions in this case *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
  have a1: "t1 \<Down> Lam [x].t" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   578
  have ih1: "\<And>Es. <t1, Es> \<mapsto>* <Lam [x].t, Es>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
  have a2: "t2 \<Down> v'" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
  have ih2: "\<And>Es. <t2, Es> \<mapsto>* <v', Es>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
  have a3: "t[x::=v'] \<Down> v" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
  have ih3: "\<And>Es. <t[x::=v'], Es> \<mapsto>* <v, Es>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
  -- {* your reasoning *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   584
  have "<App t1 t2, Es> \<mapsto>* <t1, CAppL \<box> t2 # Es>" by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   585
  moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
  have "<t1, CAppL \<box> t2 # Es> \<mapsto>* <Lam [x].t, CAppL \<box> t2 # Es>" using ih1 by auto 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   587
  moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   588
  have "<Lam [x].t, CAppL \<box> t2 # Es> \<mapsto>* <t2, CAppR (Lam [x].t) \<box> # Es>" by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   589
  moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   590
  have "<t2, CAppR (Lam [x].t) \<box> # Es> \<mapsto>* <v', CAppR (Lam [x].t) \<box> # Es>" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
  using ih2 by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   592
  moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   593
  have "val v'" using a2 eval_to_val by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   594
  then have "<v', CAppR (Lam [x].t) \<box> # Es> \<mapsto>* <t[x::=v'], Es>" by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
  moreover
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   596
  have "<t[x::=v'], Es> \<mapsto>* <v, Es>" using ih3 by auto
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
  ultimately show "<App t1 t2, Es> \<mapsto>* <v, Es>" by blast
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   598
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   601
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
  Again the automatic tools in Isabelle can discharge automatically 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
  of the routine work in these proofs. We can write: 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
theorem eval_implies_machines_ctx:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607
  assumes a: "t \<Down> t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
  shows "<t, Es> \<mapsto>* <t', Es>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   609
using a
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   610
by (induct arbitrary: Es)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   611
   (metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   613
corollary eval_implies_machines:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   614
  assumes a: "t \<Down> t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
  shows "<t, []> \<mapsto>* <t', []>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
using a eval_implies_machines_ctx by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
section {* Function Definitions: Filling a Lambda-Term into a Context *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
  Many functions over datatypes can be defined by recursion on the
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
  structure. For this purpose, Isabelle provides "fun". To use it one needs 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
  to give a name for the function, its type, optionally some pretty-syntax 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
  and then some equations defining the function. Like in "inductive",
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
  "fun" expects that more than one such equation is separated by "|".
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
fun
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   630
  filling :: "ctx \<Rightarrow> lam \<Rightarrow> lam" ("_\<lbrakk>_\<rbrakk>" [100, 100] 100)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
where
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
  "\<box>\<lbrakk>t\<rbrakk> = t"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
| "(CAppL E t')\<lbrakk>t\<rbrakk> = App (E\<lbrakk>t\<rbrakk>) t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
| "(CAppR t' E)\<lbrakk>t\<rbrakk> = App t' (E\<lbrakk>t\<rbrakk>)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   638
  After this definition Isabelle will be able to simplify
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
  statements like: 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
lemma 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
  shows "(CAppL \<box> (Var x))\<lbrakk>Var y\<rbrakk> = App (Var y) (Var x)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
  by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
fun 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
 ctx_compose :: "ctx \<Rightarrow> ctx \<Rightarrow> ctx" (infixr "\<odot>" 99)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
where
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
  "\<box> \<odot> E' = E'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
| "(CAppL E t') \<odot> E' = CAppL (E \<odot> E') t'"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
| "(CAppR t' E) \<odot> E' = CAppR t' (E \<odot> E')"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
fun
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
  ctx_composes :: "ctxs \<Rightarrow> ctx" ("_\<down>" [110] 110)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
where
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
    "[]\<down> = \<box>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   657
  | "(E # Es)\<down> = (Es\<down>) \<odot> E"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   658
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
text {*  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
  Notice that we not just have given a pretty syntax for the functions, but
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
  also some precedences. The numbers inside the [\<dots>] stand for the precedences
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
  of the arguments; the one next to it the precedence of the whole term.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
  This means we have to write (Es1 \<odot> Es2) \<odot> Es3 otherwise Es1 \<odot> Es2 \<odot> Es3 is
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
  interpreted as Es1 \<odot> (Es2 \<odot> Es3).
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   668
section {* Structural Inductions over Contexts *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   669
 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671
  So far we have had a look at an induction over an inductive predicate. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
  Another important induction principle is structural inductions for 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   673
  datatypes. To illustrate structural inductions we prove some facts
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
  about context composition, some of which we will need later on.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
subsection {* EXERCISE 5 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
text {* Complete the proof and remove the sorries. *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
3132
87eca760dcba updated tutorial to latest version and added it to the tests
Christian Urban <urbanc@in.tum.de>
parents: 2694
diff changeset
   681
lemma ctx_compose:
2694
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
  shows "(E1 \<odot> E2)\<lbrakk>t\<rbrakk> = E1\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   683
proof (induct E1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   684
  case Hole
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   685
  show "(\<box> \<odot> E2)\<lbrakk>t\<rbrakk> = \<box>\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   686
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   687
  case (CAppL E1 t')
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   688
  have ih: "(E1 \<odot> E2)\<lbrakk>t\<rbrakk> = E1\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   689
  show "((CAppL E1 t') \<odot> E2)\<lbrakk>t\<rbrakk> = (CAppL E1 t')\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" using ih by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   690
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   691
  case (CAppR t' E1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   692
  have ih: "(E1 \<odot> E2)\<lbrakk>t\<rbrakk> = E1\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   693
  show "((CAppR t' E1) \<odot> E2)\<lbrakk>t\<rbrakk> = (CAppR t' E1)\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" using ih by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   694
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   695
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   696
subsection {* EXERCISE 6 *}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   697
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   698
text {*
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   699
  Remove the sorries in the ctx_append proof below. You can make 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   700
  use of the following two properties.    
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   701
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   702
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   703
lemma neut_hole:
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   704
  shows "E \<odot> \<box> = E"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   705
by (induct E) (simp_all)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   706
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   707
lemma compose_assoc:  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   708
  shows "(E1 \<odot> E2) \<odot> E3 = E1 \<odot> (E2 \<odot> E3)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   709
by (induct E1) (simp_all)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   710
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   711
lemma
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   712
  shows "(Es1 @ Es2)\<down> = (Es2\<down>) \<odot> (Es1\<down>)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
proof (induct Es1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
  case Nil
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   715
  show "([] @ Es2)\<down> = Es2\<down> \<odot> []\<down>" using neut_hole by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
  case (Cons E Es1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718
  have ih: "(Es1 @ Es2)\<down> = Es2\<down> \<odot> Es1\<down>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   719
  have eq1: "((E # Es1) @ Es2)\<down> = (E # (Es1 @ Es2))\<down>" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720
  have eq2: "(E # (Es1 @ Es2))\<down> = (Es1 @ Es2)\<down> \<odot> E" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   721
  have eq3: "(Es1 @ Es2)\<down> \<odot> E = (Es2\<down> \<odot> Es1\<down>) \<odot> E" using ih by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   722
  have eq4: "(Es2\<down> \<odot> Es1\<down>) \<odot> E = Es2\<down> \<odot> (Es1\<down> \<odot> E)" using compose_assoc by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   723
  have eq5: "Es2\<down> \<odot> (Es1\<down> \<odot> E) = Es2\<down> \<odot> (E # Es1)\<down>" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   724
  show "((E # Es1) @ Es2)\<down> = Es2\<down> \<odot> (E # Es1)\<down>" using eq1 eq2 eq3 eq4 eq5 by (simp only:)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   725
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   726
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   727
text {* 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   728
  The last proof involves several steps of equational reasoning.
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   729
  Isar provides some convenient means to express such equational 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   730
  reasoning in a much cleaner fashion using the "also have" 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   731
  construction. 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   732
*}
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   733
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   734
lemma 
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
  shows "(Es1 @ Es2)\<down> = (Es2\<down>) \<odot> (Es1\<down>)"
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   736
proof (induct Es1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   737
  case Nil
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   738
  show "([] @ Es2)\<down> = Es2\<down> \<odot> []\<down>" using neut_hole by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   739
next
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   740
  case (Cons E Es1)
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   741
  have ih: "(Es1 @ Es2)\<down> = Es2\<down> \<odot> Es1\<down>" by fact
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
  have "((E # Es1) @ Es2)\<down> = (E # (Es1 @ Es2))\<down>" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   743
  also have "\<dots> = (Es1 @ Es2)\<down> \<odot> E" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   744
  also have "\<dots> = (Es2\<down> \<odot> Es1\<down>) \<odot> E" using ih by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   745
  also have "\<dots> = Es2\<down> \<odot> (Es1\<down> \<odot> E)" using compose_assoc by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   746
  also have "\<dots> = Es2\<down> \<odot> (E # Es1)\<down>" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   747
  finally show "((E # Es1) @ Es2)\<down> = Es2\<down> \<odot> (E # Es1)\<down>" by simp
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   748
qed
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   749
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   750
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   751
end  
3485111c7d62 cleaned up tutorial1...added solution file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   752