author | Christian Urban <urbanc@in.tum.de> |
Fri, 17 Oct 2008 05:02:04 -0400 | |
changeset 39 | 631d12c25bde |
parent 34 | 527fc0af45e3 |
child 40 | 35e1dff0d9bb |
permissions | -rw-r--r-- |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
theory FirstSteps |
25
e2f9f94b26d4
Antiquotation setup is now contained in theory Base.
berghofe
parents:
21
diff
changeset
|
2 |
imports Base |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
chapter {* First Steps *} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
8 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
text {* |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
10 |
Isabelle programming is done in Standard ML. |
6 | 11 |
Just like lemmas and proofs, code in Isabelle is part of a |
12 |
theory. If you want to follow the code written in this chapter, we |
|
13 |
assume you are working inside the theory defined by |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
|
6 | 15 |
\begin{center} |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
16 |
\begin{tabular}{@ {}l} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
17 |
\isacommand{theory} FirstSteps\\ |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
18 |
\isacommand{imports} Main\\ |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
19 |
\isacommand{begin}\\ |
6 | 20 |
\ldots |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
21 |
\end{tabular} |
6 | 22 |
\end{center} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
23 |
*} |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
24 |
|
20 | 25 |
section {* Including ML-Code *} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
26 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
27 |
text {* |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
28 |
The easiest and quickest way to include code in a theory is |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
29 |
by using the \isacommand{ML} command. For example\smallskip |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
31 |
\isacommand{ML} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
32 |
@{ML_text "{"}@{ML_text "*"}\isanewline |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
33 |
\hspace{5mm}@{ML "3 + 4"}\isanewline |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
34 |
@{ML_text "*"}@{ML_text "}"}\isanewline |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
35 |
@{ML_text "> 7"}\smallskip |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
37 |
Expressions inside \isacommand{ML} commands are immediately evaluated, |
6 | 38 |
like ``normal'' Isabelle proof scripts, by using the advance and undo buttons of |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
39 |
your Isabelle environment. The code inside the \isacommand{ML} command |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
40 |
can also contain value and function bindings. However on such \isacommand{ML} |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
41 |
commands the undo operation behaves slightly counter-intuitive, because |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
42 |
if you define\smallskip |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
43 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
44 |
\isacommand{ML} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
45 |
@{ML_text "{"}@{ML_text "*"}\isanewline |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
46 |
@{ML_text "val foo = true"}\isanewline |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
47 |
@{ML_text "*"}@{ML_text "}"}\isanewline |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
48 |
@{ML_text "> true"}\smallskip |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
49 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
50 |
then Isabelle's undo operation has no effect on the definition of |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
51 |
@{ML_text "foo"}. Note that from now on we will drop the |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
52 |
\isacommand{ML} @{ML_text "{"}@{ML_text "* \<dots> *"}@{ML_text "}"} whenever |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
53 |
we show code. |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
54 |
|
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
55 |
Once a portion of code is relatively stable, one usually wants to |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
56 |
export it to a separate ML-file. Such files can then be included in a |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
57 |
theory by using \isacommand{uses} in the header of the theory, like |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
58 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
59 |
\begin{center} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
60 |
\begin{tabular}{@ {}l} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
61 |
\isacommand{theory} CookBook\\ |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
62 |
\isacommand{imports} Main\\ |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
63 |
\isacommand{uses} @{ML_text "\"file_to_be_included.ML\""} @{text "\<dots>"}\\ |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
64 |
\isacommand{begin}\\ |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
65 |
\ldots |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
66 |
\end{tabular} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
67 |
\end{center} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
68 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
69 |
Note that from now on we are going to drop the the |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
70 |
|
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
71 |
*} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
72 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
73 |
section {* Debugging and Printing *} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
74 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
75 |
text {* |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
76 |
|
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
77 |
During developments you might find it necessary to quickly inspect some data |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
78 |
in your code. This can be done in a ``quick-and-dirty'' fashion using |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
79 |
the function @{ML "warning"}. For example |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
80 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
81 |
@{ML [display] "warning \"any string\""} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
82 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
83 |
will print out @{ML_text "\"any string\""} inside the response buffer of Isabelle. |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
84 |
If you develop under PolyML, then there is a convenient, though again |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
85 |
``quick-and-dirty'', method for converting values into strings, |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
86 |
for example: |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
87 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
88 |
@{ML [display] "warning (makestring 1)"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
89 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
90 |
However this only works if the type of what is converted is monomorphic and not |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
91 |
a function. |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
92 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
93 |
The funtion warning should only be used for testing purposes, because any |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
94 |
output this funtion generates will be overwritten, as soon as an error is |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
95 |
raised. Therefore for printing anything more serious and elaborate, the |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
96 |
function @{ML tracing} should be used. This function writes all output into |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
97 |
a separate buffer. |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
98 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
99 |
@{ML [display] "tracing \"foo\""} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
100 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
101 |
It is also possible to redirect the channel where the @{ML_text "foo"} is |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
102 |
printed to a separate file, e.g. to prevent Proof General from choking on massive |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
103 |
amounts of trace output. This rediretion can be achieved using the code |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
104 |
*} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
105 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
106 |
ML {* |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
107 |
val strip_specials = |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
108 |
let |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
109 |
fun strip ("\^A" :: _ :: cs) = strip cs |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
110 |
| strip (c :: cs) = c :: strip cs |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
111 |
| strip [] = []; |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
112 |
in implode o strip o explode end; |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
113 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
114 |
fun redirect_tracing stream = |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
115 |
Output.tracing_fn := (fn s => |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
116 |
(TextIO.output (stream, (strip_specials s)); |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
117 |
TextIO.output (stream, "\n"); |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
118 |
TextIO.flushOut stream)); |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
119 |
*} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
120 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
121 |
text {* |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
122 |
Calling @{ML "redirect_tracing"} with @{ML "(TextIO.openOut \"foo.bar\")"} |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
123 |
will cause that all tracing information is printed into the file @{ML_text "foo.bar"}. |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
124 |
|
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
125 |
*} |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
126 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
127 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
128 |
section {* Antiquotations *} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
129 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
text {* |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
131 |
The main advantage of embedding all code |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
132 |
in a theory is that the code can contain references to entities defined |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
133 |
on the logical level of Isabelle. This is done using antiquotations. |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
134 |
For example, one can print out the name of |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
135 |
the current theory by typing |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
136 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
137 |
@{ML_response [display] "Context.theory_name @{theory}" "FirstSteps : string"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
138 |
|
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
139 |
where @{text "@{theory}"} is an antiquotation that is substituted with the |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
140 |
current theory (remember that we assumed we are inside the theory CookBook). |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
141 |
The name of this theory can be extracted using the function |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
142 |
@{ML "Context.theory_name"}. |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
143 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
144 |
Note, however, that antiquotations are statically scoped, that is the value is |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
145 |
determined at ``compile-time'', not ``run-time''. For example the function |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
146 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
ML {* |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
150 |
fun not_current_thyname () = Context.theory_name @{theory} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
151 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
152 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
153 |
text {* |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
154 |
does \emph{not} return the name of the current theory, if it is run in a |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
155 |
different theory. Instead, the code above defines the constant function |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
156 |
that always returns the string @{ML_text "FirstSteps"}, no matter where the |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
157 |
function is called. Operationally speaking, @{text "@{theory}"} is |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
158 |
\emph{not} replaced with code that will look up the current theory in |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
159 |
some data structure and return it. Instead, it is literally |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
160 |
replaced with the value representing the theory name. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
161 |
|
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
162 |
In a similar way you can use antiquotations to refer to theorems or simpsets: |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
163 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
164 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
165 |
@{ML [display] "@{thm allI}"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
166 |
@{ML [display] "@{simpset}"} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
167 |
|
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
168 |
In the course of this introduction, we will learn more about |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
169 |
these antiquotations: they greatly simplify Isabelle programming since one |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
170 |
can directly access all kinds of logical elements from ML. |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
171 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
172 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
174 |
section {* Terms and Types *} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
175 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
176 |
text {* |
34 | 177 |
One way to construct terms of Isabelle on the ML level is by using the antiquotation |
178 |
\mbox{@{text "@{term \<dots>}"}}: |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
179 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
180 |
@{ML_response [display] "@{term \"(a::nat) + b = c\"}" |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
181 |
"Const (\"op =\", \<dots>) $ (Const (\"HOL.plus_class.plus\", \<dots>) $ \<dots> $ \<dots>) $ \<dots>"} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
182 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
183 |
This will show the term @{term "(a::nat) + b = c"}, but printed out using the internal |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
184 |
representation of this term. This internal representation corresponds to the |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
185 |
datatype @{ML_type "term"}. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
186 |
|
34 | 187 |
The internal representation of terms uses the usual de Bruijn index mechanism where bound |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
188 |
variables are represented by the constructor @{ML Bound}. The index in @{ML Bound} refers to |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
189 |
the number of Abstractions (@{ML Abs}) we have to skip until we hit the @{ML Abs} that |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
190 |
binds the corresponding variable. However, in Isabelle the names of bound variables are |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
191 |
kept at abstractions for printing purposes, and so should be treated only as comments. |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
192 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
193 |
\begin{readmore} |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
194 |
Terms are described in detail in \isccite{sec:terms}. Their |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
195 |
definition and many useful operations can be found in @{ML_file "Pure/term.ML"}. |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
196 |
\end{readmore} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
197 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
198 |
Sometimes the internal representation of terms can be surprisingly different |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
199 |
from what you see at the user level, because the layers of |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
200 |
parsing/type checking/pretty printing can be quite elaborate. |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
201 |
*} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
202 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
203 |
text {* |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
204 |
\begin{exercise} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
205 |
Look at the internal term representation of the following terms, and |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
206 |
find out why they are represented like this. |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
207 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
208 |
\begin{itemize} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
209 |
\item @{term "case x of 0 \<Rightarrow> 0 | Suc y \<Rightarrow> y"} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
210 |
\item @{term "\<lambda>(x,y). P y x"} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
211 |
\item @{term "{ [x::int] | x. x \<le> -2 }"} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
212 |
\end{itemize} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
213 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
214 |
Hint: The third term is already quite big, and the pretty printer |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
215 |
may omit parts of it by default. If you want to see all of it, you |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
216 |
can use the following ML funtion to set the limit to a value high |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
217 |
enough: |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
218 |
\end{exercise} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
219 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
220 |
@{ML [display] "print_depth 50"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
221 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
222 |
The antiquotation @{text "@{prop \<dots>}"} constructs terms of propositional type, |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
223 |
inserting the invisible @{text "Trueprop"} coercions whenever necessary. |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
224 |
Consider for example |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
225 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
226 |
@{ML_response [display] "@{term \"P x\"}" "Free (\"P\", \<dots>) $ Free (\"x\", \<dots>)"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
227 |
@{ML_response [display] "@{prop \"P x\"}" |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
228 |
"Const (\"Trueprop\", \<dots>) $ (Free (\"P\", \<dots>) $ Free (\"x\", \<dots>))"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
229 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
230 |
which inserts the coercion in the latter case and |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
231 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
232 |
@{ML_response [display] "@{term \"P x \<Longrightarrow> Q x\"}" "Const (\"==>\", \<dots>) $ \<dots> $ \<dots>"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
233 |
@{ML_response [display] "@{prop \"P x \<Longrightarrow> Q x\"}" "Const (\"==>\", \<dots>) $ \<dots> $ \<dots>"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
234 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
235 |
which does not. |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
236 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
237 |
Types can be constructed using the antiquotation @{text "@{typ \<dots>}"}. For example |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
238 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
239 |
*} |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
240 |
|
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
241 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
242 |
text {* |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
243 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
244 |
@{ML_response [display] "@{typ \"bool \<Rightarrow> nat\"}" "Type \<dots>"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
245 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
246 |
(FIXME: Unlike the term antiquotation, @{text "@{typ \<dots>}"} does not print the |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
247 |
internal representation. Is there a reason for this, that needs to be explained |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
248 |
here?) |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
249 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
250 |
\begin{readmore} |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
251 |
Types are described in detail in \isccite{sec:types}. Their |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
252 |
definition and many useful operations can be found in @{ML_file "Pure/type.ML"}. |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
253 |
\end{readmore} |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
254 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
255 |
*} |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
256 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
257 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
258 |
section {* Constructing Terms and Types Manually *} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
259 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
260 |
text {* |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
261 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
262 |
While antiquotations are very convenient for constructing terms and types, |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
263 |
they can only construct fixed terms. Unfortunately, one often needs to construct them |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
264 |
dynamically. For example, a function that returns the implication |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
265 |
@{text "\<And>(x::\<tau>). P x \<Longrightarrow> Q x"} taking @{term P}, @{term Q} and the typ @{term "\<tau>"} |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
266 |
as arguments can only be written as |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
267 |
*} |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
268 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
269 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
270 |
ML {* |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
271 |
fun make_imp P Q tau = |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
272 |
let |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
273 |
val x = Free ("x",tau) |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
274 |
in Logic.all x (Logic.mk_implies (HOLogic.mk_Trueprop (P $ x), |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
275 |
HOLogic.mk_Trueprop (Q $ x))) |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
276 |
end |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
277 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
278 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
279 |
text {* |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
280 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
281 |
The reason is that one cannot pass the arguments @{term P}, @{term Q} and |
20 | 282 |
@{term "tau"} into an antiquotation. For example the following does not work. |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
283 |
*} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
284 |
|
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
285 |
ML {* |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
286 |
fun make_wrong_imp P Q tau = @{prop "\<And>x. P x \<Longrightarrow> Q x"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
287 |
*} |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
288 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
289 |
text {* |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
290 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
291 |
To see this apply @{text "@{term S}"}, @{text "@{term T}"} and @{text "@{typ nat}"} |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
292 |
to both functions. |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
293 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
294 |
One tricky point in constructing terms by hand is to obtain the |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
295 |
fully qualified name for constants. For example the names for @{text "zero"} or |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
296 |
@{text "+"} are more complex than one first expects, namely |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
297 |
|
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
298 |
\begin{center} |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
299 |
@{ML_text "HOL.zero_class.zero"} and @{ML_text "HOL.plus_class.plus"}. |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
300 |
\end{center} |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
301 |
|
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
302 |
The extra prefixes @{ML_text zero_class} and @{ML_text plus_class} are present because |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
303 |
these constants are defined within type classes; the prefix @{text "HOL"} indicates in |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
304 |
which theory they are defined. Guessing such internal names can sometimes be quite hard. |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
305 |
Therefore Isabellle provides the antiquotation @{text "@{const_name \<dots>}"} which does the |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
306 |
expansion automatically, for example: |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
307 |
*} |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
308 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
309 |
text {* |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
310 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
311 |
(FIXME: Is it useful to explain @{text "@{const_syntax}"}?) |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
312 |
|
20 | 313 |
(FIXME: how to construct types manually) |
314 |
||
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
315 |
\begin{readmore} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
316 |
There are many functions in @{ML_file "Pure/logic.ML"} and |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
317 |
@{ML_file "HOL/hologic.ML"} that make such manual constructions of terms |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
318 |
easier.\end{readmore} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
319 |
|
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
320 |
Have a look at these files and try to solve the following two exercises: |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
321 |
|
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
322 |
*} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
323 |
|
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
324 |
text {* |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
325 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
326 |
\begin{exercise}\label{fun:revsum} |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
327 |
Write a function @{ML_text "rev_sum : term -> term"} that takes a |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
328 |
term of the form @{text "t\<^isub>1 + t\<^isub>2 + \<dots> + t\<^isub>n"} (whereby @{text "i"} might be zero) |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
329 |
and returns the reversed sum @{text "t\<^isub>n + \<dots> + t\<^isub>2 + t\<^isub>1"}. Assume |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
330 |
the @{text "t\<^isub>i"} can be arbitrary expressions and also note that @{text "+"} |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
331 |
associates to the left. Try your function on some examples. |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
332 |
\end{exercise} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
333 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
334 |
\begin{exercise}\label{fun:makesum} |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
335 |
Write a function which takes two terms representing natural numbers |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
336 |
in unary (like @{term "Suc (Suc (Suc 0))"}), and produce the unary |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
337 |
number representing their sum. |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
338 |
\end{exercise} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
339 |
|
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
340 |
*} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
341 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
342 |
|
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
343 |
section {* Type Checking *} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
344 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
345 |
text {* |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
346 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
347 |
We can freely construct and manipulate terms, since they are just |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
348 |
arbitrary unchecked trees. However, we eventually want to see if a |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
349 |
term is well-formed, or type checks, relative to a theory. |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
350 |
Type checking is done via the function @{ML cterm_of}, which turns |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
351 |
a @{ML_type term} into a @{ML_type cterm}, a \emph{certified} term. |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
352 |
Unlike @{ML_type term}s, which are just trees, @{ML_type |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
353 |
"cterm"}s are abstract objects that are guaranteed to be |
20 | 354 |
type-correct, and that can only be constructed via the official |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
355 |
interfaces. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
356 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
357 |
Type checking is always relative to a theory context. For now we can use |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
358 |
the @{ML "@{theory}"} antiquotation to get hold of the current theory. |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
359 |
For example we can write: |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
360 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
361 |
(FIXME ML-response-unchecked needed) |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
362 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
363 |
@{ML [display] "@{term \"(a::nat) + b = c\"}"} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
364 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
365 |
and |
20 | 366 |
|
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
367 |
@{ML [display] |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
368 |
"let |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
369 |
val natT = @{typ \"nat\"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
370 |
val zero = @{term \"0::nat\"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
371 |
in |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
372 |
cterm_of @{theory} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
373 |
(Const (@{const_name plus}, natT --> natT --> natT) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
374 |
$ zero $ zero) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
375 |
end"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
376 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
377 |
\begin{exercise} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
378 |
Check that the function defined in Exercise~\ref{fun:revsum} returns a |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
379 |
result that type checks. |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
380 |
\end{exercise} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
381 |
|
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
382 |
*} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
383 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
384 |
section {* Theorems *} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
385 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
386 |
text {* |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
387 |
Just like @{ML_type cterm}s, theorems (of type @{ML_type thm}) are |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
388 |
abstract objects that can only be built by going through the kernel |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
389 |
interfaces, which means that all your proofs will be checked. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
390 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
391 |
To see theorems in ``action'', let us give a proof for the following statement |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
392 |
*} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
393 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
394 |
lemma |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
395 |
assumes assm\<^isub>1: "\<And>(x::nat). P x \<Longrightarrow> Q x" |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
396 |
and assm\<^isub>2: "P t" |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
397 |
shows "Q t" (*<*)oops(*>*) |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
398 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
399 |
text {* |
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
400 |
on the ML level:\footnote{Note that @{text "|>"} is reverse |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
401 |
application. This combinator, and several variants are defined in |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
402 |
@{ML_file "Pure/General/basics.ML"}.} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
403 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
404 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
405 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
406 |
ML {* |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
407 |
let |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
408 |
val thy = @{theory} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
409 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
410 |
val assm1 = cterm_of thy @{prop "\<And>(x::nat). P x \<Longrightarrow> Q x"} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
411 |
val assm2 = cterm_of thy @{prop "((P::nat\<Rightarrow>bool) t)"} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
412 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
413 |
val Pt_implies_Qt = |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
414 |
assume assm1 |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
415 |
|> forall_elim (cterm_of thy @{term "t::nat"}); |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
416 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
417 |
val Qt = implies_elim Pt_implies_Qt (assume assm2); |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
418 |
in |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
419 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
420 |
Qt |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
421 |
|> implies_intr assm2 |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
422 |
|> implies_intr assm1 |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
423 |
end |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
424 |
*} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
425 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
426 |
text {* |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
427 |
|
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
428 |
This code-snippet constructs the following proof: |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
429 |
|
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
430 |
\[ |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
431 |
\infer[(@{text "\<Longrightarrow>"}$-$intro)]{\vdash @{prop "(\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> P t \<Longrightarrow> Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
432 |
{\infer[(@{text "\<Longrightarrow>"}$-$intro)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "P t \<Longrightarrow> Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
433 |
{\infer[(@{text "\<Longrightarrow>"}$-$elim)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"}, @{prop "P t"} \vdash @{prop "Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
434 |
{\infer[(@{text "\<And>"}$-$elim)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "P t \<Longrightarrow> Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
435 |
{\infer[(assume)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "\<And>x. P x \<Longrightarrow> Q x"}}{}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
436 |
& |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
437 |
\infer[(assume)]{@{prop "P t"} \vdash @{prop "P t"}}{} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
438 |
} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
439 |
} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
440 |
} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
441 |
\] |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
442 |
|
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
443 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
444 |
\begin{readmore} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
445 |
For how the functions @{text "assume"}, @{text "forall_elim"} etc work |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
446 |
see \isccite{sec:thms}. The basic functions for theorems are defined in |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
447 |
@{ML_file "Pure/thm.ML"}. |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
448 |
\end{readmore} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
449 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
450 |
*} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
451 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
452 |
|
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
453 |
section {* Tactical Reasoning *} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
454 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
455 |
text {* |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
456 |
The goal-oriented tactical style reasoning of the ML level is similar |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
457 |
to the @{text apply}-style at the user level, i.e.~the reasoning is centred |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
458 |
around a \emph{goal}, which is modified in a sequence of proof steps |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
459 |
until it is solved. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
460 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
461 |
A goal (or goal state) is a special @{ML_type thm}, which by |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
462 |
convention is an implication of the form: |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
463 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
464 |
@{text[display] "A\<^isub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^isub>n \<Longrightarrow> #(C)"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
465 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
466 |
where @{term C} is the goal to be proved and the @{term "A\<^isub>i"} are the open subgoals. |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
467 |
Since the goal @{term C} can potentially be an implication, there is a |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
468 |
@{text "#"} wrapped around it, which prevents that premises are |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
469 |
misinterpreted as open subgoals. The protection @{text "# :: prop \<Rightarrow> |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
470 |
prop"} is just the identity function and used as a syntactic marker. |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
471 |
|
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
472 |
(FIXME: maybe show how this is printed on the screen) |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
473 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
474 |
\begin{readmore} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
475 |
For more on goals see \isccite{sec:tactical-goals}. |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
476 |
\end{readmore} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
477 |
|
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
478 |
Tactics are functions that map a goal state to a (lazy) |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
479 |
sequence of successor states, hence the type of a tactic is |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
480 |
@{ML_type[display] "thm -> thm Seq.seq"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
481 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
482 |
\begin{readmore} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
483 |
See @{ML_file "Pure/General/seq.ML"} for the implementation of lazy |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
484 |
sequences. However in day-to-day Isabelle programming, one rarely |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
485 |
constructs sequences explicitly, but uses the predefined tactic |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
486 |
combinators (tacticals) instead (see @{ML_file "Pure/tctical.ML"}). |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
487 |
(FIXME: Pointer to the old reference manual) |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
488 |
\end{readmore} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
489 |
|
34 | 490 |
While tactics can operate on the subgoals (the @{text "A\<^isub>i"} above), they |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
491 |
are expected to leave the conclusion @{term C} intact, with the |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
492 |
exception of possibly instantiating schematic variables. |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
493 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
494 |
To see how tactics work, let us transcribe a simple @{text apply}-style |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
495 |
proof from the tutorial \cite{isa-tutorial} into ML: |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
496 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
497 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
498 |
lemma disj_swap: "P \<or> Q \<Longrightarrow> Q \<or> P" |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
499 |
apply (erule disjE) |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
500 |
apply (rule disjI2) |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
501 |
apply assumption |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
502 |
apply (rule disjI1) |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
503 |
apply assumption |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
504 |
done |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
505 |
|
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
506 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
507 |
text {* |
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
508 |
To start the proof, the function @{ML "Goal.prove"}~@{text "ctxt xs As C tac"} sets |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
509 |
up a goal state for proving the goal @{text C} under the assumptions @{text As} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
510 |
(empty in the proof at hand) |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
511 |
with the variables @{text xs} that will be generalised once the |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
512 |
goal is proved. The @{text "tac"} is the tactic which proves the goal and which |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
513 |
can make use of the local assumptions. |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
514 |
*} |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
515 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
516 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
517 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
518 |
ML {* |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
519 |
let |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
520 |
val ctxt = @{context} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
521 |
val goal = @{prop "P \<or> Q \<Longrightarrow> Q \<or> P"} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
522 |
in |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
523 |
Goal.prove ctxt ["P", "Q"] [] goal (fn _ => |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
524 |
eresolve_tac [disjE] 1 |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
525 |
THEN resolve_tac [disjI2] 1 |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
526 |
THEN assume_tac 1 |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
527 |
THEN resolve_tac [disjI1] 1 |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
528 |
THEN assume_tac 1) |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
529 |
end |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
530 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
531 |
|
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
532 |
text {* |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
533 |
|
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
534 |
\begin{readmore} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
535 |
To learn more about the function @{ML Goal.prove} see \isccite{sec:results}. |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
536 |
\end{readmore} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
537 |
|
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
538 |
*} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
539 |
|
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
540 |
|
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
541 |
text {* An alternative way to transcribe this proof is as follows *} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
542 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
543 |
ML {* |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
544 |
let |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
545 |
val ctxt = @{context} |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
546 |
val goal = @{prop "P \<or> Q \<Longrightarrow> Q \<or> P"} |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
547 |
in |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
548 |
Goal.prove ctxt ["P", "Q"] [] goal (fn _ => |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
549 |
(eresolve_tac [disjE] |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
550 |
THEN' resolve_tac [disjI2] |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
551 |
THEN' assume_tac |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
552 |
THEN' resolve_tac [disjI1] |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
553 |
THEN' assume_tac) 1) |
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
554 |
end |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
555 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
556 |
|
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
557 |
text {* (FIXME: are there any advantages/disadvantages about this way?) *} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
558 |
|
20 | 559 |
section {* Storing Theorems *} |
560 |
||
561 |
section {* Theorem Attributes *} |
|
562 |
||
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
563 |
ML {* |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
564 |
val str_of_source = space_implode " " o map OuterLex.unparse o #2 o #1 o Args.dest_src; |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
565 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
566 |
fun ml_val ys txt = "fn " ^ |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
567 |
(case ys of [] => "_" | _ => enclose "(" ")" (commas ys)) ^ |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
568 |
" => (" ^ txt ^ ");"; |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
569 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
570 |
fun ml_val_open (ys, []) txt = ml_val ys txt |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
571 |
| ml_val_open (ys, xs) txt = |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
572 |
ml_val ys ("let open " ^ space_implode " " xs ^ " in " ^ txt ^ " end"); |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
573 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
574 |
fun ml_pat (rhs, pat) = |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
575 |
let val pat' = implode (map (fn "\\<dots>" => "_" | s => s) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
576 |
(Symbol.explode pat)) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
577 |
in |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
578 |
"val " ^ pat' ^ " = " ^ rhs |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
579 |
end; |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
580 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
581 |
(* modified from original *) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
582 |
fun ml_val txt = "fn _ => (" ^ txt ^ ");"; |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
583 |
fun ml_struct txt = "functor DUMMY_FUNCTOR() = struct structure DUMMY = " ^ txt ^ " end;"; |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
584 |
fun ml_type txt = "val _ = NONE : (" ^ txt ^ ") option;"; |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
585 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
586 |
*} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
587 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
588 |
ML {* ml_pat *} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
589 |
ML {* K ml_pat *} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
590 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
591 |
ML {* |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
592 |
fun output_verbatim ml src ctxt (txt, pos) = |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
593 |
let val txt = ml ctxt (txt, pos) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
594 |
in |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
595 |
(if ! ThyOutput.source then str_of_source src else txt) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
596 |
|> (if ! ThyOutput.quotes then quote else I) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
597 |
|> ThyOutput.output (fn _ => fn s => Pretty.str s) src ctxt |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
598 |
end; |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
599 |
*} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
600 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
601 |
ML {* |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
602 |
fun output_ml ml = output_verbatim |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
603 |
(fn ctxt => fn ((txt, p), pos) => |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
604 |
(ML_Context.eval_in (SOME ctxt) false pos (ml p txt); |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
605 |
txt |> Source.of_string |> ML_Lex.source |> Source.exhaust |> |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
606 |
Chunks.transform_cmts |> implode)); |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
607 |
*} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
608 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
609 |
ML {* |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
610 |
fun output_ml_checked ml src ctxt (txt, pos) = |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
611 |
(ML_Context.eval_in (SOME ctxt) false pos (ml txt); |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
612 |
(if ! ThyOutput.source then str_of_source src else SymbolPos.content (SymbolPos.explode (txt, pos))) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
613 |
|> (if ! ThyOutput.quotes then quote else I) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
614 |
|> ThyOutput.output (fn _ => fn s => Pretty.str s) src ctxt) |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
615 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
616 |
*} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
617 |
|
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
618 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
619 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
620 |
end |