1 (* Title: MathEngine/step.sml
2 Author: Walther Neuper 2019
3 (c) due to copyright terms
6 (* survey on results of by_tactic, find_next, by_term:
8 * by_tactic "ok", "ok",
10 * locate_input_tactic : "ok", "unsafe-ok", "not-applicable", "end-of-calculation"
11 * locate_input_term : "ok", "syntax error", "same-formula", "no derivation found",
12 "error pattern #" ^ errpatID (the latter doesn't fit into the pattern of fixed string)
13 * find_next_formula : "ok", "helpless", "no-fmz-spec"(=helpless), "end-of-calculation"
17 val do_next: Ctree.pos' -> Chead.calcstate -> string * Chead.calcstate'
18 val by_tactic: Tactic.input -> Calc.T -> string * Chead.calcstate'
20 val by_tactic = Step_Solve.by_tactic
21 = Step_Specify.by_tactic ? depending on PIDE, see TODO.thy
22 val by_term = Step_Solve.by_term: Calc.T -> term -> string * Chead.calcstate'
23 TODO --------------------------------------"----------> ?????? Calc.T
24 = Step_Specify.by_tactic ? depending on PIDE, see TODO.thy
26 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
28 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
29 val specify_do_next: Calc.T -> string * Chead.calcstate'
30 val switch_specify_solve: Pos.pos_ -> Calc.T -> string * Chead.calcstate'
32 datatype lOc_ = ERror of string | UNsafe of Chead.calcstate' | Updated of Chead.calcstate'
33 val loc_solve_ : Tactic.T -> Calc.T -> lOc_
34 val loc_specify_ : Tactic.T -> Calc.T -> lOc_
35 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
39 structure Step(**): STEP(**) =
43 (** do a next step **)
45 fun specify_do_next (ptp as (pt, (p, p_))) =
47 val (_, (p_', tac)) = SpecifyNEW.find_next_step ptp
48 val ist_ctxt = Ctree.get_loc pt (p, p_)
51 Tactic.Apply_Method mI =>
52 (*vvvvvvvvvv-------------------------------------------------------------- solve-phase *)
53 LI.by_tactic (Tactic.Apply_Method' (mI, NONE, Istate.e_istate, ContextC.e_ctxt))
54 ist_ctxt (pt, (p, p_'))
55 | _ => ("dummy", Step_Specify.by_tactic tac (pt, (p, p_')))
58 fun switch_specify_solve state_pos (pt, input_pos) =
61 if member op = [Pos.Pbl, Pos.Met] state_pos
62 then specify_do_next (pt, input_pos)
63 else LI.do_next (pt, input_pos)
66 (_, cs as ([], _, _)) => ("helpless", cs)
70 (* does a step forward; returns tactic used, ctree updated (i.e. with NEW term/calchead) *)
71 fun do_next (ip as (_, p_)) (ptp as (pt, p), tacis) =
72 let val pIopt = Ctree.get_pblID (pt, ip);
75 then ("end-of-calculation", (tacis, [], ptp): Chead.calcstate')
79 if ip = p (*the request is done where ptp waits for*)
81 let val (pt', c', p') = Generate.generate tacis (pt, [], p)
82 in ("ok", (tacis, c', (pt', p'))) end
84 switch_specify_solve p_ (pt, ip)
86 NONE => ("no-fmz-spec", ([], [], ptp))
87 | SOME _ => switch_specify_solve p_ (pt, ip)
91 (** locate an input tactic **)
93 datatype lOc_ = ERror of string | UNsafe of Chead.calcstate' | Updated of Chead.calcstate'
94 (* loc_specify_ : Tactic.T -> Calc.T -> lOc_*)
95 fun loc_specify_ m (pt, pos) =
97 val (p, _, f, _, _, pt) = Chead.specify m pos [] pt;
99 case f of (Generate.Error' e) => ERror e | _ => Updated ([], [], (pt,p))
101 (* loc_solve_ : Tactic.T -> Calc.T -> lOc_*)
102 fun loc_solve_ m (pt, pos) =
104 val (msg, cs') = Step_Solve.by_tactic m (pt, pos); (*..sig.OK*)
106 case msg of "ok" => Updated cs' | msg => ERror msg
109 (* locate a tactic in a program and apply it if possible;
110 report of tacs' applicability in tacis; pt is dropped in setNextTactic*)
111 fun by_tactic _ (ptp as (_, ([], Pos.Res))) = ("end-of-calculation", ([], [], ptp))
112 | by_tactic m (ptp as (pt, p)) =
113 case Applicable.applicable_in p pt m of
114 Applicable.Notappl _ => ("not-applicable", ([],[], ptp): Chead.calcstate')
115 | Applicable.Appl m =>
117 val x = if Tactic.for_specify' m
118 then loc_specify_ m ptp else loc_solve_ m ptp
121 ERror _ => ("failure", ([], [], ptp))
122 (*FIXXXXXME: loc_specify_, loc_solve_ TOGETHER with dropping meOLD+detail.sml*)
123 | UNsafe cs' => ("unsafe-ok", cs')
124 | Updated (cs' as (_, _, (_, p'))) => (*ev.SEVER.tacs like Begin_Trans*)
125 (if p' = ([], Pos.Res) then "end-of-calculation" else "ok", cs')
126 (*for SEVER.tacs user to ask ? *)