author | Christian Urban <urbanc@in.tum.de> |
Tue, 19 Jun 2012 15:02:22 +0100 | |
changeset 525 | 92a3600e50e4 |
child 527 | efe63c062e48 |
permissions | -rw-r--r-- |
525
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
theory Introspection |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
imports "../Appendix" |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
begin |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
section {* Introspection of Theorems and Proofs \label{rec:introspection} *} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
text{* |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
{\bf Problem:} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
How to obtain all theorems that are used in the proof of a theorem?\smallskip |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
{\bf Solution:} They can be obtained by introspecting the theorem.\smallskip |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
To introspect a theorem, let us define the following three functions that |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
analyse the @{ML_type proof_body} data-structure from @{ML_struct Proofterm}. |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
*} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
17 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
ML %grayML{*fun pthms_of (PBody {thms, ...}) = map #2 thms |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
val get_names = map #1 o pthms_of |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
val get_pbodies = map (Future.join o #3) o pthms_of *} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
text {* |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
To see what their purpose is, consider the following two short proofs. |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
*} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
lemma my_conjIa: |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
shows "A \<and> B \<Longrightarrow> A \<and> B" |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
apply(rule conjI) |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
apply(drule conjunct1) |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
apply(assumption) |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
apply(drule conjunct2) |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
apply(assumption) |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
done |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
lemma my_conjIb: |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
shows "A \<and> B \<Longrightarrow> A \<and> B" |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
apply(assumption) |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
38 |
done |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
text {* |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
While the theorems used in these proofs is obvious, in general it |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
is not obvious, because of automated provers that can be part of a |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
proof. Fortunately, ``behind'' every completed proof is a tree of |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
theorems that records all theorems that are employed for establishing |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
theorems like @{thm [source] my_conjIa}. We can traverse this tree |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
once a theorem is established. Let us first extract the name of the |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
established theorem from this tree. This can be done with |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
@{ML_response [display,gray] |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
"@{thm my_conjIa} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
|> Thm.proof_body_of |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
|> get_names" |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
"[\"Introspection.my_conjIa\"]"} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
whereby @{text "Introspection"} refers to the theory name in which we established |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
@{thm [source] my_conjIa}. Notice that the apply-proof of this theorem references |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
three other theorems. We can obtain them by descending into the first level of the |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
proof-tree, as follows. |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
@{ML_response [display,gray] |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
"@{thm my_conjIa} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
|> Thm.proof_body_of |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
|> get_pbodies |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
|> map get_names |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
|> List.concat" |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
"[\"HOL.conjunct2\", \"HOL.conjunct1\", \"HOL.conjI\", \"Pure.protectD\", |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
\"Pure.protectI\"]"} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
Note that the theorems @{thm [source] "protectD"} and @{thm [source] |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
70 |
protectI} are internal theorems that are always part of a |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
71 |
proof in Isabelle. Note also that applications of @{text assumption} do not |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
count as a separate theorem, as you can see in the following code. |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
@{ML_response [display,gray] |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
"@{thm my_conjIb} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
|> Thm.proof_body_of |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
|> get_pbodies |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
|> map get_names |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
|> List.concat" |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
"[\"Pure.protectD\", \"Pure.protectI\"]"} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
Of course we can also descend to the second level of the tree |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
``behind'' @{thm [source] my_conjIa}, which |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
means we obtain the theorems that are used in order to prove |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
@{thm [source] conjunct1}, @{thm conjunct2} and @{thm conjI}. |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
@{ML_response [display, gray] |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
"@{thm my_conjIa} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
|> Thm.proof_body_of |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
|> get_pbodies |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
|> map get_pbodies |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
|> (map o map) get_names |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
|> List.concat |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
|> List.concat |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
|> duplicates (op=)" |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
"[\"HOL.spec\", \"HOL.and_def\", \"HOL.mp\", \"HOL.impI\", \"Pure.protectD\", |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
97 |
\"Pure.protectI\"]"} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
\begin{readmore} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
The data-structure @{ML_type proof_body} is implemented |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
in @{ML_file "Pure/proofterm.ML"}. The functions concerning the |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
102 |
structure of theorems are in @{ML_file "Pure/thm.ML"}. |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
\end{readmore} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
*} |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
106 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
107 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
109 |
end |
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
|
92a3600e50e4
added a new recipe for introspecting theorems (suggested by Lukas and Rafal)
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |