agriesma@328: (* use"../ME/script.sml"; agriesma@328: use"ME/script.sml"; agriesma@328: use"script.sml"; agriesma@328: *) agriesma@328: agriesma@328: signature INTERPRETER = agriesma@328: sig agriesma@328: (*type ets (list of executed tactics) see sequent.sml*) agriesma@328: agriesma@328: datatype locate agriesma@328: = NotLocatable wneuper@807: | Steps of (tac_ * mout * ptree * pos' * cid * safe (* ets*)) list agriesma@328: (* | ToDo of ets 28.4.02*) agriesma@328: agriesma@328: (*diss: next-tactic-function*) wneuper@807: val next_tac : theory' -> ptree * pos' -> metID -> scr -> ets -> tac_ agriesma@328: (*diss: locate-function*) agriesma@328: val locate_gen : theory' wneuper@807: -> tac_ agriesma@328: -> ptree * pos' -> scr * rls -> ets -> loc_ -> locate agriesma@328: wneuper@807: val sel_rules : ptree -> pos' -> tac list wneuper@1592: val init_form : scr -> ets -> loc_ * term option (*FIXME not up to date*) neuper@703: val formal_args : term -> term list agriesma@328: agriesma@328: (*shift to library ...*) agriesma@328: val inst_abs : theory' -> term -> term agriesma@328: val itms2args : metID -> itm list -> term list wneuper@807: val user_interrupt : loc_ * (tac_ * env * env * term * term * safe) agriesma@328: (*val empty : term*) agriesma@328: end agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: (* agriesma@328: structure Interpreter : INTERPRETER = agriesma@328: struct agriesma@328: *) agriesma@328: agriesma@328: val string_of_thm' = (implode o tl o drop_last o explode o string_of_thm); agriesma@328: (* agriesma@328: string_of_thm sym; agriesma@328: val it = "\"?s = ?t ==> ?t = ?s\"" : string agriesma@328: string_of_thm' sym; agriesma@328: val it = "?s = ?t ==> ?t = ?s" : string*) agriesma@328: agriesma@328: type step = (*data for creating a new node in the ptree; agriesma@328: designed for use: agriesma@328: fun ass* scrstate steps = agriesma@328: ... case ass* scrstate steps of agriesma@328: Assoc (scrstate, steps) => ... ass* scrstate steps*) wneuper@807: tac_ (*transformed from associated tac*) agriesma@328: * mout (*result with indentation etc.*) wneuper@807: * ptree (*containing node created by tac_ + resp. scrstate*) agriesma@328: * pos' (*position in ptree; ptree * pos' is the proofstate*) wneuper@1967: * pos' list; (*of ptree-nodes probably cut (by fst tac_)*) wneuper@1967: val e_step = (Empty_Tac_, EmptyMout, EmptyPtree, e_pos',[]:pos' list):step; agriesma@328: agriesma@328: fun rule2thm' (Thm (id, thm)) = (id, string_of_thm thm):thm' agriesma@328: | rule2thm' r = raise error ("rule2thm': not defined for "^(rule2str r)); agriesma@328: agriesma@328: (*.makes a (rule,term) list to a Step (m, mout, pt', p', cid) for solve; agriesma@328: complicated with current t in rrlsstate.*) agriesma@328: fun rts2steps steps ((pt,p),(f,f'',rss,rts),(thy',ro,er,pa)) [(r, (f', am))] = agriesma@328: let val thy = assoc_thy thy' agriesma@328: val m = Rewrite' (thy',ro,er,pa, rule2thm' r, f, (f', am)) agriesma@328: val is = RrlsState (f',f'',rss,rts) agriesma@328: val p = case p of (p',Frm) => p | (p',Res) => (lev_on p',Res) agriesma@328: val (p', cid, mout, pt') = generate1 thy m is p pt agriesma@328: in (is, (m, mout, pt', p', cid)::steps) end agriesma@328: | rts2steps steps ((pt,p),(f,f'',rss,rts),(thy',ro,er,pa)) agriesma@328: ((r, (f', am))::rts') = agriesma@328: let val thy = assoc_thy thy' agriesma@328: val m = Rewrite' (thy',ro,er,pa, rule2thm' r, f, (f', am)) agriesma@328: val is = RrlsState (f',f'',rss,rts) agriesma@328: val p = case p of (p',Frm) => p | (p',Res) => (lev_on p',Res) agriesma@328: val (p', cid, mout, pt') = generate1 thy m is p pt agriesma@328: in rts2steps ((m, mout, pt', p', cid)::steps) agriesma@328: ((pt',p'),(f',f'',rss,rts),(thy',ro,er,pa)) rts' end; agriesma@328: agriesma@328: agriesma@328: val trace_locate = ref false; (*23.11.01*) agriesma@328: agriesma@328: (*. functions for the environment stack .*) agriesma@328: fun accessenv id es = the (assoc((top es):env, id)) agriesma@328: handle _ => error ("accessenv: "^(free2str id)^" not in env"); agriesma@328: fun updateenv id vl (es:env stack) = agriesma@328: (push (overwrite(top es, (id, vl))) (pop es)):env stack; agriesma@328: fun pushenv id vl (es:env stack) = agriesma@328: (push (overwrite(top es, (id, vl))) es):env stack; agriesma@328: val popenv = pop:env stack -> env stack; agriesma@328: agriesma@328: agriesma@328: agriesma@328: fun de_esc_underscore str = agriesma@328: let fun scan [] = [] agriesma@328: | scan (s::ss) = if s = "'" then (scan ss) agriesma@328: else (s::(scan ss)) agriesma@328: in (implode o scan o explode) str end; agriesma@328: (* agriesma@328: > val str = "Rewrite_Set_Inst"; agriesma@328: > val esc = esc_underscore str; agriesma@328: val it = "Rewrite'_Set'_Inst" : string agriesma@328: > val des = de_esc_underscore esc; agriesma@328: val des = de_esc_underscore esc;*) agriesma@328: neuper@711: neuper@711: (*WN.12.5.03 not used any more, neuper@711: tacs are more stable than listepxr: subst_tacexpr agriesma@328: fun is_listexpr t = agriesma@328: (((ids_of o head_of) t) inter (!listexpr)) <> []; neuper@711: ----*) agriesma@328: agriesma@328: (*go at a location in a script and fetch the contents*) agriesma@328: fun go [] t = t agriesma@328: | go (D::p) (Abs(s,ty,t0)) = go (p:loc_) t0 agriesma@328: | go (L::p) (t1 $ t2) = go p t1 agriesma@328: | go (R::p) (t1 $ t2) = go p t2 agriesma@328: | go l _ = raise error ("go: no "^(loc_2str l)); agriesma@328: (* agriesma@328: > val t = (term_of o the o (parse thy)) "a+b"; agriesma@328: val it = Const (#,#) $ Free (#,#) $ Free ("b","RealDef.real") : term agriesma@328: > val plus_a = go [L] t; agriesma@328: > val b = go [R] t; agriesma@328: > val plus = go [L,L] t; agriesma@328: > val a = go [L,R] t; agriesma@328: agriesma@328: > val t = (term_of o the o (parse thy)) "a+b+c"; agriesma@328: val t = Const (#,#) $ (# $ # $ Free #) $ Free ("c","RealDef.real") : term agriesma@328: > val pl_pl_a_b = go [L] t; agriesma@328: > val c = go [R] t; agriesma@328: > val a = go [L,R,L,R] t; agriesma@328: > val b = go [L,R,R] t; agriesma@328: *) agriesma@328: agriesma@328: agriesma@328: (* get a subterm t with test t, and record location *) agriesma@328: fun get l test (t as Const (s,T)) = agriesma@328: if test t then Some (l,t) else None agriesma@328: | get l test (t as Free (s,T)) = agriesma@328: if test t then Some (l,t) else None agriesma@328: | get l test (t as Bound n) = agriesma@328: if test t then Some (l,t) else None agriesma@328: | get l test (t as Var (s,T)) = agriesma@328: if test t then Some (l,t) else None agriesma@328: | get l test (t as Abs (s,T,body)) = agriesma@328: if test t then Some (l:loc_,t) else get ((l@[D]):loc_) test body agriesma@328: | get l test (t as t1 $ t2) = agriesma@328: if test t then Some (l,t) agriesma@328: else case get (l@[L]) test t1 of agriesma@328: None => get (l@[R]) test t2 agriesma@328: | Some (l',t') => Some (l',t'); agriesma@328: (*18.6.00 agriesma@328: > val sss = ((term_of o the o (parse thy)) agriesma@328: "Script Solve_root_equation (eq_::bool) (v_::real) (err_::bool) =\ agriesma@328: \ (let e_ = Try (Rewrite square_equation_left True eq_) \ agriesma@328: \ in [e_])"); agriesma@328: ______ compares head_of !! agriesma@328: > get [] (eq_str "Let") sss; [R] agriesma@328: > get [] (eq_str "Script.Try") sss; [R,L,R] agriesma@328: > get [] (eq_str "Script.Rewrite") sss; [R,L,R,R] agriesma@328: > get [] (eq_str "True") sss; [R,L,R,R,L,R] agriesma@328: > get [] (eq_str "e_") sss; [R,R] agriesma@328: *) agriesma@328: agriesma@328: fun test_negotiable t = ((strip_thy o (term_str Script.thy) o head_of) t) agriesma@328: mem (!negotiable); agriesma@328: agriesma@328: (*30.4.02: vvv--- doesnt work with curried functions ---> get_tac ------ agriesma@328: (*18.6.00: below _ALL_ negotiables must be in fun-patterns ! agriesma@328: then the last (non)pattern must be a subproblem*) agriesma@328: fun init_frm thy (Const ("Script.Rewrite",_) $ _ $ _ $ eq) = Some eq agriesma@328: | init_frm thy (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ $ eq) = Some eq agriesma@328: | init_frm thy (Const ("Script.Rewrite'_Set",_) $ _ $ _ $ eq) = Some eq agriesma@328: | init_frm thy (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ $ eq) = agriesma@328: Some eq agriesma@328: | init_frm thy (Const ("Script.Calculate",_) $ _ $ t) = Some t agriesma@328: | init_frm thy t = agriesma@328: (*if ((strip_thy o (term_str thy) o head_of) t) mem (!subpbls) agriesma@328: then None agriesma@328: else *)raise error ("init_frm: not impl. for "^ agriesma@328: (Sign.string_of_term (sign_of thy) t)); agriesma@328: agriesma@328: > val t = (term_of o the o (parse thy)) agriesma@328: "Rewrite square_equation_left True (sqrt(#9+#4*x)=sqrt x + sqrt(#5+x))"; agriesma@328: > val Some ini = init_frm thy t; agriesma@328: > Sign.string_of_term (sign_of thy) ini; agriesma@328: val it = "sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x)" : string agriesma@328: agriesma@328: > val t = (term_of o the o (parse thy)) agriesma@328: "solve_univar (Reals, [univar,equation], no_met) e1_ v1_"; agriesma@328: > val ini = init_frm thy t; agriesma@328: > Sign.string_of_term (sign_of thy) ini; agriesma@328: val it = "empty" : string agriesma@328: agriesma@328: > val t = (term_of o the o (parse thy)) agriesma@328: "Rewrite_Set norm_equation False x + #1 = #2"; agriesma@328: > val Some ini = init_frm thy t; agriesma@328: > Sign.string_of_term (sign_of thy) ini; agriesma@328: val it = "x + #1 = #2" : string agriesma@328: agriesma@328: > val t = (term_of o the o (parse thy)) agriesma@328: "Rewrite_Set_Inst [(bdv,x)] isolate_bdv False x + #1 = #2"; agriesma@328: > val Some ini = init_frm thy t; agriesma@328: > Sign.string_of_term (sign_of thy) ini; agriesma@328: val it = "x + #1 = #2" : string *) agriesma@328: agriesma@328: wneuper@807: (*.get argument of first stactic in a script for init_form.*) wneuper@807: fun get_stac thy (h $ body) = wneuper@2918: (* wneuper@2918: *) agriesma@328: let agriesma@328: fun get_t y (Const ("Script.Seq",_) $ e1 $ e2) a = agriesma@328: (case get_t y e1 a of None => get_t y e2 a | la => la) agriesma@328: | get_t y (Const ("Script.Seq",_) $ e1 $ e2 $ a) _ = agriesma@328: (case get_t y e1 a of None => get_t y e2 a | la => la) agriesma@328: | get_t y (Const ("Script.Try",_) $ e) a = get_t y e a agriesma@328: | get_t y (Const ("Script.Try",_) $ e $ a) _ = get_t y e a agriesma@328: | get_t y (Const ("Script.Repeat",_) $ e) a = get_t y e a agriesma@328: | get_t y (Const ("Script.Repeat",_) $ e $ a) _ = get_t y e a agriesma@328: | get_t y (Const ("Script.Or",_) $e1 $ e2) a = agriesma@328: (case get_t y e1 a of None => get_t y e2 a | la => la) agriesma@328: | get_t y (Const ("Script.Or",_) $e1 $ e2 $ a) _ = agriesma@328: (case get_t y e1 a of None => get_t y e2 a | la => la) agriesma@328: | get_t y (Const ("Script.While",_) $ c $ e) a = get_t y e a agriesma@328: | get_t y (Const ("Script.While",_) $ c $ e $ a) _ = get_t y e a agriesma@328: | get_t y (Const ("Script.Letpar",_) $ e1 $ Abs (_,_,e2)) a = agriesma@328: (case get_t y e1 a of None => get_t y e2 a | la => la) neuper@711: (*| get_t y (Const ("Let",_) $ e1 $ Abs (_,_,e2)) a = neuper@711: (writeln("get_t: Let e1= "^(term2str e1)^", e2= "^(term2str e2)); neuper@711: case get_t y e1 a of None => get_t y e2 a | la => la) neuper@711: | get_t y (Abs (_,_,e)) a = get_t y e a*) agriesma@328: | get_t y (Const ("Let",_) $ e1 $ Abs (_,_,e2)) a = neuper@711: get_t y e1 a (*don't go deeper without evaluation !*) neuper@711: | get_t y (Const ("If",_) $ c $ e1 $ e2) a = None neuper@711: (*(case get_t y e1 a of None => get_t y e2 a | la => la)*) agriesma@328: agriesma@328: | get_t y (Const ("Script.Rewrite",_) $ _ $ _ $ a) _ = Some a agriesma@328: | get_t y (Const ("Script.Rewrite",_) $ _ $ _ ) a = Some a agriesma@328: | get_t y (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ $ a) _ = Some a agriesma@328: | get_t y (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ ) a = Some a agriesma@328: | get_t y (Const ("Script.Rewrite'_Set",_) $ _ $ _ $ a) _ = Some a agriesma@328: | get_t y (Const ("Script.Rewrite'_Set",_) $ _ $ _ ) a = Some a agriesma@328: | get_t y (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ $a)_ =Some a agriesma@328: | get_t y (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ ) a =Some a agriesma@328: | get_t y (Const ("Script.Calculate",_) $ _ $ a) _ = Some a agriesma@328: | get_t y (Const ("Script.Calculate",_) $ _ ) a = Some a agriesma@328: agriesma@328: | get_t y (Const ("Script.Substitute",_) $ _ $ a) _ = Some a agriesma@328: | get_t y (Const ("Script.Substitute",_) $ _ ) a = Some a agriesma@328: agriesma@328: | get_t y (Const ("Script.SubProblem",_) $ _ $ _) _ = None agriesma@328: neuper@711: | get_t y x _ = neuper@711: ((*writeln ("### get_t yac: list-expr "^(term2str x));*) neuper@711: None) agriesma@328: in get_t thy body e_term end; agriesma@328: wneuper@807: (*FIXME: get 1st stac by next_stac [] instead of ... ?? 29.7.02*) neuper@711: (* val Script sc = scr; agriesma@328: *) agriesma@328: fun init_form thy (Script sc) env = wneuper@807: (case get_stac thy sc of wneuper@807: None => None (*raise error ("init_form: no 1st stac in "^ agriesma@328: (Sign.string_of_term (sign_of thy) sc))*) wneuper@807: | Some stac => Some (subst_atomic env stac)) agriesma@328: | init_form _ _ _ = raise error "init_form: no match"; agriesma@328: agriesma@328: (* use"ME/script.sml"; agriesma@328: use"script.sml"; agriesma@328: *) agriesma@328: agriesma@328: agriesma@328: wneuper@807: (*the 'iteration-argument' of a stac (args not eval)*) agriesma@328: fun itr_arg _ (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ $ v) = v agriesma@328: | itr_arg _ (Const ("Script.Rewrite",_) $ _ $ _ $ v) = v agriesma@328: | itr_arg _ (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ $ v) = v agriesma@328: | itr_arg _ (Const ("Script.Rewrite'_Set",_) $ _ $ _ $ v) = v agriesma@328: | itr_arg _ (Const ("Script.Calculate",_) $ _ $ v) = v agriesma@328: | itr_arg _ (Const ("Script.Check'_elementwise",_) $ consts $ _) = consts agriesma@328: | itr_arg _ (Const ("Script.Or'_to'_List",_) $ _) = e_term wneuper@807: | itr_arg _ (Const ("Script.Tac",_) $ _) = e_term agriesma@328: | itr_arg _ (Const ("Script.SubProblem",_) $ _ $ _) = e_term agriesma@328: | itr_arg thy t = raise error agriesma@328: ("itr_arg not impl. for "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t)); agriesma@328: (* val t = (term_of o the o (parse thy))"Rewrite rroot_square_inv False e_"; agriesma@328: > itr_arg "Script.thy" t; agriesma@328: val it = Free ("e_","RealDef.real") : term agriesma@328: > val t = (term_of o the o (parse thy))"xxx"; agriesma@328: > itr_arg "Script.thy" t; agriesma@328: *** itr_arg not impl. for xxx agriesma@328: uncaught exception ERROR agriesma@328: raised at: library.ML:1114.35-1114.40*) agriesma@328: agriesma@328: neuper@703: fun formal_args scr = (fst o split_last o snd o strip_comb) scr; agriesma@328: (* agriesma@328: > parms scr; agriesma@328: [Free ("f_","RealDef.real"),Free ("v_","RealDef.real"), agriesma@328: Free ("eqs_","bool List.list")] : term list agriesma@328: *) agriesma@328: agriesma@328: agriesma@328: (*26.5.02: not clear, when a is available in ass_up for eva-_true*) agriesma@328: fun upd_env_opt env (Some a, v) = upd_env env (a,v) agriesma@328: | upd_env_opt env (None, v) = agriesma@328: (writeln("*** upd_env_opt: (None,"^(term2str v)^")");env); agriesma@328: agriesma@328: agriesma@328: type dsc = typ; (*<-> nam..unknow in Descript.thy*) agriesma@328: fun typ_str (Type (s,_)) = s agriesma@328: | typ_str (TFree(s,_)) = s agriesma@328: | typ_str (TVar ((s,i),_)) = s^(string_of_int i); agriesma@328: agriesma@328: (*get the _result_-type of a description*) agriesma@328: fun dsc_valT (Const (_,(Type (_,[_,T])))) = (strip_thy o typ_str) T; agriesma@328: (*> val t = (term_of o the o (parse thy)) "equality"; agriesma@328: > val T = type_of t; agriesma@328: val T = "bool => Tools.una" : typ agriesma@328: > val dsc = dsc_valT t; agriesma@328: val dsc = "una" : string agriesma@328: agriesma@328: > val t = (term_of o the o (parse thy)) "fixedValues"; agriesma@328: > val T = type_of t; agriesma@328: val T = "bool List.list => Tools.nam" : typ agriesma@328: > val dsc = dsc_valT t; agriesma@328: val dsc = "nam" : string*) agriesma@328: neuper@703: (*.from penv in itm_ make args for script depending on type of description.*) neuper@703: (*6.5.03 TODO: push penv into script -- and drop mk_arg here || drop penv neuper@703: 9.5.03 penv postponed: penv = env for script at the moment, (*mk_arg*)*) agriesma@328: fun mk_arg thy d [] = raise error ("mk_arg: no data for "^ agriesma@328: (Sign.string_of_term (sign_of thy) d)) agriesma@328: | mk_arg thy d [t] = neuper@703: (case dsc_valT d of neuper@703: "una" => [t] neuper@703: | "nam" => neuper@703: [case t of neuper@703: r as (Const ("op =",_) $ _ $ _) => r neuper@703: | _ => raise error neuper@703: ("mk_arg: dsc-typ 'nam' applied to non-equality "^ neuper@703: (Sign.string_of_term (sign_of thy) t))] neuper@703: | s => raise error ("mk_arg: not impl. for "^s)) neuper@703: agriesma@328: | mk_arg thy d (t::ts) = (mk_arg thy d [t]) @ (mk_arg thy d ts); agriesma@328: (* agriesma@328: val d = d_in itm_; agriesma@328: val [t] = ts_in itm_; agriesma@328: mk_arg thy agriesma@328: *) agriesma@328: agriesma@328: neuper@703: neuper@703: neuper@703: (*.create the actual parameters (args) of script: their order neuper@703: is given by the order of "#Given" in method.ppc .*) neuper@703: (*WN.5.5.03: ?: does this allow for different descriptions ??? neuper@703: ?: why not taken from formal args of script ??? neuper@703: !: FIXXXME penv: push it here in itms2args into script-evaluation*) agriesma@328: (* val mI = methID; agriesma@328: *) agriesma@328: fun itms2args thy mI (itms:itm list) = agriesma@328: let agriesma@328: fun test_dsc d (_,_,_,_,itm_) = (d = d_in itm_); agriesma@328: fun itm2arg itms (_,(d,_)) = agriesma@328: case find_first (test_dsc d) itms of agriesma@328: None => agriesma@328: raise error ("itms2args: '"^ agriesma@328: (Sign.string_of_term (sign_of thy) d)^ agriesma@328: "' not in itms") neuper@703: (*| Some (_,_,_,_,itm_) => mk_arg thy (d_in itm_) (ts_in itm_); neuper@703: penv postponed; presently penv holds already env for script*) neuper@703: | Some (_,_,_,_,itm_) => penvval_in itm_; agriesma@328: fun test_given (s,_) = (s = "#Given"); agriesma@328: val mpc = (#ppc o get_met) mI; agriesma@328: val gs = filter test_given mpc; agriesma@328: in (flat o (map (itm2arg itms))) gs end; agriesma@328: (* agriesma@328: > val sc = ... Solve_root_equation ... agriesma@328: > val mI = ("Script.thy","sqrt-equ-test"); agriesma@328: > val PblObj{meth={ppc=itms,...},...} = get_obj I pt []; agriesma@328: > val ts = itms2args thy mI itms; agriesma@328: > map (Sign.string_of_term (sign_of thy)) ts; agriesma@328: ["sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x)","x","#0"] : string list agriesma@328: *) agriesma@328: wneuper@1267: (*["bool_ (1+x=2)","real_ x"] --match_ags--> oris wneuper@1267: --oris2fmz_--> ["equality (1+x=2)","boundVariable x","solutions L"]*) wneuper@1267: fun oris2fmz_vals oris = wneuper@1267: let fun ori2fmz_vals ((_,_,_,dsc,ts):ori) = wneuper@1267: ((term2str o comp_dts') (dsc, ts), last_elem ts) wneuper@1267: handle _ => raise error ("ori2fmz_env called with "^terms2str ts) wneuper@1267: in (split_list o (map ori2fmz_vals)) oris end; agriesma@328: agriesma@328: (*detour necessary, because generate1 delivers a string-result*) agriesma@328: fun mout2term thy (Form' (FormKF (_,_,_,_,res))) = agriesma@328: (term_of o the o (parse (assoc_thy thy))) res agriesma@328: | mout2term thy (Form' (PpcKF _)) = e_term;(*3.8.01: res of subpbl agriesma@328: at time of detection in script*) agriesma@328: wneuper@1250: (*.convert a script-tac to a tac (and SubProblem to tac_, too).*) wneuper@807: fun stac2tac_ thy (Const ("Script.Rewrite",_) $ Free (thmID,_) $ _ $ f) = agriesma@328: let val tid = (de_esc_underscore o strip_thy) thmID agriesma@328: in (Rewrite (tid, (de_quote o string_of_thm o wneuper@1250: (assoc_thm' thy)) (tid,"")), Empty_Tac_) end agriesma@328: (* val (thy, agriesma@328: mm as(Const ("Script.Rewrite'_Inst",_) $ sub $ Free(thmID,_) $ _ $ f)) wneuper@807: = (assoc_thy th,stac); wneuper@807: stac2tac_ thy mm; agriesma@328: agriesma@328: assoc_thm' (assoc_thy "Isac.thy") (tid,""); agriesma@328: assoc_thm' Isac.thy (tid,""); agriesma@328: *) wneuper@807: | stac2tac_ thy (Const ("Script.Rewrite'_Inst",_) $ agriesma@328: sub $ Free (thmID,_) $ _ $ f) = agriesma@328: let val subML = ((map isapair2pair) o isalist2list) sub agriesma@328: val subStr = subst2subs subML agriesma@328: val tid = (de_esc_underscore o strip_thy) thmID (*4.10.02 unnoetig*) agriesma@328: in (Rewrite_Inst agriesma@328: (subStr, (tid, (de_quote o string_of_thm o wneuper@1250: (assoc_thm' thy)) (tid,""))), Empty_Tac_) end agriesma@328: wneuper@807: | stac2tac_ thy (Const ("Script.Rewrite'_Set",_) $ Free (rls,_) $ _ $ f)= wneuper@1250: (Rewrite_Set ((de_esc_underscore o strip_thy) rls), Empty_Tac_) agriesma@328: wneuper@807: | stac2tac_ thy (Const ("Script.Rewrite'_Set'_Inst",_) $ agriesma@328: sub $ Free (rls,_) $ _ $ f) = agriesma@328: let val subML = ((map isapair2pair) o isalist2list) sub; agriesma@328: val subStr = subst2subs subML; wneuper@1250: in (Rewrite_Set_Inst (subStr,rls), Empty_Tac_) end agriesma@328: wneuper@807: | stac2tac_ thy (Const ("Script.Calculate",_) $ Free (op_,_) $ f) = wneuper@1250: (Calculate op_, Empty_Tac_) agriesma@328: agriesma@328: (*12.1.01.*) wneuper@807: | stac2tac_ thy (Const("Script.Check'_elementwise",_) $ _ $ agriesma@328: (set as Const ("Collect",_) $ Abs (_,_,pred))) = wneuper@1250: (Check_elementwise (Sign.string_of_term (sign_of thy) pred), wneuper@1250: (*set*)Empty_Tac_) agriesma@328: wneuper@807: | stac2tac_ thy (Const("Script.Or'_to'_List",_) $ _ ) = wneuper@1250: (Or_to_List, Empty_Tac_) agriesma@328: agriesma@328: (*12.1.01.for subproblem_equation_dummy in root-equation *) wneuper@807: | stac2tac_ thy (Const ("Script.Tac",_) $ Free (str,_)) = wneuper@1250: (Tac ((de_esc_underscore o strip_thy) str), Empty_Tac_) agriesma@328: (*L_ will come from pt in appl_in*) agriesma@328: wneuper@1250: (*3.12.03 copied from assod SubProblem*) wneuper@1267: (* val Const ("Script.SubProblem",_) $ wneuper@1267: (Const ("Pair",_) $ wneuper@1267: Free (dI',_) $ wneuper@1267: (Const ("Pair",_) $ pI' $ mI')) $ ags' = wneuper@1267: str2term wneuper@1267: "SubProblem (Test_,[linear,univariate,equation,test],[Test,solve_linear])\ wneuper@1267: \ [bool_ (-1+x=0), real_ x]"; wneuper@1267: *) wneuper@807: | stac2tac_ thy (Const ("Script.SubProblem",_) $ wneuper@1250: (Const ("Pair",_) $ wneuper@1250: Free (dI',_) $ wneuper@1250: (Const ("Pair",_) $ pI' $ mI')) $ ags') = wneuper@1267: (*compare "| assod _ (Subproblem'"*) wneuper@1250: let val dI = ((implode o drop_last o explode) dI')^".thy"; wneuper@1250: val pI = ((map (de_esc_underscore o free2str)) o isalist2list) pI'; wneuper@1250: val mI = ((map (de_esc_underscore o free2str)) o isalist2list) mI'; wneuper@1267: val ags = isalist2list ags'; wneuper@1267: val thy = assoc_thy dI; wneuper@1267: val (pI, pors, mI) = wneuper@1267: if mI = ["no_met"] wneuper@1267: then let val pors = match_ags thy ((#ppc o get_pbt) pI) ags; wneuper@1267: val pI' = refine_ori' pors pI; wneuper@1267: in (pI', pors (*refinement over models with diff.prec only*), wneuper@1267: (hd o #met o get_pbt) pI') end wneuper@1267: else (pI, match_ags thy ((#ppc o get_pbt) pI) ags, mI); wneuper@1267: val (fmz_, vals) = oris2fmz_vals pors; wneuper@1267: val {cas,ppc,thy,...} = get_pbt pI wneuper@1267: val dI = theory2theory' thy (*take dI from _refined_ pbl*) wneuper@1250: val hdl = case cas of wneuper@1250: None => pblterm dI pI wneuper@1267: | Some t => subst_atomic ((vars_of_pbl_' ppc) ~~~ vals) t wneuper@1267: val f = subpbl (strip_thy dI) pI wneuper@1250: in (Subproblem (dI, pI), wneuper@1267: Subproblem' ((dI, pI, mI), pors, hdl, fmz_, f)) wneuper@1250: end agriesma@328: wneuper@807: | stac2tac_ thy t = raise error wneuper@807: ("stac2tac_ TODO: no match for "^ agriesma@328: (Sign.string_of_term (sign_of thy) t)); agriesma@328: (* agriesma@328: > val t = (term_of o the o (parse thy)) agriesma@328: "Rewrite_Set_Inst [(bdv,v_::real)] isolate_bdv False (x=a+#1)"; wneuper@807: > stac2tac_ t; wneuper@807: val it = Rewrite_Set_Inst ([(#,#)],"isolate_bdv") : tac agriesma@328: agriesma@328: > val t = (term_of o the o (parse SqRoot.thy)) agriesma@328: "(SubProblem (SqRoot_,[equation,univariate],(SqRoot_,solve_linear))\ agriesma@328: \ [bool_ e_, real_ v_])::bool list"; wneuper@807: > stac2tac_ SqRoot.thy t; agriesma@328: val it = (Subproblem ("SqRoot.thy",[#,#]),Const (#,#) $ (# $ # $ (# $ #))) agriesma@328: *) agriesma@328: wneuper@807: fun stac2tac thy t = (fst o stac2tac_ thy) t; agriesma@328: wneuper@807: (*24.6.02 unused, use subst_stac instead !*) wneuper@807: fun is_stac t = wneuper@807: (stac2tac_ Script.thy t; true) agriesma@328: handle _ => false; agriesma@328: agriesma@328: agriesma@328: wneuper@807: (*.get the stactics and problems of a script as tacs agriesma@328: instantiated with the current environment; neuper@711: l is the location which generated the given formula.*) neuper@711: (*WN.12.5.03: quick-and-dirty repair for listexpressions*) agriesma@328: fun is_spec_pos Pbl = true agriesma@328: | is_spec_pos Met = true agriesma@328: | is_spec_pos _ = false; agriesma@328: wneuper@2092: fun sel_rules _ (([],Res):pos') = wneuper@2092: raise PTREE "no tactics applicable at the end of a calculation" wneuper@2092: | sel_rules pt (p,p_) = wneuper@2092: if is_spec_pos p_ wneuper@2092: then [get_obj g_tac pt p] agriesma@328: else agriesma@328: let val pp = par_pblobj pt p; agriesma@328: val thy' = (get_obj g_domID pt pp):theory'; agriesma@328: val thy = assoc_thy thy'; agriesma@328: val metID = get_obj g_metID pt pp; wneuper@1124: val metID' =if metID =e_metID then(thd3 o snd3)(get_obj g_origin pt pp) agriesma@328: else metID; agriesma@328: val Script sc = (#scr o get_met) metID'; agriesma@328: val ScrState (env,_,_,_,_,_) = get_istate pt (p,p_); wneuper@807: in map ((stac2tac thy) o rep_stacexpr o wneuper@807: (subst_stacexpr env None e_term)) (stacpbls sc) end; agriesma@328: (* agriesma@328: > val Script sc = (#scr o get_met) ("SqRoot.thy","sqrt-equ-test"); agriesma@328: > val env = [((term_of o the o (parse Isac.thy)) "bdv", agriesma@328: (term_of o the o (parse Isac.thy)) "x")]; wneuper@807: > map ((stac2tac thy) o (subst_stacexpr env None e_term)) (stacpbls sc); agriesma@328: *) agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: (*test a term for being a _list_ (set ?) of constants; could be more rigorous*) agriesma@328: fun list_of_consts (Const ("List.list.Cons",_) $ _ $ _) = true agriesma@328: | list_of_consts (Const ("List.list.Nil",_)) = true agriesma@328: | list_of_consts _ = false; agriesma@328: (*val ttt = (term_of o the o (parse thy)) "[x=#1,x=#2,x=#3]"; agriesma@328: > list_of_consts ttt; agriesma@328: val it = true : bool agriesma@328: > val ttt = (term_of o the o (parse thy)) "[]"; agriesma@328: > list_of_consts ttt; agriesma@328: val it = true : bool*) agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: (* 15.1.01: evaluation of preds only works occasionally, agriesma@328: but luckily for the 2 examples of root-equ: agriesma@328: > val s = ((term_of o the o (parse thy)) "x", agriesma@328: (term_of o the o (parse thy)) "-#5//#12"); agriesma@328: > val asm = (term_of o the o (parse thy)) agriesma@328: "#0 <= #9 + #4 * x & #0 <= sqrt x + sqrt (#-3 + x)"; agriesma@328: > val pred = subst_atomic [s] asm; agriesma@328: > rewrite_set_ thy false (cterm_of (sign_of thy) pred); agriesma@328: val it = None : (cterm * cterm list) option !!!!!!!!!!!!!!!!!!!!!!!!!!!! agriesma@328: > eval_true' (string_of_thy thy) "eval_rls" (subst_atomic [s] pred); agriesma@328: val it = false : bool agriesma@328: agriesma@328: > val s = ((term_of o the o (parse thy)) "x", agriesma@328: (term_of o the o (parse thy)) "#4"); agriesma@328: > val asm = (term_of o the o (parse thy)) agriesma@328: "#0 <= #9 + #4 * x & #0 <= sqrt x + sqrt (#5 + x)"; agriesma@328: > val pred = subst_atomic [s] asm; agriesma@328: > rewrite_set_ thy false (cterm_of (sign_of thy) pred); agriesma@328: val it = Some ("True & True",[]) : (cterm * cterm list) option agriesma@328: > eval_true' (string_of_thy thy) "eval_rls" (subst_atomic [s] pred); agriesma@328: val it = true : bool`*) agriesma@328: neuper@750: (*for check_elementwise: take apart the set, ev. instantiate assumptions agriesma@328: fun rep_set thy pt p (set as Const ("Collect",_) $ Abs _) = agriesma@328: let val (_ $ Abs (bdv,T,pred)) = inst_abs thy set; agriesma@328: val bdv = Free (bdv,T); agriesma@328: val pred = if pred <> Const ("Script.Assumptions",bool) agriesma@328: then pred neuper@750: else (mk_and o (map fst)) (get_assumptions_ pt (p,Res)) agriesma@328: in (bdv, pred) end agriesma@328: | rep_set thy _ _ set = agriesma@328: raise error ("check_elementwise: no set "^ (*from script*) agriesma@328: (Sign.string_of_term (sign_of thy) set)); agriesma@328: (*> val set = (term_of o the o (parse thy)) "{(x::real). Assumptions}"; agriesma@328: > val p = []; agriesma@328: > val pt = union_asm pt p [("#0 <= sqrt x + sqrt (#5 + x)",[11]), agriesma@328: ("#0 <= #9 + #4 * x",[22]), agriesma@328: ("#0 <= x ^^^ #2 + #5 * x",[33]), agriesma@328: ("#0 <= #2 + x",[44])]; agriesma@328: > val (bdv,pred) = rep_set thy pt p set; agriesma@328: val bdv = Free ("x","RealDef.real") : term agriesma@328: > writeln (Sign.string_of_term (sign_of thy) pred); agriesma@328: ((#0 <= sqrt x + sqrt (#5 + x) & #0 <= #9 + #4 * x) & agriesma@328: #0 <= x ^^^ #2 + #5 * x) & agriesma@328: #0 <= #2 + x agriesma@328: *) neuper@750: --------------------------------------------11.6.03--was unused*) agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: datatype ass = wneuper@807: Ass of tac_ * (*SubProblem gets args instantiated in assod*) agriesma@328: term (*for itr_arg,result in ets*) wneuper@807: | AssWeak of tac_ * agriesma@328: term (*for itr_arg,result in ets*) agriesma@328: | NotAss; agriesma@328: wneuper@807: (*.assod: tac_ associated with stac w.r.t. d agriesma@328: returns wneuper@807: Ass : associated: e.g. thmID in stac = thmID in m wneuper@807: +++ arg in stac = arg in m wneuper@807: AssWeak: weakly ass.:e.g. thmID in stac = thmID in m, //arg// wneuper@807: NotAss : e.g. thmID in stac/=/thmID in m (not =) agriesma@328: 8.01: wneuper@807: tac_ SubProblem with args completed from script neuper@711: .*) agriesma@328: fun assod d (m as Rewrite_Inst' (thy',rod,rls,put,subs,(thmID,thm),f,(f',asm))) agriesma@328: (Const ("Script.Rewrite'_Inst",_) $ subs_ $ Free (thmID_,idT) $ b $ f_) = agriesma@328: if thmID = thmID_ then agriesma@328: if f = f_ then ((*writeln"3### assod ..Ass";*)Ass (m,f')) agriesma@328: else ((*writeln"3### assod ..AssWeak";*)AssWeak(m, f')) agriesma@328: else ((*writeln"3### assod ..NotAss";*)NotAss) agriesma@328: agriesma@328: | assod d (m as Rewrite' (thy,rod,rls,put,(thmID,thm),f,(f',asm))) agriesma@328: (t as Const ("Script.Rewrite",_) $ Free (thmID_,idT) $ b $ f_) = wneuper@807: ((*writeln("3### assod: stac = "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t)); agriesma@328: writeln("3### assod: f(m)= "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) f));*) agriesma@328: if thmID = thmID_ then agriesma@328: if f = f_ then ((*writeln"3### assod ..Ass";*)Ass (m,f')) agriesma@328: else ((*writeln"### assod ..AssWeak"; agriesma@328: writeln("### assod: f(m) = "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) f)); wneuper@807: writeln("### assod: f(stac)= "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) f_));*) agriesma@328: AssWeak (m,f')) agriesma@328: else ((*writeln"3### assod ..NotAss";*)NotAss)) agriesma@328: agriesma@328: (*val f = (term_of o the o (parse thy))"#0+(sqrt(sqrt(sqrt a))^^^#2)^^^#2=#0"; agriesma@328: > val f'= (term_of o the o (parse thy))"#0+(sqrt(sqrt a))^^^#2=#0"; agriesma@328: > val m = Rewrite'("Script.thy","tless_true","eval_rls",false, agriesma@328: ("rroot_square_inv",""),f,(f',[])); wneuper@807: > val stac = (term_of o the o (parse thy)) agriesma@328: "Rewrite rroot_square_inv False (#0+(sqrt(sqrt(sqrt a))^^^#2)^^^#2=#0)"; wneuper@807: > assod e_rls m stac; agriesma@328: val it = agriesma@328: (Some (Rewrite' (#,#,#,#,#,#,#)),Const ("empty","RealDef.real"), wneuper@807: Const ("empty","RealDef.real")) : tac_ option * term * term*) agriesma@328: agriesma@328: | assod d (m as Rewrite_Set_Inst' (thy',put,sub,rls,f,(f',asm))) agriesma@328: (Const ("Script.Rewrite'_Set'_Inst",_) $ sub_ $ Free (rls_,_) $ _ $ f_)= agriesma@328: if id_rls rls = rls_ then agriesma@328: if f = f_ then Ass (m,f') else AssWeak (m,f') agriesma@328: else NotAss agriesma@328: wneuper@1408: | assod d (m as Detail_Set_Inst' (thy',put,sub,rls,f,(f',asm))) wneuper@1408: (Const ("Script.Rewrite'_Set'_Inst",_) $ sub_ $ Free (rls_,_) $ _ $ f_)= wneuper@1408: if id_rls rls = rls_ then wneuper@1408: if f = f_ then Ass (m,f') else AssWeak (m,f') wneuper@1408: else NotAss wneuper@1408: agriesma@328: | assod d (m as Rewrite_Set' (thy,put,rls,f,(f',asm))) agriesma@328: (Const ("Script.Rewrite'_Set",_) $ Free (rls_,_) $ _ $ f_) = agriesma@328: if id_rls rls = rls_ then agriesma@328: if f = f_ then Ass (m,f') else AssWeak (m,f') agriesma@328: else NotAss agriesma@328: wneuper@1408: | assod d (m as Detail_Set' (thy,put,rls,f,(f',asm))) wneuper@1408: (Const ("Script.Rewrite'_Set",_) $ Free (rls_,_) $ _ $ f_) = wneuper@1408: if id_rls rls = rls_ then wneuper@1408: if f = f_ then Ass (m,f') else AssWeak (m,f') wneuper@1408: else NotAss wneuper@1408: agriesma@328: | assod d (m as Calculate' (thy',op_,f,(f',thm'))) agriesma@328: (Const ("Script.Calculate",_) $ Free (op__,_) $ f_) = agriesma@328: if op_ = op__ then agriesma@328: if f = f_ then Ass (m,f') else AssWeak (m,f') agriesma@328: else NotAss agriesma@328: neuper@732: | assod _ (m as Check_elementwise' (consts,_,(consts_chkd,_))) agriesma@328: (Const ("Script.Check'_elementwise",_) $ consts' $ _) = neuper@750: ((*writeln("### assod Check'_elementwise: consts= "^(term2str consts)^ neuper@750: ", consts'= "^(term2str consts')); neuper@750: atomty(assoc_thy "Isac.thy")consts; atomty(assoc_thy "Isac.thy")consts';*) neuper@750: if consts = consts' then ((*writeln"### assod Check'_elementwise: Ass";*) neuper@750: Ass (m, consts_chkd)) neuper@750: else ((*writeln"### assod Check'_elementwise: NotAss";*) NotAss)) agriesma@328: agriesma@328: | assod _ (m as Or_to_List' (ors, list)) agriesma@328: (Const ("Script.Or'_to'_List",_) $ _) = agriesma@328: Ass (m, list) agriesma@328: wneuper@807: | assod _ (m as Tac_ (thy,f,id,f')) wneuper@807: (Const ("Script.Tac",_) $ Free (id',_)) = agriesma@328: if id = id' then Ass (m, ((term_of o the o (parse thy)) f')) agriesma@328: else NotAss agriesma@328: neuper@703: neuper@711: (* val t = str2term neuper@711: "SubProblem (DiffApp_,[make,function],[no_met]) \ neuper@711: \[real_ m_, real_ v_, bool_list_ rs_]"; neuper@711: wneuper@1124: val (Subproblem' ((domID,pblID,metID),_,_,_,f)) = m; neuper@711: val (Const ("Script.SubProblem",_) $ neuper@711: (Const ("Pair",_) $ neuper@711: Free (dI',_) $ wneuper@807: (Const ("Pair",_) $ pI' $ mI')) $ ags') = stac; neuper@711: *) wneuper@1124: | assod _ (Subproblem' ((domID,pblID,metID),_,_,_,f)) agriesma@328: (Const ("Script.SubProblem",_) $ neuper@703: (Const ("Pair",_) $ neuper@711: Free (dI',_) $ neuper@703: (Const ("Pair",_) $ pI' $ mI')) $ ags') = wneuper@1267: (*compare "| stac2tac_ thy (Const ("Script.SubProblem",_)"*) wneuper@1267: let val dI = ((implode o drop_last o explode) dI')^".thy"; wneuper@1267: val pI = ((map (de_esc_underscore o free2str)) o isalist2list) pI'; wneuper@1267: val mI = ((map (de_esc_underscore o free2str)) o isalist2list) mI'; wneuper@1267: val ags = isalist2list ags'; wneuper@1267: val thy = assoc_thy dI; wneuper@1267: val (pI, pors, mI) = wneuper@1267: if mI = ["no_met"] wneuper@1267: then let val pors = match_ags thy ((#ppc o get_pbt) pI) ags; wneuper@1267: val pI' = refine_ori' pors pI; wneuper@1267: in (pI', pors (*refinement over models with diff.prec only*), wneuper@1267: (hd o #met o get_pbt) pI') end wneuper@1267: else (pI, match_ags thy ((#ppc o get_pbt) pI) ags, mI); wneuper@1267: val (fmz_, vals) = oris2fmz_vals pors; wneuper@1267: val {cas, ppc,...} = get_pbt pI wneuper@1267: val {cas, ppc, thy,...} = get_pbt pI wneuper@1267: val dI = theory2theory' thy (*take dI from _refined_ pbl*) wneuper@1124: val hdl = case cas of wneuper@1267: None => pblterm dI pI wneuper@1267: | Some t => subst_atomic ((vars_of_pbl_' ppc) ~~~ vals) t wneuper@1267: val f = subpbl (strip_thy dI) pI wneuper@1267: in if domID = dI andalso pblID = pI wneuper@1267: then Ass (Subproblem' ((dI, pI, mI), pors, hdl, fmz_, f), f) wneuper@1267: else NotAss agriesma@328: end agriesma@328: agriesma@328: | assod d m t = agriesma@328: ( wneuper@807: (*writeln("### assod: NotAss m= "^(tac_2str m)^"\n stac= "^(term2str t));*) agriesma@328: NotAss); agriesma@328: agriesma@328: agriesma@328: wneuper@825: fun tac_2tac (Refine_Tacitly' (pI,_,_,_,_)) = Refine_Tacitly pI wneuper@856: | tac_2tac (Model_Problem' (pI,_)) = Model_Problem pI wneuper@825: | tac_2tac (Add_Given' (t,_)) = Add_Given t wneuper@825: | tac_2tac (Add_Find' (t,_)) = Add_Find t wneuper@825: | tac_2tac (Add_Relation' (t,_)) = Add_Relation t wneuper@825: wneuper@839: | tac_2tac (Specify_Theory' dI) = Specify_Theory dI wneuper@825: | tac_2tac (Specify_Problem' (dI,_)) = Specify_Problem dI wneuper@825: | tac_2tac (Specify_Method' (dI,_,_)) = Specify_Method dI wneuper@825: wneuper@825: | tac_2tac (Rewrite' (thy,rod,erls,put,(thmID,thm),f,(f',asm))) = wneuper@1408: Rewrite (thmID,thm) agriesma@328: wneuper@807: | tac_2tac (Rewrite_Inst' (thy,rod,erls,put,sub,(thmID,thm),f,(f',asm)))= wneuper@1408: Rewrite_Inst (subst2subs sub,(thmID,thm)) agriesma@328: wneuper@807: | tac_2tac (Rewrite_Set' (thy,put,rls,f,(f',asm))) = wneuper@1408: Rewrite_Set (id_rls rls) wneuper@1408: wneuper@1408: | tac_2tac (Detail_Set' (thy,put,rls,f,(f',asm))) = wneuper@1408: Detail_Set (id_rls rls) agriesma@328: wneuper@807: | tac_2tac (Rewrite_Set_Inst' (thy,put,sub,rls,f,(f',asm))) = wneuper@1408: Rewrite_Set_Inst (subst2subs sub,id_rls rls) wneuper@1408: wneuper@1408: | tac_2tac (Detail_Set_Inst' (thy,put,sub,rls,f,(f',asm))) = wneuper@1408: Detail_Set_Inst (subst2subs sub,id_rls rls) agriesma@328: wneuper@807: | tac_2tac (Calculate' (thy,op_,t,(t',thm'))) = Calculate (op_) agriesma@328: wneuper@807: | tac_2tac (Check_elementwise' (consts,pred,consts')) = wneuper@1408: Check_elementwise pred agriesma@328: wneuper@807: | tac_2tac (Or_to_List' _) = Or_to_List agriesma@328: wneuper@807: | tac_2tac (Tac_ (_,f,id,f')) = Tac id agriesma@328: wneuper@1124: | tac_2tac (Subproblem' ((domID, pblID, _), _, _,_,_)) = agriesma@328: Subproblem (domID, pblID) wneuper@807: | tac_2tac (Check_Postcond' (pblID, _)) = wneuper@807: Check_Postcond pblID wneuper@807: | tac_2tac Empty_Tac_ = Empty_Tac agriesma@328: wneuper@807: | tac_2tac m = wneuper@807: raise error ("tac_2tac: not impl. for "^(tac_2str m)); agriesma@328: agriesma@328: agriesma@328: wneuper@807: wneuper@807: (** decompose tac_ to a rule and to (lhs,rhs) agriesma@328: unly needed ~~~ **) agriesma@328: agriesma@328: val idT = Type ("Script.ID",[]); agriesma@328: (*val tt = (term_of o the o (parse thy)) "square_equation_left::ID"; agriesma@328: type_of tt = idT; agriesma@328: val it = true : bool agriesma@328: *) agriesma@328: (* 13.3.01 agriesma@328: v agriesma@328: *) agriesma@328: fun make_rule thy t = agriesma@328: let val ct = cterm_of (sign_of thy) (Trueprop $ t) agriesma@328: in Thm (string_of_cterm ct, make_thm ct) end; agriesma@328: agriesma@328: (* val (Rewrite_Inst'(thy',rod,rls,put,subs,(thmID,thm),f,(f',asm)))=m; agriesma@328: *) wneuper@1250: (*decompose tac_ to a rule and to (lhs,rhs) for ets FIXME.12.03: obsolete! wneuper@1250: NOTE.12.03: also used for msg 'not locatable' ?!: 'Subproblem' missing !!!*) wneuper@807: fun rep_tac_ (Rewrite_Inst' agriesma@328: (thy',rod,rls,put,subs,(thmID,thm),f,(f',asm))) = agriesma@328: let val fT = type_of f; agriesma@328: val b = if put then HOLogic.true_const else HOLogic.false_const; agriesma@328: val sT = (type_of o fst o hd) subs; agriesma@328: val subs' = list2isalist (HOLogic.mk_prodT (sT, sT)) agriesma@328: (map HOLogic.mk_prod subs); agriesma@328: val sT' = type_of subs'; agriesma@328: val lhs = Const ("Script.Rewrite'_Inst",[sT',idT,(*fT*)bool,fT] ---> fT) agriesma@328: $ subs' $ Free (thmID,idT) $ b $ f; agriesma@328: in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end agriesma@328: (*Fehlersuche 25.4.01 agriesma@328: (a)----- als String zusammensetzen: agriesma@328: ML> Sign.string_of_term (sign_of thy)f; agriesma@328: val it = "d_d x #4 + d_d x (x ^^^ #2 + #3 * x)" : string agriesma@328: ML> Sign.string_of_term (sign_of thy)f'; agriesma@328: val it = "#0 + d_d x (x ^^^ #2 + #3 * x)" : string agriesma@328: ML> subs; agriesma@328: val it = [(Free ("bdv","RealDef.real"),Free ("x","RealDef.real"))] : subst agriesma@328: > val tt = (term_of o the o (parse thy)) agriesma@328: "(Rewrite_Inst[(bdv,x)]diff_const False(d_d x #4 + d_d x (x ^^^ #2 + #3 * x)))=(#0 + d_d x (x ^^^ #2 + #3 * x))"; agriesma@328: > atomty thy tt; agriesma@328: ML> writeln(Sign.string_of_term (sign_of thy)tt); agriesma@328: (Rewrite_Inst [(bdv,x)] diff_const False d_d x #4 + d_d x (x ^^^ #2 + #3 * x)) = agriesma@328: #0 + d_d x (x ^^^ #2 + #3 * x) agriesma@328: wneuper@807: (b)----- laut rep_tac_: agriesma@328: > val ttt=HOLogic.mk_eq (lhs,f'); agriesma@328: > atomty thy ttt; agriesma@328: agriesma@328: agriesma@328: (*Fehlersuche 1-2Monate vor 4.01:*) agriesma@328: > val tt = (term_of o the o (parse thy)) agriesma@328: "Rewrite_Inst[(bdv,x)]square_equation_left True(x=#1+#2)"; agriesma@328: > atomty thy tt; agriesma@328: agriesma@328: > val f = (term_of o the o (parse thy)) "x=#1+#2"; agriesma@328: > val f' = (term_of o the o (parse thy)) "x=#3"; agriesma@328: > val subs = [((term_of o the o (parse thy)) "bdv", agriesma@328: (term_of o the o (parse thy)) "x")]; agriesma@328: > val sT = (type_of o fst o hd) subs; agriesma@328: > val subs' = list2isalist (HOLogic.mk_prodT (sT, sT)) agriesma@328: (map HOLogic.mk_prod subs); agriesma@328: > val sT' = type_of subs'; agriesma@328: > val lhs = Const ("Script.Rewrite'_Inst",[sT',idT,fT,fT] ---> fT) agriesma@328: $ subs' $ Free (thmID,idT) $ HOLogic.true_const $ f; agriesma@328: > lhs = tt; agriesma@328: val it = true : bool wneuper@807: > rep_tac_ (Rewrite_Inst' agriesma@328: ("Script.thy","tless_true","eval_rls",false,subs, agriesma@328: ("square_equation_left",""),f,(f',[]))); agriesma@328: *) wneuper@807: | rep_tac_ (Rewrite' (thy',rod,rls,put,(thmID,thm),f,(f',asm)))= agriesma@328: let agriesma@328: val fT = type_of f; agriesma@328: val b = if put then HOLogic.true_const else HOLogic.false_const; agriesma@328: val lhs = Const ("Script.Rewrite",[idT,HOLogic.boolT,fT] ---> fT) agriesma@328: $ Free (thmID,idT) $ b $ f; agriesma@328: in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end agriesma@328: (* agriesma@328: > val tt = (term_of o the o (parse thy)) (*____ ____..test*) agriesma@328: "Rewrite square_equation_left True (x=#1+#2) = (x=#3)"; agriesma@328: agriesma@328: > val f = (term_of o the o (parse thy)) "x=#1+#2"; agriesma@328: > val f' = (term_of o the o (parse thy)) "x=#3"; agriesma@328: > val Thm (id,thm) = wneuper@807: rep_tac_ (Rewrite' agriesma@328: ("Script.thy","tless_true","eval_rls",false, agriesma@328: ("square_equation_left",""),f,(f',[]))); agriesma@328: > val Some ct = parse thy agriesma@328: "Rewrite square_equation_left True (x=#1+#2)"; agriesma@328: > rewrite_ Script.thy tless_true eval_rls true thm ct; agriesma@328: val it = Some ("x = #3",[]) : (cterm * cterm list) option agriesma@328: *) wneuper@807: | rep_tac_ (Rewrite_Set_Inst' agriesma@328: (thy',put,subs,rls,f,(f',asm))) = agriesma@328: let val fT = type_of f; agriesma@328: val sT = (type_of o fst o hd) subs; agriesma@328: val subs' = list2isalist (HOLogic.mk_prodT (sT, sT)) agriesma@328: (map HOLogic.mk_prod subs); agriesma@328: val sT' = type_of subs'; agriesma@328: val b = if put then HOLogic.true_const else HOLogic.false_const agriesma@328: val lhs = Const ("Script.Rewrite'_Set'_Inst", agriesma@328: [sT',idT,fT,fT] ---> fT) agriesma@328: $ subs' $ Free (id_rls rls,idT) $ b $ f; agriesma@328: in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end agriesma@328: (* ... vals from Rewrite_Inst' ... wneuper@807: > rep_tac_ (Rewrite_Set_Inst' agriesma@328: ("Script.thy",false,subs, agriesma@328: "isolate_bdv",f,(f',[]))); agriesma@328: *) agriesma@328: (* val (Rewrite_Set' (thy',put,rls,f,(f',asm)))=m; agriesma@328: *) wneuper@807: | rep_tac_ (Rewrite_Set' (thy',put,rls,f,(f',asm)))= agriesma@328: let val fT = type_of f; agriesma@328: val b = if put then HOLogic.true_const else HOLogic.false_const; agriesma@328: val lhs = Const ("Script.Rewrite'_Set",[idT,bool,fT] ---> fT) agriesma@328: $ Free (id_rls rls,idT) $ b $ f; agriesma@328: in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end agriesma@328: (* 13.3.01: agriesma@328: val thy = assoc_thy thy'; agriesma@328: val t = HOLogic.mk_eq (lhs,f'); agriesma@328: make_rule thy t; agriesma@328: -------------------------------------------------- agriesma@328: val lll = (term_of o the o (parse thy)) agriesma@328: "Rewrite_Set SqRoot_simplify False (d_d x (x ^^^ #2 + #3 * x) + d_d x #4)"; agriesma@328: agriesma@328: -------------------------------------------------- agriesma@328: > val f = (term_of o the o (parse thy)) "x=#1+#2"; agriesma@328: > val f' = (term_of o the o (parse thy)) "x=#3"; agriesma@328: > val Thm (id,thm) = wneuper@807: rep_tac_ (Rewrite_Set' agriesma@328: ("Script.thy",false,"SqRoot_simplify",f,(f',[]))); agriesma@328: val id = "(Rewrite_Set SqRoot_simplify True x = #1 + #2) = (x = #3)" : string agriesma@328: val thm = "(Rewrite_Set SqRoot_simplify True x = #1 + #2) = (x = #3)" : thm agriesma@328: *) wneuper@807: | rep_tac_ (Calculate' (thy',op_,f,(f',thm')))= agriesma@328: let val fT = type_of f; agriesma@328: val lhs = Const ("Script.Calculate",[idT,fT] ---> fT) agriesma@328: $ Free (op_,idT) $ f agriesma@328: in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end agriesma@328: (* agriesma@328: > val lhs'=(term_of o the o (parse thy))"Calculate plus (#1+#2)"; agriesma@328: ... test-root-equ.sml: calculate ... agriesma@328: > val Appl m'=applicable_in p pt (Calculate "plus"); wneuper@807: > val (lhs,_)=tac_2etac m'; agriesma@328: > lhs'=lhs; agriesma@328: val it = true : bool*) wneuper@807: | rep_tac_ (Check_elementwise' (t,str,(t',asm))) = (Erule, (e_term, t')) wneuper@1250: | rep_tac_ (Subproblem' (_,_,_,_,t')) = (Erule, (e_term, t')) wneuper@1250: | rep_tac_ (Or_to_List' (t, t')) = (Erule, (t, t')) wneuper@807: | rep_tac_ m = raise error ("rep_tac_: not impl.for "^ wneuper@807: (tac_2str m)); agriesma@328: neuper@742: (*"N.3.6.03------ wneuper@807: fun tac_2rule m = (fst o rep_tac_) m; wneuper@807: fun tac_2etac m = (snd o rep_tac_) m; wneuper@807: fun tac_2tac m = (fst o snd o rep_tac_) m;*) wneuper@807: fun tac_2res m = (snd o snd o rep_tac_) m;(*ONLYuse of rep_tac_ wneuper@807: FIXXXXME: simplify rep_tac_*) agriesma@328: agriesma@328: agriesma@328: (* use"ME/script.sml"; agriesma@328: use"script.sml"; agriesma@328: *) agriesma@328: agriesma@328: agriesma@328: agriesma@328: wneuper@807: (** locate an applicable stactic in a script **) agriesma@328: agriesma@328: datatype assoc = (*ExprVal in the sense of denotational semantics*) wneuper@807: Assoc of (*the stac is associated, strongly or weakly*) agriesma@328: scrstate * (*the current; returned for next_tac etc. outside ass* *) wneuper@807: (step list) (*list of steps done until associated stac found; agriesma@328: initiated with the data for doing the 1st step, agriesma@328: thus the head holds these data further on, agriesma@328: while the tail holds steps finished (incl.scrstate in ptree)*) wneuper@807: | NasApp of (*stac not associated, but applicable, ptree-node generated*) agriesma@328: scrstate * (step list) wneuper@807: | NasNap of (*stac not associated, not applicable, nothing generated; agriesma@328: for distinction in Or, for leaving iterations, leaving Seq, agriesma@328: evaluate scriptexpressions*) agriesma@328: term * env; agriesma@328: fun assoc2str (Assoc _) = "Assoc" agriesma@328: | assoc2str (NasNap _) = "NasNap" agriesma@328: | assoc2str (NasApp _) = "NasApp"; agriesma@328: agriesma@328: agriesma@328: datatype asap = (*arg. of assy _only_ for distinction w.r.t. Or*) agriesma@328: Aundef (*undefined: set only by (topmost) Or*) wneuper@807: | AssOnly (*do not execute appl stacs - there could be an associated agriesma@328: in parallel Or-branch*) agriesma@328: | AssGen; (*no Ass(Weak) found within Or, thus wneuper@807: search for _applicable_ stacs, execute and generate pt*) agriesma@328: (*this constructions doesnt allow arbitrary nesting of Or !!!*) agriesma@328: agriesma@328: wneuper@807: (*assy, ass_up, astep_up scanning for locate_gen at stactic in a script. agriesma@328: search is clearly separated into (1)-(2): agriesma@328: (1) assy is recursive descent; agriesma@328: (2) ass_up resumes interpretation at a location somewhere in the script; agriesma@328: astep_up does only get to the parentnode of the scriptexpr. agriesma@328: consequence: agriesma@328: * call of (2) means _always_ that in this branch below wneuper@807: there was an appl.stac (Repeat, Or e1, ...) agriesma@328: *) agriesma@328: wneuper@1250: fun assy ya (is as (E,l,a,v,S,b),ss) agriesma@328: (Const ("Let",_) $ e $ (Abs (id,T,body))) = wneuper@1250: ((*writeln("### assy Let$e$Abs: is="); wneuper@1250: writeln(istate2str (ScrState is));*) wneuper@1250: case assy ya ((E , l@[L,R], a,v,S,b),ss) e of agriesma@328: NasApp ((E',l,a,v,S,bb),ss) => agriesma@328: let val id' = mk_Free (id, T); agriesma@328: val E' = upd_env E' (id', v); agriesma@328: (*val _=writeln("### assy Let -> NasApp");*) agriesma@328: in assy ya ((E', l@[R,D], a,v,S,b),ss) body end agriesma@328: | NasNap (v,E) => agriesma@328: let val id' = mk_Free (id, T); agriesma@328: val E' = upd_env E (id', v); agriesma@328: (*val _=writeln("### assy Let -> NasNap");*) agriesma@328: in assy ya ((E', l@[R,D], a,v,S,b),ss) body end agriesma@328: | ay => ay) agriesma@328: agriesma@328: | assy (ya as (((thy,srls),_),_)) ((E,l,_,v,S,b),ss) agriesma@328: (Const ("Script.While",_) $ c $ e $ a) = agriesma@328: ((*writeln("### assy While $ c $ e $ a, upd_env= "^ agriesma@328: (subst2str (upd_env E (a,v))));*) agriesma@328: if eval_true_ thy srls (subst_atomic (upd_env E (a,v)) c) agriesma@328: then assy ya ((E, l@[L,R], Some a,v,S,b),ss) e agriesma@328: else NasNap (v, E)) agriesma@328: agriesma@328: | assy (ya as (((thy,srls),_),_)) ((E,l,a,v,S,b),ss) agriesma@328: (Const ("Script.While",_) $ c $ e) = agriesma@328: ((*writeln("### assy While, l= "^(loc_2str l));*) agriesma@328: if eval_true_ thy srls (subst_atomic (upd_env_opt E (a,v)) c) agriesma@328: then assy ya ((E, l@[R], a,v,S,b),ss) e agriesma@328: else NasNap (v, E)) agriesma@328: agriesma@328: | assy (ya as (((thy,srls),_),_)) ((E,l,a,v,S,b),ss) agriesma@328: (Const ("If",_) $ c $ e1 $ e2) = agriesma@328: (if eval_true_ thy srls (subst_atomic (upd_env_opt E (a,v)) c) agriesma@328: then assy ya ((E, l@[L,R], a,v,S,b),ss) e1 agriesma@328: else assy ya ((E, l@[ R], a,v,S,b),ss) e2) agriesma@328: agriesma@328: | assy ya ((E,l,_,v,S,b),ss) (Const ("Script.Try",_) $ e $ a) = agriesma@328: ((*writeln("### assy Try, l= "^(loc_2str l));*) agriesma@328: case assy ya ((E, l@[L,R], Some a,v,S,b),ss) e of agriesma@328: ay => ay) agriesma@328: agriesma@328: | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Try",_) $ e) = agriesma@328: ((*writeln("### assy Try, l= "^(loc_2str l));*) agriesma@328: case assy ya ((E, l@[R], a,v,S,b),ss) e of agriesma@328: ay => ay) agriesma@328: agriesma@328: | assy ya ((E,l,_,v,S,b),ss) (Const ("Script.Seq",_) $e1 $ e2 $ a) = agriesma@328: ((*writeln("### assy Seq $e1 $ e2 $ a, E= "^(subst2str E));*) agriesma@328: case assy ya ((E, l@[L,L,R], Some a,v,S,b),ss) e1 of agriesma@328: NasNap (v, E) => assy ya ((E, l@[L,R], Some a,v,S,b),ss) e2 agriesma@328: | NasApp ((E,_,_,v,_,_),ss) => agriesma@328: assy ya ((E, l@[L,R], Some a,v,S,b),ss) e2 agriesma@328: | ay => ay) agriesma@328: agriesma@328: | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Seq",_) $e1 $ e2) = agriesma@328: (case assy ya ((E, l@[L,R], a,v,S,b),ss) e1 of agriesma@328: NasNap (v, E) => assy ya ((E, l@[R], a,v,S,b),ss) e2 agriesma@328: | NasApp ((E,_,_,v,_,_),ss) => agriesma@328: assy ya ((E, l@[R], a,v,S,b),ss) e2 agriesma@328: | ay => ay) agriesma@328: agriesma@328: | assy ya ((E,l,_,v,S,b),ss) (Const ("Script.Repeat",_) $ e $ a) = agriesma@328: assy ya ((E,(l@[L,R]),Some a,v,S,b),ss) e agriesma@328: agriesma@328: | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Repeat",_) $ e) = agriesma@328: assy ya ((E,(l@[R]),a,v,S,b),ss) e agriesma@328: agriesma@328: (*15.6.02: ass,app Or nochmals "uberlegen FIXXXME*) agriesma@328: | assy (y, Aundef) ((E,l,_,v,S,b),ss) (Const ("Script.Or",_) $e1 $ e2 $ a) = agriesma@328: (case assy (y, AssOnly) ((E,(l@[L,L,R]),Some a,v,S,b),ss) e1 of agriesma@328: NasNap (v, E) => agriesma@328: (case assy (y, AssOnly) ((E,(l@[L,R]),Some a,v,S,b),ss) e2 of agriesma@328: NasNap (v, E) => agriesma@328: (case assy (y, AssGen) ((E,(l@[L,L,R]),Some a,v,S,b),ss) e1 of agriesma@328: NasNap (v, E) => agriesma@328: assy (y, AssGen) ((E, (l@[L,R]), Some a,v,S,b),ss) e2 agriesma@328: | ay => ay) agriesma@328: | ay =>(ay)) agriesma@328: | NasApp _ => raise error ("assy: FIXXXME ///must not return NasApp///") agriesma@328: | ay => (ay)) agriesma@328: agriesma@328: | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Or",_) $e1 $ e2) = agriesma@328: (case assy ya ((E,(l@[L,R]),a,v,S,b),ss) e1 of agriesma@328: NasNap (v, E) => agriesma@328: assy ya ((E,(l@[R]),a,v,S,b),ss) e2 agriesma@328: | ay => (ay)) agriesma@328: (* val ((m,_,pt,(p,p_),c)::ss) = [(m,EmptyMout,pt,p,[])]; agriesma@328: val t = (term_of o the o (parse Isac.thy)) "Rewrite rmult_1 False"; neuper@711: neuper@711: val (ap,(p,p_),c,ss) = (Aundef,p,[],[]); neuper@711: assy (((thy',srls),d),ap) ((E,l,a,v,S,b), (m,EmptyMout,pt,(p,p_),c)::ss) t; agriesma@328: *) agriesma@328: wneuper@1250: | assy (((thy',sr),d),ap) (is as (E,l,a,v,S,b), (m,_,pt,(p,p_),c)::ss) t = wneuper@1250: ((*writeln("### assy, is= "); wneuper@1250: writeln(istate2str (ScrState is));*) wneuper@1250: case subst_stacexpr E a v t of neuper@711: Expr s => wneuper@825: ((*writeln("### assy: listexpr t= "^(term2str t)); neuper@711: writeln("### assy, E= "^(env2str E)); neuper@711: writeln("### assy, eval(..)= "^(term2str neuper@711: (eval_listexpr_ (assoc_thy thy') sr wneuper@825: (subst_atomic (upd_env_opt E (a,v)) t))));*) neuper@711: NasNap (eval_listexpr_ (assoc_thy thy') sr neuper@711: (subst_atomic (upd_env_opt E (a,v)) t), E)) wneuper@807: (* val STac stac = subst_stacexpr E a v t; neuper@711: *) wneuper@807: | STac stac => neuper@711: let val p' = case p_ of Frm => p | Res => lev_on p neuper@711: | _ => raise error ("assy: call by "^ neuper@711: (pos'2str (p,p_))); wneuper@807: in case assod d m stac of agriesma@328: Ass (m,v') => agriesma@328: let val (p'',c',f',pt') = generate1 (assoc_thy thy') m agriesma@328: (ScrState (E,l,a,v',S,true)) (p',p_) pt; agriesma@328: in Assoc ((E,l,a,v',S,true), (m,f',pt',p'',c @ c')::ss) end agriesma@328: | AssWeak (m,v') => agriesma@328: let val (p'',c',f',pt') = generate1 (assoc_thy thy') m agriesma@328: (ScrState (E,l,a,v',S,false)) (p',p_) pt; agriesma@328: in Assoc ((E,l,a,v',S,false), (m,f',pt',p'',c @ c')::ss) end agriesma@328: | NotAss => agriesma@328: (case ap of (*switch for Or: 1st AssOnly, 2nd AssGen*) agriesma@328: AssOnly => (NasNap (v, E)) agriesma@328: | gen => (case applicable_in (p,p_) pt wneuper@807: (stac2tac (assoc_thy thy') stac) of agriesma@328: Appl m' => wneuper@807: let val is = (E,l,a,tac_2res m',S,false(*FIXXXME*)) agriesma@328: val (p'',c',f',pt') = agriesma@328: generate1 (assoc_thy thy') m' (ScrState is) (p',p_) pt; agriesma@328: in NasApp (is,(m,f',pt',p'',c @ c')::ss) end agriesma@328: | Notappl _ => agriesma@328: (NasNap (v, E)) agriesma@328: ) agriesma@328: ) wneuper@1250: end); agriesma@328: (* (astep_up ((thy',scr,d),NasApp_) ((E,l,a,v,S,b),[(m,EmptyMout,pt,p,[])])) handle e => print_exn_G e; agriesma@328: *) agriesma@328: neuper@742: neuper@742: (* val (ys as (y,s,Script sc,d), Const ("Let",_) $ _) = (ys, go up sc); neuper@742: *) wneuper@1250: fun ass_up (ys as (y,s,Script sc,d)) (is as (E,l,a,v,S,b),ss) agriesma@328: (Const ("Let",_) $ _) = wneuper@1250: let (*val _= writeln("### ass_up1 Let$e: is=") wneuper@1250: val _= writeln(istate2str (ScrState is))*) wneuper@1250: val l = drop_last l; (*comes from e, goes to Abs*) agriesma@328: val (Const ("Let",_) $ e $ (Abs (i,T,body))) = go l sc; agriesma@328: val i = mk_Free (i, T); agriesma@328: val E = upd_env E (i, v); wneuper@1250: (*val _=writeln("### ass_up2 Let$e: E="^(subst2str E));*) agriesma@328: in case assy (((y,s),d),Aundef) ((E, l@[R,D], a,v,S,b),ss) body of agriesma@328: Assoc iss => Assoc iss agriesma@328: | NasApp iss => astep_up ys iss agriesma@328: | NasNap (v, E) => astep_up ys ((E,l,a,v,S,b),ss) end agriesma@328: agriesma@328: | ass_up ys iss (Abs (_,_,_)) = agriesma@328: astep_up ys iss (*TODO 5.9.00: env ?*) agriesma@328: wneuper@1250: | ass_up ys (iss as (is,_)) (Const ("Let",_) $ e $ (Abs (i,T,b)))= wneuper@1250: ((*writeln("### ass_up Let$e$Abs: is="); wneuper@1250: writeln(istate2str (ScrState is));*) wneuper@1250: astep_up ys iss) (*TODO 5.9.00: env ?*) agriesma@328: agriesma@328: agriesma@328: | ass_up ysa iss (Const ("Script.Seq",_) $ _ $ _ $ _) = agriesma@328: astep_up ysa iss (*all has been done in (*2*) below*) agriesma@328: agriesma@328: | ass_up ysa iss (Const ("Script.Seq",_) $ _ $ _) = agriesma@328: astep_up ysa iss (*2*: comes from e2*) agriesma@328: wneuper@1250: | ass_up (ysa as (y,s,Script sc,d)) (is as (E,l,a,v,S,b),ss) agriesma@328: (Const ("Script.Seq",_) $ _ ) = (*2*: comes from e1, goes to e2*) agriesma@328: let val up = drop_last l; wneuper@1250: val Const ("Script.Seq",_) $ _ $ e2 = go up sc wneuper@1250: (*val _= writeln("### ass_up Seq$e: is=") wneuper@1250: val _= writeln(istate2str (ScrState is))*) agriesma@328: in case assy (((y,s),d),Aundef) ((E, up@[R], a,v,S,b),ss) e2 of agriesma@328: NasNap (v,E) => astep_up ysa ((E,up,a,v,S,b),ss) agriesma@328: | NasApp iss => astep_up ysa iss agriesma@328: | ay => ay end agriesma@328: agriesma@328: | ass_up ysa iss (Const ("Script.Try",_) $ e $ _) = agriesma@328: astep_up ysa iss agriesma@328: agriesma@328: | ass_up ysa iss (Const ("Script.Try",_) $ e) = agriesma@328: astep_up ysa iss agriesma@328: agriesma@328: | ass_up (ys as (y,s,_,d)) ((E,l,_,v,S,b),ss) agriesma@328: (Const ("Script.While",_) $ c $ e $ a) = agriesma@328: ((*writeln("### ass_up: While c= "^ agriesma@328: (term2str (subst_atomic (upd_env E (a,v)) c)));*) agriesma@328: if eval_true_ y s (subst_atomic (upd_env E (a,v)) c) agriesma@328: then (case assy (((y,s),d),Aundef) ((E, l@[L,R], Some a,v,S,b),ss) e of agriesma@328: NasNap (v,E') => astep_up ys ((E',l, Some a,v,S,b),ss) agriesma@328: | NasApp ((E',l,a,v,S,b),ss) => agriesma@328: ass_up ys ((E',l,a,v,S,b),ss) t agriesma@328: | ay => ay) agriesma@328: else astep_up ys ((E,l, Some a,v,S,b),ss) agriesma@328: ) agriesma@328: agriesma@328: | ass_up (ys as (y,s,_,d)) ((E,l,a,v,S,b),ss) agriesma@328: (Const ("Script.While",_) $ c $ e) = agriesma@328: if eval_true_ y s (subst_atomic (upd_env_opt E (a,v)) c) agriesma@328: then (case assy (((y,s),d),Aundef) ((E, l@[R], a,v,S,b),ss) e of agriesma@328: NasNap (v,E') => astep_up ys ((E',l, a,v,S,b),ss) agriesma@328: | NasApp ((E',l,a,v,S,b),ss) => agriesma@328: ass_up ys ((E',l,a,v,S,b),ss) t agriesma@328: | ay => ay) agriesma@328: else astep_up ys ((E,l, a,v,S,b),ss) agriesma@328: agriesma@328: | ass_up y iss (Const ("If",_) $ _ $ _ $ _) = astep_up y iss agriesma@328: agriesma@328: | ass_up (ys as (y,s,_,d)) ((E,l,_,v,S,b),ss) agriesma@328: (t as Const ("Script.Repeat",_) $ e $ a) = agriesma@328: (case assy (((y,s),d), Aundef) ((E, (l@[L,R]), Some a,v,S,b),ss) e of agriesma@328: NasNap (v,E') => astep_up ys ((E',l, Some a,v,S,b),ss) agriesma@328: | NasApp ((E',l,a,v,S,b),ss) => agriesma@328: ass_up ys ((E',l,a,v,S,b),ss) t agriesma@328: | ay => ay) agriesma@328: agriesma@328: | ass_up (ys as (y,s,_,d)) (is as ((E,l,a,v,S,b),ss)) agriesma@328: (t as Const ("Script.Repeat",_) $ e) = agriesma@328: (case assy (((y,s),d), Aundef) ((E, (l@[R]), a,v,S,b),ss) e of agriesma@328: NasNap (v', E') => astep_up ys ((E',l,a,v',S,b),ss) agriesma@328: | NasApp ((E',l,a,v',S,bb),ss) => agriesma@328: ass_up ys ((E',l,a,v',S,b),ss) t agriesma@328: | ay => ay) agriesma@328: agriesma@328: | ass_up y iss (Const ("Script.Or",_) $ _ $ _ $ _) = astep_up y iss agriesma@328: agriesma@328: | ass_up y iss (Const ("Script.Or",_) $ _ $ _) = astep_up y iss agriesma@328: agriesma@328: | ass_up y ((E,l,a,v,S,b),ss) (Const ("Script.Or",_) $ _ ) = agriesma@328: astep_up y ((E, (drop_last l), a,v,S,b),ss) agriesma@328: agriesma@328: | ass_up y iss t = agriesma@328: raise error ("ass_up not impl for t= "^(term2str t)) neuper@750: (* 9.6.03 neuper@750: val (ys as (_,_,Script sc,_), ss) = neuper@742: ((thy',srls,scr,d), [(m,EmptyMout,pt,p,[])]:step list); neuper@742: astep_up ys ((E,l,a,v,S,b),ss); neuper@742: *) agriesma@328: and astep_up (ys as (_,_,Script sc,_)) ((E,l,a,v,S,b),ss) = agriesma@328: if 1 < length l agriesma@328: then agriesma@328: let val up = drop_last l; wneuper@1250: (*val _= writeln("### astep_up: E= "env2str E);*) agriesma@328: in ass_up ys ((E,up,a,v,S,b),ss) (go up sc) end agriesma@328: else (NasNap (v, E)) agriesma@328: ; agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: agriesma@328: (* use"ME/script.sml"; agriesma@328: use"script.sml"; neuper@750: term2str (go up sc); neuper@750: agriesma@328: *) agriesma@328: wneuper@807: (*check if there are tacs for rewriting only*) agriesma@328: fun rew_only ([]:step list) = true agriesma@328: | rew_only (((Rewrite' _ ,_,_,_,_))::ss) = rew_only ss agriesma@328: | rew_only (((Rewrite_Inst' _ ,_,_,_,_))::ss) = rew_only ss agriesma@328: | rew_only (((Rewrite_Set' _ ,_,_,_,_))::ss) = rew_only ss agriesma@328: | rew_only (((Rewrite_Set_Inst' _ ,_,_,_,_))::ss) = rew_only ss agriesma@328: | rew_only (((Calculate' _ ,_,_,_,_))::ss) = rew_only ss agriesma@328: | rew_only (((Begin_Trans' _ ,_,_,_,_))::ss) = rew_only ss agriesma@328: | rew_only (((End_Trans' _ ,_,_,_,_))::ss) = rew_only ss agriesma@328: | rew_only _ = false; agriesma@328: agriesma@328: agriesma@328: datatype locate = agriesma@328: Steps of istate (*producing hd of step list (which was latest) agriesma@328: for next_tac, for reporting Safe|Unsafe to DG*) agriesma@328: * step (*(scrstate producing this step is in ptree !)*) agriesma@328: list (*locate_gen may produce intermediate steps*) agriesma@328: | NotLocatable; (*no (m Ass m') or (m AssWeak m') found*) agriesma@328: agriesma@328: agriesma@328: wneuper@807: (* locate_gen tries to locate an input tac m in the script. agriesma@328: pursuing this goal the script is executed until an (m' equiv m) is found, agriesma@328: or the end of the script agriesma@328: args agriesma@328: m : input by the user, already checked by applicable_in, agriesma@328: (to be searched within Or; and _not_ an m doing the step on ptree !) agriesma@328: p,pt: (incl ets) at the time of input agriesma@328: scr : the script agriesma@328: d : canonical simplifier for locating Take, Substitute, Subproblems etc. agriesma@328: ets : ets at the time of input wneuper@807: l : the location (in scr) of the stac which generated the current formula agriesma@328: returns agriesma@328: Steps: pt,p (incl. ets) with m done agriesma@328: pos' list of proofobjs cut (from generate) agriesma@328: safe: implied from last proofobj agriesma@328: ets: wneuper@807: ///ToDo : ets contains a list of tacs to be done before m can be done agriesma@328: NOT IMPL. -- "error: do other step before" agriesma@328: NotLocatable: thus generate_hard agriesma@328: *) agriesma@328: (* val (Rewrite'(_,ro,er,pa,(id,str),f,_), p, Rfuns {locate_rule=lo,...}, agriesma@328: RrlsState (_,f'',rss,rts)) = (m, (p,p_), sc, is); agriesma@328: *) agriesma@328: fun locate_gen (thy',_) (Rewrite'(_,ro,er,pa,(id,str),f,_)) (pt,p) agriesma@328: (Rfuns {locate_rule=lo,...}, d) (RrlsState (_,f'',rss,rts)) = agriesma@328: (case lo rss f (Thm (id, mk_thm (assoc_thy thy') str)) of agriesma@328: [] => NotLocatable agriesma@328: | rts' => agriesma@328: Steps (rts2steps [] ((pt,p),(f,f'',rss,rts),(thy',ro,er,pa)) rts')) agriesma@328: (* val p as(p',p_)=(p,p_);val scr as Script(h $ body)=sc;val (E,l,a,v,S,bb)=is; wneuper@807: locate_gen (thy':theory') (m:tac_) ((pt,p):ptree * pos') agriesma@328: (scr,d) (E,l,a,v,S,bb); neuper@750: 9.6.03 neuper@711: val ts = (thy',srls); neuper@711: val p = (p,p_); agriesma@328: val (scr as Script (h $ body)) = (sc); agriesma@328: val ScrState (E,l,a,v,S,b) = (is); wneuper@1250: wneuper@1250: val (ts as (thy',srls), m, (pt,p), (scr as Script (h $ body),d), (ScrState (E,l,a,v,S,b))) = ((thy',srls), m, (pt,(p,p_)), (sc,d), is); neuper@711: locate_gen (thy',srls) m (pt,p) (Script(h $ body),d)(ScrState(E,l,a,v,S,b)); agriesma@328: *) wneuper@807: | locate_gen (ts as (thy',srls)) (m:tac_) ((pt,p):ptree * pos') agriesma@328: (scr as Script (h $ body),d) (ScrState (E,l,a,v,S,b)) = wneuper@1250: let (*val _= writeln("### locate_gen-----------------: is="); wneuper@1250: val _= writeln( istate2str (ScrState (E,l,a,v,S,b)));*) agriesma@328: val thy = assoc_thy thy'; agriesma@328: in case if l=[] then (assy ((ts,d),Aundef) ((E,[R],a,v,S,b), agriesma@328: [(m,EmptyMout,pt,p,[])]) body) neuper@732: (* val Assoc (iss as (is as (_,_,_,_,_,bb), ss as ((m',f',pt',p',c')::_))) = wneuper@1250: (astep_up (thy',srls,scr,d) ((E,l,a,v,S,b),[(m,EmptyMout,pt,p,[])])); neuper@732: (assy ((ts,d),Aundef) ((E,[R],a,v,S,b),[(m,EmptyMout,pt,p,[])]) body); neuper@732: *) agriesma@328: else (astep_up (thy',srls,scr,d) ((E,l,a,v,S,b), wneuper@1250: [(m,EmptyMout,pt,p,[])]) ) of agriesma@328: Assoc (iss as (is as (_,_,_,_,_,bb), ss as ((m',f',pt',p',c')::_))) => agriesma@328: ((*writeln("### locate_gen: p'="^(pos'2str p'));*) agriesma@328: if bb then Steps (ScrState is, ss) agriesma@328: else if rew_only ss (*andalso 'not bb'= associated weakly*) agriesma@328: then let (*val _=writeln("### locate_gen, bef g1: p="^(pos'2str p));*) agriesma@328: val (po,p_) = p; agriesma@328: val po' = case p_ of Frm => po | Res => lev_on po wneuper@1250: (*WN.12.03: noticed, that pos is also updated in assy !?! wneuper@1250: instead take p' from Assoc ?????????????????????????????*) neuper@711: val (p'',c'',f'',pt'') = neuper@711: generate1 thy m (ScrState is) (po',p_) pt; agriesma@328: (*val _=writeln("### locate_gen, aft g1: p''="^(pos'2str p''));*) agriesma@328: (*drop the intermediate steps !*) agriesma@328: in Steps (ScrState is, [(m, f'',pt'',p'',c'')]) end agriesma@328: else Steps (ScrState is, ss)) agriesma@328: agriesma@328: | NasApp _ (*[((E,l,a,v,S,bb),(m',f',pt',p',c'))] => agriesma@328: raise error ("locate_gen: should not have got NasApp, ets =")*) agriesma@328: => NotLocatable agriesma@328: | NasNap (_,_) => agriesma@328: if l=[] then NotLocatable agriesma@328: else (*scan from begin of script for rew_only*) agriesma@328: (case assy ((ts,d),Aundef) ((E,[R],a,v,Unsafe,b), agriesma@328: [(m,EmptyMout,pt,p,[])]) body of agriesma@328: Assoc (iss as (is as (_,_,_,_,_,bb), agriesma@328: ss as ((m',f',pt',p',c')::_))) => agriesma@328: ((*writeln"4### locate_gen Assoc after Fini";*) agriesma@328: if rew_only ss agriesma@328: then let val(p'',c'',f'',pt'') = generate1 thy m (ScrState is) p' pt; agriesma@328: (*drop the intermediate steps !*) agriesma@328: in Steps (ScrState is, [(m, f'',pt'',p'',c'')]) end agriesma@328: else NotLocatable) agriesma@328: | _ => ((*writeln ("#### locate_gen: after Fini");*) agriesma@328: NotLocatable)) agriesma@328: end agriesma@328: | locate_gen _ m _ (sc,_) is = wneuper@807: raise error ("locate_gen: wrong arguments,\n tac= "^(tac_2str m)^ agriesma@328: ",\n scr= "^(scr2str sc)^",\n istate= "^(istate2str is)); agriesma@328: agriesma@328: agriesma@328: wneuper@807: (** find the next stactic in a script **) agriesma@328: agriesma@328: datatype appy = (*ExprVal in the sense of denotational semantics*) wneuper@807: Appy of (*applicable stac found, search stalled*) wneuper@825: tac_ * (*tac_ associated (fun assod) with stac*) wneuper@825: scrstate (*after determination of stac WN.18.8.03*) wneuper@807: | Napp of (*stac found was not applicable; agriesma@328: this mode may become Skip in Repeat, Try and Or*) agriesma@328: env (*stack*) (*popped while nxt_up*) agriesma@328: | Skip of (*for restart after Appy, for leaving iterations, agriesma@328: for passing the value of scriptexpressions, agriesma@328: and for finishing the script successfully*) agriesma@328: term * env (*stack*); agriesma@328: agriesma@328: (*appy, nxt_up, nstep_up scanning for next_tac. agriesma@328: search is clearly separated into (1)-(2): agriesma@328: (1) appy is recursive descent; agriesma@328: (2) nxt_up resumes interpretation at a location somewhere in the script; agriesma@328: nstep_up does only get to the parentnode of the scriptexpr. agriesma@328: consequence: agriesma@328: * call of (2) means _always_ that in this branch below wneuper@807: there was an appl.stac (Repeat, Or e1, ...) agriesma@328: *) agriesma@328: agriesma@328: datatype appy_ = (*as argument in nxt_up, nstep_up, from appy*) agriesma@328: (* Appy is only (final) returnvalue, not argument during search agriesma@328: |*) Napp_ (*ev. detects 'script is not appropriate for this example'*) agriesma@328: | Skip_; (*detects 'script successfully finished' agriesma@328: also used as init-value for resuming; this works, agriesma@328: because 'nxt_up Or e1' treats as Appy*) agriesma@328: agriesma@328: fun appy thy ptp E l agriesma@328: (t as Const ("Let",_) $ e $ (Abs (i,T,b))) a v = wneuper@1250: ((*writeln("### appy Let$e$Abs: is="); wneuper@1250: writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*) wneuper@1250: case appy thy ptp E (l@[L,R]) e a v of agriesma@328: Skip (res, E) => agriesma@328: let (*val _= writeln("### appy Let "^(term2str t)); agriesma@328: val _= writeln("### appy Let: Skip res ="^(term2str res));*) neuper@711: (*val (i',b') = variant_abs (i,T,b); WN.15.5.03 neuper@711: val i = mk_Free(i',T); WN.15.5.03 *) neuper@711: val E' = upd_env E (Free (i,T), res); neuper@711: in appy thy ptp E' (l@[R,D]) b a v end agriesma@328: | ay => ay) agriesma@328: agriesma@328: | appy (thy as (th,sr)) ptp E l agriesma@328: (t as Const ("Script.While"(*1*),_) $ c $ e $ a) _ v = (*ohne n. 28.9.00*) agriesma@328: ((*writeln("### appy While $ c $ e $ a, upd_env= "^ agriesma@328: (subst2str (upd_env E (a,v))));*) agriesma@328: if eval_true_ th sr (subst_atomic (upd_env E (a,v)) c) agriesma@328: then appy thy ptp E (l@[L,R]) e (Some a) v agriesma@328: else Skip (v, E)) agriesma@328: agriesma@328: | appy (thy as (th,sr)) ptp E l agriesma@328: (t as Const ("Script.While"(*2*),_) $ c $ e) a v =(*ohne nachdenken 28.9.00*) agriesma@328: ((*writeln("### appy While $ c $ e, upd_env= "^ agriesma@328: (subst2str (upd_env_opt E (a,v))));*) agriesma@328: if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c) agriesma@328: then appy thy ptp E (l@[R]) e a v agriesma@328: else Skip (v, E)) agriesma@328: agriesma@328: | appy (thy as (th,sr)) ptp E l (t as Const ("If",_) $ c $ e1 $ e2) a v = neuper@724: ((*writeln("### appy If: t= "^(term2str t)); neuper@711: writeln("### appy If: c= "^(term2str(subst_atomic(upd_env_opt E(a,v))c))); neuper@724: writeln("### appy If: thy= "^(fst thy));*) agriesma@328: if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c) neuper@724: then ((*writeln("### appy If: true");*)appy thy ptp E (l@[L,R]) e1 a v) neuper@724: else ((*writeln("### appy If: false");*)appy thy ptp E (l@[ R]) e2 a v)) agriesma@328: agriesma@328: | appy thy ptp E (*env*) l agriesma@328: (Const ("Script.Repeat"(*1*),_) $ e $ a) _ v = agriesma@328: ((*writeln("### appy Repeat a: ");*) agriesma@328: appy thy ptp E (*env*) (l@[L,R]) e (Some a) v) agriesma@328: agriesma@328: | appy thy ptp E (*env*) l agriesma@328: (Const ("Script.Repeat"(*2*),_) $ e) a v = agriesma@328: ((*writeln("3### appy Repeat: a= "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) a));*) agriesma@328: appy thy ptp E (*env*) (l@[R]) e a v) agriesma@328: agriesma@328: | appy thy ptp E l agriesma@328: (t as Const ("Script.Try",_) $ e $ a) _ v = agriesma@328: (case appy thy ptp E (l@[L,R]) e (Some a) v of agriesma@328: Napp E => ((*writeln("### appy Try "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t));*) agriesma@328: Skip (v, E)) agriesma@328: | ay => ay) agriesma@328: (* val (l,t as Const ("Script.Try",_) $ e) = (l@[L,R],e1); agriesma@328: appy thy ptp E l t a v; agriesma@328: *) agriesma@328: | appy thy ptp E l agriesma@328: (t as Const ("Script.Try",_) $ e) a v = agriesma@328: (case appy thy ptp E (l@[R]) e a v of agriesma@328: Napp E => ((*writeln("### appy Try "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t));*) agriesma@328: Skip (v, E)) agriesma@328: | ay => ay) agriesma@328: agriesma@328: agriesma@328: | appy thy ptp E l agriesma@328: (Const ("Script.Or"(*1*),_) $e1 $ e2 $ a) _ v = agriesma@328: (case appy thy ptp E (l@[L,L,R]) e1 (Some a) v of wneuper@825: Appy lme => Appy lme agriesma@328: | _ => appy thy ptp E (*env*) (l@[L,R]) e2 (Some a) v) agriesma@328: agriesma@328: | appy thy ptp E l agriesma@328: (Const ("Script.Or"(*2*),_) $e1 $ e2) a v = agriesma@328: (case appy thy ptp E (l@[L,R]) e1 a v of wneuper@825: Appy lme => Appy lme agriesma@328: | _ => appy thy ptp E (l@[R]) e2 a v) agriesma@328: agriesma@328: agriesma@328: | appy thy ptp E l agriesma@328: (Const ("Script.Seq"(*1*),_) $e1 $ e2 $ a) _ v = agriesma@328: ((*writeln("### appy Seq $ e1 $ e2 $ a, upd_env= "^ agriesma@328: (subst2str (upd_env E (a,v))));*) agriesma@328: case appy thy ptp E (l@[L,L,R]) e1 (Some a) v of agriesma@328: Skip (v,E) => appy thy ptp E (l@[L,R]) e2 (Some a) v agriesma@328: | ay => ay) agriesma@328: (* val (l,t as Const ("Script.Seq",_) $e1 $ e2) = (up@[R],e2); agriesma@328: appy thy ptp E l t a v; agriesma@328: *) agriesma@328: | appy thy ptp E l agriesma@328: (Const ("Script.Seq",_) $e1 $ e2) a v = agriesma@328: (case appy thy ptp E (l@[L,R]) e1 a v of agriesma@328: Skip (v,E) => appy thy ptp E (l@[R]) e2 a v agriesma@328: | ay => ay) agriesma@328: wneuper@807: (*here at the end, this must be a stactic wneuper@807: wrt. diss. missing checks: stac in ets, stac ready*) agriesma@328: (* val (pt, p) = ptp; agriesma@328: val t = (term_of o the o (parse SqRoot.thy)) agriesma@328: "Rewrite square_equation_left True"; agriesma@328: agriesma@328: val (pt, p) = ptp; agriesma@328: val t = (term_of o the o (parseold SqRoot.thy)) agriesma@328: "Check_elementwise L_ {v_. Assumptions} "; agriesma@328: agriesma@328: val ((pt,p),l,t,a,v) = (ptp,[R],body,None,e_term); agriesma@328: val t = body; agriesma@328: val t = (term_of o the o (parseold SqRoot.thy)) agriesma@328: "Rewrite square_equation_left True"; agriesma@328: val a = Some ((term_of o the o (parseold SqRoot.thy)) "e_::bool"); agriesma@328: agriesma@328: val ((pt,p),l,t,a,v) = (ptp,[R],body,None,e_term); agriesma@328: agriesma@328: val (thy as (th,sr),(pt,p),l,t) = (thy,ptp,l@[R],e); neuper@742: neuper@742: val (thy as (th,sr),(pt,p),l,t) = (thy,ptp,l@[R],v); neuper@742: neuper@750: val ((th,sr), t, p) = (thy, neuper@750: str2term "Rewrite real_plus_binom_pow2 False", (p,p_)); neuper@750: neuper@742: val (thy as (th,sr),(pt,p),l,t) = (thy,ptp,up@[R,D],body); agriesma@328: appy (th,sr) (pt, p) E l t a v; agriesma@328: *) agriesma@328: | appy (thy as (th,sr)) (pt, p) E l t a v = wneuper@1250: (case subst_stacexpr E a v t of wneuper@825: Expr s => ((*writeln("### appy, listexpr= "^(term2str t)); neuper@711: writeln("### appy, E= "^(env2str E)); agriesma@328: writeln("### appy, eval(..)= "^(term2str neuper@711: (eval_listexpr_ (assoc_thy th) sr wneuper@825: (subst_atomic (upd_env_opt E (a,v)) t))));*) agriesma@328: Skip (eval_listexpr_ (assoc_thy th) sr agriesma@328: (subst_atomic (upd_env_opt E (a,v)) t), E)) wneuper@807: (* val STac stac = subst_stacexpr E a v t; neuper@742: *) wneuper@807: | STac stac => neuper@711: let wneuper@1250: (*val _= writeln("### appy t, stac= "^(term2str stac));*) wneuper@1250: (*val _= writeln("### appy t, vor stac2tac_ is="); wneuper@1250: val _= writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*) wneuper@1250: val (m,m') = stac2tac_ (assoc_thy th) stac; wneuper@807: (*val _= writeln("### appy t, nach stac2tac, m= "^(tac2str m));*) wneuper@1250: in case m of wneuper@1250: Subproblem _ => Appy (m', (E,l,a,tac_2res m',Sundef,false)) wneuper@1250: | _ => (case applicable_in p pt m of wneuper@1250: Appl m' => wneuper@1250: ((*writeln("### appy: Appy");*) wneuper@1250: Appy (m', (E,l,a,tac_2res m',Sundef,false))) wneuper@1250: | _ => ((*writeln("### appy: Napp");*)Napp E)) wneuper@1250: end); agriesma@328: agriesma@328: neuper@742: (* val (scr as Script sc, l, t as Const ("Let",_) $ _) = neuper@742: (Script sc, up, go up sc); neuper@742: nxt_up thy ptp (Script sc) E l ay t a v; neuper@742: *) agriesma@328: fun nxt_up thy ptp (scr as (Script sc)) E l ay agriesma@328: (t as Const ("Let",_) $ _) a v = (*comes from let=...*) wneuper@1250: ((*writeln("### nxt_up1 Let$e: is="); wneuper@1250: writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*) wneuper@1250: if ay = Napp_ agriesma@328: then nstep_up thy ptp scr E (drop_last l) Napp_ a v agriesma@328: else (*Skip_*) agriesma@328: let val up = drop_last l; neuper@742: val (Const ("Let",_) $ e $ (Abs (i,T,body))) = go up sc; wneuper@1250: val i = mk_Free (i, T); wneuper@1250: val E = upd_env E (i, v); wneuper@1250: (*val _= writeln("### nxt_up2 Let$e: is="); wneuper@1250: val _= writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*) wneuper@1250: in case appy thy ptp (E) (up@[R,D]) body a v of wneuper@825: Appy lre => Appy lre agriesma@328: | Napp E => nstep_up thy ptp scr E up Napp_ a v wneuper@1250: | Skip (v,E) => nstep_up thy ptp scr E up Skip_ a v end) agriesma@328: agriesma@328: | nxt_up thy ptp scr E l ay agriesma@328: (t as Abs (_,_,_)) a v = agriesma@328: ((*writeln("### nxt_up Abs: "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t));*) agriesma@328: nstep_up thy ptp scr E (*enr*) l ay a v) agriesma@328: agriesma@328: | nxt_up thy ptp scr E l ay agriesma@328: (t as Const ("Let",_) $ e $ (Abs (i,T,b))) a v = wneuper@1250: ((*writeln("### nxt_up Let$e$Abs: is="); wneuper@1250: writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*) wneuper@1250: (*writeln("### nxt_up Let e Abs: "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t));*) agriesma@328: nstep_up thy ptp scr (*upd_env*) E (*a,v)*) agriesma@328: (*eno,upd_env env (iar,res),iar,res,saf*) l ay a v) agriesma@328: agriesma@328: (*no appy_: never causes Napp -> Helpless*) agriesma@328: | nxt_up (thy as (th,sr)) ptp scr E l _ agriesma@328: (Const ("Script.While"(*1*),_) $ c $ e $ _) a v = agriesma@328: if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c) agriesma@328: then case appy thy ptp E (l@[L,R]) e a v of agriesma@328: Appy lr => Appy lr agriesma@328: | Napp E => nstep_up thy ptp scr E l Skip_ a v agriesma@328: | Skip (v,E) => nstep_up thy ptp scr E l Skip_ a v agriesma@328: else nstep_up thy ptp scr E l Skip_ a v agriesma@328: agriesma@328: (*no appy_: never causes Napp - Helpless*) agriesma@328: | nxt_up (thy as (th,sr)) ptp scr E l _ agriesma@328: (Const ("Script.While"(*2*),_) $ c $ e) a v = agriesma@328: if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c) agriesma@328: then case appy thy ptp E (l@[R]) e a v of agriesma@328: Appy lr => Appy lr agriesma@328: | Napp E => nstep_up thy ptp scr E l Skip_ a v agriesma@328: | Skip (v,E) => nstep_up thy ptp scr E l Skip_ a v agriesma@328: else nstep_up thy ptp scr E l Skip_ a v agriesma@328: neuper@750: (* val (scr, l) = (Script sc, up); neuper@750: *) agriesma@328: | nxt_up thy ptp scr E l ay (Const ("If",_) $ _ $ _ $ _) a v = agriesma@328: nstep_up thy ptp scr E l ay a v agriesma@328: wneuper@807: | nxt_up thy ptp scr E l _ (*no appy_: there was already a stac below*) agriesma@328: (Const ("Script.Repeat"(*1*),T) $ e $ _) a v = agriesma@328: (case appy thy ptp (*upd_env*) E (*a,v)*) ((l@[L,R]):loc_) e a v of agriesma@328: Appy lr => Appy lr agriesma@328: | Napp E => ((*writeln("### nxt_up Repeat a: ");*) agriesma@328: nstep_up thy ptp scr E l Skip_ a v) agriesma@328: | Skip (v,E) => ((*writeln("### nxt_up Repeat: Skip res ="^ agriesma@328: (Sign.string_of_term(sign_of (assoc_thy thy)) res'));*) agriesma@328: nstep_up thy ptp scr E l Skip_ a v)) agriesma@328: wneuper@807: | nxt_up thy ptp scr E l _ (*no appy_: there was already a stac below*) agriesma@328: (Const ("Script.Repeat"(*2*),T) $ e) a v = agriesma@328: (case appy thy ptp (*upd_env*) E (*a,v)*) ((l@[R]):loc_) e a v of agriesma@328: Appy lr => Appy lr agriesma@328: | Napp E => ((*writeln("### nxt_up Repeat a: ");*) agriesma@328: nstep_up thy ptp scr E l Skip_ a v) agriesma@328: | Skip (v,E) => ((*writeln("### nxt_up Repeat: Skip res ="^ agriesma@328: (Sign.string_of_term(sign_of (assoc_thy thy)) res'));*) agriesma@328: nstep_up thy ptp scr E l Skip_ a v)) agriesma@328: agriesma@328: (* val (scr,l,t) = (Script sc,up,go up sc); agriesma@328: nxt_up thy ptp scr E l ay t a v; agriesma@328: *) agriesma@328: | nxt_up thy ptp scr E l _ (*makes Napp to Skip*) agriesma@328: (t as Const ("Script.Try",_) $ e $ _) a v = agriesma@328: ((*writeln("### nxt_up Try "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t));*) agriesma@328: nstep_up thy ptp scr E l Skip_ a v ) agriesma@328: agriesma@328: | nxt_up thy ptp scr E l _ (*makes Napp to Skip*) agriesma@328: (t as Const ("Script.Try"(*2*),_) $ e) a v = agriesma@328: ((*writeln("### nxt_up Try "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t));*) agriesma@328: nstep_up thy ptp scr (*upd_env*) E (*a,v)*) l Skip_ a v) agriesma@328: agriesma@328: agriesma@328: | nxt_up thy ptp scr E l ay agriesma@328: (Const ("Script.Or",_) $ _ $ _ $ _) a v = nstep_up thy ptp scr E l ay a v agriesma@328: agriesma@328: | nxt_up thy ptp scr E l ay agriesma@328: (Const ("Script.Or",_) $ _ $ _) a v = nstep_up thy ptp scr E l ay a v agriesma@328: agriesma@328: | nxt_up thy ptp scr E l ay agriesma@328: (Const ("Script.Or",_) $ _ ) a v = agriesma@328: nstep_up thy ptp scr E (drop_last l) ay a v agriesma@328: agriesma@328: agriesma@328: | nxt_up thy ptp scr E l ay (*all has been done in (*2*) below*) agriesma@328: (Const ("Script.Seq"(*1*),_) $ _ $ _ $ _) a v = agriesma@328: nstep_up thy ptp scr E l ay a v agriesma@328: agriesma@328: | nxt_up thy ptp scr E l ay (*comes from e2*) agriesma@328: (Const ("Script.Seq"(*2*),_) $ _ $ e2) a v = agriesma@328: nstep_up thy ptp scr E l ay a v agriesma@328: (* val (scr as Script sc,l,t) = (Script sc,up,go up sc); agriesma@328: !! Const ("Script.Seq",_ $ _ agriesma@328: nxt_up thy ptp scr E l ay t a v; agriesma@328: *) agriesma@328: | nxt_up thy ptp (scr as Script sc) E l ay (*comes from e1*) agriesma@328: (Const ("Script.Seq",_) $ _ ) a v = agriesma@328: if ay = Napp_ agriesma@328: then nstep_up thy ptp scr E (drop_last l) Napp_ a v agriesma@328: else (*Skip_*) agriesma@328: let val up = drop_last l; agriesma@328: val Const ("Script.Seq"(*2*),_) $ _ $ e2 = go up sc; agriesma@328: in case appy thy ptp E (up@[R]) e2 a v of agriesma@328: Appy lr => Appy lr agriesma@328: | Napp E => nstep_up thy ptp scr E up Napp_ a v agriesma@328: | Skip (v,E) => nstep_up thy ptp scr E up Skip_ a v end agriesma@328: agriesma@328: | nxt_up (thy,_) ptp scr E l ay t a v = agriesma@328: raise error ("nxt_up not impl for "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) t)) agriesma@328: neuper@742: (* val (Script sc, ay) = (scr,Skip_); neuper@750: neuper@742: val (Script sc, ay) = (sc,Skip_); agriesma@328: *) agriesma@328: and nstep_up thy ptp (Script sc) E l ay a v = agriesma@328: ((*writeln("### nstep_up from: "^(loc_2str l)); agriesma@328: writeln("### nstep_up from: "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) (go l sc)));*) agriesma@328: if 1 < length l agriesma@328: then neuper@742: let neuper@742: val up = drop_last l; agriesma@328: in ((*writeln("### nstep_up to: "^ agriesma@328: (Sign.string_of_term (sign_of (assoc_thy thy)) (go up sc)));*) agriesma@328: nxt_up thy ptp (Script sc) E up ay (go up sc) a v ) end agriesma@328: else (*interpreted to end*) agriesma@328: if ay = Skip_ then Skip (v, E) else Napp E agriesma@328: ); agriesma@328: wneuper@807: (* decide for the next applicable stac in the script; wneuper@807: returns (stactic, value) - the value in case the script is finished agriesma@328: 12.8.02: ~~~~~ and no assumptions ??? FIXME ??? agriesma@328: 20.8.02: must return p in case of finished, because the next script agriesma@328: consulted need not be the calling script: wneuper@807: in case of detail ie. _inserted_ PrfObjs, the next stac agriesma@328: has to searched in a script with PblObj.status<>Complete ! agriesma@328: (.. not true for other details ..PrfObj ?????????????????? agriesma@328: 20.8.02: do NOT return safe (is only changed in locate !!!) agriesma@328: *) agriesma@328: (* val (thy, (pt,p), Rfuns {next_rule=ne,...}, RrlsState (f,f',rss,_)) = agriesma@328: (thy', (pt,p), sc, RrlsState (ii t)); agriesma@328: val (thy, (pt,p), Rfuns {next_rule=ne,...}, RrlsState (f,f',rss,_)) = agriesma@328: (thy', (pt',p'), sc, is'); agriesma@328: *) wneuper@825: fun next_tac (thy,_) (pt,p) (Rfuns {next_rule,...}) (RrlsState(f,f',rss,_))= wneuper@1360: if f = f' then (End_Detail' (f',[])(*8.6.03*), Uistate, wneuper@825: (f', Sundef(*FIXME is no value of next_tac! vor 8.6.03*))) agriesma@328: (*finished*) wneuper@825: else (case next_rule rss f of wneuper@825: None => (Empty_Tac_, Uistate, (e_term, Sundef)) (*helpless*) wneuper@825: (* val Some (Thm (id,thm)) = next_rule rss f; agriesma@328: *) wneuper@825: | Some (Thm (id,thm))(*8.6.03: muss auch f' liefern ?!!*) => wneuper@825: (Rewrite' (thy, "e_rew_ord", e_rls,(*!?!8.6.03*) false, wneuper@825: (id, string_of_thm' thm), f,(e_term,[(*!?!8.6.03*)])), wneuper@825: Uistate, (e_term, Sundef))) (*next stac*) wneuper@825: wneuper@1408: (* val(thy, ptp as (pt,(p,_)), sc as Script (h $ body),ScrState (E,l,a,v,s,b))= wneuper@1250: ((thy',srls), (pt,pos), sc, is); agriesma@328: next_tac thy ptp (Script (h $ body)) (ScrState (E,l,a,v,s,b)); neuper@750: *) agriesma@328: | next_tac thy (ptp as (pt,(p,_)):ptree * pos') (sc as Script (h $ body)) agriesma@328: (ScrState (E,l,a,v,s,b)) = wneuper@1250: ((*writeln("### next_tac-----------------: E= "); wneuper@1250: writeln( istate2str (ScrState (E,l,a,v,s,b)));*) agriesma@328: case if l=[] then appy thy ptp E [R] body None e_term agriesma@328: else nstep_up thy ptp sc E l Skip_ a v of wneuper@825: Skip (v,_) => (*finished*) agriesma@328: (case par_pbl_det pt p of agriesma@328: (true, p', _) => agriesma@328: let val (_,pblID,_) = get_obj g_spec pt p'; wneuper@1250: in (Check_Postcond' (pblID, (v, [(*8.6.03 NO asms???*)])), wneuper@825: e_istate, (v,s)) end wneuper@1360: | (_,p',rls') => (End_Detail' (e_term,[])(*8.6.03*), e_istate, (v,s))) wneuper@825: | Napp _ => (Empty_Tac_, e_istate, (e_term, Sundef)) (*helpless*) wneuper@1250: | Appy (m', scrst as (_,_,_,v,_,_)) => (m', ScrState scrst, wneuper@1250: (v, Sundef))) (*next stac*) wneuper@825: agriesma@328: | next_tac _ _ _ is = raise error ("next_tac: not impl for "^ agriesma@328: (istate2str is)); agriesma@328: agriesma@328: (* val metID = mI; agriesma@328: *) agriesma@328: fun init_scrstate thy itms metID = agriesma@328: let val ags = itms2args thy metID itms; agriesma@328: val scr as Script sc = (#scr o get_met) metID; neuper@703: val env = ((formal_args sc) ~~ ags) agriesma@328: handle _ => raise error ("init_scrstate: formal_args = "^ neuper@703: (terms2str (formal_args sc))^ agriesma@328: "\ndon't match actual_args ="^ agriesma@328: (terms2str ags)); agriesma@328: in (ScrState (env,[],None,e_term,Safe,true), scr):istate * scr end; agriesma@328: wneuper@1592: (*.decide, where to get script/istate from: wneuper@1592: (*1*) from PblObj.env: at begin of script if no init_form wneuper@1592: (*2*) from PblObj/PrfObj: if stac is in the middle of the script wneuper@1592: (*3*) from rls/PrfObj: in case of detail a ruleset.*) wneuper@1592: fun from_pblobj_or_detail' thy' (p,p_) pt = wneuper@1592: if p_ mem [Pbl,Met] wneuper@1592: then case get_obj g_env pt p of wneuper@1592: None => raise error "from_pblobj_or_detail': no istate" wneuper@1592: | Some is => wneuper@1592: let val metID = get_obj g_metID pt p wneuper@1592: val {srls,...} = get_met metID wneuper@1592: in (srls, is, (#scr o get_met) metID) end wneuper@1592: else agriesma@328: let val (pbl,p',rls') = par_pbl_det pt p agriesma@328: in if pbl wneuper@1592: then (*2*) agriesma@328: let val thy = assoc_thy thy' agriesma@328: val PblObj{meth=itms,...} = get_obj I pt p' agriesma@328: val metID = get_obj g_metID pt p' agriesma@328: val {srls,...} = get_met metID wneuper@1592: in (*if last_elem p = 0 (*nothing written to pt yet*) agriesma@328: then let val (is, sc) = init_scrstate thy itms metID agriesma@328: in (srls, is, sc) end wneuper@1592: else*) (srls, get_istate pt (p,p_), (#scr o get_met) metID) agriesma@328: end wneuper@1592: else (*3*) wneuper@1592: (e_rls, (*FIXME: get from pbl or met !!! wneuper@1592: unused for Rrls in locate_gen, next_tac*) wneuper@1592: get_istate pt (p,p_), wneuper@1592: case rls' of wneuper@1592: Rls {scr=scr,...} => scr wneuper@1592: | Rrls {scr=rfuns,...} => rfuns) agriesma@328: end; wneuper@1329: agriesma@328: (*.get script and istate from PblObj, see (*1*) above.*) agriesma@328: fun from_pblobj' thy' (p,p_) pt = agriesma@328: let val p' = par_pblobj pt p agriesma@328: val thy = assoc_thy thy' agriesma@328: val PblObj{meth=itms,...} = get_obj I pt p' agriesma@328: val metID = get_obj g_metID pt p' agriesma@328: val {srls,scr,...} = get_met metID agriesma@328: in if last_elem p = 0 (*nothing written to pt yet*) agriesma@328: then let val (is, scr) = init_scrstate thy itms metID agriesma@328: in (srls, is, scr) end agriesma@328: else (srls, get_istate pt (p,p_), scr) agriesma@328: end; agriesma@328: agriesma@328: (* agriesma@328: end agriesma@328: open Interpreter; agriesma@328: *) agriesma@328: agriesma@328: (* use"ME/script.sml"; agriesma@328: use"script.sml"; agriesma@328: *)