walther@59813
|
1 |
(* Title: "Minisubpbl/250-Rewrite_Set-from-method.sml"
|
walther@59813
|
2 |
Author: Walther Neuper 1105
|
walther@59813
|
3 |
(c) copyright due to lincense terms.
|
walther@59813
|
4 |
*)
|
walther@59813
|
5 |
|
walther@59813
|
6 |
"----------- Minisubpbl/800-append-on-Frm.sml ------------------------------------------------";
|
walther@59813
|
7 |
"----------- Minisubpbl/800-append-on-Frm.sml ------------------------------------------------";
|
walther@59813
|
8 |
"----------- Minisubpbl/800-append-on-Frm.sml ------------------------------------------------";
|
walther@59815
|
9 |
(*cp from -- appendFormula: on Frm + equ_nrls --- in Interpret.inform.sml --------------------*)
|
walther@60340
|
10 |
val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
|
walther@59815
|
11 |
val (dI',pI',mI') =
|
walther@59997
|
12 |
("Test", ["sqroot-test", "univariate", "equation", "test"],
|
walther@59997
|
13 |
["Test", "squ-equ-test-subpbl1"]);
|
walther@59813
|
14 |
(*[], Pbl*)val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];(*Model_Problem*)
|
walther@59815
|
15 |
(*autoCalculate 1 CompleteCalcHead;*)
|
walther@59813
|
16 |
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Add_Given "equality (x + 1 = 2)"*)
|
walther@59813
|
17 |
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Add_Given "solveFor x"*)
|
walther@59813
|
18 |
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Add_Find "solutions L"*)
|
walther@59813
|
19 |
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Specify_Theory "Test"*)
|
walther@59813
|
20 |
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Specify_Problem ["sqroot-test", "univariate", "equation", "test"]*)
|
walther@59813
|
21 |
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Specify_Method ["Test", "squ-equ-test-subpbl1"]*)
|
walther@59815
|
22 |
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Apply_Method ["Test", "squ-equ-test-subpbl1"])*);
|
walther@59815
|
23 |
|
walther@59815
|
24 |
(*autoCalculate 1 (Steps 1);*)
|
walther@59813
|
25 |
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = ("Rewrite_Set", Rewrite_Set "norm_equation")*)
|
walther@59815
|
26 |
|
walther@59983
|
27 |
(*+*)Test_Tool.show_pt_tac pt; (*isa==REP [
|
walther@59815
|
28 |
([], Frm), solve (x + 1 = 2, x)
|
walther@59997
|
29 |
. . . . . . . . . . Apply_Method ["Test", "squ-equ-test-subpbl1"],
|
walther@59815
|
30 |
([1], Frm), x + 1 = 2
|
walther@59815
|
31 |
. . . . . . . . . . Empty_Tac] *)
|
walther@59815
|
32 |
|
walther@60324
|
33 |
(*appendFormula 1 "2+ - 1 + x = 2";*)
|
walther@60324
|
34 |
"~~~~~ fun appendFormula , args:"; val (ifo) = ("2+ - 1 + x = 2");
|
walther@59815
|
35 |
val cs = (*get_calc cI*) ((pt, p), []) (*..continue fun me*)
|
walther@59815
|
36 |
val pos = (*get_pos cI 1*) p (*..continue fun me*)
|
walther@59815
|
37 |
|
walther@59815
|
38 |
val ("ok", cs' as (_, _, ptp''''')) = (*case*)
|
walther@59815
|
39 |
Step.do_next pos cs (*of*);
|
walther@59815
|
40 |
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) = (pos, cs);
|
walther@59815
|
41 |
val pIopt = Ctree.get_pblID (pt, ip);
|
walther@59815
|
42 |
(*if*) ip = ([], Pos.Res) (*else*);
|
walther@59815
|
43 |
val _ = (*case*) tacis (*of*);
|
walther@59815
|
44 |
val SOME _ = (*case*) pIopt (*of*);
|
walther@59815
|
45 |
|
walther@59815
|
46 |
Step.switch_specify_solve p_ (pt, ip);
|
walther@59815
|
47 |
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
|
walther@60017
|
48 |
(*if*) member op = [Pos.Pbl, Pos.Met] state_pos (*else*);
|
walther@59815
|
49 |
|
walther@59815
|
50 |
LI.do_next (pt, input_pos);
|
walther@59815
|
51 |
"~~~~~ and do_next , args:"; val ((ptp as (pt, pos as (p, p_)))) = (pt, input_pos);
|
walther@60154
|
52 |
(*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) (*else*);
|
walther@59815
|
53 |
val thy' = get_obj g_domID pt (par_pblobj pt p);
|
walther@59831
|
54 |
val ((ist, ctxt), sc) = LItool.resume_prog thy' (p,p_) pt;
|
walther@59815
|
55 |
|
walther@59815
|
56 |
val Next_Step (ist, ctxt, tac) = (*case*) (**..Ctree NOT updated yet**)
|
walther@59815
|
57 |
LI.find_next_step sc (pt, pos) ist ctxt (*of*);
|
walther@59815
|
58 |
|
walther@59815
|
59 |
(*+*)val ("ok", ([(Rewrite_Set "norm_equation", _, (([1], Frm), _))], _, _)) =
|
walther@59815
|
60 |
LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp;
|
walther@59815
|
61 |
"~~~~~ fun by_tactic , args:"; val (tac_, is, (pt, pos)) = (tac, (ist, Tactic.insert_assumptions tac ctxt), ptp);
|
walther@59815
|
62 |
val pos = next_in_prog' pos;
|
walther@59815
|
63 |
|
walther@59815
|
64 |
(** )val (pos', c, _, pt) =( **)
|
walther@59932
|
65 |
Step.add tac_ is (pt, pos);
|
walther@59932
|
66 |
"~~~~~ fun add , args:"; val ((Tactic.Rewrite_Set' (_, _, rls', f, (f', asm))), (is, ctxt), (pt, (p, _)))
|
walther@59815
|
67 |
= (tac_, is, (pt, pos));
|
walther@59932
|
68 |
(*+*)pos = ([1], Frm);
|
walther@59815
|
69 |
|
walther@59815
|
70 |
(** )val (pt, c) =( **)
|
walther@59815
|
71 |
cappend_atomic pt p (is, ContextC.insert_assumptions asm ctxt) f
|
walther@59867
|
72 |
(Tactic.Rewrite_Set (Rule_Set.id rls')) (f',asm) Complete;
|
walther@59815
|
73 |
"~~~~~ fun cappend_atomic , args:"; val (pt, p: pos, ic_res, f, r, f', s)
|
walther@59815
|
74 |
= (pt, p, (is, ContextC.insert_assumptions asm ctxt), f,
|
walther@59867
|
75 |
(Tactic.Rewrite_Set (Rule_Set.id rls')), (f',asm), Complete);
|
walther@59844
|
76 |
(*if*) existpt p pt andalso Tactic.is_empty (get_obj g_tac pt p) (*then*);
|
walther@59815
|
77 |
val (ic_form, f) = (get_loc pt (p, Frm), get_obj g_form pt p)
|
walther@59815
|
78 |
val (pt, cs) = cut_tree(*!*)pt (p, Frm);
|
walther@59815
|
79 |
(** )val pt = ( **)
|
walther@59815
|
80 |
append_atomic p (SOME ic_form, ic_res) f r f' s pt;
|
walther@59815
|
81 |
"~~~~~ fun append_atomic , args:"; val (p, (ic_form, ic_res), f, r, f', s, pt)
|
walther@59815
|
82 |
= (p, (SOME ic_form, ic_res), f, r, f', s, pt);
|
walther@59844
|
83 |
(*if*) existpt p pt andalso Tactic.is_empty (get_obj g_tac pt p) (*else*);
|
walther@59815
|
84 |
val (iss, f) =
|
walther@59815
|
85 |
((ic_form, SOME ic_res), f); (*return from if*)
|
walther@59815
|
86 |
|
walther@59840
|
87 |
insert_pt (PrfObj {form = f, tac = r, loc = iss, branch = NoBranch,
|
walther@59932
|
88 |
result = f', ostate = s}) pt p (*return from append_atomic*);
|
walther@59932
|
89 |
"~~~~~ from fun append_atomic \<longrightarrow>fun cappend_atomic , return:"; val (pt)
|
walther@59840
|
90 |
= (insert_pt (PrfObj {form = f, tac = r, loc = iss, branch = NoBranch,
|
walther@59815
|
91 |
result = f', ostate = s}) pt p);
|
walther@59815
|
92 |
|
walther@60340
|
93 |
(*/--------------------- step into Deriv.embed -----------------------------------------------\*)
|
walther@59815
|
94 |
val ("ok", ([], _, ptp''''' as (_, ([1], Res)))) =
|
walther@59932
|
95 |
(*case*)
|
walther@59932
|
96 |
Step_Solve.by_term ptp (encode ifo) (*of*);
|
walther@59932
|
97 |
"~~~~~ fun by_term , args:"; val ((pt, pos as (p, _)), istr) = (ptp, (encode ifo));
|
Walther@60424
|
98 |
val SOME f_in =(*case*) TermC.parseNEW (get_ctxt pt pos) istr (*of*);
|
walther@59932
|
99 |
val pos_pred = lev_back(*'*) pos
|
walther@59932
|
100 |
val f_pred = Ctree.get_curr_formula (pt, pos_pred);
|
walther@59932
|
101 |
val f_succ = Ctree.get_curr_formula (pt, pos);
|
walther@59932
|
102 |
(*if*) f_succ = f_in (*else*);
|
walther@59982
|
103 |
val NONE =(*case*) CAS_Cmd.input f_in (*of*);
|
walther@59815
|
104 |
|
walther@59932
|
105 |
(*case*)
|
walther@59932
|
106 |
LI.locate_input_term (pt, pos) f_in (*of*);
|
walther@59932
|
107 |
"~~~~~ fun locate_input_term , args:"; val ((pt, pos), tm) = ((pt, pos), f_in);
|
walther@59932
|
108 |
val pos_pred = Pos.lev_back' pos (*f_pred ---"step pos cs"---> f_succ in appendFormula*)
|
walther@59932
|
109 |
val _(*f_pred*) = Ctree.get_curr_formula (pt, pos_pred);
|
walther@59932
|
110 |
|
walther@59932
|
111 |
(*case*) compare_step ([], [], (pt, pos_pred)) tm (*of*);
|
walther@59932
|
112 |
"~~~~~ fun compare_step , args:"; val ((tacis, c, ptp as (pt, pos as (p, _))), ifo) = (([], [], (pt, pos_pred)), tm);
|
walther@59932
|
113 |
val fo = Calc.current_formula ptp
|
walther@60154
|
114 |
val {nrls, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt (Ctree.par_pblobj pt p))
|
walther@59932
|
115 |
val {rew_ord, erls, rules, ...} = Rule_Set.rep nrls
|
walther@59932
|
116 |
val (found, der) = Derive.steps rew_ord erls rules fo ifo; (*<---------------*)
|
walther@59932
|
117 |
(*if*) found (*then*);
|
walther@59932
|
118 |
val tacis' = map (State_Steps.make_single rew_ord erls) der;
|
walther@59932
|
119 |
|
walther@59932
|
120 |
val (c', ptp) =
|
walther@59932
|
121 |
Derive.embed tacis' ptp;
|
walther@59932
|
122 |
"~~~~~ fun embed , args:"; val (tacis, (pt, pos as (p, Res))) = (tacis', ptp);
|
walther@59932
|
123 |
val (res, asm) = (State_Steps.result o last_elem) tacis
|
walther@59932
|
124 |
val (ist, ctxt) = case Ctree.get_obj Ctree.g_loc pt p of
|
walther@59932
|
125 |
(_, SOME (ist, ctxt)) => (ist, ctxt)
|
walther@59932
|
126 |
| (_, NONE) => error "Derive.embed Frm: uncovered case get_obj"
|
walther@59932
|
127 |
val (f, _) = Ctree.get_obj Ctree.g_result pt p
|
walther@59932
|
128 |
val p = Pos.lev_on p(*---------------only difference to (..,Frm) above*);
|
walther@59932
|
129 |
val tacis = (Tactic.Begin_Trans, Tactic.Begin_Trans' f, ((p, Pos.Frm), (Istate_Def.Uistate, ctxt))) ::
|
walther@59932
|
130 |
(State_Steps.insert_pos ((Pos.lev_on o Pos.lev_dn) p) tacis) @ [(Tactic.End_Trans, Tactic.End_Trans' (res, asm),
|
walther@59932
|
131 |
(Pos.pos_plus (length tacis) (Pos.lev_dn p, Pos.Res), (Ctree.new_val res ist, ctxt)))];
|
walther@60154
|
132 |
val {nrls, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt (Ctree.par_pblobj pt p))
|
walther@59932
|
133 |
val (pt, c, pos as (p, _)) =
|
walther@59932
|
134 |
|
walther@59932
|
135 |
Solve_Step.s_add_general (rev tacis) (pt, [], (p, Res));
|
walther@59932
|
136 |
"~~~~~ fun s_add_general , args:"; val (tacis, (pt, c, _)) = ((rev tacis), (pt, [], (p, Res)));
|
walther@59932
|
137 |
(*+*)length tacis = 8;
|
walther@59932
|
138 |
(*+*)if State_Steps.to_string tacis = "[\"\n" ^
|
walther@59997
|
139 |
"( End_Trans, End_Trans' xxx, ( ([2, 6], Res), Pstate ([\"\n(e_e, x + 1 = 2)\", \"\n" ^
|
walther@60324
|
140 |
"(v_v, x)\"], [], empty, NONE, \n2 + - 1 + x = 2, ORundef, false, true) ))\", \"\n" ^
|
walther@59997
|
141 |
"( Rewrite (\"sym_radd_commute\", \"?n + ?m = ?m + ?n\"), Rewrite' , ( ([2, 6], Res), Uistate ))\", \"\n" ^
|
walther@59997
|
142 |
"( Rewrite (\"sym_radd_commute\", \"?n + ?m = ?m + ?n\"), Rewrite' , ( ([2, 5], Res), Uistate ))\", \"\n" ^
|
walther@59997
|
143 |
"( Rewrite (\"sym_radd_left_commute\", \"?y + (?x + ?z) = ?x + (?y + ?z)\"), Rewrite' , ( ([2, 4], Res), Uistate ))\", \"\n" ^
|
walther@59997
|
144 |
"( Rewrite (\"sym_radd_commute\", \"?n + ?m = ?m + ?n\"), Rewrite' , ( ([2, 3], Res), Uistate ))\", \"\n" ^
|
walther@60324
|
145 |
"( Rewrite (\"#: 1 + x = - 1 + (2 + x)\", \"1 + x = - 1 + (2 + x)\"), Rewrite' , ( ([2, 2], Res), Uistate ))\", \"\n" ^
|
walther@59997
|
146 |
"( Rewrite (\"radd_commute\", \"?m + ?n = ?n + ?m\"), Rewrite' , ( ([2, 1], Res), Uistate ))\", \"\n" ^
|
walther@59932
|
147 |
"( Begin_Trans, Begin_Trans' xxx, ( ([2], Frm), Uistate ))\"]"
|
walther@59932
|
148 |
then () else error "Derive.embed CHANGED";
|
walther@59932
|
149 |
|
walther@59932
|
150 |
val (tacis', (_, tac_, (p, is))) = split_last tacis
|
walther@59932
|
151 |
|
walther@59932
|
152 |
(*+*)val Begin_Trans' _ = tac_;
|
walther@59932
|
153 |
|
walther@59933
|
154 |
val (p',c',_,pt') = Specify_Step.add tac_ is (pt, p)
|
walther@59932
|
155 |
|
walther@59932
|
156 |
(*-------------------- stop step into -------------------------------------------------------*)
|
walther@59932
|
157 |
(*\------------------- end step into -------------------------------------------------------/*)
|
walther@59932
|
158 |
|
walther@60340
|
159 |
(*/--------------------- final test ----------------------------------------------------------\*)
|
walther@59815
|
160 |
val (SOME (Uistate, ctxt_frm), SOME (ist_res, ctxt_res)) = get_obj g_loc (fst ptp''''') (fst (snd ptp'''''))
|
walther@59815
|
161 |
;
|
walther@59815
|
162 |
if
|
walther@59868
|
163 |
(ctxt_frm |> get_assumptions |> UnparseC.terms) = "[\"precond_rootmet x\"]"
|
walther@59815
|
164 |
andalso
|
walther@59868
|
165 |
(ctxt_res |> get_assumptions |> UnparseC.terms) = "[\"precond_rootmet x\"]"
|
walther@59815
|
166 |
andalso
|
walther@59844
|
167 |
Istate.string_of ist_res =
|
walther@60324
|
168 |
"Pstate ([\"\n(e_e, x + 1 = 2)\", \"\n(v_v, x)\"], [], empty, NONE, \n2 + - 1 + x = 2, ORundef, false, true)"
|
walther@59815
|
169 |
then () else error "/800-append-on-Frm.sml CHANGED";
|
walther@59815
|
170 |
|
walther@59983
|
171 |
Test_Tool.show_pt_tac (fst ptp''''');(*[
|
walther@59815
|
172 |
([], Frm), solve (x + 1 = 2, x)
|
walther@59997
|
173 |
. . . . . . . . . . Apply_Method ["Test", "squ-equ-test-subpbl1"],
|
walther@59815
|
174 |
([1], Frm), x + 1 = 2
|
walther@59815
|
175 |
. . . . . . . . . . Derive Test_simplify,
|
walther@59815
|
176 |
([1,1], Frm), x + 1 = 2
|
walther@59815
|
177 |
. . . . . . . . . . Rewrite ("radd_commute", "?m + ?n = ?n + ?m"),
|
walther@59815
|
178 |
([1,1], Res), 1 + x = 2
|
walther@60324
|
179 |
. . . . . . . . . . Rewrite ("#: 1 + x = - 1 + (2 + x)", "1 + x = - 1 + (2 + x)"),
|
walther@60324
|
180 |
([1,2], Res), - 1 + (2 + x) = 2
|
walther@59815
|
181 |
. . . . . . . . . . Rewrite ("sym_radd_commute", "?n + ?m = ?m + ?n"),
|
walther@60324
|
182 |
([1,3], Res), - 1 + (x + 2) = 2
|
walther@59815
|
183 |
. . . . . . . . . . Rewrite ("sym_radd_left_commute", "?y + (?x + ?z) = ?x + (?y + ?z)"),
|
walther@60324
|
184 |
([1,4], Res), x + (- 1 + 2) = 2
|
walther@59815
|
185 |
. . . . . . . . . . Rewrite ("sym_radd_commute", "?n + ?m = ?m + ?n"),
|
walther@60324
|
186 |
([1,5], Res), x + (2 + - 1) = 2
|
walther@59815
|
187 |
. . . . . . . . . . Rewrite ("sym_radd_commute", "?n + ?m = ?m + ?n"),
|
walther@60324
|
188 |
([1,6], Res), 2 + - 1 + x = 2
|
walther@59846
|
189 |
. . . . . . . . . . Tactic.input_to_string not impl. for ?!,
|
walther@60324
|
190 |
([1], Res), 2 + - 1 + x = 2
|
walther@59997
|
191 |
. . . . . . . . . . Check_Postcond ["sqroot-test", "univariate", "equation", "test"]]
|
walther@59815
|
192 |
*)
|