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
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 10
val quotient_def: (binding option * mixfix) * (Attrib.binding * (term * term)) ->
775
+ − 11
local_theory -> (term * thm) * local_theory
789
+ − 12
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 13
val quotdef_cmd: (binding option * mixfix) * (Attrib.binding * (string * string)) ->
1146
+ − 14
local_theory -> (term * thm) * local_theory
277
+ − 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
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 28
- an optional binding and mixfix annotation
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 29
- attributes
884
+ − 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
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 36
Restriction: At the moment the right-hand side of the
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 37
definition must be a constant. Similarly the left-hand
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 38
side must be a constant.
858
+ − 39
*)
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 40
fun error_msg bind str =
1151
+ − 41
let
+ − 42
val name = Binding.name_of bind
+ − 43
val pos = Position.str_of (Binding.pos_of bind)
+ − 44
in
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 45
error ("Head of quotient_definition " ^
1151
+ − 46
(quote str) ^ " differs from declaration " ^ name ^ pos)
+ − 47
end
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 48
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 49
fun quotient_def ((optbind, mx), (attr, (lhs, rhs))) lthy =
293
+ − 50
let
884
+ − 51
val (lhs_str, lhs_ty) = dest_Free lhs handle TERM _ => error "Constant already defined."
+ − 52
val _ = if null (strip_abs_vars rhs) then () else error "The definiens cannot be an abstraction"
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 53
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 54
fun sanity_test NONE _ = true
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 55
| sanity_test (SOME bind) str =
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 56
if Name.of_binding bind = str then true
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 57
else error_msg bind str
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 58
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 59
val _ = sanity_test optbind lhs_str
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 60
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 61
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
+ − 62
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
+ − 63
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
+ − 64
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
+ − 65
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
+ − 66
1142
+ − 67
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
+ − 68
800
+ − 69
(* data storage *)
799
+ − 70
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
+ − 71
fun trans_name phi = (fst o dest_Const o #qconst) (qcinfo phi)
319
+ − 72
val lthy'' = Local_Theory.declaration true
869
ce5f78f0eac5
Finished organising an efficient datastructure for qconst_info.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 73
(fn phi => qconsts_update_gen (trans_name phi) (qcinfo phi)) lthy'
293
+ − 74
in
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 75
((trm, thm), lthy'')
293
+ − 76
end
+ − 77
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 78
fun quotdef_cmd (decl, (attr, (lhs_str, rhs_str))) lthy =
277
+ − 79
let
1141
+ − 80
val lhs = Syntax.read_term lthy lhs_str
+ − 81
val rhs = Syntax.read_term lthy rhs_str
1114
+ − 82
val lthy' = Variable.declare_term lhs lthy
+ − 83
val lthy'' = Variable.declare_term rhs lthy'
277
+ − 84
in
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 85
quotient_def (decl, (attr, (lhs, rhs))) lthy''
277
+ − 86
end
+ − 87
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 88
local
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 89
structure P = OuterParse;
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 90
in
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 91
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 92
val quotdef_decl = (P.binding >> SOME) -- P.opt_mixfix' --| P.$$$ "where"
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 93
279
+ − 94
val quotdef_parser =
1150
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 95
Scan.optional quotdef_decl (NONE, NoSyn) --
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 96
P.!!! (SpecParse.opt_thm_name ":" -- (P.term --| P.$$$ "is" -- P.term))
689a18f9484c
tuned the parsing and testing code in quotient_def.ML; cleaned out old stuff in AbsRepTest.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 97
end
279
+ − 98
1144
+ − 99
val _ =
+ − 100
OuterSyntax.local_theory "quotient_definition"
+ − 101
"definition for constants over the quotient type"
1146
+ − 102
OuterKeyword.thy_decl (quotdef_parser >> (snd oo quotdef_cmd))
277
+ − 103
+ − 104
end; (* structure *)