264
|
1 |
signature QUOTIENT_INFO =
|
|
2 |
sig
|
|
3 |
type maps_info = {mapfun: string, relfun: string}
|
|
4 |
val maps_lookup: theory -> string -> maps_info option
|
|
5 |
val maps_update_thy: string -> maps_info -> theory -> theory
|
|
6 |
val maps_update: string -> maps_info -> Proof.context -> Proof.context
|
|
7 |
|
|
8 |
type quotient_info = {qtyp: typ, rtyp: typ, rel: term, equiv_thm: thm}
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
9 |
val print_quotinfo: Proof.context -> unit
|
311
|
10 |
val quotdata_lookup_thy: theory -> string -> quotient_info option
|
|
11 |
val quotdata_lookup: Proof.context -> string -> quotient_info option
|
|
12 |
val quotdata_update_thy: string -> (typ * typ * term * thm) -> theory -> theory
|
|
13 |
val quotdata_update: string -> (typ * typ * term * thm) -> Proof.context -> Proof.context
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
14 |
|
322
|
15 |
(*FIXME: obsolete *)
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
16 |
type qenv = (typ * typ) list
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
17 |
val mk_qenv: Proof.context -> qenv
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
18 |
val lookup_qenv: ((typ * typ) -> bool) -> qenv -> typ -> (typ * typ) option
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
19 |
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
20 |
type qconsts_info = {qconst: term, rconst: term}
|
318
|
21 |
val qconsts_transfer: morphism -> qconsts_info -> qconsts_info
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
22 |
val qconsts_lookup: theory -> string -> qconsts_info option
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
23 |
val qconsts_update_thy: string -> qconsts_info -> theory -> theory
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
24 |
val qconsts_update_gen: string -> qconsts_info -> Context.generic -> Context.generic
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
25 |
val print_qconstinfo: Proof.context -> unit
|
264
|
26 |
end;
|
|
27 |
|
|
28 |
structure Quotient_Info: QUOTIENT_INFO =
|
|
29 |
struct
|
|
30 |
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
31 |
|
264
|
32 |
(* data containers *)
|
|
33 |
(*******************)
|
|
34 |
|
|
35 |
(* info about map- and rel-functions *)
|
|
36 |
type maps_info = {mapfun: string, relfun: string}
|
|
37 |
|
306
|
38 |
structure MapsData = Theory_Data
|
264
|
39 |
(type T = maps_info Symtab.table
|
|
40 |
val empty = Symtab.empty
|
|
41 |
val extend = I
|
306
|
42 |
val merge = Symtab.merge (K true))
|
264
|
43 |
|
|
44 |
val maps_lookup = Symtab.lookup o MapsData.get
|
|
45 |
|
|
46 |
fun maps_update_thy k minfo = MapsData.map (Symtab.update (k, minfo))
|
|
47 |
fun maps_update k minfo = ProofContext.theory (maps_update_thy k minfo)
|
|
48 |
|
|
49 |
fun maps_attribute_aux s minfo = Thm.declaration_attribute
|
|
50 |
(fn thm => Context.mapping (maps_update_thy s minfo) (maps_update s minfo))
|
|
51 |
|
|
52 |
(* attribute to be used in declare statements *)
|
|
53 |
fun maps_attribute (ctxt, (tystr, (mapstr, relstr))) =
|
|
54 |
let
|
|
55 |
val thy = ProofContext.theory_of ctxt
|
|
56 |
val tyname = Sign.intern_type thy tystr
|
|
57 |
val mapname = Sign.intern_const thy mapstr
|
|
58 |
val relname = Sign.intern_const thy relstr
|
|
59 |
in
|
|
60 |
maps_attribute_aux tyname {mapfun = mapname, relfun = relname}
|
|
61 |
end
|
|
62 |
|
|
63 |
val maps_attr_parser =
|
|
64 |
Args.context -- Scan.lift
|
|
65 |
((Args.name --| OuterParse.$$$ "=") --
|
|
66 |
(OuterParse.$$$ "(" |-- Args.name --| OuterParse.$$$ "," --
|
|
67 |
Args.name --| OuterParse.$$$ ")"))
|
|
68 |
|
|
69 |
val _ = Context.>> (Context.map_theory
|
|
70 |
(Attrib.setup @{binding "map"} (maps_attr_parser >> maps_attribute)
|
|
71 |
"declaration of map information"))
|
|
72 |
|
|
73 |
|
329
|
74 |
(* info about quotient types *)
|
264
|
75 |
type quotient_info = {qtyp: typ, rtyp: typ, rel: term, equiv_thm: thm}
|
|
76 |
|
306
|
77 |
structure QuotData = Theory_Data
|
311
|
78 |
(type T = quotient_info Symtab.table
|
|
79 |
val empty = Symtab.empty
|
264
|
80 |
val extend = I
|
311
|
81 |
val merge = Symtab.merge (K true))
|
264
|
82 |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
83 |
fun quotdata_lookup_thy thy str =
|
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
84 |
Symtab.lookup (QuotData.get thy) (Sign.intern_type thy str)
|
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
85 |
|
311
|
86 |
val quotdata_lookup = quotdata_lookup_thy o ProofContext.theory_of
|
264
|
87 |
|
314
|
88 |
fun quotdata_update_thy qty_name (qty, rty, rel, equiv_thm) =
|
311
|
89 |
QuotData.map (Symtab.update (qty_name, {qtyp = qty, rtyp = rty, rel = rel, equiv_thm = equiv_thm}))
|
264
|
90 |
|
311
|
91 |
fun quotdata_update qty_name (qty, rty, rel, equiv_thm) =
|
|
92 |
ProofContext.theory (quotdata_update_thy qty_name (qty, rty, rel, equiv_thm))
|
264
|
93 |
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
94 |
fun print_quotinfo ctxt =
|
264
|
95 |
let
|
|
96 |
fun prt_quot {qtyp, rtyp, rel, equiv_thm} =
|
|
97 |
Pretty.block (Library.separate (Pretty.brk 2)
|
324
|
98 |
[Pretty.str "quotient type:",
|
264
|
99 |
Syntax.pretty_typ ctxt qtyp,
|
324
|
100 |
Pretty.str "raw type:",
|
264
|
101 |
Syntax.pretty_typ ctxt rtyp,
|
324
|
102 |
Pretty.str "relation:",
|
264
|
103 |
Syntax.pretty_term ctxt rel,
|
324
|
104 |
Pretty.str "equiv. thm:",
|
264
|
105 |
Syntax.pretty_term ctxt (prop_of equiv_thm)])
|
|
106 |
in
|
|
107 |
QuotData.get (ProofContext.theory_of ctxt)
|
311
|
108 |
|> Symtab.dest
|
|
109 |
|> map (prt_quot o snd)
|
264
|
110 |
|> Pretty.big_list "quotients:"
|
|
111 |
|> Pretty.writeln
|
|
112 |
end
|
|
113 |
|
|
114 |
val _ =
|
|
115 |
OuterSyntax.improper_command "print_quotients" "print out all quotients"
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
116 |
OuterKeyword.diag (Scan.succeed (Toplevel.keep (print_quotinfo o Toplevel.context_of)))
|
264
|
117 |
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
118 |
|
329
|
119 |
(* FIXME: obsolete: environments for quotient and raw types *)
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
120 |
type qenv = (typ * typ) list
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
121 |
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
122 |
fun mk_qenv ctxt =
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
123 |
let
|
311
|
124 |
val thy = ProofContext.theory_of ctxt
|
|
125 |
val qinfo = (QuotData.get thy) |> Symtab.dest |> map snd
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
126 |
in
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
127 |
map (fn {qtyp, rtyp, ...} => (qtyp, rtyp)) qinfo
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
128 |
end
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
129 |
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
130 |
fun lookup_qenv _ [] _ = NONE
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
131 |
| lookup_qenv eq ((qty, rty)::xs) qty' =
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
132 |
if eq (qty', qty) then SOME (qty, rty)
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
133 |
else lookup_qenv eq xs qty'
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
134 |
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
135 |
(* information about quotient constants *)
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
136 |
type qconsts_info = {qconst: term, rconst: term}
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
137 |
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
138 |
structure QConstsData = Theory_Data
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
139 |
(type T = qconsts_info Symtab.table
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
140 |
val empty = Symtab.empty
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
141 |
val extend = I
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
142 |
val merge = Symtab.merge (K true))
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
143 |
|
318
|
144 |
fun qconsts_transfer phi {qconst, rconst} =
|
|
145 |
{qconst = Morphism.term phi qconst,
|
|
146 |
rconst = Morphism.term phi rconst}
|
|
147 |
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
148 |
val qconsts_lookup = Symtab.lookup o QConstsData.get
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
149 |
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
150 |
fun qconsts_update_thy k qcinfo = QConstsData.map (Symtab.update (k, qcinfo))
|
324
|
151 |
fun qconsts_update_gen k qcinfo = Context.mapping (qconsts_update_thy k qcinfo) I
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
152 |
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
153 |
fun print_qconstinfo ctxt =
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
154 |
let
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
155 |
fun prt_qconst {qconst, rconst} =
|
318
|
156 |
Pretty.block (separate (Pretty.brk 1)
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
157 |
[Syntax.pretty_term ctxt qconst,
|
318
|
158 |
Pretty.str ":=",
|
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
159 |
Syntax.pretty_term ctxt rconst])
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
160 |
in
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
161 |
QConstsData.get (ProofContext.theory_of ctxt)
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
162 |
|> Symtab.dest
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
163 |
|> map (prt_qconst o snd)
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
164 |
|> Pretty.big_list "quotient constants:"
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
165 |
|> Pretty.writeln
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
166 |
end
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
167 |
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
168 |
val _ =
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
169 |
OuterSyntax.improper_command "print_quotconsts" "print out all quotient constants"
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
170 |
OuterKeyword.diag (Scan.succeed (Toplevel.keep (print_qconstinfo o Toplevel.context_of)))
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
171 |
|
264
|
172 |
end; (* structure *)
|
|
173 |
|
314
|
174 |
open Quotient_Info
|