1.1 --- a/src/Tools/isac/Interpret/solve-step.sml Sat May 02 15:41:27 2020 +0200
1.2 +++ b/src/Tools/isac/Interpret/solve-step.sml Sat May 02 16:34:42 2020 +0200
1.3 @@ -34,7 +34,7 @@
1.4 case Rewrite.calculate_ (ThyC.get_theory thy') isa_fn f of
1.5 SOME (f', (id, thm))
1.6 => Applicable.Yes (Tactic.Calculate' (thy', op_, f, (f', (id, thm))))
1.7 - | NONE => Applicable.No ("'calculate "^op_^"' not applicable")
1.8 + | NONE => Applicable.No ("'calculate " ^ op_ ^ "' not applicable")
1.9 else Applicable.No msg
1.10 end
1.11 | check (Tactic.Check_Postcond pI) (_, _) = (*TODO: only applicable, if evaluating to True*)
1.12 @@ -46,47 +46,40 @@
1.13 Applicable.Yes (Tactic.Check_elementwise' (f, pred, (f, [])))
1.14 end
1.15 | check Tactic.Empty_Tac _ = Applicable.No "Empty_Tac is not applicable"
1.16 - | check (Tactic.Free_Solve) _ = Applicable.Yes (Tactic.Free_Solve') (* always applicable *)
1.17 - | check Tactic.Or_to_List (pt, (p, p_)) =
1.18 + | check (Tactic.Free_Solve) _ = Applicable.Yes (Tactic.Free_Solve')
1.19 + | check Tactic.Or_to_List cs =
1.20 let
1.21 - val f = case p_ of
1.22 - Pos.Frm => Ctree.get_obj Ctree.g_form pt p
1.23 - | Pos.Res => (fst o (Ctree.get_obj Ctree.g_result pt)) p
1.24 - | _ => error ("Solve_Step.check: call by " ^ Pos.pos'2str (p, p_));
1.25 - in (let val ls = Prog_Expr.or2list f
1.26 - in Applicable.Yes (Tactic.Or_to_List' (f, ls)) end)
1.27 - handle _ => Applicable.No ("'Or_to_List' not applicable to " ^ UnparseC.term f)
1.28 + val f = Calc.current_formula cs;
1.29 + val ls = Prog_Expr.or2list f;
1.30 + in
1.31 + Applicable.Yes (Tactic.Or_to_List' (f, ls))
1.32 end
1.33 - | check (Tactic.Rewrite thm'') (cs as (pt, (p, _))) =
1.34 + | check (Tactic.Rewrite thm) (cs as (pt, (p, _))) =
1.35 let
1.36 - val (msg, thy', ro, rls', _)= ApplicableOLD.from_pblobj_or_detail_thm thm'' p pt;
1.37 + val (msg, thy', ro, rls', _) = ApplicableOLD.from_pblobj_or_detail_thm thm p pt;
1.38 val thy = ThyC.get_theory thy';
1.39 val f = Calc.current_formula cs;
1.40 in
1.41 if msg = "OK"
1.42 then
1.43 - case Rewrite.rewrite_ thy (Rewrite_Ord.assoc_rew_ord ro) rls' false (snd thm'') f of
1.44 - SOME (f',asm) => Applicable.Yes (Tactic.Rewrite' (thy', ro, rls', false, thm'', f, (f', asm)))
1.45 - | NONE => Applicable.No ("'" ^ fst thm'' ^"' not applicable")
1.46 + case Rewrite.rewrite_ thy (Rewrite_Ord.assoc_rew_ord ro) rls' false (snd thm) f of
1.47 + SOME (f',asm) => Applicable.Yes (Tactic.Rewrite' (thy', ro, rls', false, thm, f, (f', asm)))
1.48 + | NONE => Applicable.No ((thm |> fst |> quote) ^ " not applicable")
1.49 else Applicable.No msg
1.50 end
1.51 - | check (Tactic.Rewrite_Inst (subs, thm'')) (cs as (pt, (p, _))) =
1.52 + | check (Tactic.Rewrite_Inst (subs, thm)) (cs as (pt, (p, _))) =
1.53 let
1.54 val pp = Ctree.par_pblobj pt p;
1.55 val thy' = Ctree.get_obj Ctree.g_domID pt pp;
1.56 val thy = ThyC.get_theory thy';
1.57 val {rew_ord' = ro', erls = erls, ...} = Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp);
1.58 val f = Calc.current_formula cs;
1.59 + val subst = Subst.T_from_input thy subs; (*TODO: input requires parse _: _ -> _ option*)
1.60 in
1.61 - let
1.62 - val subst = Subst.T_from_input thy subs;
1.63 - in
1.64 - case Rewrite.rewrite_inst_ thy (Rewrite_Ord.assoc_rew_ord ro') erls false subst (snd thm'') f of
1.65 - SOME (f',asm) =>
1.66 - Applicable.Yes (Tactic.Rewrite_Inst' (thy', ro', erls, false, subst, thm'', f, (f', asm)))
1.67 - | NONE => Applicable.No ((fst thm'')^" not applicable")
1.68 - end
1.69 - handle _ => Applicable.No ("syntax error in " ^ subs2str subs)
1.70 + case Rewrite.rewrite_inst_ thy (Rewrite_Ord.assoc_rew_ord ro') erls false subst (snd thm) f of
1.71 + SOME (f', asm) =>
1.72 + Applicable.Yes (Tactic.Rewrite_Inst' (thy', ro', erls, false, subst, thm, f, (f', asm)))
1.73 + | NONE => Applicable.No (fst thm ^ " not applicable")
1.74 end
1.75 | check (Tactic.Rewrite_Set rls) (cs as (pt, (p, _))) =
1.76 let
1.77 @@ -99,37 +92,29 @@
1.78 => Applicable.Yes (Tactic.Rewrite_Set' (thy', false, assoc_rls rls, f, (f', asm)))
1.79 | NONE => Applicable.No (rls ^ " not applicable")
1.80 end
1.81 - | check (m as Tactic.Rewrite_Set_Inst (subs, rls)) (cs as (pt, (p, p_))) =
1.82 - if member op = [Pos.Pbl, Pos.Met] p_
1.83 - then Applicable.No ((Tactic.input_to_string m)^" not for pos "^(Pos.pos'2str (p,p_)))
1.84 - else
1.85 + | check (Tactic.Rewrite_Set_Inst (subs, rls)) (cs as (pt, (p, _))) =
1.86 let
1.87 val pp = Ctree.par_pblobj pt p;
1.88 val thy' = Ctree.get_obj Ctree.g_domID pt pp;
1.89 val thy = ThyC.get_theory thy';
1.90 val f = Calc.current_formula cs;
1.91 - val subst = Subst.T_from_input thy subs;
1.92 + val subst = Subst.T_from_input thy subs; (*TODO: input requires parse _: _ -> _ option*)
1.93 in
1.94 case Rewrite.rewrite_set_inst_ thy false subst (assoc_rls rls) f of
1.95 SOME (f', asm)
1.96 => Applicable.Yes (Tactic.Rewrite_Set_Inst' (thy', false, subst, assoc_rls rls, f, (f', asm)))
1.97 | NONE => Applicable.No (rls ^ " not applicable")
1.98 - handle _ => Applicable.No ("syntax error in " ^(subs2str subs))
1.99 end
1.100 | check (Tactic.Subproblem (domID, pblID)) (_, _) =
1.101 Applicable.Yes (Tactic.Subproblem' ((domID, pblID, Method.id_empty), [],
1.102 TermC.empty, [], ContextC.empty, Auto_Prog.subpbl domID pblID))
1.103 -
1.104 - (*Substitute combines two different kind of "substitution":
1.105 - (1) subst_atomic: for ?a..?z
1.106 - (2) Pattern.match: for solving equational systems (which raises exn for ?a..?z)*)
1.107 - | check (Tactic.Substitute sube) (cs as (pt, (p, _))) =
1.108 + | check (Tactic.Substitute sube) (cs as (pt, (p, _))) =
1.109 let
1.110 val pp = Ctree.par_pblobj pt p
1.111 val thy = ThyC.get_theory (Ctree.get_obj Ctree.g_domID pt pp)
1.112 val f = Calc.current_formula cs;
1.113 val {rew_ord', erls, ...} = Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp)
1.114 - val subte = Subst.input_to_terms sube
1.115 + val subte = Subst.input_to_terms sube (*TODO: input requires parse _: _ -> _ option*)
1.116 val subst = Subst.T_from_string_eqs thy sube
1.117 val ro = Rewrite_Ord.assoc_rew_ord rew_ord'
1.118 in
1.119 @@ -146,37 +131,30 @@
1.120 | NONE => Applicable.No (Subst.string_eqs_to_string sube ^ " not applicable")
1.121 end
1.122 | check (Tactic.Tac id) (cs as (pt, (p, _))) =
1.123 - let
1.124 - val pp = Ctree.par_pblobj pt p;
1.125 - val thy' = Ctree.get_obj Ctree.g_domID pt pp;
1.126 - val thy = ThyC.get_theory thy';
1.127 - val f = Calc.current_formula cs;
1.128 - in case id of
1.129 - "subproblem_equation_dummy" =>
1.130 - if TermC.is_expliceq f
1.131 - then Applicable.Yes (Tactic.Tac_ (thy, UnparseC.term f, id, "subproblem_equation_dummy (" ^ UnparseC.term f ^ ")"))
1.132 - else Applicable.No "applicable only to equations made explicit"
1.133 - | "solve_equation_dummy" =>
1.134 - let val (id', f') = ApplicableOLD.split_dummy (UnparseC.term f);
1.135 - in
1.136 - if id' <> "subproblem_equation_dummy"
1.137 - then Applicable.No "no subproblem"
1.138 - else if (ThyC.to_ctxt thy, f') |-> TermC.parseNEW |> the |> TermC.is_expliceq
1.139 - then Applicable.Yes (Tactic.Tac_ (thy, UnparseC.term f, id, "[" ^ f' ^ "]"))
1.140 - else error ("Solve_Step.check: f= " ^ f')
1.141 + let
1.142 + val pp = Ctree.par_pblobj pt p;
1.143 + val thy' = Ctree.get_obj Ctree.g_domID pt pp;
1.144 + val thy = ThyC.get_theory thy';
1.145 + val f = Calc.current_formula cs;
1.146 + in case id of
1.147 + "subproblem_equation_dummy" =>
1.148 + if TermC.is_expliceq f
1.149 + then Applicable.Yes (Tactic.Tac_ (thy, UnparseC.term f, id, "subproblem_equation_dummy (" ^ UnparseC.term f ^ ")"))
1.150 + else Applicable.No "applicable only to equations made explicit"
1.151 + | "solve_equation_dummy" =>
1.152 + let val (id', f') = ApplicableOLD.split_dummy (UnparseC.term f);
1.153 + in
1.154 + if id' <> "subproblem_equation_dummy"
1.155 + then Applicable.No "no subproblem"
1.156 + else if (ThyC.to_ctxt thy, f') |-> TermC.parseNEW |> the |> TermC.is_expliceq
1.157 + then Applicable.Yes (Tactic.Tac_ (thy, UnparseC.term f, id, "[" ^ f' ^ "]"))
1.158 + else error ("Solve_Step.check: f= " ^ f')
1.159 + end
1.160 + | _ => Applicable.Yes (Tactic.Tac_ (thy, UnparseC.term f, id, UnparseC.term f))
1.161 end
1.162 - | _ => Applicable.Yes (Tactic.Tac_ (thy, UnparseC.term f, id, UnparseC.term f))
1.163 - end
1.164 | check (Tactic.Take str) _ = Applicable.Yes (Tactic.Take' (TermC.str2term str)) (* always applicable ?*)
1.165 - | check (Tactic.Begin_Trans) (pt, (p, p_)) =
1.166 - let
1.167 - val (f, _) = case p_ of (*p 12.4.00 unnecessary, implizit Take in gen*)
1.168 - Pos.Frm => (Ctree.get_obj Ctree.g_form pt p, (Pos.lev_on o Pos.lev_dn) p)
1.169 - | Pos.Res => ((fst o (Ctree.get_obj Ctree.g_result pt)) p, (Pos.lev_on o Pos.lev_dn o Pos.lev_on) p)
1.170 - | _ => error ("Solve_Step.check: call by " ^ Pos.pos'2str (p, p_));
1.171 - in (Applicable.Yes (Tactic.Begin_Trans' f))
1.172 - handle _ => raise ERROR ("Solve_Step.check: Begin_Trans finds syntaxerror in '" ^ UnparseC.term f ^ "'")
1.173 - end
1.174 + | check (Tactic.Begin_Trans) cs =
1.175 + Applicable.Yes (Tactic.Begin_Trans' (Calc.current_formula cs))
1.176 | check (Tactic.End_Trans) (pt, (p, p_)) = (*TODO: check parent branches*)
1.177 if p_ = Pos.Res
1.178 then Applicable.Yes (Tactic.End_Trans' (Ctree.get_obj Ctree.g_result pt p))