walther@59983
|
1 |
(* Title: MathEngine/me-misc.sml
|
walther@59983
|
2 |
Author: Walther Neuper
|
walther@59983
|
3 |
(c) due to copyright terms
|
walther@59983
|
4 |
|
walther@59983
|
5 |
Code from Specify/* to be re-allocated in MathEngine/* and later.
|
walther@59983
|
6 |
*)
|
walther@59983
|
7 |
signature MATHENGINE_MISCELLANEOUS =
|
walther@59983
|
8 |
sig
|
Walther@60576
|
9 |
val pt_extract : Proof.context -> Calc.T -> Ctree.ptform * Tactic.input option * term list
|
Walther@60576
|
10 |
val get_interval : Proof.context -> Pos.pos' -> Pos.pos' -> int -> Ctree.ctree -> (Pos.pos' * term * Tactic.input option) list
|
Walther@60576
|
11 |
(*should be in isac_test*)
|
Walther@60576
|
12 |
val pt_model: Ctree.ppobj -> Pos.pos_ -> Ctree.ptform
|
Walther@60576
|
13 |
val pt_form: Ctree.ppobj -> Ctree.ptform
|
Walther@60576
|
14 |
\<^isac_test>\<open>
|
Walther@60576
|
15 |
(**)
|
Walther@60576
|
16 |
\<close>
|
walther@59983
|
17 |
end
|
walther@59983
|
18 |
|
walther@59983
|
19 |
(**)
|
walther@59983
|
20 |
structure ME_Misc(**): MATHENGINE_MISCELLANEOUS(**) =
|
walther@59983
|
21 |
struct
|
walther@59983
|
22 |
(**)
|
walther@59983
|
23 |
|
Walther@60729
|
24 |
(*T_TESTold* )
|
Walther@60557
|
25 |
fun pt_model (Ctree.PblObj {meth, spec, origin = (_, spec', hdl), ctxt, ...}) Pos.Met =
|
walther@59983
|
26 |
let
|
walther@59983
|
27 |
val (_, _, metID) = Ctree.get_somespec' spec spec'
|
Walther@60586
|
28 |
val where_ = if metID = MethodC.id_empty then []
|
walther@59983
|
29 |
else
|
walther@59983
|
30 |
let
|
Walther@60586
|
31 |
val {where_rls, where_ = where_, ...} = MethodC.from_store ctxt metID
|
Walther@60590
|
32 |
val (_, where_) = Pre_Conds.check ctxt where_rls where_ meth 0
|
Walther@60586
|
33 |
in where_ end
|
Walther@60586
|
34 |
val allcorrect = I_Model.is_complete meth andalso foldl and_ (true, (map #1 where_))
|
walther@59983
|
35 |
in
|
Walther@60586
|
36 |
Ctree.ModSpec (allcorrect, Pos.Met, hdl, meth, where_, spec)
|
walther@59983
|
37 |
end
|
Walther@60729
|
38 |
( *T_TEST**)
|
Walther@60729
|
39 |
fun pt_model (Ctree.PblObj {meth, spec, origin = (_, spec', hdl), ctxt, ...}) Pos.Met =
|
Walther@60729
|
40 |
let
|
Walther@60729
|
41 |
val (_, _, metID) = Ctree.get_somespec' spec spec'
|
Walther@60729
|
42 |
val where_ = if metID = MethodC.id_empty then []
|
Walther@60729
|
43 |
else
|
Walther@60729
|
44 |
let
|
Walther@60729
|
45 |
val {where_rls, where_, model, ...} = MethodC.from_store ctxt metID
|
Walther@60729
|
46 |
val (_, where_) = Pre_Conds.check_OLD ctxt where_rls where_
|
Walther@60729
|
47 |
(model, I_Model.OLD_to_TEST meth)
|
Walther@60729
|
48 |
in where_ end
|
Walther@60729
|
49 |
val allcorrect = I_Model.is_complete meth andalso foldl and_ (true, (map #1 where_))
|
Walther@60729
|
50 |
in
|
Walther@60729
|
51 |
Ctree.ModSpec (allcorrect, Pos.Met, hdl, meth, where_, spec)
|
Walther@60729
|
52 |
end
|
Walther@60729
|
53 |
(*T_TESTnew*)
|
Walther@60728
|
54 |
(*T_TESTold* )
|
Walther@60576
|
55 |
| pt_model (Ctree.PblObj {probl, spec, origin = (_, spec', hdl), ctxt, ...}) _(*Frm,Pbl*) =
|
walther@59983
|
56 |
let
|
Walther@60576
|
57 |
val (_, pI, _) = Ctree.get_somespec' spec spec'
|
Walther@60586
|
58 |
val where_ = if pI = Problem.id_empty then []
|
walther@59983
|
59 |
else
|
walther@59983
|
60 |
let
|
Walther@60585
|
61 |
val {where_rls, where_, ...} = Problem.from_store ctxt pI
|
Walther@60590
|
62 |
val (_, where_) = Pre_Conds.check ctxt where_rls where_ probl 0
|
Walther@60586
|
63 |
in where_ end
|
Walther@60586
|
64 |
val allcorrect = I_Model.is_complete probl andalso foldl and_ (true, (map #1 where_))
|
walther@59983
|
65 |
in
|
Walther@60586
|
66 |
Ctree.ModSpec (allcorrect, Pos.Pbl, hdl, probl, where_, spec)
|
walther@59983
|
67 |
end
|
Walther@60728
|
68 |
( *T_TEST*)
|
Walther@60723
|
69 |
| pt_model (Ctree.PblObj {probl, spec, origin = (_, spec', hdl), ctxt, ...}) _(*Frm,Pbl*) =
|
Walther@60723
|
70 |
let
|
Walther@60723
|
71 |
val (_, pI, _) = Ctree.get_somespec' spec spec'
|
Walther@60723
|
72 |
val where_ = if pI = Problem.id_empty then []
|
Walther@60723
|
73 |
else
|
Walther@60723
|
74 |
let
|
Walther@60723
|
75 |
val {where_rls, where_, model, ...} = Problem.from_store ctxt pI
|
Walther@60723
|
76 |
val (_, where_) = Pre_Conds.check_OLD ctxt where_rls where_
|
Walther@60723
|
77 |
(model, I_Model.OLD_to_TEST probl)
|
Walther@60723
|
78 |
in where_ end
|
Walther@60723
|
79 |
val allcorrect = I_Model.is_complete probl andalso foldl and_ (true, (map #1 where_))
|
Walther@60723
|
80 |
in
|
Walther@60723
|
81 |
Ctree.ModSpec (allcorrect, Pos.Pbl, hdl, probl, where_, spec)
|
Walther@60723
|
82 |
end
|
Walther@60728
|
83 |
(*T_TESTnew*)
|
Walther@60723
|
84 |
| pt_model _ _ = raise ERROR "pt_model: uncovered definition"
|
walther@59983
|
85 |
|
walther@59983
|
86 |
fun pt_form (Ctree.PrfObj {form, ...}) = Ctree.Form form
|
Walther@60576
|
87 |
| pt_form (Ctree.PblObj {probl, spec, origin = (_, spec', _), ctxt, ...}) =
|
walther@59983
|
88 |
let
|
walther@59983
|
89 |
val (dI, pI, _) = Ctree.get_somespec' spec spec'
|
Walther@60733
|
90 |
val {cas, model, ...} = Problem.from_store ctxt pI
|
Walther@60733
|
91 |
val env_model = Pre_Conds.environment_TEST model (I_Model.OLD_to_TEST probl)
|
walther@59983
|
92 |
in case cas of
|
Walther@60559
|
93 |
NONE => Ctree.Form (Auto_Prog.pblterm dI pI)
|
Walther@60733
|
94 |
| SOME t => Ctree.Form (subst_atomic env_model t)
|
walther@59983
|
95 |
end
|
walther@59983
|
96 |
|
walther@59983
|
97 |
(* pt_extract returns
|
walther@59983
|
98 |
# the formula at pos
|
walther@59983
|
99 |
# the tactic applied to this formula
|
walther@59983
|
100 |
# the list of assumptions generated at this formula
|
walther@59983
|
101 |
(by application of another tac to the preceding formula !)
|
walther@59983
|
102 |
pos is assumed to come from the frontend, ie. generated by moveDown.
|
walther@59983
|
103 |
Notes: cannot be in ctree.sml, because ModSpec has to be calculated.
|
walther@59983
|
104 |
TODO 110417 get assumptions from ctxt !?
|
walther@59983
|
105 |
*)
|
Walther@60576
|
106 |
fun pt_extract ctxt (pt, ([], Pos.Res)) =
|
walther@59983
|
107 |
(* WN120512: returns Check_Postcondition WRONGLY see --- build fun is_exactly_equal *)
|
walther@59983
|
108 |
let
|
walther@59983
|
109 |
val (f, asm) = Ctree.get_obj Ctree.g_result pt []
|
walther@59983
|
110 |
in (Ctree.Form f, NONE, asm) end
|
Walther@60576
|
111 |
| pt_extract ctxt (pt, (p, Pos.Res)) =
|
walther@59983
|
112 |
let
|
walther@59983
|
113 |
val (f, asm) = Ctree.get_obj Ctree.g_result pt p
|
walther@59983
|
114 |
val tac =
|
walther@59983
|
115 |
if Ctree.last_onlev pt p
|
walther@59983
|
116 |
then
|
walther@59983
|
117 |
if Ctree.is_pblobj' pt (Pos.lev_up p)
|
walther@59983
|
118 |
then
|
walther@59983
|
119 |
let
|
walther@59983
|
120 |
val pI = case Ctree.get_obj I pt (Pos.lev_up p) of
|
walther@59983
|
121 |
Ctree.PblObj{spec = (_, pI, _), ...} => pI
|
walther@59983
|
122 |
| _ => raise ERROR "pt_extract last_onlev: uncovered case get_obj"
|
walther@59983
|
123 |
in if pI = Problem.id_empty then NONE else SOME (Tactic.Check_Postcond pI) end
|
walther@59983
|
124 |
else SOME Tactic.End_Trans (* WN0502 TODO for other branches *)
|
walther@59983
|
125 |
else
|
walther@59983
|
126 |
let val p' = Pos.lev_on p
|
walther@59983
|
127 |
in
|
walther@59983
|
128 |
if Ctree.is_pblobj' pt p'
|
walther@59983
|
129 |
then
|
walther@59983
|
130 |
let
|
walther@59983
|
131 |
val (dI , pI) = case Ctree.get_obj I pt p' of
|
walther@59983
|
132 |
Ctree.PblObj{origin = (_, (dI, pI, _), _), ...} => (dI ,pI)
|
walther@59983
|
133 |
| _ => raise ERROR "pt_extract \<not>last_onlev: uncovered case get_obj"
|
walther@59983
|
134 |
in SOME (Tactic.Subproblem (dI, pI)) end
|
walther@59983
|
135 |
else
|
walther@59983
|
136 |
if f = Ctree.get_obj Ctree.g_form pt p'
|
walther@59983
|
137 |
then SOME (Ctree.get_obj Ctree.g_tac pt p') (*because this Frm ~~~is not on worksheet*)
|
Walther@60675
|
138 |
else SOME (Tactic.Take (UnparseC.term ctxt (Ctree.get_obj Ctree.g_form pt p')))
|
walther@59983
|
139 |
end
|
walther@59983
|
140 |
in (Ctree.Form f, tac, asm) end
|
Walther@60576
|
141 |
| pt_extract ctxt (pt, (p, p_(*Frm,Pbl*))) =
|
walther@59983
|
142 |
let
|
walther@59983
|
143 |
val ppobj = Ctree.get_obj I pt p
|
walther@59983
|
144 |
val f = if Ctree.is_pblobj ppobj then pt_model ppobj p_ else Ctree.get_obj pt_form pt p
|
walther@59983
|
145 |
val tac = Ctree.g_tac ppobj
|
walther@59983
|
146 |
in (f, SOME tac, []) end
|
walther@59983
|
147 |
|
walther@59983
|
148 |
|
walther@59983
|
149 |
(** get an 'interval' 'from' 'to' of formulae from a ctree **)
|
walther@59983
|
150 |
|
walther@59983
|
151 |
(* WN0401 this functionality belongs to ctree.sml *)
|
walther@59983
|
152 |
fun eq_pos' (p1, Pos.Frm) (p2, Pos.Frm) = p1 = p2
|
walther@59983
|
153 |
| eq_pos' (p1, Pos.Res) (p2, Pos.Res) = p1 = p2
|
walther@59983
|
154 |
| eq_pos' (p1, Pos.Pbl) (p2, p2_) =
|
walther@59983
|
155 |
p1 = p2 andalso (case p2_ of Pos.Pbl => true | Pos.Met => true | _ => false)
|
walther@59983
|
156 |
| eq_pos' (p1, Pos.Met) (p2, p2_) =
|
walther@59983
|
157 |
p1 = p2 andalso (case p2_ of Pos.Pbl => true | Pos.Met => true | _ => false)
|
walther@59983
|
158 |
| eq_pos' _ _ = false;
|
walther@59983
|
159 |
|
walther@59983
|
160 |
(* get an 'interval' from the ctree; 'interval' is w.r.t. the
|
walther@59983
|
161 |
total ordering Position#compareTo(Position p) in the java-code
|
walther@59983
|
162 |
val get_interval = fn :
|
walther@59983
|
163 |
pos' -> : from is "move_up 1st-element" to return
|
walther@59983
|
164 |
pos' -> : to the last element to be returned; from < to
|
walther@59983
|
165 |
int -> : level: 0 gets the flattest sub-tree possible, 999 the deepest
|
walther@59983
|
166 |
ctree -> :
|
walther@59983
|
167 |
(pos' * : of the formula
|
walther@59983
|
168 |
Term.term) : the formula
|
walther@59983
|
169 |
list *)
|
Walther@60576
|
170 |
fun get_interval ctxt from to level pt =
|
walther@59983
|
171 |
let
|
walther@59983
|
172 |
fun get_inter c (from) (to) lev pt =
|
walther@59983
|
173 |
if eq_pos' from to orelse from = ([], Pos.Res)
|
walther@59983
|
174 |
then
|
Walther@60576
|
175 |
let val (f, tacopt, _) = pt_extract ctxt (pt, from)
|
walther@59983
|
176 |
in case f of
|
walther@59983
|
177 |
Ctree.ModSpec (_, _, headline, _, _, _) => c @ [(from, headline, NONE)]
|
walther@59983
|
178 |
| Ctree.Form t => c @ [(from, t, tacopt)]
|
walther@59983
|
179 |
end
|
walther@59983
|
180 |
else
|
walther@59983
|
181 |
if lev < Pos.lev_of from
|
walther@59983
|
182 |
then (get_inter c (Ctree.move_dn [] pt from) to lev pt)
|
walther@59983
|
183 |
handle (Ctree.PTREE _(*from move_dn too far*)) => c
|
walther@59983
|
184 |
else
|
walther@59983
|
185 |
let
|
Walther@60576
|
186 |
val (f, tacopt, _) = pt_extract ctxt (pt, from)
|
walther@59983
|
187 |
val term = case f of
|
walther@59983
|
188 |
Ctree.ModSpec (_,_,headline,_,_,_) => headline
|
walther@59983
|
189 |
| Ctree.Form t => t
|
walther@59983
|
190 |
in (get_inter (c @ [(from, term, tacopt)]) (Ctree.move_dn [] pt from) to lev pt)
|
walther@59983
|
191 |
handle (Ctree.PTREE _(*from move_dn too far*)) => c @ [(from, term, tacopt)]
|
walther@59983
|
192 |
end
|
walther@59983
|
193 |
in get_inter [] from to level pt end
|
walther@59983
|
194 |
|
Walther@60576
|
195 |
(**)end(*struct*)
|