walther@60096
|
1 |
(* Title: src/Tools/isac/BridgeJEdit/Calculation.thy
|
walther@60095
|
2 |
Author: Walther Neuper, JKU Linz
|
walther@60095
|
3 |
(c) due to copyright terms
|
walther@60095
|
4 |
|
walther@60121
|
5 |
Outer syntax for Isabelle/Isac's Calculation.
|
walther@60095
|
6 |
*)
|
walther@60095
|
7 |
|
walther@60095
|
8 |
theory Calculation
|
walther@60115
|
9 |
imports
|
walther@60178
|
10 |
(**)"~~/src/Tools/isac/Knowledge/Build_Thydata" (*remove after devel.of BridgeJEdit*)
|
walther@60177
|
11 |
(**)"~~/src/Tools/isac/MathEngine/MathEngine"
|
walther@60178
|
12 |
(**)"HOL-SPARK.SPARK" (*remove after devel.of BridgeJEdit*)
|
walther@60095
|
13 |
keywords
|
walther@60178
|
14 |
"Example" :: thy_load (*(isac_example)~(spark_vcg) ..would involve registering in Isabelle/Scala*)
|
walther@60178
|
15 |
and(**)"Problem" :: thy_decl (*r oot-problem + recursively in Solution *)
|
walther@60178
|
16 |
and "Specification" "Model" "References" :: diag (* structure only *)
|
walther@60162
|
17 |
and "Solution" :: thy_decl (* structure only *)
|
walther@60178
|
18 |
and "Where" "Given" "Find" "Relate" :: prf_decl (* await input of term *)
|
walther@60158
|
19 |
(*and "Where" (* only output, preliminarily *)*)
|
walther@60162
|
20 |
and "RTheory" :: thy_decl (* await input of string; "R" distingues "Problem".."RProblem" *)
|
walther@60162
|
21 |
and "RProblem" "RMethod" :: thy_decl (* await input of string list *)
|
walther@60158
|
22 |
and "Tactic" (* optional for each step 0..end of calculation *)
|
walther@60095
|
23 |
begin
|
walther@60178
|
24 |
(** )declare [[ML_print_depth = 99999]]( **)
|
walther@60178
|
25 |
ML_file parseC.sml
|
walther@60178
|
26 |
ML_file preliminary.sml
|
walther@60146
|
27 |
|
walther@60095
|
28 |
|
walther@60123
|
29 |
section \<open>new code for Outer_Syntax Example, Problem, ...\<close>
|
walther@60123
|
30 |
text \<open>
|
walther@60156
|
31 |
code for Example, Problem shifted into structure Preliminary.
|
walther@60156
|
32 |
\<close>
|
walther@60123
|
33 |
|
walther@60151
|
34 |
subsubsection \<open>cp from Pure.thy\<close>
|
walther@60123
|
35 |
ML \<open>
|
walther@60156
|
36 |
\<close> ML \<open> (* for "from" ~~ "Given:" *)
|
walther@60151
|
37 |
(* original *)
|
walther@60151
|
38 |
val facts = Parse.and_list1 Parse.thms1;
|
walther@60151
|
39 |
facts: (Facts.ref * Token.src list) list list parser;
|
walther@60123
|
40 |
\<close> ML \<open>
|
walther@60151
|
41 |
val facts =
|
walther@60151
|
42 |
(writeln "####-## from parser";
|
walther@60151
|
43 |
Parse.$$$ ":" |-- Parse.and_list1 Parse.thms1)(** ) --| Parse.$$$ "Where"( **);
|
walther@60151
|
44 |
facts: (Facts.ref * Token.src list) list list parser;
|
walther@60151
|
45 |
\<close> ML \<open>
|
walther@60123
|
46 |
\<close> ML \<open>
|
walther@60148
|
47 |
\<close>
|
walther@60123
|
48 |
|
walther@60157
|
49 |
subsubsection \<open>tools to analyse parsing in Outer_Syntax >> \<close>
|
walther@60157
|
50 |
ML \<open>
|
walther@60157
|
51 |
\<close> text \<open> (*original basics.ML*)
|
walther@60157
|
52 |
op |>> : ('a * 'b) * ('a -> 'c) -> 'c * 'b;
|
walther@60157
|
53 |
fun (x, y) |>> f = (f x, y);
|
walther@60157
|
54 |
\<close> text \<open> (*original scan.ML*)
|
walther@60157
|
55 |
op >> : ('a -> 'b * 'c) * ('b -> 'd) -> 'a -> 'd * 'c; (*---vvv*)
|
walther@60157
|
56 |
fun (scan >> f) xs = scan xs |>> f;
|
walther@60157
|
57 |
\<close> ML \<open>
|
walther@60157
|
58 |
\<close> ML \<open> (*cp.from originals*)
|
walther@60157
|
59 |
infix 3 @>>;
|
walther@60157
|
60 |
fun (scan @>> f) xs = scan xs |>> f;
|
walther@60157
|
61 |
op @>> : ('a -> 'b * 'c) * ('b -> 'd) -> 'a -> 'd * 'c; (*---^^^*)
|
walther@60157
|
62 |
\<close> ML \<open> (*appl.to parser*)
|
walther@60157
|
63 |
op @>> : (Token.src -> 'b * Token.src) * ('b -> 'd) -> Token.src -> 'd * Token.src; (*---^^^*)
|
walther@60157
|
64 |
\<close> ML \<open>
|
walther@60157
|
65 |
\<close> ML \<open> (*add analysis*)
|
walther@60157
|
66 |
\<close> text \<open>
|
walther@60157
|
67 |
datatype T = Pos of (int * int * int) * Properties.T;
|
walther@60157
|
68 |
|
walther@60157
|
69 |
fun s_to_string (Pos ((line, offset, end_offset), _)) = ("Pos ((" ^
|
walther@60157
|
70 |
string_of_int line ^ ", " ^ string_of_int offset ^ ", " ^ string_of_int end_offset ^ "), [_])")
|
walther@60157
|
71 |
|
walther@60157
|
72 |
s_to_string: src -> string
|
walther@60157
|
73 |
\<close> text \<open>
|
walther@60157
|
74 |
datatype T = Token of (Symbol_Pos.text * Position.range) * (kind * string) * slot
|
walther@60157
|
75 |
\<close> ML \<open>
|
walther@60157
|
76 |
Token.pos_of; (*^^^^^^^^^^^^^^^*)
|
walther@60157
|
77 |
Token.end_pos_of; (*^^^^^^^^^^^^^*)
|
walther@60157
|
78 |
Token.unparse; (*^^^^^^^^^^^^^*)
|
walther@60157
|
79 |
\<close> ML \<open>
|
walther@60157
|
80 |
fun string_of_tok tok = ("\nToken ((" ^
|
walther@60157
|
81 |
Position.to_string (Token.pos_of tok) ^ ", " ^
|
walther@60157
|
82 |
Position.to_string (Token.end_pos_of tok) ^ "), " ^
|
walther@60157
|
83 |
Token.unparse tok ^ ", _)")
|
walther@60157
|
84 |
\<close> ML \<open>
|
walther@60157
|
85 |
fun string_of_toks toks = fold (curry op ^) (map string_of_tok toks |> rev |> separate ", ") "";
|
walther@60157
|
86 |
string_of_toks: Token.src -> string;
|
walther@60157
|
87 |
\<close> ML \<open>
|
walther@60157
|
88 |
Token.s_to_string: Token.src -> string; (*<-- string_of_toks WN*)
|
walther@60157
|
89 |
\<close> ML \<open>
|
walther@60157
|
90 |
fun (scan @>> f) xs = (@{print}{a = "_ >> ", toks = xs(*GIVES\<rightarrow>"?"*)}; scan xs) |>> f;
|
walther@60157
|
91 |
fun (scan @>> f) xs = (writeln ("toks= " ^ Token.s_to_string xs); scan xs) |>> f;
|
walther@60157
|
92 |
op @>> : (Token.src -> 'b * Token.src) * ('b -> 'd) -> Token.src -> 'd * Token.src; (*---^^^*)
|
walther@60157
|
93 |
\<close> ML \<open>
|
walther@60157
|
94 |
op @>> : (Token.T list -> 'a * 'b) * ('a -> 'c) -> Token.T list -> 'c * 'b
|
walther@60157
|
95 |
\<close> ML \<open>
|
walther@60157
|
96 |
\<close> ML \<open> (*Scan < Token in bootstrap, thus we take Token.s_to_string as argument of >> *)
|
walther@60157
|
97 |
infix 3 @@>>;
|
walther@60157
|
98 |
\<close> ML \<open>
|
walther@60157
|
99 |
fun ((write, scan) @@>> f) xs = (write xs; scan xs) |>> f;
|
walther@60157
|
100 |
op @@>> : (('a -> 'b) * ('a -> 'c * 'd)) * ('c -> 'e) -> 'a -> 'e * 'd
|
walther@60157
|
101 |
\<close> ML \<open>
|
walther@60157
|
102 |
\<close>
|
walther@60157
|
103 |
|
walther@60148
|
104 |
subsubsection \<open>TODO\<close>
|
walther@60123
|
105 |
ML \<open>
|
walther@60123
|
106 |
\<close> ML \<open>
|
walther@60132
|
107 |
\<close> ML \<open>
|
walther@60157
|
108 |
\<close> ML \<open>
|
walther@60097
|
109 |
\<close>
|
walther@60097
|
110 |
|
walther@60153
|
111 |
section \<open>setup command_keyword + preliminary test\<close>
|
walther@60157
|
112 |
ML \<open>
|
walther@60103
|
113 |
\<close> ML \<open>
|
walther@60103
|
114 |
val _ =
|
walther@60117
|
115 |
Outer_Syntax.command \<^command_keyword>\<open>Example\<close> "start a Calculation from a Formalise-file"
|
walther@60177
|
116 |
(Resources.provide_parse_file -- Parse.parname
|
walther@60155
|
117 |
>> (Toplevel.theory o (*vvvvvvvvvvvvvvvvvvvv--- HACK makes test independent from session Isac*)
|
walther@60155
|
118 |
(Preliminary.load_formalisation @{theory Biegelinie} ParseC.formalisation)) );
|
walther@60110
|
119 |
\<close> ML \<open>
|
walther@60123
|
120 |
val _ =
|
walther@60156
|
121 |
Outer_Syntax.command \<^command_keyword>\<open>Problem\<close>
|
walther@60123
|
122 |
"start a Specification, either from scratch or from preceding 'Example'"
|
walther@60178
|
123 |
((writeln o Token.s_to_string, ParseC.problem_headline)
|
walther@60178
|
124 |
@@>> (Toplevel.theory o Preliminary.init_specify));
|
walther@60123
|
125 |
\<close> ML \<open>
|
walther@60160
|
126 |
Preliminary.init_specify: ParseC.problem_headline -> theory -> theory;
|
walther@60160
|
127 |
(Toplevel.theory o Preliminary.init_specify)
|
walther@60160
|
128 |
: ParseC.problem_headline -> Toplevel.transition -> Toplevel.transition;
|
walther@60160
|
129 |
\<close> ML \<open>
|
walther@60156
|
130 |
(**) Preliminary.init_specify: ParseC.problem_headline -> theory -> theory;(**)
|
walther@60156
|
131 |
(* ^^^^^^ ^^^^^^*)
|
walther@60156
|
132 |
(**)(Toplevel.theory o Preliminary.init_specify):
|
walther@60156
|
133 |
ParseC.problem_headline -> Toplevel.transition -> Toplevel.transition;(**)
|
walther@60156
|
134 |
(* ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^*)
|
walther@60155
|
135 |
\<close> ML \<open>
|
walther@60161
|
136 |
fun dummy (_(*":"*): string) thy =
|
walther@60161
|
137 |
let
|
walther@60161
|
138 |
val refs' = Refs_Data.get thy
|
walther@60161
|
139 |
val o_model = OMod_Data.get thy
|
walther@60161
|
140 |
val i_model = IMod_Data.get thy
|
walther@60161
|
141 |
val _ =
|
walther@60161
|
142 |
@{print} {a = "### dummy Specification", refs = refs', o_model = o_model, i_model = i_model}
|
walther@60178
|
143 |
in thy end;
|
walther@60160
|
144 |
\<close> ML \<open>
|
walther@60158
|
145 |
val _ =
|
walther@60178
|
146 |
Outer_Syntax.command \<^command_keyword>\<open>Specification\<close> "Specification dummy"
|
walther@60161
|
147 |
((writeln o Token.s_to_string, Parse.$$$ ":") @@>> (Toplevel.theory o dummy))
|
walther@60158
|
148 |
\<close> ML \<open>
|
walther@60185
|
149 |
fun dummy2 _ (thy: theory) = thy
|
walther@60185
|
150 |
\<close> ML \<open> (*or*)
|
walther@60185
|
151 |
fun dummy2 _ (ctxt: Proof.context) = ctxt
|
walther@60185
|
152 |
\<close> ML \<open>
|
walther@60158
|
153 |
val _ =
|
walther@60160
|
154 |
Outer_Syntax.command \<^command_keyword>\<open>Model\<close> "Model dummy"
|
walther@60161
|
155 |
((writeln o Token.s_to_string, Parse.$$$ ":") @@>> (Toplevel.theory o dummy))
|
walther@60155
|
156 |
\<close> ML \<open>
|
walther@60151
|
157 |
val _ =
|
walther@60151
|
158 |
Outer_Syntax.command \<^command_keyword>\<open>Given\<close> "input Given items to the Model of a Specification"
|
walther@60157
|
159 |
(* (facts >> (Toplevel.proof o Proof.from_thmss_cmd));*)
|
walther@60157
|
160 |
((writeln o Token.s_to_string, facts) @@>> (Toplevel.proof o Proof.from_thmss_cmd));
|
walther@60151
|
161 |
val _ =
|
walther@60158
|
162 |
Outer_Syntax.command \<^command_keyword>\<open>Where\<close> "input Find items to the Model of a Specification"
|
walther@60158
|
163 |
(facts @>> (Toplevel.proof o Proof.from_thmss_cmd));
|
walther@60158
|
164 |
val _ =
|
walther@60155
|
165 |
Outer_Syntax.command \<^command_keyword>\<open>Find\<close> "input Find items to the Model of a Specification"
|
walther@60157
|
166 |
(facts @>> (Toplevel.proof o Proof.from_thmss_cmd));
|
walther@60151
|
167 |
val _ =
|
walther@60151
|
168 |
Outer_Syntax.command \<^command_keyword>\<open>Relate\<close> "input Relate items to the Model of a Specification"
|
walther@60157
|
169 |
(facts @>> (Toplevel.proof o Proof.from_thmss_cmd));
|
walther@60151
|
170 |
\<close> ML \<open>
|
walther@60155
|
171 |
(Toplevel.proof o Proof.from_thmss_cmd)
|
walther@60155
|
172 |
:
|
walther@60155
|
173 |
(Facts.ref * Token.src list) list list -> Toplevel.transition -> Toplevel.transition
|
walther@60155
|
174 |
(* ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^*)
|
walther@60151
|
175 |
\<close> ML \<open>
|
walther@60158
|
176 |
val _ =
|
walther@60158
|
177 |
Outer_Syntax.command @{command_keyword References} "References dummy"
|
walther@60158
|
178 |
(Parse.$$$ ":" >> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
|
walther@60158
|
179 |
val _ =
|
walther@60158
|
180 |
Outer_Syntax.command @{command_keyword RTheory} "RTheory dummy"
|
walther@60158
|
181 |
(Parse.$$$ ":" -- Parse.string
|
walther@60158
|
182 |
>> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
|
walther@60158
|
183 |
val _ =
|
walther@60158
|
184 |
Outer_Syntax.command @{command_keyword RProblem} "RProblem dummy"
|
walther@60158
|
185 |
(Parse.$$$ ":" -- (Parse.$$$ "[" |-- Parse.list1 Parse.string --| Parse.$$$ "]")
|
walther@60158
|
186 |
>> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
|
walther@60158
|
187 |
val _ =
|
walther@60158
|
188 |
Outer_Syntax.command @{command_keyword RMethod} "RMethod dummy"
|
walther@60158
|
189 |
(Parse.$$$ ":" -- (Parse.$$$ "[" |-- Parse.list1 Parse.string --| Parse.$$$ "]")
|
walther@60158
|
190 |
>> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
|
walther@60158
|
191 |
val _ =
|
walther@60158
|
192 |
Outer_Syntax.command @{command_keyword Solution} "Solution dummy"
|
walther@60158
|
193 |
(Parse.$$$ ":" >> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
|
walther@60158
|
194 |
\<close> ML \<open>
|
walther@60158
|
195 |
\<close> ML \<open>
|
walther@60132
|
196 |
\<close>
|
walther@60103
|
197 |
|
walther@60174
|
198 |
subsection \<open>runs with test-Example\<close>
|
walther@60174
|
199 |
(**)
|
walther@60180
|
200 |
Example \<open>../Examples/exp_Statics_Biegel_Timischl_7-70.str\<close>
|
walther@60174
|
201 |
(**)
|
walther@60156
|
202 |
Problem ("Biegelinie", ["Biegelinien"])
|
walther@60156
|
203 |
(*1 collapse* )
|
walther@60161
|
204 |
Specification:
|
walther@60157
|
205 |
(*2 collapse*)
|
walther@60150
|
206 |
Model:
|
walther@60161
|
207 |
Given: "Traegerlaenge " "Streckenlast " (*Bad context for command "Given"\<^here> -- using reset state*)
|
walther@60158
|
208 |
Where: "q_0 ist_integrierbar_auf {| 0, L |}" "0 < L"
|
walther@60158
|
209 |
Find: "Biegelinie "
|
walther@60150
|
210 |
Relate: "Randbedingungen "
|
walther@60158
|
211 |
References:
|
walther@60156
|
212 |
(*3 collapse*)
|
walther@60162
|
213 |
RTheory: "" (*Bad context for command "RTheory"\<^here> -- using reset state*)
|
walther@60150
|
214 |
RProblem: ["", ""]
|
walther@60150
|
215 |
RMethod: ["", ""]
|
walther@60156
|
216 |
(*3 collapse*)
|
walther@60157
|
217 |
(*2 collapse*)
|
walther@60150
|
218 |
Solution:
|
walther@60161
|
219 |
( * 1 collapse*)
|
walther@60150
|
220 |
(*
|
walther@60178
|
221 |
TODO: compare click on above Given: "Traegerlaenge ", "Streckenlast "
|
walther@60150
|
222 |
with click on from \<open>0 < d\<close> in SPARK/../Greatest_Common_Divisorthy
|
walther@60150
|
223 |
*)
|
walther@60150
|
224 |
|
walther@60179
|
225 |
end |