src/Tools/isac/MathEngine/step.sml
author Walther Neuper <walther.neuper@jku.at>
Fri, 01 May 2020 16:06:59 +0200
changeset 59922 9dbb624c2ec2
parent 59921 0766dade4a78
child 59932 87336f3b021f
permissions -rw-r--r--
separate Specify_Step.check
     1 (* Title:  MathEngine/step.sml
     2    Author: Walther Neuper 2019
     3    (c) due to copyright terms
     4 
     5 Unify function of structure Step_Specify and structure Step_Solve
     6 as well as of structure Specify_Step and structure Solve_Step.
     7 *)
     8 
     9 signature STEP =
    10 sig
    11   val do_next: Pos.pos' -> Chead.calcstate -> string * Chead.calcstate'
    12   val by_tactic: Tactic.input -> Calc.T -> string * Chead.calcstate'
    13 (*val by_term  = Step_Solve.by_term: Calc.T -> term -> string * Chead.calcstate' NOT for specify*)
    14   val check: Tactic.input -> Calc.T -> Applicable.T
    15 
    16 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
    17   (*NONE*)                                                     
    18 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
    19   val specify_do_next: Calc.T -> string * Chead.calcstate'
    20   val switch_specify_solve: Pos.pos_ -> Calc.T -> string * Chead.calcstate'
    21 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
    22 end
    23 
    24 (**)
    25 structure Step(**): STEP(**) =
    26 struct
    27 (**)
    28 
    29 (** check a tactic for applicability **)
    30 
    31 fun check tac (ctree, pos) =
    32   if Pos.on_specification (snd pos)
    33   then Specify_Step.check tac (ctree, pos)
    34   else Solve_Step.check tac (ctree, pos)
    35 
    36 
    37 (* survey on results of by_tactic, find_next, by_term:
    38    * Step_Specify
    39      * by_tactic "ok", "ok", 
    40    * Step_Solve              
    41      * locate_input_tactic  : "ok", "unsafe-ok", "not-applicable", "end-of-calculation"
    42      * locate_input_term : "ok", "syntax error", "same-formula", "no derivation found",
    43         "error pattern #" ^ errpatID (the latter doesn't fit into the pattern of fixed string)
    44      * find_next_formula    : "ok", "helpless", "no-fmz-spec"(=helpless), "end-of-calculation"
    45  *)
    46 
    47 (** do a next step **)
    48 
    49 fun specify_do_next (ptp as (pt, (p, p_))) =
    50   let
    51     val (_, (p_', tac)) = SpecifyNEW.find_next_step ptp
    52     val ist_ctxt =  Ctree.get_loc pt (p, p_)
    53   in
    54     case tac of
    55   	  Tactic.Apply_Method mI =>
    56   	    (*vvvvvvvvvv-------------------------------------------------------------- solve-phase *)
    57   	    LI.by_tactic (Tactic.Apply_Method' (mI, NONE, Istate.empty, ContextC.empty))
    58   	      ist_ctxt (pt, (p, p_'))
    59     | _ => ("dummy", Step_Specify.by_tactic_input tac (pt, (p, p_')))
    60   end
    61 
    62 fun switch_specify_solve state_pos (pt, input_pos) =
    63   let
    64     val result =
    65       if Library.member op = [Pos.Pbl, Pos.Met] state_pos
    66   	  then specify_do_next (pt, input_pos)
    67       else LI.do_next (pt, input_pos)
    68   in
    69     case result of
    70       (_, cs as ([], _, _)) => ("helpless", cs)
    71     | scs => scs
    72   end
    73 
    74 (* does a step forward; returns tactic used, ctree updated (i.e. with NEW term/calchead) *)
    75 fun do_next (ip as (_, p_)) (ptp as (pt, p), tacis) =
    76   let
    77     val pIopt = Ctree.get_pblID (pt, ip);
    78   in
    79     if ip = ([], Pos.Res)
    80     then ("end-of-calculation", (tacis, [], ptp): Chead.calcstate') 
    81     else
    82       case tacis of
    83         (_ :: _) => 
    84           if ip = p (*the request is done where ptp waits for*)
    85           then 
    86             let val (pt', c', p') = Generate.generate tacis (pt, [], p)
    87   	        in ("ok", (tacis, c', (pt', p'))) end
    88           else
    89             switch_specify_solve p_ (pt, ip)
    90       | _ => case pIopt of
    91   	            NONE => ("no-fmz-spec", ([], [], ptp))
    92   	          | SOME _ => switch_specify_solve p_ (pt, ip)
    93   end
    94 
    95 
    96 (** locate an input tactic **)
    97 
    98 (* LEGACY: report of tacs' applicability in tacis; pt is dropped in setNextTactic*)
    99 fun by_tactic _ (ptp as (_, ([], Pos.Res))) = ("end-of-calculation", ([], [], ptp))
   100   | by_tactic tac (ptp as (pt, p)) =
   101     case check tac (pt, p) of
   102 	    Applicable.No _ => ("not-applicable", ([],[],  ptp): Chead.calcstate')
   103 	  | Applicable.Yes tac' =>
   104 	    if Tactic.for_specify' tac'
   105 	    then Step_Specify.by_tactic tac' ptp
   106 	    else Step_Solve.by_tactic tac' ptp
   107 
   108 
   109 (**)end(**)