1 (* states for calculation in global refs
8 string list * (*hide: tacs +
9 "ALL", .. result immediately
10 "MODELPBL", .. modeling hidden
11 "SPEC", .. specifying hidden
12 "MODELMET", .. (additional itms !)
13 "APPLY", .. solving hidden
15 "Rewrite_*" (as strings) must _not_ be ..
16 .. contained in this list, rls _only_ !*)
17 bool) (*inherit to children in pbl-herarchy*)
20 (*. points a pbl/metID to a sub-hierarchy of key ?.*)
21 fun is_child_of child key =
22 let fun is_ch [] [] = true (*is child of itself*)
23 | is_ch (c::_) [] = true
24 | is_ch [] (k::_) = false
25 | is_ch (c::cs) (k::ks) =
26 if c = k then is_ch cs ks else false
27 in is_ch (rev child) (rev key) end;
29 is_child_of ["root'","univar","equation"] ["univar","equation"];
31 is_child_of ["root'","univar","equation"] ["system","equation"];
33 is_child_of ["equation"] ["system","equation"];
35 is_child_of ["root'","univar","equation"] ["linear","univar","equation"];
39 (*.what tactics have to be hidden (in model/specify these may be several).*)
43 | Htac (*a tactic has to be hidden*)
44 | Hmodel (*the model of the (sub)problem has to be hidden*)
45 | Hspecify (*the specification of the (sub)problem has to be hidden*)
46 | Happly; (*solving the (sub)problem has to be hidden*)
48 (*. search all pbls if there is some tactic or model/spec/calc to hide .*)
49 fun is_hid pblID arg [] = Show
50 | is_hid pblID arg ((pblID', strs, inherit)::pts) =
52 if arg mem strs then Htac
53 else if arg mem ["Add_Given","Add_Find","Add_Relation"]
54 andalso "MODEL" mem strs then Hmodel
55 else if arg mem ["Specify_Theory","Specify_Problem",
57 andalso "SPEC" mem strs then Hspecify
58 else if "APPLY" mem strs then Htac
61 if is_child_of (pblID:pblID) pblID'
62 then case is_mem arg of Hundef => is_hid pblID arg (pts:hide)
64 else is_hid pblID arg pts
65 else if pblID = pblID'
66 then case is_mem arg of Hundef => is_hid pblID arg (pts:hide)
68 else is_hid pblID arg pts
70 (*val hide = [([],["Refine_Tacitly"],true),
71 (["univar","equation"],["Apply_Method","Model_Problem","SPEC"],
74 is_hid [] "Rewrite" hide;
76 is_hid ["any","problem"] "Refine_Tacitly" hide;
78 is_hid ["root'","univar","equation"] "Apply_Method" hide;
80 is_hid ["univar","equation"] "Apply_Method" hide;
82 is_hid ["univar","equation"] "Specify_Problem" hide;
86 fun is_hide pblID (tac as (Subproblem (_,pI))) (det:detail) =
87 is_hid pblID "SELF" det
88 | is_hide pblID (tac as (Rewrite (thmID,_))) det =
89 is_hid pblID thmID det
90 | is_hide pblID (tac as (Rewrite_Inst (_,(thmID,_)))) det =
91 is_hid pblID thmID det
92 | is_hide pblID (tac as (Rewrite_Set rls)) det =
94 | is_hide pblID (tac as (Rewrite_Set_Inst (_,rls))) det =
96 | is_hide pblID tac det = is_hid pblID (tac2IDstr tac) det;
97 (*val hide = [([],["Refine_Tacitly"],true),
98 (["univar","equation"],["Apply_Method","Model_Problem",
102 is_hide [] (Rewrite ("","")) hide;
104 is_hide ["any","problem"] (Refine_Tacitly []) hide;
106 is_hide ["root'","univar","equation"] (Apply_Method []) hide;
108 is_hide ["univar","equation"] (Apply_Method []) hide;
110 is_hide ["univar","equation"] (Specify_Problem []) hide;
112 is_hide ["univar","equation"] (Subproblem (e_domID,["univar","equation"]))hide;
114 is_hide ["equation"] (Subproblem (e_domID,["univar","equation"]))hide;
119 (*. search all pbls in detail if there is some rls' to be detailed .*)
120 fun is_det pblID arg [] = false
121 | is_det pblID arg ((pblID', rlss, inherit)::pts) =
123 if is_child_of (pblID:pblID) pblID'
124 then if arg mem rlss then true
125 else is_det pblID arg (pts:detail)
126 else is_det pblID arg pts
127 else if pblID = pblID'
128 then if arg mem rlss then true
129 else is_det pblID arg (pts:detail)
130 else is_det pblID arg pts;
132 (*fun is_detail pblID (tac as (Subproblem (_,pI))) (det:detail) =
133 is_det pblID "SELF" det*)
134 fun is_detail pblID (tac as (Rewrite_Set rls)) det =
136 | is_detail pblID (tac as (Rewrite_Set_Inst (_,rls))) det =
138 | is_detail _ _ _ = false;
139 ----------------------------------------*)
144 (*FIXME.WN.9.03: ev. resdesign calcstate + pos for CalcIterator
146 (*pos' * set by the CalcIterator ---> for each user*)
147 calcstate; (*to which ev.included 'preview' tac_s could be applied*)
148 val e_state = (e_pos', e_calcstate):state;
149 val states = Unsynchronized.ref ([]:(iterID * (calcID * state) list) list);
152 val states = Unsynchronized.ref
155 (iterID * (*1 sets the 'active formula'*)
156 pos' (*for iterator of a user *)
159 states:= [(3,(e_calcstate, [(1,e_pos'),
161 (4,(e_calcstate, [(1,e_pos'),
165 (** create new instances of users and ptrees
166 new keys are the lowest possible in the association list **)
169 fun new_key u n = case assoc (u, n) of
171 | SOME _ => new_key u (n+1);
173 fun get_calcID (u:(calcID * (calcstate * (iterID * pos') list)) list) =
174 (new_key u 1):calcID;*)
176 val new_iterID = get_calcID (!states);
178 states:= (!states) @ [(new_iterID, [])];
180 val it = [(3,[(#,#),(#,#)]),(4,[(#,#),(#,#)]),(1,[])]
183 (*///7.10.03/// add states to a users active states
184 fun get_calcID (uI:iterID) (p:(iterID * (calcID * state) list) list) =
185 case assoc (p, uI) of
186 NONE => error ("get_calcID: no iterID " ^
188 | SOME ps => (new_key ps 1):calcID;
189 > get_calcID 1 (!states);
192 (* add users to a calcstate *)
193 fun get_iterID (cI:calcID)
194 (p:(calcID * (calcstate * (iterID * pos') list)) list) =
195 case assoc (p, cI) of
196 NONE => error ("get_iterID: no iterID " ^ (string_of_int cI))
197 | SOME (_, us) => (new_key us 1):iterID;
198 (* get_iterID 3 (!states);
199 val it = 2 : iterID*)
202 (** retrieve, update, delete a state by iterID, calcID **)
205 fun get_cal (uI:iterID) (pI:calcID) (p:(iterID * (calcID * state) list) list) =
206 (the (assoc2 (p,(uI, pI))))
207 handle _ => error ("get_state " ^ (string_of_int uI) ^
208 " " ^ (string_of_int pI) ^ " not existent");
209 > get_cal 3 1 (!states);
210 val it = (((EmptyPtree,(#,#)),[]),([],[])) : state
214 fun get_state (uI:iterID) (pI:calcID) = get_cal uI pI (!states);
215 fun get_calc (uI:iterID) (pI:calcID) = (snd o (get_cal uI pI)) (!states);
217 fun get_calc (cI:calcID) =
218 case assoc (!states, cI) of
219 NONE => error ("get_calc "^(string_of_int cI)^" not existent")
221 fun get_pos (cI:calcID) (uI:iterID) =
222 case assoc (!states, cI) of
223 NONE => error ("get_pos: calc " ^ (string_of_int cI)
226 (case assoc (us, uI) of
227 NONE => error ("get_pos: user " ^ (string_of_int uI)
232 fun del_assoc ([],_) = []
234 let fun del ([], key) ps = ps
235 | del ((keyi, xi) :: pairs, key) ps =
236 if key = keyi then ps @ pairs
237 else del (pairs, key) (ps @ [(keyi, xi)])
240 > val ps = [(1,"1"),(2,"2"),(3,"3"),(4,"4")];
242 val it = [(1,"1"),(2,"2"),(4,"4")] : (int * string) list
245 (* delete doesn't report non existing elements *)
247 fun del_assoc2 (uI:iterID) (pI:calcID) ps =
248 let val new_ps = del_assoc (the (assoc (ps, uI)), pI)
249 in overwrite (ps, (uI, new_ps)) end;*)
251 > states:= del_assoc2 4 41 (!states);
253 val it = [(3,[(#,#),(#,#),(#,#)]),(4,[(#,#)]),(1,[(#,#)])] : states
257 val it = [(4,[(#,#)]),(1,[(#,#)])] : states
259 fun del_assoc2 (cI:calcID) (uI:iterID) ps =
260 case assoc (ps, cI) of
263 overwrite (ps, (cI, (cs, del_assoc (us, uI))));
265 > del_assoc2 4 1 (!states);
267 [(3, (((EmptyPtree, ([], Und)), []), [(1, ([], Und)), (3, ([], Und))])),
268 (4, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))]))]*)
271 fun overwrite2 (ps, (((uI:iterID), (pI:calcID)), p)) =
272 let val new_ps = overwrite (the (assoc (ps, uI)), (pI, p))
273 in (overwrite (ps, (uI, new_ps)))
274 handle _ => error ("overwrite2 " ^ (string_of_int uI) ^
275 " " ^ (string_of_int pI) ^ " not existent")
277 fun overwrite2 (ps, (((cI:calcID), (uI:iterID)), p)) =
278 case assoc (ps, cI) of
280 error ("overwrite2: calc " ^ (string_of_int uI) ^" not existent")
282 overwrite (ps, (cI ,(cs, overwrite (us, (uI, p)))));
284 fun upd_calc (cI:calcID) cs =
285 case assoc (!states, cI) of
286 NONE => error ("upd_calc "^(string_of_int cI)^" not existent")
287 | SOME (_, us) => states:= overwrite (!states, (cI, (cs, us)));
288 (*WN051210 testing before initac: only 1 taci in calcstate so far:
289 fun upd_calc (cI:calcID) (cs as (_, tacis):calcstate) =
291 then error ("upd_calc, |tacis|>1: "^tacis2str tacis)
293 case assoc (!states, cI) of
294 NONE => error ("upd_calc "^(string_of_int cI)^" not existent")
295 | SOME (_, us) => states:= overwrite (!states, (cI, (cs, us)))
300 fun upd_tacis (uI:iterID) (pI:calcID) tacis =
301 let val (p, (ptp,_)) = get_state uI pI
303 overwrite2 ((!states), ((uI, pI), (p, (ptp, tacis)))) end;*)
304 fun upd_tacis (cI:calcID) tacis =
305 case assoc (!states, cI) of
307 error ("upd_tacis: calctree "^(string_of_int cI)^" not existent")
308 | SOME ((ptp,_), us) =>
309 states:= overwrite (!states, (cI, ((ptp, tacis), us)));
311 fun upd_ipos (uI:iterID) (pI:calcID) (ip:pos') =
312 let val (_, calc) = get_state uI pI
313 in states:= overwrite2 ((!states), ((uI, pI), (ip, calc))) end;*)
314 fun upd_ipos (cI:calcID) (uI:iterID) (ip:pos') =
315 case assoc (!states, cI) of
317 error ("upd_ipos: calctree "^(string_of_int cI)^" not existent")
319 states:= overwrite2 (!states, ((cI, uI), ip));
322 (** add and delete calcs **)
325 fun add_pID (uI:iterID) (s:state) (p:(iterID * (calcID * state) list) list) =
326 let val new_ID = get_calcID uI p;
327 val new_states = (the (assoc (p, uI))) @ [(new_ID, s)];
328 in (new_ID, (overwrite (p, (uI, new_states)))) end;*)
330 > val (new_calcID, new_states) = add_pID 1 (!states);
331 > states:= new_states;
333 val it = [(3,[(#,#),(#,#)]),(4,[(#,#),(#,#)]),(1,[(#,#)])] : states
334 > val (new_calcID, new_states) = add_pID 3 (!states);
335 > states:= new_states;
337 val it = [(3,[(#,#),(#,#),(#,#)]),(4,[(#,#),(#,#)]),(1,[(#,#)])] : states
338 > assoc2 (!states, (3, 1));
339 val it = SOME EmptyPtree : ptree option
340 > assoc2 (!states, (3, 2));
341 val it = NONE : ptree option
344 fun add_calc (uI:iterID) (s:state) =
345 let val (new_calcID, new_calcs) = add_pID uI s (!states)
346 in states:= new_calcs;
348 fun add_user (cI:calcID) =
349 case assoc (!states, cI) of
351 error ("add_user: calctree "^(string_of_int cI)^" not existent")
353 let val new_uI = new_key us 1
354 in states:= overwrite2 (!states, ((cI, new_uI), e_pos'));
358 fun del_calc (uI:iterID) (pI:calcID) =
359 (states:= del_assoc2 uI pI (!states); pI);*)
360 fun del_user (cI:calcID) (uI:iterID) =
361 (states:= del_assoc2 cI uI (!states); uI);
364 (** add and delete calculations **)
365 (**///7.10 add and delete users **)
368 let val new_uI = get_calcID (!states)
369 in states:= (!states) @ [(new_uI, [])];
371 fun add_calc (cs:calcstate) =
372 let val new_cI = new_key (!states) 1
373 in states:= (!states) @ [(new_cI, (cs, []))];
376 (* delete doesn't report non existing elements *)
378 fun del_user (uI:userID) =
379 (states:= del_assoc (!states, uI); uI);*)
380 fun del_calc (cI:calcID) =
381 (states:= del_assoc (!states, cI); cI:calcID);
383 (* -------------- test all exported funs --------------
385 Compiler.Control.Print.printDepth:=8;
387 add_user (); add_user (); !states;
388 ML> val it = 1 : userID
389 ML> val it = 2 : userID
390 ML> val it = [(1,[]),(2,[])]
392 val (hide,detail) = ([(["pI"],["tac"],true)]:hide,
393 [(["pI"],["tac"],true)]:detail);
395 add_calc 1 (e_calcstate,(hide,detail)); !states;
396 ML> val it = 1 : calcID
397 ML> val it = 2 : calcID
400 [(1,(((EmptyPtree,(#,#)),[]),([],[]))),
401 (2,(((EmptyPtree,(#,#)),[]),([(#,#,#)],[(#,#,#)])))]),(2,[])]
403 val (pt,(p,p_)) = (EmptyPtree,e_pos');
404 val (pt,_) = cappend_problem pt p Uistate ([],e_spec);
405 upd_calc 1 2 ((pt,(p,p_)),[]); !states;
408 [(1,(((EmptyPtree,(#,#)),[]),([],[]))),
409 (2,(((Nd #,(#,#)),[]),([(#,#,#)],[(#,#,#)])))]),(2,[])]
410 (* ~~~~~~~~~~~~~~~~~~~~ unchanged !!!*)
412 get_state 1 1; get_state 1 2;
413 ML> val it = (((EmptyPtree,([],Und)),[]),([],[])) : state
417 {branch=NoBranch,cell=[],env=(#,#,#,#),loc=(#,#),meth=[],
418 model={Find=#,Given=#,Relate=#,Where=#,With=#},origin=(#,#),
419 ostate=Incomplete,probl=[],result=(#,#),spec=(#,#,#)},[]),([],Und)),
420 []),([(["pI"],["tac"],true)],[(["pI"],["tac"],true)])) : state
422 del_calc 2 1 (*non existent - NO msg!*); del_calc 1 2; !states;
423 ML> val it = [(1,[(1,(((EmptyPtree,(#,#)),[]),([],[])))]),(2,[])]
426 ML> val it = [(2,[])]
428 add_user (); add_user (); !states;
429 ML> val it = 1 : userID
430 ML> val it = 3 : userID
431 ML> val it = [(2,[]),(1,[]),(3,[])]
435 (* -------------- test all exported funs --------------
438 add_calc e_calcstate; add_calc e_calcstate; !states;
442 | [(1, (((EmptyPtree, ([], Und)), []), [])),
443 | (2, (((EmptyPtree, ([], Und)), []), []))]
445 add_user 2; add_user 2; !states;
449 | [(1, (((EmptyPtree, ([], Und)), []), [])),
450 | (2, (((EmptyPtree, ([], Und)), []), [(1, ([], Und)), (2, ([], Und))]))]
453 val cs = ((EmptyPtree, ([111], Und)), []) : calcstate;
454 upd_calc 1 cs; !states;
456 | [(1, (((EmptyPtree, ([111], Und)), []), [])),
457 | (2, (((EmptyPtree, ([], Und)), []), [(1, ([], Und)), (2, ([], Und))]))]
459 get_calc 1; get_calc 2;
460 |val it = ((EmptyPtree, ([111], Und)), []) : calcstate
461 |val it = ((EmptyPtree, ([], Und)), []) : calcstate
463 del_user 2 3 (*non existent - NO msg!*); del_user 2 1; !states;
467 | [(1, (((EmptyPtree, ([111], Und)), []), [])),
468 | (2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))]))]
472 |val it = [(2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))]))]
474 add_calc e_calcstate; add_calc e_calcstate; !states;
478 | [(2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))])),
479 | (1, (((EmptyPtree, ([], Und)), []), [])),
480 | (3, (((EmptyPtree, ([], Und)), []), []))]
484 | [(2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und)), (1, ([], Und))])),
485 | (1, (((EmptyPtree, ([], Und)), []), [])),
486 | (3, (((EmptyPtree, ([], Und)), []), []))]