author | bulwahn |
Mon, 31 Oct 2011 08:22:56 +0100 | |
changeset 45312 | 6fd165677109 |
parent 45291 | 57cd50f98fdc |
child 45314 | 97b771579000 |
permissions | -rw-r--r-- |
37744 | 1 |
(* Title: HOL/Tools/Quotient/quotient_typ.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 |
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
9 |
val add_quotient_type: ((string list * binding * mixfix) * (typ * term * bool)) * thm |
45279 | 10 |
-> Proof.context -> Quotient_Info.quotients * local_theory |
35415
1810b1ade437
export add_quotient_type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
35351
diff
changeset
|
11 |
|
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
12 |
val quotient_type: ((string list * binding * mixfix) * (typ * term * bool)) list |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
13 |
-> Proof.context -> Proof.state |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
14 |
|
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
15 |
val quotient_type_cmd: ((((string list * binding) * mixfix) * string) * (bool * string)) list |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
16 |
-> Proof.context -> Proof.state |
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 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
28 |
(* constructs the term lambda (c::rty => bool). EX (x::rty). c = rel x *) |
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 |
45 |
val typedef_tac = |
|
46 |
EVERY1 (map rtac [@{thm part_equivp_typedef}, equiv_thm]) |
|
47 |
in |
|
48 |
(* FIXME: purely local typedef causes at the moment |
|
49 |
problems with type variables |
|
50 |
||
51 |
Typedef.add_typedef false NONE (qty_name, vs, mx) |
|
52 |
(typedef_term rel rty lthy) NONE typedef_tac lthy |
|
53 |
*) |
|
54 |
(* FIXME should really use local typedef here *) |
|
55 |
Local_Theory.background_theory_result |
|
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
|
56 |
(Typedef.add_typedef_global false NONE |
35842 | 57 |
(qty_name, map (rpair dummyS) vs, mx) |
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
|
58 |
(typedef_term rel rty lthy) |
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
|
59 |
NONE typedef_tac) lthy |
41444 | 60 |
end |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
61 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
62 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
63 |
(* tactic to prove the quot_type theorem for the new type *) |
35994
9cc3df9a606e
Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents:
35842
diff
changeset
|
64 |
fun typedef_quot_type_tac equiv_thm ((_, typedef_info): Typedef.info) = |
41444 | 65 |
let |
66 |
val rep_thm = #Rep typedef_info RS mem_def1 |
|
67 |
val rep_inv = #Rep_inverse typedef_info |
|
68 |
val abs_inv = #Abs_inverse typedef_info |
|
69 |
val rep_inj = #Rep_inject typedef_info |
|
70 |
in |
|
71 |
(rtac @{thm quot_type.intro} THEN' RANGE [ |
|
72 |
rtac equiv_thm, |
|
73 |
rtac rep_thm, |
|
74 |
rtac rep_inv, |
|
75 |
rtac abs_inv THEN' rtac mem_def2 THEN' atac, |
|
76 |
rtac rep_inj]) 1 |
|
77 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
78 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
79 |
(* 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
|
80 |
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy = |
41444 | 81 |
let |
82 |
val quot_type_const = Const (@{const_name "quot_type"}, dummyT) |
|
83 |
val goal = |
|
84 |
HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep) |
|
85 |
|> Syntax.check_term lthy |
|
86 |
in |
|
87 |
Goal.prove lthy [] [] goal |
|
88 |
(K (typedef_quot_type_tac equiv_thm typedef_info)) |
|
89 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
90 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
91 |
(* main function for constructing a quotient type *) |
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
92 |
fun add_quotient_type (((vs, qty_name, mx), (rty, rel, partial)), equiv_thm) lthy = |
41444 | 93 |
let |
94 |
val part_equiv = |
|
95 |
if partial |
|
96 |
then equiv_thm |
|
97 |
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
|
98 |
|
41444 | 99 |
(* generates the typedef *) |
100 |
val ((qty_full_name, typedef_info), lthy1) = |
|
101 |
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
|
102 |
|
41444 | 103 |
(* abs and rep functions from the typedef *) |
104 |
val Abs_ty = #abs_type (#1 typedef_info) |
|
105 |
val Rep_ty = #rep_type (#1 typedef_info) |
|
106 |
val Abs_name = #Abs_name (#1 typedef_info) |
|
107 |
val Rep_name = #Rep_name (#1 typedef_info) |
|
108 |
val Abs_const = Const (Abs_name, Rep_ty --> Abs_ty) |
|
109 |
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
|
110 |
|
41444 | 111 |
(* more useful abs and rep definitions *) |
45283 | 112 |
val abs_const = Const (@{const_name quot_type.abs}, dummyT) |
113 |
val rep_const = Const (@{const_name quot_type.rep}, dummyT) |
|
41444 | 114 |
val abs_trm = Syntax.check_term lthy1 (abs_const $ rel $ Abs_const) |
115 |
val rep_trm = Syntax.check_term lthy1 (rep_const $ Rep_const) |
|
116 |
val abs_name = Binding.prefix_name "abs_" qty_name |
|
117 |
val rep_name = Binding.prefix_name "rep_" qty_name |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
118 |
|
45282 | 119 |
val ((_, (_, abs_def)), lthy2) = lthy1 |
120 |
|> Local_Theory.define ((abs_name, NoSyn), (Attrib.empty_binding, abs_trm)) |
|
121 |
val ((_, (_, rep_def)), lthy3) = lthy2 |
|
122 |
|> Local_Theory.define ((rep_name, NoSyn), (Attrib.empty_binding, rep_trm)) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
123 |
|
41444 | 124 |
(* quot_type theorem *) |
125 |
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
|
126 |
|
41444 | 127 |
(* quotient theorem *) |
128 |
val quotient_thm_name = Binding.prefix_name "Quotient_" qty_name |
|
129 |
val quotient_thm = |
|
130 |
(quot_thm RS @{thm quot_type.Quotient}) |
|
131 |
|> fold_rule [abs_def, rep_def] |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
132 |
|
41444 | 133 |
(* name equivalence theorem *) |
134 |
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
|
135 |
|
45279 | 136 |
(* storing the quotients *) |
137 |
val quotients = {qtyp = Abs_ty, rtyp = rty, equiv_rel = rel, equiv_thm = equiv_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
|
138 |
|
45279 | 139 |
fun qinfo phi = Quotient_Info.transform_quotients phi quotients |
37530
70d03844b2f9
export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents:
37493
diff
changeset
|
140 |
|
41444 | 141 |
val lthy4 = lthy3 |
45291
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
wenzelm
parents:
45283
diff
changeset
|
142 |
|> Local_Theory.declaration {syntax = false, pervasive = true} |
45279 | 143 |
(fn phi => Quotient_Info.update_quotients qty_full_name (qinfo phi)) |
45282 | 144 |
|> (snd oo Local_Theory.note) |
145 |
((equiv_thm_name, |
|
146 |
if partial then [] else [Attrib.internal (K Quotient_Info.equiv_rules_add)]), |
|
147 |
[equiv_thm]) |
|
148 |
|> (snd oo Local_Theory.note) |
|
149 |
((quotient_thm_name, [Attrib.internal (K Quotient_Info.quotient_rules_add)]), |
|
150 |
[quotient_thm]) |
|
41444 | 151 |
in |
45279 | 152 |
(quotients, lthy4) |
41444 | 153 |
end |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
154 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
155 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
156 |
(* sanity checks for the quotient type specifications *) |
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
157 |
fun sanity_check ((vs, qty_name, _), (rty, rel, _)) = |
41444 | 158 |
let |
159 |
val rty_tfreesT = map fst (Term.add_tfreesT rty []) |
|
160 |
val rel_tfrees = map fst (Term.add_tfrees rel []) |
|
161 |
val rel_frees = map fst (Term.add_frees rel []) |
|
162 |
val rel_vars = Term.add_vars rel [] |
|
163 |
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
|
164 |
val qty_str = Binding.print qty_name ^ ": " |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
165 |
|
41444 | 166 |
val illegal_rel_vars = |
167 |
if null rel_vars andalso null rel_tvars then [] |
|
168 |
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
|
169 |
|
41444 | 170 |
val dup_vs = |
171 |
(case duplicates (op =) vs of |
|
172 |
[] => [] |
|
173 |
| 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
|
174 |
|
41444 | 175 |
val extra_rty_tfrees = |
176 |
(case subtract (op =) vs rty_tfreesT of |
|
177 |
[] => [] |
|
178 |
| 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
|
179 |
|
41444 | 180 |
val extra_rel_tfrees = |
181 |
(case subtract (op =) vs rel_tfrees of |
|
182 |
[] => [] |
|
183 |
| 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
|
184 |
|
41444 | 185 |
val illegal_rel_frees = |
186 |
(case rel_frees of |
|
187 |
[] => [] |
|
188 |
| 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
|
189 |
|
41444 | 190 |
val errs = illegal_rel_vars @ dup_vs @ extra_rty_tfrees @ extra_rel_tfrees @ illegal_rel_frees |
191 |
in |
|
192 |
if null errs then () else error (cat_lines errs) |
|
193 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
194 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
195 |
(* check for existence of map functions *) |
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
196 |
fun map_check ctxt (_, (rty, _, _)) = |
41444 | 197 |
let |
198 |
fun map_check_aux rty warns = |
|
45280 | 199 |
(case rty of |
41444 | 200 |
Type (_, []) => warns |
45280 | 201 |
| Type (s, _) => if is_some (Quotient_Info.lookup_quotmaps ctxt s) then warns else s :: warns |
202 |
| _ => warns) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
203 |
|
41444 | 204 |
val warns = map_check_aux rty [] |
205 |
in |
|
206 |
if null warns then () |
|
207 |
else warning ("No map function defined for " ^ commas warns ^ |
|
208 |
". This will cause problems later on.") |
|
209 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
210 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
211 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
212 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
213 |
(*** interface and syntax setup ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
214 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
215 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
216 |
(* the ML-interface takes a list of 5-tuples consisting of: |
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 |
- the name of the quotient type |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
219 |
- its free type variables (first argument) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
220 |
- its mixfix annotation |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
221 |
- the type to be quotient |
37530
70d03844b2f9
export of proper information in the ML-interface of the quotient package
Christian Urban <urbanc@in.tum.de>
parents:
37493
diff
changeset
|
222 |
- the partial flag (a boolean) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
223 |
- the relation according to which the type is quotient |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
224 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
225 |
it opens a proof-state in which one has to show that the |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
226 |
relations are equivalence relations |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
227 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
228 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
229 |
fun quotient_type quot_list lthy = |
41444 | 230 |
let |
231 |
(* sanity check *) |
|
232 |
val _ = List.app sanity_check quot_list |
|
233 |
val _ = List.app (map_check lthy) quot_list |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
234 |
|
41444 | 235 |
fun mk_goal (rty, rel, partial) = |
236 |
let |
|
237 |
val equivp_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool} |
|
238 |
val const = |
|
239 |
if partial then @{const_name part_equivp} else @{const_name equivp} |
|
240 |
in |
|
241 |
HOLogic.mk_Trueprop (Const (const, equivp_ty) $ rel) |
|
242 |
end |
|
243 |
||
244 |
val goals = map (mk_goal o snd) quot_list |
|
245 |
||
45282 | 246 |
fun after_qed [thms] = fold (snd oo add_quotient_type) (quot_list ~~ thms) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
247 |
in |
45282 | 248 |
Proof.theorem NONE after_qed [map (rpair []) goals] lthy |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
249 |
end |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
250 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
251 |
fun quotient_type_cmd specs lthy = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
252 |
let |
41444 | 253 |
fun parse_spec ((((vs, qty_name), mx), rty_str), (partial, rel_str)) lthy = |
254 |
let |
|
255 |
val rty = Syntax.read_typ lthy rty_str |
|
256 |
val lthy1 = Variable.declare_typ rty lthy |
|
257 |
val rel = |
|
258 |
Syntax.parse_term lthy1 rel_str |
|
259 |
|> Type.constraint (rty --> rty --> @{typ bool}) |
|
260 |
|> Syntax.check_term lthy1 |
|
261 |
val lthy2 = Variable.declare_term rel lthy1 |
|
262 |
in |
|
263 |
(((vs, qty_name, mx), (rty, rel, partial)), lthy2) |
|
264 |
end |
|
265 |
||
266 |
val (spec', lthy') = fold_map parse_spec specs lthy |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
267 |
in |
41444 | 268 |
quotient_type spec' lthy' |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
269 |
end |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
270 |
|
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
271 |
val partial = Scan.optional (Parse.reserved "partial" -- Parse.$$$ ":" >> K true) false |
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
272 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
273 |
val quotspec_parser = |
37493
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
274 |
Parse.and_list1 |
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
275 |
((Parse.type_args -- Parse.binding) -- |
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
276 |
Parse.opt_mixfix -- (Parse.$$$ "=" |-- Parse.typ) -- |
2377d246a631
Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
36960
diff
changeset
|
277 |
(Parse.$$$ "/" |-- (partial -- Parse.term))) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
278 |
|
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36323
diff
changeset
|
279 |
val _ = Keyword.keyword "/" |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
280 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
281 |
val _ = |
41444 | 282 |
Outer_Syntax.local_theory_to_proof "quotient_type" |
283 |
"quotient type definitions (require equivalence proofs)" |
|
284 |
Keyword.thy_goal (quotspec_parser >> quotient_type_cmd) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
285 |
|
45280 | 286 |
end; |