4 (c) due to copyright terms |
4 (c) due to copyright terms |
5 *) |
5 *) |
6 "-----------------------------------------------------------------"; |
6 "-----------------------------------------------------------------"; |
7 "table of contents -----------------------------------------------"; |
7 "table of contents -----------------------------------------------"; |
8 "-----------------------------------------------------------------"; |
8 "-----------------------------------------------------------------"; |
9 "-------- test auto-generated script '(Repeat (Calculate times))'-"; |
|
10 "-------- test the same called by interSteps norm_Poly -----------"; |
9 "-------- test the same called by interSteps norm_Poly -----------"; |
11 "-------- test the same called by interSteps norm_Rational -------"; |
10 "-------- test the same called by interSteps norm_Rational -------"; |
12 "-------- check auto-gen.script for Rewrite_Set_Inst -------------"; |
11 "-------- check auto-gen.script for Rewrite_Set_Inst -------------"; |
13 "-------- how to stepwise construct Scripts -------";(*TODO remove -- partial_function is easier*) |
|
14 "-------- distinguish input to Model -----------------------------------------"; |
12 "-------- distinguish input to Model -----------------------------------------"; |
15 "-------- fun subpbl, fun pblterm --------------------------------------------"; |
13 "-------- fun subpbl, fun pblterm --------------------------------------------"; |
16 "-------- fun stacpbls, fun subst_stacexpr -----------------------------------"; |
14 "-------- fun stacpbls, fun subst_stacexpr -----------------------------------"; |
17 "-------- fun is_calc, fun op_of_calc ----------------------------------------"; |
15 "-------- fun is_calc, fun op_of_calc ----------------------------------------"; |
18 "-------- fun rule2stac, fun rule2stac_inst ----------------------------------"; |
16 "-------- fun rule2stac, fun rule2stac_inst ----------------------------------"; |
19 "-------- fun op @@ ----------------------------------------------------------"; |
17 "-------- fun op @@ ----------------------------------------------------------"; |
20 "-------- compare Scripts: xxx :: ID --> ''xxx'' :: char list ----------------"; |
|
21 "-------- Handle Var from parsing by partial_function ------------------------"; |
|
22 "-------- Compare program terms: from old parsing | from partial_function ----"; |
|
23 "-------- fun get_fun_id -----------------------------------------------------"; |
18 "-------- fun get_fun_id -----------------------------------------------------"; |
24 "-------- fun rules2scr_Rls --------------------------------------------------"; |
19 "-------- fun rules2scr_Rls --------------------------------------------------"; |
25 "-----------------------------------------------------------------------------"; |
20 "-----------------------------------------------------------------------------"; |
26 "-----------------------------------------------------------------------------"; |
21 "-----------------------------------------------------------------------------"; |
27 "-----------------------------------------------------------------------------"; |
22 "-----------------------------------------------------------------------------"; |
28 |
|
29 |
|
30 "-------- test auto-generated script '(Repeat (Calculate times))'-"; |
|
31 "-------- test auto-generated script '(Repeat (Calculate times))'-"; |
|
32 "-------- test auto-generated script '(Repeat (Calculate times))'-"; |
|
33 val Seq {scr = Prog auto_script,...} = assoc_rls "norm_Poly"; |
|
34 writeln(term2str auto_script); |
|
35 atomty auto_script; |
|
36 |
|
37 show_mets(); |
|
38 val {scr = Prog parsed_script,...} = get_met ["Test","test_interSteps_1"]; |
|
39 writeln(term2str parsed_script); |
|
40 atomty parsed_script; |
|
41 |
|
42 (*the structure of the auto-gen. script is interpreted correctly*) |
|
43 reset_states (); |
|
44 CalcTree |
|
45 [(["Term (b + a - b)",(*this is Schalk 299b*) |
|
46 "normalform N"], |
|
47 ("Poly",["polynomial","simplification"], |
|
48 ["Test","test_interSteps_1"]))]; |
|
49 Iterator 1; |
|
50 moveActiveRoot 1; |
|
51 autoCalculate 1 CompleteCalcHead; |
|
52 |
|
53 fetchProposedTactic 1 (*..Apply_Method*); |
|
54 autoCalculate 1 (Step 1); |
|
55 getTactic 1 ([1], Frm) (*still empty*); |
|
56 |
|
57 fetchProposedTactic 1 (*discard_minus_*); |
|
58 autoCalculate 1 (Step 1); |
|
59 |
|
60 fetchProposedTactic 1 (*order_add_rls_*); |
|
61 autoCalculate 1 (Step 1); |
|
62 |
|
63 fetchProposedTactic 1 (*collect_numerals_*); |
|
64 autoCalculate 1 (Step 1); |
|
65 |
|
66 autoCalculate 1 CompleteCalc; |
|
67 |
|
68 val ((pt,p),_) = get_calc 1; show_pt pt; |
|
69 if existpt' ([1], Frm) pt then () |
|
70 else error "scrtools.sml: test-script test_interSteps_1 doesnt work"; |
|
71 |
|
72 |
23 |
73 "-------- test the same called by interSteps norm_Poly -----------"; |
24 "-------- test the same called by interSteps norm_Poly -----------"; |
74 "-------- test the same called by interSteps norm_Poly -----------"; |
25 "-------- test the same called by interSteps norm_Poly -----------"; |
75 "-------- test the same called by interSteps norm_Poly -----------"; |
26 "-------- test the same called by interSteps norm_Poly -----------"; |
76 val Seq {scr = Prog auto_script,...} = assoc_rls "norm_Poly"; |
27 val Seq {scr = Prog auto_script,...} = assoc_rls "norm_Poly"; |
418 "Try (Repeat (Rewrite ''risolate_root_add'' False)) @@\n" ^ |
323 "Try (Repeat (Rewrite ''risolate_root_add'' False)) @@\n" ^ |
419 "Try (Repeat (Rewrite ''risolate_root_mult'' False)) @@\n" ^ |
324 "Try (Repeat (Rewrite ''risolate_root_mult'' False)) @@\n" ^ |
420 "Try (Repeat (Rewrite ''risolate_root_div'' False))" |
325 "Try (Repeat (Rewrite ''risolate_root_div'' False))" |
421 then () else error "fun @@ changed" |
326 then () else error "fun @@ changed" |
422 |
327 |
423 "-------- compare Scripts: xxx :: ID --> ''xxx'' :: char list ----------------"; |
|
424 "-------- compare Scripts: xxx :: ID --> ''xxx'' :: char list ----------------"; |
|
425 "-------- compare Scripts: xxx :: ID --> ''xxx'' :: char list ----------------"; |
|
426 (* meth for Minisubpbl ["Test", "squ-equ-test-subpbl1"] *) |
|
427 val prog_str_'''' = (* string constants: the intermediate version before partial_function *) |
|
428 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^ |
|
429 " (let e_e = ((Try (Rewrite_Set ''norm_equation'' False)) @@ " ^ |
|
430 " (Try (Rewrite_Set ''Test_simplify'' False))) e_e; " ^ |
|
431 " (L_L::bool list) = " ^ |
|
432 " (SubProblem (''TestX'', " ^ |
|
433 " [''LINEAR'', ''univariate'', ''equation'', ''test''], " ^ |
|
434 " [''Test'', ''solve_linear'']) " ^ |
|
435 " [BOOL e_e, REAL v_v]) " ^ |
|
436 " in Check_elementwise L_L {(v_v::real). Assumptions}) "; |
|
437 val prog_str_Free = (* Free varibles: the version up to now *) |
|
438 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^ |
|
439 " (let e_e = ((Try (Rewrite_Set norm_equation False)) @@ " ^ |
|
440 " (Try (Rewrite_Set Test_simplify False))) e_e; " ^ |
|
441 " (L_L::bool list) = " ^ |
|
442 " (SubProblem (TestX, " ^ |
|
443 " [LINEAR, univariate, equation, test], " ^ |
|
444 " [Test, solve_linear]) " ^ |
|
445 " [BOOL e_e, REAL v_v]) " ^ |
|
446 " in Check_elementwise L_L {(v_v::real). Assumptions}) " |
|
447 |
|
448 (* term with string constants *) |
|
449 val prog_'''' = (TermC.inst_abs o Thm.term_of o the o (TermC.parse @{theory})) prog_str_'''' |
|
450 val Const ("Test.Solve'_root'_equation", _) $ |
|
451 Free ("e_e", _) $ Free ("v_v", _) $ |
|
452 (Const ("HOL.Let", _) $ |
|
453 (Const ("Script.Seq", _) $ |
|
454 (Const ("Script.Try", _) $ |
|
455 (Const ("Script.Rewrite'_Set", _) $ |
|
456 norm_equation_'''' $ Const ("HOL.False", _))) $ |
|
457 (Const ("Script.Try", _) $ |
|
458 (Const ("Script.Rewrite'_Set", _) $ |
|
459 Test_simplify_'''' $ Const ("HOL.False", _))) $ |
|
460 Free ("e_e", _)) $ |
|
461 Abs ("e_e", _, |
|
462 Const ("HOL.Let", _) $ |
|
463 (Const ("Script.SubProblem", _) $ |
|
464 (Const ("Product_Type.Pair", _) $ TestX_'''' $ |
|
465 (Const ("Product_Type.Pair", _) $ |
|
466 pblkey_'''' $ metkey_'''')) $ |
|
467 args) $ |
|
468 Abs ("L_L", _, |
|
469 Const ("Script.Check'_elementwise", _) $ Free _ $ (_ $ _)))) = prog_'''' |
|
470 ; |
|
471 (* term with Free varibles *) |
|
472 val prog_Free = (TermC.inst_abs o Thm.term_of o the o (TermC.parse @{theory})) prog_str_Free |
|
473 val Const ("Test.Solve'_root'_equation", _) $ |
|
474 Free ("e_e", _) $ Free ("v_v", _) $ |
|
475 (Const ("HOL.Let", _) $ |
|
476 (Const ("Script.Seq", _) $ |
|
477 (Const ("Script.Try", _) $ |
|
478 (Const ("Script.Rewrite'_Set", _) $ |
|
479 norm_equation_Free $ Const ("HOL.False", _))) $ |
|
480 (Const ("Script.Try", _) $ |
|
481 (Const ("Script.Rewrite'_Set", _) $ |
|
482 Test_simplify_Free $ Const ("HOL.False", _))) $ |
|
483 Free ("e_e", _)) $ |
|
484 Abs ("e_e", _, |
|
485 Const ("HOL.Let", _) $ |
|
486 (Const ("Script.SubProblem", _) $ |
|
487 (Const ("Product_Type.Pair", _) $ TestX_Free $ |
|
488 (Const ("Product_Type.Pair", _) $ |
|
489 pblkey_Free $ metkey_Free)) $ |
|
490 args) $ |
|
491 Abs ("L_L", _, |
|
492 Const ("Script.Check'_elementwise", _) $ Free _ $ (_ $ _)))) = prog_Free |
|
493 ; |
|
494 (* compare term with string constants and term with Free varibles *) |
|
495 if HOLogic.dest_string norm_equation_'''' = "norm_equation" then () else error "dest_string 1"; |
|
496 (* --------------------- string constants = Free varibles *) |
|
497 if HOLogic.dest_string norm_equation_'''' = Term.term_name norm_equation_Free then () else error ""; |
|
498 if HOLogic.dest_string Test_simplify_'''' = Term.term_name Test_simplify_Free then () else error ""; |
|
499 if HOLogic.dest_string TestX_'''' = Term.term_name TestX_Free then () else error "dest_string 2"; |
|
500 |
|
501 if (pblkey_'''' |> HOLogic.dest_list |> map HOLogic.dest_string) = |
|
502 ["LINEAR", "univariate", "equation", "test"] then () else error "dest_string 3"; |
|
503 (* --------------------- string constants = Free varibles *) |
|
504 if (pblkey_'''' |> HOLogic.dest_list |> map HOLogic.dest_string) = |
|
505 (pblkey_Free |> HOLogic.dest_list |> map Term.term_name) then () else error "dest_string 4"; |
|
506 if (metkey_'''' |> HOLogic.dest_list |> map HOLogic.dest_string) = |
|
507 (metkey_Free |> HOLogic.dest_list |> map Term.term_name) then () else error "dest_string 5"; |
|
508 |
|
509 "-------- Handle Var from parsing by partial_function ------------------------"; |
|
510 "-------- Handle Var from parsing by partial_function ------------------------"; |
|
511 "-------- Handle Var from parsing by partial_function ------------------------"; |
|
512 (* (1) parsing proprietary as used up to now *) |
|
513 val prog_str_'''' = |
|
514 "xxx e_e = (let e_e = (Rewrite_Set ''yyy'' False) e_e in [e_e])" |
|
515 val prog_'''' = ((*TermC.inst_abs o*) Thm.term_of o the o (TermC.parse @{theory})) prog_str_'''' |
|
516 (*Output: val prog_'''' = ... $ (Const ("HOL.Let", "bool... )... $ Free ("e_e", "bool")) $ ...*) |
|
517 |
|
518 (* (2) parsing by funpack: take the definition from test/../ProgLang/scrtools.thy *) |
|
519 val prog_part = (HOLogic.dest_Trueprop o Thm.prop_of) @{thm simplify.simps} |
|
520 (*Output: val prog_part = ... $ (Const ("HOL.Let", "bool... )... $ Var (("e_e", 0), "bool")) $ ...*) |
|
521 ; |
|
522 Logic.unvarify_global: term -> term |
|
523 ; |
|
524 val prog_part = (Logic.unvarify_global o HOLogic.dest_Trueprop o Thm.prop_of) @{thm simplify.simps}; |
|
525 (*val prog_part = ... $ (Const ("HOL.Let", "bool... )... $ Var (("e_e", 0), "bool")) $ ...*) |
|
526 |
|
527 (* (3) compare (1)..(2) *) |
|
528 if prog_'''' = prog_part then () else error "appl of Logic.unvarify_global changed" |
|
529 |
|
530 "-------- Compare program terms: from old parsing | from partial_function ----"; |
|
531 "-------- Compare program terms: from old parsing | from partial_function ----"; |
|
532 "-------- Compare program terms: from old parsing | from partial_function ----"; |
|
533 (* meth for Minisubpbl ["Test", "squ-equ-test-subpbl1"] *) |
|
534 |
|
535 (* (1) parsing proprietary as used up to now *) |
|
536 val prog_str_'''' = (* string constants: the intermediate version before partial_function *) |
|
537 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^ |
|
538 " (let e_e = ((Try (Rewrite_Set ''norm_equation'' False)) @@ " ^ |
|
539 " (Try (Rewrite_Set ''Test_simplify'' False))) e_e; " ^ |
|
540 " (L_L::bool list) = " ^ |
|
541 " (SubProblem (''TestX'', " ^ |
|
542 " [''LINEAR'', ''univariate'', ''equation'', ''test''], " ^ |
|
543 " [''Test'', ''solve_linear'']) " ^ |
|
544 " [BOOL e_e, REAL v_v]) " ^ |
|
545 " in Check_elementwise L_L {(v_v::real). Assumptions}) "; |
|
546 val prog_'''' = (TermC.inst_abs o Thm.term_of o the o (TermC.parse @{theory})) prog_str_'''' |
|
547 |
|
548 (* body_of ---> src/../scrtools.sml for test with old parsing *) |
|
549 fun body_of_'''' (_ $ body) = body |
|
550 | body_of_'''' t = raise TERM ("body_of", [t]) |
|
551 |
|
552 val body_'''' = body_of_'''' prog_''''; |
|
553 term2str body_''''; (* with TermC.inst_abs: |
|
554 "let e_ea =\n (Try (Rewrite_Set ''norm_equation'' False) @@\n Try (Rewrite_Set ''Test_simplify'' False))\n e_e;\n L_La =\n SubProblem\n (''TestX'', [''LINEAR'', ''univariate'', ''equation'', ''test''],\n [''Test'', ''solve_linear''])\n [BOOL e_e, REAL v_v]\nin Check_elementwise L_L {v_v. Assumptions}": |
|
555 ------------------------> e_e; Free ("e_e", "bool")) |
|
556 *) |
|
557 |
|
558 (* formal_args in src/../scrtools.sml*) |
|
559 fun formal_args_'''' scr = (fst o split_last o snd o strip_comb) scr; |
|
560 |
|
561 val args_'''' = formal_args_'''' prog_''''; |
|
562 case args_'''' of [Free ("e_e", _), Free ("v_v", _)] => () |
|
563 | _ => error "formal_args"; |
|
564 |
|
565 (* (2) parsing by funpack: take the definition from test/../ProgLang/scrtools.thy *) |
|
566 val prog_part = Thm.prop_of @{thm minisubpbl.simps} |
|
567 |
|
568 (* body_of ---> src/../scrtools.sml BEFORE above, new body_of *) |
|
569 fun body_of_part t = (t |
|
570 |> HOLogic.dest_Trueprop |
|
571 |> HOLogic.dest_eq |
|
572 |> snd |
|
573 |> Logic.unvarify_global |
|
574 |> TermC.inst_abs) |
|
575 handle TERM _ => raise TERM ("body_of", [t]) |
|
576 |
|
577 val body_part = body_of_part prog_part; |
|
578 term2str body_part; (* with TermC.inst_abs, without: |
|
579 "let e_ea =\n (Try (Rewrite_Set ''norm_equation'' False) @@\n Try (Rewrite_Set ''Test_simplify'' False))\n ?e_e;\n L_La =\n SubProblem\n (''TestX'', [''LINEAR'', ''univariate'', ''equation'', ''test''],\n [''Test'', ''solve_linear''])\n [BOOL e_e, REAL ?v_v]\nin Check_elementwise L_L {v_v. Assumptions}": |
|
580 ------------------------> ?e_e; Var (("e_e", 0), "bool")) |
|
581 *) |
|
582 |
|
583 (* formal_args ---> src/../scrtools.sml BEFORE old formal_args *) |
|
584 fun formal_args_part prog = (prog |
|
585 |> HOLogic.dest_Trueprop |
|
586 |> HOLogic.dest_eq |
|
587 |> fst |
|
588 |> Logic.unvarify_global |
|
589 |> strip_comb |
|
590 |> snd |
|
591 ) |
|
592 handle TERM _ => raise TERM ("formal_args", [t]) |
|
593 |
|
594 val args_part = formal_args_part prog_part; |
|
595 |
|
596 (* (3) compare (1)..(2) *) |
|
597 if body_'''' = body_part then () else error "body_of changed"; |
|
598 if args_'''' = args_part then () else error "formal_args changed" |
|
599 |
|
600 "-------- fun get_fun_id -----------------------------------------------------"; |
328 "-------- fun get_fun_id -----------------------------------------------------"; |
601 "-------- fun get_fun_id -----------------------------------------------------"; |
329 "-------- fun get_fun_id -----------------------------------------------------"; |
602 "-------- fun get_fun_id -----------------------------------------------------"; |
330 "-------- fun get_fun_id -----------------------------------------------------"; |
603 (* fun_id is nested into arguments, compare ... *) |
331 (* fun_id is nested into arguments, compare ... *) |
604 val Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ |
332 val Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ |
605 (((((Const (const_id, const_typ) $ _) $ _) $ _) $ _) $ _) $ _) = |
333 (((((((Const (const_id, const_typ) $ _) $ _) $ _) $ _) $ _) $ _) $ _) $ _) = |
606 Thm.prop_of @{thm biegelinie.simps}; |
334 Thm.prop_of @{thm biegelinie.simps}; |
607 (* ... to: *) |
335 (* ... to: *) |
608 val Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ |
336 val Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ |
609 (Const (const_id, const_typ) $ _) $ _) = |
337 (Const (const_id, const_typ) $ _) $ _) = |
610 Thm.prop_of @{thm simplify.simps}; |
338 Thm.prop_of @{thm simplify.simps}; |
611 |
339 |
612 (* get fun_id out of nesting *) |
340 (* get fun_id out of nesting *) |
613 val Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ |
341 val Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ |
614 nested $ _) = |
342 nested $ _) = |
615 Thm.prop_of @{thm biegelinie.simps}; |
343 Thm.prop_of @{thm biegelinie.simps}; |
616 val (((((Const ("Biegelinie.biegelinie", _) $ |
344 val (Const ("Biegelinie.biegelinie", _) $ |
617 Var (("l", 0), _)) $ |
345 Var (("l", 0), _) $ |
618 Var (("q", 0), _)) $ |
346 Var (("q", 0), _) $ |
619 Var (("v", 0), _)) $ |
347 Var (("v", 0), _) $ |
620 Var (("b", 0), _)) $ |
348 Var (("b", 0), _) $ |
621 Var (("s", 0), _)) = nested; |
349 Var (("s", 0), _) $ |
|
350 Var (("vs", 0), _) $ |
|
351 Var (("id_abl", 0), _)) = nested; |
622 strip_comb nested; |
352 strip_comb nested; |
623 (*val it = |
353 (*val it = |
624 (Const ("Biegelinie.biegelinie", "real \<Rightarrow> real \<Rightarrow> real \<Rightarrow> (real \<Rightarrow> real) \<Rightarrow> bool list \<Rightarrow> bool") |
354 (Const ("Biegelinie.biegelinie", "real \<Rightarrow> real \<Rightarrow> real \<Rightarrow> (real \<Rightarrow> real) \<Rightarrow> bool list \<Rightarrow> bool") |
625 , |
355 , |
626 [Var (("l", 0), "real"), Var (("q", 0), "real"), Var (("v", 0), "real"), |
356 [Var (("l", 0), "real"), Var (("q", 0), "real"), Var (("v", 0), "real"), |
627 Var (("b", 0), "real \<Rightarrow> real"), Var (("s", 0), "bool list")]): |
357 Var (("b", 0), "real \<Rightarrow> real"), Var (("s", 0), "bool list")]): |
628 term * term list*) |
358 term * term list*) |
629 |
359 |
630 case get_fun_id (Thm.prop_of @{thm biegelinie.simps}) of |
360 case get_fun_id (prep_program @{thm biegelinie.simps}) of |
631 ("Biegelinie.biegelinie", _) => () |
361 ("Biegelinie.biegelinie", _) => () |
632 | _ => error "get_fun_id changed"; |
362 | _ => error "get_fun_id changed"; |
633 case get_fun_id (Thm.prop_of @{thm simplify.simps}) of |
363 case get_fun_id (prep_program @{thm simplify.simps}) of |
634 ("PolyMinus.simplify", _) => () |
364 ("PolyMinus.simplify", _) => () |
635 | _ => error "get_fun_id changed"; |
365 | _ => error "get_fun_id changed"; |
636 |
366 |
637 "-------- fun rules2scr_Rls --------------------------------------------------"; |
367 "-------- fun rules2scr_Rls --------------------------------------------------"; |
638 "-------- fun rules2scr_Rls --------------------------------------------------"; |
368 "-------- fun rules2scr_Rls --------------------------------------------------"; |