wneuper@59292
|
1 |
(* Title: the calctree, which holds a calculation
|
wneuper@59292
|
2 |
Author: Walther Neuper 1999
|
wneuper@59292
|
3 |
(c) due to copyright terms
|
wneuper@59292
|
4 |
*)
|
wneuper@59292
|
5 |
|
wneuper@59292
|
6 |
signature BASIC_CALC_TREE =
|
wneuper@59292
|
7 |
sig (* vvv--- *.sml require these typs incrementally, with these exception -----------------vvv *)
|
wneuper@59294
|
8 |
(*===\<Longrightarrow> other ?mstools.sml? =================================================================*)
|
wneuper@59292
|
9 |
type state
|
wneuper@59292
|
10 |
type con
|
wneuper@59292
|
11 |
|
wneuper@59292
|
12 |
eqtype posel
|
wneuper@59292
|
13 |
type pos = posel list
|
wneuper@59292
|
14 |
val pos2str : int list -> string (* for datatypes.sml *)
|
wneuper@59292
|
15 |
datatype pos_ = Frm | Met | Pbl | Res | Und
|
wneuper@59292
|
16 |
val pos_2str : pos_ -> string
|
wneuper@59292
|
17 |
type pos'
|
wneuper@59292
|
18 |
val pos'2str : pos' -> string
|
wneuper@59292
|
19 |
val str2pos_ : string -> pos_ (* for datatypes.sml *)
|
wneuper@59292
|
20 |
val e_pos' : pos'
|
wneuper@59292
|
21 |
(* for generate.sml ?!? ca.*)
|
wneuper@59292
|
22 |
eqtype cellID
|
wneuper@59292
|
23 |
|
wneuper@59292
|
24 |
datatype branch = AndB | CollectB | IntersectB | MapB | NoBranch | OrB | SequenceB | TransitiveB
|
wneuper@59292
|
25 |
datatype ostate = Complete | Incomplete | Inconsistent
|
wneuper@59292
|
26 |
datatype ppobj =
|
wneuper@59292
|
27 |
PblObj of
|
wneuper@59292
|
28 |
{branch: branch,
|
wneuper@59405
|
29 |
cell: Celem.lrd option,
|
wneuper@59300
|
30 |
loc: (Selem.istate * Proof.context) option * (Selem.istate * Proof.context) option,
|
wneuper@59292
|
31 |
ostate: ostate,
|
wneuper@59299
|
32 |
result: Selem.result,
|
wneuper@59292
|
33 |
|
wneuper@59298
|
34 |
fmz: Selem.fmz,
|
wneuper@59405
|
35 |
origin: Model.ori list * Celem.spec * term,
|
wneuper@59316
|
36 |
probl: Model.itm list,
|
wneuper@59316
|
37 |
meth: Model.itm list,
|
wneuper@59405
|
38 |
spec: Celem.spec,
|
wneuper@59292
|
39 |
ctxt: Proof.context,
|
wneuper@59300
|
40 |
env: (Selem.istate * Proof.context) option}
|
wneuper@59292
|
41 |
| PrfObj of
|
wneuper@59292
|
42 |
{branch: branch,
|
wneuper@59405
|
43 |
cell: Celem.lrd option,
|
wneuper@59300
|
44 |
loc: (Selem.istate * Proof.context) option * (Selem.istate * Proof.context) option,
|
wneuper@59292
|
45 |
ostate: ostate,
|
wneuper@59299
|
46 |
result: Selem.result,
|
wneuper@59292
|
47 |
|
wneuper@59292
|
48 |
form: term,
|
wneuper@59302
|
49 |
tac: Tac.tac}
|
wneuper@59292
|
50 |
|
wneuper@59292
|
51 |
datatype ctree = EmptyPtree | Nd of ppobj * ctree list
|
wneuper@59292
|
52 |
val e_ctree : ctree (* TODO: replace by EmptyPtree*)
|
wneuper@59292
|
53 |
val existpt' : pos' -> ctree -> bool (* for interface.sml *)
|
wneuper@59292
|
54 |
val is_interpos : pos' -> bool (* for interface.sml *)
|
wneuper@59292
|
55 |
val lev_pred' : ctree -> pos' -> pos' (* for interface.sml *)
|
wneuper@59292
|
56 |
val ins_chn : ctree list -> ctree -> pos -> ctree (* for solve.sml *)
|
wneuper@59292
|
57 |
val children : ctree -> ctree list (* for solve.sml *)
|
wneuper@59292
|
58 |
val get_nd : ctree -> pos -> ctree (* for solve.sml *)
|
wneuper@59292
|
59 |
val just_created_ : ppobj -> bool (* for mathengine.sml *)
|
wneuper@59405
|
60 |
val just_created : state -> bool (* for mathengine.sml *)
|
wneuper@59405
|
61 |
val e_origin : Model.ori list * Celem.spec * term (* for mathengine.sml *)
|
wneuper@59292
|
62 |
|
wneuper@59292
|
63 |
val is_pblobj : ppobj -> bool
|
wneuper@59292
|
64 |
val is_pblobj' : ctree -> pos -> bool
|
wneuper@59292
|
65 |
val is_pblnd : ctree -> bool
|
wneuper@59292
|
66 |
|
wneuper@59405
|
67 |
val g_spec : ppobj -> Celem.spec
|
wneuper@59300
|
68 |
val g_loc : ppobj -> (Selem.istate * Proof.context) option * (Selem.istate * Proof.context) option
|
wneuper@59292
|
69 |
val g_form : ppobj -> term
|
wneuper@59316
|
70 |
val g_pbl : ppobj -> Model.itm list
|
wneuper@59316
|
71 |
val g_met : ppobj -> Model.itm list
|
wneuper@59405
|
72 |
val g_metID : ppobj -> Celem.metID
|
wneuper@59299
|
73 |
val g_result : ppobj -> Selem.result
|
wneuper@59302
|
74 |
val g_tac : ppobj -> Tac.tac
|
wneuper@59405
|
75 |
val g_domID : ppobj -> Celem.domID (* for appl.sml TODO: replace by thyID *)
|
wneuper@59405
|
76 |
val g_env : ppobj -> (Selem.istate * Proof.context) option (* for appl.sml *)
|
wneuper@59292
|
77 |
|
wneuper@59405
|
78 |
val g_origin : ppobj -> Model.ori list * Celem.spec * term (* for script.sml *)
|
wneuper@59405
|
79 |
val get_loc : ctree -> pos' -> Selem.istate * Proof.context (* for script.sml *)
|
wneuper@59405
|
80 |
val get_istate : ctree -> pos' -> Selem.istate (* for script.sml *)
|
wneuper@59292
|
81 |
val get_ctxt : ctree -> pos' -> Proof.context
|
wneuper@59292
|
82 |
val get_obj : (ppobj -> 'a) -> ctree -> pos -> 'a
|
wneuper@59292
|
83 |
val get_curr_formula : state -> term
|
wneuper@59292
|
84 |
val get_assumptions_ : ctree -> pos' -> term list (* for appl.sml *)
|
wneuper@59292
|
85 |
|
wneuper@59292
|
86 |
val is_e_ctxt : Proof.context -> bool (* for appl.sml *)
|
wneuper@59300
|
87 |
val new_val : term -> Selem.istate -> Selem.istate
|
wneuper@59292
|
88 |
(* for calchead.sml *)
|
wneuper@59292
|
89 |
type cid = cellID list
|
wneuper@59405
|
90 |
type ocalhd = bool * pos_ * term * Model.itm list * (bool * term) list * Celem.spec
|
wneuper@59292
|
91 |
datatype ptform = Form of term | ModSpec of ocalhd
|
wneuper@59405
|
92 |
val get_somespec' : Celem.spec -> Celem.spec -> Celem.spec
|
wneuper@59292
|
93 |
exception PTREE of string;
|
wneuper@59296
|
94 |
|
wneuper@59405
|
95 |
val par_pbl_det : ctree -> pos -> bool * pos * Celem.rls (* for appl.sml *)
|
wneuper@59405
|
96 |
val rootthy : ctree -> theory (* for script.sml *)
|
wneuper@59294
|
97 |
(* ---- made visible ONLY for structure CTaccess : CALC_TREE_ACCESS --------------------------- *)
|
wneuper@59294
|
98 |
val appl_obj : (ppobj -> ppobj) -> ctree -> pos -> ctree
|
wneuper@59294
|
99 |
val existpt : pos -> ctree -> bool (* also for tests *)
|
wneuper@59294
|
100 |
val cut_tree : ctree -> pos * 'a -> ctree * pos' list (* also for tests *)
|
wneuper@59294
|
101 |
val insert_pt : ppobj -> ctree -> int list -> ctree
|
wneuper@59294
|
102 |
(* ---- made visible ONLY for structure CTnavi : CALC_TREE_NAVIGATION ------------------------- *)
|
wneuper@59296
|
103 |
val g_branch : ppobj -> branch
|
wneuper@59296
|
104 |
val g_form' : ctree -> term
|
wneuper@59296
|
105 |
val g_ostate : ppobj -> ostate
|
wneuper@59296
|
106 |
val g_ostate' : ctree -> ostate
|
wneuper@59296
|
107 |
val g_res : ppobj -> term
|
wneuper@59296
|
108 |
val g_res' : ctree -> term
|
wneuper@59296
|
109 |
(*/---- duplicates in CTnavi, reconsider structs -----------------------------------------------
|
wneuper@59296
|
110 |
val lev_on : CTbasic.pos -> CTbasic.pos (* duplicate in ctree-navi.sml *)
|
wneuper@59296
|
111 |
val lev_dn : CTbasic.pos -> CTbasic.pos (* duplicate in ctree-navi.sml *)
|
wneuper@59296
|
112 |
val par_pblobj : CTbasic.ctree -> CTbasic.pos -> CTbasic.pos (* duplicate in ctree-navi.sml *)
|
wneuper@59296
|
113 |
---- duplicates in CTnavi, reconsider structs ----------------------------------------------/*)
|
wneuper@59294
|
114 |
|
wneuper@59299
|
115 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
wneuper@59292
|
116 |
val pr_ctree : (pos -> ppobj -> string) -> ctree -> string
|
wneuper@59292
|
117 |
val pr_short : pos -> ppobj -> string
|
wneuper@59292
|
118 |
val g_ctxt : ppobj -> Proof.context
|
wneuper@59298
|
119 |
val g_fmz : ppobj -> Selem.fmz
|
wneuper@59292
|
120 |
val get_allp : pos' list -> pos * (int list * pos_) -> ctree -> pos' list
|
wneuper@59292
|
121 |
val get_allps : (pos * pos_) list -> posel list -> ctree list -> pos' list
|
wneuper@59292
|
122 |
val get_allpos' : pos * posel -> ctree -> pos' list
|
wneuper@59292
|
123 |
val get_allpos's : pos * posel -> ctree list -> (pos * pos_) list
|
wneuper@59292
|
124 |
val cut_bottom : pos * posel -> ctree -> (ctree * pos' list) * bool
|
wneuper@59292
|
125 |
val cut_level : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
|
wneuper@59292
|
126 |
val cut_level_'_ : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
|
wneuper@59292
|
127 |
val get_trace : ctree -> int list -> int list -> int list list
|
wneuper@59292
|
128 |
val branch2str : branch -> string
|
wneuper@59299
|
129 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
wneuper@59310
|
130 |
|
wneuper@59310
|
131 |
(*----- unused code, kept as hints to design ideas ---------------------------------------------*)
|
wneuper@59310
|
132 |
(* NONE *)
|
wneuper@59292
|
133 |
end
|
wneuper@59292
|
134 |
|
wneuper@59292
|
135 |
(**)
|
wneuper@59292
|
136 |
structure CTbasic(**): BASIC_CALC_TREE(**) =
|
wneuper@59292
|
137 |
struct
|
wneuper@59292
|
138 |
(**)
|
wneuper@59292
|
139 |
type env = (term * term) list;
|
wneuper@59292
|
140 |
|
wneuper@59292
|
141 |
datatype branch =
|
wneuper@59292
|
142 |
NoBranch | AndB | OrB
|
wneuper@59292
|
143 |
| TransitiveB (* FIXXXME.0308: set branch from met in Apply_Method
|
wneuper@59292
|
144 |
FIXXXME.0402: -"- in Begin_Trans'*)
|
wneuper@59292
|
145 |
| SequenceB | IntersectB | CollectB | MapB;
|
wneuper@59292
|
146 |
|
wneuper@59292
|
147 |
fun branch2str NoBranch = "NoBranch" (* for tests only *)
|
wneuper@59292
|
148 |
| branch2str AndB = "AndB"
|
wneuper@59292
|
149 |
| branch2str OrB = "OrB"
|
wneuper@59292
|
150 |
| branch2str TransitiveB = "TransitiveB"
|
wneuper@59292
|
151 |
| branch2str SequenceB = "SequenceB"
|
wneuper@59292
|
152 |
| branch2str IntersectB = "IntersectB"
|
wneuper@59292
|
153 |
| branch2str CollectB = "CollectB"
|
wneuper@59292
|
154 |
| branch2str MapB = "MapB";
|
wneuper@59292
|
155 |
|
wneuper@59292
|
156 |
datatype ostate =
|
wneuper@59292
|
157 |
Incomplete | Complete | Inconsistent (* WN041020 latter still unused *);
|
wneuper@59292
|
158 |
fun ostate2str Incomplete = "Incomplete" (* for tests only *)
|
wneuper@59292
|
159 |
| ostate2str Complete = "Complete"
|
wneuper@59292
|
160 |
| ostate2str Inconsistent = "Inconsistent";
|
wneuper@59292
|
161 |
|
wneuper@59292
|
162 |
type cellID = int;
|
wneuper@59292
|
163 |
type cid = cellID list;
|
wneuper@59292
|
164 |
|
wneuper@59292
|
165 |
type posel = int; (* for readability in funs accessing Ctree *)
|
wneuper@59292
|
166 |
type pos = int list;
|
wneuper@59292
|
167 |
val pos2str = ints2str';
|
wneuper@59292
|
168 |
datatype pos_ =
|
wneuper@59292
|
169 |
Pbl (* PblObj-position: problem-type *)
|
wneuper@59292
|
170 |
| Met (* PblObj-position: method *)
|
wneuper@59292
|
171 |
| Frm (* PblObj-position: -> Pbl in ME (not by moveDown !)
|
wneuper@59299
|
172 |
| PrfObj-position: formula *)
|
wneuper@59292
|
173 |
| Res (* PblObj | PrfObj-position: result *)
|
wneuper@59292
|
174 |
| Und; (* undefined*)
|
wneuper@59292
|
175 |
fun pos_2str Pbl = "Pbl"
|
wneuper@59292
|
176 |
| pos_2str Met = "Met"
|
wneuper@59292
|
177 |
| pos_2str Frm = "Frm"
|
wneuper@59292
|
178 |
| pos_2str Res = "Res"
|
wneuper@59292
|
179 |
| pos_2str Und = "Und";
|
wneuper@59292
|
180 |
fun str2pos_ "Pbl" = Pbl
|
wneuper@59292
|
181 |
| str2pos_ "Met" = Met
|
wneuper@59292
|
182 |
| str2pos_ "Frm" = Frm
|
wneuper@59292
|
183 |
| str2pos_ "Res" = Res
|
wneuper@59292
|
184 |
| str2pos_ "Und" = Und
|
wneuper@59292
|
185 |
| str2pos_ str = error ("str2pos_: wrong argument = " ^ str)
|
wneuper@59292
|
186 |
|
wneuper@59292
|
187 |
type pos' = pos * pos_;
|
wneuper@59292
|
188 |
(*WN0312 remembering interator (pos * pos_) for ctree
|
wneuper@59292
|
189 |
pos : lev_on, lev_dn, lev_up
|
wneuper@59292
|
190 |
pos_:
|
wneuper@59292
|
191 |
# generate1 sets pos_ if possible ...?WN0502?NOT...
|
wneuper@59292
|
192 |
# generate1 does NOT set pos, because certain nodes can be lev_on OR lev_dn
|
wneuper@59292
|
193 |
exceptions: Begin/End_Trans
|
wneuper@59292
|
194 |
# thus generate(1) called in
|
wneuper@59292
|
195 |
.# assy, locate_gen
|
wneuper@59292
|
196 |
.# nxt_solv (tac_ -cases); general case:
|
wneuper@59292
|
197 |
val pos' = case pos' of (p,Res) => (lev_on p',Res) | _ => pos'
|
wneuper@59292
|
198 |
# WN050220, S(604):
|
wneuper@59292
|
199 |
generate1...(Rewrite(f,..,res))..(pos, pos_)
|
wneuper@59292
|
200 |
cappend_atomic.................pos ////// gets f+res always!!!
|
wneuper@59292
|
201 |
cut_tree....................pos, pos_
|
wneuper@59292
|
202 |
*)
|
wneuper@59292
|
203 |
fun pos'2str (p, p_) = pair2str (ints2str' p, pos_2str p_);
|
wneuper@59292
|
204 |
fun pos's2str ps = (strs2str' o (map pos'2str)) ps; (* for tests only *)
|
wneuper@59292
|
205 |
val e_pos' = ([], Und);
|
wneuper@59292
|
206 |
|
wneuper@59292
|
207 |
(* ATTENTION: does _not_ recognise Variable.declare_constraints, etc...*)
|
wneuper@59397
|
208 |
fun is_e_ctxt ctxt = Context.eq_thy (Proof_Context.theory_of ctxt, @{theory "Pure"});
|
wneuper@59292
|
209 |
|
wneuper@59300
|
210 |
type iist = Selem.istate option * Selem.istate option;
|
wneuper@59292
|
211 |
(*val e_iist = (e_istate, e_istate); --- sinnlos f"ur NICHT-equality-type*)
|
wneuper@59292
|
212 |
|
wneuper@59292
|
213 |
|
wneuper@59300
|
214 |
fun new_val v (Selem.ScrState (env, loc_, topt, _, safe, bool)) =
|
wneuper@59300
|
215 |
(Selem.ScrState (env, loc_, topt, v, safe, bool))
|
wneuper@59292
|
216 |
| new_val _ _ = error "new_val: only for ScrState";
|
wneuper@59292
|
217 |
|
wneuper@59292
|
218 |
datatype con = land | lor;
|
wneuper@59292
|
219 |
|
wneuper@59292
|
220 |
(* executed tactics (tac_s) with local environment etc.;
|
wneuper@59292
|
221 |
used for continuing eval script + for generate *)
|
wneuper@59292
|
222 |
type ets =
|
wneuper@59405
|
223 |
(Celem.loc_ *(* of tactic in scr, tactic (weakly) associated with tac_ *)
|
wneuper@59302
|
224 |
(Tac.tac_ * (* (for generate) *)
|
wneuper@59302
|
225 |
env * (* with 'tactic=result' as rule, tactic ev. _not_ ready for 'parallel let' *)
|
wneuper@59302
|
226 |
env * (* with results of (ready) tacs *)
|
wneuper@59302
|
227 |
term * (* itr_arg of tactic, for upd. env at Repeat, Try *)
|
wneuper@59302
|
228 |
term * (* result value of the tac *)
|
wneuper@59299
|
229 |
Selem.safe))
|
wneuper@59292
|
230 |
list;
|
wneuper@59292
|
231 |
|
wneuper@59292
|
232 |
fun ets2s (l,(m,eno,env,iar,res,s)) =
|
wneuper@59405
|
233 |
"\n(" ^ Celem.loc_2str l ^ ",(" ^ Tac.tac_2str m ^
|
wneuper@59405
|
234 |
",\n ens= " ^ Celem.subst2str eno ^
|
wneuper@59405
|
235 |
",\n env= " ^ Celem.subst2str env ^
|
wneuper@59405
|
236 |
",\n iar= " ^ Celem.term2str iar ^
|
wneuper@59405
|
237 |
",\n res= " ^ Celem.term2str res ^
|
wneuper@59299
|
238 |
",\n " ^ Selem.safe2str s ^ "))";
|
wneuper@59292
|
239 |
fun ets2str (ets: ets) = (strs2str o (map ets2s)) ets; (* for tests only *)
|
wneuper@59292
|
240 |
|
wneuper@59292
|
241 |
type envp =(*9.5.03: unused, delete with field in ctree.PblObj FIXXXME*)
|
wneuper@59292
|
242 |
(int * term list) list * (* assoc-list: args of met*)
|
wneuper@59292
|
243 |
(int * rls) list * (* assoc-list: tacs already done ///15.9.00*)
|
wneuper@59292
|
244 |
(int * ets) list * (* assoc-list: tacs etc. already done*)
|
wneuper@59292
|
245 |
(string * pos) list; (* asms * from where*)
|
wneuper@59292
|
246 |
|
wneuper@59292
|
247 |
datatype ppobj = (* TODO: arrange according to signature *)
|
wneuper@59292
|
248 |
PrfObj of
|
wneuper@59405
|
249 |
{cell : Celem.lrd option, (* where in form tac has been applied, FIXME.WN0607 rename field *)
|
wneuper@59292
|
250 |
form : term, (* where tac is applied to *)
|
wneuper@59302
|
251 |
tac : Tac.tac, (* also in istate *)
|
wneuper@59300
|
252 |
loc : (Selem.istate * (* script interpreter state *)
|
wneuper@59292
|
253 |
Proof.context) (* context for provers, type inference *)
|
wneuper@59292
|
254 |
option * (* both for interpreter location on Frm, Pbl, Met *)
|
wneuper@59300
|
255 |
(Selem.istate * (* script interpreter state *)
|
wneuper@59292
|
256 |
Proof.context) (* context for provers, type inference *)
|
wneuper@59292
|
257 |
option, (* both for interpreter location on Res *)
|
wneuper@59292
|
258 |
(*(NONE,NONE) <==> e_istate ! see update_loc, get_loc *)
|
wneuper@59292
|
259 |
branch: branch, (* only rudimentary *)
|
wneuper@59299
|
260 |
result: Selem.result, (* result and assumptions *)
|
wneuper@59292
|
261 |
ostate: ostate} (* Complete <=> result is OK *)
|
wneuper@59292
|
262 |
| PblObj of
|
wneuper@59405
|
263 |
{cell : Celem.lrd option, (* unused: meaningful only for some _Prf_Obj *)
|
wneuper@59298
|
264 |
fmz : Selem.fmz, (* from init:FIXME never use this spec;-drop *)
|
wneuper@59316
|
265 |
origin: (Model.ori list) * (* representation from fmz+pbt
|
wneuper@59292
|
266 |
for efficiently adding items in probl, meth *)
|
wneuper@59405
|
267 |
Celem.spec * (* updated by Refine_Tacitly *)
|
wneuper@59292
|
268 |
term, (* headline of calc-head, as calculated initially(!) *)
|
wneuper@59405
|
269 |
spec : Celem.spec, (* explicitly input *)
|
wneuper@59405
|
270 |
probl : Model.itm list, (* itms explicitly input *)
|
wneuper@59405
|
271 |
meth : Model.itm list, (* itms automatically added to copy of probl *)
|
wneuper@59292
|
272 |
ctxt : Proof.context, (* WN110513 introduced to avoid [*] [**] *)
|
wneuper@59300
|
273 |
env : (Selem.istate * Proof.context) option, (* istate only for initac in script
|
wneuper@59292
|
274 |
context for specify phase on this node NO..
|
wneuper@59292
|
275 |
..NO: this conflicts with init_form/initac: see Apply_Method without init_form *)
|
wneuper@59300
|
276 |
loc : (Selem.istate * Proof.context) option * (Selem.istate * (* like PrfObj *)
|
wneuper@59292
|
277 |
Proof.context) option, (* for spec-phase [*], NO..
|
wneuper@59292
|
278 |
..NO: raises errors not tracable on WN110513 [**] *)
|
wneuper@59292
|
279 |
branch: branch, (* like PrfObj *)
|
wneuper@59299
|
280 |
result: Selem.result, (* like PrfObj *)
|
wneuper@59292
|
281 |
ostate: ostate}; (* like PrfObj *)
|
wneuper@59292
|
282 |
|
wneuper@59292
|
283 |
(* this tree contains isac's calculations;
|
wneuper@59292
|
284 |
the tree's structure has been copied from an early version of Theorema(c);
|
wneuper@59292
|
285 |
it has the disadvantage, that there is no space
|
wneuper@59292
|
286 |
for the first tactic in a script generating the first formula at (p,Frm);
|
wneuper@59292
|
287 |
this trouble has been covered by 'init_form' and 'Take' so far,
|
wneuper@59292
|
288 |
but it is crucial if the first tactic in a script is eg. 'Subproblem';
|
wneuper@59292
|
289 |
see 'type tac', Apply_Method.
|
wneuper@59292
|
290 |
*)
|
wneuper@59292
|
291 |
datatype ctree =
|
wneuper@59292
|
292 |
EmptyPtree
|
wneuper@59292
|
293 |
| Nd of ppobj * (ctree list);
|
wneuper@59292
|
294 |
val e_ctree = EmptyPtree;
|
wneuper@59292
|
295 |
type state = ctree * pos'
|
wneuper@59292
|
296 |
|
wneuper@59292
|
297 |
fun is_pblobj (PblObj _) = true
|
wneuper@59292
|
298 |
| is_pblobj _ = false;
|
wneuper@59292
|
299 |
|
wneuper@59292
|
300 |
exception PTREE of string;
|
wneuper@59292
|
301 |
fun nth _ [] = raise PTREE "nth _ []"
|
wneuper@59292
|
302 |
| nth 1 (x :: _) = x
|
wneuper@59292
|
303 |
| nth n (_ :: xs) = nth (n - 1) xs;
|
wneuper@59292
|
304 |
(*> nth 2 [11,22,33]; -->> val it = 22 : int*)
|
wneuper@59292
|
305 |
|
wneuper@59292
|
306 |
|
wneuper@59292
|
307 |
(** convert ctree to a string **)
|
wneuper@59292
|
308 |
|
wneuper@59292
|
309 |
(* convert a pos from list to string *)
|
wneuper@59292
|
310 |
fun pr_pos ps = (space_implode "." (map string_of_int ps))^". ";
|
wneuper@59292
|
311 |
(* show hd origin or form only *)
|
wneuper@59292
|
312 |
fun pr_short p (PblObj _) = pr_pos p ^ " ----- pblobj -----\n" (* for tests only *)
|
wneuper@59405
|
313 |
| pr_short p (PrfObj {form = form, ...}) = pr_pos p ^ Celem.term2str form ^ "\n";
|
wneuper@59292
|
314 |
fun pr_ctree f pt = (* for tests only *)
|
wneuper@59292
|
315 |
let
|
wneuper@59292
|
316 |
fun pr_pt _ _ EmptyPtree = ""
|
wneuper@59292
|
317 |
| pr_pt pfn ps (Nd (b, [])) = pfn ps b
|
wneuper@59292
|
318 |
| pr_pt pfn ps (Nd (b, ts)) = pfn ps b ^ prts pfn ps 1 ts
|
wneuper@59292
|
319 |
and prts _ _ _ [] = ""
|
wneuper@59292
|
320 |
| prts pfn ps p (t :: ts) = (pr_pt pfn (ps @ [p]) t)^
|
wneuper@59292
|
321 |
(prts pfn ps (p + 1) ts)
|
wneuper@59292
|
322 |
in pr_pt f [] pt end;
|
wneuper@59292
|
323 |
|
wneuper@59292
|
324 |
(** access the branches of ctree **)
|
wneuper@59292
|
325 |
|
wneuper@59292
|
326 |
fun repl [] _ _ = raise PTREE "repl [] _ _"
|
wneuper@59292
|
327 |
| repl (_ :: ls) 1 e = e :: ls
|
wneuper@59292
|
328 |
| repl (l :: ls) n e = l :: (repl ls (n-1) e);
|
wneuper@59292
|
329 |
fun repl_app ls n e =
|
wneuper@59292
|
330 |
let
|
wneuper@59292
|
331 |
val lim = 1 + length ls
|
wneuper@59292
|
332 |
in
|
wneuper@59292
|
333 |
if n > lim
|
wneuper@59292
|
334 |
then raise PTREE "repl_app: n > lim"
|
wneuper@59292
|
335 |
else if n = lim
|
wneuper@59292
|
336 |
then ls @ [e]
|
wneuper@59292
|
337 |
else repl ls n e end;
|
wneuper@59292
|
338 |
|
wneuper@59292
|
339 |
(* get from obj at pos by f : ppobj -> 'a *)
|
wneuper@59292
|
340 |
fun get_obj _ EmptyPtree _ = raise PTREE "get_obj f EmptyPtree"
|
wneuper@59292
|
341 |
| get_obj f (Nd (b, _)) [] = f b
|
wneuper@59292
|
342 |
| get_obj f (Nd (_, bs)) (p :: ps) =
|
wneuper@59292
|
343 |
let
|
wneuper@59292
|
344 |
val _ = (nth p bs)
|
wneuper@59292
|
345 |
handle _ => raise PTREE ("get_obj: pos = " ^ ints2str' (p::ps) ^ " does not exist");
|
wneuper@59292
|
346 |
in
|
wneuper@59292
|
347 |
(get_obj f (nth p bs) ps)
|
wneuper@59292
|
348 |
handle _ => raise PTREE ("get_obj: pos = " ^ ints2str' (p::ps) ^ " does not exist")
|
wneuper@59292
|
349 |
end;
|
wneuper@59292
|
350 |
fun get_nd EmptyPtree _ = raise PTREE "get_nd EmptyPtree"
|
wneuper@59292
|
351 |
| get_nd n [] = n
|
wneuper@59292
|
352 |
| get_nd (Nd (_, nds)) (pos as p :: ps) = (get_nd (nth p nds) ps)
|
wneuper@59292
|
353 |
handle _ => raise PTREE ("get_nd: not existent pos = " ^ ints2str' pos);
|
wneuper@59292
|
354 |
|
wneuper@59292
|
355 |
(* for use by get_obj *)
|
wneuper@59292
|
356 |
fun g_form (PrfObj {form = f,...}) = f
|
wneuper@59292
|
357 |
| g_form (PblObj {origin= (_,_,f),...}) = f;
|
wneuper@59292
|
358 |
fun g_form' (Nd (PrfObj {form = f, ...}, _)) = f
|
wneuper@59292
|
359 |
| g_form' (Nd (PblObj {origin= (_, _, f),...}, _)) = f
|
wneuper@59292
|
360 |
| g_form' _ = error "g_form': uncovered fun def.";
|
wneuper@59292
|
361 |
(* | g_form _ = raise PTREE "g_form not for PblObj";*)
|
wneuper@59292
|
362 |
fun g_origin (PblObj {origin = ori, ...}) = ori
|
wneuper@59292
|
363 |
| g_origin _ = raise PTREE "g_origin not for PrfObj";
|
wneuper@59292
|
364 |
fun g_fmz (PblObj {fmz = f, ...}) = f (* for tests only *)
|
wneuper@59292
|
365 |
| g_fmz _ = raise PTREE "g_fmz not for PrfObj";
|
wneuper@59292
|
366 |
fun g_spec (PblObj {spec = s, ...}) = s
|
wneuper@59292
|
367 |
| g_spec _ = raise PTREE "g_spec not for PrfObj";
|
wneuper@59292
|
368 |
fun g_pbl (PblObj {probl = p, ...}) = p
|
wneuper@59292
|
369 |
| g_pbl _ = raise PTREE "g_pbl not for PrfObj";
|
wneuper@59292
|
370 |
fun g_met (PblObj {meth = p, ...}) = p
|
wneuper@59292
|
371 |
| g_met _ = raise PTREE "g_met not for PrfObj";
|
wneuper@59292
|
372 |
fun g_domID (PblObj {spec = (d, _, _), ...}) = d
|
wneuper@59292
|
373 |
| g_domID _ = raise PTREE "g_metID not for PrfObj";
|
wneuper@59292
|
374 |
fun g_metID (PblObj {spec = (_, _, m), ...}) = m
|
wneuper@59292
|
375 |
| g_metID _ = raise PTREE "g_metID not for PrfObj";
|
wneuper@59292
|
376 |
fun g_ctxt (PblObj {ctxt, ...}) = ctxt
|
wneuper@59292
|
377 |
| g_ctxt _ = raise PTREE "g_ctxt not for PrfObj";
|
wneuper@59292
|
378 |
fun g_env (PblObj {env, ...}) = env
|
wneuper@59292
|
379 |
| g_env _ = raise PTREE "g_env not for PrfObj";
|
wneuper@59292
|
380 |
fun g_loc (PblObj {loc = l, ...}) = l
|
wneuper@59292
|
381 |
| g_loc (PrfObj {loc = l, ...}) = l;
|
wneuper@59292
|
382 |
fun g_branch (PblObj {branch = b, ...}) = b
|
wneuper@59292
|
383 |
| g_branch (PrfObj {branch = b, ...}) = b;
|
wneuper@59302
|
384 |
fun g_tac (PblObj {spec = (_, _, m),...}) = Tac.Apply_Method m
|
wneuper@59292
|
385 |
| g_tac (PrfObj {tac = m, ...}) = m;
|
wneuper@59292
|
386 |
fun g_result (PblObj {result = r, ...}) = r
|
wneuper@59292
|
387 |
| g_result (PrfObj {result = r, ...}) = r;
|
wneuper@59292
|
388 |
fun g_res (PblObj {result = (r, _) ,...}) = r
|
wneuper@59299
|
389 |
| g_res (PrfObj {result = (r, _),...}) = r;
|
wneuper@59292
|
390 |
fun g_res' (Nd (PblObj {result = (r, _), ...}, _)) = r
|
wneuper@59292
|
391 |
| g_res' (Nd (PrfObj {result = (r, _),...}, _)) = r
|
wneuper@59292
|
392 |
| g_res' _ = raise PTREE "g_res': uncovered fun def.";
|
wneuper@59292
|
393 |
fun g_ostate (PblObj {ostate = r, ...}) = r
|
wneuper@59292
|
394 |
| g_ostate (PrfObj {ostate = r, ...}) = r;
|
wneuper@59292
|
395 |
fun g_ostate' (Nd (PblObj {ostate = r, ...}, _)) = r
|
wneuper@59292
|
396 |
| g_ostate' (Nd (PrfObj {ostate = r, ...}, _)) = r
|
wneuper@59292
|
397 |
| g_ostate' _ = raise PTREE "g_ostate': uncovered fun def.";
|
wneuper@59292
|
398 |
|
wneuper@59292
|
399 |
(* get the formula preceeding the current position in a calculation *)
|
wneuper@59292
|
400 |
fun get_curr_formula (pt, (p, p_)) =
|
wneuper@59292
|
401 |
case p_ of
|
wneuper@59292
|
402 |
Frm => get_obj g_form pt p
|
wneuper@59292
|
403 |
| Res => (fst o (get_obj g_result pt)) p
|
wneuper@59292
|
404 |
| _ => #3 (get_obj g_origin pt p);
|
wneuper@59292
|
405 |
|
wneuper@59292
|
406 |
(* in CalcTree/Subproblem an 'just_created_' model is created;
|
wneuper@59292
|
407 |
this is filled to 'untouched' by Model/Refine_Problem *)
|
wneuper@59292
|
408 |
fun just_created_ (PblObj {meth, probl, spec, ...}) =
|
wneuper@59405
|
409 |
null meth andalso null probl andalso spec = Celem.e_spec
|
wneuper@59292
|
410 |
| just_created_ _ = raise PTREE "g_ostate': uncovered fun def.";
|
wneuper@59405
|
411 |
val e_origin = ([], Celem.e_spec, Celem.e_term);
|
wneuper@59292
|
412 |
|
wneuper@59292
|
413 |
fun just_created (pt, (p, _)) =
|
wneuper@59292
|
414 |
let val ppobj = get_obj I pt p
|
wneuper@59292
|
415 |
in is_pblobj ppobj andalso just_created_ ppobj end;
|
wneuper@59292
|
416 |
|
wneuper@59292
|
417 |
(* does the pos in the ctree exist ? *)
|
wneuper@59292
|
418 |
fun existpt pos pt = can (get_obj I pt) pos;
|
wneuper@59292
|
419 |
(* does the pos' in the ctree exist, ie. extra check for result in the node *)
|
wneuper@59299
|
420 |
fun existpt' (p, p_) pt =
|
wneuper@59292
|
421 |
if can (get_obj I pt) p
|
wneuper@59292
|
422 |
then case p_ of
|
wneuper@59292
|
423 |
Res => get_obj g_ostate pt p = Complete
|
wneuper@59292
|
424 |
| _ => true
|
wneuper@59292
|
425 |
else false;
|
wneuper@59292
|
426 |
|
wneuper@59292
|
427 |
(* is this position appropriate for calculating intermediate steps? *)
|
wneuper@59292
|
428 |
fun is_interpos (_, Res) = true
|
wneuper@59292
|
429 |
| is_interpos _ = false;
|
wneuper@59292
|
430 |
|
wneuper@59296
|
431 |
(* get the children of a node in ctree *)
|
wneuper@59296
|
432 |
fun children (Nd (PblObj _, cn)) = cn
|
wneuper@59296
|
433 |
| children (Nd (PrfObj _, cn)) = cn
|
wneuper@59296
|
434 |
| children _ = error "children: uncovered fun def.";
|
wneuper@59292
|
435 |
|
wneuper@59296
|
436 |
(*/--------------- duplicates in ctree-navi.sml: required also here below ---------------\*)
|
wneuper@59296
|
437 |
fun lev_on [] = raise PTREE "lev_on []"
|
wneuper@59296
|
438 |
| lev_on pos =
|
wneuper@59296
|
439 |
let val len = length pos
|
wneuper@59296
|
440 |
in (drop_last pos) @ [(nth len pos)+1] end;
|
wneuper@59296
|
441 |
fun lev_up [] = raise PTREE "lev_up []"
|
wneuper@59296
|
442 |
| lev_up p = (drop_last p):pos;
|
wneuper@59292
|
443 |
(* find the position of the next parent which is a PblObj in ctree *)
|
wneuper@59292
|
444 |
fun par_pblobj _ [] = []
|
wneuper@59292
|
445 |
| par_pblobj pt p =
|
wneuper@59292
|
446 |
let
|
wneuper@59292
|
447 |
fun par _ [] = []
|
wneuper@59292
|
448 |
| par pt p =
|
wneuper@59292
|
449 |
if is_pblobj (get_obj I pt p)
|
wneuper@59292
|
450 |
then p
|
wneuper@59292
|
451 |
else par pt (lev_up p)
|
wneuper@59292
|
452 |
in par pt (lev_up p) end;
|
wneuper@59296
|
453 |
(*\--------------- duplicates in ctree-navi.sml: required also here below ---------------/*)
|
wneuper@59292
|
454 |
|
wneuper@59292
|
455 |
(* find the next parent, which is either a PblObj (return true)
|
wneuper@59292
|
456 |
or a PrfObj with tac = Detail_Set (return false)
|
wneuper@59292
|
457 |
FIXME.030403: re-organize par_pbl_det after rls' --> rls*)
|
wneuper@59405
|
458 |
fun par_pbl_det pt [] = (true, [], Celem.Erls)
|
wneuper@59292
|
459 |
| par_pbl_det pt p =
|
wneuper@59292
|
460 |
let
|
wneuper@59405
|
461 |
fun par _ [] = (true, [], Celem.Erls)
|
wneuper@59292
|
462 |
| par pt p =
|
wneuper@59292
|
463 |
if is_pblobj (get_obj I pt p)
|
wneuper@59405
|
464 |
then (true, p, Celem.Erls)
|
wneuper@59292
|
465 |
else case get_obj g_tac pt p of
|
wneuper@59302
|
466 |
Tac.Rewrite_Set rls' => (false, p, assoc_rls rls')
|
wneuper@59302
|
467 |
| Tac.Rewrite_Set_Inst (_, rls') => (false, p, assoc_rls rls')
|
wneuper@59292
|
468 |
| _ => par pt (lev_up p)
|
wneuper@59292
|
469 |
in par pt (lev_up p) end;
|
wneuper@59292
|
470 |
|
wneuper@59292
|
471 |
(* insert obj b into ctree at pos, ev.overwriting this pos *)
|
wneuper@59292
|
472 |
fun insert_pt b EmptyPtree [] = Nd (b, [])
|
wneuper@59292
|
473 |
| insert_pt _ EmptyPtree _ = raise PTREE "insert_pt b Empty _"
|
wneuper@59292
|
474 |
| insert_pt _ (Nd ( _, _)) [] = raise PTREE "insert_pt b _ []"
|
wneuper@59292
|
475 |
| insert_pt b (Nd (b', bs)) (p :: []) = Nd (b', repl_app bs p (Nd (b, [])))
|
wneuper@59292
|
476 |
| insert_pt b (Nd (b', bs)) (p :: ps) = Nd (b', repl_app bs p (insert_pt b (nth p bs) ps));
|
wneuper@59292
|
477 |
|
wneuper@59292
|
478 |
(* insert children to a node without children. compare: fun insert_pt *)
|
wneuper@59292
|
479 |
fun ins_chn _ EmptyPtree _ = raise PTREE "ins_chn: EmptyPtree"
|
wneuper@59292
|
480 |
| ins_chn _ (Nd _) [] = raise PTREE "ins_chn: pos = []"
|
wneuper@59292
|
481 |
| ins_chn ns (Nd (b, bs)) (p :: []) =
|
wneuper@59292
|
482 |
if p > length bs
|
wneuper@59292
|
483 |
then raise PTREE "ins_chn: pos not existent"
|
wneuper@59292
|
484 |
else
|
wneuper@59292
|
485 |
let
|
wneuper@59292
|
486 |
val (b', bs') = case nth p bs of
|
wneuper@59292
|
487 |
Nd (b', bs') => (b', bs')
|
wneuper@59292
|
488 |
| _ => error "ins_chn: uncovered case nth"
|
wneuper@59292
|
489 |
in
|
wneuper@59292
|
490 |
if null bs'
|
wneuper@59292
|
491 |
then Nd (b, repl_app bs p (Nd (b', ns)))
|
wneuper@59292
|
492 |
else raise PTREE "ins_chn: pos mustNOT be overwritten"
|
wneuper@59292
|
493 |
end
|
wneuper@59292
|
494 |
| ins_chn ns (Nd (b, bs)) (p::ps) = Nd (b, repl_app bs p (ins_chn ns (nth p bs) ps));
|
wneuper@59292
|
495 |
|
wneuper@59292
|
496 |
(* apply f to obj at pos, f: ppobj -> ppobj *)
|
wneuper@59292
|
497 |
fun appl_to_node f (Nd (b, bs)) = Nd (f b, bs)
|
wneuper@59292
|
498 |
| appl_to_node _ _ = error "appl_to_node: uncovered fun def.";
|
wneuper@59292
|
499 |
fun appl_obj _ EmptyPtree [] = EmptyPtree
|
wneuper@59292
|
500 |
| appl_obj _ EmptyPtree _ = raise PTREE "appl_obj f Empty _"
|
wneuper@59292
|
501 |
| appl_obj f (Nd (b, bs)) [] = Nd (f b, bs)
|
wneuper@59292
|
502 |
| appl_obj f (Nd (b, bs)) (p :: []) = Nd (b, repl_app bs p (((appl_to_node f) o (nth p)) bs))
|
wneuper@59292
|
503 |
| appl_obj f (Nd (b, bs)) (p :: ps) = Nd (b, repl_app bs p (appl_obj f (nth p bs) (ps:pos)));
|
wneuper@59292
|
504 |
|
wneuper@59292
|
505 |
|
wneuper@59292
|
506 |
type ocalhd =
|
wneuper@59292
|
507 |
bool * (* ALL itms+preconds true *)
|
wneuper@59292
|
508 |
pos_ * (* model belongs to Problem | Method *)
|
wneuper@59292
|
509 |
term * (* header: Problem... or Cas FIXME.0312: item for marking syntaxerrors *)
|
wneuper@59405
|
510 |
Model.itm list * (* model: given, find, relate *)
|
wneuper@59292
|
511 |
((bool * term) list) *(* model: preconds *)
|
wneuper@59405
|
512 |
Celem.spec; (* specification *)
|
wneuper@59405
|
513 |
val e_ocalhd = (false, Und, Celem.e_term, [Model.e_itm], [(false, Celem.e_term)], Celem.e_spec);
|
wneuper@59292
|
514 |
|
wneuper@59292
|
515 |
datatype ptform = Form of term | ModSpec of ocalhd;
|
wneuper@59292
|
516 |
|
wneuper@59292
|
517 |
(* for cut_level; (deprecated) *)
|
wneuper@59292
|
518 |
fun test_trans (PrfObj {branch, ...}) = true andalso branch = TransitiveB
|
wneuper@59292
|
519 |
| test_trans (PblObj {branch, ...}) = true andalso branch = TransitiveB;
|
wneuper@59292
|
520 |
|
wneuper@59292
|
521 |
fun is_pblobj' pt p =
|
wneuper@59292
|
522 |
let val ppobj = get_obj I pt p
|
wneuper@59292
|
523 |
in is_pblobj ppobj end;
|
wneuper@59292
|
524 |
|
wneuper@59292
|
525 |
fun del_res (PblObj {cell, fmz, origin, spec, probl, meth, ctxt, env, loc= (l1, _), branch, ...}) =
|
wneuper@59292
|
526 |
PblObj {cell = cell, fmz = fmz, origin = origin, spec = spec, probl = probl, meth = meth,
|
wneuper@59292
|
527 |
ctxt = ctxt, env = env, loc= (l1, NONE), branch = branch,
|
wneuper@59405
|
528 |
result = (Celem.e_term, []), ostate = Incomplete}
|
wneuper@59292
|
529 |
| del_res (PrfObj {cell, form, tac, loc= (l1, _), branch, ...}) =
|
wneuper@59292
|
530 |
PrfObj {cell = cell, form = form, tac = tac, loc = (l1, NONE), branch = branch,
|
wneuper@59405
|
531 |
result = (Celem.e_term, []), ostate = Incomplete};
|
wneuper@59292
|
532 |
|
wneuper@59292
|
533 |
|
wneuper@59301
|
534 |
fun get_loc EmptyPtree _ = (Selem.e_istate, Selem.e_ctxt)
|
wneuper@59292
|
535 |
| get_loc pt (p, Res) =
|
wneuper@59292
|
536 |
(case get_obj g_loc pt p of
|
wneuper@59292
|
537 |
(SOME i, NONE) => i
|
wneuper@59301
|
538 |
| (NONE , NONE) => (Selem.e_istate, Selem.e_ctxt)
|
wneuper@59292
|
539 |
| (_ , SOME i) => i)
|
wneuper@59292
|
540 |
| get_loc pt (p, _) =
|
wneuper@59292
|
541 |
(case get_obj g_loc pt p of
|
wneuper@59292
|
542 |
(NONE , SOME i) => i (*13.8.02 just copied from ^^^: too liberal ?*)
|
wneuper@59301
|
543 |
| (NONE , NONE) => (Selem.e_istate, Selem.e_ctxt)
|
wneuper@59292
|
544 |
| (SOME i, _) => i);
|
wneuper@59292
|
545 |
fun get_istate pt p = get_loc pt p |> #1;
|
wneuper@59292
|
546 |
fun get_ctxt pt (pos as (p, p_)) =
|
wneuper@59292
|
547 |
if member op = [Frm, Res] p_
|
wneuper@59292
|
548 |
then get_loc pt pos |> #2 (*for script interpretation rely on fun get_loc*)
|
wneuper@59292
|
549 |
else get_obj g_ctxt pt p (*for specify phase take ctx from PblObj*)
|
wneuper@59292
|
550 |
|
wneuper@59308
|
551 |
fun get_assumptions_ pt p = get_ctxt pt p |> Stool.get_assumptions;
|
wneuper@59292
|
552 |
|
wneuper@59292
|
553 |
fun get_somespec' (dI, pI, mI) (dI', pI', mI') =
|
wneuper@59292
|
554 |
let
|
wneuper@59405
|
555 |
val domID = if dI = Celem.e_domID then dI' else dI
|
wneuper@59405
|
556 |
val pblID = if pI = Celem.e_pblID then pI' else pI
|
wneuper@59405
|
557 |
val metID = if mI = Celem.e_metID then mI' else mI
|
wneuper@59292
|
558 |
in (domID, pblID, metID) end;
|
wneuper@59292
|
559 |
|
wneuper@59292
|
560 |
(**.development for extracting an 'interval' from ptree.**)
|
wneuper@59292
|
561 |
|
wneuper@59292
|
562 |
(*WN0510 version stopped in favour of get_interval with !!!move_dn, getFormulaeFromTo
|
wneuper@59292
|
563 |
actually used (inefficient) version with move_dn: see modspec.sml*)
|
wneuper@59292
|
564 |
local
|
wneuper@59292
|
565 |
|
wneuper@59292
|
566 |
fun hdp [] = 1 | hdp [0] = 1 | hdp x = hd x;(*start with first*)
|
wneuper@59292
|
567 |
fun hdq [] = 99999 | hdq [0] = 99999 | hdq x = hd x;(*take until last*)
|
wneuper@59292
|
568 |
fun tlp [] = [0] | tlp [_] = [0] | tlp x = tl x;
|
wneuper@59292
|
569 |
fun tlq [] = [99999] | tlq [_] = [99999] | tlq x = tl x;
|
wneuper@59292
|
570 |
|
wneuper@59292
|
571 |
fun getnd i (b,p) q (Nd (po, nds)) =
|
wneuper@59292
|
572 |
(if i <= 0 then [[b]] else []) @
|
wneuper@59292
|
573 |
(getnds (i-1) true (b@[hdp p], tlp p) (tlq q)
|
wneuper@59292
|
574 |
(take_fromto (hdp p) (hdq q) nds))
|
wneuper@59292
|
575 |
|
wneuper@59292
|
576 |
and getnds _ _ _ _ [] = [] (*no children*)
|
wneuper@59292
|
577 |
| getnds i _ (b,p) q [nd] = (getnd i (b,p) q nd) (*l+r-margin*)
|
wneuper@59292
|
578 |
|
wneuper@59292
|
579 |
| getnds i true (b,p) q [n1, n2] = (*l-margin, r-margin*)
|
wneuper@59292
|
580 |
(getnd i ( b, p ) [99999] n1) @
|
wneuper@59292
|
581 |
(getnd ~99999 (lev_on b,[0]) q n2)
|
wneuper@59292
|
582 |
|
wneuper@59292
|
583 |
| getnds i _ (b,p) q [n1, n2] = (*intern, r-margin*)
|
wneuper@59292
|
584 |
(getnd i ( b,[0]) [99999] n1) @
|
wneuper@59292
|
585 |
(getnd ~99999 (lev_on b,[0]) q n2)
|
wneuper@59292
|
586 |
|
wneuper@59292
|
587 |
| getnds i true (b,p) q (nd::(nds as _::_)) = (*l-margin, intern*)
|
wneuper@59292
|
588 |
(getnd i ( b, p ) [99999] nd) @
|
wneuper@59292
|
589 |
(getnds ~99999 false (lev_on b,[0]) q nds)
|
wneuper@59292
|
590 |
|
wneuper@59292
|
591 |
| getnds i _ (b,p) q (nd::(nds as _::_)) = (*intern, ...*)
|
wneuper@59292
|
592 |
(getnd i ( b,[0]) [99999] nd) @
|
wneuper@59292
|
593 |
(getnds ~99999 false (lev_on b,[0]) q nds);
|
wneuper@59292
|
594 |
in
|
wneuper@59292
|
595 |
(*get an 'interval from to' from a ptree as 'intervals f t' of respective nodes
|
wneuper@59292
|
596 |
where 'from' are pos, i.e. a key as int list, 'f' an int (to,t analoguous)
|
wneuper@59292
|
597 |
(1) the 'f' are given
|
wneuper@59292
|
598 |
(1a) by 'from' if 'f' = the respective element of 'from' (left margin)
|
wneuper@59292
|
599 |
(1b) -inifinity, if 'f' > the respective element of 'from' (internal node)
|
wneuper@59292
|
600 |
(2) the 't' ar given
|
wneuper@59292
|
601 |
(2a) by 'to' if 't' = the respective element of 'to' (right margin)
|
wneuper@59292
|
602 |
(2b) inifinity, if 't' < the respective element of 'to (internal node)'
|
wneuper@59292
|
603 |
the 'f' and 't' are set by hdp,... *)
|
wneuper@59292
|
604 |
fun get_trace pt p q =
|
wneuper@59292
|
605 |
(flat o (getnds ((length p) -1) true ([hdp p], tlp p) (tlq q)))
|
wneuper@59292
|
606 |
(take_fromto (hdp p) (hdq q) (children pt));
|
wneuper@59292
|
607 |
end;
|
wneuper@59292
|
608 |
|
wneuper@59292
|
609 |
(*extract a formula or model from ctree for itms2itemppc or model2xml*)
|
wneuper@59292
|
610 |
fun preconds2str bts =
|
wneuper@59405
|
611 |
(strs2str o (map (Celem.linefeed o pair2str o
|
wneuper@59405
|
612 |
(apsnd Celem.term2str) o
|
wneuper@59292
|
613 |
(apfst bool2str)))) bts;
|
wneuper@59292
|
614 |
fun ocalhd2str (b, p, hdf, itms, prec, spec) = (* for tests only *)
|
wneuper@59405
|
615 |
"(" ^ bool2str b ^ ", " ^ pos_2str p ^ ", " ^ Celem.term2str hdf ^
|
wneuper@59405
|
616 |
", " ^ Model.itms2str_ (Celem.thy2ctxt' "Isac") itms ^
|
wneuper@59405
|
617 |
", " ^ preconds2str prec ^ ", \n" ^ Celem.spec2str spec ^ " )";
|
wneuper@59292
|
618 |
|
wneuper@59292
|
619 |
fun is_pblnd (Nd (ppobj, _)) = is_pblobj ppobj
|
wneuper@59292
|
620 |
| is_pblnd _ = error "is_pblnd: uncovered fun def.";
|
wneuper@59292
|
621 |
|
wneuper@59292
|
622 |
|
wneuper@59292
|
623 |
(* determine the previous pos' on the same level
|
wneuper@59292
|
624 |
WN0502 made for interSteps; _only_ works for branch TransitiveB WN120517 compare lev_back *)
|
wneuper@59292
|
625 |
fun lev_pred' _ ([], Res) = ([], Pbl)
|
wneuper@59292
|
626 |
| lev_pred' pt (p, Res) =
|
wneuper@59292
|
627 |
let val (p', last) = split_last p
|
wneuper@59292
|
628 |
in
|
wneuper@59292
|
629 |
if last = 1
|
wneuper@59292
|
630 |
then if (is_pblobj o (get_obj I pt)) p then (p, Pbl) else (p, Frm)
|
wneuper@59292
|
631 |
else if get_obj g_res pt (p' @ [last - 1]) = get_obj g_form pt p
|
wneuper@59292
|
632 |
then (p' @ [last - 1], Res) (* TransitiveB *)
|
wneuper@59292
|
633 |
else if (is_pblobj o (get_obj I pt)) p then (p,Pbl) else (p, Frm)
|
wneuper@59292
|
634 |
end
|
wneuper@59292
|
635 |
| lev_pred' _ _ = error "";
|
wneuper@59292
|
636 |
|
wneuper@59292
|
637 |
|
wneuper@59292
|
638 |
(**.insert into ctree and cut branches accordingly.**)
|
wneuper@59292
|
639 |
|
wneuper@59292
|
640 |
(* get all positions of certain intervals on the ctree.
|
wneuper@59292
|
641 |
OLD VERSION without move_dn; kept for occasional redesign
|
wneuper@59292
|
642 |
get all pos's to be cut in a ctree
|
wneuper@59292
|
643 |
below a pos or from a ctree list after i-th element (NO level_up) *)
|
wneuper@59292
|
644 |
fun get_allpos' (_, _) EmptyPtree = []
|
wneuper@59292
|
645 |
| get_allpos' (p, 1) (Nd (b, bs)) = (* p is pos of Nd *)
|
wneuper@59292
|
646 |
if g_ostate b = Incomplete
|
wneuper@59292
|
647 |
then (p, Frm) :: (get_allpos's (p, 1) bs)
|
wneuper@59292
|
648 |
else (p, Frm) :: (get_allpos's (p, 1) bs) @ [(p, Res)]
|
wneuper@59292
|
649 |
| get_allpos' (p, i) (Nd (b, bs)) = (* p is pos of Nd *)
|
wneuper@59292
|
650 |
if length bs > 0 orelse is_pblobj b
|
wneuper@59292
|
651 |
then if g_ostate b = Incomplete
|
wneuper@59292
|
652 |
then [(p,Frm)] @ (get_allpos's (p, 1) bs)
|
wneuper@59292
|
653 |
else [(p,Frm)] @ (get_allpos's (p, 1) bs) @ [(p, Res)]
|
wneuper@59292
|
654 |
else if g_ostate b = Incomplete then [] else [(p, Res)]
|
wneuper@59292
|
655 |
and get_allpos's _ [] = []
|
wneuper@59292
|
656 |
| get_allpos's (p, i) (pt :: pts) = (* p is pos of parent-Nd *)
|
wneuper@59292
|
657 |
(get_allpos' (p @ [i], i) pt) @ (get_allpos's (p, i + 1) pts);
|
wneuper@59292
|
658 |
|
wneuper@59292
|
659 |
(*WN050106 like cut_level, but deletes exactly 1 node *)
|
wneuper@59292
|
660 |
fun cut_level_'_ _ _ EmptyPtree _ =raise PTREE "cut_level_'_ Empty _" (* for tests ONLY *)
|
wneuper@59292
|
661 |
| cut_level_'_ _ _ (Nd ( _, _)) ([], _) = raise PTREE "cut_level_'_ _ []"
|
wneuper@59292
|
662 |
| cut_level_'_ cuts P (Nd (b, bs)) (p :: [], p_) =
|
wneuper@59292
|
663 |
if test_trans b
|
wneuper@59292
|
664 |
then
|
wneuper@59292
|
665 |
(Nd (b, drop_nth [] (p:posel, bs)),
|
wneuper@59292
|
666 |
cuts @ (if p_ = Frm then [(P @ [p], Res)] else []) @
|
wneuper@59292
|
667 |
(get_allpos's (P, p + 1) (drop_nth [] (p, bs))))
|
wneuper@59292
|
668 |
else (Nd (b, bs), cuts)
|
wneuper@59292
|
669 |
| cut_level_'_ cuts P (Nd (b, bs)) ((p :: ps), p_) =
|
wneuper@59292
|
670 |
let
|
wneuper@59292
|
671 |
val (bs', cuts') = cut_level_'_ cuts P (nth p bs) (ps, p_)
|
wneuper@59292
|
672 |
in (Nd (b, repl_app bs p bs'), cuts @ cuts') end;
|
wneuper@59292
|
673 |
|
wneuper@59292
|
674 |
fun cut_level _ _ EmptyPtree _ = raise PTREE "cut_level EmptyPtree _"
|
wneuper@59292
|
675 |
| cut_level _ _ (Nd ( _, _)) ([],_) = raise PTREE "cut_level _ []"
|
wneuper@59292
|
676 |
| cut_level cuts P (Nd (b, bs)) (p :: [], p_) =
|
wneuper@59292
|
677 |
if test_trans b
|
wneuper@59292
|
678 |
then
|
wneuper@59292
|
679 |
(Nd (b, take (p:posel, bs)),
|
wneuper@59292
|
680 |
cuts @
|
wneuper@59292
|
681 |
(if p_ = Frm andalso (*#*) g_ostate b = Complete then [(P@[p],Res)] else ([]:pos' list)) @
|
wneuper@59292
|
682 |
(get_allpos's (P, p+1) (takerest (p, bs))))
|
wneuper@59292
|
683 |
else (Nd (b, bs), cuts)
|
wneuper@59292
|
684 |
| cut_level cuts P (Nd (b, bs)) ((p :: ps), p_) =
|
wneuper@59292
|
685 |
let
|
wneuper@59292
|
686 |
val (bs', cuts') = cut_level cuts P (nth p bs) (ps, p_)
|
wneuper@59292
|
687 |
in (Nd (b, repl_app bs p bs'), cuts @ cuts') end;
|
wneuper@59292
|
688 |
|
wneuper@59292
|
689 |
(*OLD version before WN050219, overwritten below*)
|
wneuper@59292
|
690 |
fun cut_tree _ ([], _) = raise PTREE "cut_tree _ ([],_)" (* for test only *)
|
wneuper@59292
|
691 |
| cut_tree pt (pos as ([_], _)) =
|
wneuper@59292
|
692 |
let
|
wneuper@59292
|
693 |
val (pt', cuts) = cut_level [] [] pt pos
|
wneuper@59292
|
694 |
in
|
wneuper@59292
|
695 |
(pt', cuts @ (if get_obj g_ostate pt [] = Incomplete then [] else [([], Res)]))
|
wneuper@59292
|
696 |
end
|
wneuper@59292
|
697 |
| cut_tree pt (p,p_) =
|
wneuper@59292
|
698 |
let
|
wneuper@59292
|
699 |
fun cutfn pt cuts (p, p_) =
|
wneuper@59292
|
700 |
let
|
wneuper@59292
|
701 |
val (pt', cuts') = cut_level [] (lev_up p) pt (p,p_)
|
wneuper@59292
|
702 |
in
|
wneuper@59292
|
703 |
if length cuts' > 0 andalso length p > 1
|
wneuper@59292
|
704 |
then cutfn pt' (cuts @ cuts') (lev_up p, Frm(*-->(p,Res)*))
|
wneuper@59292
|
705 |
else (pt', cuts @ cuts')
|
wneuper@59292
|
706 |
end
|
wneuper@59292
|
707 |
val (pt', cuts) = cutfn pt [] (p, p_)
|
wneuper@59292
|
708 |
in
|
wneuper@59292
|
709 |
(pt', cuts @ (if get_obj g_ostate pt [] = Incomplete then [] else [([], Res)]))
|
wneuper@59292
|
710 |
end;
|
wneuper@59292
|
711 |
|
wneuper@59296
|
712 |
local
|
wneuper@59296
|
713 |
fun move_dn _ (Nd (_, ns)) ([],p_) = (* root problem *)
|
wneuper@59296
|
714 |
(case p_ of
|
wneuper@59296
|
715 |
Res => raise PTREE "move_dn: end of calculation"
|
wneuper@59296
|
716 |
| _ =>
|
wneuper@59296
|
717 |
if null ns (* go down from Pbl + Met *)
|
wneuper@59296
|
718 |
then raise PTREE "move_dn: solve problem not started"
|
wneuper@59296
|
719 |
else ([1], Frm))
|
wneuper@59296
|
720 |
| move_dn P (Nd (_, ns)) (p :: (ps as (_ :: _)), p_) = (* iterate to end of pos *)
|
wneuper@59296
|
721 |
if p > length ns
|
wneuper@59296
|
722 |
then raise PTREE "move_dn: pos not existent 2"
|
wneuper@59296
|
723 |
else move_dn (P @ [p]) (nth p ns) (ps, p_)
|
wneuper@59296
|
724 |
| move_dn P (Nd (c, ns)) ([p], p_) = (* act on last element of pos *)
|
wneuper@59296
|
725 |
if p > length ns
|
wneuper@59296
|
726 |
then raise PTREE "move_dn: pos not existent 3"
|
wneuper@59296
|
727 |
else
|
wneuper@59296
|
728 |
(case p_ of
|
wneuper@59296
|
729 |
Res =>
|
wneuper@59296
|
730 |
if p = length ns (* last Res on this level: go a level up *)
|
wneuper@59296
|
731 |
then if g_ostate c = Complete
|
wneuper@59296
|
732 |
then (P, Res)
|
wneuper@59296
|
733 |
else raise PTREE (ints2str' P ^ " not complete 1")
|
wneuper@59296
|
734 |
else (* go to the next Nd on this level, or down into the next Nd *)
|
wneuper@59296
|
735 |
if is_pblnd (nth (p + 1) ns) then (P@[p + 1], Pbl)
|
wneuper@59296
|
736 |
else if g_res' (nth p ns) = g_form' (nth (p + 1) ns)
|
wneuper@59296
|
737 |
then if (null o children o (nth (p + 1))) ns
|
wneuper@59296
|
738 |
then (* take the Res if Complete *)
|
wneuper@59296
|
739 |
if g_ostate' (nth (p + 1) ns) = Complete
|
wneuper@59296
|
740 |
then (P@[p + 1], Res)
|
wneuper@59296
|
741 |
else raise PTREE (ints2str' (P@[p + 1]) ^ " not complete 2")
|
wneuper@59296
|
742 |
else (P@[p + 1, 1], Frm) (* go down into the next PrfObj *)
|
wneuper@59296
|
743 |
else (P@[p + 1], Frm) (* take Frm: exists if the Nd exists *)
|
wneuper@59296
|
744 |
| Frm => (*go down or to the Res of this Nd*)
|
wneuper@59296
|
745 |
if (null o children o (nth p)) ns
|
wneuper@59296
|
746 |
then if g_ostate' (nth p ns) = Complete then (P @ [p], Res)
|
wneuper@59296
|
747 |
else raise PTREE (ints2str' (P @ [p])^" not complete 3")
|
wneuper@59296
|
748 |
else (P @ [p, 1], Frm)
|
wneuper@59296
|
749 |
| _ => (* is Pbl or Met *)
|
wneuper@59296
|
750 |
if (null o children o (nth p)) ns
|
wneuper@59296
|
751 |
then raise PTREE "move_dn:solve subproblem not startd"
|
wneuper@59296
|
752 |
else (P @ [p, 1],
|
wneuper@59296
|
753 |
if (is_pblnd o hd o children o (nth p)) ns
|
wneuper@59296
|
754 |
then Pbl else Frm))
|
wneuper@59296
|
755 |
| move_dn _ _ _ = error "";
|
wneuper@59296
|
756 |
in
|
wneuper@59292
|
757 |
(* get all positions in a ctree until ([],Res) or ostate=Incomplete
|
wneuper@59292
|
758 |
val get_allp = fn :
|
wneuper@59292
|
759 |
pos' list -> : accumulated, start with []
|
wneuper@59292
|
760 |
pos -> : the offset for subtrees wrt the root
|
wneuper@59292
|
761 |
ctree -> : (sub)tree
|
wneuper@59292
|
762 |
pos' : initialization (the last pos' before ...)
|
wneuper@59292
|
763 |
-> pos' list : of positions in this (sub) tree (relative to the root)
|
wneuper@59292
|
764 |
*)
|
wneuper@59292
|
765 |
fun get_allp cuts (P, pos) pt =
|
wneuper@59292
|
766 |
(let
|
wneuper@59292
|
767 |
val nxt = move_dn [] pt pos (*exn if Incomplete reached*)
|
wneuper@59292
|
768 |
in
|
wneuper@59292
|
769 |
if nxt <> ([], Res)
|
wneuper@59292
|
770 |
then get_allp (cuts @ [nxt]) (P, nxt) pt
|
wneuper@59292
|
771 |
else map (apfst (curry op @ P)) (cuts @ [nxt])
|
wneuper@59292
|
772 |
end)
|
wneuper@59292
|
773 |
handle PTREE _ => (map (apfst (curry op@ P)) cuts);
|
wneuper@59296
|
774 |
end
|
wneuper@59292
|
775 |
|
wneuper@59292
|
776 |
(* the pts are assumed to be on the same level *)
|
wneuper@59292
|
777 |
fun get_allps cuts _ [] = cuts
|
wneuper@59292
|
778 |
| get_allps cuts P (pt :: pts) =
|
wneuper@59292
|
779 |
let
|
wneuper@59292
|
780 |
val below = get_allp [] (P, ([], Frm)) pt
|
wneuper@59292
|
781 |
val levfrm =
|
wneuper@59292
|
782 |
if is_pblnd pt
|
wneuper@59292
|
783 |
then (P, Pbl) :: below
|
wneuper@59292
|
784 |
else if last_elem P = 1
|
wneuper@59292
|
785 |
then (P, Frm) :: below
|
wneuper@59292
|
786 |
else (*Trans*) below
|
wneuper@59292
|
787 |
val levres = levfrm @ (if null below then [(P, Res)] else [])
|
wneuper@59292
|
788 |
in
|
wneuper@59292
|
789 |
get_allps (cuts @ levres) (lev_on P) pts
|
wneuper@59292
|
790 |
end;
|
wneuper@59292
|
791 |
|
wneuper@59292
|
792 |
(** these 2 funs decide on how far cut_tree goes **)
|
wneuper@59292
|
793 |
(* shall the nodes _after_ the pos to be inserted at be deleted?
|
wneuper@59292
|
794 |
shall cutting be continued on the higher level(s)? the Nd regarded will NOT be changed *)
|
wneuper@59292
|
795 |
fun test_trans (PrfObj {branch, ...}) = (branch = TransitiveB orelse branch = NoBranch)
|
wneuper@59292
|
796 |
| test_trans (PblObj {branch, ...}) = (branch = TransitiveB orelse branch = NoBranch);
|
wneuper@59292
|
797 |
|
wneuper@59292
|
798 |
(* cut_bottom new sml603..608
|
wneuper@59292
|
799 |
cut the level at the bottom of the pos (used by cappend_...)
|
wneuper@59292
|
800 |
and handle the parent in order to avoid extra case for root
|
wneuper@59292
|
801 |
fn: ctree -> : the _whole_ ctree for cut_levup
|
wneuper@59292
|
802 |
pos * posel -> : the pos after split_last
|
wneuper@59292
|
803 |
ctree -> : the parent of the Nd to be cut
|
wneuper@59292
|
804 |
return
|
wneuper@59292
|
805 |
(ctree * : the updated ctree
|
wneuper@59292
|
806 |
pos' list) * : the pos's cut
|
wneuper@59292
|
807 |
bool : cutting shall be continued on the higher level(s)
|
wneuper@59292
|
808 |
*)
|
wneuper@59292
|
809 |
fun cut_bottom _ (pt' as Nd (b, [])) = ((pt', []), test_trans b)
|
wneuper@59292
|
810 |
| cut_bottom (P, p) (Nd (b, bs)) =
|
wneuper@59292
|
811 |
let (*divide level into 3 parts...*)
|
wneuper@59292
|
812 |
val keep = take (p - 1, bs)
|
wneuper@59292
|
813 |
val pt' = case nth p bs of
|
wneuper@59292
|
814 |
pt' as Nd _ => pt'
|
wneuper@59292
|
815 |
| _ => error "cut_bottom: uncovered case nth p bs"
|
wneuper@59292
|
816 |
(*^^^^^_here_ will be 'insert_pt'ed by 'append_..'*)
|
wneuper@59292
|
817 |
val (tail, _) = (takerest (p, bs), if null (takerest (p, bs)) then 0 else p + 1)
|
wneuper@59292
|
818 |
val (children, cuts) =
|
wneuper@59292
|
819 |
if test_trans b
|
wneuper@59292
|
820 |
then
|
wneuper@59292
|
821 |
(keep, (if is_pblnd pt' then [(P @ [p], Pbl)] else [])
|
wneuper@59292
|
822 |
@ (get_allp [] (P @ [p], (P, Frm)) pt')
|
wneuper@59292
|
823 |
@ (get_allps [] (P @ [p + 1]) tail))
|
wneuper@59292
|
824 |
else (keep @ [(*'insert_pt'ed by 'append_..'*)] @ tail,
|
wneuper@59292
|
825 |
get_allp [] (P @ [p], (P, Frm)) pt')
|
wneuper@59292
|
826 |
val (pt'', cuts) =
|
wneuper@59292
|
827 |
if test_trans b
|
wneuper@59292
|
828 |
then (Nd (del_res b, children), cuts @ (if g_ostate b = Incomplete then [] else [(P, Res)]))
|
wneuper@59292
|
829 |
else (Nd (b, children), cuts)
|
wneuper@59292
|
830 |
in ((pt'', cuts), test_trans b) end
|
wneuper@59292
|
831 |
| cut_bottom _ _ = error "cut_bottom: uncovered fun def.";
|
wneuper@59292
|
832 |
|
wneuper@59292
|
833 |
|
wneuper@59292
|
834 |
(* go all levels from the bottom of 'pos' up to the root,
|
wneuper@59292
|
835 |
on each level compose the children of a node and accumulate the cut Nds
|
wneuper@59292
|
836 |
args
|
wneuper@59292
|
837 |
pos' list -> : for accumulation
|
wneuper@59292
|
838 |
bool -> : cutting shall be continued on the higher level(s)
|
wneuper@59292
|
839 |
ctree -> : the whole ctree for 'get_nd pt P' on each level
|
wneuper@59292
|
840 |
ctree -> : the Nd from the lower level for insertion at path
|
wneuper@59292
|
841 |
pos * posel -> : pos=path split for convenience
|
wneuper@59292
|
842 |
ctree -> : Nd the children of are under consideration on this call
|
wneuper@59292
|
843 |
returns :
|
wneuper@59292
|
844 |
ctree * pos' list : the updated parent-Nd and the pos's of the Nds cut
|
wneuper@59292
|
845 |
*)
|
wneuper@59292
|
846 |
fun cut_levup (cuts:pos' list) clevup pt pt' (P:pos, p:posel) (Nd (b, bs)) =
|
wneuper@59292
|
847 |
let (*divide level into 3 parts...*)
|
wneuper@59292
|
848 |
val keep = take (p - 1, bs)
|
wneuper@59292
|
849 |
(*val pt' comes as argument from below*)
|
wneuper@59292
|
850 |
val (tail, _) =
|
wneuper@59292
|
851 |
(takerest (p, bs), if null (takerest (p, bs)) then 0 else p + 1)
|
wneuper@59292
|
852 |
val (children, cuts') =
|
wneuper@59292
|
853 |
if clevup
|
wneuper@59292
|
854 |
then (keep @ [pt'], get_allps [] (P @ [p+1]) tail)
|
wneuper@59292
|
855 |
else (keep @ [pt'] @ tail, [])
|
wneuper@59292
|
856 |
val clevup' = if clevup then test_trans b else false
|
wneuper@59292
|
857 |
(*the first Nd with false stops cutting on all levels above*)
|
wneuper@59292
|
858 |
val (pt'', cuts') =
|
wneuper@59292
|
859 |
if clevup'
|
wneuper@59292
|
860 |
then (Nd (del_res b, children), cuts' @ (if g_ostate b = Incomplete then [] else [(P, Res)]))
|
wneuper@59292
|
861 |
else (Nd (b, children), cuts')
|
wneuper@59292
|
862 |
in
|
wneuper@59292
|
863 |
if null P
|
wneuper@59292
|
864 |
then (pt'', cuts @ cuts')
|
wneuper@59292
|
865 |
else
|
wneuper@59292
|
866 |
let val (P, p) = split_last P
|
wneuper@59292
|
867 |
in cut_levup (cuts @ cuts') clevup' pt pt'' (P, p) (get_nd pt P) end
|
wneuper@59292
|
868 |
end
|
wneuper@59292
|
869 |
| cut_levup _ _ _ _ _ _ = error "cut_levup: uncovered fun def.";
|
wneuper@59292
|
870 |
|
wneuper@59292
|
871 |
(* cut nodes after and below an inserted node in the ctree;
|
wneuper@59292
|
872 |
the cuts range is limited by the predicate 'fun cutlevup' *)
|
wneuper@59292
|
873 |
fun cut_tree pt (pos, _) =
|
wneuper@59292
|
874 |
if not (existpt pos pt)
|
wneuper@59292
|
875 |
then (pt,[]) (*appending a formula never cuts anything*)
|
wneuper@59292
|
876 |
else
|
wneuper@59292
|
877 |
let
|
wneuper@59292
|
878 |
val (P, p) = split_last pos
|
wneuper@59292
|
879 |
val ((pt', cuts), clevup) = cut_bottom (P, p) (get_nd pt P)
|
wneuper@59292
|
880 |
(* pt' is the updated parent of the Nd to cappend_..*)
|
wneuper@59292
|
881 |
in
|
wneuper@59292
|
882 |
if null P
|
wneuper@59292
|
883 |
then (pt', cuts)
|
wneuper@59292
|
884 |
else
|
wneuper@59292
|
885 |
let val (P, p) = split_last P
|
wneuper@59292
|
886 |
in cut_levup cuts clevup pt pt' (P, p) (get_nd pt P) end
|
wneuper@59292
|
887 |
end;
|
wneuper@59292
|
888 |
|
wneuper@59292
|
889 |
(* get the theory explicitly specified for the rootpbl;
|
wneuper@59292
|
890 |
thus use this function _after_ finishing specification *)
|
wneuper@59405
|
891 |
fun rootthy (Nd (PblObj {spec = (thyID, _, _), ...}, _)) = Celem.assoc_thy thyID
|
wneuper@59292
|
892 |
| rootthy _ = error "rootthy: uncovered fun def.";
|
wneuper@59292
|
893 |
|
wneuper@59292
|
894 |
(**)
|
wneuper@59292
|
895 |
end;
|
wneuper@59292
|
896 |
(**)
|