author | wenzelm |
Sun, 20 May 2012 11:34:33 +0200 | |
changeset 47884 | 21c42b095c84 |
parent 47852 | 0c3b8d036a5c |
child 47889 | 29212a4bb866 |
permissions | -rw-r--r-- |
47308 | 1 |
(* Title: HOL/Tools/Lifting/lifting_setup.ML |
2 |
Author: Ondrej Kuncar |
|
3 |
||
47352 | 4 |
Setting up the lifting infrastructure. |
47308 | 5 |
*) |
6 |
||
7 |
signature LIFTING_SETUP = |
|
8 |
sig |
|
9 |
exception SETUP_LIFTING_INFR of string |
|
10 |
||
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
11 |
val setup_by_quotient: bool -> thm -> thm option -> local_theory -> local_theory |
47308 | 12 |
|
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
13 |
val setup_by_typedef_thm: bool -> thm -> local_theory -> local_theory |
47308 | 14 |
end; |
15 |
||
47334 | 16 |
structure Lifting_Setup: LIFTING_SETUP = |
47308 | 17 |
struct |
18 |
||
47698 | 19 |
open Lifting_Util |
47308 | 20 |
|
47698 | 21 |
infix 0 MRSL |
47308 | 22 |
|
23 |
exception SETUP_LIFTING_INFR of string |
|
24 |
||
47361
87c0eaf04bad
support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents:
47352
diff
changeset
|
25 |
fun define_cr_rel rep_fun lthy = |
47308 | 26 |
let |
47361
87c0eaf04bad
support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents:
47352
diff
changeset
|
27 |
val (qty, rty) = (dest_funT o fastype_of) rep_fun |
87c0eaf04bad
support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents:
47352
diff
changeset
|
28 |
val rep_fun_graph = (HOLogic.eq_const rty) $ Bound 1 $ (rep_fun $ Bound 0) |
87c0eaf04bad
support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents:
47352
diff
changeset
|
29 |
val def_term = Abs ("x", rty, Abs ("y", qty, rep_fun_graph)); |
47308 | 30 |
val qty_name = (fst o dest_Type) qty |
31 |
val cr_rel_name = Binding.prefix_name "cr_" (Binding.qualified_name qty_name) |
|
32 |
val (fixed_def_term, lthy') = yield_singleton (Variable.importT_terms) def_term lthy |
|
33 |
val ((_, (_ , def_thm)), lthy'') = |
|
34 |
Local_Theory.define ((cr_rel_name, NoSyn), ((Thm.def_binding cr_rel_name, []), fixed_def_term)) lthy' |
|
35 |
in |
|
36 |
(def_thm, lthy'') |
|
37 |
end |
|
38 |
||
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
39 |
fun define_abs_type gen_abs_code quot_thm lthy = |
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
40 |
if gen_abs_code andalso Lifting_Def.can_generate_code_cert quot_thm then |
47308 | 41 |
let |
42 |
val abs_type_thm = quot_thm RS @{thm Quotient_abs_rep} |
|
43 |
val add_abstype_attribute = |
|
44 |
Thm.declaration_attribute (fn thm => Context.mapping (Code.add_abstype thm) I) |
|
45 |
val add_abstype_attrib = Attrib.internal (K add_abstype_attribute); |
|
46 |
in |
|
47 |
lthy |
|
48 |
|> (snd oo Local_Theory.note) ((Binding.empty, [add_abstype_attrib]), [abs_type_thm]) |
|
49 |
end |
|
50 |
else |
|
51 |
lthy |
|
52 |
||
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
53 |
fun quot_thm_sanity_check ctxt quot_thm = |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
54 |
let |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
55 |
val ((_, [quot_thm_fixed]), ctxt') = Variable.importT [quot_thm] ctxt |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
56 |
val (rty, qty) = Lifting_Term.quot_thm_rty_qty quot_thm_fixed |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
57 |
val rty_tfreesT = Term.add_tfree_namesT rty [] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
58 |
val qty_tfreesT = Term.add_tfree_namesT qty [] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
59 |
val extra_rty_tfrees = |
47545 | 60 |
case subtract (op =) qty_tfreesT rty_tfreesT of |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
61 |
[] => [] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
62 |
| extras => [Pretty.block ([Pretty.str "Extra variables in the raw type:", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
63 |
Pretty.brk 1] @ |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
64 |
((Pretty.commas o map (Pretty.str o quote)) extras) @ |
47545 | 65 |
[Pretty.str "."])] |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
66 |
val not_type_constr = |
47545 | 67 |
case qty of |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
68 |
Type _ => [] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
69 |
| _ => [Pretty.block [Pretty.str "The quotient type ", |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
70 |
Pretty.quote (Syntax.pretty_typ ctxt' qty), |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
71 |
Pretty.brk 1, |
47545 | 72 |
Pretty.str "is not a type constructor."]] |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
73 |
val errs = extra_rty_tfrees @ not_type_constr |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
74 |
in |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
75 |
if null errs then () else error (cat_lines (["Sanity check of the quotient theorem failed:",""] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
76 |
@ (map Pretty.string_of errs))) |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
77 |
end |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
78 |
|
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
79 |
fun setup_lifting_infr gen_abs_code quot_thm lthy = |
47308 | 80 |
let |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
81 |
val _ = quot_thm_sanity_check lthy quot_thm |
47308 | 82 |
val (_, qtyp) = Lifting_Term.quot_thm_rty_qty quot_thm |
83 |
val qty_full_name = (fst o dest_Type) qtyp |
|
84 |
val quotients = { quot_thm = quot_thm } |
|
85 |
fun quot_info phi = Lifting_Info.transform_quotients phi quotients |
|
86 |
in |
|
87 |
lthy |
|
88 |
|> Local_Theory.declaration {syntax = false, pervasive = true} |
|
89 |
(fn phi => Lifting_Info.update_quotients qty_full_name (quot_info phi)) |
|
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
90 |
|> define_abs_type gen_abs_code quot_thm |
47308 | 91 |
end |
92 |
||
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
93 |
(* |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
94 |
Sets up the Lifting package by a quotient theorem. |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
95 |
|
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
96 |
gen_abs_code - flag if an abstract type given by quot_thm should be registred |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
97 |
as an abstract type in the code generator |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
98 |
quot_thm - a quotient theorem (Quotient R Abs Rep T) |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
99 |
maybe_reflp_thm - a theorem saying that a relation from quot_thm is reflexive |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
100 |
(in the form "reflp R") |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
101 |
*) |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
102 |
|
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
103 |
fun setup_by_quotient gen_abs_code quot_thm maybe_reflp_thm lthy = |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
104 |
let |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
105 |
val transfer_attr = Attrib.internal (K Transfer.transfer_add) |
47545 | 106 |
val (_, qty) = Lifting_Term.quot_thm_rty_qty quot_thm |
47575 | 107 |
val induct_attr = Attrib.internal (K (Induct.induct_type (fst (dest_Type qty)))) |
47583 | 108 |
val qty_name = (Binding.name o Long_Name.base_name o fst o dest_Type) qty |
47545 | 109 |
fun qualify suffix = Binding.qualified true suffix qty_name |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
110 |
val lthy' = case maybe_reflp_thm of |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
111 |
SOME reflp_thm => lthy |
47545 | 112 |
|> (snd oo Local_Theory.note) ((qualify "bi_total", [transfer_attr]), |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
113 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_bi_total}]) |
47545 | 114 |
|> (snd oo Local_Theory.note) ((qualify "id_abs_transfer", [transfer_attr]), |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
115 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_id_abs_transfer}]) |
47575 | 116 |
|> (snd oo Local_Theory.note) ((qualify "abs_induct", [induct_attr]), |
117 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_total_abs_induct}]) |
|
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
118 |
| NONE => lthy |
47545 | 119 |
|> (snd oo Local_Theory.note) ((qualify "All_transfer", [transfer_attr]), |
120 |
[quot_thm RS @{thm Quotient_All_transfer}]) |
|
121 |
|> (snd oo Local_Theory.note) ((qualify "Ex_transfer", [transfer_attr]), |
|
122 |
[quot_thm RS @{thm Quotient_Ex_transfer}]) |
|
123 |
|> (snd oo Local_Theory.note) ((qualify "forall_transfer", [transfer_attr]), |
|
124 |
[quot_thm RS @{thm Quotient_forall_transfer}]) |
|
47575 | 125 |
|> (snd oo Local_Theory.note) ((qualify "abs_induct", [induct_attr]), |
126 |
[quot_thm RS @{thm Quotient_abs_induct}]) |
|
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
127 |
in |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
128 |
lthy' |
47545 | 129 |
|> (snd oo Local_Theory.note) ((qualify "right_unique", [transfer_attr]), |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
130 |
[quot_thm RS @{thm Quotient_right_unique}]) |
47545 | 131 |
|> (snd oo Local_Theory.note) ((qualify "right_total", [transfer_attr]), |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
132 |
[quot_thm RS @{thm Quotient_right_total}]) |
47545 | 133 |
|> (snd oo Local_Theory.note) ((qualify "rel_eq_transfer", [transfer_attr]), |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
134 |
[quot_thm RS @{thm Quotient_rel_eq_transfer}]) |
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
135 |
|> setup_lifting_infr gen_abs_code quot_thm |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
136 |
end |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
137 |
|
47852
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
138 |
(* |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
139 |
Sets up the Lifting package by a typedef theorem. |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
140 |
|
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
141 |
gen_abs_code - flag if an abstract type given by typedef_thm should be registred |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
142 |
as an abstract type in the code generator |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
143 |
typedef_thm - a typedef theorem (type_definition Rep Abs S) |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
144 |
*) |
0c3b8d036a5c
documentation of the Lifting package on the ML level & tuned
kuncar
parents:
47779
diff
changeset
|
145 |
|
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
146 |
fun setup_by_typedef_thm gen_abs_code typedef_thm lthy = |
47308 | 147 |
let |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
148 |
val transfer_attr = Attrib.internal (K Transfer.transfer_add) |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
149 |
val (_ $ rep_fun $ _ $ typedef_set) = (HOLogic.dest_Trueprop o prop_of) typedef_thm |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
150 |
val (T_def, lthy') = define_cr_rel rep_fun lthy |
47545 | 151 |
|
152 |
val quot_thm = case typedef_set of |
|
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
153 |
Const ("Orderings.top_class.top", _) => |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
154 |
[typedef_thm, T_def] MRSL @{thm UNIV_typedef_to_Quotient} |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
155 |
| Const (@{const_name "Collect"}, _) $ Abs (_, _, _) => |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
156 |
[typedef_thm, T_def] MRSL @{thm open_typedef_to_Quotient} |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
157 |
| _ => |
47545 | 158 |
[typedef_thm, T_def] MRSL @{thm typedef_to_Quotient} |
159 |
||
160 |
val (_, qty) = Lifting_Term.quot_thm_rty_qty quot_thm |
|
47583 | 161 |
val qty_name = (Binding.name o Long_Name.base_name o fst o dest_Type) qty |
47545 | 162 |
fun qualify suffix = Binding.qualified true suffix qty_name |
47623
01e4fdf9d748
setup_lifting preprocesses forall_transfer rule by unfolding mem_Collect_eq
huffman
parents:
47608
diff
changeset
|
163 |
val simplify = Raw_Simplifier.rewrite_rule [mk_meta_eq @{thm mem_Collect_eq}] |
47308 | 164 |
|
47545 | 165 |
val lthy'' = case typedef_set of |
166 |
Const ("Orderings.top_class.top", _) => |
|
167 |
let |
|
168 |
val equivp_thm = typedef_thm RS @{thm UNIV_typedef_to_equivp} |
|
169 |
val reflp_thm = equivp_thm RS @{thm equivp_reflp2} |
|
170 |
in |
|
171 |
lthy' |
|
172 |
|> (snd oo Local_Theory.note) ((qualify "bi_total", [transfer_attr]), |
|
173 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_bi_total}]) |
|
174 |
|> (snd oo Local_Theory.note) ((qualify "id_abs_transfer", [transfer_attr]), |
|
175 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_id_abs_transfer}]) |
|
176 |
end |
|
177 |
| _ => lthy' |
|
178 |
|> (snd oo Local_Theory.note) ((qualify "All_transfer", [transfer_attr]), |
|
179 |
[[typedef_thm, T_def] MRSL @{thm typedef_All_transfer}]) |
|
180 |
|> (snd oo Local_Theory.note) ((qualify "Ex_transfer", [transfer_attr]), |
|
181 |
[[typedef_thm, T_def] MRSL @{thm typedef_Ex_transfer}]) |
|
182 |
|> (snd oo Local_Theory.note) ((qualify "forall_transfer", [transfer_attr]), |
|
47623
01e4fdf9d748
setup_lifting preprocesses forall_transfer rule by unfolding mem_Collect_eq
huffman
parents:
47608
diff
changeset
|
183 |
[simplify ([typedef_thm, T_def] MRSL @{thm typedef_forall_transfer})]) |
47308 | 184 |
in |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
185 |
lthy'' |
47545 | 186 |
|> (snd oo Local_Theory.note) ((qualify "bi_unique", [transfer_attr]), |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
187 |
[[typedef_thm, T_def] MRSL @{thm typedef_bi_unique}]) |
47545 | 188 |
|> (snd oo Local_Theory.note) ((qualify "rep_transfer", [transfer_attr]), |
47535
0f94b02fda1c
lifting_setup generates transfer rule for rep of typedefs
huffman
parents:
47534
diff
changeset
|
189 |
[[typedef_thm, T_def] MRSL @{thm typedef_rep_transfer}]) |
47545 | 190 |
|> (snd oo Local_Theory.note) ((qualify "right_unique", [transfer_attr]), |
191 |
[[quot_thm] MRSL @{thm Quotient_right_unique}]) |
|
192 |
|> (snd oo Local_Theory.note) ((qualify "right_total", [transfer_attr]), |
|
193 |
[[quot_thm] MRSL @{thm Quotient_right_total}]) |
|
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
194 |
|> setup_lifting_infr gen_abs_code quot_thm |
47308 | 195 |
end |
196 |
||
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
197 |
fun setup_lifting_cmd gen_abs_code xthm opt_reflp_xthm lthy = |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
198 |
let |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
199 |
val input_thm = singleton (Attrib.eval_thms lthy) xthm |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
200 |
val input_term = (HOLogic.dest_Trueprop o prop_of) input_thm |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
201 |
handle TERM _ => error "Unsupported type of a theorem. Only Quotient or type_definition are supported." |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
202 |
|
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
203 |
fun sanity_check_reflp_thm reflp_thm = |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
204 |
let |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
205 |
val reflp_tm = (HOLogic.dest_Trueprop o prop_of) reflp_thm |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
206 |
handle TERM _ => error "Invalid form of the reflexivity theorem. Use \"reflp R\"." |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
207 |
in |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
208 |
case reflp_tm of |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
209 |
Const (@{const_name reflp}, _) $ _ => () |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
210 |
| _ => error "Invalid form of the reflexivity theorem. Use \"reflp R\"." |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
211 |
end |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
212 |
|
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
213 |
fun setup_quotient () = |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
214 |
case opt_reflp_xthm of |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
215 |
SOME reflp_xthm => |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
216 |
let |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
217 |
val reflp_thm = singleton (Attrib.eval_thms lthy) reflp_xthm |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
218 |
val _ = sanity_check_reflp_thm reflp_thm |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
219 |
in |
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
220 |
setup_by_quotient gen_abs_code input_thm (SOME reflp_thm) lthy |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
221 |
end |
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
222 |
| NONE => setup_by_quotient gen_abs_code input_thm NONE lthy |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
223 |
|
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
224 |
fun setup_typedef () = |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
225 |
case opt_reflp_xthm of |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
226 |
SOME _ => error "The reflexivity theorem cannot be specified if the type_definition theorem is used." |
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
227 |
| NONE => setup_by_typedef_thm gen_abs_code input_thm lthy |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
228 |
in |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
229 |
case input_term of |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
230 |
(Const (@{const_name Quotient}, _) $ _ $ _ $ _ $ _) => setup_quotient () |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
231 |
| (Const (@{const_name type_definition}, _) $ _ $ _ $ _) => setup_typedef () |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
232 |
| _ => error "Unsupported type of a theorem. Only Quotient or type_definition are supported." |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
233 |
end |
47308 | 234 |
|
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
235 |
val opt_gen_abs_code = |
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
236 |
Scan.optional (@{keyword "("} |-- Parse.!!! ((Parse.reserved "no_abs_code" >> K false) --| @{keyword ")"})) true |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
237 |
|
47308 | 238 |
val _ = |
239 |
Outer_Syntax.local_theory @{command_spec "setup_lifting"} |
|
47352 | 240 |
"Setup lifting infrastructure" |
47779
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
241 |
(opt_gen_abs_code -- Parse_Spec.xthm -- Scan.option Parse_Spec.xthm >> |
5a10e24fe7ab
tuned; don't generate abs code if quotient_type is used
kuncar
parents:
47698
diff
changeset
|
242 |
(fn ((gen_abs_code, xthm), opt_reflp_xthm) => setup_lifting_cmd gen_abs_code xthm opt_reflp_xthm)) |
47308 | 243 |
end; |