1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/Tools/isac/Knowledge/eqsystem-1.sml Tue Aug 03 19:16:27 2021 +0200
1.3 @@ -0,0 +1,580 @@
1.4 +(* Title: Knowledge/eqsystem-1.sml
1.5 + author: Walther Neuper 050826,
1.6 + (c) due to copyright terms
1.7 +*)
1.8 +
1.9 +Rewrite.trace_on := false; (*true false*)
1.10 +"-----------------------------------------------------------------";
1.11 +"table of contents -----------------------------------------------";
1.12 +"-----------------------------------------------------------------";
1.13 +"----------- occur_exactly_in ------------------------------------";
1.14 +"----------- problems --------------------------------------------";
1.15 +"----------- rewrite-order ord_simplify_System -------------------";
1.16 +"----------- rewrite in [EqSystem,normalise,2x2] -----------------";
1.17 +"----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
1.18 +"----------- rewrite in [EqSystem,top_down_substitution,2x2] -----";
1.19 +"----------- rewrite in [EqSystem,normalise,4x4] -----------------";
1.20 +"----------- script [EqSystem,top_down_substitution,2x2] Vers.1 --";
1.21 +"----------- refine [linear,system]-------------------------------";
1.22 +"----------- refine [2x2,linear,system] search error--------------";
1.23 +"----------- me [EqSystem,normalise,2x2] -------------------------";
1.24 +(*^^^--- eqsystem-1.sml #####################################################################
1.25 + vvv--- eqsystem-2.sml #####################################################################*)
1.26 +"----------- me [linear,system] ..normalise..top_down_sub..-------";
1.27 +"----------- all systems from Biegelinie -------------------------";
1.28 +"----------- 4x4 systems from Biegelinie -------------------------";
1.29 +"-----------------------------------------------------------------";
1.30 +"-----------------------------------------------------------------";
1.31 +"-----------------------------------------------------------------";
1.32 +
1.33 +val thy = @{theory "EqSystem"};
1.34 +val ctxt = Proof_Context.init_global thy;
1.35 +
1.36 +"----------- occur_exactly_in ------------------------------------";
1.37 +"----------- occur_exactly_in ------------------------------------";
1.38 +"----------- occur_exactly_in ------------------------------------";
1.39 +val all = [TermC.str2term"c", TermC.str2term"c_2", TermC.str2term"c_3"];
1.40 +val t = TermC.str2term"0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2";
1.41 +
1.42 +if occur_exactly_in [TermC.str2term"c", TermC.str2term"c_2"] all t
1.43 +then () else error "eqsystem.sml occur_exactly_in 1";
1.44 +
1.45 +if not (occur_exactly_in [TermC.str2term"c", TermC.str2term"c_2", TermC.str2term"c_3"] all t)
1.46 +then () else error "eqsystem.sml occur_exactly_in 2";
1.47 +
1.48 +if not (occur_exactly_in [TermC.str2term"c_2"] all t)
1.49 +then () else error "eqsystem.sml occur_exactly_in 3";
1.50 +
1.51 +val t = TermC.str2term"[c,c_2] from [c,c_2,c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2";
1.52 +eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
1.53 +val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
1.54 +if str = "[c, c_2] from [c, c_2,\n" ^
1.55 + " c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 = True"
1.56 +then () else error "eval_occur_exactly_in [c, c_2]";
1.57 +
1.58 +val t = TermC.str2term ("[c,c_2,c_3] from [c,c_2,c_3] occur_exactly_in " ^
1.59 + "- 1 * q_0 * L \<up> 2 / 2 + L * c + c_2");
1.60 +val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
1.61 +if str = "[c, c_2,\n c_3] from [c, c_2,\n" ^
1.62 +" c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 = False"
1.63 +then () else error "eval_occur_exactly_in [c, c_2, c_3]";
1.64 +
1.65 +val t = TermC.str2term"[c_2] from [c,c_2,c_3] occur_exactly_in \
1.66 + \- 1 * q_0 * L \<up> 2 / 2 + L * c + c_2";
1.67 +val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
1.68 +if str = "[c_2] from [c, c_2,\n" ^
1.69 + " c_3] occur_exactly_in - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2 = False"
1.70 +then () else error "eval_occur_exactly_in [c, c_2, c_3]";
1.71 +
1.72 +val t = TermC.str2term"[] from [c,c_2,c_3] occur_exactly_in 0";
1.73 +val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
1.74 +if str = "[] from [c, c_2, c_3] occur_exactly_in 0 = True" then ()
1.75 +else error "eval_occur_exactly_in [c, c_2, c_3]";
1.76 +
1.77 +val t =
1.78 + TermC.str2term
1.79 + "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) /2";
1.80 +val SOME (str, t') = eval_occur_exactly_in 0 "EqSystem.occur_exactly_in" t 0;
1.81 +if str = "[] from [c, c_2, c_3, c_4] occur_exactly_in \
1.82 + \- 1 * (q_0 * L \<up> 2) / 2 = True" then ()
1.83 +else error "eval_occur_exactly_in [c, c_2, c_3, c_4]";
1.84 +
1.85 +"----------- problems --------------------------------------------";
1.86 +"----------- problems --------------------------------------------";
1.87 +"----------- problems --------------------------------------------";
1.88 +val t = TermC.str2term "Length [x+y=1,y=2] = 2";
1.89 +TermC.atomty t;
1.90 +val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty
1.91 + [(Thm ("LENGTH_NIL", @{thm LENGTH_NIL})),
1.92 + (Thm ("LENGTH_CONS", @{thm LENGTH_CONS})),
1.93 + Eval (\<^const_name>\<open>plus\<close>, eval_binop "#add_"),
1.94 + Eval (\<^const_name>\<open>HOL.eq\<close>,eval_equal "#equal_")
1.95 + ];
1.96 +val SOME (t',_) = rewrite_set_ thy false testrls t;
1.97 +if UnparseC.term t' = "True" then ()
1.98 +else error "eqsystem.sml: length_ [x+y=1,y=2] = 2";
1.99 +
1.100 +val SOME t = TermC.parse thy "solution LL";
1.101 +TermC.atomty (Thm.term_of t);
1.102 +val SOME t = TermC.parse thy "solution LL";
1.103 +TermC.atomty (Thm.term_of t);
1.104 +
1.105 +val t = TermC.str2term
1.106 +"(tl (tl (tl v_s))) from v_s occur_exactly_in (NTH 1 (e_s::bool list))";
1.107 +TermC.atomty t;
1.108 +val t = TermC.str2term ("(tl (tl (tl [c, c_2, c_3, c_4]))) from [c, c_2, c_3, c_4] occur_exactly_in " ^
1.109 + "(NTH 1 [c_4 = 1, 2 = 2, 3 = 3, 4 = 4])");
1.110 +(*----- broken in child of.1790e1073acc : eliminate "handle _ => ..." from Rewrite.rewrite -----\\
1.111 + assume flawed test setup hidden by "handle _ => ..."
1.112 + ERROR rewrite__set_ called with 'Erls' for '1 < 1'
1.113 +val SOME (t,_) =
1.114 + rewrite_set_ thy true
1.115 + (Rule_Set.append_rules "prls_" Rule_Set.empty
1.116 + [Thm ("NTH_CONS",ThmC.numerals_to_Free @{thm NTH_CONS}),
1.117 + Thm ("NTH_NIL",ThmC.numerals_to_Free @{thm NTH_NIL}),
1.118 + Thm ("TL_CONS",ThmC.numerals_to_Free @{thm tl_Cons}),
1.119 + Thm ("TL_NIL",ThmC.numerals_to_Free @{thm tl_Nil}),
1.120 + Eval ("EqSystem.occur_exactly_in", eval_occur_exactly_in "#eval_occur_exactly_in_")
1.121 + ]) t;
1.122 +if t = @{term True} then ()
1.123 +else error "eqsystem.sml ..occur_exactly_in (nth_ 1 [c_4..";
1.124 + broken in child of.1790e1073acc : eliminate "handle _ => ..." from Rewrite.rewrite ---//*)
1.125 +
1.126 +
1.127 +"----------- rewrite-order ord_simplify_System -------------------";
1.128 +"----------- rewrite-order ord_simplify_System -------------------";
1.129 +"----------- rewrite-order ord_simplify_System -------------------";
1.130 +"M_b x = c * x + - 1 * q_0 * (x \<up> 2 / 2) + c_2";
1.131 +"--- add.commute ---"; (* ... add.commute cf. b42e334c97ee *)
1.132 +if ord_simplify_System false thy [] (TermC.str2term"- 1 * q_0 * (x \<up> 2 / 2)",
1.133 + TermC.str2term"c * x") then ()
1.134 +else error "integrate.sml, (- 1 * q_0 * (x \<up> 2 / 2)) < (c * x) not#1";
1.135 +
1.136 +if ord_simplify_System false thy [] (TermC.str2term"- 1 * q_0 * (x \<up> 2 / 2)",
1.137 + TermC.str2term"c_2") then ()
1.138 +else error "integrate.sml, (- 1 * q_0 * (x \<up> 2 / 2)) < (c_2) not#2";
1.139 +
1.140 +if ord_simplify_System false thy [] (TermC.str2term"c * x",
1.141 + TermC.str2term"c_2") then ()
1.142 +else error "integrate.sml, (c * x) < (c_2) not#3";
1.143 +
1.144 +"--- mult.commute ---";
1.145 +if ord_simplify_System false thy [] (TermC.str2term"x * c",
1.146 + TermC.str2term"c * x") then ()
1.147 +else error "integrate.sml, (x * c) < (c * x) not#4";
1.148 +
1.149 +if ord_simplify_System false thy [] (TermC.str2term"- 1 * q_0 * (x \<up> 2 / 2) * c",
1.150 + TermC.str2term"- 1 * q_0 * c * (x \<up> 2 / 2)")
1.151 +then () else error "integrate.sml, (. * .) < (. * .) not#5";
1.152 +
1.153 +if ord_simplify_System false thy [] (TermC.str2term"- 1 * q_0 * (x \<up> 2 / 2) * c",
1.154 + TermC.str2term"c * - 1 * q_0 * (x \<up> 2 / 2)")
1.155 +then () else error "integrate.sml, (. * .) < (. * .) not#6";
1.156 +
1.157 +
1.158 +"----------- rewrite in [EqSystem,normalise,2x2] -----------------";
1.159 +"----------- rewrite in [EqSystem,normalise,2x2] -----------------";
1.160 +"----------- rewrite in [EqSystem,normalise,2x2] -----------------";
1.161 +val t = TermC.str2term"[0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2,\
1.162 + \0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2]";
1.163 +val bdvs = [(TermC.str2term"bdv_1",TermC.str2term"c"),
1.164 + (TermC.str2term"bdv_2",TermC.str2term"c_2")];
1.165 +val SOME(t,_)= rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
1.166 +if UnparseC.term t = "[0 = - 1 * q_0 * L \<up> 2 / 2 + (L * c + c_2), 0 = c_2]"
1.167 +then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.1";
1.168 +
1.169 +val SOME (t,_) = rewrite_set_inst_ thy true bdvs isolate_bdvs t;
1.170 +if UnparseC.term t = "[L * c + c_2 = 0 + - 1 * (- 1 * q_0 * L \<up> 2 / 2), c_2 = 0]"
1.171 +then () else error "eqsystem.sml rewrite in 2x2 isolate_bdvs";
1.172 +
1.173 +val SOME(t,_)= rewrite_set_inst_ thy true bdvs simplify_System t;
1.174 +if UnparseC.term t = "[L * c + c_2 = q_0 * L \<up> 2 / 2, c_2 = 0]"
1.175 +then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.2";
1.176 +
1.177 +"--- 3--- see EqSystem.thy (*..if replaced by 'and' ...*)";
1.178 +val SOME (t,_) = rewrite_set_ thy true order_system t;
1.179 +if UnparseC.term t = "[c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]"
1.180 +then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.3";
1.181 +
1.182 +"----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
1.183 +"----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
1.184 +"----------- rewrite example from 2nd [EqSystem,normalise,2x2] ---";
1.185 +val thy = @{theory "Isac_Knowledge"} (*because of Undeclared constant "Biegelinie.EI*);
1.186 +val t =
1.187 + TermC.str2term"[0 = c_2 + c * 0 + 1 / EI * (L * q_0 / 12 * 0 \<up> 3 + \
1.188 + \ - 1 * q_0 / 24 * 0 \<up> 4),\
1.189 + \ 0 = c_2 + c * L + 1 / EI * (L * q_0 / 12 * L \<up> 3 + \
1.190 + \ - 1 * q_0 / 24 * L \<up> 4)]";
1.191 +val SOME (t, _) = rewrite_set_ thy true norm_Rational t;
1.192 +if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
1.193 + "[c_2 = 0, 0 = q_0 * L \<up> 4 / (24 * EI) + (L * c + c_2)]"*)
1.194 + "[0 = c_2, 0 = (24 * c_2 + 24 * L * c + L \<up> 4 * q_0) / 24]"
1.195 +then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.0b";
1.196 +
1.197 +val SOME(t, _)= rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
1.198 +if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
1.199 + "[c_2 = 0, 0 = q_0 * L \<up> 4 / (24 * EI) + (L * c + c_2)]"*)
1.200 + "[0 = c_2, 0 = q_0 * L \<up> 4 / 24 + (L * c + c_2)]"
1.201 +then () else error "eqsystem.sml rewrite in 2x2 simplify_System_par.1b";
1.202 +
1.203 +val SOME (t,_) = rewrite_set_inst_ thy true bdvs isolate_bdvs t;
1.204 +if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
1.205 + "[c_2 = 0, L * c + c_2 = 0 + - 1 * (q_0 * L \<up> 4 / (24 * EI))]"*)
1.206 + "[c_2 = 0, L * c + c_2 = 0 + - 1 * (q_0 * L \<up> 4 / 24)]"
1.207 +then () else error "eqsystem.sml rewrite in 2x2 isolate_bdvs b";
1.208 +
1.209 +val SOME(t,_)= rewrite_set_inst_ thy true bdvs simplify_System t;
1.210 +if UnparseC.term t = (*BEFORE "eliminate ThmC.numerals_to_Free"..
1.211 + "[c_2 = 0, L * c + c_2 = - 1 * q_0 * L \<up> 4 / (24 * EI)]"*)
1.212 + "[c_2 = 0, L * c + c_2 = - 1 * q_0 * L \<up> 4 / 24]"
1.213 +then () else error "eqsystem.sml rewrite in 2x2 simplify_System.2b";
1.214 +
1.215 +val xxx = rewrite_set_ thy true order_system t;
1.216 +if is_none xxx
1.217 +then () else error "eqsystem.sml rewrite in 2x2 simplify_System.3b";
1.218 +
1.219 +
1.220 +"----------- rewrite in [EqSystem,top_down_substitution,2x2] -----";
1.221 +"----------- rewrite in [EqSystem,top_down_substitution,2x2] -----";
1.222 +"----------- rewrite in [EqSystem,top_down_substitution,2x2] -----";
1.223 +val e1__ = TermC.str2term "c_2 = 77";
1.224 +val e2__ = TermC.str2term "L * c + c_2 = q_0 * L \<up> 2 / 2";
1.225 +val bdvs = [(TermC.str2term"bdv_1",TermC.str2term"c"),
1.226 + (TermC.str2term"bdv_2",TermC.str2term"c_2")];
1.227 +val SOME (e2__,_) = rewrite_terms_ thy dummy_ord Rule_Set.Empty [e1__] e2__;
1.228 +if UnparseC.term e2__ = "L * c + 77 = q_0 * L \<up> 2 / 2" then ()
1.229 +else error "eqsystem.sml top_down_substitution,2x2] subst";
1.230 +
1.231 +val SOME (e2__,_) =
1.232 + rewrite_set_inst_ thy true bdvs simplify_System_parenthesized e2__;
1.233 +if UnparseC.term e2__ = "77 + L * c = q_0 * L \<up> 2 / 2" then ()
1.234 +else error "eqsystem.sml top_down_substitution,2x2] simpl_par";
1.235 +
1.236 +val SOME (e2__,_) = rewrite_set_inst_ thy true bdvs isolate_bdvs e2__;
1.237 +if UnparseC.term e2__ = "c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L" then ()
1.238 +else error "eqsystem.sml top_down_substitution,2x2] isolate";
1.239 +
1.240 +val t = TermC.str2term "[c_2 = 77, c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L]";
1.241 +val SOME (t,_) = rewrite_set_ thy true order_system t;
1.242 +if UnparseC.term t = "[c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L, c_2 = 77]" then ()
1.243 +else error "eqsystem.sml top_down_substitution,2x2] order_system";
1.244 +
1.245 +if not (ord_simplify_System
1.246 + false thy []
1.247 + (TermC.str2term"[c_2 = 77, c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L]",
1.248 + TermC.str2term"[c = (q_0 * L \<up> 2 / 2 + - 1 * 77) / L, c_2 = 77]"))
1.249 +then () else error "eqsystem.sml, order_result rew_ord";
1.250 +
1.251 +
1.252 +"----------- rewrite in [EqSystem,normalise,4x4] -----------------";
1.253 +"----------- rewrite in [EqSystem,normalise,4x4] -----------------";
1.254 +"----------- rewrite in [EqSystem,normalise,4x4] -----------------";
1.255 +(*STOPPED.WN06?: revise rewrite in [EqSystem,normalise,4x4] from before 0609*)
1.256 +val t = TermC.str2term (
1.257 + "[(0::real) = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c_3 + c_4, " ^
1.258 + "(0::real) = - 1 * q_0 * L \<up> 2 / 2 + L * c_3 + c_4, " ^
1.259 + "c + c_2 + c_3 + c_4 = 0, " ^
1.260 + "c_2 + c_3 + c_4 = 0]");
1.261 +val bdvs = [(TermC.str2term"bdv_1::real",TermC.str2term"c::real"),
1.262 + (TermC.str2term"bdv_2::real",TermC.str2term"c_2::real"),
1.263 + (TermC.str2term"bdv_3::real",TermC.str2term"c_3::real"),
1.264 + (TermC.str2term"bdv_4::real",TermC.str2term"c_4::real")];
1.265 +val SOME (t, _) =
1.266 + rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
1.267 +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]"
1.268 +then () else error "eqsystem.sml rewrite in 4x4 simplify_System_paren";
1.269 +
1.270 +val SOME (t, _) = rewrite_set_inst_ thy true bdvs isolate_bdvs t;
1.271 +if UnparseC.term t = "[c_4 = 0, \
1.272 + \L * c_3 + c_4 = 0 + - 1 * (- 1 * q_0 * L \<up> 2 / 2),\n \
1.273 + \c + (c_2 + (c_3 + c_4)) = 0, c_2 + (c_3 + c_4) = 0]"
1.274 +then () else error "eqsystem.sml rewrite in 4x4 isolate_bdvs";
1.275 +
1.276 +val SOME(t, _)= rewrite_set_inst_ thy true bdvs simplify_System_parenthesized t;
1.277 +if UnparseC.term t = "[c_4 = 0,\
1.278 + \ L * c_3 + c_4 = q_0 * L \<up> 2 / 2,\
1.279 + \ c + (c_2 + (c_3 + c_4)) = 0,\n\
1.280 + \ c_2 + (c_3 + c_4) = 0]"
1.281 +then () else error "eqsystem.sml rewrite in 4x4 simplify_System_p..2";
1.282 +
1.283 +val SOME (t, _) = rewrite_set_ thy true order_system t;
1.284 +if UnparseC.term t = "[c_4 = 0,\
1.285 + \ L * c_3 + c_4 = q_0 * L \<up> 2 / 2,\
1.286 + \ c_2 + (c_3 + c_4) = 0,\n\
1.287 + \ c + (c_2 + (c_3 + c_4)) = 0]"
1.288 +then () else error "eqsystem.sml rewrite in 4x4 order_system";
1.289 +
1.290 +"----------- refine [linear,system]-------------------------------";
1.291 +"----------- refine [linear,system]-------------------------------";
1.292 +"----------- refine [linear,system]-------------------------------";
1.293 +val fmz =
1.294 + ["equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2," ^
1.295 + "0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + (c_2::real)]",
1.296 + "solveForVars [c, c_2]", "solution LL"];
1.297 +
1.298 +(*WN120313 in "solution L" above "Refine.refine fmz ["LINEAR", "system"]" caused an error...*)
1.299 +"~~~~~ fun Refine.refine, args:"; val ((fmz: Formalise.model), (pblID:Problem.id)) = (fmz, ["LINEAR", "system"]);
1.300 +"~~~~~ fun refin', args:"; val ((pblRD: Problem.id_reverse), fmz, pbls, ((Store.Node (pI, [py], [])): Problem.T Store.node)) =
1.301 + ((rev o tl) pblID, fmz, [(*match list*)],
1.302 + ((Store.Node ("LINEAR", [Problem.from_store ["LINEAR", "system"]], [])): Problem.T Store.node));
1.303 + val {thy, ppc, where_, prls, ...} = py ;
1.304 +"~~~~~ fun O_Model.init, args:"; val (fmz, thy, pbt) = (fmz, thy, ppc);
1.305 + val ctxt = Proof_Context.init_global thy;
1.306 +"~~~~~ fun declare_constraints, args:"; val (t, ctxt) = (nth 1 fmz, ctxt);
1.307 + fun get_vars ((v,T)::vs) = (case raw_explode v |> Library.read_int of
1.308 + (_, _::_) => (Free (v,T)::get_vars vs)
1.309 + | (_, [] ) => get_vars vs) (*filter out nums as long as
1.310 + we have Free ("123",_)*)
1.311 + | get_vars [] = [];
1.312 + t = "equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,"^
1.313 + "0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + (c_2::real)]";
1.314 + val ts = Term.add_frees (Syntax.read_term ctxt t) [] |> get_vars;
1.315 +val ctxt = Variable.declare_constraints (nth 1 ts) ctxt;
1.316 +val ctxt = Variable.declare_constraints (nth 2 ts) ctxt;
1.317 +val ctxt = Variable.declare_constraints (nth 3 ts) ctxt;
1.318 +val ctxt = Variable.declare_constraints (nth 4 ts) ctxt;
1.319 + val t = nth 2 fmz; t = "solveForVars [c, c_2]";
1.320 + val ts = Term.add_frees (Syntax.read_term ctxt t) [] |> get_vars;
1.321 +val ctxt = Variable.declare_constraints (nth 1 ts) ctxt;
1.322 + val t = nth 3 fmz; t = "solution LL";
1.323 + (*(Syntax.read_term ctxt t);
1.324 +Type unification failed: Clash of types "real" and "_ list"
1.325 +Type error in application: incompatible operand type
1.326 +
1.327 +Operator: solution :: bool list \<Rightarrow> toreall
1.328 +Operand: L :: real ========== L was already present in equalities ========== *)
1.329 +
1.330 +"===== case 1 =====";
1.331 +val matches = Refine.refine fmz ["LINEAR", "system"];
1.332 +case matches of
1.333 + [M_Match.Matches (["LINEAR", "system"], _),
1.334 + M_Match.Matches (["2x2", "LINEAR", "system"], _),
1.335 + M_Match.NoMatch (["triangular", "2x2", "LINEAR", "system"], _),
1.336 + M_Match.Matches (["normalise", "2x2", "LINEAR", "system"],
1.337 + {Find = [Correct "solution LL"],
1.338 + With = [],
1.339 + Given =
1.340 + [Correct
1.341 + "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]",
1.342 + Correct "solveForVars [c, c_2]"],
1.343 + Where = [],
1.344 + Relate = []})] => ()
1.345 +| _ => error "eqsystem.sml Refine.refine ['normalise','2x2'...]";
1.346 +
1.347 +"===== case 2 =====";
1.348 +val fmz = ["equalities [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]",
1.349 + "solveForVars [c, c_2]", "solution LL"];
1.350 +val matches = Refine.refine fmz ["LINEAR", "system"];
1.351 +case matches of [_,_,
1.352 + M_Match.Matches
1.353 + (["triangular", "2x2", "LINEAR", "system"],
1.354 + {Find = [Correct "solution LL"],
1.355 + With = [],
1.356 + Given =
1.357 + [Correct "equalities [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]",
1.358 + Correct "solveForVars [c, c_2]"],
1.359 + Where = [Correct
1.360 + "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]",
1.361 + Correct
1.362 + "[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]"],
1.363 + Relate = []})] => ()
1.364 +| _ => error "eqsystem.sml Refine.refine ['triangular','2x2'...]";
1.365 +
1.366 +(*WN051014-----------------------------------------------------------------------------------\\
1.367 + the above 'val matches = Refine.refine fmz ["LINEAR", "system"]'
1.368 + didn't work anymore; we investigated in these steps:*)
1.369 +val fmz = ["equalities [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]",
1.370 + "solveForVars [c, c_2]", "solution LL"];
1.371 +val matches = Refine.refine fmz ["triangular", "2x2", "LINEAR", "system"];
1.372 +(*... resulted in
1.373 + False "[c, c_2] from_ [c, c_2] occur_exactly_in nth_ 2\n
1.374 + [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]"]*)
1.375 +val t = TermC.str2term ("[c, c_2] from [c, c_2] occur_exactly_in NTH 2" ^
1.376 + "[c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]");
1.377 +Rewrite.trace_on := false; (*true false*)
1.378 +val SOME (t', _) = rewrite_set_ thy false prls_triangular t;
1.379 +(*found:...
1.380 +## try thm: NTH_CONS
1.381 +### eval asms: 1 < 2 + - 1
1.382 +==> nth_ (2 + - 1) [L * c + c_2 = q_0 * L \<up> 2 / 2] =
1.383 + nth_ (2 + - 1 + - 1) []
1.384 +#### rls: erls_prls_triangular on: 1 < 2 + - 1
1.385 +##### try calc: op <'
1.386 +### asms accepted: ["1 < 2 + - 1"] stored: ["1 < 2 + - 1"]
1.387 +
1.388 +... i.e Eval ("Groups.plus_class.plus", eval_binop "#add_") was missing in erls_prls_triangular*)
1.389 +(*--------------------------------------------------------------------------------------------//*)
1.390 +
1.391 +
1.392 +"===== case 3: relaxed preconditions for triangular system =====";
1.393 +val fmz = ["equalities [L * q_0 = c, \
1.394 + \ 0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2,\
1.395 + \ 0 = c_4, \
1.396 + \ 0 = c_3]",
1.397 + "solveForVars [c, c_2, c_3, c_4]", "solution LL"];
1.398 +(*============ inhibit exn WN120314 TODO: investigate type error (same) in these 2 cases:
1.399 +probably exn thrown by fun declare_constraints
1.400 +/-------------------------------------------------------\
1.401 +Type unification failed
1.402 +Type error in application: incompatible operand type
1.403 +
1.404 +Operator: op # c_3 :: 'a list \<Rightarrow> 'a list
1.405 +Operand: [c_4] :: 'b list
1.406 +\-------------------------------------------------------/
1.407 +val TermC.matches = Refine.refine fmz ["LINEAR", "system"];
1.408 +case TermC.matches of
1.409 + [M_Match.Matches (["LINEAR", "system"], _),
1.410 + M_Match.NoMatch (["2x2", "LINEAR", "system"], _),
1.411 + M_Match.NoMatch (["3x3", "LINEAR", "system"], _),
1.412 + M_Match.Matches (["4x4", "LINEAR", "system"], _),
1.413 + M_Match.NoMatch (["triangular", "4x4", "LINEAR", "system"], _),
1.414 + M_Match.Matches (["normalise", "4x4", "LINEAR", "system"], _)] => ()
1.415 + | _ => error "eqsystem.sml: Refine.refine relaxed triangular sys M_Match.NoMatch";
1.416 +(*WN060914 does NOT match, because 3rd and 4th equ are not ordered*)
1.417 +
1.418 +"===== case 4 =====";
1.419 +val fmz = ["equalities [L * q_0 = c, \
1.420 + \ 0 = (2 * c_2 + 2 * L * c + - 1 * L \<up> 2 * q_0) / 2,\
1.421 + \ 0 = c_3, \
1.422 + \ 0 = c_4]",
1.423 + "solveForVars [c, c_2, c_3, c_4]", "solution LL"];
1.424 +val TermC.matches = Refine.refine fmz ["triangular", "4x4", "LINEAR", "system"];
1.425 +case TermC.matches of
1.426 + [M_Match.Matches (["triangular", "4x4", "LINEAR", "system"], _)] => ()
1.427 + | _ => error "eqsystem.sml: Refine.refine relaxed triangular sys M_Match.NoMatch";
1.428 +val TermC.matches = Refine.refine fmz ["LINEAR", "system"];
1.429 +============ inhibit exn WN120314 ==============================================*)
1.430 +
1.431 +"----------- Refine.refine [2x2,linear,system] search error--------------";
1.432 +"----------- Refine.refine [2x2,linear,system] search error--------------";
1.433 +"----------- Refine.refine [2x2,linear,system] search error--------------";
1.434 +(*didn't go into ["2x2", "LINEAR", "system"];
1.435 + we investigated in these steps:*)
1.436 +val fmz = ["equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,\
1.437 + \0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]",
1.438 + "solveForVars [c, c_2]", "solution LL"];
1.439 +Rewrite.trace_on := false; (*true false*)
1.440 +val matches = Refine.refine fmz ["2x2", "LINEAR", "system"];
1.441 +Rewrite.trace_on := false; (*true false*)
1.442 +(*default_print_depth 11;*) TermC.matches; (*default_print_depth 3;*)
1.443 +(*brought: 'False "length_ es_ = 2"'*)
1.444 +
1.445 +(*-----fun refin' (pblRD:Problem.id_reverse) fmz pbls ((Store.Node (pI,[py],[])):pbt Store.store) =
1.446 +(* val ((pblRD:Problem.id_reverse), fmz, pbls, ((Store.Node (pI,[py],[])):pbt Store.store)) =
1.447 + (rev ["LINEAR", "system"], fmz, [(*match list*)],
1.448 + ((Store.Node ("2x2",[Problem.from_store ["2x2", "LINEAR", "system"]],[])):pbt Store.store));
1.449 + *)
1.450 +> show_types:=true; UnparseC.term (hd where_); show_types:=false;
1.451 +val it = "length_ (es_::real list) = (2::real)" : string
1.452 +
1.453 +=========================================================================\
1.454 +-------fun Problem.prep_input
1.455 +(* val (thy, (pblID, dsc_dats: (string * (string list)) list,
1.456 + ev:rls, ca: string option, metIDs:metID list)) =
1.457 + (EqSystem.thy, (["system"],
1.458 + [("#Given" ,["equalities es_", "solveForVars v_s"]),
1.459 + ("#Find" ,["solution ss___"](*___ is copy-named*))
1.460 + ],
1.461 + Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)],
1.462 + SOME "solveSystem es_ v_s",
1.463 + []));
1.464 + *)
1.465 +> val [("#Given", [equalities_es_, "solveForVars v_s"])] = gi;
1.466 +val equalities_es_ = "equalities es_" : string
1.467 +> val (dd, ii) = (split_did o Thm.term_of o the o (TermC.parse thy)) equalities_es_;
1.468 +> show_types:=true; UnparseC.term ii; show_types:=false;
1.469 +val it = "es_::bool list" : string
1.470 +~~~~~~~~~~~~~~~ \<up> \<up> \<up> OK~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.471 +
1.472 +> val {where_,...} = Problem.from_store ["2x2", "LINEAR", "system"];
1.473 +> show_types:=true; UnparseC.term (hd where_); show_types:=false;
1.474 +
1.475 +=========================================================================/
1.476 +
1.477 +-----fun refin' ff:
1.478 +> (writeln o (I_Model.to_string (ThyC.to_ctxt @{theory Isac_Knowledge}))) itms;
1.479 +[
1.480 +(1 ,[1] ,true ,#Given ,Cor equalities
1.481 + [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,
1.482 + 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,
1.483 + 0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]])),
1.484 +(2 ,[1] ,true ,#Given ,Cor solveForVars [c, c_2] ,(v_s, [[c, c_2]])),
1.485 +(3 ,[1] ,true ,#Find ,Cor solution L ,(ss___, [L]))]
1.486 +
1.487 +> (writeln o pres2str) pre';
1.488 +[
1.489 +(false, length_ es_ = 2),
1.490 +(true, length_ [c, c_2] = 2)]
1.491 +
1.492 +----- fun match_oris':
1.493 +> (writeln o (I_Model.to_string (ThyC.to_ctxt @{theory Isac_Knowledge}))) itms;
1.494 +> (writeln o pres2str) pre';
1.495 +..as in refin'
1.496 +
1.497 +----- fun check in Pre_Conds.
1.498 +> (writeln o env2str) env;
1.499 +["
1.500 +(es_, [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,
1.501 + 0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2])", "
1.502 +(v_s, [c, c_2])", "
1.503 +(ss___, L)"]
1.504 +
1.505 +> val es_ = (fst o hd) env;
1.506 +val es_ = Free ("es_", "bool List.list") : Term.term
1.507 +
1.508 +> val pre1 = hd pres;
1.509 +TermC.atomty pre1;
1.510 +***
1.511 +*** Const (op =, [real, real] => bool)
1.512 +*** . Const (ListG.length_, real list => real)
1.513 +*** . . Free (es_, real list)
1.514 +~~~~~~~~~~~~~~~~~~~ \<up> \<up> \<up> should be bool list~~~~~~~~~~~~~~~~~~~
1.515 +*** . Free (2, real)
1.516 +***
1.517 +
1.518 +THE REASON WAS A non-type-constrained variable IN #WHERE OF PROBLEM
1.519 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.520 +*)
1.521 +
1.522 +"----------- me [EqSystem,normalise,2x2] -------------------------";
1.523 +"----------- me [EqSystem,normalise,2x2] -------------------------";
1.524 +"----------- me [EqSystem,normalise,2x2] -------------------------";
1.525 +val fmz = ["equalities [0 = - 1 * q_0 * 0 \<up> 2 / 2 + 0 * c + c_2,\
1.526 + \0 = - 1 * q_0 * L \<up> 2 / 2 + L * c + c_2]",
1.527 + "solveForVars [c, c_2]", "solution LL"];
1.528 +val (dI',pI',mI') =
1.529 + ("Biegelinie",["normalise", "2x2", "LINEAR", "system"],
1.530 + ["EqSystem", "normalise", "2x2"]);
1.531 +val p = e_pos'; val c = [];
1.532 +val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
1.533 +val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.534 +val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.535 +val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.536 +val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.537 +case nxt of Specify_Method ["EqSystem", "normalise", "2x2"] => ()
1.538 + | _ => error "eqsystem.sml [EqSystem,normalise,2x2] specify";
1.539 +
1.540 +val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.541 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.542 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f(*["(bdv_1, c)", "(bdv_2, hd (tl [c, c_2] ... corrected srls; ran only AFTER use"RCODE-root.sml", store_met was NOT SUFFICIENT*);
1.543 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.544 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.545 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.546 +case nxt of
1.547 + (Subproblem ("Biegelinie", ["triangular", "2x2", "LINEAR",_])) => ()
1.548 + | _ => error "eqsystem.sml me [EqSystem,normalise,2x2] SubProblem";
1.549 +
1.550 +val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.551 +val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.552 +val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.553 +val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.554 +case nxt of
1.555 + (Specify_Method ["EqSystem", "top_down_substitution", "2x2"]) => ()
1.556 + | _ => error "eqsystem.sml me [EqSys...2x2] top_down_substitution";
1.557 +
1.558 +val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.559 +val PblObj {probl,...} = get_obj I pt [5];
1.560 + (writeln o (I_Model.to_string (ThyC.to_ctxt @{theory Isac_Knowledge}))) probl;
1.561 +(*[
1.562 +(1 ,[1] ,true ,#Given ,Cor equalities [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2] ,(es_, [[c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]])),
1.563 +(2 ,[1] ,true ,#Given ,Cor solveForVars [c, c_2] ,(v_s, [[c, c_2]])),
1.564 +(3 ,[1] ,true ,#Find ,Cor solution ss___ ,(ss___, [ss___]))]
1.565 +*)
1.566 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.567 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.568 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.569 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.570 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.571 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.572 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.573 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.574 +case nxt of
1.575 + (Check_Postcond ["triangular", "2x2", "LINEAR", "system"]) => ()
1.576 + | _ => error "eqsystem.sml me Subpbl .[EqSys...2x2] finished";
1.577 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.578 +val (p,_,f,nxt,_,pt) = me nxt p c pt;f2str f;
1.579 +if f2str f = "[c = L * q_0 / 2, c_2 = 0]" then ()
1.580 +else error "eqsystem.sml me [EqSys...2x2] finished f2str f";
1.581 +case nxt of
1.582 + (End_Proof') => ()
1.583 + | _ => error "eqsystem.sml me [EqSys...2x2] finished End_Proof'";