src/Tools/isac/MathEngine/detail-step.sml
author Walther Neuper <walther.neuper@jku.at>
Mon, 04 May 2020 12:38:16 +0200
changeset 59935 16927a749dd7
parent 59932 87336f3b021f
child 60154 2ab0d1523731
permissions -rw-r--r--
end cleanup Interpret/*, preliminary

preliminary means: no canonical argument order
walther@59833
     1
(* Title:  MathEngine/detail-step.sml
walther@59833
     2
   Author: Walther Neuper 2020
walther@59833
     3
   (c) due to copyright terms
walther@59833
     4
walther@59833
     5
Within one step go into detailed steps on request by the user
walther@59833
     6
*)
walther@59833
     7
walther@59833
     8
signature DETAIL_STEP =
walther@59833
     9
sig
walther@59846
    10
  val go : Ctree.ctree -> Pos.pos' -> string * Ctree.ctree * Pos.pos'
walther@59846
    11
  val detailrls : Ctree.ctree -> Pos.pos' -> string * Ctree.ctree * Pos.pos'
walther@59833
    12
end
walther@59833
    13
walther@59833
    14
(**)
walther@59833
    15
structure Detail_Step(**): DETAIL_STEP(**) =
walther@59833
    16
struct
walther@59833
    17
(**)
walther@59833
    18
open Ctree;
walther@59833
    19
open Pos
walther@59833
    20
walther@59833
    21
(* aux.fun for detailrls with Rrls, reverse rewriting *)
walther@59833
    22
fun rul_terms_2nds _ nds _ [] = nds
walther@59833
    23
  | rul_terms_2nds thy nds t ((rule, res as (t', _)) :: rts) =
walther@59846
    24
    (append_atomic [] (NONE(*guessed*), (Istate.empty, ContextC.empty)) t (Tactic.rule2tac thy [] rule) res Complete EmptyPtree) ::
walther@59833
    25
      (rul_terms_2nds thy nds t' rts);
walther@59833
    26
walther@59833
    27
(* detail steps done internally by Rewrite_Set* into Ctree 
walther@59833
    28
  by use of a program *)
walther@59833
    29
fun detailrls pt (pos as (p, _)) = 
walther@59833
    30
  let
walther@59833
    31
    val t = get_obj g_form pt p
walther@59833
    32
	  val tac = get_obj g_tac pt p
walther@59833
    33
	  val rls = (assoc_rls o Tactic.rls_of) tac
walther@59833
    34
    val ctxt = get_ctxt pt pos
walther@59833
    35
  in
walther@59833
    36
    case rls of
walther@59850
    37
	    Rule_Set.Rrls {scr = Rule.Rfuns {init_state, ...}, ...} => 
walther@59833
    38
	    let
walther@59833
    39
        val (_, _, _, rul_terms) = init_state t
walther@59833
    40
	      val newnds = rul_terms_2nds (Proof_Context.theory_of ctxt) [] t rul_terms
walther@59833
    41
	      val pt''' = ins_chn newnds pt p 
walther@59833
    42
	    in ("detailrls", pt''', (p @ [length newnds], Res)) end
walther@59833
    43
	  | _ =>
walther@59833
    44
	    let
walther@59935
    45
        val is = Istate.init_detail tac t
walther@59903
    46
	      val tac_ = Tactic.Apply_Method' (Method.id_empty(*WN0402: see generate1 !?!*), SOME t, is, ctxt)
walther@59833
    47
	      val pos' = ((lev_on o lev_dn) p, Frm)
walther@59932
    48
	      val (_, _, _, pt') = Step.add tac_ (is, ctxt) (pt, pos') (* implicit Take *)
walther@59833
    49
	      val (_,_, (pt'', _)) = Solve.complete_solve Solve.CompleteSubpbl [] (pt', pos')
walther@59833
    50
	      val newnds = children (get_nd pt'' p)
walther@59833
    51
	      val pt''' = ins_chn newnds pt p (*complete_solve cuts branches after*)
walther@59833
    52
	    in ("detailrls", pt''', (p @ [length newnds], Res)) end
walther@59833
    53
  end;
walther@59833
    54
walther@59833
    55
fun go pt (pos as (p, _)) = 
walther@59833
    56
  let 
walther@59833
    57
    val nd = Ctree.get_nd pt p
walther@59833
    58
    val cn = Ctree.children nd
walther@59833
    59
  in 
walther@59833
    60
    if null cn 
walther@59833
    61
    then
walther@59833
    62
      if (Tactic.is_rewset o (Ctree.get_obj Ctree.g_tac nd)) [(*root of nd*)]
walther@59833
    63
      then detailrls pt pos
walther@59833
    64
      else ("no-Rewrite_Set...", Ctree.EmptyPtree, Pos.e_pos')
walther@59833
    65
    else ("donesteps", pt, (p @ [length (Ctree.children (Ctree.get_nd pt p))], Pos.Res)) 
walther@59833
    66
  end;
walther@59833
    67
walther@59833
    68
end