| author | popescua |
| Tue, 28 May 2013 13:19:51 +0200 | |
| changeset 52199 | d25fc4c0ff62 |
| parent 51717 | 9e7d1c139569 |
| child 54742 | 7a86358a3c0b |
| permissions | -rw-r--r-- |
| 42151 | 1 |
(* Title: HOL/HOLCF/Tools/Domain/domain_take_proofs.ML |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
2 |
Author: Brian Huffman |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
3 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
4 |
Defines take functions for the given domain equation |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
5 |
and proves related theorems. |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
6 |
*) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
7 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
8 |
signature DOMAIN_TAKE_PROOFS = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
9 |
sig |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
10 |
type iso_info = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
11 |
{
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
12 |
absT : typ, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
13 |
repT : typ, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
14 |
abs_const : term, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
15 |
rep_const : term, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
16 |
abs_inverse : thm, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
17 |
rep_inverse : thm |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
18 |
} |
| 35651 | 19 |
type take_info = |
| 35659 | 20 |
{
|
21 |
take_consts : term list, |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
22 |
take_defs : thm list, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
23 |
chain_take_thms : thm list, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
24 |
take_0_thms : thm list, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
25 |
take_Suc_thms : thm list, |
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
26 |
deflation_take_thms : thm list, |
| 40015 | 27 |
take_strict_thms : thm list, |
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
28 |
finite_consts : term list, |
|
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
29 |
finite_defs : thm list |
| 35651 | 30 |
} |
| 35656 | 31 |
type take_induct_info = |
32 |
{
|
|
| 35659 | 33 |
take_consts : term list, |
34 |
take_defs : thm list, |
|
35 |
chain_take_thms : thm list, |
|
36 |
take_0_thms : thm list, |
|
37 |
take_Suc_thms : thm list, |
|
38 |
deflation_take_thms : thm list, |
|
| 40015 | 39 |
take_strict_thms : thm list, |
| 35659 | 40 |
finite_consts : term list, |
41 |
finite_defs : thm list, |
|
42 |
lub_take_thms : thm list, |
|
43 |
reach_thms : thm list, |
|
44 |
take_lemma_thms : thm list, |
|
45 |
is_finite : bool, |
|
46 |
take_induct_thms : thm list |
|
| 35656 | 47 |
} |
| 35651 | 48 |
val define_take_functions : |
49 |
(binding * iso_info) list -> theory -> take_info * theory |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
50 |
|
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
51 |
val add_lub_take_theorems : |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
52 |
(binding * iso_info) list -> take_info -> thm list -> |
| 35656 | 53 |
theory -> take_induct_info * theory |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
54 |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
55 |
val map_of_typ : |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
56 |
theory -> (typ * term) list -> typ -> term |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
57 |
|
|
40737
2037021f034f
remove map function names from domain package theory data
huffman
parents:
40489
diff
changeset
|
58 |
val add_rec_type : (string * bool list) -> theory -> theory |
|
2037021f034f
remove map function names from domain package theory data
huffman
parents:
40489
diff
changeset
|
59 |
val get_rec_tab : theory -> (bool list) Symtab.table |
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40016
diff
changeset
|
60 |
val add_deflation_thm : thm -> theory -> theory |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
61 |
val get_deflation_thms : theory -> thm list |
| 40489 | 62 |
val map_ID_add : attribute |
63 |
val get_map_ID_thms : theory -> thm list |
|
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40016
diff
changeset
|
64 |
val setup : theory -> theory |
| 40832 | 65 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
66 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
67 |
structure Domain_Take_Proofs : DOMAIN_TAKE_PROOFS = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
68 |
struct |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
69 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
70 |
type iso_info = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
71 |
{
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
72 |
absT : typ, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
73 |
repT : typ, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
74 |
abs_const : term, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
75 |
rep_const : term, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
76 |
abs_inverse : thm, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
77 |
rep_inverse : thm |
| 40832 | 78 |
} |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
79 |
|
| 35651 | 80 |
type take_info = |
81 |
{ take_consts : term list,
|
|
82 |
take_defs : thm list, |
|
83 |
chain_take_thms : thm list, |
|
84 |
take_0_thms : thm list, |
|
85 |
take_Suc_thms : thm list, |
|
86 |
deflation_take_thms : thm list, |
|
| 40015 | 87 |
take_strict_thms : thm list, |
| 35651 | 88 |
finite_consts : term list, |
89 |
finite_defs : thm list |
|
| 40832 | 90 |
} |
| 35651 | 91 |
|
| 35656 | 92 |
type take_induct_info = |
93 |
{
|
|
| 35659 | 94 |
take_consts : term list, |
95 |
take_defs : thm list, |
|
96 |
chain_take_thms : thm list, |
|
97 |
take_0_thms : thm list, |
|
98 |
take_Suc_thms : thm list, |
|
99 |
deflation_take_thms : thm list, |
|
| 40015 | 100 |
take_strict_thms : thm list, |
| 35659 | 101 |
finite_consts : term list, |
102 |
finite_defs : thm list, |
|
103 |
lub_take_thms : thm list, |
|
104 |
reach_thms : thm list, |
|
105 |
take_lemma_thms : thm list, |
|
106 |
is_finite : bool, |
|
107 |
take_induct_thms : thm list |
|
| 40832 | 108 |
} |
| 35656 | 109 |
|
|
40833
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
110 |
val beta_ss = |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
111 |
simpset_of (put_simpset HOL_basic_ss @{context}
|
|
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
112 |
addsimps @{thms simp_thms} addsimprocs [@{simproc beta_cfun_proc}])
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
113 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
114 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
115 |
(******************************** theory data *********************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
116 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
117 |
|
|
40737
2037021f034f
remove map function names from domain package theory data
huffman
parents:
40489
diff
changeset
|
118 |
structure Rec_Data = Theory_Data |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
119 |
( |
|
40737
2037021f034f
remove map function names from domain package theory data
huffman
parents:
40489
diff
changeset
|
120 |
(* list indicates which type arguments allow indirect recursion *) |
| 40832 | 121 |
type T = (bool list) Symtab.table |
122 |
val empty = Symtab.empty |
|
123 |
val extend = I |
|
124 |
fun merge data = Symtab.merge (K true) data |
|
125 |
) |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
126 |
|
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40016
diff
changeset
|
127 |
structure DeflMapData = Named_Thms |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
128 |
( |
| 45294 | 129 |
val name = @{binding domain_deflation}
|
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40016
diff
changeset
|
130 |
val description = "theorems like deflation a ==> deflation (foo_map$a)" |
| 40832 | 131 |
) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
132 |
|
| 40489 | 133 |
structure Map_Id_Data = Named_Thms |
134 |
( |
|
| 45294 | 135 |
val name = @{binding domain_map_ID}
|
| 40489 | 136 |
val description = "theorems like foo_map$ID = ID" |
| 40832 | 137 |
) |
| 40489 | 138 |
|
|
40737
2037021f034f
remove map function names from domain package theory data
huffman
parents:
40489
diff
changeset
|
139 |
fun add_rec_type (tname, bs) = |
| 40832 | 140 |
Rec_Data.map (Symtab.insert (K true) (tname, bs)) |
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40016
diff
changeset
|
141 |
|
|
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40016
diff
changeset
|
142 |
fun add_deflation_thm thm = |
| 40832 | 143 |
Context.theory_map (DeflMapData.add_thm thm) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
144 |
|
| 40832 | 145 |
val get_rec_tab = Rec_Data.get |
| 42361 | 146 |
fun get_deflation_thms thy = DeflMapData.get (Proof_Context.init_global thy) |
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40016
diff
changeset
|
147 |
|
| 40832 | 148 |
val map_ID_add = Map_Id_Data.add |
| 42361 | 149 |
val get_map_ID_thms = Map_Id_Data.get o Proof_Context.init_global |
| 40489 | 150 |
|
| 40832 | 151 |
val setup = DeflMapData.setup #> Map_Id_Data.setup |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
152 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
153 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
154 |
(************************** building types and terms **************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
155 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
156 |
|
| 40832 | 157 |
open HOLCF_Library |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
158 |
|
| 40832 | 159 |
infixr 6 ->> |
160 |
infix -->> |
|
161 |
infix 9 ` |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
162 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
163 |
fun mk_deflation t = |
| 40832 | 164 |
Const (@{const_name deflation}, Term.fastype_of t --> boolT) $ t
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
165 |
|
| 40832 | 166 |
fun mk_eqs (t, u) = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u)) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
167 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
168 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
169 |
(****************************** isomorphism info ******************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
170 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
171 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
172 |
fun deflation_abs_rep (info : iso_info) : thm = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
173 |
let |
| 40832 | 174 |
val abs_iso = #abs_inverse info |
175 |
val rep_iso = #rep_inverse info |
|
176 |
val thm = @{thm deflation_abs_rep} OF [abs_iso, rep_iso]
|
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
177 |
in |
|
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35773
diff
changeset
|
178 |
Drule.zero_var_indexes thm |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
179 |
end |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
180 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
181 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
182 |
(********************* building map functions over types **********************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
183 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
184 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
185 |
fun map_of_typ (thy : theory) (sub : (typ * term) list) (T : typ) : term = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
186 |
let |
| 40832 | 187 |
val thms = get_map_ID_thms thy |
188 |
val rules = map (Thm.concl_of #> HOLogic.dest_Trueprop #> HOLogic.dest_eq) thms |
|
189 |
val rules' = map (apfst mk_ID) sub @ map swap rules |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
190 |
in |
| 40489 | 191 |
mk_ID T |
192 |
|> Pattern.rewrite_term thy rules' [] |
|
193 |
|> Pattern.rewrite_term thy rules [] |
|
| 40832 | 194 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
195 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
196 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
197 |
(********************* declaring definitions and theorems *********************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
198 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
199 |
|
| 35773 | 200 |
fun add_qualified_def name (dbind, eqn) = |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
201 |
yield_singleton (Global_Theory.add_defs false) |
| 40832 | 202 |
((Binding.qualified true name dbind, eqn), []) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
203 |
|
| 35773 | 204 |
fun add_qualified_thm name (dbind, thm) = |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
205 |
yield_singleton Global_Theory.add_thms |
| 40832 | 206 |
((Binding.qualified true name dbind, thm), []) |
| 35650 | 207 |
|
| 35773 | 208 |
fun add_qualified_simp_thm name (dbind, thm) = |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
209 |
yield_singleton Global_Theory.add_thms |
| 40832 | 210 |
((Binding.qualified true name dbind, thm), [Simplifier.simp_add]) |
| 35573 | 211 |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
212 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
213 |
(************************** defining take functions ***************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
214 |
(******************************************************************************) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
215 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
216 |
fun define_take_functions |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
217 |
(spec : (binding * iso_info) list) |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
218 |
(thy : theory) = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
219 |
let |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
220 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
221 |
(* retrieve components of spec *) |
| 40832 | 222 |
val dbinds = map fst spec |
223 |
val iso_infos = map snd spec |
|
224 |
val dom_eqns = map (fn x => (#absT x, #repT x)) iso_infos |
|
225 |
val rep_abs_consts = map (fn x => (#rep_const x, #abs_const x)) iso_infos |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
226 |
|
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
227 |
fun mk_projs [] _ = [] |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
228 |
| mk_projs (x::[]) t = [(x, t)] |
| 40832 | 229 |
| mk_projs (x::xs) t = (x, mk_fst t) :: mk_projs xs (mk_snd t) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
230 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
231 |
fun mk_cfcomp2 ((rep_const, abs_const), f) = |
| 40832 | 232 |
mk_cfcomp (abs_const, mk_cfcomp (f, rep_const)) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
233 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
234 |
(* define take functional *) |
| 40832 | 235 |
val newTs : typ list = map fst dom_eqns |
236 |
val copy_arg_type = mk_tupleT (map (fn T => T ->> T) newTs) |
|
237 |
val copy_arg = Free ("f", copy_arg_type)
|
|
238 |
val copy_args = map snd (mk_projs dbinds copy_arg) |
|
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
239 |
fun one_copy_rhs (rep_abs, (_, rhsT)) = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
240 |
let |
| 40832 | 241 |
val body = map_of_typ thy (newTs ~~ copy_args) rhsT |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
242 |
in |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
243 |
mk_cfcomp2 (rep_abs, body) |
| 40832 | 244 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
245 |
val take_functional = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
246 |
big_lambda copy_arg |
| 40832 | 247 |
(mk_tuple (map one_copy_rhs (rep_abs_consts ~~ dom_eqns))) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
248 |
val take_rhss = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
249 |
let |
| 40832 | 250 |
val n = Free ("n", HOLogic.natT)
|
251 |
val rhs = mk_iterate (n, take_functional) |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
252 |
in |
| 35773 | 253 |
map (lambda n o snd) (mk_projs dbinds rhs) |
| 40832 | 254 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
255 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
256 |
(* define take constants *) |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
257 |
fun define_take_const ((dbind, take_rhs), (lhsT, _)) thy = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
258 |
let |
| 40832 | 259 |
val take_type = HOLogic.natT --> lhsT ->> lhsT |
260 |
val take_bind = Binding.suffix_name "_take" dbind |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
261 |
val (take_const, thy) = |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
262 |
Sign.declare_const_global ((take_bind, take_type), NoSyn) thy |
| 40832 | 263 |
val take_eqn = Logic.mk_equals (take_const, take_rhs) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
264 |
val (take_def_thm, thy) = |
| 40832 | 265 |
add_qualified_def "take_def" (dbind, take_eqn) thy |
266 |
in ((take_const, take_def_thm), thy) end |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
267 |
val ((take_consts, take_defs), thy) = thy |
| 35773 | 268 |
|> fold_map define_take_const (dbinds ~~ take_rhss ~~ dom_eqns) |
| 40832 | 269 |
|>> ListPair.unzip |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
270 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
271 |
(* prove chain_take lemmas *) |
| 35773 | 272 |
fun prove_chain_take (take_const, dbind) thy = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
273 |
let |
| 40832 | 274 |
val goal = mk_trp (mk_chain take_const) |
275 |
val rules = take_defs @ @{thms chain_iterate ch2ch_fst ch2ch_snd}
|
|
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
276 |
val tac = simp_tac (Simplifier.global_context thy HOL_basic_ss addsimps rules) 1 |
| 40832 | 277 |
val thm = Goal.prove_global thy [] [] goal (K tac) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
278 |
in |
| 35773 | 279 |
add_qualified_simp_thm "chain_take" (dbind, thm) thy |
| 40832 | 280 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
281 |
val (chain_take_thms, thy) = |
| 40832 | 282 |
fold_map prove_chain_take (take_consts ~~ dbinds) thy |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
283 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
284 |
(* prove take_0 lemmas *) |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
285 |
fun prove_take_0 ((take_const, dbind), (lhsT, _)) thy = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
286 |
let |
| 40832 | 287 |
val lhs = take_const $ @{term "0::nat"}
|
288 |
val goal = mk_eqs (lhs, mk_bottom (lhsT ->> lhsT)) |
|
289 |
val rules = take_defs @ @{thms iterate_0 fst_strict snd_strict}
|
|
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
290 |
val tac = simp_tac (Simplifier.global_context thy HOL_basic_ss addsimps rules) 1 |
| 40832 | 291 |
val take_0_thm = Goal.prove_global thy [] [] goal (K tac) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
292 |
in |
|
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40015
diff
changeset
|
293 |
add_qualified_simp_thm "take_0" (dbind, take_0_thm) thy |
| 40832 | 294 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
295 |
val (take_0_thms, thy) = |
| 40832 | 296 |
fold_map prove_take_0 (take_consts ~~ dbinds ~~ dom_eqns) thy |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
297 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
298 |
(* prove take_Suc lemmas *) |
| 40832 | 299 |
val n = Free ("n", natT)
|
300 |
val take_is = map (fn t => t $ n) take_consts |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
301 |
fun prove_take_Suc |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
302 |
(((take_const, rep_abs), dbind), (_, rhsT)) thy = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
303 |
let |
| 40832 | 304 |
val lhs = take_const $ (@{term Suc} $ n)
|
305 |
val body = map_of_typ thy (newTs ~~ take_is) rhsT |
|
306 |
val rhs = mk_cfcomp2 (rep_abs, body) |
|
307 |
val goal = mk_eqs (lhs, rhs) |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
308 |
val simps = @{thms iterate_Suc fst_conv snd_conv}
|
| 40832 | 309 |
val rules = take_defs @ simps |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
310 |
val tac = simp_tac (Simplifier.global_context thy beta_ss addsimps rules) 1 |
| 40832 | 311 |
val take_Suc_thm = Goal.prove_global thy [] [] goal (K tac) |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
312 |
in |
| 35773 | 313 |
add_qualified_thm "take_Suc" (dbind, take_Suc_thm) thy |
| 40832 | 314 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
315 |
val (take_Suc_thms, thy) = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
316 |
fold_map prove_take_Suc |
| 40832 | 317 |
(take_consts ~~ rep_abs_consts ~~ dbinds ~~ dom_eqns) thy |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
318 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
319 |
(* prove deflation theorems for take functions *) |
| 40832 | 320 |
val deflation_abs_rep_thms = map deflation_abs_rep iso_infos |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
321 |
val deflation_take_thm = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
322 |
let |
| 40832 | 323 |
val n = Free ("n", natT)
|
324 |
fun mk_goal take_const = mk_deflation (take_const $ n) |
|
325 |
val goal = mk_trp (foldr1 mk_conj (map mk_goal take_consts)) |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
326 |
val bottom_rules = |
|
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
40833
diff
changeset
|
327 |
take_0_thms @ @{thms deflation_bottom simp_thms}
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
328 |
val deflation_rules = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
329 |
@{thms conjI deflation_ID}
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
330 |
@ deflation_abs_rep_thms |
| 40832 | 331 |
@ get_deflation_thms thy |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
332 |
in |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
333 |
Goal.prove_global thy [] [] goal (fn _ => |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
334 |
EVERY |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
335 |
[rtac @{thm nat.induct} 1,
|
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
336 |
simp_tac (Simplifier.global_context thy HOL_basic_ss addsimps bottom_rules) 1, |
|
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
337 |
asm_simp_tac (Simplifier.global_context thy HOL_basic_ss addsimps take_Suc_thms) 1, |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
338 |
REPEAT (etac @{thm conjE} 1
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
339 |
ORELSE resolve_tac deflation_rules 1 |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
340 |
ORELSE atac 1)]) |
| 40832 | 341 |
end |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
342 |
fun conjuncts [] _ = [] |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
343 |
| conjuncts (n::[]) thm = [(n, thm)] |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
344 |
| conjuncts (n::ns) thm = let |
| 40832 | 345 |
val thmL = thm RS @{thm conjunct1}
|
346 |
val thmR = thm RS @{thm conjunct2}
|
|
347 |
in (n, thmL):: conjuncts ns thmR end |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
348 |
val (deflation_take_thms, thy) = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
349 |
fold_map (add_qualified_thm "deflation_take") |
|
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35773
diff
changeset
|
350 |
(map (apsnd Drule.zero_var_indexes) |
| 40832 | 351 |
(conjuncts dbinds deflation_take_thm)) thy |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
352 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
353 |
(* prove strictness of take functions *) |
| 35773 | 354 |
fun prove_take_strict (deflation_take, dbind) thy = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
355 |
let |
|
35572
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
356 |
val take_strict_thm = |
|
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35773
diff
changeset
|
357 |
Drule.zero_var_indexes |
| 40832 | 358 |
(@{thm deflation_strict} OF [deflation_take])
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
359 |
in |
|
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40015
diff
changeset
|
360 |
add_qualified_simp_thm "take_strict" (dbind, take_strict_thm) thy |
| 40832 | 361 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
362 |
val (take_strict_thms, thy) = |
|
35572
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
363 |
fold_map prove_take_strict |
| 40832 | 364 |
(deflation_take_thms ~~ dbinds) thy |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
365 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
366 |
(* prove take/take rules *) |
| 35773 | 367 |
fun prove_take_take ((chain_take, deflation_take), dbind) thy = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
368 |
let |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
369 |
val take_take_thm = |
|
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35773
diff
changeset
|
370 |
Drule.zero_var_indexes |
| 40832 | 371 |
(@{thm deflation_chain_min} OF [chain_take, deflation_take])
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
372 |
in |
| 35773 | 373 |
add_qualified_thm "take_take" (dbind, take_take_thm) thy |
| 40832 | 374 |
end |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
375 |
val (_, thy) = |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
376 |
fold_map prove_take_take |
| 40832 | 377 |
(chain_take_thms ~~ deflation_take_thms ~~ dbinds) thy |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
378 |
|
|
35572
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
379 |
(* prove take_below rules *) |
| 35773 | 380 |
fun prove_take_below (deflation_take, dbind) thy = |
|
35572
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
381 |
let |
|
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
382 |
val take_below_thm = |
|
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35773
diff
changeset
|
383 |
Drule.zero_var_indexes |
| 40832 | 384 |
(@{thm deflation.below} OF [deflation_take])
|
|
35572
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
385 |
in |
| 35773 | 386 |
add_qualified_thm "take_below" (dbind, take_below_thm) thy |
| 40832 | 387 |
end |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
388 |
val (_, thy) = |
|
35572
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
389 |
fold_map prove_take_below |
| 40832 | 390 |
(deflation_take_thms ~~ dbinds) thy |
|
35572
44eeda8cb708
generate lemma take_below, declare chain_take [simp]
huffman
parents:
35557
diff
changeset
|
391 |
|
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
392 |
(* define finiteness predicates *) |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
393 |
fun define_finite_const ((dbind, take_const), (lhsT, _)) thy = |
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
394 |
let |
| 40832 | 395 |
val finite_type = lhsT --> boolT |
396 |
val finite_bind = Binding.suffix_name "_finite" dbind |
|
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
397 |
val (finite_const, thy) = |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
398 |
Sign.declare_const_global ((finite_bind, finite_type), NoSyn) thy |
| 40832 | 399 |
val x = Free ("x", lhsT)
|
400 |
val n = Free ("n", natT)
|
|
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
401 |
val finite_rhs = |
|
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
402 |
lambda x (HOLogic.exists_const natT $ |
| 40832 | 403 |
(lambda n (mk_eq (mk_capply (take_const $ n, x), x)))) |
404 |
val finite_eqn = Logic.mk_equals (finite_const, finite_rhs) |
|
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
405 |
val (finite_def_thm, thy) = |
| 40832 | 406 |
add_qualified_def "finite_def" (dbind, finite_eqn) thy |
407 |
in ((finite_const, finite_def_thm), thy) end |
|
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
408 |
val ((finite_consts, finite_defs), thy) = thy |
| 35773 | 409 |
|> fold_map define_finite_const (dbinds ~~ take_consts ~~ dom_eqns) |
| 40832 | 410 |
|>> ListPair.unzip |
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
411 |
|
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
412 |
val result = |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
413 |
{
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
414 |
take_consts = take_consts, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
415 |
take_defs = take_defs, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
416 |
chain_take_thms = chain_take_thms, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
417 |
take_0_thms = take_0_thms, |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
418 |
take_Suc_thms = take_Suc_thms, |
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
419 |
deflation_take_thms = deflation_take_thms, |
| 40015 | 420 |
take_strict_thms = take_strict_thms, |
|
35515
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
421 |
finite_consts = finite_consts, |
|
d631dc53ede0
move definition of finiteness predicate into domain_take_proofs.ML
huffman
parents:
35514
diff
changeset
|
422 |
finite_defs = finite_defs |
| 40832 | 423 |
} |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
424 |
|
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
425 |
in |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
426 |
(result, thy) |
| 40832 | 427 |
end |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
diff
changeset
|
428 |
|
| 35655 | 429 |
fun prove_finite_take_induct |
430 |
(spec : (binding * iso_info) list) |
|
431 |
(take_info : take_info) |
|
432 |
(lub_take_thms : thm list) |
|
433 |
(thy : theory) = |
|
434 |
let |
|
| 40832 | 435 |
val dbinds = map fst spec |
436 |
val iso_infos = map snd spec |
|
437 |
val absTs = map #absT iso_infos |
|
438 |
val {take_consts, ...} = take_info
|
|
439 |
val {chain_take_thms, take_0_thms, take_Suc_thms, ...} = take_info
|
|
440 |
val {finite_consts, finite_defs, ...} = take_info
|
|
| 35655 | 441 |
|
442 |
val decisive_lemma = |
|
443 |
let |
|
| 37165 | 444 |
fun iso_locale (info : iso_info) = |
| 40832 | 445 |
@{thm iso.intro} OF [#abs_inverse info, #rep_inverse info]
|
446 |
val iso_locale_thms = map iso_locale iso_infos |
|
| 35655 | 447 |
val decisive_abs_rep_thms = |
| 40832 | 448 |
map (fn x => @{thm decisive_abs_rep} OF [x]) iso_locale_thms
|
449 |
val n = Free ("n", @{typ nat})
|
|
| 35655 | 450 |
fun mk_decisive t = |
| 40832 | 451 |
Const (@{const_name decisive}, fastype_of t --> boolT) $ t
|
452 |
fun f take_const = mk_decisive (take_const $ n) |
|
453 |
val goal = mk_trp (foldr1 mk_conj (map f take_consts)) |
|
454 |
val rules0 = @{thm decisive_bottom} :: take_0_thms
|
|
| 35655 | 455 |
val rules1 = |
456 |
take_Suc_thms @ decisive_abs_rep_thms |
|
| 40832 | 457 |
@ @{thms decisive_ID decisive_ssum_map decisive_sprod_map}
|
| 35655 | 458 |
val tac = EVERY [ |
459 |
rtac @{thm nat.induct} 1,
|
|
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
460 |
simp_tac (Simplifier.global_context thy HOL_ss addsimps rules0) 1, |
|
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
45654
diff
changeset
|
461 |
asm_simp_tac (Simplifier.global_context thy HOL_ss addsimps rules1) 1] |
| 40832 | 462 |
in Goal.prove_global thy [] [] goal (K tac) end |
| 35655 | 463 |
fun conjuncts 1 thm = [thm] |
464 |
| conjuncts n thm = let |
|
| 40832 | 465 |
val thmL = thm RS @{thm conjunct1}
|
466 |
val thmR = thm RS @{thm conjunct2}
|
|
467 |
in thmL :: conjuncts (n-1) thmR end |
|
468 |
val decisive_thms = conjuncts (length spec) decisive_lemma |
|
| 35655 | 469 |
|
470 |
fun prove_finite_thm (absT, finite_const) = |
|
471 |
let |
|
| 40832 | 472 |
val goal = mk_trp (finite_const $ Free ("x", absT))
|
| 35655 | 473 |
val tac = |
474 |
EVERY [ |
|
475 |
rewrite_goals_tac finite_defs, |
|
476 |
rtac @{thm lub_ID_finite} 1,
|
|
477 |
resolve_tac chain_take_thms 1, |
|
478 |
resolve_tac lub_take_thms 1, |
|
| 40832 | 479 |
resolve_tac decisive_thms 1] |
| 35655 | 480 |
in |
481 |
Goal.prove_global thy [] [] goal (K tac) |
|
| 40832 | 482 |
end |
| 35655 | 483 |
val finite_thms = |
| 40832 | 484 |
map prove_finite_thm (absTs ~~ finite_consts) |
| 35655 | 485 |
|
486 |
fun prove_take_induct ((ch_take, lub_take), decisive) = |
|
487 |
Drule.export_without_context |
|
| 40832 | 488 |
(@{thm lub_ID_finite_take_induct} OF [ch_take, lub_take, decisive])
|
| 35655 | 489 |
val take_induct_thms = |
490 |
map prove_take_induct |
|
| 40832 | 491 |
(chain_take_thms ~~ lub_take_thms ~~ decisive_thms) |
| 35655 | 492 |
|
493 |
val thy = thy |
|
494 |
|> fold (snd oo add_qualified_thm "finite") |
|
| 35773 | 495 |
(dbinds ~~ finite_thms) |
| 35655 | 496 |
|> fold (snd oo add_qualified_thm "take_induct") |
| 40832 | 497 |
(dbinds ~~ take_induct_thms) |
| 35655 | 498 |
in |
499 |
((finite_thms, take_induct_thms), thy) |
|
| 40832 | 500 |
end |
| 35655 | 501 |
|
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
502 |
fun add_lub_take_theorems |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
503 |
(spec : (binding * iso_info) list) |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
504 |
(take_info : take_info) |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
505 |
(lub_take_thms : thm list) |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
506 |
(thy : theory) = |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
507 |
let |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
508 |
|
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
509 |
(* retrieve components of spec *) |
| 40832 | 510 |
val dbinds = map fst spec |
511 |
val iso_infos = map snd spec |
|
512 |
val absTs = map #absT iso_infos |
|
513 |
val repTs = map #repT iso_infos |
|
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
514 |
val {chain_take_thms, ...} = take_info
|
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
515 |
|
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
516 |
(* prove take lemmas *) |
| 35773 | 517 |
fun prove_take_lemma ((chain_take, lub_take), dbind) thy = |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
518 |
let |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
519 |
val take_lemma = |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
520 |
Drule.export_without_context |
| 40832 | 521 |
(@{thm lub_ID_take_lemma} OF [chain_take, lub_take])
|
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
522 |
in |
| 35773 | 523 |
add_qualified_thm "take_lemma" (dbind, take_lemma) thy |
| 40832 | 524 |
end |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
525 |
val (take_lemma_thms, thy) = |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
526 |
fold_map prove_take_lemma |
| 40832 | 527 |
(chain_take_thms ~~ lub_take_thms ~~ dbinds) thy |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
528 |
|
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
529 |
(* prove reach lemmas *) |
| 35773 | 530 |
fun prove_reach_lemma ((chain_take, lub_take), dbind) thy = |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
531 |
let |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
532 |
val thm = |
|
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35773
diff
changeset
|
533 |
Drule.zero_var_indexes |
| 40832 | 534 |
(@{thm lub_ID_reach} OF [chain_take, lub_take])
|
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
535 |
in |
| 35773 | 536 |
add_qualified_thm "reach" (dbind, thm) thy |
| 40832 | 537 |
end |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
538 |
val (reach_thms, thy) = |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
539 |
fold_map prove_reach_lemma |
| 40832 | 540 |
(chain_take_thms ~~ lub_take_thms ~~ dbinds) thy |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
541 |
|
| 35655 | 542 |
(* test for finiteness of domain definitions *) |
543 |
local |
|
| 40832 | 544 |
val types = [@{type_name ssum}, @{type_name sprod}]
|
|
36692
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents:
36241
diff
changeset
|
545 |
fun finite d T = if member (op =) absTs T then d else finite' d T |
| 35655 | 546 |
and finite' d (Type (c, Ts)) = |
| 40832 | 547 |
let val d' = d andalso member (op =) types c |
| 35655 | 548 |
in forall (finite d') Ts end |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
549 |
| finite' _ _ = true |
| 35655 | 550 |
in |
| 40832 | 551 |
val is_finite = forall (finite true) repTs |
552 |
end |
|
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
553 |
|
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
42375
diff
changeset
|
554 |
val ((_, take_induct_thms), thy) = |
| 35655 | 555 |
if is_finite |
556 |
then |
|
557 |
let |
|
558 |
val ((finites, take_inducts), thy) = |
|
| 40832 | 559 |
prove_finite_take_induct spec take_info lub_take_thms thy |
| 35655 | 560 |
in |
561 |
((SOME finites, take_inducts), thy) |
|
562 |
end |
|
563 |
else |
|
564 |
let |
|
565 |
fun prove_take_induct (chain_take, lub_take) = |
|
|
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35773
diff
changeset
|
566 |
Drule.zero_var_indexes |
| 40832 | 567 |
(@{thm lub_ID_take_induct} OF [chain_take, lub_take])
|
| 35655 | 568 |
val take_inducts = |
| 40832 | 569 |
map prove_take_induct (chain_take_thms ~~ lub_take_thms) |
| 35655 | 570 |
val thy = fold (snd oo add_qualified_thm "take_induct") |
| 40832 | 571 |
(dbinds ~~ take_inducts) thy |
| 35655 | 572 |
in |
573 |
((NONE, take_inducts), thy) |
|
| 40832 | 574 |
end |
| 35655 | 575 |
|
| 35656 | 576 |
val result = |
577 |
{
|
|
| 35659 | 578 |
take_consts = #take_consts take_info, |
579 |
take_defs = #take_defs take_info, |
|
580 |
chain_take_thms = #chain_take_thms take_info, |
|
581 |
take_0_thms = #take_0_thms take_info, |
|
582 |
take_Suc_thms = #take_Suc_thms take_info, |
|
583 |
deflation_take_thms = #deflation_take_thms take_info, |
|
| 40015 | 584 |
take_strict_thms = #take_strict_thms take_info, |
| 35659 | 585 |
finite_consts = #finite_consts take_info, |
586 |
finite_defs = #finite_defs take_info, |
|
587 |
lub_take_thms = lub_take_thms, |
|
588 |
reach_thms = reach_thms, |
|
589 |
take_lemma_thms = take_lemma_thms, |
|
590 |
is_finite = is_finite, |
|
591 |
take_induct_thms = take_induct_thms |
|
| 40832 | 592 |
} |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
593 |
in |
|
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
594 |
(result, thy) |
| 40832 | 595 |
end |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35651
diff
changeset
|
596 |
|
| 40832 | 597 |
end |