test/Tools/isac/Minisubpbl/200-start-method-NEXT_STEP.sml
author wneuper <Walther.Neuper@jku.at>
Fri, 31 Mar 2023 12:07:52 +0200
changeset 60705 b719a0b7c6b5
parent 60682 81fe68e76522
child 60710 21ae85b023bb
permissions -rw-r--r--
//new Pre_Conds.check/_TEST breaks tests, need new signature
     1 (* Title:  "Minisubpbl/200-start-method-NEXT_STEP.sml"
     2    Author: Walther Neuper 1105
     3    (c) copyright due to lincense terms.
     4 *)
     5 
     6 open Rewrite;
     7 open Pos;
     8 open TermC;
     9 
    10 "----------- Minisubplb/200-start-method-NEXT_STEP.sml ---------------------------------------";
    11 "----------- Minisubplb/200-start-method-NEXT_STEP.sml ---------------------------------------";
    12 "----------- Minisubplb/200-start-method-NEXT_STEP.sml ---------------------------------------";
    13 val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
    14 val (dI',pI',mI') =
    15   ("Test", ["sqroot-test", "univariate", "equation", "test"],
    16    ["Test", "squ-equ-test-subpbl1"]);
    17 val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context} [(fmz, (dI',pI',mI'))];
    18 (*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Model_Problem*)
    19 (*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Specify_Theory "Test"*)
    20 (*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Specify_Problem ["sqroot-test", "univariate", "equation", "test"*)
    21 
    22 (*[], Met*)val return_Step_do_next_Specify_Problem = Step.do_next p ((pt, e_pos'), []);(*Specify_Method ["Test", "squ-equ-test-subpbl1"]*)
    23 (*/------------------- step into Step.do_next_Specify_Problem ------------------------------\\*)
    24 "~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) =
    25   (p, ((pt, e_pos'), []));
    26   (*if*) Pos.on_calc_end ip (*else*);
    27       val (_, probl_id, _) = Calc.references (pt, p);
    28 val _ =
    29       (*case*) tacis (*of*);
    30         (*if*) probl_id = Problem.id_empty (*else*);
    31 
    32       Step.switch_specify_solve p_ (pt, ip);
    33 "~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
    34       (*if*) Pos.on_specification ([], state_pos) (*then*);
    35 
    36       Step.specify_do_next (pt, input_pos);
    37 "~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = ((pt, input_pos));
    38     val (_, (p_', tac)) = Specify.find_next_step ptp
    39     val ist_ctxt =  Ctree.get_loc pt (p, p_)
    40 val _ =
    41     (*case*) tac (*of*);
    42 
    43 Step_Specify.by_tactic_input tac (pt, (p, p_'));
    44 "~~~~~ fun by_tactic_input , args:"; val ((Tactic.Specify_Method id), (pt, pos)) =
    45   (tac, (pt, (p, p_')));
    46 
    47       val (o_model, ctxt, i_model) =
    48 Specify_Step.complete_for id (pt, pos);
    49 "~~~~~ fun complete_for , args:"; val (mID, (ctree, pos)) = (id, (pt, pos));
    50     val {origin = (o_model, _, _), probl = i_prob, ctxt,
    51        ...} = Calc.specify_data (ctree, pos);
    52     val {model = m_patt, where_, where_rls, ...} = MethodC.from_store ctxt mID
    53     val {origin = (root_model, _, _), ...} = Calc.specify_data (ctree, ([], Pos.Und))
    54     val (o_model', ctxt') = O_Model.complete_for m_patt root_model (o_model, ctxt)
    55 
    56     val (_, (i_model, _)) =
    57    M_Match.match_itms_oris ctxt i_prob (m_patt, where_, where_rls) o_model';
    58 "~~~~~ fun match_itms_oris , args:"; val (ctxt, pbl, (pbt, where_, where_rls), oris) =
    59   (ctxt, i_prob, (m_patt, where_, where_rls), o_model');
    60  (*0*)val mv = Pre_Conds.max_variant pbl;
    61 
    62       fun eqdsc_pbt_itm ((_,(d,_))) (_, _, _, _, itm_) = d = I_Model.descriptor itm_;
    63       fun notmem pbl pbt1 = case find_first (eqdsc_pbt_itm pbt1) pbl of
    64 				SOME _ => false | NONE => true;
    65  (*1*)val mis = (filter (notmem pbl)) pbt;
    66       fun eqdsc_ori (_,(d,_)) (_, _, _, d', _) = d = d';
    67       fun ori2itmMis (f, (d, pid)) (i, v, _, _, _) = (i, v, false, f, I_Model.Mis (d, pid));
    68  (*2*)fun oris2itms oris mis1 = ((map (ori2itmMis mis1)) o (filter (eqdsc_ori mis1))) oris;
    69       val news = (flat o (map (oris2itms oris))) mis;
    70  (*3*)fun mem_vat (_, vats, _, _, _) = member op = vats mv;
    71       val newitms = filter mem_vat news;
    72  (*4*)val itms' = pbl @ newitms;
    73 
    74       val (pb, where_') =
    75  Pre_Conds.check ctxt where_rls where_ itms' mv;
    76 "~~~~~ fun check , args:"; val (ctxt, where_rls, pres, pbl, (_)) =
    77   (ctxt, where_rls, where_, itms', mv);
    78       val env = Pre_Conds.environment pbl;
    79       val pres' = map (TermC.subst_atomic_all env) pres;
    80 
    81 (*+*)val "Test" = ctxt |> Proof_Context.theory_of  |> ThyC.id_of
    82 (*+*)val Rule_Set.Repeat {id = "prls_met_test_squ_sub", ...} = where_rls
    83 (*+*)val [(true, tTEST as Const ("Test.precond_rootmet", _) $ Free ("x", xxx))] = pres'
    84 
    85 (*+*)val ctxt = Config.put rewrite_trace true ctxt;
    86       val evals = map (
    87  Pre_Conds.eval ctxt where_rls) pres';
    88 (* (*declare [[rewrite_trace = true]]*)
    89 @## rls: prls_met_test_squ_sub on: precond_rootmet x 
    90 @### try calc: "Test.precond_rootmet" 
    91 @#### eval asms: "(precond_rootmet x) = True" 
    92 @### calc. to: True 
    93 @### try calc: "Test.precond_rootmet" 
    94 @### try calc: "Test.precond_rootmet" 
    95 *)
    96 (*+*)val ctxt = Config.put rewrite_trace false ctxt;
    97 
    98 "~~~~~ fun eval_precond_rootmet , args:"; val ((thmid:string), _, (t as (Const (\<^const_name>\<open>Test.precond_rootmet\<close>, _) $ arg)), ctxt) =
    99   ("aaa", "bbb", tTEST, ctxt);
   100     SOME (TermC.mk_thmid thmid (UnparseC.term ctxt arg) "",
   101       HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
   102 ;
   103     (TermC.mk_thmid thmid (UnparseC.term ctxt arg)) "";
   104 "~~~~~ fun mk_thmid , args:"; val (thmid, n1, n2) = (thmid, (UnparseC.term ctxt arg), "");
   105   thmid ^ (cut_longid n1) ^ "_" ^ (cut_longid n2);
   106 
   107       (cut_longid n2);
   108 "~~~~~ fun cut_longid , args:"; val (dn) = (n2);
   109 (*\------------------- step into Step.do_next_Specify_Problem ------------------------------//*)
   110 val (_, ([(tac, _, _)], _, (pt, p))) = return_Step_do_next_Specify_Problem
   111 
   112 (*[1], Frm*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Apply_Method ["Test", "squ-equ-test-subpbl1"]*)
   113 (*[1], Res*)val return_Step_do_next_Apply_Method = Step.do_next p ((pt, e_pos'), []);(*Rewrite_Set "norm_equation"*)
   114 
   115 (*/------------------- step into Apply_Method ----------------------------------------------\\*)
   116 "~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
   117   = (p ,((pt, e_pos'), []));
   118   (*if*) Pos.on_calc_end ip (*else*);
   119       val (_, probl_id, _) = Calc.references (pt, p);
   120 val _ =
   121       (*case*) tacis (*of*);
   122         (*if*) probl_id = Problem.id_empty (*else*);
   123 
   124       Step.switch_specify_solve p_ (pt, ip);
   125 "~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos))
   126   = (p_, (pt, ip));
   127       (*if*) Pos.on_specification ([], state_pos) (*else*);
   128 
   129         LI.do_next (pt, input_pos);
   130 "~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) = (pt, input_pos);
   131     (*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) (*else*);
   132 	      val ((ist, ctxt), sc) = LItool.resume_prog (p,p_) pt;
   133 
   134 val return_LI_find_next_step = (*case*)
   135         LI.find_next_step sc (pt, pos) ist ctxt (*of*);
   136 (*//------------------ step into LI.find_next_step -----------------------------------------\\*)
   137 "~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as (pt, pos as (p, _))), (Istate.Pstate ist), ctxt) =
   138   (sc, (pt, pos), ist, ctxt);
   139 (*.. this showed that we have ContextC.empty*)
   140 (*\\------------------ step into XXXXX -----------------------------------------------------//*)
   141 val LI.Next_Step (ist, ctxt, tac) = return_LI_find_next_step;
   142 
   143         LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp;
   144 "~~~~~ fun by_tactic , args:"; val (tac_, ic, (pt, pos))
   145   = (tac, (ist, Tactic.insert_assumptions tac ctxt), ptp);
   146       val pos = next_in_prog' pos
   147 
   148  	    val (pos', c, _, pt) =
   149 Solve_Step.add_general tac_ ic (pt, pos);
   150 "~~~~~ fun add_general , args:"; val (tac, ic, cs)
   151   = (tac_, ic, (pt, pos));
   152  (*if*) Tactic.for_specify' tac (*else*);
   153 
   154 Solve_Step.add tac ic cs;
   155 "~~~~~ fun add , args:"; val ((Tactic.Rewrite_Set' (_, _, rls', f, (f', asm))), (is, ctxt), (pt, (p, _)))
   156   = (tac, ic, cs);
   157       val (pt, c) = Ctree.cappend_atomic pt p (is, ctxt) f 
   158         (Tactic.Rewrite_Set (Rule_Set.id rls')) (f', asm) Ctree.Complete
   159       val pt = Ctree.update_branch pt p Ctree.TransitiveB
   160 
   161 val return =
   162       ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term ctxt f'), pt)
   163 (*\------------------- step into Apply_Method ----------------------------------------------//*)
   164 val (_, ([(tac, _, _)], _, (pt, p))) = return_Step_do_next_Apply_Method
   165 
   166 (*[2], Res*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Rewrite_Set "Test_simplify"*)
   167 
   168 (* final test ... ----------------------------------------------------------------------------*)
   169 (*+*)val ([2], Res) = p;
   170 Test_Tool.show_pt_tac pt; (*[
   171 ([], Frm), solve (x + 1 = 2, x)
   172 . . . . . . . . . . Apply_Method ["Test", "squ-equ-test-subpbl1"], 
   173 ([1], Frm), x + 1 = 2
   174 . . . . . . . . . . Rewrite_Set "norm_equation", 
   175 ([1], Res), x + 1 + - 1 * 2 = 0
   176 . . . . . . . . . . Rewrite_Set "Test_simplify", 
   177 ([2], Res), - 1 + x = 0
   178 . . . . . . . . . . Check_Postcond ["sqroot-test", "univariate", "equation", "test"]]   ..INCORRECT
   179 *)