author | Christian Urban <urbanc@in.tum.de> |
Thu, 19 Nov 2009 14:17:10 +0100 | |
changeset 319 | 0ae9d9e66cb7 |
parent 318 | 746b17e1d6d8 |
child 321 | f46dc0ca08c3 |
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 |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
5 |
val get_fun: flag -> (typ * typ) list -> Proof.context -> typ -> term |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
6 |
val make_def: binding -> typ -> mixfix -> Attrib.binding -> term -> |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
Proof.context -> (term * thm) * local_theory |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
val quotdef: (binding * typ * mixfix) * (Attrib.binding * term) -> |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
local_theory -> (term * thm) * local_theory |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
val quotdef_cmd: (binding * string * mixfix) * (Attrib.binding * string) -> |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
local_theory -> local_theory |
307
9aa3aba71ecc
Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
297
diff
changeset
|
13 |
val diff: (typ * typ) -> (typ * typ) list -> (typ * typ) list |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
end; |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
structure Quotient_Def: QUOTIENT_DEF = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
17 |
struct |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
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') = |
319 | 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 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
(* calculates the aggregate abs and rep functions for a given type; |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
repF is for constants' arguments; absF is for constants; |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
function types need to be treated specially, since repF and absF |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
change *) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
datatype flag = absF | repF |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
fun negF absF = repF |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
| negF repF = absF |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
38 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
fun get_fun flag qenv lthy ty = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
let |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
42 |
fun get_fun_aux s fs = |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
(case (maps_lookup (ProofContext.theory_of lthy) s) of |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
44 |
SOME info => list_comb (Const (#mapfun info, dummyT), fs) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
| NONE => error ("no map association for type " ^ s)) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
47 |
fun get_const flag qty = |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
let |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
val thy = ProofContext.theory_of lthy |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
val qty_name = Long_Name.base_name (fst (dest_Type qty)) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
in |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
case flag of |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
53 |
absF => Const (Sign.full_bname thy ("ABS_" ^ qty_name), dummyT) |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
54 |
| repF => Const (Sign.full_bname thy ("REP_" ^ qty_name), dummyT) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
fun mk_identity ty = Abs ("", ty, Bound 0) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
in |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
if (AList.defined (op=) qenv ty) |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
61 |
then (get_const flag ty) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
else (case ty of |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
63 |
TFree _ => mk_identity ty |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
64 |
| Type (_, []) => mk_identity ty |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
| Type ("fun" , [ty1, ty2]) => |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
66 |
let |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
67 |
val fs_ty1 = get_fun (negF flag) qenv lthy ty1 |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
68 |
val fs_ty2 = get_fun flag qenv lthy ty2 |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
69 |
in |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
70 |
get_fun_aux "fun" [fs_ty1, fs_ty2] |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
71 |
end |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
| Type (s, tys) => get_fun_aux s (map (get_fun flag qenv lthy) tys) |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
73 |
| _ => error ("no type variables allowed")) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
(* returns all subterms where two types differ *) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
fun diff (T, S) Ds = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
case (T, S) of |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
(TVar v, TVar u) => if v = u then Ds else (T, S)::Ds |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
| (TFree x, TFree y) => if x = y then Ds else (T, S)::Ds |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
| (Type (a, Ts), Type (b, Us)) => |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
if a = b then diffs (Ts, Us) Ds else (T, S)::Ds |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
| _ => (T, S)::Ds |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
and diffs (T::Ts, U::Us) Ds = diffs (Ts, Us) (diff (T, U) Ds) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
| diffs ([], []) Ds = Ds |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
| diffs _ _ = error "Unequal length of type arguments" |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
|
279 | 89 |
(* sanity check that the calculated quotient environment |
90 |
matches with the stored quotient environment. *) |
|
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
91 |
fun sanity_chk qenv lthy = |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
let |
286 | 93 |
val global_qenv = Quotient_Info.mk_qenv lthy |
279 | 94 |
val thy = ProofContext.theory_of lthy |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
|
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
96 |
fun error_msg lthy (qty, rty) = |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
97 |
let |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
98 |
val qtystr = quote (Syntax.string_of_typ lthy qty) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
99 |
val rtystr = quote (Syntax.string_of_typ lthy rty) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
100 |
in |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
101 |
error (implode ["Quotient type ", qtystr, " does not match with ", rtystr]) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
102 |
end |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
103 |
|
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
104 |
fun is_inst (qty, rty) (qty', rty') = |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
105 |
if Sign.typ_instance thy (qty, qty') |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
106 |
then let |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
107 |
val inst = Sign.typ_match thy (qty', qty) Vartab.empty |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
108 |
in |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
109 |
rty = Envir.subst_type inst rty' |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
110 |
end |
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
111 |
else false |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
|
279 | 113 |
fun chk_inst (qty, rty) = |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
114 |
if exists (is_inst (qty, rty)) global_qenv |
286 | 115 |
then true |
279 | 116 |
else error_msg lthy (qty, rty) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
117 |
in |
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
parents:
287
diff
changeset
|
118 |
map chk_inst qenv |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
119 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
|
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
121 |
fun make_def nconst_bname qty mx attr rhs lthy = |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
122 |
let |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
123 |
val (arg_tys, res_ty) = strip_type qty |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
124 |
|
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
125 |
val rty = fastype_of rhs |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
126 |
val qenv = distinct (op=) (diff (qty, rty) []) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
127 |
|
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
128 |
val _ = sanity_chk qenv lthy |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
129 |
|
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
130 |
val rep_fns = map (get_fun repF qenv lthy) arg_tys |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
131 |
val abs_fn = (get_fun absF qenv lthy) res_ty |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
132 |
|
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
133 |
fun mk_fun_map t s = |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
134 |
Const (@{const_name "fun_map"}, dummyT) $ t $ s |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
135 |
|
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
136 |
val absrep_trm = (fold_rev mk_fun_map rep_fns abs_fn $ rhs) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
137 |
|> Syntax.check_term lthy |
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
138 |
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
139 |
val ((trm, thm), lthy') = define nconst_bname mx attr absrep_trm lthy |
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
140 |
|
312
4cf79f70efec
looking up data in quot_info works now (needs qualified string)
Christian Urban <urbanc@in.tum.de>
parents:
310
diff
changeset
|
141 |
val nconst_str = Binding.name_of nconst_bname |
318
746b17e1d6d8
fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents:
312
diff
changeset
|
142 |
val qcinfo = {qconst = trm, rconst = rhs} |
319 | 143 |
val lthy'' = Local_Theory.declaration true |
318
746b17e1d6d8
fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents:
312
diff
changeset
|
144 |
(fn phi => qconsts_update_generic nconst_str |
746b17e1d6d8
fixed the storage of qconst definitions
Christian Urban <urbanc@in.tum.de>
parents:
312
diff
changeset
|
145 |
(qconsts_transfer phi qcinfo)) lthy' |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
146 |
in |
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
147 |
((trm, thm), lthy'') |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
148 |
end |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
149 |
|
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
150 |
(* interface and syntax setup *) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
151 |
|
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
152 |
(* the ML-interface takes a 5-tuple consisting of *) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
153 |
(* *) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
154 |
(* - the name of the constant to be lifted *) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
155 |
(* - its type *) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
156 |
(* - its mixfix annotation *) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
157 |
(* - a meta-equation defining the constant, *) |
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
158 |
(* and the attributes of for this meta-equality *) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
159 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
160 |
fun quotdef ((bind, qty, mx), (attr, prop)) lthy = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
161 |
let |
319 | 162 |
val (_, prop') = LocalDefs.cert_def lthy prop |
297
28b264299590
updated to new Isabelle version and added a new example file
Christian Urban <urbanc@in.tum.de>
parents:
293
diff
changeset
|
163 |
val (_, rhs) = Primitive_Defs.abs_def prop' |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
164 |
in |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
290
diff
changeset
|
165 |
make_def bind qty mx attr rhs lthy |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
167 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
fun quotdef_cmd ((bind, qtystr, mx), (attr, propstr)) lthy = |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
169 |
let |
287
fc72f5b2f9d7
replaced check_term o parse_term by read_term
Christian Urban <urbanc@in.tum.de>
parents:
286
diff
changeset
|
170 |
val qty = Syntax.read_typ lthy qtystr |
fc72f5b2f9d7
replaced check_term o parse_term by read_term
Christian Urban <urbanc@in.tum.de>
parents:
286
diff
changeset
|
171 |
val prop = Syntax.read_prop lthy propstr |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
172 |
in |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
quotdef ((bind, qty, mx), (attr, prop)) lthy |> snd |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
174 |
end |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
175 |
|
279 | 176 |
|
177 |
val quotdef_parser = |
|
178 |
(OuterParse.binding -- |
|
179 |
(OuterParse.$$$ "::" |-- OuterParse.!!! (OuterParse.typ -- |
|
180 |
OuterParse.opt_mixfix' --| OuterParse.where_)) >> OuterParse.triple2) -- |
|
181 |
(SpecParse.opt_thm_name ":" -- OuterParse.prop) |
|
182 |
||
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
186 |
end; (* structure *) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
187 |
|
307
9aa3aba71ecc
Modifications while preparing the goal-directed version.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
297
diff
changeset
|
188 |
open Quotient_Def; |