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