test/Tools/isac/Test_Isac.thy
branchdecompose-isar
changeset 42009 5f5807893ceb
parent 42008 384eede0e288
child 42010 85ce1938a811
equal deleted inserted replaced
42008:384eede0e288 42009:5f5807893ceb
   102   use "Minisubpbl/500-met-sub-to-root.sml"
   102   use "Minisubpbl/500-met-sub-to-root.sml"
   103   use "Minisubpbl/600-postcond.sml"
   103   use "Minisubpbl/600-postcond.sml"
   104   ML {*"%%%%%%%%%%%%%%%%% end Minisubpbl %%%%%%%%%%%%%%%%%%%%%%%";*}
   104   ML {*"%%%%%%%%%%%%%%%%% end Minisubpbl %%%%%%%%%%%%%%%%%%%%%%%";*}
   105   ML {*"%%%%%%%%%%%%%%%%% start Interpret.thy %%%%%%%%%%%%%%%%%%";*}
   105   ML {*"%%%%%%%%%%%%%%%%% start Interpret.thy %%%%%%%%%%%%%%%%%%";*}
   106   use "Interpret/mstools.sml"       (*new 2010*)
   106   use "Interpret/mstools.sml"       (*new 2010*)
   107 ML {*
       
   108 (*test/../ctree.sml*)
       
   109 val pt = EmptyPtree;
       
   110 val pt = append_problem [] (e_istate, e_ctxt) e_fmz ([(*oris*)], e_spec, e_term) pt;
       
   111 val ctxt = get_obj g_ctxt pt [];
       
   112 if is_e_ctxt ctxt then () else error "TODO";
       
   113 *}
       
   114   use "Interpret/ctree.sml"         (*!...!see(25)*)
   107   use "Interpret/ctree.sml"         (*!...!see(25)*)
   115   use "Interpret/ptyps.sml"         (*    *)
   108   use "Interpret/ptyps.sml"         (*    *)
   116 (*use "Interpret/generate.sml"        new 2011*)
   109 (*use "Interpret/generate.sml"        new 2011*)
   117   use "Interpret/calchead.sml"      (*!    *)
   110   use "Interpret/calchead.sml"      (*!    *)
   118   use "Interpret/appl.sml"          (*!complete WEGEN INTERMED TESTCODE*)
   111   use "Interpret/appl.sml"          (*!complete WEGEN INTERMED TESTCODE*)
   176 val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
   169 val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
   177 val (dI',pI',mI') =
   170 val (dI',pI',mI') =
   178   ("Test", ["sqroot-test","univariate","equation","test"],
   171   ("Test", ["sqroot-test","univariate","equation","test"],
   179    ["Test","squ-equ-test-subpbl1"]);
   172    ["Test","squ-equ-test-subpbl1"]);
   180 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   173 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
       
   174 
       
   175 "=(1)= variables known from root-fmz provide type-inference in further input";
       
   176 val ctxt = get_ctxt pt p;
       
   177 val SOME known_x = parseNEW ctxt "x+z+z";
       
   178 val SOME unknown = parseNEW ctxt "xa+b+c";
       
   179 if type_of known_x = Type ("RealDef.real",[]) then ()
       
   180 else error "x+1=2 after start root-pbl wrong type-inference for known_x";
       
   181 if  type_of unknown = TFree ("'a", ["Groups.plus"]) then ()
       
   182 else error "x+1=2 after start root-pbl wrong type-inference for unknown";
       
   183 
   181 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   184 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   182 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   185 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   183 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   186 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   184 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   187 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   185 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   188 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   186 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   189 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   187 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "squ-equ-test-subpbl1"]*)
   190 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "squ-equ-test-subpbl1"]*)
   188 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   191 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   192 *}
       
   193 ML {*
       
   194 "=(2)= preconds of (root-)met are known at start of lucas-interpreter";
       
   195 if get_assumptions_ pt p = [(*str2term "precond_rootmet x"*)] then ((*!!!!!!!!!!!!!!!!*))
       
   196 else error "x+1=2 after start root-met no precondition";
   189 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   197 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   190 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Subp ["linear", "univariate", "equation", "test"]*)
   198 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Subp ["linear", "univariate", "equation", "test"]*)
   191 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   199 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   200 
       
   201 "=(3)= variables known from sub-fmz provide type-inference in further input";
       
   202 val ctxt = get_ctxt pt p;
       
   203 val SOME known_x = parseNEW ctxt "x+z+z"; (*x has declare_constraints to real*)
       
   204 val SOME unknown = parseNEW ctxt "a+b+c";
       
   205 if type_of known_x = Type ("RealDef.real",[]) then ()
       
   206 else error "x+1=2 after start root-pbl wrong type-inference for known_x";
       
   207 if  type_of unknown = TFree ("'a", ["Groups.plus"]) then ()
       
   208 else error "x+1=2 after start root-pbl wrong type-inference for unknown";
       
   209 
   192 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   210 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   193 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   211 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   194 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   212 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   195 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   213 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   196 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   214 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   197 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   215 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   198 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
   216 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
   199 val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
   217 val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
       
   218 *}
       
   219 ML {*
       
   220 "=(4)= preconds of (sub-)met are known at start of lucas-interpreter";
       
   221 (*del GOON*)terms2strs (get_assumptions_ pt p);
       
   222 *}
       
   223 ML {*
       
   224 if get_assumptions_ pt p =
       
   225   [(*parse_patt @{theory} "matches (?a = ?b) (-1 + x = 0)"*)
       
   226    (*, precond-rootmet, precond_submet*)] then ()
       
   227 else error "x+1=2 after start sub-met no precondition";
       
   228 *}
       
   229 ML {*
   200 val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
   230 val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
       
   231 
       
   232 "prep =(5)=: inject assumptions into sub-met: sub_asm_out, sub_asm_local";
       
   233 val (SOME (iform, cform), SOME (ires, cres)) = get_obj g_loc pt (fst p);
       
   234 val ctxt = insert_assumptions [str2term "x < sub_asm_out", str2term "a < sub_asm_local"] cres;
       
   235 val pt = update_loc' pt (fst p) (SOME (iform, cform), SOME (ires, ctxt));
       
   236 
   201 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["linear","univariate", ...]) *);
   237 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["linear","univariate", ...]) *);
   202 *}
   238 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   203 
   239 *}
   204 ML {*
   240 ML {*
   205 *}
   241 "=(5)= transfer of non-local assumptions from sub-met to root-met";
   206 ML {*
   242 (*del*)terms2strs (get_assumptions_ pt p);
   207 val t = str2term "precond_rootmet x";
   243 get_assumptions_ pt p = [(*precond_rootmet, precond_submet, sub_asm_out, sub_res*)];
   208 val SOME (s, t') = eval_precond_rootmet "precond_rootmet_" 0 t @{theory};
   244 (*del*)terms2strs (get_assumptions_ pt p);
   209 term2str t'
   245 terms2strs (get_assumptions_ pt p);
   210 *}
   246 *}
   211 ML {*
   247 ML {*
   212 *}
   248 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt=Check_P["sqroot-test","univariate","equation","test"*)
   213 ML {*
   249 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   214 *}
   250 *}
   215 ML {*
   251 ML {*
   216 *}
   252 "=(6)= assumptions collected during lucas-interpretation for proving postcondition";
   217 ML {*
   253 get_assumptions_ pt p = [(*precond_rootmet, precond_submet, sub_asm_out, sub_res, root_res*)];
   218 
   254 terms2strs (get_assumptions_ pt p);
   219 *}
   255 *}
   220 
   256 
       
   257 ML {*
       
   258 (*############################################################################*)
       
   259 *}
       
   260 ML {*
       
   261 (*Minisubplb/500-met-sub-to-root.sml*)
       
   262 val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
       
   263 val (dI',pI',mI') =
       
   264    ("Test", ["sqroot-test","univariate","equation","test"],
       
   265     ["Test","squ-equ-test-subpbl1"]);
       
   266 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
       
   267 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   268 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   269 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   270 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   271 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   272 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   273 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "squ-equ-test-subpbl1"]*)
       
   274 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   275 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   276 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Subp ["linear", "univariate", "equation", "test"]*)
       
   277 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   278 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   279 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   280 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   281 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   282 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   283 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
       
   284 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
       
   285 val (p,_,f,nxt,_,pt) = me nxt p'' [] pt''; (*nxt = Rewrite_Set_Inst isolate_bdv*);
       
   286 get_ctxt pt p |> is_e_ctxt;       (*false*)
       
   287 val ctxt = get_ctxt pt p; 
       
   288 val SOME t = parseNEW ctxt "Check_elementwise [x = 1] {(v_v::real). Assumptions}";
       
   289 get_loc pt p |> snd |> is_e_ctxt; (*false*)
       
   290 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*);
       
   291 get_ctxt pt p |> is_e_ctxt;       (*false*)
       
   292 val ctxt = get_ctxt pt p; 
       
   293 val SOME t = parseNEW ctxt "Check_elementwise [x = 1] {(v_v::real). Assumptions}";
       
   294 get_loc pt p |> snd |> is_e_ctxt; (*false*)
       
   295 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["linear","univariate", ...]) *);
       
   296 val (pt'''', p'''') = (pt, p);
       
   297 *}
       
   298 ML {*
       
   299 locatetac tac (pt,p)
       
   300 *}
       
   301 ML {*
       
   302 "~~~~~ fun me, args:"; val (_,tac) = nxt;
       
   303 val (pt, p) = case locatetac tac (pt,p) of
       
   304 	("ok", (_, _, ptp))  => ptp | _ => error "script.sml locatetac";
       
   305 *}
       
   306 ML {*
       
   307 show_pt pt; (*...(([3], Res), [x = 1])]... back in root, OK *)
       
   308 "~~~~~ fun step, args:"; val (ip as (_,p_), (ptp as (pt,p), tacis)) = (p, ((pt, e_pos'), []))
       
   309 val pIopt = get_pblID (pt,ip); (*= SOME ["sqroot-test", "univariate", ...]*)
       
   310 tacis; (*= []*)
       
   311 member op = [Pbl,Met] p_ andalso is_none (get_obj g_env pt (fst p)); (*= false*)
       
   312 *}
       
   313 ML {*
       
   314 "~~~~~ fun nxt_solve_, args:"; val (ptp as (pt, pos as (p, p_))) = (pt, ip);
       
   315 val thy' = get_obj g_domID pt (par_pblobj pt p);
       
   316 val (srls, is, sc) = from_pblobj_or_detail' thy' (p,p_) pt; (*is: which ctxt?*)
       
   317 "~~~~~ fun next_tac, args:"; val (thy, (ptp as (pt, pos as (p, _)):ptree * pos'), (sc as Script (h $ body)), 
       
   318 	                               (ScrState (E,l,a,v,s,b), ctxt)) = ((thy',srls), (pt,pos), sc, is);
       
   319 val ctxt = get_ctxt pt pos
       
   320 val SOME t = parseNEW ctxt "Check_elementwise [x = 1] {(v_v::real). Assumptions}";
       
   321 l; (*= [R, R, D, L, R]*)
       
   322 "~~~~~ fun nstep_up, args:"; val (thy, ptp, (Script sc), E, l, ay, a, v) =
       
   323                                  (thy, ptp, sc, E, l, Skip_, a, v);
       
   324 1 < length l; (*true*)
       
   325 val up = drop_last l;
       
   326 go up sc; (* = Const ("HOL.Let", *)
       
   327 *}
       
   328 ML {*
       
   329 "~~~~~ fun nxt_up, args:"; val (thy, ptp, (scr as (Script sc)), E, l, ay,
       
   330                                       (t as Const ("HOL.Let",_) $ _), a, v) =
       
   331                             (thy, ptp, (Script sc), E, up, ay, (go up sc), a, v);
       
   332 ay = Napp_; (*false*)
       
   333 val up = drop_last l;
       
   334 val (Const ("HOL.Let",_) $ e $ (Abs (i,T,body))) = go up sc;
       
   335 val i = mk_Free (i, T);
       
   336 val E = upd_env E (i, v);
       
   337 body; (*= Const ("Script.Check'_elementwise"*)
       
   338 "~~~~~ fun appy, args:"; val ((thy as (th,sr)), (pt, p), E, l, t, a, v)=
       
   339                               (thy, ptp, E, (up@[R,D]), body, a, v);
       
   340 handle_leaf "next  " th sr E a v t; (*= (NONE, STac (Const ("Script.Check'_elementwise"*)
       
   341 val (a', STac stac) = handle_leaf "next  " th sr E a v t;
       
   342 "~~~~~ fun stac2tac_, args:"; val (pt, thy, (Const("Script.Check'_elementwise",_) $ _ $ 
       
   343 		(set as Const ("Set.Collect",_) $ Abs (_,_,pred)))) = (pt, (assoc_thy th), stac);
       
   344 (*2011 changed ^^^^^   *)
       
   345 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*WAS nxt = ("Empty_Tac", Empty_Tac)*)
       
   346 if nxt = ("Check_elementwise", Check_elementwise "Assumptions") then ()
       
   347 else error "Check_elementwise changed; after switch sub-->root-method"
       
   348 *}
   221 end
   349 end
   222 
   350 
   223 (*=== inhibit exn ?=============================================================
   351 (*=== inhibit exn ?=============================================================
   224 ===== inhibit exn ?===========================================================*)
   352 ===== inhibit exn ?===========================================================*)
   225 
   353