src/Tools/isac/MathEngine/fetch-tactics.sml
author Walther Neuper <walther.neuper@jku.at>
Tue, 28 Apr 2020 15:31:49 +0200
changeset 59914 ab5bd5c37e13
parent 59903 5037ca1b112b
child 59932 87336f3b021f
permissions -rw-r--r--
assign code from Rtools to appropriate struct.s
     1 (* Title:  MathEngine/fetch-tactics.sml
     2    Author: Walther Neuper
     3    (c) due to copyright terms
     4 
     5 Fetch tactics from a program in order to present them for selection by the user
     6 *)
     7 
     8 signature FETCH_TACTICS =
     9 sig
    10   val from_prog : Ctree.ctree -> Pos.pos' -> Tactic.input list 
    11   val specific_from_prog : Ctree.ctree -> Pos.pos' -> Tactic.input list
    12 end
    13 
    14 (**)
    15 structure Fetch_Tacs(**): FETCH_TACTICS(**) =
    16 struct
    17 (**)
    18 open Ctree
    19 open Pos
    20 
    21 (* fetch _all_ tactics from a program *)
    22 fun from_prog _ ([], Res) = 
    23     raise PTREE "no tactics applicable at the end of a calculation"
    24   | from_prog pt (p,p_) =
    25     if Pos.on_specification p_ 
    26     then [get_obj g_tac pt p]
    27     else
    28       let
    29         val pp = par_pblobj pt p;
    30         val thy' = get_obj g_domID pt pp;
    31         val thy = ThyC.get_theory thy';
    32         val metID = get_obj g_metID pt pp;
    33         val metID' = if metID = Method.id_empty then (thd3 o snd3) (get_obj g_origin pt pp) else metID
    34         val (sc, srls) = (case Specify.get_met metID' of
    35             {scr = Rule.Prog sc, srls, ...} => (sc, srls) | _ => raise ERROR "from_prog 1")
    36         val subst = get_istate_LI pt (p, p_) |> Istate.the_pstate |> Istate.get_subst
    37         val ctxt = get_ctxt pt (p, p_)
    38       in map ((LItool.tac_from_prog pt thy) o Program.rep_stacexpr o #1 o
    39   	    (LItool.check_leaf "selrul" ctxt srls subst)) (Auto_Prog.stacpbls sc)
    40   	  end;
    41 
    42 (* fetch tactics from script and filter _applicable_ tactics;
    43    in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *)
    44 fun specific_from_prog _ (([], Res) : pos') = 
    45     raise PTREE "no tactics applicable at the end of a calculation"
    46   | specific_from_prog pt (p, p_) =
    47     if Pos.on_specification p_ 
    48     then [get_obj g_tac pt p]
    49     else
    50       let
    51         val pp = par_pblobj pt p
    52         val thy' = get_obj g_domID pt pp
    53         val thy = ThyC.get_theory thy'
    54         val metID = get_obj g_metID pt pp
    55         val metID' =
    56           if metID = Method.id_empty 
    57           then (thd3 o snd3) (get_obj g_origin pt pp)
    58           else metID
    59         val (sc, srls, erls, ro) = (case Specify.get_met metID' of
    60             {scr = Rule.Prog sc, srls, erls, rew_ord' = ro, ...} => (sc, srls, erls, ro)
    61           | _ => raise ERROR "specific_from_prog 1")
    62         val (env, (a, v)) = (case get_istate_LI pt (p, p_) of
    63             Istate.Pstate pst => (Istate.get_subst pst) | _ => error "specific_from_prog 2")
    64         val ctxt = get_ctxt pt (p, p_)
    65         val alltacs = (*we expect at least 1 Prog_Tac in a program*)
    66           map ((LItool.tac_from_prog pt thy) o Program.rep_stacexpr o #1 o
    67            (LItool.check_leaf "selrul" ctxt srls (env, (a, v)))) (Auto_Prog.stacpbls sc)
    68         val f =
    69           (case p_ of Frm => get_obj g_form pt p | Res => (fst o (get_obj g_result pt)) p
    70           | _ => raise ERROR "specific_from_prog 2")
    71           (*WN071231 ? replace atomic_appl_tacs with applicable_in (ineff!) ?*)
    72       in
    73         ((gen_distinct Tactic.eq_tac) o flat o (map (Tactic.applicable thy ro erls f))) alltacs
    74       end;
    75 
    76 (**)end(**)