138 FIXME.WN040214: treats rules as in Rls, _not_ as in Seq |
139 FIXME.WN040214: treats rules as in Rls, _not_ as in Seq |
139 |
140 |
140 WN060825 too complicated for the intended use by cancel_, common_nominator_ |
141 WN060825 too complicated for the intended use by cancel_, common_nominator_ |
141 and unreflectedly adapted to extension of rules by Rls_: returns Rls_("sym_simpl.. |
142 and unreflectedly adapted to extension of rules by Rls_: returns Rls_("sym_simpl.. |
142 -- replaced below *) |
143 -- replaced below *) |
143 fun make_deriv thy erls (rs:rule list) ro goal tt = |
144 fun make_deriv thy erls rs ro goal tt = |
144 let |
145 let |
145 datatype switch = Appl | Noap (* unify with version in rewrite.sml *) |
146 datatype switch = Appl | Noap (* unify with version in rewrite.sml *) |
146 fun rew_once _ rts t Noap [] = |
147 fun rew_once _ rts t Noap [] = |
147 (case goal of NONE => rts | SOME _ => error ("make_deriv: no derivation for " ^ term2str t)) |
148 (case goal of NONE => rts | SOME _ => error ("make_deriv: no derivation for " ^ Celem.term2str t)) |
148 | rew_once lim rts t Appl [] = rew_once lim rts t Noap rs |
149 | rew_once lim rts t Appl [] = rew_once lim rts t Noap rs |
149 (*| Seq _ => rts) FIXXXXXME 14.3.03*) |
150 (*| Seq _ => rts) FIXXXXXME 14.3.03*) |
150 | rew_once lim rts t apno rs' = |
151 | rew_once lim rts t apno rs' = |
151 (case goal of |
152 (case goal of |
152 NONE => rew_or_calc lim rts t apno rs' |
153 NONE => rew_or_calc lim rts t apno rs' |
153 | SOME g => if g = t then rts else rew_or_calc lim rts t apno rs') |
154 | SOME g => if g = t then rts else rew_or_calc lim rts t apno rs') |
154 and rew_or_calc lim rts t apno (rrs' as (r :: rs')) = |
155 and rew_or_calc lim rts t apno (rrs' as (r :: rs')) = |
155 if lim < 0 |
156 if lim < 0 |
156 then (tracing ("make_deriv exceeds " ^ int2str (! lim_deriv) ^ "with deriv =\n"); |
157 then (tracing ("make_deriv exceeds " ^ int2str (! Celem.lim_deriv) ^ "with deriv =\n"); |
157 tracing (deriv2str rts); rts) |
158 tracing (deriv2str rts); rts) |
158 else |
159 else |
159 (case r of |
160 (case r of |
160 Thm (thmid, tm) => |
161 Celem.Thm (thmid, tm) => |
161 (if not (! trace_rewrite) then () else tracing ("### trying thm \"" ^ thmid ^ "\""); |
162 (if not (! Celem.trace_rewrite) then () else tracing ("### trying thm \"" ^ thmid ^ "\""); |
162 case Rewrite.rewrite_ thy ro erls true tm t of |
163 case Rewrite.rewrite_ thy ro erls true tm t of |
163 NONE => rew_once lim rts t apno rs' |
164 NONE => rew_once lim rts t apno rs' |
164 | SOME (t', a') => |
165 | SOME (t', a') => |
165 (if ! trace_rewrite then tracing ("### rewrites to: " ^ term2str t') else (); |
166 (if ! Celem.trace_rewrite then tracing ("### rewrites to: " ^ Celem.term2str t') else (); |
166 rew_once (lim - 1) (rts @ [(t, r, (t', a'))]) t' Appl rrs')) |
167 rew_once (lim - 1) (rts @ [(t, r, (t', a'))]) t' Appl rrs')) |
167 | Calc (c as (op_, _)) => |
168 | Celem.Calc (c as (op_, _)) => |
168 let |
169 let |
169 val _ = if not (! trace_rewrite) then () else tracing ("### trying calc. \"" ^ op_^"\"") |
170 val _ = if not (! Celem.trace_rewrite) then () else tracing ("### trying calc. \"" ^ op_^"\"") |
170 val t = TermC.uminus_to_string t |
171 val t = TermC.uminus_to_string t |
171 in |
172 in |
172 case Calc.adhoc_thm thy c t of |
173 case Calc.adhoc_thm thy c t of |
173 NONE => rew_once lim rts t apno rs' |
174 NONE => rew_once lim rts t apno rs' |
174 | SOME (thmid, tm) => |
175 | SOME (thmid, tm) => |
175 (let |
176 (let |
176 val (t', a') = case Rewrite.rewrite_ thy ro erls true tm t of |
177 val (t', a') = case Rewrite.rewrite_ thy ro erls true tm t of |
177 SOME ta => ta |
178 SOME ta => ta |
178 | NONE => error "adhoc_thm: NONE" |
179 | NONE => error "adhoc_thm: NONE" |
179 val _ = if not (! trace_rewrite) then () else tracing("### calc. to: " ^term2str t') |
180 val _ = if not (! Celem.trace_rewrite) then () else tracing("### calc. to: " ^ Celem.term2str t') |
180 val r' = Thm (thmid, tm) |
181 val r' = Celem.Thm (thmid, tm) |
181 in rew_once (lim - 1) (rts @ [(t, r', (t', a'))]) t' Appl rrs' end) |
182 in rew_once (lim - 1) (rts @ [(t, r', (t', a'))]) t' Appl rrs' end) |
182 handle _ => error "derive_norm, Calc: no rewrite" |
183 handle _ => error "derive_norm, Calc: no rewrite" |
183 end |
184 end |
184 (*| Cal1 (cc as (op_,_)) => ... WN080222 see rewrite__set_: see 7df94616c1bd and earlier*) |
185 (*| Cal1 (cc as (op_,_)) => ... WN080222 see rewrite__set_: see 7df94616c1bd and earlier*) |
185 | Rls_ rls => (* WN060829: CREATES "sym_rlsID", see 7df94616c1bd and earlier*) |
186 | Celem.Rls_ rls => (* WN060829: CREATES "sym_rlsID", see 7df94616c1bd and earlier*) |
186 (case Rewrite.rewrite_set_ thy true rls t of |
187 (case Rewrite.rewrite_set_ thy true rls t of |
187 NONE => rew_once lim rts t apno rs' |
188 NONE => rew_once lim rts t apno rs' |
188 | SOME (t', a') => rew_once (lim - 1) (rts @ [(t, r, (t', a'))]) t' Appl rrs') |
189 | SOME (t', a') => rew_once (lim - 1) (rts @ [(t, r, (t', a'))]) t' Appl rrs') |
189 | rule => error ("rew_once: uncovered case " ^ rule2str rule)) |
190 | rule => error ("rew_once: uncovered case " ^ Celem.rule2str rule)) |
190 | rew_or_calc _ _ _ _ [] = error "rew_or_calc: called with []" |
191 | rew_or_calc _ _ _ _ [] = error "rew_or_calc: called with []" |
191 in rew_once (! lim_deriv) [] tt Noap rs : deriv end |
192 in rew_once (! Celem.lim_deriv) [] tt Noap rs end |
192 |
193 |
193 fun sym_drop (thmID : thmID) = |
194 fun sym_drop thmID = |
194 case Symbol.explode thmID of |
195 case Symbol.explode thmID of |
195 "s" :: "y" :: "m" :: "_" :: id => implode id : thmID |
196 "s" :: "y" :: "m" :: "_" :: id => implode id |
196 | _ => thmID |
197 | _ => thmID |
197 fun is_sym (thmID : thmID) = |
198 fun is_sym thmID = |
198 case Symbol.explode thmID of |
199 case Symbol.explode thmID of |
199 "s" :: "y" :: "m" :: "_" :: _ => true |
200 "s" :: "y" :: "m" :: "_" :: _ => true |
200 | _ => false; |
201 | _ => false; |
201 |
202 |
202 (*FIXXXXME.040219: detail has to handle Rls id="sym_..." |
203 (*FIXXXXME.040219: detail has to handle Rls id="sym_..." |
203 by applying make_deriv, rev_deriv'; see concat_deriv*) |
204 by applying make_deriv, rev_deriv'; see concat_deriv*) |
204 fun sym_rls Erls = Erls |
205 fun sym_rls Celem.Erls = Celem.Erls |
205 | sym_rls (Rls {id, scr, calc, errpatts, erls, srls, rules, rew_ord, preconds}) = |
206 | sym_rls (Celem.Rls {id, scr, calc, errpatts, erls, srls, rules, rew_ord, preconds}) = |
206 Rls {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, srls = srls, |
207 Celem.Rls {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, srls = srls, |
207 rules = rules, rew_ord = rew_ord, preconds = preconds} |
208 rules = rules, rew_ord = rew_ord, preconds = preconds} |
208 | sym_rls (Seq {id, scr, calc, errpatts, erls, srls, rules, rew_ord, preconds}) = |
209 | sym_rls (Celem.Seq {id, scr, calc, errpatts, erls, srls, rules, rew_ord, preconds}) = |
209 Seq {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, srls = srls, |
210 Celem.Seq {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, srls = srls, |
210 rules = rules, rew_ord = rew_ord, preconds = preconds} |
211 rules = rules, rew_ord = rew_ord, preconds = preconds} |
211 | sym_rls (Rrls {id, scr, calc, errpatts, erls, prepat, rew_ord}) = |
212 | sym_rls (Celem.Rrls {id, scr, calc, errpatts, erls, prepat, rew_ord}) = |
212 Rrls {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, |
213 Celem.Rrls {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, |
213 prepat = prepat, rew_ord = rew_ord} |
214 prepat = prepat, rew_ord = rew_ord} |
214 |
215 |
215 (* toggles sym_* and keeps "#:" for ad-hoc calculations *) |
216 (* toggles sym_* and keeps "#:" for ad-hoc calculations *) |
216 fun sym_rule (Thm (thmID, thm)) = |
217 fun sym_rule (Celem.Thm (thmID, thm)) = |
217 let |
218 let |
218 val thm' = sym_thm thm |
219 val thm' = sym_thm thm |
219 val thmID' = case Symbol.explode thmID of |
220 val thmID' = case Symbol.explode thmID of |
220 "s" :: "y" :: "m" :: "_" :: id => implode id |
221 "s" :: "y" :: "m" :: "_" :: id => implode id |
221 | "#" :: ":" :: _ => "#: " ^ string_of_thmI thm' |
222 | "#" :: ":" :: _ => "#: " ^ Celem.string_of_thmI thm' |
222 | _ => "sym_" ^ thmID |
223 | _ => "sym_" ^ thmID |
223 in Thm (thmID', thm') end |
224 in Celem.Thm (thmID', thm') end |
224 | sym_rule (Rls_ rls) = Rls_ (sym_rls rls) (* TODO? handle with interSteps ? *) |
225 | sym_rule (Celem.Rls_ rls) = Celem.Rls_ (sym_rls rls) (* TODO? handle with interSteps ? *) |
225 | sym_rule r = error ("sym_rule: not for " ^ rule2str r) |
226 | sym_rule r = error ("sym_rule: not for " ^ Celem.rule2str r) |
226 |
227 |
227 (*version for reverse rewrite used before 040214*) |
228 (*version for reverse rewrite used before 040214*) |
228 fun rev_deriv (t, r, (_, a)) = (sym_rule r, (t, a)); |
229 fun rev_deriv (t, r, (_, a)) = (sym_rule r, (t, a)); |
229 fun reverse_deriv thy erls (rs:rule list) ro goal t = |
230 fun reverse_deriv thy erls rs ro goal t = |
230 (rev o (map rev_deriv)) (make_deriv thy erls (rs:rule list) ro goal t) |
231 (rev o (map rev_deriv)) (make_deriv thy erls rs ro goal t) |
231 |
232 |
232 fun eq_Thm (Thm (id1, _), Thm (id2,_)) = id1 = id2 |
233 fun eq_Thm (Celem.Thm (id1, _), Celem.Thm (id2,_)) = id1 = id2 |
233 | eq_Thm (Thm (_, _), _) = false |
234 | eq_Thm (Celem.Thm (_, _), _) = false |
234 | eq_Thm (Rls_ r1, Rls_ r2) = id_rls r1 = id_rls r2 |
235 | eq_Thm (Celem.Rls_ r1, Celem.Rls_ r2) = Celem.id_rls r1 = Celem.id_rls r2 |
235 | eq_Thm (Rls_ _, _) = false |
236 | eq_Thm (Celem.Rls_ _, _) = false |
236 | eq_Thm (r1, r2) = error ("eq_Thm: called with '" ^ rule2str r1 ^ "' '"^ rule2str r2 ^ "'") |
237 | eq_Thm (r1, r2) = error ("eq_Thm: called with '" ^ Celem.rule2str r1 ^ "' '" ^ Celem.rule2str r2 ^ "'") |
237 fun distinct_Thm r = gen_distinct eq_Thm r |
238 fun distinct_Thm r = gen_distinct eq_Thm r |
238 |
239 |
239 fun eq_Thms thmIDs thm = (member op = thmIDs (id_of_thm thm)) |
240 fun eq_Thms thmIDs thm = (member op = thmIDs (Celem.id_of_thm thm)) |
240 handle ERROR _ => false |
241 handle ERROR _ => false |
241 |
242 |
242 fun thy_containing_thm thmDeriv = |
243 fun thy_containing_thm thmDeriv = |
243 let |
244 let |
244 val isabthys' = map Context.theory_name (isabthys ()); |
245 val isabthys' = map Context.theory_name (Celem.isabthys ()); |
245 in |
246 in |
246 if member op= isabthys' (thyID_of_derivation_name thmDeriv) |
247 if member op= isabthys' (Celem.thyID_of_derivation_name thmDeriv) |
247 then ("Isabelle", thyID_of_derivation_name thmDeriv) |
248 then ("Isabelle", Celem.thyID_of_derivation_name thmDeriv) |
248 else ("IsacKnowledge", thyID_of_derivation_name thmDeriv) |
249 else ("IsacKnowledge", Celem.thyID_of_derivation_name thmDeriv) |
249 end |
250 end |
250 |
251 |
251 (* which theory in ancestors of thy' contains a ruleset *) |
252 (* which theory in ancestors of thy' contains a ruleset *) |
252 fun thy_containing_rls (thy' : theory') (rls' : rls') = |
253 fun thy_containing_rls thy' rls' = |
253 let |
254 let |
254 val thy = Thy_Info_get_theory thy' |
255 val thy = Celem.Thy_Info_get_theory thy' |
255 in |
256 in |
256 case AList.lookup op= (KEStore_Elems.get_rlss thy) rls' of |
257 case AList.lookup op= (KEStore_Elems.get_rlss thy) rls' of |
257 SOME (thy'', _) => (partID' thy'', thy'') |
258 SOME (thy'', _) => (Celem.partID' thy'', thy'') |
258 | _ => error ("thy_containing_rls : rls '" ^ rls' ^ "' not in ancestors of thy '" ^ thy' ^ "'") |
259 | _ => error ("thy_containing_rls : rls '" ^ rls' ^ "' not in ancestors of thy '" ^ thy' ^ "'") |
259 end |
260 end |
260 |
261 |
261 (* this function cannot work as long as the datastructure does not contain thy' *) |
262 (* this function cannot work as long as the datastructure does not contain thy' *) |
262 fun thy_containing_cal (thy' : theory') (sop : prog_calcID) = |
263 fun thy_containing_cal thy' sop = |
263 let |
264 let |
264 val thy = Thy_Info_get_theory thy' |
265 val thy = Celem.Thy_Info_get_theory thy' |
265 in |
266 in |
266 case AList.lookup op= (KEStore_Elems.get_calcs thy) sop of |
267 case AList.lookup op= (KEStore_Elems.get_calcs thy) sop of |
267 SOME (_(*"Groups.plus_class.plus"*), _) => ("IsacKnowledge", "Atools" (*FIXME*)) |
268 SOME (_(*"Groups.plus_class.plus"*), _) => ("IsacKnowledge", "Atools" (*FIXME*)) |
268 | _ => error ("thy_containing_cal : rls '" ^ sop ^ "' not in ancestors of thy '" ^ thy' ^ "'") |
269 | _ => error ("thy_containing_cal : rls '" ^ sop ^ "' not in ancestors of thy '" ^ thy' ^ "'") |
269 end |
270 end |
270 |
271 |
271 (* packing return-values to matchTheory, contextToThy for xml-generation *) |
272 (* packing return-values to matchTheory, contextToThy for xml-generation *) |
272 datatype contthy = (*also an item from KEStore on Browser .....#*) |
273 datatype contthy = (*also an item from KEStore on Browser .....#*) |
273 EContThy (* not from KEStore ..............................*) |
274 EContThy (* not from KEStore ..............................*) |
274 | ContThm of (* a theorem in contex ===========================*) |
275 | ContThm of (* a theorem in contex ===========================*) |
275 {thyID : thyID, (* for *2guh in sub-elems here .*) |
276 {thyID : Celem.thyID, (* for *2guh in sub-elems here .*) |
276 thm : guh, (* theorem in the context .*) |
277 thm : Celem.guh, (* theorem in the context .*) |
277 applto : term, (* applied to formula ... .*) |
278 applto : term, (* applied to formula ... .*) |
278 applat : term, (* ... with lhs inserted .*) |
279 applat : term, (* ... with lhs inserted .*) |
279 reword : rew_ord', (* order used for rewrite .*) |
280 reword : Celem.rew_ord', (* order used for rewrite .*) |
280 asms : (term (* asumption instantiated .*) |
281 asms : (term (* asumption instantiated .*) |
281 * term) list, (* asumption evaluated .*) |
282 * term) list, (* asumption evaluated .*) |
282 lhs : term (* lhs of the theorem ... #*) |
283 lhs : term (* lhs of the theorem ... #*) |
283 * term, (* ... instantiated .*) |
284 * term, (* ... instantiated .*) |
284 rhs : term (* rhs of the theorem ... #*) |
285 rhs : term (* rhs of the theorem ... #*) |
285 * term, (* ... instantiated .*) |
286 * term, (* ... instantiated .*) |
286 result : term, (* resulting from the rewrite .*) |
287 result : term, (* resulting from the rewrite .*) |
287 resasms : term list, (* ... with asms stored .*) |
288 resasms : term list, (* ... with asms stored .*) |
288 asmrls : rls' (* ruleset for evaluating asms .*) |
289 asmrls : Celem.rls' (* ruleset for evaluating asms .*) |
289 } |
290 } |
290 | ContThmInst of (* a theorem with bdvs in contex ============ *) |
291 | ContThmInst of (* a theorem with bdvs in contex ============ *) |
291 {thyID : thyID, (*for *2guh in sub-elems here .*) |
292 {thyID : Celem.thyID, (*for *2guh in sub-elems here .*) |
292 thm : guh, (*theorem in the context .*) |
293 thm : Celem.guh, (*theorem in the context .*) |
293 bdvs : subst, (*bound variables to modify... .*) |
294 bdvs : Celem.subst, (*bound variables to modify... .*) |
294 thminst : term, (*... theorem instantiated .*) |
295 thminst : term, (*... theorem instantiated .*) |
295 applto : term, (*applied to formula ... .*) |
296 applto : term, (*applied to formula ... .*) |
296 applat : term, (*... with lhs inserted .*) |
297 applat : term, (*... with lhs inserted .*) |
297 reword : rew_ord', (*order used for rewrite .*) |
298 reword : Celem.rew_ord', (*order used for rewrite .*) |
298 asms : (term (*asumption instantiated .*) |
299 asms : (term (*asumption instantiated .*) |
299 * term) list, (*asumption evaluated .*) |
300 * term) list, (*asumption evaluated .*) |
300 lhs : term (*lhs of the theorem ... #*) |
301 lhs : term (*lhs of the theorem ... #*) |
301 * term, (*... instantiated .*) |
302 * term, (*... instantiated .*) |
302 rhs : term (*rhs of the theorem ... #*) |
303 rhs : term (*rhs of the theorem ... #*) |
303 * term, (*... instantiated .*) |
304 * term, (*... instantiated .*) |
304 result : term, (*resulting from the rewrite .*) |
305 result : term, (*resulting from the rewrite .*) |
305 resasms : term list, (*... with asms stored .*) |
306 resasms : term list, (*... with asms stored .*) |
306 asmrls : rls' (*ruleset for evaluating asms .*) |
307 asmrls : Celem.rls' (*ruleset for evaluating asms .*) |
307 } |
308 } |
308 | ContRls of (* a rule set in contex ========================= *) |
309 | ContRls of (* a rule set in contex ========================= *) |
309 {thyID : thyID, (*for *2guh in sub-elems here .*) |
310 {thyID : Celem.thyID, (*for *2guh in sub-elems here .*) |
310 rls : guh, (*rule set in the context .*) |
311 rls : Celem.guh, (*rule set in the context .*) |
311 applto : term, (*rewrite this formula .*) |
312 applto : term, (*rewrite this formula .*) |
312 result : term, (*resulting from the rewrite .*) |
313 result : term, (*resulting from the rewrite .*) |
313 asms : term list (*... with asms stored .*) |
314 asms : term list (*... with asms stored .*) |
314 } |
315 } |
315 | ContRlsInst of (* a rule set with bdvs in contex =========== *) |
316 | ContRlsInst of (* a rule set with bdvs in contex =========== *) |
316 {thyID : thyID, (*for *2guh in sub-elems here .*) |
317 {thyID : Celem.thyID, (*for *2guh in sub-elems here .*) |
317 rls : guh, (*rule set in the context .*) |
318 rls : Celem.guh, (*rule set in the context .*) |
318 bdvs : subst, (*for bound variables in thms .*) |
319 bdvs : Celem.subst, (*for bound variables in thms .*) |
319 applto : term, (*rewrite this formula .*) |
320 applto : term, (*rewrite this formula .*) |
320 result : term, (*resulting from the rewrite .*) |
321 result : term, (*resulting from the rewrite .*) |
321 asms : term list (*... with asms stored .*) |
322 asms : term list (*... with asms stored .*) |
322 } |
323 } |
323 | ContNOrew of (* no rewrite for thm or rls ================== *) |
324 | ContNOrew of (* no rewrite for thm or rls ================== *) |
324 {thyID : thyID, (*for *2guh in sub-elems here .*) |
325 {thyID : Celem.thyID, (*for *2guh in sub-elems here .*) |
325 thm_rls : guh, (*thm or rls in the context .*) |
326 thm_rls : Celem.guh, (*thm or rls in the context .*) |
326 applto : term (*rewrite this formula .*) |
327 applto : term (*rewrite this formula .*) |
327 } |
328 } |
328 | ContNOrewInst of (* no rewrite for some instantiation ====== *) |
329 | ContNOrewInst of (* no rewrite for some instantiation ====== *) |
329 {thyID : thyID, (*for *2guh in sub-elems here .*) |
330 {thyID : Celem.thyID, (*for *2guh in sub-elems here .*) |
330 thm_rls : guh, (*thm or rls in the context .*) |
331 thm_rls : Celem.guh, (*thm or rls in the context .*) |
331 bdvs : subst, (*for bound variables in thms .*) |
332 bdvs : Celem.subst, (*for bound variables in thms .*) |
332 thminst : term, (*... theorem instantiated .*) |
333 thminst : term, (*... theorem instantiated .*) |
333 applto : term (*rewrite this formula .*) |
334 applto : term (*rewrite this formula .*) |
334 } |
335 } |
335 |
336 |
336 (*.check a rewrite-tac for bdv (RL always used *_Inst !) TODO.WN060718 |
337 (*.check a rewrite-tac for bdv (RL always used *_Inst !) TODO.WN060718 |
337 pass other tacs unchanged.*) |
338 pass other tacs unchanged.*) |
338 fun get_tac_checked pt ((p, _) : Ctree.pos') = Ctree.get_obj Ctree.g_tac pt p; |
339 fun get_tac_checked pt ((p, _) : Ctree.pos') = Ctree.get_obj Ctree.g_tac pt p; |
339 |
340 |
340 (* create a derivation-name, eg. ("refl", _) --> "HOL.refl"*) |
341 (* create a derivation-name, eg. ("refl", _) --> "HOL.refl"*) |
341 fun deriv_of_thm'' ((thmID, _) : thm'') = |
342 fun deriv_of_thm'' (thmID, _) = |
342 thmID |> Global_Theory.get_thm (Isac ()) |> Thm.get_name_hint |
343 thmID |> Global_Theory.get_thm (Celem.Isac ()) |> Thm.get_name_hint |
343 |
344 |
344 (* get the formula f at ptp rewritten by the Rewrite_* already applied to f *) |
345 (* get the formula f at ptp rewritten by the Rewrite_* already applied to f *) |
345 fun context_thy (pt, pos as (p,p_)) (tac as Tac.Rewrite thm'') = |
346 fun context_thy (pt, pos as (p,p_)) (tac as Tac.Rewrite thm'') = |
346 let val thm_deriv = deriv_of_thm'' thm'' |
347 let val thm_deriv = deriv_of_thm'' thm'' |
347 in |
348 in |
348 (case Applicable.applicable_in pos pt tac of |
349 (case Applicable.applicable_in pos pt tac of |
349 Chead.Appl (Tac.Rewrite' (thy', ord', erls, _, _, f, (res,asm))) => |
350 Chead.Appl (Tac.Rewrite' (thy', ord', erls, _, _, f, (res,asm))) => |
350 ContThm |
351 ContThm |
351 {thyID = theory'2thyID thy', |
352 {thyID = Celem.theory'2thyID thy', |
352 thm = thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
353 thm = Celem.thm2guh (thy_containing_thm thm_deriv) (Celem.thmID_of_derivation_name thm_deriv), |
353 applto = f, applat = e_term, reword = ord', |
354 applto = f, applat = Celem.e_term, reword = ord', |
354 asms = [](*asms ~~ asms'*), lhs = (e_term, e_term)(*(lhs, lhs')*), rhs = (e_term, e_term)(*(rhs, rhs')*), |
355 asms = [](*asms ~~ asms'*), lhs = (Celem.e_term, Celem.e_term)(*(lhs, lhs')*), rhs = (Celem.e_term, Celem.e_term)(*(rhs, rhs')*), |
355 result = res, resasms = asm, asmrls = id_rls erls} |
356 result = res, resasms = asm, asmrls = Celem.id_rls erls} |
356 | Chead.Notappl _ => |
357 | Chead.Notappl _ => |
357 let |
358 let |
358 val pp = Ctree.par_pblobj pt p |
359 val pp = Ctree.par_pblobj pt p |
359 val thy' = Ctree.get_obj Ctree.g_domID pt pp |
360 val thy' = Ctree.get_obj Ctree.g_domID pt pp |
360 val f = case p_ of |
361 val f = case p_ of |
361 Ctree.Frm => Ctree.get_obj Ctree.g_form pt p |
362 Ctree.Frm => Ctree.get_obj Ctree.g_form pt p |
362 | Ctree.Res => (fst o (Ctree.get_obj Ctree.g_result pt)) p |
363 | Ctree.Res => (fst o (Ctree.get_obj Ctree.g_result pt)) p |
363 | _ => error "context_thy: uncovered position" |
364 | _ => error "context_thy: uncovered position" |
364 in |
365 in |
365 ContNOrew |
366 ContNOrew |
366 {thyID = theory'2thyID thy', |
367 {thyID = Celem.theory'2thyID thy', |
367 thm_rls = |
368 thm_rls = |
368 thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
369 Celem.thm2guh (thy_containing_thm thm_deriv) (Celem.thmID_of_derivation_name thm_deriv), |
369 applto = f} |
370 applto = f} |
370 end |
371 end |
371 | _ => error "context_thy..Rewrite: uncovered case 2") |
372 | _ => error "context_thy..Rewrite: uncovered case 2") |
372 end |
373 end |
373 | context_thy (pt, pos as (p, p_)) (tac as Tac.Rewrite_Inst (subs, (thmID, _))) = |
374 | context_thy (pt, pos as (p, p_)) (tac as Tac.Rewrite_Inst (subs, (thmID, _))) = |
374 let val thm = Global_Theory.get_thm (Isac ()) thmID |
375 let val thm = Global_Theory.get_thm (Celem.Isac ()) thmID |
375 in |
376 in |
376 (case Applicable.applicable_in pos pt tac of |
377 (case Applicable.applicable_in pos pt tac of |
377 Chead.Appl (Tac.Rewrite_Inst' (thy', ord', erls, _, subst, _, f, (res, asm))) => |
378 Chead.Appl (Tac.Rewrite_Inst' (thy', ord', erls, _, subst, _, f, (res, asm))) => |
378 let |
379 let |
379 val thm_deriv = Thm.get_name_hint thm |
380 val thm_deriv = Thm.get_name_hint thm |
380 val thminst = TermC.inst_bdv subst ((Calc.norm o #prop o Thm.rep_thm) thm) |
381 val thminst = TermC.inst_bdv subst ((Calc.norm o #prop o Thm.rep_thm) thm) |
381 in |
382 in |
382 ContThmInst |
383 ContThmInst |
383 {thyID = theory'2thyID thy', |
384 {thyID = Celem.theory'2thyID thy', |
384 thm = |
385 thm = |
385 thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
386 Celem.thm2guh (thy_containing_thm thm_deriv) (Celem.thmID_of_derivation_name thm_deriv), |
386 bdvs = subst, thminst = thminst, applto = f, applat = e_term, reword = ord', |
387 bdvs = subst, thminst = thminst, applto = f, applat = Celem.e_term, reword = ord', |
387 asms = [](*asms ~~ asms'*), lhs = (e_term, e_term)(*(lhs, lhs')*), rhs = (e_term, e_term)(*(rhs, rhs')*), |
388 asms = [](*asms ~~ asms'*), lhs = (Celem.e_term, Celem.e_term)(*(lhs, lhs')*), rhs = (Celem.e_term, Celem.e_term)(*(rhs, rhs')*), |
388 result = res, resasms = asm, asmrls = id_rls erls} |
389 result = res, resasms = asm, asmrls = Celem.id_rls erls} |
389 end |
390 end |
390 | Chead.Notappl _ => |
391 | Chead.Notappl _ => |
391 let |
392 let |
392 val thm = Global_Theory.get_thm (Isac ()(*WN141021 assoc_thy thy' ERROR*)) thmID |
393 val thm = Global_Theory.get_thm (Celem.Isac ()(*WN141021 assoc_thy thy' ERROR*)) thmID |
393 val thm_deriv = Thm.get_name_hint thm |
394 val thm_deriv = Thm.get_name_hint thm |
394 val pp = Ctree.par_pblobj pt p |
395 val pp = Ctree.par_pblobj pt p |
395 val thy' = Ctree.get_obj Ctree.g_domID pt pp |
396 val thy' = Ctree.get_obj Ctree.g_domID pt pp |
396 val subst = Selem.subs2subst (assoc_thy thy') subs |
397 val subst = Selem.subs2subst (Celem.assoc_thy thy') subs |
397 val thminst = TermC.inst_bdv subst ((Calc.norm o #prop o Thm.rep_thm) thm) |
398 val thminst = TermC.inst_bdv subst ((Calc.norm o #prop o Thm.rep_thm) thm) |
398 val f = case p_ of |
399 val f = case p_ of |
399 Ctree.Frm => Ctree.get_obj Ctree.g_form pt p |
400 Ctree.Frm => Ctree.get_obj Ctree.g_form pt p |
400 | Ctree.Res => (fst o (Ctree.get_obj Ctree.g_result pt)) p |
401 | Ctree.Res => (fst o (Ctree.get_obj Ctree.g_result pt)) p |
401 | _ => error "context_thy: uncovered case 3" |
402 | _ => error "context_thy: uncovered case 3" |
402 in |
403 in |
403 ContNOrewInst |
404 ContNOrewInst |
404 {thyID = theory'2thyID thy', |
405 {thyID = Celem.theory'2thyID thy', |
405 thm_rls = thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
406 thm_rls = Celem.thm2guh (thy_containing_thm thm_deriv) (Celem.thmID_of_derivation_name thm_deriv), |
406 bdvs = subst, thminst = thminst, applto = f} |
407 bdvs = subst, thminst = thminst, applto = f} |
407 end |
408 end |
408 | _ => error "context_thy..Rewrite_Inst: uncovered case 4") |
409 | _ => error "context_thy..Rewrite_Inst: uncovered case 4") |
409 end |
410 end |
410 | context_thy (pt, p) (tac as Tac.Rewrite_Set rls') = |
411 | context_thy (pt, p) (tac as Tac.Rewrite_Set rls') = |
411 (case Applicable.applicable_in p pt tac of |
412 (case Applicable.applicable_in p pt tac of |
412 Chead.Appl (Tac.Rewrite_Set' (thy', _, _(*rls*), f, (res,asm))) => |
413 Chead.Appl (Tac.Rewrite_Set' (thy', _, _(*rls*), f, (res,asm))) => |
413 ContRls |
414 ContRls |
414 {thyID = theory'2thyID thy', |
415 {thyID = Celem.theory'2thyID thy', |
415 rls = rls2guh (thy_containing_rls thy' rls') rls', |
416 rls = Celem.rls2guh (thy_containing_rls thy' rls') rls', |
416 applto = f, result = res, asms = asm} |
417 applto = f, result = res, asms = asm} |
417 | _ => error ("context_thy Rewrite_Set: not for Chead.Notappl")) |
418 | _ => error ("context_thy Rewrite_Set: not for Chead.Notappl")) |
418 | context_thy (pt,p) (tac as Tac.Rewrite_Set_Inst (_(*subs*), rls')) = |
419 | context_thy (pt,p) (tac as Tac.Rewrite_Set_Inst (_(*subs*), rls')) = |
419 (case Applicable.applicable_in p pt tac of |
420 (case Applicable.applicable_in p pt tac of |
420 Chead.Appl (Tac.Rewrite_Set_Inst' (thy', _, subst, _, f, (res,asm))) => |
421 Chead.Appl (Tac.Rewrite_Set_Inst' (thy', _, subst, _, f, (res,asm))) => |
421 ContRlsInst |
422 ContRlsInst |
422 {thyID = theory'2thyID thy', |
423 {thyID = Celem.theory'2thyID thy', |
423 rls = rls2guh (thy_containing_rls thy' rls') rls', |
424 rls = Celem.rls2guh (thy_containing_rls thy' rls') rls', |
424 bdvs = subst, applto = f, result = res, asms = asm} |
425 bdvs = subst, applto = f, result = res, asms = asm} |
425 | _ => error ("context_thy Rewrite_Set_Inst: not for Chead.Notappl")) |
426 | _ => error ("context_thy Rewrite_Set_Inst: not for Chead.Notappl")) |
426 | context_thy (_, p) tac = |
427 | context_thy (_, p) tac = |
427 error ("context_thy: not for tac " ^ Tac.tac2str tac ^ " at " ^ Ctree.pos'2str p) |
428 error ("context_thy: not for tac " ^ Tac.tac2str tac ^ " at " ^ Ctree.pos'2str p) |
428 |
429 |
429 (* get all theorems in a rule set (recursivley containing rule sets) *) |
430 (* get all theorems in a rule set (recursivley containing rule sets) *) |
430 fun thm_of_rule Erule = [] |
431 fun thm_of_rule Erule = [] |
431 | thm_of_rule (thm as Thm _) = [thm] |
432 | thm_of_rule (thm as Celem.Thm _) = [thm] |
432 | thm_of_rule (Calc _) = [] |
433 | thm_of_rule (Celem.Calc _) = [] |
433 | thm_of_rule (Cal1 _) = [] |
434 | thm_of_rule (Celem.Cal1 _) = [] |
434 | thm_of_rule (Rls_ rls) = thms_of_rls rls |
435 | thm_of_rule (Celem.Rls_ rls) = thms_of_rls rls |
435 and thms_of_rls Erls = [] |
436 and thms_of_rls Celem.Erls = [] |
436 | thms_of_rls (Rls {rules,...}) = (flat o (map thm_of_rule)) rules |
437 | thms_of_rls (Celem.Rls {rules,...}) = (flat o (map thm_of_rule)) rules |
437 | thms_of_rls (Seq {rules,...}) = (flat o (map thm_of_rule)) rules |
438 | thms_of_rls (Celem.Seq {rules,...}) = (flat o (map thm_of_rule)) rules |
438 | thms_of_rls (Rrls _) = [] |
439 | thms_of_rls (Celem.Rrls _) = [] |
439 |
440 |
440 (* check if a rule is contained in a rule-set (recursivley down in Rls_); |
441 (* check if a rule is contained in a rule-set (recursivley down in Rls_); |
441 this rule can even be a rule-set itself *) |
442 this rule can even be a rule-set itself *) |
442 fun contains_rule r rls = |
443 fun contains_rule r rls = |
443 let |
444 let |
444 fun (*find (_, Rls_ rls) = finds (get_rules rls) |
445 fun (*find (_, Rls_ rls) = finds (get_rules rls) |
445 | find r12 = eq_rule r12 |
446 | find r12 = eq_rule r12 |
446 and*) finds [] = false |
447 and*) finds [] = false |
447 | finds (r1 :: rs) = if eq_rule (r, r1) then true else finds rs |
448 | finds (r1 :: rs) = if Celem.eq_rule (r, r1) then true else finds rs |
448 in |
449 in |
449 finds (get_rules rls) |
450 finds (Celem.get_rules rls) |
450 end |
451 end |
451 |
452 |
452 (* try if a rewrite-rule is applicable to a given formula; |
453 (* try if a rewrite-rule is applicable to a given formula; |
453 in case of rule-sets (recursivley) collect all _atomic_ rewrites *) |
454 in case of rule-sets (recursivley) collect all _atomic_ rewrites *) |
454 fun try_rew thy ((_, ro) : rew_ord) erls (subst : subst) f (thm' as Thm (_, thm)) = |
455 fun try_rew thy ((_, ro) : Celem.rew_ord) erls (subst : Celem.subst) f (thm' as Celem.Thm (_, thm)) = |
455 if LTool.contains_bdv thm |
456 if LTool.contains_bdv thm |
456 then case Rewrite.rewrite_inst_ thy ro erls false subst thm f of |
457 then case Rewrite.rewrite_inst_ thy ro erls false subst thm f of |
457 SOME _ => [Tac.rule2tac thy subst thm'] |
458 SOME _ => [Tac.rule2tac thy subst thm'] |
458 | NONE => [] |
459 | NONE => [] |
459 else (case Rewrite.rewrite_ thy ro erls false thm f of |
460 else (case Rewrite.rewrite_ thy ro erls false thm f of |
460 SOME _ => [Tac.rule2tac thy [] thm'] |
461 SOME _ => [Tac.rule2tac thy [] thm'] |
461 | NONE => []) |
462 | NONE => []) |
462 | try_rew thy _ _ _ f (cal as Calc c) = |
463 | try_rew thy _ _ _ f (cal as Celem.Calc c) = |
463 (case Calc.adhoc_thm thy c f of |
464 (case Calc.adhoc_thm thy c f of |
464 SOME _ => [Tac.rule2tac thy [] cal] |
465 SOME _ => [Tac.rule2tac thy [] cal] |
465 | NONE => []) |
466 | NONE => []) |
466 | try_rew thy _ _ _ f (cal as Cal1 c) = |
467 | try_rew thy _ _ _ f (cal as Celem.Cal1 c) = |
467 (case Calc.adhoc_thm thy c f of |
468 (case Calc.adhoc_thm thy c f of |
468 SOME _ => [Tac.rule2tac thy [] cal] |
469 SOME _ => [Tac.rule2tac thy [] cal] |
469 | NONE => []) |
470 | NONE => []) |
470 | try_rew thy _ _ subst f (Rls_ rls) = filter_appl_rews thy subst f rls |
471 | try_rew thy _ _ subst f (Celem.Rls_ rls) = filter_appl_rews thy subst f rls |
471 | try_rew _ _ _ _ _ _ = error "try_rew: uncovered case" |
472 | try_rew _ _ _ _ _ _ = error "try_rew: uncovered case" |
472 and filter_appl_rews thy subst f (Rls {rew_ord = ro, erls, rules, ...}) = |
473 and filter_appl_rews thy subst f (Celem.Rls {rew_ord = ro, erls, rules, ...}) = |
473 gen_distinct Tac.eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
474 gen_distinct Tac.eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
474 | filter_appl_rews thy subst f (Seq {rew_ord = ro, erls, rules,...}) = |
475 | filter_appl_rews thy subst f (Celem.Seq {rew_ord = ro, erls, rules,...}) = |
475 gen_distinct Tac.eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
476 gen_distinct Tac.eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
476 | filter_appl_rews _ _ _ (Rrls _) = [] |
477 | filter_appl_rews _ _ _ (Celem.Rrls _) = [] |
477 | filter_appl_rews _ _ _ _ = error "filter_appl_rews: uncovered case" |
478 | filter_appl_rews _ _ _ _ = error "filter_appl_rews: uncovered case" |
478 |
479 |
479 (* decide if a tactic is applicable to a given formula; |
480 (* decide if a tactic is applicable to a given formula; |
480 in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *) |
481 in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *) |
481 fun atomic_appl_tacs thy _ _ f (Tac.Calculate scrID) = |
482 fun atomic_appl_tacs thy _ _ f (Tac.Calculate scrID) = |
482 try_rew thy e_rew_ordX e_rls [] f (Calc (assoc_calc' thy scrID |> snd)) |
483 try_rew thy Celem.e_rew_ordX Celem.e_rls [] f (Celem.Calc (assoc_calc' thy scrID |> snd)) |
483 | atomic_appl_tacs thy ro erls f (Tac.Rewrite thm'') = |
484 | atomic_appl_tacs thy ro erls f (Tac.Rewrite thm'') = |
484 try_rew thy (ro, assoc_rew_ord ro) erls [] f (Thm thm'') |
485 try_rew thy (ro, Celem.assoc_rew_ord ro) erls [] f (Celem.Thm thm'') |
485 | atomic_appl_tacs thy ro erls f (Tac.Rewrite_Inst (subs, thm'')) = |
486 | atomic_appl_tacs thy ro erls f (Tac.Rewrite_Inst (subs, thm'')) = |
486 try_rew thy (ro, assoc_rew_ord ro) erls (Selem.subs2subst thy subs) f (Thm thm'') |
487 try_rew thy (ro, Celem.assoc_rew_ord ro) erls (Selem.subs2subst thy subs) f (Celem.Thm thm'') |
487 |
488 |
488 | atomic_appl_tacs thy _ _ f (Tac.Rewrite_Set rls') = |
489 | atomic_appl_tacs thy _ _ f (Tac.Rewrite_Set rls') = |
489 filter_appl_rews thy [] f (assoc_rls rls') |
490 filter_appl_rews thy [] f (assoc_rls rls') |
490 | atomic_appl_tacs thy _ _ f (Tac.Rewrite_Set_Inst (subs, rls')) = |
491 | atomic_appl_tacs thy _ _ f (Tac.Rewrite_Set_Inst (subs, rls')) = |
491 filter_appl_rews thy (Selem.subs2subst thy subs) f (assoc_rls rls') |
492 filter_appl_rews thy (Selem.subs2subst thy subs) f (assoc_rls rls') |
492 | atomic_appl_tacs _ _ _ _ tac = |
493 | atomic_appl_tacs _ _ _ _ tac = |
493 (tracing ("### atomic_appl_tacs: not impl. for tac = '" ^ Tac.tac2str tac ^ "'"); []); |
494 (tracing ("### atomic_appl_tacs: not impl. for tac = '" ^ Tac.tac2str tac ^ "'"); []); |
494 |
495 |
495 (* filenames not only for thydata, but also for thy's etc *) |
496 (* filenames not only for thydata, but also for thy's etc *) |
496 fun theID2filename (theID : theID) = theID2guh theID ^ ".xml" : filename |
497 fun theID2filename theID = Celem.theID2guh theID ^ ".xml" |
497 |
498 |
498 fun guh2theID (guh : guh) = |
499 fun guh2theID guh = |
499 let |
500 let |
500 val guh' = Symbol.explode guh |
501 val guh' = Symbol.explode guh |
501 val part = implode (take_fromto 1 4 guh') |
502 val part = implode (take_fromto 1 4 guh') |
502 val isa = implode (take_fromto 5 9 guh') |
503 val isa = implode (take_fromto 5 9 guh') |
503 in |
504 in |