funpack: remove remainings of Script, finished.
1 (* equational systems, minimal -- for use in Biegelinie
4 (c) due to copyright terms
7 theory EqSystem imports Integrate Rational Root begin
12 "[real list, real list, 'a] => bool" ("_ from _ occur'_exactly'_in _")
14 (*descriptions in the related problems*)
15 solveForVars :: "real list => toreall"
16 solution :: "bool list => toreall"
18 (*the CAS-command, eg. "solveSystem [x+y=1,y=2] [x,y]"*)
19 solveSystem :: "[bool list, real list] => bool list"
22 (*stated as axioms, todo: prove as theorems
23 'bdv' is a constant handled on the meta-level
24 specifically as a 'bound variable' *)
26 commute_0_equality: "(0 = a) = (a = 0)" and
28 (*WN0510 see simliar rules 'isolate_' 'separate_' (by RL)
29 [bdv_1,bdv_2,bdv_3,bdv_4] work also for 2 and 3 bdvs, ugly !*)
31 "[| [] from [bdv_1,bdv_2,bdv_3,bdv_4] occur_exactly_in a |]
32 ==> (a + b = c) = (b = c + -1*a)" and
34 "[| some_of [bdv_1,bdv_2,bdv_3,bdv_4] occur_in b; Not (b=!=0) |]
35 ==> (a = b) = (a + -1*b = 0)" and
37 "[| some_of [bdv_1,bdv_2,bdv_3,bdv_4] occur_in c |]
38 ==> (a = b + c) = (a + -1*c = b)" and
40 "[| Not (some_of [bdv_1,bdv_2,bdv_3,bdv_4] occur_in a) |]
41 ==> (a + b = c) = (b = -1*a + c)" and
43 "[| [] from [bdv_1,bdv_2,bdv_3,bdv_4] occur_exactly_in a; Not (a=!=0) |]
44 ==>(a * b = c) = (b = c / a)"
45 axiomatization where (*..if replaced by "and" we get an error in
46 --- rewrite in [EqSystem,normalise,2x2] --- step "--- 3---";*)
47 order_system_NxN: "[a,b] = [b,a]"
48 (*requires rew_ord for termination, eg. ord_simplify_Integral;
49 works for lists of any length, interestingly !?!*)
54 (** eval functions **)
56 (*certain variables of a given list occur _all_ in a term
57 args: all: ..variables, which are under consideration (eg. the bound vars)
58 vs: variables which must be in t,
59 and none of the others in all must be in t
60 t: the term under consideration
62 fun occur_exactly_in vs all t =
63 let fun occurs_in' a b = occurs_in b a
64 in foldl and_ (true, map (occurs_in' t) vs)
65 andalso not (foldl or_ (false, map (occurs_in' t)
66 (subtract op = vs all)))
69 (*("occur_exactly_in", ("EqSystem.occur'_exactly'_in",
70 eval_occur_exactly_in "#eval_occur_exactly_in_"))*)
71 fun eval_occur_exactly_in _ "EqSystem.occur'_exactly'_in"
72 (p as (Const ("EqSystem.occur'_exactly'_in",_)
74 if occur_exactly_in (TermC.isalist2list vs) (TermC.isalist2list all) t
75 then SOME ((Rule.term2str p) ^ " = True",
76 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
77 else SOME ((Rule.term2str p) ^ " = False",
78 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
79 | eval_occur_exactly_in _ _ _ _ = NONE;
81 setup \<open>KEStore_Elems.add_calcs
83 ("EqSystem.occur'_exactly'_in",
84 eval_occur_exactly_in "#eval_occur_exactly_in_"))]\<close>
86 (** rewrite order 'ord_simplify_System' **)
88 (* order wrt. several linear (i.e. without exponents) variables "c","c_2",..
89 which leaves the monomials containing c, c_2,... at the end of an Integral
90 and puts the c, c_2,... rightmost within a monomial.
92 WN050906 this is a quick and dirty adaption of ord_make_polynomial_in,
93 which was most adequate, because it uses size_of_term*)
95 local (*. for simplify_System .*)
97 open Term; (* for type order = EQUAL | LESS | GREATER *)
99 fun pr_ord EQUAL = "EQUAL"
100 | pr_ord LESS = "LESS"
101 | pr_ord GREATER = "GREATER";
103 fun dest_hd' (Const (a, T)) = (((a, 0), T), 0)
104 | dest_hd' (Free (ccc, T)) =
105 (case Symbol.explode ccc of
106 "c"::[] => ((("|||||||||||||||||||||", 0), T), 1)(*greatest string WN*)
107 | "c"::"_"::_ => ((("|||||||||||||||||||||", 0), T), 1)
108 | _ => (((ccc, 0), T), 1))
109 | dest_hd' (Var v) = (v, 2)
110 | dest_hd' (Bound i) = ((("", i), dummyT), 3)
111 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
113 fun size_of_term' (Free (ccc, _)) =
114 (case Symbol.explode ccc of (*WN0510 hack for the bound variables*)
116 | "c"::"_"::is => 1000 * ((TermC.int_of_str o implode) is)
118 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
119 | size_of_term' (f$t) = size_of_term' f + size_of_term' t
120 | size_of_term' _ = 1;
122 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *)
123 (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
124 | term_ord' pr thy (t, u) =
128 val (f, ts) = strip_comb t and (g, us) = strip_comb u;
129 val _ = tracing ("t= f@ts= \"" ^ Rule.term_to_string''' thy f ^ "\" @ \"[" ^
130 commas (map (Rule.term_to_string''' thy) ts) ^ "]\"");
131 val _ = tracing ("u= g@us= \"" ^ Rule.term_to_string''' thy g ^ "\" @ \"[" ^
132 commas (map (Rule.term_to_string''' thy) us) ^ "]\"");
133 val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' t) ^ ", " ^
134 string_of_int (size_of_term' u) ^ ")");
135 val _ = tracing ("hd_ord(f,g) = " ^ ((pr_ord o hd_ord) (f,g)));
136 val _ = tracing ("terms_ord (ts,us) = " ^(pr_ord o terms_ord str false) (ts,us));
137 val _=tracing("-------");
140 case int_ord (size_of_term' t, size_of_term' u) of
142 let val (f, ts) = strip_comb t and (g, us) = strip_comb u
143 in (case hd_ord (f, g) of
144 EQUAL => (terms_ord str pr) (ts, us)
148 and hd_ord (f, g) = (* ~ term.ML *)
149 prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
150 and terms_ord str pr (ts, us) = list_ord (term_ord' pr (Celem.assoc_thy "Isac"))(ts, us);
154 (*WN0510 for preliminary use in eval_order_system, see case-study mat-eng.tex
155 fun ord_simplify_System_rev (pr:bool) thy subst tu =
156 (term_ord' pr thy (Library.swap tu) = LESS);*)
159 fun ord_simplify_System (pr:bool) thy subst tu =
160 (term_ord' pr thy tu = LESS);
164 Rule.rew_ord' := overwritel (! Rule.rew_ord',
165 [("ord_simplify_System", ord_simplify_System false thy)
171 (*.adapted from 'order_add_mult_in' by just replacing the rew_ord.*)
172 val order_add_mult_System =
173 Rule.Rls{id = "order_add_mult_System", preconds = [],
174 rew_ord = ("ord_simplify_System",
175 ord_simplify_System false @{theory "Integrate"}),
176 erls = Rule.e_rls,srls = Rule.Erls, calc = [], errpatts = [],
177 rules = [Rule.Thm ("mult_commute",TermC.num_str @{thm mult.commute}),
179 Rule.Thm ("real_mult_left_commute",TermC.num_str @{thm real_mult_left_commute}),
180 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
181 Rule.Thm ("mult_assoc",TermC.num_str @{thm mult.assoc}),
182 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
183 Rule.Thm ("add_commute",TermC.num_str @{thm add.commute}),
185 Rule.Thm ("add_left_commute",TermC.num_str @{thm add.left_commute}),
186 (*x + (y + z) = y + (x + z)*)
187 Rule.Thm ("add_assoc",TermC.num_str @{thm add.assoc})
188 (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
190 scr = Rule.EmptyScr};
193 (*.adapted from 'norm_Rational' by
194 #1 using 'ord_simplify_System' in 'order_add_mult_System'
195 #2 NOT using common_nominator_p .*)
196 val norm_System_noadd_fractions =
197 Rule.Rls {id = "norm_System_noadd_fractions", preconds = [],
198 rew_ord = ("dummy_ord",Rule.dummy_ord),
199 erls = norm_rat_erls, srls = Rule.Erls, calc = [], errpatts = [],
200 rules = [(*sequence given by operator precedence*)
201 Rule.Rls_ discard_minus,
203 Rule.Rls_ rat_mult_divide,
205 Rule.Rls_ reduce_0_1_2,
206 Rule.Rls_ (*order_add_mult #1*) order_add_mult_System,
207 Rule.Rls_ collect_numerals,
208 (*Rule.Rls_ add_fractions_p, #2*)
215 (*.adapted from 'norm_Rational' by
216 *1* using 'ord_simplify_System' in 'order_add_mult_System'.*)
218 Rule.Rls {id = "norm_System", preconds = [],
219 rew_ord = ("dummy_ord",Rule.dummy_ord),
220 erls = norm_rat_erls, srls = Rule.Erls, calc = [], errpatts = [],
221 rules = [(*sequence given by operator precedence*)
222 Rule.Rls_ discard_minus,
224 Rule.Rls_ rat_mult_divide,
226 Rule.Rls_ reduce_0_1_2,
227 Rule.Rls_ (*order_add_mult *1*) order_add_mult_System,
228 Rule.Rls_ collect_numerals,
229 Rule.Rls_ add_fractions_p,
236 (*.simplify an equational system BEFORE solving it such that parentheses are
237 ( ((u0*v0)*w0) + ( ((u1*v1)*w1) * c + ... +((u4*v4)*w4) * c_4 ) )
238 ATTENTION: works ONLY for bound variables c, c_1, c_2, c_3, c_4 :ATTENTION
239 This is a copy from 'make_ratpoly_in' with respective reductions:
240 *0* expand the term, ie. distribute * and / over +
241 *1* ord_simplify_System instead of termlessI
242 *2* no add_fractions_p (= common_nominator_p_rls !)
243 *3* discard_parentheses only for (.*(.*.))
244 analoguous to simplify_Integral .*)
245 val simplify_System_parenthesized =
246 Rule.Seq {id = "simplify_System_parenthesized", preconds = []:term list,
247 rew_ord = ("dummy_ord", Rule.dummy_ord),
248 erls = Atools_erls, srls = Rule.Erls, calc = [], errpatts = [],
249 rules = [Rule.Thm ("distrib_right",TermC.num_str @{thm distrib_right}),
250 (*"(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w"*)
251 Rule.Thm ("add_divide_distrib",TermC.num_str @{thm add_divide_distrib}),
252 (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)
253 (*^^^^^ *0* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
254 Rule.Rls_ norm_Rational_noadd_fractions(**2**),
255 Rule.Rls_ (*order_add_mult_in*) norm_System_noadd_fractions (**1**),
256 Rule.Thm ("sym_mult_assoc",
257 TermC.num_str (@{thm mult.assoc} RS @{thm sym}))
258 (*Rule.Rls_ discard_parentheses *3**),
259 Rule.Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
260 Rule.Rls_ separate_bdv2,
261 Rule.Calc ("Rings.divide_class.divide" ,eval_cancel "#divide_e")
263 scr = Rule.EmptyScr};
266 (*.simplify an equational system AFTER solving it;
267 This is a copy of 'make_ratpoly_in' with the differences
268 *1* ord_simplify_System instead of termlessI .*)
269 (*TODO.WN051031 ^^^^^^^^^^ should be in EACH rls contained *)
270 val simplify_System =
271 Rule.Seq {id = "simplify_System", preconds = []:term list,
272 rew_ord = ("dummy_ord", Rule.dummy_ord),
273 erls = Atools_erls, srls = Rule.Erls, calc = [], errpatts = [],
274 rules = [Rule.Rls_ norm_Rational,
275 Rule.Rls_ (*order_add_mult_in*) norm_System (**1**),
276 Rule.Rls_ discard_parentheses,
277 Rule.Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
278 Rule.Rls_ separate_bdv2,
279 Rule.Calc ("Rings.divide_class.divide" ,eval_cancel "#divide_e")
281 scr = Rule.EmptyScr};
283 val simplify_System =
284 Rule.append_rls "simplify_System" simplify_System_parenthesized
285 [Rule.Thm ("sym_add_assoc",
286 TermC.num_str (@{thm add.assoc} RS @{thm sym}))];
291 Rule.Rls {id="isolate_bdvs", preconds = [],
292 rew_ord = ("e_rew_ord", Rule.e_rew_ord),
293 erls = Rule.append_rls "erls_isolate_bdvs" Rule.e_rls
294 [(Rule.Calc ("EqSystem.occur'_exactly'_in",
295 eval_occur_exactly_in
296 "#eval_occur_exactly_in_"))
298 srls = Rule.Erls, calc = [], errpatts = [],
300 [Rule.Thm ("commute_0_equality", TermC.num_str @{thm commute_0_equality}),
301 Rule.Thm ("separate_bdvs_add", TermC.num_str @{thm separate_bdvs_add}),
302 Rule.Thm ("separate_bdvs_mult", TermC.num_str @{thm separate_bdvs_mult})],
303 scr = Rule.EmptyScr};
306 val isolate_bdvs_4x4 =
307 Rule.Rls {id="isolate_bdvs_4x4", preconds = [],
308 rew_ord = ("e_rew_ord", Rule.e_rew_ord),
309 erls = Rule.append_rls
310 "erls_isolate_bdvs_4x4" Rule.e_rls
311 [Rule.Calc ("EqSystem.occur'_exactly'_in",
312 eval_occur_exactly_in "#eval_occur_exactly_in_"),
313 Rule.Calc ("Atools.ident",eval_ident "#ident_"),
314 Rule.Calc ("Atools.some'_occur'_in",
315 eval_some_occur_in "#some_occur_in_"),
316 Rule.Thm ("not_true",TermC.num_str @{thm not_true}),
317 Rule.Thm ("not_false",TermC.num_str @{thm not_false})
319 srls = Rule.Erls, calc = [], errpatts = [],
320 rules = [Rule.Thm ("commute_0_equality", TermC.num_str @{thm commute_0_equality}),
321 Rule.Thm ("separate_bdvs0", TermC.num_str @{thm separate_bdvs0}),
322 Rule.Thm ("separate_bdvs_add1", TermC.num_str @{thm separate_bdvs_add1}),
323 Rule.Thm ("separate_bdvs_add1", TermC.num_str @{thm separate_bdvs_add2}),
324 Rule.Thm ("separate_bdvs_mult", TermC.num_str @{thm separate_bdvs_mult})
325 ], scr = Rule.EmptyScr};
330 (*.order the equations in a system such, that a triangular system (if any)
331 appears as [..c_4 = .., ..., ..., ..c_1 + ..c_2 + ..c_3 ..c_4 = ..].*)
333 Rule.Rls {id="order_system", preconds = [],
334 rew_ord = ("ord_simplify_System",
335 ord_simplify_System false thy),
336 erls = Rule.Erls, srls = Rule.Erls, calc = [], errpatts = [],
337 rules = [Rule.Thm ("order_system_NxN", TermC.num_str @{thm order_system_NxN})
339 scr = Rule.EmptyScr};
341 val prls_triangular =
342 Rule.Rls {id="prls_triangular", preconds = [],
343 rew_ord = ("e_rew_ord", Rule.e_rew_ord),
344 erls = Rule.Rls {id="erls_prls_triangular", preconds = [],
345 rew_ord = ("e_rew_ord", Rule.e_rew_ord),
346 erls = Rule.Erls, srls = Rule.Erls, calc = [], errpatts = [],
347 rules = [(*for precond NTH_CONS ...*)
348 Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
349 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_")
350 (*immediately repeated rewrite pushes
351 '+' into precondition !*)
353 scr = Rule.EmptyScr},
354 srls = Rule.Erls, calc = [], errpatts = [],
355 rules = [Rule.Thm ("NTH_CONS",TermC.num_str @{thm NTH_CONS}),
356 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
357 Rule.Thm ("NTH_NIL",TermC.num_str @{thm NTH_NIL}),
358 Rule.Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
359 Rule.Thm ("tl_Nil",TermC.num_str @{thm tl_Nil}),
360 Rule.Calc ("EqSystem.occur'_exactly'_in",
361 eval_occur_exactly_in
362 "#eval_occur_exactly_in_")
364 scr = Rule.EmptyScr};
368 (*WN060914 quickly created for 4x4;
369 more similarity to prls_triangular desirable*)
370 val prls_triangular4 =
371 Rule.Rls {id="prls_triangular4", preconds = [],
372 rew_ord = ("e_rew_ord", Rule.e_rew_ord),
373 erls = Rule.Rls {id="erls_prls_triangular4", preconds = [],
374 rew_ord = ("e_rew_ord", Rule.e_rew_ord),
375 erls = Rule.Erls, srls = Rule.Erls, calc = [], errpatts = [],
376 rules = [(*for precond NTH_CONS ...*)
377 Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
378 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_")
379 (*immediately repeated rewrite pushes
380 '+' into precondition !*)
382 scr = Rule.EmptyScr},
383 srls = Rule.Erls, calc = [], errpatts = [],
384 rules = [Rule.Thm ("NTH_CONS",TermC.num_str @{thm NTH_CONS}),
385 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
386 Rule.Thm ("NTH_NIL",TermC.num_str @{thm NTH_NIL}),
387 Rule.Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
388 Rule.Thm ("tl_Nil",TermC.num_str @{thm tl_Nil}),
389 Rule.Calc ("EqSystem.occur'_exactly'_in",
390 eval_occur_exactly_in
391 "#eval_occur_exactly_in_")
393 scr = Rule.EmptyScr};
396 setup \<open>KEStore_Elems.add_rlss
397 [("simplify_System_parenthesized",
398 (Context.theory_name @{theory}, prep_rls' simplify_System_parenthesized)),
399 ("simplify_System", (Context.theory_name @{theory}, prep_rls' simplify_System)),
400 ("isolate_bdvs", (Context.theory_name @{theory}, prep_rls' isolate_bdvs)),
401 ("isolate_bdvs_4x4", (Context.theory_name @{theory}, prep_rls' isolate_bdvs_4x4)),
402 ("order_system", (Context.theory_name @{theory}, prep_rls' order_system)),
403 ("order_add_mult_System", (Context.theory_name @{theory}, prep_rls' order_add_mult_System)),
404 ("norm_System_noadd_fractions",
405 (Context.theory_name @{theory}, prep_rls' norm_System_noadd_fractions)),
406 ("norm_System", (Context.theory_name @{theory}, prep_rls' norm_System))]\<close>
409 setup \<open>KEStore_Elems.add_pbts
410 [(Specify.prep_pbt thy "pbl_equsys" [] Celem.e_pblID
412 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
413 ("#Find" ,["solution ss'''"](*''' is copy-named*))],
414 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)], SOME "solveSystem e_s v_s", [])),
415 (Specify.prep_pbt thy "pbl_equsys_lin" [] Celem.e_pblID
416 (["LINEAR", "system"],
417 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
418 (*TODO.WN050929 check linearity*)
419 ("#Find" ,["solution ss'''"])],
420 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)], SOME "solveSystem e_s v_s", [])),
421 (Specify.prep_pbt thy "pbl_equsys_lin_2x2" [] Celem.e_pblID
422 (["2x2", "LINEAR", "system"],
423 (*~~~~~~~~~~~~~~~~~~~~~~~~~*)
424 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
425 ("#Where" ,["LENGTH (e_s:: bool list) = 2", "LENGTH v_s = 2"]),
426 ("#Find" ,["solution ss'''"])],
427 Rule.append_rls "prls_2x2_linear_system" Rule.e_rls
428 [Rule.Thm ("LENGTH_CONS",TermC.num_str @{thm LENGTH_CONS}),
429 Rule.Thm ("LENGTH_NIL",TermC.num_str @{thm LENGTH_NIL}),
430 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
431 Rule.Calc ("HOL.eq",eval_equal "#equal_")],
432 SOME "solveSystem e_s v_s", [])),
433 (Specify.prep_pbt thy "pbl_equsys_lin_2x2_tri" [] Celem.e_pblID
434 (["triangular", "2x2", "LINEAR", "system"],
435 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
437 ["(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))",
438 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"]),
439 ("#Find" ,["solution ss'''"])],
440 prls_triangular, SOME "solveSystem e_s v_s", [["EqSystem","top_down_substitution","2x2"]])),
441 (Specify.prep_pbt thy "pbl_equsys_lin_2x2_norm" [] Celem.e_pblID
442 (["normalise", "2x2", "LINEAR", "system"],
443 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
444 ("#Find" ,["solution ss'''"])],
445 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)],
446 SOME "solveSystem e_s v_s",
447 [["EqSystem","normalise","2x2"]])),
448 (Specify.prep_pbt thy "pbl_equsys_lin_3x3" [] Celem.e_pblID
449 (["3x3", "LINEAR", "system"],
450 (*~~~~~~~~~~~~~~~~~~~~~~~~~*)
451 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
452 ("#Where" ,["LENGTH (e_s:: bool list) = 3", "LENGTH v_s = 3"]),
453 ("#Find" ,["solution ss'''"])],
454 Rule.append_rls "prls_3x3_linear_system" Rule.e_rls
455 [Rule.Thm ("LENGTH_CONS",TermC.num_str @{thm LENGTH_CONS}),
456 Rule.Thm ("LENGTH_NIL",TermC.num_str @{thm LENGTH_NIL}),
457 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
458 Rule.Calc ("HOL.eq",eval_equal "#equal_")],
459 SOME "solveSystem e_s v_s", [])),
460 (Specify.prep_pbt thy "pbl_equsys_lin_4x4" [] Celem.e_pblID
461 (["4x4", "LINEAR", "system"],
462 (*~~~~~~~~~~~~~~~~~~~~~~~~~*)
463 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
464 ("#Where" ,["LENGTH (e_s:: bool list) = 4", "LENGTH v_s = 4"]),
465 ("#Find" ,["solution ss'''"])],
466 Rule.append_rls "prls_4x4_linear_system" Rule.e_rls
467 [Rule.Thm ("LENGTH_CONS",TermC.num_str @{thm LENGTH_CONS}),
468 Rule.Thm ("LENGTH_NIL",TermC.num_str @{thm LENGTH_NIL}),
469 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
470 Rule.Calc ("HOL.eq",eval_equal "#equal_")],
471 SOME "solveSystem e_s v_s", [])),
472 (Specify.prep_pbt thy "pbl_equsys_lin_4x4_tri" [] Celem.e_pblID
473 (["triangular", "4x4", "LINEAR", "system"],
474 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
475 ("#Where" , (*accepts missing variables up to diagional form*)
476 ["(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))",
477 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))",
478 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))",
479 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"]),
480 ("#Find" ,["solution ss'''"])],
481 Rule.append_rls "prls_tri_4x4_lin_sys" prls_triangular
482 [Rule.Calc ("Atools.occurs'_in",eval_occurs_in "")],
483 SOME "solveSystem e_s v_s",
484 [["EqSystem","top_down_substitution","4x4"]])),
485 (Specify.prep_pbt thy "pbl_equsys_lin_4x4_norm" [] Celem.e_pblID
486 (["normalise", "4x4", "LINEAR", "system"],
487 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
488 (*LENGTH is checked 1 level above*)
489 ("#Find" ,["solution ss'''"])],
490 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)],
491 SOME "solveSystem e_s v_s",
492 [["EqSystem","normalise","4x4"]]))]\<close>
495 (*this is for NTH only*)
496 val srls = Rule.Rls {id="srls_normalise_4x4",
498 rew_ord = ("termlessI",termlessI),
499 erls = Rule.append_rls "erls_in_srls_IntegrierenUnd.." Rule.e_rls
500 [(*for asm in NTH_CONS ...*)
501 Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
502 (*2nd NTH_CONS pushes n+-1 into asms*)
503 Rule.Calc("Groups.plus_class.plus", eval_binop "#add_")
505 srls = Rule.Erls, calc = [], errpatts = [],
506 rules = [Rule.Thm ("NTH_CONS",TermC.num_str @{thm NTH_CONS}),
507 Rule.Calc("Groups.plus_class.plus", eval_binop "#add_"),
508 Rule.Thm ("NTH_NIL",TermC.num_str @{thm NTH_NIL})],
509 scr = Rule.EmptyScr};
513 setup \<open>KEStore_Elems.add_mets
514 [Specify.prep_met thy "met_eqsys" [] Celem.e_metID
516 {rew_ord'="tless_true", rls' = Rule.Erls, calc = [], srls = Rule.Erls, prls = Rule.Erls, crls = Rule.Erls,
517 errpats = [], nrls = Rule.Erls},
519 Specify.prep_met thy "met_eqsys_topdown" [] Celem.e_metID
520 (["EqSystem","top_down_substitution"], [],
521 {rew_ord'="tless_true", rls' = Rule.Erls, calc = [], srls = Rule.Erls, prls = Rule.Erls, crls = Rule.Erls,
522 errpats = [], nrls = Rule.Erls},
526 partial_function (tailrec) solve_system :: "bool list => real list => bool list"
528 "solve_system e_s v_s =
529 (let e_1 = Take (hd e_s);
530 e_1 = ((Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s),(''bdv_2'', hd (tl v_s))]
531 ''isolate_bdvs'' False)) @@
532 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s),(''bdv_2'', hd (tl v_s))]
533 ''simplify_System'' False))) e_1;
534 e_2 = Take (hd (tl e_s));
535 e_2 = ((Substitute [e_1]) @@
536 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s),(''bdv_2'', hd (tl v_s))]
537 ''simplify_System_parenthesized'' False)) @@
538 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s),(''bdv_2'', hd (tl v_s))]
539 ''isolate_bdvs'' False)) @@
540 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s),(''bdv_2'', hd (tl v_s))]
541 ''simplify_System'' False))) e_2;
542 e__s = Take [e_1, e_2]
543 in Try (Rewrite_Set ''order_system'' False) e__s) "
544 setup \<open>KEStore_Elems.add_mets
545 [Specify.prep_met thy "met_eqsys_topdown_2x2" [] Celem.e_metID
546 (["EqSystem", "top_down_substitution", "2x2"],
547 [("#Given", ["equalities e_s", "solveForVars v_s"]),
549 ["(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))",
550 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"]),
551 ("#Find" ,["solution ss'''"])],
552 {rew_ord'="ord_simplify_System", rls' = Rule.Erls, calc = [],
553 srls = Rule.append_rls "srls_top_down_2x2" Rule.e_rls
554 [Rule.Thm ("hd_thm",TermC.num_str @{thm hd_thm}),
555 Rule.Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
556 Rule.Thm ("tl_Nil",TermC.num_str @{thm tl_Nil})],
557 prls = prls_triangular, crls = Rule.Erls, errpats = [], nrls = Rule.Erls},
558 @{thm solve_system.simps})]
560 setup \<open>KEStore_Elems.add_mets
561 [Specify.prep_met thy "met_eqsys_norm" [] Celem.e_metID
562 (["EqSystem", "normalise"], [],
563 {rew_ord'="tless_true", rls' = Rule.Erls, calc = [], srls = Rule.Erls, prls = Rule.Erls, crls = Rule.Erls,
564 errpats = [], nrls = Rule.Erls},
568 partial_function (tailrec) solve_system2 :: "bool list => real list => bool list"
570 "solve_system2 e_s v_s =
571 (let e__s = ((Try (Rewrite_Set ''norm_Rational'' False)) @@
572 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))]
573 ''simplify_System_parenthesized'' False)) @@
574 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))]
575 ''isolate_bdvs'' False)) @@
576 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))]
577 ''simplify_System_parenthesized'' False)) @@
578 (Try (Rewrite_Set ''order_system'' False))) e_s
579 in (SubProblem (''EqSystem'', [''LINEAR'', ''system''], [''no_met''])
580 [BOOL_LIST e__s, REAL_LIST v_s]))"
581 setup \<open>KEStore_Elems.add_mets
582 [Specify.prep_met thy "met_eqsys_norm_2x2" [] Celem.e_metID
583 (["EqSystem","normalise","2x2"],
584 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
585 ("#Find" ,["solution ss'''"])],
586 {rew_ord'="tless_true", rls' = Rule.Erls, calc = [],
587 srls = Rule.append_rls "srls_normalise_2x2" Rule.e_rls
588 [Rule.Thm ("hd_thm",TermC.num_str @{thm hd_thm}),
589 Rule.Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
590 Rule.Thm ("tl_Nil",TermC.num_str @{thm tl_Nil})],
591 prls = Rule.Erls, crls = Rule.Erls, errpats = [], nrls = Rule.Erls},
592 @{thm solve_system2.simps})]
595 partial_function (tailrec) solve_system3 :: "bool list => real list => bool list"
597 "solve_system3 e_s v_s =
599 ((Try (Rewrite_Set ''norm_Rational'' False)) @@
600 (Repeat (Rewrite ''commute_0_equality'' False)) @@
601 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s),(''bdv_2'', NTH 2 v_s ),
602 (''bdv_3'', NTH 3 v_s),(''bdv_3'', NTH 4 v_s )]
603 ''simplify_System_parenthesized'' False)) @@
604 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s),(''bdv_2'', NTH 2 v_s ),
605 (''bdv_3'', NTH 3 v_s),(''bdv_3'', NTH 4 v_s )]
606 ''isolate_bdvs_4x4'' False)) @@
607 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s),(''bdv_2'', NTH 2 v_s ),
608 (''bdv_3'', NTH 3 v_s),(''bdv_3'', NTH 4 v_s )]
609 ''simplify_System_parenthesized'' False)) @@
610 (Try (Rewrite_Set ''order_system'' False))) e_s
611 in (SubProblem (''EqSystem'', [''LINEAR'', ''system''], [''no_met''])
612 [BOOL_LIST e__s, REAL_LIST v_s]))"
613 setup \<open>KEStore_Elems.add_mets
614 [Specify.prep_met thy "met_eqsys_norm_4x4" [] Celem.e_metID
615 (["EqSystem","normalise","4x4"],
616 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
617 ("#Find" ,["solution ss'''"])],
618 {rew_ord'="tless_true", rls' = Rule.Erls, calc = [],
619 srls = Rule.append_rls "srls_normalise_4x4" srls
620 [Rule.Thm ("hd_thm",TermC.num_str @{thm hd_thm}),
621 Rule.Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
622 Rule.Thm ("tl_Nil",TermC.num_str @{thm tl_Nil})],
623 prls = Rule.Erls, crls = Rule.Erls, errpats = [], nrls = Rule.Erls},
624 (*STOPPED.WN06? met ["EqSystem","normalise","4x4"] @@@@@@@@@@@@@@@@@@@@@@@@@@@*)
625 @{thm solve_system3.simps})]
628 partial_function (tailrec) solve_system4 :: "bool list => real list => bool list"
630 "solve_system4 e_s v_s =
631 (let e_1 = NTH 1 e_s;
632 e_2 = Take (NTH 2 e_s);
633 e_2 = ((Substitute [e_1]) @@
634 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s),(''bdv_2'',NTH 2 v_s),
635 (''bdv_3'',NTH 3 v_s),(''bdv_4'',NTH 4 v_s)]
636 ''simplify_System_parenthesized'' False)) @@
637 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s),(''bdv_2'',NTH 2 v_s),
638 (''bdv_3'',NTH 3 v_s),(''bdv_4'',NTH 4 v_s)]
639 ''isolate_bdvs'' False)) @@
640 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s),(''bdv_2'',NTH 2 v_s),
641 (''bdv_3'',NTH 3 v_s),(''bdv_4'',NTH 4 v_s)]
642 ''norm_Rational'' False))) e_2
643 in [e_1, e_2, NTH 3 e_s, NTH 4 e_s])"
644 setup \<open>KEStore_Elems.add_mets
645 [Specify.prep_met thy "met_eqsys_topdown_4x4" [] Celem.e_metID
646 (["EqSystem","top_down_substitution","4x4"],
647 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
648 ("#Where" , (*accepts missing variables up to diagonal form*)
649 ["(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))",
650 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))",
651 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))",
652 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"]),
653 ("#Find", ["solution ss'''"])],
654 {rew_ord'="ord_simplify_System", rls' = Rule.Erls, calc = [],
655 srls = Rule.append_rls "srls_top_down_4x4" srls [],
656 prls = Rule.append_rls "prls_tri_4x4_lin_sys" prls_triangular
657 [Rule.Calc ("Atools.occurs'_in",eval_occurs_in "")],
658 crls = Rule.Erls, errpats = [], nrls = Rule.Erls},
659 (*FIXXXXME.WN060916: this script works ONLY for exp 7.79 @@@@@@@@@@@@@@@@@@@@*)
660 @{thm solve_system4.simps})]