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 SolveSystemScript :: "[bool list, real list, bool list]
24 ("((Script SolveSystemScript (_ _ =))// (_))" 9)
27 (*stated as axioms, todo: prove as theorems
28 'bdv' is a constant handled on the meta-level
29 specifically as a 'bound variable' *)
31 commute_0_equality: "(0 = a) = (a = 0)" and
33 (*WN0510 see simliar rules 'isolate_' 'separate_' (by RL)
34 [bdv_1,bdv_2,bdv_3,bdv_4] work also for 2 and 3 bdvs, ugly !*)
36 "[| [] from [bdv_1,bdv_2,bdv_3,bdv_4] occur_exactly_in a |]
37 ==> (a + b = c) = (b = c + -1*a)" and
39 "[| some_of [bdv_1,bdv_2,bdv_3,bdv_4] occur_in b; Not (b=!=0) |]
40 ==> (a = b) = (a + -1*b = 0)" and
42 "[| some_of [bdv_1,bdv_2,bdv_3,bdv_4] occur_in c |]
43 ==> (a = b + c) = (a + -1*c = b)" and
45 "[| Not (some_of [bdv_1,bdv_2,bdv_3,bdv_4] occur_in a) |]
46 ==> (a + b = c) = (b = -1*a + c)" and
48 "[| [] from [bdv_1,bdv_2,bdv_3,bdv_4] occur_exactly_in a; Not (a=!=0) |]
49 ==>(a * b = c) = (b = c / a)"
50 axiomatization where (*..if replaced by "and" we get an error in
51 --- rewrite in [EqSystem,normalise,2x2] --- step "--- 3---";*)
52 order_system_NxN: "[a,b] = [b,a]"
53 (*requires rew_ord for termination, eg. ord_simplify_Integral;
54 works for lists of any length, interestingly !?!*)
59 (** eval functions **)
61 (*certain variables of a given list occur _all_ in a term
62 args: all: ..variables, which are under consideration (eg. the bound vars)
63 vs: variables which must be in t,
64 and none of the others in all must be in t
65 t: the term under consideration
67 fun occur_exactly_in vs all t =
68 let fun occurs_in' a b = occurs_in b a
69 in foldl and_ (true, map (occurs_in' t) vs)
70 andalso not (foldl or_ (false, map (occurs_in' t)
71 (subtract op = vs all)))
74 (*("occur_exactly_in", ("EqSystem.occur'_exactly'_in",
75 eval_occur_exactly_in "#eval_occur_exactly_in_"))*)
76 fun eval_occur_exactly_in _ "EqSystem.occur'_exactly'_in"
77 (p as (Const ("EqSystem.occur'_exactly'_in",_)
79 if occur_exactly_in (TermC.isalist2list vs) (TermC.isalist2list all) t
80 then SOME ((term2str p) ^ " = True",
81 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
82 else SOME ((term2str p) ^ " = False",
83 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
84 | eval_occur_exactly_in _ _ _ _ = NONE;
86 setup {* KEStore_Elems.add_calcs
88 ("EqSystem.occur'_exactly'_in",
89 eval_occur_exactly_in "#eval_occur_exactly_in_"))] *}
91 (** rewrite order 'ord_simplify_System' **)
93 (* order wrt. several linear (i.e. without exponents) variables "c","c_2",..
94 which leaves the monomials containing c, c_2,... at the end of an Integral
95 and puts the c, c_2,... rightmost within a monomial.
97 WN050906 this is a quick and dirty adaption of ord_make_polynomial_in,
98 which was most adequate, because it uses size_of_term*)
100 local (*. for simplify_System .*)
102 open Term; (* for type order = EQUAL | LESS | GREATER *)
104 fun pr_ord EQUAL = "EQUAL"
105 | pr_ord LESS = "LESS"
106 | pr_ord GREATER = "GREATER";
108 fun dest_hd' (Const (a, T)) = (((a, 0), T), 0)
109 | dest_hd' (Free (ccc, T)) =
110 (case Symbol.explode ccc of
111 "c"::[] => ((("|||||||||||||||||||||", 0), T), 1)(*greatest string WN*)
112 | "c"::"_"::_ => ((("|||||||||||||||||||||", 0), T), 1)
113 | _ => (((ccc, 0), T), 1))
114 | dest_hd' (Var v) = (v, 2)
115 | dest_hd' (Bound i) = ((("", i), dummyT), 3)
116 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
118 fun size_of_term' (Free (ccc, _)) =
119 (case Symbol.explode ccc of (*WN0510 hack for the bound variables*)
121 | "c"::"_"::is => 1000 * ((TermC.int_of_str o implode) is)
123 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
124 | size_of_term' (f$t) = size_of_term' f + size_of_term' t
125 | size_of_term' _ = 1;
127 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *)
128 (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
129 | term_ord' pr thy (t, u) =
133 val (f, ts) = strip_comb t and (g, us) = strip_comb u;
134 val _ = tracing ("t= f@ts= \"" ^ term_to_string''' thy f ^ "\" @ \"[" ^
135 commas (map (term_to_string''' thy) ts) ^ "]\"");
136 val _ = tracing ("u= g@us= \"" ^ term_to_string''' thy g ^ "\" @ \"[" ^
137 commas (map (term_to_string''' thy) us) ^ "]\"");
138 val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' t) ^ ", " ^
139 string_of_int (size_of_term' u) ^ ")");
140 val _ = tracing ("hd_ord(f,g) = " ^ ((pr_ord o hd_ord) (f,g)));
141 val _ = tracing ("terms_ord (ts,us) = " ^(pr_ord o terms_ord str false) (ts,us));
142 val _=tracing("-------");
145 case int_ord (size_of_term' t, size_of_term' u) of
147 let val (f, ts) = strip_comb t and (g, us) = strip_comb u
148 in (case hd_ord (f, g) of
149 EQUAL => (terms_ord str pr) (ts, us)
153 and hd_ord (f, g) = (* ~ term.ML *)
154 prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
155 and terms_ord str pr (ts, us) = list_ord (term_ord' pr (assoc_thy "Isac"))(ts, us);
159 (*WN0510 for preliminary use in eval_order_system, see case-study mat-eng.tex
160 fun ord_simplify_System_rev (pr:bool) thy subst tu =
161 (term_ord' pr thy (Library.swap tu) = LESS);*)
164 fun ord_simplify_System (pr:bool) thy subst tu =
165 (term_ord' pr thy tu = LESS);
169 rew_ord' := overwritel (!rew_ord',
170 [("ord_simplify_System", ord_simplify_System false thy)
176 (*.adapted from 'order_add_mult_in' by just replacing the rew_ord.*)
177 val order_add_mult_System =
178 Rls{id = "order_add_mult_System", preconds = [],
179 rew_ord = ("ord_simplify_System",
180 ord_simplify_System false @{theory "Integrate"}),
181 erls = e_rls,srls = Erls, calc = [], errpatts = [],
182 rules = [Thm ("mult_commute",TermC.num_str @{thm mult.commute}),
184 Thm ("real_mult_left_commute",TermC.num_str @{thm real_mult_left_commute}),
185 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
186 Thm ("mult_assoc",TermC.num_str @{thm mult.assoc}),
187 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
188 Thm ("add_commute",TermC.num_str @{thm add.commute}),
190 Thm ("add_left_commute",TermC.num_str @{thm add.left_commute}),
191 (*x + (y + z) = y + (x + z)*)
192 Thm ("add_assoc",TermC.num_str @{thm add.assoc})
193 (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
198 (*.adapted from 'norm_Rational' by
199 #1 using 'ord_simplify_System' in 'order_add_mult_System'
200 #2 NOT using common_nominator_p .*)
201 val norm_System_noadd_fractions =
202 Rls {id = "norm_System_noadd_fractions", preconds = [],
203 rew_ord = ("dummy_ord",dummy_ord),
204 erls = norm_rat_erls, srls = Erls, calc = [], errpatts = [],
205 rules = [(*sequence given by operator precedence*)
208 Rls_ rat_mult_divide,
211 Rls_ (*order_add_mult #1*) order_add_mult_System,
212 Rls_ collect_numerals,
213 (*Rls_ add_fractions_p, #2*)
216 scr = Prog ((Thm.term_of o the o (TermC.parse thy)) "empty_script")
220 (*.adapted from 'norm_Rational' by
221 *1* using 'ord_simplify_System' in 'order_add_mult_System'.*)
223 Rls {id = "norm_System", preconds = [],
224 rew_ord = ("dummy_ord",dummy_ord),
225 erls = norm_rat_erls, srls = Erls, calc = [], errpatts = [],
226 rules = [(*sequence given by operator precedence*)
229 Rls_ rat_mult_divide,
232 Rls_ (*order_add_mult *1*) order_add_mult_System,
233 Rls_ collect_numerals,
234 Rls_ add_fractions_p,
237 scr = Prog ((Thm.term_of o the o (TermC.parse thy)) "empty_script")
241 (*.simplify an equational system BEFORE solving it such that parentheses are
242 ( ((u0*v0)*w0) + ( ((u1*v1)*w1) * c + ... +((u4*v4)*w4) * c_4 ) )
243 ATTENTION: works ONLY for bound variables c, c_1, c_2, c_3, c_4 :ATTENTION
244 This is a copy from 'make_ratpoly_in' with respective reductions:
245 *0* expand the term, ie. distribute * and / over +
246 *1* ord_simplify_System instead of termlessI
247 *2* no add_fractions_p (= common_nominator_p_rls !)
248 *3* discard_parentheses only for (.*(.*.))
249 analoguous to simplify_Integral .*)
250 val simplify_System_parenthesized =
251 Seq {id = "simplify_System_parenthesized", preconds = []:term list,
252 rew_ord = ("dummy_ord", dummy_ord),
253 erls = Atools_erls, srls = Erls, calc = [], errpatts = [],
254 rules = [Thm ("distrib_right",TermC.num_str @{thm distrib_right}),
255 (*"(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w"*)
256 Thm ("add_divide_distrib",TermC.num_str @{thm add_divide_distrib}),
257 (*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"*)
258 (*^^^^^ *0* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
259 Rls_ norm_Rational_noadd_fractions(**2**),
260 Rls_ (*order_add_mult_in*) norm_System_noadd_fractions (**1**),
261 Thm ("sym_mult_assoc",
262 TermC.num_str (@{thm mult.assoc} RS @{thm sym}))
263 (*Rls_ discard_parentheses *3**),
264 Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
266 Calc ("Rings.divide_class.divide" ,eval_cancel "#divide_e")
271 (*.simplify an equational system AFTER solving it;
272 This is a copy of 'make_ratpoly_in' with the differences
273 *1* ord_simplify_System instead of termlessI .*)
274 (*TODO.WN051031 ^^^^^^^^^^ should be in EACH rls contained *)
275 val simplify_System =
276 Seq {id = "simplify_System", preconds = []:term list,
277 rew_ord = ("dummy_ord", dummy_ord),
278 erls = Atools_erls, srls = Erls, calc = [], errpatts = [],
279 rules = [Rls_ norm_Rational,
280 Rls_ (*order_add_mult_in*) norm_System (**1**),
281 Rls_ discard_parentheses,
282 Rls_ collect_bdv, (*from make_polynomial_in WN051031 welldone?*)
284 Calc ("Rings.divide_class.divide" ,eval_cancel "#divide_e")
288 val simplify_System =
289 append_rls "simplify_System" simplify_System_parenthesized
290 [Thm ("sym_add_assoc",
291 TermC.num_str (@{thm add.assoc} RS @{thm sym}))];
296 Rls {id="isolate_bdvs", preconds = [],
297 rew_ord = ("e_rew_ord", e_rew_ord),
298 erls = append_rls "erls_isolate_bdvs" e_rls
299 [(Calc ("EqSystem.occur'_exactly'_in",
300 eval_occur_exactly_in
301 "#eval_occur_exactly_in_"))
303 srls = Erls, calc = [], errpatts = [],
305 [Thm ("commute_0_equality", TermC.num_str @{thm commute_0_equality}),
306 Thm ("separate_bdvs_add", TermC.num_str @{thm separate_bdvs_add}),
307 Thm ("separate_bdvs_mult", TermC.num_str @{thm separate_bdvs_mult})],
311 val isolate_bdvs_4x4 =
312 Rls {id="isolate_bdvs_4x4", preconds = [],
313 rew_ord = ("e_rew_ord", e_rew_ord),
315 "erls_isolate_bdvs_4x4" e_rls
316 [Calc ("EqSystem.occur'_exactly'_in",
317 eval_occur_exactly_in "#eval_occur_exactly_in_"),
318 Calc ("Atools.ident",eval_ident "#ident_"),
319 Calc ("Atools.some'_occur'_in",
320 eval_some_occur_in "#some_occur_in_"),
321 Thm ("not_true",TermC.num_str @{thm not_true}),
322 Thm ("not_false",TermC.num_str @{thm not_false})
324 srls = Erls, calc = [], errpatts = [],
325 rules = [Thm ("commute_0_equality", TermC.num_str @{thm commute_0_equality}),
326 Thm ("separate_bdvs0", TermC.num_str @{thm separate_bdvs0}),
327 Thm ("separate_bdvs_add1", TermC.num_str @{thm separate_bdvs_add1}),
328 Thm ("separate_bdvs_add1", TermC.num_str @{thm separate_bdvs_add2}),
329 Thm ("separate_bdvs_mult", TermC.num_str @{thm separate_bdvs_mult})
335 (*.order the equations in a system such, that a triangular system (if any)
336 appears as [..c_4 = .., ..., ..., ..c_1 + ..c_2 + ..c_3 ..c_4 = ..].*)
338 Rls {id="order_system", preconds = [],
339 rew_ord = ("ord_simplify_System",
340 ord_simplify_System false thy),
341 erls = Erls, srls = Erls, calc = [], errpatts = [],
342 rules = [Thm ("order_system_NxN", TermC.num_str @{thm order_system_NxN})
346 val prls_triangular =
347 Rls {id="prls_triangular", preconds = [],
348 rew_ord = ("e_rew_ord", e_rew_ord),
349 erls = Rls {id="erls_prls_triangular", preconds = [],
350 rew_ord = ("e_rew_ord", e_rew_ord),
351 erls = Erls, srls = Erls, calc = [], errpatts = [],
352 rules = [(*for precond NTH_CONS ...*)
353 Calc ("Orderings.ord_class.less",eval_equ "#less_"),
354 Calc ("Groups.plus_class.plus", eval_binop "#add_")
355 (*immediately repeated rewrite pushes
356 '+' into precondition !*)
359 srls = Erls, calc = [], errpatts = [],
360 rules = [Thm ("NTH_CONS",TermC.num_str @{thm NTH_CONS}),
361 Calc ("Groups.plus_class.plus", eval_binop "#add_"),
362 Thm ("NTH_NIL",TermC.num_str @{thm NTH_NIL}),
363 Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
364 Thm ("tl_Nil",TermC.num_str @{thm tl_Nil}),
365 Calc ("EqSystem.occur'_exactly'_in",
366 eval_occur_exactly_in
367 "#eval_occur_exactly_in_")
373 (*WN060914 quickly created for 4x4;
374 more similarity to prls_triangular desirable*)
375 val prls_triangular4 =
376 Rls {id="prls_triangular4", preconds = [],
377 rew_ord = ("e_rew_ord", e_rew_ord),
378 erls = Rls {id="erls_prls_triangular4", preconds = [],
379 rew_ord = ("e_rew_ord", e_rew_ord),
380 erls = Erls, srls = Erls, calc = [], errpatts = [],
381 rules = [(*for precond NTH_CONS ...*)
382 Calc ("Orderings.ord_class.less",eval_equ "#less_"),
383 Calc ("Groups.plus_class.plus", eval_binop "#add_")
384 (*immediately repeated rewrite pushes
385 '+' into precondition !*)
388 srls = Erls, calc = [], errpatts = [],
389 rules = [Thm ("NTH_CONS",TermC.num_str @{thm NTH_CONS}),
390 Calc ("Groups.plus_class.plus", eval_binop "#add_"),
391 Thm ("NTH_NIL",TermC.num_str @{thm NTH_NIL}),
392 Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
393 Thm ("tl_Nil",TermC.num_str @{thm tl_Nil}),
394 Calc ("EqSystem.occur'_exactly'_in",
395 eval_occur_exactly_in
396 "#eval_occur_exactly_in_")
401 setup {* KEStore_Elems.add_rlss
402 [("simplify_System_parenthesized",
403 (Context.theory_name @{theory}, prep_rls' simplify_System_parenthesized)),
404 ("simplify_System", (Context.theory_name @{theory}, prep_rls' simplify_System)),
405 ("isolate_bdvs", (Context.theory_name @{theory}, prep_rls' isolate_bdvs)),
406 ("isolate_bdvs_4x4", (Context.theory_name @{theory}, prep_rls' isolate_bdvs_4x4)),
407 ("order_system", (Context.theory_name @{theory}, prep_rls' order_system)),
408 ("order_add_mult_System", (Context.theory_name @{theory}, prep_rls' order_add_mult_System)),
409 ("norm_System_noadd_fractions",
410 (Context.theory_name @{theory}, prep_rls' norm_System_noadd_fractions)),
411 ("norm_System", (Context.theory_name @{theory}, prep_rls' norm_System))] *}
414 setup {* KEStore_Elems.add_pbts
415 [(Specify.prep_pbt thy "pbl_equsys" [] e_pblID
417 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
418 ("#Find" ,["solution ss'''"](*''' is copy-named*))],
419 append_rls "e_rls" e_rls [(*for preds in where_*)], SOME "solveSystem e_s v_s", [])),
420 (Specify.prep_pbt thy "pbl_equsys_lin" [] e_pblID
421 (["LINEAR", "system"],
422 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
423 (*TODO.WN050929 check linearity*)
424 ("#Find" ,["solution ss'''"])],
425 append_rls "e_rls" e_rls [(*for preds in where_*)], SOME "solveSystem e_s v_s", [])),
426 (Specify.prep_pbt thy "pbl_equsys_lin_2x2" [] e_pblID
427 (["2x2", "LINEAR", "system"],
428 (*~~~~~~~~~~~~~~~~~~~~~~~~~*)
429 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
430 ("#Where" ,["LENGTH (e_s:: bool list) = 2", "LENGTH v_s = 2"]),
431 ("#Find" ,["solution ss'''"])],
432 append_rls "prls_2x2_linear_system" e_rls
433 [Thm ("LENGTH_CONS",TermC.num_str @{thm LENGTH_CONS}),
434 Thm ("LENGTH_NIL",TermC.num_str @{thm LENGTH_NIL}),
435 Calc ("Groups.plus_class.plus", eval_binop "#add_"),
436 Calc ("HOL.eq",eval_equal "#equal_")],
437 SOME "solveSystem e_s v_s", [])),
438 (Specify.prep_pbt thy "pbl_equsys_lin_2x2_tri" [] e_pblID
439 (["triangular", "2x2", "LINEAR", "system"],
440 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
442 ["(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))",
443 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"]),
444 ("#Find" ,["solution ss'''"])],
445 prls_triangular, SOME "solveSystem e_s v_s", [["EqSystem","top_down_substitution","2x2"]])),
446 (Specify.prep_pbt thy "pbl_equsys_lin_2x2_norm" [] e_pblID
447 (["normalise", "2x2", "LINEAR", "system"],
448 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
449 ("#Find" ,["solution ss'''"])],
450 append_rls "e_rls" e_rls [(*for preds in where_*)],
451 SOME "solveSystem e_s v_s",
452 [["EqSystem","normalise","2x2"]])),
453 (Specify.prep_pbt thy "pbl_equsys_lin_3x3" [] e_pblID
454 (["3x3", "LINEAR", "system"],
455 (*~~~~~~~~~~~~~~~~~~~~~~~~~*)
456 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
457 ("#Where" ,["LENGTH (e_s:: bool list) = 3", "LENGTH v_s = 3"]),
458 ("#Find" ,["solution ss'''"])],
459 append_rls "prls_3x3_linear_system" e_rls
460 [Thm ("LENGTH_CONS",TermC.num_str @{thm LENGTH_CONS}),
461 Thm ("LENGTH_NIL",TermC.num_str @{thm LENGTH_NIL}),
462 Calc ("Groups.plus_class.plus", eval_binop "#add_"),
463 Calc ("HOL.eq",eval_equal "#equal_")],
464 SOME "solveSystem e_s v_s", [])),
465 (Specify.prep_pbt thy "pbl_equsys_lin_4x4" [] e_pblID
466 (["4x4", "LINEAR", "system"],
467 (*~~~~~~~~~~~~~~~~~~~~~~~~~*)
468 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
469 ("#Where" ,["LENGTH (e_s:: bool list) = 4", "LENGTH v_s = 4"]),
470 ("#Find" ,["solution ss'''"])],
471 append_rls "prls_4x4_linear_system" e_rls
472 [Thm ("LENGTH_CONS",TermC.num_str @{thm LENGTH_CONS}),
473 Thm ("LENGTH_NIL",TermC.num_str @{thm LENGTH_NIL}),
474 Calc ("Groups.plus_class.plus", eval_binop "#add_"),
475 Calc ("HOL.eq",eval_equal "#equal_")],
476 SOME "solveSystem e_s v_s", [])),
477 (Specify.prep_pbt thy "pbl_equsys_lin_4x4_tri" [] e_pblID
478 (["triangular", "4x4", "LINEAR", "system"],
479 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
480 ("#Where" , (*accepts missing variables up to diagional form*)
481 ["(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))",
482 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))",
483 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))",
484 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"]),
485 ("#Find" ,["solution ss'''"])],
486 append_rls "prls_tri_4x4_lin_sys" prls_triangular
487 [Calc ("Atools.occurs'_in",eval_occurs_in "")],
488 SOME "solveSystem e_s v_s",
489 [["EqSystem","top_down_substitution","4x4"]])),
490 (Specify.prep_pbt thy "pbl_equsys_lin_4x4_norm" [] e_pblID
491 (["normalise", "4x4", "LINEAR", "system"],
492 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
493 (*LENGTH is checked 1 level above*)
494 ("#Find" ,["solution ss'''"])],
495 append_rls "e_rls" e_rls [(*for preds in where_*)],
496 SOME "solveSystem e_s v_s",
497 [["EqSystem","normalise","4x4"]]))] *}
500 (*this is for NTH only*)
501 val srls = Rls {id="srls_normalise_4x4",
503 rew_ord = ("termlessI",termlessI),
504 erls = append_rls "erls_in_srls_IntegrierenUnd.." e_rls
505 [(*for asm in NTH_CONS ...*)
506 Calc ("Orderings.ord_class.less",eval_equ "#less_"),
507 (*2nd NTH_CONS pushes n+-1 into asms*)
508 Calc("Groups.plus_class.plus", eval_binop "#add_")
510 srls = Erls, calc = [], errpatts = [],
511 rules = [Thm ("NTH_CONS",TermC.num_str @{thm NTH_CONS}),
512 Calc("Groups.plus_class.plus", eval_binop "#add_"),
513 Thm ("NTH_NIL",TermC.num_str @{thm NTH_NIL})],
518 setup {* KEStore_Elems.add_mets
519 [Specify.prep_met thy "met_eqsys" [] e_metID
521 {rew_ord'="tless_true", rls' = Erls, calc = [], srls = Erls, prls = Erls, crls = Erls,
522 errpats = [], nrls = Erls},
524 Specify.prep_met thy "met_eqsys_topdown" [] e_metID
525 (["EqSystem","top_down_substitution"], [],
526 {rew_ord'="tless_true", rls' = Erls, calc = [], srls = Erls, prls = Erls, crls = Erls,
527 errpats = [], nrls = Erls},
529 Specify.prep_met thy "met_eqsys_topdown_2x2" [] e_metID
530 (["EqSystem", "top_down_substitution", "2x2"],
531 [("#Given", ["equalities e_s", "solveForVars v_s"]),
533 ["(tl v_s) from v_s occur_exactly_in (NTH 1 (e_s::bool list))",
534 " v_s from v_s occur_exactly_in (NTH 2 (e_s::bool list))"]),
535 ("#Find" ,["solution ss'''"])],
536 {rew_ord'="ord_simplify_System", rls' = Erls, calc = [],
537 srls = append_rls "srls_top_down_2x2" e_rls
538 [Thm ("hd_thm",TermC.num_str @{thm hd_thm}),
539 Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
540 Thm ("tl_Nil",TermC.num_str @{thm tl_Nil})],
541 prls = prls_triangular, crls = Erls, errpats = [], nrls = Erls},
542 "Script SolveSystemScript (e_s::bool list) (v_s::real list) = " ^
543 " (let e_1 = Take (hd e_s); " ^
544 " e_1 = ((Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
545 " isolate_bdvs False)) @@ " ^
546 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
547 " simplify_System False))) e_1; " ^
548 " e_2 = Take (hd (tl e_s)); " ^
549 " e_2 = ((Substitute [e_1]) @@ " ^
550 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
551 " simplify_System_parenthesized False)) @@ " ^
552 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
553 " isolate_bdvs False)) @@ " ^
554 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
555 " simplify_System False))) e_2; " ^
556 " e__s = Take [e_1, e_2] " ^
557 " in (Try (Rewrite_Set order_system False)) e__s)"
558 (*---------------------------------------------------------------------------
559 this script does NOT separate the equations as above,
560 but it does not yet work due to preliminary script-interpreter,
561 see eqsystem.sml 'script [EqSystem,top_down_substitution,2x2] Vers.2'
563 "Script SolveSystemScript (e_s::bool list) (v_s::real list) = " ^
564 " (let e__s = Take e_s; " ^
566 " e_2 = hd (tl e__s); " ^
567 " e__s = [e_1, Substitute [e_1] e_2] " ^
568 " in ((Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
569 " simplify_System_parenthesized False)) @@ " ^
570 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))] " ^
571 " isolate_bdvs False)) @@ " ^
572 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
573 " simplify_System False))) e__s)"
574 ---------------------------------------------------------------------------*)),
575 Specify.prep_met thy "met_eqsys_norm" [] e_metID
576 (["EqSystem", "normalise"], [],
577 {rew_ord'="tless_true", rls' = Erls, calc = [], srls = Erls, prls = Erls, crls = Erls,
578 errpats = [], nrls = Erls},
580 Specify.prep_met thy "met_eqsys_norm_2x2" [] e_metID
581 (["EqSystem","normalise","2x2"],
582 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
583 ("#Find" ,["solution ss'''"])],
584 {rew_ord'="tless_true", rls' = Erls, calc = [],
585 srls = append_rls "srls_normalise_2x2" e_rls
586 [Thm ("hd_thm",TermC.num_str @{thm hd_thm}),
587 Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
588 Thm ("tl_Nil",TermC.num_str @{thm tl_Nil})],
589 prls = Erls, crls = Erls, errpats = [], nrls = Erls},
590 "Script SolveSystemScript (e_s::bool list) (v_s::real list) = " ^
591 " (let e__s = ((Try (Rewrite_Set norm_Rational False)) @@ " ^
592 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
593 " simplify_System_parenthesized False)) @@ " ^
594 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
595 " isolate_bdvs False)) @@ " ^
596 " (Try (Rewrite_Set_Inst [(bdv_1, hd v_s),(bdv_2, hd (tl v_s))]" ^
597 " simplify_System_parenthesized False)) @@ " ^
598 " (Try (Rewrite_Set order_system False))) e_s " ^
599 " in (SubProblem (EqSystem',[LINEAR,system],[no_met]) " ^
600 " [BOOL_LIST e__s, REAL_LIST v_s]))"),
601 Specify.prep_met thy "met_eqsys_norm_4x4" [] e_metID
602 (["EqSystem","normalise","4x4"],
603 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
604 ("#Find" ,["solution ss'''"])],
605 {rew_ord'="tless_true", rls' = Erls, calc = [],
606 srls = append_rls "srls_normalise_4x4" srls
607 [Thm ("hd_thm",TermC.num_str @{thm hd_thm}),
608 Thm ("tl_Cons",TermC.num_str @{thm tl_Cons}),
609 Thm ("tl_Nil",TermC.num_str @{thm tl_Nil})],
610 prls = Erls, crls = Erls, errpats = [], nrls = Erls},
611 (*STOPPED.WN06? met ["EqSystem","normalise","4x4"] @@@@@@@@@@@@@@@@@@@@@@@@@@@*)
612 "Script SolveSystemScript (e_s::bool list) (v_s::real list) = " ^
614 " ((Try (Rewrite_Set norm_Rational False)) @@ " ^
615 " (Repeat (Rewrite commute_0_equality False)) @@ " ^
616 " (Try (Rewrite_Set_Inst [(bdv_1, NTH 1 v_s),(bdv_2, NTH 2 v_s ), " ^
617 " (bdv_3, NTH 3 v_s),(bdv_3, NTH 4 v_s )] " ^
618 " simplify_System_parenthesized False)) @@ " ^
619 " (Try (Rewrite_Set_Inst [(bdv_1, NTH 1 v_s),(bdv_2, NTH 2 v_s ), " ^
620 " (bdv_3, NTH 3 v_s),(bdv_3, NTH 4 v_s )] " ^
621 " isolate_bdvs_4x4 False)) @@ " ^
622 " (Try (Rewrite_Set_Inst [(bdv_1, NTH 1 v_s),(bdv_2, NTH 2 v_s ), " ^
623 " (bdv_3, NTH 3 v_s),(bdv_3, NTH 4 v_s )] " ^
624 " simplify_System_parenthesized False)) @@ " ^
625 " (Try (Rewrite_Set order_system False))) e_s " ^
626 " in (SubProblem (EqSystem',[LINEAR,system],[no_met]) " ^
627 " [BOOL_LIST e__s, REAL_LIST v_s]))"),
628 Specify.prep_met thy "met_eqsys_topdown_4x4" [] e_metID
629 (["EqSystem","top_down_substitution","4x4"],
630 [("#Given" ,["equalities e_s", "solveForVars v_s"]),
631 ("#Where" , (*accepts missing variables up to diagonal form*)
632 ["(NTH 1 (v_s::real list)) occurs_in (NTH 1 (e_s::bool list))",
633 "(NTH 2 (v_s::real list)) occurs_in (NTH 2 (e_s::bool list))",
634 "(NTH 3 (v_s::real list)) occurs_in (NTH 3 (e_s::bool list))",
635 "(NTH 4 (v_s::real list)) occurs_in (NTH 4 (e_s::bool list))"]),
636 ("#Find", ["solution ss'''"])],
637 {rew_ord'="ord_simplify_System", rls' = Erls, calc = [],
638 srls = append_rls "srls_top_down_4x4" srls [],
639 prls = append_rls "prls_tri_4x4_lin_sys" prls_triangular
640 [Calc ("Atools.occurs'_in",eval_occurs_in "")],
641 crls = Erls, errpats = [], nrls = Erls},
642 (*FIXXXXME.WN060916: this script works ONLY for exp 7.79 @@@@@@@@@@@@@@@@@@@@*)
643 "Script SolveSystemScript (e_s::bool list) (v_s::real list) = " ^
644 " (let e_1 = NTH 1 e_s; " ^
645 " e_2 = Take (NTH 2 e_s); " ^
646 " e_2 = ((Substitute [e_1]) @@ " ^
647 " (Try (Rewrite_Set_Inst [(bdv_1,NTH 1 v_s),(bdv_2,NTH 2 v_s)," ^
648 " (bdv_3,NTH 3 v_s),(bdv_4,NTH 4 v_s)]" ^
649 " simplify_System_parenthesized False)) @@ " ^
650 " (Try (Rewrite_Set_Inst [(bdv_1,NTH 1 v_s),(bdv_2,NTH 2 v_s)," ^
651 " (bdv_3,NTH 3 v_s),(bdv_4,NTH 4 v_s)]" ^
652 " isolate_bdvs False)) @@ " ^
653 " (Try (Rewrite_Set_Inst [(bdv_1,NTH 1 v_s),(bdv_2,NTH 2 v_s)," ^
654 " (bdv_3,NTH 3 v_s),(bdv_4,NTH 4 v_s)]" ^
655 " norm_Rational False))) e_2 " ^
656 " in [e_1, e_2, NTH 3 e_s, NTH 4 e_s])")]