wneuper@59546
|
1 |
(* Title: "Minisubpbl/200-start-method.sml"
|
neuper@41985
|
2 |
Author: Walther Neuper 1105
|
neuper@41985
|
3 |
(c) copyright due to lincense terms.
|
neuper@41985
|
4 |
*)
|
neuper@41985
|
5 |
|
neuper@42011
|
6 |
"----------- Minisubplb/200-start-method.sml ---------------------";
|
neuper@42011
|
7 |
"----------- Minisubplb/200-start-method.sml ---------------------";
|
neuper@42011
|
8 |
"----------- Minisubplb/200-start-method.sml ---------------------";
|
neuper@41985
|
9 |
val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
|
neuper@41985
|
10 |
val (dI',pI',mI') =
|
neuper@41985
|
11 |
("Test", ["sqroot-test","univariate","equation","test"],
|
neuper@41985
|
12 |
["Test","squ-equ-test-subpbl1"]);
|
neuper@41985
|
13 |
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
|
neuper@41985
|
14 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@41985
|
15 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@41985
|
16 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@41985
|
17 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
wneuper@59236
|
18 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = ("Specify_Problem",..*)
|
wneuper@59236
|
19 |
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
wneuper@59236
|
20 |
val (p'''',_,f'''',nxt'''',_,pt'''') = me nxt p [] pt; (* (@1) nxt'''' = ("Specify_Method",..*)
|
wneuper@59240
|
21 |
(*me nxt'''' p'''' [] pt''''; "ERROR in creating the environment..", SHOULD BE("Apply_Method",.*)
|
wneuper@59236
|
22 |
"~~~~~ we continue with (@1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
wneuper@59236
|
23 |
val (p, f, nxt, pt) = (p'''',f'''',nxt'''',pt'''');
|
walther@59749
|
24 |
"~~~~~ fun me, args:"; val tac = nxt;
|
wneuper@59236
|
25 |
val (pt, p) =
|
walther@59765
|
26 |
(*locatetac is here for testing by me; Step.do_next would suffice in me*)
|
wneuper@59236
|
27 |
case locatetac tac (pt,p) of
|
wneuper@59236
|
28 |
("ok", (_, _, ptp)) => ptp | _ => error "CHANGED --- Minisubplb/200-start-method 1"
|
walther@59765
|
29 |
(* Step.do_next p ((pt, e_pos'),[]) ..ERROR = ("helpless",*)
|
walther@59765
|
30 |
"~~~~~ fun Step.do_next, args:"; val (((ip as (_,p_)):pos'), ((ptp as (pt,p), tacis):calcstate)) =
|
wneuper@59236
|
31 |
(p, ((pt, e_pos'),[]));
|
wneuper@59236
|
32 |
val pIopt = get_pblID (pt,ip);
|
wneuper@59236
|
33 |
ip = ([],Res) (*= false*);
|
wneuper@59236
|
34 |
tacis (* = []*);
|
wneuper@59236
|
35 |
val SOME pI = pIopt;
|
wneuper@59236
|
36 |
member op = [Pbl,Met] p_ andalso is_none (get_obj g_env pt (fst p)) (*= true*);
|
wneuper@59236
|
37 |
(*nxt_specify_ (pt, ip) ..ERROR in creating the environment..*);
|
wneuper@59236
|
38 |
|
wneuper@59236
|
39 |
val (p, f, nxt, pt) = (p'''',f'''',nxt'''',pt'''');
|
wneuper@59236
|
40 |
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
wneuper@59236
|
41 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; (* (@2) nxt = ("Apply_Method",..*)
|
wneuper@59480
|
42 |
|
wneuper@59480
|
43 |
val (p'''',_,f'''',nxt'''',_,pt'''') = me nxt p [] pt; (* (@3)
|
wneuper@59480
|
44 |
1.ERROR WAS: nxt = ("Empty_Tac",..
|
walther@59635
|
45 |
2.ERROR WAS: *** stac2tac_ TODO: no match for (Rewrite_Set ''norm_equation'') (x + 1 = 2)*)
|
wneuper@59236
|
46 |
"~~~~~ we continue with (@2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
walther@59749
|
47 |
"~~~~~ fun me, args:"; val tac = nxt;
|
wneuper@59480
|
48 |
val ("ok", (_, _, (pt''''',p'''''))) = locatetac tac (pt,p);
|
neuper@42009
|
49 |
"~~~~~ fun locatetac, args:"; val ptp as (pt, p) = (pt, p);
|
walther@59755
|
50 |
val Appl m = applicable_in p pt tac; (*m = Apply_Method'..*)
|
walther@59755
|
51 |
(*if*) Tactic.for_specify' m; (*false*)
|
walther@59749
|
52 |
"~~~~~ fun loc_solve_ , args:"; val (m, (pt, pos) ) = (m, ptp);
|
walther@59751
|
53 |
"~~~~~ fun Step_Solve.by_tactic , args:"; val (Apply_Method' (mI,_,_,_), pos as (p,_)) = (m, pos);
|
neuper@42009
|
54 |
val PblObj {meth, ctxt, ...} = get_obj I pt p;
|
neuper@42009
|
55 |
val thy' = get_obj g_domID pt p;
|
neuper@42009
|
56 |
val thy = assoc_thy thy';
|
neuper@42009
|
57 |
val {srls, pre, prls, ...} = get_met mI;
|
neuper@42009
|
58 |
val pres = check_preconds thy prls pre meth |> map snd;
|
walther@59728
|
59 |
val ctxt = ctxt |> ContextC.insert_assumptions pres;
|
walther@59682
|
60 |
val (is'''' as Pstate {env = env'''',...}, _, sc'''') = init_pstate srls ctxt meth mI;
|
walther@59677
|
61 |
"~~~~~ fun init_pstate , args:"; val (srls, thy, itms, metID) = (srls, thy, meth, mI)
|
neuper@42015
|
62 |
val actuals = itms2args thy metID itms
|
neuper@48790
|
63 |
val scr as Prog sc = (#scr o get_met) metID
|
neuper@42015
|
64 |
val formals = formal_args sc
|
neuper@42015
|
65 |
(*expects same sequence of (actual) args in itms and (formal) args in met*)
|
wneuper@59550
|
66 |
fun msg_miss sc metID caller f formals actuals =
|
walther@59618
|
67 |
"ERROR in creating the environment from formal args. of partial_function \"" ^ fst (Program.get_fun_id sc) ^ "\"\n" ^
|
wneuper@59550
|
68 |
"and the actual args., ie. items of the guard of \"" ^ Celem.metID2str metID ^ "\" by \"" ^ caller ^ "\":\n" ^
|
wneuper@59550
|
69 |
"formal arg \"" ^ Rule.term2str f ^ "\" doesn't mach an actual arg.\n" ^
|
wneuper@59550
|
70 |
"with:\n" ^
|
wneuper@59550
|
71 |
(string_of_int o length) formals ^ " formal args: " ^ Rule.terms2str formals ^ "\n" ^
|
wneuper@59550
|
72 |
(string_of_int o length) actuals ^ " actual args: " ^ Rule.terms2str actuals
|
wneuper@59550
|
73 |
fun msg_ambiguous sc metID f aas formals actuals =
|
walther@59618
|
74 |
"AMBIGUITY in creating the environment from formal args. of partial_function \"" ^ fst (Program.get_fun_id sc) ^ "\"\n" ^
|
wneuper@59550
|
75 |
"and the actual args., ie. items of the guard of \"" ^ Celem.metID2str metID ^ "\" by \"assoc_by_type\":\n" ^
|
wneuper@59550
|
76 |
"formal arg. \"" ^ Rule.term2str f ^ "\" type-matches with several..." ^
|
wneuper@59550
|
77 |
"actual args. \"" ^ Rule.terms2str aas ^ "\"\n" ^
|
wneuper@59550
|
78 |
"selected \"" ^ Rule.term2str (hd aas) ^ "\"\n" ^
|
wneuper@59550
|
79 |
"with\n" ^
|
wneuper@59550
|
80 |
"formals: " ^ Rule.terms2str formals ^ "\n" ^
|
wneuper@59550
|
81 |
"actuals: " ^ Rule.terms2str actuals
|
wneuper@59550
|
82 |
fun assoc_by_type f aa =
|
wneuper@59550
|
83 |
case filter (curry (fn (f, a) => type_of f = type_of a) f) aa of
|
wneuper@59550
|
84 |
[] => error (msg_miss sc metID "assoc_by_type" f formals actuals)
|
wneuper@59550
|
85 |
| [a] => (f, a)
|
wneuper@59550
|
86 |
| aas as (a :: _) => (writeln (msg_ambiguous sc metID f aas formals actuals); (f, a));
|
wneuper@59550
|
87 |
fun relate_args _ (f::_) [] = error (msg_miss sc metID "relate_args" f formals actuals)
|
wneuper@59550
|
88 |
| relate_args env [] _ = env (*may drop Find?*)
|
wneuper@59550
|
89 |
| relate_args env (f::ff) (aas as (a::aa)) =
|
wneuper@59550
|
90 |
if type_of f = type_of a
|
wneuper@59550
|
91 |
then relate_args (env @ [(f, a)]) ff aa
|
wneuper@59550
|
92 |
else
|
wneuper@59550
|
93 |
let val (f, a) = assoc_by_type f aas
|
wneuper@59550
|
94 |
in relate_args (env @ [(f, a)]) ff (remove op = a aas) end
|
wneuper@59582
|
95 |
val env = relate_args [] formals actuals;
|
wneuper@59582
|
96 |
(*val _ = trace_istate env;*)
|
wneuper@59582
|
97 |
val {pre, prls, ...} = Specify.get_met metID;
|
wneuper@59582
|
98 |
val pres = Stool.check_preconds (Proof_Context.theory_of ctxt) prls pre itms |> map snd;
|
wneuper@59582
|
99 |
val ctxt = ctxt |> ContextC.insert_assumptions pres;
|
neuper@42015
|
100 |
|
walther@59751
|
101 |
"~~~~~ continue Step_Solve.by_tactic";
|
neuper@42015
|
102 |
val ini = init_form thy sc'''' env'''';
|
neuper@42009
|
103 |
val p = lev_dn p;
|
neuper@42009
|
104 |
val SOME t = ini;
|
neuper@42009
|
105 |
val (pos,c,_,pt) =
|
neuper@42015
|
106 |
generate1 thy (Apply_Method' (mI, SOME t, is'''', ctxt))
|
neuper@42015
|
107 |
(is'''', ctxt) (lev_on p, Frm)(*implicit Take*) pt;
|
neuper@42015
|
108 |
("ok",([(Apply_Method mI, Apply_Method' (mI, SOME t, is'''', ctxt),
|
neuper@42015
|
109 |
((lev_on p, Frm), (is'''', ctxt)))], c, (pt,pos)):calcstate');
|
neuper@42015
|
110 |
|
neuper@42015
|
111 |
val ctxt = get_ctxt pt pos;
|
neuper@42015
|
112 |
val SOME known_x = parseNEW ctxt "x+z+z"; (*x has declare_constraints to real*)
|
neuper@42015
|
113 |
val SOME unknown = parseNEW ctxt "a+b+c";
|
neuper@55279
|
114 |
if type_of known_x = Type ("Real.real",[]) then ()
|
neuper@42015
|
115 |
else error "x+1=2 after start root-pbl wrong type-inference for known_x";
|
neuper@42015
|
116 |
if type_of unknown = TFree ("'a", ["Groups.plus"]) then ()
|
neuper@42015
|
117 |
else error "x+1=2 after start root-pbl wrong type-inference for unknown";
|
neuper@42009
|
118 |
|
wneuper@59480
|
119 |
"~~~~~ continue me (@3) after locatetac";
|
wneuper@59480
|
120 |
val (pt, p) = (pt''''',p''''');
|
wneuper@59480
|
121 |
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
walther@59765
|
122 |
"~~~~~ fun Step.do_next, args:"; val ((ip as (_, p_)), (ptp as (pt,p), tacis)) = (p, ((pt, Pos.e_pos'),[]));
|
wneuper@59480
|
123 |
val pIopt = get_pblID (pt,ip);
|
walther@59694
|
124 |
ip = ([], Pos.Res) (* = false*);
|
wneuper@59480
|
125 |
case tacis of [] => ();
|
wneuper@59480
|
126 |
case pIopt of SONE => ();
|
walther@59694
|
127 |
member op = [Pos.Pbl, Pos.Met] p_ andalso is_none (Ctree.get_obj Ctree.g_env pt (fst p)) (* = false*);
|
walther@59760
|
128 |
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) = (pt,ip);
|
wneuper@59480
|
129 |
Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (* = false*);
|
wneuper@59480
|
130 |
val thy' = get_obj g_domID pt (par_pblobj pt p);
|
wneuper@59480
|
131 |
val (srls, is, sc) = Lucin.from_pblobj_or_detail' thy' (p,p_) pt;
|
walther@59743
|
132 |
"~~~~~ fun find_next_tactic , args:"; val ((ptp as(pt, (p, _))), (Rule.Prog prog), (Istate.Pstate ist, ctxt))
|
walther@59722
|
133 |
= ((pt, pos), sc, is);
|
walther@59722
|
134 |
(*case*) scan_to_tactic2 (prog, (ptp, ctxt)) (Istate.Pstate ist) (*of*);
|
walther@59722
|
135 |
"~~~~~ fun scan_to_tactic2 , args:"; val ((prog, cc), (Istate.Pstate (ist as {path, ...})))
|
walther@59722
|
136 |
= ((prog, (ptp, ctxt)), (Istate.Pstate ist));
|
walther@59722
|
137 |
(*if*) path = [] (*then*);
|
walther@59722
|
138 |
scan_dn2 cc (trans_scan_down2 ist) (Program.body_of prog);
|
walther@59722
|
139 |
"~~~~~ fun scan_dn2 , args:"; val (cc, ist, (Const ("HOL.Let"(*1*), _) $ e $ (Abs (i, T, b)))) =
|
walther@59722
|
140 |
(cc, (trans_scan_down2 ist), (Program.body_of prog));
|
walther@59722
|
141 |
(*case*) scan_dn2 cc (ist |> path_down [L, R]) e (*of*);
|
walther@59722
|
142 |
"~~~~~ fun scan_dn2 , args:"; val (cc, ist, (Const ("Tactical.Chain"(*1*), _) $ e1 $ e2 $ a))
|
walther@59722
|
143 |
= (cc, (ist |> path_down [L, R]), e);
|
walther@59722
|
144 |
(*case*) scan_dn2 cc (ist |> path_down_form ([L, L, R], a)) e1 (*of*);
|
walther@59722
|
145 |
"~~~~~ fun scan_dn2 , args:"; val (cc, (ist as {act_arg, ...}), (Const ("Tactical.Try"(*2*), _) $ e))
|
walther@59722
|
146 |
= (cc, (ist |> path_down_form ([L, L, R], a)), e1);
|
walther@59722
|
147 |
(*case*) scan_dn2 cc (ist |> path_down [R]) e (*of*);
|
walther@59722
|
148 |
"~~~~~ fun scan_dn2 , args:"; val (((pt, p), ctxt), (ist as {eval, ...}), t) =
|
walther@59722
|
149 |
(cc, (ist |> path_down [R]), e);
|
walther@59722
|
150 |
val (Program.Tac stac, a') =
|
walther@59722
|
151 |
(*case*) Lucin.interpret_leaf "next " ctxt eval (get_subst ist) t (*of*);
|
walther@59722
|
152 |
val (m, m') = Lucin.stac2tac_ pt (Proof_Context.theory_of ctxt) stac;
|
walther@59722
|
153 |
"~~~~~ fun stac2tac_ , args:"; val (_, _, (Const ("Prog_Tac.Rewrite'_Set",_) $ rls $ _)) =
|
walther@59722
|
154 |
(pt, (Proof_Context.theory_of ctxt), stac);
|
walther@59722
|
155 |
(*+*)case stac2tac_ pt (Proof_Context.theory_of ctxt) stac of (Rewrite_Set "norm_equation", _) => ()
|
walther@59722
|
156 |
(*+*)| _ => error "stac2tac_ changed"
|
walther@59691
|
157 |
"~~~~~ continue last scan_dn2";
|
walther@59737
|
158 |
val Applicable.Appl m' = Applicable.applicable_in p pt m;
|
walther@59728
|
159 |
"~~~~~ fun result, args:"; val (m) = (m');
|
wneuper@59571
|
160 |
"~~~~~ fun rep_tac_, args:"; val (Tactic.Rewrite_Set' (thy', put, rls, f, (f', _))) = (m);
|
wneuper@59480
|
161 |
val fT = type_of f;
|
walther@59635
|
162 |
val lhs = Const ("Prog_Tac.Rewrite'_Set", [HOLogic.stringT, fT] ---> fT)
|
walther@59635
|
163 |
$ HOLogic.mk_string (Rule.id_rls rls) $ f;
|
wneuper@59480
|
164 |
(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here was Free (Rule.id_rls rls, idT) *)
|
wneuper@59480
|
165 |
|
neuper@42009
|
166 |
val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*nxt = ("Rewrite_Set"*)
|
walther@59749
|
167 |
case nxt of (Rewrite_Set _) => ()
|
walther@59722
|
168 |
| _ => error "minisubpbl: Method not started in root-problem";
|