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