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 ~~/test/Tools/isac/Minimsubpbl/* *)
8 theory All_Ctxt imports Isac.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"]);
21 val (p,_,f,nxt,_,pt) = Math_Engine.CalcTreeTEST [(fmz, (dI',pI',mI'))];
24 section \<open>start of specify phase\<close>
25 text \<open>variables known from formalisation provide type-inference
26 for further input\<close>
29 val ctxt = Ctree.get_ctxt pt p;
30 val SOME known_x = TermC.parseNEW ctxt "x + y + z";
31 val SOME unknown = TermC.parseNEW ctxt "a + b + c";
32 if type_of known_x = HOLogic.realT andalso
33 type_of unknown = TFree ("'a",["Groups.plus"])
34 then () else error "All_Ctx: type constraints beginning specification of root-problem ";
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 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
45 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
48 section \<open>start interpretation of method\<close>
49 text \<open>preconditions are known at start of interpretation of (root-)method\<close>
52 if Rule.terms2strs (Ctree.get_assumptions_ pt p) = ["precond_rootmet x"]
53 then () else error "All_Ctx: asms after start interpretation of root-method";
57 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
58 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
59 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
62 section \<open>start a subproblem: specification\<close>
64 ctxt is initialised from the thy in "SubProblem (thy, pbl, met) args"
65 and extended with the types of the variables in args.\<close>
67 ML \<open>(*not significant in this example*)
68 val ctxt = Ctree.get_ctxt pt p;
69 val SOME known_x = TermC.parseNEW ctxt "x+y+z";
70 val SOME unknown = TermC.parseNEW ctxt "a+b+c";
71 if type_of known_x = HOLogic.realT andalso
72 type_of unknown = TFree ("'a",["Groups.plus"])
73 then () else error "All_Ctx: type constraints beginning specification of SubProblem ";
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 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
84 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
87 section \<open>interpretation of subproblem's method\<close>
89 text \<open>preconds are known at start of interpretation of (sub-)method\<close>
95 Rule.terms2strs (Ctree.get_assumptions_ pt p) = ["precond_rootmet x"]
100 if Rule.terms2strs (Ctree.get_assumptions_ pt p) = ["matches (?a = ?b) (-1 + x = 0)"]
101 then () else error "All_Ctx: asms after start interpretation of SubProblem";
105 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
109 "artifically inject assumptions";
110 val (SOME (iform, cform), SOME (ires, cres)) = Ctree.get_obj Ctree.g_loc pt (fst p);
111 val ctxt = ContextC.insert_assumptions [TermC.str2term "x < sub_asm_out",
112 TermC.str2term "a < sub_asm_local"] cres;
113 val pt = Ctree.update_loc' pt (fst p) (SOME (iform, cform), SOME (ires, ctxt));
117 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
118 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
121 section \<open>finish subproblem, return to calling method\<close>
123 text \<open>transfer non-local assumptions and result from sub-method to root-method.
124 non-local assumptions are those contaning a variable known in root-method.
128 Rule.terms2strs (Ctree.get_assumptions_ pt p)
133 if Rule.terms2strs (Ctree.get_assumptions_ pt p) =
134 ["matches (?a = ?b) (-1 + x = 0)", "x < sub_asm_out", "x = 1"]
135 then () else error "All_Ctx: asms after finishing SubProblem";
139 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
140 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
143 section \<open>finish Lucas interpretation\<close>
145 text \<open>assumptions collected during lucas-interpretation for proof of postcondition\<close>
149 Rule.terms2strs (Ctree.get_assumptions_ pt p)
154 if Rule.terms2strs (Ctree.get_assumptions_ pt p) =
155 ["matches (?a = ?b) (-1 + x = 0)", "x < sub_asm_out", "x = 1"]
156 then () else error "All_Ctx at final result";