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 (\<^const_name>\<open>EqSystem.occur_exactly_in\<close>,_)
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*) (ts, us) =
157 (term_ord' pr thy (TermC.numerals_to_Free ts, TermC.numerals_to_Free us) = 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 =
171 id = "order_add_mult_System", preconds = [],
172 rew_ord = ("ord_simplify_System", ord_simplify_System false @{theory "Integrate"}),
173 erls = Rule_Set.empty,srls = Rule_Set.Empty, calc = [], errpatts = [],
175 \<^rule_thm>\<open>mult.commute\<close>, (* z * w = w * z *)
176 \<^rule_thm>\<open>real_mult_left_commute\<close>, (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
177 \<^rule_thm>\<open>mult.assoc\<close>, (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
178 \<^rule_thm>\<open>add.commute\<close>, (*z + w = w + z*)
179 \<^rule_thm>\<open>add.left_commute\<close>, (*x + (y + z) = y + (x + z)*)
180 \<^rule_thm>\<open>add.assoc\<close> ], (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
181 scr = Rule.Empty_Prog};
184 (*.adapted from 'norm_Rational' by
185 #1 using 'ord_simplify_System' in 'order_add_mult_System'
186 #2 NOT using common_nominator_p .*)
187 val norm_System_noadd_fractions =
188 Rule_Def.Repeat {id = "norm_System_noadd_fractions", preconds = [],
189 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
190 erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
191 rules = [(*sequence given by operator precedence*)
192 Rule.Rls_ discard_minus,
194 Rule.Rls_ rat_mult_divide,
196 Rule.Rls_ reduce_0_1_2,
197 Rule.Rls_ (*order_add_mult #1*) order_add_mult_System,
198 Rule.Rls_ collect_numerals,
199 (*Rule.Rls_ add_fractions_p, #2*)
201 scr = Rule.Empty_Prog};
204 (*.adapted from 'norm_Rational' by
205 *1* using 'ord_simplify_System' in 'order_add_mult_System'.*)
207 Rule_Def.Repeat {id = "norm_System", preconds = [],
208 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
209 erls = norm_rat_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
210 rules = [(*sequence given by operator precedence*)
211 Rule.Rls_ discard_minus,
213 Rule.Rls_ rat_mult_divide,
215 Rule.Rls_ reduce_0_1_2,
216 Rule.Rls_ (*order_add_mult *1*) order_add_mult_System,
217 Rule.Rls_ collect_numerals,
218 Rule.Rls_ add_fractions_p,
220 scr = Rule.Empty_Prog};
223 (*.simplify an equational system BEFORE solving it such that parentheses are
224 ( ((u0*v0)*w0) + ( ((u1*v1)*w1) * c + ... +((u4*v4)*w4) * c_4 ) )
225 ATTENTION: works ONLY for bound variables c, c_1, c_2, c_3, c_4 :ATTENTION
226 This is a copy from 'make_ratpoly_in' with respective reductions:
227 *0* expand the term, ie. distribute * and / over +
228 *1* ord_simplify_System instead of termlessI
229 *2* no add_fractions_p (= common_nominator_p_rls !)
230 *3* discard_parentheses only for (.*(.*.))
231 analoguous to simplify_Integral .*)
232 val simplify_System_parenthesized =
233 Rule_Set.Sequence {id = "simplify_System_parenthesized", preconds = []:term list,
234 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
235 erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
237 \<^rule_thm>\<open>distrib_right\<close>, (*"(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w"*)
238 \<^rule_thm>\<open>add_divide_distrib\<close>, (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)
239 Rule.Rls_ norm_Rational_noadd_fractions,
240 Rule.Rls_ (*order_add_mult_in*) norm_System_noadd_fractions,
241 \<^rule_thm_sym>\<open>mult.assoc\<close>,
242 Rule.Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
243 Rule.Rls_ separate_bdv2,
244 \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e")],
245 scr = Rule.Empty_Prog};
248 (*.simplify an equational system AFTER solving it;
249 This is a copy of 'make_ratpoly_in' with the differences
250 *1* ord_simplify_System instead of termlessI .*)
251 (*TODO.WN051031 ^^^^^^^^^^ should be in EACH rls contained *)
252 val simplify_System =
253 Rule_Set.Sequence {id = "simplify_System", preconds = []:term list,
254 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
255 erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
257 Rule.Rls_ norm_Rational,
258 Rule.Rls_ (*order_add_mult_in*) norm_System (**1**),
259 Rule.Rls_ discard_parentheses,
260 Rule.Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
261 Rule.Rls_ separate_bdv2,
262 \<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e")],
263 scr = Rule.Empty_Prog};
265 val simplify_System =
266 Rule_Set.append_rules "simplify_System" simplify_System_parenthesized
267 [\<^rule_thm_sym>\<open>add.assoc\<close>];
273 id="isolate_bdvs", preconds = [], rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
274 erls = Rule_Set.append_rules "erls_isolate_bdvs" Rule_Set.empty [
275 (\<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_"))],
276 srls = Rule_Set.Empty, calc = [], errpatts = [],
278 \<^rule_thm>\<open>commute_0_equality\<close>,
279 \<^rule_thm>\<open>separate_bdvs_add\<close>,
280 \<^rule_thm>\<open>separate_bdvs_mult\<close>],
281 scr = Rule.Empty_Prog};
284 val isolate_bdvs_4x4 =
285 Rule_Def.Repeat {id="isolate_bdvs_4x4", preconds = [],
286 rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
287 erls = Rule_Set.append_rules "erls_isolate_bdvs_4x4" Rule_Set.empty [
288 \<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_"),
289 \<^rule_eval>\<open>Prog_Expr.ident\<close> (Prog_Expr.eval_ident "#ident_"),
290 \<^rule_eval>\<open>Prog_Expr.some_occur_in\<close> (Prog_Expr.eval_some_occur_in "#some_occur_in_"),
291 \<^rule_thm>\<open>not_true\<close>,
292 \<^rule_thm>\<open>not_false\<close>],
293 srls = Rule_Set.Empty, calc = [], errpatts = [],
295 \<^rule_thm>\<open>commute_0_equality\<close>,
296 \<^rule_thm>\<open>separate_bdvs0\<close>,
297 \<^rule_thm>\<open>separate_bdvs_add1\<close>,
298 \<^rule_thm>\<open>separate_bdvs_add2\<close>,
299 \<^rule_thm>\<open>separate_bdvs_mult\<close>],
300 scr = Rule.Empty_Prog};
305 (*.order the equations in a system such, that a triangular system (if any)
306 appears as [..c_4 = .., ..., ..., ..c_1 + ..c_2 + ..c_3 ..c_4 = ..].*)
308 Rule_Def.Repeat {id="order_system", preconds = [],
309 rew_ord = ("ord_simplify_System", ord_simplify_System false \<^theory>),
310 erls = Rule_Set.Empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
312 \<^rule_thm>\<open>order_system_NxN\<close>],
313 scr = Rule.Empty_Prog};
315 val prls_triangular =
317 id="prls_triangular", preconds = [], rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
318 erls = Rule_Def.Repeat {
319 id="erls_prls_triangular", preconds = [], rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
320 erls = Rule_Set.Empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
321 rules = [(*for precond NTH_CONS ...*)
322 \<^rule_eval>\<open>less\<close> (Prog_Expr.eval_equ "#less_"),
323 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
324 \<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_")],
325 (*immediately repeated rewrite pushes '+' into precondition !*)
326 scr = Rule.Empty_Prog},
327 srls = Rule_Set.Empty, calc = [], errpatts = [],
329 \<^rule_thm>\<open>NTH_CONS\<close>,
330 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
331 \<^rule_thm>\<open>NTH_NIL\<close>,
332 \<^rule_thm>\<open>tl_Cons\<close>,
333 \<^rule_thm>\<open>tl_Nil\<close>,
334 \<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_")],
335 scr = Rule.Empty_Prog};
339 (*WN060914 quickly created for 4x4;
340 more similarity to prls_triangular desirable*)
341 val prls_triangular4 =
343 id="prls_triangular4", preconds = [], rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
344 erls = Rule_Def.Repeat {
345 id="erls_prls_triangular4", preconds = [], rew_ord = ("e_rew_ord", Rewrite_Ord.e_rew_ord),
346 erls = Rule_Set.Empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
347 rules = [(*for precond NTH_CONS ...*)
348 \<^rule_eval>\<open>less\<close> (Prog_Expr.eval_equ "#less_"),
349 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_")],
350 (*immediately repeated rewrite pushes '+' into precondition !*)
351 scr = Rule.Empty_Prog},
352 srls = Rule_Set.Empty, calc = [], errpatts = [],
354 \<^rule_thm>\<open>NTH_CONS\<close>,
355 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
356 \<^rule_thm>\<open>NTH_NIL\<close>,
357 \<^rule_thm>\<open>tl_Cons\<close>,
358 \<^rule_thm>\<open>tl_Nil\<close>,
359 \<^rule_eval>\<open>occur_exactly_in\<close> (eval_occur_exactly_in "#eval_occur_exactly_in_")],
360 scr = Rule.Empty_Prog};
364 simplify_System_parenthesized = \<open>prep_rls' simplify_System_parenthesized\<close> and
365 simplify_System = \<open>prep_rls' simplify_System\<close> and
366 isolate_bdvs = \<open>prep_rls' isolate_bdvs\<close> and
367 isolate_bdvs_4x4 = \<open>prep_rls' isolate_bdvs_4x4\<close> and
368 order_system = \<open>prep_rls' order_system\<close> and
369 order_add_mult_System = \<open>prep_rls' order_add_mult_System\<close> and
370 norm_System_noadd_fractions = \<open>prep_rls' norm_System_noadd_fractions\<close> and
371 norm_System = \<open>prep_rls' norm_System\<close>
374 section \<open>Problems\<close>
376 problem pbl_equsys : "system" =
377 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
378 CAS: "solveSystem e_s v_s"
379 Given: "equalities e_s" "solveForVars v_s"
380 Find: "solution ss'''" (*''' is copy-named*)
382 problem pbl_equsys_lin : "LINEAR/system" =
383 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
384 CAS: "solveSystem e_s v_s"
385 Given: "equalities e_s" "solveForVars v_s"
386 (*TODO.WN050929 check linearity*)
387 Find: "solution ss'''"
389 problem pbl_equsys_lin_2x2: "2x2/LINEAR/system" =
390 \<open>Rule_Set.append_rules "prls_2x2_linear_system" Rule_Set.empty
391 [\<^rule_thm>\<open>LENGTH_CONS\<close>,
392 \<^rule_thm>\<open>LENGTH_NIL\<close>,
393 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
394 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_")]\<close>
395 CAS: "solveSystem e_s v_s"
396 Given: "equalities e_s" "solveForVars v_s"
397 Where: "Length (e_s:: bool list) = 2" "Length v_s = 2"
398 Find: "solution ss'''"
400 problem pbl_equsys_lin_2x2_tri : "triangular/2x2/LINEAR/system" =
401 \<open>prls_triangular\<close>
402 Method: "EqSystem/top_down_substitution/2x2"
403 CAS: "solveSystem e_s v_s"
404 Given: "equalities e_s" "solveForVars v_s"
406 "(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))"
407 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"
408 Find: "solution ss'''"
410 problem pbl_equsys_lin_2x2_norm : "normalise/2x2/LINEAR/system" =
411 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
412 Method: "EqSystem/normalise/2x2"
413 CAS: "solveSystem e_s v_s"
414 Given: "equalities e_s" "solveForVars v_s"
415 Find: "solution ss'''"
417 problem pbl_equsys_lin_3x3 : "3x3/LINEAR/system" =
418 \<open>Rule_Set.append_rules "prls_3x3_linear_system" Rule_Set.empty
419 [\<^rule_thm>\<open>LENGTH_CONS\<close>,
420 \<^rule_thm>\<open>LENGTH_NIL\<close>,
421 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
422 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_")]\<close>
423 CAS: "solveSystem e_s v_s"
424 Given: "equalities e_s" "solveForVars v_s"
425 Where: "Length (e_s:: bool list) = 3" "Length v_s = 3"
426 Find: "solution ss'''"
428 problem pbl_equsys_lin_4x4 : "4x4/LINEAR/system" =
429 \<open>Rule_Set.append_rules "prls_4x4_linear_system" Rule_Set.empty
430 [\<^rule_thm>\<open>LENGTH_CONS\<close>,
431 \<^rule_thm>\<open>LENGTH_NIL\<close>,
432 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
433 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_")]\<close>
434 CAS: "solveSystem e_s v_s"
435 Given: "equalities e_s" "solveForVars v_s"
436 Where: "Length (e_s:: bool list) = 4" "Length v_s = 4"
437 Find: "solution ss'''"
439 problem pbl_equsys_lin_4x4_tri : "triangular/4x4/LINEAR/system" =
440 \<open>Rule_Set.append_rules "prls_tri_4x4_lin_sys" prls_triangular
441 [\<^rule_eval>\<open>Prog_Expr.occurs_in\<close> (Prog_Expr.eval_occurs_in "")]\<close>
442 Method: "EqSystem/top_down_substitution/4x4"
443 CAS: "solveSystem e_s v_s"
444 Given: "equalities e_s" "solveForVars v_s"
445 Where: (*accepts missing variables up to diagional form*)
446 "(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))"
447 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))"
448 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))"
449 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"
450 Find: "solution ss'''"
452 problem pbl_equsys_lin_4x4_norm : "normalise/4x4/LINEAR/system" =
453 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)]\<close>
454 Method: "EqSystem/normalise/4x4"
455 CAS: "solveSystem e_s v_s"
456 Given: "equalities e_s" "solveForVars v_s"
457 (*Length is checked 1 level above*)
458 Find: "solution ss'''"
461 (*this is for NTH only*)
462 val srls = Rule_Def.Repeat {id="srls_normalise_4x4",
464 rew_ord = ("termlessI",termlessI),
465 erls = Rule_Set.append_rules "erls_in_srls_IntegrierenUnd.." Rule_Set.empty
466 [(*for asm in NTH_CONS ...*)
467 \<^rule_eval>\<open>less\<close> (Prog_Expr.eval_equ "#less_"),
468 (*2nd NTH_CONS pushes n+-1 into asms*)
469 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_")
471 srls = Rule_Set.Empty, calc = [], errpatts = [],
472 rules = [\<^rule_thm>\<open>NTH_CONS\<close>,
473 \<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
474 \<^rule_thm>\<open>NTH_NIL\<close>],
475 scr = Rule.Empty_Prog};
478 section \<open>Methods\<close>
480 method met_eqsys : "EqSystem" =
481 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [], srls = Rule_Set.Empty, prls = Rule_Set.Empty, crls = Rule_Set.Empty,
482 errpats = [], nrls = Rule_Set.Empty}\<close>
484 method met_eqsys_topdown : "EqSystem/top_down_substitution" =
485 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [], srls = Rule_Set.Empty, prls = Rule_Set.Empty, crls = Rule_Set.Empty,
486 errpats = [], nrls = Rule_Set.Empty}\<close>
488 partial_function (tailrec) solve_system :: "bool list => real list => bool list"
490 "solve_system e_s v_s = (
494 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''isolate_bdvs'')) #>
495 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System''))
497 e_2 = Take (hd (tl e_s));
499 (Substitute [e_1]) #>
500 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System_parenthesized'' )) #>
501 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''isolate_bdvs'' )) #>
502 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System'' ))
504 e__s = Take [e_1, e_2]
506 Try (Rewrite_Set ''order_system'' ) e__s) "
508 method met_eqsys_topdown_2x2 : "EqSystem/top_down_substitution/2x2" =
509 \<open>{rew_ord'="ord_simplify_System", rls' = Rule_Set.Empty, calc = [],
510 srls = Rule_Set.append_rules "srls_top_down_2x2" Rule_Set.empty
511 [\<^rule_thm>\<open>hd_thm\<close>,
512 \<^rule_thm>\<open>tl_Cons\<close>,
513 \<^rule_thm>\<open>tl_Nil\<close>],
514 prls = prls_triangular, crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
515 Program: solve_system.simps
516 Given: "equalities e_s" "solveForVars v_s"
518 "(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))"
519 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"
520 Find: "solution ss'''"
522 method met_eqsys_norm : "EqSystem/normalise" =
523 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [], srls = Rule_Set.Empty, prls = Rule_Set.Empty, crls = Rule_Set.Empty,
524 errpats = [], nrls = Rule_Set.Empty}\<close>
526 partial_function (tailrec) solve_system2 :: "bool list => real list => bool list"
528 "solve_system2 e_s v_s = (
531 (Try (Rewrite_Set ''norm_Rational'' )) #>
532 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System_parenthesized'' )) #>
533 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''isolate_bdvs'' )) #>
534 (Try (Rewrite_Set_Inst [(''bdv_1'', hd v_s), (''bdv_2'', hd (tl v_s))] ''simplify_System_parenthesized'' )) #>
535 (Try (Rewrite_Set ''order_system'' ))
538 SubProblem (''EqSystem'', [''LINEAR'', ''system''], [''no_met''])
539 [BOOL_LIST e__s, REAL_LIST v_s])"
541 method met_eqsys_norm_2x2 : "EqSystem/normalise/2x2" =
542 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [],
543 srls = Rule_Set.append_rules "srls_normalise_2x2" Rule_Set.empty
544 [\<^rule_thm>\<open>hd_thm\<close>,
545 \<^rule_thm>\<open>tl_Cons\<close>,
546 \<^rule_thm>\<open>tl_Nil\<close>],
547 prls = Rule_Set.Empty, crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
548 Program: solve_system2.simps
549 Given: "equalities e_s" "solveForVars v_s"
550 Find: "solution ss'''"
552 partial_function (tailrec) solve_system3 :: "bool list => real list => bool list"
554 "solve_system3 e_s v_s = (
557 (Try (Rewrite_Set ''norm_Rational'' )) #>
558 (Repeat (Rewrite ''commute_0_equality'' )) #>
559 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s), (''bdv_2'', NTH 2 v_s ),
560 (''bdv_3'', NTH 3 v_s), (''bdv_3'', NTH 4 v_s )] ''simplify_System_parenthesized'' )) #>
561 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s), (''bdv_2'', NTH 2 v_s ),
562 (''bdv_3'', NTH 3 v_s), (''bdv_3'', NTH 4 v_s )] ''isolate_bdvs_4x4'' )) #>
563 (Try (Rewrite_Set_Inst [(''bdv_1'', NTH 1 v_s), (''bdv_2'', NTH 2 v_s ),
564 (''bdv_3'', NTH 3 v_s), (''bdv_3'', NTH 4 v_s )] ''simplify_System_parenthesized'' )) #>
565 (Try (Rewrite_Set ''order_system''))
568 SubProblem (''EqSystem'', [''LINEAR'', ''system''], [''no_met''])
569 [BOOL_LIST e__s, REAL_LIST v_s])"
571 method met_eqsys_norm_4x4 : "EqSystem/normalise/4x4" =
572 \<open>{rew_ord'="tless_true", rls' = Rule_Set.Empty, calc = [],
574 Rule_Set.append_rules "srls_normalise_4x4" srls
575 [\<^rule_thm>\<open>hd_thm\<close>, \<^rule_thm>\<open>tl_Cons\<close>, \<^rule_thm>\<open>tl_Nil\<close>],
576 prls = Rule_Set.Empty, crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
577 Program: solve_system3.simps
578 Given: "equalities e_s" "solveForVars v_s"
579 Find: "solution ss'''"
580 (*STOPPED.WN06? met ["EqSystem", "normalise", "4x4"] #>#>#>#>#>#>#>#>#>#>#>#>#>@*)
582 partial_function (tailrec) solve_system4 :: "bool list => real list => bool list"
584 "solve_system4 e_s v_s = (
587 e_2 = Take (NTH 2 e_s);
589 (Substitute [e_1]) #>
590 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s), (''bdv_2'',NTH 2 v_s),
591 (''bdv_3'',NTH 3 v_s), (''bdv_4'',NTH 4 v_s)] ''simplify_System_parenthesized'' )) #>
592 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s), (''bdv_2'',NTH 2 v_s),
593 (''bdv_3'',NTH 3 v_s), (''bdv_4'',NTH 4 v_s)] ''isolate_bdvs'' )) #>
594 (Try (Rewrite_Set_Inst [(''bdv_1'',NTH 1 v_s), (''bdv_2'',NTH 2 v_s),
595 (''bdv_3'',NTH 3 v_s), (''bdv_4'',NTH 4 v_s)] ''norm_Rational'' ))
598 [e_1, e_2, NTH 3 e_s, NTH 4 e_s])"
600 method met_eqsys_topdown_4x4 : "EqSystem/top_down_substitution/4x4" =
601 \<open>{rew_ord'="ord_simplify_System", rls' = Rule_Set.Empty, calc = [],
602 srls = Rule_Set.append_rules "srls_top_down_4x4" srls [],
603 prls = Rule_Set.append_rules "prls_tri_4x4_lin_sys" prls_triangular
604 [\<^rule_eval>\<open>Prog_Expr.occurs_in\<close> (Prog_Expr.eval_occurs_in "")],
605 crls = Rule_Set.Empty, errpats = [], nrls = Rule_Set.Empty}\<close>
606 (*FIXXXXME.WN060916: this script works ONLY for exp 7.79 #>#>#>#>#>#>#>#>#>#>*)
607 Program: solve_system4.simps
608 Given: "equalities e_s" "solveForVars v_s"
609 Where: (*accepts missing variables up to diagonal form*)
610 "(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))"
611 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))"
612 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))"
613 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"
614 Find: "solution ss'''"