test/Tools/isac/ADDTESTS/All_Ctxt.thy
author Walther Neuper <wneuper@ist.tugraz.at>
Thu, 22 Dec 2016 10:25:49 +0100
changeset 59276 56dc790071cb
parent 59275 2423f0fbdd08
child 59308 15e75745a7fa
permissions -rw-r--r--
--- closed structure Ctree

Notes:
# "closed" means removed "open Ctree" immediately after respective end.
# test do not work (with "! activate for Test_Isac") due to 1 "open Ctree,
see next changeset.
     1 (* this is evaluated BEFORE Test_Isac.thu opens structures*)
     2 
     3 theory All_Ctxt imports 
     4   "~~/src/Tools/isac/Knowledge/Isac"
     5 (*Isac ...ERROR Bad theory (file "/usr/local/isabisac/test/Tools/isac/ADDTESTS/Isac.thy") 
     6   from Isac.thy ...*)
     7 begin
     8 
     9 text {* all changes of context are demonstrated in a mini example.
    10   see test/../mstools.sml --- all ctxt changes in minimsubpbl x+1=2 --- *}
    11 
    12 section {* start of the mini example *}
    13 
    14 ML {*
    15   val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
    16   val (dI',pI',mI') =
    17     ("Test", ["sqroot-test","univariate","equation","test"],
    18      ["Test","squ-equ-test-subpbl1"]);
    19   val (p,_,f,nxt,_,pt) = Math_Engine.CalcTreeTEST [(fmz, (dI',pI',mI'))];
    20 *}
    21 
    22 section {* start of specify phase *}
    23 text {* variables known from formalisation provide type-inference 
    24   for further input *}
    25 
    26 ML {*
    27   val ctxt = Ctree.get_ctxt pt p;
    28   val SOME known_x = parseNEW ctxt "x + y + z";
    29   val SOME unknown = parseNEW ctxt "a + b + c";
    30   if type_of known_x = HOLogic.realT andalso 
    31      type_of unknown = TFree ("'a",["Groups.plus"])
    32   then () else error "All_Ctx: type constraints beginning specification of root-problem ";
    33 *}
    34 
    35 ML {*
    36   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    37   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    38   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    39   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    40   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    41   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    42   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    43   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    44 *}
    45 
    46 section {* start interpretation of method *}
    47 text {* preconditions are known at start of interpretation of (root-)method *}
    48 
    49 ML {*
    50   if terms2strs (Ctree.get_assumptions_ pt p) = ["precond_rootmet x"]
    51   then () else error "All_Ctx: asms after start interpretation of root-method";
    52 *}
    53 
    54 ML {*
    55   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    56   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    57   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    58 *}
    59 
    60 section {* start a subproblem: specification *}
    61 text {* 
    62   ctxt is initialised from the thy in "SubProblem (thy, pbl, met) args"
    63   and extended with the types of the variables in args. *}
    64 
    65 ML {* (*not significant in this example*)
    66   val ctxt = Ctree.get_ctxt pt p;
    67   val SOME known_x = parseNEW ctxt "x+y+z";
    68   val SOME unknown = parseNEW ctxt "a+b+c";
    69   if type_of known_x = HOLogic.realT andalso 
    70      type_of unknown = TFree ("'a",["Groups.plus"])
    71   then () else error "All_Ctx: type constraints beginning specification of SubProblem ";
    72 *}
    73 
    74 ML {*
    75   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    76   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    77   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    78   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    79   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    80   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    81   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
    82   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt; 
    83 *}
    84 
    85 section {* interpretation of subproblem's method *}
    86 
    87 text {* preconds are known at start of interpretation of (sub-)method *}
    88 
    89 ML {*
    90   if terms2strs (Ctree.get_assumptions_ pt p) = ["matches (?a = ?b) (-1 + x = 0)"]
    91   then () else error "All_Ctx: asms after start interpretation of SubProblem";
    92 *}
    93 
    94 ML {*
    95  val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt; 
    96 *}
    97 
    98 ML {*
    99   "artifically inject assumptions";
   100   val (SOME (iform, cform), SOME (ires, cres)) = Ctree.get_obj Ctree.g_loc pt (fst p);
   101   val ctxt = insert_assumptions [str2term "x < sub_asm_out",
   102                                  str2term "a < sub_asm_local"] cres;
   103   val pt = Ctree.update_loc' pt (fst p) (SOME (iform, cform), SOME (ires, ctxt));
   104 *}
   105 
   106 ML {* 
   107 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
   108 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
   109 *}
   110 
   111 section {* finish subproblem, return to calling method*}
   112 
   113 text {* transfer non-local assumptions and result from sub-method to root-method.
   114   non-local assumptions are those contaning a variable known in root-method.
   115 *}
   116 
   117 ML {*
   118   if terms2strs (Ctree.get_assumptions_ pt p) = 
   119     ["matches (?a = ?b) (-1 + x = 0)", "x < sub_asm_out", "x = 1", "precond_rootmet x"]
   120   then () else error "All_Ctx: asms after finishing SubProblem";
   121 *}
   122 
   123 ML {*
   124   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
   125   val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
   126 *}
   127 
   128 section {* finish Lucas interpretation *}
   129 
   130 text {* assumptions collected during lucas-interpretation for proof of postcondition *}
   131 
   132 ML {*
   133   if terms2strs (Ctree.get_assumptions_ pt p) = 
   134     ["matches (?a = ?b) (-1 + x = 0)", "x < sub_asm_out", "x = 1", "precond_rootmet x"]
   135   then () else error "All_Ctx at final result";
   136 *}
   137 
   138 ML {*
   139   Chead.show_pt pt;
   140 *}
   141 
   142 end