walther@59984
|
1 |
signature SPECIFY =
|
walther@59763
|
2 |
sig
|
walther@59775
|
3 |
val find_next_step: Calc.T -> string * (Pos.pos_ * Tactic.input)
|
walther@59990
|
4 |
val find_next_step': Pos.pos_ -> bool -> O_Model.T -> References.T -> I_Model.T * I_Model.T ->
|
walther@59990
|
5 |
Model_Pattern.T * Model_Pattern.T -> References.T -> Pos.pos_ * Tactic.input
|
walther@59990
|
6 |
val do_all: Calc.T -> Calc.T
|
walther@59990
|
7 |
val finish_phase: Calc.T -> Calc.T
|
walther@59990
|
8 |
|
walther@60002
|
9 |
val item_to_add: theory -> O_Model.T -> Model_Pattern.T -> I_Model.T ->
|
walther@60002
|
10 |
(Model_Def.m_field * TermC.as_string) option
|
walther@59990
|
11 |
val item_to_add': theory -> O_Model.T -> Model_Pattern.T -> I_Model.T ->
|
walther@59990
|
12 |
(Model_Def.m_field * TermC.as_string) option
|
walther@59990
|
13 |
(*TODO: vvvvvvvvvvvvvv unify code*)
|
walther@59990
|
14 |
val by_tactic_input': string -> TermC.as_string -> Calc.T -> Calc.state_post
|
walther@59990
|
15 |
val by_tactic': string -> TermC.as_string -> Calc.T -> string * Calc.state_post
|
walther@59990
|
16 |
(*TODO: ^^^^^^^^^^^^^^ unify code*)
|
walther@59806
|
17 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
walther@59806
|
18 |
(*NONE*)
|
walther@59886
|
19 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
walther@59806
|
20 |
(*NONE*)
|
walther@59886
|
21 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
walther@59763
|
22 |
end
|
walther@59763
|
23 |
|
walther@59763
|
24 |
(**)
|
walther@59984
|
25 |
structure Specify(**): SPECIFY(**) =
|
walther@59763
|
26 |
struct
|
walther@59763
|
27 |
(**)
|
walther@59763
|
28 |
|
walther@59990
|
29 |
(*
|
walther@59990
|
30 |
select an item in oris, notyet input in itms
|
walther@59990
|
31 |
(precondition: in itms are only I_Model.Cor, I_Model.Sup, I_Model.Inc)
|
walther@59990
|
32 |
args of item_to_add'
|
walther@59990
|
33 |
thy : for?
|
walther@59990
|
34 |
oris: from formalization 'type fmz', structured for efficient access
|
walther@59990
|
35 |
pbt : the problem-pattern to be matched with oris in order to get itms
|
walther@59990
|
36 |
itms: already input items
|
walther@59990
|
37 |
*)
|
walther@59990
|
38 |
fun item_to_add' thy [] pbt itms = (*root (only) ori...fmz=[]*)
|
walther@59990
|
39 |
let
|
walther@59990
|
40 |
fun test_d d (i, _, _, _, itm_) = (d = (I_Model.d_in itm_)) andalso i <> 0
|
walther@59990
|
41 |
fun is_elem itms (_, (d, _)) =
|
walther@59990
|
42 |
case find_first (test_d d) itms of SOME _ => true | NONE => false
|
walther@59990
|
43 |
in
|
walther@59990
|
44 |
case filter_out (is_elem itms) pbt of
|
walther@59990
|
45 |
(f, (d, _)) :: _ => SOME (f, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, []))
|
walther@59990
|
46 |
| _ => NONE
|
walther@59990
|
47 |
end
|
walther@59990
|
48 |
| item_to_add' thy oris _ itms =
|
walther@59990
|
49 |
let
|
walther@60003
|
50 |
(*OLD*)fun testr_vt v ori = Library.member op= (#2 (ori : O_Model.single)) v andalso (#3 ori) <> "#undef"
|
walther@60002
|
51 |
(*OLD*)fun testi_vt v itm = Library.member op= (#2 (itm : I_Model.single)) v
|
walther@60002
|
52 |
fun test_id ids r = Library.member op= ids (#1 (r : O_Model.single))
|
walther@59990
|
53 |
fun test_subset itm (_, _, _, d, ts) =
|
walther@59990
|
54 |
(I_Model.d_in (#5 (itm: I_Model.single))) = d andalso subset op = (I_Model.ts_in (#5 itm), ts)
|
walther@59990
|
55 |
fun false_and_not_Sup (_, _, false, _, I_Model.Sup _) = false
|
walther@59990
|
56 |
| false_and_not_Sup (_, _, false, _, _) = true
|
walther@59990
|
57 |
| false_and_not_Sup _ = false
|
walther@59990
|
58 |
val v = if itms = [] then 1 else I_Model.max_vt itms
|
walther@59990
|
59 |
val vors = if v = 0 then oris else filter (testr_vt v) oris (* oris..vat *)
|
walther@59990
|
60 |
val vits =
|
walther@59990
|
61 |
if v = 0
|
walther@59990
|
62 |
then itms (* because of dsc without dat *)
|
walther@59990
|
63 |
else filter (testi_vt v) itms; (* itms..vat *)
|
walther@59990
|
64 |
val icl = filter false_and_not_Sup vits; (* incomplete *)
|
walther@59990
|
65 |
in
|
walther@60002
|
66 |
if icl = [] then
|
walther@60002
|
67 |
case filter_out (test_id (map #1 vits)) vors of
|
walther@60002
|
68 |
[] => NONE
|
walther@60002
|
69 |
| miss => SOME (O_Model.getr_ct thy (hd miss))
|
walther@59990
|
70 |
else
|
walther@59990
|
71 |
case find_first (test_subset (hd icl)) vors of
|
walther@59990
|
72 |
NONE => raise ERROR "item_to_add': types or dsc DO NOT MATCH BETWEEN fmz --- pbt"
|
walther@59992
|
73 |
| SOME ori => SOME (I_Model.geti_ct thy ori (hd icl))
|
walther@59990
|
74 |
end
|
walther@59984
|
75 |
|
walther@60002
|
76 |
(* preliminary doubling of code, ONLY difference SHALL BE in fun testr_vt *)
|
walther@60002
|
77 |
fun item_to_add thy [] pbt itms = (*root (only) ori...fmz=[]*)
|
walther@60002
|
78 |
let
|
walther@60002
|
79 |
fun test_d d (i, _, _, _, itm_) = (d = (I_Model.d_in itm_)) andalso i <> 0
|
walther@60002
|
80 |
fun is_elem itms (_, (d, _)) =
|
walther@60002
|
81 |
case find_first (test_d d) itms of SOME _ => true | NONE => false
|
walther@60002
|
82 |
in
|
walther@60002
|
83 |
case filter_out (is_elem itms) pbt of
|
walther@60002
|
84 |
(f, (d, _)) :: _ => SOME (f, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, []))
|
walther@60002
|
85 |
| _ => NONE
|
walther@60002
|
86 |
end
|
walther@60002
|
87 |
| item_to_add thy oris _ itms =
|
walther@60002
|
88 |
let
|
walther@60003
|
89 |
(*NEW*)fun testr_vt v ori = Library.member op= (#2 (ori : O_Model.single)) v (*andalso (#3 ori) <> "#undef"*)
|
walther@60003
|
90 |
(*OLD* )fun testr_vt v ori = Library.member op= (#2 (ori : O_Model.single)) v andalso (#3 ori) <> "#undef"
|
walther@60003
|
91 |
( *OLD*)fun testi_vt v itm = Library.member op= (#2 (itm : I_Model.single)) v
|
walther@60002
|
92 |
fun test_id ids r = Library.member op= ids (#1 (r : O_Model.single))
|
walther@60002
|
93 |
fun test_subset itm (_, _, _, d, ts) =
|
walther@60002
|
94 |
(I_Model.d_in (#5 (itm: I_Model.single))) = d andalso subset op = (I_Model.ts_in (#5 itm), ts)
|
walther@60002
|
95 |
fun false_and_not_Sup (_, _, false, _, I_Model.Sup _) = false
|
walther@60002
|
96 |
| false_and_not_Sup (_, _, false, _, _) = true
|
walther@60002
|
97 |
| false_and_not_Sup _ = false
|
walther@60002
|
98 |
val v = if itms = [] then 1 else I_Model.max_vt itms
|
walther@60002
|
99 |
val vors = if v = 0 then oris else filter (testr_vt v) oris (* oris..vat *)
|
walther@60002
|
100 |
val vits =
|
walther@60002
|
101 |
if v = 0
|
walther@60002
|
102 |
then itms (* because of dsc without dat *)
|
walther@60002
|
103 |
else filter (testi_vt v) itms; (* itms..vat *)
|
walther@60002
|
104 |
val icl = filter false_and_not_Sup vits; (* incomplete *)
|
walther@60002
|
105 |
in
|
walther@60002
|
106 |
if icl = [] then
|
walther@60002
|
107 |
case filter_out (test_id (map #1 vits)) vors of
|
walther@60002
|
108 |
[] => NONE
|
walther@60002
|
109 |
| miss => SOME (O_Model.getr_ct thy (hd miss))
|
walther@60002
|
110 |
else
|
walther@60002
|
111 |
case find_first (test_subset (hd icl)) vors of
|
walther@60002
|
112 |
NONE => raise ERROR "item_to_add': types or dsc DO NOT MATCH BETWEEN fmz --- pbt"
|
walther@60002
|
113 |
| SOME ori => SOME (I_Model.geti_ct thy ori (hd icl))
|
walther@60002
|
114 |
end
|
walther@60002
|
115 |
|
walther@60002
|
116 |
(*TODO: unify*)
|
walther@59772
|
117 |
fun find_next_step (pt, (p, p_)) =
|
walther@59763
|
118 |
let
|
walther@60002
|
119 |
(*OLD*)val (pblobj, met, origin, oris, dI', pI', mI', pbl, dI, pI, mI) =
|
walther@60002
|
120 |
(*OLD*) case Ctree.get_obj I pt p of
|
walther@60002
|
121 |
(*OLD*) pblobj as (Ctree.PblObj {meth, origin = origin as (oris, (dI', pI', mI'), _),
|
walther@60002
|
122 |
(*OLD*) probl, spec = (dI, pI, mI), ...}) => (pblobj, meth, origin, oris, dI', pI', mI', probl, dI, pI, mI)
|
walther@60002
|
123 |
(*OLD*) | Ctree.PrfObj _ => raise ERROR "nxt_specify_: not on PrfObj"
|
walther@60002
|
124 |
(*OLD*)in
|
walther@60003
|
125 |
(*OLD*) if Ctree.just_created_ pblobj (*by Subproblem*) andalso origin <> Ctree.e_origin then
|
walther@60003
|
126 |
(*OLD*)
|
walther@60002
|
127 |
(*NEW* )val pblobj as {meth = met, origin = origin as (oris, (dI', pI', mI'), _), probl = pbl,
|
walther@60002
|
128 |
(*NEW*) spec = (dI, pI, mI), ctxt, ...} = Calc.specify_data (pt, (p, p_));
|
walther@60002
|
129 |
(*NEW*)in
|
walther@60003
|
130 |
(*NEW*) if Ctree.just_created (pt, (p, p_)) andalso origin <> Ctree.e_origin then
|
walther@60002
|
131 |
( *NEW*)
|
walther@59763
|
132 |
case mI' of
|
walther@59992
|
133 |
["no_met"] => ("ok", (Pos.Pbl, Tactic.Refine_Tacitly pI'))
|
walther@59992
|
134 |
| _ => ("ok", (Pos.Pbl, Tactic.Model_Problem))
|
walther@59763
|
135 |
else
|
walther@59763
|
136 |
let
|
walther@60002
|
137 |
(*NEW* ) References.select (dI', pI', mI') (dI, pI, mI) ( *NEW*)
|
walther@59903
|
138 |
val cpI = if pI = Problem.id_empty then pI' else pI;
|
walther@59903
|
139 |
val cmI = if mI = Method.id_empty then mI' else mI;
|
walther@59970
|
140 |
val {ppc = pbt, prls, where_, ...} = Problem.from_store cpI;
|
walther@59965
|
141 |
val pre = Pre_Conds.check' "thy 100820" prls where_ pbl;
|
walther@59763
|
142 |
val preok = foldl and_ (true, map fst pre);
|
walther@59763
|
143 |
(*FIXME.WN0308: ~~~~~: just check true in itms of pbl/met?*)
|
walther@59970
|
144 |
val mpc = (#ppc o Method.from_store) cmI
|
walther@59763
|
145 |
in
|
walther@59763
|
146 |
case p_ of
|
walther@60002
|
147 |
(*vvvvvvv---------------------------*)
|
walther@59992
|
148 |
Pos.Pbl =>
|
walther@59992
|
149 |
(if dI' = ThyC.id_empty andalso dI = ThyC.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Theory dI'))
|
walther@59992
|
150 |
else if pI' = Problem.id_empty andalso pI = Problem.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Problem pI'))
|
walther@59763
|
151 |
else
|
walther@59988
|
152 |
case find_first (I_Model.is_error o #5) pbl of
|
walther@59763
|
153 |
SOME (_, _, _, fd, itm_) =>
|
walther@59992
|
154 |
("dummy", (Pos.Pbl, P_Model.mk_delete (ThyC.get_theory
|
walther@59979
|
155 |
(if dI = ThyC.id_empty then dI' else dI)) fd itm_))
|
walther@59763
|
156 |
| NONE =>
|
walther@59990
|
157 |
(case item_to_add' (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris pbt pbl of
|
walther@59992
|
158 |
SOME (fd, ct') => ("dummy", (Pos.Pbl, P_Model.mk_additem fd ct'))
|
walther@59763
|
159 |
| NONE => (*pbl-items complete*)
|
walther@59992
|
160 |
if not preok then ("dummy", (Pos.Pbl, Tactic.Refine_Problem pI'))
|
walther@59992
|
161 |
else if dI = ThyC.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Theory dI'))
|
walther@59992
|
162 |
else if pI = Problem.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Problem pI'))
|
walther@59992
|
163 |
else if mI = Method.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Method mI'))
|
walther@59763
|
164 |
else
|
walther@59988
|
165 |
case find_first (I_Model.is_error o #5) met of
|
walther@59992
|
166 |
SOME (_, _, _, fd, itm_) => ("dummy", (Pos.Met, P_Model.mk_delete (ThyC.get_theory dI) fd itm_))
|
walther@59763
|
167 |
| NONE =>
|
walther@60002
|
168 |
(case item_to_add (ThyC.get_theory dI) oris mpc met of
|
walther@59992
|
169 |
SOME (fd, ct') => ("dummy", (Pos.Met, P_Model.mk_additem fd ct')) (*30.8.01: pre?!?*)
|
walther@59992
|
170 |
| NONE => ("dummy", (Pos.Met, Tactic.Apply_Method mI)))))
|
walther@60002
|
171 |
(*vvvvvvv---------------------------*)
|
walther@59992
|
172 |
| Pos.Met =>
|
walther@59988
|
173 |
(case find_first (I_Model.is_error o #5) met of
|
walther@59998
|
174 |
SOME (_,_,_, fd, itm_) => ("dummy", (Pos.Met, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_))
|
walther@59763
|
175 |
| NONE =>
|
walther@60002
|
176 |
case item_to_add (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris mpc met of
|
walther@60003
|
177 |
SOME (fd, ct') => ("dummy", (Pos.Met, P_Model.mk_additem fd ct')) (*->->*)
|
walther@59763
|
178 |
| NONE =>
|
walther@59992
|
179 |
(if dI = ThyC.id_empty then ("dummy", (Pos.Met, Tactic.Specify_Theory dI'))
|
walther@59992
|
180 |
else if pI = Problem.id_empty then ("dummy", (Pos.Met, Tactic.Specify_Problem pI'))
|
walther@59992
|
181 |
else if not preok then ("dummy", (Pos.Met, Tactic.Specify_Method mI))
|
walther@59992
|
182 |
else ("dummy", (Pos.Met, Tactic.Apply_Method mI))))
|
walther@59772
|
183 |
| p_ => raise ERROR ("Specify.find_next_step called with " ^ Pos.pos_2str p_)
|
walther@59763
|
184 |
end
|
walther@59763
|
185 |
end
|
walther@59763
|
186 |
|
walther@59990
|
187 |
(*
|
walther@59994
|
188 |
TODO: unify code with Specify.find_next_step ! ! ! USED ONLY to determine Pos.Pbl .. Pos.Met
|
walther@59990
|
189 |
|
walther@59990
|
190 |
determine the next step of specification;
|
walther@59990
|
191 |
not done here: Refine_Tacitly (otherwise *** unknown method: (..., no_met))
|
walther@59990
|
192 |
eg. in rootpbl 'no_met':
|
walther@59990
|
193 |
args:
|
walther@59990
|
194 |
preok predicates are _all_ ok (and problem matches completely)
|
walther@59990
|
195 |
oris immediately from formalization
|
walther@59990
|
196 |
(dI',pI',mI') specification coming from author/parent-problem
|
walther@59990
|
197 |
(pbl, item lists specified by user
|
walther@59990
|
198 |
met) -"-, tacitly completed by copy_probl
|
walther@59990
|
199 |
(dI,pI,mI) specification explicitly done by the user
|
walther@59990
|
200 |
(pbt, mpc) problem type, guard of method
|
walther@59990
|
201 |
*)
|
walther@60002
|
202 |
(*--------------vvvvvvv *)
|
walther@59990
|
203 |
fun find_next_step' Pos.Pbl preok oris (dI', pI', mI') (pbl, met) (pbt, mpc) (dI, pI, mI) =
|
walther@59990
|
204 |
(if dI' = ThyC.id_empty andalso dI = ThyC.id_empty then (Pos.Pbl, Tactic.Specify_Theory dI')
|
walther@59990
|
205 |
else if pI' = Problem.id_empty andalso pI = Problem.id_empty then (Pos.Pbl, Tactic.Specify_Problem pI')
|
walther@59990
|
206 |
else
|
walther@59990
|
207 |
case find_first (I_Model.is_error o #5) pbl of
|
walther@59990
|
208 |
SOME (_, _, _, fd, itm_) =>
|
walther@59990
|
209 |
(Pos.Pbl, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_)
|
walther@59990
|
210 |
| NONE =>
|
walther@59990
|
211 |
(case item_to_add' (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris pbt pbl of
|
walther@59990
|
212 |
SOME (fd, ct') => (Pos.Pbl, P_Model.mk_additem fd ct')
|
walther@59990
|
213 |
| NONE => (*pbl-items complete*)
|
walther@59990
|
214 |
if not preok then (Pos.Pbl, Tactic.Refine_Problem pI')
|
walther@59990
|
215 |
else if dI = ThyC.id_empty then (Pos.Pbl, Tactic.Specify_Theory dI')
|
walther@59990
|
216 |
else if pI = Problem.id_empty then (Pos.Pbl, Tactic.Specify_Problem pI')
|
walther@59990
|
217 |
else if mI = Method.id_empty then (Pos.Pbl, Tactic.Specify_Method mI')
|
walther@59990
|
218 |
else
|
walther@59990
|
219 |
case find_first (I_Model.is_error o #5) met of
|
walther@59990
|
220 |
SOME (_, _, _, fd, itm_) => (Pos.Met, P_Model.mk_delete (ThyC.get_theory dI) fd itm_)
|
walther@59990
|
221 |
| NONE =>
|
walther@60002
|
222 |
(case item_to_add (ThyC.get_theory dI) oris mpc met of
|
walther@59990
|
223 |
SOME (fd, ct') => (Pos.Met, P_Model.mk_additem fd ct') (*30.8.01: pre?!?*)
|
walther@59990
|
224 |
| NONE => (Pos.Met, Tactic.Apply_Method mI))))
|
walther@60002
|
225 |
(*--------------vvvvvvv *)
|
walther@59990
|
226 |
| find_next_step' Pos.Met preok oris (dI', pI', _) (_, met) (_ ,mpc) (dI, pI, mI) =
|
walther@59990
|
227 |
(case find_first (I_Model.is_error o #5) met of
|
walther@59990
|
228 |
SOME (_,_,_,fd,itm_) => (Pos.Met, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_)
|
walther@59990
|
229 |
| NONE =>
|
walther@60002
|
230 |
case item_to_add (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris mpc met of
|
walther@59990
|
231 |
SOME (fd,ct') => (Pos.Met, P_Model.mk_additem fd ct')
|
walther@59990
|
232 |
| NONE =>
|
walther@59990
|
233 |
(if dI = ThyC.id_empty then (Pos.Met, Tactic.Specify_Theory dI')
|
walther@59990
|
234 |
else if pI = Problem.id_empty then (Pos.Met, Tactic.Specify_Problem pI')
|
walther@59990
|
235 |
else if not preok then (Pos.Met, Tactic.Specify_Method mI)
|
walther@59990
|
236 |
else (Pos.Met, Tactic.Apply_Method mI)))
|
walther@59990
|
237 |
| find_next_step' p _ _ _ _ _ _ = raise ERROR ("find_next_step': uncovered case with " ^ Pos.pos_2str p)
|
walther@59990
|
238 |
|
walther@59990
|
239 |
fun by_tactic' sel ct (pt, pos as (p, Pos.Met)) =
|
walther@59990
|
240 |
let
|
walther@59992
|
241 |
val (met, oris, (dI', pI', mI'), pbl, (dI, pI, mI), ctxt) = Specification.get_data (pt, pos)
|
walther@59990
|
242 |
val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI
|
walther@59990
|
243 |
val cpI = if pI = Problem.id_empty then pI' else pI
|
walther@59990
|
244 |
val cmI = if mI = Method.id_empty then mI' else mI
|
walther@59990
|
245 |
val {ppc, pre, prls, ...} = Method.from_store cmI
|
walther@59990
|
246 |
in
|
walther@59990
|
247 |
case I_Model.check_single ctxt sel oris met ppc ct of
|
walther@59990
|
248 |
I_Model.Add itm => (*..union old input *)
|
walther@59990
|
249 |
let
|
walther@59990
|
250 |
val met' = I_Model.add_single thy itm met
|
walther@59992
|
251 |
val tac' = I_Model.get_tac sel (ct, met')
|
walther@59990
|
252 |
val (p, pt') =
|
walther@59992
|
253 |
case Specify_Step.add tac' (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Met)) of
|
walther@59990
|
254 |
((p, Pos.Met), _, _, pt') => (p, pt')
|
walther@59990
|
255 |
| _ => raise ERROR "by_tactic': uncovered case of generate1"
|
walther@59990
|
256 |
val pre' = Pre_Conds.check' thy prls pre met'
|
walther@59990
|
257 |
val pb = foldl and_ (true, map fst pre')
|
walther@60002
|
258 |
val (p_, _) = find_next_step' Pos.Met pb oris (dI',pI',mI') (pbl,met')
|
walther@59990
|
259 |
((#ppc o Problem.from_store) cpI,ppc) (dI,pI,mI);
|
walther@59990
|
260 |
in
|
walther@59990
|
261 |
("ok", ([], [], (pt', (p, p_))))
|
walther@59990
|
262 |
end
|
walther@59990
|
263 |
| I_Model.Err msg =>
|
walther@59990
|
264 |
let
|
walther@59990
|
265 |
val pre' = Pre_Conds.check' thy prls pre met
|
walther@59990
|
266 |
val pb = foldl and_ (true, map fst pre')
|
walther@60002
|
267 |
val (p_, _) = find_next_step' Pos.Met pb oris (dI',pI',mI') (pbl,met)
|
walther@60002
|
268 |
((#ppc o Problem.from_store) cpI,(#ppc o Method.from_store) cmI) (dI,pI,mI);
|
walther@59990
|
269 |
in
|
walther@59990
|
270 |
(msg, ([], [], (pt, (p, p_))))
|
walther@59990
|
271 |
end
|
walther@59990
|
272 |
end
|
walther@59990
|
273 |
| by_tactic' sel ct (pt, pos as (p, _(*Frm, Pbl*))) =
|
walther@59990
|
274 |
let
|
walther@59992
|
275 |
val (met, oris, (dI', pI', mI'), pbl, (dI, pI, mI), ctxt) = Specification.get_data (pt, pos)
|
walther@59990
|
276 |
val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI
|
walther@59990
|
277 |
val cpI = if pI = Problem.id_empty then pI' else pI
|
walther@59990
|
278 |
val cmI = if mI = Method.id_empty then mI' else mI
|
walther@59990
|
279 |
val {ppc, where_, prls, ...} = Problem.from_store cpI
|
walther@59990
|
280 |
in
|
walther@59990
|
281 |
case I_Model.check_single ctxt sel oris pbl ppc ct of
|
walther@59990
|
282 |
I_Model.Add itm => (*..union old input *)
|
walther@59990
|
283 |
let
|
walther@59990
|
284 |
val pbl' = I_Model.add_single thy itm pbl
|
walther@59992
|
285 |
val tac' = I_Model.get_tac sel (ct, pbl')
|
walther@59990
|
286 |
val (p, pt') =
|
walther@59992
|
287 |
case Specify_Step.add tac' (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Pbl)) of
|
walther@59990
|
288 |
((p, Pos.Pbl), _, _, pt') => (p, pt')
|
walther@59990
|
289 |
| _ => raise ERROR "by_tactic': uncovered case of Specify_Step.add"
|
walther@59994
|
290 |
(* only for getting final p_ ..*)
|
walther@59990
|
291 |
val pre = Pre_Conds.check' thy prls where_ pbl';
|
walther@59990
|
292 |
val pb = foldl and_ (true, map fst pre);
|
walther@60002
|
293 |
val (p_, _) = find_next_step' Pos.Pbl pb oris (dI',pI',mI')
|
walther@60002
|
294 |
(pbl',met) (ppc, (#ppc o Method.from_store) cmI) (dI, pI, mI);
|
walther@59990
|
295 |
in
|
walther@59990
|
296 |
("ok", ([], [], (pt', (p, p_))))
|
walther@59990
|
297 |
end
|
walther@59990
|
298 |
| I_Model.Err msg =>
|
walther@59990
|
299 |
let
|
walther@59990
|
300 |
val pre = Pre_Conds.check' thy prls where_ pbl
|
walther@59990
|
301 |
val pb = foldl and_ (true, map fst pre)
|
walther@60002
|
302 |
val (p_, _(*Tactic.input*)) = find_next_step' Pos.Pbl pb oris (dI', pI', mI')
|
walther@60002
|
303 |
(pbl, met) (ppc, (#ppc o Method.from_store) cmI) (dI, pI, mI)
|
walther@59990
|
304 |
in
|
walther@59990
|
305 |
(msg, ([], [], (pt, (p, p_))))
|
walther@59990
|
306 |
end
|
walther@59990
|
307 |
end
|
walther@59990
|
308 |
|
walther@59990
|
309 |
(*FIXME.WN110515 declare_constraints for ct (without dsc) into PblObj{ctxt, ...}
|
walther@59990
|
310 |
-- for input from scratch*)
|
walther@59990
|
311 |
fun by_tactic_input' sel ct (ptp as (pt, (p, Pos.Pbl))) =
|
walther@59990
|
312 |
let
|
walther@59990
|
313 |
val (oris, dI', pI', dI, pI, pbl, ctxt) = case Ctree.get_obj I pt p of
|
walther@59990
|
314 |
Ctree.PblObj {origin = (oris, (dI', pI', _), _), spec = (dI, pI, _), probl = pbl, ctxt, ...} =>
|
walther@59990
|
315 |
(oris, dI', pI', dI, pI, pbl, ctxt)
|
walther@59990
|
316 |
| _ => raise ERROR "specify (Specify_Theory': uncovered case get_obj"
|
walther@59990
|
317 |
val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI;
|
walther@59990
|
318 |
val cpI = if pI = Problem.id_empty then pI' else pI;
|
walther@59990
|
319 |
in
|
walther@59990
|
320 |
case I_Model.check_single ctxt sel oris pbl ((#ppc o Problem.from_store) cpI) ct of
|
walther@59990
|
321 |
I_Model.Add itm (*..union old input *) =>
|
walther@59990
|
322 |
let
|
walther@59990
|
323 |
val pbl' = I_Model.add_single thy itm pbl
|
walther@59990
|
324 |
val (tac, tac_) = case sel of
|
walther@59990
|
325 |
"#Given" => (Tactic.Add_Given ct, Tactic.Add_Given' (ct, pbl'))
|
walther@59990
|
326 |
| "#Find" => (Tactic.Add_Find ct, Tactic.Add_Find' (ct, pbl'))
|
walther@59990
|
327 |
| "#Relate"=> (Tactic.Add_Relation ct, Tactic.Add_Relation'(ct, pbl'))
|
walther@59990
|
328 |
| sel => raise ERROR ("by_tactic_input': uncovered case of" ^ sel)
|
walther@59990
|
329 |
val (p, c, pt') =
|
walther@59990
|
330 |
case Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Pbl)) of
|
walther@59990
|
331 |
((p, Pos.Pbl), c, _, pt') => (p, c, pt')
|
walther@59990
|
332 |
| _ => raise ERROR "by_tactic_input': uncovered case generate1"
|
walther@59990
|
333 |
in
|
walther@59990
|
334 |
([(tac, tac_, ((p, Pos.Pbl), (Istate_Def.Uistate, ctxt)))], c, (pt', (p, Pos.Pbl)))
|
walther@59990
|
335 |
end
|
walther@59990
|
336 |
| I_Model.Err msg => (*TODO.WN03 pass error-msgs to the frontend..
|
walther@59990
|
337 |
FIXME ..and dont abuse a tactic for that purpose*)
|
walther@59990
|
338 |
([(Tactic.Tac msg, Tactic.Tac_ (ThyC.get_theory "Isac_Knowledge", msg,msg,msg),
|
walther@59990
|
339 |
(Pos.e_pos', (Istate_Def.empty, ContextC.empty)))], [], ptp)
|
walther@59990
|
340 |
end
|
walther@59990
|
341 |
| by_tactic_input' sel ct (ptp as (pt, (p, Pos.Met))) =
|
walther@59990
|
342 |
let
|
walther@59998
|
343 |
(*NEW* ) *.specify_data ( *NEW*)
|
walther@59990
|
344 |
val (oris, dI', mI', dI, mI, met, ctxt) = case Ctree.get_obj I pt p of
|
walther@59990
|
345 |
Ctree.PblObj {origin = (oris, (dI', _, mI'), _), spec = (dI, _, mI), meth = met,ctxt, ...} =>
|
walther@59990
|
346 |
(oris, dI', mI', dI, mI, met, ctxt)
|
walther@59990
|
347 |
| _ => raise ERROR "by_tactic_input' Met: uncovered case get_obj"
|
walther@59998
|
348 |
(*NEW* ) References.select ( *NEW*)
|
walther@59990
|
349 |
val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI;
|
walther@59990
|
350 |
val cmI = if mI = Method.id_empty then mI' else mI;
|
walther@59990
|
351 |
in
|
walther@59990
|
352 |
case I_Model.check_single ctxt sel oris met ((#ppc o Method.from_store) cmI) ct of
|
walther@59990
|
353 |
I_Model.Add itm (*..union old input *) =>
|
walther@59990
|
354 |
let
|
walther@59990
|
355 |
val met' = I_Model.add_single thy itm met;
|
walther@59990
|
356 |
val (tac,tac_) = case sel of
|
walther@59990
|
357 |
"#Given" => (Tactic.Add_Given ct, Tactic.Add_Given' (ct, met'))
|
walther@59990
|
358 |
| "#Find" => (Tactic.Add_Find ct, Tactic.Add_Find' (ct, met'))
|
walther@59990
|
359 |
| "#Relate"=> (Tactic.Add_Relation ct, Tactic.Add_Relation'(ct, met'))
|
walther@59990
|
360 |
| sel => raise ERROR ("by_tactic_input' Met: uncovered case of" ^ sel)
|
walther@59990
|
361 |
val (p, c, pt') =
|
walther@59990
|
362 |
case Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Met)) of
|
walther@59990
|
363 |
((p, Pos.Met), c, _, pt') => (p, c, pt')
|
walther@59990
|
364 |
| _ => raise ERROR "by_tactic_input': uncovered case generate1 (WARNING WHY ?)"
|
walther@59990
|
365 |
in
|
walther@59990
|
366 |
([(tac, tac_, ((p, Pos.Met), (Istate_Def.Uistate, ctxt)))], c, (pt', (p, Pos.Met)))
|
walther@59990
|
367 |
end
|
walther@59990
|
368 |
| I_Model.Err _ => ([(*tacis*)], [], ptp) (*nxt_me collects tacis until not hide; here just no progress*)
|
walther@59990
|
369 |
end
|
walther@59990
|
370 |
| by_tactic_input' _ _ (_, p) = raise ERROR ("by_tactic_input' not impl. for" ^ Pos.pos'2str p)
|
walther@59990
|
371 |
|
walther@59990
|
372 |
(* complete _NON_empty calc-head for autocalc (sub-)pbl from oris
|
walther@59990
|
373 |
+ met from fmz; assumes pos on PblObj, meth = [] *)
|
walther@59990
|
374 |
fun finish_phase (pt, pos as (p, p_)) =
|
walther@59990
|
375 |
let
|
walther@59990
|
376 |
val _ = if p_ <> Pos.Pbl
|
walther@59990
|
377 |
then raise ERROR ("###finish_phase: only impl.for Pbl, called with " ^ Pos.pos'2str pos)
|
walther@59990
|
378 |
else ()
|
walther@59990
|
379 |
val (oris, ospec, probl, spec) = case Ctree.get_obj I pt p of
|
walther@59990
|
380 |
Ctree.PblObj {origin = (oris, ospec, _), probl, spec, ...} => (oris, ospec, probl, spec)
|
walther@59990
|
381 |
| _ => raise ERROR "finish_phase: unvered case get_obj"
|
walther@59990
|
382 |
val (_, pI, mI) = References.select ospec spec
|
walther@59990
|
383 |
val mpc = (#ppc o Method.from_store) mI
|
walther@59990
|
384 |
val ppc = (#ppc o Problem.from_store) pI
|
walther@59990
|
385 |
val (pits, mits) = I_Model.complete_method (oris, mpc, ppc, probl)
|
walther@59990
|
386 |
val pt = Ctree.update_pblppc pt p pits
|
walther@59990
|
387 |
val pt = Ctree.update_metppc pt p mits
|
walther@59990
|
388 |
in (pt, (p, Pos.Met)) end
|
walther@59990
|
389 |
|
walther@59990
|
390 |
(* do all specification in one single step:
|
walther@59990
|
391 |
complete calc-head for autocalc (sub-)pbl from oris (+ met from fmz);
|
walther@59990
|
392 |
oris and spec (incl. pbl-refinement) given from init_calc or SubProblem
|
walther@59990
|
393 |
*)
|
walther@59990
|
394 |
fun do_all (pt, (p, _)) =
|
walther@59990
|
395 |
let
|
walther@59990
|
396 |
val (pors, dI, pI, mI) = case Ctree.get_obj I pt p of
|
walther@59990
|
397 |
Ctree.PblObj {origin = (pors, (dI, pI, mI), _), ...}
|
walther@59990
|
398 |
=> (pors, dI, pI, mI)
|
walther@59990
|
399 |
| _ => raise ERROR "do_all: uncovered case get_obj"
|
walther@59990
|
400 |
val {ppc, ...} = Method.from_store mI
|
walther@59990
|
401 |
val (_, vals) = O_Model.values' pors
|
walther@59990
|
402 |
val ctxt = ContextC.initialise dI vals
|
walther@59990
|
403 |
val (pt, _) = Ctree.cupdate_problem pt p ((dI, pI, mI),
|
walther@59990
|
404 |
map (I_Model.complete' ppc) pors, map (I_Model.complete' ppc) pors, ctxt)
|
walther@59990
|
405 |
in
|
walther@59990
|
406 |
(pt, (p, Pos.Met))
|
walther@59990
|
407 |
end
|
walther@59990
|
408 |
|
walther@59946
|
409 |
(**)end(**)
|