test/Tools/isac/Knowledge/eqsystem-1.sml
author wneuper <Walther.Neuper@jku.at>
Wed, 11 Jan 2023 11:38:01 +0100
changeset 60650 06ec8abfd3bc
parent 60594 439f7f3867ec
child 60651 b7a2ad3b3d45
permissions -rw-r--r--
eliminate use of Thy_Info 12: TermC partially
     1 (* Title: Knowledge/eqsystem-1.sml
     2    author: Walther Neuper 050826,
     3    (c) due to copyright terms
     4 *)
     5 
     6 "-----------------------------------------------------------------------------------------------";
     7 "table of contents -----------------------------------------------------------------------------";
     8 "-----------------------------------------------------------------------------------------------";
     9 "----------- occur_exactly_in ---------------------------------------------------equsystem-1.sml";
    10 "----------- problems -----------------------------------------------------------equsystem-1.sml";
    11 "----------- rewrite-order ord_simplify_System ----------------------------------equsystem-1.sml";
    12 "----------- rewrite in [EqSystem,normalise,2x2] --------------------------------equsystem-1.sml";
    13 "----------- rewrite example from 2nd [EqSystem,normalise,2x2] ------------------equsystem-1.sml";
    14 "----------- rewrite in [EqSystem,top_down_substitution,2x2] --------------------equsystem-1.sml";
    15 "----------- rewrite in [EqSystem,normalise,4x4] --------------------------------equsystem-1.sml";
    16 "----------- script [EqSystem,top_down_substitution,2x2] Vers.1 -----------------equsystem-1.sml";
    17 "----------- refine [linear,system]----------------------------------------------equsystem-1.sml";
    18 "----------- refine [2x2,linear,system] search error-----------------------------equsystem-1.sml";
    19 "----------- me [EqSystem,normalise,2x2], refine Subproblem ---------------------equsystem-1.sml";
    20 "----------- me [EqSystem,normalise,2x2], refine Subproblem, step into istate---equsystem-1a.sml";
    21 "----------- me [linear,system] ..normalise..top_down_sub..----------------------equsystem-2.sml";
    22 "----------- all systems from Biegelinie ----------------------------------------equsystem-2.sml";
    23 "----------- 4x4 systems from Biegelinie ----------------------------------------equsystem-2.sml";
    24 "-----------------------------------------------------------------------------------------------";
    25 "-----------------------------------------------------------------------------------------------";
    26 "-----------------------------------------------------------------------------------------------";
    27 
    28 val thy = @{theory "EqSystem"};
    29 val ctxt = Proof_Context.init_global thy;
    30 
    31 "----------- occur_exactly_in ------------------------------------";
    32 "----------- occur_exactly_in ------------------------------------";
    33 "----------- occur_exactly_in ------------------------------------";
    34 val all = [TermC.parse_test @{context}"c", TermC.parse_test @{context}"c_2", TermC.parse_test @{context}"c_3"];
    35 val t = TermC.parse_test @{context}"0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2";
    36 
    37 if occur_exactly_in [TermC.parse_test @{context}"c", TermC.parse_test @{context}"c_2"] all t
    38 then () else error "eqsystem.sml occur_exactly_in 1";
    39 
    40 if not (occur_exactly_in [TermC.parse_test @{context}"c", TermC.parse_test @{context}"c_2", TermC.parse_test @{context}"c_3"] all t)
    41 then () else error "eqsystem.sml occur_exactly_in 2";
    42 
    43 if not (occur_exactly_in [TermC.parse_test @{context}"c_2"] all t)
    44 then () else error "eqsystem.sml occur_exactly_in 3";
    45 
    46 val t = TermC.parse_test @{context}"[c,c_2] from [c,c_2,c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2";
    47 eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
    48 val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
    49 if str = "[c, c_2] from [c, c_2,\n" ^
    50   "               c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 = True"
    51 then () else error "eval_occur_exactly_in [c, c_2]";
    52 
    53 val t = TermC.parse_test @{context} ("[c,c_2,c_3] from [c,c_2,c_3] occur_exactly_in " ^
    54 		  "- 1 * q_0 * L \<up> 2 / 2 + L * c + c_2");
    55 val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
    56 if str = "[c, c_2,\n c_3] from [c, c_2,\n" ^
    57 "            c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 = False"
    58 then () else error "eval_occur_exactly_in [c, c_2, c_3]";
    59 
    60 val t = TermC.parse_test @{context}"[c_2] from [c,c_2,c_3] occur_exactly_in \
    61 		\- 1 * q_0 * L \<up> 2 / 2 + L * c + c_2";
    62 val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
    63 if str = "[c_2] from [c, c_2,\n" ^
    64   "            c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 = False"
    65 then () else error "eval_occur_exactly_in [c, c_2, c_3]";
    66 
    67 val t = TermC.parse_test @{context}"[] from [c,c_2,c_3] occur_exactly_in 0";
    68 val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
    69 if str = "[] from [c, c_2, c_3] occur_exactly_in 0 = True" then ()
    70 else error "eval_occur_exactly_in [c, c_2, c_3]";
    71 
    72 val t = 
    73     TermC.parse_test @{context}
    74 	"[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) /2";
    75 val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
    76 if str = "[] from [c, c_2, c_3, c_4] occur_exactly_in \
    77 	 \- 1 * (q_0 * L \<up> 2) / 2 = True" then ()
    78 else error "eval_occur_exactly_in [c, c_2, c_3, c_4]";
    79 
    80 "----------- problems --------------------------------------------";
    81 "----------- problems --------------------------------------------";
    82 "----------- problems --------------------------------------------";
    83 val t = TermC.parse_test @{context} "Length [x+y=1,y=2] = 2";
    84 TermC.atom_trace_detail @{context} t;
    85 val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty 
    86 			 [(Thm ("LENGTH_NIL", @{thm LENGTH_NIL})),
    87 			  (Thm ("LENGTH_CONS", @{thm LENGTH_CONS})),
    88 			  Eval (\<^const_name>\<open>plus\<close>, Calc_Binop.numeric "#add_"),
    89 			  Eval (\<^const_name>\<open>HOL.eq\<close>,eval_equal "#equal_")
    90 			  ];
    91 val SOME (t',_) = rewrite_set_ ctxt false testrls t;
    92 if UnparseC.term t' = "True" then () 
    93 else error "eqsystem.sml: length_ [x+y=1,y=2] = 2";
    94 
    95 val SOME t = TermC.parseNEW ctxt "solution LL";
    96 TermC.atom_trace_detail @{context} t;
    97 val SOME t = TermC.parseNEW ctxt "solution LL";
    98 TermC.atom_trace_detail @{context} t;
    99 
   100 val t = TermC.parse_test @{context} 
   101 "(tl (tl (tl v_s))) from v_s occur_exactly_in (NTH 1 (e_s::bool list))";
   102 TermC.atom_trace_detail @{context} t;
   103 val t = TermC.parse_test @{context} ("(tl (tl (tl [c, c_2, c_3, c_4]))) from [c, c_2, c_3, c_4] occur_exactly_in " ^
   104   "(NTH 1 [c_4 = 1, 2 = 2, 3 = 3, 4 = 4])");
   105 (*----- broken in child of.1790e1073acc : eliminate "handle _ => ..." from Rewrite.rewrite -----\\
   106         assume flawed test setup hidden by "handle _ => ..."
   107         ERROR rewrite__set_ called with 'Erls' for '1 < 1'
   108 val SOME (t,_) = 
   109     rewrite_set_ ctxt true 
   110 		 (Rule_Set.append_rules "prls_" Rule_Set.empty 
   111 			     [Thm ("NTH_CONS",ThmC.numerals_to_Free @{thm NTH_CONS}),
   112 			      Thm ("NTH_NIL",ThmC.numerals_to_Free @{thm NTH_NIL}),
   113 			      Thm ("TL_CONS",ThmC.numerals_to_Free @{thm tl_Cons}),
   114 			      Thm ("TL_NIL",ThmC.numerals_to_Free @{thm tl_Nil}),
   115 			      Eval ("EqSystem.occur_exactly_in", eval_occur_exactly_in "#eval_occur_exactly_in_")
   116 			      ]) t;
   117 if t = @{term True} then () 
   118 else error "eqsystem.sml ..occur_exactly_in (nth_ 1 [c_4..";
   119         broken in child of.1790e1073acc : eliminate "handle _ => ..." from Rewrite.rewrite ---//*)
   120 
   121 
   122 "----------- rewrite-order ord_simplify_System -------------------";
   123 "----------- rewrite-order ord_simplify_System -------------------";
   124 "----------- rewrite-order ord_simplify_System -------------------";
   125 "M_b x = c * x + - 1 * q_0 * (x \<up> 2 / 2) + c_2";
   126 "--- add.commute ---"; (* ... add.commute cf. b42e334c97ee *)
   127 if ord_simplify_System false ctxt [] (TermC.parse_test @{context}"- 1 * q_0 * (x \<up> 2 / 2)", 
   128 				       TermC.parse_test @{context}"c * x") then ()
   129 else error "integrate.sml, (- 1 * q_0 * (x \<up> 2 / 2)) < (c * x) not#1";
   130 
   131 if ord_simplify_System false ctxt [] (TermC.parse_test @{context}"- 1 * q_0 * (x \<up> 2 / 2)", 
   132 				       TermC.parse_test @{context}"c_2") then ()
   133 else error "integrate.sml, (- 1 * q_0 * (x \<up> 2 / 2)) < (c_2) not#2";
   134 
   135 if ord_simplify_System false ctxt [] (TermC.parse_test @{context}"c * x", 
   136 				       TermC.parse_test @{context}"c_2") then ()
   137 else error "integrate.sml, (c * x) < (c_2) not#3";
   138 
   139 "--- mult.commute ---";
   140 if ord_simplify_System false ctxt [] (TermC.parse_test @{context}"x * c", 
   141 				       TermC.parse_test @{context}"c * x") then ()
   142 else error "integrate.sml, (x * c) < (c * x) not#4";
   143 
   144 if ord_simplify_System false ctxt [] (TermC.parse_test @{context}"- 1 * q_0 * (x \<up> 2 / 2) * c", 
   145 				       TermC.parse_test @{context}"- 1 * q_0 * c * (x \<up> 2 / 2)") 
   146 then () else error "integrate.sml, (. * .) < (. * .) not#5";
   147 
   148 if ord_simplify_System false ctxt [] (TermC.parse_test @{context}"- 1 * q_0 * (x \<up> 2 / 2) * c", 
   149 				       TermC.parse_test @{context}"c * - 1 * q_0 * (x \<up> 2 / 2)") 
   150 then () else error "integrate.sml, (. * .) < (. * .) not#6";
   151 
   152 
   153 "----------- rewrite in [EqSystem,normalise,2x2] -----------------";
   154 "----------- rewrite in [EqSystem,normalise,2x2] -----------------";
   155 "----------- rewrite in [EqSystem,normalise,2x2] -----------------";
   156 val t = TermC.parse_test @{context}"[0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2,\
   157 	        \0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2]";
   158 val bdvs = [(TermC.parse_test @{context}"bdv_1",TermC.parse_test @{context}"c"),
   159 	    (TermC.parse_test @{context}"bdv_2",TermC.parse_test @{context}"c_2")];
   160 val SOME (t,_) = rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
   161 if UnparseC.term t = "[0 = - 1 * q_0 * L \<up> 2 / 2 + (L * c + c_2), 0 = c_2]"
   162 then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.1";
   163 
   164 val SOME (t,_) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs t;
   165 if UnparseC.term t = "[L * c + c_2 = 0 + - 1 * (- 1 * q_0 * L \<up> 2 / 2), c_2 = 0]"
   166 then () else error "eqsystem.sml rewrite in 2x2 isolate_bdvs";
   167 
   168 val SOME (t,_)= rewrite_set_inst_ ctxt true bdvs simplify_System t;
   169 if UnparseC.term t = "[L * c + c_2 = q_0 * L \<up> 2 / 2, c_2 = 0]"
   170 then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.2";
   171 
   172 "--- 3--- see EqSystem.thy (*..if replaced by 'and' ...*)";
   173 val SOME (t,_) = rewrite_set_ ctxt true order_system t;
   174 if UnparseC.term t = "[c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]"
   175 then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.3";
   176 
   177 
   178 "----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
   179 "----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
   180 "----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
   181 val thy = @{theory "Isac_Knowledge"} (*because of Undeclared constant "Biegelinie.EI*);
   182 val ctxt = Proof_Context.init_global thy;
   183 val t = 
   184     TermC.parse_test @{context}"[0 = c_2 + c * 0 + 1 / EI * (L * q_0 / 12 * 0 \<up> 3 +         \
   185 	    \                                     - 1 * q_0 / 24 * 0 \<up> 4),\
   186 	    \ 0 = c_2 + c * L + 1 / EI * (L * q_0 / 12 * L \<up> 3 +         \
   187 	    \                                     - 1 * q_0 / 24 * L \<up> 4)]";
   188 val SOME (t, _) = rewrite_set_ ctxt true norm_Rational t;
   189 if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   190                       "[c_2 = 0, 0 = q_0 * L \<up> 4 / (24 * EI) + (L * c + c_2)]"*)
   191                       "[0 = c_2, 0 = (24 * c_2 + 24 * L * c + L \<up> 4 * q_0) / 24]"
   192 then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.0b";
   193 
   194 val SOME(t, _)= rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
   195 if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   196                        "[c_2 = 0, 0 = q_0 * L \<up> 4 / (24 * EI) + (L * c + c_2)]"*)
   197                        "[0 = c_2, 0 = q_0 * L \<up> 4 / 24 + (L * c + c_2)]"
   198 then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.1b";
   199 
   200 val SOME (t,_) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs t;
   201 if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   202                        "[c_2 = 0, L * c + c_2 = 0 + - 1 * (q_0 * L \<up> 4 / (24 * EI))]"*)
   203                        "[c_2 = 0, L * c + c_2 = 0 + - 1 * (q_0 * L \<up> 4 / 24)]"
   204 then () else error "eqsystem.sml rewrite in 2x2 isolate_bdvs b";
   205 
   206 val SOME(t,_)= rewrite_set_inst_ ctxt true bdvs simplify_System t;
   207 if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
   208                        "[c_2 = 0, L * c + c_2 = - 1 * q_0 * L \<up> 4 / (24 * EI)]"*)
   209                        "[c_2 = 0, L * c + c_2 = - 1 * q_0 * L \<up> 4 / 24]"
   210 then () else error "eqsystem.sml rewrite in 2x2 simplify_System.2b";
   211 
   212 val xxx = rewrite_set_ ctxt true order_system t;
   213 if is_none xxx
   214 then () else error "eqsystem.sml rewrite in 2x2 simplify_System.3b";
   215 
   216 
   217 "----------- rewrite in [EqSystem,top_down_substitution,2x2] -----";
   218 "----------- rewrite in [EqSystem,top_down_substitution,2x2] -----";
   219 "----------- rewrite in [EqSystem,top_down_substitution,2x2] -----";
   220 val e1__ = TermC.parse_test @{context} "c_2 = 77";
   221 val e2__ = TermC.parse_test @{context} "L * c + c_2 = q_0 * L \<up> 2 / 2";
   222 val bdvs = [(TermC.parse_test @{context}"bdv_1",TermC.parse_test @{context}"c"),
   223 	    (TermC.parse_test @{context}"bdv_2",TermC.parse_test @{context}"c_2")];
   224 val SOME (e2__,_) = rewrite_terms_ ctxt Rewrite_Ord.function_empty Rule_Set.Empty [e1__] e2__;
   225 if UnparseC.term e2__ = "L * c + 77 = q_0 * L \<up> 2 / 2" then ()
   226 else error "eqsystem.sml top_down_substitution,2x2] subst";
   227 
   228 val SOME (e2__,_) = 
   229     rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized e2__;
   230 if UnparseC.term e2__ = "77 + L * c = q_0 * L \<up> 2 / 2" then ()
   231 else error "eqsystem.sml top_down_substitution,2x2] simpl_par";
   232 
   233 val SOME (e2__,_) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs e2__;
   234 if UnparseC.term e2__ = "c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L" then ()
   235 else error "eqsystem.sml top_down_substitution,2x2] isolate";
   236 
   237 val t = TermC.parse_test @{context} "[c_2 = 77, c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L]";
   238 val SOME (t,_) = rewrite_set_ ctxt true order_system t;
   239 if UnparseC.term t = "[c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L, c_2 = 77]" then ()
   240 else error "eqsystem.sml top_down_substitution,2x2] order_system";
   241 
   242 if not (ord_simplify_System
   243 	    false ctxt [] 
   244 	    (TermC.parse_test @{context}"[c_2 = 77, c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L]", 
   245 	     TermC.parse_test @{context}"[c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L, c_2 = 77]")) 
   246 then () else error "eqsystem.sml, order_result rew_ord";
   247 
   248 
   249 "----------- rewrite in [EqSystem,normalise,4x4] -----------------";
   250 "----------- rewrite in [EqSystem,normalise,4x4] -----------------";
   251 "----------- rewrite in [EqSystem,normalise,4x4] -----------------";
   252 (*STOPPED.WN06?: revise rewrite in [EqSystem,normalise,4x4] from before 0609*)
   253 val t = TermC.parse_test @{context} (
   254   "[(0::real) = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c_3 + c_4, " ^ 
   255   "(0::real) = - 1 * q_0 * L \<up> 2 / 2 + L * c_3 + c_4, " ^ 
   256   "c + c_2 + c_3 + c_4 = 0, " ^ 
   257   "c_2 + c_3 + c_4 = 0]");
   258 val bdvs = [(TermC.parse_test @{context}"bdv_1::real",TermC.parse_test @{context}"c::real"),
   259 	    (TermC.parse_test @{context}"bdv_2::real",TermC.parse_test @{context}"c_2::real"),
   260 	    (TermC.parse_test @{context}"bdv_3::real",TermC.parse_test @{context}"c_3::real"),
   261 	    (TermC.parse_test @{context}"bdv_4::real",TermC.parse_test @{context}"c_4::real")];
   262 val SOME (t, _) = 
   263     rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
   264 if UnparseC.term t = "[0 = c_4, 0 = - 1 * q_0 * L \<up> 2 / 2 + (L * c_3 + c_4),\n c + (c_2 + (c_3 + c_4)) = 0, c_2 + (c_3 + c_4) = 0]"
   265 then () else error "eqsystem.sml rewrite in 4x4 simplify_System_paren";
   266 
   267 val SOME (t, _) = rewrite_set_inst_ ctxt true bdvs isolate_bdvs t;
   268 if UnparseC.term t = "[c_4 = 0, \
   269 	        \L * c_3 + c_4 = 0 + - 1 * (- 1 * q_0 * L \<up> 2 / 2),\n \
   270 		\c + (c_2 + (c_3 + c_4)) = 0, c_2 + (c_3 + c_4) = 0]"
   271 then () else error "eqsystem.sml rewrite in 4x4 isolate_bdvs";
   272 
   273 val SOME(t, _)= rewrite_set_inst_ ctxt true bdvs simplify_System_parenthesized t;
   274 if UnparseC.term t = "[c_4 = 0,\
   275 		\ L * c_3 + c_4 = q_0 * L \<up> 2 / 2,\
   276 		\ c + (c_2 + (c_3 + c_4)) = 0,\n\
   277 		\ c_2 + (c_3 + c_4) = 0]"
   278 then () else error "eqsystem.sml rewrite in 4x4 simplify_System_p..2";
   279 
   280 val SOME (t, _) = rewrite_set_ ctxt true order_system t;
   281 if UnparseC.term t = "[c_4 = 0,\
   282 		\ L * c_3 + c_4 = q_0 * L \<up> 2 / 2,\
   283 		\ c_2 + (c_3 + c_4) = 0,\n\
   284 		\ c + (c_2 + (c_3 + c_4)) = 0]"
   285 then () else error "eqsystem.sml rewrite in 4x4 order_system";
   286 
   287 
   288 
   289 "----------- refine [linear,system]-------------------------------";
   290 "----------- refine [linear,system]-------------------------------";
   291 "----------- refine [linear,system]-------------------------------";
   292 val fmz =
   293   ["equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2," ^
   294                "0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + (c_2::real)]", 
   295 	   "solveForVars [c, c_2]", "solution LL"];
   296 
   297 (*WN120313 in "solution L" above "Refine.xxxxx @{context} fmz ["LINEAR", "system"]" caused an error...*)
   298 "~~~~~ fun Refine.refine , args:"; val ((fmz: Formalise.model), (pblID:Problem.id)) = (fmz, ["LINEAR", "system"]);
   299 "~~~~~ fun refin' , args:"; val ((pblRD: Problem.id_reverse), fmz, pbls, ((Store.Node (pI, [py], [])): Problem.T Store.node)) =
   300    ((rev o tl) pblID, fmz, [(*match list*)],
   301      ((Store.Node ("LINEAR", [Problem.from_store ctxt ["LINEAR", "system"]], [])): Problem.T Store.node));
   302       val {thy, model, where_, where_rls, ...} = py ;
   303 "~~~~~ fun O_Model.init, args:"; val (thy, fmz, pbt) = (thy, fmz, model);
   304         val ctxt = Proof_Context.init_global thy;
   305 "~~~~~ fun declare_constraints, args:"; val (t, ctxt) = (nth 1 fmz, ctxt);
   306       fun get_vars ((v,T)::vs) = (case raw_explode v |> Library.read_int of
   307               (_, _::_) => (Free (v,T)::get_vars vs)
   308             | (_, []  ) => get_vars vs) (*filter out nums as long as 
   309                                           we have Free ("123",_)*)
   310         | get_vars [] = [];
   311                                         t = "equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,"^
   312                                             "0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + (c_2::real)]";
   313       val ts = Term.add_frees (Syntax.read_term ctxt t) [] |> get_vars;
   314 val ctxt = Variable.declare_constraints (nth 1 ts) ctxt;
   315 val ctxt = Variable.declare_constraints (nth 2 ts) ctxt;
   316 val ctxt = Variable.declare_constraints (nth 3 ts) ctxt;
   317 val ctxt = Variable.declare_constraints (nth 4 ts) ctxt;
   318                                         val t = nth 2 fmz; t = "solveForVars [c, c_2]";
   319       val ts = Term.add_frees (Syntax.read_term ctxt t) [] |> get_vars;
   320 val ctxt = Variable.declare_constraints (nth 1 ts) ctxt;
   321                                         val t = nth 3 fmz; t = "solution LL";
   322       (*(Syntax.read_term ctxt t); 
   323 Type unification failed: Clash of types "real" and "_ list"
   324 Type error in application: incompatible operand type
   325 
   326 Operator:  solution :: bool list \<Rightarrow> toreall
   327 Operand:   L :: real                 ========== L was already present in equalities ========== *)
   328 
   329 "===== case 1 =====";
   330 val matches = Refine.xxxxx @{context} fmz ["LINEAR", "system"];
   331 case matches of 
   332  [M_Match.Matches (["LINEAR", "system"], _),                      (*Matches*)
   333   M_Match.Matches (["2x2", "LINEAR", "system"], _),               (*NoMatch ! GOON !*)
   334   M_Match.NoMatch (["triangular", "2x2", "LINEAR", "system"], _), (**)
   335   M_Match.Matches (["normalise", "2x2", "LINEAR", "system"],      (**)
   336     {Find = [Correct "solution LL"], With = [],                   (**)
   337     Given = [Correct "equalities\n [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,\n  0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]",
   338              Correct "solveForVars [c, c_2]"],
   339     Where = [],
   340     Relate = []})] => ()
   341 | _ => error "eqsystem.sml Refine.refine ['normalise','2x2'...]";
   342 
   343 "===== case 2 =====";
   344 val fmz = ["equalities [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]", 
   345 	   "solveForVars [c, c_2]", "solution LL"];
   346 val matches = Refine.xxxxx @{context} fmz ["LINEAR", "system"];
   347 case matches of [_,_,
   348 		  M_Match.Matches
   349 		    (["triangular", "2x2", "LINEAR", "system"],
   350 		      {Find = [Correct "solution LL"],
   351 		       With = [],
   352 		       Given =
   353 		        [Correct "equalities [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]",
   354 		         Correct "solveForVars [c, c_2]"],
   355 		       Where = [Correct
   356 			"tl [c, c_2] from [c, c_2] occur_exactly_in NTH 1\n      [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]",
   357 			                Correct
   358 				"[c, c_2] from [c, c_2] occur_exactly_in NTH 2\n   [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]"],
   359 		       Relate = []})] => ()
   360 | _ => error "eqsystem.sml Refine.refine ['triangular','2x2'...]";
   361 
   362 (*WN051014-----------------------------------------------------------------------------------\\
   363   the above 'val matches = Refine.xxxxx @{context} fmz ["LINEAR", "system"]'
   364   didn't work anymore; we investigated in these steps:*)
   365 val fmz = ["equalities [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]", 
   366 	  "solveForVars [c, c_2]", "solution LL"];
   367 val matches = Refine.xxxxx @{context} fmz ["triangular", "2x2", "LINEAR", "system"];
   368 (*... resulted in 
   369    False "[c, c_2] from_ [c, c_2] occur_exactly_in nth_ 2\n    
   370           [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]"]*)
   371 val t = TermC.parse_test @{context} ("[c, c_2] from [c, c_2] occur_exactly_in NTH 2" ^   
   372 		  "[c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]");
   373 
   374 val SOME (t', _) = rewrite_set_ ctxt false prls_triangular t;
   375 (*found:...
   376 ##  try thm: NTH_CONS
   377 ###  eval asms: 1 < 2 + - 1
   378 ==> nth_ (2 + - 1) [L * c + c_2 = q_0 * L \<up> 2 / 2] =
   379     nth_ (2 + - 1 + - 1) []
   380 ####  rls: erls_prls_triangular on: 1 < 2 + - 1
   381 #####  try calc: op <'
   382 ###  asms accepted: ["1 < 2 + - 1"]   stored: ["1 < 2 + - 1"]
   383 
   384 ... i.e Eval ("Groups.plus_class.plus", Calc_Binop.numeric "#add_") was missing in erls_prls_triangular*)
   385 (*--------------------------------------------------------------------------------------------//*)
   386 
   387 
   388 "===== case 3: relaxed preconditions for triangular system =====";
   389 val fmz = ["equalities [L * q_0 = c,                               \
   390 	   \            0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2,\
   391 	   \            0 = c_4,                                           \
   392 	   \            0 = c_3]", 
   393 	   "solveForVars [c, c_2, c_3, c_4]", "solution LL"];
   394 (*============ inhibit exn WN120314 TODO: investigate type error (same) in these 2 cases:
   395 probably exn thrown by fun declare_constraints
   396 /-------------------------------------------------------\
   397 Type unification failed
   398 Type error in application: incompatible operand type
   399 
   400 Operator:  op # c_3 :: 'a list \<Rightarrow> 'a list
   401 Operand:   [c_4] :: 'b list
   402 \-------------------------------------------------------/
   403 val TermC.matches = Refine.refine fmz ["LINEAR", "system"];
   404 case TermC.matches of 
   405     [M_Match.Matches (["LINEAR", "system"], _),
   406      M_Match.NoMatch (["2x2", "LINEAR", "system"], _),
   407      M_Match.NoMatch (["3x3", "LINEAR", "system"], _),
   408      M_Match.Matches (["4x4", "LINEAR", "system"], _),
   409      M_Match.NoMatch (["triangular", "4x4", "LINEAR", "system"], _),
   410      M_Match.Matches (["normalise", "4x4", "LINEAR", "system"], _)] => ()
   411   | _ => error "eqsystem.sml: Refine.refine relaxed triangular sys M_Match.NoMatch";
   412 (*WN060914 does NOT match, because 3rd and 4th equ are not ordered*)
   413 
   414 "===== case 4 =====";
   415 val fmz = ["equalities [L * q_0 = c,                                       \
   416 	   \            0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2,\
   417 	   \            0 = c_3,                           \
   418 	   \            0 = c_4]", 
   419 	   "solveForVars [c, c_2, c_3, c_4]", "solution LL"];
   420 val TermC.matches = Refine.refine fmz ["triangular", "4x4", "LINEAR", "system"];
   421 case TermC.matches of 
   422     [M_Match.Matches (["triangular", "4x4", "LINEAR", "system"], _)] => ()
   423   | _ => error "eqsystem.sml: Refine.refine relaxed triangular sys M_Match.NoMatch";
   424 val TermC.matches = Refine.refine fmz ["LINEAR", "system"];
   425 ============ inhibit exn WN120314 ==============================================*)
   426 
   427 
   428 
   429 "----------- Refine.refine [2x2,linear,system] search error--------------";
   430 "----------- Refine.refine [2x2,linear,system] search error--------------";
   431 "----------- Refine.refine [2x2,linear,system] search error--------------";
   432 (*didn't go into ["2x2", "LINEAR", "system"]; 
   433   we investigated in these steps:*)
   434 val fmz = ["equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,\
   435 	               \0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]", 
   436 	   "solveForVars [c, c_2]", "solution LL"];
   437 val matches = Refine.xxxxx @{context} fmz ["2x2", "LINEAR", "system"];
   438 (*default_print_depth 11;*) TermC.matches; (*default_print_depth 3;*)
   439 (*brought: 'False "length_ es_ = 2"'*)
   440 
   441 (*-----fun refin' (pblRD:Problem.id_reverse) fmz pbls ((Store.Node (pI,[py],[])):pbt Store.store) =
   442 (* val ((pblRD:Problem.id_reverse), fmz, pbls, ((Store.Node (pI,[py],[])):pbt Store.store)) =
   443        (rev ["LINEAR", "system"], fmz, [(*match list*)],
   444 	((Store.Node ("2x2",[Problem.from_store ["2x2", "LINEAR", "system"]],[])):pbt Store.store));
   445    *)
   446 > show_types:=true; UnparseC.term (hd where_); show_types:=false;
   447 val it = "length_ (es_::real list) = (2::real)" : string
   448 
   449 =========================================================================\
   450 -------fun Problem.prep_input
   451 (* val (thy, (pblID, dsc_dats: (string * (string list)) list, 
   452 		  ev:rls, ca: string option, metIDs:metID list)) =
   453        (EqSystem.thy, (["system"],
   454 		       [("#Given" ,["equalities es_", "solveForVars v_s"]),
   455 			("#Find"  ,["solution ss___"](*___ is copy-named*))
   456 			],
   457 		       Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)], 
   458 		       SOME "solveSystem es_ v_s", 
   459 		       []));
   460    *)
   461 > val [("#Given", [equalities_es_, "solveForVars v_s"])] = gi;
   462 val equalities_es_ = "equalities es_" : string
   463 > val (dd, ii) = ((Model_Pattern.split_descriptor ctxt)  o Thm.term_of o the o (TermC.parse thy)) equalities_es_;
   464 > show_types:=true; UnparseC.term ii; show_types:=false;
   465 val it = "es_::bool list" : string
   466 ~~~~~~~~~~~~~~~ \<up> \<up> \<up>  OK~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   467 
   468 > val {where_,...} = Problem.from_store ["2x2", "LINEAR", "system"];
   469 > show_types:=true; UnparseC.term (hd where_); show_types:=false;
   470 
   471 =========================================================================/
   472 
   473 -----fun refin' ff:
   474 > (writeln o (I_Model.to_string (Proof_Context.init_global @{theory Isac_Knowledge}))) itms;
   475 [
   476 (1 ,[1] ,true ,#Given ,Cor equalities
   477  [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,
   478   0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2] ,(es_, [[0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,
   479  0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]])),
   480 (2 ,[1] ,true ,#Given ,Cor solveForVars [c, c_2] ,(v_s, [[c, c_2]])),
   481 (3 ,[1] ,true ,#Find ,Cor solution L ,(ss___, [L]))]
   482 
   483 > (writeln o pres2str) pre';
   484 [
   485 (false, length_ es_ = 2),
   486 (true, length_ [c, c_2] = 2)]
   487 
   488 ----- fun match_oris':
   489 > (writeln o (I_Model.to_string (Proof_Context.init_global @{theory Isac_Knowledge}))) itms;
   490 > (writeln o pres2str) pre';
   491 ..as in refin'
   492 
   493 ----- fun check in Pre_Conds.
   494 > (writeln o env2str) env;
   495 ["
   496 (es_, [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,
   497  0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2])", "
   498 (v_s, [c, c_2])", "
   499 (ss___, L)"]
   500 
   501 > val es_ = (fst o hd) env;
   502 val es_ = Free ("es_", "bool List.list") : Term.term
   503 
   504 > val pre1 = hd pres;
   505 TermC.atom_trace_detail @{context} pre1;
   506 ***
   507 *** Const (op =, [real, real] => bool)
   508 *** . Const (ListG.length_, real list => real)
   509 *** . . Free (es_, real list)
   510 ~~~~~~~~~~~~~~~~~~~ \<up> \<up> \<up>  should be bool list~~~~~~~~~~~~~~~~~~~
   511 *** . Free (2, real)
   512 ***
   513 
   514 THE REASON WAS A non-type-constrained variable IN #WHERE OF PROBLEM
   515 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   516 *)
   517 
   518 
   519 "----------- me [EqSystem,normalise,2x2], refine Subproblem ------------------------------------";
   520 "----------- me [EqSystem,normalise,2x2], refine Subproblem ------------------------------------";
   521 "----------- me [EqSystem,normalise,2x2], refine Subproblem ------------------------------------";
   522 val fmz = ["equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2," ^
   523                        "0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]", 
   524 	   "solveForVars [c, c_2]", "solution LL"];
   525 val (dI',pI',mI') =
   526   ("Biegelinie",["normalise", "2x2", "LINEAR", "system"],
   527    ["EqSystem", "normalise", "2x2"]);
   528 val p = e_pos'; val c = []; 
   529 val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context} [(fmz, (dI',pI',mI'))];
   530 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   531 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   532 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   533 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   534 case nxt of Specify_Method ["EqSystem", "normalise", "2x2"] => ()
   535 	  | _ => error "eqsystem.sml [EqSystem,normalise,2x2] specify";
   536 
   537 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   538 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   539 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   540 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   541 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   542 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   543 case nxt of
   544     (Subproblem ("Biegelinie", ["triangular", "2x2", "LINEAR",_])) => ()
   545   | _ => error "eqsystem.sml me [EqSystem,normalise,2x2] SubProblem";
   546 
   547 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   548 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   549 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   550 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   551 case nxt of
   552     (Specify_Method ["EqSystem", "top_down_substitution", "2x2"]) => ()
   553   | _ => error "eqsystem.sml me [EqSys...2x2] top_down_substitution";
   554 
   555 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   556 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   557 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   558 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   559 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   560 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   561 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   562 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   563 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   564 case nxt of
   565     (Check_Postcond ["triangular", "2x2", "LINEAR", "system"]) => ()
   566   | _ => error "eqsystem.sml me Subpbl .[EqSys...2x2] finished";
   567 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   568 val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
   569 (* final test ... ----------------------------------------------------------------------------*)
   570 if f2str f = "[c = L * q_0 / 2, c_2 = 0]" then ()
   571 else error "eqsystem.sml me [EqSys...2x2] finished f2str f";
   572 
   573 case nxt of
   574     (End_Proof') => ()
   575   | _ => error "eqsystem.sml me [EqSys...2x2] finished End_Proof'";
   576 
   577 Test_Tool.show_pt pt (*[
   578 (([], Frm), solveSystem
   579  [[0 = - 1 * q_0 * 0 \<up> 2 div 2 + 0 * c + c_2],
   580   [0 = - 1 * q_0 * L \<up> 2 div 2 + L * c + c_2]]
   581  [[c], [c_2]]), 
   582 (([1], Frm), [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,
   583  0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]), 
   584 (([1], Res), [0 = c_2, 0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2]), 
   585 (([2], Res), [0 = c_2, 0 = - 1 * q_0 * L \<up> 2 / 2 + (L * c + c_2)]), 
   586 (([3], Res), [c_2 = 0, L * c + c_2 = 0 + - 1 * (- 1 * q_0 * L \<up> 2 / 2)]), 
   587 (([4], Res), [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]), 
   588 (([5], Pbl), solveSystem [L * c + c_2 = q_0 * L \<up> 2 / 2] [c_2]), 
   589 (([5, 1], Frm), L * c + c_2 = q_0 * L \<up> 2 / 2), 
   590 (([5, 1], Res), L * c + 0 = q_0 * L \<up> 2 / 2), 
   591 (([5, 2], Res), L * c = q_0 * L \<up> 2 / 2), 
   592 (([5, 3], Res), c = q_0 * L \<up> 2 / 2 / L), 
   593 (([5, 4], Res), c = L * q_0 / 2), 
   594 (([5, 5], Frm), [c_2 = 0, c = L * q_0 / 2]), 
   595 (([5, 5], Res), [c = L * q_0 / 2, c_2 = 0]), 
   596 (([5], Res), [c = L * q_0 / 2, c_2 = 0]), 
   597 (([], Res), [c = L * q_0 / 2, c_2 = 0])] 
   598 *)