1 (* Title: MathEngine/step.sml
2 Author: Walther Neuper 2019
3 (c) due to copyright terms
5 Unify function of structure Step_Specify and structure Step_Solve
6 as well as of structure Specify_Step and structure Solve_Step.
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
16 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
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 ----------------------------------------------------------/*)
25 structure Step(**): STEP(**) =
29 (** check a tactic for applicability **)
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)
37 (* survey on results of by_tactic, find_next, by_term:
39 * by_tactic "ok", "ok",
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"
47 (** do a next step **)
49 fun specify_do_next (ptp as (pt, (p, p_))) =
51 val (_, (p_', tac)) = SpecifyNEW.find_next_step ptp
52 val ist_ctxt = Ctree.get_loc pt (p, p_)
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_')))
62 fun switch_specify_solve state_pos (pt, input_pos) =
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)
70 (_, cs as ([], _, _)) => ("helpless", cs)
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) =
77 val pIopt = Ctree.get_pblID (pt, ip);
80 then ("end-of-calculation", (tacis, [], ptp): Chead.calcstate')
84 if ip = p (*the request is done where ptp waits for*)
86 let val (pt', c', p') = Generate.generate tacis (pt, [], p)
87 in ("ok", (tacis, c', (pt', p'))) end
89 switch_specify_solve p_ (pt, ip)
91 NONE => ("no-fmz-spec", ([], [], ptp))
92 | SOME _ => switch_specify_solve p_ (pt, ip)
96 (** locate an input tactic **)
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