1 (* use"../ME/ctreeNEW.sml";
7 (*.get all positions in a ptree until ([],Res) or ostate=Incomplete
9 pos' list -> : accumulated, start with []
10 pos -> : the offset for subtrees wrt the root
12 pos' : initialization (the last pos' before ...)
13 -> pos' list : of positions in this (sub) tree (relative to the root)
15 (*###################################################################*)
16 (* val (cuts, P, pt, pos) = ([], [3], get_nd pt [3], ([], Frm):pos');
17 val (cuts, P, pt, pos) = ([], [2], get_nd pt [2], ([], Frm):pos');
20 fun get_allp (cuts:pos' list) (P:pos, pos:pos') pt =
21 (let val nxt = move_dn [] pt pos (*exn if Incomplete reached*)
23 then get_allp (cuts @ [nxt]) (P, nxt) pt
24 else (map (apfst (curry op@ P)) (cuts @ [nxt])): pos' list
25 end) handle PTREE _ => (map (apfst (curry op@ P)) cuts);
26 (*###################################################################*)
31 fun get_allps (cuts: pos' list) (P:pos) [] = cuts
32 | get_allps cuts P (pt::pts) =
34 get_allp [] (P, ([], Frm)) pt
35 in get_allps (cuts @ cuts') (lev_on P) pts end;
38 (* val (cuts: pos' list, P, pt::pts) = ([], [1], children pt);
39 val cuts' = get_allp [] P pt ([], Frm);
40 val (cuts: pos' list, P, pt::pts) = (cuts @ cuts', lev_on P, pts);
41 val cuts' = get_allp [] P pt ([], Frm);
44 (*the pts are assumed to be on the same level*)
45 fun get_allps (cuts: pos' list) (P:pos) [] = cuts
46 | get_allps cuts P (pt::pts) =
47 let val below = get_allp [] (P, ([], Frm)) pt
51 else if last_elem P = 1
54 val levres = levfrm @ (if null below then [(P, Res)] else [])
55 in get_allps (cuts @ levres) (lev_on P) pts end;
59 print_depth 11; move_dn; print_depth 3;
60 print_depth 11; get_allpos'; print_depth 3;
63 (**.these 2 funs decide on how far cut_tree goes.**)
64 (*.shall the nodes _after_ the pos to be inserted at be deleted?.*)
65 fun test_trans (PrfObj{branch = Transitive,...}) = true
66 | test_trans (PrfObj{branch = NoBranch,...}) = true
67 | test_trans (PblObj{branch = Transitive,...}) = true
68 | test_trans (PblObj{branch = NoBranch,...}) = true
69 | test_trans _ = false;
70 (*.shall cutting be continued on the higher level(s)?
71 the Nd regarded will NOT be changed.*)
72 fun cutlevup (PblObj _) = false (*for tests of LK0502*)
75 (*cut_bottom new S(603)..(608)
76 cut the level at the bottom of the pos (used by cappend_...)
77 and handle the parent in order to avoid extra case for root
78 fn: ptree -> : the _whole_ ptree for cut_levup
79 pos * posel -> : the pos after split_last
80 ptree -> : the parent of the Nd to be cut
82 (ptree * : the updated ptree
83 pos' list) * : the pos's cut
84 bool : cutting shall be continued on the higher level(s)
86 (**############# 2nd get_allp finished############################**)
88 fun cut_bottom _ (pt' as Nd (b, [])) = ((pt', []), cutlevup b)
89 | cut_bottom (P:pos, p:posel) (Nd (b, bs)) =
90 let (*divide level into 3 parts...*)
91 val keep = take (p - 1, bs)
92 val pt' as Nd (_,bs') = nth p bs
93 (*^^^^^_here_ will be 'insert'ed by 'append_..'*)
94 val (tail, tp) = (takerest (p, bs),
95 if null (takerest (p, bs)) then 0 else p + 1)
96 val (children, cuts) =
99 (if is_pblnd pt' then [(P @ [p], Pbl)] else [])
100 @ (get_allp [] (P @ [p], (P, Frm)) pt')
101 @ (get_allps [] (P @ [p+1]) tail))
102 else (keep @ [(*'insert'ed by 'append_..'*)] @ tail,
103 get_allp [] (P @ [p], (P, Frm)) pt')
106 then (Nd (del_res b, children),
107 cuts @ (if g_ostate b = Incomplete then [] else [(P,Res)]))
108 else (Nd (b, children), cuts)
109 (*val _= writeln("####cut_bottom (P, p)="^pos2str (P @ [p])^
110 ", Nd=.............................................")
112 val _= writeln("####cut_bottom form='"^
113 term2str (get_obj g_form pt'' []))
114 val _= writeln("####cut_bottom cuts#="^string_of_int (length cuts)^
115 ", cuts="^pos's2str cuts)*)
116 in ((pt'', cuts:pos' list), cutlevup b) end;
118 (**######################################################################**);
119 (*.go all levels from the bottom of 'pos' up to the root,
120 on each level compose the children of a node and accumulate the cut Nds
122 pos' list -> : for accumulation
123 bool -> : cutting shall be continued on the higher level(s)
124 ptree -> : the whole ptree for 'get_nd pt P' on each level
125 ptree -> : the Nd from the lower level for insertion at path
126 pos * posel -> : pos=path split for convenience
127 ptree -> : Nd the children of are under consideration on this call
129 ptree * pos' list : the updated parent-Nd and the pos's of the Nds cut
132 fun cut_levup (cuts:pos' list) clevup pt pt' (P:pos, p:posel) (Nd (b, bs)) =
133 let (*divide level into 3 parts...*)
134 val keep = take (p - 1, bs)
135 (*val pt' comes as argument from below*)
136 val (tail, tp) = (takerest (p, bs),
137 if null (takerest (p, bs)) then 0 else p + 1)
138 val (children, cuts') =
140 then (keep @ [pt'], get_allps [] (P @ [p+1]) tail)
141 else (keep @ [pt'] @ tail, [])
142 val clevup' = if clevup then cutlevup b else false
143 (*the first Nd with false stops cutting on all levels above*)
146 then (Nd (del_res b, children),
147 cuts' @ (if g_ostate b = Incomplete then [] else [(P,Res)]))
148 else (Nd (b, children), cuts')
149 (*val _= writeln("#####cut_levup clevup= "^bool2str clevup)
150 val _= writeln("#####cut_levup cutlevup b= "^bool2str (cutlevup b))
151 val _= writeln("#####cut_levup (P, p)="^pos2str (P @ [p])^
152 ", Nd=.............................................")
154 val _= writeln("#####cut_levup form='"^
155 term2str (get_obj g_form pt'' []))
156 val _= writeln("#####cut_levup cuts#="^string_of_int (length cuts)^
157 ", cuts="^pos's2str cuts)*)
158 in if null P then (pt'', (cuts @ cuts'):pos' list)
159 else let val (P, p) = split_last P
160 in cut_levup (cuts @ cuts') clevup' pt pt'' (P, p) (get_nd pt P)
164 (**######################################################################**);
165 (* use"../ME/ctreeNEW.sml";
166 use"ME/ctreeNEW.sml";
170 fun cut_tree pt (pos,_) =
171 if not (existpt pos pt)
172 then (pt,[]) (*appending a formula never cuts anything*)
173 else let val (P, p) = split_last pos
174 val ((pt', cuts), clevup) = cut_bottom (P, p) (get_nd pt P)
175 (* pt' is the updated parent of the Nd to cappend_..*)
176 in if null P then (pt', cuts)
177 else let val (P, p) = split_last P
178 in cut_levup cuts clevup pt pt' (P, p) (get_nd pt P)
185 (*######## eval from here ##########################################**)
186 (*######## eval from here ##########################################**)
187 (*######## eval from here ##########################################**)
189 fun append_atomic p l f r f' s pt =
190 let (*val _= writeln("##append_atomic: pos ="^pos2str p^
191 ", Nd=.............................................")
193 val (iss, f) = if existpt p pt andalso get_obj g_tac pt p=Empty_Tac
195 ((fst (get_obj g_loc pt p), Some l),
197 (*040223 else ((Some l, None), f)*)
198 else ((None, Some l), f)
199 in insert (PrfObj {cell = [(*3.00. unused*)],
205 ostate= s}) pt p end;
207 (*20.8.02: cappend_* FIXXXXME cut branches below cannot be decided here:
208 detail - generate - cappend: inserted, not appended !!!
210 cut decided in applicable_in !?!
212 fun cappend_atomic pt p loc f r f' s =
213 let val _= writeln("#cappend_atomic: pos ="^pos2str p)
214 val (pt',c) = cut_tree pt (p,Frm)
215 val _= writeln("#cappend_atomic: after cut")
216 val pt'' = append_atomic p loc f r f' s pt'
218 fun cappend_atomic pt p loc f r f' s =
219 (* val (pt, p, loc, f, r, f', s) =
220 (pt,p,l,f,Rewrite_Set_Inst (subst2subs subs',id_rls rls'),
223 ((*writeln("###cappend_atomic: pos ="^pos2str p);*)
224 apfst (append_atomic p loc f r f' s) (cut_tree pt (p,Frm))
228 fun append_form p l f pt =
229 ((*writeln("###append_form: pos ="^pos2str p);*)
230 insert (PrfObj {cell = [(*3.00. unused*)],
231 form = (*if existpt p pt
232 andalso get_obj g_tac pt p = Empty_Tac
233 (*distinction from 'old' (+complete!) pobjs*)
234 then get_obj g_form pt p else*) f,
236 loc = (Some l, None),
239 ostate= Incomplete}) pt p
241 (* val (p,loc,f) = ([1], e_istate, str2term "x + 1 = 2");
242 val (p,loc,f) = (fst p, e_istate, str2term "-1 + x = 0");
244 fun cappend_form pt p loc f =
245 ((*writeln("###cappend_form: pos ="^pos2str p);*)
246 apfst (append_form p loc f) (cut_tree pt (p,Frm))
251 fun append_result pt p l f s =
252 ((*writeln("###append_result: pos ="^pos2str p);*)
253 (appl_obj (repl_result (fst (get_obj g_loc pt p),
254 Some l) f s) pt p, [])
258 (*WN041022 deprecated, still for kbtest/diffapp.sml, /systest/root-equ.sml*)
259 fun append_parent p l f r b pt =
260 let (*val _= writeln("###append_parent: pos ="^pos2str p);*)
261 val (ll,f) = if existpt p pt andalso get_obj g_tac pt p=Empty_Tac
262 then ((fst (get_obj g_loc pt p), Some l),
264 else ((Some l, None), f)
266 {cell = [(*unused*)],
272 ostate= Incomplete}) pt p end;
273 fun cappend_parent pt p loc f r b =
274 ((*writeln("###cappend_parent: pos ="^pos2str p);*)
275 apfst (append_parent p loc f r b) (cut_tree pt (p,Und))
279 fun append_problem [] l fmz (strs,spec,hdf) _ =
280 ((*writeln("###append_problem: pos = []");*)
282 {cell = [(*3.00. unused*)],
283 origin= (strs,spec,hdf),
289 loc = (Some l, None),
290 branch= TransitiveB,(*FIXXXXXME.27.8.03: for equations only*)
292 ostate= Incomplete},[]))
294 | append_problem p l fmz (strs,spec,hdf) pt =
295 ((*writeln("###append_problem: pos ="^pos2str p);*)
297 {cell = [(*3.00. unused*)],
298 origin= (strs,spec,hdf),
304 loc = (Some l, None),
307 ostate= Incomplete}) pt p
309 fun cappend_problem _ [] loc fmz ori =
310 ((*writeln("###cappend_problem: pos = []");*)
311 (append_problem [] loc fmz ori EmptyPtree,[])
313 | cappend_problem pt p loc fmz ori =
314 ((*writeln("###cappend_problem: pos ="^pos2str p);*)
315 apfst (append_problem p (loc:istate) fmz ori) (cut_tree pt (p,Frm))
319 (* use"ME/ctreeNEW.sml";