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