1 (* this is evaluated BEFORE Test_Isac.thu opens structures*)
3 theory All_Ctxt imports
4 "~~/src/Tools/isac/Knowledge/Isac"
5 (*Isac ...ERROR Bad theory (file "/usr/local/isabisac/test/Tools/isac/ADDTESTS/Isac.thy")
9 text {* all changes of context are demonstrated in a mini example.
10 see test/../mstools.sml --- all ctxt changes in minimsubpbl x+1=2 --- *}
12 section {* start of the mini example *}
15 val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
17 ("Test", ["sqroot-test","univariate","equation","test"],
18 ["Test","squ-equ-test-subpbl1"]);
19 val (p,_,f,nxt,_,pt) = Math_Engine.CalcTreeTEST [(fmz, (dI',pI',mI'))];
22 section {* start of specify phase *}
23 text {* variables known from formalisation provide type-inference
27 val ctxt = Ctree.get_ctxt pt p;
28 val SOME known_x = parseNEW ctxt "x + y + z";
29 val SOME unknown = parseNEW ctxt "a + b + c";
30 if type_of known_x = HOLogic.realT andalso
31 type_of unknown = TFree ("'a",["Groups.plus"])
32 then () else error "All_Ctx: type constraints beginning specification of root-problem ";
36 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
37 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
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;
46 section {* start interpretation of method *}
47 text {* preconditions are known at start of interpretation of (root-)method *}
50 if terms2strs (Ctree.get_assumptions_ pt p) = ["precond_rootmet x"]
51 then () else error "All_Ctx: asms after start interpretation of root-method";
55 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
56 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
57 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
60 section {* start a subproblem: specification *}
62 ctxt is initialised from the thy in "SubProblem (thy, pbl, met) args"
63 and extended with the types of the variables in args. *}
65 ML {* (*not significant in this example*)
66 val ctxt = Ctree.get_ctxt pt p;
67 val SOME known_x = parseNEW ctxt "x+y+z";
68 val SOME unknown = parseNEW ctxt "a+b+c";
69 if type_of known_x = HOLogic.realT andalso
70 type_of unknown = TFree ("'a",["Groups.plus"])
71 then () else error "All_Ctx: type constraints beginning specification of SubProblem ";
75 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
76 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
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;
85 section {* interpretation of subproblem's method *}
87 text {* preconds are known at start of interpretation of (sub-)method *}
90 if terms2strs (Ctree.get_assumptions_ pt p) = ["matches (?a = ?b) (-1 + x = 0)"]
91 then () else error "All_Ctx: asms after start interpretation of SubProblem";
95 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
99 "artifically inject assumptions";
100 val (SOME (iform, cform), SOME (ires, cres)) = Ctree.get_obj Ctree.g_loc pt (fst p);
101 val ctxt = insert_assumptions [str2term "x < sub_asm_out",
102 str2term "a < sub_asm_local"] cres;
103 val pt = Ctree.update_loc' pt (fst p) (SOME (iform, cform), SOME (ires, ctxt));
107 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
108 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
111 section {* finish subproblem, return to calling method*}
113 text {* transfer non-local assumptions and result from sub-method to root-method.
114 non-local assumptions are those contaning a variable known in root-method.
118 if terms2strs (Ctree.get_assumptions_ pt p) =
119 ["matches (?a = ?b) (-1 + x = 0)", "x < sub_asm_out", "x = 1", "precond_rootmet x"]
120 then () else error "All_Ctx: asms after finishing SubProblem";
124 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
125 val (p,_,f,nxt,_,pt) = Math_Engine.me nxt p [] pt;
128 section {* finish Lucas interpretation *}
130 text {* assumptions collected during lucas-interpretation for proof of postcondition *}
133 if terms2strs (Ctree.get_assumptions_ pt p) =
134 ["matches (?a = ?b) (-1 + x = 0)", "x < sub_asm_out", "x = 1", "precond_rootmet x"]
135 then () else error "All_Ctx at final result";