124 val name = "Isar/rule_context"; |
124 val name = "Isar/rule_context"; |
125 type T = T; |
125 type T = T; |
126 |
126 |
127 val empty = make_rules ~1 [] empty_netpairs ([], []); |
127 val empty = make_rules ~1 [] empty_netpairs ([], []); |
128 val copy = I; |
128 val copy = I; |
129 val prep_ext = I; |
129 val extend = I; |
130 |
130 |
131 fun merge (Rules {rules = rules1, wrappers = (ws1, ws1'), ...}, |
131 fun merge _ (Rules {rules = rules1, wrappers = (ws1, ws1'), ...}, |
132 Rules {rules = rules2, wrappers = (ws2, ws2'), ...}) = |
132 Rules {rules = rules2, wrappers = (ws2, ws2'), ...}) = |
133 let |
133 let |
134 val wrappers = (gen_merge_lists' eq_snd ws1 ws2, gen_merge_lists' eq_snd ws1' ws2'); |
134 val wrappers = (gen_merge_lists' eq_snd ws1 ws2, gen_merge_lists' eq_snd ws1' ws2'); |
135 val rules = gen_merge_lists' (fn ((_, (k1, th1)), (_, (k2, th2))) => |
135 val rules = gen_merge_lists' (fn ((_, (k1, th1)), (_, (k2, th2))) => |
136 k1 = k2 andalso Drule.eq_thm_prop (th1, th2)) rules1 rules2; |
136 k1 = k2 andalso Drule.eq_thm_prop (th1, th2)) rules1 rules2; |
145 |
145 |
146 structure GlobalRules = TheoryDataFun(GlobalRulesArgs); |
146 structure GlobalRules = TheoryDataFun(GlobalRulesArgs); |
147 val _ = Context.add_setup [GlobalRules.init]; |
147 val _ = Context.add_setup [GlobalRules.init]; |
148 val print_global_rules = GlobalRules.print; |
148 val print_global_rules = GlobalRules.print; |
149 |
149 |
150 structure LocalRulesArgs = |
150 structure LocalRules = ProofDataFun |
151 struct |
151 (struct |
152 val name = GlobalRulesArgs.name; |
152 val name = GlobalRulesArgs.name; |
153 type T = GlobalRulesArgs.T; |
153 type T = GlobalRulesArgs.T; |
154 val init = GlobalRules.get; |
154 val init = GlobalRules.get; |
155 val print = print_rules ProofContext.pretty_thm; |
155 val print = print_rules ProofContext.pretty_thm; |
156 end; |
156 end); |
157 |
157 |
158 structure LocalRules = ProofDataFun(LocalRulesArgs); |
|
159 val _ = Context.add_setup [LocalRules.init]; |
158 val _ = Context.add_setup [LocalRules.init]; |
160 val print_local_rules = LocalRules.print; |
159 val print_local_rules = LocalRules.print; |
161 |
160 |
162 |
161 |
163 (* access data *) |
162 (* access data *) |
173 | untaglist [(k : int * int, x)] = [x] |
172 | untaglist [(k : int * int, x)] = [x] |
174 | untaglist ((k, x) :: (rest as (k', x') :: _)) = |
173 | untaglist ((k, x) :: (rest as (k', x') :: _)) = |
175 if k = k' then untaglist rest |
174 if k = k' then untaglist rest |
176 else x :: untaglist rest; |
175 else x :: untaglist rest; |
177 |
176 |
178 fun orderlist brls = |
177 fun orderlist brls = |
179 untaglist (sort (prod_ord Int.compare Int.compare o pairself fst) brls); |
178 untaglist (sort (prod_ord Int.compare Int.compare o pairself fst) brls); |
180 fun orderlist_no_weight brls = |
179 |
181 untaglist (sort (Int.compare o pairself (snd o fst)) brls); |
180 fun orderlist_no_weight brls = |
|
181 untaglist (sort (Int.compare o pairself (snd o fst)) brls); |
182 |
182 |
183 fun may_unify weighted t net = |
183 fun may_unify weighted t net = |
184 map snd ((if weighted then orderlist else orderlist_no_weight) (Net.unify_term net t)); |
184 map snd ((if weighted then orderlist else orderlist_no_weight) (Net.unify_term net t)); |
185 |
185 |
186 fun find_erules _ [] = K [] |
186 fun find_erules _ [] = K [] |
187 | find_erules w (fact :: _) = may_unify w (Logic.strip_assums_concl (Thm.prop_of fact)); |
187 | find_erules w (fact :: _) = may_unify w (Logic.strip_assums_concl (Thm.prop_of fact)); |
|
188 |
188 fun find_irules w goal = may_unify w (Logic.strip_assums_concl goal); |
189 fun find_irules w goal = may_unify w (Logic.strip_assums_concl goal); |
189 |
190 |
190 fun find_rules_netpair weighted facts goal (inet, enet) = |
191 fun find_rules_netpair weighted facts goal (inet, enet) = |
191 find_erules weighted facts enet @ find_irules weighted goal inet; |
192 find_erules weighted facts enet @ find_irules weighted goal inet; |
192 |
193 |
193 fun find_rules weighted facts goals = map (find_rules_netpair weighted facts goals) o netpairs; |
194 fun find_rules weighted facts goals = |
|
195 map (find_rules_netpair weighted facts goals) o netpairs; |
194 |
196 |
195 |
197 |
196 (* wrappers *) |
198 (* wrappers *) |
197 |
199 |
198 fun gen_add_wrapper upd w = GlobalRules.map (fn (rs as Rules {next, rules, netpairs, wrappers}) => |
200 fun gen_add_wrapper upd w = GlobalRules.map (fn (rs as Rules {next, rules, netpairs, wrappers}) => |