5 |
5 |
6 signature REWRITE_TOOLS = |
6 signature REWRITE_TOOLS = |
7 sig |
7 sig |
8 type deriv |
8 type deriv |
9 val contains_rule : rule -> rls -> bool |
9 val contains_rule : rule -> rls -> bool |
10 val atomic_appl_tacs : theory -> string -> rls -> term -> tac -> tac list |
10 val atomic_appl_tacs : theory -> string -> rls -> term -> Ctree.tac -> Ctree.tac list |
11 val thy_containing_rls : theory' -> rls' -> string * theory' |
11 val thy_containing_rls : theory' -> rls' -> string * theory' |
12 val thy_containing_cal : theory' -> prog_calcID -> string * string |
12 val thy_containing_cal : theory' -> prog_calcID -> string * string |
13 datatype contthy |
13 datatype contthy |
14 = ContNOrew of {applto: term, thm_rls: guh, thyID: thyID} |
14 = ContNOrew of {applto: term, thm_rls: guh, thyID: thyID} |
15 | ContNOrewInst of {applto: term, bdvs: subst, thm_rls: guh, thminst: term, thyID: thyID} |
15 | ContNOrewInst of {applto: term, bdvs: subst, thm_rls: guh, thminst: term, thyID: thyID} |
27 val sym_drop : thmID -> thmID val sym_rls : rls -> rls |
27 val sym_drop : thmID -> thmID val sym_rls : rls -> rls |
28 val sym_rule : rule -> rule |
28 val sym_rule : rule -> rule |
29 val thms_of_rls : rls -> rule list |
29 val thms_of_rls : rls -> rule list |
30 val theID2filename : theID -> filename |
30 val theID2filename : theID -> filename |
31 val no_thycontext : guh -> bool |
31 val no_thycontext : guh -> bool |
32 val subs_from : istate -> 'a -> guh -> subs |
32 val subs_from : Ctree.istate -> 'a -> guh -> Ctree.subs |
33 val guh2rewtac : guh -> subs -> tac |
33 val guh2rewtac : guh -> Ctree.subs -> Ctree.tac |
34 val get_tac_checked : ptree -> pos' -> tac |
34 val get_tac_checked : Ctree.ptree -> Ctree.pos' -> Ctree.tac |
35 val context_thy : ptree * (pos * pos_) -> tac -> contthy |
35 val context_thy : Ctree.ptree * Ctree.pos' -> Ctree.tac -> contthy |
36 val distinct_Thm : rule list -> rule list |
36 val distinct_Thm : rule list -> rule list |
37 val eq_Thms : string list -> rule -> bool |
37 val eq_Thms : string list -> rule -> bool |
38 val make_deriv : theory -> rls -> rule list -> ((term * term) list -> term * term -> bool) -> |
38 val make_deriv : theory -> rls -> rule list -> ((term * term) list -> term * term -> bool) -> |
39 term option -> term -> deriv |
39 term option -> term -> deriv |
40 val reverse_deriv : theory -> rls -> rule list -> ((term * term) list -> term * term -> bool) -> |
40 val reverse_deriv : theory -> rls -> rule list -> ((term * term) list -> term * term -> bool) -> |
41 term option -> term -> (rule * (term * term list)) list |
41 term option -> term -> (rule * (term * term list)) list |
42 val get_bdv_subst : term -> (term * term) list -> subs option * subst |
42 val get_bdv_subst : term -> (term * term) list -> Ctree.subs option * subst |
43 val thy_containing_thm : string -> string * string val thypart2filename : theID -> filename |
43 val thy_containing_thm : string -> string * string val thypart2filename : theID -> filename |
44 val guh2theID : guh -> theID |
44 val guh2theID : guh -> theID |
45 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* ) |
45 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* ) |
46 val trtas2str : (term * rule * (term * term list)) list -> string |
46 val trtas2str : (term * rule * (term * term list)) list -> string |
47 val eq_Thm : rule * rule -> bool |
47 val eq_Thm : rule * rule -> bool |
351 applto : term (*rewrite this formula .*) |
351 applto : term (*rewrite this formula .*) |
352 } |
352 } |
353 |
353 |
354 (*.check a rewrite-tac for bdv (RL always used *_Inst !) TODO.WN060718 |
354 (*.check a rewrite-tac for bdv (RL always used *_Inst !) TODO.WN060718 |
355 pass other tacs unchanged.*) |
355 pass other tacs unchanged.*) |
356 fun get_tac_checked pt ((p, _) : pos') = get_obj g_tac pt p; |
356 fun get_tac_checked pt ((p, _) : Ctree.pos') = Ctree.get_obj Ctree.g_tac pt p; |
357 |
357 |
358 (* create a derivation-name, eg. ("refl", _) --> "HOL.refl"*) |
358 (* create a derivation-name, eg. ("refl", _) --> "HOL.refl"*) |
359 fun deriv_of_thm'' ((thmID, _) : thm'') = |
359 fun deriv_of_thm'' ((thmID, _) : thm'') = |
360 thmID |> Global_Theory.get_thm (Isac ()) |> Thm.get_name_hint |
360 thmID |> Global_Theory.get_thm (Isac ()) |> Thm.get_name_hint |
361 |
361 |
362 (* get the formula f at ptp rewritten by the Rewrite_* already applied to f *) |
362 (* get the formula f at ptp rewritten by the Rewrite_* already applied to f *) |
363 fun context_thy (pt, pos as (p,p_)) (tac as Rewrite thm'') = |
363 fun context_thy (pt, pos as (p,p_)) (tac as Ctree.Rewrite thm'') = |
364 let val thm_deriv = deriv_of_thm'' thm'' |
364 let val thm_deriv = deriv_of_thm'' thm'' |
365 in |
365 in |
366 (case Applicable.applicable_in pos pt tac of |
366 (case Applicable.applicable_in pos pt tac of |
367 Chead.Appl (Rewrite' (thy', ord', erls, _, _, f, (res,asm))) => |
367 Chead.Appl (Ctree.Rewrite' (thy', ord', erls, _, _, f, (res,asm))) => |
368 ContThm |
368 ContThm |
369 {thyID = theory'2thyID thy', |
369 {thyID = theory'2thyID thy', |
370 thm = thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
370 thm = thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
371 applto = f, applat = e_term, reword = ord', |
371 applto = f, applat = e_term, reword = ord', |
372 asms = [](*asms ~~ asms'*), lhs = (e_term, e_term)(*(lhs, lhs')*), rhs = (e_term, e_term)(*(rhs, rhs')*), |
372 asms = [](*asms ~~ asms'*), lhs = (e_term, e_term)(*(lhs, lhs')*), rhs = (e_term, e_term)(*(rhs, rhs')*), |
373 result = res, resasms = asm, asmrls = id_rls erls} |
373 result = res, resasms = asm, asmrls = id_rls erls} |
374 | Chead.Notappl _ => |
374 | Chead.Notappl _ => |
375 let |
375 let |
376 val pp = par_pblobj pt p |
376 val pp = Ctree.par_pblobj pt p |
377 val thy' = get_obj g_domID pt pp |
377 val thy' = Ctree.get_obj Ctree.g_domID pt pp |
378 val f = case p_ of |
378 val f = case p_ of |
379 Frm => get_obj g_form pt p |
379 Frm => Ctree.get_obj Ctree.g_form pt p |
380 | Res => (fst o (get_obj g_result pt)) p | _ => error "context_thy: uncovered position" |
380 | Res => (fst o (Ctree.get_obj Ctree.g_result pt)) p | _ => error "context_thy: uncovered position" |
381 in |
381 in |
382 ContNOrew |
382 ContNOrew |
383 {thyID = theory'2thyID thy', |
383 {thyID = theory'2thyID thy', |
384 thm_rls = |
384 thm_rls = |
385 thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
385 thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
386 applto = f} |
386 applto = f} |
387 end |
387 end |
388 | _ => error "context_thy..Rewrite: uncovered case 2") |
388 | _ => error "context_thy..Rewrite: uncovered case 2") |
389 end |
389 end |
390 | context_thy (pt, pos as (p, p_)) (tac as Rewrite_Inst (subs, (thmID, _))) = |
390 | context_thy (pt, pos as (p, p_)) (tac as Ctree.Rewrite_Inst (subs, (thmID, _))) = |
391 let val thm = Global_Theory.get_thm (Isac ()) thmID |
391 let val thm = Global_Theory.get_thm (Isac ()) thmID |
392 in |
392 in |
393 (case Applicable.applicable_in pos pt tac of |
393 (case Applicable.applicable_in pos pt tac of |
394 Chead.Appl (Rewrite_Inst' (thy', ord', erls, _, subst, _, f, (res, asm))) => |
394 Chead.Appl (Ctree.Rewrite_Inst' (thy', ord', erls, _, subst, _, f, (res, asm))) => |
395 let |
395 let |
396 val thm_deriv = Thm.get_name_hint thm |
396 val thm_deriv = Thm.get_name_hint thm |
397 val thminst = inst_bdv subst ((norm o #prop o Thm.rep_thm) thm) |
397 val thminst = inst_bdv subst ((norm o #prop o Thm.rep_thm) thm) |
398 in |
398 in |
399 ContThmInst |
399 ContThmInst |
406 end |
406 end |
407 | Chead.Notappl _ => |
407 | Chead.Notappl _ => |
408 let |
408 let |
409 val thm = Global_Theory.get_thm (Isac ()(*WN141021 assoc_thy thy' ERROR*)) thmID |
409 val thm = Global_Theory.get_thm (Isac ()(*WN141021 assoc_thy thy' ERROR*)) thmID |
410 val thm_deriv = Thm.get_name_hint thm |
410 val thm_deriv = Thm.get_name_hint thm |
411 val pp = par_pblobj pt p |
411 val pp = Ctree.par_pblobj pt p |
412 val thy' = get_obj g_domID pt pp |
412 val thy' = Ctree.get_obj Ctree.g_domID pt pp |
413 val subst = subs2subst (assoc_thy thy') subs |
413 val subst = Ctree.subs2subst (assoc_thy thy') subs |
414 val thminst = inst_bdv subst ((norm o #prop o Thm.rep_thm) thm) |
414 val thminst = inst_bdv subst ((norm o #prop o Thm.rep_thm) thm) |
415 val f = case p_ of |
415 val f = case p_ of |
416 Frm => get_obj g_form pt p |
416 Frm => Ctree.get_obj Ctree.g_form pt p |
417 | Res => (fst o (get_obj g_result pt)) p | _ => error "context_thy: uncovered case 3" |
417 | Res => (fst o (Ctree.get_obj Ctree.g_result pt)) p | _ => error "context_thy: uncovered case 3" |
418 in |
418 in |
419 ContNOrewInst |
419 ContNOrewInst |
420 {thyID = theory'2thyID thy', |
420 {thyID = theory'2thyID thy', |
421 thm_rls = thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
421 thm_rls = thm2guh (thy_containing_thm thm_deriv) (thmID_of_derivation_name thm_deriv), |
422 bdvs = subst, thminst = thminst, applto = f} |
422 bdvs = subst, thminst = thminst, applto = f} |
423 end |
423 end |
424 | _ => error "context_thy..Rewrite_Inst: uncovered case 4") |
424 | _ => error "context_thy..Rewrite_Inst: uncovered case 4") |
425 end |
425 end |
426 | context_thy (pt, p) (tac as Rewrite_Set rls') = |
426 | context_thy (pt, p) (tac as Ctree.Rewrite_Set rls') = |
427 (case Applicable.applicable_in p pt tac of |
427 (case Applicable.applicable_in p pt tac of |
428 Chead.Appl (Rewrite_Set' (thy', _, _(*rls*), f, (res,asm))) => |
428 Chead.Appl (Ctree.Rewrite_Set' (thy', _, _(*rls*), f, (res,asm))) => |
429 ContRls |
429 ContRls |
430 {thyID = theory'2thyID thy', |
430 {thyID = theory'2thyID thy', |
431 rls = rls2guh (thy_containing_rls thy' rls') rls', |
431 rls = rls2guh (thy_containing_rls thy' rls') rls', |
432 applto = f, result = res, asms = asm} |
432 applto = f, result = res, asms = asm} |
433 | _ => error ("context_thy Rewrite_Set: not for Chead.Notappl")) |
433 | _ => error ("context_thy Rewrite_Set: not for Chead.Notappl")) |
434 | context_thy (pt,p) (tac as Rewrite_Set_Inst (_(*subs*), rls')) = |
434 | context_thy (pt,p) (tac as Ctree.Rewrite_Set_Inst (_(*subs*), rls')) = |
435 (case Applicable.applicable_in p pt tac of |
435 (case Applicable.applicable_in p pt tac of |
436 Chead.Appl (Rewrite_Set_Inst' (thy', _, subst, _, f, (res,asm))) => |
436 Chead.Appl (Ctree.Rewrite_Set_Inst' (thy', _, subst, _, f, (res,asm))) => |
437 ContRlsInst |
437 ContRlsInst |
438 {thyID = theory'2thyID thy', |
438 {thyID = theory'2thyID thy', |
439 rls = rls2guh (thy_containing_rls thy' rls') rls', |
439 rls = rls2guh (thy_containing_rls thy' rls') rls', |
440 bdvs = subst, applto = f, result = res, asms = asm} |
440 bdvs = subst, applto = f, result = res, asms = asm} |
441 | _ => error ("context_thy Rewrite_Set_Inst: not for Chead.Notappl")) |
441 | _ => error ("context_thy Rewrite_Set_Inst: not for Chead.Notappl")) |
442 | context_thy (_, p) tac = |
442 | context_thy (_, p) tac = |
443 error ("context_thy: not for tac " ^ tac2str tac ^ " at " ^ pos'2str p) |
443 error ("context_thy: not for tac " ^ Ctree.tac2str tac ^ " at " ^ Ctree.pos'2str p) |
444 |
444 |
445 (* get all theorems in a rule set (recursivley containing rule sets) *) |
445 (* get all theorems in a rule set (recursivley containing rule sets) *) |
446 fun thm_of_rule Erule = [] |
446 fun thm_of_rule Erule = [] |
447 | thm_of_rule (thm as Thm _) = [thm] |
447 | thm_of_rule (thm as Thm _) = [thm] |
448 | thm_of_rule (Calc _) = [] |
448 | thm_of_rule (Calc _) = [] |
468 (* try if a rewrite-rule is applicable to a given formula; |
468 (* try if a rewrite-rule is applicable to a given formula; |
469 in case of rule-sets (recursivley) collect all _atomic_ rewrites *) |
469 in case of rule-sets (recursivley) collect all _atomic_ rewrites *) |
470 fun try_rew thy ((_, ro) : rew_ord) erls (subst : subst) f (thm' as Thm (_, thm)) = |
470 fun try_rew thy ((_, ro) : rew_ord) erls (subst : subst) f (thm' as Thm (_, thm)) = |
471 if contains_bdv thm |
471 if contains_bdv thm |
472 then case rewrite_inst_ thy ro erls false subst thm f of |
472 then case rewrite_inst_ thy ro erls false subst thm f of |
473 SOME _ => [rule2tac thy subst thm'] |
473 SOME _ => [Ctree.rule2tac thy subst thm'] |
474 | NONE => [] |
474 | NONE => [] |
475 else (case rewrite_ thy ro erls false thm f of |
475 else (case rewrite_ thy ro erls false thm f of |
476 SOME _ => [rule2tac thy [] thm'] |
476 SOME _ => [Ctree.rule2tac thy [] thm'] |
477 | NONE => []) |
477 | NONE => []) |
478 | try_rew thy _ _ _ f (cal as Calc c) = |
478 | try_rew thy _ _ _ f (cal as Calc c) = |
479 (case adhoc_thm thy c f of |
479 (case adhoc_thm thy c f of |
480 SOME _ => [rule2tac thy [] cal] |
480 SOME _ => [Ctree.rule2tac thy [] cal] |
481 | NONE => []) |
481 | NONE => []) |
482 | try_rew thy _ _ _ f (cal as Cal1 c) = |
482 | try_rew thy _ _ _ f (cal as Cal1 c) = |
483 (case adhoc_thm thy c f of |
483 (case adhoc_thm thy c f of |
484 SOME _ => [rule2tac thy [] cal] |
484 SOME _ => [Ctree.rule2tac thy [] cal] |
485 | NONE => []) |
485 | NONE => []) |
486 | try_rew thy _ _ subst f (Rls_ rls) = filter_appl_rews thy subst f rls |
486 | try_rew thy _ _ subst f (Rls_ rls) = filter_appl_rews thy subst f rls |
487 | try_rew _ _ _ _ _ _ = error "try_rew: uncovered case" |
487 | try_rew _ _ _ _ _ _ = error "try_rew: uncovered case" |
488 and filter_appl_rews thy subst f (Rls {rew_ord = ro, erls, rules, ...}) = |
488 and filter_appl_rews thy subst f (Rls {rew_ord = ro, erls, rules, ...}) = |
489 gen_distinct eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
489 gen_distinct Ctree.eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
490 | filter_appl_rews thy subst f (Seq {rew_ord = ro, erls, rules,...}) = |
490 | filter_appl_rews thy subst f (Seq {rew_ord = ro, erls, rules,...}) = |
491 gen_distinct eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
491 gen_distinct Ctree.eq_tac (flat (map (try_rew thy ro erls subst f) rules)) |
492 | filter_appl_rews _ _ _ (Rrls _) = [] |
492 | filter_appl_rews _ _ _ (Rrls _) = [] |
493 | filter_appl_rews _ _ _ _ = error "filter_appl_rews: uncovered case" |
493 | filter_appl_rews _ _ _ _ = error "filter_appl_rews: uncovered case" |
494 |
494 |
495 (* decide if a tactic is applicable to a given formula; |
495 (* decide if a tactic is applicable to a given formula; |
496 in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *) |
496 in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *) |
497 fun atomic_appl_tacs thy _ _ f (Calculate scrID) = |
497 fun atomic_appl_tacs thy _ _ f (Ctree.Calculate scrID) = |
498 try_rew thy e_rew_ordX e_rls [] f (Calc (assoc_calc' thy scrID |> snd)) |
498 try_rew thy e_rew_ordX e_rls [] f (Calc (assoc_calc' thy scrID |> snd)) |
499 | atomic_appl_tacs thy ro erls f (Rewrite thm'') = |
499 | atomic_appl_tacs thy ro erls f (Ctree.Rewrite thm'') = |
500 try_rew thy (ro, assoc_rew_ord ro) erls [] f (Thm thm'') |
500 try_rew thy (ro, assoc_rew_ord ro) erls [] f (Thm thm'') |
501 | atomic_appl_tacs thy ro erls f (Rewrite_Inst (subs, thm'')) = |
501 | atomic_appl_tacs thy ro erls f (Ctree.Rewrite_Inst (subs, thm'')) = |
502 try_rew thy (ro, assoc_rew_ord ro) erls (subs2subst thy subs) f (Thm thm'') |
502 try_rew thy (ro, assoc_rew_ord ro) erls (Ctree.subs2subst thy subs) f (Thm thm'') |
503 |
503 |
504 | atomic_appl_tacs thy _ _ f (Rewrite_Set rls') = |
504 | atomic_appl_tacs thy _ _ f (Ctree.Rewrite_Set rls') = |
505 filter_appl_rews thy [] f (assoc_rls rls') |
505 filter_appl_rews thy [] f (assoc_rls rls') |
506 | atomic_appl_tacs thy _ _ f (Rewrite_Set_Inst (subs, rls')) = |
506 | atomic_appl_tacs thy _ _ f (Ctree.Rewrite_Set_Inst (subs, rls')) = |
507 filter_appl_rews thy (subs2subst thy subs) f (assoc_rls rls') |
507 filter_appl_rews thy (Ctree.subs2subst thy subs) f (assoc_rls rls') |
508 | atomic_appl_tacs _ _ _ _ tac = |
508 | atomic_appl_tacs _ _ _ _ tac = |
509 (tracing ("### atomic_appl_tacs: not impl. for tac = '" ^ tac2str tac ^ "'"); []); |
509 (tracing ("### atomic_appl_tacs: not impl. for tac = '" ^ Ctree.tac2str tac ^ "'"); []); |
510 |
510 |
511 (* filenames not only for thydata, but also for thy's etc *) |
511 (* filenames not only for thydata, but also for thy's etc *) |
512 fun theID2filename (theID : theID) = theID2guh theID ^ ".xml" : filename |
512 fun theID2filename (theID : theID) = theID2guh theID ^ ".xml" : filename |
513 |
513 |
514 fun guh2theID (guh : guh) = |
514 fun guh2theID (guh : guh) = |
552 end |
552 end |
553 end |
553 end |
554 |
554 |
555 fun guh2filename (guh : guh) = guh ^ ".xml" : filename; |
555 fun guh2filename (guh : guh) = guh ^ ".xml" : filename; |
556 |
556 |
557 fun guh2rewtac (guh : guh) ([] : subs) = |
557 fun guh2rewtac (guh : guh) ([] : Ctree.subs) = |
558 let |
558 let |
559 val (_, thy, sect, xstr) = case guh2theID guh of |
559 val (_, thy, sect, xstr) = case guh2theID guh of |
560 [isa, thy, sect, xstr] => (isa, thy, sect, xstr) |
560 [isa, thy, sect, xstr] => (isa, thy, sect, xstr) |
561 | _ => error "guh2rewtac: uncovered case" |
561 | _ => error "guh2rewtac: uncovered case" |
562 in case sect of |
562 in case sect of |
563 "Theorems" => Rewrite (xstr, assoc_thm'' (assoc_thy thy) xstr) |
563 "Theorems" => Ctree.Rewrite (xstr, assoc_thm'' (assoc_thy thy) xstr) |
564 | "Rulesets" => Rewrite_Set xstr |
564 | "Rulesets" => Ctree.Rewrite_Set xstr |
565 | _ => error ("guh2rewtac: not impl. for '"^xstr^"'") |
565 | _ => error ("guh2rewtac: not impl. for '"^xstr^"'") |
566 end |
566 end |
567 | guh2rewtac guh subs = |
567 | guh2rewtac guh subs = |
568 let |
568 let |
569 val (_, thy, sect, xstr) = case guh2theID guh of |
569 val (_, thy, sect, xstr) = case guh2theID guh of |
570 [isa, thy, sect, xstr] => (isa, thy, sect, xstr) |
570 [isa, thy, sect, xstr] => (isa, thy, sect, xstr) |
571 | _ => error "guh2rewtac: uncovered case" |
571 | _ => error "guh2rewtac: uncovered case" |
572 in case sect of |
572 in case sect of |
573 "Theorems" => |
573 "Theorems" => |
574 Rewrite_Inst (subs, (xstr, assoc_thm'' (assoc_thy thy) xstr)) |
574 Ctree.Rewrite_Inst (subs, (xstr, assoc_thm'' (assoc_thy thy) xstr)) |
575 | "Rulesets" => Rewrite_Set_Inst (subs, xstr) |
575 | "Rulesets" => Ctree.Rewrite_Set_Inst (subs, xstr) |
576 | str => error ("guh2rewtac: not impl. for '" ^ str ^ "'") |
576 | str => error ("guh2rewtac: not impl. for '" ^ str ^ "'") |
577 end |
577 end |
578 |
578 |
579 (* the front-end may request a context for any element of the hierarchy *) |
579 (* the front-end may request a context for any element of the hierarchy *) |
580 fun no_thycontext (guh : guh) = (guh2theID guh; false) |
580 fun no_thycontext (guh : guh) = (guh2theID guh; false) |
585 # take the [(bdv, v_),..] from the respective Rewrite_(Set_)Inst |
585 # take the [(bdv, v_),..] from the respective Rewrite_(Set_)Inst |
586 # instantiate this subs with the istates env to [(bdv, x),..] |
586 # instantiate this subs with the istates env to [(bdv, x),..] |
587 # otherwise [] |
587 # otherwise [] |
588 WN060617 hack assuming that all scripts use only one bound variable |
588 WN060617 hack assuming that all scripts use only one bound variable |
589 and use 'v_' as the formal argument for this bound variable*) |
589 and use 'v_' as the formal argument for this bound variable*) |
590 fun subs_from (ScrState (env, _, _, _, _, _)) _ (guh : guh) = |
590 fun subs_from (Ctree.ScrState (env, _, _, _, _, _)) _ (guh : guh) = |
591 let |
591 let |
592 val (_, _, thyID, sect, xstr) = case guh2theID guh of |
592 val (_, _, thyID, sect, xstr) = case guh2theID guh of |
593 theID as [isa, thyID, sect, xstr] => (theID, isa, thyID, sect, xstr) |
593 theID as [isa, thyID, sect, xstr] => (theID, isa, thyID, sect, xstr) |
594 | _ => error "subs_from: uncovered case" |
594 | _ => error "subs_from: uncovered case" |
595 in |
595 in |
633 if is_bdv_subst t then SOME t else NONE |
633 if is_bdv_subst t then SOME t else NONE |
634 | scan (Abs (_, _, body)) = scan body |
634 | scan (Abs (_, _, body)) = scan body |
635 | scan (t1 $ t2) = case scan t1 of NONE => scan t2 | SOME subst => SOME subst |
635 | scan (t1 $ t2) = case scan t1 of NONE => scan t2 | SOME subst => SOME subst |
636 in |
636 in |
637 case scan prog of |
637 case scan prog of |
638 NONE => (NONE: subs option, []: subst) |
638 NONE => (NONE: Ctree.subs option, []: subst) |
639 | SOME tm => |
639 | SOME tm => |
640 let val subst = tm |> subst_atomic env |> isalist2list |> map isapair2pair |
640 let val subst = tm |> subst_atomic env |> isalist2list |> map isapair2pair |
641 (* "[(bdv,v_v)]": term |
641 (* "[(bdv,v_v)]": term |
642 |> "[(bdv,x)]": term |> ["(bdv,x)"]: term list |
642 |> "[(bdv,x)]": term |> ["(bdv,x)"]: term list |
643 |> [("bdv","x")]: (term * term) list *) |
643 |> [("bdv","x")]: (term * term) list *) |
644 in (SOME (subst2subs subst), subst) end |
644 in (SOME (Ctree.subst2subs subst), subst) end |
645 (*"SOME [(bdv,v_v)]": term --> ["(bdv,v_v)"]: string list*) |
645 (*"SOME [(bdv,v_v)]": term --> ["(bdv,v_v)"]: string list*) |
646 end |
646 end |
647 |
647 |
648 end |
648 end |