test/Tools/isac/Minisubpbl/250-Rewrite_Set-from-method.sml
author Walther Neuper <walther.neuper@jku.at>
Thu, 19 Dec 2019 16:41:57 +0100
changeset 59749 cc3b1807f72e
parent 59743 e6d97ceba3fc
child 59751 fa26464c66bf
permissions -rw-r--r--
cleanup fun solve, shift from Solve --> Step_Solve
wneuper@59569
     1
(* Title:  "Minisubpbl/250-Rewrite_Set-from-method.sml"
wneuper@59569
     2
   Author: Walther Neuper 1105
wneuper@59411
     3
   (c) copyright due to lincense terms.
wneuper@59411
     4
*)
wneuper@59411
     5
wneuper@59564
     6
"----------- Minisubpbl/250-Rewrite_Set-from-method.sml ----------";
wneuper@59564
     7
"----------- Minisubpbl/250-Rewrite_Set-from-method.sml ----------";
wneuper@59564
     8
"----------- Minisubpbl/250-Rewrite_Set-from-method.sml ----------";
wneuper@59411
     9
val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
wneuper@59411
    10
val (dI',pI',mI') =
wneuper@59411
    11
  ("Test", ["sqroot-test","univariate","equation","test"],
wneuper@59411
    12
   ["Test","squ-equ-test-subpbl1"]);
wneuper@59411
    13
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
wneuper@59411
    14
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59411
    15
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59411
    16
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59411
    17
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59411
    18
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59411
    19
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59582
    20
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "squ-equ-test-subpbl1"]*);
walther@59670
    21
(*[1], Frm*)val (p'''',_,f'''',nxt'''',_,pt'''') = me nxt p [] pt; (*nxt'''' = Rewrite_Set "norm_equation"*)
wneuper@59411
    22
wneuper@59582
    23
(*//--1 begin step into relevant call -----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----\\
wneuper@59582
    24
      1 relevant for original decomposition                                                     *)
wneuper@59582
    25
(*[1], Res*)val (p'''_',_,f,nxt'''_',_,pt'''_') = me nxt'''' p'''' [] pt'''';(*nxt = Rewrite_Set "Test_simplify"*)
wneuper@59582
    26
walther@59749
    27
if p'''' = ([1],  Frm) andalso f'''' = FormKF "x + 1 = 2"
walther@59749
    28
then case nxt'''' of Rewrite_Set _ => () | _ => error "start of test CHANGED 1"
walther@59749
    29
else error "250-Rewrite_Set-from-method.sml: start of test CHANGED";
wneuper@59411
    30
wneuper@59482
    31
(* val (p,_,f,nxt,_,pt) = ERROR WAS: nxt = ("Empty_Tac",..*) me nxt p [] pt;
walther@59691
    32
(*                        ERROR WAS: scan_dn1: call by ([3], Pbl) *)
walther@59749
    33
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt'''', p'''', [], pt'''');
wneuper@59411
    34
walther@59691
    35
(*ERROR WAS: scan_dn1: call by ([3], Pbl)*)
wneuper@59482
    36
val ("ok", (_, _, ptp''''')) = (*case*) locatetac tac (pt,p) (*of*);
wneuper@59482
    37
"~~~~~ fun locatetac, args:"; val (tac, (ptp as (pt, p))) = (tac, (pt,p));
wneuper@59482
    38
      val (mI, m) = Solve.mk_tac'_ tac;
walther@59737
    39
val Applicable.Appl m = (*case*) Applicable.applicable_in p pt m (*of*);
wneuper@59482
    40
member op = Solve.specsteps mI (* = false*);
wneuper@59482
    41
walther@59749
    42
           loc_solve_ m ptp ;  (* scan_dn1: call by ([3], Pbl)*)
walther@59749
    43
"~~~~~ fun loc_solve_, args:"; val (m, (pt, pos)) = (m, ptp);
walther@59691
    44
           solve m (pt, pos);  (* scan_dn1: call by ([3], Pbl)*)
walther@59686
    45
    (* ======== general tactic as fall through ======== *)
walther@59749
    46
"~~~~~ fun solve , args:"; val (m, (pt, po as (p, p_))) = (m, (pt, pos));
walther@59686
    47
  (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (* = else*);
wneuper@59482
    48
	      val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59686
    49
	      val (_, is, sc) = Lucin.from_pblobj_or_detail' thy' (p,p_) pt;
wneuper@59482
    50
walther@59686
    51
  val Safe_Step (_, _, Rewrite_Set' (_, _, Rls {id = "norm_equation", ...}, _, _)) = (*case*)
walther@59686
    52
          locate_input_tactic sc (pt, po) (fst is) (snd is) m  (*of*);
walther@59692
    53
"~~~~~ fun locate_input_tactic , args:"; val (Rule.Prog progr, cstate, istate, ctxt, tac)
wneuper@59569
    54
     = (sc, (pt, po), (fst is), (snd is), m);
wneuper@59569
    55
       val srls = get_simplifier cstate;
wneuper@59569
    56
walther@59690
    57
         (*case*) scan_to_tactic1 (progr, (cstate, ctxt, tac)) istate (*of*);
walther@59692
    58
"~~~~~ fun scan_to_tactic1 , args:"; val ((prog, (cctt as ((_, p), _, _))), (Istate.Pstate (ist as {path, ...})))
walther@59686
    59
  = ((progr, (cstate, ctxt, tac)), istate);
walther@59686
    60
   (*if*) path = [] orelse ((last_elem o fst) p = 0 andalso snd p = Res) (*then*);
wneuper@59482
    61
walther@59718
    62
           scan_dn1 cctt (ist |> set_path [R] |> set_or ORundef) (Program.body_of prog);
walther@59691
    63
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const ("HOL.Let", _) $ e $ (Abs (id, T, b))))
walther@59718
    64
  = (cctt, (ist |> set_path [R] |> set_or ORundef), (Program.body_of prog));
wneuper@59482
    65
walther@59718
    66
val Accept_Tac1 (_, _, Rewrite_Set' (_, _, Rls {id = "norm_equation", ...}, _, _)) = (*case*)
walther@59691
    67
           scan_dn1 xxx (ist |> path_down [L, R]) e (*of*);
walther@59691
    68
"~~~~~ fun scan_dn1, args:"; val ((xxx as (cstate, _, _)), ist, (Const ("Tactical.Chain"(*1*),_) $e1 $ e2 $ a)) =
walther@59684
    69
  (xxx, (ist |> path_down [L, R]), e);
wneuper@59482
    70
walther@59718
    71
val Accept_Tac1 _ =  (*case*)
walther@59691
    72
           scan_dn1 xxx (ist |> path_down_form ([L, L, R], a)) e1 (*of*);
walther@59691
    73
"~~~~~ fun scan_dn1, args:"; val (xxx, ist, (Const ("Tactical.Try"(*1*),_) $ e)) =
walther@59684
    74
  (xxx, (ist |> path_down_form ([L, L, R], a)), e1);
wneuper@59482
    75
walther@59684
    76
(*+*)term2str e1 = "Try (Rewrite_Set ''norm_equation'')"  (*in isabisac*);
wneuper@59482
    77
walther@59718
    78
val Accept_Tac1 _ =  (*case*)
walther@59691
    79
           scan_dn1 xxx (ist |> path_down_form ([L, R], a)) e (*of*);
walther@59684
    80
    (*======= end of scanning tacticals, a leaf =======*)
walther@59722
    81
"~~~~~ fun scan_dn1 , args:"; val (((pt, p), ctxt, tac), (ist as {env, eval, or, ...}), t) =
walther@59684
    82
  (xxx, (ist |> path_down_form ([L, R], a)), e);
walther@59722
    83
val (Program.Tac stac, a') = (*case*) interpret_leaf "locate" ctxt eval (get_subst ist) t (*of*);
walther@59684
    84
val Ass (Rewrite_Set' _, _, _) = (*case*)
walther@59684
    85
           associate pt ctxt (m, stac) (*of*);
wneuper@59578
    86
"~~~~~ fun associate, args:"; val (_, ctxt, (m as Tactic.Rewrite_Set' (_, _, rls, f, (f', _))), 
walther@59635
    87
      (Const ("Prog_Tac.Rewrite'_Set", _) $ rls_ $ f_)) = (pt, d, m, stac);
wneuper@59482
    88
walther@59722
    89
(*+*)if Rule.id_rls rls = HOLogic.dest_string rls_ then () else error "Prog_Tac.associate changed";
wneuper@59482
    90
wneuper@59482
    91
"~~~~~ continue me[1] after locatetac";
wneuper@59482
    92
    val (pt, p) = ptp''''';
walther@59694
    93
(* isabisac17: val ("helpless", _) = (*case*) step p ((pt, Pos.e_pos'),[]) (*of*)*)
wneuper@59411
    94
"~~~~~ fun step, args:"; val ((ip as (_, p_)), (ptp as (pt,p), tacis)) = (p, ((pt, e_pos'),[]));
wneuper@59411
    95
val pIopt = get_pblID (pt,ip);
walther@59694
    96
(*if*) ip = ([], Pos.Res) = false;
wneuper@59411
    97
val _ = (*case*) tacis (*of*);
wneuper@59411
    98
(*if*) ip = p = false;
wneuper@59411
    99
(*if*) member op = [Pbl, Met] p_ = false;
wneuper@59411
   100
walther@59684
   101
"~~~~~ and do_solve_step , args:"; val (ptp as (pt, pos as (p, p_))) = (pt, ip);
walther@59686
   102
   e_metID = get_obj g_metID pt (par_pblobj pt p) = false;
walther@59684
   103
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p)(*else*);
wneuper@59411
   104
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59723
   105
	      val (_, (ist, ctxt), sc) = Lucin.from_pblobj_or_detail' thy' (p,p_) pt;
wneuper@59411
   106
walther@59734
   107
	      val Next_Step (_, _, _) =
walther@59743
   108
           (*case*)  find_next_tactic sc (pt, pos) ist ctxt (*of*);
walther@59743
   109
"~~~~~ fun find_next_tactic , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), Istate.Pstate ist, ctxt)
walther@59723
   110
  = (sc, (pt, pos), ist, ctxt);
wneuper@59411
   111
walther@59728
   112
val Accept_Tac2 (Rewrite_Set' _, _, _) = (*case*)
walther@59699
   113
           scan_to_tactic2 (prog, (ptp, ctxt)) (Istate.Pstate ist) (*of*);
walther@59699
   114
"~~~~~ fun scan_to_tactic2 , args:"; val ((prog, cct), (Istate.Pstate (ist as {path, ...})))
walther@59699
   115
  = ((prog, (ptp, ctxt)), (Istate.Pstate ist));
walther@59686
   116
  (*if*) 0 = length path (*else*);
wneuper@59411
   117
walther@59728
   118
val Accept_Tac2 (Rewrite_Set' _, _, _) =
walther@59699
   119
           go_scan_up2 (prog, cct) (trans_scan_up2 ist |> set_appy Skip_);
walther@59699
   120
"~~~~~ and go_scan_up2 , args:"; val ((yyy as (prog, _)), (ist as {env, path, finish, ...})) =
walther@59699
   121
  ((prog, cct), (trans_scan_up2 ist |> set_appy Skip_));
walther@59686
   122
    (*if*) 1 < length path (*then*);
wneuper@59411
   123
walther@59699
   124
           scan_up2 yyy (ist |> path_up) (go_up path prog);
walther@59691
   125
"~~~~~ fun scan_up2 , args:"; val (yyy, ist, (Const ("Tactical.Try"(*2*), _) $ _)) =
walther@59699
   126
  (yyy, (ist |> path_up), (go_up path prog));
wneuper@59582
   127
wneuper@59582
   128
(*\\--1 end step into relevant call ----------------------------------------------------------//*)
wneuper@59582
   129
                                                 
wneuper@59582
   130
(*                                               nxt'''_' = Rewrite_Set "Test_simplify"
wneuper@59582
   131
  //--2 begin step into relevant call -----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----\\
wneuper@59582
   132
      2 relevant for exception TERM raised (line 297 of "term.ML"): dest_Free -1 + x = 0                                                           *)
wneuper@59582
   133
(**)val (p,_,f,nxt,_,pt) = me nxt'''_' p'''_' [] pt'''_';(**)
walther@59749
   134
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt'''_', p'''_', [], pt'''_');
wneuper@59582
   135
    val (pt, p) = 
wneuper@59582
   136
	    (*locatetac is here for testing by me; step would suffice in me*)
wneuper@59582
   137
	    case locatetac tac (pt, p) of
wneuper@59582
   138
		    ("ok", (_, _, ptp)) => ptp
wneuper@59582
   139
	    | ("unsafe-ok", (_, _, ptp)) => ptp
wneuper@59582
   140
	    | ("not-applicable",_) => (pt, p)
wneuper@59582
   141
	    | ("end-of-calculation", (_, _, ptp)) => ptp
wneuper@59582
   142
	    | ("failure", _) => error "sys-error"
wneuper@59582
   143
	    | _ => error "me: uncovered case"
wneuper@59582
   144
walther@59694
   145
  (*case*) step p ((pt, Pos.e_pos'), []) (*of*);
wneuper@59582
   146
"~~~~~ fun step , args:"; val ((ip as (_, p_)), (ptp as (pt,p), tacis))
walther@59694
   147
  = (p, ((pt, Pos.e_pos'), []));
wneuper@59582
   148
     val pIopt = get_pblID (pt,ip);
walther@59694
   149
    (*if*) ip = ([], Pos.Res) (*else*);
wneuper@59582
   150
      val _ = (*case*) tacis (*of*);
wneuper@59582
   151
      val SOME _ = (*case*) pIopt (*of*);
walther@59694
   152
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ 
wneuper@59582
   153
  	                    andalso is_none (Ctree.get_obj Ctree.g_env pt (fst p)) (*else*);
wneuper@59582
   154
wneuper@59582
   155
           do_solve_step (pt, ip);
wneuper@59582
   156
"~~~~~ and do_solve_step , args:"; val (ptp as (pt, pos as (p, p_))) = (pt, ip);
wneuper@59582
   157
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*else*);
wneuper@59582
   158
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59723
   159
	      val (srls, (ist, ctxt), sc) = Lucin.from_pblobj_or_detail' thy' (p,p_) pt;
wneuper@59582
   160
walther@59734
   161
	      val Next_Step (_, _, _) =
walther@59743
   162
           (*case*) find_next_tactic sc (pt, pos) ist ctxt (*of*);
walther@59743
   163
"~~~~~ fun find_next_tactic , args:"; val (Rule.Prog prog, (ptp as(pt, (p, _))), Istate.Pstate ist, ctxt)
walther@59723
   164
  = (sc, (pt, pos), ist, ctxt);
wneuper@59582
   165
walther@59728
   166
val Accept_Tac2 (_, _, _) = (*case*)
walther@59699
   167
           scan_to_tactic2 (prog, (ptp, ctxt)) (Istate.Pstate ist) (*of*);
walther@59699
   168
"~~~~~ fun scan_to_tactic2 , args:"; val ((prog, cct), (Istate.Pstate (ist as {path, ...})))
walther@59699
   169
  = ((prog, (ptp, ctxt)), (Istate.Pstate ist));
walther@59686
   170
    (*if*) 0 = length path (*else*);
wneuper@59582
   171
walther@59723
   172
       go_scan_up2 (prog, cc) (trans_scan_up2 ist |> set_appy Skip_);
walther@59723
   173
"~~~~~ fun go_scan_up2 , args:"; val ((yyy as (prog, _)), (ist as {env, path, finish, ...}))
walther@59699
   174
  = ((prog, cct), (trans_scan_up2 ist |> set_appy Skip_));
walther@59686
   175
    (*if*) 1 < length path (*then*);
wneuper@59582
   176
walther@59699
   177
           scan_up2 yyy (ist |> path_up) (go_up path prog);
walther@59723
   178
"~~~~~ and scan_up2 , args:"; val (yyy, ist, (Const ("Tactical.Try"(*1*),_) $ _ ))
walther@59699
   179
  = (yyy, (ist |> path_up), (go_up path prog));
wneuper@59582
   180
walther@59698
   181
           go_scan_up2 yyy (ist |> set_appy Skip_);
walther@59723
   182
"~~~~~ fun go_scan_up2 , args:"; val ((yyy as (prog, _)), (ist as {env, path, finish, ...}))
walther@59698
   183
  = (yyy, (ist |> set_appy Skip_));
walther@59686
   184
    (*if*) 1 < length path (*then*);
wneuper@59582
   185
walther@59723
   186
           scan_up2 yyy (ist |> path_up) (go_up path prog);
walther@59723
   187
"~~~~~ and scan_up2 , args:"; val (yyy, ist, (Const ("Tactical.Chain"(*2*), _) $ _ $ _))
walther@59723
   188
  = (yyy, (ist |> path_up), (go_up path prog));
wneuper@59582
   189
walther@59691
   190
           go_scan_up2 yyy ist;
walther@59699
   191
"~~~~~ and go_scan_up2 , args:"; val ((yyy as (prog, _)), (ist as {env, path, finish, ...}))
walther@59686
   192
  = (yyy, ist);
walther@59686
   193
    (*if*) 1 < length path (*then*);
wneuper@59582
   194
walther@59723
   195
           scan_up2 yyy (ist |> path_up) (go_up path prog);
walther@59691
   196
"~~~~~ fun scan_up2 , args:"; val (yyy, ist, (Const ("Tactical.Chain"(*1*), _) $ _ $ _ $ _))
walther@59723
   197
  = (yyy, (ist |> path_up), (go_up path prog));
wneuper@59582
   198
walther@59691
   199
           go_scan_up2 yyy ist;
walther@59699
   200
"~~~~~ and go_scan_up2 , args:"; val ((yyy as (prog, _)), (ist as {env, path, finish, ...}))
walther@59686
   201
  = (yyy, ist);
walther@59686
   202
    (*if*) 1 < length path (*then*);
wneuper@59582
   203
walther@59723
   204
           scan_up2 yyy (ist |> path_up) (go_up path prog);
walther@59699
   205
"~~~~~ fun scan_up2 , args:"; val ((yyy as (prog, xxx)), (ist as {finish, ...}), (Const ("HOL.Let"(*1*), _) $ _))
walther@59723
   206
  = (yyy, (ist |> path_up), (go_up path prog));
walther@59686
   207
    (*if*) finish = Napp_ (*else*);
walther@59723
   208
        val (i, body) = check_Let_up ist prog;
wneuper@59582
   209
walther@59698
   210
  (*case*) scan_dn2 xxx (ist |> path_up_down [R, D] |> upd_env i) body (*of*);
walther@59691
   211
"~~~~~ fun scan_dn2 , args:"; val (xxx, ist, (Const ("HOL.Let"(*1*),_) $ e $ (Abs (i,T,b))))
walther@59698
   212
  = (xxx, (ist |> path_up_down [R, D] |> upd_env i), body);
wneuper@59582
   213
walther@59728
   214
  val Accept_Tac2 (Subproblem' _, _, _) = (*case*)
walther@59691
   215
           scan_dn2 xxx (ist |> path_down [L, R]) e (*of*);
walther@59684
   216
    (*========== a leaf has been found ==========*)   
walther@59722
   217
"~~~~~ fun scan_dn2 , args:"; val (((pt, p), ctxt), (ist as {eval, ...}), t)
walther@59684
   218
  = (xxx, (ist |> path_down [L, R]), e);
walther@59721
   219
        val (Program.Tac stac, a') = (*case*) Lucin.interpret_leaf  "next  " ctxt eval (get_subst ist) t (*of*);
walther@59672
   220
walther@59722
   221
   (*val (m,m') = Lucin.*) stac2tac_ pt (Proof_Context.theory_of ctxt) stac;
wneuper@59601
   222
"~~~~~ fun stac2tac_ , args:"; val (pt, _, (stac as Const ("Prog_Tac.SubProblem", _) $ spec' $ ags'))
walther@59722
   223
  = (pt, (Proof_Context.theory_of ctxt), stac);
walther@59618
   224
      val (dI, pI, mI) = Prog_Tac.dest_spec spec'
wneuper@59582
   225
      val thy = Stool.common_subthy (Celem.assoc_thy dI, rootthy pt);
wneuper@59582
   226
	    val ags = TermC.isalist2list ags';
wneuper@59582
   227
	      (*if*) mI = ["no_met"] (*else*);
wneuper@59582
   228
	    val (pI, pors, mI) = 
wneuper@59582
   229
        (pI, (Chead.match_ags thy ((#ppc o Specify.get_pbt) pI) ags)
wneuper@59582
   230
		       handle ERROR "actual args do not match formal args"
wneuper@59582
   231
		       => (Chead.match_ags_msg pI stac ags(*raise exn*); []), mI)
wneuper@59582
   232
      val (fmz_, vals) = Chead.oris2fmz_vals pors;
wneuper@59582
   233
	    val {cas,ppc,thy,...} = Specify.get_pbt pI
wneuper@59582
   234
	    val dI = Rule.theory2theory' thy (*.take dI from _refined_ pbl.*)
wneuper@59582
   235
	    val dI = Rule.theory2theory' (Stool.common_subthy (Celem.assoc_thy dI, rootthy pt));
wneuper@59582
   236
      val ctxt = ContextC.initialise dI (map TermC.vars vals |> flat |> distinct);
wneuper@59582
   237
(*\\--2 end step into relevant call ----------------------------------------------------------//*)
wneuper@59582
   238
wneuper@59582
   239
if p = ([2], Res) andalso f2str f = "-1 + x = 0" then
wneuper@59582
   240
  case nxt of
walther@59749
   241
    (Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])) => ()
wneuper@59582
   242
  | _ => error "Minisubpbl/250-Rewrite_Set-from-method changed 1"
wneuper@59582
   243
else error "Minisubpbl/250-Rewrite_Set-from-method changed 2";
wneuper@59582
   244
walther@59723
   245
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Model_Problem*)