walther@59978
|
1 |
(* Title: Specify/specification.sml
|
walther@59978
|
2 |
Author: Walther Neuper, Mathias Lehnfeld
|
neuper@37906
|
3 |
(c) due to copyright terms
|
wneuper@59265
|
4 |
*)
|
wneuper@59540
|
5 |
(* Survey on type fmz_ .. type ori .. type itm (in probl, meth) .. formal args of root-/SubProblem
|
wneuper@59540
|
6 |
and relations between respective list elements: #1#
|
wneuper@59540
|
7 |
fmz = [ dsc $ v......................................(dsc $ v)..]
|
wneuper@59540
|
8 |
root problem on pos = ([], _)
|
wneuper@59540
|
9 |
fmz_ = [(dsc, v).......................................(dsc, v)..]
|
wneuper@59540
|
10 |
\<down>
|
wneuper@59540
|
11 |
oris = [(dsc, v)..(dsc, v),(dsc, v),(dsc, v)...........(dsc, v)..]
|
wneuper@59540
|
12 |
\<down> #Given,..,#Relate #Find #undef............#undef \<down>
|
wneuper@59540
|
13 |
\<down> \<down> \<down> \<down>
|
wneuper@59540
|
14 |
Specify_Problem + pbl.ppc= [(dsc,id)..(dsc,id),(dsc,id)] \<down> \<down> \<down>
|
wneuper@59540
|
15 |
\<down> \<down> \<down> \<down>
|
wneuper@59540
|
16 |
itms = [(dsc, v)..(dsc, v),(dsc, v)] \<down> \<down> \<down>
|
wneuper@59540
|
17 |
int.modelling +Cor ++++++++++Cor +Cor \<down> \<down> \<down>
|
wneuper@59540
|
18 |
\<down> \<down> \<down> \<down>
|
wneuper@59540
|
19 |
Specify_Method + met.ppc= [(dsc,id)..(dsc,id),(dsc,id)] \<down> \<down> \<down>
|
wneuper@59540
|
20 |
\<down> \<down> \<down> \<down>
|
wneuper@59540
|
21 |
itms = [(dsc, v)..(dsc, v),(dsc, v),(dsc, v)..(dsc, v)] \<down> \<down>
|
wneuper@59540
|
22 |
int.modelling +Cor ++++++Cor \<down> \<down>
|
wneuper@59540
|
23 |
form.args= [ id ..... id , /////// id ....... id ] \<down> \<down>
|
wneuper@59540
|
24 |
env = [(id, v)..(id, v) , /////// (id, v)....(id, v)] \<down> \<down>
|
walther@59718
|
25 |
interpret code env = [(id, v)..(id, v),(id, v)..(id, v) , /////// (id, v)....(id, v)] \<down> \<down>
|
wneuper@59540
|
26 |
..extends env ^^^^^^^^^^^^^^^^ \<down> \<down> \<down> \<down> \<down>
|
wneuper@59540
|
27 |
\<down> \<down> \<down> \<down> \<down> \<down>
|
wneuper@59540
|
28 |
SubProblem on pos = ([2], _) \<down> \<down> \<down> \<down> \<down> \<down>
|
wneuper@59540
|
29 |
form.args= [id ................................ id ]\<down> \<down> \<down>
|
wneuper@59540
|
30 |
\<down> REAL..BOOL.. \<down> \<down> \<down>
|
wneuper@59540
|
31 |
\<down> \<down> \<down> \<down>
|
wneuper@59540
|
32 |
+ met.ppc= [(dsc,id).......................(dsc,id)]\<down> \<down> \<down>
|
wneuper@59540
|
33 |
\<down> \<down> \<down> \<down> \<down>
|
wneuper@59540
|
34 |
oris = [(dsc, v)...................... (dsc, v) ........... (dsc, v)]\<down>
|
walther@59718
|
35 |
Specify_Problem, int.modelling, Specify_Method, interpret code as above #1# \<down>
|
wneuper@59540
|
36 |
\<down>
|
wneuper@59540
|
37 |
SubProblem on pos = ([3, 4], _) \<down>
|
wneuper@59540
|
38 |
form.args= [id ...................... id ] \<down>
|
wneuper@59540
|
39 |
\<down> REAL..BOOL.. \<down>
|
wneuper@59540
|
40 |
+ met.ppc= [(dsc,id).............(dsc,id)] \<down>
|
wneuper@59540
|
41 |
oris = [(dsc, v).............(dsc, v)...................(dsc, v)]
|
walther@59718
|
42 |
Specify_Problem, int.modelling, Specify_Method, interpret code as above #1#
|
wneuper@59540
|
43 |
|
wneuper@59540
|
44 |
Notes:
|
wneuper@59540
|
45 |
(1) SubProblem implements sub-function calls such, that the arguments (+ pre- + post-condition)
|
wneuper@59540
|
46 |
of the functions become concern of interactive modelling.
|
wneuper@59540
|
47 |
(2) In Isac-terms, the above concerns the phases of modelling and
|
wneuper@59540
|
48 |
and of specifying (Specify_Problem, Specify_Method),
|
wneuper@59540
|
49 |
while stepwise construction of solutions is called solving.
|
wneuper@59540
|
50 |
The latter is supported by Lucas-Interpretation of the functions' body.
|
wneuper@59540
|
51 |
(3) ori list is determined by fmz_ (in root-pbl) or by args of SubProblem;
|
wneuper@59540
|
52 |
it is as complete as possible (this has been different up to now).
|
wneuper@59540
|
53 |
(4) itm list is initialised by pbl-ppc | met-pps and completed (Cor) by stepwise user input.
|
wneuper@59550
|
54 |
(5) model-pattern of pbl can omit technical items, e.g. boundVariable or functionName,
|
wneuper@59550
|
55 |
add them to the model-pattern of met and let this input be done automatically;
|
wneuper@59550
|
56 |
respective items must be in fmz.
|
wneuper@59540
|
57 |
*)
|
walther@59977
|
58 |
signature SPECIFICATION =
|
wneuper@59265
|
59 |
sig
|
walther@59735
|
60 |
|
walther@59977
|
61 |
type T = Specification_Def.T
|
neuper@37906
|
62 |
|
walther@59984
|
63 |
(*val reset: Calc.T -> Calc.T*)
|
walther@59984
|
64 |
val reset_calchead: Calc.T -> Calc.T
|
walther@59984
|
65 |
(*val get: Calc.T -> T*)
|
walther@59984
|
66 |
val get_ocalhd: Calc.T -> T
|
walther@59984
|
67 |
(*val complete: I_Model.T -> Pre_Conds.T -> ThyC.id * Problem.id * Method.id -> bool*)
|
walther@59984
|
68 |
val ocalhd_complete: I_Model.T -> Pre_Conds.T -> ThyC.id * Problem.id * Method.id -> bool
|
walther@59984
|
69 |
(*val is_complete: Calc.T -> bool*)
|
walther@59984
|
70 |
val is_complete_mod: Calc.T -> bool
|
neuper@37906
|
71 |
|
wneuper@59310
|
72 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
walther@59981
|
73 |
(*NONE*)
|
walther@59886
|
74 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
walther@59985
|
75 |
val get: Calc.T -> I_Model.T * O_Model.T * References.T * I_Model.T * References.T * Proof.context
|
walther@59957
|
76 |
val make: I_Model.m_field -> TermC.as_string * I_Model.T -> Tactic.T
|
walther@59886
|
77 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
wneuper@59265
|
78 |
end
|
neuper@37906
|
79 |
|
walther@59763
|
80 |
(**)
|
walther@59986
|
81 |
structure Specification(** ): SPECIFICATION( **) =
|
neuper@37906
|
82 |
struct
|
walther@59763
|
83 |
(**)
|
walther@59957
|
84 |
|
walther@59977
|
85 |
type T = Specification_Def.T;
|
walther@59977
|
86 |
|
wneuper@59265
|
87 |
(* is the calchead complete ? *)
|
wneuper@59265
|
88 |
fun ocalhd_complete its pre (dI, pI, mI) =
|
walther@59939
|
89 |
foldl and_ (true, map #3 (its: I_Model.T)) andalso
|
walther@59963
|
90 |
foldl and_ (true, map #1 (pre: Pre_Conds.T)) andalso
|
walther@59903
|
91 |
dI <> ThyC.id_empty andalso pI <> Problem.id_empty andalso mI <> Method.id_empty
|
neuper@37906
|
92 |
|
walther@59943
|
93 |
fun is_parsed (I_Model.Syn _) = false
|
wneuper@59265
|
94 |
| is_parsed _ = true
|
neuper@37906
|
95 |
|
wneuper@59265
|
96 |
(* get the first term in ts from ori *)
|
wneuper@59308
|
97 |
fun getr_ct thy (_, _, fd, d, ts) =
|
walther@59953
|
98 |
(fd, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d,[hd ts]))
|
neuper@37906
|
99 |
|
neuper@38051
|
100 |
(* get a term from ori, notyet input in itm.
|
neuper@38051
|
101 |
the term from ori is thrown back to a string in order to reuse
|
neuper@38051
|
102 |
machinery for immediate input by the user. *)
|
wneuper@59308
|
103 |
fun geti_ct thy (_, _, _, d, ts) (_, _, _, fd, itm_) =
|
walther@59953
|
104 |
(fd, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, subtract op = (I_Model.ts_in itm_) ts))
|
neuper@37906
|
105 |
|
wneuper@59265
|
106 |
(* output the headline to a ppc *)
|
wneuper@59265
|
107 |
fun header p_ pI mI =
|
walther@59969
|
108 |
case p_ of
|
walther@59969
|
109 |
Pos.Pbl => Test_Out.Problem (if pI = Problem.id_empty then [] else pI)
|
walther@59969
|
110 |
| Pos.Met => Test_Out.Method mI
|
walther@59969
|
111 |
| pos => raise ERROR ("header called with "^ Pos.pos_2str pos)
|
neuper@37906
|
112 |
|
walther@59957
|
113 |
fun make m_field (term_as_string, i_model) =
|
walther@59957
|
114 |
case m_field of
|
walther@59957
|
115 |
"#Given" => Tactic.Add_Given' (term_as_string, i_model)
|
walther@59957
|
116 |
| "#Find" => Tactic.Add_Find' (term_as_string, i_model)
|
walther@59957
|
117 |
| "#Relate" => Tactic.Add_Relation'(term_as_string, i_model)
|
walther@59957
|
118 |
| str => raise ERROR ("specify_additem Frm, Pbl: uncovered case with " ^ str);
|
walther@59957
|
119 |
fun get (pt, (p, _)) =
|
walther@59957
|
120 |
case Ctree.get_obj I pt p of
|
walther@59957
|
121 |
(Ctree.PblObj {meth, origin = (oris, (dI', pI', mI'), _), probl, spec = (dI, pI, mI), ctxt, ...})
|
walther@59985
|
122 |
=> (meth, oris, (dI', pI', mI'), probl, (dI, pI, mI), ctxt)
|
walther@59957
|
123 |
| _ => raise ERROR "specify_additem: uncovered case of get_obj I pt p";
|
neuper@41994
|
124 |
|
wneuper@59265
|
125 |
(* fun tag_form thy (formal, given) = Thm.global_cterm_of thy
|
wneuper@59265
|
126 |
(((head_of o Thm.term_of) given) $ (Thm.term_of formal)); WN100819 *)
|
neuper@37934
|
127 |
fun tag_form thy (formal, given) =
|
neuper@52070
|
128 |
(let
|
neuper@52070
|
129 |
val gf = (head_of given) $ formal;
|
wneuper@59184
|
130 |
val _ = Thm.global_cterm_of thy gf
|
neuper@52070
|
131 |
in gf end)
|
walther@59962
|
132 |
handle _ => raise ERROR ("calchead.tag_form: " ^ UnparseC.term_in_thy thy given ^
|
walther@59870
|
133 |
" .. " ^ UnparseC.term_in_thy thy formal ^ " ..types do not match")
|
neuper@38053
|
134 |
|
walther@59969
|
135 |
fun is_complete_mod (pt, pos as (p, Pos.Pbl)) =
|
walther@59957
|
136 |
if (Ctree.is_pblobj o (Ctree.get_obj I pt)) p
|
walther@59988
|
137 |
then (I_Model.is_complete o (Ctree.get_obj Ctree.g_pbl pt)) p
|
walther@59962
|
138 |
else raise ERROR ("is_complete_mod: called by PrfObj at " ^ Pos.pos'2str pos)
|
walther@59969
|
139 |
| is_complete_mod (pt, pos as (p, Pos.Met)) =
|
walther@59957
|
140 |
if (Ctree.is_pblobj o (Ctree.get_obj I pt)) p
|
walther@59988
|
141 |
then (I_Model.is_complete o (Ctree.get_obj Ctree.g_met pt)) p
|
walther@59962
|
142 |
else raise ERROR ("is_complete_mod: called by PrfObj at " ^ Pos.pos'2str pos)
|
neuper@37906
|
143 |
| is_complete_mod (_, pos) =
|
walther@59962
|
144 |
raise ERROR ("is_complete_mod called by " ^ Pos.pos'2str pos ^ " (should be Pbl or Met)")
|
neuper@37906
|
145 |
|
walther@59969
|
146 |
(** get the formula from a ctree-node **)
|
walther@59969
|
147 |
(*
|
wneuper@59265
|
148 |
take form+res from PblObj and 1.PrfObj and (PrfObj after PblObj)
|
wneuper@59265
|
149 |
take res from all other PrfObj's
|
walther@59969
|
150 |
Designed for interSteps, outcommented 04 in favour of calcChangedEvent
|
walther@59969
|
151 |
*)
|
walther@59957
|
152 |
fun formres p (Ctree.Nd (Ctree.PblObj {origin = (_, _, h), result = (r, _), ...}, _)) =
|
walther@59957
|
153 |
[("headline", (p, Pos.Frm), h), ("stepform", (p, Pos.Res), r)]
|
walther@59957
|
154 |
| formres p (Ctree.Nd (Ctree.PrfObj {form, result = (r, _), ...}, _)) =
|
walther@59957
|
155 |
[("stepform", (p, Pos.Frm), form), ("stepform", (p, Pos.Res), r)]
|
walther@59962
|
156 |
| formres _ _ = raise ERROR "formres: uncovered definition"
|
walther@59957
|
157 |
fun form p (Ctree.Nd (Ctree.PrfObj {result = (r, _), ...}, _)) =
|
walther@59957
|
158 |
[("stepform", (p, Pos.Res), r)]
|
walther@59962
|
159 |
| form _ _ = raise ERROR "form: uncovered definition"
|
neuper@37906
|
160 |
|
wneuper@59265
|
161 |
(* get a calchead from a PblObj-node in the ctree; preconditions must be calculated *)
|
walther@59969
|
162 |
fun get_ocalhd (pt, (p, Pos.Pbl)) =
|
wneuper@59265
|
163 |
let
|
walther@59957
|
164 |
val (ospec, hdf', spec, probl) = case Ctree.get_obj I pt p of
|
walther@59957
|
165 |
Ctree.PblObj {origin = (_, ospec, hdf'), spec, probl,...} => (ospec, hdf', spec, probl)
|
walther@59962
|
166 |
| _ => raise ERROR "get_ocalhd Pbl: uncovered case get_obj"
|
walther@59983
|
167 |
val {prls, where_, ...} = Problem.from_store (#2 (References.select ospec spec))
|
walther@59965
|
168 |
val pre = Pre_Conds.check' (ThyC.get_theory "Isac_Knowledge") prls where_ probl
|
wneuper@59265
|
169 |
in
|
walther@59969
|
170 |
(ocalhd_complete probl pre spec, Pos.Pbl, hdf', probl, pre, spec)
|
wneuper@59265
|
171 |
end
|
walther@59969
|
172 |
| get_ocalhd (pt, (p, Pos.Met)) =
|
wneuper@59265
|
173 |
let
|
walther@59957
|
174 |
val (ospec, hdf', spec, meth) = case Ctree.get_obj I pt p of
|
walther@59957
|
175 |
Ctree.PblObj {origin = (_, ospec, hdf'), spec, meth, ...} => (ospec, hdf', spec, meth)
|
walther@59962
|
176 |
| _ => raise ERROR "get_ocalhd Met: uncovered case get_obj"
|
walther@59983
|
177 |
val {prls, pre, ...} = Method.from_store (#3 (References.select ospec spec))
|
walther@59965
|
178 |
val pre = Pre_Conds.check' (ThyC.get_theory "Isac_Knowledge") prls pre meth
|
wneuper@59265
|
179 |
in
|
walther@59969
|
180 |
(ocalhd_complete meth pre spec, Pos.Met, hdf', meth, pre, spec)
|
wneuper@59265
|
181 |
end
|
walther@59962
|
182 |
| get_ocalhd _ = raise ERROR "get_ocalhd: uncovered definition"
|
neuper@37906
|
183 |
|
walther@59977
|
184 |
(* at the activeFormula set the Specification
|
wneuper@59265
|
185 |
to empty and return a CalcHead;
|
wneuper@59265
|
186 |
the 'origin' remains (for reconstructing all that) *)
|
walther@59957
|
187 |
fun reset_calchead (pt, (p,_)) =
|
wneuper@59265
|
188 |
let
|
walther@59957
|
189 |
val () = case Ctree.get_obj I pt p of
|
walther@59957
|
190 |
Ctree.PblObj _ => ()
|
walther@59962
|
191 |
| _ => raise ERROR "reset_calchead: uncovered case get_obj"
|
walther@59957
|
192 |
val pt = Ctree.update_pbl pt p []
|
walther@59957
|
193 |
val pt = Ctree.update_met pt p []
|
walther@59976
|
194 |
val pt = Ctree.update_spec pt p References.empty
|
walther@59957
|
195 |
in (pt, (p, Pos.Pbl)) end
|
neuper@37906
|
196 |
|
walther@59763
|
197 |
(**)end(**) |