6 *) |
6 *) |
7 |
7 |
8 signature NORMALIZER_DATA = |
8 signature NORMALIZER_DATA = |
9 sig |
9 sig |
10 type entry |
10 type entry |
11 val get: Proof.context -> (thm * entry) list |
11 val get: Proof.context -> simpset * ((thm * entry) list) |
12 val match: Proof.context -> cterm -> entry option |
12 val match: Proof.context -> cterm -> entry option |
13 val del: attribute |
13 val del: attribute |
14 val add: {semiring: cterm list * thm list, ring: cterm list * thm list, idom: thm list} |
14 val add: {semiring: cterm list * thm list, ring: cterm list * thm list, idom: thm list} |
15 -> attribute |
15 -> attribute |
16 val funs: thm -> {is_const: morphism -> cterm -> bool, |
16 val funs: thm -> {is_const: morphism -> cterm -> bool, |
38 val eq_key = Thm.eq_thm; |
38 val eq_key = Thm.eq_thm; |
39 fun eq_data arg = eq_fst eq_key arg; |
39 fun eq_data arg = eq_fst eq_key arg; |
40 |
40 |
41 structure Data = GenericDataFun |
41 structure Data = GenericDataFun |
42 ( |
42 ( |
43 type T = (thm * entry) list; |
43 type T = simpset * ((thm * entry) list); |
44 val empty = []; |
44 val empty = (HOL_basic_ss, []); |
45 val extend = I; |
45 val extend = I; |
46 fun merge _ = AList.merge eq_key (K true); |
46 fun merge _ ((ss, e), (ss', e')) = (merge_ss (ss, ss'), |
|
47 AList.merge eq_key (K true) (e,e')); |
47 ); |
48 ); |
48 |
49 |
49 val get = Data.get o Context.Proof; |
50 val get = Data.get o Context.Proof; |
50 |
51 |
51 |
52 |
75 end; |
76 end; |
76 |
77 |
77 fun match_struct (_, |
78 fun match_struct (_, |
78 entry as ({semiring = (sr_ops, _), ring = (r_ops, _), ...}, _): entry) = |
79 entry as ({semiring = (sr_ops, _), ring = (r_ops, _), ...}, _): entry) = |
79 get_first (match_inst entry) (sr_ops @ r_ops); |
80 get_first (match_inst entry) (sr_ops @ r_ops); |
80 in get_first match_struct (get ctxt) end; |
81 in get_first match_struct (snd (get ctxt)) end; |
81 |
82 |
82 |
83 |
83 (* logical content *) |
84 (* logical content *) |
84 |
85 |
85 val semiringN = "semiring"; |
86 val semiringN = "semiring"; |
86 val ringN = "ring"; |
87 val ringN = "ring"; |
87 val idomN = "idom"; |
88 val idomN = "idom"; |
88 |
89 |
89 fun undefined _ = raise Match; |
90 fun undefined _ = raise Match; |
90 |
91 |
91 fun del_data key = remove eq_data (key, []); |
92 fun del_data key = apsnd (remove eq_data (key, [])); |
92 |
93 |
93 val del = Thm.declaration_attribute (Data.map o del_data); |
94 val del = Thm.declaration_attribute (Data.map o del_data); |
|
95 val add_ss = Thm.declaration_attribute |
|
96 (fn th => Data.map (fn (ss,data) => (ss addsimps [th], data))); |
|
97 |
|
98 val del_ss = Thm.declaration_attribute |
|
99 (fn th => Data.map (fn (ss,data) => (ss delsimps [th], data))); |
94 |
100 |
95 fun add {semiring = (sr_ops, sr_rules), ring = (r_ops, r_rules), idom} = |
101 fun add {semiring = (sr_ops, sr_rules), ring = (r_ops, r_rules), idom} = |
96 Thm.declaration_attribute (fn key => fn context => context |> Data.map |
102 Thm.declaration_attribute (fn key => fn context => context |> Data.map |
97 let |
103 let |
98 val ctxt = Context.proof_of context; |
104 val ctxt = Context.proof_of context; |
130 val _ = map print_thm sr_rules'; |
136 val _ = map print_thm sr_rules'; |
131 val semiring = (sr_ops, sr_rules'); |
137 val semiring = (sr_ops, sr_rules'); |
132 val ring = (r_ops, r_rules'); |
138 val ring = (r_ops, r_rules'); |
133 in |
139 in |
134 del_data key #> |
140 del_data key #> |
135 cons (key, ({vars = vars, semiring = semiring, ring = ring, idom = idom}, |
141 apsnd (cons (key, ({vars = vars, semiring = semiring, ring = ring, idom = idom}, |
136 {is_const = undefined, dest_const = undefined, mk_const = undefined, |
142 {is_const = undefined, dest_const = undefined, mk_const = undefined, |
137 conv = undefined})) |
143 conv = undefined}))) |
138 end); |
144 end); |
139 |
145 |
140 |
146 |
141 (* extra-logical functions *) |
147 (* extra-logical functions *) |
142 |
148 |
143 fun funs raw_key {is_const, dest_const, mk_const, conv} phi = Data.map (fn data => |
149 fun funs raw_key {is_const, dest_const, mk_const, conv} phi = |
|
150 (Data.map o apsnd) (fn data => |
144 let |
151 let |
145 val key = Morphism.thm phi raw_key; |
152 val key = Morphism.thm phi raw_key; |
146 val _ = AList.defined eq_key data key orelse |
153 val _ = AList.defined eq_key data key orelse |
147 raise THM ("No data entry for structure key", 0, [key]); |
154 raise THM ("No data entry for structure key", 0, [key]); |
148 val fns = {is_const = is_const phi, dest_const = dest_const phi, |
155 val fns = {is_const = is_const phi, dest_const = dest_const phi, |