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 f_model = ["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.init_calc @{context} [(f_model, f_refs)];
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"
29 section \<open>start of specify phase\<close>
31 variables known from formalisation provide type-inference for further input
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";
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 ";
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;
60 section \<open>start interpretation of method\<close>
61 text \<open>preconditions are known at start of interpretation of (root-)method\<close>
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";
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;
74 section \<open>start a subproblem: specification\<close>
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>
80 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
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"
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>
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";
106 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
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));
118 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
119 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
122 section \<open>finish subproblem, return to calling method\<close>
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.
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";
135 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
136 val (p,_,f,nxt,_,pt) = Test_Code.me nxt p [] pt;
139 section \<open>finish Lucas interpretation\<close>
141 text \<open>assumptions collected during lucas-interpretation for proof of postcondition\<close>
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";
154 Test_Tool.show_pt pt;