| author | Christian Urban <urbanc@in.tum.de> |
| Sun, 22 Nov 2009 15:27:10 +0100 | |
| changeset 401 | 36d61044f9bf |
| parent 400 | 7675427e311f |
| child 408 | ef048892d0f0 |
| permissions | -rw-r--r-- |
|
395
2c392f61f400
spilt the Essential's chapter
Christian Urban <urbanc@in.tum.de>
parents:
394
diff
changeset
|
1 |
theory Advanced |
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
imports Base FirstSteps |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
345
diff
changeset
|
5 |
(*<*) |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
345
diff
changeset
|
6 |
setup{*
|
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
345
diff
changeset
|
7 |
open_file_with_prelude |
|
395
2c392f61f400
spilt the Essential's chapter
Christian Urban <urbanc@in.tum.de>
parents:
394
diff
changeset
|
8 |
"Advanced_Code.thy" |
|
401
36d61044f9bf
updated to new Isabelle and clarified Skip_Proof
Christian Urban <urbanc@in.tum.de>
parents:
400
diff
changeset
|
9 |
["theory Advanced", "imports Base FirstSteps", "begin"] |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
345
diff
changeset
|
10 |
*} |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
345
diff
changeset
|
11 |
(*>*) |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
345
diff
changeset
|
12 |
|
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
345
diff
changeset
|
13 |
|
|
395
2c392f61f400
spilt the Essential's chapter
Christian Urban <urbanc@in.tum.de>
parents:
394
diff
changeset
|
14 |
chapter {* Advanced Isabelle *}
|
|
381
97518188ef0e
added more to the unification section
Christian Urban <urbanc@in.tum.de>
parents:
380
diff
changeset
|
15 |
|
|
97518188ef0e
added more to the unification section
Christian Urban <urbanc@in.tum.de>
parents:
380
diff
changeset
|
16 |
text {*
|
| 400 | 17 |
While terms, types and theorems are the most basic data structures in |
18 |
Isabelle, there are a number of layers built on top of them. Most of these |
|
19 |
layers are concerned with storing and manipulating data. Handling |
|
20 |
them properly is an essential skill for Isabelle programming. The most basic |
|
21 |
layer are theories. They contain global data and can be seen as the |
|
22 |
``long-term memory'' of Isabelle. There is usually only one theory |
|
23 |
active at each moment. Proof contexts and local theories, on the |
|
24 |
other hand, store local data for a task at hand. They act like the |
|
25 |
``short-term memory'' and there can be many of them that are active |
|
26 |
in parallel. |
|
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
*} |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
|
| 358 | 29 |
section {* Theories\label{sec:theories} (TBD) *}
|
30 |
||
31 |
text {*
|
|
|
401
36d61044f9bf
updated to new Isabelle and clarified Skip_Proof
Christian Urban <urbanc@in.tum.de>
parents:
400
diff
changeset
|
32 |
Theories, as said above, are the most basic layer in Isabelle. They contain |
| 400 | 33 |
definitions, syntax declarations, axioms, proofs etc. If a definition is |
34 |
stated, it must be stored in a theory in order to be usable later |
|
35 |
on. Similar with proofs: once a proof is finished, the proved theorem needs |
|
36 |
to be stored in the theorem database of the theory in order to be |
|
37 |
usable. All relevant data of a theory can be queried as follows. |
|
| 358 | 38 |
|
39 |
\begin{isabelle}
|
|
40 |
\isacommand{print\_theory}\\
|
|
41 |
@{text "> names: Pure Code_Generator HOL \<dots>"}\\
|
|
42 |
@{text "> classes: Inf < type \<dots>"}\\
|
|
43 |
@{text "> default sort: type"}\\
|
|
44 |
@{text "> syntactic types: #prop \<dots>"}\\
|
|
45 |
@{text "> logical types: 'a \<times> 'b \<dots>"}\\
|
|
46 |
@{text "> type arities: * :: (random, random) random \<dots>"}\\
|
|
47 |
@{text "> logical constants: == :: 'a \<Rightarrow> 'a \<Rightarrow> prop \<dots>"}\\
|
|
48 |
@{text "> abbreviations: \<dots>"}\\
|
|
49 |
@{text "> axioms: \<dots>"}\\
|
|
50 |
@{text "> oracles: \<dots>"}\\
|
|
51 |
@{text "> definitions: \<dots>"}\\
|
|
52 |
@{text "> theorems: \<dots>"}
|
|
53 |
\end{isabelle}
|
|
54 |
||
| 400 | 55 |
|
56 |
||
| 358 | 57 |
\begin{center}
|
58 |
\begin{tikzpicture}
|
|
59 |
\node[top color=white, bottom color=gray!30, draw=black!100, drop shadow] {A};
|
|
60 |
\end{tikzpicture}
|
|
61 |
\end{center}
|
|
62 |
||
|
392
47e5b71c7f6c
modified the typ-pretty-printer and added parser exercise
Christian Urban <urbanc@in.tum.de>
parents:
389
diff
changeset
|
63 |
\footnote{\bf FIXME: list append in merge operations can cause
|
|
47e5b71c7f6c
modified the typ-pretty-printer and added parser exercise
Christian Urban <urbanc@in.tum.de>
parents:
389
diff
changeset
|
64 |
exponential blowups.} |
| 358 | 65 |
*} |
66 |
||
| 348 | 67 |
section {* Setups (TBD) *}
|
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
|
| 348 | 69 |
text {*
|
| 361 | 70 |
@{ML Sign.declare_const}
|
71 |
||
| 348 | 72 |
In the previous section we used \isacommand{setup} in order to make
|
73 |
a theorem attribute known to Isabelle. What happens behind the scenes |
|
74 |
is that \isacommand{setup} expects a function of type
|
|
75 |
@{ML_type "theory -> theory"}: the input theory is the current theory and the
|
|
76 |
output the theory where the theory attribute has been stored. |
|
77 |
||
78 |
This is a fundamental principle in Isabelle. A similar situation occurs |
|
79 |
for example with declaring constants. The function that declares a |
|
80 |
constant on the ML-level is @{ML_ind add_consts_i in Sign}.
|
|
81 |
If you write\footnote{Recall that ML-code needs to be
|
|
82 |
enclosed in \isacommand{ML}~@{text "\<verbopen> \<dots> \<verbclose>"}.}
|
|
83 |
*} |
|
84 |
||
85 |
ML{*Sign.add_consts_i [(@{binding "BAR"}, @{typ "nat"}, NoSyn)] @{theory} *}
|
|
86 |
||
87 |
text {*
|
|
88 |
for declaring the constant @{text "BAR"} with type @{typ nat} and
|
|
89 |
run the code, then you indeed obtain a theory as result. But if you |
|
90 |
query the constant on the Isabelle level using the command \isacommand{term}
|
|
91 |
||
92 |
\begin{isabelle}
|
|
93 |
\isacommand{term}~@{text [quotes] "BAR"}\\
|
|
94 |
@{text "> \"BAR\" :: \"'a\""}
|
|
95 |
\end{isabelle}
|
|
96 |
||
97 |
you do not obtain a constant of type @{typ nat}, but a free variable (printed in
|
|
98 |
blue) of polymorphic type. The problem is that the ML-expression above did |
|
99 |
not register the declaration with the current theory. This is what the command |
|
100 |
\isacommand{setup} is for. The constant is properly declared with
|
|
101 |
*} |
|
102 |
||
103 |
setup %gray {* Sign.add_consts_i [(@{binding "BAR"}, @{typ "nat"}, NoSyn)] *}
|
|
104 |
||
105 |
text {*
|
|
106 |
Now |
|
107 |
||
108 |
\begin{isabelle}
|
|
109 |
\isacommand{term}~@{text [quotes] "BAR"}\\
|
|
110 |
@{text "> \"BAR\" :: \"nat\""}
|
|
111 |
\end{isabelle}
|
|
112 |
||
113 |
returns a (black) constant with the type @{typ nat}.
|
|
114 |
||
115 |
A similar command is \isacommand{local\_setup}, which expects a function
|
|
116 |
of type @{ML_type "local_theory -> local_theory"}. Later on we will also
|
|
117 |
use the commands \isacommand{method\_setup} for installing methods in the
|
|
118 |
current theory and \isacommand{simproc\_setup} for adding new simprocs to
|
|
119 |
the current simpset. |
|
120 |
*} |
|
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
|
|
341
62dea749d5ed
more work on theorem section
Christian Urban <urbanc@in.tum.de>
parents:
340
diff
changeset
|
122 |
section {* Contexts (TBD) *}
|
|
62dea749d5ed
more work on theorem section
Christian Urban <urbanc@in.tum.de>
parents:
340
diff
changeset
|
123 |
|
|
62dea749d5ed
more work on theorem section
Christian Urban <urbanc@in.tum.de>
parents:
340
diff
changeset
|
124 |
section {* Local Theories (TBD) *}
|
|
62dea749d5ed
more work on theorem section
Christian Urban <urbanc@in.tum.de>
parents:
340
diff
changeset
|
125 |
|
| 394 | 126 |
text {*
|
| 400 | 127 |
In contrast to an ordinary theory, which simply consists of a type |
128 |
signature, as well as tables for constants, axioms and theorems, a local |
|
129 |
theory contains additional context information, such as locally fixed |
|
130 |
variables and local assumptions that may be used by the package. The type |
|
131 |
@{ML_type local_theory} is identical to the type of \emph{proof contexts}
|
|
132 |
@{ML_type "Proof.context"}, although not every proof context constitutes a
|
|
133 |
valid local theory. |
|
134 |
||
135 |
@{ML "Context.>> o Context.map_theory"}
|
|
| 394 | 136 |
@{ML_ind "Local_Theory.declaration"}
|
137 |
*} |
|
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
138 |
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
139 |
(* |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
setup {*
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
141 |
Sign.add_consts_i [(Binding"bar", @{typ "nat"},NoSyn)]
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
142 |
*} |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
143 |
lemma "bar = (1::nat)" |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
144 |
oops |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
145 |
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
146 |
setup {*
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
Sign.add_consts_i [("foo", @{typ "nat"},NoSyn)]
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
#> PureThy.add_defs false [((@{binding "foo_def"},
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
Logic.mk_equals (Const ("FirstSteps.foo", @{typ "nat"}), @{term "1::nat"})), [])]
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
#> snd |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
151 |
*} |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
152 |
*) |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
153 |
(* |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
154 |
lemma "foo = (1::nat)" |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
155 |
apply(simp add: foo_def) |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
done |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
158 |
thm foo_def |
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
159 |
*) |
|
336
a12bb28fe2bd
polished on the pretty printing section
Christian Urban <urbanc@in.tum.de>
parents:
335
diff
changeset
|
160 |
|
| 394 | 161 |
section {* Morphisms (TBD) *}
|
162 |
||
163 |
text {*
|
|
164 |
Morphisms are arbitrary transformations over terms, types, theorems and bindings. |
|
165 |
They can be constructed using the function @{ML_ind morphism in Morphism},
|
|
166 |
which expects a record with functions of type |
|
167 |
||
168 |
\begin{isabelle}
|
|
169 |
\begin{tabular}{rl}
|
|
170 |
@{text "binding:"} & @{text "binding -> binding"}\\
|
|
171 |
@{text "typ:"} & @{text "typ -> typ"}\\
|
|
172 |
@{text "term:"} & @{text "term -> term"}\\
|
|
173 |
@{text "fact:"} & @{text "thm list -> thm list"}
|
|
174 |
\end{tabular}
|
|
175 |
\end{isabelle}
|
|
176 |
||
177 |
The simplest morphism is the @{ML_ind identity in Morphism}-morphism defined as
|
|
178 |
*} |
|
179 |
||
180 |
ML{*val identity = Morphism.morphism {binding = I, typ = I, term = I, fact = I}*}
|
|
181 |
||
182 |
text {*
|
|
183 |
Morphisms can be composed with the function @{ML_ind "$>" in Morphism}
|
|
184 |
*} |
|
185 |
||
186 |
ML{*fun trm_phi (Free (x, T)) = Var ((x, 0), T)
|
|
187 |
| trm_phi (Abs (x, T, t)) = Abs (x, T, trm_phi t) |
|
188 |
| trm_phi (t $ s) = (trm_phi t) $ (trm_phi s) |
|
189 |
| trm_phi t = t*} |
|
190 |
||
191 |
ML{*val phi = Morphism.term_morphism trm_phi*}
|
|
192 |
||
193 |
ML{*Morphism.term phi @{term "P x y"}*}
|
|
194 |
||
195 |
text {*
|
|
196 |
@{ML_ind term_morphism in Morphism}
|
|
197 |
||
198 |
@{ML_ind term in Morphism},
|
|
199 |
@{ML_ind thm in Morphism}
|
|
200 |
||
201 |
\begin{readmore}
|
|
202 |
Morphisms are implemented in the file @{ML_file "Pure/morphism.ML"}.
|
|
203 |
\end{readmore}
|
|
204 |
*} |
|
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
205 |
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
206 |
section {* Misc (TBD) *}
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
207 |
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
208 |
ML {*Datatype.get_info @{theory} "List.list"*}
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
209 |
|
|
319
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
210 |
text {*
|
|
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
211 |
FIXME: association lists: |
|
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
212 |
@{ML_file "Pure/General/alist.ML"}
|
|
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
213 |
|
|
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
214 |
FIXME: calling the ML-compiler |
|
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
215 |
|
|
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
216 |
*} |
|
6bce4acf7f2a
added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
318
diff
changeset
|
217 |
|
|
335
163ac0662211
reorganised the certified terms section; tuned
Christian Urban <urbanc@in.tum.de>
parents:
329
diff
changeset
|
218 |
section {* Managing Name Spaces (TBD) *}
|
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
219 |
|
| 360 | 220 |
ML {* Sign.intern_type @{theory} "list" *}
|
221 |
ML {* Sign.intern_const @{theory} "prod_fun" *}
|
|
222 |
||
|
387
5dcee4d751ad
completed the unification section
Christian Urban <urbanc@in.tum.de>
parents:
386
diff
changeset
|
223 |
|
|
5dcee4d751ad
completed the unification section
Christian Urban <urbanc@in.tum.de>
parents:
386
diff
changeset
|
224 |
text {*
|
|
5dcee4d751ad
completed the unification section
Christian Urban <urbanc@in.tum.de>
parents:
386
diff
changeset
|
225 |
@{ML_ind "Binding.str_of"} returns the string with markup;
|
|
5dcee4d751ad
completed the unification section
Christian Urban <urbanc@in.tum.de>
parents:
386
diff
changeset
|
226 |
@{ML_ind "Binding.name_of"} returns the string without markup
|
| 394 | 227 |
|
228 |
@{ML_ind "Binding.conceal"}
|
|
|
387
5dcee4d751ad
completed the unification section
Christian Urban <urbanc@in.tum.de>
parents:
386
diff
changeset
|
229 |
*} |
|
5dcee4d751ad
completed the unification section
Christian Urban <urbanc@in.tum.de>
parents:
386
diff
changeset
|
230 |
|
|
388
0b337dedc306
added Skip_Proof.mk_thm and some pointers about concurrency
Christian Urban <urbanc@in.tum.de>
parents:
387
diff
changeset
|
231 |
section {* Concurrency (TBD) *}
|
|
0b337dedc306
added Skip_Proof.mk_thm and some pointers about concurrency
Christian Urban <urbanc@in.tum.de>
parents:
387
diff
changeset
|
232 |
|
|
0b337dedc306
added Skip_Proof.mk_thm and some pointers about concurrency
Christian Urban <urbanc@in.tum.de>
parents:
387
diff
changeset
|
233 |
text {*
|
|
0b337dedc306
added Skip_Proof.mk_thm and some pointers about concurrency
Christian Urban <urbanc@in.tum.de>
parents:
387
diff
changeset
|
234 |
@{ML_ind prove_future in Goal}
|
|
0b337dedc306
added Skip_Proof.mk_thm and some pointers about concurrency
Christian Urban <urbanc@in.tum.de>
parents:
387
diff
changeset
|
235 |
@{ML_ind future_result in Goal}
|
|
0b337dedc306
added Skip_Proof.mk_thm and some pointers about concurrency
Christian Urban <urbanc@in.tum.de>
parents:
387
diff
changeset
|
236 |
@{ML_ind fork_pri in Future}
|
|
0b337dedc306
added Skip_Proof.mk_thm and some pointers about concurrency
Christian Urban <urbanc@in.tum.de>
parents:
387
diff
changeset
|
237 |
*} |
|
387
5dcee4d751ad
completed the unification section
Christian Urban <urbanc@in.tum.de>
parents:
386
diff
changeset
|
238 |
|
| 396 | 239 |
section {* Parse and Print Translations (TBD) *}
|
240 |
||
|
349
9e374cd891e1
updated to Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents:
348
diff
changeset
|
241 |
section {* Summary *}
|
|
9e374cd891e1
updated to Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents:
348
diff
changeset
|
242 |
|
|
9e374cd891e1
updated to Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents:
348
diff
changeset
|
243 |
text {*
|
|
395
2c392f61f400
spilt the Essential's chapter
Christian Urban <urbanc@in.tum.de>
parents:
394
diff
changeset
|
244 |
TBD |
|
349
9e374cd891e1
updated to Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents:
348
diff
changeset
|
245 |
*} |
|
318
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
246 |
|
|
efb5fff99c96
split up the first-steps section into two chapters
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
247 |
end |