author | haftmann |
Mon, 23 Feb 2009 08:19:25 +0100 | |
changeset 30064 | 3cd19b113854 |
parent 30061 | c95e8f696b68 |
child 30075 | ff5b4900d9a5 |
permissions | -rw-r--r-- |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
1 |
(* Title: Tools/code/code_wellsorted.ML |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
2 |
Author: Florian Haftmann, TU Muenchen |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
3 |
|
30061
c95e8f696b68
clarified status of variables in evaluation terms; tuned header
haftmann
parents:
30058
diff
changeset
|
4 |
Producing well-sorted systems of code equations in a graph |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
5 |
with explicit dependencies -- the Waisenhaus algorithm. |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
6 |
*) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
7 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
8 |
signature CODE_FUNCGR = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
9 |
sig |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
10 |
type T |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
11 |
val eqns: T -> string -> (thm * bool) list |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
12 |
val typ: T -> string -> (string * sort) list * typ |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
13 |
val all: T -> string list |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
14 |
val pretty: theory -> T -> Pretty.T |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
15 |
val make: theory -> string list |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
16 |
-> ((sort -> sort) * Sorts.algebra) * T |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
17 |
val eval_conv: theory |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
18 |
-> (term -> term * (((sort -> sort) * Sorts.algebra) -> T -> thm)) -> cterm -> thm |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
19 |
val eval_term: theory |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
20 |
-> (term -> term * (((sort -> sort) * Sorts.algebra) -> T -> 'a)) -> term -> 'a |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
21 |
end |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
22 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
23 |
structure Code_Funcgr : CODE_FUNCGR = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
24 |
struct |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
25 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
26 |
(** the equation graph type **) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
27 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
28 |
type T = (((string * sort) list * typ) * (thm * bool) list) Graph.T; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
29 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
30 |
fun eqns eqngr = these o Option.map snd o try (Graph.get_node eqngr); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
31 |
fun typ eqngr = fst o Graph.get_node eqngr; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
32 |
fun all eqngr = Graph.keys eqngr; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
33 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
34 |
fun pretty thy eqngr = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
35 |
AList.make (snd o Graph.get_node eqngr) (Graph.keys eqngr) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
36 |
|> (map o apfst) (Code_Unit.string_of_const thy) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
37 |
|> sort (string_ord o pairself fst) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
38 |
|> map (fn (s, thms) => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
39 |
(Pretty.block o Pretty.fbreaks) ( |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
40 |
Pretty.str s |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
41 |
:: map (Display.pretty_thm o fst) thms |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
42 |
)) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
43 |
|> Pretty.chunks; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
44 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
45 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
46 |
(** the Waisenhaus algorithm **) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
47 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
48 |
(* auxiliary *) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
49 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
50 |
fun complete_proper_sort thy = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
51 |
Sign.complete_sort thy #> filter (can (AxClass.get_info thy)); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
52 |
|
30029 | 53 |
fun inst_params thy tyco = |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
54 |
map (fn (c, _) => AxClass.param_of_inst thy (c, tyco)) |
30029 | 55 |
o maps (#params o AxClass.get_info thy); |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
56 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
57 |
fun consts_of thy eqns = [] |> (fold o fold o fold_aterms) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
58 |
(fn Const (c, ty) => insert (op =) (c, Sign.const_typargs thy (c, Logic.unvarifyT ty)) | _ => I) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
59 |
(map (op :: o swap o apfst (snd o strip_comb) o Logic.dest_equals o Thm.plain_prop_of o fst) eqns); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
60 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
61 |
fun tyscm_rhss_of thy c eqns = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
62 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
63 |
val tyscm = case eqns of [] => Code.default_typscheme thy c |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
64 |
| ((thm, _) :: _) => (snd o Code_Unit.head_eqn thy) thm; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
65 |
val rhss = consts_of thy eqns; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
66 |
in (tyscm, rhss) end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
67 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
68 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
69 |
(* data structures *) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
70 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
71 |
datatype const = Fun of string | Inst of class * string; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
72 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
73 |
fun const_ord (Fun c1, Fun c2) = fast_string_ord (c1, c2) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
74 |
| const_ord (Inst class_tyco1, Inst class_tyco2) = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
75 |
prod_ord fast_string_ord fast_string_ord (class_tyco1, class_tyco2) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
76 |
| const_ord (Fun _, Inst _) = LESS |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
77 |
| const_ord (Inst _, Fun _) = GREATER; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
78 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
79 |
type var = const * int; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
80 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
81 |
structure Vargraph = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
82 |
GraphFun(type key = var val ord = prod_ord const_ord int_ord); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
83 |
|
30054 | 84 |
datatype styp = Tyco of string * styp list | Var of var | Free; |
85 |
||
86 |
fun styp_of c_lhs (Type (tyco, tys)) = Tyco (tyco, map (styp_of c_lhs) tys) |
|
87 |
| styp_of c_lhs (TFree (v, _)) = case c_lhs |
|
88 |
of SOME (c, lhs) => Var (Fun c, find_index (fn (v', _) => v = v') lhs) |
|
89 |
| NONE => Free; |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
90 |
|
30054 | 91 |
type vardeps_data = ((string * styp list) list * class list) Vargraph.T |
92 |
* (((string * sort) list * (thm * bool) list) Symtab.table |
|
93 |
* (class * string) list); |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
94 |
|
30054 | 95 |
val empty_vardeps_data : vardeps_data = |
96 |
(Vargraph.empty, (Symtab.empty, [])); |
|
97 |
||
98 |
(* retrieving equations and instances from the background context *) |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
99 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
100 |
fun obtain_eqns thy eqngr c = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
101 |
case try (Graph.get_node eqngr) c |
30058 | 102 |
of SOME ((lhs, _), eqns) => ((lhs, []), []) |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
103 |
| NONE => let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
104 |
val eqns = Code.these_eqns thy c |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
105 |
|> burrow_fst (Code_Unit.norm_args thy) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
106 |
|> burrow_fst (Code_Unit.norm_varnames thy Code_Name.purify_tvar Code_Name.purify_var); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
107 |
val ((lhs, _), rhss) = tyscm_rhss_of thy c eqns; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
108 |
in ((lhs, rhss), eqns) end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
109 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
110 |
fun obtain_instance thy arities (inst as (class, tyco)) = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
111 |
case AList.lookup (op =) arities inst |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
112 |
of SOME classess => (classess, ([], [])) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
113 |
| NONE => let |
30029 | 114 |
val all_classes = complete_proper_sort thy [class]; |
115 |
val superclasses = remove (op =) class all_classes |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
116 |
val classess = map (complete_proper_sort thy) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
117 |
(Sign.arity_sorts thy tyco [class]); |
30029 | 118 |
val inst_params = inst_params thy tyco all_classes; |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
119 |
in (classess, (superclasses, inst_params)) end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
120 |
|
30054 | 121 |
|
122 |
(* computing instantiations *) |
|
123 |
||
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
124 |
fun add_classes thy arities eqngr c_k new_classes vardeps_data = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
125 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
126 |
val (styps, old_classes) = Vargraph.get_node (fst vardeps_data) c_k; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
127 |
val diff_classes = new_classes |> subtract (op =) old_classes; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
128 |
in if null diff_classes then vardeps_data |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
129 |
else let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
130 |
val c_ks = Vargraph.imm_succs (fst vardeps_data) c_k |> insert (op =) c_k; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
131 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
132 |
vardeps_data |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
133 |
|> (apfst o Vargraph.map_node c_k o apsnd) (append diff_classes) |
30054 | 134 |
|> fold (fn styp => fold (assert_typmatch_inst thy arities eqngr styp) new_classes) styps |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
135 |
|> fold (fn c_k => add_classes thy arities eqngr c_k diff_classes) c_ks |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
136 |
end end |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
137 |
and add_styp thy arities eqngr c_k tyco_styps vardeps_data = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
138 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
139 |
val (old_styps, classes) = Vargraph.get_node (fst vardeps_data) c_k; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
140 |
in if member (op =) old_styps tyco_styps then vardeps_data |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
141 |
else |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
142 |
vardeps_data |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
143 |
|> (apfst o Vargraph.map_node c_k o apfst) (cons tyco_styps) |
30054 | 144 |
|> fold (assert_typmatch_inst thy arities eqngr tyco_styps) classes |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
145 |
end |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
146 |
and add_dep thy arities eqngr c_k c_k' vardeps_data = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
147 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
148 |
val (_, classes) = Vargraph.get_node (fst vardeps_data) c_k; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
149 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
150 |
vardeps_data |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
151 |
|> add_classes thy arities eqngr c_k' classes |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
152 |
|> apfst (Vargraph.add_edge (c_k, c_k')) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
153 |
end |
30054 | 154 |
and assert_typmatch_inst thy arities eqngr (tyco, styps) class vardeps_data = |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
155 |
if can (Sign.arity_sorts thy tyco) [class] |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
156 |
then vardeps_data |
30054 | 157 |
|> assert_inst thy arities eqngr (class, tyco) |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
158 |
|> fold_index (fn (k, styp) => |
30054 | 159 |
assert_typmatch thy arities eqngr styp (Inst (class, tyco), k)) styps |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
160 |
else vardeps_data (*permissive!*) |
30054 | 161 |
and assert_inst thy arities eqngr (inst as (class, tyco)) (vardeps_data as (_, (_, insts))) = |
162 |
if member (op =) insts inst then vardeps_data |
|
163 |
else let |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
164 |
val (classess, (superclasses, inst_params)) = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
165 |
obtain_instance thy arities inst; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
166 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
167 |
vardeps_data |
30054 | 168 |
|> (apsnd o apsnd) (insert (op =) inst) |
169 |
|> fold (fn superclass => assert_inst thy arities eqngr (superclass, tyco)) superclasses |
|
170 |
|> fold (assert_fun thy arities eqngr) inst_params |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
171 |
|> fold_index (fn (k, classes) => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
172 |
apfst (Vargraph.new_node ((Inst (class, tyco), k), ([] ,[]))) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
173 |
#> add_classes thy arities eqngr (Inst (class, tyco), k) classes |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
174 |
#> fold (fn superclass => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
175 |
add_dep thy arities eqngr (Inst (superclass, tyco), k) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
176 |
(Inst (class, tyco), k)) superclasses |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
177 |
#> fold (fn inst_param => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
178 |
add_dep thy arities eqngr (Fun inst_param, k) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
179 |
(Inst (class, tyco), k) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
180 |
) inst_params |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
181 |
) classess |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
182 |
end |
30054 | 183 |
and assert_typmatch thy arities eqngr (Tyco tyco_styps) c_k vardeps_data = |
184 |
vardeps_data |
|
185 |
|> add_styp thy arities eqngr c_k tyco_styps |
|
186 |
| assert_typmatch thy arities eqngr (Var c_k') c_k vardeps_data = |
|
187 |
vardeps_data |
|
188 |
|> add_dep thy arities eqngr c_k c_k' |
|
189 |
| assert_typmatch thy arities eqngr Free c_k vardeps_data = |
|
190 |
vardeps_data |
|
191 |
and assert_rhs thy arities eqngr (c', styps) vardeps_data = |
|
192 |
vardeps_data |
|
193 |
|> assert_fun thy arities eqngr c' |
|
194 |
|> fold_index (fn (k, styp) => |
|
195 |
assert_typmatch thy arities eqngr styp (Fun c', k)) styps |
|
196 |
and assert_fun thy arities eqngr c (vardeps_data as (_, (eqntab, _))) = |
|
197 |
if Symtab.defined eqntab c then vardeps_data |
|
198 |
else let |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
199 |
val ((lhs, rhss), eqns) = obtain_eqns thy eqngr c; |
30054 | 200 |
val rhss' = (map o apsnd o map) (styp_of (SOME (c, lhs))) rhss; |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
201 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
202 |
vardeps_data |
30054 | 203 |
|> (apsnd o apfst) (Symtab.update_new (c, (lhs, eqns))) |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
204 |
|> fold_index (fn (k, (_, sort)) => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
205 |
apfst (Vargraph.new_node ((Fun c, k), ([] ,[]))) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
206 |
#> add_classes thy arities eqngr (Fun c, k) (complete_proper_sort thy sort)) lhs |
30054 | 207 |
|> fold (assert_rhs thy arities eqngr) rhss' |
208 |
end; |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
209 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
210 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
211 |
(* applying instantiations *) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
212 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
213 |
fun dicts_of thy (proj_sort, algebra) (T, sort) = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
214 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
215 |
fun class_relation (x, _) _ = x; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
216 |
fun type_constructor tyco xs class = |
30054 | 217 |
inst_params thy tyco (Sorts.complete_sort algebra [class]) |
218 |
@ (maps o maps) fst xs; |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
219 |
fun type_variable (TFree (_, sort)) = map (pair []) (proj_sort sort); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
220 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
221 |
flat (Sorts.of_sort_derivation (Syntax.pp_global thy) algebra |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
222 |
{ class_relation = class_relation, type_constructor = type_constructor, |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
223 |
type_variable = type_variable } (T, proj_sort sort) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
224 |
handle Sorts.CLASS_ERROR _ => [] (*permissive!*)) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
225 |
end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
226 |
|
30054 | 227 |
fun add_arity thy vardeps (class, tyco) = |
30058 | 228 |
AList.default (op =) |
30054 | 229 |
((class, tyco), map (fn k => (snd o Vargraph.get_node vardeps) (Inst (class, tyco), k)) |
230 |
(0 upto Sign.arity_number thy tyco - 1)); |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
231 |
|
30054 | 232 |
fun add_eqs thy (proj_sort, algebra) vardeps |
233 |
(c, (proto_lhs, proto_eqns)) (rhss, eqngr) = |
|
30058 | 234 |
if can (Graph.get_node eqngr) c then (rhss, eqngr) |
235 |
else let |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
236 |
val lhs = map_index (fn (k, (v, _)) => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
237 |
(v, snd (Vargraph.get_node vardeps (Fun c, k)))) proto_lhs; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
238 |
val inst_tab = Vartab.empty |> fold (fn (v, sort) => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
239 |
Vartab.update ((v, 0), sort)) lhs; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
240 |
val eqns = proto_eqns |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
241 |
|> (map o apfst) (Code_Unit.inst_thm thy inst_tab); |
30054 | 242 |
val (tyscm, rhss') = tyscm_rhss_of thy c eqns; |
243 |
val eqngr' = Graph.new_node (c, (tyscm, eqns)) eqngr; |
|
244 |
in (map (pair c) rhss' @ rhss, eqngr') end; |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
245 |
|
30054 | 246 |
fun extend_arities_eqngr thy cs cs_rhss (arities, eqngr) = |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
247 |
let |
30054 | 248 |
val cs_rhss' = (map o apsnd o map) (styp_of NONE) cs_rhss; |
249 |
val (vardeps, (eqntab, insts)) = empty_vardeps_data |
|
250 |
|> fold (assert_fun thy arities eqngr) cs |
|
251 |
|> fold (assert_rhs thy arities eqngr) cs_rhss'; |
|
252 |
val arities' = fold (add_arity thy vardeps) insts arities; |
|
30064 | 253 |
val pp = Syntax.pp_global thy; |
254 |
val is_proper_class = can (AxClass.get_info thy); |
|
255 |
val (proj_sort, algebra) = Sorts.subalgebra pp is_proper_class |
|
256 |
(AList.lookup (op =) arities') (Sign.classes_of thy); |
|
30054 | 257 |
val (rhss, eqngr') = Symtab.fold |
258 |
(add_eqs thy (proj_sort, algebra) vardeps) eqntab ([], eqngr); |
|
259 |
fun deps_of (c, rhs) = c :: |
|
260 |
maps (dicts_of thy (proj_sort, algebra)) |
|
261 |
(rhs ~~ (map snd o fst o fst o Graph.get_node eqngr') c); |
|
262 |
val eqngr'' = fold (fn (c, rhs) => fold |
|
263 |
(curry Graph.add_edge c) (deps_of rhs)) rhss eqngr'; |
|
264 |
in ((proj_sort, algebra), (arities', eqngr'')) end; |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
265 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
266 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
267 |
(** retrieval interfaces **) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
268 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
269 |
fun proto_eval thy cterm_of evaluator_lift evaluator proto_ct arities_eqngr = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
270 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
271 |
val ct = cterm_of proto_ct; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
272 |
val _ = Sign.no_vars (Syntax.pp_global thy) (Thm.term_of ct); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
273 |
val _ = Term.fold_types (Type.no_tvars #> K I) (Thm.term_of ct) (); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
274 |
fun consts_of t = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
275 |
fold_aterms (fn Const c_ty => cons c_ty | _ => I) t []; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
276 |
val thm = Code.preprocess_conv thy ct; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
277 |
val ct' = Thm.rhs_of thm; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
278 |
val t' = Thm.term_of ct'; |
30054 | 279 |
val (t'', evaluator_eqngr) = evaluator t'; |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
280 |
val consts = map fst (consts_of t'); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
281 |
val consts' = consts_of t''; |
30054 | 282 |
val const_matches' = fold (fn (c, ty) => |
30061
c95e8f696b68
clarified status of variables in evaluation terms; tuned header
haftmann
parents:
30058
diff
changeset
|
283 |
insert (op =) (c, Sign.const_typargs thy (c, ty))) consts' []; |
30054 | 284 |
val (algebra', arities_eqngr') = |
285 |
extend_arities_eqngr thy consts const_matches' arities_eqngr; |
|
286 |
in |
|
287 |
(evaluator_lift (evaluator_eqngr algebra') thm (snd arities_eqngr'), |
|
288 |
arities_eqngr') |
|
289 |
end; |
|
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
290 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
291 |
fun proto_eval_conv thy = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
292 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
293 |
fun evaluator_lift evaluator thm1 eqngr = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
294 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
295 |
val thm2 = evaluator eqngr; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
296 |
val thm3 = Code.postprocess_conv thy (Thm.rhs_of thm2); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
297 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
298 |
Thm.transitive thm1 (Thm.transitive thm2 thm3) handle THM _ => |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
299 |
error ("could not construct evaluation proof:\n" |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
300 |
^ (cat_lines o map Display.string_of_thm) [thm1, thm2, thm3]) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
301 |
end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
302 |
in proto_eval thy I evaluator_lift end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
303 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
304 |
fun proto_eval_term thy = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
305 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
306 |
fun evaluator_lift evaluator _ eqngr = evaluator eqngr; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
307 |
in proto_eval thy (Thm.cterm_of thy) evaluator_lift end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
308 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
309 |
structure Wellsorted = CodeDataFun |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
310 |
( |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
311 |
type T = ((string * class) * sort list) list * T; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
312 |
val empty = ([], Graph.empty); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
313 |
fun purge thy cs (arities, eqngr) = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
314 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
315 |
val del_cs = ((Graph.all_preds eqngr |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
316 |
o filter (can (Graph.get_node eqngr))) cs); |
30050
916a8427f65a
first attempt to solve evaluation bootstrap problem
haftmann
parents:
30029
diff
changeset
|
317 |
val del_arities = del_cs |
916a8427f65a
first attempt to solve evaluation bootstrap problem
haftmann
parents:
30029
diff
changeset
|
318 |
|> map_filter (AxClass.inst_of_param thy) |
916a8427f65a
first attempt to solve evaluation bootstrap problem
haftmann
parents:
30029
diff
changeset
|
319 |
|> maps (fn (c, tyco) => |
916a8427f65a
first attempt to solve evaluation bootstrap problem
haftmann
parents:
30029
diff
changeset
|
320 |
(map (rpair tyco) o Sign.complete_sort thy o the_list |
916a8427f65a
first attempt to solve evaluation bootstrap problem
haftmann
parents:
30029
diff
changeset
|
321 |
o AxClass.class_of_param thy) c); |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
322 |
val arities' = fold (AList.delete (op =)) del_arities arities; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
323 |
val eqngr' = Graph.del_nodes del_cs eqngr; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
324 |
in (arities', eqngr') end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
325 |
); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
326 |
|
30050
916a8427f65a
first attempt to solve evaluation bootstrap problem
haftmann
parents:
30029
diff
changeset
|
327 |
fun make thy cs = apsnd snd |
916a8427f65a
first attempt to solve evaluation bootstrap problem
haftmann
parents:
30029
diff
changeset
|
328 |
(Wellsorted.change_yield thy (extend_arities_eqngr thy cs [])); |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
329 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
330 |
fun eval_conv thy f = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
331 |
fst o Wellsorted.change_yield thy o proto_eval_conv thy f; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
332 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
333 |
fun eval_term thy f = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
334 |
fst o Wellsorted.change_yield thy o proto_eval_term thy f; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
335 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
336 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
337 |
(** diagnostic commands **) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
338 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
339 |
fun code_depgr thy consts = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
340 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
341 |
val (_, eqngr) = make thy consts; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
342 |
val select = Graph.all_succs eqngr consts; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
343 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
344 |
eqngr |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
345 |
|> not (null consts) ? Graph.subgraph (member (op =) select) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
346 |
|> Graph.map_nodes ((apsnd o map o apfst) (AxClass.overload thy)) |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
347 |
end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
348 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
349 |
fun code_thms thy = Pretty.writeln o pretty thy o code_depgr thy; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
350 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
351 |
fun code_deps thy consts = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
352 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
353 |
val eqngr = code_depgr thy consts; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
354 |
fun mk_entry (const, (_, (_, parents))) = |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
355 |
let |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
356 |
val name = Code_Unit.string_of_const thy const; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
357 |
val nameparents = map (Code_Unit.string_of_const thy) parents; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
358 |
in { name = name, ID = name, dir = "", unfold = true, |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
359 |
path = "", parents = nameparents } |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
360 |
end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
361 |
val prgr = Graph.fold ((fn x => fn xs => xs @ [x]) o mk_entry) eqngr []; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
362 |
in Present.display_graph prgr end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
363 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
364 |
local |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
365 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
366 |
structure P = OuterParse |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
367 |
and K = OuterKeyword |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
368 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
369 |
fun code_thms_cmd thy = code_thms thy o op @ o Code_Name.read_const_exprs thy; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
370 |
fun code_deps_cmd thy = code_deps thy o op @ o Code_Name.read_const_exprs thy; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
371 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
372 |
in |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
373 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
374 |
val _ = |
30024 | 375 |
OuterSyntax.improper_command "code_thms" "print system of code equations for code" OuterKeyword.diag |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
376 |
(Scan.repeat P.term_group |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
377 |
>> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
378 |
o Toplevel.keep ((fn thy => code_thms_cmd thy cs) o Toplevel.theory_of))); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
379 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
380 |
val _ = |
30024 | 381 |
OuterSyntax.improper_command "code_deps" "visualize dependencies of code equations for code" OuterKeyword.diag |
30010
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
382 |
(Scan.repeat P.term_group |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
383 |
>> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
384 |
o Toplevel.keep ((fn thy => code_deps_cmd thy cs) o Toplevel.theory_of))); |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
385 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
386 |
end; |
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
387 |
|
862fc7751a15
tuned and incremental version of wellsorting algorithm
haftmann
parents:
diff
changeset
|
388 |
end; (*struct*) |