test/Tools/isac/ADDTESTS/All_Ctxt.thy
author wneuper <Walther.Neuper@jku.at>
Sun, 09 Oct 2022 07:44:22 +0200
changeset 60565 f92963a33fe3
parent 60558 2350ba2640fd
child 60571 19a172de0bb5
permissions -rw-r--r--
eliminate term2str in test/*
     1 (* Title:  "ADDTESTS/All_Ctxt.thy"
     2    Author: Walther Neuper
     3    (c) due to copyright terms
     4 
     5   this theory is evaluated BEFORE Test_Isac.thy opens structures.
     6   So, if you encounter errors here, first fix them in $ISABELLE_ISAC_TEST/Tools/isac/Minisubpbl/* *)
     7 
     8 theory All_Ctxt imports Isac.Build_Isac
     9 begin
    10 
    11 text \<open>all changes of context are demonstrated in a mini example.
    12   see test/../mstools.sml --- all ctxt changes in minimsubpbl x+1=2 ---\<close>
    13 
    14 section \<open>start of the mini example\<close>
    15 
    16 ML \<open>
    17   val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
    18   val (dI',pI',mI') =
    19     ("Test", ["sqroot-test", "univariate", "equation", "test"],
    20      ["Test", "squ-equ-test-subpbl1"]);
    21 \<close> ML \<open>
    22   val (p,_,f,nxt,_,pt) = Test_Code.CalcTreeTEST [(fmz, (dI',pI',mI'))];
    23 \<close>
    24 
    25 section \<open>start of specify phase\<close>
    26 text \<open>
    27   variables known from formalisation provide type-inference for further input
    28 \<close>
    29 
    30 ML \<open>
    31 (*+*)if ((fst p) |> get_obj g_origin pt |> LibraryC.fst3) <> []
    32 (*+*)then () else error "check correct of get_ctxt at start of (sub-)problem";
    33 
    34   val ctxt = Ctree.get_ctxt pt p; 
    35   (*must NOT check ThyC.id_empty in specify_data.spec,      .. is still empty in this case  
    36     but for References_Def.T in specify_data.origin.        .. is already assigned in this case
    37                                                                and in case of CAS-cmd          *)
    38   val SOME known_x = TermC.parseNEW ctxt "x + y + z";
    39   val SOME unknown = TermC.parseNEW ctxt "a + b + c";
    40   if type_of known_x = HOLogic.realT andalso 
    41      type_of unknown = TFree ("'a",["Groups.plus"])
    42   then () else error "All_Ctx: type constraints beginning specification of root-problem ";
    43 \<close>
    44 
    45 ML \<open>
    46   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    47   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    48   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    49   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    50   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    51   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    52   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    53   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    54 \<close>
    55 
    56 section \<open>start interpretation of method\<close>
    57 text \<open>preconditions are known at start of interpretation of (root-)method\<close>
    58 
    59 ML \<open>
    60   if UnparseC.terms_to_strings (Ctree.get_assumptions pt p) = ["precond_rootmet x"]
    61   then () else error "All_Ctx: asms after start interpretation of root-method";
    62 \<close>
    63 
    64 ML \<open>
    65   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    66   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    67   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    68 \<close>
    69 
    70 section \<open>start a subproblem: specification\<close>
    71 text \<open>
    72   ctxt is initialised from the thy in "SubProblem (thy, pbl, met) args"
    73   and extended with the types of the variables in args.\<close>
    74 
    75 ML \<open>(*not significant in this example*)
    76   val ctxt = Ctree.get_ctxt pt p;
    77   val SOME known_x = TermC.parseNEW ctxt "x+y+z";
    78   val SOME unknown = TermC.parseNEW ctxt "a+b+c";
    79   if type_of known_x = HOLogic.realT andalso 
    80      type_of unknown = TFree ("'a",["Groups.plus"])
    81   then () else error "All_Ctx: type constraints beginning specification of SubProblem ";
    82 \<close>
    83 
    84 ML \<open>
    85   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    86   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    87   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    88   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    89   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    90   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    91   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    92   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt; 
    93 \<close>
    94 
    95 section \<open>interpretation of subproblem's method\<close>
    96 
    97 text \<open>preconds are known at start of interpretation of (sub-)method\<close>
    98 
    99 ML \<open>
   100 \<close> ML \<open>
   101 UnparseC.terms_to_strings (Ctree.get_assumptions pt p);
   102 (*"precond_rootmet (x::real)" -- fix in Model_Pattern? *)
   103 \<close> ML \<open>
   104 \<close>
   105 
   106 ML \<open>
   107   if eq_set op = (UnparseC.terms_to_strings (Ctree.get_assumptions pt p),
   108     ["matches (?a = ?b) (- 1 + x = 0)", "precond_rootmet x"])
   109   then () else error "All_Ctx: asms after start interpretation of SubProblem";
   110 \<close>
   111 
   112 ML \<open>
   113  val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt; 
   114 \<close>
   115 
   116 ML \<open>
   117   "artifically inject assumptions";
   118   val (SOME (iform, cform), SOME (ires, cres)) = Ctree.get_obj Ctree.g_loc pt (fst p);
   119   val ctxt = ContextC.insert_assumptions [TermC.parse_test @{context} "x < sub_asm_out",
   120                                  TermC.parse_test @{context} "a < sub_asm_local"] cres;
   121   val pt = Ctree.update_loc' pt (fst p) (SOME (iform, cform), SOME (ires, ctxt));
   122 \<close>
   123 
   124 ML \<open>
   125 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   126 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   127 \<close>
   128 
   129 section \<open>finish subproblem, return to calling method\<close>
   130 
   131 text \<open>transfer non-local assumptions and result from sub-method to root-method.
   132   non-local assumptions are those contaning a variable known in root-method.
   133 \<close>
   134 
   135 ML \<open>
   136 eq_set
   137 \<close>
   138 
   139 ML \<open>
   140   if eq_set op = (UnparseC.terms_to_strings (Ctree.get_assumptions pt p),
   141     ["matches (?a = ?b) (- 1 + x = 0)", "x < sub_asm_out", "x = 1", "precond_rootmet x"])
   142   then () else error "All_Ctx: asms after finishing SubProblem";
   143 \<close>
   144 
   145 ML \<open>
   146   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   147   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   148 \<close>
   149 
   150 section \<open>finish Lucas interpretation\<close>
   151 
   152 text \<open>assumptions collected during lucas-interpretation for proof of postcondition\<close>
   153 
   154 ML \<open>
   155 \<close> ML \<open>
   156 \<close>
   157 
   158 ML \<open>
   159   if eq_set op = (UnparseC.terms_to_strings (Ctree.get_assumptions pt p),
   160     ["matches (?a = ?b) (- 1 + x = 0)", "x < sub_asm_out", "x = 1", "precond_rootmet x"])
   161   then () else error "All_Ctx at final result";
   162 \<close>
   163 
   164 ML \<open>
   165   Test_Tool.show_pt pt;
   166 \<close>
   167 
   168 ML \<open>
   169 \<close> ML \<open>
   170 \<close>
   171 
   172 end