wneuper@59308
|
1 |
(* Title: Specify-phase: specifying and modeling a problem or a subproblem. The
|
wneuper@59308
|
2 |
most important types are declared in mstools.sml.
|
wneuper@59308
|
3 |
TODO: allocate elements of Selem and of Stool appropriately
|
wneuper@59308
|
4 |
Author: Walther Neuper 991122, Mathias Lehnfeld
|
wneuper@59308
|
5 |
(c) due to copyright terms
|
wneuper@59308
|
6 |
*)
|
wneuper@59298
|
7 |
signature SPECIFY_ELEMENT =
|
wneuper@59298
|
8 |
sig
|
wneuper@59298
|
9 |
type fmz
|
wneuper@59298
|
10 |
type fmz_
|
wneuper@59299
|
11 |
type result
|
wneuper@59299
|
12 |
val res2str : term * term list -> string
|
wneuper@59492
|
13 |
type subs (* substitution as seen by learner. rename stubst_user ["(''bdv'', x)"]*)
|
wneuper@59494
|
14 |
type sube (* = subs. delete ! = stubst_user *)
|
wneuper@59492
|
15 |
type subte (* _sub_stitution as _t_erms of _e_qualities: revise ! [bdv = x] *)
|
wneuper@59494
|
16 |
type subst' (* substitution in isac-programs; rename subst_prog [(bdv, x)] *)
|
wneuper@59492
|
17 |
(*type subst for rewriting, in Rule (+?Isabelle); rename subst_rew [(bools, x)] *)
|
wneuper@59494
|
18 |
(* TODO use these types in functions below and elsewhere; rename below according to types *)
|
walther@59865
|
19 |
val subst'_to_sube : subst' -> TermC.as_string list (* e.g. rename to subst_user_of_prog *)
|
walther@59863
|
20 |
val subst_to_subst' : UnparseC.subst -> subst'
|
wneuper@59494
|
21 |
val subst'_to_subst : subst' -> (term * term) list
|
walther@59865
|
22 |
val sube2str : TermC.as_string list -> string
|
walther@59865
|
23 |
val sube2subst : theory -> TermC.as_string list -> (term * term) list
|
walther@59865
|
24 |
val sube2subte : TermC.as_string list -> term list
|
walther@59865
|
25 |
val subs2subst : theory -> TermC.as_string list -> (term * term) list
|
walther@59865
|
26 |
val subst2sube : (term * term) list -> TermC.as_string list (* for datatypes.sml *)
|
walther@59865
|
27 |
val subst2subs : (term * term) list -> TermC.as_string list
|
wneuper@59301
|
28 |
val subst2subs' : (term * term) list -> (string * string) list
|
walther@59865
|
29 |
val subte2sube : term list -> TermC.as_string list
|
wneuper@59492
|
30 |
|
wneuper@59310
|
31 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
walther@59898
|
32 |
val e_fmz : fmz_ * Spec.spec (* for datatypes.sml *)
|
walther@59865
|
33 |
val e_sube : TermC.as_string list
|
wneuper@59301
|
34 |
val e_subs : string list
|
wneuper@59301
|
35 |
val subte2subst : term list -> (term * term) list
|
walther@59886
|
36 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
wneuper@59310
|
37 |
(* NONE *)
|
walther@59886
|
38 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
wneuper@59298
|
39 |
|
wneuper@59310
|
40 |
(*----- unused code, kept as hints to design ideas ---------------------------------------------*)
|
wneuper@59310
|
41 |
(*----- unused code, kept as hints to design ideas ---------------------------------------------*)
|
wneuper@59310
|
42 |
(* NONE *)
|
wneuper@59298
|
43 |
end
|
wneuper@59298
|
44 |
|
wneuper@59298
|
45 |
structure Selem(**): SPECIFY_ELEMENT(**) =
|
wneuper@59298
|
46 |
struct
|
wneuper@59298
|
47 |
|
walther@59659
|
48 |
fun subst2str s =
|
walther@59659
|
49 |
(strs2str o
|
walther@59659
|
50 |
(map (
|
walther@59899
|
51 |
linefeed o pair2str o (apsnd UnparseC.term) o (apfst UnparseC.term)))) s;
|
walther@59865
|
52 |
type fmz_ = TermC.as_string list;
|
wneuper@59539
|
53 |
(* a formalization of an example contains data
|
wneuper@59539
|
54 |
sufficient for mechanically finding the solution for the example.
|
wneuper@59298
|
55 |
FIXME.WN051014: dont store fmz = (_,spec) in the PblObj, this is done in origin *)
|
walther@59898
|
56 |
type fmz = fmz_ * Spec.spec;
|
walther@59898
|
57 |
val e_fmz = ([], Spec.empty_spec);
|
wneuper@59298
|
58 |
|
wneuper@59299
|
59 |
type result = term * term list
|
walther@59868
|
60 |
fun res2str (t, ts) = pair2str (UnparseC.term t, UnparseC.terms ts); (* for tests only *)
|
wneuper@59299
|
61 |
|
walther@59865
|
62 |
type subs = TermC.as_string list; (* substitution as seen by learner in tactics, in programs, etc.
|
wneuper@59492
|
63 |
questionable design. rename to stubst_user *)
|
wneuper@59492
|
64 |
val e_subs = ["(''bdv'', x)"]; (* for tests only *)
|
wneuper@59301
|
65 |
|
wneuper@59301
|
66 |
(* argument type of tac Rewrite_Inst *)
|
walther@59865
|
67 |
type sube = TermC.as_string list; (* = subs. delete *)
|
walther@59865
|
68 |
val e_sube = []: TermC.as_string list; (* for tests only *)
|
wneuper@59301
|
69 |
fun sube2str s = strs2str s;
|
wneuper@59301
|
70 |
|
wneuper@59492
|
71 |
type subte = term list; (* _sub_stitution as _t_erms of _e_qualities: revise ! *)
|
wneuper@59301
|
72 |
|
wneuper@59492
|
73 |
type subst' = term; (* substitution in isac-programs. rename to subst_prog
|
wneuper@59492
|
74 |
is "(char list * term) list", where term is Free ("xxx", _)
|
wneuper@59484
|
75 |
e.g. @{term "[(''bdv_1'', x::real), (''bdv_2'', y::real), (''bdv_3'', z::real)]"} *)
|
wneuper@59489
|
76 |
fun subst'_to_sube sub = (sub
|
wneuper@59484
|
77 |
|> HOLogic.dest_list
|
wneuper@59484
|
78 |
|> map HOLogic.dest_prod
|
walther@59868
|
79 |
|> map (fn (e1, e2) => (HOLogic.dest_string e1, UnparseC.term e2))
|
walther@59865
|
80 |
|> map (fn (e1, e2) => "(''" ^ e1 ^ "'', " ^ e2 ^ ")"): TermC.as_string list)
|
wneuper@59489
|
81 |
handle TERM _ => raise TERM ("subst'_to_sube: wrong argument ", [sub])
|
wneuper@59492
|
82 |
fun subst_to_subst' subst = subst
|
wneuper@59492
|
83 |
|> map (apfst TermC.free2str)
|
wneuper@59492
|
84 |
|> map (apfst HOLogic.mk_string)
|
wneuper@59492
|
85 |
|> map HOLogic.mk_prod
|
wneuper@59492
|
86 |
|> HOLogic.mk_list (HOLogic.mk_prodT (HOLogic.stringT, HOLogic.realT (*FIXME: 'a*)))
|
wneuper@59494
|
87 |
fun subst'_to_subst t = (t
|
wneuper@59494
|
88 |
|> HOLogic.dest_list
|
wneuper@59494
|
89 |
|> map HOLogic.dest_prod
|
wneuper@59494
|
90 |
|> map (apfst HOLogic.dest_string))
|
wneuper@59494
|
91 |
|> map (apfst (fn e1 => (TermC.mk_Free (e1, HOLogic.realT))))
|
wneuper@59494
|
92 |
handle TERM _ => raise TERM ("subst'_to_subst: wrong argument ", [t])
|
walther@59868
|
93 |
val subte2sube = map UnparseC.term;
|
wneuper@59492
|
94 |
fun subst2subs subst_rew = (subst_rew
|
walther@59868
|
95 |
|> map (apsnd UnparseC.term)
|
walther@59868
|
96 |
|> map (apfst UnparseC.term)
|
wneuper@59492
|
97 |
|> map (apfst (enclose "''" "''")))
|
wneuper@59492
|
98 |
|> map pair2str
|
walther@59659
|
99 |
handle TERM _ => raise TERM ("subst2subs: wrong argument " ^ subst2str subst_rew, [])
|
walther@59868
|
100 |
fun subst2sube subst = map UnparseC.term (map HOLogic.mk_eq subst)
|
walther@59868
|
101 |
val subst2subs' = map ((apfst UnparseC.term) o (apsnd UnparseC.term));
|
wneuper@59492
|
102 |
fun subs2subst thy subs = (subs
|
wneuper@59492
|
103 |
|> map (TermC.parse_patt thy(*FIXME use context, get type of snd (e.g. x,y,z), copy to fst*))
|
wneuper@59492
|
104 |
|> map TermC.isapair2pair
|
wneuper@59492
|
105 |
|> map (apfst HOLogic.dest_string)
|
wneuper@59492
|
106 |
|> map (apfst (fn str => (TermC.mk_Free (str, HOLogic.realT)))))
|
wneuper@59492
|
107 |
handle TERM _ => raise TERM ("subs2subst: wrong argument " ^ strs2str' subs, [])
|
wneuper@59390
|
108 |
fun sube2subst thy s = map (TermC.dest_equals o (TermC.parse_patt thy)) s;
|
wneuper@59389
|
109 |
val sube2subte = map TermC.str2term;
|
wneuper@59301
|
110 |
val subte2subst = map HOLogic.dest_eq;
|
wneuper@59301
|
111 |
|
wneuper@59298
|
112 |
end
|