neuper@37906
|
1 |
(* Handle user-input during the specify- and the solve-phase.
|
neuper@37906
|
2 |
author: Walther Neuper
|
neuper@37906
|
3 |
0603
|
neuper@37906
|
4 |
(c) due to copyright terms
|
neuper@37906
|
5 |
|
neuper@37906
|
6 |
use"ME/inform.sml";
|
neuper@37906
|
7 |
use"inform.sml";
|
neuper@37906
|
8 |
*)
|
neuper@37906
|
9 |
|
neuper@37906
|
10 |
signature INFORM =
|
s1210629013@52166
|
11 |
sig
|
neuper@37906
|
12 |
|
neuper@37906
|
13 |
type icalhd
|
neuper@37906
|
14 |
|
neuper@37906
|
15 |
(* type iitem *)
|
neuper@37906
|
16 |
datatype
|
neuper@37906
|
17 |
iitem =
|
neuper@37906
|
18 |
Find of cterm' list
|
neuper@37906
|
19 |
| Given of cterm' list
|
neuper@37906
|
20 |
| Relate of cterm' list
|
neuper@37906
|
21 |
type imodel
|
neuper@37906
|
22 |
val imodel2fstr : iitem list -> (string * cterm') list
|
neuper@37906
|
23 |
|
neuper@37906
|
24 |
|
neuper@37931
|
25 |
val Isac : 'a -> theory
|
neuper@37906
|
26 |
val appl_add' :
|
neuper@37906
|
27 |
theory' ->
|
neuper@37906
|
28 |
SpecifyTools.ori list ->
|
neuper@37906
|
29 |
SpecifyTools.itm list ->
|
neuper@37906
|
30 |
('a * (Term.term * Term.term)) list ->
|
neuper@37906
|
31 |
string * cterm' -> SpecifyTools.itm
|
neuper@37906
|
32 |
(* val appl_adds :
|
neuper@37906
|
33 |
theory' ->
|
neuper@37906
|
34 |
SpecifyTools.ori list ->
|
neuper@37906
|
35 |
SpecifyTools.itm list ->
|
neuper@37906
|
36 |
(string * (Term.term * Term.term)) list ->
|
neuper@37906
|
37 |
(string * string) list -> SpecifyTools.itm list *)
|
neuper@37906
|
38 |
(* val cas_input : string -> ptree * ocalhd *)
|
neuper@37906
|
39 |
(* val cas_input_ :
|
neuper@37906
|
40 |
spec ->
|
neuper@37906
|
41 |
(Term.term * Term.term list) list ->
|
neuper@37906
|
42 |
pblID * SpecifyTools.itm list * metID * SpecifyTools.itm list *
|
neuper@37906
|
43 |
(bool * Term.term) list *)
|
neuper@37906
|
44 |
val compare_step :
|
neuper@37906
|
45 |
calcstate' -> Term.term -> string * calcstate'
|
neuper@37906
|
46 |
(* val concat_deriv :
|
neuper@37906
|
47 |
'a * ((Term.term * Term.term) list -> Term.term * Term.term -> bool)
|
neuper@37906
|
48 |
->
|
neuper@37906
|
49 |
rls ->
|
neuper@37906
|
50 |
rule list ->
|
neuper@37906
|
51 |
Term.term ->
|
neuper@37906
|
52 |
Term.term ->
|
neuper@37906
|
53 |
bool * (Term.term * rule * (Term.term * Term.term list)) list *)
|
neuper@37906
|
54 |
val dropwhile' : (* systest/auto-inform.sml *)
|
neuper@37906
|
55 |
('a -> 'b -> bool) -> 'a list -> 'b list -> 'a list * 'b list
|
neuper@37906
|
56 |
(* val dtss2itm_ :
|
neuper@37906
|
57 |
pbt_ list ->
|
neuper@37906
|
58 |
Term.term * Term.term list ->
|
neuper@37906
|
59 |
int list * bool * string * SpecifyTools.itm_ *)
|
neuper@37906
|
60 |
(* val e_icalhd : icalhd *)
|
neuper@37906
|
61 |
val eq7 : ''a * ''b -> ''a * (''b * 'c) -> bool
|
neuper@37906
|
62 |
val equal : ''a -> ''a -> bool
|
neuper@37906
|
63 |
(* val filter_dsc :
|
neuper@37906
|
64 |
SpecifyTools.ori list -> SpecifyTools.itm -> SpecifyTools.ori list *)
|
neuper@37906
|
65 |
(* val filter_sep : ('a -> bool) -> 'a list -> 'a list * 'a list *)
|
neuper@37906
|
66 |
(* val flattup2 : 'a * ('b * 'c * 'd * 'e) -> 'a * 'b * 'c * 'd * 'e *)
|
neuper@37906
|
67 |
(* val fstr2itm_ :
|
neuper@37931
|
68 |
theory ->
|
neuper@37906
|
69 |
(''a * (Term.term * Term.term)) list ->
|
neuper@37906
|
70 |
''a * string -> int list * bool * ''a * SpecifyTools.itm_ *)
|
neuper@37906
|
71 |
val inform :
|
neuper@37906
|
72 |
calcstate' -> cterm' -> string * calcstate'
|
neuper@37906
|
73 |
val input_icalhd : ptree -> icalhd -> ptree * ocalhd
|
neuper@37906
|
74 |
(* val is_Par : SpecifyTools.itm -> bool *)
|
neuper@37906
|
75 |
(* val is_casinput : cterm' -> fmz -> bool *)
|
neuper@37906
|
76 |
(* val is_e_ts : Term.term list -> bool *)
|
neuper@37906
|
77 |
(* val itms2fstr : SpecifyTools.itm -> string * string *)
|
neuper@37906
|
78 |
(* val mk_tacis :
|
neuper@37906
|
79 |
rew_ord' * 'a ->
|
neuper@37906
|
80 |
rls ->
|
neuper@37906
|
81 |
Term.term * rule * (Term.term * Term.term list) ->
|
neuper@37906
|
82 |
tac * tac_ * (pos' * istate) *)
|
neuper@37906
|
83 |
val oris2itms :
|
neuper@37906
|
84 |
'a -> int -> SpecifyTools.ori list -> SpecifyTools.itm list
|
neuper@37906
|
85 |
(* val par2fstr : SpecifyTools.itm -> string * cterm' *)
|
neuper@37931
|
86 |
(* val parsitm : theory -> SpecifyTools.itm -> SpecifyTools.itm *)
|
neuper@37906
|
87 |
val rev_deriv' : 'a * rule * ('b * 'c) -> 'b * rule * ('a * 'c)
|
neuper@37906
|
88 |
(* val unknown_expl :
|
neuper@37906
|
89 |
theory' ->
|
neuper@37906
|
90 |
(string * (Term.term * Term.term)) list ->
|
neuper@37906
|
91 |
(string * string) list -> SpecifyTools.itm list *)
|
neuper@37906
|
92 |
end
|
neuper@37906
|
93 |
|
neuper@37906
|
94 |
|
neuper@37906
|
95 |
|
neuper@37906
|
96 |
|
neuper@37906
|
97 |
|
neuper@37906
|
98 |
|
neuper@37906
|
99 |
(***. handle an input calc-head .***)
|
neuper@37906
|
100 |
|
neuper@37906
|
101 |
(*------------------------------------------------------------------(**)
|
neuper@37906
|
102 |
structure inform :INFORM =
|
neuper@37906
|
103 |
struct
|
neuper@37906
|
104 |
(**)------------------------------------------------------------------*)
|
neuper@37906
|
105 |
|
neuper@37906
|
106 |
datatype iitem =
|
neuper@37906
|
107 |
Given of cterm' list
|
neuper@37906
|
108 |
(*Where is never input*)
|
neuper@37906
|
109 |
| Find of cterm' list
|
neuper@37906
|
110 |
| Relate of cterm' list;
|
neuper@37906
|
111 |
|
neuper@37906
|
112 |
type imodel = iitem list;
|
neuper@37906
|
113 |
|
neuper@37906
|
114 |
(*calc-head as input*)
|
neuper@37906
|
115 |
type icalhd =
|
wneuper@59156
|
116 |
pos' * (*the position of the calc-head in the calc-tree*)
|
neuper@37906
|
117 |
cterm' * (*the headline*)
|
neuper@37906
|
118 |
imodel * (*the model (without Find) of the calc-head*)
|
neuper@37906
|
119 |
pos_ * (*model belongs to Pbl or Met*)
|
neuper@37906
|
120 |
spec; (*specification: domID, pblID, metID*)
|
neuper@37906
|
121 |
val e_icalhd = (e_pos', "", [Given [""]], Pbl, e_spec): icalhd;
|
neuper@37906
|
122 |
|
neuper@37906
|
123 |
fun is_casinput (hdf: cterm') ((fmz_, spec): fmz) =
|
neuper@37906
|
124 |
hdf <> "" andalso fmz_ = [] andalso spec = e_spec;
|
neuper@37906
|
125 |
|
neuper@37906
|
126 |
(*.handle an input as into an algebra system.*)
|
neuper@37906
|
127 |
fun dtss2itm_ ppc (d, ts) =
|
neuper@37906
|
128 |
let val (f, (d, id)) = the (find_first ((curry op= d) o
|
neuper@37906
|
129 |
(#1: (term * term) -> term) o
|
neuper@37906
|
130 |
(#2: pbt_ -> (term * term))) ppc)
|
neuper@37906
|
131 |
in ([1], true, f, Cor ((d, ts), (id, ts))) end;
|
neuper@37906
|
132 |
|
neuper@37906
|
133 |
fun flattup2 (a,(b,c,d,e)) = (a,b,c,d,e);
|
neuper@37906
|
134 |
|
neuper@41995
|
135 |
fun cas_input_ ((dI,pI,mI): spec) dtss = (*WN110515 reconsider thy..ctxt*)
|
neuper@41995
|
136 |
let
|
neuper@41995
|
137 |
val thy = assoc_thy dI
|
neuper@41995
|
138 |
val {ppc, ...} = get_pbt pI
|
neuper@41995
|
139 |
val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
|
neuper@41995
|
140 |
val its = add_id its_
|
neuper@41995
|
141 |
val pits = map flattup2 its
|
neuper@41995
|
142 |
val (pI, mI) =
|
neuper@41995
|
143 |
if mI <> ["no_met"]
|
neuper@41995
|
144 |
then (pI, mI)
|
neuper@41995
|
145 |
else
|
neuper@41995
|
146 |
case refine_pbl thy pI pits of
|
neuper@37926
|
147 |
SOME (pI,_) => (pI, (hd o #met o get_pbt) pI)
|
neuper@37926
|
148 |
| NONE => (pI, (hd o #met o get_pbt) pI)
|
neuper@41995
|
149 |
val {ppc, pre, prls, ...} = get_met mI
|
neuper@41995
|
150 |
val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
|
neuper@41995
|
151 |
val its = add_id its_
|
neuper@41995
|
152 |
val mits = map flattup2 its
|
neuper@41995
|
153 |
val pre = check_preconds thy prls pre mits
|
neuper@41995
|
154 |
val ctxt = e_ctxt (*WN110515 cas_input_ DOESNT WORK*)
|
neuper@41995
|
155 |
in (pI, pits: itm list, mI, mits: itm list, pre, ctxt) end;
|
neuper@37906
|
156 |
|
neuper@37906
|
157 |
|
neuper@41995
|
158 |
(* check if the input term is a CAScmd and return a ptree with a _complete_ calchead *)
|
neuper@37906
|
159 |
fun cas_input hdt =
|
neuper@41995
|
160 |
let val (h,argl) = strip_comb hdt
|
neuper@41995
|
161 |
in
|
s1210629013@55443
|
162 |
case assoc_cas (assoc_thy "Isac") h of
|
neuper@41995
|
163 |
NONE => NONE
|
neuper@41995
|
164 |
| SOME (spec as (dI,_,_), argl2dtss) =>
|
neuper@41995
|
165 |
let
|
neuper@41995
|
166 |
val dtss = argl2dtss argl
|
neuper@41995
|
167 |
val (pI, pits, mI, mits, pre, ctxt) = cas_input_ spec dtss
|
neuper@41995
|
168 |
val spec = (dI, pI, mI)
|
neuper@41995
|
169 |
val (pt,_) =
|
neuper@41995
|
170 |
cappend_problem e_ptree [] (e_istate, e_ctxt) ([], e_spec) ([], e_spec, hdt)
|
neuper@41995
|
171 |
val pt = update_spec pt [] spec
|
neuper@41995
|
172 |
val pt = update_pbl pt [] pits
|
neuper@41995
|
173 |
val pt = update_met pt [] mits
|
neuper@41995
|
174 |
val pt = update_ctxt pt [] ctxt
|
neuper@41995
|
175 |
in SOME (pt, (true, Met, hdt, mits, pre, spec) : ocalhd) end
|
neuper@41995
|
176 |
end;
|
neuper@37906
|
177 |
|
neuper@40836
|
178 |
(*lazy evaluation for (Thy_Info.get_theory "Isac")*)
|
neuper@38050
|
179 |
fun Isac _ = assoc_thy "Isac";
|
neuper@37906
|
180 |
|
neuper@37906
|
181 |
(*re-parse itms with a new thy and prepare for checking with ori list*)
|
neuper@37906
|
182 |
fun parsitm dI (itm as (i,v,b,f, Cor ((d,ts),_)):itm) =
|
neuper@52070
|
183 |
(let
|
neuper@52070
|
184 |
val t = comp_dts (d,ts);
|
neuper@52070
|
185 |
val s = term_to_string''' dI t;
|
neuper@52070
|
186 |
(*this ^ should raise the exn on unability of re-parsing dts*)
|
neuper@52070
|
187 |
in itm end
|
neuper@52070
|
188 |
handle _ => ((i,v,false,f, Syn (term2str t)):itm))
|
neuper@37906
|
189 |
| parsitm dI (itm as (i,v,b,f, Syn str)) =
|
wneuper@59186
|
190 |
(let val t = (Thm.term_of o the o (parse dI)) str
|
neuper@52070
|
191 |
in (i,v,b,f, Par str) end
|
neuper@52070
|
192 |
handle _ => (i,v,b,f, Syn str))
|
neuper@37906
|
193 |
| parsitm dI (itm as (i,v,b,f, Typ str)) =
|
wneuper@59186
|
194 |
(let val t = (Thm.term_of o the o (parse dI)) str
|
neuper@52070
|
195 |
in (i,v,b,f, Par str) end
|
neuper@52070
|
196 |
handle _ => (i,v,b,f, Syn str))
|
neuper@37906
|
197 |
| parsitm dI (itm as (i,v,_,f, Inc ((d,ts),_))) =
|
bonzai@41949
|
198 |
(let val t = comp_dts (d,ts);
|
neuper@52070
|
199 |
val s = term_to_string''' dI t;
|
neuper@37906
|
200 |
(*this ^ should raise the exn on unability of re-parsing dts*)
|
neuper@52070
|
201 |
in itm end
|
neuper@52070
|
202 |
handle _ => ((i,v,false,f, Syn (term2str t)):itm))
|
neuper@37906
|
203 |
| parsitm dI (itm as (i,v,_,f, Sup (d,ts))) =
|
bonzai@41949
|
204 |
(let val t = comp_dts (d,ts);
|
neuper@52070
|
205 |
val s = term_to_string''' dI t;
|
neuper@37906
|
206 |
(*this ^ should raise the exn on unability of re-parsing dts*)
|
neuper@52070
|
207 |
in itm end
|
neuper@52070
|
208 |
handle _ => ((i,v,false,f, Syn (term2str t)):itm))
|
neuper@37906
|
209 |
| parsitm dI (itm as (i,v,_,f, Mis (d,t'))) =
|
neuper@37906
|
210 |
(let val t = d $ t';
|
neuper@52070
|
211 |
val s = term_to_string''' dI t;
|
neuper@37906
|
212 |
(*this ^ should raise the exn on unability of re-parsing dts*)
|
neuper@52070
|
213 |
in itm end
|
neuper@52070
|
214 |
handle _ => ((i,v,false,f, Syn (term2str t)):itm))
|
neuper@37906
|
215 |
| parsitm dI (itm as (i,v,_,f, Par _)) =
|
neuper@52070
|
216 |
error ("parsitm (" ^ itm2str_ (thy2ctxt dI) itm ^ "): Par should be internal");
|
neuper@37906
|
217 |
|
neuper@37906
|
218 |
(*separate a list to a pair of elements that do NOT satisfy the predicate,
|
neuper@37906
|
219 |
and of elements that satisfy the predicate, i.e. (false, true)*)
|
neuper@37906
|
220 |
fun filter_sep pred xs =
|
neuper@37906
|
221 |
let fun filt ab [] = ab
|
neuper@37906
|
222 |
| filt (a,b) (x :: xs) = if pred x
|
neuper@37906
|
223 |
then filt (a,b@[x]) xs
|
neuper@37906
|
224 |
else filt (a@[x],b) xs
|
neuper@37906
|
225 |
in filt ([],[]) xs end;
|
neuper@37906
|
226 |
fun is_Par ((_,_,_,_,Par _):itm) = true
|
neuper@37906
|
227 |
| is_Par _ = false;
|
neuper@37906
|
228 |
|
neuper@37906
|
229 |
fun is_e_ts [] = true
|
neuper@37906
|
230 |
| is_e_ts [Const ("List.list.Nil", _)] = true
|
neuper@37906
|
231 |
| is_e_ts _ = false;
|
neuper@37906
|
232 |
|
neuper@37906
|
233 |
(*WN.9.11.03 copied from fun appl_add (in modspec.sml)*)
|
neuper@37906
|
234 |
(* val (sel,ct) = selct;
|
neuper@37906
|
235 |
val (dI, oris, ppc, pbt, (sel, ct))=
|
neuper@37906
|
236 |
(#1 (some_spec ospec spec), oris, []:itm list,
|
neuper@37906
|
237 |
((#ppc o get_pbt) (#2 (some_spec ospec spec))),
|
neuper@37906
|
238 |
hd (imodel2fstr imodel));
|
neuper@37906
|
239 |
*)
|
neuper@37906
|
240 |
fun appl_add' dI oris ppc pbt (sel, ct) =
|
neuper@37906
|
241 |
let
|
bonzai@41951
|
242 |
val ctxt = assoc_thy dI |> thy2ctxt;
|
bonzai@41952
|
243 |
in case parseNEW ctxt ct of
|
neuper@37926
|
244 |
NONE => (0,[],false,sel, Syn ct):itm
|
bonzai@41952
|
245 |
| SOME t => (case is_known ctxt sel oris t of
|
bonzai@41951
|
246 |
("", ori', all) =>
|
bonzai@41951
|
247 |
(case is_notyet_input ctxt ppc all ori' pbt of
|
bonzai@41949
|
248 |
("",itm) => itm
|
bonzai@41949
|
249 |
| (msg,_) => error ("appl_add': " ^ msg))
|
bonzai@41949
|
250 |
| (_, (i, v, _, d, ts), _) => if is_e_ts ts then
|
bonzai@41949
|
251 |
(i, v, false, sel, Inc ((d, ts), (e_term, []))) else
|
bonzai@41949
|
252 |
(i, v, false, sel, Sup (d, ts)))
|
neuper@37906
|
253 |
end;
|
neuper@37906
|
254 |
|
neuper@37906
|
255 |
(*.generate preliminary itm_ from a strin (with field "#Given" etc.).*)
|
neuper@37906
|
256 |
(* val (f, str) = hd selcts;
|
neuper@37906
|
257 |
*)
|
neuper@37906
|
258 |
fun eq7 (f, d) (f', (d', _)) = f=f' andalso d=d';
|
neuper@37906
|
259 |
fun fstr2itm_ thy pbt (f, str) =
|
neuper@37906
|
260 |
let val topt = parse thy str
|
neuper@37906
|
261 |
in case topt of
|
neuper@37926
|
262 |
NONE => ([], false, f, Syn str)
|
neuper@37926
|
263 |
| SOME ct =>
|
neuper@37926
|
264 |
(* val SOME ct = parse thy str;
|
neuper@37906
|
265 |
*)
|
wneuper@59186
|
266 |
let val (d,ts) = (split_dts o Thm.term_of) ct
|
neuper@37906
|
267 |
val popt = find_first (eq7 (f,d)) pbt
|
neuper@37906
|
268 |
in case popt of
|
neuper@37926
|
269 |
NONE => ([1](*??*), true(*??*), f, Sup (d,ts))
|
neuper@37926
|
270 |
| SOME (f, (d, id)) => ([1], true, f, Cor ((d,ts), (id, ts)))
|
neuper@37906
|
271 |
end
|
neuper@37906
|
272 |
end;
|
neuper@37906
|
273 |
|
neuper@37906
|
274 |
|
neuper@37906
|
275 |
(*.input into empty PblObj, i.e. empty fmz+origin (unknown example).*)
|
neuper@37906
|
276 |
fun unknown_expl dI pbt selcts =
|
neuper@37906
|
277 |
let
|
neuper@37906
|
278 |
val thy = assoc_thy dI
|
neuper@37906
|
279 |
val its_ = map (fstr2itm_ thy pbt) selcts (*([1],true,"#Given",Cor (...))*)
|
neuper@37906
|
280 |
val its = add_id its_
|
neuper@37906
|
281 |
in (map flattup2 its): itm list end;
|
neuper@37906
|
282 |
|
neuper@37906
|
283 |
|
neuper@37906
|
284 |
|
neuper@37906
|
285 |
|
neuper@37906
|
286 |
(*WN.11.03 for input_icalhd, ~ specify_additem for Add_Given/_Find/_Relation
|
neuper@37906
|
287 |
appl_add': generate 1 item
|
neuper@37906
|
288 |
appl_add' . is_known: parse, get data from oris (vats, all (elems if list)..)
|
neuper@37906
|
289 |
appl_add' . is_notyet_input: compare with items in model already input
|
neuper@37906
|
290 |
insert_ppc': insert this 1 item*)
|
neuper@37906
|
291 |
(* val (dI,oris,ppc,pbt,selcts) =((#1 (some_spec ospec spec)),oris,[(*!!*)],
|
neuper@37906
|
292 |
((#ppc o get_pbt) (#2 (some_spec ospec spec))),
|
neuper@37906
|
293 |
(imodel2fstr imodel));
|
neuper@37906
|
294 |
*)
|
neuper@37906
|
295 |
fun appl_adds dI [] _ pbt selcts = unknown_expl dI pbt selcts
|
neuper@37906
|
296 |
(*already present itms in model are being overwritten*)
|
neuper@37906
|
297 |
| appl_adds dI oris ppc pbt [] = ppc
|
neuper@37906
|
298 |
| appl_adds dI oris ppc pbt (selct::ss) =
|
neuper@37906
|
299 |
(* val selct = (sel, string_of_cterm ct);
|
neuper@37906
|
300 |
*)
|
neuper@37906
|
301 |
let val itm = appl_add' dI oris ppc pbt selct;
|
neuper@37906
|
302 |
in appl_adds dI oris (insert_ppc' itm ppc) pbt ss end;
|
neuper@37906
|
303 |
(* val (dI, oris, ppc, pbt, selct::ss) =
|
neuper@37906
|
304 |
(dI, pors, probl, ppc, map itms2fstr probl);
|
neuper@37906
|
305 |
...vvv
|
neuper@37906
|
306 |
*)
|
neuper@37906
|
307 |
(* val (dI, oris, ppc, pbt, (selct::ss))=
|
neuper@37906
|
308 |
(#1 (some_spec ospec spec), oris, []:itm list,
|
neuper@37906
|
309 |
((#ppc o get_pbt) (#2 (some_spec ospec spec))),(imodel2fstr imodel));
|
neuper@37906
|
310 |
val iii = appl_adds dI oris ppc pbt (selct::ss);
|
neuper@38015
|
311 |
tracing(itms2str_ thy iii);
|
neuper@37906
|
312 |
|
neuper@37906
|
313 |
val itm = appl_add' dI oris ppc pbt selct;
|
neuper@37906
|
314 |
val ppc = insert_ppc' itm ppc;
|
neuper@37906
|
315 |
|
neuper@37906
|
316 |
val _::selct::ss = (selct::ss);
|
neuper@37906
|
317 |
val itm = appl_add' dI oris ppc pbt selct;
|
neuper@37906
|
318 |
val ppc = insert_ppc' itm ppc;
|
neuper@37906
|
319 |
|
neuper@37906
|
320 |
val _::selct::ss = (selct::ss);
|
neuper@37906
|
321 |
val itm = appl_add' dI oris ppc pbt selct;
|
neuper@37906
|
322 |
val ppc = insert_ppc' itm ppc;
|
neuper@38015
|
323 |
tracing(itms2str_ thy ppc);
|
neuper@37906
|
324 |
|
neuper@37906
|
325 |
val _::selct::ss = (selct::ss);
|
neuper@37906
|
326 |
val itm = appl_add' dI oris ppc pbt selct;
|
neuper@37906
|
327 |
val ppc = insert_ppc' itm ppc;
|
neuper@37906
|
328 |
*)
|
neuper@37906
|
329 |
|
neuper@37906
|
330 |
|
neuper@37906
|
331 |
fun oris2itms _ _ ([]:ori list) = ([]:itm list)
|
neuper@37906
|
332 |
| oris2itms pbt vat ((i,v,f,d,ts)::(os: ori list)) =
|
neuper@37930
|
333 |
if member op = vat v
|
neuper@37906
|
334 |
then (i,v,true,f,Cor ((d,ts),(e_term,[])))::(oris2itms pbt vat os)
|
neuper@37906
|
335 |
else oris2itms pbt vat os;
|
neuper@37906
|
336 |
|
neuper@37906
|
337 |
fun filter_dsc oris itm =
|
neuper@37906
|
338 |
filter_out ((curry op= ((d_in o #5) (itm:itm))) o
|
neuper@37906
|
339 |
(#4:ori -> term)) oris;
|
neuper@37906
|
340 |
|
neuper@37906
|
341 |
|
neuper@37906
|
342 |
|
neuper@37906
|
343 |
|
neuper@37906
|
344 |
fun par2fstr ((_,_,_,f, Par s):itm) = (f, s)
|
neuper@38031
|
345 |
| par2fstr itm = error ("par2fstr: called with " ^
|
neuper@37939
|
346 |
itm2str_ (thy2ctxt' "Isac") itm);
|
neuper@37906
|
347 |
fun itms2fstr ((_,_,_,f, Cor ((d,ts),_)):itm) = (f, comp_dts'' (d,ts))
|
neuper@37906
|
348 |
| itms2fstr (_,_,_,f, Syn str) = (f, str)
|
neuper@37906
|
349 |
| itms2fstr (_,_,_,f, Typ str) = (f, str)
|
neuper@37906
|
350 |
| itms2fstr (_,_,_,f, Inc ((d,ts),_)) = (f, comp_dts'' (d,ts))
|
neuper@37906
|
351 |
| itms2fstr (_,_,_,f, Sup (d,ts)) = (f, comp_dts'' (d,ts))
|
neuper@37906
|
352 |
| itms2fstr (_,_,_,f, Mis (d,t)) = (f, term2str (d $ t))
|
neuper@37906
|
353 |
| itms2fstr (itm as (_,_,_,f, Par _)) =
|
neuper@38031
|
354 |
error ("parsitm ("^itm2str_ (thy2ctxt' "Isac") itm ^
|
neuper@37906
|
355 |
"): Par should be internal");
|
neuper@37906
|
356 |
|
neuper@37906
|
357 |
fun imodel2fstr iitems =
|
neuper@41976
|
358 |
let
|
neuper@41976
|
359 |
fun xxx is [] = is
|
neuper@41976
|
360 |
| xxx is ((Given strs)::iis) = xxx (is @ (map (pair "#Given") strs)) iis
|
neuper@41976
|
361 |
| xxx is ((Find strs)::iis) = xxx (is @ (map (pair "#Find") strs)) iis
|
neuper@41976
|
362 |
| xxx is ((Relate strs)::iis) = xxx (is @ (map (pair "#Relate") strs)) iis
|
neuper@41976
|
363 |
in xxx [] iitems end;
|
neuper@37906
|
364 |
|
neuper@41976
|
365 |
(* input a calchead, WN110505 "prep_oris -> (_, ctxt)" not handled properly *)
|
neuper@37906
|
366 |
fun input_icalhd pt (((p,_), hdf, imodel, Pbl, spec as (dI,pI,mI)):icalhd) =
|
neuper@37906
|
367 |
let val PblObj {fmz = fmz as (fmz_,_), origin = (oris, ospec, hdf'),
|
neuper@41988
|
368 |
spec = sspec as (sdI,spI,smI), probl, meth, ...} = get_obj I pt p;
|
neuper@37906
|
369 |
in if is_casinput hdf fmz then the (cas_input (str2term hdf))
|
neuper@37906
|
370 |
else (*hacked WN0602 ~~~ ~~~~~~~~~, ..dropped !*)
|
neuper@41976
|
371 |
let val (pos_, pits, mits) =
|
neuper@41976
|
372 |
if dI <> sdI
|
neuper@41976
|
373 |
then let val its = map (parsitm (assoc_thy dI)) probl;
|
neuper@41976
|
374 |
val (its, trms) = filter_sep is_Par its;
|
neuper@41976
|
375 |
val pbt = (#ppc o get_pbt) (#2(some_spec ospec sspec));
|
neuper@41976
|
376 |
in (Pbl, appl_adds dI oris its pbt (map par2fstr trms), meth) end
|
neuper@41976
|
377 |
else if pI <> spI
|
neuper@41976
|
378 |
then if pI = snd3 ospec then (Pbl, probl, meth)
|
neuper@41976
|
379 |
else
|
neuper@41976
|
380 |
let val pbt = (#ppc o get_pbt) pI
|
neuper@41976
|
381 |
val dI' = #1 (some_spec ospec spec)
|
neuper@41976
|
382 |
val oris = if pI = #2 ospec then oris
|
neuper@41976
|
383 |
else prep_ori fmz_(assoc_thy"Isac") pbt |> #1;
|
neuper@41976
|
384 |
in (Pbl, appl_adds dI' oris probl pbt
|
neuper@41976
|
385 |
(map itms2fstr probl), meth) end
|
neuper@41976
|
386 |
else if mI <> smI (*FIXME.WN0311: what if probl is incomplete?!*)
|
neuper@41976
|
387 |
then let val met = (#ppc o get_met) mI
|
neuper@41976
|
388 |
val mits = complete_metitms oris probl meth met
|
neuper@41976
|
389 |
in if foldl and_ (true, map #3 mits)
|
neuper@41976
|
390 |
then (Pbl, probl, mits) else (Met, probl, mits)
|
neuper@41976
|
391 |
end
|
neuper@41976
|
392 |
else (Pbl, appl_adds (#1 (some_spec ospec spec)) oris [(*!!!*)]
|
neuper@41976
|
393 |
((#ppc o get_pbt) (#2 (some_spec ospec spec)))
|
neuper@41976
|
394 |
(imodel2fstr imodel), meth);
|
neuper@41976
|
395 |
val pt = update_spec pt p spec;
|
neuper@41976
|
396 |
in if pos_ = Pbl
|
neuper@41976
|
397 |
then let val {prls,where_,...} = get_pbt (#2 (some_spec ospec spec))
|
neuper@41976
|
398 |
val pre =check_preconds(assoc_thy"Isac")prls where_ pits
|
neuper@41976
|
399 |
in (update_pbl pt p pits,
|
neuper@41976
|
400 |
(ocalhd_complete pits pre spec, Pbl, hdf', pits, pre, spec):ocalhd)
|
neuper@41976
|
401 |
end
|
neuper@41976
|
402 |
else let val {prls,pre,...} = get_met (#3 (some_spec ospec spec))
|
neuper@41976
|
403 |
val pre = check_preconds (assoc_thy"Isac") prls pre mits
|
neuper@41976
|
404 |
in (update_met pt p mits,
|
neuper@41976
|
405 |
(ocalhd_complete mits pre spec, Met, hdf', mits, pre, spec):ocalhd)
|
neuper@41976
|
406 |
end
|
neuper@41976
|
407 |
end
|
neuper@41976
|
408 |
end
|
neuper@37906
|
409 |
| input_icalhd pt ((p,_), hdf, imodel, _(*Met*), spec as (dI,pI,mI)) =
|
neuper@38031
|
410 |
error "input_icalhd Met not impl.";
|
neuper@37906
|
411 |
|
neuper@37906
|
412 |
|
neuper@37906
|
413 |
(***. handle an input formula .***)
|
neuper@37906
|
414 |
(*
|
neuper@37906
|
415 |
Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
|
neuper@37906
|
416 |
Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden,
|
neuper@37906
|
417 |
wenn Abteilungen nur auf gleichem Level gesucht werden ?
|
neuper@37906
|
418 |
WN.040216
|
neuper@37906
|
419 |
|
neuper@37906
|
420 |
Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
|
neuper@37906
|
421 |
|
neuper@37906
|
422 |
------------------------------------------------------------------------------
|
neuper@37906
|
423 |
"Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
|
neuper@37906
|
424 |
------------------------------------------------------------------------------
|
neuper@37906
|
425 |
1. "5 * x / (x - 2) - x / (x + 2) = 4"
|
neuper@37906
|
426 |
...
|
neuper@37906
|
427 |
4. "12 * x + 4 * x ^^^ 2 = 4 * (-4 + x ^^^ 2)",Subproblem["normalize", "poly"..
|
neuper@37906
|
428 |
...
|
neuper@37906
|
429 |
4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
|
neuper@37906
|
430 |
...
|
neuper@37906
|
431 |
4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
|
neuper@37906
|
432 |
...
|
neuper@37906
|
433 |
"[x = -4 / 3]"
|
neuper@37906
|
434 |
------------------------------------------------------------------------------
|
neuper@37906
|
435 |
(1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
|
neuper@37906
|
436 |
|
neuper@37906
|
437 |
(4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
|
neuper@37906
|
438 |
------------------------------------------------------------------------------
|
neuper@37906
|
439 |
|
neuper@37906
|
440 |
|
neuper@37906
|
441 |
------------------------------------------------------------------------------
|
neuper@37906
|
442 |
"Schalk I s.87 Bsp 55b (x/(x^^^2 - 6*x+9) - 1/(x^^^2 - 3*x) =1/x)";
|
neuper@37906
|
443 |
------------------------------------------------------------------------------
|
neuper@37906
|
444 |
1. "x / (x ^^^ 2 - 6 * x + 9) - 1 / (x ^^^ 2 - 3 * x) = 1 / x"
|
neuper@37906
|
445 |
...
|
neuper@37906
|
446 |
4. "(3 + (-1 * x + x ^^^ 2)) * x = 1 * (9 * x + (x ^^^ 3 + -6 * x ^^^ 2))"
|
neuper@37906
|
447 |
Subproblem["normalize", "polynomial", "univariate"..
|
neuper@37906
|
448 |
...
|
neuper@37906
|
449 |
4.4. "-6 * x + 5 * x ^^^ 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
|
neuper@37906
|
450 |
...
|
neuper@37906
|
451 |
4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
|
neuper@37906
|
452 |
4.4.5. "[x = 0, x = 6 / 5]"
|
neuper@37906
|
453 |
...
|
neuper@37906
|
454 |
5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
|
neuper@37906
|
455 |
"[x = 6 / 5]"
|
neuper@37906
|
456 |
------------------------------------------------------------------------------
|
neuper@37906
|
457 |
(1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
|
neuper@37906
|
458 |
|
neuper@37906
|
459 |
(4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
|
neuper@37906
|
460 |
------------------------------------------------------------------------------
|
neuper@37906
|
461 |
|
neuper@37906
|
462 |
|
neuper@37906
|
463 |
------------------------------------------------------------------------------
|
neuper@37906
|
464 |
"Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
|
neuper@37906
|
465 |
------------------------------------------------------------------------------
|
neuper@37906
|
466 |
1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
|
neuper@37906
|
467 |
...
|
neuper@37906
|
468 |
6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
|
neuper@37986
|
469 |
Subproblem["sq", "root'", "univariate", "equation"]
|
neuper@37906
|
470 |
...
|
neuper@37906
|
471 |
6.6. "144 + 288 * x + 144 * x ^^^ 2 = 144 + x ^^^ 2 + 288 * x + 143 * x ^^^ 2"
|
neuper@37906
|
472 |
Subproblem["normalize", "polynomial", "univariate", "equation"]
|
neuper@37906
|
473 |
...
|
neuper@37906
|
474 |
6.6.3 "0 = 0" Subproblem["degree_0", "polynomial", "univariate", "equation"]
|
neuper@37906
|
475 |
... Or_to_List
|
neuper@37906
|
476 |
6.6.3.2 "UniversalList"
|
neuper@37906
|
477 |
------------------------------------------------------------------------------
|
neuper@37906
|
478 |
(1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
|
neuper@37906
|
479 |
|
neuper@37906
|
480 |
(6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
|
neuper@37906
|
481 |
------------------------------------------------------------------------------
|
neuper@37906
|
482 |
*)
|
neuper@37906
|
483 |
(*sh. comments auf 498*)
|
neuper@37906
|
484 |
|
neuper@37906
|
485 |
fun equal a b = a=b;
|
neuper@37906
|
486 |
|
neuper@37906
|
487 |
(*the lists contain eq-al elem-pairs at the beginning;
|
neuper@37906
|
488 |
return first list reverted (again) - ie. in order as required subsequently*)
|
neuper@37906
|
489 |
fun dropwhile' equal (f1::f2::fs) (i1::i2::is) =
|
neuper@37906
|
490 |
if equal f1 i1 then
|
neuper@37906
|
491 |
if equal f2 i2 then dropwhile' equal (f2::fs) (i2::is)
|
neuper@37906
|
492 |
else (rev (f1::f2::fs), i1::i2::is)
|
neuper@38031
|
493 |
else error "dropwhile': did not start with equal elements"
|
neuper@37906
|
494 |
| dropwhile' equal (f::fs) [i] =
|
neuper@37906
|
495 |
if equal f i then (rev (f::fs), [i])
|
neuper@38031
|
496 |
else error "dropwhile': did not start with equal elements"
|
neuper@37906
|
497 |
| dropwhile' equal [f] (i::is) =
|
neuper@37906
|
498 |
if equal f i then ([f], i::is)
|
neuper@38031
|
499 |
else error "dropwhile': did not start with equal elements";
|
neuper@37906
|
500 |
(*
|
neuper@37906
|
501 |
fun equal a b = a=b;
|
neuper@37906
|
502 |
val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
|
neuper@37906
|
503 |
val r_foder = rev foder; val r_ifoder = rev ifoder;
|
neuper@37906
|
504 |
dropwhile' equal r_foder r_ifoder;
|
neuper@37906
|
505 |
> vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
|
neuper@37906
|
506 |
|
neuper@37906
|
507 |
val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
|
neuper@37906
|
508 |
val r_foder = rev foder; val r_ifoder = rev ifoder;
|
neuper@37906
|
509 |
dropwhile' equal r_foder r_ifoder;
|
neuper@37906
|
510 |
> val it = ([3], [3, 12, 11]) : int list * int list
|
neuper@37906
|
511 |
|
neuper@37906
|
512 |
val foder = [5]; val ifoder = [11,12,3,4,5];
|
neuper@37906
|
513 |
val r_foder = rev foder; val r_ifoder = rev ifoder;
|
neuper@37906
|
514 |
dropwhile' equal r_foder r_ifoder;
|
neuper@37906
|
515 |
> val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
|
neuper@37906
|
516 |
|
neuper@37906
|
517 |
val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
|
neuper@37906
|
518 |
val r_foder = rev foder; val r_ifoder = rev ifoder;
|
neuper@37906
|
519 |
dropwhile' equal r_foder r_ifoder;
|
neuper@37906
|
520 |
> *** dropwhile': did not start with equal elements*)
|
neuper@37906
|
521 |
|
neuper@37906
|
522 |
(*040214: version for concat_deriv*)
|
neuper@55485
|
523 |
fun rev_deriv' (t, r, (t', a)) = (t', sym_rule r, (t, a));
|
neuper@37906
|
524 |
|
wneuper@59250
|
525 |
fun mk_tacis ro erls (t, r as Thm (id, thm), (t', a)) =
|
wneuper@59250
|
526 |
(Rewrite (id, Thm.prop_of thm),
|
neuper@41995
|
527 |
Rewrite' ("Isac", fst ro, erls, false, rule2thm' r, t, (t', a)),
|
neuper@41995
|
528 |
(e_pos'(*to be updated before generate tacis!!!*), (Uistate, e_ctxt)))
|
neuper@37906
|
529 |
| mk_tacis ro erls (t, r as Rls_ rls, (t', a)) =
|
neuper@41995
|
530 |
(Rewrite_Set (rule2rls' r),
|
neuper@41995
|
531 |
Rewrite_Set' ("Isac", false, rls, t, (t', a)),
|
neuper@41995
|
532 |
(e_pos'(*to be updated before generate tacis!!!*), (Uistate, e_ctxt)));
|
neuper@37906
|
533 |
|
neuper@37906
|
534 |
(*fo = ifo excluded already in inform*)
|
neuper@37906
|
535 |
fun concat_deriv rew_ord erls rules fo ifo =
|
neuper@55487
|
536 |
let
|
neuper@55487
|
537 |
fun derivat ([]:(term * rule * (term * term list)) list) = e_term
|
neuper@55487
|
538 |
| derivat dt = (#1 o #3 o last_elem) dt
|
neuper@55487
|
539 |
fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1=t2
|
neuper@55487
|
540 |
val fod = make_deriv (Isac"") erls rules (snd rew_ord) NONE fo
|
neuper@55487
|
541 |
val ifod = make_deriv (Isac"") erls rules (snd rew_ord) NONE ifo
|
neuper@55487
|
542 |
in
|
neuper@55487
|
543 |
case (fod, ifod) of
|
neuper@55487
|
544 |
([], []) => if fo = ifo then (true, []) else (false, [])
|
neuper@55487
|
545 |
| (fod, []) => if derivat fod = ifo then (true, fod) (*ifo is normal form*) else (false, [])
|
neuper@55487
|
546 |
| ([], ifod) => if fo = derivat ifod then (true, ((map rev_deriv') o rev) ifod) else (false, [])
|
neuper@55487
|
547 |
| (fod, ifod) =>
|
neuper@55487
|
548 |
if derivat fod = derivat ifod (*common normal form found*)
|
neuper@55487
|
549 |
then
|
neuper@55487
|
550 |
let
|
neuper@55487
|
551 |
val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod)
|
neuper@55487
|
552 |
in (true, fod' @ (map rev_deriv' rifod')) end
|
neuper@55487
|
553 |
else (false, [])
|
neuper@55487
|
554 |
end;
|
neuper@37906
|
555 |
(*
|
neuper@37906
|
556 |
val ({rew_ord, erls, rules,...}, fo, ifo) =
|
neuper@37906
|
557 |
(rep_rls Test_simplify, str2term "x+1+ -1*2=0", str2term "-2*1+(x+1)=0");
|
neuper@38015
|
558 |
(tracing o trtas2str) fod';
|
neuper@37906
|
559 |
> ["
|
neuper@37906
|
560 |
(x + 1 + -1 * 2 = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (x + 1) = 0, []))","
|
neuper@37906
|
561 |
(-1 * 2 + (x + 1) = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (1 + x) = 0, []))","
|
neuper@37906
|
562 |
(-1 * 2 + (1 + x) = 0, Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (-1 * 2 + x) = 0, []))","
|
neuper@37906
|
563 |
(1 + (-1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))","-1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
|
neuper@37906
|
564 |
val it = () : unit
|
neuper@38015
|
565 |
(tracing o trtas2str) (map rev_deriv' rifod');
|
neuper@37906
|
566 |
> ["
|
neuper@37906
|
567 |
(1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))","-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))","
|
neuper@37906
|
568 |
(1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))","
|
neuper@37906
|
569 |
(-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute","?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
|
neuper@37906
|
570 |
val it = () : unit
|
neuper@37906
|
571 |
*)
|
neuper@37906
|
572 |
|
neuper@37906
|
573 |
|
neuper@41995
|
574 |
(* compare inform with ctree.form at current pos by nrls;
|
neuper@37906
|
575 |
if found, embed the derivation generated during comparison
|
neuper@41995
|
576 |
if not, let the mat-engine compute the next ctree.form *)
|
neuper@37906
|
577 |
(*structure copied from complete_solve
|
neuper@37906
|
578 |
CAUTION: tacis in returned calcstate' do NOT construct resulting ptp --
|
neuper@37906
|
579 |
all_modspec etc. has to be inserted at Subproblem'*)
|
neuper@37906
|
580 |
fun compare_step ((tacis, c, ptp as (pt, pos as (p,p_))): calcstate') ifo =
|
neuper@41995
|
581 |
let
|
neuper@41995
|
582 |
val fo =
|
neuper@41995
|
583 |
case p_ of
|
neuper@41995
|
584 |
Frm => get_obj g_form pt p
|
neuper@41995
|
585 |
| Res => (fst o (get_obj g_result pt)) p
|
neuper@41995
|
586 |
| _ => e_term (*on PblObj is fo <> ifo*);
|
neuper@41995
|
587 |
val {nrls, ...} = get_met (get_obj g_metID pt (par_pblobj pt p))
|
neuper@41995
|
588 |
val {rew_ord, erls, rules, ...} = rep_rls nrls
|
neuper@42423
|
589 |
val (found, der) = concat_deriv rew_ord erls rules fo ifo; (*<---------------*)
|
neuper@41995
|
590 |
in
|
neuper@41995
|
591 |
if found
|
neuper@41995
|
592 |
then
|
neuper@41995
|
593 |
let
|
neuper@41995
|
594 |
val tacis' = map (mk_tacis rew_ord erls) der;
|
neuper@41995
|
595 |
val (c', ptp) = embed_deriv tacis' ptp;
|
neuper@41995
|
596 |
in ("ok", (tacis (*@ tacis'?WN050408*), c @ c', ptp)) end
|
neuper@41995
|
597 |
else
|
neuper@55487
|
598 |
if pos = ([], Res) (*TODO: we should stop earlier with trying subproblems *)
|
neuper@41995
|
599 |
then ("no derivation found", (tacis, c, ptp): calcstate')
|
neuper@41995
|
600 |
else
|
neuper@41995
|
601 |
let
|
neuper@42423
|
602 |
val cs' as (tacis, c', ptp) = nxt_solve_ ptp; (*<---------------------*)
|
neuper@41995
|
603 |
val cs' as (tacis, c'', ptp) =
|
neuper@41995
|
604 |
case tacis of
|
neuper@41995
|
605 |
((Subproblem _, _, _)::_) =>
|
neuper@41995
|
606 |
let
|
neuper@55487
|
607 |
val ptp as (pt, (p,_)) = all_modspec ptp (*<------------------*)
|
neuper@41995
|
608 |
val mI = get_obj g_metID pt p
|
neuper@42423
|
609 |
in
|
neuper@42423
|
610 |
nxt_solv (Apply_Method' (mI, NONE, e_istate, e_ctxt)) (e_istate, e_ctxt) ptp
|
neuper@41995
|
611 |
end
|
neuper@41995
|
612 |
| _ => cs';
|
neuper@41995
|
613 |
in compare_step (tacis, c @ c' @ c'', ptp) ifo end
|
neuper@41995
|
614 |
end;
|
neuper@37906
|
615 |
|
neuper@42428
|
616 |
(* check if (agreed result, input formula) matches the error pattern "pat" modulo simplifier rls *)
|
neuper@42426
|
617 |
fun check_err_patt (res, inf) (subst: subst) (errpatID: errpatID, pat) rls =
|
neuper@42423
|
618 |
let
|
neuper@42423
|
619 |
val (res', _, _, rewritten) =
|
neuper@42426
|
620 |
rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
|
neuper@42423
|
621 |
in
|
neuper@42423
|
622 |
if rewritten
|
neuper@42423
|
623 |
then
|
neuper@42423
|
624 |
let
|
neuper@42426
|
625 |
val norm_res = case rewrite_set_inst_ (Isac()) false subst rls res' of
|
neuper@42423
|
626 |
NONE => res'
|
neuper@42423
|
627 |
| SOME (norm_res, _) => norm_res
|
neuper@42426
|
628 |
val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
|
neuper@42423
|
629 |
NONE => inf
|
neuper@42423
|
630 |
| SOME (norm_inf, _) => norm_inf
|
neuper@42423
|
631 |
in if norm_res = norm_inf then SOME errpatID else NONE
|
neuper@42423
|
632 |
end
|
neuper@42423
|
633 |
else NONE
|
neuper@42423
|
634 |
end;
|
neuper@42423
|
635 |
|
neuper@42428
|
636 |
(* check if (agreed result, input formula) matches SOME error pattern modulo simplifier rls;
|
neuper@42428
|
637 |
(prog, env) for retrieval of casual substitution for bdv in the pattern. *)
|
neuper@42428
|
638 |
fun check_error_patterns (res, inf) (prog, env) (errpats, rls) =
|
neuper@42428
|
639 |
let
|
neuper@42433
|
640 |
val (_, subst) = get_bdv_subst prog env
|
neuper@42428
|
641 |
fun scan (_, [], _) = NONE
|
neuper@42428
|
642 |
| scan (errpatID, errpat :: errpats, _) =
|
neuper@42428
|
643 |
case check_err_patt (res, inf) (subst: subst) (errpatID, errpat) rls of
|
neuper@42428
|
644 |
NONE => scan (errpatID, errpats, [])
|
neuper@42428
|
645 |
| SOME errpatID => SOME errpatID
|
neuper@42428
|
646 |
fun scans [] = NONE
|
neuper@42428
|
647 |
| scans (group :: groups) =
|
neuper@42428
|
648 |
case scan group of
|
neuper@42428
|
649 |
NONE => scans groups
|
neuper@42428
|
650 |
| SOME errpatID => SOME errpatID
|
neuper@42428
|
651 |
in scans errpats end;
|
neuper@42428
|
652 |
|
neuper@37906
|
653 |
(*.handle a user-input formula, which may be a CAS-command, too.
|
neuper@37906
|
654 |
CAS-command:
|
neuper@37906
|
655 |
create a calchead, and do 1 step
|
neuper@37906
|
656 |
TOOODO.WN0602 works only for the root-problem !!!
|
neuper@37906
|
657 |
formula, which is no CAS-command:
|
neuper@37906
|
658 |
compare iform with calc-tree.form at pos by equ_nrls and all subsequent pos;
|
neuper@42423
|
659 |
collect all the tacs applied by the way;
|
neuper@42426
|
660 |
if "no derivation found" then check_error_patterns.
|
neuper@42427
|
661 |
ALTERNATIVE: check_error_patterns _within_ compare_step seems too expensive.*)
|
neuper@37906
|
662 |
fun inform (cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate') istr =
|
neuper@42423
|
663 |
case parse (assoc_thy "Isac") istr of
|
neuper@42427
|
664 |
SOME f_in =>
|
neuper@42423
|
665 |
let
|
wneuper@59186
|
666 |
val f_in = Thm.term_of f_in
|
neuper@42431
|
667 |
val f_succ = get_curr_formula (pt, pos);
|
neuper@42423
|
668 |
in
|
neuper@42427
|
669 |
if f_succ = f_in
|
neuper@42423
|
670 |
then ("same-formula", cs) (* ctree not cut with replaceFormula *)
|
neuper@42423
|
671 |
else
|
neuper@42427
|
672 |
case cas_input f_in of
|
neuper@42423
|
673 |
SOME (pt, _) => ("ok",([], [], (pt, (p, Met))))
|
neuper@42423
|
674 |
| NONE =>
|
neuper@42428
|
675 |
let
|
neuper@42428
|
676 |
val pos_pred = lev_back' pos
|
neuper@42428
|
677 |
(* f_pred ---"step pos cs"---> f_succ in appendFormula *)
|
neuper@42431
|
678 |
val f_pred = get_curr_formula (pt, pos_pred)
|
neuper@42430
|
679 |
val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in (*<<=====*)
|
neuper@42426
|
680 |
(*last step re-calc in compare_step TODO before WN09*)
|
neuper@42423
|
681 |
in
|
neuper@42423
|
682 |
case msg_calcstate' of
|
neuper@42426
|
683 |
("no derivation found", calcstate') =>
|
neuper@42426
|
684 |
let
|
neuper@42426
|
685 |
val pp = par_pblobj pt p
|
neuper@48763
|
686 |
val {errpats, nrls, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
|
neuper@42427
|
687 |
val ScrState (env, _, _, _, _, _) = get_istate pt pos
|
neuper@42426
|
688 |
in
|
neuper@42428
|
689 |
case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
|
neuper@42426
|
690 |
SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
|
neuper@42426
|
691 |
| NONE => msg_calcstate'
|
neuper@42426
|
692 |
end
|
neuper@42423
|
693 |
| _ => msg_calcstate'
|
neuper@42423
|
694 |
end
|
neuper@42423
|
695 |
end
|
neuper@42426
|
696 |
| NONE => ("syntax error in '" ^ istr ^ "'", e_calcstate');
|
neuper@37906
|
697 |
|
neuper@42433
|
698 |
(* fill-in patterns an forms.
|
neuper@42433
|
699 |
returns thm required by "fun in_fillform *)
|
neuper@42433
|
700 |
fun get_fillform (subs_opt, subst) (thm, form) errpatID ((fillpatID, pat, erpaID): fillpat) =
|
neuper@42430
|
701 |
let
|
neuper@42430
|
702 |
val (form', _, _, rewritten) =
|
neuper@42430
|
703 |
rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
|
neuper@42430
|
704 |
in (*the fillpat of the thm must be dedicated to errpatID*)
|
neuper@42430
|
705 |
if errpatID = erpaID andalso rewritten
|
neuper@42433
|
706 |
then SOME (fillpatID, HOLogic.mk_eq (form, form'), thm, subs_opt) else NONE end;
|
neuper@42430
|
707 |
|
neuper@42430
|
708 |
fun get_fillpats subst form errpatID thm =
|
neuper@42430
|
709 |
let
|
neuper@42430
|
710 |
val thmDeriv = Thm.get_name_hint thm
|
neuper@42430
|
711 |
val (part, thyID) = thy_containing_thm thmDeriv
|
neuper@42430
|
712 |
val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
|
neuper@42430
|
713 |
val Hthm {fillpats, ...} = get_the theID
|
neuper@42433
|
714 |
val some = map (get_fillform subst (thm, form) errpatID) fillpats
|
neuper@42430
|
715 |
in some |> filter is_some |> map the end;
|
neuper@42430
|
716 |
|
neuper@42430
|
717 |
fun find_fillpatterns (pt, pos as (p, _): pos') errpatID =
|
neuper@42430
|
718 |
let
|
neuper@42436
|
719 |
val f_curr = get_curr_formula (pt, pos);
|
neuper@42430
|
720 |
val pp = par_pblobj pt p
|
neuper@48763
|
721 |
val {errpats, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
|
neuper@42430
|
722 |
val ScrState (env, _, _, _, _, _) = get_istate pt pos
|
neuper@42430
|
723 |
val subst = get_bdv_subst prog env
|
neuper@42430
|
724 |
val errpatthms = errpats
|
neuper@42430
|
725 |
|> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
|
neuper@42430
|
726 |
|> map (#3: errpat -> thm list)
|
neuper@42430
|
727 |
|> flat
|
neuper@42430
|
728 |
in map (get_fillpats subst f_curr errpatID) errpatthms |> flat end;
|
neuper@37906
|
729 |
|
neuper@42437
|
730 |
(* check if an input formula is exactly equal the rewrite from a rule
|
neuper@42437
|
731 |
which is stored at the pos where the input is stored of "ok". *)
|
neuper@42437
|
732 |
fun is_exactly_equal (pt, pos as (p, _)) istr =
|
neuper@42437
|
733 |
case parseNEW (assoc_thy "Isac" |> thy2ctxt) istr of
|
neuper@42437
|
734 |
NONE => ("syntax error in '" ^ istr ^ "'", Tac "")
|
neuper@42437
|
735 |
| SOME ifo =>
|
neuper@42437
|
736 |
let
|
neuper@42437
|
737 |
val p' = lev_on p;
|
neuper@42437
|
738 |
val tac = get_obj g_tac pt p';
|
neuper@42437
|
739 |
in
|
neuper@42437
|
740 |
case applicable_in pos pt tac of
|
neuper@42437
|
741 |
Notappl msg => (msg, Tac "")
|
neuper@42437
|
742 |
| Appl rew =>
|
neuper@42437
|
743 |
let
|
neuper@42437
|
744 |
val res = case rew of
|
neuper@42437
|
745 |
Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) => res
|
neuper@42437
|
746 |
| Rewrite' (_, _, _, _, _, _, (res, _)) => res
|
neuper@42437
|
747 |
in
|
neuper@42437
|
748 |
if not (ifo = res)
|
neuper@42437
|
749 |
then ("input does not exactly fill the gaps", Tac "")
|
neuper@42437
|
750 |
else ("ok", tac)
|
neuper@42437
|
751 |
end
|
neuper@42437
|
752 |
end
|
neuper@42437
|
753 |
|
neuper@42458
|
754 |
(* fetch errpatIDs from an arbitrary tactic *)
|
neuper@42458
|
755 |
fun fetchErrorpatterns tac =
|
neuper@42458
|
756 |
let
|
neuper@42458
|
757 |
val rlsID =
|
neuper@42458
|
758 |
case tac of
|
neuper@42458
|
759 |
Rewrite_Set rlsID => rlsID
|
neuper@42458
|
760 |
| Rewrite_Set_Inst (_, rlsID) => rlsID
|
neuper@55415
|
761 |
| _ => "e_rls"
|
neuper@42458
|
762 |
val (part, thyID) = thy_containing_rls "Isac" rlsID;
|
neuper@42458
|
763 |
val Hrls {thy_rls = (_, rls), ...} = get_the [part, thyID, "Rulesets", rlsID]
|
neuper@42458
|
764 |
in case rls of
|
neuper@42458
|
765 |
Rls {errpatts, ...} => errpatts
|
neuper@42458
|
766 |
| Seq {errpatts, ...} => errpatts
|
neuper@42458
|
767 |
| Rrls {errpatts, ...} => errpatts
|
neuper@42458
|
768 |
| Erls => []
|
neuper@42458
|
769 |
end
|
neuper@42458
|
770 |
|
neuper@37906
|
771 |
(*------------------------------------------------------------------(**)
|
neuper@37906
|
772 |
end
|
neuper@37906
|
773 |
open inform;
|
neuper@37906
|
774 |
(**)------------------------------------------------------------------*)
|