1 (* Title: "ADDTESTS/All_Ctxt.thy"
3 (c) due to copyright terms
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/* *)
8 theory All_Ctxt imports Isac.Build_Isac
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>
14 section \<open>start of the mini example\<close>
17 val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
19 ("Test", ["sqroot-test", "univariate", "equation", "test"],
20 ["Test", "squ-equ-test-subpbl1"]);
22 val (p,_,f,nxt,_,pt) = Test_Code.CalcTreeTEST [(fmz, (dI',pI',mI'))];
25 section \<open>start of specify phase\<close>
27 variables known from formalisation provide type-inference for further input
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";
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 ";
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;
56 section \<open>start interpretation of method\<close>
57 text \<open>preconditions are known at start of interpretation of (root-)method\<close>
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";
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;
70 section \<open>start a subproblem: specification\<close>
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>
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 ";
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;
95 section \<open>interpretation of subproblem's method\<close>
97 text \<open>preconds are known at start of interpretation of (sub-)method\<close>
101 UnparseC.terms_to_strings (Ctree.get_assumptions pt p);
102 (*"precond_rootmet (x::real)" -- fix in Model_Pattern? *)
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";
113 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
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));
125 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
126 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
129 section \<open>finish subproblem, return to calling method\<close>
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.
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";
146 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
147 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
150 section \<open>finish Lucas interpretation\<close>
152 text \<open>assumptions collected during lucas-interpretation for proof of postcondition\<close>
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";
165 Test_Tool.show_pt pt;