author | Christian Urban <urbanc@in.tum.de> |
Sat, 19 Dec 2009 22:21:51 +0100 | |
changeset 762 | baac4639ecef |
parent 760 | c1989de100b4 |
child 767 | 37285ec4387d |
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 = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
sig |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
datatype flag = absF | repF |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
5 |
val get_fun: flag -> Proof.context -> typ * typ -> term |
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
6 |
|
709 | 7 |
val quotient_def: mixfix -> Attrib.binding -> term -> term -> |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
Proof.context -> (term * thm) * local_theory |
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
9 |
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
|
10 |
local_theory -> local_theory |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
end; |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
structure Quotient_Def: QUOTIENT_DEF = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
struct |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
|
762
baac4639ecef
avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents:
760
diff
changeset
|
16 |
open Quotient_Info; |
baac4639ecef
avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents:
760
diff
changeset
|
17 |
open Quotient_Type; |
baac4639ecef
avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents:
760
diff
changeset
|
18 |
|
279 | 19 |
(* wrapper for define *) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
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
|
21 |
let |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
val ((rhs, (_ , thm)), lthy') = |
331
345c422b1cb5
updated to Isabelle 22nd November
Christian Urban <urbanc@in.tum.de>
parents:
329
diff
changeset
|
23 |
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
|
24 |
in |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
((rhs, thm), lthy') |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
datatype flag = absF | repF |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
fun negF absF = repF |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
| negF repF = absF |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
33 |
fun mk_identity ty = Const (@{const_name "id"}, ty --> ty) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
35 |
fun get_fun_aux lthy s fs = |
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
36 |
let |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
37 |
val thy = ProofContext.theory_of lthy |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
38 |
val exc = LIFT_MATCH (space_implode " " ["get_fun_aux: no map for type", quote s, "."]) |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
39 |
val info = maps_lookup thy s handle NotFound => raise exc |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
40 |
in |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
41 |
list_comb (Const (#mapfun info, dummyT), fs) |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
42 |
end |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
44 |
fun get_const flag lthy _ qty = |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
45 |
(* FIXME: check here that _ and qty are related *) |
719 | 46 |
let |
279 | 47 |
val thy = ProofContext.theory_of lthy |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
48 |
val qty_name = Long_Name.base_name (fst (dest_Type qty)) |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
49 |
in |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
50 |
case flag of |
719 | 51 |
absF => Const (Sign.full_bname thy ("abs_" ^ qty_name), dummyT) |
52 |
| repF => Const (Sign.full_bname thy ("rep_" ^ qty_name), dummyT) |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
53 |
end |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
|
329 | 55 |
|
56 |
(* calculates the aggregate abs and rep functions for a given type; |
|
57 |
repF is for constants' arguments; absF is for constants; |
|
58 |
function types need to be treated specially, since repF and absF |
|
59 |
change *) |
|
60 |
||
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
61 |
fun get_fun flag lthy (rty, qty) = |
389 | 62 |
if rty = qty then mk_identity qty else |
719 | 63 |
case (rty, qty) of |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
64 |
(Type ("fun", [ty1, ty2]), Type ("fun", [ty1', ty2'])) => |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
65 |
let |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
66 |
val fs_ty1 = get_fun (negF flag) lthy (ty1, ty1') |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
67 |
val fs_ty2 = get_fun flag lthy (ty2, ty2') |
719 | 68 |
in |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
69 |
get_fun_aux lthy "fun" [fs_ty1, fs_ty2] |
719 | 70 |
end |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
71 |
| (Type (s, []), Type (s', [])) => |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
72 |
if s = s' |
719 | 73 |
then mk_identity qty |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
74 |
else get_const flag lthy rty qty |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
75 |
| (Type (s, tys), Type (s', tys')) => |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
76 |
if s = s' |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
77 |
then get_fun_aux lthy s' (map (get_fun flag lthy) (tys ~~ tys')) |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
78 |
else get_const flag lthy rty qty |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
79 |
| (TFree x, TFree x') => |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
80 |
if x = x' |
719 | 81 |
then mk_identity qty |
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
82 |
else raise (LIFT_MATCH "get_fun (frees)") |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
83 |
| (TVar _, TVar _) => raise (LIFT_MATCH "get_fun (vars)") |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
84 |
| _ => raise (LIFT_MATCH "get_fun (default)") |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
|
709 | 86 |
(* interface and syntax setup *) |
87 |
||
88 |
(* the ML-interface takes a 4-tuple consisting of *) |
|
89 |
(* *) |
|
90 |
(* - the mixfix annotation *) |
|
91 |
(* - name and attributes of the meta eq *) |
|
92 |
(* - the new constant including its type *) |
|
93 |
(* - the rhs of the definition *) |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
719
diff
changeset
|
94 |
|
709 | 95 |
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
|
96 |
let |
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
97 |
val Free (lhs_str, lhs_ty) = lhs; |
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
98 |
val qconst_bname = Binding.name lhs_str; |
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
99 |
val absrep_trm = get_fun absF lthy (fastype_of rhs, lhs_ty) $ rhs |
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
|
100 |
|> Syntax.check_term lthy |
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
|
101 |
val prop = Logic.mk_equals (lhs, absrep_trm) |
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
|
102 |
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
|
103 |
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
|
104 |
|
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
|
105 |
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
|
106 |
|
496
8f1bf5266ebc
Added the definition to quotient constant data.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
389
diff
changeset
|
107 |
fun qcinfo phi = qconsts_transfer phi {qconst = trm, rconst = rhs, def = thm} |
319 | 108 |
val lthy'' = Local_Theory.declaration true |
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
109 |
(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
|
110 |
in |
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
111 |
((trm, thm), lthy'') |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
112 |
end |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
113 |
|
709 | 114 |
fun quotdef_cmd ((attr, lhsstr), (mx, rhsstr)) lthy = |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
115 |
let |
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
|
116 |
val lhs = Syntax.read_term lthy lhsstr |
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
|
117 |
val rhs = Syntax.read_term lthy rhsstr |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
118 |
in |
709 | 119 |
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
|
120 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
|
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
122 |
val _ = OuterKeyword.keyword "as"; |
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
123 |
|
279 | 124 |
val quotdef_parser = |
705
f51c6069cd17
New syntax for definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
670
diff
changeset
|
125 |
(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
|
126 |
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
|
127 |
(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
|
128 |
OuterParse.term) |
279 | 129 |
|
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
val _ = OuterSyntax.local_theory "quotient_def" "lifted definition of constants" |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
131 |
OuterKeyword.thy_decl (quotdef_parser >> quotdef_cmd) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
133 |
end; (* structure *) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
135 |
|
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
136 |
|
762
baac4639ecef
avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents:
760
diff
changeset
|
137 |