11 "-----------------------------------------------------------------"; |
11 "-----------------------------------------------------------------"; |
12 "------ polyeq- 1.sml ---------------------------------------------"; |
12 "------ polyeq- 1.sml ---------------------------------------------"; |
13 "----------- tests on predicates in problems ---------------------"; |
13 "----------- tests on predicates in problems ---------------------"; |
14 "----------- test matching problems ------------------------------"; |
14 "----------- test matching problems ------------------------------"; |
15 "----------- prep. for introduction of Matthias Goldgruber 2003 trials on rewrite orders -----"; |
15 "----------- prep. for introduction of Matthias Goldgruber 2003 trials on rewrite orders -----"; |
|
16 "----------- open local of fun ord_make_polynomial_in ------------------------------------------"; |
16 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
17 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
17 "----------- lin.eq degree_0 -------------------------------------"; |
18 "----------- lin.eq degree_0 -------------------------------------"; |
18 "----------- test thm's d2_pq_formulsxx[_neg]---------------------"; |
19 "----------- test thm's d2_pq_formulsxx[_neg]---------------------"; |
19 "----------- equality (2 +(- 1)*x + x \<up> 2 = (0::real)) ----------------------------------------"; |
20 "----------- equality (2 +(- 1)*x + x \<up> 2 = (0::real)) ----------------------------------------"; |
20 "----------- equality (- 2 +(- 1)*x + 1*x \<up> 2 = 0) ---------------------------------------------"; |
21 "----------- equality (- 2 +(- 1)*x + 1*x \<up> 2 = 0) ---------------------------------------------"; |
47 "-----------------------------------------------------------------"; |
48 "-----------------------------------------------------------------"; |
48 |
49 |
49 "----------- tests on predicates in problems ---------------------"; |
50 "----------- tests on predicates in problems ---------------------"; |
50 "----------- tests on predicates in problems ---------------------"; |
51 "----------- tests on predicates in problems ---------------------"; |
51 "----------- tests on predicates in problems ---------------------"; |
52 "----------- tests on predicates in problems ---------------------"; |
52 Rewrite.trace_on:=true; (*true false*) |
53 Rewrite.trace_on:=false; (*true false*) |
53 |
54 |
54 val t1 = (Thm.term_of o the o (TermC.parse thy)) "lhs (-8 - 2*x + x \<up> 2 = 0)"; |
55 val t1 = (Thm.term_of o the o (TermC.parse thy)) "lhs (-8 - 2*x + x \<up> 2 = 0)"; |
55 val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t1; |
56 val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t1; |
56 if ((UnparseC.term t) = "-8 - 2 * x + x \<up> 2") then () |
57 if ((UnparseC.term t) = "- 8 - 2 * x + x \<up> 2") then () |
57 else error "polyeq.sml: diff.behav. in lhs"; |
58 else error "polyeq.sml: diff.behav. in lhs"; |
58 |
59 |
59 val t2 = (Thm.term_of o the o (TermC.parse thy)) "(-8 - 2*x + x \<up> 2) is_expanded_in x"; |
60 val t2 = (Thm.term_of o the o (TermC.parse thy)) "(-8 - 2*x + x \<up> 2) is_expanded_in x"; |
60 val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t2; |
61 val SOME (t,_) = rewrite_set_ @{theory PolyEq} false PolyEq_prls t2; |
61 if (UnparseC.term t) = "True" then () |
62 if (UnparseC.term t) = "True" then () |
219 |
220 |
220 val t = (Thm.term_of o the o (parseold thy)) "7"; |
221 val t = (Thm.term_of o the o (parseold thy)) "7"; |
221 ##################################################################################*) |
222 ##################################################################################*) |
222 |
223 |
223 |
224 |
|
225 "----------- open local of fun ord_make_polynomial_in ------------------------------------------"; |
|
226 "----------- open local of fun ord_make_polynomial_in ------------------------------------------"; |
|
227 "----------- open local of fun ord_make_polynomial_in ------------------------------------------"; |
|
228 (* termorder hacked by MG, adapted later by WN *) |
|
229 (** )local ( *. for make_polynomial_in .*) |
|
230 |
|
231 open Term; (* for type order = EQUAL | LESS | GREATER *) |
|
232 |
|
233 fun pr_ord EQUAL = "EQUAL" |
|
234 | pr_ord LESS = "LESS" |
|
235 | pr_ord GREATER = "GREATER"; |
|
236 |
|
237 fun dest_hd' _ (Const (a, T)) = (((a, 0), T), 0) |
|
238 | dest_hd' x (t as Free (a, T)) = |
|
239 if x = t then ((("|||||||||||||", 0), T), 0) (*WN*) |
|
240 else (((a, 0), T), 1) |
|
241 | dest_hd' _ (Var v) = (v, 2) |
|
242 | dest_hd' _ (Bound i) = ((("", i), dummyT), 3) |
|
243 | dest_hd' _ (Abs (_, T, _)) = ((("", 0), T), 4) |
|
244 | dest_hd' _ _ = raise ERROR "dest_hd': uncovered case in fun.def."; |
|
245 |
|
246 fun size_of_term' i pr x (t as Const (\<^const_name>\<open>powr\<close>, _) $ |
|
247 Free (var, _) $ Free (pot, _)) = |
|
248 (if pr then tracing (idt "#" i ^ "size_of_term' powr: " ^ UnparseC.term t) else (); |
|
249 case x of (*WN*) |
|
250 (Free (xstr, _)) => |
|
251 if xstr = var |
|
252 then (if pr then tracing (idt "#" i ^ "xstr = var --> " ^ string_of_int (1000 * (the (TermC.int_opt_of_string pot)))) else (); |
|
253 1000 * (the (TermC.int_opt_of_string pot))) |
|
254 else (if pr then tracing (idt "#" i ^ "x <> Free --> " ^ "3") else (); 3) |
|
255 | _ => raise ERROR ("size_of_term' called with subst = " ^ UnparseC.term x)) |
|
256 | size_of_term' i pr x (t as Abs (_, _, body)) = |
|
257 (if pr then tracing (idt "#" i ^ "size_of_term' Abs: " ^ UnparseC.term t) else (); |
|
258 1 + size_of_term' (i + 1) pr x body) |
|
259 | size_of_term' i pr x (f $ t) = |
|
260 let |
|
261 val _ = if pr then tracing (idt "#" i ^ "size_of_term' $$$: " ^ UnparseC.term f ^ " $$$ " ^ UnparseC.term t) else (); |
|
262 val s1 = size_of_term' (i + 1) pr x f |
|
263 val s2 = size_of_term' (i + 1) pr x t |
|
264 val _ = if pr then tracing (idt "#" i ^ "size_of_term' $$$-->: " ^ string_of_int s1 ^ " + " ^ string_of_int s2 ^ " = " ^ string_of_int(s1 + s2)) else (); |
|
265 in (s1 + s2) end |
|
266 | size_of_term' i pr x t = |
|
267 (if pr then tracing (idt "#" i ^ "size_of_term' bot: " ^ UnparseC.term t) else (); |
|
268 case t of |
|
269 Free (subst, _) => |
|
270 (case x of |
|
271 Free (xstr, _) => |
|
272 if xstr = subst |
|
273 then (if pr then tracing (idt "#" i ^ "xstr = var --> " ^ "1000") else (); 1000) |
|
274 else (if pr then tracing (idt "#" i ^ "x <> Free --> " ^ "1") else (); 1) |
|
275 | _ => raise ERROR ("size_of_term' called with subst = " ^ UnparseC.term x)) |
|
276 | _ => (if pr then tracing (idt "#" i ^ "bot --> " ^ "1") else (); 1)); |
|
277 |
|
278 fun term_ord' i pr x thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *) |
|
279 let |
|
280 val _ = if pr then tracing (idt "#" i ^ "term_ord' Abs") else (); |
|
281 val ord = |
|
282 case term_ord' (i + 1) pr x thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord |
|
283 val _ = if pr then tracing (idt "#" i ^ "term_ord' Abs --> " ^ pr_ord ord) else () |
|
284 in ord end |
|
285 | term_ord' i pr x _ (t, u) = |
|
286 let |
|
287 val _ = if pr then tracing (idt "#" i ^ "term_ord' bot (" ^ UnparseC.term t ^ ", " ^ UnparseC.term u ^ ")") else (); |
|
288 val ord = |
|
289 case int_ord (size_of_term' (i + 1) pr x t, size_of_term' (i + 1) pr x u) of |
|
290 EQUAL => |
|
291 let val (f, ts) = strip_comb t and (g, us) = strip_comb u |
|
292 in |
|
293 (case hd_ord (i + 1) pr x (f, g) of |
|
294 EQUAL => (terms_ord x (i + 1) pr) (ts, us) |
|
295 | ord => ord) |
|
296 end |
|
297 | ord => ord |
|
298 val _ = if pr then tracing (idt "#" i ^ "term_ord' bot --> " ^ pr_ord ord) else () |
|
299 in ord end |
|
300 and hd_ord i pr x (f, g) = (* ~ term.ML *) |
|
301 let |
|
302 val _ = if pr then tracing (idt "#" i ^ "hd_ord (" ^ UnparseC.term f ^ ", " ^ UnparseC.term g ^ ")") else (); |
|
303 val ord = prod_ord |
|
304 (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord |
|
305 (dest_hd' x f, dest_hd' x g) |
|
306 val _ = if pr then tracing (idt "#" i ^ "hd_ord --> " ^ pr_ord ord) else (); |
|
307 in ord end |
|
308 and terms_ord x i pr (ts, us) = |
|
309 let |
|
310 val _ = if pr then tracing (idt "#" i ^ "terms_ord (" ^ UnparseC.terms ts ^ ", " ^ UnparseC.terms us ^ ")") else (); |
|
311 val ord = list_ord (term_ord' (i + 1) pr x (ThyC.get_theory "Isac_Knowledge"))(ts, us); |
|
312 val _ = if pr then tracing (idt "#" i ^ "terms_ord --> " ^ pr_ord ord) else (); |
|
313 in ord end |
|
314 |
|
315 (** )in( *local*) |
|
316 |
|
317 fun ord_make_polynomial_in (pr:bool) thy subst (ts, us) = |
|
318 ((** )tracing ("*** subs variable is: " ^ Env.subst2str subst); ( **) |
|
319 case subst of |
|
320 (_, x) :: _ => |
|
321 term_ord' 1 pr x thy (TermC.numerals_to_Free ts, TermC.numerals_to_Free us) = LESS |
|
322 | _ => raise ERROR ("ord_make_polynomial_in called with subst = " ^ Env.subst2str subst)) |
|
323 |
|
324 (** )end;( *local*) |
|
325 |
|
326 \<close> ML \<open> |
|
327 val subs = [(TermC.str2term "bdv::real", TermC.str2term "x::real")]; |
|
328 if ord_make_polynomial_in true @{theory} subs (t1, t2) then () else error "still GREATER?"; |
|
329 |
|
330 val x = TermC.str2term "x ::real"; |
|
331 |
|
332 val t1 = TermC.numerals_to_Free (TermC.str2term "L * q_0 * x \<up> 2 / 4 ::real"); |
|
333 if 2006 = size_of_term' 1 true x t1 |
|
334 then () else error "size_of_term' (L * q_0 * x \<up> 2) CHANGED)"; |
|
335 |
|
336 val t2 = TermC.numerals_to_Free (TermC.str2term "- 1 * (q_0 * x \<up> 3) :: real"); |
|
337 if 3004 = size_of_term' 1 true x t2 |
|
338 then () else error "size_of_term' (- 1 * (q_0 * x \<up> 3)) CHANGED"; |
|
339 |
|
340 |
224 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
341 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
225 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
342 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
226 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
343 "----------- Matthias Goldgruber 2003 trials on rewrite orders -------------------------------"; |
227 val substa = [(TermC.empty, (Thm.term_of o the o (TermC.parse thy)) "a")]; |
344 val substa = [(TermC.empty, (Thm.term_of o the o (TermC.parse thy)) "a")]; |
228 val substb = [(TermC.empty, (Thm.term_of o the o (TermC.parse thy)) "b")]; |
345 val substb = [(TermC.empty, (Thm.term_of o the o (TermC.parse thy)) "b")]; |
269 else error "termorder.sml diff.behav ord_make_polynomial_in #13"; |
386 else error "termorder.sml diff.behav ord_make_polynomial_in #13"; |
270 |
387 |
271 val ppp' = "-6 + -5*x + x \<up> 3 + - 1*x \<up> 2 + - 1*x \<up> 3 + - 14*x \<up> 2"; |
388 val ppp' = "-6 + -5*x + x \<up> 3 + - 1*x \<up> 2 + - 1*x \<up> 3 + - 14*x \<up> 2"; |
272 val ppp = (Thm.term_of o the o (TermC.parse thy)) ppp'; |
389 val ppp = (Thm.term_of o the o (TermC.parse thy)) ppp'; |
273 val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ppp; |
390 val SOME (t',_) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ppp; |
274 if UnparseC.term t' = "-6 + -5 * x + - 15 * x \<up> 2 + 0" then () |
391 if UnparseC.term t' = "- 6 + -5 * x + - 15 * x \<up> 2 + 0" then () |
275 else error "termorder.sml diff.behav ord_make_polynomial_in #14"; |
392 else error "termorder.sml diff.behav ord_make_polynomial_in #14"; |
276 |
393 |
277 val SOME (t', _) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ppp; |
394 val SOME (t', _) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ppp; |
278 if UnparseC.term t' = "-6 + -5 * x + - 15 * x \<up> 2 + 0" then () |
395 if UnparseC.term t' = "- 6 + - 5 * x + - 15 * x \<up> 2 + 0" then () |
279 else error "termorder.sml diff.behav ord_make_polynomial_in #15"; |
396 else error "termorder.sml diff.behav ord_make_polynomial_in #15"; |
280 |
397 |
281 val ttt' = "(3*x + 5)/18"; |
398 val ttt' = "(3*x + 5)/18 ::real"; |
282 val ttt = (Thm.term_of o the o (TermC.parse thy)) ttt'; |
399 val ttt = (Thm.term_of o the o (TermC.parse thy)) ttt'; |
283 val SOME (uuu,_) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ttt; |
400 val SOME (uuu,_) = rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ttt; |
284 if UnparseC.term uuu = "(5 + 3 * x) / 18" then () |
401 if UnparseC.term uuu = "(5 + 3 * x) / 18" then () |
285 else error "termorder.sml diff.behav ord_make_polynomial_in #16a"; |
402 else error "termorder.sml diff.behav ord_make_polynomial_in #16a"; |
286 |
403 |
287 (*============ inhibit exn WN120316 ============================================== |
404 (*============ inhibit exn WN120316 ============================================== |
288 val SOME (uuu,_) = rewrite_set_ thy false make_polynomial ttt; |
405 val SOME (uuu,_) = rewrite_set_ thy false make_polynomial ttt; |
289 if UnparseC.term uuu = "(5 + 3 * x) / 18" then () |
406 if UnparseC.term uuu = "(5 + 3 * x) / 18" then () |
290 else error "termorder.sml diff.behav ord_make_polynomial_in #16b"; |
407 else error "termorder.sml diff.behav ord_make_polynomial_in #16b"; |
291 ============ inhibit exn WN120316 ==============================================*) |
|
292 |
408 |
293 |
409 |
294 "----------- lin.eq degree_0 -------------------------------------"; |
410 "----------- lin.eq degree_0 -------------------------------------"; |
295 "----------- lin.eq degree_0 -------------------------------------"; |
411 "----------- lin.eq degree_0 -------------------------------------"; |
296 "----------- lin.eq degree_0 -------------------------------------"; |
412 "----------- lin.eq degree_0 -------------------------------------"; |