author | wenzelm |
Tue, 13 Mar 2012 20:04:24 +0100 | |
changeset 46909 | 3c73a121a387 |
parent 46708 | b138dee7bed3 |
child 46949 | 94aa7b81bcf6 |
permissions | -rw-r--r-- |
42151 | 1 |
(* Title: HOL/HOLCF/Tools/Domain/domain_isomorphism.ML |
33774 | 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 : |
35657
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
10 |
(string list * binding * mixfix * typ |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
11 |
* (binding * binding) option) list -> |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
12 |
theory -> |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
13 |
(Domain_Take_Proofs.iso_info list |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
14 |
* Domain_Take_Proofs.take_induct_info) * theory |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
15 |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
16 |
val define_map_functions : |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
17 |
(binding * Domain_Take_Proofs.iso_info) list -> |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
18 |
theory -> |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
19 |
{ |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
20 |
map_consts : term list, |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
21 |
map_apply_thms : thm list, |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
22 |
map_unfold_thms : thm list, |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
23 |
map_cont_thm : thm, |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
24 |
deflation_map_thms : thm list |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
25 |
} |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
26 |
* theory |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
27 |
|
35489 | 28 |
val domain_isomorphism_cmd : |
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
29 |
(string list * binding * mixfix * string * (binding * binding) option) list |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
30 |
-> theory -> theory |
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
31 |
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
32 |
val setup : theory -> theory |
40832 | 33 |
end |
33774 | 34 |
|
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
35 |
structure Domain_Isomorphism : DOMAIN_ISOMORPHISM = |
33774 | 36 |
struct |
37 |
||
40833
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
38 |
val beta_ss = |
45654 | 39 |
HOL_basic_ss addsimps @{thms simp_thms} addsimprocs [@{simproc beta_cfun_proc}] |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
40 |
|
40832 | 41 |
fun is_cpo thy T = Sign.of_sort thy (T, @{sort cpo}) |
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
42 |
|
33774 | 43 |
(******************************************************************************) |
33791 | 44 |
(******************************** theory data *********************************) |
45 |
(******************************************************************************) |
|
46 |
||
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
47 |
structure RepData = Named_Thms |
33791 | 48 |
( |
45294 | 49 |
val name = @{binding domain_defl_simps} |
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
50 |
val description = "theorems like DEFL('a t) = t_defl$DEFL('a)" |
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
51 |
) |
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
52 |
|
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
53 |
structure IsodeflData = Named_Thms |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
54 |
( |
45294 | 55 |
val name = @{binding domain_isodefl} |
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
56 |
val description = "theorems like isodefl d t ==> isodefl (foo_map$d) (foo_defl$t)" |
40832 | 57 |
) |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
58 |
|
40489 | 59 |
val setup = RepData.setup #> IsodeflData.setup |
33801 | 60 |
|
33791 | 61 |
|
62 |
(******************************************************************************) |
|
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35474
diff
changeset
|
63 |
(************************** building types and terms **************************) |
33774 | 64 |
(******************************************************************************) |
65 |
||
40832 | 66 |
open HOLCF_Library |
33774 | 67 |
|
40832 | 68 |
infixr 6 ->> |
69 |
infixr -->> |
|
33774 | 70 |
|
40832 | 71 |
val udomT = @{typ udom} |
41287
029a6fc1bfb8
type 'defl' takes a type parameter again (cf. b525988432e9)
huffman
parents:
40833
diff
changeset
|
72 |
val deflT = @{typ "udom defl"} |
41292
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
73 |
val udeflT = @{typ "udom u defl"} |
33774 | 74 |
|
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
75 |
fun mk_DEFL T = |
40832 | 76 |
Const (@{const_name defl}, Term.itselfT T --> deflT) $ Logic.mk_type T |
33774 | 77 |
|
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
78 |
fun dest_DEFL (Const (@{const_name defl}, _) $ t) = Logic.dest_type t |
40832 | 79 |
| dest_DEFL t = raise TERM ("dest_DEFL", [t]) |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
80 |
|
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
81 |
fun mk_LIFTDEFL T = |
41292
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
82 |
Const (@{const_name liftdefl}, Term.itselfT T --> udeflT) $ Logic.mk_type T |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
83 |
|
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
84 |
fun dest_LIFTDEFL (Const (@{const_name liftdefl}, _) $ t) = Logic.dest_type t |
40832 | 85 |
| dest_LIFTDEFL t = raise TERM ("dest_LIFTDEFL", [t]) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
86 |
|
40832 | 87 |
fun mk_u_defl t = mk_capply (@{const "u_defl"}, t) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
88 |
|
40832 | 89 |
fun emb_const T = Const (@{const_name emb}, T ->> udomT) |
90 |
fun prj_const T = Const (@{const_name prj}, udomT ->> T) |
|
91 |
fun coerce_const (T, U) = mk_cfcomp (prj_const U, emb_const T) |
|
33778 | 92 |
|
33788 | 93 |
fun isodefl_const T = |
40832 | 94 |
Const (@{const_name isodefl}, (T ->> T) --> deflT --> HOLogic.boolT) |
33788 | 95 |
|
41292
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
96 |
fun isodefl'_const T = |
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
97 |
Const (@{const_name isodefl'}, (T ->> T) --> udeflT --> HOLogic.boolT) |
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
98 |
|
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
99 |
fun mk_deflation t = |
40832 | 100 |
Const (@{const_name deflation}, Term.fastype_of t --> boolT) $ t |
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
101 |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
102 |
(* splits a cterm into the right and lefthand sides of equality *) |
40832 | 103 |
fun dest_eqs t = HOLogic.dest_eq (HOLogic.dest_Trueprop t) |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
104 |
|
40832 | 105 |
fun mk_eqs (t, u) = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u)) |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
106 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
107 |
(******************************************************************************) |
35489 | 108 |
(****************************** isomorphism info ******************************) |
109 |
(******************************************************************************) |
|
110 |
||
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35498
diff
changeset
|
111 |
fun deflation_abs_rep (info : Domain_Take_Proofs.iso_info) : thm = |
35489 | 112 |
let |
40832 | 113 |
val abs_iso = #abs_inverse info |
114 |
val rep_iso = #rep_inverse info |
|
115 |
val thm = @{thm deflation_abs_rep} OF [abs_iso, rep_iso] |
|
35489 | 116 |
in |
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35842
diff
changeset
|
117 |
Drule.zero_var_indexes thm |
35489 | 118 |
end |
119 |
||
120 |
(******************************************************************************) |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
121 |
(*************** fixed-point definitions and unfolding theorems ***************) |
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 |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
124 |
fun mk_projs [] _ = [] |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
125 |
| mk_projs (x::[]) t = [(x, t)] |
40832 | 126 |
| mk_projs (x::xs) t = (x, mk_fst t) :: mk_projs xs (mk_snd t) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
127 |
|
33775
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) |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
130 |
(thy : theory) : (thm list * thm list * thm) * theory = |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
131 |
let |
40832 | 132 |
val binds = map fst spec |
133 |
val (lhss, rhss) = ListPair.unzip (map (dest_eqs o snd) spec) |
|
134 |
val functional = lambda_tuple lhss (mk_tuple rhss) |
|
135 |
val fixpoint = mk_fix (mk_cabs functional) |
|
33775
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 *) |
40832 | 138 |
val projs = mk_projs lhss fixpoint |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
139 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
140 |
(* convert parameters to lambda abstractions *) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
141 |
fun mk_eqn (lhs, rhs) = |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
142 |
case lhs of |
40327 | 143 |
Const (@{const_name Rep_cfun}, _) $ f $ (x as Free _) => |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
144 |
mk_eqn (f, big_lambda x rhs) |
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
145 |
| f $ Const (@{const_name TYPE}, T) => |
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
146 |
mk_eqn (f, Abs ("t", T, rhs)) |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
147 |
| Const _ => Logic.mk_equals (lhs, rhs) |
40832 | 148 |
| _ => raise TERM ("lhs not of correct form", [lhs, rhs]) |
149 |
val eqns = map mk_eqn projs |
|
33775
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 |
(* register constant definitions *) |
33777 | 152 |
val (fixdef_thms, thy) = |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
153 |
(Global_Theory.add_defs false o map Thm.no_attributes) |
46909 | 154 |
(map Thm.def_binding binds ~~ eqns) thy |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
155 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
156 |
(* prove applied version of definitions *) |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
157 |
fun prove_proj (lhs, rhs) = |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
158 |
let |
40833
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
159 |
val tac = rewrite_goals_tac fixdef_thms THEN (simp_tac beta_ss) 1 |
40832 | 160 |
val goal = Logic.mk_equals (lhs, rhs) |
161 |
in Goal.prove_global thy [] [] goal (K tac) end |
|
162 |
val proj_thms = map prove_proj projs |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
163 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
164 |
(* mk_tuple lhss == fixpoint *) |
40832 | 165 |
fun pair_equalI (thm1, thm2) = @{thm Pair_equalI} OF [thm1, thm2] |
166 |
val tuple_fixdef_thm = foldr1 pair_equalI proj_thms |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
167 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
168 |
val cont_thm = |
40833
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
169 |
let |
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
170 |
val prop = mk_trp (mk_cont functional) |
42361 | 171 |
val rules = Cont2ContData.get (Proof_Context.init_global thy) |
40833
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
172 |
val tac = REPEAT_ALL_NEW (match_tac rules) 1 |
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
173 |
in |
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
174 |
Goal.prove_global thy [] [] prop (K tac) |
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
175 |
end |
4f130bd9e17e
internal domain package proofs use cont2cont simproc instead of a fixed list of cont rules
huffman
parents:
40832
diff
changeset
|
176 |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
177 |
val tuple_unfold_thm = |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
178 |
(@{thm def_cont_fix_eq} OF [tuple_fixdef_thm, cont_thm]) |
42361 | 179 |
|> Local_Defs.unfold (Proof_Context.init_global thy) @{thms split_conv} |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
180 |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
181 |
fun mk_unfold_thms [] _ = [] |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
182 |
| mk_unfold_thms (n::[]) thm = [(n, thm)] |
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
183 |
| mk_unfold_thms (n::ns) thm = let |
40832 | 184 |
val thmL = thm RS @{thm Pair_eqD1} |
185 |
val thmR = thm RS @{thm Pair_eqD2} |
|
186 |
in (n, thmL) :: mk_unfold_thms ns thmR end |
|
187 |
val unfold_binds = map (Binding.suffix_name "_unfold") binds |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
188 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
189 |
(* register unfold theorems *) |
33777 | 190 |
val (unfold_thms, thy) = |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
191 |
(Global_Theory.add_thms o map (Thm.no_attributes o apsnd Drule.zero_var_indexes)) |
40832 | 192 |
(mk_unfold_thms unfold_binds tuple_unfold_thm) thy |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
193 |
in |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
194 |
((proj_thms, unfold_thms, cont_thm), thy) |
40832 | 195 |
end |
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
196 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
197 |
|
33774 | 198 |
(******************************************************************************) |
33790 | 199 |
(****************** deflation combinators and map functions *******************) |
200 |
(******************************************************************************) |
|
33774 | 201 |
|
202 |
fun defl_of_typ |
|
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
203 |
(thy : theory) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
204 |
(tab1 : (typ * term) list) |
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
205 |
(tab2 : (typ * term) list) |
33774 | 206 |
(T : typ) : term = |
207 |
let |
|
42361 | 208 |
val defl_simps = RepData.get (Proof_Context.init_global thy) |
40832 | 209 |
val rules = map (Thm.concl_of #> HOLogic.dest_Trueprop #> HOLogic.dest_eq) defl_simps |
210 |
val rules' = map (apfst mk_DEFL) tab1 @ map (apfst mk_LIFTDEFL) tab2 |
|
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
211 |
fun proc1 t = |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
212 |
(case dest_DEFL t of |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
213 |
TFree (a, _) => SOME (Free ("d" ^ Library.unprefix "'" a, deflT)) |
40832 | 214 |
| _ => NONE) handle TERM _ => NONE |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
215 |
fun proc2 t = |
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
216 |
(case dest_LIFTDEFL t of |
41292
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
217 |
TFree (a, _) => SOME (Free ("p" ^ Library.unprefix "'" a, udeflT)) |
40832 | 218 |
| _ => NONE) handle TERM _ => NONE |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
219 |
in |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
220 |
Pattern.rewrite_term thy (rules @ rules') [proc1, proc2] (mk_DEFL T) |
40832 | 221 |
end |
33774 | 222 |
|
223 |
(******************************************************************************) |
|
35477 | 224 |
(********************* declaring definitions and theorems *********************) |
225 |
(******************************************************************************) |
|
226 |
||
227 |
fun define_const |
|
228 |
(bind : binding, rhs : term) |
|
229 |
(thy : theory) |
|
230 |
: (term * thm) * theory = |
|
231 |
let |
|
40832 | 232 |
val typ = Term.fastype_of rhs |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
233 |
val (const, thy) = Sign.declare_const_global ((bind, typ), NoSyn) thy |
40832 | 234 |
val eqn = Logic.mk_equals (const, rhs) |
46909 | 235 |
val def = Thm.no_attributes (Thm.def_binding bind, eqn) |
40832 | 236 |
val (def_thm, thy) = yield_singleton (Global_Theory.add_defs false) def thy |
35477 | 237 |
in |
238 |
((const, def_thm), thy) |
|
40832 | 239 |
end |
35477 | 240 |
|
35773 | 241 |
fun add_qualified_thm name (dbind, thm) = |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
242 |
yield_singleton Global_Theory.add_thms |
40832 | 243 |
((Binding.qualified true name dbind, thm), []) |
35489 | 244 |
|
245 |
(******************************************************************************) |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
246 |
(*************************** defining map functions ***************************) |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
247 |
(******************************************************************************) |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
248 |
|
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
249 |
fun define_map_functions |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
250 |
(spec : (binding * Domain_Take_Proofs.iso_info) list) |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
251 |
(thy : theory) = |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
252 |
let |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
253 |
|
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
254 |
(* retrieve components of spec *) |
40832 | 255 |
val dbinds = map fst spec |
256 |
val iso_infos = map snd spec |
|
257 |
val dom_eqns = map (fn x => (#absT x, #repT x)) iso_infos |
|
258 |
val rep_abs_consts = map (fn x => (#rep_const x, #abs_const x)) iso_infos |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
259 |
|
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
260 |
fun mapT (T as Type (_, Ts)) = |
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
261 |
(map (fn T => T ->> T) (filter (is_cpo thy) Ts)) -->> (T ->> T) |
40832 | 262 |
| mapT T = T ->> T |
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
263 |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
264 |
(* declare map functions *) |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
265 |
fun declare_map_const (tbind, (lhsT, _)) thy = |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
266 |
let |
40832 | 267 |
val map_type = mapT lhsT |
268 |
val map_bind = Binding.suffix_name "_map" tbind |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
269 |
in |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
270 |
Sign.declare_const_global ((map_bind, map_type), NoSyn) thy |
40832 | 271 |
end |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
272 |
val (map_consts, thy) = thy |> |
40832 | 273 |
fold_map declare_map_const (dbinds ~~ dom_eqns) |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
274 |
|
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
275 |
(* defining equations for map functions *) |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
276 |
local |
40832 | 277 |
fun unprime a = Library.unprefix "'" a |
278 |
fun mapvar T = Free (unprime (fst (dest_TFree T)), T ->> T) |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
279 |
fun map_lhs (map_const, lhsT) = |
40832 | 280 |
(lhsT, list_ccomb (map_const, map mapvar (filter (is_cpo thy) (snd (dest_Type lhsT))))) |
281 |
val tab1 = map map_lhs (map_consts ~~ map fst dom_eqns) |
|
282 |
val Ts = (snd o dest_Type o fst o hd) dom_eqns |
|
283 |
val tab = (Ts ~~ map mapvar Ts) @ tab1 |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
284 |
fun mk_map_spec (((rep_const, abs_const), _), (lhsT, rhsT)) = |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
285 |
let |
40832 | 286 |
val lhs = Domain_Take_Proofs.map_of_typ thy tab lhsT |
287 |
val body = Domain_Take_Proofs.map_of_typ thy tab rhsT |
|
288 |
val rhs = mk_cfcomp (abs_const, mk_cfcomp (body, rep_const)) |
|
289 |
in mk_eqs (lhs, rhs) end |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
290 |
in |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
291 |
val map_specs = |
40832 | 292 |
map mk_map_spec (rep_abs_consts ~~ map_consts ~~ dom_eqns) |
293 |
end |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
294 |
|
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
295 |
(* register recursive definition of map functions *) |
40832 | 296 |
val map_binds = map (Binding.suffix_name "_map") dbinds |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
297 |
val ((map_apply_thms, map_unfold_thms, map_cont_thm), thy) = |
40832 | 298 |
add_fixdefs (map_binds ~~ map_specs) thy |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
299 |
|
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
300 |
(* prove deflation theorems for map functions *) |
40832 | 301 |
val deflation_abs_rep_thms = map deflation_abs_rep iso_infos |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
302 |
val deflation_map_thm = |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
303 |
let |
40832 | 304 |
fun unprime a = Library.unprefix "'" a |
305 |
fun mk_f T = Free (unprime (fst (dest_TFree T)), T ->> T) |
|
306 |
fun mk_assm T = mk_trp (mk_deflation (mk_f T)) |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
307 |
fun mk_goal (map_const, (lhsT, _)) = |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
308 |
let |
40832 | 309 |
val (_, Ts) = dest_Type lhsT |
310 |
val map_term = list_ccomb (map_const, map mk_f (filter (is_cpo thy) Ts)) |
|
311 |
in mk_deflation map_term end |
|
312 |
val assms = (map mk_assm o filter (is_cpo thy) o snd o dest_Type o fst o hd) dom_eqns |
|
313 |
val goals = map mk_goal (map_consts ~~ dom_eqns) |
|
314 |
val goal = mk_trp (foldr1 HOLogic.mk_conj goals) |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
315 |
val adm_rules = |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
316 |
@{thms adm_conj adm_subst [OF _ adm_deflation] |
40832 | 317 |
cont2cont_fst cont2cont_snd cont_id} |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
318 |
val bottom_rules = |
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
41324
diff
changeset
|
319 |
@{thms fst_strict snd_strict deflation_bottom simp_thms} |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
320 |
val tuple_rules = |
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
321 |
@{thms split_def fst_conv snd_conv} |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
322 |
val deflation_rules = |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
323 |
@{thms conjI deflation_ID} |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
324 |
@ deflation_abs_rep_thms |
40832 | 325 |
@ Domain_Take_Proofs.get_deflation_thms thy |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
326 |
in |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
327 |
Goal.prove_global thy [] assms goal (fn {prems, ...} => |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
328 |
EVERY |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
329 |
[rewrite_goals_tac map_apply_thms, |
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
330 |
rtac (map_cont_thm RS @{thm cont_fix_ind}) 1, |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
331 |
REPEAT (resolve_tac adm_rules 1), |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
332 |
simp_tac (HOL_basic_ss addsimps bottom_rules) 1, |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
333 |
simp_tac (HOL_basic_ss addsimps tuple_rules) 1, |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
334 |
REPEAT (etac @{thm conjE} 1), |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
335 |
REPEAT (resolve_tac (deflation_rules @ prems) 1 ORELSE atac 1)]) |
40832 | 336 |
end |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
337 |
fun conjuncts [] _ = [] |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
338 |
| conjuncts (n::[]) thm = [(n, thm)] |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
339 |
| conjuncts (n::ns) thm = let |
40832 | 340 |
val thmL = thm RS @{thm conjunct1} |
341 |
val thmR = thm RS @{thm conjunct2} |
|
342 |
in (n, thmL):: conjuncts ns thmR end |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
343 |
val deflation_map_binds = dbinds |> |
40832 | 344 |
map (Binding.prefix_name "deflation_" o Binding.suffix_name "_map") |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
345 |
val (deflation_map_thms, thy) = thy |> |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
346 |
(Global_Theory.add_thms o map (Thm.no_attributes o apsnd Drule.zero_var_indexes)) |
40832 | 347 |
(conjuncts deflation_map_binds deflation_map_thm) |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
348 |
|
40737
2037021f034f
remove map function names from domain package theory data
huffman
parents:
40575
diff
changeset
|
349 |
(* register indirect recursion in theory data *) |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
350 |
local |
40737
2037021f034f
remove map function names from domain package theory data
huffman
parents:
40575
diff
changeset
|
351 |
fun register_map (dname, args) = |
40832 | 352 |
Domain_Take_Proofs.add_rec_type (dname, args) |
353 |
val dnames = map (fst o dest_Type o fst) dom_eqns |
|
354 |
fun args (T, _) = case T of Type (_, Ts) => map (is_cpo thy) Ts | _ => [] |
|
355 |
val argss = map args dom_eqns |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
356 |
in |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
357 |
val thy = |
40832 | 358 |
fold register_map (dnames ~~ argss) thy |
359 |
end |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
360 |
|
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
361 |
(* register deflation theorems *) |
40832 | 362 |
val thy = fold Domain_Take_Proofs.add_deflation_thm deflation_map_thms thy |
40216
366309dfaf60
use Named_Thms instead of Theory_Data for some domain package theorems
huffman
parents:
40037
diff
changeset
|
363 |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
364 |
val result = |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
365 |
{ |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
366 |
map_consts = map_consts, |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
367 |
map_apply_thms = map_apply_thms, |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
368 |
map_unfold_thms = map_unfold_thms, |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
369 |
map_cont_thm = map_cont_thm, |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
370 |
deflation_map_thms = deflation_map_thms |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
371 |
} |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
372 |
in |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
373 |
(result, thy) |
40832 | 374 |
end |
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
375 |
|
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
376 |
(******************************************************************************) |
35477 | 377 |
(******************************* main function ********************************) |
378 |
(******************************************************************************) |
|
33774 | 379 |
|
380 |
fun read_typ thy str sorts = |
|
381 |
let |
|
42361 | 382 |
val ctxt = Proof_Context.init_global thy |
40832 | 383 |
|> fold (Variable.declare_typ o TFree) sorts |
384 |
val T = Syntax.read_typ ctxt str |
|
385 |
in (T, Term.add_tfreesT T sorts) end |
|
33774 | 386 |
|
387 |
fun cert_typ sign raw_T sorts = |
|
388 |
let |
|
389 |
val T = Type.no_tvars (Sign.certify_typ sign raw_T) |
|
40832 | 390 |
handle TYPE (msg, _, _) => error msg |
391 |
val sorts' = Term.add_tfreesT T sorts |
|
33774 | 392 |
val _ = |
393 |
case duplicates (op =) (map fst sorts') of |
|
394 |
[] => () |
|
395 |
| dups => error ("Inconsistent sort constraints for " ^ commas dups) |
|
40832 | 396 |
in (T, sorts') end |
33774 | 397 |
|
398 |
fun gen_domain_isomorphism |
|
399 |
(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
|
400 |
(doms_raw: (string list * binding * mixfix * 'a * (binding * binding) option) list) |
33774 | 401 |
(thy: theory) |
35657
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
402 |
: (Domain_Take_Proofs.iso_info list |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
403 |
* Domain_Take_Proofs.take_induct_info) * theory = |
33774 | 404 |
let |
40832 | 405 |
val _ = Theory.requires thy "Domain" "domain isomorphisms" |
33774 | 406 |
|
407 |
(* this theory is used just for parsing *) |
|
408 |
val tmp_thy = thy |> |
|
409 |
Theory.copy |> |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
410 |
Sign.add_types_global (map (fn (tvs, tbind, mx, _, _) => |
40832 | 411 |
(tbind, length tvs, mx)) doms_raw) |
33774 | 412 |
|
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
413 |
fun prep_dom thy (vs, t, mx, typ_raw, morphs) sorts = |
33774 | 414 |
let val (typ, sorts') = prep_typ thy typ_raw sorts |
40832 | 415 |
in ((vs, t, mx, typ, morphs), sorts') end |
33774 | 416 |
|
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
417 |
val (doms : (string list * binding * mixfix * typ * (binding * binding) option) list, |
33774 | 418 |
sorts : (string * sort) list) = |
40832 | 419 |
fold_map (prep_dom tmp_thy) doms_raw [] |
33774 | 420 |
|
40486 | 421 |
(* lookup function for sorts of type variables *) |
40832 | 422 |
fun the_sort v = the (AList.lookup (op =) sorts v) |
40486 | 423 |
|
40490
05be0c37db1d
add bifiniteness check for domain_isomorphism command
huffman
parents:
40489
diff
changeset
|
424 |
(* declare arities in temporary theory *) |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
425 |
val tmp_thy = |
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
426 |
let |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
427 |
fun arity (vs, tbind, _, _, _) = |
40832 | 428 |
(Sign.full_name thy tbind, map the_sort vs, @{sort "domain"}) |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
429 |
in |
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
430 |
fold AxClass.axiomatize_arity (map arity doms) tmp_thy |
40832 | 431 |
end |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
432 |
|
40490
05be0c37db1d
add bifiniteness check for domain_isomorphism command
huffman
parents:
40489
diff
changeset
|
433 |
(* check bifiniteness of right-hand sides *) |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
434 |
fun check_rhs (_, _, _, rhs, _) = |
40497 | 435 |
if Sign.of_sort tmp_thy (rhs, @{sort "domain"}) then () |
436 |
else error ("Type not of sort domain: " ^ |
|
40832 | 437 |
quote (Syntax.string_of_typ_global tmp_thy rhs)) |
438 |
val _ = map check_rhs doms |
|
40490
05be0c37db1d
add bifiniteness check for domain_isomorphism command
huffman
parents:
40489
diff
changeset
|
439 |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
440 |
(* domain equations *) |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
441 |
fun mk_dom_eqn (vs, tbind, _, rhs, _) = |
40832 | 442 |
let fun arg v = TFree (v, the_sort v) |
443 |
in (Type (Sign.full_name tmp_thy tbind, map arg vs), rhs) end |
|
444 |
val dom_eqns = map mk_dom_eqn doms |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
445 |
|
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
446 |
(* check for valid type parameters *) |
40832 | 447 |
val (tyvars, _, _, _, _) = hd doms |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
448 |
val _ = map (fn (tvs, tname, _, _, _) => |
33774 | 449 |
let val full_tname = Sign.full_name tmp_thy tname |
450 |
in |
|
451 |
(case duplicates (op =) tvs of |
|
452 |
[] => |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
453 |
if eq_set (op =) (tyvars, tvs) then (full_tname, tvs) |
33774 | 454 |
else error ("Mutually recursive domains must have same type parameters") |
42381
309ec68442c6
added Binding.print convenience, which includes quote already;
wenzelm
parents:
42375
diff
changeset
|
455 |
| dups => error ("Duplicate parameter(s) for domain " ^ Binding.print tname ^ |
33774 | 456 |
" : " ^ commas dups)) |
40832 | 457 |
end) doms |
458 |
val dbinds = map (fn (_, dbind, _, _, _) => dbind) doms |
|
459 |
val morphs = map (fn (_, _, _, _, morphs) => morphs) doms |
|
33774 | 460 |
|
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
461 |
(* determine deflation combinator arguments *) |
40832 | 462 |
val lhsTs : typ list = map fst dom_eqns |
463 |
val defl_rec = Free ("t", mk_tupleT (map (K deflT) lhsTs)) |
|
464 |
val defl_recs = mk_projs lhsTs defl_rec |
|
465 |
val defl_recs' = map (apsnd mk_u_defl) defl_recs |
|
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
466 |
fun defl_body (_, _, _, rhsT, _) = |
40832 | 467 |
defl_of_typ tmp_thy defl_recs defl_recs' rhsT |
468 |
val functional = Term.lambda defl_rec (mk_tuple (map defl_body doms)) |
|
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
469 |
|
40832 | 470 |
val tfrees = map fst (Term.add_tfrees functional []) |
471 |
val frees = map fst (Term.add_frees functional []) |
|
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
472 |
fun get_defl_flags (vs, _, _, _, _) = |
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
473 |
let |
40832 | 474 |
fun argT v = TFree (v, the_sort v) |
475 |
fun mk_d v = "d" ^ Library.unprefix "'" v |
|
476 |
fun mk_p v = "p" ^ Library.unprefix "'" v |
|
477 |
val args = maps (fn v => [(mk_d v, mk_DEFL (argT v)), (mk_p v, mk_LIFTDEFL (argT v))]) vs |
|
478 |
val typeTs = map argT (filter (member (op =) tfrees) vs) |
|
479 |
val defl_args = map snd (filter (member (op =) frees o fst) args) |
|
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
480 |
in |
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
481 |
(typeTs, defl_args) |
40832 | 482 |
end |
483 |
val defl_flagss = map get_defl_flags doms |
|
40218
f7d4d023a899
make domain package work with non-cpo argument types
huffman
parents:
40216
diff
changeset
|
484 |
|
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
485 |
(* declare deflation combinator constants *) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
486 |
fun declare_defl_const ((typeTs, defl_args), (_, tbind, _, _, _)) thy = |
33774 | 487 |
let |
40832 | 488 |
val defl_bind = Binding.suffix_name "_defl" tbind |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
489 |
val defl_type = |
41292
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
490 |
map Term.itselfT typeTs ---> map fastype_of defl_args -->> deflT |
33774 | 491 |
in |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
492 |
Sign.declare_const_global ((defl_bind, defl_type), NoSyn) thy |
40832 | 493 |
end |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
494 |
val (defl_consts, thy) = |
40832 | 495 |
fold_map declare_defl_const (defl_flagss ~~ doms) thy |
33774 | 496 |
|
33775
7a1518c42c56
cleaned up; factored out fixed-point definition code
huffman
parents:
33774
diff
changeset
|
497 |
(* defining equations for type combinators *) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
498 |
fun mk_defl_term (defl_const, (typeTs, defl_args)) = |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
499 |
let |
40832 | 500 |
val type_args = map Logic.mk_type typeTs |
40487
1320a0747974
implement defl_of_typ using Pattern.rewrite_term instead of DeflData theory data
huffman
parents:
40486
diff
changeset
|
501 |
in |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
502 |
list_ccomb (list_comb (defl_const, type_args), defl_args) |
40832 | 503 |
end |
504 |
val defl_terms = map mk_defl_term (defl_consts ~~ defl_flagss) |
|
505 |
val defl_tab = map fst dom_eqns ~~ defl_terms |
|
506 |
val defl_tab' = map fst dom_eqns ~~ map mk_u_defl defl_terms |
|
33776 | 507 |
fun mk_defl_spec (lhsT, rhsT) = |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
508 |
mk_eqs (defl_of_typ tmp_thy defl_tab defl_tab' lhsT, |
40832 | 509 |
defl_of_typ tmp_thy defl_tab defl_tab' rhsT) |
510 |
val defl_specs = map mk_defl_spec dom_eqns |
|
33774 | 511 |
|
33784
7e434813752f
change naming convention for deflation combinators
huffman
parents:
33782
diff
changeset
|
512 |
(* register recursive definition of deflation combinators *) |
40832 | 513 |
val defl_binds = map (Binding.suffix_name "_defl") dbinds |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
514 |
val ((defl_apply_thms, defl_unfold_thms, defl_cont_thm), thy) = |
40832 | 515 |
add_fixdefs (defl_binds ~~ defl_specs) thy |
33774 | 516 |
|
33776 | 517 |
(* define types using deflation combinators *) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
518 |
fun make_repdef ((vs, tbind, mx, _, _), defl) thy = |
33774 | 519 |
let |
40832 | 520 |
val spec = (tbind, map (rpair dummyS) vs, mx) |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
521 |
val ((_, _, _, {DEFL, ...}), thy) = |
40832 | 522 |
Domaindef.add_domaindef false NONE spec defl NONE thy |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
523 |
(* declare domain_defl_simps rules *) |
40832 | 524 |
val thy = Context.theory_map (RepData.add_thm DEFL) thy |
33774 | 525 |
in |
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
526 |
(DEFL, thy) |
40832 | 527 |
end |
528 |
val (DEFL_thms, thy) = fold_map make_repdef (doms ~~ defl_terms) thy |
|
33776 | 529 |
|
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
530 |
(* prove DEFL equations *) |
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
531 |
fun mk_DEFL_eq_thm (lhsT, rhsT) = |
33776 | 532 |
let |
40832 | 533 |
val goal = mk_eqs (mk_DEFL lhsT, mk_DEFL rhsT) |
42361 | 534 |
val DEFL_simps = RepData.get (Proof_Context.init_global thy) |
33776 | 535 |
val tac = |
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
536 |
rewrite_goals_tac (map mk_meta_eq DEFL_simps) |
40832 | 537 |
THEN TRY (resolve_tac defl_unfold_thms 1) |
33776 | 538 |
in |
33777 | 539 |
Goal.prove_global thy [] [] goal (K tac) |
40832 | 540 |
end |
541 |
val DEFL_eq_thms = map mk_DEFL_eq_thm dom_eqns |
|
33782 | 542 |
|
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
543 |
(* register DEFL equations *) |
40832 | 544 |
val DEFL_eq_binds = map (Binding.prefix_name "DEFL_eq_") dbinds |
33782 | 545 |
val (_, thy) = thy |> |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
546 |
(Global_Theory.add_thms o map Thm.no_attributes) |
40832 | 547 |
(DEFL_eq_binds ~~ DEFL_eq_thms) |
33776 | 548 |
|
33778 | 549 |
(* define rep/abs functions *) |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
550 |
fun mk_rep_abs ((tbind, _), (lhsT, rhsT)) thy = |
33778 | 551 |
let |
40832 | 552 |
val rep_bind = Binding.suffix_name "_rep" tbind |
553 |
val abs_bind = Binding.suffix_name "_abs" tbind |
|
35477 | 554 |
val ((rep_const, rep_def), thy) = |
40832 | 555 |
define_const (rep_bind, coerce_const (lhsT, rhsT)) thy |
35477 | 556 |
val ((abs_const, abs_def), thy) = |
40832 | 557 |
define_const (abs_bind, coerce_const (rhsT, lhsT)) thy |
33778 | 558 |
in |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
559 |
(((rep_const, abs_const), (rep_def, abs_def)), thy) |
40832 | 560 |
end |
33785
2f2d9eb37084
automate definition of map functions; remove unused code
huffman
parents:
33784
diff
changeset
|
561 |
val ((rep_abs_consts, rep_abs_defs), thy) = thy |
35773 | 562 |
|> fold_map mk_rep_abs (dbinds ~~ morphs ~~ dom_eqns) |
40832 | 563 |
|>> ListPair.unzip |
33782 | 564 |
|
565 |
(* prove isomorphism and isodefl rules *) |
|
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
566 |
fun mk_iso_thms ((tbind, DEFL_eq), (rep_def, abs_def)) thy = |
33782 | 567 |
let |
35773 | 568 |
fun make thm = |
40832 | 569 |
Drule.zero_var_indexes (thm OF [DEFL_eq, abs_def, rep_def]) |
570 |
val rep_iso_thm = make @{thm domain_rep_iso} |
|
571 |
val abs_iso_thm = make @{thm domain_abs_iso} |
|
572 |
val isodefl_thm = make @{thm isodefl_abs_rep} |
|
35773 | 573 |
val thy = thy |
574 |
|> snd o add_qualified_thm "rep_iso" (tbind, rep_iso_thm) |
|
575 |
|> snd o add_qualified_thm "abs_iso" (tbind, abs_iso_thm) |
|
40832 | 576 |
|> snd o add_qualified_thm "isodefl_abs_rep" (tbind, isodefl_thm) |
33782 | 577 |
in |
578 |
(((rep_iso_thm, abs_iso_thm), isodefl_thm), thy) |
|
40832 | 579 |
end |
35489 | 580 |
val ((iso_thms, isodefl_abs_rep_thms), thy) = |
35480
7a1f285cad25
domain_isomorphism package proves deflation rules for map functions
huffman
parents:
35479
diff
changeset
|
581 |
thy |
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
582 |
|> fold_map mk_iso_thms (dbinds ~~ DEFL_eq_thms ~~ rep_abs_defs) |
40832 | 583 |
|>> ListPair.unzip |
33778 | 584 |
|
35467
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
585 |
(* 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
|
586 |
val iso_infos : Domain_Take_Proofs.iso_info list = |
35467
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
587 |
let |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
588 |
fun mk_info (((lhsT, rhsT), (repC, absC)), (rep_iso, abs_iso)) = |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
589 |
{ |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
590 |
repT = rhsT, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
591 |
absT = lhsT, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
592 |
rep_const = repC, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
593 |
abs_const = absC, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
594 |
rep_inverse = rep_iso, |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
595 |
abs_inverse = abs_iso |
40832 | 596 |
} |
35467
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
597 |
in |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
598 |
map mk_info (dom_eqns ~~ rep_abs_consts ~~ iso_thms) |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
599 |
end |
561d8e98d9d3
domain_isomorphism function returns iso_info record
huffman
parents:
35021
diff
changeset
|
600 |
|
35791
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
601 |
(* definitions and proofs related to map functions *) |
dc175fe29326
separate map-related code into new function define_map_functions
huffman
parents:
35773
diff
changeset
|
602 |
val (map_info, thy) = |
40832 | 603 |
define_map_functions (dbinds ~~ iso_infos) thy |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
604 |
val { map_consts, map_apply_thms, map_cont_thm, ...} = map_info |
33788 | 605 |
|
606 |
(* prove isodefl rules for map functions *) |
|
607 |
val isodefl_thm = |
|
608 |
let |
|
40832 | 609 |
fun unprime a = Library.unprefix "'" a |
610 |
fun mk_d T = Free ("d" ^ unprime (fst (dest_TFree T)), deflT) |
|
41292
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
611 |
fun mk_p T = Free ("p" ^ unprime (fst (dest_TFree T)), udeflT) |
40832 | 612 |
fun mk_f T = Free ("f" ^ unprime (fst (dest_TFree T)), T ->> T) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
613 |
fun mk_assm t = |
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
614 |
case try dest_LIFTDEFL t of |
41292
2b7bc8d9fd6e
use deflations over type 'udom u' to represent predomains;
huffman
parents:
41287
diff
changeset
|
615 |
SOME T => mk_trp (isodefl'_const T $ mk_f T $ mk_p T) |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
616 |
| NONE => |
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
617 |
let val T = dest_DEFL t |
40832 | 618 |
in mk_trp (isodefl_const T $ mk_f T $ mk_d T) end |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
619 |
fun mk_goal (map_const, (T, _)) = |
33788 | 620 |
let |
40832 | 621 |
val (_, Ts) = dest_Type T |
622 |
val map_term = list_ccomb (map_const, map mk_f (filter (is_cpo thy) Ts)) |
|
623 |
val defl_term = defl_of_typ thy (Ts ~~ map mk_d Ts) (Ts ~~ map mk_p Ts) T |
|
624 |
in isodefl_const T $ map_term $ defl_term end |
|
625 |
val assms = (map mk_assm o snd o hd) defl_flagss |
|
626 |
val goals = map mk_goal (map_consts ~~ dom_eqns) |
|
627 |
val goal = mk_trp (foldr1 HOLogic.mk_conj goals) |
|
33788 | 628 |
val adm_rules = |
40832 | 629 |
@{thms adm_conj adm_isodefl cont2cont_fst cont2cont_snd cont_id} |
33788 | 630 |
val bottom_rules = |
40832 | 631 |
@{thms fst_strict snd_strict isodefl_bottom simp_thms} |
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
632 |
val tuple_rules = |
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
633 |
@{thms split_def fst_conv snd_conv} |
40832 | 634 |
val map_ID_thms = Domain_Take_Proofs.get_map_ID_thms thy |
635 |
val map_ID_simps = map (fn th => th RS sym) map_ID_thms |
|
33788 | 636 |
val isodefl_rules = |
40491
6de5839e2fb3
add 'predomain' class: unpointed version of bifinite
huffman
parents:
40490
diff
changeset
|
637 |
@{thms conjI isodefl_ID_DEFL isodefl_LIFTDEFL} |
33791 | 638 |
@ isodefl_abs_rep_thms |
42361 | 639 |
@ IsodeflData.get (Proof_Context.init_global thy) |
33845 | 640 |
in |
641 |
Goal.prove_global thy [] assms goal (fn {prems, ...} => |
|
642 |
EVERY |
|
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
643 |
[rewrite_goals_tac (defl_apply_thms @ map_apply_thms), |
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
644 |
rtac (@{thm cont_parallel_fix_ind} |
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
645 |
OF [defl_cont_thm, map_cont_thm]) 1, |
33788 | 646 |
REPEAT (resolve_tac adm_rules 1), |
647 |
simp_tac (HOL_basic_ss addsimps bottom_rules) 1, |
|
41324
1383653efec3
make internal proofs for deflation and isodefl theorems more robust, by avoiding calls to the simplifier for beta-reduction
huffman
parents:
41292
diff
changeset
|
648 |
simp_tac (HOL_basic_ss addsimps tuple_rules) 1, |
40492 | 649 |
simp_tac (HOL_basic_ss addsimps map_ID_simps) 1, |
33788 | 650 |
REPEAT (etac @{thm conjE} 1), |
33845 | 651 |
REPEAT (resolve_tac (isodefl_rules @ prems) 1 ORELSE atac 1)]) |
40832 | 652 |
end |
653 |
val isodefl_binds = map (Binding.prefix_name "isodefl_") dbinds |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
654 |
fun conjuncts [] _ = [] |
33789 | 655 |
| conjuncts (n::[]) thm = [(n, thm)] |
656 |
| conjuncts (n::ns) thm = let |
|
40832 | 657 |
val thmL = thm RS @{thm conjunct1} |
658 |
val thmR = thm RS @{thm conjunct2} |
|
659 |
in (n, thmL):: conjuncts ns thmR end |
|
33789 | 660 |
val (isodefl_thms, thy) = thy |> |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
661 |
(Global_Theory.add_thms o map (Thm.no_attributes o apsnd Drule.zero_var_indexes)) |
40832 | 662 |
(conjuncts isodefl_binds isodefl_thm) |
663 |
val thy = fold (Context.theory_map o IsodeflData.add_thm) isodefl_thms thy |
|
33793 | 664 |
|
665 |
(* prove map_ID theorems *) |
|
666 |
fun prove_map_ID_thm |
|
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
667 |
(((map_const, (lhsT, _)), DEFL_thm), isodefl_thm) = |
33793 | 668 |
let |
40832 | 669 |
val Ts = snd (dest_Type lhsT) |
670 |
fun is_cpo T = Sign.of_sort thy (T, @{sort cpo}) |
|
671 |
val lhs = list_ccomb (map_const, map mk_ID (filter is_cpo Ts)) |
|
672 |
val goal = mk_eqs (lhs, mk_ID lhsT) |
|
33793 | 673 |
val tac = EVERY |
39989
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
674 |
[rtac @{thm isodefl_DEFL_imp_ID} 1, |
ad60d7311f43
renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents:
39974
diff
changeset
|
675 |
stac DEFL_thm 1, |
33793 | 676 |
rtac isodefl_thm 1, |
40832 | 677 |
REPEAT (resolve_tac @{thms isodefl_ID_DEFL isodefl_LIFTDEFL} 1)] |
33793 | 678 |
in |
679 |
Goal.prove_global thy [] [] goal (K tac) |
|
40832 | 680 |
end |
681 |
val map_ID_binds = map (Binding.suffix_name "_map_ID") dbinds |
|
33793 | 682 |
val map_ID_thms = |
683 |
map prove_map_ID_thm |
|
40832 | 684 |
(map_consts ~~ dom_eqns ~~ DEFL_thms ~~ isodefl_thms) |
33793 | 685 |
val (_, thy) = thy |> |
40489 | 686 |
(Global_Theory.add_thms o map (rpair [Domain_Take_Proofs.map_ID_add])) |
40832 | 687 |
(map_ID_binds ~~ map_ID_thms) |
33802
48ce3a1063f2
domain_isomorphism package defines copy functions
huffman
parents:
33801
diff
changeset
|
688 |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
689 |
(* 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
|
690 |
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
|
691 |
Domain_Take_Proofs.define_take_functions |
40832 | 692 |
(dbinds ~~ iso_infos) thy |
40015 | 693 |
val { take_consts, chain_take_thms, take_0_thms, take_Suc_thms, ...} = |
40832 | 694 |
take_info |
33807
ce8d2e8bca21
domain_isomorphism package defines combined copy function
huffman
parents:
33802
diff
changeset
|
695 |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
696 |
(* 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
|
697 |
val lub_take_lemma = |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
698 |
let |
40832 | 699 |
val lhs = mk_tuple (map mk_lub take_consts) |
700 |
fun is_cpo T = Sign.of_sort thy (T, @{sort cpo}) |
|
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
701 |
fun mk_map_ID (map_const, (lhsT, _)) = |
40832 | 702 |
list_ccomb (map_const, map mk_ID (filter is_cpo (snd (dest_Type lhsT)))) |
703 |
val rhs = mk_tuple (map mk_map_ID (map_consts ~~ dom_eqns)) |
|
704 |
val goal = mk_trp (mk_eq (lhs, rhs)) |
|
705 |
val map_ID_thms = Domain_Take_Proofs.get_map_ID_thms thy |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
706 |
val start_rules = |
40771 | 707 |
@{thms lub_Pair [symmetric] ch2ch_Pair} @ chain_take_thms |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
708 |
@ @{thms pair_collapse split_def} |
40832 | 709 |
@ map_apply_thms @ map_ID_thms |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
710 |
val rules0 = |
40832 | 711 |
@{thms iterate_0 Pair_strict} @ take_0_thms |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
712 |
val rules1 = |
44066
d74182c93f04
rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents:
42381
diff
changeset
|
713 |
@{thms iterate_Suc prod_eq_iff fst_conv snd_conv} |
40832 | 714 |
@ take_Suc_thms |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
715 |
val tac = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
716 |
EVERY |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
717 |
[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
|
718 |
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
|
719 |
rtac @{thm lub_eq} 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
720 |
rtac @{thm nat.induct} 1, |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
721 |
simp_tac (HOL_basic_ss addsimps rules0) 1, |
40832 | 722 |
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
|
723 |
in |
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
724 |
Goal.prove_global thy [] [] goal (K tac) |
40832 | 725 |
end |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
726 |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
727 |
(* prove lub of take equals ID *) |
44080
53d95b52954c
HOLCF: fix warnings about unreferenced identifiers
huffman
parents:
44066
diff
changeset
|
728 |
fun prove_lub_take (((dbind, take_const), map_ID_thm), (lhsT, _)) thy = |
33809
033831fd9ef3
store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents:
33807
diff
changeset
|
729 |
let |
40832 | 730 |
val n = Free ("n", natT) |
731 |
val goal = mk_eqs (mk_lub (lambda n (take_const $ n)), mk_ID lhsT) |
|
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
732 |
val tac = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
733 |
EVERY |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
734 |
[rtac @{thm trans} 1, rtac map_ID_thm 2, |
46708
b138dee7bed3
prefer cut_tac, where it is clear that the special variants cut_rules_tac or cut_facts_tac are not required;
wenzelm
parents:
45654
diff
changeset
|
735 |
cut_tac lub_take_lemma 1, |
40832 | 736 |
REPEAT (etac @{thm Pair_inject} 1), atac 1] |
737 |
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
|
738 |
in |
35773 | 739 |
add_qualified_thm "lub_take" (dbind, lub_take_thm) thy |
40832 | 740 |
end |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
741 |
val (lub_take_thms, thy) = |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35490
diff
changeset
|
742 |
fold_map prove_lub_take |
40832 | 743 |
(dbinds ~~ 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
|
744 |
|
35654
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35640
diff
changeset
|
745 |
(* prove additional take theorems *) |
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35640
diff
changeset
|
746 |
val (take_info2, thy) = |
7a15e181bf3b
move proofs of reach and take lemmas to domain_take_proofs.ML
huffman
parents:
35640
diff
changeset
|
747 |
Domain_Take_Proofs.add_lub_take_theorems |
40832 | 748 |
(dbinds ~~ iso_infos) take_info lub_take_thms thy |
33774 | 749 |
in |
35659 | 750 |
((iso_infos, take_info2), thy) |
40832 | 751 |
end |
33774 | 752 |
|
40832 | 753 |
val domain_isomorphism = gen_domain_isomorphism cert_typ |
754 |
val domain_isomorphism_cmd = snd oo gen_domain_isomorphism read_typ |
|
33774 | 755 |
|
756 |
(******************************************************************************) |
|
757 |
(******************************** outer syntax ********************************) |
|
758 |
(******************************************************************************) |
|
759 |
||
760 |
local |
|
761 |
||
34149
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
762 |
val parse_domain_iso : |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
763 |
(string list * binding * mixfix * string * (binding * binding) option) |
a0efb4754cb7
add 'morphisms' option to domain_isomorphism command
huffman
parents:
33971
diff
changeset
|
764 |
parser = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
765 |
(Parse.type_args -- Parse.binding -- Parse.opt_mixfix -- (Parse.$$$ "=" |-- Parse.typ) -- |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
766 |
Scan.option (Parse.$$$ "morphisms" |-- Parse.!!! (Parse.binding -- Parse.binding))) |
40832 | 767 |
>> (fn ((((vs, t), mx), rhs), morphs) => (vs, t, mx, rhs, morphs)) |
33774 | 768 |
|
40832 | 769 |
val parse_domain_isos = Parse.and_list1 parse_domain_iso |
33774 | 770 |
|
771 |
in |
|
772 |
||
773 |
val _ = |
|
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
774 |
Outer_Syntax.command "domain_isomorphism" "define domain isomorphisms (HOLCF)" |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
775 |
Keyword.thy_decl |
40832 | 776 |
(parse_domain_isos >> (Toplevel.theory o domain_isomorphism_cmd)) |
33774 | 777 |
|
40832 | 778 |
end |
33774 | 779 |
|
40832 | 780 |
end |