wneuper@59292
|
1 |
(* Title: read and write access to the calctree
|
wneuper@59292
|
2 |
Author: Walther Neuper 2017
|
wneuper@59292
|
3 |
(c) due to copyright terms
|
wneuper@59292
|
4 |
*)
|
wneuper@59292
|
5 |
signature CALC_TREE_ACCESS =
|
wneuper@59292
|
6 |
sig
|
wneuper@59292
|
7 |
|
wneuper@59294
|
8 |
val update_branch : CTbasic.ctree -> CTbasic.pos -> CTbasic.branch -> CTbasic.ctree
|
wneuper@59294
|
9 |
val update_ctxt : CTbasic.ctree -> CTbasic.pos -> Proof.context -> CTbasic.ctree
|
wneuper@59300
|
10 |
val update_env : CTbasic.ctree -> CTbasic.pos -> (Selem.istate * Proof.context) option -> CTbasic.ctree
|
wneuper@59405
|
11 |
val update_domID : CTbasic.ctree -> CTbasic.pos -> Celem.domID -> CTbasic.ctree
|
wneuper@59316
|
12 |
val update_met : CTbasic.ctree -> CTbasic.pos -> Model.itm list -> CTbasic.ctree (* =vvv= ? *)
|
wneuper@59316
|
13 |
val update_metppc : CTbasic.ctree -> CTbasic.pos -> Model.itm list -> CTbasic.ctree (* =^^^= ? *)
|
wneuper@59405
|
14 |
val update_metID : CTbasic.ctree -> CTbasic.pos -> Celem.metID -> CTbasic.ctree
|
wneuper@59316
|
15 |
val update_pbl : CTbasic.ctree -> CTbasic.pos -> Model.itm list -> CTbasic.ctree (* =vvv= ? *)
|
wneuper@59316
|
16 |
val update_pblppc : CTbasic.ctree -> CTbasic.pos -> Model.itm list -> CTbasic.ctree (* =^^^= ? *)
|
wneuper@59405
|
17 |
val update_pblID : CTbasic.ctree -> CTbasic.pos -> Celem.pblID -> CTbasic.ctree
|
wneuper@59316
|
18 |
val update_oris : CTbasic.ctree -> CTbasic.pos -> Model.ori list -> CTbasic.ctree
|
wneuper@59405
|
19 |
val update_orispec : CTbasic.ctree -> CTbasic.pos -> Celem.spec -> CTbasic.ctree
|
wneuper@59405
|
20 |
val update_spec : CTbasic.ctree -> CTbasic.pos -> Celem.spec -> CTbasic.ctree
|
wneuper@59302
|
21 |
val update_tac : CTbasic.ctree -> CTbasic.pos -> Tac.tac -> CTbasic.ctree
|
wneuper@59294
|
22 |
|
wneuper@59300
|
23 |
val cappend_form : CTbasic.ctree -> CTbasic.pos -> Selem.istate * Proof.context -> term ->
|
wneuper@59294
|
24 |
CTbasic.ctree * CTbasic.pos' list
|
wneuper@59300
|
25 |
val cappend_problem : CTbasic.ctree -> CTbasic.pos -> Selem.istate * Proof.context ->
|
wneuper@59405
|
26 |
Selem.fmz -> Model.ori list * Celem.spec * term -> CTbasic.ctree * CTbasic.pos' list
|
wneuper@59300
|
27 |
val append_result : CTbasic.ctree -> CTbasic.pos -> Selem.istate * Proof.context ->
|
wneuper@59299
|
28 |
Selem.result -> CTbasic.ostate -> CTbasic.ctree * 'a list
|
wneuper@59294
|
29 |
val append_atomic : (* for solve.sml *)
|
wneuper@59302
|
30 |
CTbasic.pos -> Selem.istate * Proof.context -> term -> Tac.tac -> Selem.result ->
|
wneuper@59294
|
31 |
CTbasic.ostate -> CTbasic.ctree -> CTbasic.ctree
|
wneuper@59300
|
32 |
val cappend_atomic : CTbasic.ctree -> CTbasic.pos -> Selem.istate * Proof.context -> term ->
|
wneuper@59302
|
33 |
Tac.tac -> Selem.result -> CTbasic.ostate -> CTbasic.ctree * CTbasic.pos' list
|
wneuper@59310
|
34 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
wneuper@59300
|
35 |
val cappend_parent : CTbasic.ctree -> int list -> Selem.istate * Proof.context -> term ->
|
wneuper@59302
|
36 |
Tac.tac -> CTbasic.branch -> CTbasic.ctree * CTbasic.pos' list
|
wneuper@59299
|
37 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
wneuper@59294
|
38 |
val update_loc' : CTbasic.ctree -> CTbasic.pos ->
|
wneuper@59300
|
39 |
(Selem.istate * Proof.context) option * (Selem.istate * Proof.context) option -> CTbasic.ctree
|
wneuper@59300
|
40 |
val append_problem : int list -> Selem.istate * Proof.context -> Selem.fmz ->
|
wneuper@59316
|
41 |
Model.ori list * spec * term -> CTbasic.ctree -> CTbasic.ctree
|
wneuper@59299
|
42 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
wneuper@59292
|
43 |
end
|
wneuper@59292
|
44 |
(**)
|
wneuper@59292
|
45 |
structure CTaccess(**): CALC_TREE_ACCESS(**) =
|
wneuper@59292
|
46 |
struct
|
wneuper@59292
|
47 |
(**)
|
wneuper@59292
|
48 |
open CTbasic
|
wneuper@59292
|
49 |
|
wneuper@59294
|
50 |
(* for use by appl_obj *)
|
wneuper@59294
|
51 |
fun repl_pbl x (PblObj {cell, origin, fmz, spec, probl = _, meth, ctxt, env, loc,
|
wneuper@59294
|
52 |
branch, result, ostate}) =
|
wneuper@59294
|
53 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec = spec, probl= x, meth = meth,
|
wneuper@59294
|
54 |
ctxt = ctxt, env = env, loc = loc, branch = branch, result = result, ostate = ostate}
|
wneuper@59294
|
55 |
| repl_pbl _ _ = raise PTREE "repl_pbl takes no PrfObj";
|
wneuper@59294
|
56 |
fun repl_met x (PblObj {cell, origin, fmz, spec, probl, meth = _, ctxt, env, loc,
|
wneuper@59294
|
57 |
branch, result, ostate}) =
|
wneuper@59294
|
58 |
PblObj {cell = cell, origin = origin, fmz= fmz, spec = spec, probl = probl,
|
wneuper@59294
|
59 |
meth = x, ctxt = ctxt, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
60 |
ostate = ostate}
|
wneuper@59294
|
61 |
| repl_met _ _ = raise PTREE "repl_pbl takes no PrfObj";
|
wneuper@59294
|
62 |
fun repl_spec x (PblObj {cell, origin, fmz, spec = _, probl, meth, ctxt, env, loc,
|
wneuper@59294
|
63 |
branch, result, ostate}) =
|
wneuper@59294
|
64 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec = x, probl = probl,
|
wneuper@59294
|
65 |
meth = meth, ctxt = ctxt, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
66 |
ostate = ostate}
|
wneuper@59294
|
67 |
| repl_spec _ _ = raise PTREE "repl_domID takes no PrfObj";
|
wneuper@59294
|
68 |
fun repl_domID x (PblObj {cell, origin, fmz, spec = (_, p, m), probl, meth, ctxt, env, loc,
|
wneuper@59294
|
69 |
branch, result, ostate}) =
|
wneuper@59294
|
70 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec= (x, p, m), probl = probl,
|
wneuper@59294
|
71 |
meth = meth, ctxt = ctxt, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
72 |
ostate = ostate}
|
wneuper@59294
|
73 |
| repl_domID _ _ = raise PTREE "repl_domID takes no PrfObj";
|
wneuper@59294
|
74 |
fun repl_pblID x (PblObj {cell, origin, fmz, spec= (d, _, m), probl, meth, ctxt, env, loc,
|
wneuper@59294
|
75 |
branch, result, ostate}) =
|
wneuper@59294
|
76 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec= (d, x, m), probl = probl,
|
wneuper@59294
|
77 |
meth = meth, ctxt = ctxt, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
78 |
ostate = ostate}
|
wneuper@59294
|
79 |
| repl_pblID _ _ = raise PTREE "repl_pblID takes no PrfObj";
|
wneuper@59294
|
80 |
fun repl_metID x (PblObj {cell, origin, fmz, spec = (d, p,_), probl, meth, ctxt, env, loc,
|
wneuper@59294
|
81 |
branch, result, ostate}) =
|
wneuper@59294
|
82 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec = (d, p, x), probl = probl,
|
wneuper@59294
|
83 |
meth = meth, ctxt = ctxt, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
84 |
ostate = ostate}
|
wneuper@59294
|
85 |
| repl_metID _ _ = raise PTREE "repl_metID takes no PrfObj";
|
wneuper@59294
|
86 |
fun repl_result l f' s (PrfObj {cell, form, tac, loc = _, branch, result = _ , ostate = _}) =
|
wneuper@59294
|
87 |
PrfObj {cell = cell, form = form, tac = tac, loc = l, branch = branch, result = f', ostate = s}
|
wneuper@59294
|
88 |
| repl_result l f' s (PblObj {cell, origin, fmz, spec, probl, meth, ctxt, env, loc = _,
|
wneuper@59294
|
89 |
branch, result = _ , ostate= _}) =
|
wneuper@59294
|
90 |
PblObj {cell = cell, origin = origin, fmz= fmz, spec = spec, probl = probl,
|
wneuper@59294
|
91 |
meth = meth, ctxt = ctxt, env = env, loc = l, branch = branch, result = f', ostate = s};
|
wneuper@59294
|
92 |
fun repl_tac x (PrfObj {cell, form, tac = _, loc, branch, result, ostate}) =
|
wneuper@59294
|
93 |
PrfObj {cell = cell, form = form, tac = x, loc = loc, branch = branch,
|
wneuper@59294
|
94 |
result = result, ostate = ostate}
|
wneuper@59294
|
95 |
| repl_tac _ _ = raise PTREE "repl_tac takes no PblObj";
|
wneuper@59294
|
96 |
fun repl_ctxt x (PblObj {cell, origin, fmz, spec, probl, meth,
|
wneuper@59294
|
97 |
ctxt = _, env, loc, branch, result, ostate}) =
|
wneuper@59294
|
98 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec = spec, probl = probl,
|
wneuper@59294
|
99 |
meth = meth, ctxt = x, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
100 |
ostate = ostate}
|
wneuper@59294
|
101 |
| repl_ctxt _ _ = raise PTREE "repl_env takes no PrfObj";
|
wneuper@59294
|
102 |
fun repl_env e (PblObj {cell, origin, fmz, spec, probl, meth,
|
wneuper@59294
|
103 |
ctxt, env = _, loc, branch, result, ostate}) =
|
wneuper@59294
|
104 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec = spec, probl = probl,
|
wneuper@59294
|
105 |
meth = meth, ctxt = ctxt, env = e, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
106 |
ostate = ostate}
|
wneuper@59294
|
107 |
| repl_env _ _ = raise PTREE "repl_env takes no PrfObj";
|
wneuper@59294
|
108 |
fun repl_oris oris (PblObj { cell, origin = (_, spe, hdf),fmz, spec, probl, meth,
|
wneuper@59294
|
109 |
ctxt, env, loc, branch, result, ostate}) =
|
wneuper@59294
|
110 |
PblObj{cell = cell, origin = (oris, spe, hdf), fmz = fmz, spec = spec, probl = probl,
|
wneuper@59294
|
111 |
meth = meth, ctxt = ctxt, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
112 |
ostate = ostate}
|
wneuper@59294
|
113 |
| repl_oris _ _ = raise PTREE "repl_oris takes no PrfObj";
|
wneuper@59294
|
114 |
fun repl_orispec spe (PblObj {cell, origin = (oris, _, hdf), fmz, spec, probl, meth,
|
wneuper@59294
|
115 |
ctxt, env, loc, branch, result, ostate}) =
|
wneuper@59294
|
116 |
PblObj{cell = cell, origin = (oris, spe, hdf), fmz = fmz, spec = spec, probl = probl,
|
wneuper@59294
|
117 |
meth = meth, ctxt = ctxt, env = env, loc = loc, branch = branch, result = result,
|
wneuper@59294
|
118 |
ostate = ostate}
|
wneuper@59294
|
119 |
| repl_orispec _ _ = raise PTREE "repl_orispec takes no PrfObj";
|
wneuper@59294
|
120 |
fun repl_loc l (PblObj {cell, origin, fmz, spec, probl, meth,
|
wneuper@59294
|
121 |
ctxt, env, loc = _ , branch, result, ostate}) =
|
wneuper@59294
|
122 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec = spec, probl = probl,
|
wneuper@59294
|
123 |
meth = meth, ctxt = ctxt, env = env, loc = l, branch = branch, result = result,
|
wneuper@59294
|
124 |
ostate = ostate}
|
wneuper@59294
|
125 |
| repl_loc l (PrfObj {cell, form, tac, loc = _, branch, result, ostate}) =
|
wneuper@59294
|
126 |
PrfObj {cell = cell, form = form, tac = tac, loc= l, branch = branch, result = result,
|
wneuper@59294
|
127 |
ostate = ostate}
|
wneuper@59294
|
128 |
|
wneuper@59294
|
129 |
|
wneuper@59294
|
130 |
fun repl_branch b (PblObj {cell, origin, fmz, spec, probl, meth, ctxt, env, loc, branch = _,
|
wneuper@59294
|
131 |
result, ostate}) =
|
wneuper@59294
|
132 |
PblObj {cell = cell, origin = origin, fmz = fmz, spec = spec, probl = probl,
|
wneuper@59294
|
133 |
meth = meth, ctxt = ctxt, env = env, loc = loc, branch = b, result = result,
|
wneuper@59294
|
134 |
ostate = ostate}
|
wneuper@59294
|
135 |
| repl_branch b (PrfObj {cell, form, tac, loc, branch = _, result, ostate}) =
|
wneuper@59294
|
136 |
PrfObj {cell = cell, form = form, tac = tac, loc = loc, branch = b,
|
wneuper@59294
|
137 |
result = result, ostate = ostate};
|
wneuper@59294
|
138 |
|
wneuper@59294
|
139 |
fun update_branch pt pos x = appl_obj (repl_branch x) pt pos;
|
wneuper@59294
|
140 |
fun update_ctxt pt pos x = appl_obj (repl_ctxt x) pt pos; (* for use on PblObj,
|
wneuper@59294
|
141 |
otherwise use fun generate1; compare fun get_ctxt*)
|
wneuper@59294
|
142 |
fun update_env pt pos x = appl_obj (repl_env x) pt pos;
|
wneuper@59294
|
143 |
fun update_domID pt pos x = appl_obj (repl_domID x) pt pos;
|
wneuper@59294
|
144 |
fun update_met pt pos x = appl_obj (repl_met x) pt pos;
|
wneuper@59294
|
145 |
fun update_metppc pt pos x = appl_obj (repl_met x) pt pos;
|
wneuper@59294
|
146 |
fun update_metID pt pos x = appl_obj (repl_metID x) pt pos;
|
wneuper@59294
|
147 |
fun update_pbl pt pos x = appl_obj (repl_pbl x) pt pos;
|
wneuper@59294
|
148 |
fun update_pblppc pt pos x = appl_obj (repl_pbl x) pt pos;
|
wneuper@59294
|
149 |
fun update_pblID pt pos x = appl_obj (repl_pblID x) pt pos;
|
wneuper@59294
|
150 |
fun update_oris pt pos x = appl_obj (repl_oris x) pt pos;
|
wneuper@59294
|
151 |
fun update_orispec pt pos x = appl_obj (repl_orispec x) pt pos;
|
wneuper@59294
|
152 |
fun update_spec pt pos x = appl_obj (repl_spec x) pt pos;
|
wneuper@59294
|
153 |
fun update_tac pt pos x = appl_obj (repl_tac x) pt pos;
|
wneuper@59294
|
154 |
|
wneuper@59294
|
155 |
fun update_loc' pt pos x = appl_obj (repl_loc x) pt pos;
|
wneuper@59294
|
156 |
|
wneuper@59294
|
157 |
(* called by Take *)
|
wneuper@59294
|
158 |
fun append_form p l f pt =
|
wneuper@59302
|
159 |
insert_pt (PrfObj {cell = NONE, form = f, tac = Tac.Empty_Tac, loc = (SOME l, NONE),
|
wneuper@59405
|
160 |
branch = NoBranch, result = (Celem.e_term, []), ostate = Incomplete}) pt p;
|
wneuper@59294
|
161 |
fun cappend_form pt p loc f =
|
wneuper@59294
|
162 |
let
|
wneuper@59294
|
163 |
val (pt', cs) = cut_tree pt (p, Frm)
|
wneuper@59294
|
164 |
val pt'' = append_form p loc f pt'
|
wneuper@59294
|
165 |
in (pt'', cs) end;
|
wneuper@59294
|
166 |
|
wneuper@59294
|
167 |
fun append_problem [] l fmz (strs, spec, hdf) _ =
|
wneuper@59405
|
168 |
(Nd (PblObj {cell = NONE, origin = (strs, spec, hdf), fmz = fmz, spec = Celem.empty_spec,
|
wneuper@59301
|
169 |
probl = [], meth = [], ctxt = Selem.e_ctxt, env = NONE, loc = (SOME l, NONE),
|
wneuper@59405
|
170 |
branch = TransitiveB, result = (Celem.e_term, []), ostate = Incomplete}, []))
|
wneuper@59294
|
171 |
| append_problem p l fmz (strs, spec, hdf) pt =
|
wneuper@59405
|
172 |
insert_pt (PblObj {cell = NONE, origin = (strs, spec, hdf), fmz = fmz, spec = Celem.empty_spec,
|
wneuper@59301
|
173 |
probl = [], meth = [], ctxt = Selem.e_ctxt, env = NONE, loc = (SOME l, NONE),
|
wneuper@59405
|
174 |
branch = TransitiveB, result = (Celem.e_term, []), ostate= Incomplete}) pt p;
|
wneuper@59294
|
175 |
fun cappend_problem _ [] loc fmz ori = (append_problem [] loc fmz ori EmptyPtree, [])
|
wneuper@59294
|
176 |
| cappend_problem pt p loc fmz ori =
|
wneuper@59294
|
177 |
apfst (append_problem p loc fmz ori) (cut_tree pt (p, Frm));
|
wneuper@59294
|
178 |
|
wneuper@59294
|
179 |
(*WN041022 deprecated, still for kbtest/diffapp.sml, /systest/root-equ.sml*)
|
wneuper@59294
|
180 |
fun append_parent p l f r b pt =
|
wneuper@59294
|
181 |
let
|
wneuper@59294
|
182 |
val (ll, f) =
|
wneuper@59302
|
183 |
if existpt p pt andalso Tac.is_empty_tac (get_obj g_tac pt p)
|
wneuper@59294
|
184 |
then ((fst (get_obj g_loc pt p), SOME l), get_obj g_form pt p)
|
wneuper@59294
|
185 |
else ((SOME l, NONE), f)
|
wneuper@59294
|
186 |
in insert_pt (PrfObj {cell = NONE, form = f, tac = r, loc = ll,
|
wneuper@59405
|
187 |
branch = b, result = (Celem.e_term, []), ostate= Incomplete}) pt p
|
wneuper@59294
|
188 |
end;
|
wneuper@59294
|
189 |
fun cappend_parent pt p loc f r b = (* for tests only *)
|
wneuper@59294
|
190 |
apfst (append_parent p loc f r b) (cut_tree pt (p, Und));
|
wneuper@59294
|
191 |
|
wneuper@59294
|
192 |
fun append_atomic p l f r f' s pt =
|
wneuper@59294
|
193 |
let
|
wneuper@59294
|
194 |
val (iss, f) =
|
wneuper@59302
|
195 |
if existpt p pt andalso Tac.is_empty_tac (get_obj g_tac pt p)
|
wneuper@59294
|
196 |
then (*after Take*) ((fst (get_obj g_loc pt p), SOME l), get_obj g_form pt p)
|
wneuper@59294
|
197 |
else ((NONE, SOME l), f)
|
wneuper@59294
|
198 |
in
|
wneuper@59294
|
199 |
insert_pt (PrfObj {cell = NONE, form = f, tac = r, loc = iss, branch = NoBranch,
|
wneuper@59294
|
200 |
result = f', ostate = s}) pt p
|
wneuper@59294
|
201 |
end;
|
wneuper@59294
|
202 |
|
wneuper@59294
|
203 |
(* 20.8.02: cappend_* FIXXXXME cut branches below cannot be decided here:
|
wneuper@59294
|
204 |
detail - generate - cappend: inserted, not appended !!!
|
wneuper@59294
|
205 |
cut decided in applicable_in !?!
|
wneuper@59294
|
206 |
*)
|
wneuper@59294
|
207 |
fun cappend_atomic pt p ist_res f r f' s =
|
wneuper@59302
|
208 |
if existpt p pt andalso Tac.is_empty_tac (get_obj g_tac pt p)
|
wneuper@59294
|
209 |
then (*after Take: transfer Frm and respective istate*)
|
wneuper@59294
|
210 |
let
|
wneuper@59294
|
211 |
val (ist_form, f) =
|
wneuper@59294
|
212 |
(get_loc pt (p,Frm), get_obj g_form pt p)
|
wneuper@59294
|
213 |
val (pt, cs) = cut_tree pt (p,Frm)
|
wneuper@59301
|
214 |
val pt = append_atomic p (Selem.e_istate, Selem.e_ctxt) f r f' s pt
|
wneuper@59294
|
215 |
val pt = update_loc' pt p (SOME ist_form, SOME ist_res)
|
wneuper@59294
|
216 |
in (pt, cs) end
|
wneuper@59294
|
217 |
else apfst (append_atomic p ist_res f r f' s) (cut_tree pt (p,Frm));
|
wneuper@59294
|
218 |
|
wneuper@59294
|
219 |
fun append_result pt p l f s =
|
wneuper@59294
|
220 |
(appl_obj (repl_result (fst (get_obj g_loc pt p), SOME l) f s) pt p, []);
|
wneuper@59294
|
221 |
|
wneuper@59292
|
222 |
end |