test/Tools/isac/Minisubpbl/700-interSteps.sml
author Walther Neuper <walther.neuper@jku.at>
Wed, 13 Nov 2019 15:27:17 +0100
changeset 59697 dd85e03d47e6
parent 59691 53c60fa9c41c
child 59698 149fa1c2cb89
permissions -rw-r--r--
renaming in structure Env
wneuper@59493
     1
(* Title:  700-interSteps.sml
wneuper@59493
     2
   Author: Walther Neuper 1105
wneuper@59493
     3
   (c) copyright due to lincense terms.
wneuper@59493
     4
*)
wneuper@59493
     5
"----------- Minisubplb/700-interSteps.sml -----------------------";
wneuper@59493
     6
"----------- Minisubplb/700-interSteps.sml -----------------------";
wneuper@59493
     7
"----------- Minisubplb/700-interSteps.sml -----------------------";
wneuper@59493
     8
(** adaption from rewtools.sml --- initContext..Thy_, fun context_thm ---,
wneuper@59493
     9
  *into a functional representation, i.e. we outcomment statements with side-effects:
wneuper@59493
    10
 ** reset_states ();
wneuper@59493
    11
 ** CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
wneuper@59493
    12
 **   ("Test", ["sqroot-test","univariate","equation","test"],
wneuper@59493
    13
 **    ["Test","squ-equ-test-subpbl1"]))];
wneuper@59493
    14
 ** Iterator 1; moveActiveRoot 1;
wneuper@59493
    15
 ** autoCalculate 1 CompleteCalc;
wneuper@59493
    16
 **)
wneuper@59493
    17
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
wneuper@59493
    18
  ("Test", ["sqroot-test","univariate","equation","test"],
wneuper@59493
    19
   ["Test","squ-equ-test-subpbl1"]))];
wneuper@59493
    20
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    21
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    22
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    23
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    24
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    25
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    26
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    27
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    28
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    29
val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = ("Subproblem"*)
wneuper@59493
    30
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    31
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    32
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    33
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    34
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    35
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    36
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    37
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    38
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    39
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    40
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    41
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    42
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59493
    43
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59686
    44
wneuper@59493
    45
if p = ([], Res)
wneuper@59493
    46
then case nxt of ("End_Proof'", End_Proof') => ()
wneuper@59493
    47
  | _ => error "calculation not finished correctly 1"
wneuper@59493
    48
else error "calculation not finished correctly 2";
wneuper@59493
    49
show_pt pt; (* 11 lines with subpbl *)
wneuper@59493
    50
;
walther@59686
    51
wneuper@59493
    52
"----- no thy-context at result -----";
wneuper@59493
    53
(** val p = ([], Res);
wneuper@59493
    54
 ** initContext 1 Thy_ p
wneuper@59493
    55
 ***  = <MESSAGE><CALCID>1</CALCID><STRING>no thy-context at result</STRING></MESSAGE>: XML.tree;
wneuper@59493
    56
 ** val ((pt,_),_) = get_calc 1;  (* 11 lines with subpbl *)
wneuper@59493
    57
 **
wneuper@59493
    58
 ** interSteps 1 ([2], Res); (* added [2,1]..[2,6] *)
wneuper@59493
    59
 **)
wneuper@59493
    60
"~~~~~ fun interSteps, args:"; val (cI, ip) = (1, ([2], Res));
wneuper@59493
    61
(** val ((pt, p), tacis) = get_calc cI;*)
wneuper@59493
    62
val ip' = lev_pred' pt ip;
wneuper@59493
    63
val ("detailrls", pt, _(*lastpos*)) = (*case*) Math_Engine.detailstep pt ip (*of*) (* LOST ([3,1,1], Frm) .. ([], Res), [x = 1]*);
wneuper@59493
    64
show_pt pt;                  (* added [2,1]..[2,6] *)
wneuper@59493
    65
wneuper@59493
    66
(**
wneuper@59493
    67
 ** interSteps 1 ([3,1], Res); (* added [3,1,1] Frm + Res *)
wneuper@59493
    68
 ** val ((pt,_),_) = get_calc 1; 
wneuper@59493
    69
 ** show_pt pt;                   (*show 6 + 2 steps added*)
wneuper@59493
    70
 **
wneuper@59493
    71
 ** if existpt' ([1,1,1], Frm) pt then ()
wneuper@59493
    72
 ** else error "integrate.sml: interSteps on Rewrite_Set_Inst";
wneuper@59493
    73
 **)
wneuper@59493
    74
;
wneuper@59493
    75
"~~~~~ fun interSteps, args:"; val (cI, ip) = (1, ([3,1], Res));
wneuper@59493
    76
(**val ((pt, p), tacis) = get_calc cI;*)
wneuper@59493
    77
(*if*) (not o is_interpos) ip (* = false*);
wneuper@59493
    78
val ip' = lev_pred' pt ip;
wneuper@59493
    79
(*case*) Math_Engine.detailstep pt ip (*of*) (* LOST ([3,1,1], Frm) .. ([], Res), [x = 1]*);
wneuper@59493
    80
wneuper@59493
    81
"~~~~~ fun detailstep, args:"; val (pt, (pos as (p, _))) = (pt, ip);
wneuper@59493
    82
    val nd = Ctree.get_nd pt p
wneuper@59493
    83
    val cn = Ctree.children nd;
wneuper@59493
    84
(*if*) null cn  (* = true*);
wneuper@59571
    85
(*if*) (Tactic.is_rewset o (Ctree.get_obj Ctree.g_tac nd)) [(*root of nd*)]  (* = true*)
wneuper@59493
    86
;
wneuper@59493
    87
(* ?!?: in spite of exception PTREE "ins_chn: pos mustNOT be overwritten" insertion OK ?!?*)
wneuper@59493
    88
(* Solve.detailrls pt pos (* LOST ([3,1,1], Frm) ff.. ([], Res), [x = 1]*)  *)
wneuper@59493
    89
wneuper@59493
    90
"~~~~~ fun detailrls, args:"; val (pt, (pos as (p, _))) = (pt, pos);
wneuper@59493
    91
    val t = get_obj g_form pt p
wneuper@59493
    92
	  val tac = get_obj g_tac pt p
wneuper@59571
    93
	  val rls = (assoc_rls o Tactic.rls_of) tac
wneuper@59493
    94
    val ctxt = get_ctxt pt pos;
wneuper@59493
    95
 (*case*) rls (*of*);
wneuper@59493
    96
        val is = Generate.init_istate tac t
wneuper@59571
    97
	      val tac_ = Tactic.Apply_Method' (Celem.e_metID(*WN0402: see generate1 !?!*), SOME t, is, ctxt)
wneuper@59493
    98
	      val pos' = ((lev_on o lev_dn) p, Frm)
wneuper@59592
    99
	      val thy = Celem.assoc_thy "Isac_Knowledge"
wneuper@59493
   100
	      val (_, _, _, pt') = Generate.generate1 thy tac_ (is, ctxt) pos' pt (* implicit Take *);
wneuper@59493
   101
wneuper@59493
   102
show_pt pt'; (* cut ctree after ([3,1,1], Frm) *)
wneuper@59493
   103
walther@59686
   104
  	       complete_solve CompleteSubpbl [] (pt', pos');
wneuper@59493
   105
"~~~~~ fun complete_solve, args:"; val (auto, c, (ptp as (_, p as (_, p_)))) = (CompleteSubpbl, [], (pt', pos'));
wneuper@59493
   106
(*if*) p = ([], Res) (* = false*);
wneuper@59493
   107
(*if*) member op = [Pbl,Met] p_ (* = false*);
walther@59686
   108
walther@59686
   109
val ([(Rewrite_Inst (["(''bdv'', x)"], ("risolate_bdv_add", _)), _, _)], _, _) = (*case*)
walther@59686
   110
           do_solve_step ptp (*of*);
walther@59686
   111
"~~~~~ and do_solve_step , args:"; val (ptp as (pt, pos as (p, p_))) = (ptp);
walther@59686
   112
  (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (* = false  isabisac = ?*);
wneuper@59493
   113
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59636
   114
walther@59686
   115
	      val (srls, is, sc) =
walther@59686
   116
           from_pblobj_or_detail' thy' (p,p_) pt;
walther@59636
   117
"~~~~~ fun from_pblobj_or_detail' , args:"; val (_, (p, p_), pt) = (thy', (p,p_), pt);
walther@59636
   118
  (*if*) member op = [Pbl, Met] p_ (*else*);
walther@59636
   119
    val (pbl, p', rls') = par_pbl_det pt p;
walther@59636
   120
  (*if*) pbl (*else*);
walther@59636
   121
	          val scr = (*case*) rls' (*of*);
walther@59636
   122
    (Rule.e_rls(*!!!*), get_loc pt (p, p_), scr)  (*return value*);
walther@59636
   123
walther@59636
   124
(*+*)id_rls rls' = "isolate_bdv";
walther@59636
   125
"~~~~~ from from_pblobj_or_detail' to do_solve_step return val:"; val () = ();
wneuper@59493
   126
walther@59686
   127
  val (Rewrite_Inst' (_, _, _, _, _, ("risolate_bdv_add", _), _, _), is, (t, _)) =
walther@59686
   128
            determine_next_tactic (thy', srls) (pt, pos) sc is;
walther@59686
   129
"~~~~~ fun determine_next_tactic , args:"; val ((thy, _), (ptp as (pt, (p, _))), sc, (Istate.Pstate ist, _(*ctxt*)))
walther@59686
   130
  = ((thy', srls), (pt, pos), sc, is);
wneuper@59493
   131
walther@59686
   132
    (*case*)
walther@59690
   133
           scan_to_tactic2 (sc, (ptp, thy)) (Istate.Pstate ist) (*of*);
walther@59690
   134
"~~~~~ fun scan_to_tactic2 , args:"; val ((sc as Rule.Prog prog, cct), (Istate.Pstate (ist as {path, ...})))
walther@59686
   135
  = ((sc, (ptp, thy)), (Istate.Pstate ist));
walther@59686
   136
  (*if*) 0 = length path (*else*);
wneuper@59493
   137
walther@59691
   138
           go_scan_up2 (sc, cct) (trans_scan_up2 ist |> upd_appy Skip_);
walther@59691
   139
"~~~~~ and go_scan_up2 , args:"; val ((yyy as (Rule.Prog sc, _)), (ist as {env, path, finish, ...}) )
walther@59686
   140
  = ((sc, cct), (trans_scan_up2 ist |> upd_appy Skip_));
walther@59686
   141
    (*if*) 1 < length path (*then*);
wneuper@59493
   142
walther@59691
   143
      scan_up2 yyy (ist |> path_up) (go_up path sc);
walther@59691
   144
"~~~~~ fun scan_up2 , args:"; val ((yyy as (_, xxx)), ist, (Const ("Tactical.Repeat"(*2*), _) $ e))
walther@59686
   145
  = (yyy, (ist |> path_up), (go_up path sc));
wneuper@59493
   146
walther@59686
   147
    (*case*)
walther@59691
   148
           scan_dn2 xxx (ist |> path_down [R]) e (*of*);
walther@59672
   149
    (*========== a leaf has been found ==========*)   
walther@59691
   150
"~~~~~ fun scan_dn2 , args:"; val (((pt, p), ctxt), (ist as {env, eval, ...}), t)
walther@59686
   151
  = (xxx, (ist |> path_down [R]), e);
walther@59636
   152
walther@59672
   153
  val (a', STac stac) =
walther@59672
   154
  (*case*) handle_leaf "next  " th sr (get_subst ist) t (*of*);
walther@59686
   155
"~~~~~ fun handle_leaf , args:"; val (call, thy, srls, (E, (a, v)), t)
walther@59686
   156
  = ("next  ", th, sr, (get_subst ist), t);
walther@59686
   157
walther@59636
   158
(*+*)val [(Free ("t_t", Tt_t), Const ("HOL.eq", _) $ (Const ("Groups.plus_class.plus", _) $ Free ("-1", _) $ Free ("x", _)) $ Free ("0", _)),
walther@59636
   159
    (Free ("v", Tv), Free ("x", Tx))] = E (* THE WRONG TYPES IN E ..(TODO.4)*)
walther@59636
   160
walther@59636
   161
(*+*)val TFree ("'z", ["HOL.type"]) = Tt_t;
walther@59686
   162
(*+*)val Type ("Real.real", []) = Tv;
walther@59686
   163
(*+*)val Type ("Real.real", []) = Tx;
walther@59636
   164
walther@59636
   165
(*+*)val SOME (Const ("empty", Ta)) = a;
walther@59686
   166
(*+*)val Type ("'a", []) = Ta;
walther@59686
   167
(*+*)if term2str v = "x = 0 + -1 * -1" then () else error "handle_leaf changed";
walther@59686
   168
(*+*)val Type ("Real.real", []) = Tv;
walther@59636
   169
walther@59636
   170
    (*case*) Prog_Tac.subst_stacexpr E a v t (*of*);
walther@59636
   171
"~~~~~ fun subst_stacexpr , args:"; val (E, a, v, (t as (*2*)(Const ("Prog_Tac.Rewrite'_Inst", _) $ _ $ _)))
walther@59636
   172
  = (E, a, v, t);
walther@59636
   173
walther@59636
   174
(*+*)val [(Free ("t_t", Tt_t), Const ("HOL.eq", _) $ (Const ("Groups.plus_class.plus", _) $ Free ("-1", _) $ Free ("x", _)) $ Free ("0", _)),
walther@59636
   175
    (Free ("v", Tv), Free ("x", Tx)) ] = E ;      (* THIS IS CORRECT*)
walther@59636
   176
walther@59636
   177
(*+*)term2str t = "Rewrite_Inst [(''bdv'', v)] ''risolate_bdv_add''";
walther@59636
   178
(*+*)val Const ("Prog_Tac.Rewrite'_Inst", _)
walther@59636
   179
  $ (Const ("List.list.Cons", _) 
walther@59636
   180
    $ ((Const ("Product_Type.Pair", _) $ _(*''bdv''*) $ Free ("v", Tv))) 
walther@59636
   181
      $ Const ("List.list.Nil", _))
walther@59636
   182
  $ _ = t;
walther@59636
   183
(*+*)val Type ("Real.real",[]) = Tv;   (* Free ("v", Tv) WRONG TYPE*)
walther@59636
   184
(* THUS (*TODO.*): the "v" (argument of Prog + Prog_Tac ) must get the appropriate type "real" *)
walther@59636
   185
walther@59636
   186
    val SOME a' = (*case*) a (*of*);
walther@59636
   187
walther@59636
   188
"~~~~~ from subst_stacexpr to handle_leaf return val:"; val (a', Celem.STac stac) =
walther@59636
   189
  ((a, Celem.STac (subst_atomic E (t $ a'))));
walther@59697
   190
  val stac' = Rewrite.eval_listexpr_ (Celem.assoc_thy thy) srls (subst_atomic (update_opt E (a,v)) stac)
walther@59636
   191
  (*------------------------------------------- HERE IS A SECOND subst_atomic ?!?*)
walther@59636
   192
;
walther@59691
   193
"~~~~~ from handle_leaf to scan_dn2 return val:"; val (a', Celem.STac stac) = (a', Celem.STac stac);
walther@59636
   194
  val (m,m') = (stac2tac_ : ctree -> theory -> term -> input * T) pt (Celem.assoc_thy th) stac;
walther@59636
   195
  case m of
wneuper@59493
   196
(**)Rewrite_Inst ([_(*"(''bdv'', x)"*)], ("risolate_bdv_add", _)) => ();
walther@59636
   197
    (*case*) Applicable.applicable_in p pt m (*of*);
wneuper@59493
   198
wneuper@59571
   199
"~~~~~ fun applicable_in, args:"; val ((p, p_), pt, (m as Tactic.Rewrite_Inst (subs, thm''))) =
wneuper@59493
   200
  (p, pt, m);
wneuper@59493
   201
(*if*) member op = [Pbl, Met] p_ (* = false  in isabisac*);
wneuper@59493
   202
        val pp = par_pblobj pt p;
wneuper@59493
   203
        val thy' = get_obj g_domID pt pp;
wneuper@59493
   204
        val thy = Celem.assoc_thy thy';
wneuper@59493
   205
        val {rew_ord' = ro', erls = erls, ...} = Specify.get_met (get_obj g_metID pt pp);
wneuper@59493
   206
        val (f, _) = case p_ of (*p 12.4.00 unnecessary*)
wneuper@59493
   207
                      Frm => (get_obj g_form pt p, p)
wneuper@59493
   208
                    | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
wneuper@59493
   209
                    | _ => error ("applicable_in: call by " ^ pos'2str (p, p_));
wneuper@59493
   210
          val subst = Selem.subs2subst thy subs;
walther@59635
   211
val SOME (f', asm) = (*case*) Rewrite.rewrite_inst_ thy (Rule.assoc_rew_ord ro') erls false subst (snd thm'') f (*of*)
wneuper@59493
   212
;
wneuper@59571
   213
Chead.Appl (Tactic.Rewrite_Inst' (thy', ro', erls, false, subst, thm'', f, (f', asm)))
walther@59636
   214
;
walther@59636
   215
"~~~~~ fun rewrite_inst_ , args:"; val (thy, rew_ord, rls, put_asm, subst, thm, ct) =
walther@59636
   216
  (thy, (Rule.assoc_rew_ord ro'), erls, false, subst, (snd thm''), f);
walther@59636
   217
walther@59636
   218
"~~~~~ fun rewrite__ , args:"; val (thy, i, bdv, tless, rls, put_asm, thm, ct) =
walther@59636
   219
  (thy, 1, subst, rew_ord, rls, put_asm, thm, ct);
walther@59636
   220
    val (t', asms, _ (*lrd*), rew) = rew_sub thy i bdv tless rls put_asm ([(*root of the term*)]: Celem.lrd list)
walther@59636
   221
		  (((TermC.inst_bdv bdv) o Calc.norm o #prop o Thm.rep_thm) thm) ct
walther@59636
   222
;
walther@59636
   223
"~~~~~ fun rew_sub , args:"; val (thy, i, bdv, tless, rls, put_asm, lrd, r, t) =
walther@59636
   224
  (thy, i, bdv, tless, rls, put_asm, ([(*root of the term*)]: Celem.lrd list),
walther@59636
   225
		  (((TermC.inst_bdv bdv) o Calc.norm o #prop o Thm.rep_thm) thm), ct);
walther@59636
   226
walther@59636
   227
(*+*)val [(Free ("bdv", Tbdv), Free ("x", Tv))] = bdv
walther@59636
   228
(*+*)val Type ("Real.real",[]) = Tbdv
walther@59636
   229
(*+*)val Type ("Real.real",[]) = Tv;
walther@59636
   230
walther@59636
   231
    val (lhs, rhs) = (HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r
walther@59636
   232
    val r' = (Envir.subst_term (Pattern.match thy (lhs, t) (Vartab.empty, Vartab.empty)) r)
walther@59636
   233
(*+*) handle Pattern.MATCH => @{term aaaaaaaaaaaaaaa} (* <<<<<<<<<-----------------(*TODO.90*)*)
walther@59636
   234
    val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems) (Logic.count_prems r', [], r'))
walther@59636
   235
    val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r'
walther@59636
   236