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