762
|
1 |
signature QUOTIENT_TYPE =
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
2 |
sig
|
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
3 |
exception LIFT_MATCH of string
|
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
4 |
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
5 |
val quotient_type: ((string list * binding * mixfix) * (typ * term)) list
|
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
6 |
-> Proof.context -> Proof.state
|
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
7 |
val quotient_type_cmd: ((((string list * binding) * mixfix) * string) * string) list
|
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
8 |
-> Proof.context -> Proof.state
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
9 |
end;
|
71
|
10 |
|
762
|
11 |
structure Quotient_Type: QUOTIENT_TYPE =
|
71
|
12 |
struct
|
|
13 |
|
762
|
14 |
open Quotient_Info;
|
|
15 |
|
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
16 |
exception LIFT_MATCH of string
|
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
17 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
18 |
(* wrappers for define, note, Attrib.internal and theorem_i *)
|
135
|
19 |
fun define (name, mx, rhs) lthy =
|
|
20 |
let
|
|
21 |
val ((rhs, (_ , thm)), lthy') =
|
331
|
22 |
Local_Theory.define ((name, mx), (Attrib.empty_binding, rhs)) lthy
|
135
|
23 |
in
|
|
24 |
((rhs, thm), lthy')
|
|
25 |
end
|
|
26 |
|
503
d2c9a72e52e0
first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
27 |
fun note (name, thm, attrs) lthy =
|
135
|
28 |
let
|
503
d2c9a72e52e0
first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
29 |
val ((_,[thm']), lthy') = Local_Theory.note ((name, attrs), [thm]) lthy
|
135
|
30 |
in
|
|
31 |
(thm', lthy')
|
|
32 |
end
|
|
33 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
34 |
fun intern_attr at = Attrib.internal (K at)
|
582
|
35 |
|
203
|
36 |
fun theorem after_qed goals ctxt =
|
|
37 |
let
|
|
38 |
val goals' = map (rpair []) goals
|
|
39 |
fun after_qed' thms = after_qed (the_single thms)
|
|
40 |
in
|
|
41 |
Proof.theorem_i NONE after_qed' [goals'] ctxt
|
|
42 |
end
|
135
|
43 |
|
130
|
44 |
|
329
|
45 |
(* definition of quotient types *)
|
|
46 |
(********************************)
|
130
|
47 |
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
48 |
val mem_def1 = @{lemma "y : S ==> S y" by (simp add: mem_def)}
|
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
49 |
val mem_def2 = @{lemma "S y ==> y : S" by (simp add: mem_def)}
|
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
50 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
51 |
(* constructs the term lambda (c::rty => bool). EX (x::rty). c = rel x *)
|
71
|
52 |
fun typedef_term rel rty lthy =
|
|
53 |
let
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
54 |
val [x, c] = [("x", rty), ("c", HOLogic.mk_setT rty)]
|
71
|
55 |
|> Variable.variant_frees lthy [rel]
|
|
56 |
|> map Free
|
|
57 |
in
|
|
58 |
lambda c
|
|
59 |
(HOLogic.exists_const rty $
|
|
60 |
lambda x (HOLogic.mk_eq (c, (rel $ x))))
|
|
61 |
end
|
|
62 |
|
|
63 |
(* makes the new type definitions and proves non-emptyness*)
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
64 |
fun typedef_make (vs, qty_name, mx, rel, rty) lthy =
|
71
|
65 |
let
|
|
66 |
val typedef_tac =
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
67 |
EVERY1 [rtac @{thm exI},
|
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
68 |
rtac mem_def2,
|
71
|
69 |
rtac @{thm exI},
|
|
70 |
rtac @{thm refl}]
|
|
71 |
in
|
319
|
72 |
Local_Theory.theory_result
|
71
|
73 |
(Typedef.add_typedef false NONE
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
74 |
(qty_name, vs, mx)
|
71
|
75 |
(typedef_term rel rty lthy)
|
|
76 |
NONE typedef_tac) lthy
|
|
77 |
end
|
|
78 |
|
781
|
79 |
(* tactic to prove the Quot_Type theorem for the new type *)
|
71
|
80 |
fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) =
|
|
81 |
let
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
82 |
val rep_thm = (#Rep typedef_info) RS mem_def1
|
71
|
83 |
val rep_inv = #Rep_inverse typedef_info
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
84 |
val abs_inv = mem_def2 RS (#Abs_inverse typedef_info)
|
71
|
85 |
val rep_inj = #Rep_inject typedef_info
|
|
86 |
in
|
781
|
87 |
(rtac @{thm Quot_Type.intro} THEN'
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
88 |
RANGE [rtac equiv_thm,
|
71
|
89 |
rtac rep_thm,
|
|
90 |
rtac rep_inv,
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
91 |
EVERY' [rtac abs_inv, rtac @{thm exI}, rtac @{thm refl}],
|
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
92 |
rtac rep_inj]) 1
|
71
|
93 |
end
|
|
94 |
|
781
|
95 |
(* proves the Quot_Type theorem *)
|
71
|
96 |
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy =
|
|
97 |
let
|
781
|
98 |
val quot_type_const = Const (@{const_name "Quot_Type"}, dummyT)
|
71
|
99 |
val goal = HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep)
|
|
100 |
|> Syntax.check_term lthy
|
|
101 |
in
|
|
102 |
Goal.prove lthy [] [] goal
|
|
103 |
(K (typedef_quot_type_tac equiv_thm typedef_info))
|
|
104 |
end
|
|
105 |
|
|
106 |
(* proves the quotient theorem *)
|
|
107 |
fun typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_type_thm) lthy =
|
|
108 |
let
|
529
|
109 |
val quotient_const = Const (@{const_name "Quotient"}, dummyT)
|
71
|
110 |
val goal = HOLogic.mk_Trueprop (quotient_const $ rel $ abs $ rep)
|
|
111 |
|> Syntax.check_term lthy
|
|
112 |
|
|
113 |
val typedef_quotient_thm_tac =
|
|
114 |
EVERY1 [K (rewrite_goals_tac [abs_def, rep_def]),
|
781
|
115 |
rtac @{thm Quot_Type.Quotient},
|
71
|
116 |
rtac quot_type_thm]
|
|
117 |
in
|
|
118 |
Goal.prove lthy [] [] goal
|
|
119 |
(K typedef_quotient_thm_tac)
|
|
120 |
end
|
|
121 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
122 |
(* main function for constructing a quotient type *)
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
123 |
fun mk_typedef_main (((vs, qty_name, mx), (rty, rel)), equiv_thm) lthy =
|
71
|
124 |
let
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
125 |
(* generates the typedef *)
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
126 |
val ((qty_full_name, typedef_info), lthy1) = typedef_make (vs, qty_name, mx, rel, rty) lthy
|
71
|
127 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
128 |
(* abs and rep functions from the typedef *)
|
782
|
129 |
val Abs_ty = #abs_type typedef_info
|
|
130 |
val Rep_ty = #rep_type typedef_info
|
|
131 |
val Abs_name = #Abs_name typedef_info
|
|
132 |
val Rep_name = #Rep_name typedef_info
|
|
133 |
val Abs_const = Const (Abs_name, Rep_ty --> Abs_ty)
|
|
134 |
val Rep_const = Const (Rep_name, Abs_ty --> Rep_ty)
|
71
|
135 |
|
782
|
136 |
(* more abstract abs and rep definitions *)
|
|
137 |
val abs_const = Const (@{const_name "Quot_Type.abs"}, dummyT )
|
|
138 |
val rep_const = Const (@{const_name "Quot_Type.rep"}, dummyT )
|
|
139 |
val abs_trm = Syntax.check_term lthy1 (abs_const $ rel $ Abs_const)
|
|
140 |
val rep_trm = Syntax.check_term lthy1 (rep_const $ Rep_const)
|
|
141 |
val abs_name = Binding.prefix_name "abs_" qty_name
|
|
142 |
val rep_name = Binding.prefix_name "rep_" qty_name
|
781
|
143 |
|
782
|
144 |
val ((abs, abs_def), lthy2) = define (abs_name, NoSyn, abs_trm) lthy1
|
|
145 |
val ((rep, rep_def), lthy3) = define (rep_name, NoSyn, rep_trm) lthy2
|
71
|
146 |
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
147 |
(* quot_type theorem - needed below *)
|
782
|
148 |
val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, equiv_thm, typedef_info) lthy3
|
71
|
149 |
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
150 |
(* quotient theorem *)
|
782
|
151 |
val quotient_thm = typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_thm) lthy3
|
529
|
152 |
val quotient_thm_name = Binding.prefix_name "Quotient_" qty_name
|
71
|
153 |
|
782
|
154 |
(* name equivalence theorem *)
|
|
155 |
val equiv_thm_name = Binding.suffix_name "_equivp" qty_name
|
|
156 |
|
182
|
157 |
(* storing the quot-info *)
|
783
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
158 |
(* FIXME: VarifyT should not be used - at the moment it allows matching against the types. *)
|
786
|
159 |
fun qinfo phi = quotdata_transfer phi
|
|
160 |
{qtyp = Logic.varifyT Abs_ty, rtyp = Logic.varifyT rty,
|
|
161 |
equiv_rel = map_types Logic.varifyT rel, equiv_thm = equiv_thm}
|
|
162 |
val lthy4 = Local_Theory.declaration true
|
|
163 |
(fn phi => quotdata_update_gen qty_full_name (qinfo phi)) lthy3
|
71
|
164 |
in
|
781
|
165 |
lthy4
|
780
a24e26f5488c
explicit handling of mem_def, avoiding the use of the simplifier; this fixes some quotient_type definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
166 |
|> note (quotient_thm_name, quotient_thm, [intern_attr quotient_rules_add])
|
782
|
167 |
||>> note (equiv_thm_name, equiv_thm, [intern_attr equiv_rules_add])
|
71
|
168 |
end
|
|
169 |
|
130
|
170 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
171 |
(* interface and syntax setup *)
|
75
|
172 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
173 |
(* the ML-interface takes a list of 4-tuples consisting of *)
|
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
174 |
(* *)
|
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
175 |
(* - the name of the quotient type *)
|
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
176 |
(* - its mixfix annotation *)
|
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
177 |
(* - the type to be quotient *)
|
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
178 |
(* - the relation according to which the type is quotient *)
|
130
|
179 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
180 |
fun quotient_type quot_list lthy =
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
181 |
let
|
185
|
182 |
fun mk_goal (rty, rel) =
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
183 |
let
|
529
|
184 |
val equivp_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool}
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
185 |
in
|
529
|
186 |
HOLogic.mk_Trueprop (Const (@{const_name equivp}, equivp_ty) $ rel)
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
187 |
end
|
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
188 |
|
185
|
189 |
val goals = map (mk_goal o snd) quot_list
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
190 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
191 |
fun after_qed thms lthy =
|
203
|
192 |
fold_map mk_typedef_main (quot_list ~~ thms) lthy |> snd
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
193 |
in
|
203
|
194 |
theorem after_qed goals lthy
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
195 |
end
|
205
|
196 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
197 |
fun quotient_type_cmd spec lthy =
|
205
|
198 |
let
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
199 |
fun parse_spec ((((vs, qty_name), mx), rty_str), rel_str) =
|
205
|
200 |
let
|
293
|
201 |
val rty = Syntax.read_typ lthy rty_str
|
|
202 |
val rel = Syntax.read_term lthy rel_str
|
205
|
203 |
in
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
204 |
((vs, qty_name, mx), (rty, rel))
|
205
|
205 |
end
|
|
206 |
in
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
207 |
quotient_type (map parse_spec spec) lthy
|
205
|
208 |
end
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
209 |
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
210 |
val quotspec_parser =
|
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
211 |
OuterParse.and_list1
|
787
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
212 |
((OuterParse.type_args -- OuterParse.binding) --
|
5cf83fa5b36c
made the quotient_type definition more like typedef; now type variables need to be explicitly given
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
213 |
OuterParse.opt_infix -- (OuterParse.$$$ "=" |-- OuterParse.typ) --
|
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
214 |
(OuterParse.$$$ "/" |-- OuterParse.term))
|
75
|
215 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
216 |
val _ = OuterKeyword.keyword "/"
|
75
|
217 |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
218 |
val _ =
|
766
df053507edba
renamed "quotient" command to "quotient_type"; needs new keyword file to be installed
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
219 |
OuterSyntax.local_theory_to_proof "quotient_type"
|
df053507edba
renamed "quotient" command to "quotient_type"; needs new keyword file to be installed
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
220 |
"quotient type definitions (require equivalence proofs)"
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
221 |
OuterKeyword.thy_goal (quotspec_parser >> quotient_type_cmd)
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
222 |
|
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
223 |
end; (* structure *)
|
71
|
224 |
|
762
|
225 |
|