test/Tools/isac/ADDTESTS/All_Ctxt.thy
author wneuper <Walther.Neuper@jku.at>
Sat, 04 Feb 2023 17:00:25 +0100
changeset 60675 d841c720d288
parent 60670 b8597ed7999a
child 60688 ee663dd09aa1
permissions -rw-r--r--
eliminate use of Thy_Info 22: eliminate UnparseC.term, rename "_in_ctxt" -> ""
     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 f_model = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
    18   val f_refs =
    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.init_calc @{context} [(f_model, f_refs)];
    23 \<close> ML \<open>
    24   val PblObj {ctxt, ...} = Ctree.get_obj I pt (#1 p)
    25   val Free ("x", Type ("Real.real", [])) = Syntax.read_term ctxt "x"
    26   val Free ("a", TFree ("'a", ["HOL.type"])) = Syntax.read_term ctxt "a"
    27 \<close>
    28 
    29 section \<open>start of specify phase\<close>
    30 text \<open>
    31   variables known from formalisation provide type-inference for further input
    32 \<close>
    33 
    34 ML \<open>
    35 (*+*)if ((fst p) |> get_obj g_origin pt |> LibraryC.fst3) <> []
    36 (*+*)then () else error "check correct of get_ctxt at start of (sub-)problem";
    37 
    38   val ctxt = Ctree.get_ctxt pt p; 
    39   (*must NOT check ThyC.id_empty in specify_data.spec,      .. is still empty in this case  
    40     but for References_Def.T in specify_data.origin.        .. is already assigned in this case
    41                                                                and in case of CAS-cmd          *)
    42   val known_x = Syntax.read_term ctxt "x + y + z";
    43   val unknown = Syntax.read_term ctxt "a + b + c";
    44   if type_of known_x = HOLogic.realT andalso 
    45      type_of unknown = TFree ("'a",["Groups.plus"])
    46   then () else error "All_Ctx: type constraints beginning specification of root-problem ";
    47 \<close>
    48 
    49 ML \<open>
    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   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    55   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    56   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    57 (*[1], Frm*)val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt; val Rewrite_Set "norm_equation" = nxt;
    58 \<close>
    59 
    60 section \<open>start interpretation of method\<close>
    61 text \<open>preconditions are known at start of interpretation of (root-)method\<close>
    62 
    63 ML \<open>
    64   if UnparseC.terms @{context} (Ctree.get_assumptions pt p) = "[precond_rootmet x]"
    65   then () else error "All_Ctx: asms after start interpretation of root-method";
    66 \<close>
    67 
    68 ML \<open>
    69   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    70   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    71 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt; val Model_Problem = nxt;
    72 \<close>
    73 
    74 section \<open>start a subproblem: specification\<close>
    75 text \<open>
    76   ctxt is initialised from the thy in "SubProblem (thy, pbl, met) args"
    77   and extended with the types of the variables in args.\<close>
    78 
    79 ML \<open>
    80   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
    81 \<close> ML \<open>
    82   val PblObj {ctxt, ...} = Ctree.get_obj I pt (#1 p)
    83   val Free ("x", Type ("Real.real", [])) = Syntax.read_term ctxt "x"
    84   val Free ("a", TFree ("'a", ["HOL.type"])) = Syntax.read_term ctxt "a"
    85 \<close> ML \<open>
    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 if eq_set op = ( UnparseC.asms_test @{context} (Ctree.get_assumptions pt p),
   101   ["matches (?a = ?b) (- 1 + x = 0)", "precond_rootmet x"])
   102 then () else error "preconds at start of method CHANGED";
   103 \<close>
   104 
   105 ML \<open>
   106  val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt; 
   107 \<close>
   108 
   109 ML \<open>
   110   "artifically inject assumptions";
   111   val (SOME (iform, cform), SOME (ires, cres)) = Ctree.get_obj Ctree.g_loc pt (fst p);
   112   val ctxt = ContextC.insert_assumptions [ParseC.parse_test @{context} "x < sub_asm_out",
   113                                  ParseC.parse_test @{context} "a < sub_asm_local"] cres;
   114   val pt = Ctree.update_loc' pt (fst p) (SOME (iform, cform), SOME (ires, ctxt));
   115 \<close>
   116 
   117 ML \<open>
   118 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   119 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   120 \<close>
   121 
   122 section \<open>finish subproblem, return to calling method\<close>
   123 
   124 text \<open>transfer non-local assumptions and result from sub-method to root-method.
   125   non-local assumptions are those contaning a variable known in root-method.
   126 \<close>
   127 
   128 ML \<open>
   129   if eq_set op = (UnparseC.asms_test @{context} (Ctree.get_assumptions pt p),
   130     ["precond_rootmet x", "matches (?a = ?b) (- 1 + x = 0)", "x < sub_asm_out", "x = 1"])
   131   then () else error "All_Ctx: asms after finishing SubProblem";
   132 \<close>
   133 
   134 ML \<open>
   135   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   136   val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
   137 \<close>
   138 
   139 section \<open>finish Lucas interpretation\<close>
   140 
   141 text \<open>assumptions collected during lucas-interpretation for proof of postcondition\<close>
   142 
   143 ML \<open>
   144 \<close> ML \<open>
   145 \<close>
   146 
   147 ML \<open>
   148   if eq_set op = (UnparseC.asms_test  @{context} (Ctree.get_assumptions pt p),
   149     ["precond_rootmet x", "matches (?a = ?b) (- 1 + x = 0)", "x < sub_asm_out", "x = 1"])
   150   then () else error "All_Ctx at final result";
   151 \<close>
   152 
   153 ML \<open>
   154   Test_Tool.show_pt pt;
   155 \<close>
   156 
   157 ML \<open>
   158 \<close> ML \<open>
   159 \<close>
   160 
   161 end