test/Tools/isac/Minisubpbl/250-Rewrite_Set-from-method.sml
author wneuper <walther.neuper@jku.at>
Mon, 19 Jul 2021 17:29:35 +0200
changeset 60336 dcb37736d573
parent 60331 40eb8aa2b0d6
child 60529 a823f87dd5aa
permissions -rw-r--r--
introduce ALL valid const_name in test/*
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 ----------";
walther@59997
     9
val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
wneuper@59411
    10
val (dI',pI',mI') =
walther@59997
    11
  ("Test", ["sqroot-test", "univariate", "equation", "test"],
walther@59997
    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
walther@59932
    23
(*/------------------- begin step into 1 ---------------------------------------------------\*)
wneuper@59582
    24
(*[1], Res*)val (p'''_',_,f,nxt'''_',_,pt'''_') = me nxt'''' p'''' [] pt'''';(*nxt = Rewrite_Set "Test_simplify"*)
wneuper@59582
    25
walther@59959
    26
(*+*)if p'''' = ([1],  Frm) andalso f'''' = Test_Out.FormKF "x + 1 = 2"
walther@59932
    27
(*+*)then case nxt'''' of Rewrite_Set _ => () | _ => error "start of test CHANGED 1"
walther@59932
    28
(*+*)else error "250-Rewrite_Set-from-method.sml: start of test CHANGED";
wneuper@59411
    29
walther@59749
    30
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt'''', p'''', [], pt'''');
walther@59806
    31
val ("ok", (_, _, ptp''''')) = (*case*)
walther@59806
    32
      Step.by_tactic tac (pt, p) (*of*);
walther@59806
    33
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
walther@59921
    34
val Applicable.Yes m = (*case*) Step.check tac (pt, p) (*of*);
walther@59755
    35
  (*if*) Tactic.for_specify' m; (*false*)
wneuper@59482
    36
walther@59806
    37
Step_Solve.by_tactic m ptp;
walther@59921
    38
"~~~~~ fun by_tactic , args:"; val (m, (pt, po as (p, p_))) = (m, ptp);
walther@60154
    39
  (*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) (* = else*);
wneuper@59482
    40
	      val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
    41
	      val (is, sc) = LItool.resume_prog thy' (p,p_) pt;
wneuper@59482
    42
walther@59851
    43
  val Safe_Step (_, _, Rewrite_Set' (_, _, Rule_Set.Repeat {id = "norm_equation", ...}, _, _)) = (*case*)
walther@59686
    44
          locate_input_tactic sc (pt, po) (fst is) (snd is) m  (*of*);
walther@59692
    45
"~~~~~ fun locate_input_tactic , args:"; val (Rule.Prog progr, cstate, istate, ctxt, tac)
wneuper@59569
    46
     = (sc, (pt, po), (fst is), (snd is), m);
wneuper@59569
    47
       val srls = get_simplifier cstate;
wneuper@59569
    48
walther@59690
    49
         (*case*) scan_to_tactic1 (progr, (cstate, ctxt, tac)) istate (*of*);
walther@59692
    50
"~~~~~ fun scan_to_tactic1 , args:"; val ((prog, (cctt as ((_, p), _, _))), (Istate.Pstate (ist as {path, ...})))
walther@59686
    51
  = ((progr, (cstate, ctxt, tac)), istate);
walther@59686
    52
   (*if*) path = [] orelse ((last_elem o fst) p = 0 andalso snd p = Res) (*then*);
wneuper@59482
    53
walther@59718
    54
           scan_dn1 cctt (ist |> set_path [R] |> set_or ORundef) (Program.body_of prog);
wenzelm@60309
    55
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const (\<^const_name>\<open>Let\<close>, _) $ e $ (Abs (id, T, b))))
walther@59718
    56
  = (cctt, (ist |> set_path [R] |> set_or ORundef), (Program.body_of prog));
wneuper@59482
    57
walther@59851
    58
val Accept_Tac1 (_, _, Rewrite_Set' (_, _, Rule_Set.Repeat {id = "norm_equation", ...}, _, _)) = (*case*)
walther@59691
    59
           scan_dn1 xxx (ist |> path_down [L, R]) e (*of*);
walther@60336
    60
"~~~~~ fun scan_dn1, args:"; val ((xxx as (cstate, _, _)), ist, (Const (\<^const_name>\<open>Chain\<close>(*1*),_) $e1 $ e2 $ a)) =
walther@59684
    61
  (xxx, (ist |> path_down [L, R]), e);
wneuper@59482
    62
walther@59718
    63
val Accept_Tac1 _ =  (*case*)
walther@59691
    64
           scan_dn1 xxx (ist |> path_down_form ([L, L, R], a)) e1 (*of*);
walther@60336
    65
"~~~~~ fun scan_dn1, args:"; val (xxx, ist, (Const (\<^const_name>\<open>Try\<close>(*1*),_) $ e)) =
walther@59684
    66
  (xxx, (ist |> path_down_form ([L, L, R], a)), e1);
wneuper@59482
    67
walther@59868
    68
(*+*)UnparseC.term e1 = "Try (Rewrite_Set ''norm_equation'')"  (*in isabisac*);
wneuper@59482
    69
walther@59718
    70
val Accept_Tac1 _ =  (*case*)
walther@59691
    71
           scan_dn1 xxx (ist |> path_down_form ([L, R], a)) e (*of*);
walther@59684
    72
    (*======= end of scanning tacticals, a leaf =======*)
walther@59722
    73
"~~~~~ fun scan_dn1 , args:"; val (((pt, p), ctxt, tac), (ist as {env, eval, or, ...}), t) =
walther@59684
    74
  (xxx, (ist |> path_down_form ([L, R], a)), e);
walther@59772
    75
val (Program.Tac stac, a') = (*case*) check_leaf "locate" ctxt eval (get_subst ist) t (*of*);
walther@59844
    76
val Associated (Rewrite_Set' _, _, _) = (*case*)
walther@59684
    77
           associate pt ctxt (m, stac) (*of*);
wneuper@59578
    78
"~~~~~ fun associate, args:"; val (_, ctxt, (m as Tactic.Rewrite_Set' (_, _, rls, f, (f', _))), 
walther@60336
    79
      (Const (\<^const_name>\<open>Rewrite_Set\<close>, _) $ rls_ $ f_)) = (pt, ctxt, m, stac);
wneuper@59482
    80
walther@59867
    81
(*+*)if Rule_Set.id rls = HOLogic.dest_string rls_ then () else error "Prog_Tac.associate changed";
wneuper@59482
    82
walther@59804
    83
"~~~~~ continue me[1] after Step.by_tactic";
wneuper@59482
    84
    val (pt, p) = ptp''''';
walther@59765
    85
(* isabisac17: val ("helpless", _) = (*case*) Step.do_next p ((pt, Pos.e_pos'),[]) (*of*)*)
wneuper@59411
    86
"~~~~~ fun step, args:"; val ((ip as (_, p_)), (ptp as (pt,p), tacis)) = (p, ((pt, e_pos'),[]));
wneuper@59411
    87
val pIopt = get_pblID (pt,ip);
walther@59694
    88
(*if*) ip = ([], Pos.Res) = false;
wneuper@59411
    89
val _ = (*case*) tacis (*of*);
wneuper@59411
    90
(*if*) ip = p = false;
walther@60017
    91
(*if*) member op = [Pbl, Met] p_ = false;
wneuper@59411
    92
walther@59760
    93
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) = (pt, ip);
walther@60154
    94
   MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) = false;
walther@60154
    95
    (*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p)(*else*);
wneuper@59411
    96
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
    97
	      val ((ist, ctxt), sc) = LItool.resume_prog thy' (p,p_) pt;
wneuper@59411
    98
walther@59734
    99
	      val Next_Step (_, _, _) =
walther@59791
   100
           (*case*)  LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59772
   101
"~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), Istate.Pstate ist, ctxt)
walther@59723
   102
  = (sc, (pt, pos), ist, ctxt);
wneuper@59411
   103
walther@59770
   104
val Accept_Tac (Rewrite_Set' _, _, _) = (*case*)
walther@59769
   105
           scan_to_tactic (prog, (ptp, ctxt)) (Istate.Pstate ist) (*of*);
walther@59769
   106
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cct), (Istate.Pstate (ist as {path, ...})))
walther@59699
   107
  = ((prog, (ptp, ctxt)), (Istate.Pstate ist));
walther@59686
   108
  (*if*) 0 = length path (*else*);
wneuper@59411
   109
walther@59770
   110
val Accept_Tac (Rewrite_Set' _, _, _) =
walther@59785
   111
           go_scan_up (prog, cct) (trans_scan_up ist |> set_found);
walther@59784
   112
"~~~~~ and go_scan_up , args:"; val ((yyy as (prog, _)), (ist as {env, path, found_accept, ...})) =
walther@59785
   113
  ((prog, cct), (trans_scan_up ist |> set_found));
walther@59686
   114
    (*if*) 1 < length path (*then*);
wneuper@59411
   115
walther@59769
   116
           scan_up yyy (ist |> path_up) (go_up path prog);
walther@60336
   117
"~~~~~ fun scan_up , args:"; val (yyy, ist, (Const (\<^const_name>\<open>Try\<close>(*2*), _) $ _)) =
walther@59699
   118
  (yyy, (ist |> path_up), (go_up path prog));
walther@59932
   119
(*\------------------- end step into 1 -----------------------------------------------------/*)
wneuper@59582
   120
                                                 
walther@59932
   121
(*                                               nxt'''_' = Rewrite_Set "Test_simplify"*)
walther@59932
   122
(*/------------------- begin step into 2 ---------------------------------------------------\*)
walther@59921
   123
(*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt'''_' p'''_' [] pt'''_';(*Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])*)
walther@59921
   124
(*+*)val p'''''_'' = p; (* keep for final test*)
walther@59749
   125
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt'''_', p'''_', [], pt'''_');
wneuper@59582
   126
    val (pt, p) = 
walther@59804
   127
	    (*Step.by_tactic is here for testing by me; step would suffice in me*)
walther@59804
   128
	    case Step.by_tactic tac (pt, p) of
wneuper@59582
   129
		    ("ok", (_, _, ptp)) => ptp
wneuper@59582
   130
	    | ("unsafe-ok", (_, _, ptp)) => ptp
wneuper@59582
   131
	    | ("not-applicable",_) => (pt, p)
wneuper@59582
   132
	    | ("end-of-calculation", (_, _, ptp)) => ptp
wneuper@59582
   133
	    | ("failure", _) => error "sys-error"
wneuper@59582
   134
	    | _ => error "me: uncovered case"
wneuper@59582
   135
walther@59765
   136
  (*case*) Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
wneuper@59582
   137
"~~~~~ fun step , args:"; val ((ip as (_, p_)), (ptp as (pt,p), tacis))
walther@59694
   138
  = (p, ((pt, Pos.e_pos'), []));
wneuper@59582
   139
     val pIopt = get_pblID (pt,ip);
walther@59694
   140
    (*if*) ip = ([], Pos.Res) (*else*);
wneuper@59582
   141
      val _ = (*case*) tacis (*of*);
wneuper@59582
   142
      val SOME _ = (*case*) pIopt (*of*);
walther@60017
   143
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ (**else*);
wneuper@59582
   144
walther@59760
   145
           Step_Solve.do_next (pt, ip);
walther@59760
   146
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) = (pt, ip);
walther@60154
   147
    (*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) (*else*);
wneuper@59582
   148
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   149
	      val ((ist, ctxt), sc) = LItool.resume_prog thy' (p,p_) pt;
wneuper@59582
   150
walther@59734
   151
	      val Next_Step (_, _, _) =
walther@59791
   152
           (*case*)  LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59772
   153
"~~~~~ fun find_next_step , args:"; val (Rule.Prog prog, (ptp as(pt, (p, _))), Istate.Pstate ist, ctxt)
walther@59723
   154
  = (sc, (pt, pos), ist, ctxt);
wneuper@59582
   155
walther@59770
   156
val Accept_Tac (_, _, _) = (*case*)
walther@59769
   157
           scan_to_tactic (prog, (ptp, ctxt)) (Istate.Pstate ist) (*of*);
walther@59921
   158
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cc), (Istate.Pstate (ist as {path, ...})))
walther@59699
   159
  = ((prog, (ptp, ctxt)), (Istate.Pstate ist));
walther@59686
   160
    (*if*) 0 = length path (*else*);
wneuper@59582
   161
walther@59785
   162
       go_scan_up (prog, cc) (trans_scan_up ist |> set_found);
walther@59784
   163
"~~~~~ fun go_scan_up , args:"; val ((yyy as (prog, _)), (ist as {env, path, found_accept, ...}))
walther@59785
   164
  = ((prog, cct), (trans_scan_up ist |> set_found));
walther@59686
   165
    (*if*) 1 < length path (*then*);
wneuper@59582
   166
walther@59769
   167
           scan_up yyy (ist |> path_up) (go_up path prog);
walther@60336
   168
"~~~~~ and scan_up , args:"; val (yyy, ist, (Const (\<^const_name>\<open>Try\<close>(*1*),_) $ _ ))
walther@59699
   169
  = (yyy, (ist |> path_up), (go_up path prog));
wneuper@59582
   170
walther@59785
   171
           go_scan_up yyy (ist |> set_found);
walther@59784
   172
"~~~~~ fun go_scan_up , args:"; val ((yyy as (prog, _)), (ist as {env, path, found_accept, ...}))
walther@59785
   173
  = (yyy, (ist |> set_found));
walther@59686
   174
    (*if*) 1 < length path (*then*);
wneuper@59582
   175
walther@59769
   176
           scan_up yyy (ist |> path_up) (go_up path prog);
walther@60336
   177
"~~~~~ and scan_up , args:"; val (yyy, ist, (Const (\<^const_name>\<open>Chain\<close>(*2*), _) $ _ $ _))
walther@59723
   178
  = (yyy, (ist |> path_up), (go_up path prog));
wneuper@59582
   179
walther@59769
   180
           go_scan_up yyy ist;
walther@59784
   181
"~~~~~ and go_scan_up , args:"; val ((yyy as (prog, _)), (ist as {env, path, found_accept, ...}))
walther@59686
   182
  = (yyy, ist);
walther@59686
   183
    (*if*) 1 < length path (*then*);
wneuper@59582
   184
walther@59769
   185
           scan_up yyy (ist |> path_up) (go_up path prog);
walther@60336
   186
"~~~~~ fun scan_up , args:"; val (yyy, ist, (Const (\<^const_name>\<open>Chain\<close>(*1*), _) $ _ $ _ $ _))
walther@59723
   187
  = (yyy, (ist |> path_up), (go_up path prog));
wneuper@59582
   188
walther@59769
   189
           go_scan_up yyy ist;
walther@59784
   190
"~~~~~ and go_scan_up , args:"; val ((yyy as (prog, _)), (ist as {env, path, found_accept, ...}))
walther@59686
   191
  = (yyy, ist);
walther@59686
   192
    (*if*) 1 < length path (*then*);
wneuper@59582
   193
walther@59769
   194
           scan_up yyy (ist |> path_up) (go_up path prog);
wenzelm@60309
   195
"~~~~~ fun scan_up , args:"; val ((yyy as (prog, xxx)), (ist as {found_accept, ...}), (Const (\<^const_name>\<open>Let\<close>(*1*), _) $ _))
walther@59723
   196
  = (yyy, (ist |> path_up), (go_up path prog));
walther@59784
   197
    (*if* ) found_accept = Napp_ ( *else*);
walther@59723
   198
        val (i, body) = check_Let_up ist prog;
wneuper@59582
   199
walther@59769
   200
  (*case*) scan_dn xxx (ist |> path_up_down [R, D] |> upd_env i) body (*of*);
wenzelm@60309
   201
"~~~~~ fun scan_dn , args:"; val (xxx, ist, (Const (\<^const_name>\<open>Let\<close>(*1*),_) $ e $ (Abs (i,T,b))))
walther@59698
   202
  = (xxx, (ist |> path_up_down [R, D] |> upd_env i), body);
wneuper@59582
   203
walther@59770
   204
  val Accept_Tac (Subproblem' _, _, _) = (*case*)
walther@59769
   205
           scan_dn xxx (ist |> path_down [L, R]) e (*of*);
walther@59684
   206
    (*========== a leaf has been found ==========*)   
walther@59769
   207
"~~~~~ fun scan_dn , args:"; val (((pt, p), ctxt), (ist as {eval, ...}), t)
walther@59684
   208
  = (xxx, (ist |> path_down [L, R]), e);
walther@59790
   209
        val (Program.Tac stac, a') = (*case*) LItool.check_leaf  "next  " ctxt eval (get_subst ist) t (*of*);
walther@59672
   210
walther@59825
   211
   (*val m =*)
walther@59825
   212
Sub_Problem.tac_from_prog pt stac;
walther@60336
   213
"~~~~~ fun tac_from_prog , args:"; val (pt, _, (stac as Const (\<^const_name>\<open>SubProblem\<close>, _) $ spec' $ ags'))
walther@59722
   214
  = (pt, (Proof_Context.theory_of ctxt), stac);
walther@59618
   215
      val (dI, pI, mI) = Prog_Tac.dest_spec spec'
walther@59965
   216
      val thy = ThyC.sub_common (ThyC.get_theory dI, rootthy pt);
wneuper@59582
   217
	    val ags = TermC.isalist2list ags';
wneuper@59582
   218
	      (*if*) mI = ["no_met"] (*else*);
wneuper@59582
   219
	    val (pI, pors, mI) = 
walther@59987
   220
        (pI, (M_Match.arguments thy ((#ppc o Problem.from_store) pI) ags)
wneuper@59582
   221
		       handle ERROR "actual args do not match formal args"
walther@59987
   222
		       => (M_Match.arguments_msg pI stac ags(*raise exn*); []), mI)
walther@59987
   223
      val (fmz_, vals) = O_Model.values' pors;
walther@59970
   224
	    val {cas,ppc,thy,...} = Problem.from_store pI
walther@59880
   225
	    val dI = Context.theory_name thy (*.take dI from _refined_ pbl.*)
walther@59965
   226
	    val dI = Context.theory_name (ThyC.sub_common (ThyC.get_theory dI, rootthy pt));
walther@60017
   227
      val ctxt = ContextC.initialise dI (map TermC.vars vals |> flat |> distinct op =);
walther@59932
   228
(*\------------------- end step into 2 -----------------------------------------------------/*)
wneuper@59582
   229
walther@59921
   230
val p = p'''''_''; (*kept from before stepping into detail*)
walther@59921
   231
walther@60324
   232
if p = ([2], Res) andalso f2str f = "- 1 + x = 0" then
wneuper@59582
   233
  case nxt of
walther@59749
   234
    (Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])) => ()
wneuper@59582
   235
  | _ => error "Minisubpbl/250-Rewrite_Set-from-method changed 1"
wneuper@59582
   236
else error "Minisubpbl/250-Rewrite_Set-from-method changed 2";