author | wenzelm |
Mon, 10 Nov 2014 21:49:48 +0100 | |
changeset 58963 | 26bf09b95dda |
parent 58959 | 1f195ed99941 |
child 59157 | 949829bae42a |
permissions | -rw-r--r-- |
45680 | 1 |
(* Title: HOL/Tools/Quotient/quotient_type.ML |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Cezary Kaliszyk and Christian Urban |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
3 |
|
35806
a814cccce0b8
rollback of local typedef until problem with type-variables can be sorted out; fixed header
Christian Urban <urbanc@in.tum.de>
parents:
35790
diff
changeset
|
4 |
Definition of a quotient type. |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
5 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
6 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
7 |
signature QUOTIENT_TYPE = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
8 |
sig |
45676
fa46fef06590
alternative names of morphisms in the definition of a quotient type can be specified
kuncar
parents:
45534
diff
changeset
|
9 |
val add_quotient_type: ((string list * binding * mixfix) * (typ * term * bool) * |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
10 |
((binding * binding) option * bool * thm option)) * thm -> local_theory -> Quotient_Info.quotients * local_theory |
35415
1810b1ade437
export add_quotient_type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
35351
diff
changeset
|
11 |
|
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
12 |
val quotient_type: (string list * binding * mixfix) * (typ * term * bool) * |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
13 |
((binding * binding) option * bool * thm option) -> Proof.context -> Proof.state |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
14 |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
15 |
val quotient_type_cmd: ((((((bool * string list) * binding) * mixfix) * string) * (bool * string)) * |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57960
diff
changeset
|
16 |
(binding * binding) option) * (Facts.ref * Token.src list) option -> Proof.context -> Proof.state |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
17 |
end; |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
18 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
19 |
structure Quotient_Type: QUOTIENT_TYPE = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
20 |
struct |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
21 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
22 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
23 |
(*** definition of quotient types ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
24 |
|
44204
3cdc4176638c
Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
43547
diff
changeset
|
25 |
val mem_def1 = @{lemma "y : Collect S ==> S y" by simp} |
3cdc4176638c
Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
43547
diff
changeset
|
26 |
val mem_def2 = @{lemma "S y ==> y : Collect S" by simp} |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
27 |
|
47100 | 28 |
(* constructs the term {c. EX (x::rty). rel x x \<and> c = Collect (rel x)} *) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
29 |
fun typedef_term rel rty lthy = |
41444 | 30 |
let |
31 |
val [x, c] = |
|
32 |
[("x", rty), ("c", HOLogic.mk_setT rty)] |
|
33 |
|> Variable.variant_frees lthy [rel] |
|
34 |
|> map Free |
|
35 |
in |
|
45312 | 36 |
HOLogic.Collect_const (HOLogic.mk_setT rty) $ (lambda c (HOLogic.exists_const rty $ |
44204
3cdc4176638c
Quotient Package: make quotient_type work with separate set type
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
43547
diff
changeset
|
37 |
lambda x (HOLogic.mk_conj (rel $ x $ x, |
45312 | 38 |
HOLogic.mk_eq (c, HOLogic.Collect_const rty $ (rel $ x)))))) |
41444 | 39 |
end |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
40 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
41 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
42 |
(* makes the new type definitions and proves non-emptyness *) |
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
43 |
fun typedef_make (vs, qty_name, mx, rel, rty) equiv_thm lthy = |
41444 | 44 |
let |
58959 | 45 |
fun typedef_tac _ = |
41444 | 46 |
EVERY1 (map rtac [@{thm part_equivp_typedef}, equiv_thm]) |
47 |
in |
|
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
58028
diff
changeset
|
48 |
Typedef.add_typedef false (qty_name, map (rpair dummyS) vs, mx) |
41444 | 49 |
(typedef_term rel rty lthy) NONE typedef_tac lthy |
50 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
51 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
52 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
53 |
(* tactic to prove the quot_type theorem for the new type *) |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58959
diff
changeset
|
54 |
fun typedef_quot_type_tac ctxt equiv_thm ((_, typedef_info): Typedef.info) = |
41444 | 55 |
let |
56 |
val rep_thm = #Rep typedef_info RS mem_def1 |
|
57 |
val rep_inv = #Rep_inverse typedef_info |
|
58 |
val abs_inv = #Abs_inverse typedef_info |
|
59 |
val rep_inj = #Rep_inject typedef_info |
|
60 |
in |
|
61 |
(rtac @{thm quot_type.intro} THEN' RANGE [ |
|
62 |
rtac equiv_thm, |
|
63 |
rtac rep_thm, |
|
64 |
rtac rep_inv, |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58959
diff
changeset
|
65 |
rtac abs_inv THEN' rtac mem_def2 THEN' assume_tac ctxt, |
41444 | 66 |
rtac rep_inj]) 1 |
67 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
68 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
69 |
(* proves the quot_type theorem for the new type *) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
70 |
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy = |
41444 | 71 |
let |
45317
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
72 |
val quot_type_const = Const (@{const_name "quot_type"}, |
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
73 |
fastype_of rel --> fastype_of abs --> fastype_of rep --> @{typ bool}) |
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
74 |
val goal = HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep) |
41444 | 75 |
in |
76 |
Goal.prove lthy [] [] goal |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58959
diff
changeset
|
77 |
(fn {context = ctxt, ...} => typedef_quot_type_tac ctxt equiv_thm typedef_info) |
41444 | 78 |
end |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
79 |
|
47698 | 80 |
open Lifting_Util |
47362
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
81 |
|
47698 | 82 |
infix 0 MRSL |
47362
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
83 |
|
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
84 |
fun define_cr_rel equiv_thm abs_fun lthy = |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
85 |
let |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
86 |
fun force_type_of_rel rel forced_ty = |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
87 |
let |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
88 |
val thy = Proof_Context.theory_of lthy |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
89 |
val rel_ty = (domain_type o fastype_of) rel |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
90 |
val ty_inst = Sign.typ_match thy (rel_ty, forced_ty) Vartab.empty |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
91 |
in |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
92 |
Envir.subst_term_types ty_inst rel |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
93 |
end |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
94 |
|
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
95 |
val (rty, qty) = (dest_funT o fastype_of) abs_fun |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
96 |
val abs_fun_graph = HOLogic.mk_eq(abs_fun $ Bound 1, Bound 0) |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
97 |
val Abs_body = (case (HOLogic.dest_Trueprop o prop_of) equiv_thm of |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
98 |
Const (@{const_name equivp}, _) $ _ => abs_fun_graph |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
99 |
| Const (@{const_name part_equivp}, _) $ rel => |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
100 |
HOLogic.mk_conj (force_type_of_rel rel rty $ Bound 1 $ Bound 1, abs_fun_graph) |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
101 |
| _ => error "unsupported equivalence theorem" |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
102 |
) |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
103 |
val def_term = Abs ("x", rty, Abs ("y", qty, Abs_body)); |
50177 | 104 |
val qty_name = (Binding.name o Long_Name.base_name o fst o dest_Type) qty |
105 |
val cr_rel_name = Binding.prefix_name "cr_" qty_name |
|
47362
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
106 |
val (fixed_def_term, lthy') = yield_singleton (Variable.importT_terms) def_term lthy |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
107 |
val ((_, (_ , def_thm)), lthy'') = |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
108 |
Local_Theory.define ((cr_rel_name, NoSyn), ((Thm.def_binding cr_rel_name, []), fixed_def_term)) lthy' |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
109 |
in |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
110 |
(def_thm, lthy'') |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
111 |
end; |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
112 |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
113 |
fun setup_lifting_package gen_code quot3_thm equiv_thm opt_par_thm lthy = |
47362
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
114 |
let |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
115 |
val (_ $ _ $ abs_fun $ _) = (HOLogic.dest_Trueprop o prop_of) quot3_thm |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
116 |
val (T_def, lthy') = define_cr_rel equiv_thm abs_fun lthy |
47502 | 117 |
val (rty, qty) = (dest_funT o fastype_of) abs_fun |
50177 | 118 |
val qty_name = (Binding.name o Long_Name.base_name o fst o dest_Type) qty |
119 |
val quotient_thm_name = Binding.prefix_name "Quotient_" qty_name |
|
47521
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47502
diff
changeset
|
120 |
val (reflp_thm, quot_thm) = (case (HOLogic.dest_Trueprop o prop_of) equiv_thm of |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47502
diff
changeset
|
121 |
Const (@{const_name equivp}, _) $ _ => |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47502
diff
changeset
|
122 |
(SOME (equiv_thm RS @{thm equivp_reflp2}), |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47502
diff
changeset
|
123 |
[quot3_thm, T_def, equiv_thm] MRSL @{thm Quotient3_to_Quotient_equivp}) |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47502
diff
changeset
|
124 |
| Const (@{const_name part_equivp}, _) $ _ => |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47502
diff
changeset
|
125 |
(NONE, |
69f95ac85c3d
tuned the setup of lifting; generate transfer rules for typedef and Quotient thms
kuncar
parents:
47502
diff
changeset
|
126 |
[quot3_thm, T_def] MRSL @{thm Quotient3_to_Quotient}) |
47362
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
127 |
| _ => error "unsupported equivalence theorem" |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
128 |
) |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
129 |
in |
47502 | 130 |
lthy' |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
131 |
|> Lifting_Setup.setup_by_quotient gen_code quot_thm reflp_thm opt_par_thm |
47502 | 132 |
|> (snd oo Local_Theory.note) ((quotient_thm_name, []), [quot_thm]) |
47362
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
133 |
end |
b1f099bdfbba
connect the Quotient package to the Lifting package
kuncar
parents:
47308
diff
changeset
|
134 |
|
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
135 |
fun init_quotient_infr gen_code quot_thm equiv_thm opt_par_thm lthy = |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
136 |
let |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
137 |
val (_ $ rel $ abs $ rep) = (HOLogic.dest_Trueprop o prop_of) quot_thm |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
138 |
val (qtyp, rtyp) = (dest_funT o fastype_of) rep |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
139 |
val qty_full_name = (fst o dest_Type) qtyp |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
140 |
val quotients = {qtyp = qtyp, rtyp = rtyp, equiv_rel = rel, equiv_thm = equiv_thm, |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
141 |
quot_thm = quot_thm } |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
142 |
fun quot_info phi = Quotient_Info.transform_quotients phi quotients |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
143 |
val abs_rep = {abs = abs, rep = rep} |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
144 |
fun abs_rep_info phi = Quotient_Info.transform_abs_rep phi abs_rep |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
145 |
in |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
146 |
lthy |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
147 |
|> Local_Theory.declaration {syntax = false, pervasive = true} |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
148 |
(fn phi => Quotient_Info.update_quotients qty_full_name (quot_info phi) |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
149 |
#> Quotient_Info.update_abs_rep qty_full_name (abs_rep_info phi)) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
150 |
|> setup_lifting_package gen_code quot_thm equiv_thm opt_par_thm |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
151 |
end |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
152 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
153 |
(* main function for constructing a quotient type *) |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
154 |
fun add_quotient_type (((vs, qty_name, mx), (rty, rel, partial), (opt_morphs, gen_code, opt_par_thm)), equiv_thm) lthy = |
41444 | 155 |
let |
156 |
val part_equiv = |
|
157 |
if partial |
|
158 |
then equiv_thm |
|
159 |
else equiv_thm RS @{thm equivp_implies_part_equivp} |
|
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
160 |
|
41444 | 161 |
(* generates the typedef *) |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
162 |
val ((_, typedef_info), lthy1) = |
41444 | 163 |
typedef_make (vs, qty_name, mx, rel, rty) part_equiv lthy |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
164 |
|
41444 | 165 |
(* abs and rep functions from the typedef *) |
166 |
val Abs_ty = #abs_type (#1 typedef_info) |
|
167 |
val Rep_ty = #rep_type (#1 typedef_info) |
|
168 |
val Abs_name = #Abs_name (#1 typedef_info) |
|
169 |
val Rep_name = #Rep_name (#1 typedef_info) |
|
170 |
val Abs_const = Const (Abs_name, Rep_ty --> Abs_ty) |
|
171 |
val Rep_const = Const (Rep_name, Abs_ty --> Rep_ty) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
172 |
|
41444 | 173 |
(* more useful abs and rep definitions *) |
45317
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
174 |
val abs_const = Const (@{const_name quot_type.abs}, |
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
175 |
(rty --> rty --> @{typ bool}) --> (Rep_ty --> Abs_ty) --> rty --> Abs_ty) |
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
176 |
val rep_const = Const (@{const_name quot_type.rep}, (Abs_ty --> Rep_ty) --> Abs_ty --> rty) |
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
177 |
val abs_trm = abs_const $ rel $ Abs_const |
bf8b9ac6000c
more robust, declarative and unsurprising computation of types in the quotient type definition
bulwahn
parents:
45314
diff
changeset
|
178 |
val rep_trm = rep_const $ Rep_const |
45676
fa46fef06590
alternative names of morphisms in the definition of a quotient type can be specified
kuncar
parents:
45534
diff
changeset
|
179 |
val (rep_name, abs_name) = |
fa46fef06590
alternative names of morphisms in the definition of a quotient type can be specified
kuncar
parents:
45534
diff
changeset
|
180 |
(case opt_morphs of |
fa46fef06590
alternative names of morphisms in the definition of a quotient type can be specified
kuncar
parents:
45534
diff
changeset
|
181 |
NONE => (Binding.prefix_name "rep_" qty_name, Binding.prefix_name "abs_" qty_name) |
fa46fef06590
alternative names of morphisms in the definition of a quotient type can be specified
kuncar
parents:
45534
diff
changeset
|
182 |
| SOME morphs => morphs) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
183 |
|
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
184 |
val ((_, (_, abs_def)), lthy2) = lthy1 |
46909 | 185 |
|> Local_Theory.define ((abs_name, NoSyn), ((Thm.def_binding abs_name, []), abs_trm)) |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
186 |
val ((_, (_, rep_def)), lthy3) = lthy2 |
46909 | 187 |
|> Local_Theory.define ((rep_name, NoSyn), ((Thm.def_binding rep_name, []), rep_trm)) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
188 |
|
41444 | 189 |
(* quot_type theorem *) |
190 |
val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, part_equiv, typedef_info) lthy3 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
191 |
|
41444 | 192 |
(* quotient theorem *) |
47308 | 193 |
val quotient_thm_name = Binding.prefix_name "Quotient3_" qty_name |
41444 | 194 |
val quotient_thm = |
195 |
(quot_thm RS @{thm quot_type.Quotient}) |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
51374
diff
changeset
|
196 |
|> fold_rule lthy3 [abs_def, rep_def] |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
197 |
|
41444 | 198 |
(* name equivalence theorem *) |
199 |
val equiv_thm_name = Binding.suffix_name "_equivp" qty_name |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
200 |
|
45279 | 201 |
(* storing the quotients *) |
47093 | 202 |
val quotients = {qtyp = Abs_ty, rtyp = rty, equiv_rel = rel, equiv_thm = equiv_thm, |
203 |
quot_thm = quotient_thm} |
|
37530
70d03844b2f9
export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents:
37493
diff
changeset
|
204 |
|
41444 | 205 |
val lthy4 = lthy3 |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
206 |
|> init_quotient_infr gen_code quotient_thm equiv_thm opt_par_thm |
45282 | 207 |
|> (snd oo Local_Theory.note) |
208 |
((equiv_thm_name, |
|
57960 | 209 |
if partial then [] else @{attributes [quot_equiv]}), |
45282 | 210 |
[equiv_thm]) |
211 |
|> (snd oo Local_Theory.note) |
|
57960 | 212 |
((quotient_thm_name, @{attributes [quot_thm]}), [quotient_thm]) |
41444 | 213 |
in |
45279 | 214 |
(quotients, lthy4) |
41444 | 215 |
end |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
216 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
217 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
218 |
(* sanity checks for the quotient type specifications *) |
45676
fa46fef06590
alternative names of morphisms in the definition of a quotient type can be specified
kuncar
parents:
45534
diff
changeset
|
219 |
fun sanity_check ((vs, qty_name, _), (rty, rel, _), _) = |
41444 | 220 |
let |
221 |
val rty_tfreesT = map fst (Term.add_tfreesT rty []) |
|
222 |
val rel_tfrees = map fst (Term.add_tfrees rel []) |
|
223 |
val rel_frees = map fst (Term.add_frees rel []) |
|
224 |
val rel_vars = Term.add_vars rel [] |
|
225 |
val rel_tvars = Term.add_tvars rel [] |
|
43547
f3a8476285c6
clarified Binding.pretty/print: no quotes, only markup -- Binding.str_of is rendered obsolete;
wenzelm
parents:
42361
diff
changeset
|
226 |
val qty_str = Binding.print qty_name ^ ": " |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
227 |
|
41444 | 228 |
val illegal_rel_vars = |
229 |
if null rel_vars andalso null rel_tvars then [] |
|
230 |
else [qty_str ^ "illegal schematic variable(s) in the relation."] |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
231 |
|
41444 | 232 |
val dup_vs = |
233 |
(case duplicates (op =) vs of |
|
234 |
[] => [] |
|
235 |
| dups => [qty_str ^ "duplicate type variable(s) on the lhs: " ^ commas_quote dups]) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
236 |
|
41444 | 237 |
val extra_rty_tfrees = |
238 |
(case subtract (op =) vs rty_tfreesT of |
|
239 |
[] => [] |
|
240 |
| extras => [qty_str ^ "extra type variable(s) on the lhs: " ^ commas_quote extras]) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
241 |
|
41444 | 242 |
val extra_rel_tfrees = |
243 |
(case subtract (op =) vs rel_tfrees of |
|
244 |
[] => [] |
|
245 |
| extras => [qty_str ^ "extra type variable(s) in the relation: " ^ commas_quote extras]) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
246 |
|
41444 | 247 |
val illegal_rel_frees = |
248 |
(case rel_frees of |
|
249 |
[] => [] |
|
250 |
| xs => [qty_str ^ "illegal variable(s) in the relation: " ^ commas_quote xs]) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
251 |
|
41444 | 252 |
val errs = illegal_rel_vars @ dup_vs @ extra_rty_tfrees @ extra_rel_tfrees @ illegal_rel_frees |
253 |
in |
|
254 |
if null errs then () else error (cat_lines errs) |
|
255 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
256 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
257 |
(* check for existence of map functions *) |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45698
diff
changeset
|
258 |
fun map_check ctxt (_, (rty, _, _), _) = |
41444 | 259 |
let |
260 |
fun map_check_aux rty warns = |
|
45280 | 261 |
(case rty of |
41444 | 262 |
Type (_, []) => warns |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45317
diff
changeset
|
263 |
| Type (s, _) => |
55467
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents:
54742
diff
changeset
|
264 |
if Symtab.defined (Functor.entries ctxt) s then warns else s :: warns |
45280 | 265 |
| _ => warns) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
266 |
|
41444 | 267 |
val warns = map_check_aux rty [] |
268 |
in |
|
269 |
if null warns then () |
|
270 |
else warning ("No map function defined for " ^ commas warns ^ |
|
271 |
". This will cause problems later on.") |
|
272 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
273 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
274 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
275 |
(*** interface and syntax setup ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
276 |
|
45698
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
277 |
(* the ML-interface takes a list of tuples consisting of: |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
278 |
|
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
279 |
- the name of the quotient type |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
280 |
- its free type variables (first argument) |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
281 |
- its mixfix annotation |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
282 |
- the type to be quotient |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
283 |
- the partial flag (a boolean) |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
284 |
- the relation according to which the type is quotient |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
285 |
- optional names of morphisms (rep/abs) |
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47698
diff
changeset
|
286 |
- flag if code should be generated by Lifting package |
45698
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
287 |
|
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
288 |
it opens a proof-state in which one has to show that the |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
289 |
relations are equivalence relations |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
290 |
*) |
fd8e140ae879
removed outdated comment moved back and updated (at the direct request of Christian Urban)
kuncar
parents:
45690
diff
changeset
|
291 |
|
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
292 |
fun quotient_type quot lthy = |
41444 | 293 |
let |
294 |
(* sanity check *) |
|
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
295 |
val _ = sanity_check quot |
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
296 |
val _ = map_check lthy quot |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
297 |
|
41444 | 298 |
fun mk_goal (rty, rel, partial) = |
299 |
let |
|
300 |
val equivp_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool} |
|
301 |
val const = |
|
302 |
if partial then @{const_name part_equivp} else @{const_name equivp} |
|
303 |
in |
|
304 |
HOLogic.mk_Trueprop (Const (const, equivp_ty) $ rel) |
|
305 |
end |
|
306 |
||
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
307 |
val goal = (mk_goal o #2) quot |
41444 | 308 |
|
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
309 |
fun after_qed [[thm]] = (snd oo add_quotient_type) (quot, thm) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
310 |
in |
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
311 |
Proof.theorem NONE after_qed [[(goal, [])]] lthy |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
312 |
end |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
313 |
|
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
314 |
fun quotient_type_cmd spec lthy = |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
315 |
let |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
316 |
fun parse_spec (((((((gen_code, vs), qty_name), mx), rty_str), (partial, rel_str)), opt_morphs), opt_par_xthm) lthy = |
41444 | 317 |
let |
318 |
val rty = Syntax.read_typ lthy rty_str |
|
46727
0162a0d284ac
Finish localizing the quotient package.
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
45835
diff
changeset
|
319 |
val tmp_lthy1 = Variable.declare_typ rty lthy |
41444 | 320 |
val rel = |
46727
0162a0d284ac
Finish localizing the quotient package.
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
45835
diff
changeset
|
321 |
Syntax.parse_term tmp_lthy1 rel_str |
41444 | 322 |
|> Type.constraint (rty --> rty --> @{typ bool}) |
46727
0162a0d284ac
Finish localizing the quotient package.
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
45835
diff
changeset
|
323 |
|> Syntax.check_term tmp_lthy1 |
0162a0d284ac
Finish localizing the quotient package.
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
45835
diff
changeset
|
324 |
val tmp_lthy2 = Variable.declare_term rel tmp_lthy1 |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
325 |
val opt_par_thm = Option.map (singleton (Attrib.eval_thms lthy)) opt_par_xthm |
41444 | 326 |
in |
51374
84d01fd733cf
lift_definition and setup_lifting generate parametric transfer rules if parametricity theorems are provided
kuncar
parents:
50177
diff
changeset
|
327 |
(((vs, qty_name, mx), (rty, rel, partial), (opt_morphs, gen_code, opt_par_thm)), tmp_lthy2) |
41444 | 328 |
end |
329 |
||
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
330 |
val (spec', _) = parse_spec spec lthy |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
331 |
in |
46727
0162a0d284ac
Finish localizing the quotient package.
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
45835
diff
changeset
|
332 |
quotient_type spec' lthy |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
333 |
end |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
334 |
|
47937
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47698
diff
changeset
|
335 |
val opt_gen_code = |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47698
diff
changeset
|
336 |
Scan.optional (@{keyword "("} |-- (Parse.reserved "no_code" >> K false) --| Parse.!!! @{keyword ")"}) true |
70375fa2679d
generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents:
47698
diff
changeset
|
337 |
|
46949 | 338 |
val partial = Scan.optional (Parse.reserved "partial" -- @{keyword ":"} >> K true) false |
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
339 |
|
47091
d5cd13aca90b
respectfulness theorem has to be proved if a new constant is lifted by quotient_definition
kuncar
parents:
46961
diff
changeset
|
340 |
val quotspec_parser = |
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
341 |
(opt_gen_code -- Parse.type_args -- Parse.binding) -- |
47091
d5cd13aca90b
respectfulness theorem has to be proved if a new constant is lifted by quotient_definition
kuncar
parents:
46961
diff
changeset
|
342 |
(* FIXME Parse.type_args_constrained and standard treatment of sort constraints *) |
d5cd13aca90b
respectfulness theorem has to be proved if a new constant is lifted by quotient_definition
kuncar
parents:
46961
diff
changeset
|
343 |
Parse.opt_mixfix -- (@{keyword "="} |-- Parse.typ) -- |
d5cd13aca90b
respectfulness theorem has to be proved if a new constant is lifted by quotient_definition
kuncar
parents:
46961
diff
changeset
|
344 |
(@{keyword "/"} |-- (partial -- Parse.term)) -- |
47983
a5e699834f2d
drop the feature that more than one quotient type can be defined by quotient_type -> it causes problems
kuncar
parents:
47938
diff
changeset
|
345 |
Scan.option (@{keyword "morphisms"} |-- Parse.!!! (Parse.binding -- Parse.binding)) |
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
346 |
-- Scan.option (@{keyword "parametric"} |-- Parse.!!! Parse.xthm) |
47091
d5cd13aca90b
respectfulness theorem has to be proved if a new constant is lifted by quotient_definition
kuncar
parents:
46961
diff
changeset
|
347 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
348 |
val _ = |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
349 |
Outer_Syntax.local_theory_to_proof @{command_spec "quotient_type"} |
41444 | 350 |
"quotient type definitions (require equivalence proofs)" |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
351 |
(quotspec_parser >> quotient_type_cmd) |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47093
diff
changeset
|
352 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
353 |
|
45280 | 354 |
end; |