author | huffman |
Sat, 21 Apr 2012 10:59:52 +0200 | |
changeset 47647 | ec29cc09599d |
parent 47623 | 01e4fdf9d748 |
child 47698 | 18202d3d5832 |
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_lifting_infr: bool -> thm -> local_theory -> local_theory |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
12 |
|
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
13 |
val setup_by_quotient: bool -> thm -> thm option -> local_theory -> local_theory |
47308 | 14 |
|
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
15 |
val setup_by_typedef_thm: bool -> thm -> local_theory -> local_theory |
47308 | 16 |
end; |
17 |
||
47334 | 18 |
structure Lifting_Setup: LIFTING_SETUP = |
47308 | 19 |
struct |
20 |
||
21 |
infix 0 MRSL |
|
22 |
||
23 |
fun ants MRSL thm = fold (fn rl => fn thm => rl RS thm) ants thm |
|
24 |
||
25 |
exception SETUP_LIFTING_INFR of string |
|
26 |
||
47361
87c0eaf04bad
support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents:
47352
diff
changeset
|
27 |
fun define_cr_rel rep_fun lthy = |
47308 | 28 |
let |
47361
87c0eaf04bad
support non-open typedefs; define cr_rel in terms of a rep function for typedefs
kuncar
parents:
47352
diff
changeset
|
29 |
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
|
30 |
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
|
31 |
val def_term = Abs ("x", rty, Abs ("y", qty, rep_fun_graph)); |
47308 | 32 |
val qty_name = (fst o dest_Type) qty |
33 |
val cr_rel_name = Binding.prefix_name "cr_" (Binding.qualified_name qty_name) |
|
34 |
val (fixed_def_term, lthy') = yield_singleton (Variable.importT_terms) def_term lthy |
|
35 |
val ((_, (_ , def_thm)), lthy'') = |
|
36 |
Local_Theory.define ((cr_rel_name, NoSyn), ((Thm.def_binding cr_rel_name, []), fixed_def_term)) lthy' |
|
37 |
in |
|
38 |
(def_thm, lthy'') |
|
39 |
end |
|
40 |
||
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
41 |
fun define_abs_type no_abs_code quot_thm lthy = |
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
42 |
if not no_abs_code andalso Lifting_Def.can_generate_code_cert quot_thm then |
47308 | 43 |
let |
44 |
val abs_type_thm = quot_thm RS @{thm Quotient_abs_rep} |
|
45 |
val add_abstype_attribute = |
|
46 |
Thm.declaration_attribute (fn thm => Context.mapping (Code.add_abstype thm) I) |
|
47 |
val add_abstype_attrib = Attrib.internal (K add_abstype_attribute); |
|
48 |
in |
|
49 |
lthy |
|
50 |
|> (snd oo Local_Theory.note) ((Binding.empty, [add_abstype_attrib]), [abs_type_thm]) |
|
51 |
end |
|
52 |
else |
|
53 |
lthy |
|
54 |
||
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
55 |
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
|
56 |
let |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
val extra_rty_tfrees = |
47545 | 62 |
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
|
63 |
[] => [] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
64 |
| 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
|
65 |
Pretty.brk 1] @ |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
66 |
((Pretty.commas o map (Pretty.str o quote)) extras) @ |
47545 | 67 |
[Pretty.str "."])] |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
68 |
val not_type_constr = |
47545 | 69 |
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
|
70 |
Type _ => [] |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
71 |
| _ => [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
|
72 |
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
|
73 |
Pretty.brk 1, |
47545 | 74 |
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
|
75 |
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
|
76 |
in |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
77 |
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
|
78 |
@ (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
|
79 |
end |
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
80 |
|
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
81 |
fun setup_lifting_infr no_abs_code quot_thm lthy = |
47308 | 82 |
let |
47379
075d22b3a32f
detect incorrect situations; better error messages; sanity check for quot_thm in setup_lifting_infr
kuncar
parents:
47361
diff
changeset
|
83 |
val _ = quot_thm_sanity_check lthy quot_thm |
47308 | 84 |
val (_, qtyp) = Lifting_Term.quot_thm_rty_qty quot_thm |
85 |
val qty_full_name = (fst o dest_Type) qtyp |
|
86 |
val quotients = { quot_thm = quot_thm } |
|
87 |
fun quot_info phi = Lifting_Info.transform_quotients phi quotients |
|
88 |
in |
|
89 |
lthy |
|
90 |
|> Local_Theory.declaration {syntax = false, pervasive = true} |
|
91 |
(fn phi => Lifting_Info.update_quotients qty_full_name (quot_info phi)) |
|
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
92 |
|> define_abs_type no_abs_code quot_thm |
47308 | 93 |
end |
94 |
||
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
95 |
fun setup_by_quotient no_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
|
96 |
let |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
97 |
val transfer_attr = Attrib.internal (K Transfer.transfer_add) |
47545 | 98 |
val (_, qty) = Lifting_Term.quot_thm_rty_qty quot_thm |
47575 | 99 |
val induct_attr = Attrib.internal (K (Induct.induct_type (fst (dest_Type qty)))) |
47583 | 100 |
val qty_name = (Binding.name o Long_Name.base_name o fst o dest_Type) qty |
47545 | 101 |
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
|
102 |
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
|
103 |
SOME reflp_thm => lthy |
47545 | 104 |
|> (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
|
105 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_bi_total}]) |
47545 | 106 |
|> (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
|
107 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_id_abs_transfer}]) |
47575 | 108 |
|> (snd oo Local_Theory.note) ((qualify "abs_induct", [induct_attr]), |
109 |
[[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
|
110 |
| NONE => lthy |
47545 | 111 |
|> (snd oo Local_Theory.note) ((qualify "All_transfer", [transfer_attr]), |
112 |
[quot_thm RS @{thm Quotient_All_transfer}]) |
|
113 |
|> (snd oo Local_Theory.note) ((qualify "Ex_transfer", [transfer_attr]), |
|
114 |
[quot_thm RS @{thm Quotient_Ex_transfer}]) |
|
115 |
|> (snd oo Local_Theory.note) ((qualify "forall_transfer", [transfer_attr]), |
|
116 |
[quot_thm RS @{thm Quotient_forall_transfer}]) |
|
47575 | 117 |
|> (snd oo Local_Theory.note) ((qualify "abs_induct", [induct_attr]), |
118 |
[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
|
119 |
in |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
120 |
lthy' |
47545 | 121 |
|> (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
|
122 |
[quot_thm RS @{thm Quotient_right_unique}]) |
47545 | 123 |
|> (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
|
124 |
[quot_thm RS @{thm Quotient_right_total}]) |
47545 | 125 |
|> (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
|
126 |
[quot_thm RS @{thm Quotient_rel_eq_transfer}]) |
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
127 |
|> setup_lifting_infr no_abs_code quot_thm |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
128 |
end |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
129 |
|
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
130 |
fun setup_by_typedef_thm no_abs_code typedef_thm lthy = |
47308 | 131 |
let |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
val (T_def, lthy') = define_cr_rel rep_fun lthy |
47545 | 135 |
|
136 |
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
|
137 |
Const ("Orderings.top_class.top", _) => |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
138 |
[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
|
139 |
| Const (@{const_name "Collect"}, _) $ Abs (_, _, _) => |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
140 |
[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
|
141 |
| _ => |
47545 | 142 |
[typedef_thm, T_def] MRSL @{thm typedef_to_Quotient} |
143 |
||
144 |
val (_, qty) = Lifting_Term.quot_thm_rty_qty quot_thm |
|
47583 | 145 |
val qty_name = (Binding.name o Long_Name.base_name o fst o dest_Type) qty |
47545 | 146 |
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
|
147 |
val simplify = Raw_Simplifier.rewrite_rule [mk_meta_eq @{thm mem_Collect_eq}] |
47308 | 148 |
|
47545 | 149 |
val lthy'' = case typedef_set of |
150 |
Const ("Orderings.top_class.top", _) => |
|
151 |
let |
|
152 |
val equivp_thm = typedef_thm RS @{thm UNIV_typedef_to_equivp} |
|
153 |
val reflp_thm = equivp_thm RS @{thm equivp_reflp2} |
|
154 |
in |
|
155 |
lthy' |
|
156 |
|> (snd oo Local_Theory.note) ((qualify "bi_total", [transfer_attr]), |
|
157 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_bi_total}]) |
|
158 |
|> (snd oo Local_Theory.note) ((qualify "id_abs_transfer", [transfer_attr]), |
|
159 |
[[quot_thm, reflp_thm] MRSL @{thm Quotient_id_abs_transfer}]) |
|
160 |
end |
|
161 |
| _ => lthy' |
|
162 |
|> (snd oo Local_Theory.note) ((qualify "All_transfer", [transfer_attr]), |
|
163 |
[[typedef_thm, T_def] MRSL @{thm typedef_All_transfer}]) |
|
164 |
|> (snd oo Local_Theory.note) ((qualify "Ex_transfer", [transfer_attr]), |
|
165 |
[[typedef_thm, T_def] MRSL @{thm typedef_Ex_transfer}]) |
|
166 |
|> (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
|
167 |
[simplify ([typedef_thm, T_def] MRSL @{thm typedef_forall_transfer})]) |
47308 | 168 |
in |
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
169 |
lthy'' |
47545 | 170 |
|> (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
|
171 |
[[typedef_thm, T_def] MRSL @{thm typedef_bi_unique}]) |
47545 | 172 |
|> (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
|
173 |
[[typedef_thm, T_def] MRSL @{thm typedef_rep_transfer}]) |
47545 | 174 |
|> (snd oo Local_Theory.note) ((qualify "right_unique", [transfer_attr]), |
175 |
[[quot_thm] MRSL @{thm Quotient_right_unique}]) |
|
176 |
|> (snd oo Local_Theory.note) ((qualify "right_total", [transfer_attr]), |
|
177 |
[[quot_thm] MRSL @{thm Quotient_right_total}]) |
|
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
178 |
|> setup_lifting_infr no_abs_code quot_thm |
47308 | 179 |
end |
180 |
||
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
181 |
fun setup_lifting_cmd no_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
|
182 |
let |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
|
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
187 |
fun sanity_check_reflp_thm reflp_thm = |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
188 |
let |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
189 |
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
|
190 |
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
|
191 |
in |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
192 |
case reflp_tm of |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
193 |
Const (@{const_name reflp}, _) $ _ => () |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
194 |
| _ => 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
|
195 |
end |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
196 |
|
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
197 |
fun setup_quotient () = |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
198 |
case opt_reflp_xthm of |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
199 |
SOME reflp_xthm => |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
200 |
let |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
201 |
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
|
202 |
val _ = sanity_check_reflp_thm reflp_thm |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
203 |
in |
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
204 |
setup_by_quotient no_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
|
205 |
end |
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
206 |
| NONE => setup_by_quotient no_abs_code input_thm NONE lthy |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
207 |
|
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
208 |
fun setup_typedef () = |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
209 |
case opt_reflp_xthm of |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
210 |
SOME _ => error "The reflexivity theorem cannot be specified if the type_definition theorem is used." |
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
211 |
| NONE => setup_by_typedef_thm no_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
|
212 |
in |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47379
diff
changeset
|
213 |
case input_term of |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
214 |
(Const (@{const_name Quotient}, _) $ _ $ _ $ _ $ _) => setup_quotient () |
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
215 |
| (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
|
216 |
| _ => 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
|
217 |
end |
47308 | 218 |
|
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
219 |
val opt_no_abs_code = |
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
220 |
Scan.optional (@{keyword "("} |-- Parse.!!! ((Parse.reserved "no_abs_code" >> K true) --| @{keyword ")"})) false |
47566
c201a1fe0a81
setup_lifting: no_code switch and supoport for quotient theorems
kuncar
parents:
47545
diff
changeset
|
221 |
|
47308 | 222 |
val _ = |
223 |
Outer_Syntax.local_theory @{command_spec "setup_lifting"} |
|
47352 | 224 |
"Setup lifting infrastructure" |
47608
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
225 |
(opt_no_abs_code -- Parse_Spec.xthm -- Scan.option Parse_Spec.xthm >> |
572d7e51de4d
rename no_code to no_abs_code - more appropriate name
kuncar
parents:
47583
diff
changeset
|
226 |
(fn ((no_abs_code, xthm), opt_reflp_xthm) => setup_lifting_cmd no_abs_code xthm opt_reflp_xthm)) |
47308 | 227 |
end; |