author | Christian Urban <urbanc@in.tum.de> |
Mon, 23 Mar 2009 18:17:24 +0100 | |
changeset 194 | 8cd51a25a7ca |
parent 192 | 2fff636e1fa0 |
child 208 | 0634d42bb69f |
permissions | -rw-r--r-- |
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
theory Ind_Code |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
2 |
imports "../Base" "../FirstSteps" Simple_Inductive_Package Ind_Prelims |
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
192 | 5 |
datatype trm = |
6 |
Var "string" |
|
7 |
| App "trm" "trm" |
|
8 |
| Lam "string" "trm" |
|
9 |
||
10 |
simple_inductive |
|
11 |
fresh :: "string \<Rightarrow> trm \<Rightarrow> bool" ("_ \<sharp> _" [100,100] 100) |
|
12 |
where |
|
13 |
"a\<noteq>b \<Longrightarrow> a\<sharp>Var b" |
|
14 |
| "\<lbrakk>a\<sharp>t; a\<sharp>s\<rbrakk> \<Longrightarrow> a\<sharp>App t s" |
|
15 |
| "a\<sharp>Lam a t" |
|
16 |
| "\<lbrakk>a\<noteq>b; a\<sharp>t\<rbrakk> \<Longrightarrow> a\<sharp>Lam b t" |
|
17 |
||
18 |
||
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
19 |
section {* Code *} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
20 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
21 |
text {* |
192 | 22 |
|
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
23 |
@{text [display] "rule ::= \<And>xs. As \<Longrightarrow> (\<And>ys. Bs \<Longrightarrow> pred ss)\<^isup>* \<Longrightarrow> pred ts"} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
24 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
25 |
@{text [display] "orule ::= \<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> pred ss)\<^isup>* \<longrightarrow> pred ts"} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
26 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
27 |
@{text [display] "def ::= pred \<equiv> \<lambda>zs. \<forall>preds. orules \<longrightarrow> pred zs"} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
28 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
29 |
@{text [display] "ind ::= \<And>zs. pred zs \<Longrightarrow> rules[preds::=Ps] \<Longrightarrow> P zs"} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
30 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
31 |
@{text [display] "oind ::= \<forall>zs. pred zs \<longrightarrow> orules[preds::=Ps] \<longrightarrow> P zs"} |
189
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
32 |
|
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
33 |
\underline{Induction proof} |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
34 |
|
189
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
35 |
After ``objectivication'' we have |
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
36 |
@{text "pred zs"} and @{text "orules[preds::=Ps]"}; and have to show |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
37 |
@{text "P zs"}. Expanding @{text "pred zs"} gives @{text "\<forall>preds. orules \<longrightarrow> pred zs"}. |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
38 |
Instantiating the @{text "preds"} with @{text "Ps"} gives |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
39 |
@{text "orules[preds::=Ps] \<longrightarrow> P zs"}. So we can conclude with @{text "P zs"}. |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
40 |
|
189
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
41 |
\underline{Intro proof} |
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
42 |
|
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
43 |
Assume we want to prove the $i$th intro rule. |
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
44 |
|
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
45 |
We have to show @{text "\<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> pred ss)\<^isup>* \<longrightarrow> pred ts"}; |
189
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
46 |
expanding the defs, gives |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
47 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
48 |
@{text [display] |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
49 |
"\<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> (\<forall>preds. orules \<longrightarrow> pred ss))\<^isup>* \<longrightarrow> (\<forall>preds. orules \<longrightarrow> pred ts"} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
50 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
51 |
By applying as many allI and impI as possible, we have |
189
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
52 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
53 |
@{text "As"}, @{text "(\<forall>ys. Bs \<longrightarrow> (\<forall>preds. orules \<longrightarrow> pred ss))\<^isup>*"}, |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
54 |
@{text "orules"}; and have to show @{text "pred ts"} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
55 |
|
189
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
56 |
the $i$th @{text "orule"} is of the |
069d525f8f1d
made more of the transition from "CookBook" to "ProgTutorial"
Christian Urban <urbanc@in.tum.de>
parents:
186
diff
changeset
|
57 |
form @{text "\<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> pred ss)\<^isup>* \<longrightarrow> pred ts"}. |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
58 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
59 |
So we apply the $i$th @{text "orule"}, but we have to show the @{text "As"} (by assumption) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
60 |
and all @{text "(\<forall>ys. Bs \<longrightarrow> pred ss)\<^isup>*"}. For the latter we use the assumptions |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
61 |
@{text "(\<forall>ys. Bs \<longrightarrow> (\<forall>preds. orules \<longrightarrow> pred ss))\<^isup>*"} and @{text "orules"}. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
62 |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
63 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
64 |
|
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
65 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
66 |
text {* |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
67 |
First we have to produce for each predicate the definition of the form |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
68 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
69 |
@{text [display] "pred \<equiv> \<lambda>zs. \<forall>preds. orules \<longrightarrow> pred zs"} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
70 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
71 |
and then ``register'' the definitions with Isabelle. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
72 |
To do the latter, we use the following wrapper for |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
73 |
@{ML LocalTheory.define}. The wrapper takes a predicate name, a syntax |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
74 |
annotation and a term representing the right-hand side of the definition. |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
75 |
*} |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
76 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
77 |
ML %linenosgray{*fun make_defs ((predname, syn), trm) lthy = |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
78 |
let |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
79 |
val arg = ((predname, syn), (Attrib.empty_binding, trm)) |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
80 |
val ((_, (_ , thm)), lthy') = LocalTheory.define Thm.internalK arg lthy |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
81 |
in |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
82 |
(thm, lthy') |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
83 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
84 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
85 |
text {* |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
86 |
It returns the definition (as a theorem) and the local theory in which this definition has |
184 | 87 |
been made. In Line 4, @{ML internalK in Thm} is a flag attached to the |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
88 |
theorem (others possibilities are @{ML definitionK in Thm} and @{ML axiomK in Thm}). |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
89 |
These flags just classify theorems and have no significant meaning, except |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
90 |
for tools that, for example, find theorems in the theorem database. We also |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
91 |
use @{ML empty_binding in Attrib} in Line 3, since the definition does |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
92 |
not need to have any theorem attributes. A testcase for this function is |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
93 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
94 |
|
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
95 |
local_setup %gray {* fn lthy => |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
96 |
let |
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
97 |
val arg = ((@{binding "MyTrue"}, NoSyn), @{term True}) |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
98 |
val (def, lthy') = make_defs arg lthy |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
99 |
in |
194 | 100 |
warning (str_of_thm_no_vars lthy' def); lthy' |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
101 |
end *} |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
102 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
103 |
text {* |
184 | 104 |
which makes the definition @{prop "MyTrue \<equiv> True"} and then prints it out. |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
105 |
Since we are testing the function inside \isacommand{local\_setup}, i.e.~make |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
106 |
changes to the ambient theory, we can query the definition using the usual |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
107 |
command \isacommand{thm}: |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
108 |
|
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
109 |
\begin{isabelle} |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
110 |
\isacommand{thm}~@{text "MyTrue_def"}\\ |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
111 |
@{text "> MyTrue \<equiv> True"} |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
112 |
\end{isabelle} |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
113 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
114 |
The next two functions construct the right-hand sides of the definitions, which |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
115 |
are of the form |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
116 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
117 |
@{text [display] "\<lambda>zs. \<forall>preds. orules \<longrightarrow> pred zs"} |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
118 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
119 |
The variables @{text "zs"} need to be chosen so that they do not occur |
184 | 120 |
in the @{text orules} and also be distinct from the @{text "preds"}. |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
121 |
|
184 | 122 |
The first function constructs the term for one particular predicate, say |
123 |
@{text "pred"}; the number of arguments of this predicate is |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
124 |
determined by the number of argument types given in @{text "arg_tys"}. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
125 |
The other arguments are all @{text "preds"} and the @{text "orules"}. |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
126 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
127 |
|
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
128 |
ML %linenosgray{*fun defs_aux lthy orules preds (pred, arg_tys) = |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
129 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
130 |
fun mk_all x P = HOLogic.all_const (fastype_of x) $ lambda x P |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
131 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
132 |
val fresh_args = |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
133 |
arg_tys |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
134 |
|> map (pair "z") |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
135 |
|> Variable.variant_frees lthy (preds @ orules) |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
136 |
|> map Free |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
137 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
138 |
list_comb (pred, fresh_args) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
139 |
|> fold_rev (curry HOLogic.mk_imp) orules |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
140 |
|> fold_rev mk_all preds |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
141 |
|> fold_rev lambda fresh_args |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
142 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
143 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
144 |
text {* |
184 | 145 |
The function in Line 3 is just a helper function for constructing universal |
146 |
quantifications. The code in Lines 5 to 9 produces the fresh @{text |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
147 |
"zs"}. For this it pairs every argument type with the string |
184 | 148 |
@{text [quotes] "z"} (Line 7); then generates variants for all these strings |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
149 |
so that they are unique w.r.t.~to the predicates and @{text "orules"} (Line 8); |
184 | 150 |
in Line 9 it generates the corresponding variable terms for the unique |
151 |
strings. |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
152 |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
153 |
The unique free variables are applied to the predicate (Line 11) using the |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
154 |
function @{ML list_comb}; then the @{text orules} are prefixed (Line 12); in |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
155 |
Line 13 we quantify over all predicates; and in line 14 we just abstract |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
156 |
over all the @{text "zs"}, i.e.~the fresh arguments of the |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
157 |
predicate. A testcase for this function is |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
158 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
159 |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
160 |
local_setup %gray{* fn lthy => |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
161 |
let |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
162 |
val orules = [@{prop "even 0"}, |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
163 |
@{prop "\<forall>n::nat. odd n \<longrightarrow> even (Suc n)"}, |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
164 |
@{prop "\<forall>n::nat. even n \<longrightarrow> odd (Suc n)"}] |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
165 |
val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}] |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
166 |
val pred = @{term "even::nat\<Rightarrow>bool"} |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
167 |
val arg_tys = [@{typ "nat"}] |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
168 |
val def = defs_aux lthy orules preds (pred, arg_tys) |
173
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
169 |
in |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
170 |
warning (Syntax.string_of_term lthy def); lthy |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
171 |
end *} |
173
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
172 |
|
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
text {* |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
174 |
It calls @{ML defs_aux} for the definition of @{text "even"} and prints |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
175 |
out the definition. So we obtain as printout |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
176 |
|
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
177 |
@{text [display] |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
178 |
"\<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n)) |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
179 |
\<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> even z"} |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
180 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
181 |
The second function for the definitions has to just iterate the function |
184 | 182 |
@{ML defs_aux} over all predicates. The argument @{text "preds"} is again |
183 |
the the list of predicates as @{ML_type term}s; the argument @{text |
|
184 |
"prednames"} is the list of names of the predicates; @{text "arg_tyss"} is |
|
185 |
the list of argument-type-lists for each predicate. |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
186 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
187 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
188 |
ML %linenosgray{*fun definitions rules preds prednames syns arg_typss lthy = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
189 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
190 |
val thy = ProofContext.theory_of lthy |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
191 |
val orules = map (ObjectLogic.atomize_term thy) rules |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
192 |
val defs = map (defs_aux lthy orules preds) (preds ~~ arg_typss) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
193 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
194 |
fold_map make_defs (prednames ~~ syns ~~ defs) lthy |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
195 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
196 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
197 |
text {* |
184 | 198 |
The user will state the introduction rules using meta-implications and |
199 |
meta-quanti\-fications. In Line 4, we transform these introduction rules into |
|
200 |
the object logic (since definitions cannot be stated with |
|
201 |
meta-connectives). To do this transformation we have to obtain the theory |
|
202 |
behind the local theory (Line 3); with this theory we can use the function |
|
203 |
@{ML ObjectLogic.atomize_term} to make the transformation (Line 4). The call |
|
204 |
to @{ML defs_aux} in Line 5 produces all left-hand sides of the |
|
205 |
definitions. The actual definitions are then made in Line 7. The result |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
206 |
of the function is a list of theorems and a local theory. A testcase for |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
207 |
this function is |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
208 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
209 |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
210 |
local_setup %gray {* fn lthy => |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
211 |
let |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
212 |
val rules = [@{prop "even 0"}, |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
213 |
@{prop "\<And>n::nat. odd n \<Longrightarrow> even (Suc n)"}, |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
214 |
@{prop "\<And>n::nat. even n \<Longrightarrow> odd (Suc n)"}] |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
215 |
val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}] |
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
216 |
val prednames = [@{binding "even"}, @{binding "odd"}] |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
217 |
val syns = [NoSyn, NoSyn] |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
218 |
val arg_tyss = [[@{typ "nat"}], [@{typ "nat"}]] |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
219 |
val (defs, lthy') = definitions rules preds prednames syns arg_tyss lthy |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
220 |
in |
194 | 221 |
warning (str_of_thms_no_vars lthy' defs); lthy' |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
222 |
end *} |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
223 |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
224 |
text {* |
184 | 225 |
where we feed into the functions all parameters corresponding to |
226 |
the @{text even}-@{text odd} example. The definitions we obtain |
|
227 |
are: |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
228 |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
229 |
\begin{isabelle} |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
230 |
\isacommand{thm}~@{text "even_def odd_def"}\\ |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
231 |
@{text [break] |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
232 |
"> even \<equiv> \<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n)) |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
233 |
> \<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> even z, |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
234 |
> odd \<equiv> \<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n)) |
184 | 235 |
> \<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> odd z"} |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
236 |
\end{isabelle} |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
237 |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
238 |
|
184 | 239 |
This completes the code for making the definitions. Next we deal with |
240 |
the induction principles. Recall that the proof of the induction principle |
|
241 |
for @{text "even"} was: |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
242 |
*} |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
243 |
|
184 | 244 |
lemma man_ind_principle: |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
245 |
assumes prems: "even n" |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
246 |
shows "P 0 \<Longrightarrow> (\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P n" |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
247 |
apply(atomize (full)) |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
248 |
apply(cut_tac prems) |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
249 |
apply(unfold even_def) |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
250 |
apply(drule spec[where x=P]) |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
251 |
apply(drule spec[where x=Q]) |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
252 |
apply(assumption) |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
253 |
done |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
254 |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
255 |
text {* |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
256 |
The code for automating such induction principles has to accomplish two tasks: |
184 | 257 |
constructing the induction principles from the given introduction |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
258 |
rules and then automatically generating proofs for them using a tactic. |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
259 |
|
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
260 |
The tactic will use the following helper function for instantiating universal |
184 | 261 |
quantifiers. |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
262 |
*} |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
263 |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
264 |
ML{*fun inst_spec ctrm = |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
265 |
Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}*} |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
266 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
267 |
text {* |
184 | 268 |
This helper function instantiates the @{text "?x"} in the theorem |
269 |
@{thm spec} with a given @{ML_type cterm}. Together with the tactic |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
270 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
271 |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
272 |
ML{*fun inst_spec_tac ctrms = |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
273 |
EVERY' (map (dtac o inst_spec) ctrms)*} |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
274 |
|
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
275 |
text {* |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
276 |
we can use @{ML inst_spec_tac} in the following proof to instantiate the |
184 | 277 |
three quantifiers in the assumption. |
278 |
*} |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
279 |
|
184 | 280 |
lemma |
281 |
fixes P::"nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool" |
|
282 |
shows "\<forall>x y z. P x y z \<Longrightarrow> True" |
|
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
283 |
apply (tactic {* |
184 | 284 |
inst_spec_tac [@{cterm "a::nat"},@{cterm "b::nat"},@{cterm "c::nat"}] 1 *}) |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
285 |
txt {* |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
286 |
We obtain the goal state |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
287 |
|
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
288 |
\begin{minipage}{\textwidth} |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
289 |
@{subgoals} |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
290 |
\end{minipage}*} |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
291 |
(*<*)oops(*>*) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
292 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
293 |
text {* |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
294 |
Now the complete tactic for proving the induction principles can |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
295 |
be implemented as follows: |
163
2319cff107f0
removed rep_ss, and used dest_ss instead; some very slight changes to simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
296 |
*} |
2319cff107f0
removed rep_ss, and used dest_ss instead; some very slight changes to simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
297 |
|
180
9c25418db6f0
added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents:
179
diff
changeset
|
298 |
ML %linenosgray{*fun induction_tac defs prems insts = |
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
299 |
EVERY1 [ObjectLogic.full_atomize_tac, |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
300 |
cut_facts_tac prems, |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
301 |
K (rewrite_goals_tac defs), |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
302 |
inst_spec_tac insts, |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
303 |
assume_tac]*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
304 |
|
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
305 |
text {* |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
306 |
We only have to give it the definitions, the premise (like @{text "even n"}) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
307 |
and the instantiations as arguments. Compare this with the manual proof |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
308 |
given for the lemma @{thm [source] man_ind_principle}: there is almos a |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
309 |
one-to-one correspondence between the \isacommand{apply}-script and the |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
310 |
@{ML induction_tac}. A testcase for this tactic is the function |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
311 |
*} |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
312 |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
313 |
ML{*fun test_tac prems = |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
314 |
let |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
315 |
val defs = [@{thm even_def}, @{thm odd_def}] |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
316 |
val insts = [@{cterm "P::nat\<Rightarrow>bool"}, @{cterm "Q::nat\<Rightarrow>bool"}] |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
317 |
in |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
318 |
induction_tac defs prems insts |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
319 |
end*} |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
320 |
|
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
321 |
text {* |
184 | 322 |
which indeed proves the induction principle: |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
323 |
*} |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
324 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
325 |
lemma auto_ind_principle: |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
326 |
assumes prems: "even n" |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
327 |
shows "P 0 \<Longrightarrow> (\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P n" |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
328 |
apply(tactic {* test_tac @{thms prems} *}) |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
329 |
done |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
330 |
|
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
331 |
text {* |
184 | 332 |
While the tactic for the induction principle is relatively simple, |
333 |
it is a bit harder to construct the goals from the introduction |
|
334 |
rules the user provides. In general we have to construct for each predicate |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
335 |
@{text "pred"} a goal of the form |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
336 |
|
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
337 |
@{text [display] |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
338 |
"pred ?zs \<Longrightarrow> rules[preds := ?Ps] \<Longrightarrow> ?P$ ?zs"} |
180
9c25418db6f0
added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents:
179
diff
changeset
|
339 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
340 |
where the predicates @{text preds} are replaced in the introduction |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
341 |
rules by new distinct variables written @{text "Ps"}. |
184 | 342 |
We also need to generate fresh arguments for the predicate @{text "pred"} in |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
343 |
the premise and the @{text "?P"} in the conclusion. Note |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
344 |
that the @{text "?Ps"} and @{text "?zs"} need to be |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
345 |
schematic variables that can be instantiated. This corresponds to what the |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
346 |
@{thm [source] auto_ind_principle} looks like: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
347 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
348 |
\begin{isabelle} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
349 |
\isacommand{thm}~@{thm [source] auto_ind_principle}\\ |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
350 |
@{text "> \<lbrakk>even ?n; ?P 0; \<And>m. ?Q m \<Longrightarrow> ?P (Suc m); \<And>m. ?P m \<Longrightarrow> ?Q (Suc m)\<rbrakk> \<Longrightarrow> ?P ?n"} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
351 |
\end{isabelle} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
352 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
353 |
We achieve |
184 | 354 |
that in two steps. |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
355 |
|
184 | 356 |
The function below expects that the introduction rules are already appropriately |
357 |
substituted. The argument @{text "srules"} stands for these substituted |
|
358 |
rules; @{text cnewpreds} are the certified terms coresponding |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
359 |
to the variables @{text "Ps"}; @{text "pred"} is the predicate for |
180
9c25418db6f0
added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents:
179
diff
changeset
|
360 |
which we prove the introduction principle; @{text "newpred"} is its |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
361 |
replacement and @{text "tys"} are the argument types of this predicate. |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
362 |
*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
363 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
364 |
ML %linenosgray{*fun prove_induction lthy defs srules cnewpreds ((pred, newpred), arg_tys) = |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
365 |
let |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
366 |
val zs = replicate (length arg_tys) "z" |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
367 |
val (newargnames, lthy') = Variable.variant_fixes zs lthy; |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
368 |
val newargs = map Free (newargnames ~~ arg_tys) |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
369 |
|
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
370 |
val prem = HOLogic.mk_Trueprop (list_comb (pred, newargs)) |
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
371 |
val goal = Logic.list_implies |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
372 |
(srules, HOLogic.mk_Trueprop (list_comb (newpred, newargs))) |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
373 |
in |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
374 |
Goal.prove lthy' [] [prem] goal |
178
fb8f22dd8ad0
adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents:
177
diff
changeset
|
375 |
(fn {prems, ...} => induction_tac defs prems cnewpreds) |
179
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
376 |
|> singleton (ProofContext.export lthy' lthy) |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
377 |
end *} |
75381fa516cd
more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents:
178
diff
changeset
|
378 |
|
180
9c25418db6f0
added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents:
179
diff
changeset
|
379 |
text {* |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
380 |
In Line 3 we produce names @{text "zs"} for each type in the |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
381 |
argument type list. Line 4 makes these names unique and declares them as |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
382 |
\emph{free} (but fixed) variables in the local theory @{text "lthy'"}. In |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
383 |
Line 5 we just construct the terms corresponding to these variables. |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
384 |
The term variables are applied to the predicate in Line 7 (this corresponds |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
385 |
to the first premise @{text "pred zs"} of the induction principle). |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
386 |
In Line 8 and 9, we first construct the term @{text "P zs"} |
184 | 387 |
and then add the (substituded) introduction rules as premises. In case that |
388 |
no introduction rules are given, the conclusion of this implication needs |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
389 |
to be wrapped inside a @{term Trueprop}, otherwise the Isabelle's goal |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
390 |
mechanism will fail. |
180
9c25418db6f0
added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents:
179
diff
changeset
|
391 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
392 |
In Line 11 we set up the goal to be proved; in the next line we call the tactic |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
393 |
for proving the induction principle. This tactic expects the definitions, the |
184 | 394 |
premise and the (certified) predicates with which the introduction rules |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
395 |
have been substituted. The code in these two lines will return a theorem. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
396 |
However, it is a theorem |
184 | 397 |
proved inside the local theory @{text "lthy'"}, where the variables @{text |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
398 |
"zs"} are fixed, but free. By exporting this theorem from @{text |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
399 |
"lthy'"} (which contains the @{text "zs"} as free) to @{text |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
400 |
"lthy"} (which does not), we obtain the desired schematic variables. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
401 |
*} |
180
9c25418db6f0
added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents:
179
diff
changeset
|
402 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
403 |
local_setup %gray{* fn lthy => |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
404 |
let |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
405 |
val defs = [@{thm even_def}, @{thm odd_def}] |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
406 |
val srules = [@{prop "P (0::nat)"}, |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
407 |
@{prop "\<And>n::nat. Q n \<Longrightarrow> P (Suc n)"}, |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
408 |
@{prop "\<And>n::nat. P n \<Longrightarrow> Q (Suc n)"}] |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
409 |
val cnewpreds = [@{cterm "P::nat\<Rightarrow>bool"}, @{cterm "Q::nat\<Rightarrow>bool"}] |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
410 |
val pred = @{term "even::nat\<Rightarrow>bool"} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
411 |
val newpred = @{term "P::nat\<Rightarrow>bool"} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
412 |
val arg_tys = [@{typ "nat"}] |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
413 |
val intro = |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
414 |
prove_induction lthy defs srules cnewpreds ((pred, newpred), arg_tys) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
415 |
in |
194 | 416 |
warning (str_of_thm lthy intro); lthy |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
417 |
end *} |
184 | 418 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
419 |
text {* |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
420 |
This prints out: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
421 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
422 |
@{text [display] |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
423 |
" \<lbrakk>even ?z; P 0; \<And>n. Q n \<Longrightarrow> P (Suc n); \<And>n. P n \<Longrightarrow> Q (Suc n)\<rbrakk> \<Longrightarrow> P ?z"} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
424 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
425 |
Note that the export from @{text lthy'} to @{text lthy} in Line 13 above |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
426 |
has turned the free, but fixed, @{text "z"} into a schematic |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
427 |
variable @{text "?z"}. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
428 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
429 |
We still have to produce the new predicates with which the introduction |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
430 |
rules are substituted and iterate @{ML prove_induction} over all |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
431 |
predicates. This is what the next function does. |
180
9c25418db6f0
added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents:
179
diff
changeset
|
432 |
*} |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
433 |
|
184 | 434 |
ML %linenosgray{*fun inductions rules defs preds arg_tyss lthy = |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
435 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
436 |
val Ps = replicate (length preds) "P" |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
437 |
val (newprednames, lthy') = Variable.variant_fixes Ps lthy |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
438 |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
439 |
val thy = ProofContext.theory_of lthy' |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
440 |
|
184 | 441 |
val tyss' = map (fn tys => tys ---> HOLogic.boolT) arg_tyss |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
442 |
val newpreds = map Free (newprednames ~~ tyss') |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
443 |
val cnewpreds = map (cterm_of thy) newpreds |
184 | 444 |
val srules = map (subst_free (preds ~~ newpreds)) rules |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
445 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
446 |
in |
184 | 447 |
map (prove_induction lthy' defs srules cnewpreds) |
448 |
(preds ~~ newpreds ~~ arg_tyss) |
|
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
449 |
|> ProofContext.export lthy' lthy |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
450 |
end*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
451 |
|
184 | 452 |
text {* |
453 |
In Line 3 we generate a string @{text [quotes] "P"} for each predicate. |
|
454 |
In Line 4, we use the same trick as in the previous function, that is making the |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
455 |
@{text "Ps"} fresh and declaring them as fixed, but free, in |
184 | 456 |
the new local theory @{text "lthy'"}. From the local theory we extract |
457 |
the ambient theory in Line 6. We need this theory in order to certify |
|
458 |
the new predicates. In Line 8 we calculate the types of these new predicates |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
459 |
using the given argument types. Next we turn them into terms and subsequently |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
460 |
certify them (Line 9 and 10). We can now produce the substituted introduction rules |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
461 |
(Line 11) using the function @{ML subst_free}. Line 14 and 15 just iterate |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
462 |
the proofs for all predicates. |
184 | 463 |
From this we obtain a list of theorems. Finally we need to export the |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
464 |
fixed variables @{text "Ps"} to obtain the schematic variables |
184 | 465 |
(Line 16). |
466 |
||
467 |
A testcase for this function is |
|
468 |
*} |
|
469 |
||
470 |
local_setup %gray {* fn lthy => |
|
471 |
let |
|
472 |
val rules = [@{prop "even (0::nat)"}, |
|
473 |
@{prop "\<And>n::nat. odd n \<Longrightarrow> even (Suc n)"}, |
|
474 |
@{prop "\<And>n::nat. even n \<Longrightarrow> odd (Suc n)"}] |
|
475 |
val defs = [@{thm even_def}, @{thm odd_def}] |
|
476 |
val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}] |
|
477 |
val tyss = [[@{typ "nat"}], [@{typ "nat"}]] |
|
478 |
val ind_thms = inductions rules defs preds tyss lthy |
|
479 |
in |
|
194 | 480 |
warning (str_of_thms lthy ind_thms); lthy |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
481 |
end *} |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
482 |
|
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
483 |
|
184 | 484 |
text {* |
485 |
which prints out |
|
486 |
||
487 |
@{text [display] |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
488 |
"> even ?z \<Longrightarrow> ?P1 0 \<Longrightarrow> |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
489 |
> (\<And>m. ?Pa1 m \<Longrightarrow> ?P1 (Suc m)) \<Longrightarrow> (\<And>m. ?P1 m \<Longrightarrow> ?Pa1 (Suc m)) \<Longrightarrow> ?P1 ?z, |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
490 |
> odd ?z \<Longrightarrow> ?P1 0 |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
491 |
> \<Longrightarrow> (\<And>m. ?Pa1 m \<Longrightarrow> ?P1 (Suc m)) \<Longrightarrow> (\<And>m. ?P1 m \<Longrightarrow> ?Pa1 (Suc m)) \<Longrightarrow> ?Pa1 ?z"} |
184 | 492 |
|
493 |
||
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
494 |
Note that now both, the @{text "Ps"} and the @{text "zs"}, are schematic |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
495 |
variables. The numbers have been introduced by the pretty-printer and are |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
496 |
not significant. |
184 | 497 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
498 |
This completes the code for the induction principles. Finally we can prove the |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
499 |
introduction rules. Their proofs are quite a bit more involved. To ease them |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
500 |
somewhat we use the following two helper function. |
184 | 501 |
*} |
502 |
||
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
503 |
ML{*val all_elims = fold (fn ct => fn th => th RS inst_spec ct) |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
504 |
val imp_elims = fold (fn th => fn th' => [th', th] MRS @{thm mp})*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
505 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
506 |
text {* |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
507 |
To see what they do, let us suppose whe have the follwoing three |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
508 |
theorems. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
509 |
*} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
510 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
511 |
lemma all_elims_test: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
512 |
fixes P::"nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
513 |
shows "\<forall>x y z. P x y z" sorry |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
514 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
515 |
lemma imp_elims_test: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
516 |
fixes A B C::"bool" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
517 |
shows "A \<longrightarrow> B \<longrightarrow> C" sorry |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
518 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
519 |
lemma imp_elims_test': |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
520 |
fixes A::"bool" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
521 |
shows "A" "B" sorry |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
522 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
523 |
text {* |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
524 |
The function @{ML all_elims} takes a list of (certified) terms and instantiates |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
525 |
theorems of the form @{thm [source] all_elims_test}. For example we can instantiate |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
526 |
the quantifiers in this theorem with @{term a}, @{term b} and @{term c} as follows |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
527 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
528 |
@{ML_response_fake [display, gray] |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
529 |
"let |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
530 |
val ctrms = [@{cterm \"a::nat\"}, @{cterm \"b::nat\"}, @{cterm \"c::nat\"}] |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
531 |
val new_thm = all_elims ctrms @{thm all_elims_test} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
532 |
in |
194 | 533 |
warning (str_of_thm_no_vars @{context} new_thm) |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
534 |
end" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
535 |
"P a b c"} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
536 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
537 |
Similarly, the function @{ML imp_elims} eliminates preconditions from implications. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
538 |
For example |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
539 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
540 |
@{ML_response_fake [display, gray] |
194 | 541 |
"warning (str_of_thm_no_vars @{context} |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
542 |
(imp_elims @{thms imp_elims_test'} @{thm imp_elims_test}))" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
543 |
"C"} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
544 |
*} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
545 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
546 |
ML {* prems_of *} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
547 |
ML {* Logic.strip_params *} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
548 |
ML {* Logic.strip_assums_hyp *} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
549 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
550 |
ML {* |
192 | 551 |
fun chop_print_tac m n ctxt thm = |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
552 |
let |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
553 |
val [trm] = prems_of thm |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
554 |
val params = map fst (Logic.strip_params trm) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
555 |
val prems = Logic.strip_assums_hyp trm |
192 | 556 |
val (prems1, prems2) = chop (length prems - m) prems; |
557 |
val (params1, params2) = chop (length params - n) params; |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
558 |
val _ = warning (Syntax.string_of_term ctxt trm) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
559 |
val _ = warning (commas params) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
560 |
val _ = warning (commas (map (Syntax.string_of_term ctxt) prems)) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
561 |
val _ = warning ((commas params1) ^ " | " ^ (commas params2)) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
562 |
val _ = warning ((commas (map (Syntax.string_of_term ctxt) prems1)) ^ " | " ^ |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
563 |
(commas (map (Syntax.string_of_term ctxt) prems2))) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
564 |
in |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
565 |
Seq.single thm |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
566 |
end |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
567 |
*} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
568 |
|
192 | 569 |
ML {* METAHYPS *} |
570 |
||
571 |
ML {* |
|
572 |
fun chop_print_tac2 ctxt prems = |
|
573 |
let |
|
194 | 574 |
val _ = warning (commas (map (str_of_thm_no_vars ctxt) prems)) |
192 | 575 |
in |
576 |
all_tac |
|
577 |
end |
|
578 |
*} |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
579 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
580 |
lemma intro1: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
581 |
shows "\<And>m. odd m \<Longrightarrow> even (Suc m)" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
582 |
apply(tactic {* ObjectLogic.rulify_tac 1 *}) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
583 |
apply(tactic {* rewrite_goals_tac [@{thm even_def}, @{thm odd_def}] *}) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
584 |
apply(tactic {* REPEAT (resolve_tac [@{thm allI}, @{thm impI}] 1) *}) |
192 | 585 |
apply(tactic {* chop_print_tac 3 2 @{context} *}) |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
586 |
oops |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
587 |
|
192 | 588 |
ML {* |
589 |
fun SUBPROOF_test tac ctxt = |
|
590 |
SUBPROOF (fn {params, prems, context,...} => |
|
591 |
let |
|
592 |
val thy = ProofContext.theory_of context |
|
593 |
in |
|
594 |
tac (params, prems, context) |
|
595 |
THEN Method.insert_tac prems 1 |
|
596 |
THEN print_tac "SUBPROOF Test" |
|
597 |
THEN SkipProof.cheat_tac thy |
|
598 |
end) ctxt 1 |
|
599 |
*} |
|
600 |
||
601 |
||
602 |
||
603 |
||
604 |
lemma fresh_App: |
|
605 |
shows "\<And>a t s. \<lbrakk>a\<sharp>t; a\<sharp>s\<rbrakk> \<Longrightarrow> a\<sharp>App t s" |
|
606 |
apply(tactic {* ObjectLogic.rulify_tac 1 *}) |
|
607 |
apply(tactic {* rewrite_goals_tac [@{thm fresh_def}] *}) |
|
608 |
apply(tactic {* REPEAT (resolve_tac [@{thm allI}, @{thm impI}] 1) *}) |
|
609 |
oops |
|
610 |
(* |
|
611 |
apply(tactic {* SUBPROOF_test |
|
612 |
(fn (params, prems, ctxt) => |
|
613 |
let |
|
614 |
val (prems1, prems2) = chop (length prems - 4) prems; |
|
615 |
val (params1, params2) = chop (length params - 1) params; |
|
616 |
in |
|
617 |
rtac (ObjectLogic.rulify (all_elims params1 (nth prems2 2))) 1 |
|
618 |
end) @{context} *}) |
|
619 |
*) |
|
620 |
||
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
621 |
ML{*fun subproof2 prem params2 prems2 = |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
622 |
SUBPROOF (fn {prems, ...} => |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
623 |
let |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
624 |
val prem' = prems MRS prem; |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
625 |
val prem'' = |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
626 |
case prop_of prem' of |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
627 |
_ $ (Const (@{const_name All}, _) $ _) => |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
628 |
prem' |> all_elims params2 |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
629 |
|> imp_elims prems2 |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
630 |
| _ => prem'; |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
631 |
in |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
632 |
rtac prem'' 1 |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
633 |
end)*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
634 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
635 |
text {* |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
636 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
637 |
*} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
638 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
639 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
640 |
ML %linenosgray{*fun subproof1 rules preds i = |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
641 |
SUBPROOF (fn {params, prems, context = ctxt', ...} => |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
642 |
let |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
643 |
val (prems1, prems2) = chop (length prems - length rules) prems; |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
644 |
val (params1, params2) = chop (length params - length preds) params; |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
645 |
in |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
646 |
rtac (ObjectLogic.rulify (all_elims params1 (nth prems2 i))) 1 |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
647 |
(* applicateion of the i-ith intro rule *) |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
648 |
THEN |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
649 |
EVERY1 (map (fn prem => subproof2 prem params2 prems2 ctxt') prems1) |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
650 |
end)*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
651 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
652 |
text {* |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
653 |
@{text "params1"} are the variables of the rules; @{text "params2"} is |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
654 |
the variables corresponding to the @{text "preds"}. |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
655 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
656 |
@{text "prems1"} are the assumption corresponding to the rules; |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
657 |
@{text "prems2"} are the assumptions coming from the allIs/impIs |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
658 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
659 |
you instantiate the parameters i-th introduction rule with the parameters |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
660 |
that come from the rule; and you apply it to the goal |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
661 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
662 |
this now generates subgoals corresponding to the premisses of this |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
663 |
intro rule |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
664 |
*} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
665 |
|
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
666 |
ML{* |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
667 |
fun intros_tac defs rules preds i ctxt = |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
668 |
EVERY1 [ObjectLogic.rulify_tac, |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
669 |
K (rewrite_goals_tac defs), |
184 | 670 |
REPEAT o (resolve_tac [@{thm allI}, @{thm impI}]), |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
671 |
subproof1 rules preds i ctxt]*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
672 |
|
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
673 |
text {* |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
674 |
A test case |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
675 |
*} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
676 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
677 |
ML{*fun intros_tac_test ctxt i = |
173
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
678 |
let |
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
679 |
val rules = [@{prop "even (0::nat)"}, |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
680 |
@{prop "\<And>n::nat. odd n \<Longrightarrow> even (Suc n)"}, |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
681 |
@{prop "\<And>n::nat. even n \<Longrightarrow> odd (Suc n)"}] |
173
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
682 |
val defs = [@{thm even_def}, @{thm odd_def}] |
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
683 |
val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}] |
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
684 |
in |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
685 |
intros_tac defs rules preds i ctxt |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
686 |
end*} |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
687 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
688 |
lemma intro0: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
689 |
shows "even 0" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
690 |
apply(tactic {* intros_tac_test @{context} 0 *}) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
691 |
done |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
692 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
693 |
lemma intro1: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
694 |
shows "\<And>m. odd m \<Longrightarrow> even (Suc m)" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
695 |
apply(tactic {* intros_tac_test @{context} 1 *}) |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
696 |
done |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
697 |
|
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
698 |
lemma intro2: |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
699 |
shows "\<And>m. even m \<Longrightarrow> odd (Suc m)" |
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
700 |
apply(tactic {* intros_tac_test @{context} 2 *}) |
173
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
701 |
done |
d820cb5873ea
used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
702 |
|
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
703 |
ML{*fun introductions rules preds defs lthy = |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
704 |
let |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
705 |
fun prove_intro (i, goal) = |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
706 |
Goal.prove lthy [] [] goal |
190
ca0ac2e75f6d
more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
707 |
(fn {context, ...} => intros_tac defs rules preds i context) |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
708 |
in |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
709 |
map_index prove_intro rules |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
710 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
711 |
|
176
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
712 |
text {* main internal function *} |
3da5f3f07d8b
updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents:
173
diff
changeset
|
713 |
|
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
714 |
ML %linenosgray{*fun add_inductive pred_specs rule_specs lthy = |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
715 |
let |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
716 |
val syns = map snd pred_specs |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
717 |
val pred_specs' = map fst pred_specs |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
718 |
val prednames = map fst pred_specs' |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
719 |
val preds = map (fn (p, ty) => Free (Binding.name_of p, ty)) pred_specs' |
163
2319cff107f0
removed rep_ss, and used dest_ss instead; some very slight changes to simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
124
diff
changeset
|
720 |
|
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
721 |
val tyss = map (binder_types o fastype_of) preds |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
722 |
val (attrs, rules) = split_list rule_specs |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
723 |
|
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
724 |
val (defs, lthy') = definitions rules preds prednames syns tyss lthy |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
725 |
val ind_rules = inductions rules defs preds tyss lthy' |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
726 |
val intro_rules = introductions rules preds defs lthy' |
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
727 |
|
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
728 |
val mut_name = space_implode "_" (map Binding.name_of prednames) |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
729 |
val case_names = map (Binding.name_of o fst) attrs |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
730 |
in |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
731 |
lthy' |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
732 |
|> LocalTheory.notes Thm.theoremK (map (fn (((a, atts), _), th) => |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
733 |
((Binding.qualify false mut_name a, atts), [([th], [])])) (rule_specs ~~ intro_rules)) |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
734 |
|-> (fn intross => LocalTheory.note Thm.theoremK |
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
735 |
((Binding.qualify false mut_name (@{binding "intros"}), []), maps snd intross)) |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
736 |
|>> snd |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
737 |
||>> (LocalTheory.notes Thm.theoremK (map (fn (((R, _), _), th) => |
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
738 |
((Binding.qualify false (Binding.name_of R) (@{binding "induct"}), |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
739 |
[Attrib.internal (K (RuleCases.case_names case_names)), |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
740 |
Attrib.internal (K (RuleCases.consumes 1)), |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
741 |
Attrib.internal (K (Induct.induct_pred ""))]), [([th], [])])) |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
742 |
(pred_specs ~~ ind_rules)) #>> maps snd) |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
743 |
|> snd |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
744 |
end*} |
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
745 |
|
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
746 |
ML{*fun add_inductive_cmd pred_specs rule_specs lthy = |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
747 |
let |
183
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
748 |
val ((pred_specs', rule_specs'), _) = |
8bb4eaa2ec92
a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents:
180
diff
changeset
|
749 |
Specification.read_spec pred_specs rule_specs lthy |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
750 |
in |
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
751 |
add_inductive pred_specs' rule_specs' lthy |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
752 |
end*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
753 |
|
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
754 |
ML{*val spec_parser = |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
755 |
OuterParse.fixes -- |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
756 |
Scan.optional |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
757 |
(OuterParse.$$$ "where" |-- |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
758 |
OuterParse.!!! |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
759 |
(OuterParse.enum1 "|" |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
760 |
(SpecParse.opt_thm_name ":" -- OuterParse.prop))) []*} |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
761 |
|
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
762 |
ML{*val specification = |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
763 |
spec_parser >> |
186
371e4375c994
made the Ackermann function example safer and included suggestions from MW
Christian Urban <urbanc@in.tum.de>
parents:
185
diff
changeset
|
764 |
(fn ((pred_specs), rule_specs) => add_inductive_cmd pred_specs rule_specs)*} |
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
765 |
|
185 | 766 |
ML{*val _ = OuterSyntax.local_theory "simple_inductive" |
767 |
"define inductive predicates" |
|
768 |
OuterKeyword.thy_decl specification*} |
|
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
769 |
|
124
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
770 |
text {* |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
771 |
Things to include at the end: |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
772 |
|
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
773 |
\begin{itemize} |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
774 |
\item say something about add-inductive-i to return |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
775 |
the rules |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
776 |
\item say that the induction principle is weaker (weaker than |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
777 |
what the standard inductive package generates) |
192 | 778 |
\item say that no conformity test is done |
124
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
779 |
\end{itemize} |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
780 |
|
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
781 |
*} |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
782 |
|
165
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
783 |
simple_inductive |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
784 |
Even and Odd |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
785 |
where |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
786 |
Even0: "Even 0" |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
787 |
| EvenS: "Odd n \<Longrightarrow> Even (Suc n)" |
890fbfef6d6b
partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
164
diff
changeset
|
788 |
| OddS: "Even n \<Longrightarrow> Odd (Suc n)" |
124
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
789 |
|
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
790 |
end |