walther@59850
|
1 |
(* Title: CalcElements/rule.sml
|
walther@59850
|
2 |
Author: Walther Neuper 2018
|
wneuper@59415
|
3 |
(c) copyright due to lincense terms
|
walther@59850
|
4 |
|
walther@59850
|
5 |
Some stuff waits for later rounds of restructuring, e.g. Rule.e_term
|
wneuper@59415
|
6 |
*)
|
wneuper@59415
|
7 |
|
wneuper@59415
|
8 |
signature RULE =
|
walther@59850
|
9 |
sig
|
walther@59850
|
10 |
datatype rule = datatype Rule_Def.rule
|
walther@59850
|
11 |
datatype program = datatype Rule_Def.program
|
walther@59849
|
12 |
|
walther@59850
|
13 |
eqtype cterm'
|
walther@59850
|
14 |
type subst = (term * term) list
|
wneuper@59416
|
15 |
|
walther@59857
|
16 |
eqtype errpatID
|
walther@59850
|
17 |
type errpat = errpatID * term list * thm list
|
wneuper@59415
|
18 |
|
walther@59850
|
19 |
val scr2str: program -> string
|
wneuper@59415
|
20 |
|
walther@59850
|
21 |
val e_term: term (* shift up to Unparse *)
|
walther@59850
|
22 |
val e_type: typ (* shift up to Unparse *)
|
walther@59850
|
23 |
val type2str: typ -> string
|
walther@59850
|
24 |
val term_to_string': Proof.context -> term -> string (* shift up to Unparse *)
|
walther@59850
|
25 |
val term2str: term -> string (* shift up to Unparse *)
|
walther@59850
|
26 |
val termopt2str: term option -> string (* shift up to Unparse *)
|
walther@59850
|
27 |
val terms2str: term list -> string (* shift up to Unparse *)
|
walther@59850
|
28 |
val terms2strs: term list -> string list
|
walther@59857
|
29 |
val term_to_string'': ThyC.thyID -> term -> string (* shift up to Unparse *)
|
walther@59850
|
30 |
val term_to_string''': theory -> term -> string (* shift up to Unparse *)
|
walther@59850
|
31 |
val t2str: theory -> term -> string
|
walther@59850
|
32 |
val ts2str: theory -> term list -> string (* shift up to Unparse *)
|
walther@59850
|
33 |
val string_of_typ: typ -> string (* shift up to Unparse *)
|
walther@59857
|
34 |
val string_of_typ_thy: ThyC.thyID -> typ -> string (* shift up to Unparse *)
|
wneuper@59415
|
35 |
|
wneuper@59415
|
36 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
walther@59850
|
37 |
val terms2str': term list -> string (* shift up to Unparse *)
|
walther@59850
|
38 |
val thm2str: thm -> string
|
walther@59850
|
39 |
val thms2str : thm list -> string
|
walther@59854
|
40 |
val string_of_thmI: thm -> string
|
walther@59850
|
41 |
val string_of_thm': theory -> thm -> string (* shift up to Unparse *)
|
walther@59850
|
42 |
val errpats2str : errpat list -> string
|
walther@59785
|
43 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
wneuper@59416
|
44 |
val string_of_thm: thm -> string (* shift up to Unparse *)
|
walther@59785
|
45 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
walther@59850
|
46 |
end
|
wneuper@59415
|
47 |
|
wneuper@59415
|
48 |
(**)
|
wneuper@59415
|
49 |
structure Rule(**): RULE(**) =
|
wneuper@59415
|
50 |
struct
|
wneuper@59415
|
51 |
(**)
|
wneuper@59415
|
52 |
|
walther@59850
|
53 |
datatype rule = datatype Rule_Def.rule
|
walther@59850
|
54 |
datatype program = datatype Rule_Def.program
|
walther@59850
|
55 |
|
walther@59850
|
56 |
type calc = Rule_Def.calc (*..from Rule_Def*)
|
walther@59849
|
57 |
type calID = Rule_Def.calID; (*..from Rule_Def*)
|
wneuper@59415
|
58 |
(* eval function calling sml code during rewriting.
|
wneuper@59415
|
59 |
Unifying "type cal" and "type calc" would make Lucas-Interpretation more efficient,
|
wneuper@59415
|
60 |
see "fun rule2stac": instead of
|
walther@59773
|
61 |
Num_Calc: calID * eval_fn -> rule
|
wneuper@59415
|
62 |
would be better
|
walther@59773
|
63 |
Num_Calc: prog_calcID * (calID * eval_fn)) -> rule*)
|
walther@59849
|
64 |
type eval_fn = Rule_Def.eval_fn (*..from Rule_Def*)
|
wneuper@59416
|
65 |
|
wneuper@59416
|
66 |
type cterm' = string;
|
wneuper@59416
|
67 |
type subst = (term * term) list;
|
wneuper@59416
|
68 |
|
wneuper@59562
|
69 |
fun term_to_string' ctxt t =
|
wneuper@59562
|
70 |
let
|
wneuper@59562
|
71 |
val ctxt' = Config.put show_markup false ctxt
|
wneuper@59562
|
72 |
in Print_Mode.setmp [] (Syntax.string_of_term ctxt') t end;
|
wneuper@59562
|
73 |
fun term_to_string'' thyID t =
|
wneuper@59562
|
74 |
let
|
walther@59854
|
75 |
val ctxt' = Config.put show_markup false (Proof_Context.init_global (ThyC.Thy_Info_get_theory thyID))
|
wneuper@59562
|
76 |
in Print_Mode.setmp [] (Syntax.string_of_term ctxt') t end;
|
wneuper@59562
|
77 |
fun term_to_string''' thy t =
|
wneuper@59562
|
78 |
let
|
wneuper@59562
|
79 |
val ctxt' = Config.put show_markup false (Proof_Context.init_global thy)
|
wneuper@59562
|
80 |
in Print_Mode.setmp [] (Syntax.string_of_term ctxt') t end;
|
wneuper@59562
|
81 |
|
walther@59854
|
82 |
fun term2str t = term_to_string' (ThyC.thy2ctxt' "Isac_Knowledge") t;
|
walther@59854
|
83 |
fun t2str thy t = term_to_string' (ThyC.thy2ctxt thy) t;
|
wneuper@59562
|
84 |
fun ts2str thy ts = ts |> map (t2str thy) |> strs2str';
|
wneuper@59562
|
85 |
fun terms2strs ts = map term2str ts; (* terms2strs [t1,t2] = ["1 + 2", "abc"]; *)
|
wneuper@59562
|
86 |
val terms2str = strs2str o terms2strs; (* terms2str [t1,t2] = "[\"1 + 2\",\"abc\"]"; *)
|
wneuper@59562
|
87 |
val terms2str' = strs2str' o terms2strs; (* terms2str' [t1,t2] = "[1 + 2,abc]"; *)
|
wneuper@59562
|
88 |
fun termopt2str (SOME t) = "(SOME " ^ term2str t ^ ")"
|
wneuper@59562
|
89 |
| termopt2str NONE = "NONE";
|
wneuper@59562
|
90 |
|
wneuper@59562
|
91 |
fun thm2str thm =
|
wneuper@59562
|
92 |
let
|
wneuper@59562
|
93 |
val t = Thm.prop_of thm
|
wneuper@59592
|
94 |
val ctxt = Proof_Context.init_global (Thy_Info.get_theory ("Isac.Isac_Knowledge"))
|
wneuper@59562
|
95 |
val ctxt' = Config.put show_markup false ctxt
|
wneuper@59562
|
96 |
in Print_Mode.setmp [] (Syntax.string_of_term ctxt') t end;
|
wneuper@59562
|
97 |
fun thms2str thms = (strs2str o (map thm2str)) thms
|
wneuper@59562
|
98 |
|
wneuper@59415
|
99 |
(* error patterns and fill patterns *)
|
wneuper@59415
|
100 |
type errpatID = string
|
wneuper@59415
|
101 |
type errpat =
|
wneuper@59415
|
102 |
errpatID (* one identifier for a list of patterns
|
wneuper@59415
|
103 |
DESIGN ?TODO: errpatID list for hierarchy of errpats ? *)
|
wneuper@59415
|
104 |
* term list (* error patterns *)
|
wneuper@59415
|
105 |
* thm list (* thms related to error patterns; note that respective lhs
|
wneuper@59415
|
106 |
do not match (which reflects student's error).
|
wneuper@59415
|
107 |
fillpatterns are stored with these thms. *)
|
wneuper@59562
|
108 |
fun errpat2str (id, tms, thms) =
|
wneuper@59562
|
109 |
"(\"" ^ id ^ "\",\n" ^ terms2str tms ^ ",\n" ^ thms2str thms
|
wneuper@59562
|
110 |
fun errpats2str errpats = (strs2str' o (map errpat2str)) errpats
|
wneuper@59415
|
111 |
|
wneuper@59415
|
112 |
|
walther@59854
|
113 |
fun type_to_string'' (thyID : ThyC.thyID) t =
|
wneuper@59415
|
114 |
let
|
walther@59854
|
115 |
val ctxt' = Config.put show_markup false (Proof_Context.init_global (ThyC.Thy_Info_get_theory thyID))
|
wneuper@59415
|
116 |
in Print_Mode.setmp [] (Syntax.string_of_typ ctxt') t end;
|
wneuper@59592
|
117 |
fun type2str typ = type_to_string'' "Isac_Knowledge" typ; (*TODO legacy*)
|
wneuper@59415
|
118 |
val string_of_typ = type2str; (*legacy*)
|
wneuper@59415
|
119 |
fun string_of_typ_thy thy typ = type_to_string'' thy typ; (*legacy*)
|
wneuper@59415
|
120 |
|
wneuper@59415
|
121 |
(*check for [.] as caused by "fun assoc_thm'"*)
|
walther@59854
|
122 |
fun string_of_thm thm = term_to_string' (ThyC.thy2ctxt' "Isac_Knowledge") (Thm.prop_of thm)
|
walther@59854
|
123 |
fun string_of_thm' thy thm = term_to_string' (ThyC.thy2ctxt thy) (Thm.prop_of thm)
|
wneuper@59415
|
124 |
fun string_of_thmI thm =
|
wneuper@59415
|
125 |
let
|
wneuper@59415
|
126 |
val str = (de_quote o string_of_thm) thm
|
wneuper@59415
|
127 |
val (a, b) = split_nlast (5, Symbol.explode str)
|
wneuper@59415
|
128 |
in
|
wneuper@59415
|
129 |
case b of
|
wneuper@59415
|
130 |
[" ", " ","[", ".", "]"] => implode a
|
wneuper@59415
|
131 |
| _ => str
|
wneuper@59415
|
132 |
end
|
wneuper@59415
|
133 |
|
wneuper@59415
|
134 |
fun scr2str EmptyScr = "EmptyScr"
|
wneuper@59415
|
135 |
| scr2str (Prog s) = "Prog " ^ term2str s
|
wneuper@59415
|
136 |
| scr2str (Rfuns _) = "Rfuns";
|
wneuper@59415
|
137 |
|
wneuper@59415
|
138 |
val e_type = Type ("empty",[]);
|
wneuper@59415
|
139 |
val e_term = Const ("empty", Type("'a", []));
|
wneuper@59416
|
140 |
|
wneuper@59415
|
141 |
end (*struct*)
|