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