author | huffman |
Tue, 02 Mar 2010 13:50:23 -0800 | |
changeset 35514 | a2cfa413eaab |
parent 35498 | 5c70de748522 |
child 35515 | d631dc53ede0 |
permissions | -rw-r--r-- |
33774 | 1 |
(* Title: HOLCF/Tools/domain/domain_isomorphism.ML |
2 |
Author: Brian Huffman |
|
3 |
||
4 |
Defines new types satisfying the given domain equations. |
|
5 |
*) |
|
6 |
||
7 |
signature DOMAIN_ISOMORPHISM = |
|
8 |
sig |
|
35489 | 9 |
val domain_isomorphism : |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
10 |
(string list * binding * mixfix * typ * (binding * binding) option) list |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
11 |
-> theory -> Domain_Take_Proofs.iso_info list * theory |
35489 | 12 |
val domain_isomorphism_cmd : |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
13 |
(string list * binding * mixfix * string * (binding * binding) option) list |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
14 |
-> theory -> theory |
35489 | 15 |
val add_type_constructor : |
35479
dffffe36344a
store deflation thms for map functions in theory data
huffman
parents:
35478
diff
changeset
|
16 |
(string * term * string * thm * thm * thm * thm) -> theory -> theory |
33774 | 17 |
end; |
18 |
||
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
19 |
structure Domain_Isomorphism : DOMAIN_ISOMORPHISM = |
33774 | 20 |
struct |
21 |
||
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
22 |
val beta_ss = |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
23 |
HOL_basic_ss |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
24 |
addsimps simp_thms |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
25 |
addsimps [@{thm beta_cfun}] |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
26 |
addsimprocs [@{simproc cont_proc}]; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
27 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
28 |
val beta_tac = simp_tac beta_ss; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
29 |
|
33774 | 30 |
(******************************************************************************) |
33791 | 31 |
(******************************** theory data *********************************) |
32 |
(******************************************************************************) |
|
33 |
||
34 |
structure DeflData = Theory_Data |
|
35 |
( |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
36 |
(* terms like "foo_defl" *) |
33791 | 37 |
type T = term Symtab.table; |
38 |
val empty = Symtab.empty; |
|
39 |
val extend = I; |
|
40 |
fun merge data = Symtab.merge (K true) data; |
|
41 |
); |
|
42 |
||
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
43 |
structure RepData = Theory_Data |
33791 | 44 |
( |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
45 |
(* theorems like "REP('a foo) = foo_defl$REP('a)" *) |
33791 | 46 |
type T = thm list; |
47 |
val empty = []; |
|
48 |
val extend = I; |
|
49 |
val merge = Thm.merge_thms; |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
50 |
); |
33791 | 51 |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
52 |
structure MapIdData = Theory_Data |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
53 |
( |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
54 |
(* theorems like "foo_map$ID = ID" *) |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
55 |
type T = thm list; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
56 |
val empty = []; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
57 |
val extend = I; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
58 |
val merge = Thm.merge_thms; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
59 |
); |
35479
dffffe36344a
store deflation thms for map functions in theory data
huffman
parents:
35478
diff
changeset
|
60 |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
61 |
structure IsodeflData = Theory_Data |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
62 |
( |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
63 |
(* theorems like "isodefl d t ==> isodefl (foo_map$d) (foo_defl$t)" *) |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
64 |
type T = thm list; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
65 |
val empty = []; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
66 |
val extend = I; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
67 |
val merge = Thm.merge_thms; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
68 |
); |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
69 |
|
33791 | 70 |
fun add_type_constructor |
35479
dffffe36344a
store deflation thms for map functions in theory data
huffman
parents:
35478
diff
changeset
|
71 |
(tname, defl_const, map_name, REP_thm, |
dffffe36344a
store deflation thms for map functions in theory data
huffman
parents:
35478
diff
changeset
|
72 |
isodefl_thm, map_ID_thm, defl_map_thm) = |
33791 | 73 |
DeflData.map (Symtab.insert (K true) (tname, defl_const)) |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
74 |
#> Domain_Take_Proofs.add_map_function (tname, map_name, defl_map_thm) |
33791 | 75 |
#> RepData.map (Thm.add_thm REP_thm) |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
76 |
#> IsodeflData.map (Thm.add_thm isodefl_thm) |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
77 |
#> MapIdData.map (Thm.add_thm map_ID_thm); |
33791 | 78 |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
79 |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
80 |
(* val get_map_tab = MapData.get; *) |
33801 | 81 |
|
33791 | 82 |
|
83 |
(******************************************************************************) |
|
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
84 |
(************************** building types and terms **************************) |
33774 | 85 |
(******************************************************************************) |
86 |
||
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
87 |
open HOLCF_Library; |
33774 | 88 |
|
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
89 |
infixr 6 ->>; |
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
90 |
infix -->>; |
33774 | 91 |
|
92 |
val deflT = @{typ "udom alg_defl"}; |
|
93 |
||
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
94 |
fun mapT (T as Type (_, Ts)) = |
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
95 |
(map (fn T => T ->> T) Ts) -->> (T ->> T) |
35474 | 96 |
| mapT T = T ->> T; |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
97 |
|
33774 | 98 |
fun mk_Rep_of T = |
99 |
Const (@{const_name Rep_of}, Term.itselfT T --> deflT) $ Logic.mk_type T; |
|
100 |
||
33778 | 101 |
fun coerce_const T = Const (@{const_name coerce}, T); |
102 |
||
33788 | 103 |
fun isodefl_const T = |
104 |
Const (@{const_name isodefl}, (T ->> T) --> deflT --> HOLogic.boolT); |
|
105 |
||
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
106 |
fun mk_deflation t = |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
107 |
Const (@{const_name deflation}, Term.fastype_of t --> boolT) $ t; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
108 |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
109 |
fun mk_lub t = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
110 |
let |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
111 |
val T = Term.range_type (Term.fastype_of t); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
112 |
val lub_const = Const (@{const_name lub}, (T --> boolT) --> T); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
113 |
val UNIV_const = @{term "UNIV :: nat set"}; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
114 |
val image_type = (natT --> T) --> (natT --> boolT) --> T --> boolT; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
115 |
val image_const = Const (@{const_name image}, image_type); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
116 |
in |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
117 |
lub_const $ (image_const $ t $ UNIV_const) |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
118 |
end; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
119 |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
120 |
(* splits a cterm into the right and lefthand sides of equality *) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
121 |
fun dest_eqs t = HOLogic.dest_eq (HOLogic.dest_Trueprop t); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
122 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
123 |
fun mk_eqs (t, u) = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u)); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
124 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
125 |
(******************************************************************************) |
35489 | 126 |
(****************************** isomorphism info ******************************) |
127 |
(******************************************************************************) |
|
128 |
||
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
129 |
fun deflation_abs_rep (info : Domain_Take_Proofs.iso_info) : thm = |
35489 | 130 |
let |
131 |
val abs_iso = #abs_inverse info; |
|
132 |
val rep_iso = #rep_inverse info; |
|
133 |
val thm = @{thm deflation_abs_rep} OF [abs_iso, rep_iso]; |
|
134 |
in |
|
135 |
Drule.export_without_context thm |
|
136 |
end |
|
137 |
||
138 |
(******************************************************************************) |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
139 |
(*************** fixed-point definitions and unfolding theorems ***************) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
140 |
(******************************************************************************) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
141 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
142 |
fun add_fixdefs |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
143 |
(spec : (binding * term) list) |
33788 | 144 |
(thy : theory) : (thm list * thm list) * theory = |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
145 |
let |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
146 |
val binds = map fst spec; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
147 |
val (lhss, rhss) = ListPair.unzip (map (dest_eqs o snd) spec); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
148 |
val functional = lambda_tuple lhss (mk_tuple rhss); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
149 |
val fixpoint = mk_fix (mk_cabs functional); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
150 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
151 |
(* project components of fixpoint *) |
35474 | 152 |
fun mk_projs [] t = [] |
153 |
| mk_projs (x::[]) t = [(x, t)] |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
154 |
| mk_projs (x::xs) t = (x, mk_fst t) :: mk_projs xs (mk_snd t); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
155 |
val projs = mk_projs lhss fixpoint; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
156 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
157 |
(* convert parameters to lambda abstractions *) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
158 |
fun mk_eqn (lhs, rhs) = |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
159 |
case lhs of |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
160 |
Const (@{const_name Rep_CFun}, _) $ f $ (x as Free _) => |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
161 |
mk_eqn (f, big_lambda x rhs) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
162 |
| Const _ => Logic.mk_equals (lhs, rhs) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
163 |
| _ => raise TERM ("lhs not of correct form", [lhs, rhs]); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
164 |
val eqns = map mk_eqn projs; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
165 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
166 |
(* register constant definitions *) |
33777 | 167 |
val (fixdef_thms, thy) = |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
168 |
(PureThy.add_defs false o map Thm.no_attributes) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
169 |
(map (Binding.suffix_name "_def") binds ~~ eqns) thy; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
170 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
171 |
(* prove applied version of definitions *) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
172 |
fun prove_proj (lhs, rhs) = |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
173 |
let |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
174 |
val tac = rewrite_goals_tac fixdef_thms THEN beta_tac 1; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
175 |
val goal = Logic.mk_equals (lhs, rhs); |
33777 | 176 |
in Goal.prove_global thy [] [] goal (K tac) end; |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
177 |
val proj_thms = map prove_proj projs; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
178 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
179 |
(* mk_tuple lhss == fixpoint *) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
180 |
fun pair_equalI (thm1, thm2) = @{thm Pair_equalI} OF [thm1, thm2]; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
181 |
val tuple_fixdef_thm = foldr1 pair_equalI proj_thms; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
182 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
183 |
val cont_thm = |
33777 | 184 |
Goal.prove_global thy [] [] (mk_trp (mk_cont functional)) |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
185 |
(K (beta_tac 1)); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
186 |
val tuple_unfold_thm = |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
187 |
(@{thm def_cont_fix_eq} OF [tuple_fixdef_thm, cont_thm]) |
33777 | 188 |
|> LocalDefs.unfold (ProofContext.init thy) @{thms split_conv}; |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
189 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
190 |
fun mk_unfold_thms [] thm = [] |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
191 |
| mk_unfold_thms (n::[]) thm = [(n, thm)] |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
192 |
| mk_unfold_thms (n::ns) thm = let |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
193 |
val thmL = thm RS @{thm Pair_eqD1}; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
194 |
val thmR = thm RS @{thm Pair_eqD2}; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
195 |
in (n, thmL) :: mk_unfold_thms ns thmR end; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
196 |
val unfold_binds = map (Binding.suffix_name "_unfold") binds; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
197 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
198 |
(* register unfold theorems *) |
33777 | 199 |
val (unfold_thms, thy) = |
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34149
diff
changeset
|
200 |
(PureThy.add_thms o map (Thm.no_attributes o apsnd Drule.export_without_context)) |
33777 | 201 |
(mk_unfold_thms unfold_binds tuple_unfold_thm) thy; |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
202 |
in |
33788 | 203 |
((proj_thms, unfold_thms), thy) |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
204 |
end; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
205 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
206 |
|
33774 | 207 |
(******************************************************************************) |
33790 | 208 |
(****************** deflation combinators and map functions *******************) |
209 |
(******************************************************************************) |
|
33774 | 210 |
|
211 |
fun defl_of_typ |
|
212 |
(tab : term Symtab.table) |
|
213 |
(T : typ) : term = |
|
214 |
let |
|
215 |
fun is_closed_typ (Type (_, Ts)) = forall is_closed_typ Ts |
|
216 |
| is_closed_typ _ = false; |
|
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
217 |
fun defl_of (TFree (a, _)) = Free (Library.unprefix "'" a, deflT) |
33774 | 218 |
| defl_of (TVar _) = error ("defl_of_typ: TVar") |
219 |
| defl_of (T as Type (c, Ts)) = |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
220 |
case Symtab.lookup tab c of |
35478 | 221 |
SOME t => list_ccomb (t, map defl_of Ts) |
33774 | 222 |
| NONE => if is_closed_typ T |
223 |
then mk_Rep_of T |
|
224 |
else error ("defl_of_typ: type variable under unsupported type constructor " ^ c); |
|
225 |
in defl_of T end; |
|
226 |
||
227 |
||
228 |
(******************************************************************************) |
|
35477 | 229 |
(********************* declaring definitions and theorems *********************) |
230 |
(******************************************************************************) |
|
231 |
||
232 |
fun define_const |
|
233 |
(bind : binding, rhs : term) |
|
234 |
(thy : theory) |
|
235 |
: (term * thm) * theory = |
|
236 |
let |
|
237 |
val typ = Term.fastype_of rhs; |
|
238 |
val (const, thy) = Sign.declare_const ((bind, typ), NoSyn) thy; |
|
239 |
val eqn = Logic.mk_equals (const, rhs); |
|
240 |
val def = Thm.no_attributes (Binding.suffix_name "_def" bind, eqn); |
|
241 |
val (def_thm, thy) = yield_singleton (PureThy.add_defs false) def thy; |
|
242 |
in |
|
243 |
((const, def_thm), thy) |
|
244 |
end; |
|
245 |
||
35489 | 246 |
fun add_qualified_thm name (path, thm) thy = |
247 |
thy |
|
248 |
|> Sign.add_path path |
|
249 |
|> yield_singleton PureThy.add_thms |
|
250 |
(Thm.no_attributes (Binding.name name, thm)) |
|
251 |
||> Sign.parent_path; |
|
252 |
||
253 |
(******************************************************************************) |
|
35477 | 254 |
(******************************* main function ********************************) |
255 |
(******************************************************************************) |
|
33774 | 256 |
|
257 |
fun read_typ thy str sorts = |
|
258 |
let |
|
259 |
val ctxt = ProofContext.init thy |
|
260 |
|> fold (Variable.declare_typ o TFree) sorts; |
|
261 |
val T = Syntax.read_typ ctxt str; |
|
262 |
in (T, Term.add_tfreesT T sorts) end; |
|
263 |
||
264 |
fun cert_typ sign raw_T sorts = |
|
265 |
let |
|
266 |
val T = Type.no_tvars (Sign.certify_typ sign raw_T) |
|
267 |
handle TYPE (msg, _, _) => error msg; |
|
268 |
val sorts' = Term.add_tfreesT T sorts; |
|
269 |
val _ = |
|
270 |
case duplicates (op =) (map fst sorts') of |
|
271 |
[] => () |
|
272 |
| dups => error ("Inconsistent sort constraints for " ^ commas dups) |
|
273 |
in (T, sorts') end; |
|
274 |
||
275 |
fun gen_domain_isomorphism |
|
276 |
(prep_typ: theory -> 'a -> (string * sort) list -> typ * (string * sort) list) |
|
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
277 |
(doms_raw: (string list * binding * mixfix * 'a * (binding * binding) option) list) |
33774 | 278 |
(thy: theory) |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
279 |
: Domain_Take_Proofs.iso_info list * theory = |
33774 | 280 |
let |
33792 | 281 |
val _ = Theory.requires thy "Representable" "domain isomorphisms"; |
33774 | 282 |
|
283 |
(* this theory is used just for parsing *) |
|
284 |
val tmp_thy = thy |> |
|
285 |
Theory.copy |> |
|
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
286 |
Sign.add_types (map (fn (tvs, tname, mx, _, morphs) => |
33774 | 287 |
(tname, length tvs, mx)) doms_raw); |
288 |
||
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
289 |
fun prep_dom thy (vs, t, mx, typ_raw, morphs) sorts = |
33774 | 290 |
let val (typ, sorts') = prep_typ thy typ_raw sorts |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
291 |
in ((vs, t, mx, typ, morphs), sorts') end; |
33774 | 292 |
|
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
293 |
val (doms : (string list * binding * mixfix * typ * (binding * binding) option) list, |
33774 | 294 |
sorts : (string * sort) list) = |
295 |
fold_map (prep_dom tmp_thy) doms_raw []; |
|
296 |
||
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
297 |
(* domain equations *) |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
298 |
fun mk_dom_eqn (vs, tbind, mx, rhs, morphs) = |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
299 |
let fun arg v = TFree (v, the (AList.lookup (op =) sorts v)); |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
300 |
in (Type (Sign.full_name tmp_thy tbind, map arg vs), rhs) end; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
301 |
val dom_eqns = map mk_dom_eqn doms; |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
302 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
303 |
(* check for valid type parameters *) |
35474 | 304 |
val (tyvars, _, _, _, _) = hd doms; |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
305 |
val new_doms = map (fn (tvs, tname, mx, _, _) => |
33774 | 306 |
let val full_tname = Sign.full_name tmp_thy tname |
307 |
in |
|
308 |
(case duplicates (op =) tvs of |
|
309 |
[] => |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
310 |
if eq_set (op =) (tyvars, tvs) then (full_tname, tvs) |
33774 | 311 |
else error ("Mutually recursive domains must have same type parameters") |
312 |
| dups => error ("Duplicate parameter(s) for domain " ^ quote (Binding.str_of tname) ^ |
|
313 |
" : " ^ commas dups)) |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
314 |
end) doms; |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
315 |
val dom_binds = map (fn (_, tbind, _, _, _) => tbind) doms; |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
316 |
val morphs = map (fn (_, _, _, _, morphs) => morphs) doms; |
33774 | 317 |
|
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
318 |
(* declare deflation combinator constants *) |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
319 |
fun declare_defl_const (vs, tbind, mx, rhs, morphs) thy = |
33774 | 320 |
let |
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
321 |
val defl_type = map (K deflT) vs -->> deflT; |
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
322 |
val defl_bind = Binding.suffix_name "_defl" tbind; |
33774 | 323 |
in |
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
324 |
Sign.declare_const ((defl_bind, defl_type), NoSyn) thy |
33774 | 325 |
end; |
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
326 |
val (defl_consts, thy) = fold_map declare_defl_const doms thy; |
33774 | 327 |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
328 |
(* defining equations for type combinators *) |
33790 | 329 |
val defl_tab1 = DeflData.get thy; |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
330 |
val defl_tab2 = |
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
331 |
Symtab.make (map (fst o dest_Type o fst) dom_eqns ~~ defl_consts); |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
332 |
val defl_tab' = Symtab.merge (K true) (defl_tab1, defl_tab2); |
33790 | 333 |
val thy = DeflData.put defl_tab' thy; |
33776 | 334 |
fun mk_defl_spec (lhsT, rhsT) = |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
335 |
mk_eqs (defl_of_typ defl_tab' lhsT, |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
336 |
defl_of_typ defl_tab' rhsT); |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
337 |
val defl_specs = map mk_defl_spec dom_eqns; |
33774 | 338 |
|
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
339 |
(* register recursive definition of deflation combinators *) |
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
340 |
val defl_binds = map (Binding.suffix_name "_defl") dom_binds; |
33788 | 341 |
val ((defl_apply_thms, defl_unfold_thms), thy) = |
342 |
add_fixdefs (defl_binds ~~ defl_specs) thy; |
|
33774 | 343 |
|
33776 | 344 |
(* define types using deflation combinators *) |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
345 |
fun make_repdef ((vs, tbind, mx, _, _), defl_const) thy = |
33774 | 346 |
let |
347 |
fun tfree a = TFree (a, the (AList.lookup (op =) sorts a)) |
|
348 |
val reps = map (mk_Rep_of o tfree) vs; |
|
35478 | 349 |
val defl = list_ccomb (defl_const, reps); |
33777 | 350 |
val ((_, _, _, {REP, ...}), thy) = |
33774 | 351 |
Repdef.add_repdef false NONE (tbind, vs, mx) defl NONE thy; |
352 |
in |
|
33777 | 353 |
(REP, thy) |
33774 | 354 |
end; |
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
355 |
val (REP_thms, thy) = fold_map make_repdef (doms ~~ defl_consts) thy; |
33791 | 356 |
val thy = RepData.map (fold Thm.add_thm REP_thms) thy; |
33776 | 357 |
|
358 |
(* prove REP equations *) |
|
33782 | 359 |
fun mk_REP_eq_thm (lhsT, rhsT) = |
33776 | 360 |
let |
361 |
val goal = mk_eqs (mk_Rep_of lhsT, mk_Rep_of rhsT); |
|
33791 | 362 |
val REP_simps = RepData.get thy; |
33776 | 363 |
val tac = |
364 |
simp_tac (HOL_basic_ss addsimps REP_simps) 1 |
|
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
365 |
THEN resolve_tac defl_unfold_thms 1; |
33776 | 366 |
in |
33777 | 367 |
Goal.prove_global thy [] [] goal (K tac) |
33776 | 368 |
end; |
33782 | 369 |
val REP_eq_thms = map mk_REP_eq_thm dom_eqns; |
370 |
||
371 |
(* register REP equations *) |
|
372 |
val REP_eq_binds = map (Binding.prefix_name "REP_eq_") dom_binds; |
|
373 |
val (_, thy) = thy |> |
|
374 |
(PureThy.add_thms o map Thm.no_attributes) |
|
375 |
(REP_eq_binds ~~ REP_eq_thms); |
|
33776 | 376 |
|
33778 | 377 |
(* define rep/abs functions *) |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
378 |
fun mk_rep_abs ((tbind, morphs), (lhsT, rhsT)) thy = |
33778 | 379 |
let |
380 |
val rep_bind = Binding.suffix_name "_rep" tbind; |
|
381 |
val abs_bind = Binding.suffix_name "_abs" tbind; |
|
35477 | 382 |
val ((rep_const, rep_def), thy) = |
383 |
define_const (rep_bind, coerce_const (lhsT ->> rhsT)) thy; |
|
384 |
val ((abs_const, abs_def), thy) = |
|
385 |
define_const (abs_bind, coerce_const (rhsT ->> lhsT)) thy; |
|
33778 | 386 |
in |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
387 |
(((rep_const, abs_const), (rep_def, abs_def)), thy) |
33778 | 388 |
end; |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
389 |
val ((rep_abs_consts, rep_abs_defs), thy) = thy |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
390 |
|> fold_map mk_rep_abs (dom_binds ~~ morphs ~~ dom_eqns) |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
391 |
|>> ListPair.unzip; |
33782 | 392 |
|
393 |
(* prove isomorphism and isodefl rules *) |
|
394 |
fun mk_iso_thms ((tbind, REP_eq), (rep_def, abs_def)) thy = |
|
395 |
let |
|
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34149
diff
changeset
|
396 |
fun make thm = Drule.export_without_context (thm OF [REP_eq, abs_def, rep_def]); |
33782 | 397 |
val rep_iso_thm = make @{thm domain_rep_iso}; |
398 |
val abs_iso_thm = make @{thm domain_abs_iso}; |
|
399 |
val isodefl_thm = make @{thm isodefl_abs_rep}; |
|
33797 | 400 |
val rep_iso_bind = Binding.name "rep_iso"; |
401 |
val abs_iso_bind = Binding.name "abs_iso"; |
|
402 |
val isodefl_bind = Binding.name "isodefl_abs_rep"; |
|
403 |
val (_, thy) = thy |
|
404 |
|> Sign.add_path (Binding.name_of tbind) |
|
405 |
|> (PureThy.add_thms o map Thm.no_attributes) |
|
406 |
[(rep_iso_bind, rep_iso_thm), |
|
407 |
(abs_iso_bind, abs_iso_thm), |
|
408 |
(isodefl_bind, isodefl_thm)] |
|
409 |
||> Sign.parent_path; |
|
33782 | 410 |
in |
411 |
(((rep_iso_thm, abs_iso_thm), isodefl_thm), thy) |
|
412 |
end; |
|
35489 | 413 |
val ((iso_thms, isodefl_abs_rep_thms), thy) = |
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
414 |
thy |
33782 | 415 |
|> fold_map mk_iso_thms (dom_binds ~~ REP_eq_thms ~~ rep_abs_defs) |
416 |
|>> ListPair.unzip; |
|
33778 | 417 |
|
35467
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
418 |
(* collect info about rep/abs *) |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
419 |
val iso_infos : Domain_Take_Proofs.iso_info list = |
35467
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
420 |
let |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
421 |
fun mk_info (((lhsT, rhsT), (repC, absC)), (rep_iso, abs_iso)) = |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
422 |
{ |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
423 |
repT = rhsT, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
424 |
absT = lhsT, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
425 |
rep_const = repC, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
426 |
abs_const = absC, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
427 |
rep_inverse = rep_iso, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
428 |
abs_inverse = abs_iso |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
429 |
}; |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
430 |
in |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
431 |
map mk_info (dom_eqns ~~ rep_abs_consts ~~ iso_thms) |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
432 |
end |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
433 |
|
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
434 |
(* declare map functions *) |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
435 |
fun declare_map_const (tbind, (lhsT, rhsT)) thy = |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
436 |
let |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
437 |
val map_type = mapT lhsT; |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
438 |
val map_bind = Binding.suffix_name "_map" tbind; |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
439 |
in |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
440 |
Sign.declare_const ((map_bind, map_type), NoSyn) thy |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
441 |
end; |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
442 |
val (map_consts, thy) = thy |> |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
443 |
fold_map declare_map_const (dom_binds ~~ dom_eqns); |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
444 |
|
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
445 |
(* defining equations for map functions *) |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
446 |
local |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
447 |
fun unprime a = Library.unprefix "'" a; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
448 |
fun mapvar T = Free (unprime (fst (dest_TFree T)), T ->> T); |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
449 |
fun map_lhs (map_const, lhsT) = |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
450 |
(lhsT, list_ccomb (map_const, map mapvar (snd (dest_Type lhsT)))); |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
451 |
val tab1 = map map_lhs (map_consts ~~ map fst dom_eqns); |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
452 |
val Ts = (snd o dest_Type o fst o hd) dom_eqns; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
453 |
val tab = (Ts ~~ map mapvar Ts) @ tab1; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
454 |
fun mk_map_spec (((rep_const, abs_const), map_const), (lhsT, rhsT)) = |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
455 |
let |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
456 |
val lhs = Domain_Take_Proofs.map_of_typ thy tab lhsT; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
457 |
val body = Domain_Take_Proofs.map_of_typ thy tab rhsT; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
458 |
val rhs = mk_cfcomp (abs_const, mk_cfcomp (body, rep_const)); |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
459 |
in mk_eqs (lhs, rhs) end; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
460 |
in |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
461 |
val map_specs = |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
462 |
map mk_map_spec (rep_abs_consts ~~ map_consts ~~ dom_eqns); |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
463 |
end; |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
464 |
|
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
465 |
(* register recursive definition of map functions *) |
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
466 |
val map_binds = map (Binding.suffix_name "_map") dom_binds; |
33788 | 467 |
val ((map_apply_thms, map_unfold_thms), thy) = |
468 |
add_fixdefs (map_binds ~~ map_specs) thy; |
|
469 |
||
470 |
(* prove isodefl rules for map functions *) |
|
471 |
val isodefl_thm = |
|
472 |
let |
|
473 |
fun unprime a = Library.unprefix "'" a; |
|
35474 | 474 |
fun mk_d T = Free ("d" ^ unprime (fst (dest_TFree T)), deflT); |
475 |
fun mk_f T = Free ("f" ^ unprime (fst (dest_TFree T)), T ->> T); |
|
33788 | 476 |
fun mk_assm T = mk_trp (isodefl_const T $ mk_f T $ mk_d T); |
35474 | 477 |
fun mk_goal ((map_const, defl_const), (T, rhsT)) = |
33788 | 478 |
let |
35474 | 479 |
val (_, Ts) = dest_Type T; |
35478 | 480 |
val map_term = list_ccomb (map_const, map mk_f Ts); |
481 |
val defl_term = list_ccomb (defl_const, map mk_d Ts); |
|
33788 | 482 |
in isodefl_const T $ map_term $ defl_term end; |
483 |
val assms = (map mk_assm o snd o dest_Type o fst o hd) dom_eqns; |
|
484 |
val goals = map mk_goal (map_consts ~~ defl_consts ~~ dom_eqns); |
|
485 |
val goal = mk_trp (foldr1 HOLogic.mk_conj goals); |
|
486 |
val start_thms = |
|
487 |
@{thm split_def} :: defl_apply_thms @ map_apply_thms; |
|
488 |
val adm_rules = |
|
489 |
@{thms adm_conj adm_isodefl cont2cont_fst cont2cont_snd cont_id}; |
|
490 |
val bottom_rules = |
|
491 |
@{thms fst_strict snd_strict isodefl_bottom simp_thms}; |
|
492 |
val isodefl_rules = |
|
33791 | 493 |
@{thms conjI isodefl_ID_REP} |
494 |
@ isodefl_abs_rep_thms |
|
495 |
@ IsodeflData.get thy; |
|
33845 | 496 |
in |
497 |
Goal.prove_global thy [] assms goal (fn {prems, ...} => |
|
498 |
EVERY |
|
33788 | 499 |
[simp_tac (HOL_basic_ss addsimps start_thms) 1, |
33791 | 500 |
(* FIXME: how reliable is unification here? *) |
501 |
(* Maybe I should instantiate the rule. *) |
|
33788 | 502 |
rtac @{thm parallel_fix_ind} 1, |
503 |
REPEAT (resolve_tac adm_rules 1), |
|
504 |
simp_tac (HOL_basic_ss addsimps bottom_rules) 1, |
|
505 |
simp_tac beta_ss 1, |
|
506 |
simp_tac (HOL_basic_ss addsimps @{thms fst_conv snd_conv}) 1, |
|
507 |
REPEAT (etac @{thm conjE} 1), |
|
33845 | 508 |
REPEAT (resolve_tac (isodefl_rules @ prems) 1 ORELSE atac 1)]) |
33788 | 509 |
end; |
33789 | 510 |
val isodefl_binds = map (Binding.prefix_name "isodefl_") dom_binds; |
511 |
fun conjuncts [] thm = [] |
|
512 |
| conjuncts (n::[]) thm = [(n, thm)] |
|
513 |
| conjuncts (n::ns) thm = let |
|
514 |
val thmL = thm RS @{thm conjunct1}; |
|
515 |
val thmR = thm RS @{thm conjunct2}; |
|
516 |
in (n, thmL):: conjuncts ns thmR end; |
|
517 |
val (isodefl_thms, thy) = thy |> |
|
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34149
diff
changeset
|
518 |
(PureThy.add_thms o map (Thm.no_attributes o apsnd Drule.export_without_context)) |
33789 | 519 |
(conjuncts isodefl_binds isodefl_thm); |
33791 | 520 |
val thy = IsodeflData.map (fold Thm.add_thm isodefl_thms) thy; |
33793 | 521 |
|
522 |
(* prove map_ID theorems *) |
|
523 |
fun prove_map_ID_thm |
|
524 |
(((map_const, (lhsT, _)), REP_thm), isodefl_thm) = |
|
525 |
let |
|
526 |
val Ts = snd (dest_Type lhsT); |
|
35478 | 527 |
val lhs = list_ccomb (map_const, map mk_ID Ts); |
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
528 |
val goal = mk_eqs (lhs, mk_ID lhsT); |
33793 | 529 |
val tac = EVERY |
530 |
[rtac @{thm isodefl_REP_imp_ID} 1, |
|
531 |
stac REP_thm 1, |
|
532 |
rtac isodefl_thm 1, |
|
533 |
REPEAT (rtac @{thm isodefl_ID_REP} 1)]; |
|
534 |
in |
|
535 |
Goal.prove_global thy [] [] goal (K tac) |
|
536 |
end; |
|
537 |
val map_ID_binds = map (Binding.suffix_name "_map_ID") dom_binds; |
|
538 |
val map_ID_thms = |
|
539 |
map prove_map_ID_thm |
|
540 |
(map_consts ~~ dom_eqns ~~ REP_thms ~~ isodefl_thms); |
|
541 |
val (_, thy) = thy |> |
|
542 |
(PureThy.add_thms o map Thm.no_attributes) |
|
543 |
(map_ID_binds ~~ map_ID_thms); |
|
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
544 |
val thy = MapIdData.map (fold Thm.add_thm map_ID_thms) thy; |
33802
48ce3a1063f2
domain_isomorphism package defines copy functions
huffman
parents:
33801
diff
changeset
|
545 |
|
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
546 |
(* prove deflation theorems for map functions *) |
35489 | 547 |
val deflation_abs_rep_thms = map deflation_abs_rep iso_infos; |
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
548 |
val deflation_map_thm = |
33802
48ce3a1063f2
domain_isomorphism package defines copy functions
huffman
parents:
33801
diff
changeset
|
549 |
let |
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
550 |
fun unprime a = Library.unprefix "'" a; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
551 |
fun mk_f T = Free (unprime (fst (dest_TFree T)), T ->> T); |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
552 |
fun mk_assm T = mk_trp (mk_deflation (mk_f T)); |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
553 |
fun mk_goal (map_const, (lhsT, rhsT)) = |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
554 |
let |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
555 |
val (_, Ts) = dest_Type lhsT; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
556 |
val map_term = list_ccomb (map_const, map mk_f Ts); |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
557 |
in mk_deflation map_term end; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
558 |
val assms = (map mk_assm o snd o dest_Type o fst o hd) dom_eqns; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
559 |
val goals = map mk_goal (map_consts ~~ dom_eqns); |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
560 |
val goal = mk_trp (foldr1 HOLogic.mk_conj goals); |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
561 |
val start_thms = |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
562 |
@{thm split_def} :: map_apply_thms; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
563 |
val adm_rules = |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
564 |
@{thms adm_conj adm_subst [OF _ adm_deflation] |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
565 |
cont2cont_fst cont2cont_snd cont_id}; |
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
566 |
val bottom_rules = |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
567 |
@{thms fst_strict snd_strict deflation_UU simp_thms}; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
568 |
val deflation_rules = |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
569 |
@{thms conjI deflation_ID} |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
570 |
@ deflation_abs_rep_thms |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
571 |
@ Domain_Take_Proofs.get_deflation_thms thy; |
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
572 |
in |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
573 |
Goal.prove_global thy [] assms goal (fn {prems, ...} => |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
574 |
EVERY |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
575 |
[simp_tac (HOL_basic_ss addsimps start_thms) 1, |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
576 |
rtac @{thm fix_ind} 1, |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
577 |
REPEAT (resolve_tac adm_rules 1), |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
578 |
simp_tac (HOL_basic_ss addsimps bottom_rules) 1, |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
579 |
simp_tac beta_ss 1, |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
580 |
simp_tac (HOL_basic_ss addsimps @{thms fst_conv snd_conv}) 1, |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
581 |
REPEAT (etac @{thm conjE} 1), |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
582 |
REPEAT (resolve_tac (deflation_rules @ prems) 1 ORELSE atac 1)]) |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
583 |
end; |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
584 |
val deflation_map_binds = dom_binds |> |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
585 |
map (Binding.prefix_name "deflation_" o Binding.suffix_name "_map"); |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
586 |
val (deflation_map_thms, thy) = thy |> |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
587 |
(PureThy.add_thms o map (Thm.no_attributes o apsnd Drule.export_without_context)) |
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
588 |
(conjuncts deflation_map_binds deflation_map_thm); |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
589 |
|
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
590 |
(* register map functions in theory data *) |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
591 |
local |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
592 |
fun register_map ((dname, map_name), defl_thm) = |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
593 |
Domain_Take_Proofs.add_map_function (dname, map_name, defl_thm); |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
594 |
val dnames = map (fst o dest_Type o fst) dom_eqns; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
595 |
val map_names = map (fst o dest_Const) map_consts; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
596 |
in |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
597 |
val thy = |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
598 |
fold register_map (dnames ~~ map_names ~~ deflation_map_thms) thy; |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
599 |
end; |
33802
48ce3a1063f2
domain_isomorphism package defines copy functions
huffman
parents:
33801
diff
changeset
|
600 |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
601 |
(* definitions and proofs related to take functions *) |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
602 |
val (take_info, thy) = |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
603 |
Domain_Take_Proofs.define_take_functions |
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
604 |
(dom_binds ~~ iso_infos) thy; |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
605 |
val {take_consts, take_defs, chain_take_thms, take_0_thms, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
606 |
take_Suc_thms, deflation_take_thms} = take_info; |
33807
ce8d2e8bca21
domain_isomorphism package defines combined copy function
huffman
parents:
33802
diff
changeset
|
607 |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
608 |
(* least-upper-bound lemma for take functions *) |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
609 |
val lub_take_lemma = |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
610 |
let |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
611 |
val lhs = mk_tuple (map mk_lub take_consts); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
612 |
fun mk_map_ID (map_const, (lhsT, rhsT)) = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
613 |
list_ccomb (map_const, map mk_ID (snd (dest_Type lhsT))); |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
614 |
val rhs = mk_tuple (map mk_map_ID (map_consts ~~ dom_eqns)); |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
615 |
val goal = mk_trp (mk_eq (lhs, rhs)); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
616 |
val start_rules = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
617 |
@{thms thelub_Pair [symmetric] ch2ch_Pair} @ chain_take_thms |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
618 |
@ @{thms pair_collapse split_def} |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
619 |
@ map_apply_thms @ MapIdData.get thy; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
620 |
val rules0 = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
621 |
@{thms iterate_0 Pair_strict} @ take_0_thms; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
622 |
val rules1 = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
623 |
@{thms iterate_Suc Pair_fst_snd_eq fst_conv snd_conv} |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
624 |
@ take_Suc_thms; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
625 |
val tac = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
626 |
EVERY |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
627 |
[simp_tac (HOL_basic_ss addsimps start_rules) 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
628 |
simp_tac (HOL_basic_ss addsimps @{thms fix_def2}) 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
629 |
rtac @{thm lub_eq} 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
630 |
rtac @{thm nat.induct} 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
631 |
simp_tac (HOL_basic_ss addsimps rules0) 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
632 |
asm_full_simp_tac (beta_ss addsimps rules1) 1]; |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
633 |
in |
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
634 |
Goal.prove_global thy [] [] goal (K tac) |
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
635 |
end; |
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
636 |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
637 |
(* prove lub of take equals ID *) |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
638 |
fun prove_lub_take (((bind, take_const), map_ID_thm), (lhsT, rhsT)) thy = |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
639 |
let |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
640 |
val i = Free ("i", natT); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
641 |
val goal = mk_eqs (mk_lub (lambda i (take_const $ i)), mk_ID lhsT); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
642 |
val tac = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
643 |
EVERY |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
644 |
[rtac @{thm trans} 1, rtac map_ID_thm 2, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
645 |
cut_facts_tac [lub_take_lemma] 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
646 |
REPEAT (etac @{thm Pair_inject} 1), atac 1]; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
647 |
val lub_take_thm = Goal.prove_global thy [] [] goal (K tac); |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
648 |
in |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
649 |
add_qualified_thm "lub_take" (Binding.name_of bind, lub_take_thm) thy |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
650 |
end; |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
651 |
val (lub_take_thms, thy) = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
652 |
fold_map prove_lub_take |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
653 |
(dom_binds ~~ take_consts ~~ map_ID_thms ~~ dom_eqns) thy; |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
654 |
|
33774 | 655 |
in |
35489 | 656 |
(iso_infos, thy) |
33774 | 657 |
end; |
658 |
||
659 |
val domain_isomorphism = gen_domain_isomorphism cert_typ; |
|
35467
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
660 |
val domain_isomorphism_cmd = snd oo gen_domain_isomorphism read_typ; |
33774 | 661 |
|
662 |
(******************************************************************************) |
|
663 |
(******************************** outer syntax ********************************) |
|
664 |
(******************************************************************************) |
|
665 |
||
666 |
local |
|
667 |
||
668 |
structure P = OuterParse and K = OuterKeyword |
|
669 |
||
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
670 |
val parse_domain_iso : |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
671 |
(string list * binding * mixfix * string * (binding * binding) option) |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
672 |
parser = |
35351
7425aece4ee3
allow general mixfix syntax for type constructors;
wenzelm
parents:
35021
diff
changeset
|
673 |
(P.type_args -- P.binding -- P.opt_mixfix -- (P.$$$ "=" |-- P.typ) -- |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
674 |
Scan.option (P.$$$ "morphisms" |-- P.!!! (P.binding -- P.binding))) |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
675 |
>> (fn ((((vs, t), mx), rhs), morphs) => (vs, t, mx, rhs, morphs)); |
33774 | 676 |
|
677 |
val parse_domain_isos = P.and_list1 parse_domain_iso; |
|
678 |
||
679 |
in |
|
680 |
||
681 |
val _ = |
|
682 |
OuterSyntax.command "domain_isomorphism" "define domain isomorphisms (HOLCF)" K.thy_decl |
|
683 |
(parse_domain_isos >> (Toplevel.theory o domain_isomorphism_cmd)); |
|
684 |
||
685 |
end; |
|
686 |
||
687 |
end; |