test/Tools/isac/Knowledge/simplify.sml
author wneuper <Walther.Neuper@jku.at>
Sat, 08 Oct 2022 11:40:48 +0200
changeset 60559 aba19e46dd84
parent 60558 2350ba2640fd
child 60571 19a172de0bb5
permissions -rw-r--r--
follow up 5: cleanup
walther@60355
     1
(* Title: \<open>\<close>
walther@60355
     2
   Author: Walther Neuper 061019
neuper@37906
     3
   (c) due to copyright terms
neuper@37906
     4
*)
neuper@37906
     5
neuper@38066
     6
"--------------------------------------------------------";
neuper@38066
     7
"--------------------------------------------------------";
neuper@38066
     8
"table of contents --------------------------------------";
neuper@38066
     9
"--------------------------------------------------------";
Walther@60531
    10
(*"----------- CAS-command Simplify -----------------------";*)
neuper@38066
    11
"----------- append inform with final result ------------";
neuper@38066
    12
"--------------------------------------------------------";
neuper@38066
    13
"--------------------------------------------------------";
neuper@38066
    14
"--------------------------------------------------------";
neuper@37906
    15
neuper@42396
    16
val thy = @{theory "Simplify"};
neuper@37906
    17
Walther@60531
    18
(*
Walther@60533
    19
  This test is postponed within Isabelle/PIDE/isac development, 
Walther@60533
    20
  because respective user-requirements are not clarified.
Walther@60531
    21
  See test/../cas-command.sml --- start Calculation with CAS_Cmd ---
Walther@60531
    22
  and test/../Test_VSCode_Example.thy subsubsection \<open>Start Example with a CAS_Cmd\<close>
Walther@60531
    23
  "----------- CAS-command Simplify -----------------------";
Walther@60531
    24
  "----------- CAS-command Simplify -----------------------";
Walther@60531
    25
  "----------- CAS-command Simplify -----------------------";
Walther@60549
    26
  States.reset ();
Walther@60531
    27
  CalcTree [([], References.empty)];
Walther@60531
    28
  Iterator 1;
Walther@60531
    29
  moveActiveRoot 1;
Walther@60531
    30
  replaceFormula 1 "Simplify (2*a + 3*a)";
Walther@60531
    31
  autoCalculate 1 (Steps 1);
Walther@60531
    32
  autoCalculate 1 CompleteCalc;
Walther@60549
    33
  val ((pt,p),_) = States.get_calc 1;
Walther@60531
    34
  val Form res = (#1 o ME_Misc.pt_extract) (pt, ([],Res)); Test_Tool.show_pt pt; UnparseC.term res;
Walther@60531
    35
  if p = ([], Res) andalso UnparseC.term res = "5 * a" then ()
Walther@60531
    36
  else error "simplify.sml: diff.behav. CAScmd: Simplify (2*a + 3*a)";
Walther@60531
    37
*)
neuper@37906
    38
neuper@38066
    39
"----------- append inform with final result ------------";
neuper@38066
    40
"----------- append inform with final result ------------";
neuper@38066
    41
"----------- append inform with final result ------------";
Walther@60549
    42
States.reset ();
neuper@38083
    43
CalcTree [(["Term ((14 * x * y) / ( x * y ))", "normalform N"],
walther@59997
    44
	("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
neuper@37906
    45
Iterator 1;
neuper@37906
    46
moveActiveRoot 1;
wneuper@59227
    47
autoCalculate 1 CompleteCalcHead;
Walther@60549
    48
val ((pt,p),_) = States.get_calc 1; 
walther@60355
    49
Test_Tool.show_pt pt; (*[
neuper@52105
    50
(([], Frm), Simplify (14 * x * y / (x * y)))] *)
walther@59983
    51
ME_Misc.pt_extract (pt, p); (*determines SOME (Apply_Method ["simplification", "of_rationals"])*)
neuper@38065
    52
walther@60355
    53
(*/------------------- step into autoCalculate 1 (Steps 1) \<longrightarrow> Apply_Method ----------------\*)
walther@60355
    54
"~~~~~ fun autoCalculate , args:"; val (cI, auto) = (1, Steps 1);
Walther@60549
    55
     val pold = States.get_pos cI 1
walther@60355
    56
walther@60355
    57
(** )val ("ok", [], (_, ([], Met))) =    (*case*)                                      ( *isa*)
walther@60355
    58
(**)val ("ok", [], (_, ([1], Frm))) =   (*case*)                                     (*isa2*)
Walther@60549
    59
Math_Engine.autocalc [] pold (States.get_calc cI) auto (*of*);
Walther@60549
    60
"~~~~~  fun autocalc , args:"; val (c, ip, cs, (Solve.Steps s)) = ([], pold, (States.get_calc cI), auto);
walther@60355
    61
    (*if*) s <= 1 (*then*);
walther@60355
    62
walther@60355
    63
(** )  val ("ok", (                                                                    (*isa*)
walther@60355
    64
        [(Specify_Method ["simplification", "of_rationals"], _, (([], Met), (Uistate, _)))],
walther@60355
    65
           [], (_, ([], Met)))) = ( **)
walther@60355
    66
(**)  val ("ok", (                                                                      (*isa2*)
walther@60355
    67
        [(Apply_Method ["simplification", "of_rationals"], _, (([1], Frm), (pstate, _)))],
walther@60355
    68
           [], (_, ([1], Frm)))) = (**)
walther@60355
    69
      Step.do_next ip cs;
walther@60355
    70
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) = (ip, cs);
walther@60355
    71
  (*if*) Pos.on_calc_end ip (*else*);
walther@60355
    72
      val ("Rational", probl_id as ["rational", "simplification"], ["simplification", "of_rationals"]) =
walther@60355
    73
  Calc.references (pt, p);                                                        (*isa == isa2*)
walther@60355
    74
val _ =
walther@60355
    75
      (*case*) tacis (*of*);
walther@60355
    76
        (*if*) probl_id = Problem.id_empty (*else*);
walther@60355
    77
walther@60355
    78
(** )  val ("ok", (                                                                     (*isa*)
walther@60355
    79
        [(Specify_Method ["simplification", "of_rationals"], _, (([], Met), (Uistate, _)))],
walther@60355
    80
           [], (_, ([], Met)))) = ( **)
walther@60355
    81
(**)  val ("ok", (                                                                      (*isa2*)
walther@60355
    82
        [(Apply_Method ["simplification", "of_rationals"], _, (([1], Frm), (pstate, _)))],
walther@60355
    83
           [], (_, ([1], Frm)))) = (**)
walther@60355
    84
           switch_specify_solve p_ (pt, ip);
walther@60355
    85
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
walther@60355
    86
      (*if*) Pos.on_specification ([], state_pos) (*then*);
walther@60355
    87
walther@60355
    88
(** )  val ("ok", (                                                                     (*isa*)
walther@60355
    89
        [(Specify_Method ["simplification", "of_rationals"], _, (([], Met), (Uistate, _)))],
walther@60355
    90
           [], (_, ([], Met)))) = ( **)
walther@60355
    91
(**)  val ("ok", (                                                                      (*isa2*)
walther@60355
    92
        [(Apply_Method ["simplification", "of_rationals"], _, (([1], Frm), (pstate, _)))],
walther@60355
    93
           [], (_, ([1], Frm)))) = (**)
walther@60355
    94
           specify_do_next (pt, input_pos);
walther@60355
    95
"~~~~~ fun specify_do_next , args:"; val (ptp as (pt, (p, p_))) = (pt, input_pos);
walther@60355
    96
    val (_, (p_', tac)) = Specify.find_next_step ptp
walther@60355
    97
walther@60355
    98
(** ) val (_, (Met, Specify_Method ["simplification", "of_rationals"])) =             ( *isa*)
walther@60355
    99
(**) val (_, (Met, Apply_Method ["simplification", "of_rationals"])) =               (*isa2*)
walther@60355
   100
   Specify.find_next_step ptp;
walther@60355
   101
"~~~~~ fun find_next_step , args:"; val (pt, pos as (_, p_)) = (ptp);
walther@60355
   102
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
walther@60355
   103
      spec = refs, ...} = Calc.specify_data (pt, pos);
walther@60355
   104
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*);
walther@60355
   105
        (*if*) p_ = Pos.Pbl (*else*);
walther@60355
   106
walther@60355
   107
(** ) val (_, (Met, Specify_Method ["simplification", "of_rationals"])) =             ( *isa*)
walther@60355
   108
(**) val (_, (Met, Apply_Method ["simplification", "of_rationals"])) =               (*isa2*)
Walther@60558
   109
           for_method_PIDE ctxt oris (o_refs, refs) (pbl, met);
walther@60355
   110
"~~~~~ fun for_method , args:"; val (oris, ((dI', pI', mI'), (dI, pI, mI)), (pbl, met)) =
walther@60355
   111
  (oris, (o_refs, refs), (pbl, met));
walther@60355
   112
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60559
   113
    val {ppc = mpc, prls, pre, ...} = MethodC.from_store ctxt cmI;    (*..MethodC ?*)
walther@60355
   114
walther@60355
   115
(** ) val (preok as false, _) = Pre_Conds.check prls pre pbl 0;                       ( *isa*)
walther@60355
   116
(**) val (preok as true, _) = Pre_Conds.check prls pre pbl 0;                        (*isa2*)
walther@60355
   117
 (*####  eval asms: "14 * x * y / (x * y) is_ratpolyexp = False"                       (*isa*)
walther@60355
   118
                                                         True                        ( *isa2*)
walther@60355
   119
(*\------------------- step into autoCalculate 1 (Steps 1) \<longrightarrow> Apply_Method ----------------/*)
Walther@60549
   120
val ((pt,p),_) = States.get_calc 1;  
walther@60355
   121
Test_Tool.show_pt pt;
neuper@52105
   122
(*[
neuper@52105
   123
(([], Frm), Simplify (14 * x * y / (x * y))),
neuper@52105
   124
(([1], Frm), 14 * x * y / (x * y))] *)
neuper@38065
   125
Walther@60421
   126
appendFormula 1 "14::real" 
Walther@60421
   127
(* INPUT WITHOUT ^^^^^^^^ VARIABLES (WITH TYPE FROM  ctxt) WOULD REQUIRE ADDITIONAL ATTENTION*);
Walther@60549
   128
val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
neuper@52105
   129
(*[
neuper@52105
   130
(([], Frm), Simplify (14 * x * y / (x * y))),
neuper@52105
   131
(([1], Frm), 14 * x * y / (x * y)),
neuper@52105
   132
(([1,1], Frm), 14 * x * y / (x * y)),
neuper@52105
   133
(([1,1], Res), 14 * (x * y) / (x * y)),
neuper@52105
   134
(([1,2], Res), 14 / 1),
neuper@52105
   135
(([1,3], Res), 14),
neuper@52105
   136
(([1], Res), 14)]*)
neuper@37906
   137
walther@59747
   138
autoCalculate 1 (Steps 1);
Walther@60549
   139
val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
neuper@52105
   140
(*[
neuper@52105
   141
(([], Frm), Simplify (14 * x * y / (x * y))),
neuper@52105
   142
(([1], Frm), 14 * x * y / (x * y)),
neuper@52105
   143
(([1,1], Frm), 14 * x * y / (x * y)),
neuper@52105
   144
(([1,1], Res), 14 * (x * y) / (x * y)),
neuper@52105
   145
(([1,2], Res), 14 / 1),
neuper@52105
   146
(([1,3], Res), 14),
neuper@52105
   147
(([1], Res), 14),
neuper@52105
   148
(([], Res), 14)] *)
walther@59983
   149
val Form res = (#1 o ME_Misc.pt_extract) (pt, ([],Res));
walther@60355
   150
walther@59868
   151
if p = ([], Res) andalso UnparseC.term res = "14" then ()
neuper@52105
   152
else error "simplify.sml: append inform with final result changed";
neuper@38065
   153