author | Christian Urban <urbanc@in.tum.de> |
Tue, 10 Mar 2009 13:20:46 +0000 | |
changeset 164 | 3f617d7a2691 |
parent 163 | 2319cff107f0 |
child 165 | 890fbfef6d6b |
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 |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
2 |
imports "../Base" 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 |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
5 |
section {* Code *} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
6 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
7 |
subsection {* Definitions *} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
8 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
9 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
10 |
If we give it a term and a constant name, it will define the |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
11 |
constant as the term. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
12 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
13 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
14 |
ML{*fun make_defs ((binding, syn), trm) lthy = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
15 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
16 |
val arg = ((binding, syn), (Attrib.empty_binding, trm)) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
17 |
val ((_, (_ , thm)), lthy) = LocalTheory.define Thm.internalK arg lthy |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
18 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
19 |
(thm, lthy) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
20 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
21 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
22 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
23 |
Returns the definition and the local theory in which this definition has |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
24 |
been made. What is @{ML Thm.internalK}? |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
25 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
26 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
27 |
ML {*let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
28 |
val lthy = TheoryTarget.init NONE @{theory} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
29 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
30 |
make_defs ((Binding.name "MyTrue", NoSyn), @{term "True"}) lthy |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
31 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
32 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
33 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
34 |
Why is the output of MyTrue blue? |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
35 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
36 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
37 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
38 |
Constructs the term for the definition: the main arguments are a predicate |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
39 |
and the types of the arguments, it also expects orules which are the |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
40 |
intro rules in the object logic; preds which are all predicates. returns the |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
41 |
term. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
42 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
43 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
44 |
ML %linenosgray{*fun defs_aux lthy orules preds (pred, arg_types) = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
45 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
46 |
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
|
47 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
48 |
val fresh_args = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
49 |
arg_types |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
50 |
|> map (pair "z") |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
51 |
|> Variable.variant_frees lthy orules |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
52 |
|> map Free |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
53 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
54 |
list_comb (pred, fresh_args) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
55 |
|> fold_rev (curry HOLogic.mk_imp) orules |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
56 |
|> fold_rev mk_all preds |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
57 |
|> fold_rev lambda fresh_args |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
58 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
59 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
60 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
61 |
The lines 5-9 produce fresh arguments with which the predicate can be applied. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
62 |
For this it pairs every type with a string @{text [quotes] "z"} (Line 7); then |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
63 |
generates variants for all these strings (names) so that they are unique w.r.t.~to |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
64 |
the intro rules; in Line 9 it generates the corresponding variable terms for these |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
65 |
unique names. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
66 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
67 |
The unique free variables are applied to the predicate (Line 11); then |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
68 |
the intro rules are attached as preconditions (Line 12); in Line 13 we |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
69 |
quantify over all predicates; and in line 14 we just abstract over all |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
70 |
the (fresh) arguments of the predicate. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
71 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
72 |
|
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
text {* |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
74 |
The arguments of the main function for the definitions are |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
75 |
the intro rules; the predicates and their names, their syntax |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
76 |
annotations and the argument types of each predicate. It |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
77 |
returns a theorem list (the definitions) and a local |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
78 |
theory where the definitions are made |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
79 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
80 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
81 |
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
|
82 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
83 |
val thy = ProofContext.theory_of lthy |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
84 |
val orules = map (ObjectLogic.atomize_term thy) rules |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
85 |
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
|
86 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
87 |
fold_map make_defs (prednames ~~ syns ~~ defs) lthy |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
88 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
89 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
90 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
91 |
In line 4 we generate the intro rules in the object logic; for this we have to |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
92 |
obtain the theory behind the local theory (Line 3); with this we can |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
93 |
call @{ML defs_aux} to generate the terms for the left-hand sides. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
94 |
The actual definitions are made in Line 7. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
95 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
96 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
97 |
subsection {* Introduction Rules *} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
98 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
99 |
ML{*fun inst_spec ct = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
100 |
Drule.instantiate' [SOME (ctyp_of_term ct)] [NONE, SOME ct] @{thm spec}*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
101 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
102 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
103 |
Instantiates the @{text "x"} in @{thm spec[no_vars]} with a @{ML_type cterm}. |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
104 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
105 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
106 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
107 |
Instantiates universal qantifications in the premises |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
108 |
*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
109 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
110 |
lemma "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. P (x\<^isub>1::nat) (x\<^isub>2::nat) (x\<^isub>3::nat) \<Longrightarrow> True" |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
111 |
apply (tactic {* EVERY' (map (dtac o inst_spec) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
112 |
[@{cterm "y\<^isub>1::nat"},@{cterm "y\<^isub>2::nat"},@{cterm "y\<^isub>3::nat"}]) 1*}) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
113 |
(*<*)oops(*>*) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
114 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
115 |
text {* |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
116 |
The tactic for proving the induction rules: |
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
|
117 |
*} |
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
|
118 |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
119 |
ML{*fun induction_tac defs prems insts = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
120 |
EVERY1 [ObjectLogic.full_atomize_tac, |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
121 |
cut_facts_tac prems, |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
122 |
K (rewrite_goals_tac defs), |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
123 |
EVERY' (map (dtac o inst_spec) insts), |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
124 |
assume_tac]*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
125 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
126 |
lemma |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
127 |
assumes asm: "even n" |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
128 |
shows "P 0 \<Longrightarrow> |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
129 |
(\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P n" |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
130 |
apply(tactic {* induction_tac [@{thm even_def}, @{thm odd_def}] [@{thm asm}] |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
131 |
[@{cterm "P::nat\<Rightarrow>bool"}, @{cterm "Q::nat\<Rightarrow>bool"}] *}) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
132 |
done |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
133 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
134 |
ML %linenosgray{*fun inductions rules defs preds Tss lthy1 = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
135 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
136 |
val Ps = replicate (length preds) "P" |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
137 |
val (newprednames, lthy2) = Variable.variant_fixes Ps lthy1 |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
138 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
139 |
val thy = ProofContext.theory_of lthy2 |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
140 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
141 |
val Tss' = map (fn Ts => Ts ---> HOLogic.boolT) Tss |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
142 |
val newpreds = map Free (newprednames ~~ Tss') |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
143 |
val cnewpreds = map (cterm_of thy) newpreds |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
144 |
val rules' = map (subst_free (preds ~~ newpreds)) rules |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
145 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
146 |
fun prove_induction ((pred, newpred), Ts) = |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
147 |
let |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
148 |
val zs = replicate (length Ts) "z" |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
149 |
val (newargnames, lthy3) = Variable.variant_fixes zs lthy2; |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
150 |
val newargs = map Free (newargnames ~~ Ts) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
151 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
152 |
val prem = HOLogic.mk_Trueprop (list_comb (pred, newargs)) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
153 |
val goal = Logic.list_implies |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
154 |
(rules', HOLogic.mk_Trueprop (list_comb (newpred, newargs))) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
155 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
156 |
Goal.prove lthy3 [] [prem] goal |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
157 |
(fn {prems, ...} => induction_tac defs prems cnewpreds) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
158 |
|> singleton (ProofContext.export lthy3 lthy1) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
159 |
end |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
160 |
in |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
161 |
map prove_induction (preds ~~ newpreds ~~ Tss) |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
162 |
end*} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
163 |
|
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
164 |
ML {* Goal.prove *} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
165 |
ML {* singleton *} |
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
166 |
ML {* ProofContext.export *} |
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
|
167 |
|
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
|
168 |
text {* |
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
169 |
|
118
5f003fdf2653
polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
110
diff
changeset
|
170 |
*} |
5f003fdf2653
polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
110
diff
changeset
|
171 |
|
5f003fdf2653
polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents:
110
diff
changeset
|
172 |
text {* |
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
173 |
@{ML_chunk [display,gray] subproof1} |
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
174 |
|
164
3f617d7a2691
more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents:
163
diff
changeset
|
175 |
@{ML_chunk [display,gray] subproof2} |
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
176 |
|
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
177 |
@{ML_chunk [display,gray] intro_rules} |
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
178 |
|
124
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
179 |
|
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
180 |
*} |
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
181 |
|
124
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
182 |
text {* |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
183 |
Things to include at the end: |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
184 |
|
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
185 |
\begin{itemize} |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
186 |
\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
|
187 |
the rules |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
188 |
\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
|
189 |
what the standard inductive package generates) |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
190 |
\end{itemize} |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
191 |
|
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
192 |
*} |
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
193 |
|
0b9fa606a746
added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents:
118
diff
changeset
|
194 |
|
91
667a0943c40b
added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
195 |
end |