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