1 (* Title: test for rewtools.sml
2 authors: Walther Neuper 2000, 2006
4 theory Test_Some imports Isac.Build_Thydata begin
5 ML_file "~~/test/Tools/isac/ADDTESTS/accumulate-val/lucas_interpreter.sml"
6 ML {* KEStore_Elems.set_ref_thy @{theory};
7 fun autoCalculate' cI auto = autoCalculate cI auto |> Future.join *}
8 ML_file "Interpret/rewtools.sml"
11 "--------------------------------------------------------";
12 "--------------------------------------------------------";
13 "table of contents --------------------------------------";
14 "--------------------------------------------------------";
15 "----------- fun thy_containing_rls ---------------------";
16 "----------- apply thy_containing_rls -------------------";
17 "----------- fun thy_containing_cal ---------------------";
18 "----------- initContext Thy_ Integration-demo ----------";
19 "----------- initContext..Thy_, fun context_thm ---------";
20 "----------- initContext..Thy_, fun context_rls ---------";
21 "----------- checkContext..Thy_, fun context_thy --------";
22 "----------- checkContext..Thy_, fun context_rls --------";
23 "----------- checkContext..Thy_ on last formula ---------";
24 "----------- fun guh2theID ------------------------------";
25 "----------- debugging on Tests/solve_linear_as_rootpbl -";
26 "--------------------------------------------------------";
27 (*============ inhibit exn WN120321 ==============================================
28 "--------------------------------------------------------";
29 "----------- fun filter_appl_rews -----------------------";
30 ============ inhibit exn WN120321 ==============================================*)
31 "----------- fun is_contained_in ------------------------";
32 "--------------------------------------------------------";
33 "--------------------------------------------------------";
35 "----------- fun thy_containing_rls ---------------------";
36 "----------- fun thy_containing_rls ---------------------";
37 "----------- fun thy_containing_rls ---------------------";
38 (*ERROR WAS: Theory loader: undefined entry for theory "Isac.Complex_Main"*)
39 if thy_containing_rls "Biegelinie" "norm_Poly" = ("IsacKnowledge", "Poly") then ()
40 else error ("thy_containing_rls changed for 'Biegelinie', 'norm_Poly'")
42 "~~~~~ fun thy_containing_rls, args:"; val (thy', rls') = ("Biegelinie", "norm_Poly");
43 val thy = ThyC.get_theory thy'; (*.., EqSystem, Isac.Biegelinie}*)
44 val xxx = AList.lookup op= (KEStore_Elems.get_rlss thy) rls';
45 val SOME (thy'', _) = xxx;
46 val SOME ("Poly", _) = xxx;
47 if thy'' = "Poly" then () else error "--- fun thy_containing_rls: changed";
48 (*ERROR WAS: Theory loader: undefined entry for theory "Isac.Complex_Main" *)
49 if partID' thy'' = "IsacKnowledge" then () else error "fun partID': changed"
51 "~~~~~ fun partID', args:"; val (thy') = (thy');
52 ThyC.get_theory thy' (*.., EqSystem, Isac.Biegelinie}*)
54 "~~~~~ fun partID, args:"; val (thy) = (ThyC.get_theory thy');
55 (*ERROR WAS: Theory loader: undefined entry for theory "Isac.Complex_Main"*)
58 "~~~~~ fun knowthys , args:"; val () = ();
59 val allthys = filter_out (member Context.eq_thy
60 [(*ThyC.get_theory "ProgLang",*) ThyC.get_theory "Interpret",
61 ThyC.get_theory "MathEngine", ThyC.get_theory "BridgeLibisabelle"])
62 (Theory.ancestors_of (ThyC.get_theory "Build_Thydata"));
63 length allthys = 152; (*in Isabelle2015/Isac*)
64 (*ERROR WAS: Theory loader: undefined entry for theory "Isac.Complex_Main"
65 ThyC.get_theory "Complex_Main";*)
66 Thy_Info.get_theory "Complex_Main";;
68 "----------- apply thy_containing_rls -------------------";
69 "----------- apply thy_containing_rls -------------------";
70 "----------- apply thy_containing_rls -------------------";
71 if thy_containing_rls "Biegelinie" "norm_Poly" = ("IsacKnowledge", "Poly") then ()
72 else error ("thy_containing_rls changed for 'Biegelinie', 'norm_Poly'")
74 if thy_containing_rls "Biegelinie" "empty" = ("IsacScripts", "Know_Store") then ()
75 else error ("thy_containing_rls changed for 'Biegelinie', 'e_rls'")
77 if thy_containing_rls "Build_Thydata" "prog_expr" = (*FIXME: handle redifinition in several thys*)
78 ("IsacKnowledge", "Base_Tools") then ()
79 else error ("thy_containing_rls changed for 'Biegelinie', 'prog_expr'")
81 "----------- fun thy_containing_cal ---------------------";
82 "----------- fun thy_containing_cal ---------------------";
83 "----------- fun thy_containing_cal ---------------------";
84 (* ATTENTION: both, "IsacKnowledge" and "Prog_Expr" are fixed as results for any input*)
85 if thy_containing_cal "Biegelinie" "PLUS" = ("IsacKnowledge", "Base_Tools")
86 then () else error "(wrong) thy_containing_cal 'Biegelinie' 'PLUS' changed"
88 "----------- initContext Thy_ Integration-demo ----------";
89 "----------- initContext Thy_ Integration-demo ----------";
90 "----------- initContext Thy_ Integration-demo ----------";
93 [(["functionTerm (2 * x)","integrateBy x","antiDerivative FF"],
94 ("Integrate",["integrate","function"],
95 ["diff","integration"]))];
98 autoCalculate 1 CompleteCalc;
99 interSteps 1 ([1],Res);
100 interSteps 1 ([1,1],Res);
101 val ((pt,p),_) = get_calc 1; show_pt pt;
102 if existpt' ([1,1,1], Frm) pt then ()
103 else error "integrate.sml: interSteps on Rewrite_Set_Inst 1";
104 initContext 1 Thy_ ([1,1,1], Frm);
106 "----------- initContext..Thy_, fun context_thm ---------";
107 "----------- initContext..Thy_, fun context_thm ---------";
108 "----------- initContext..Thy_, fun context_thm ---------";
109 reset_states (); (*start of calculation, return No.1*)
110 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
111 ("Test", ["sqroot-test","univariate","equation","test"],
112 ["Test","squ-equ-test-subpbl1"]))];
113 Iterator 1; moveActiveRoot 1;
114 autoCalculate 1 CompleteCalc;
116 "----- no thy-context at result -----";
118 initContext 1 Thy_ p;
119 val ((pt,_),_) = get_calc 1; show_pt pt; (* 11 lines with subpbl *)
121 interSteps 1 ([2], Res);
122 val ((pt,_),_) = get_calc 1; show_pt pt; (* added [2,1]..[2,6] *)
123 interSteps 1 ([3,1], Res);
124 val ((pt,_),_) = get_calc 1; show_pt pt; (* added [3,1,1] Frm + Res *)
126 val p = ([2,4], Res);
127 "~~~~~ fun initContext, args:"; val ((cI:calcID), Thy_, (pos as (p,p_):pos')) = (1, Thy_, p);
128 member op = [Pbl,Met] p_ = false;
129 pos = ([],Res) = false;
130 val cs as (ptp as (pt,_),_) = get_calc cI;
131 exist_lev_on' pt pos = true;
132 val pos' = lev_on' pt pos
133 val tac = get_tac_checked pt pos';
134 is_rewtac tac = true;
135 "~~~~~ fun context_thy, args:"; val ((pt, pos as (p,p_)), (tac as Rewrite (thmID,_))) =
137 val Appl (Rewrite' (thy', ord', erls, _, (thmID,thm), f, (res,asm))) = applicable_in pos pt tac
138 val thm = Global_Theory.get_thm (Isac ()(*WN141021 ThyC.get_theory thy' ERROR*)) thmID
139 val thm_deriv = Thm.get_name_hint thm;
141 if Thy_Html.thm2guh (thy_containing_thm thm_deriv) (ThmC.cut_id thm_deriv)
142 = "thy_isac_Test-thm-radd_left_commute" then ()
143 else error "context_thy mini-subpbl ([2,4], Res) changed";
144 (*~/proto3/kbase/thy$ ls -l thy_isac_Test-thm-radd_left_commute*
145 -rw-rw-r-- 1 wneuper wneuper 638 Aug 8 16:04 thy_isac_Test-thm-radd_left_commute.html*)
148 val p = ([3,1,1], Frm);
149 "~~~~~ fun initContext, args:"; val ((cI:calcID), Thy_, (pos as (p,p_):pos')) = (1, Thy_, p);
150 member op = [Pbl,Met] p_ = false;
151 pos = ([],Res) = false;
152 val cs as (ptp as (pt,_),_) = get_calc cI;
153 exist_lev_on' pt pos = true;
154 val pos' = lev_on' pt pos
155 val tac = get_tac_checked pt pos';
156 is_rewtac tac = true;
157 "~~~~~ fun context_thy, args:"; val ((pt, pos as (p,p_)), (tac as Rewrite_Inst (subs, (thmID,_))))=
159 val Appl (Rewrite_Inst' (thy', ord', erls, _, subst, (thmID,_), f, (res, asm))) =
160 applicable_in pos pt tac
161 val thm = Global_Theory.get_thm (Isac ()(*WN141021 ThyC.get_theory thy' ERROR*)) thmID
162 val thm_deriv = Thm.get_name_hint thm;
163 if Thy_Html.thm2guh (thy_containing_thm thm_deriv) (ThmC.cut_id thm_deriv) =
164 "thy_isac_Test-thm-risolate_bdv_add" then ()
165 else error "context_thy mini-subpbl ([3,1,1], Frm) changed";
166 (*~/proto3/kbase/thy$ ls -l thy_isac_Test-thm-risolate_bdv_add*
167 -rw-rw-r-- 1 wneuper wneuper 646 Aug 8 16:04 thy_isac_Test-thm-risolate_bdv_add.html*)
170 val p = ([2,5], Res);
171 "~~~~~ fun initContext, args:"; val ((cI:calcID), Thy_, (pos as (p,p_):pos')) = (1, Thy_, p);
172 member op = [Pbl,Met] p_ = false;
173 pos = ([],Res) = false;
174 val cs as (ptp as (pt,_),_) = get_calc cI;
175 exist_lev_on' pt pos = true;
176 val pos' = lev_on' pt pos
177 val tac = get_tac_checked pt pos';
178 if is_rewtac tac = false then ()
179 else error "initContext: context_thy .. Calculate PLUS .. TO BE IMPLEMENTED"
181 "----------- initContext..Thy_, fun context_rls ---------";
182 "----------- initContext..Thy_, fun context_rls ---------";
183 "----------- initContext..Thy_, fun context_rls ---------";
184 (*using pt from above*)
186 val tac = Rewrite_Set "Test_simplify";
187 initContext 1 Thy_ p;
188 (*Res->Res, Rewrite_Set "Test_simplify" x + 1 + -1 * 2 = 0 -> -1 + x = 0
189 --- in initContext..Thy_ ---*)
190 val ContRls {rls,result,...} = context_thy (pt,p) tac;
191 if rls = "thy_isac_Test-rls-Test_simplify"
192 andalso UnparseC.term result = "-1 + x = 0" then ()
193 else error "rewtools.sml initContext..Th_ thy_isac_Test-rls-Test_simplify";
195 val p = ([3,1], Frm);
196 val tac = Rewrite_Set_Inst (["(''bdv'', x)"],"isolate_bdv");
197 initContext 1 Thy_ p;
198 (*Frm->Res, Rewrite_Set_Inst "isolate_bdv" -1 + x = 0 -> x = 0 + -1 * -1
199 --- in initContext..Thy_ ---*)
200 val ContRlsInst {rls,result,...} = context_thy (pt,p) tac;
201 if rls = "thy_isac_Test-rls-isolate_bdv"
202 andalso UnparseC.term result = "x = 0 + -1 * -1" then ()
203 else error "rewtools.sml initContext..Th_ thy_Test-thm-risolate_bdv_add";
205 "----------- checkContext..Thy_, fun context_thy --------";
206 "----------- checkContext..Thy_, fun context_thy --------";
207 "----------- checkContext..Thy_, fun context_thy --------";
208 (*using pt from above*)
209 val p = ([2,4], Res);
210 val tac = Rewrite ("radd_left_commute", @{thm radd_left_commute});
211 checkContext 1 p "thy_Test-thm-radd_left_commute";
212 (* radd_left_commute: 1 + (-2 + x) = 0 -> -2 + (1 + x) = 0
213 --- in checkContext..Thy_ ---*)
214 val ContThm {thm,result,...} = context_thy (pt,p) tac;
215 if thm = "thy_isac_Test-thm-radd_left_commute"
216 andalso UnparseC.term result = "-2 + (1 + x) = 0" then ()
217 else error "rewtools.sml checkContext.._ thy_Test-thm-radd_left_commute";
219 val p = ([3,1,1], Frm);
220 val tac = Rewrite_Inst (["(''bdv'',x)"],("risolate_bdv_add", @{thm "risolate_bdv_add"}));
221 checkContext 1 p "thy_Test-thm-risolate_bdv_add";
222 (* risolate_bdv_add: -1 + x = 0 -> x = 0 + -1 * -1
223 --- in checkContext..Thy_ ---*)
224 val ContThmInst {thm,result,...} = context_thy (pt,p) tac;
225 if thm = "thy_isac_Test-thm-risolate_bdv_add"
226 andalso UnparseC.term result = "x = 0 + - 1 * -1" then ()
227 else error "rewtools.sml checkContext..T_ thy_Test-thm-risolate_bdv_add";
229 val p = ([2,5], Res);
230 val tac = Calculate "plus";
231 (*checkContext..Thy_ 1 ([2,5], Res);*)
232 (*FIXXXME #######################vvvvv kestoreID !!!!!!!!!!!!!!!!*)
234 (* Calculate "plus" -2 + (1 + x) = 0 -> -1 + x = 0
235 --- in checkContext..Thy_ ---*)
237 "----------- checkContext..Thy_, fun context_rls --------";
238 "----------- checkContext..Thy_, fun context_rls --------";
239 "----------- checkContext..Thy_, fun context_rls --------";
240 (*using pt from above*)
242 val tac = Rewrite_Set "Test_simplify";
243 checkContext 1 p "thy_isac_Test-rls-Test_simplify";
244 (*Res->Res, Rewrite_Set "Test_simplify" x + 1 + -1 * 2 = 0 -> -1 + x = 0
245 --- in checkContext..Thy_ ---*)
246 val ContRls {rls,result,...} = context_thy (pt,p) tac;
247 if rls = "thy_isac_Test-rls-Test_simplify"
248 andalso UnparseC.term result = "-1 + x = 0" then ()
249 else error "rewtools.sml checkContext..Thy_ thy_Test-rls-Test_simplify";
251 val p = ([3,1], Frm);
252 val tac = Rewrite_Set_Inst (["(''bdv'', x)"],"isolate_bdv");
253 checkContext 1 p "thy_Test-rls-isolate_bdv";
254 val ContRlsInst {rls,result,...} = context_thy (pt,p) tac;
255 if rls = "thy_isac_Test-rls-isolate_bdv"
256 andalso UnparseC.term result = "x = 0 + -1 * -1" then ()
257 else error "rewtools.sml checkContext..Thy_ thy_Test-thm-isolate_bdv";
259 "----------- checkContext..Thy_ on last formula ---------";
260 "----------- checkContext..Thy_ on last formula ---------";
261 "----------- checkContext..Thy_ on last formula ---------";
262 reset_states (); (*start of calculation, return No.1*)
263 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
264 ("Test", ["sqroot-test","univariate","equation","test"],
265 ["Test","squ-equ-test-subpbl1"]))];
266 Iterator 1; moveActiveRoot 1;
268 autoCalculate 1 CompleteCalcHead;
269 autoCalculate 1 (Steps 1);
270 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
271 initContext 1 Thy_ ([1], Frm);
272 checkContext 1 ([1], Frm) "thy_isac_Test-thm-radd_left_commute";
274 autoCalculate 1 (Steps 1);
275 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
276 initContext 1 Thy_ ([1], Res);
277 checkContext 1 ([1], Res) "thy_isac_Test-rls-Test_simplify";
279 "----------- fun guh2theID ------------------------------";
280 "----------- fun guh2theID ------------------------------";
281 "----------- fun guh2theID ------------------------------";
282 val guh = "thy_scri_ListG-thm-zip_Nil";
283 (*default_print_depth 3; 999*)
284 take_fromto 1 4 (Symbol.explode guh);
285 take_fromto 5 9 (Symbol.explode guh);
286 val rest = takerest (9,(Symbol.explode guh));
289 space_implode "-" rest;
293 val thyID = takewhile [] (not o (curry op= delim)) rest;
294 val rest' = dropuntil (curry op= delim) rest;
295 val setc = take_fromto 1 5 rest';
296 val xstr = takerest (5, rest');
298 if guh2theID guh = ["IsacScripts", "ListG", "Theorems", "zip_Nil"] then ()
299 else error "rewtools.sml: guh2theID thy_scri_ListG-thm-zip_Nil changed";
302 "----------- debugging on Tests/solve_linear_as_rootpbl -";
303 "----------- debugging on Tests/solve_linear_as_rootpbl -";
304 "----------- debugging on Tests/solve_linear_as_rootpbl -";
305 "----- initContext -----";
308 [(["equality (1+-1*2+x=(0::real))", "solveFor x", "solutions L"],
310 ["LINEAR","univariate","equation","test"],
311 ["Test","solve_linear"]))];
312 Iterator 1; moveActiveRoot 1;
313 autoCalculate 1 CompleteCalcHead;
315 autoCalculate 1 (Steps 1); val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
316 if is_curr_endof_calc pt ([1],Frm) then ()
317 else error "rewtools.sml is_curr_endof_calc ([1],Frm)";
319 autoCalculate 1 (Steps 1); val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
321 if not (is_curr_endof_calc pt ([1],Frm)) then ()
322 else error "rewtools.sml is_curr_endof_calc ([1],Frm) not";
323 if is_curr_endof_calc pt ([1],Res) then ()
324 else error "rewtools.sml is_curr_endof_calc ([1],Res)";
326 initContext 1 Thy_ ([1],Res);
328 "----- checkContext -----";
331 [(["equality (1+-1*2+x=(0::real))", "solveFor x", "solutions L"],
333 ["LINEAR","univariate","equation","test"],
334 ["Test","solve_linear"]))];
335 Iterator 1; moveActiveRoot 1;
336 autoCalculate 1 CompleteCalc;
337 interSteps 1 ([1],Res);
339 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
340 checkContext 1 ([1],Res) "thy_isac_Test-rls-Test_simplify";
342 interSteps 1 ([2],Res);
343 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
345 checkContext 1 ([2,1],Res) "thy_isac_Test-rls-Test_simplify";
346 checkContext 1 ([2,2],Res) "thy_isac_Test-rls-Test_simplify";
348 "----------- fun is_contained_in ------------------------";
349 "----------- fun is_contained_in ------------------------";
350 "----------- fun is_contained_in ------------------------";
351 val r1 = Thm ("real_diff_minus",ThmC.numerals_to_Free @{thm real_diff_minus});
352 if Rtools.contains_rule r1 Test_simplify then ()
353 else error "rewtools.sml Rtools.contains_rule Thm";
355 val r1 = Eval ("Groups.plus_class.plus", eval_binop "#add_");
356 if Rtools.contains_rule r1 Test_simplify then ()
357 else error "rewtools.sml Rtools.contains_rule Eval";
359 val r1 = Eval ("Groups.minus_class.minus", eval_binop "#add_");
360 if not (Rtools.contains_rule r1 Test_simplify) then ()
361 else error "rewtools.sml Rtools.contains_rule Eval";