952
+ − 1
(* Title: quotient_def.thy
+ − 2
Author: Cezary Kaliszyk and Christian Urban
+ − 3
+ − 4
Definitions for constants on quotient types.
+ − 5
+ − 6
*)
277
+ − 7
+ − 8
signature QUOTIENT_DEF =
1128
+ − 9
sig
709
+ − 10
val quotient_def: mixfix -> Attrib.binding -> term -> term ->
775
+ − 11
local_theory -> (term * thm) * local_theory
789
+ − 12
1144
+ − 13
val quotdef_cmd: (Attrib.binding * mixfix) option * (Attrib.binding * (string * string)) ->
277
+ − 14
local_theory -> local_theory
+ − 15
end;
+ − 16
+ − 17
structure Quotient_Def: QUOTIENT_DEF =
+ − 18
struct
+ − 19
762
+ − 20
open Quotient_Info;
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 21
open Quotient_Term;
762
+ − 22
884
+ − 23
(** Interface and Syntax Setup **)
850
+ − 24
1128
+ − 25
(* The ML-interface for a quotient definition takes
884
+ − 26
as argument:
709
+ − 27
884
+ − 28
- the mixfix annotation
+ − 29
- name and attributes
+ − 30
- the new constant as term
+ − 31
- the rhs of the definition as term
850
+ − 32
884
+ − 33
It returns the defined constant and its definition
1128
+ − 34
theorem; stores the data in the qconsts data slot.
884
+ − 35
+ − 36
Restriction: At the moment the right-hand side must
1128
+ − 37
be a terms composed of constant. Similarly the
+ − 38
left-hand side must be a single constant.
858
+ − 39
*)
709
+ − 40
fun quotient_def mx attr lhs rhs lthy =
293
+ − 41
let
884
+ − 42
val (lhs_str, lhs_ty) = dest_Free lhs handle TERM _ => error "Constant already defined."
+ − 43
val _ = if null (strip_abs_vars rhs) then () else error "The definiens cannot be an abstraction"
+ − 44
+ − 45
val qconst_bname = Binding.name lhs_str
1097
551eacf071d7
More indentation, names and todo cleaning in the quotient package
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 46
val absrep_trm = absrep_fun AbsF lthy (fastype_of rhs, lhs_ty) $ rhs
854
5961edda27d7
absrep_fun and equiv_relation do not produce anymore spurious maps; two problems arose in IntEx, which are marked with "INJECTION PROBLEM"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 47
val prop = Logic.mk_equals (lhs, Syntax.check_term lthy absrep_trm)
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 48
val (_, prop') = LocalDefs.cert_def lthy prop
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 49
val (_, newrhs) = Primitive_Defs.abs_def prop'
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 50
1142
+ − 51
val ((trm, (_ , thm)), lthy') = Local_Theory.define ((qconst_bname, mx), (attr, newrhs)) lthy
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 52
800
+ − 53
(* data storage *)
799
+ − 54
fun qcinfo phi = transform_qconsts phi {qconst = trm, rconst = rhs, def = thm}
869
ce5f78f0eac5
Finished organising an efficient datastructure for qconst_info.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 55
fun trans_name phi = (fst o dest_Const o #qconst) (qcinfo phi)
319
+ − 56
val lthy'' = Local_Theory.declaration true
869
ce5f78f0eac5
Finished organising an efficient datastructure for qconst_info.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 57
(fn phi => qconsts_update_gen (trans_name phi) (qcinfo phi)) lthy'
293
+ − 58
in
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 59
((trm, thm), lthy'')
293
+ − 60
end
+ − 61
1144
+ − 62
fun quotdef_cmd (bindmx, (attr, (lhs_str, rhs_str))) lthy =
277
+ − 63
let
1141
+ − 64
val lhs = Syntax.read_term lthy lhs_str
+ − 65
val rhs = Syntax.read_term lthy rhs_str
1114
+ − 66
val lthy' = Variable.declare_term lhs lthy
+ − 67
val lthy'' = Variable.declare_term rhs lthy'
277
+ − 68
in
1144
+ − 69
case bindmx of
+ − 70
SOME (b, mx) => quotient_def mx attr lhs rhs lthy'' |> snd
+ − 71
| _ => quotient_def NoSyn attr lhs rhs lthy'' |> snd
277
+ − 72
end
+ − 73
279
+ − 74
val quotdef_parser =
1144
+ − 75
(Scan.option (OuterParse.binding -- OuterParse.opt_mixfix' --| OuterParse.$$$ "where")) --
+ − 76
OuterParse.!!! (SpecParse.opt_thm_name ":" -- ((OuterParse.term --| OuterParse.$$$ "is") -- OuterParse.term))
279
+ − 77
1144
+ − 78
val _ =
+ − 79
OuterSyntax.local_theory "quotient_definition"
+ − 80
"definition for constants over the quotient type"
+ − 81
OuterKeyword.thy_decl (quotdef_parser >> (quotdef_cmd))
277
+ − 82
+ − 83
end; (* structure *)