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 scrstate
|
wneuper@59292
|
10 |
datatype istate = RrlsState of rrlsstate | ScrState of scrstate | Uistate
|
wneuper@59292
|
11 |
val istate2str : istate -> string
|
wneuper@59292
|
12 |
val e_istate : istate
|
wneuper@59292
|
13 |
type state
|
wneuper@59292
|
14 |
type result
|
wneuper@59292
|
15 |
type con
|
wneuper@59292
|
16 |
type sube
|
wneuper@59292
|
17 |
type subs
|
wneuper@59292
|
18 |
type subte
|
wneuper@59292
|
19 |
val sube2str : cterm' list -> string
|
wneuper@59292
|
20 |
val sube2subst : theory -> cterm' list -> (term * term) list
|
wneuper@59292
|
21 |
val sube2subte : cterm' list -> term list
|
wneuper@59292
|
22 |
val subs2subst : theory -> cterm' list -> (term * term) list
|
wneuper@59292
|
23 |
val subst2sube : (term * term) list -> cterm' list (* for datatypes.sml *)
|
wneuper@59292
|
24 |
val subst2subs : (term * term) list -> cterm' list
|
wneuper@59292
|
25 |
val subst2subs' : (term * term) list -> (string * string) list
|
wneuper@59292
|
26 |
val subte2sube : term list -> cterm' list
|
wneuper@59292
|
27 |
|
wneuper@59292
|
28 |
datatype tac_ =
|
wneuper@59292
|
29 |
Add_Find' of cterm' * itm list | Add_Given' of cterm' * itm list | Add_Relation' of cterm' * itm list
|
wneuper@59292
|
30 |
| Apply_Assumption' of term list * term
|
wneuper@59292
|
31 |
| Apply_Method' of metID * term option * istate * Proof.context
|
wneuper@59292
|
32 |
|
wneuper@59292
|
33 |
| Begin_Sequ' | Begin_Trans' of term
|
wneuper@59292
|
34 |
| Split_And' of term | Split_Or' of term | Split_Intersect' of term
|
wneuper@59292
|
35 |
| Conclude_And' of term | Conclude_Or' of term | Collect_Trues' of term
|
wneuper@59292
|
36 |
| End_Sequ' | End_Trans' of result
|
wneuper@59292
|
37 |
| End_Ruleset' of term | End_Subproblem' of term | End_Intersect' of term | End_Proof''
|
wneuper@59292
|
38 |
|
wneuper@59292
|
39 |
| CAScmd' of term
|
wneuper@59292
|
40 |
| Calculate' of theory' * string * term * (term * thm')
|
wneuper@59292
|
41 |
| Check_Postcond' of pblID * result
|
wneuper@59292
|
42 |
| Check_elementwise' of term * cterm' * result
|
wneuper@59292
|
43 |
| Del_Find' of cterm' | Del_Given' of cterm' | Del_Relation' of cterm'
|
wneuper@59292
|
44 |
|
wneuper@59292
|
45 |
| Derive' of rls
|
wneuper@59292
|
46 |
| Detail_Set' of theory' * bool * rls * term * result
|
wneuper@59292
|
47 |
| Detail_Set_Inst' of theory' * bool * subst * rls * term * result
|
wneuper@59292
|
48 |
| End_Detail' of result
|
wneuper@59292
|
49 |
|
wneuper@59292
|
50 |
| Empty_Tac_
|
wneuper@59292
|
51 |
| Free_Solve'
|
wneuper@59292
|
52 |
|
wneuper@59292
|
53 |
| Init_Proof' of cterm' list * spec
|
wneuper@59292
|
54 |
| Model_Problem' of pblID * itm list * itm list
|
wneuper@59292
|
55 |
| Or_to_List' of term * term
|
wneuper@59292
|
56 |
| Refine_Problem' of pblID * (itm list * (bool * term) list)
|
wneuper@59292
|
57 |
| Refine_Tacitly' of pblID * pblID * domID * metID * itm list
|
wneuper@59292
|
58 |
|
wneuper@59292
|
59 |
| Rewrite' of theory' * rew_ord' * rls * bool * thm'' * term * result
|
wneuper@59292
|
60 |
| Rewrite_Asm' of theory' * rew_ord' * rls * bool * thm'' * term * result
|
wneuper@59292
|
61 |
| Rewrite_Inst' of theory' * rew_ord' * rls * bool * subst * thm'' * term * result
|
wneuper@59292
|
62 |
| Rewrite_Set' of theory' * bool * rls * term * result
|
wneuper@59292
|
63 |
| Rewrite_Set_Inst' of theory' * bool * subst * rls * term * result
|
wneuper@59292
|
64 |
|
wneuper@59292
|
65 |
| Specify_Method' of metID * ori list * itm list
|
wneuper@59292
|
66 |
| Specify_Problem' of pblID * (bool * (itm list * (bool * term) list))
|
wneuper@59292
|
67 |
| Specify_Theory' of domID
|
wneuper@59298
|
68 |
| Subproblem' of spec * ori list * term * Selem.fmz_ * Proof.context * term
|
wneuper@59292
|
69 |
| Substitute' of rew_ord_ * rls * subte * term * term
|
wneuper@59292
|
70 |
| Tac_ of theory * string * string * string
|
wneuper@59292
|
71 |
| Take' of term | Take_Inst' of term
|
wneuper@59292
|
72 |
|
wneuper@59292
|
73 |
datatype tac =
|
wneuper@59292
|
74 |
Add_Find of cterm' | Add_Given of cterm' | Add_Relation of cterm'
|
wneuper@59292
|
75 |
| Apply_Assumption of cterm' list
|
wneuper@59292
|
76 |
| Apply_Method of metID
|
wneuper@59292
|
77 |
(*/--- TODO: re-design ? -----------------------------------------------------------------\*)
|
wneuper@59292
|
78 |
| Begin_Sequ | Begin_Trans
|
wneuper@59292
|
79 |
| Split_And | Split_Or | Split_Intersect
|
wneuper@59292
|
80 |
| Conclude_And | Conclude_Or | Collect_Trues
|
wneuper@59292
|
81 |
| End_Sequ | End_Trans
|
wneuper@59292
|
82 |
| End_Ruleset | End_Subproblem | End_Intersect | End_Proof'
|
wneuper@59292
|
83 |
(*\--- TODO: re-design ? -----------------------------------------------------------------/*)
|
wneuper@59292
|
84 |
| CAScmd of cterm'
|
wneuper@59292
|
85 |
| Calculate of string
|
wneuper@59292
|
86 |
| Check_Postcond of pblID
|
wneuper@59292
|
87 |
| Check_elementwise of cterm'
|
wneuper@59292
|
88 |
| Del_Find of cterm' | Del_Given of cterm' | Del_Relation of cterm'
|
wneuper@59292
|
89 |
|
wneuper@59292
|
90 |
| Derive of rls'
|
wneuper@59292
|
91 |
| Detail_Set of rls'
|
wneuper@59292
|
92 |
| Detail_Set_Inst of subs * rls'
|
wneuper@59292
|
93 |
| End_Detail
|
wneuper@59292
|
94 |
|
wneuper@59292
|
95 |
| Empty_Tac
|
wneuper@59292
|
96 |
| Free_Solve
|
wneuper@59292
|
97 |
|
wneuper@59292
|
98 |
| Init_Proof of cterm' list * spec
|
wneuper@59292
|
99 |
| Model_Problem
|
wneuper@59292
|
100 |
| Or_to_List
|
wneuper@59292
|
101 |
| Refine_Problem of pblID
|
wneuper@59292
|
102 |
| Refine_Tacitly of pblID
|
wneuper@59292
|
103 |
|
wneuper@59292
|
104 |
| Rewrite of thm''
|
wneuper@59292
|
105 |
| Rewrite_Asm of thm''
|
wneuper@59292
|
106 |
| Rewrite_Inst of subs * thm''
|
wneuper@59292
|
107 |
| Rewrite_Set of rls'
|
wneuper@59292
|
108 |
| Rewrite_Set_Inst of subs * rls'
|
wneuper@59292
|
109 |
|
wneuper@59292
|
110 |
| Specify_Method of metID
|
wneuper@59292
|
111 |
| Specify_Problem of pblID
|
wneuper@59292
|
112 |
| Specify_Theory of domID
|
wneuper@59292
|
113 |
| Subproblem of domID * pblID
|
wneuper@59292
|
114 |
|
wneuper@59292
|
115 |
| Substitute of sube
|
wneuper@59292
|
116 |
| Tac of string
|
wneuper@59292
|
117 |
| Take of cterm' | Take_Inst of cterm'
|
wneuper@59292
|
118 |
|
wneuper@59292
|
119 |
val tac2str : tac -> string
|
wneuper@59292
|
120 |
val rls_of : tac -> rls' (* for solve.sml *)
|
wneuper@59292
|
121 |
val tac2IDstr : tac -> string
|
wneuper@59292
|
122 |
val is_rewset : tac -> bool (* for mathengine.sml *)
|
wneuper@59292
|
123 |
val is_rewtac : tac -> bool (* for interface.sml *)
|
wneuper@59292
|
124 |
|
wneuper@59292
|
125 |
eqtype posel
|
wneuper@59292
|
126 |
type pos = posel list
|
wneuper@59292
|
127 |
val pos2str : int list -> string (* for datatypes.sml *)
|
wneuper@59292
|
128 |
datatype pos_ = Frm | Met | Pbl | Res | Und
|
wneuper@59292
|
129 |
val pos_2str : pos_ -> string
|
wneuper@59292
|
130 |
type pos'
|
wneuper@59292
|
131 |
val pos'2str : pos' -> string
|
wneuper@59292
|
132 |
val str2pos_ : string -> pos_ (* for datatypes.sml *)
|
wneuper@59292
|
133 |
val e_pos' : pos'
|
wneuper@59292
|
134 |
(* for generate.sml ?!? ca.*)
|
wneuper@59292
|
135 |
datatype safe = Helpless | Safe | Sundef | Unsafe
|
wneuper@59292
|
136 |
val tac_2str : tac_ -> string
|
wneuper@59292
|
137 |
eqtype cellID
|
wneuper@59292
|
138 |
|
wneuper@59292
|
139 |
datatype branch = AndB | CollectB | IntersectB | MapB | NoBranch | OrB | SequenceB | TransitiveB
|
wneuper@59292
|
140 |
datatype ostate = Complete | Incomplete | Inconsistent
|
wneuper@59292
|
141 |
datatype ppobj =
|
wneuper@59292
|
142 |
PblObj of
|
wneuper@59292
|
143 |
{branch: branch,
|
wneuper@59292
|
144 |
cell: lrd option,
|
wneuper@59292
|
145 |
loc: (istate * Proof.context) option * (istate * Proof.context) option,
|
wneuper@59292
|
146 |
ostate: ostate,
|
wneuper@59292
|
147 |
result: result,
|
wneuper@59292
|
148 |
|
wneuper@59298
|
149 |
fmz: Selem.fmz,
|
wneuper@59292
|
150 |
origin: ori list * spec * term,
|
wneuper@59292
|
151 |
probl: itm list,
|
wneuper@59292
|
152 |
meth: itm list,
|
wneuper@59292
|
153 |
spec: spec,
|
wneuper@59292
|
154 |
ctxt: Proof.context,
|
wneuper@59292
|
155 |
env: (istate * Proof.context) option}
|
wneuper@59292
|
156 |
| PrfObj of
|
wneuper@59292
|
157 |
{branch: branch,
|
wneuper@59292
|
158 |
cell: lrd option,
|
wneuper@59292
|
159 |
loc: (istate * Proof.context) option * (istate * Proof.context) option,
|
wneuper@59292
|
160 |
ostate: ostate,
|
wneuper@59292
|
161 |
result: result,
|
wneuper@59292
|
162 |
|
wneuper@59292
|
163 |
form: term,
|
wneuper@59292
|
164 |
tac: tac}
|
wneuper@59292
|
165 |
|
wneuper@59292
|
166 |
datatype ctree = EmptyPtree | Nd of ppobj * ctree list
|
wneuper@59292
|
167 |
val e_ctree : ctree (* TODO: replace by EmptyPtree*)
|
wneuper@59292
|
168 |
val existpt' : pos' -> ctree -> bool (* for interface.sml *)
|
wneuper@59292
|
169 |
val is_interpos : pos' -> bool (* for interface.sml *)
|
wneuper@59292
|
170 |
val lev_pred' : ctree -> pos' -> pos' (* for interface.sml *)
|
wneuper@59292
|
171 |
val ins_chn : ctree list -> ctree -> pos -> ctree (* for solve.sml *)
|
wneuper@59292
|
172 |
val children : ctree -> ctree list (* for solve.sml *)
|
wneuper@59292
|
173 |
val get_nd : ctree -> pos -> ctree (* for solve.sml *)
|
wneuper@59292
|
174 |
val just_created_ : ppobj -> bool (* for mathengine.sml *)
|
wneuper@59292
|
175 |
val just_created : state -> bool (* for mathengine.sml *)
|
wneuper@59292
|
176 |
val e_origin : ori list * spec * term (* for mathengine.sml *)
|
wneuper@59292
|
177 |
|
wneuper@59292
|
178 |
val is_pblobj : ppobj -> bool
|
wneuper@59292
|
179 |
val is_pblobj' : ctree -> pos -> bool
|
wneuper@59292
|
180 |
val is_pblnd : ctree -> bool
|
wneuper@59292
|
181 |
|
wneuper@59292
|
182 |
val g_spec : ppobj -> spec
|
wneuper@59292
|
183 |
val g_loc : ppobj -> (istate * Proof.context) option * (istate * Proof.context) option
|
wneuper@59292
|
184 |
val g_form : ppobj -> term
|
wneuper@59292
|
185 |
val g_pbl : ppobj -> itm list
|
wneuper@59292
|
186 |
val g_met : ppobj -> itm list
|
wneuper@59292
|
187 |
val g_metID : ppobj -> metID
|
wneuper@59292
|
188 |
val g_result : ppobj -> result
|
wneuper@59292
|
189 |
val g_tac : ppobj -> tac
|
wneuper@59292
|
190 |
val g_domID : ppobj -> domID (* for appl.sml TODO: replace by thyID *)
|
wneuper@59292
|
191 |
val g_env : ppobj -> (istate * Proof.context) option (* for appl.sml *)
|
wneuper@59292
|
192 |
|
wneuper@59292
|
193 |
val g_origin : ppobj -> ori list * spec * term (* for script.sml *)
|
wneuper@59292
|
194 |
val get_loc : ctree -> pos' -> istate * Proof.context (* for script.sml *)
|
wneuper@59292
|
195 |
val get_istate : ctree -> pos' -> istate (* for script.sml *)
|
wneuper@59292
|
196 |
val get_ctxt : ctree -> pos' -> Proof.context
|
wneuper@59292
|
197 |
val get_obj : (ppobj -> 'a) -> ctree -> pos -> 'a
|
wneuper@59292
|
198 |
val get_curr_formula : state -> term
|
wneuper@59292
|
199 |
val get_assumptions_ : ctree -> pos' -> term list (* for appl.sml *)
|
wneuper@59292
|
200 |
|
wneuper@59292
|
201 |
val e_ctxt : Proof.context
|
wneuper@59292
|
202 |
val is_e_ctxt : Proof.context -> bool (* for appl.sml *)
|
wneuper@59292
|
203 |
val new_val : term -> istate -> istate
|
wneuper@59292
|
204 |
(* for calchead.sml *)
|
wneuper@59292
|
205 |
type cid = cellID list
|
wneuper@59292
|
206 |
type ocalhd = bool * pos_ * term * itm list * (bool * term) list * spec
|
wneuper@59292
|
207 |
datatype ptform = Form of term | ModSpec of ocalhd
|
wneuper@59292
|
208 |
val get_somespec' : spec -> spec -> spec
|
wneuper@59292
|
209 |
exception PTREE of string;
|
wneuper@59296
|
210 |
|
wneuper@59296
|
211 |
val par_pbl_det : ctree -> pos -> bool * pos * rls (* for appl.sml *)
|
wneuper@59296
|
212 |
val rule2tac : theory -> (term * term) list -> rule -> tac (* for rewtools.sml *)
|
wneuper@59296
|
213 |
val eq_tac : tac * tac -> bool (* for script.sml *)
|
wneuper@59296
|
214 |
val rootthy : ctree -> theory (* for script.sml *)
|
wneuper@59294
|
215 |
(* ---- made visible ONLY for structure CTaccess : CALC_TREE_ACCESS --------------------------- *)
|
wneuper@59294
|
216 |
val appl_obj : (ppobj -> ppobj) -> ctree -> pos -> ctree
|
wneuper@59294
|
217 |
val existpt : pos -> ctree -> bool (* also for tests *)
|
wneuper@59294
|
218 |
val is_empty_tac : tac -> bool (* also for tests *)
|
wneuper@59294
|
219 |
val cut_tree : ctree -> pos * 'a -> ctree * pos' list (* also for tests *)
|
wneuper@59294
|
220 |
val insert_pt : ppobj -> ctree -> int list -> ctree
|
wneuper@59294
|
221 |
(* ---- made visible ONLY for structure CTnavi : CALC_TREE_NAVIGATION ------------------------- *)
|
wneuper@59296
|
222 |
val g_branch : ppobj -> branch
|
wneuper@59296
|
223 |
val g_form' : ctree -> term
|
wneuper@59296
|
224 |
val g_ostate : ppobj -> ostate
|
wneuper@59296
|
225 |
val g_ostate' : ctree -> ostate
|
wneuper@59296
|
226 |
val g_res : ppobj -> term
|
wneuper@59296
|
227 |
val g_res' : ctree -> term
|
wneuper@59296
|
228 |
(*/---- duplicates in CTnavi, reconsider structs -----------------------------------------------
|
wneuper@59296
|
229 |
val lev_on : CTbasic.pos -> CTbasic.pos (* duplicate in ctree-navi.sml *)
|
wneuper@59296
|
230 |
val lev_dn : CTbasic.pos -> CTbasic.pos (* duplicate in ctree-navi.sml *)
|
wneuper@59296
|
231 |
val par_pblobj : CTbasic.ctree -> CTbasic.pos -> CTbasic.pos (* duplicate in ctree-navi.sml *)
|
wneuper@59296
|
232 |
---- duplicates in CTnavi, reconsider structs ----------------------------------------------/*)
|
wneuper@59294
|
233 |
|
wneuper@59298
|
234 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\*)
|
wneuper@59292
|
235 |
val pr_ctree : (pos -> ppobj -> string) -> ctree -> string
|
wneuper@59292
|
236 |
val pr_short : pos -> ppobj -> string
|
wneuper@59292
|
237 |
val e_subs : string list
|
wneuper@59292
|
238 |
val e_sube : cterm' list
|
wneuper@59292
|
239 |
val g_ctxt : ppobj -> Proof.context
|
wneuper@59298
|
240 |
val g_fmz : ppobj -> Selem.fmz
|
wneuper@59292
|
241 |
val get_allp : pos' list -> pos * (int list * pos_) -> ctree -> pos' list
|
wneuper@59292
|
242 |
val get_allps : (pos * pos_) list -> posel list -> ctree list -> pos' list
|
wneuper@59292
|
243 |
val get_allpos' : pos * posel -> ctree -> pos' list
|
wneuper@59292
|
244 |
val get_allpos's : pos * posel -> ctree list -> (pos * pos_) list
|
wneuper@59292
|
245 |
val cut_bottom : pos * posel -> ctree -> (ctree * pos' list) * bool
|
wneuper@59292
|
246 |
val cut_level : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
|
wneuper@59292
|
247 |
val cut_level_'_ : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
|
wneuper@59292
|
248 |
val get_trace : ctree -> int list -> int list -> int list list
|
wneuper@59292
|
249 |
val subte2subst : term list -> (term * term) list
|
wneuper@59292
|
250 |
val branch2str : branch -> string
|
wneuper@59298
|
251 |
(*\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
wneuper@59292
|
252 |
end
|
wneuper@59292
|
253 |
|
wneuper@59296
|
254 |
(*
|
wneuper@59296
|
255 |
structure CTbasic :
|
wneuper@59296
|
256 |
sig exception PTREE of string val appl_obj : (ppobj -> ppobj) -> ctree -> pos -> ctree
|
wneuper@59296
|
257 |
val appl_to_node : (ppobj -> ppobj) -> ctree -> ctree
|
wneuper@59296
|
258 |
datatype branch = AndB | CollectB | IntersectB | MapB | NoBranch | OrB | SequenceB | TransitiveB
|
wneuper@59296
|
259 |
val branch2str : branch -> string eqtype cellID val children : ctree -> ctree list type cid = cellID list
|
wneuper@59296
|
260 |
datatype con = land | lor datatype ctree = EmptyPtree | Nd of ppobj * ctree list
|
wneuper@59296
|
261 |
val cut_bottom : int list * int -> ctree -> (ctree * (int list * pos_) list) * bool
|
wneuper@59296
|
262 |
val cut_level :
|
wneuper@59296
|
263 |
(posel list * pos_) list -> posel list -> ctree -> int list * pos_ -> ctree * (posel list * pos_) list
|
wneuper@59296
|
264 |
val cut_level_'_ :
|
wneuper@59296
|
265 |
(posel list * pos_) list -> posel list -> ctree -> int list * pos_ -> ctree * (posel list * pos_) list
|
wneuper@59296
|
266 |
val cut_levup : pos' list -> bool -> ctree -> ctree -> int list * int -> ctree -> ctree * pos' list
|
wneuper@59296
|
267 |
val cut_tree : ctree -> int list * 'a -> ctree * (int list * pos_) list val del_res : ppobj -> ppobj
|
wneuper@59296
|
268 |
val e_ctree : ctree val e_ctxt : Proof.context val e_fmz : 'a list * spec val e_istate : istate
|
wneuper@59296
|
269 |
val e_ocalhd : bool * pos_ * term * itm list * (bool * term) list * spec
|
wneuper@59296
|
270 |
val e_origin : 'a list * spec * term val e_pos' : 'a list * pos_ val e_sube : cterm' list
|
wneuper@59296
|
271 |
val e_subs : string list type env = (term * term) list
|
wneuper@59296
|
272 |
type envp = (int * term list) list * (int * rls) list * (int * ets) list * (string * pos) list
|
wneuper@59296
|
273 |
val eq_tac : tac * tac -> bool type ets = (loc_ * (tac_ * env * env * term * term * safe)) list
|
wneuper@59296
|
274 |
val ets2s : loc_ * (tac_ * subst * subst * term * term * safe) -> string val ets2str : ets -> string
|
wneuper@59296
|
275 |
val existpt : int list -> ctree -> bool val existpt' : int list * pos_ -> ctree -> bool
|
wneuper@59298
|
276 |
val g_branch : ppobj -> branch
|
wneuper@59296
|
277 |
val g_ctxt : ppobj -> Proof.context val g_domID : ppobj -> domID
|
wneuper@59296
|
278 |
val g_env : ppobj -> (istate * Proof.context) option val g_fmz : ppobj -> fmz val g_form : ppobj -> term
|
wneuper@59296
|
279 |
val g_loc : ppobj -> (istate * Proof.context) option * (istate * Proof.context) option
|
wneuper@59296
|
280 |
val g_met : ppobj -> itm list val g_metID : ppobj -> metID val g_origin : ppobj -> ori list * spec * term
|
wneuper@59296
|
281 |
val g_res : ppobj -> term val g_result : ppobj -> result
|
wneuper@59296
|
282 |
val g_spec : ppobj -> spec val g_tac : ppobj -> tac
|
wneuper@59296
|
283 |
val get_allp : (int list * pos_) list -> int list * (int list * pos_) -> ctree -> (int list * pos_) list
|
wneuper@59296
|
284 |
val get_allpos' : posel list * posel -> ctree -> (posel list * pos_) list
|
wneuper@59296
|
285 |
val get_allpos's : posel list * posel -> ctree list -> (posel list * pos_) list
|
wneuper@59296
|
286 |
val get_allps : (int list * pos_) list -> int list -> ctree list -> (int list * pos_) list
|
wneuper@59296
|
287 |
val get_assumptions_ : ctree -> int list * pos_ -> term list
|
wneuper@59296
|
288 |
val get_ctxt : ctree -> int list * pos_ -> Proof.context
|
wneuper@59296
|
289 |
val get_curr_formula : ctree * (int list * pos_) -> term
|
wneuper@59296
|
290 |
val get_istate : ctree -> int list * pos_ -> istate
|
wneuper@59296
|
291 |
val get_loc : ctree -> int list * pos_ -> istate * Proof.context val get_nd : ctree -> int list -> ctree
|
wneuper@59296
|
292 |
val get_obj : (ppobj -> 'a) -> ctree -> int list -> 'a
|
wneuper@59296
|
293 |
val get_somespec' : domID * pblID * metID -> domID * pblID * metID -> domID * pblID * metID
|
wneuper@59296
|
294 |
val get_trace : ctree -> int list -> int list -> int list list type iist = istate option * istate option
|
wneuper@59296
|
295 |
val ins_chn : ctree list -> ctree -> int list -> ctree
|
wneuper@59296
|
296 |
val insert_pt : ppobj -> ctree -> int list -> ctree val is_e_ctxt : Proof.context -> bool
|
wneuper@59296
|
297 |
val is_empty_tac : tac -> bool val is_interpos : 'a * pos_ -> bool val is_pblnd : ctree -> bool
|
wneuper@59296
|
298 |
val is_pblobj : ppobj -> bool val is_pblobj' : ctree -> int list -> bool val is_rewset : tac -> bool
|
wneuper@59296
|
299 |
val is_rewtac : tac -> bool datatype istate = RrlsState of rrlsstate | ScrState of scrstate | Uistate
|
wneuper@59296
|
300 |
val istate2str : istate -> string val istates2str : istate option * istate option -> string
|
wneuper@59296
|
301 |
val just_created : ctree * (int list * 'a) -> bool val just_created_ : ppobj -> bool
|
wneuper@59296
|
302 |
val lev_on : int list -> int list val lev_pred' : ctree -> int list * pos_ -> int list * pos_
|
wneuper@59296
|
303 |
val lev_up : int list -> pos val move_dn : int list -> ctree -> int list * pos_ -> int list * pos_
|
wneuper@59296
|
304 |
val move_up : int list -> ctree -> int list * pos_ -> int list * pos_
|
wneuper@59296
|
305 |
val movecalchd_up : ctree -> int list * pos_ -> int list * pos_
|
wneuper@59296
|
306 |
val movelevel_dn : int list -> ctree -> int list * pos_ -> int list * pos_
|
wneuper@59296
|
307 |
val movelevel_up : int list -> ctree -> int list * 'a -> int list * pos_
|
wneuper@59296
|
308 |
val new_val : term -> istate -> istate val nth : int -> 'a list -> 'a
|
wneuper@59296
|
309 |
type ocalhd = bool * pos_ * term * itm list * (bool * term) list * spec
|
wneuper@59296
|
310 |
val ocalhd2str :
|
wneuper@59296
|
311 |
bool * pos_ * term * itm list * (bool * term) list * (string * string list * string list) -> string
|
wneuper@59296
|
312 |
datatype ostate = Complete | Incomplete | Inconsistent val ostate2str : ostate -> string
|
wneuper@59296
|
313 |
val par_pbl_det : ctree -> int list -> bool * int list * rls
|
wneuper@59296
|
314 |
val par_pblobj : ctree -> int list -> int list type pos = int list type pos' = pos * pos_
|
wneuper@59296
|
315 |
val pos'2str : int list * pos_ -> string val pos's2str : (int list * pos_) list -> string
|
wneuper@59296
|
316 |
val pos2str : int list -> string datatype pos_ = Frm | Met | Pbl | Res | Und
|
wneuper@59296
|
317 |
val pos_2str : pos_ -> string eqtype posel
|
wneuper@59296
|
318 |
datatype ppobj
|
wneuper@59296
|
319 |
= PblObj of
|
wneuper@59296
|
320 |
{branch: branch,
|
wneuper@59296
|
321 |
cell: lrd option,
|
wneuper@59296
|
322 |
ctxt: Proof.context,
|
wneuper@59296
|
323 |
env: (istate * Proof.context) option,
|
wneuper@59296
|
324 |
fmz: fmz,
|
wneuper@59296
|
325 |
loc: (istate * Proof.context) option * (istate * Proof.context) option,
|
wneuper@59296
|
326 |
meth: itm list,
|
wneuper@59296
|
327 |
origin: ori list * spec * term, ostate: ostate, probl: itm list, result: result, spec: spec}
|
wneuper@59296
|
328 |
| PrfObj of
|
wneuper@59296
|
329 |
{branch: branch,
|
wneuper@59296
|
330 |
cell: lrd option,
|
wneuper@59296
|
331 |
form: term,
|
wneuper@59296
|
332 |
loc: (istate * Proof.context) option * (istate * Proof.context) option,
|
wneuper@59296
|
333 |
ostate: ostate, result: result, tac: tac}
|
wneuper@59296
|
334 |
val pr_ctree : (int list -> ppobj -> string) -> ctree -> string val pr_pos : int list -> string
|
wneuper@59296
|
335 |
val pr_short : int list -> ppobj -> string val preconds2str : (bool * term) list -> string
|
wneuper@59296
|
336 |
datatype ptform = Form of term | ModSpec of ocalhd val repl : 'a list -> int -> 'a -> 'a list
|
wneuper@59296
|
337 |
val repl_app : 'a list -> int -> 'a -> 'a list val res2str : term * term list -> string
|
wneuper@59296
|
338 |
type result = term * term list val rls_of : tac -> rls' val rootthy : ctree -> theory
|
wneuper@59296
|
339 |
val rta2str : rule * (term * term list) -> string
|
wneuper@59296
|
340 |
val rule2tac : theory -> (term * term) list -> rule -> tac
|
wneuper@59296
|
341 |
datatype safe = Helpless | Safe | Sundef | Unsafe val safe2str : safe -> string
|
wneuper@59296
|
342 |
type scrstate = env * loc_ * term option * term * safe * bool
|
wneuper@59296
|
343 |
val scrstate2str : subst * loc_ * term option * term * safe * bool -> string type state = ctree * pos'
|
wneuper@59296
|
344 |
val str2pos_ : string -> pos_ type sube = cterm' list val sube2str : string list -> string
|
wneuper@59296
|
345 |
val sube2subst : theory -> string list -> (term * term) list val sube2subte : string list -> term list
|
wneuper@59296
|
346 |
type subs = cterm' list val subs2subst : theory -> string list -> (term * term) list
|
wneuper@59296
|
347 |
val subst2sube : (term * term) list -> string list val subst2subs : (term * term) list -> string list
|
wneuper@59296
|
348 |
val subst2subs' : (term * term) list -> (string * string) list type subte = term list
|
wneuper@59296
|
349 |
val subte2sube : term list -> string list val subte2subst : term list -> (term * term) list
|
wneuper@59296
|
350 |
datatype tac
|
wneuper@59296
|
351 |
= Add_Find of cterm' | Add_Given of cterm' | Add_Relation of cterm' | Apply_Assumption of cterm' list
|
wneuper@59296
|
352 |
| Apply_Method of metID | Begin_Sequ | Begin_Trans | CAScmd of cterm' | Calculate of string
|
wneuper@59296
|
353 |
| Check_Postcond of pblID | Check_elementwise of cterm' | Collect_Trues | Conclude_And | Conclude_Or
|
wneuper@59296
|
354 |
| Del_Find of cterm' | Del_Given of cterm' | Del_Relation of cterm' | Derive of rls'
|
wneuper@59296
|
355 |
| Detail_Set of rls' | Detail_Set_Inst of subs * rls' | Empty_Tac | End_Detail | End_Intersect
|
wneuper@59296
|
356 |
| End_Proof' | End_Ruleset | End_Sequ | End_Subproblem | End_Trans | Free_Solve
|
wneuper@59296
|
357 |
| Init_Proof of cterm' list * spec | Model_Problem | Or_to_List | Refine_Problem of pblID
|
wneuper@59296
|
358 |
| Refine_Tacitly of pblID | Rewrite of thm'' | Rewrite_Asm of thm'' | Rewrite_Inst of subs * thm''
|
wneuper@59296
|
359 |
| Rewrite_Set of rls' | Rewrite_Set_Inst of subs * rls' | Specify_Method of metID
|
wneuper@59296
|
360 |
| Specify_Problem of pblID | Specify_Theory of domID | Split_And | Split_Intersect | Split_Or
|
wneuper@59296
|
361 |
| Subproblem of domID * pblID | Substitute of sube | Tac of string | Take of cterm'
|
wneuper@59296
|
362 |
| Take_Inst of cterm'
|
wneuper@59296
|
363 |
val tac2IDstr : tac -> string val tac2str : tac -> string
|
wneuper@59296
|
364 |
datatype tac_
|
wneuper@59296
|
365 |
= Add_Find' of cterm' * itm list | Add_Given' of cterm' * itm list | Add_Relation' of cterm' * itm list
|
wneuper@59296
|
366 |
| Apply_Assumption' of term list * term
|
wneuper@59296
|
367 |
| Apply_Method' of metID * term option * istate * Proof.context | Begin_Sequ' | Begin_Trans' of term
|
wneuper@59296
|
368 |
| CAScmd' of term | Calculate' of theory' * string * term * (term * thm')
|
wneuper@59296
|
369 |
| Check_Postcond' of pblID * result | Check_elementwise' of term * string * result
|
wneuper@59296
|
370 |
| Collect_Trues' of term | Conclude_And' of term | Conclude_Or' of term | Del_Find' of cterm'
|
wneuper@59296
|
371 |
| Del_Given' of cterm' | Del_Relation' of cterm' | Derive' of rls
|
wneuper@59296
|
372 |
| Detail_Set' of theory' * bool * rls * term * result
|
wneuper@59296
|
373 |
| Detail_Set_Inst' of theory' * bool * subst * rls * term * result | Empty_Tac_
|
wneuper@59296
|
374 |
| End_Detail' of result | End_Intersect' of term | End_Proof'' | End_Ruleset' of term | End_Sequ'
|
wneuper@59296
|
375 |
| End_Subproblem' of term | End_Trans' of result | Free_Solve' | Init_Proof' of cterm' list * spec
|
wneuper@59296
|
376 |
| Model_Problem' of pblID * itm list * itm list | Or_to_List' of term * term
|
wneuper@59296
|
377 |
| Refine_Problem' of pblID * (itm list * (bool * term) list)
|
wneuper@59296
|
378 |
| Refine_Tacitly' of pblID * pblID * domID * metID * itm list
|
wneuper@59296
|
379 |
| Rewrite' of theory' * rew_ord' * rls * bool * thm'' * term * result
|
wneuper@59296
|
380 |
| Rewrite_Asm' of theory' * rew_ord' * rls * bool * thm'' * term * result
|
wneuper@59296
|
381 |
| Rewrite_Inst' of theory' * rew_ord' * rls * bool * subst * thm'' * term * result
|
wneuper@59296
|
382 |
| Rewrite_Set' of theory' * bool * rls * term * result
|
wneuper@59296
|
383 |
| Rewrite_Set_Inst' of theory' * bool * subst * rls * term * result
|
wneuper@59296
|
384 |
| Specify_Method' of metID * ori list * itm list
|
wneuper@59296
|
385 |
| Specify_Problem' of pblID * (bool * (itm list * (bool * term) list)) | Specify_Theory' of domID
|
wneuper@59296
|
386 |
| Split_And' of term | Split_Intersect' of term | Split_Or' of term
|
wneuper@59296
|
387 |
| Subproblem' of spec * ori list * term * fmz_ * Proof.context * term
|
wneuper@59296
|
388 |
| Substitute' of rew_ord_ * rls * subte * term * term | Tac_ of theory * string * string * string
|
wneuper@59296
|
389 |
| Take' of term | Take_Inst' of term
|
wneuper@59296
|
390 |
val tac_2str : tac_ -> string val test_trans : ppobj -> bool val topt2str : term option -> string end*)
|
wneuper@59296
|
391 |
|
wneuper@59292
|
392 |
(**)
|
wneuper@59292
|
393 |
structure CTbasic(**): BASIC_CALC_TREE(**) =
|
wneuper@59292
|
394 |
struct
|
wneuper@59292
|
395 |
(**)
|
wneuper@59292
|
396 |
type result = term * term list
|
wneuper@59292
|
397 |
type env = (term * term) list;
|
wneuper@59292
|
398 |
|
wneuper@59292
|
399 |
datatype branch =
|
wneuper@59292
|
400 |
NoBranch | AndB | OrB
|
wneuper@59292
|
401 |
| TransitiveB (* FIXXXME.0308: set branch from met in Apply_Method
|
wneuper@59292
|
402 |
FIXXXME.0402: -"- in Begin_Trans'*)
|
wneuper@59292
|
403 |
| SequenceB | IntersectB | CollectB | MapB;
|
wneuper@59292
|
404 |
|
wneuper@59292
|
405 |
fun branch2str NoBranch = "NoBranch" (* for tests only *)
|
wneuper@59292
|
406 |
| branch2str AndB = "AndB"
|
wneuper@59292
|
407 |
| branch2str OrB = "OrB"
|
wneuper@59292
|
408 |
| branch2str TransitiveB = "TransitiveB"
|
wneuper@59292
|
409 |
| branch2str SequenceB = "SequenceB"
|
wneuper@59292
|
410 |
| branch2str IntersectB = "IntersectB"
|
wneuper@59292
|
411 |
| branch2str CollectB = "CollectB"
|
wneuper@59292
|
412 |
| branch2str MapB = "MapB";
|
wneuper@59292
|
413 |
|
wneuper@59292
|
414 |
datatype ostate =
|
wneuper@59292
|
415 |
Incomplete | Complete | Inconsistent (* WN041020 latter still unused *);
|
wneuper@59292
|
416 |
fun ostate2str Incomplete = "Incomplete" (* for tests only *)
|
wneuper@59292
|
417 |
| ostate2str Complete = "Complete"
|
wneuper@59292
|
418 |
| ostate2str Inconsistent = "Inconsistent";
|
wneuper@59292
|
419 |
|
wneuper@59292
|
420 |
type cellID = int;
|
wneuper@59292
|
421 |
type cid = cellID list;
|
wneuper@59292
|
422 |
|
wneuper@59292
|
423 |
type posel = int; (* for readability in funs accessing Ctree *)
|
wneuper@59292
|
424 |
type pos = int list;
|
wneuper@59292
|
425 |
val pos2str = ints2str';
|
wneuper@59292
|
426 |
datatype pos_ =
|
wneuper@59292
|
427 |
Pbl (* PblObj-position: problem-type *)
|
wneuper@59292
|
428 |
| Met (* PblObj-position: method *)
|
wneuper@59292
|
429 |
| Frm (* PblObj-position: -> Pbl in ME (not by moveDown !)
|
wneuper@59292
|
430 |
| PrfObj-position: formula *)
|
wneuper@59292
|
431 |
| Res (* PblObj | PrfObj-position: result *)
|
wneuper@59292
|
432 |
| Und; (* undefined*)
|
wneuper@59292
|
433 |
fun pos_2str Pbl = "Pbl"
|
wneuper@59292
|
434 |
| pos_2str Met = "Met"
|
wneuper@59292
|
435 |
| pos_2str Frm = "Frm"
|
wneuper@59292
|
436 |
| pos_2str Res = "Res"
|
wneuper@59292
|
437 |
| pos_2str Und = "Und";
|
wneuper@59292
|
438 |
fun str2pos_ "Pbl" = Pbl
|
wneuper@59292
|
439 |
| str2pos_ "Met" = Met
|
wneuper@59292
|
440 |
| str2pos_ "Frm" = Frm
|
wneuper@59292
|
441 |
| str2pos_ "Res" = Res
|
wneuper@59292
|
442 |
| str2pos_ "Und" = Und
|
wneuper@59292
|
443 |
| str2pos_ str = error ("str2pos_: wrong argument = " ^ str)
|
wneuper@59292
|
444 |
|
wneuper@59292
|
445 |
type pos' = pos * pos_;
|
wneuper@59292
|
446 |
(*WN0312 remembering interator (pos * pos_) for ctree
|
wneuper@59292
|
447 |
pos : lev_on, lev_dn, lev_up
|
wneuper@59292
|
448 |
pos_:
|
wneuper@59292
|
449 |
# generate1 sets pos_ if possible ...?WN0502?NOT...
|
wneuper@59292
|
450 |
# generate1 does NOT set pos, because certain nodes can be lev_on OR lev_dn
|
wneuper@59292
|
451 |
exceptions: Begin/End_Trans
|
wneuper@59292
|
452 |
# thus generate(1) called in
|
wneuper@59292
|
453 |
.# assy, locate_gen
|
wneuper@59292
|
454 |
.# nxt_solv (tac_ -cases); general case:
|
wneuper@59292
|
455 |
val pos' = case pos' of (p,Res) => (lev_on p',Res) | _ => pos'
|
wneuper@59292
|
456 |
# WN050220, S(604):
|
wneuper@59292
|
457 |
generate1...(Rewrite(f,..,res))..(pos, pos_)
|
wneuper@59292
|
458 |
cappend_atomic.................pos ////// gets f+res always!!!
|
wneuper@59292
|
459 |
cut_tree....................pos, pos_
|
wneuper@59292
|
460 |
*)
|
wneuper@59292
|
461 |
fun pos'2str (p, p_) = pair2str (ints2str' p, pos_2str p_);
|
wneuper@59292
|
462 |
fun pos's2str ps = (strs2str' o (map pos'2str)) ps; (* for tests only *)
|
wneuper@59292
|
463 |
val e_pos' = ([], Und);
|
wneuper@59292
|
464 |
|
wneuper@59292
|
465 |
fun res2str (t, ts) = pair2str (term2str t, terms2str ts); (* for tests only *)
|
wneuper@59292
|
466 |
|
wneuper@59292
|
467 |
datatype safe = Sundef | Safe | Unsafe | Helpless;
|
wneuper@59292
|
468 |
fun safe2str Sundef = "Sundef"
|
wneuper@59292
|
469 |
| safe2str Safe = "Safe"
|
wneuper@59292
|
470 |
| safe2str Unsafe = "Unsafe"
|
wneuper@59292
|
471 |
| safe2str Helpless = "Helpless";
|
wneuper@59292
|
472 |
|
wneuper@59292
|
473 |
type subs = cterm' list; (*16.11.00 for FE-KE*)
|
wneuper@59292
|
474 |
val e_subs = ["(bdv, x)"]; (* for tests only *)
|
wneuper@59292
|
475 |
|
wneuper@59292
|
476 |
(* argument type of tac Rewrite_Inst *)
|
wneuper@59292
|
477 |
type sube = cterm' list;
|
wneuper@59292
|
478 |
val e_sube = []: cterm' list; (* for tests only *)
|
wneuper@59292
|
479 |
fun sube2str s = strs2str s;
|
wneuper@59292
|
480 |
|
wneuper@59292
|
481 |
(* _sub_stitution as _t_erms of _e_qualities *)
|
wneuper@59292
|
482 |
type subte = term list;
|
wneuper@59292
|
483 |
|
wneuper@59292
|
484 |
val subte2sube = map term2str;
|
wneuper@59292
|
485 |
val subst2subs = map (pair2str o (apfst term2str) o (apsnd term2str));
|
wneuper@59292
|
486 |
fun subst2sube subst = map term2str (map HOLogic.mk_eq subst)
|
wneuper@59292
|
487 |
val subst2subs' = map ((apfst term2str) o (apsnd term2str));
|
wneuper@59292
|
488 |
fun subs2subst thy s = map (isapair2pair o (parse_patt thy)) s;
|
wneuper@59292
|
489 |
fun sube2subst thy s = map (dest_equals' o (parse_patt thy)) s;
|
wneuper@59292
|
490 |
val sube2subte = map str2term;
|
wneuper@59292
|
491 |
val subte2subst = map HOLogic.dest_eq;
|
wneuper@59292
|
492 |
|
wneuper@59292
|
493 |
type scrstate = (*state for script interpreter*)
|
wneuper@59292
|
494 |
env(*stack*) (*used to instantiate tac for checking assod
|
wneuper@59292
|
495 |
12.03.noticed: e_ not updated during execution ?!?*)
|
wneuper@59292
|
496 |
* loc_ (*location of tac in script*)
|
wneuper@59292
|
497 |
* term option(*argument of curried functions*)
|
wneuper@59292
|
498 |
* term (*value obtained by tac executed
|
wneuper@59292
|
499 |
updated also after a derivation by 'new_val'*)
|
wneuper@59292
|
500 |
* safe (*estimation of how result will be obtained*)
|
wneuper@59292
|
501 |
* bool; (*true = strongly .., false = weakly associated:
|
wneuper@59292
|
502 |
only used during ass_dn/up*)
|
wneuper@59292
|
503 |
fun topt2str NONE = "NONE"
|
wneuper@59292
|
504 |
| topt2str (SOME t) = "SOME" ^ term2str t;
|
wneuper@59292
|
505 |
fun scrstate2str (env, loc_, topt, t, safe, bool) = (* for tests only *)
|
wneuper@59292
|
506 |
"(" ^ env2str env ^ ", " ^ loc_2str loc_ ^ ", " ^ topt2str topt ^ ", \n" ^
|
wneuper@59292
|
507 |
term2str t ^ ", " ^ safe2str safe ^ ", " ^ bool2str bool ^ ")";
|
wneuper@59292
|
508 |
|
wneuper@59292
|
509 |
(* for handling type istate see fun from_pblobj_or_detail', +? *)
|
wneuper@59292
|
510 |
datatype istate = (*interpreter state*)
|
wneuper@59292
|
511 |
Uistate (*undefined in modspec, in '_deriv'ation*)
|
wneuper@59292
|
512 |
| ScrState of scrstate (*for script interpreter*)
|
wneuper@59292
|
513 |
| RrlsState of rrlsstate; (*for reverse rewriting*)
|
wneuper@59292
|
514 |
val e_istate = (ScrState ([],[],NONE,e_term,Sundef,false));
|
wneuper@59292
|
515 |
val e_ctxt = Proof_Context.init_global @{theory "Pure"};
|
wneuper@59292
|
516 |
|
wneuper@59292
|
517 |
(* ATTENTION: does _not_ recognise Variable.declare_constraints, etc...*)
|
wneuper@59292
|
518 |
fun is_e_ctxt ctxt = Theory.eq_thy (Proof_Context.theory_of ctxt, @{theory "Pure"});
|
wneuper@59292
|
519 |
|
wneuper@59292
|
520 |
type iist = istate option * istate option;
|
wneuper@59292
|
521 |
(*val e_iist = (e_istate, e_istate); --- sinnlos f"ur NICHT-equality-type*)
|
wneuper@59292
|
522 |
|
wneuper@59292
|
523 |
fun rta2str (r, (t, a)) = "\n(" ^ rule2str r ^ ",(" ^ term2str t ^", " ^ terms2str a ^ "))";
|
wneuper@59292
|
524 |
fun istate2str Uistate = "Uistate"
|
wneuper@59292
|
525 |
| istate2str (ScrState (e, l, to, t, s, b)) =
|
wneuper@59292
|
526 |
"ScrState ("^ subst2str e ^ ",\n " ^
|
wneuper@59292
|
527 |
loc_2str l ^ ", " ^ termopt2str to ^ ",\n " ^
|
wneuper@59292
|
528 |
term2str t ^ ", " ^ safe2str s ^ ", " ^ bool2str b ^ ")"
|
wneuper@59292
|
529 |
| istate2str (RrlsState (t, t1, rss, rtas)) =
|
wneuper@59292
|
530 |
"RrlsState (" ^ term2str t ^ ", " ^ term2str t1 ^ ", " ^
|
wneuper@59292
|
531 |
(strs2str o (map (strs2str o (map rule2str)))) rss ^ ", " ^
|
wneuper@59292
|
532 |
(strs2str o (map rta2str)) rtas ^ ")";
|
wneuper@59292
|
533 |
fun istates2str (NONE, NONE) = "(#NONE, #NONE)" (* for tests only *)
|
wneuper@59292
|
534 |
| istates2str (NONE, SOME ist) = "(#NONE,\n#SOME " ^ istate2str ist ^ ")"
|
wneuper@59292
|
535 |
| istates2str (SOME ist, NONE) = "(#SOME " ^ istate2str ist ^ ",\n #NONE)"
|
wneuper@59292
|
536 |
| istates2str (SOME i1, SOME i2) = "(#SOME " ^ istate2str i1 ^ ",\n #SOME " ^ istate2str i2 ^ ")";
|
wneuper@59292
|
537 |
|
wneuper@59292
|
538 |
fun new_val v (ScrState (env, loc_, topt, _, safe, bool)) =
|
wneuper@59292
|
539 |
(ScrState (env, loc_, topt, v, safe, bool))
|
wneuper@59292
|
540 |
| new_val _ _ = error "new_val: only for ScrState";
|
wneuper@59292
|
541 |
|
wneuper@59292
|
542 |
datatype con = land | lor;
|
wneuper@59292
|
543 |
|
wneuper@59292
|
544 |
(* tactics for user at front-end.
|
wneuper@59292
|
545 |
tac propagates the construction of the calc-tree;
|
wneuper@59292
|
546 |
there are
|
wneuper@59292
|
547 |
(a) 'specsteps' for the specify-phase, and others for the solve-phase
|
wneuper@59292
|
548 |
(b) those of the solve-phase are 'initac's and others;
|
wneuper@59292
|
549 |
initacs start with a formula different from the preceding formula.
|
wneuper@59292
|
550 |
see 'type tac_' for the internal representation of tactics
|
wneuper@59292
|
551 |
TODO.WN161219: replace *every* cterm' by term
|
wneuper@59292
|
552 |
*)
|
wneuper@59292
|
553 |
datatype tac =
|
wneuper@59292
|
554 |
Add_Find of cterm' | Add_Given of cterm' | Add_Relation of cterm'
|
wneuper@59292
|
555 |
| Apply_Assumption of cterm' list
|
wneuper@59292
|
556 |
| Apply_Method of metID
|
wneuper@59292
|
557 |
(* creates an "istate" in PblObj.env; in case of "init_form"
|
wneuper@59292
|
558 |
creates a formula at ((lev_on o lev_dn) p, Frm) and in this "ppobj.loc"
|
wneuper@59292
|
559 |
a "SOME istate" at fst of "loc".
|
wneuper@59292
|
560 |
As each step (in the solve-phase) has a resulting formula (at the front-end)
|
wneuper@59292
|
561 |
Apply_Method also does the 1st step in the script (an "initac") if there is no "init_form" *)
|
wneuper@59292
|
562 |
(*/--- TODO: re-design ? -----------------------------------------------------------------\*)
|
wneuper@59292
|
563 |
| Begin_Sequ | Begin_Trans
|
wneuper@59292
|
564 |
| Split_And | Split_Or | Split_Intersect
|
wneuper@59292
|
565 |
| Conclude_And | Conclude_Or | Collect_Trues
|
wneuper@59292
|
566 |
| End_Sequ | End_Trans
|
wneuper@59292
|
567 |
| End_Ruleset | End_Subproblem (* WN0509 drop *) | End_Intersect | End_Proof'
|
wneuper@59292
|
568 |
(*\--- TODO: re-design ? -----------------------------------------------------------------/*)
|
wneuper@59292
|
569 |
| CAScmd of cterm'
|
wneuper@59292
|
570 |
| Calculate of string
|
wneuper@59292
|
571 |
| Check_Postcond of pblID
|
wneuper@59292
|
572 |
| Check_elementwise of cterm'
|
wneuper@59292
|
573 |
| Del_Find of cterm' | Del_Given of cterm' | Del_Relation of cterm'
|
wneuper@59292
|
574 |
|
wneuper@59292
|
575 |
| Derive of rls' (* WN0509 drop *)
|
wneuper@59292
|
576 |
| Detail_Set of rls' (* WN0509 drop *)
|
wneuper@59292
|
577 |
| Detail_Set_Inst of subs * rls' (* WN0509 drop *)
|
wneuper@59292
|
578 |
| End_Detail (* WN0509 drop *)
|
wneuper@59292
|
579 |
|
wneuper@59292
|
580 |
| Empty_Tac
|
wneuper@59292
|
581 |
| Free_Solve
|
wneuper@59292
|
582 |
|
wneuper@59292
|
583 |
| Init_Proof of cterm' list * spec
|
wneuper@59292
|
584 |
| Model_Problem
|
wneuper@59292
|
585 |
| Or_to_List
|
wneuper@59292
|
586 |
| Refine_Problem of pblID
|
wneuper@59292
|
587 |
| Refine_Tacitly of pblID
|
wneuper@59292
|
588 |
|
wneuper@59292
|
589 |
(* rewrite-tactics can transport a (thmID, thm) to and (!) from the java-front-end
|
wneuper@59292
|
590 |
because there all the thms are present with both (thmID, thm)
|
wneuper@59292
|
591 |
(where user-views can show both or only one of (thmID, thm)),
|
wneuper@59292
|
592 |
and thm is created from ThmID by assoc_thm'' when entering isabisac *)
|
wneuper@59292
|
593 |
| Rewrite of thm''
|
wneuper@59292
|
594 |
| Rewrite_Asm of thm''
|
wneuper@59292
|
595 |
| Rewrite_Inst of subs * thm''
|
wneuper@59292
|
596 |
| Rewrite_Set of rls'
|
wneuper@59292
|
597 |
| Rewrite_Set_Inst of subs * rls'
|
wneuper@59292
|
598 |
|
wneuper@59292
|
599 |
| Specify_Method of metID
|
wneuper@59292
|
600 |
| Specify_Problem of pblID
|
wneuper@59292
|
601 |
| Specify_Theory of domID
|
wneuper@59292
|
602 |
| Subproblem of domID * pblID (* WN0509 drop *)
|
wneuper@59292
|
603 |
|
wneuper@59292
|
604 |
| Substitute of sube
|
wneuper@59292
|
605 |
| Tac of string (* WN0509 drop *)
|
wneuper@59292
|
606 |
| Take of cterm' | Take_Inst of cterm'
|
wneuper@59292
|
607 |
|
wneuper@59292
|
608 |
fun tac2str ma = case ma of
|
wneuper@59292
|
609 |
Init_Proof (ppc, spec) =>
|
wneuper@59292
|
610 |
"Init_Proof "^(pair2str (strs2str ppc, spec2str spec))
|
wneuper@59292
|
611 |
| Model_Problem => "Model_Problem "
|
wneuper@59292
|
612 |
| Refine_Tacitly pblID => "Refine_Tacitly " ^ strs2str pblID
|
wneuper@59292
|
613 |
| Refine_Problem pblID => "Refine_Problem " ^ strs2str pblID
|
wneuper@59292
|
614 |
| Add_Given cterm' => "Add_Given " ^ cterm'
|
wneuper@59292
|
615 |
| Del_Given cterm' => "Del_Given " ^ cterm'
|
wneuper@59292
|
616 |
| Add_Find cterm' => "Add_Find " ^ cterm'
|
wneuper@59292
|
617 |
| Del_Find cterm' => "Del_Find " ^ cterm'
|
wneuper@59292
|
618 |
| Add_Relation cterm' => "Add_Relation " ^ cterm'
|
wneuper@59292
|
619 |
| Del_Relation cterm' => "Del_Relation " ^ cterm'
|
wneuper@59292
|
620 |
|
wneuper@59292
|
621 |
| Specify_Theory domID => "Specify_Theory " ^ quote domID
|
wneuper@59292
|
622 |
| Specify_Problem pblID => "Specify_Problem " ^ strs2str pblID
|
wneuper@59292
|
623 |
| Specify_Method metID => "Specify_Method " ^ strs2str metID
|
wneuper@59292
|
624 |
| Apply_Method metID => "Apply_Method " ^ strs2str metID
|
wneuper@59292
|
625 |
| Check_Postcond pblID => "Check_Postcond " ^ strs2str pblID
|
wneuper@59292
|
626 |
| Free_Solve => "Free_Solve"
|
wneuper@59292
|
627 |
|
wneuper@59292
|
628 |
| Rewrite_Inst (subs, (id, thm)) =>
|
wneuper@59292
|
629 |
"Rewrite_Inst " ^ (pair2str (subs2str subs, spair2str (id, thm |> Thm.prop_of |> term2str)))
|
wneuper@59292
|
630 |
| Rewrite (id, thm) => "Rewrite " ^ spair2str (id, thm |> Thm.prop_of |> term2str)
|
wneuper@59292
|
631 |
| Rewrite_Asm (id, thm) => "Rewrite_Asm " ^ spair2str (id, thm |> Thm.prop_of |> term2str)
|
wneuper@59292
|
632 |
| Rewrite_Set_Inst (subs, rls) =>
|
wneuper@59292
|
633 |
"Rewrite_Set_Inst " ^ pair2str (subs2str subs, quote rls)
|
wneuper@59292
|
634 |
| Rewrite_Set rls => "Rewrite_Set " ^ quote rls
|
wneuper@59292
|
635 |
| Detail_Set rls => "Detail_Set " ^ quote rls
|
wneuper@59292
|
636 |
| Detail_Set_Inst (subs, rls) => "Detail_Set_Inst " ^ pair2str (subs2str subs, quote rls)
|
wneuper@59292
|
637 |
| End_Detail => "End_Detail"
|
wneuper@59292
|
638 |
| Derive rls' => "Derive " ^ rls'
|
wneuper@59292
|
639 |
| Calculate op_ => "Calculate " ^ op_
|
wneuper@59292
|
640 |
| Substitute sube => "Substitute " ^ sube2str sube
|
wneuper@59292
|
641 |
| Apply_Assumption ct's => "Apply_Assumption " ^ strs2str ct's
|
wneuper@59292
|
642 |
|
wneuper@59292
|
643 |
| Take cterm' => "Take " ^ quote cterm'
|
wneuper@59292
|
644 |
| Take_Inst cterm' => "Take_Inst " ^ quote cterm'
|
wneuper@59292
|
645 |
| Subproblem (domID, pblID) => "Subproblem " ^ pair2str (domID, strs2str pblID)
|
wneuper@59292
|
646 |
| End_Subproblem => "End_Subproblem"
|
wneuper@59292
|
647 |
| CAScmd cterm' => "CAScmd " ^ quote cterm'
|
wneuper@59292
|
648 |
|
wneuper@59292
|
649 |
| Check_elementwise cterm'=> "Check_elementwise " ^ quote cterm'
|
wneuper@59292
|
650 |
| Or_to_List => "Or_to_List "
|
wneuper@59292
|
651 |
| Collect_Trues => "Collect_Trues"
|
wneuper@59292
|
652 |
|
wneuper@59292
|
653 |
| Empty_Tac => "Empty_Tac"
|
wneuper@59292
|
654 |
| Tac string => "Tac " ^ string
|
wneuper@59292
|
655 |
| End_Proof' => "tac End_Proof'"
|
wneuper@59292
|
656 |
| _ => "tac2str not impl. for ?!";
|
wneuper@59292
|
657 |
|
wneuper@59292
|
658 |
fun is_empty_tac tac = case tac of Empty_Tac => true | _ => false
|
wneuper@59292
|
659 |
|
wneuper@59292
|
660 |
fun eq_tac (Rewrite (id1, _), Rewrite (id2, _)) = id1 = id2
|
wneuper@59292
|
661 |
| eq_tac (Rewrite_Inst (_, (id1, _)), Rewrite_Inst (_, (id2, _))) = id1 = id2
|
wneuper@59292
|
662 |
| eq_tac (Rewrite_Set id1, Rewrite_Set id2) = id1 = id2
|
wneuper@59292
|
663 |
| eq_tac (Rewrite_Set_Inst (_, id1), Rewrite_Set_Inst (_, id2)) = id1 = id2
|
wneuper@59292
|
664 |
| eq_tac (Calculate id1, Calculate id2) = id1 = id2
|
wneuper@59292
|
665 |
| eq_tac _ = false
|
wneuper@59292
|
666 |
|
wneuper@59292
|
667 |
fun is_rewset (Rewrite_Set_Inst _) = true
|
wneuper@59292
|
668 |
| is_rewset (Rewrite_Set _) = true
|
wneuper@59292
|
669 |
| is_rewset _ = false;
|
wneuper@59292
|
670 |
fun is_rewtac (Rewrite _) = true
|
wneuper@59292
|
671 |
| is_rewtac (Rewrite_Inst _) = true
|
wneuper@59292
|
672 |
| is_rewtac (Rewrite_Asm _) = true
|
wneuper@59292
|
673 |
| is_rewtac tac = is_rewset tac;
|
wneuper@59292
|
674 |
|
wneuper@59292
|
675 |
fun tac2IDstr ma = case ma of
|
wneuper@59292
|
676 |
Model_Problem => "Model_Problem"
|
wneuper@59292
|
677 |
| Refine_Tacitly _ => "Refine_Tacitly"
|
wneuper@59292
|
678 |
| Refine_Problem _ => "Refine_Problem"
|
wneuper@59292
|
679 |
| Add_Given _ => "Add_Given"
|
wneuper@59292
|
680 |
| Del_Given _ => "Del_Given"
|
wneuper@59292
|
681 |
| Add_Find _ => "Add_Find"
|
wneuper@59292
|
682 |
| Del_Find _ => "Del_Find"
|
wneuper@59292
|
683 |
| Add_Relation _ => "Add_Relation"
|
wneuper@59292
|
684 |
| Del_Relation _ => "Del_Relation"
|
wneuper@59292
|
685 |
|
wneuper@59292
|
686 |
| Specify_Theory _ => "Specify_Theory"
|
wneuper@59292
|
687 |
| Specify_Problem _ => "Specify_Problem"
|
wneuper@59292
|
688 |
| Specify_Method _ => "Specify_Method"
|
wneuper@59292
|
689 |
| Apply_Method _ => "Apply_Method"
|
wneuper@59292
|
690 |
| Check_Postcond _ => "Check_Postcond"
|
wneuper@59292
|
691 |
| Free_Solve => "Free_Solve"
|
wneuper@59292
|
692 |
|
wneuper@59292
|
693 |
| Rewrite_Inst _ => "Rewrite_Inst"
|
wneuper@59292
|
694 |
| Rewrite _ => "Rewrite"
|
wneuper@59292
|
695 |
| Rewrite_Asm _ => "Rewrite_Asm"
|
wneuper@59292
|
696 |
| Rewrite_Set_Inst _ => "Rewrite_Set_Inst"
|
wneuper@59292
|
697 |
| Rewrite_Set _ => "Rewrite_Set"
|
wneuper@59292
|
698 |
| Detail_Set _ => "Detail_Set"
|
wneuper@59292
|
699 |
| Detail_Set_Inst _ => "Detail_Set_Inst"
|
wneuper@59292
|
700 |
| Derive _ => "Derive "
|
wneuper@59292
|
701 |
| Calculate _ => "Calculate "
|
wneuper@59292
|
702 |
| Substitute _ => "Substitute"
|
wneuper@59292
|
703 |
| Apply_Assumption _ => "Apply_Assumption"
|
wneuper@59292
|
704 |
|
wneuper@59292
|
705 |
| Take _ => "Take"
|
wneuper@59292
|
706 |
| Take_Inst _ => "Take_Inst"
|
wneuper@59292
|
707 |
| Subproblem _ => "Subproblem"
|
wneuper@59292
|
708 |
| End_Subproblem => "End_Subproblem"
|
wneuper@59292
|
709 |
| CAScmd _ => "CAScmd"
|
wneuper@59292
|
710 |
|
wneuper@59292
|
711 |
| Check_elementwise _ => "Check_elementwise"
|
wneuper@59292
|
712 |
| Or_to_List => "Or_to_List "
|
wneuper@59292
|
713 |
| Collect_Trues => "Collect_Trues"
|
wneuper@59292
|
714 |
|
wneuper@59292
|
715 |
| Empty_Tac => "Empty_Tac"
|
wneuper@59292
|
716 |
| Tac _ => "Tac "
|
wneuper@59292
|
717 |
| End_Proof' => "End_Proof'"
|
wneuper@59292
|
718 |
| _ => "tac2str not impl. for ?!";
|
wneuper@59292
|
719 |
|
wneuper@59292
|
720 |
fun rls_of (Rewrite_Set_Inst (_, rls)) = rls
|
wneuper@59292
|
721 |
| rls_of (Rewrite_Set rls) = rls
|
wneuper@59292
|
722 |
| rls_of tac = error ("rls_of: called with tac \"" ^ tac2IDstr tac ^ "\"");
|
wneuper@59292
|
723 |
|
wneuper@59292
|
724 |
fun rule2tac thy _ (Calc (opID, thm)) = Calculate (assoc_calc thy opID)
|
wneuper@59292
|
725 |
| rule2tac _ [] (Thm thm'') = Rewrite thm''
|
wneuper@59292
|
726 |
| rule2tac _ subst (Thm thm'') =
|
wneuper@59292
|
727 |
Rewrite_Inst (subst2subs subst, thm'')
|
wneuper@59292
|
728 |
| rule2tac _ [] (Rls_ rls) = Rewrite_Set (id_rls rls)
|
wneuper@59292
|
729 |
| rule2tac _ subst (Rls_ rls) =
|
wneuper@59292
|
730 |
Rewrite_Set_Inst (subst2subs subst, (id_rls rls))
|
wneuper@59292
|
731 |
| rule2tac _ _ rule =
|
wneuper@59292
|
732 |
error ("rule2tac: called with \"" ^ rule2str rule ^ "\"");
|
wneuper@59292
|
733 |
|
wneuper@59292
|
734 |
(* tactics for for internal use, compare "tac" for user at the front-end.
|
wneuper@59292
|
735 |
tac_ contains results from check in 'fun applicable_in'.
|
wneuper@59292
|
736 |
This is useful for costly results, e.g. from rewriting;
|
wneuper@59292
|
737 |
however, these results might be changed by Scripts like
|
wneuper@59292
|
738 |
" eq = (Rewrite_Set ansatz_rls False) eql;" ^
|
wneuper@59292
|
739 |
" eq = drop_questionmarks eq;" ^
|
wneuper@59292
|
740 |
" eq = (Rewrite_Set equival_trans False) eq;" ^
|
wneuper@59292
|
741 |
TODO.WN120106 ANALOGOUSLY TO Substitute':
|
wneuper@59292
|
742 |
So tac_ contains the term t the result was calculated from
|
wneuper@59292
|
743 |
in order to compare t with t' possibly changed by "Expr "
|
wneuper@59292
|
744 |
and re-calculate result if t<>t'
|
wneuper@59292
|
745 |
TODO.WN161219: replace *every* cterm' by term
|
wneuper@59292
|
746 |
*)
|
wneuper@59292
|
747 |
datatype tac_ =
|
wneuper@59292
|
748 |
Add_Find' of cterm' * itm list | Add_Given' of cterm' * itm list | Add_Relation' of cterm' * itm list
|
wneuper@59292
|
749 |
| Apply_Assumption' of term list * term
|
wneuper@59292
|
750 |
| Apply_Method' of metID * term option * istate * Proof.context
|
wneuper@59292
|
751 |
(*/--- TODO: re-design ? -----------------------------------------------------------------\*)
|
wneuper@59292
|
752 |
| Begin_Sequ' | Begin_Trans' of term
|
wneuper@59292
|
753 |
| Split_And' of term | Split_Or' of term | Split_Intersect' of term
|
wneuper@59292
|
754 |
| Conclude_And' of term | Conclude_Or' of term | Collect_Trues' of term
|
wneuper@59292
|
755 |
| End_Sequ' | End_Trans' of result
|
wneuper@59292
|
756 |
| End_Ruleset' of term | End_Subproblem' of term | End_Intersect' of term | End_Proof''
|
wneuper@59292
|
757 |
(*\--- TODO: re-design ? -----------------------------------------------------------------/*)
|
wneuper@59292
|
758 |
| CAScmd' of term
|
wneuper@59292
|
759 |
| Calculate' of theory' * string * term * (term * thm')
|
wneuper@59292
|
760 |
| Check_Postcond' of pblID *
|
wneuper@59292
|
761 |
result (* returnvalue of script in solve *)
|
wneuper@59292
|
762 |
| Check_elementwise' of (*special case:*)
|
wneuper@59292
|
763 |
term * (* (1) the current formula: [x=1,x=...] *)
|
wneuper@59292
|
764 |
string * (* (2) the pred from Check_elementwise *)
|
wneuper@59292
|
765 |
result (* (3) composed from (1) and (2): {x. pred} *)
|
wneuper@59292
|
766 |
| Del_Find' of cterm' | Del_Given' of cterm' | Del_Relation' of cterm'
|
wneuper@59292
|
767 |
|
wneuper@59292
|
768 |
| Derive' of rls
|
wneuper@59292
|
769 |
| Detail_Set' of theory' * bool * rls * term * result
|
wneuper@59292
|
770 |
| Detail_Set_Inst' of theory' * bool * subst * rls * term * result
|
wneuper@59292
|
771 |
| End_Detail' of result
|
wneuper@59292
|
772 |
|
wneuper@59292
|
773 |
| Empty_Tac_
|
wneuper@59292
|
774 |
| Free_Solve'
|
wneuper@59292
|
775 |
|
wneuper@59292
|
776 |
| Init_Proof' of cterm' list * spec
|
wneuper@59292
|
777 |
| Model_Problem' of pblID *
|
wneuper@59292
|
778 |
itm list * (* the 'untouched' pbl *)
|
wneuper@59292
|
779 |
itm list (* the casually completed met *)
|
wneuper@59292
|
780 |
| Or_to_List' of term * term
|
wneuper@59292
|
781 |
| Refine_Problem' of pblID * (itm list * (bool * term) list)
|
wneuper@59292
|
782 |
| Refine_Tacitly' of
|
wneuper@59292
|
783 |
pblID * (* input*)
|
wneuper@59292
|
784 |
pblID * (* the refined from applicable_in *)
|
wneuper@59292
|
785 |
domID * (* from new pbt?! filled in specify *)
|
wneuper@59292
|
786 |
metID * (* from new pbt?! filled in specify *)
|
wneuper@59292
|
787 |
itm list (* drop ! 9.03: remains [] for Model_Problem recognizing its activation *)
|
wneuper@59292
|
788 |
| Rewrite' of theory' * rew_ord' * rls * bool * thm'' * term * result
|
wneuper@59292
|
789 |
| Rewrite_Asm' of theory' * rew_ord' * rls * bool * thm'' * term * result
|
wneuper@59292
|
790 |
| Rewrite_Inst' of theory' * rew_ord' * rls * bool * subst * thm'' * term * result
|
wneuper@59292
|
791 |
| Rewrite_Set' of theory' * bool * rls * term * result
|
wneuper@59292
|
792 |
| Rewrite_Set_Inst' of theory' * bool * subst * rls * term * result
|
wneuper@59292
|
793 |
|
wneuper@59292
|
794 |
| Specify_Method' of metID * ori list * itm list
|
wneuper@59292
|
795 |
| Specify_Problem' of pblID *
|
wneuper@59292
|
796 |
(bool * (* matches *)
|
wneuper@59292
|
797 |
(itm list * (* ppc *)
|
wneuper@59292
|
798 |
(bool * term) list)) (* preconditions *)
|
wneuper@59292
|
799 |
| Specify_Theory' of domID
|
wneuper@59292
|
800 |
| Subproblem' of
|
wneuper@59292
|
801 |
spec *
|
wneuper@59292
|
802 |
(ori list) * (* filled in assod Subproblem' *)
|
wneuper@59292
|
803 |
term * (* -"-, headline of calc-head *)
|
wneuper@59298
|
804 |
Selem.fmz_ *
|
wneuper@59292
|
805 |
Proof.context * (* transported from assod to generate1*)
|
wneuper@59292
|
806 |
term (* Subproblem(dom,pbl) OR cascmd *)
|
wneuper@59292
|
807 |
| Substitute' of
|
wneuper@59292
|
808 |
rew_ord_ * (* for re-calculation *)
|
wneuper@59292
|
809 |
rls * (* for re-calculation *)
|
wneuper@59292
|
810 |
subte * (* the 'substitution': terms of type bool *)
|
wneuper@59292
|
811 |
term * (* to be substituted in *)
|
wneuper@59292
|
812 |
term (* resulting from the substitution *)
|
wneuper@59292
|
813 |
| Tac_ of theory * string * string * string
|
wneuper@59292
|
814 |
| Take' of term | Take_Inst' of term
|
wneuper@59292
|
815 |
|
wneuper@59292
|
816 |
fun tac_2str ma = case ma of
|
wneuper@59292
|
817 |
Init_Proof' (ppc, spec) => "Init_Proof' " ^ pair2str (strs2str ppc, spec2str spec)
|
wneuper@59292
|
818 |
| Model_Problem' (pblID, _, _) => "Model_Problem' " ^ strs2str pblID
|
wneuper@59292
|
819 |
| Refine_Tacitly'(p, prefin, domID, metID, _) => "Refine_Tacitly' (" ^ strs2str p ^ ", " ^
|
wneuper@59292
|
820 |
strs2str prefin ^ ", " ^ domID ^ ", " ^ strs2str metID ^ ", pbl-itms)"
|
wneuper@59292
|
821 |
| Refine_Problem' _ => "Refine_Problem' (" ^ (*matchs2str ms*)"..." ^ ")"
|
wneuper@59292
|
822 |
| Add_Given' _ => "Add_Given' "(*^cterm'*)
|
wneuper@59292
|
823 |
| Del_Given' _ => "Del_Given' "(*^cterm'*)
|
wneuper@59292
|
824 |
| Add_Find' _ => "Add_Find' "(*^cterm'*)
|
wneuper@59292
|
825 |
| Del_Find' _ => "Del_Find' "(*^cterm'*)
|
wneuper@59292
|
826 |
| Add_Relation' _ => "Add_Relation' "(*^cterm'*)
|
wneuper@59292
|
827 |
| Del_Relation' _ => "Del_Relation' "(*^cterm'*)
|
wneuper@59292
|
828 |
|
wneuper@59292
|
829 |
| Specify_Theory' domID => "Specify_Theory' " ^ quote domID
|
wneuper@59292
|
830 |
| Specify_Problem' (pI, (ok, _)) => "Specify_Problem' " ^
|
wneuper@59292
|
831 |
spair2str (strs2str pI, spair2str (bool2str ok, spair2str ("itms2str_ itms", "items2str pre")))
|
wneuper@59292
|
832 |
| Specify_Method' (pI, oris, _) => "Specify_Method' (" ^
|
wneuper@59292
|
833 |
metID2str pI ^ ", " ^ oris2str oris ^ ", )"
|
wneuper@59292
|
834 |
|
wneuper@59292
|
835 |
| Apply_Method' (metID, _, _, _) => "Apply_Method' " ^ strs2str metID
|
wneuper@59292
|
836 |
| Check_Postcond' (pblID, (scval, asm)) => "Check_Postcond' " ^
|
wneuper@59292
|
837 |
(spair2str (strs2str pblID, spair2str (term2str scval, terms2str asm)))
|
wneuper@59292
|
838 |
|
wneuper@59292
|
839 |
| Free_Solve' => "Free_Solve'"
|
wneuper@59292
|
840 |
|
wneuper@59292
|
841 |
| Rewrite_Inst' (*subs,thm'*) _ => "Rewrite_Inst' "(*^(pair2str (subs2str subs, spair2str thm'))*)
|
wneuper@59292
|
842 |
| Rewrite' _(*thm'*) => "Rewrite' "(*^(spair2str thm')*)
|
wneuper@59292
|
843 |
| Rewrite_Asm' _(*thm'*) => "Rewrite_Asm' "(*^(spair2str thm')*)
|
wneuper@59292
|
844 |
| Rewrite_Set_Inst' _(*subs,thm'*) => "Rewrite_Set_Inst' "(*^(pair2str (subs2str subs, quote rls))*)
|
wneuper@59292
|
845 |
| Rewrite_Set' (thy', pasm, rls', f, (f', asm)) => "Rewrite_Set' (" ^ thy' ^ "," ^ bool2str pasm ^
|
wneuper@59292
|
846 |
"," ^ id_rls rls' ^ "," ^ term2str f ^ ",(" ^ term2str f' ^ "," ^ terms2str asm ^ "))"
|
wneuper@59292
|
847 |
| End_Detail' _ => "End_Detail' xxx"
|
wneuper@59292
|
848 |
| Detail_Set' _ => "Detail_Set' xxx"
|
wneuper@59292
|
849 |
| Detail_Set_Inst' _ => "Detail_Set_Inst' xxx"
|
wneuper@59292
|
850 |
|
wneuper@59292
|
851 |
| Derive' rls => "Derive' " ^ id_rls rls
|
wneuper@59292
|
852 |
| Calculate' _ => "Calculate' "
|
wneuper@59292
|
853 |
| Substitute' _ => "Substitute' "(*^(subs2str subs)*)
|
wneuper@59292
|
854 |
| Apply_Assumption' _(* ct's*) => "Apply_Assumption' "(*^(strs2str ct's)*)
|
wneuper@59292
|
855 |
|
wneuper@59292
|
856 |
| Take' _(*cterm'*) => "Take' "(*^(quote cterm' )*)
|
wneuper@59292
|
857 |
| Take_Inst' _(*cterm'*) => "Take_Inst' "(*^(quote cterm' )*)
|
wneuper@59292
|
858 |
| Subproblem' _(*(spec, oris, _, _, _, pbl_form)*) =>
|
wneuper@59292
|
859 |
"Subproblem' "(*^(pair2str (domID, strs2str ,))*)
|
wneuper@59292
|
860 |
| End_Subproblem' _ => "End_Subproblem'"
|
wneuper@59292
|
861 |
| CAScmd' _(*cterm'*) => "CAScmd' "(*^(quote cterm')*)
|
wneuper@59292
|
862 |
|
wneuper@59292
|
863 |
| Empty_Tac_ => "Empty_Tac_"
|
wneuper@59292
|
864 |
| Tac_ (_,form,id,result) => "Tac_ (thy," ^ form ^ "," ^ id ^ "," ^ result ^ ")"
|
wneuper@59292
|
865 |
| _ => "tac_2str not impl. for arg";
|
wneuper@59292
|
866 |
|
wneuper@59292
|
867 |
(* executed tactics (tac_s) with local environment etc.;
|
wneuper@59292
|
868 |
used for continuing eval script + for generate *)
|
wneuper@59292
|
869 |
type ets =
|
wneuper@59292
|
870 |
(loc_ * (* of tactic in scr, tactic (weakly) associated with tac_ *)
|
wneuper@59292
|
871 |
(tac_ * (* (for generate) *)
|
wneuper@59292
|
872 |
env * (* with 'tactic=result' as rule, tactic ev. _not_ ready: for handling 'parallel let'*)
|
wneuper@59292
|
873 |
env * (* with results of (ready) tacs *)
|
wneuper@59292
|
874 |
term * (* itr_arg of tactic, for upd. env at Repeat, Try *)
|
wneuper@59292
|
875 |
term * (* result value of the tac *)
|
wneuper@59292
|
876 |
safe))
|
wneuper@59292
|
877 |
list;
|
wneuper@59292
|
878 |
|
wneuper@59292
|
879 |
fun ets2s (l,(m,eno,env,iar,res,s)) =
|
wneuper@59292
|
880 |
"\n(" ^ loc_2str l ^ ",(" ^ tac_2str m ^
|
wneuper@59292
|
881 |
",\n ens= " ^ subst2str eno ^
|
wneuper@59292
|
882 |
",\n env= " ^ subst2str env ^
|
wneuper@59292
|
883 |
",\n iar= " ^ term2str iar ^
|
wneuper@59292
|
884 |
",\n res= " ^ term2str res ^
|
wneuper@59292
|
885 |
",\n " ^ safe2str s ^ "))";
|
wneuper@59292
|
886 |
fun ets2str (ets: ets) = (strs2str o (map ets2s)) ets; (* for tests only *)
|
wneuper@59292
|
887 |
|
wneuper@59292
|
888 |
type envp =(*9.5.03: unused, delete with field in ctree.PblObj FIXXXME*)
|
wneuper@59292
|
889 |
(int * term list) list * (* assoc-list: args of met*)
|
wneuper@59292
|
890 |
(int * rls) list * (* assoc-list: tacs already done ///15.9.00*)
|
wneuper@59292
|
891 |
(int * ets) list * (* assoc-list: tacs etc. already done*)
|
wneuper@59292
|
892 |
(string * pos) list; (* asms * from where*)
|
wneuper@59292
|
893 |
|
wneuper@59292
|
894 |
datatype ppobj = (* TODO: arrange according to signature *)
|
wneuper@59292
|
895 |
PrfObj of
|
wneuper@59292
|
896 |
{cell : lrd option, (* where in form tac has been applied, FIXME.WN0607 rename field *)
|
wneuper@59292
|
897 |
form : term, (* where tac is applied to *)
|
wneuper@59292
|
898 |
tac : tac, (* also in istate *)
|
wneuper@59292
|
899 |
loc : (istate * (* script interpreter state *)
|
wneuper@59292
|
900 |
Proof.context) (* context for provers, type inference *)
|
wneuper@59292
|
901 |
option * (* both for interpreter location on Frm, Pbl, Met *)
|
wneuper@59292
|
902 |
(istate * (* script interpreter state *)
|
wneuper@59292
|
903 |
Proof.context) (* context for provers, type inference *)
|
wneuper@59292
|
904 |
option, (* both for interpreter location on Res *)
|
wneuper@59292
|
905 |
(*(NONE,NONE) <==> e_istate ! see update_loc, get_loc *)
|
wneuper@59292
|
906 |
branch: branch, (* only rudimentary *)
|
wneuper@59292
|
907 |
result: result, (* result and assumptions *)
|
wneuper@59292
|
908 |
ostate: ostate} (* Complete <=> result is OK *)
|
wneuper@59292
|
909 |
| PblObj of
|
wneuper@59292
|
910 |
{cell : lrd option, (* unused: meaningful only for some _Prf_Obj *)
|
wneuper@59298
|
911 |
fmz : Selem.fmz, (* from init:FIXME never use this spec;-drop *)
|
wneuper@59292
|
912 |
origin: (ori list) * (* representation from fmz+pbt
|
wneuper@59292
|
913 |
for efficiently adding items in probl, meth *)
|
wneuper@59292
|
914 |
spec * (* updated by Refine_Tacitly *)
|
wneuper@59292
|
915 |
term, (* headline of calc-head, as calculated initially(!) *)
|
wneuper@59292
|
916 |
spec : spec, (* explicitly input *)
|
wneuper@59292
|
917 |
probl : itm list, (* itms explicitly input *)
|
wneuper@59292
|
918 |
meth : itm list, (* itms automatically added to copy of probl *)
|
wneuper@59292
|
919 |
ctxt : Proof.context, (* WN110513 introduced to avoid [*] [**] *)
|
wneuper@59292
|
920 |
env : (istate * Proof.context) option, (* istate only for initac in script
|
wneuper@59292
|
921 |
context for specify phase on this node NO..
|
wneuper@59292
|
922 |
..NO: this conflicts with init_form/initac: see Apply_Method without init_form *)
|
wneuper@59292
|
923 |
loc : (istate * Proof.context) option * (istate * (* like PrfObj *)
|
wneuper@59292
|
924 |
Proof.context) option, (* for spec-phase [*], NO..
|
wneuper@59292
|
925 |
..NO: raises errors not tracable on WN110513 [**] *)
|
wneuper@59292
|
926 |
branch: branch, (* like PrfObj *)
|
wneuper@59292
|
927 |
result: result, (* like PrfObj *)
|
wneuper@59292
|
928 |
ostate: ostate}; (* like PrfObj *)
|
wneuper@59292
|
929 |
|
wneuper@59292
|
930 |
(* this tree contains isac's calculations;
|
wneuper@59292
|
931 |
the tree's structure has been copied from an early version of Theorema(c);
|
wneuper@59292
|
932 |
it has the disadvantage, that there is no space
|
wneuper@59292
|
933 |
for the first tactic in a script generating the first formula at (p,Frm);
|
wneuper@59292
|
934 |
this trouble has been covered by 'init_form' and 'Take' so far,
|
wneuper@59292
|
935 |
but it is crucial if the first tactic in a script is eg. 'Subproblem';
|
wneuper@59292
|
936 |
see 'type tac', Apply_Method.
|
wneuper@59292
|
937 |
*)
|
wneuper@59292
|
938 |
datatype ctree =
|
wneuper@59292
|
939 |
EmptyPtree
|
wneuper@59292
|
940 |
| Nd of ppobj * (ctree list);
|
wneuper@59292
|
941 |
val e_ctree = EmptyPtree;
|
wneuper@59292
|
942 |
type state = ctree * pos'
|
wneuper@59292
|
943 |
|
wneuper@59292
|
944 |
fun is_pblobj (PblObj _) = true
|
wneuper@59292
|
945 |
| is_pblobj _ = false;
|
wneuper@59292
|
946 |
|
wneuper@59292
|
947 |
exception PTREE of string;
|
wneuper@59292
|
948 |
fun nth _ [] = raise PTREE "nth _ []"
|
wneuper@59292
|
949 |
| nth 1 (x :: _) = x
|
wneuper@59292
|
950 |
| nth n (_ :: xs) = nth (n - 1) xs;
|
wneuper@59292
|
951 |
(*> nth 2 [11,22,33]; -->> val it = 22 : int*)
|
wneuper@59292
|
952 |
|
wneuper@59292
|
953 |
|
wneuper@59292
|
954 |
(** convert ctree to a string **)
|
wneuper@59292
|
955 |
|
wneuper@59292
|
956 |
(* convert a pos from list to string *)
|
wneuper@59292
|
957 |
fun pr_pos ps = (space_implode "." (map string_of_int ps))^". ";
|
wneuper@59292
|
958 |
(* show hd origin or form only *)
|
wneuper@59292
|
959 |
fun pr_short p (PblObj _) = pr_pos p ^ " ----- pblobj -----\n" (* for tests only *)
|
wneuper@59292
|
960 |
| pr_short p (PrfObj {form = form, ...}) = pr_pos p ^ term2str form ^ "\n";
|
wneuper@59292
|
961 |
fun pr_ctree f pt = (* for tests only *)
|
wneuper@59292
|
962 |
let
|
wneuper@59292
|
963 |
fun pr_pt _ _ EmptyPtree = ""
|
wneuper@59292
|
964 |
| pr_pt pfn ps (Nd (b, [])) = pfn ps b
|
wneuper@59292
|
965 |
| pr_pt pfn ps (Nd (b, ts)) = pfn ps b ^ prts pfn ps 1 ts
|
wneuper@59292
|
966 |
and prts _ _ _ [] = ""
|
wneuper@59292
|
967 |
| prts pfn ps p (t :: ts) = (pr_pt pfn (ps @ [p]) t)^
|
wneuper@59292
|
968 |
(prts pfn ps (p + 1) ts)
|
wneuper@59292
|
969 |
in pr_pt f [] pt end;
|
wneuper@59292
|
970 |
|
wneuper@59292
|
971 |
(** access the branches of ctree **)
|
wneuper@59292
|
972 |
|
wneuper@59292
|
973 |
fun repl [] _ _ = raise PTREE "repl [] _ _"
|
wneuper@59292
|
974 |
| repl (_ :: ls) 1 e = e :: ls
|
wneuper@59292
|
975 |
| repl (l :: ls) n e = l :: (repl ls (n-1) e);
|
wneuper@59292
|
976 |
fun repl_app ls n e =
|
wneuper@59292
|
977 |
let
|
wneuper@59292
|
978 |
val lim = 1 + length ls
|
wneuper@59292
|
979 |
in
|
wneuper@59292
|
980 |
if n > lim
|
wneuper@59292
|
981 |
then raise PTREE "repl_app: n > lim"
|
wneuper@59292
|
982 |
else if n = lim
|
wneuper@59292
|
983 |
then ls @ [e]
|
wneuper@59292
|
984 |
else repl ls n e end;
|
wneuper@59292
|
985 |
|
wneuper@59292
|
986 |
(* get from obj at pos by f : ppobj -> 'a *)
|
wneuper@59292
|
987 |
fun get_obj _ EmptyPtree _ = raise PTREE "get_obj f EmptyPtree"
|
wneuper@59292
|
988 |
| get_obj f (Nd (b, _)) [] = f b
|
wneuper@59292
|
989 |
| get_obj f (Nd (_, bs)) (p :: ps) =
|
wneuper@59292
|
990 |
let
|
wneuper@59292
|
991 |
val _ = (nth p bs)
|
wneuper@59292
|
992 |
handle _ => raise PTREE ("get_obj: pos = " ^ ints2str' (p::ps) ^ " does not exist");
|
wneuper@59292
|
993 |
in
|
wneuper@59292
|
994 |
(get_obj f (nth p bs) ps)
|
wneuper@59292
|
995 |
handle _ => raise PTREE ("get_obj: pos = " ^ ints2str' (p::ps) ^ " does not exist")
|
wneuper@59292
|
996 |
end;
|
wneuper@59292
|
997 |
fun get_nd EmptyPtree _ = raise PTREE "get_nd EmptyPtree"
|
wneuper@59292
|
998 |
| get_nd n [] = n
|
wneuper@59292
|
999 |
| get_nd (Nd (_, nds)) (pos as p :: ps) = (get_nd (nth p nds) ps)
|
wneuper@59292
|
1000 |
handle _ => raise PTREE ("get_nd: not existent pos = " ^ ints2str' pos);
|
wneuper@59292
|
1001 |
|
wneuper@59292
|
1002 |
(* for use by get_obj *)
|
wneuper@59292
|
1003 |
fun g_form (PrfObj {form = f,...}) = f
|
wneuper@59292
|
1004 |
| g_form (PblObj {origin= (_,_,f),...}) = f;
|
wneuper@59292
|
1005 |
fun g_form' (Nd (PrfObj {form = f, ...}, _)) = f
|
wneuper@59292
|
1006 |
| g_form' (Nd (PblObj {origin= (_, _, f),...}, _)) = f
|
wneuper@59292
|
1007 |
| g_form' _ = error "g_form': uncovered fun def.";
|
wneuper@59292
|
1008 |
(* | g_form _ = raise PTREE "g_form not for PblObj";*)
|
wneuper@59292
|
1009 |
fun g_origin (PblObj {origin = ori, ...}) = ori
|
wneuper@59292
|
1010 |
| g_origin _ = raise PTREE "g_origin not for PrfObj";
|
wneuper@59292
|
1011 |
fun g_fmz (PblObj {fmz = f, ...}) = f (* for tests only *)
|
wneuper@59292
|
1012 |
| g_fmz _ = raise PTREE "g_fmz not for PrfObj";
|
wneuper@59292
|
1013 |
fun g_spec (PblObj {spec = s, ...}) = s
|
wneuper@59292
|
1014 |
| g_spec _ = raise PTREE "g_spec not for PrfObj";
|
wneuper@59292
|
1015 |
fun g_pbl (PblObj {probl = p, ...}) = p
|
wneuper@59292
|
1016 |
| g_pbl _ = raise PTREE "g_pbl not for PrfObj";
|
wneuper@59292
|
1017 |
fun g_met (PblObj {meth = p, ...}) = p
|
wneuper@59292
|
1018 |
| g_met _ = raise PTREE "g_met not for PrfObj";
|
wneuper@59292
|
1019 |
fun g_domID (PblObj {spec = (d, _, _), ...}) = d
|
wneuper@59292
|
1020 |
| g_domID _ = raise PTREE "g_metID not for PrfObj";
|
wneuper@59292
|
1021 |
fun g_metID (PblObj {spec = (_, _, m), ...}) = m
|
wneuper@59292
|
1022 |
| g_metID _ = raise PTREE "g_metID not for PrfObj";
|
wneuper@59292
|
1023 |
fun g_ctxt (PblObj {ctxt, ...}) = ctxt
|
wneuper@59292
|
1024 |
| g_ctxt _ = raise PTREE "g_ctxt not for PrfObj";
|
wneuper@59292
|
1025 |
fun g_env (PblObj {env, ...}) = env
|
wneuper@59292
|
1026 |
| g_env _ = raise PTREE "g_env not for PrfObj";
|
wneuper@59292
|
1027 |
fun g_loc (PblObj {loc = l, ...}) = l
|
wneuper@59292
|
1028 |
| g_loc (PrfObj {loc = l, ...}) = l;
|
wneuper@59292
|
1029 |
fun g_branch (PblObj {branch = b, ...}) = b
|
wneuper@59292
|
1030 |
| g_branch (PrfObj {branch = b, ...}) = b;
|
wneuper@59292
|
1031 |
fun g_tac (PblObj {spec = (_, _, m),...}) = Apply_Method m
|
wneuper@59292
|
1032 |
| g_tac (PrfObj {tac = m, ...}) = m;
|
wneuper@59292
|
1033 |
fun g_result (PblObj {result = r, ...}) = r
|
wneuper@59292
|
1034 |
| g_result (PrfObj {result = r, ...}) = r;
|
wneuper@59292
|
1035 |
fun g_res (PblObj {result = (r, _) ,...}) = r
|
wneuper@59292
|
1036 |
| g_res (PrfObj {result = (r,_),...}) = r;
|
wneuper@59292
|
1037 |
fun g_res' (Nd (PblObj {result = (r, _), ...}, _)) = r
|
wneuper@59292
|
1038 |
| g_res' (Nd (PrfObj {result = (r, _),...}, _)) = r
|
wneuper@59292
|
1039 |
| g_res' _ = raise PTREE "g_res': uncovered fun def.";
|
wneuper@59292
|
1040 |
fun g_ostate (PblObj {ostate = r, ...}) = r
|
wneuper@59292
|
1041 |
| g_ostate (PrfObj {ostate = r, ...}) = r;
|
wneuper@59292
|
1042 |
fun g_ostate' (Nd (PblObj {ostate = r, ...}, _)) = r
|
wneuper@59292
|
1043 |
| g_ostate' (Nd (PrfObj {ostate = r, ...}, _)) = r
|
wneuper@59292
|
1044 |
| g_ostate' _ = raise PTREE "g_ostate': uncovered fun def.";
|
wneuper@59292
|
1045 |
|
wneuper@59292
|
1046 |
(* get the formula preceeding the current position in a calculation *)
|
wneuper@59292
|
1047 |
fun get_curr_formula (pt, (p, p_)) =
|
wneuper@59292
|
1048 |
case p_ of
|
wneuper@59292
|
1049 |
Frm => get_obj g_form pt p
|
wneuper@59292
|
1050 |
| Res => (fst o (get_obj g_result pt)) p
|
wneuper@59292
|
1051 |
| _ => #3 (get_obj g_origin pt p);
|
wneuper@59292
|
1052 |
|
wneuper@59292
|
1053 |
(* in CalcTree/Subproblem an 'just_created_' model is created;
|
wneuper@59292
|
1054 |
this is filled to 'untouched' by Model/Refine_Problem *)
|
wneuper@59292
|
1055 |
fun just_created_ (PblObj {meth, probl, spec, ...}) =
|
wneuper@59292
|
1056 |
null meth andalso null probl andalso spec = e_spec
|
wneuper@59292
|
1057 |
| just_created_ _ = raise PTREE "g_ostate': uncovered fun def.";
|
wneuper@59292
|
1058 |
val e_origin = ([],e_spec,e_term);
|
wneuper@59292
|
1059 |
|
wneuper@59292
|
1060 |
fun just_created (pt, (p, _)) =
|
wneuper@59292
|
1061 |
let val ppobj = get_obj I pt p
|
wneuper@59292
|
1062 |
in is_pblobj ppobj andalso just_created_ ppobj end;
|
wneuper@59292
|
1063 |
|
wneuper@59292
|
1064 |
(* does the pos in the ctree exist ? *)
|
wneuper@59292
|
1065 |
fun existpt pos pt = can (get_obj I pt) pos;
|
wneuper@59292
|
1066 |
(* does the pos' in the ctree exist, ie. extra check for result in the node *)
|
wneuper@59292
|
1067 |
fun existpt' (p,p_) pt =
|
wneuper@59292
|
1068 |
if can (get_obj I pt) p
|
wneuper@59292
|
1069 |
then case p_ of
|
wneuper@59292
|
1070 |
Res => get_obj g_ostate pt p = Complete
|
wneuper@59292
|
1071 |
| _ => true
|
wneuper@59292
|
1072 |
else false;
|
wneuper@59292
|
1073 |
|
wneuper@59292
|
1074 |
(* is this position appropriate for calculating intermediate steps? *)
|
wneuper@59292
|
1075 |
fun is_interpos (_, Res) = true
|
wneuper@59292
|
1076 |
| is_interpos _ = false;
|
wneuper@59292
|
1077 |
|
wneuper@59296
|
1078 |
(* get the children of a node in ctree *)
|
wneuper@59296
|
1079 |
fun children (Nd (PblObj _, cn)) = cn
|
wneuper@59296
|
1080 |
| children (Nd (PrfObj _, cn)) = cn
|
wneuper@59296
|
1081 |
| children _ = error "children: uncovered fun def.";
|
wneuper@59292
|
1082 |
|
wneuper@59296
|
1083 |
(*/--------------- duplicates in ctree-navi.sml: required also here below ---------------\*)
|
wneuper@59296
|
1084 |
fun lev_on [] = raise PTREE "lev_on []"
|
wneuper@59296
|
1085 |
| lev_on pos =
|
wneuper@59296
|
1086 |
let val len = length pos
|
wneuper@59296
|
1087 |
in (drop_last pos) @ [(nth len pos)+1] end;
|
wneuper@59296
|
1088 |
fun lev_up [] = raise PTREE "lev_up []"
|
wneuper@59296
|
1089 |
| lev_up p = (drop_last p):pos;
|
wneuper@59292
|
1090 |
(* find the position of the next parent which is a PblObj in ctree *)
|
wneuper@59292
|
1091 |
fun par_pblobj _ [] = []
|
wneuper@59292
|
1092 |
| par_pblobj pt p =
|
wneuper@59292
|
1093 |
let
|
wneuper@59292
|
1094 |
fun par _ [] = []
|
wneuper@59292
|
1095 |
| par pt p =
|
wneuper@59292
|
1096 |
if is_pblobj (get_obj I pt p)
|
wneuper@59292
|
1097 |
then p
|
wneuper@59292
|
1098 |
else par pt (lev_up p)
|
wneuper@59292
|
1099 |
in par pt (lev_up p) end;
|
wneuper@59296
|
1100 |
(*\--------------- duplicates in ctree-navi.sml: required also here below ---------------/*)
|
wneuper@59292
|
1101 |
|
wneuper@59292
|
1102 |
(* find the next parent, which is either a PblObj (return true)
|
wneuper@59292
|
1103 |
or a PrfObj with tac = Detail_Set (return false)
|
wneuper@59292
|
1104 |
FIXME.030403: re-organize par_pbl_det after rls' --> rls*)
|
wneuper@59292
|
1105 |
fun par_pbl_det pt [] = (true, [], Erls)
|
wneuper@59292
|
1106 |
| par_pbl_det pt p =
|
wneuper@59292
|
1107 |
let
|
wneuper@59292
|
1108 |
fun par _ [] = (true, [], Erls)
|
wneuper@59292
|
1109 |
| par pt p =
|
wneuper@59292
|
1110 |
if is_pblobj (get_obj I pt p)
|
wneuper@59292
|
1111 |
then (true, p, Erls)
|
wneuper@59292
|
1112 |
else case get_obj g_tac pt p of
|
wneuper@59292
|
1113 |
Rewrite_Set rls' => (false, p, assoc_rls rls')
|
wneuper@59292
|
1114 |
| Rewrite_Set_Inst (_, rls') => (false, p, assoc_rls rls')
|
wneuper@59292
|
1115 |
| _ => par pt (lev_up p)
|
wneuper@59292
|
1116 |
in par pt (lev_up p) end;
|
wneuper@59292
|
1117 |
|
wneuper@59292
|
1118 |
(* insert obj b into ctree at pos, ev.overwriting this pos *)
|
wneuper@59292
|
1119 |
fun insert_pt b EmptyPtree [] = Nd (b, [])
|
wneuper@59292
|
1120 |
| insert_pt _ EmptyPtree _ = raise PTREE "insert_pt b Empty _"
|
wneuper@59292
|
1121 |
| insert_pt _ (Nd ( _, _)) [] = raise PTREE "insert_pt b _ []"
|
wneuper@59292
|
1122 |
| insert_pt b (Nd (b', bs)) (p :: []) = Nd (b', repl_app bs p (Nd (b, [])))
|
wneuper@59292
|
1123 |
| insert_pt b (Nd (b', bs)) (p :: ps) = Nd (b', repl_app bs p (insert_pt b (nth p bs) ps));
|
wneuper@59292
|
1124 |
|
wneuper@59292
|
1125 |
(* insert children to a node without children. compare: fun insert_pt *)
|
wneuper@59292
|
1126 |
fun ins_chn _ EmptyPtree _ = raise PTREE "ins_chn: EmptyPtree"
|
wneuper@59292
|
1127 |
| ins_chn _ (Nd _) [] = raise PTREE "ins_chn: pos = []"
|
wneuper@59292
|
1128 |
| ins_chn ns (Nd (b, bs)) (p :: []) =
|
wneuper@59292
|
1129 |
if p > length bs
|
wneuper@59292
|
1130 |
then raise PTREE "ins_chn: pos not existent"
|
wneuper@59292
|
1131 |
else
|
wneuper@59292
|
1132 |
let
|
wneuper@59292
|
1133 |
val (b', bs') = case nth p bs of
|
wneuper@59292
|
1134 |
Nd (b', bs') => (b', bs')
|
wneuper@59292
|
1135 |
| _ => error "ins_chn: uncovered case nth"
|
wneuper@59292
|
1136 |
in
|
wneuper@59292
|
1137 |
if null bs'
|
wneuper@59292
|
1138 |
then Nd (b, repl_app bs p (Nd (b', ns)))
|
wneuper@59292
|
1139 |
else raise PTREE "ins_chn: pos mustNOT be overwritten"
|
wneuper@59292
|
1140 |
end
|
wneuper@59292
|
1141 |
| ins_chn ns (Nd (b, bs)) (p::ps) = Nd (b, repl_app bs p (ins_chn ns (nth p bs) ps));
|
wneuper@59292
|
1142 |
|
wneuper@59292
|
1143 |
(* apply f to obj at pos, f: ppobj -> ppobj *)
|
wneuper@59292
|
1144 |
fun appl_to_node f (Nd (b, bs)) = Nd (f b, bs)
|
wneuper@59292
|
1145 |
| appl_to_node _ _ = error "appl_to_node: uncovered fun def.";
|
wneuper@59292
|
1146 |
fun appl_obj _ EmptyPtree [] = EmptyPtree
|
wneuper@59292
|
1147 |
| appl_obj _ EmptyPtree _ = raise PTREE "appl_obj f Empty _"
|
wneuper@59292
|
1148 |
| appl_obj f (Nd (b, bs)) [] = Nd (f b, bs)
|
wneuper@59292
|
1149 |
| appl_obj f (Nd (b, bs)) (p :: []) = Nd (b, repl_app bs p (((appl_to_node f) o (nth p)) bs))
|
wneuper@59292
|
1150 |
| appl_obj f (Nd (b, bs)) (p :: ps) = Nd (b, repl_app bs p (appl_obj f (nth p bs) (ps:pos)));
|
wneuper@59292
|
1151 |
|
wneuper@59292
|
1152 |
|
wneuper@59292
|
1153 |
type ocalhd =
|
wneuper@59292
|
1154 |
bool * (* ALL itms+preconds true *)
|
wneuper@59292
|
1155 |
pos_ * (* model belongs to Problem | Method *)
|
wneuper@59292
|
1156 |
term * (* header: Problem... or Cas FIXME.0312: item for marking syntaxerrors *)
|
wneuper@59292
|
1157 |
itm list * (* model: given, find, relate *)
|
wneuper@59292
|
1158 |
((bool * term) list) *(* model: preconds *)
|
wneuper@59292
|
1159 |
spec; (* specification *)
|
wneuper@59292
|
1160 |
val e_ocalhd = (false, Und, e_term, [e_itm], [(false, e_term)], e_spec);
|
wneuper@59292
|
1161 |
|
wneuper@59292
|
1162 |
datatype ptform = Form of term | ModSpec of ocalhd;
|
wneuper@59292
|
1163 |
|
wneuper@59292
|
1164 |
(* for cut_level; (deprecated) *)
|
wneuper@59292
|
1165 |
fun test_trans (PrfObj {branch, ...}) = true andalso branch = TransitiveB
|
wneuper@59292
|
1166 |
| test_trans (PblObj {branch, ...}) = true andalso branch = TransitiveB;
|
wneuper@59292
|
1167 |
|
wneuper@59292
|
1168 |
fun is_pblobj' pt p =
|
wneuper@59292
|
1169 |
let val ppobj = get_obj I pt p
|
wneuper@59292
|
1170 |
in is_pblobj ppobj end;
|
wneuper@59292
|
1171 |
|
wneuper@59292
|
1172 |
fun del_res (PblObj {cell, fmz, origin, spec, probl, meth, ctxt, env, loc= (l1, _), branch, ...}) =
|
wneuper@59292
|
1173 |
PblObj {cell = cell, fmz = fmz, origin = origin, spec = spec, probl = probl, meth = meth,
|
wneuper@59292
|
1174 |
ctxt = ctxt, env = env, loc= (l1, NONE), branch = branch,
|
wneuper@59292
|
1175 |
result = (e_term, []), ostate = Incomplete}
|
wneuper@59292
|
1176 |
| del_res (PrfObj {cell, form, tac, loc= (l1, _), branch, ...}) =
|
wneuper@59292
|
1177 |
PrfObj {cell = cell, form = form, tac = tac, loc = (l1, NONE), branch = branch,
|
wneuper@59292
|
1178 |
result = (e_term, []), ostate = Incomplete};
|
wneuper@59292
|
1179 |
|
wneuper@59292
|
1180 |
|
wneuper@59292
|
1181 |
fun get_loc EmptyPtree _ = (e_istate, e_ctxt)
|
wneuper@59292
|
1182 |
| get_loc pt (p, Res) =
|
wneuper@59292
|
1183 |
(case get_obj g_loc pt p of
|
wneuper@59292
|
1184 |
(SOME i, NONE) => i
|
wneuper@59292
|
1185 |
| (NONE , NONE) => (e_istate, e_ctxt)
|
wneuper@59292
|
1186 |
| (_ , SOME i) => i)
|
wneuper@59292
|
1187 |
| get_loc pt (p, _) =
|
wneuper@59292
|
1188 |
(case get_obj g_loc pt p of
|
wneuper@59292
|
1189 |
(NONE , SOME i) => i (*13.8.02 just copied from ^^^: too liberal ?*)
|
wneuper@59292
|
1190 |
| (NONE , NONE) => (e_istate, e_ctxt)
|
wneuper@59292
|
1191 |
| (SOME i, _) => i);
|
wneuper@59292
|
1192 |
fun get_istate pt p = get_loc pt p |> #1;
|
wneuper@59292
|
1193 |
fun get_ctxt pt (pos as (p, p_)) =
|
wneuper@59292
|
1194 |
if member op = [Frm, Res] p_
|
wneuper@59292
|
1195 |
then get_loc pt pos |> #2 (*for script interpretation rely on fun get_loc*)
|
wneuper@59292
|
1196 |
else get_obj g_ctxt pt p (*for specify phase take ctx from PblObj*)
|
wneuper@59292
|
1197 |
|
wneuper@59292
|
1198 |
fun get_assumptions_ pt p = get_ctxt pt p |> get_assumptions;
|
wneuper@59292
|
1199 |
|
wneuper@59292
|
1200 |
fun get_somespec' (dI, pI, mI) (dI', pI', mI') =
|
wneuper@59292
|
1201 |
let
|
wneuper@59292
|
1202 |
val domID = if dI = e_domID then dI' else dI
|
wneuper@59292
|
1203 |
val pblID = if pI = e_pblID then pI' else pI
|
wneuper@59292
|
1204 |
val metID = if mI = e_metID then mI' else mI
|
wneuper@59292
|
1205 |
in (domID, pblID, metID) end;
|
wneuper@59292
|
1206 |
|
wneuper@59292
|
1207 |
(**.development for extracting an 'interval' from ptree.**)
|
wneuper@59292
|
1208 |
|
wneuper@59292
|
1209 |
(*WN0510 version stopped in favour of get_interval with !!!move_dn, getFormulaeFromTo
|
wneuper@59292
|
1210 |
actually used (inefficient) version with move_dn: see modspec.sml*)
|
wneuper@59292
|
1211 |
local
|
wneuper@59292
|
1212 |
|
wneuper@59292
|
1213 |
fun hdp [] = 1 | hdp [0] = 1 | hdp x = hd x;(*start with first*)
|
wneuper@59292
|
1214 |
fun hdq [] = 99999 | hdq [0] = 99999 | hdq x = hd x;(*take until last*)
|
wneuper@59292
|
1215 |
fun tlp [] = [0] | tlp [_] = [0] | tlp x = tl x;
|
wneuper@59292
|
1216 |
fun tlq [] = [99999] | tlq [_] = [99999] | tlq x = tl x;
|
wneuper@59292
|
1217 |
|
wneuper@59292
|
1218 |
fun getnd i (b,p) q (Nd (po, nds)) =
|
wneuper@59292
|
1219 |
(if i <= 0 then [[b]] else []) @
|
wneuper@59292
|
1220 |
(getnds (i-1) true (b@[hdp p], tlp p) (tlq q)
|
wneuper@59292
|
1221 |
(take_fromto (hdp p) (hdq q) nds))
|
wneuper@59292
|
1222 |
|
wneuper@59292
|
1223 |
and getnds _ _ _ _ [] = [] (*no children*)
|
wneuper@59292
|
1224 |
| getnds i _ (b,p) q [nd] = (getnd i (b,p) q nd) (*l+r-margin*)
|
wneuper@59292
|
1225 |
|
wneuper@59292
|
1226 |
| getnds i true (b,p) q [n1, n2] = (*l-margin, r-margin*)
|
wneuper@59292
|
1227 |
(getnd i ( b, p ) [99999] n1) @
|
wneuper@59292
|
1228 |
(getnd ~99999 (lev_on b,[0]) q n2)
|
wneuper@59292
|
1229 |
|
wneuper@59292
|
1230 |
| getnds i _ (b,p) q [n1, n2] = (*intern, r-margin*)
|
wneuper@59292
|
1231 |
(getnd i ( b,[0]) [99999] n1) @
|
wneuper@59292
|
1232 |
(getnd ~99999 (lev_on b,[0]) q n2)
|
wneuper@59292
|
1233 |
|
wneuper@59292
|
1234 |
| getnds i true (b,p) q (nd::(nds as _::_)) = (*l-margin, intern*)
|
wneuper@59292
|
1235 |
(getnd i ( b, p ) [99999] nd) @
|
wneuper@59292
|
1236 |
(getnds ~99999 false (lev_on b,[0]) q nds)
|
wneuper@59292
|
1237 |
|
wneuper@59292
|
1238 |
| getnds i _ (b,p) q (nd::(nds as _::_)) = (*intern, ...*)
|
wneuper@59292
|
1239 |
(getnd i ( b,[0]) [99999] nd) @
|
wneuper@59292
|
1240 |
(getnds ~99999 false (lev_on b,[0]) q nds);
|
wneuper@59292
|
1241 |
in
|
wneuper@59292
|
1242 |
(*get an 'interval from to' from a ptree as 'intervals f t' of respective nodes
|
wneuper@59292
|
1243 |
where 'from' are pos, i.e. a key as int list, 'f' an int (to,t analoguous)
|
wneuper@59292
|
1244 |
(1) the 'f' are given
|
wneuper@59292
|
1245 |
(1a) by 'from' if 'f' = the respective element of 'from' (left margin)
|
wneuper@59292
|
1246 |
(1b) -inifinity, if 'f' > the respective element of 'from' (internal node)
|
wneuper@59292
|
1247 |
(2) the 't' ar given
|
wneuper@59292
|
1248 |
(2a) by 'to' if 't' = the respective element of 'to' (right margin)
|
wneuper@59292
|
1249 |
(2b) inifinity, if 't' < the respective element of 'to (internal node)'
|
wneuper@59292
|
1250 |
the 'f' and 't' are set by hdp,... *)
|
wneuper@59292
|
1251 |
fun get_trace pt p q =
|
wneuper@59292
|
1252 |
(flat o (getnds ((length p) -1) true ([hdp p], tlp p) (tlq q)))
|
wneuper@59292
|
1253 |
(take_fromto (hdp p) (hdq q) (children pt));
|
wneuper@59292
|
1254 |
end;
|
wneuper@59292
|
1255 |
|
wneuper@59292
|
1256 |
(*extract a formula or model from ctree for itms2itemppc or model2xml*)
|
wneuper@59292
|
1257 |
fun preconds2str bts =
|
wneuper@59292
|
1258 |
(strs2str o (map (linefeed o pair2str o
|
wneuper@59292
|
1259 |
(apsnd term2str) o
|
wneuper@59292
|
1260 |
(apfst bool2str)))) bts;
|
wneuper@59292
|
1261 |
fun ocalhd2str (b, p, hdf, itms, prec, spec) = (* for tests only *)
|
wneuper@59292
|
1262 |
"(" ^ bool2str b ^ ", " ^ pos_2str p ^ ", " ^ term2str hdf ^
|
wneuper@59292
|
1263 |
", " ^ itms2str_ (thy2ctxt' "Isac") itms ^
|
wneuper@59292
|
1264 |
", " ^ preconds2str prec ^ ", \n" ^ spec2str spec ^ " )";
|
wneuper@59292
|
1265 |
|
wneuper@59292
|
1266 |
fun is_pblnd (Nd (ppobj, _)) = is_pblobj ppobj
|
wneuper@59292
|
1267 |
| is_pblnd _ = error "is_pblnd: uncovered fun def.";
|
wneuper@59292
|
1268 |
|
wneuper@59292
|
1269 |
|
wneuper@59292
|
1270 |
(* determine the previous pos' on the same level
|
wneuper@59292
|
1271 |
WN0502 made for interSteps; _only_ works for branch TransitiveB WN120517 compare lev_back *)
|
wneuper@59292
|
1272 |
fun lev_pred' _ ([], Res) = ([], Pbl)
|
wneuper@59292
|
1273 |
| lev_pred' pt (p, Res) =
|
wneuper@59292
|
1274 |
let val (p', last) = split_last p
|
wneuper@59292
|
1275 |
in
|
wneuper@59292
|
1276 |
if last = 1
|
wneuper@59292
|
1277 |
then if (is_pblobj o (get_obj I pt)) p then (p, Pbl) else (p, Frm)
|
wneuper@59292
|
1278 |
else if get_obj g_res pt (p' @ [last - 1]) = get_obj g_form pt p
|
wneuper@59292
|
1279 |
then (p' @ [last - 1], Res) (* TransitiveB *)
|
wneuper@59292
|
1280 |
else if (is_pblobj o (get_obj I pt)) p then (p,Pbl) else (p, Frm)
|
wneuper@59292
|
1281 |
end
|
wneuper@59292
|
1282 |
| lev_pred' _ _ = error "";
|
wneuper@59292
|
1283 |
|
wneuper@59292
|
1284 |
|
wneuper@59292
|
1285 |
(**.insert into ctree and cut branches accordingly.**)
|
wneuper@59292
|
1286 |
|
wneuper@59292
|
1287 |
(* get all positions of certain intervals on the ctree.
|
wneuper@59292
|
1288 |
OLD VERSION without move_dn; kept for occasional redesign
|
wneuper@59292
|
1289 |
get all pos's to be cut in a ctree
|
wneuper@59292
|
1290 |
below a pos or from a ctree list after i-th element (NO level_up) *)
|
wneuper@59292
|
1291 |
fun get_allpos' (_, _) EmptyPtree = []
|
wneuper@59292
|
1292 |
| get_allpos' (p, 1) (Nd (b, bs)) = (* p is pos of Nd *)
|
wneuper@59292
|
1293 |
if g_ostate b = Incomplete
|
wneuper@59292
|
1294 |
then (p, Frm) :: (get_allpos's (p, 1) bs)
|
wneuper@59292
|
1295 |
else (p, Frm) :: (get_allpos's (p, 1) bs) @ [(p, Res)]
|
wneuper@59292
|
1296 |
| get_allpos' (p, i) (Nd (b, bs)) = (* p is pos of Nd *)
|
wneuper@59292
|
1297 |
if length bs > 0 orelse is_pblobj b
|
wneuper@59292
|
1298 |
then if g_ostate b = Incomplete
|
wneuper@59292
|
1299 |
then [(p,Frm)] @ (get_allpos's (p, 1) bs)
|
wneuper@59292
|
1300 |
else [(p,Frm)] @ (get_allpos's (p, 1) bs) @ [(p, Res)]
|
wneuper@59292
|
1301 |
else if g_ostate b = Incomplete then [] else [(p, Res)]
|
wneuper@59292
|
1302 |
and get_allpos's _ [] = []
|
wneuper@59292
|
1303 |
| get_allpos's (p, i) (pt :: pts) = (* p is pos of parent-Nd *)
|
wneuper@59292
|
1304 |
(get_allpos' (p @ [i], i) pt) @ (get_allpos's (p, i + 1) pts);
|
wneuper@59292
|
1305 |
|
wneuper@59292
|
1306 |
(*WN050106 like cut_level, but deletes exactly 1 node *)
|
wneuper@59292
|
1307 |
fun cut_level_'_ _ _ EmptyPtree _ =raise PTREE "cut_level_'_ Empty _" (* for tests ONLY *)
|
wneuper@59292
|
1308 |
| cut_level_'_ _ _ (Nd ( _, _)) ([], _) = raise PTREE "cut_level_'_ _ []"
|
wneuper@59292
|
1309 |
| cut_level_'_ cuts P (Nd (b, bs)) (p :: [], p_) =
|
wneuper@59292
|
1310 |
if test_trans b
|
wneuper@59292
|
1311 |
then
|
wneuper@59292
|
1312 |
(Nd (b, drop_nth [] (p:posel, bs)),
|
wneuper@59292
|
1313 |
cuts @ (if p_ = Frm then [(P @ [p], Res)] else []) @
|
wneuper@59292
|
1314 |
(get_allpos's (P, p + 1) (drop_nth [] (p, bs))))
|
wneuper@59292
|
1315 |
else (Nd (b, bs), cuts)
|
wneuper@59292
|
1316 |
| cut_level_'_ cuts P (Nd (b, bs)) ((p :: ps), p_) =
|
wneuper@59292
|
1317 |
let
|
wneuper@59292
|
1318 |
val (bs', cuts') = cut_level_'_ cuts P (nth p bs) (ps, p_)
|
wneuper@59292
|
1319 |
in (Nd (b, repl_app bs p bs'), cuts @ cuts') end;
|
wneuper@59292
|
1320 |
|
wneuper@59292
|
1321 |
fun cut_level _ _ EmptyPtree _ = raise PTREE "cut_level EmptyPtree _"
|
wneuper@59292
|
1322 |
| cut_level _ _ (Nd ( _, _)) ([],_) = raise PTREE "cut_level _ []"
|
wneuper@59292
|
1323 |
| cut_level cuts P (Nd (b, bs)) (p :: [], p_) =
|
wneuper@59292
|
1324 |
if test_trans b
|
wneuper@59292
|
1325 |
then
|
wneuper@59292
|
1326 |
(Nd (b, take (p:posel, bs)),
|
wneuper@59292
|
1327 |
cuts @
|
wneuper@59292
|
1328 |
(if p_ = Frm andalso (*#*) g_ostate b = Complete then [(P@[p],Res)] else ([]:pos' list)) @
|
wneuper@59292
|
1329 |
(get_allpos's (P, p+1) (takerest (p, bs))))
|
wneuper@59292
|
1330 |
else (Nd (b, bs), cuts)
|
wneuper@59292
|
1331 |
| cut_level cuts P (Nd (b, bs)) ((p :: ps), p_) =
|
wneuper@59292
|
1332 |
let
|
wneuper@59292
|
1333 |
val (bs', cuts') = cut_level cuts P (nth p bs) (ps, p_)
|
wneuper@59292
|
1334 |
in (Nd (b, repl_app bs p bs'), cuts @ cuts') end;
|
wneuper@59292
|
1335 |
|
wneuper@59292
|
1336 |
(*OLD version before WN050219, overwritten below*)
|
wneuper@59292
|
1337 |
fun cut_tree _ ([], _) = raise PTREE "cut_tree _ ([],_)" (* for test only *)
|
wneuper@59292
|
1338 |
| cut_tree pt (pos as ([_], _)) =
|
wneuper@59292
|
1339 |
let
|
wneuper@59292
|
1340 |
val (pt', cuts) = cut_level [] [] pt pos
|
wneuper@59292
|
1341 |
in
|
wneuper@59292
|
1342 |
(pt', cuts @ (if get_obj g_ostate pt [] = Incomplete then [] else [([], Res)]))
|
wneuper@59292
|
1343 |
end
|
wneuper@59292
|
1344 |
| cut_tree pt (p,p_) =
|
wneuper@59292
|
1345 |
let
|
wneuper@59292
|
1346 |
fun cutfn pt cuts (p, p_) =
|
wneuper@59292
|
1347 |
let
|
wneuper@59292
|
1348 |
val (pt', cuts') = cut_level [] (lev_up p) pt (p,p_)
|
wneuper@59292
|
1349 |
in
|
wneuper@59292
|
1350 |
if length cuts' > 0 andalso length p > 1
|
wneuper@59292
|
1351 |
then cutfn pt' (cuts @ cuts') (lev_up p, Frm(*-->(p,Res)*))
|
wneuper@59292
|
1352 |
else (pt', cuts @ cuts')
|
wneuper@59292
|
1353 |
end
|
wneuper@59292
|
1354 |
val (pt', cuts) = cutfn pt [] (p, p_)
|
wneuper@59292
|
1355 |
in
|
wneuper@59292
|
1356 |
(pt', cuts @ (if get_obj g_ostate pt [] = Incomplete then [] else [([], Res)]))
|
wneuper@59292
|
1357 |
end;
|
wneuper@59292
|
1358 |
|
wneuper@59296
|
1359 |
local
|
wneuper@59296
|
1360 |
fun move_dn _ (Nd (_, ns)) ([],p_) = (* root problem *)
|
wneuper@59296
|
1361 |
(case p_ of
|
wneuper@59296
|
1362 |
Res => raise PTREE "move_dn: end of calculation"
|
wneuper@59296
|
1363 |
| _ =>
|
wneuper@59296
|
1364 |
if null ns (* go down from Pbl + Met *)
|
wneuper@59296
|
1365 |
then raise PTREE "move_dn: solve problem not started"
|
wneuper@59296
|
1366 |
else ([1], Frm))
|
wneuper@59296
|
1367 |
| move_dn P (Nd (_, ns)) (p :: (ps as (_ :: _)), p_) = (* iterate to end of pos *)
|
wneuper@59296
|
1368 |
if p > length ns
|
wneuper@59296
|
1369 |
then raise PTREE "move_dn: pos not existent 2"
|
wneuper@59296
|
1370 |
else move_dn (P @ [p]) (nth p ns) (ps, p_)
|
wneuper@59296
|
1371 |
| move_dn P (Nd (c, ns)) ([p], p_) = (* act on last element of pos *)
|
wneuper@59296
|
1372 |
if p > length ns
|
wneuper@59296
|
1373 |
then raise PTREE "move_dn: pos not existent 3"
|
wneuper@59296
|
1374 |
else
|
wneuper@59296
|
1375 |
(case p_ of
|
wneuper@59296
|
1376 |
Res =>
|
wneuper@59296
|
1377 |
if p = length ns (* last Res on this level: go a level up *)
|
wneuper@59296
|
1378 |
then if g_ostate c = Complete
|
wneuper@59296
|
1379 |
then (P, Res)
|
wneuper@59296
|
1380 |
else raise PTREE (ints2str' P ^ " not complete 1")
|
wneuper@59296
|
1381 |
else (* go to the next Nd on this level, or down into the next Nd *)
|
wneuper@59296
|
1382 |
if is_pblnd (nth (p + 1) ns) then (P@[p + 1], Pbl)
|
wneuper@59296
|
1383 |
else if g_res' (nth p ns) = g_form' (nth (p + 1) ns)
|
wneuper@59296
|
1384 |
then if (null o children o (nth (p + 1))) ns
|
wneuper@59296
|
1385 |
then (* take the Res if Complete *)
|
wneuper@59296
|
1386 |
if g_ostate' (nth (p + 1) ns) = Complete
|
wneuper@59296
|
1387 |
then (P@[p + 1], Res)
|
wneuper@59296
|
1388 |
else raise PTREE (ints2str' (P@[p + 1]) ^ " not complete 2")
|
wneuper@59296
|
1389 |
else (P@[p + 1, 1], Frm) (* go down into the next PrfObj *)
|
wneuper@59296
|
1390 |
else (P@[p + 1], Frm) (* take Frm: exists if the Nd exists *)
|
wneuper@59296
|
1391 |
| Frm => (*go down or to the Res of this Nd*)
|
wneuper@59296
|
1392 |
if (null o children o (nth p)) ns
|
wneuper@59296
|
1393 |
then if g_ostate' (nth p ns) = Complete then (P @ [p], Res)
|
wneuper@59296
|
1394 |
else raise PTREE (ints2str' (P @ [p])^" not complete 3")
|
wneuper@59296
|
1395 |
else (P @ [p, 1], Frm)
|
wneuper@59296
|
1396 |
| _ => (* is Pbl or Met *)
|
wneuper@59296
|
1397 |
if (null o children o (nth p)) ns
|
wneuper@59296
|
1398 |
then raise PTREE "move_dn:solve subproblem not startd"
|
wneuper@59296
|
1399 |
else (P @ [p, 1],
|
wneuper@59296
|
1400 |
if (is_pblnd o hd o children o (nth p)) ns
|
wneuper@59296
|
1401 |
then Pbl else Frm))
|
wneuper@59296
|
1402 |
| move_dn _ _ _ = error "";
|
wneuper@59296
|
1403 |
in
|
wneuper@59292
|
1404 |
(* get all positions in a ctree until ([],Res) or ostate=Incomplete
|
wneuper@59292
|
1405 |
val get_allp = fn :
|
wneuper@59292
|
1406 |
pos' list -> : accumulated, start with []
|
wneuper@59292
|
1407 |
pos -> : the offset for subtrees wrt the root
|
wneuper@59292
|
1408 |
ctree -> : (sub)tree
|
wneuper@59292
|
1409 |
pos' : initialization (the last pos' before ...)
|
wneuper@59292
|
1410 |
-> pos' list : of positions in this (sub) tree (relative to the root)
|
wneuper@59292
|
1411 |
*)
|
wneuper@59292
|
1412 |
fun get_allp cuts (P, pos) pt =
|
wneuper@59292
|
1413 |
(let
|
wneuper@59292
|
1414 |
val nxt = move_dn [] pt pos (*exn if Incomplete reached*)
|
wneuper@59292
|
1415 |
in
|
wneuper@59292
|
1416 |
if nxt <> ([], Res)
|
wneuper@59292
|
1417 |
then get_allp (cuts @ [nxt]) (P, nxt) pt
|
wneuper@59292
|
1418 |
else map (apfst (curry op @ P)) (cuts @ [nxt])
|
wneuper@59292
|
1419 |
end)
|
wneuper@59292
|
1420 |
handle PTREE _ => (map (apfst (curry op@ P)) cuts);
|
wneuper@59296
|
1421 |
end
|
wneuper@59292
|
1422 |
|
wneuper@59292
|
1423 |
(* the pts are assumed to be on the same level *)
|
wneuper@59292
|
1424 |
fun get_allps cuts _ [] = cuts
|
wneuper@59292
|
1425 |
| get_allps cuts P (pt :: pts) =
|
wneuper@59292
|
1426 |
let
|
wneuper@59292
|
1427 |
val below = get_allp [] (P, ([], Frm)) pt
|
wneuper@59292
|
1428 |
val levfrm =
|
wneuper@59292
|
1429 |
if is_pblnd pt
|
wneuper@59292
|
1430 |
then (P, Pbl) :: below
|
wneuper@59292
|
1431 |
else if last_elem P = 1
|
wneuper@59292
|
1432 |
then (P, Frm) :: below
|
wneuper@59292
|
1433 |
else (*Trans*) below
|
wneuper@59292
|
1434 |
val levres = levfrm @ (if null below then [(P, Res)] else [])
|
wneuper@59292
|
1435 |
in
|
wneuper@59292
|
1436 |
get_allps (cuts @ levres) (lev_on P) pts
|
wneuper@59292
|
1437 |
end;
|
wneuper@59292
|
1438 |
|
wneuper@59292
|
1439 |
(** these 2 funs decide on how far cut_tree goes **)
|
wneuper@59292
|
1440 |
(* shall the nodes _after_ the pos to be inserted at be deleted?
|
wneuper@59292
|
1441 |
shall cutting be continued on the higher level(s)? the Nd regarded will NOT be changed *)
|
wneuper@59292
|
1442 |
fun test_trans (PrfObj {branch, ...}) = (branch = TransitiveB orelse branch = NoBranch)
|
wneuper@59292
|
1443 |
| test_trans (PblObj {branch, ...}) = (branch = TransitiveB orelse branch = NoBranch);
|
wneuper@59292
|
1444 |
|
wneuper@59292
|
1445 |
(* cut_bottom new sml603..608
|
wneuper@59292
|
1446 |
cut the level at the bottom of the pos (used by cappend_...)
|
wneuper@59292
|
1447 |
and handle the parent in order to avoid extra case for root
|
wneuper@59292
|
1448 |
fn: ctree -> : the _whole_ ctree for cut_levup
|
wneuper@59292
|
1449 |
pos * posel -> : the pos after split_last
|
wneuper@59292
|
1450 |
ctree -> : the parent of the Nd to be cut
|
wneuper@59292
|
1451 |
return
|
wneuper@59292
|
1452 |
(ctree * : the updated ctree
|
wneuper@59292
|
1453 |
pos' list) * : the pos's cut
|
wneuper@59292
|
1454 |
bool : cutting shall be continued on the higher level(s)
|
wneuper@59292
|
1455 |
*)
|
wneuper@59292
|
1456 |
fun cut_bottom _ (pt' as Nd (b, [])) = ((pt', []), test_trans b)
|
wneuper@59292
|
1457 |
| cut_bottom (P, p) (Nd (b, bs)) =
|
wneuper@59292
|
1458 |
let (*divide level into 3 parts...*)
|
wneuper@59292
|
1459 |
val keep = take (p - 1, bs)
|
wneuper@59292
|
1460 |
val pt' = case nth p bs of
|
wneuper@59292
|
1461 |
pt' as Nd _ => pt'
|
wneuper@59292
|
1462 |
| _ => error "cut_bottom: uncovered case nth p bs"
|
wneuper@59292
|
1463 |
(*^^^^^_here_ will be 'insert_pt'ed by 'append_..'*)
|
wneuper@59292
|
1464 |
val (tail, _) = (takerest (p, bs), if null (takerest (p, bs)) then 0 else p + 1)
|
wneuper@59292
|
1465 |
val (children, cuts) =
|
wneuper@59292
|
1466 |
if test_trans b
|
wneuper@59292
|
1467 |
then
|
wneuper@59292
|
1468 |
(keep, (if is_pblnd pt' then [(P @ [p], Pbl)] else [])
|
wneuper@59292
|
1469 |
@ (get_allp [] (P @ [p], (P, Frm)) pt')
|
wneuper@59292
|
1470 |
@ (get_allps [] (P @ [p + 1]) tail))
|
wneuper@59292
|
1471 |
else (keep @ [(*'insert_pt'ed by 'append_..'*)] @ tail,
|
wneuper@59292
|
1472 |
get_allp [] (P @ [p], (P, Frm)) pt')
|
wneuper@59292
|
1473 |
val (pt'', cuts) =
|
wneuper@59292
|
1474 |
if test_trans b
|
wneuper@59292
|
1475 |
then (Nd (del_res b, children), cuts @ (if g_ostate b = Incomplete then [] else [(P, Res)]))
|
wneuper@59292
|
1476 |
else (Nd (b, children), cuts)
|
wneuper@59292
|
1477 |
in ((pt'', cuts), test_trans b) end
|
wneuper@59292
|
1478 |
| cut_bottom _ _ = error "cut_bottom: uncovered fun def.";
|
wneuper@59292
|
1479 |
|
wneuper@59292
|
1480 |
|
wneuper@59292
|
1481 |
(* go all levels from the bottom of 'pos' up to the root,
|
wneuper@59292
|
1482 |
on each level compose the children of a node and accumulate the cut Nds
|
wneuper@59292
|
1483 |
args
|
wneuper@59292
|
1484 |
pos' list -> : for accumulation
|
wneuper@59292
|
1485 |
bool -> : cutting shall be continued on the higher level(s)
|
wneuper@59292
|
1486 |
ctree -> : the whole ctree for 'get_nd pt P' on each level
|
wneuper@59292
|
1487 |
ctree -> : the Nd from the lower level for insertion at path
|
wneuper@59292
|
1488 |
pos * posel -> : pos=path split for convenience
|
wneuper@59292
|
1489 |
ctree -> : Nd the children of are under consideration on this call
|
wneuper@59292
|
1490 |
returns :
|
wneuper@59292
|
1491 |
ctree * pos' list : the updated parent-Nd and the pos's of the Nds cut
|
wneuper@59292
|
1492 |
*)
|
wneuper@59292
|
1493 |
fun cut_levup (cuts:pos' list) clevup pt pt' (P:pos, p:posel) (Nd (b, bs)) =
|
wneuper@59292
|
1494 |
let (*divide level into 3 parts...*)
|
wneuper@59292
|
1495 |
val keep = take (p - 1, bs)
|
wneuper@59292
|
1496 |
(*val pt' comes as argument from below*)
|
wneuper@59292
|
1497 |
val (tail, _) =
|
wneuper@59292
|
1498 |
(takerest (p, bs), if null (takerest (p, bs)) then 0 else p + 1)
|
wneuper@59292
|
1499 |
val (children, cuts') =
|
wneuper@59292
|
1500 |
if clevup
|
wneuper@59292
|
1501 |
then (keep @ [pt'], get_allps [] (P @ [p+1]) tail)
|
wneuper@59292
|
1502 |
else (keep @ [pt'] @ tail, [])
|
wneuper@59292
|
1503 |
val clevup' = if clevup then test_trans b else false
|
wneuper@59292
|
1504 |
(*the first Nd with false stops cutting on all levels above*)
|
wneuper@59292
|
1505 |
val (pt'', cuts') =
|
wneuper@59292
|
1506 |
if clevup'
|
wneuper@59292
|
1507 |
then (Nd (del_res b, children), cuts' @ (if g_ostate b = Incomplete then [] else [(P, Res)]))
|
wneuper@59292
|
1508 |
else (Nd (b, children), cuts')
|
wneuper@59292
|
1509 |
in
|
wneuper@59292
|
1510 |
if null P
|
wneuper@59292
|
1511 |
then (pt'', cuts @ cuts')
|
wneuper@59292
|
1512 |
else
|
wneuper@59292
|
1513 |
let val (P, p) = split_last P
|
wneuper@59292
|
1514 |
in cut_levup (cuts @ cuts') clevup' pt pt'' (P, p) (get_nd pt P) end
|
wneuper@59292
|
1515 |
end
|
wneuper@59292
|
1516 |
| cut_levup _ _ _ _ _ _ = error "cut_levup: uncovered fun def.";
|
wneuper@59292
|
1517 |
|
wneuper@59292
|
1518 |
(* cut nodes after and below an inserted node in the ctree;
|
wneuper@59292
|
1519 |
the cuts range is limited by the predicate 'fun cutlevup' *)
|
wneuper@59292
|
1520 |
fun cut_tree pt (pos, _) =
|
wneuper@59292
|
1521 |
if not (existpt pos pt)
|
wneuper@59292
|
1522 |
then (pt,[]) (*appending a formula never cuts anything*)
|
wneuper@59292
|
1523 |
else
|
wneuper@59292
|
1524 |
let
|
wneuper@59292
|
1525 |
val (P, p) = split_last pos
|
wneuper@59292
|
1526 |
val ((pt', cuts), clevup) = cut_bottom (P, p) (get_nd pt P)
|
wneuper@59292
|
1527 |
(* pt' is the updated parent of the Nd to cappend_..*)
|
wneuper@59292
|
1528 |
in
|
wneuper@59292
|
1529 |
if null P
|
wneuper@59292
|
1530 |
then (pt', cuts)
|
wneuper@59292
|
1531 |
else
|
wneuper@59292
|
1532 |
let val (P, p) = split_last P
|
wneuper@59292
|
1533 |
in cut_levup cuts clevup pt pt' (P, p) (get_nd pt P) end
|
wneuper@59292
|
1534 |
end;
|
wneuper@59292
|
1535 |
|
wneuper@59292
|
1536 |
(* get the theory explicitly specified for the rootpbl;
|
wneuper@59292
|
1537 |
thus use this function _after_ finishing specification *)
|
wneuper@59292
|
1538 |
fun rootthy (Nd (PblObj {spec = (thyID, _, _), ...}, _)) = assoc_thy thyID
|
wneuper@59292
|
1539 |
| rootthy _ = error "rootthy: uncovered fun def.";
|
wneuper@59292
|
1540 |
|
wneuper@59292
|
1541 |
(**)
|
wneuper@59292
|
1542 |
end;
|
wneuper@59292
|
1543 |
(**)
|