Isar command 'calculation' as front-end for KEStore_Elems.add_calcs, without change of semantics;
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 !?!*)
52 (** eval functions **)
54 (*certain variables of a given list occur _all_ in a term
55 args: all: ..variables, which are under consideration (eg. the bound vars)
56 vs: variables which must be in t,
57 and none of the others in all must be in t
58 t: the term under consideration
60 fun occur_exactly_in vs all t =
61 let fun occurs_in' a b = Prog_Expr.occurs_in b a
62 in foldl and_ (true, map (occurs_in' t) vs)
63 andalso not (foldl or_ (false, map (occurs_in' t)
64 (subtract op = vs all)))
67 (*("occur_exactly_in", ("EqSystem.occur_exactly_in",
68 eval_occur_exactly_in "#eval_occur_exactly_in_"))*)
69 fun eval_occur_exactly_in _ "EqSystem.occur_exactly_in"
70 (p as (Const ("EqSystem.occur_exactly_in",_)
72 if occur_exactly_in (TermC.isalist2list vs) (TermC.isalist2list all) t
73 then SOME ((UnparseC.term p) ^ " = True",
74 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
75 else SOME ((UnparseC.term p) ^ " = False",
76 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
77 | eval_occur_exactly_in _ _ _ _ = NONE;
79 calculation occur_exactly_in = \<open>eval_occur_exactly_in "#eval_occur_exactly_in_"\<close>
82 (** rewrite order 'ord_simplify_System' **)
84 (* order wrt. several linear (i.e. without exponents) variables "c", "c_2",..
85 which leaves the monomials containing c, c_2,... at the end of an Integral
86 and puts the c, c_2,... rightmost within a monomial.
88 WN050906 this is a quick and dirty adaption of ord_make_polynomial_in,
89 which was most adequate, because it uses size_of_term*)
91 local (*. for simplify_System .*)
93 open Term; (* for type order = EQUAL | LESS | GREATER *)
95 fun pr_ord EQUAL = "EQUAL"
96 | pr_ord LESS = "LESS"
97 | pr_ord GREATER = "GREATER";
99 fun dest_hd' (Const (a, T)) = (((a, 0), T), 0)
100 | dest_hd' (Free (ccc, T)) =
101 (case Symbol.explode ccc of
102 "c"::[] => ((("|||||||||||||||||||||", 0), T), 1)(*greatest string WN*)
103 | "c"::"_"::_ => ((("|||||||||||||||||||||", 0), T), 1)
104 | _ => (((ccc, 0), T), 1))
105 | dest_hd' (Var v) = (v, 2)
106 | dest_hd' (Bound i) = ((("", i), dummyT), 3)
107 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4)
108 | dest_hd' _ = raise ERROR "dest_hd': uncovered case in fun.def.";
110 fun size_of_term' (Free (ccc, _)) =
111 (case Symbol.explode ccc of (*WN0510 hack for the bound variables*)
113 | "c"::"_"::is => 1000 * ((TermC.int_of_str o implode) is)
115 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
116 | size_of_term' (f$t) = size_of_term' f + size_of_term' t
117 | size_of_term' _ = 1;
119 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *)
120 (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
121 | term_ord' pr thy (t, u) =
125 val (f, ts) = strip_comb t and (g, us) = strip_comb u;
126 val _ = tracing ("t= f@ts= \"" ^ UnparseC.term_in_thy thy f ^ "\" @ \"[" ^
127 commas (map (UnparseC.term_in_thy thy) ts) ^ "]\"");
128 val _ = tracing ("u= g@us= \"" ^ UnparseC.term_in_thy thy g ^ "\" @ \"[" ^
129 commas (map (UnparseC.term_in_thy thy) us) ^ "]\"");
130 val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' t) ^ ", " ^
131 string_of_int (size_of_term' u) ^ ")");
132 val _ = tracing ("hd_ord(f,g) = " ^ ((pr_ord o hd_ord) (f,g)));
133 val _ = tracing ("terms_ord (ts,us) = " ^(pr_ord o terms_ord str false) (ts,us));
134 val _=tracing("-------");
137 case int_ord (size_of_term' t, size_of_term' u) of
139 let val (f, ts) = strip_comb t and (g, us) = strip_comb u
140 in (case hd_ord (f, g) of
141 EQUAL => (terms_ord str pr) (ts, us)
145 and hd_ord (f, g) = (* ~ term.ML *)
146 prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
147 and terms_ord _ pr (ts, us) = list_ord (term_ord' pr (ThyC.get_theory "Isac_Knowledge"))(ts, us);
151 (*WN0510 for preliminary use in eval_order_system, see case-study mat-eng.tex
152 fun ord_simplify_System_rev (pr:bool) thy subst tu =
153 (term_ord' pr thy (Library.swap tu) = LESS);*)
156 fun ord_simplify_System (pr:bool) thy _(*subst*) tu =
157 (term_ord' pr thy tu = LESS);
161 Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord',
162 [("ord_simplify_System", ord_simplify_System false \<^theory>)
168 (*.adapted from 'order_add_mult_in' by just replacing the rew_ord.*)
169 val order_add_mult_System =
170 Rule_Def.Repeat{id = "order_add_mult_System", preconds = [],
171 rew_ord = ("ord_simplify_System",
172 ord_simplify_System false @{theory "Integrate"}),
173 erls = Rule_Set.empty,srls = Rule_Set.Empty, calc = [], errpatts = [],
174 rules = [\<^rule_thm>\<open>mult.commute\<close>,
176 \<^rule_thm>\<open>real_mult_left_commute\<close>,
177 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
178 \<^rule_thm>\<open>mult.assoc\<close>,
179 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
180 \<^rule_thm>\<open>add.commute\<close>,
182 \<^rule_thm>\<open>add.left_commute\<close>,
183 (*x + (y + z) = y + (x + z)*)
184 \<^rule_thm>\<open>add.assoc\<close>
185 (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
187 scr = Rule.Empty_Prog};
190 (*.adapted from 'norm_Rational' by
191 #1 using 'ord_simplify_System' in 'order_add_mult_System'
192 #2 NOT using common_nominator_p .*)
193 val norm_System_noadd_fractions =
194 Rule_Def.Repeat {id = "norm_System_noadd_fractions", preconds = [],
195 rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
196 erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
197 rules = [(*sequence given by operator precedence*)
198 Rule.Rls_ discard_minus,
200 Rule.Rls_ rat_mult_divide,
202 Rule.Rls_ reduce_0_1_2,
203 Rule.Rls_ (*order_add_mult #1*) order_add_mult_System,
204 Rule.Rls_ collect_numerals,
205 (*Rule.Rls_ add_fractions_p, #2*)
208 scr = Rule.Empty_Prog
212 (*.adapted from 'norm_Rational' by
213 *1* using 'ord_simplify_System' in 'order_add_mult_System'.*)
215 Rule_Def.Repeat {id = "norm_System", preconds = [],
216 rew_ord = ("dummy_ord",Rewrite_Ord.dummy_ord),
217 erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
218 rules = [(*sequence given by operator precedence*)
219 Rule.Rls_ discard_minus,
221 Rule.Rls_ rat_mult_divide,
223 Rule.Rls_ reduce_0_1_2,
224 Rule.Rls_ (*order_add_mult *1*) order_add_mult_System,
225 Rule.Rls_ collect_numerals,
226 Rule.Rls_ add_fractions_p,
229 scr = Rule.Empty_Prog
233 (*.simplify an equational system BEFORE solving it such that parentheses are
234 ( ((u0*v0)*w0) + ( ((u1*v1)*w1) * c + ... +((u4*v4)*w4) * c_4 ) )
235 ATTENTION: works ONLY for bound variables c, c_1, c_2, c_3, c_4 :ATTENTION
236 This is a copy from 'make_ratpoly_in' with respective reductions:
237 *0* expand the term, ie. distribute * and / over +
238 *1* ord_simplify_System instead of termlessI
239 *2* no add_fractions_p (= common_nominator_p_rls !)
240 *3* discard_parentheses only for (.*(.*.))
241 analoguous to simplify_Integral .*)
242 val simplify_System_parenthesized =
243 Rule_Set.Sequence {id = "simplify_System_parenthesized", preconds = []:term list,
244 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
245 erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
246 rules = [\<^rule_thm>\<open>distrib_right\<close>,
247 (*"(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w"*)
248 \<^rule_thm>\<open>add_divide_distrib\<close>,
249 (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)
250 (*^^^^^ *0* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
251 Rule.Rls_ norm_Rational_noadd_fractions(**2**),
252 Rule.Rls_ (*order_add_mult_in*) norm_System_noadd_fractions (**1**),
253 \<^rule_thm_sym>\<open>mult.assoc\<close>
254 (*Rule.Rls_ discard_parentheses *3**),
255 Rule.Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
256 Rule.Rls_ separate_bdv2,
257 \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e")
259 scr = Rule.Empty_Prog};
262 (*.simplify an equational system AFTER solving it;
263 This is a copy of 'make_ratpoly_in' with the differences
264 *1* ord_simplify_System instead of termlessI .*)
265 (*TODO.WN051031 ^^^^^^^^^^ should be in EACH rls contained *)
266 val simplify_System =
267 Rule_Set.Sequence {id = "simplify_System", preconds = []:term list,
268 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
269 erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
270 rules = [Rule.Rls_ norm_Rational,
271 Rule.Rls_ (*order_add_mult_in*) norm_System (**1**),
272 Rule.Rls_ discard_parentheses,
273 Rule.Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
274 Rule.Rls_ separate_bdv2,
275 \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e")
277 scr = Rule.Empty_Prog};
279 val simplify_System =
280 Rule_Set.append_rules "simplify_System" simplify_System_parenthesized
281 [\<^rule_thm_sym>\<open>add.assoc\<close>];
286 Rule_Def.Repeat {id="isolate_bdvs", preconds = [],
287 rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
288 erls = Rule_Set.append_rules "erls_isolate_bdvs" Rule_Set.empty
289 [(\<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_"))],
290 srls = Rule_Set.Empty, calc = [], errpatts = [],
292 [\<^rule_thm>\<open>commute_0_equality\<close>,
293 \<^rule_thm>\<open>separate_bdvs_add\<close>,
294 \<^rule_thm>\<open>separate_bdvs_mult\<close>],
295 scr = Rule.Empty_Prog};
298 val isolate_bdvs_4x4 =
299 Rule_Def.Repeat {id="isolate_bdvs_4x4", preconds = [],
300 rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
301 erls = Rule_Set.append_rules
302 "erls_isolate_bdvs_4x4" Rule_Set.empty
303 [\<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_"),
304 \<^rule_eval>\<open>Prog_Expr.ident\<close> (Prog_Expr.eval_ident "#ident_"),
305 \<^rule_eval>\<open>Prog_Expr.some_occur_in\<close> (Prog_Expr.eval_some_occur_in "#some_occur_in_"),
306 \<^rule_thm>\<open>not_true\<close>,
307 \<^rule_thm>\<open>not_false\<close>
309 srls = Rule_Set.Empty, calc = [], errpatts = [],
310 rules = [\<^rule_thm>\<open>commute_0_equality\<close>,
311 \<^rule_thm>\<open>separate_bdvs0\<close>,
312 \<^rule_thm>\<open>separate_bdvs_add1\<close>,
313 \<^rule_thm>\<open>separate_bdvs_add2\<close>,
314 \<^rule_thm>\<open>separate_bdvs_mult\<close>
315 ], scr = Rule.Empty_Prog};
320 (*.order the equations in a system such, that a triangular system (if any)
321 appears as [..c_4 = .., ..., ..., ..c_1 + ..c_2 + ..c_3 ..c_4 = ..].*)
323 Rule_Def.Repeat {id="order_system", preconds = [],
324 rew_ord = ("ord_simplify_System",
325 ord_simplify_System false \<^theory>),
326 erls = Rule_Set.Empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
327 rules = [\<^rule_thm>\<open>order_system_NxN\<close>
329 scr = Rule.Empty_Prog};
331 val prls_triangular =
332 Rule_Def.Repeat {id="prls_triangular", preconds = [],
333 rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
334 erls = Rule_Def.Repeat {id="erls_prls_triangular", preconds = [],
335 rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
336 erls = Rule_Set.Empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
337 rules = [(*for precond NTH_CONS ...*)
338 \<^rule_eval>\<open>less\<close> (Prog_Expr.eval_equ "#less_"),
339 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_")
340 (*immediately repeated rewrite pushes
341 '+' into precondition !*)
343 scr = Rule.Empty_Prog},
344 srls = Rule_Set.Empty, calc = [], errpatts = [],
345 rules = [\<^rule_thm>\<open>NTH_CONS\<close>,
346 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
347 \<^rule_thm>\<open>NTH_NIL\<close>,
348 \<^rule_thm>\<open>tl_Cons\<close>,
349 \<^rule_thm>\<open>tl_Nil\<close>,
350 \<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_")
352 scr = Rule.Empty_Prog};
356 (*WN060914 quickly created for 4x4;
357 more similarity to prls_triangular desirable*)
358 val prls_triangular4 =
359 Rule_Def.Repeat {id="prls_triangular4", preconds = [],
360 rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
361 erls = Rule_Def.Repeat {id="erls_prls_triangular4", preconds = [],
362 rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
363 erls = Rule_Set.Empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
364 rules = [(*for precond NTH_CONS ...*)
365 \<^rule_eval>\<open>less\<close> (Prog_Expr.eval_equ "#less_"),
366 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_")
367 (*immediately repeated rewrite pushes
368 '+' into precondition !*)
370 scr = Rule.Empty_Prog},
371 srls = Rule_Set.Empty, calc = [], errpatts = [],
372 rules = [\<^rule_thm>\<open>NTH_CONS\<close>,
373 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
374 \<^rule_thm>\<open>NTH_NIL\<close>,
375 \<^rule_thm>\<open>tl_Cons\<close>,
376 \<^rule_thm>\<open>tl_Nil\<close>,
377 \<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_")
379 scr = Rule.Empty_Prog};
383 simplify_System_parenthesized = \<open>prep_rls' simplify_System_parenthesized\<close> and
384 simplify_System = \<open>prep_rls' simplify_System\<close> and
385 isolate_bdvs = \<open>prep_rls' isolate_bdvs\<close> and
386 isolate_bdvs_4x4 = \<open>prep_rls' isolate_bdvs_4x4\<close> and
387 order_system = \<open>prep_rls' order_system\<close> and
388 order_add_mult_System = \<open>prep_rls' order_add_mult_System\<close> and
389 norm_System_noadd_fractions = \<open>prep_rls' norm_System_noadd_fractions\<close> and
390 norm_System = \<open>prep_rls' norm_System\<close>
393 section \<open>Problems\<close>
395 problem pbl_equsys : "system" =
396 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
397 CAS: "solveSystem e_s v_s"
398 Given: "equalities e_s" "solveForVars v_s"
399 Find: "solution ss'''" (*''' is copy-named*)
401 problem pbl_equsys_lin : "LINEAR/system" =
402 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
403 CAS: "solveSystem e_s v_s"
404 Given: "equalities e_s" "solveForVars v_s"
405 (*TODO.WN050929 check linearity*)
406 Find: "solution ss'''"
408 problem pbl_equsys_lin_2x2: "2x2/LINEAR/system" =
409 \<open>Rule_Set.append_rules "prls_2x2_linear_system" Rule_Set.empty
410 [\<^rule_thm>\<open>LENGTH_CONS\<close>,
411 \<^rule_thm>\<open>LENGTH_NIL\<close>,
412 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
413 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_")]\<close>
414 CAS: "solveSystem e_s v_s"
415 Given: "equalities e_s" "solveForVars v_s"
416 Where: "Length (e_s:: bool list) = 2" "Length v_s = 2"
417 Find: "solution ss'''"
419 problem pbl_equsys_lin_2x2_tri : "triangular/2x2/LINEAR/system" =
420 \<open>prls_triangular\<close>
421 Method: "EqSystem/top_down_substitution/2x2"
422 CAS: "solveSystem e_s v_s"
423 Given: "equalities e_s" "solveForVars v_s"
425 "(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))"
426 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"
427 Find: "solution ss'''"
429 problem pbl_equsys_lin_2x2_norm : "normalise/2x2/LINEAR/system" =
430 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
431 Method: "EqSystem/normalise/2x2"
432 CAS: "solveSystem e_s v_s"
433 Given: "equalities e_s" "solveForVars v_s"
434 Find: "solution ss'''"
436 problem pbl_equsys_lin_3x3 : "3x3/LINEAR/system" =
437 \<open>Rule_Set.append_rules "prls_3x3_linear_system" Rule_Set.empty
438 [\<^rule_thm>\<open>LENGTH_CONS\<close>,
439 \<^rule_thm>\<open>LENGTH_NIL\<close>,
440 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
441 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_")]\<close>
442 CAS: "solveSystem e_s v_s"
443 Given: "equalities e_s" "solveForVars v_s"
444 Where: "Length (e_s:: bool list) = 3" "Length v_s = 3"
445 Find: "solution ss'''"
447 problem pbl_equsys_lin_4x4 : "4x4/LINEAR/system" =
448 \<open>Rule_Set.append_rules "prls_4x4_linear_system" Rule_Set.empty
449 [\<^rule_thm>\<open>LENGTH_CONS\<close>,
450 \<^rule_thm>\<open>LENGTH_NIL\<close>,
451 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
452 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_")]\<close>
453 CAS: "solveSystem e_s v_s"
454 Given: "equalities e_s" "solveForVars v_s"
455 Where: "Length (e_s:: bool list) = 4" "Length v_s = 4"
456 Find: "solution ss'''"
458 problem pbl_equsys_lin_4x4_tri : "triangular/4x4/LINEAR/system" =
459 \<open>Rule_Set.append_rules "prls_tri_4x4_lin_sys" prls_triangular
460 [\<^rule_eval>\<open>Prog_Expr.occurs_in\<close> (Prog_Expr.eval_occurs_in "")]\<close>
461 Method: "EqSystem/top_down_substitution/4x4"
462 CAS: "solveSystem e_s v_s"
463 Given: "equalities e_s" "solveForVars v_s"
464 Where: (*accepts missing variables up to diagional form*)
465 "(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))"
466 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))"
467 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))"
468 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"
469 Find: "solution ss'''"
471 problem pbl_equsys_lin_4x4_norm : "normalise/4x4/LINEAR/system" =
472 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
473 Method: "EqSystem/normalise/4x4"
474 CAS: "solveSystem e_s v_s"
475 Given: "equalities e_s" "solveForVars v_s"
476 (*Length is checked 1 level above*)
477 Find: "solution ss'''"
480 (*this is for NTH only*)
481 val srls = Rule_Def.Repeat {id="srls_normalise_4x4",
483 rew_ord = ("termlessI",termlessI),
484 erls = Rule_Set.append_rules "erls_in_srls_IntegrierenUnd.." Rule_Set.empty
485 [(*for asm in NTH_CONS ...*)
486 \<^rule_eval>\<open>less\<close> (Prog_Expr.eval_equ "#less_"),
487 (*2nd NTH_CONS pushes n+-1 into asms*)
488 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_")
490 srls = Rule_Set.Empty, calc = [], errpatts = [],
491 rules = [\<^rule_thm>\<open>NTH_CONS\<close>,
492 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
493 \<^rule_thm>\<open>NTH_NIL\<close>],
494 scr = Rule.Empty_Prog};
497 section \<open>Methods\<close>
499 method met_eqsys : "EqSystem" =
500 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [], srls = Rule_Set.Empty, prls = Rule_Set.Empty, crls = Rule_Set.Empty,
501 errpats = [], nrls = Rule_Set.Empty}\<close>
503 method met_eqsys_topdown : "EqSystem/top_down_substitution" =
504 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [], srls = Rule_Set.Empty, prls = Rule_Set.Empty, crls = Rule_Set.Empty,
505 errpats = [], nrls = Rule_Set.Empty}\<close>
507 partial_function (tailrec) solve_system :: "bool list => real list => bool list"
509 "solve_system e_s v_s = (
513 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''isolate_bdvs'')) #>
514 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System''))
516 e_2 = Take (hd (tl e_s));
518 (Substitute [e_1]) #>
519 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System_parenthesized'' )) #>
520 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''isolate_bdvs'' )) #>
521 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System'' ))
523 e__s = Take [e_1, e_2]
525 Try (Rewrite_Set ''order_system'' ) e__s) "
527 method met_eqsys_topdown_2x2 : "EqSystem/top_down_substitution/2x2" =
528 \<open>{rew_ord'="ord_simplify_System", rls' = Rule_Set.Empty, calc = [],
529 srls = Rule_Set.append_rules "srls_top_down_2x2" Rule_Set.empty
530 [\<^rule_thm>\<open>hd_thm\<close>,
531 \<^rule_thm>\<open>tl_Cons\<close>,
532 \<^rule_thm>\<open>tl_Nil\<close>],
533 prls = prls_triangular, crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
534 Program: solve_system.simps
535 Given: "equalities e_s" "solveForVars v_s"
537 "(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))"
538 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"
539 Find: "solution ss'''"
541 method met_eqsys_norm : "EqSystem/normalise" =
542 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [], srls = Rule_Set.Empty, prls = Rule_Set.Empty, crls = Rule_Set.Empty,
543 errpats = [], nrls = Rule_Set.Empty}\<close>
545 partial_function (tailrec) solve_system2 :: "bool list => real list => bool list"
547 "solve_system2 e_s v_s = (
550 (Try (Rewrite_Set ''norm_Rational'' )) #>
551 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System_parenthesized'' )) #>
552 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''isolate_bdvs'' )) #>
553 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System_parenthesized'' )) #>
554 (Try (Rewrite_Set ''order_system'' ))
557 SubProblem (''EqSystem'', [''LINEAR'', ''system''], [''no_met''])
558 [BOOL_LIST e__s, REAL_LIST v_s])"
560 method met_eqsys_norm_2x2 : "EqSystem/normalise/2x2" =
561 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [],
562 srls = Rule_Set.append_rules "srls_normalise_2x2" Rule_Set.empty
563 [\<^rule_thm>\<open>hd_thm\<close>,
564 \<^rule_thm>\<open>tl_Cons\<close>,
565 \<^rule_thm>\<open>tl_Nil\<close>],
566 prls = Rule_Set.Empty, crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
567 Program: solve_system2.simps
568 Given: "equalities e_s" "solveForVars v_s"
569 Find: "solution ss'''"
571 partial_function (tailrec) solve_system3 :: "bool list => real list => bool list"
573 "solve_system3 e_s v_s = (
576 (Try (Rewrite_Set ''norm_Rational'' )) #>
577 (Repeat (Rewrite ''commute_0_equality'' )) #>
578 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s), (''bdv_2'', NTH 2 v_s ),
579 (''bdv_3'', NTH 3 v_s), (''bdv_3'', NTH 4 v_s )] ''simplify_System_parenthesized'' )) #>
580 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s), (''bdv_2'', NTH 2 v_s ),
581 (''bdv_3'', NTH 3 v_s), (''bdv_3'', NTH 4 v_s )] ''isolate_bdvs_4x4'' )) #>
582 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s), (''bdv_2'', NTH 2 v_s ),
583 (''bdv_3'', NTH 3 v_s), (''bdv_3'', NTH 4 v_s )] ''simplify_System_parenthesized'' )) #>
584 (Try (Rewrite_Set ''order_system''))
587 SubProblem (''EqSystem'', [''LINEAR'', ''system''], [''no_met''])
588 [BOOL_LIST e__s, REAL_LIST v_s])"
590 method met_eqsys_norm_4x4 : "EqSystem/normalise/4x4" =
591 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [],
593 Rule_Set.append_rules "srls_normalise_4x4" srls
594 [\<^rule_thm>\<open>hd_thm\<close>, \<^rule_thm>\<open>tl_Cons\<close>, \<^rule_thm>\<open>tl_Nil\<close>],
595 prls = Rule_Set.Empty, crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
596 Program: solve_system3.simps
597 Given: "equalities e_s" "solveForVars v_s"
598 Find: "solution ss'''"
599 (*STOPPED.WN06? met ["EqSystem", "normalise", "4x4"] #>#>#>#>#>#>#>#>#>#>#>#>#>@*)
601 partial_function (tailrec) solve_system4 :: "bool list => real list => bool list"
603 "solve_system4 e_s v_s = (
606 e_2 = Take (NTH 2 e_s);
608 (Substitute [e_1]) #>
609 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s), (''bdv_2'',NTH 2 v_s),
610 (''bdv_3'',NTH 3 v_s), (''bdv_4'',NTH 4 v_s)] ''simplify_System_parenthesized'' )) #>
611 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s), (''bdv_2'',NTH 2 v_s),
612 (''bdv_3'',NTH 3 v_s), (''bdv_4'',NTH 4 v_s)] ''isolate_bdvs'' )) #>
613 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s), (''bdv_2'',NTH 2 v_s),
614 (''bdv_3'',NTH 3 v_s), (''bdv_4'',NTH 4 v_s)] ''norm_Rational'' ))
617 [e_1, e_2, NTH 3 e_s, NTH 4 e_s])"
619 method met_eqsys_topdown_4x4 : "EqSystem/top_down_substitution/4x4" =
620 \<open>{rew_ord'="ord_simplify_System", rls' = Rule_Set.Empty, calc = [],
621 srls = Rule_Set.append_rules "srls_top_down_4x4" srls [],
622 prls = Rule_Set.append_rules "prls_tri_4x4_lin_sys" prls_triangular
623 [\<^rule_eval>\<open>Prog_Expr.occurs_in\<close> (Prog_Expr.eval_occurs_in "")],
624 crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
625 (*FIXXXXME.WN060916: this script works ONLY for exp 7.79 #>#>#>#>#>#>#>#>#>#>*)
626 Program: solve_system4.simps
627 Given: "equalities e_s" "solveForVars v_s"
628 Where: (*accepts missing variables up to diagonal form*)
629 "(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))"
630 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))"
631 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))"
632 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"
633 Find: "solution ss'''"