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