author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Thu, 14 Jan 2010 08:02:20 +0100 | |
changeset 868 | 09d5b7f0e55d |
parent 864 | 999870716cc8 |
child 869 | ce5f78f0eac5 |
permissions | -rw-r--r-- |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
signature QUOTIENT_DEF = |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
768
diff
changeset
|
3 |
sig |
709 | 4 |
val quotient_def: mixfix -> Attrib.binding -> term -> term -> |
775 | 5 |
local_theory -> (term * thm) * local_theory |
789 | 6 |
|
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
7 |
val quotdef_cmd: (Attrib.binding * string) * (mixfix * string) -> |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
local_theory -> local_theory |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
end; |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
structure Quotient_Def: QUOTIENT_DEF = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
struct |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
|
762
baac4639ecef
avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents:
760
diff
changeset
|
14 |
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>
parents:
768
diff
changeset
|
15 |
open Quotient_Term; |
762
baac4639ecef
avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents:
760
diff
changeset
|
16 |
|
279 | 17 |
(* wrapper for define *) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
fun define name mx attr rhs lthy = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
let |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
val ((rhs, (_ , thm)), lthy') = |
331
345c422b1cb5
updated to Isabelle 22nd November
Christian Urban <urbanc@in.tum.de>
parents:
329
diff
changeset
|
21 |
Local_Theory.define ((name, mx), (attr, rhs)) lthy |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
in |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
((rhs, thm), lthy') |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
|
850 | 27 |
(** interface and syntax setup **) |
28 |
||
29 |
(* the ML-interface takes |
|
709 | 30 |
|
858 | 31 |
- the mixfix annotation |
32 |
- name and attributes |
|
33 |
- the new constant as term |
|
34 |
- the rhs of the definition as term |
|
850 | 35 |
|
858 | 36 |
it returns the defined constant and its definition |
37 |
theorem; stores the data in the qconsts slot |
|
38 |
*) |
|
709 | 39 |
fun quotient_def mx attr lhs rhs lthy = |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
40 |
let |
864
999870716cc8
Better error message for definition failure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
862
diff
changeset
|
41 |
val (lhs_str, lhs_ty) = |
999870716cc8
Better error message for definition failure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
862
diff
changeset
|
42 |
dest_Free lhs |
999870716cc8
Better error message for definition failure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
862
diff
changeset
|
43 |
handle TERM _ => error "The name for the new constant has to be a Free; check that it is not defined yet." |
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
44 |
val qconst_bname = Binding.name lhs_str; |
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>
parents:
833
diff
changeset
|
45 |
val absrep_trm = absrep_fun absF lthy (fastype_of rhs, lhs_ty) $ rhs |
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>
parents:
833
diff
changeset
|
46 |
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>
parents:
598
diff
changeset
|
47 |
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>
parents:
598
diff
changeset
|
48 |
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>
parents:
307
diff
changeset
|
49 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
598
diff
changeset
|
50 |
val ((trm, thm), lthy') = 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>
parents:
307
diff
changeset
|
51 |
|
800 | 52 |
(* data storage *) |
799
0755f8fd56b3
renamed transfer to transform (Markus)
Christian Urban <urbanc@in.tum.de>
parents:
789
diff
changeset
|
53 |
fun qcinfo phi = transform_qconsts phi {qconst = trm, rconst = rhs, def = thm} |
319 | 54 |
val lthy'' = Local_Theory.declaration true |
868
09d5b7f0e55d
Undid changes from symtab to termtab, since we need to lookup specialized types.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
864
diff
changeset
|
55 |
(fn phi => qconsts_update_gen lhs_str (qcinfo phi)) lthy' |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
56 |
in |
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
57 |
((trm, thm), lthy'') |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
58 |
end |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
59 |
|
804 | 60 |
fun quotdef_cmd ((attr, lhs_str), (mx, rhs_str)) lthy = |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
let |
804 | 62 |
val lhs = Syntax.read_term lthy lhs_str |
63 |
val rhs = Syntax.read_term lthy rhs_str |
|
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
in |
709 | 65 |
quotient_def mx attr lhs rhs lthy |> snd |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
|
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
68 |
val _ = OuterKeyword.keyword "as"; |
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
69 |
|
279 | 70 |
val quotdef_parser = |
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
71 |
(SpecParse.opt_thm_name ":" -- |
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
72 |
OuterParse.term) -- |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
73 |
(OuterParse.opt_mixfix' --| OuterParse.$$$ "as" -- |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
74 |
OuterParse.term) |
279 | 75 |
|
767
37285ec4387d
on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
76 |
val _ = OuterSyntax.local_theory "quotient_definition" |
37285ec4387d
on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
77 |
"definition for constants over the quotient type" |
37285ec4387d
on suggestion of Tobias renamed "quotient_def" to "quotient_definition"; needs new keyword file
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
78 |
OuterKeyword.thy_decl (quotdef_parser >> quotdef_cmd) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
end; (* structure *) |