1 theory Test_VSCode_Example
2 imports "Isac.Build_Isac" (*"Isac.Calculation"*)
3 keywords "Example_TEST" :: thy_decl
7 Tests here in BridgePIDE are already based on Build_Isac.thy bypassing $ISABELLE_ISAC_TEST.
8 TODO: eliminate "Isac." above on eliminating session in $ISABELLE_ISAC_TEST.
11 subsection \<open>Development\<close>
13 Here we develop the semantics of \<open>Example_TEST\<close> as test
14 --- build Outer_Syntax Example_TEST n:
15 and save intermediate states as separate tests in test/../preliminary.sml
16 as soon as some stable state is achieved.
18 This way we make all \<open>Example\<close> to \<open>Example_TEST\<close> step by step
19 and finally rename all again to \<open>Example\<close>.
21 val ((in_thy, thy_id_pos), (in_pbl, probl_id_pos), (in_met, meth_id_pos)) =
22 (("__", Position.none), ( "__/__", Position.none), ("__/__", Position.none))
23 val in_ = (in_thy, in_pbl, in_met)
24 val spec_ as (spec_thy, spec_pbl, spec_met) = References.empty
25 val o_ as (o_thy, o_pbl, o_met) =
26 ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"])
35 \<close> ML \<open> (** preliminary handling of References **)
36 \<close> ML \<open> (* assumption: we read the Specfication as a whole *)
37 (*/-------------------- state of src/../preliminary.sml at that time -------------------------\*)
38 fun re_eval_all ((*dummyarg*)) = ("re_eval_all if new_thy"; ((*dummyarg*)))
39 fun re_eval_pbl ((*dummyarg*)) = ("re_eval_pbl"; ((*dummyarg*)))
40 fun re_eval_met ((*dummyarg*)) = ("re_eval_met"; ((*dummyarg*)))
42 re_eval_all: unit -> unit;
44 switch_pbl_met IS MISSING! Greater changes are to expect with respective introduction.
45 In the meanwhile we just \<open>re_eval\<close> the \<open>I_Model\<close> of \<open>Problem\<close>;
46 in case this is complete, we automatically complete the \<open>I_Model\<close> of \<open>MethodC\<close>
47 without displaying the respective \<open>P_Model\<close> and immediately start solve-phase by \<open>Apply_Method\<close>;
49 fun re_eval (input_thy, input_pbl, input_met) (spec_thy, spec_pbl, spec_met) =
50 if spec_thy <> input_thy
52 else if spec_pbl <> input_pbl
54 else if spec_met <> input_met
56 else ("nothing to re-evaluate"; ((*dummyarg*)))
58 re_eval: References.T -> References.T -> unit
64 (*\-------------------- state of src/../preliminary.sml at that time -------------------------/*)
65 \<close> ML \<open> (*\<longrightarrow> test/../calculation.sml*)
66 "----------- build Outer_Syntax Example_TEST ---------------------------------------------------";
67 "----------- build Outer_Syntax Example_TEST ---------------------------------------------------";
68 "----------- build Outer_Syntax Example_TEST ---------------------------------------------------";
69 "----------- build Outer_Syntax Example_TEST: stepwise input, References empty -----------------";
70 "----------- build Outer_Syntax Example_TEST: stepwise input, References empty -----------------";
71 "----------- build Outer_Syntax Example_TEST: stepwise input, References empty -----------------";
72 (*/---------------------------------------- mimic input from PIDE -----------------------------\*)
73 (* Example_TEST "Diff_App-No.123a" (*complete Model, empty References*) *)
75 val model_input = (*type Position.T is hidden, thus redefinition*)
76 [("#Given", [("Constants [r = 7]", Position.none)]),
77 ("#Where", [("0 < r", Position.none)]),
79 [("Maximum A", Position.none), ("AdditionalValues [u, v]", Position.none)]),
81 [("Extremum (A = 2 * u * v - u \<up> 2)", Position.none),
82 ("SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]", Position.none)])]
83 : (Model_Pattern.m_field * (string * Position.T) list) list
85 val ((thy_id, thy_id_pos), (probl_id, probl_id_pos), (meth_id, meth_id_pos)) =
86 (("__", Position.none), ( "__/__", Position.none), ("__/__", Position.none))
88 val example_id = "Diff_App-No.123a";
89 (*\---------------------------------------- mimic input from PIDE -----------------------------/*)
93 Ctree.EmptyPtree => Preliminary.init_ctree_TEST thy example_id
97 val {origin = (_, o_ref, _), spec = spec_ref, ctxt, ...} =
98 Ctree.get_obj I state [(*Pos will become variable*)] |> Ctree.rep_specify_data
99 val thy_id' = References.for_parse thy_id (#1 spec_ref) (#1 o_ref)
100 val (model, where_) = Model_Pattern.parse_pos_TEST ctxt model_input (*+check syntax*)
102 (model, where_) (*GOON*)
105 val _ = re_eval References.empty References.empty;
108 (*in*) Preliminary.update_state_TEST thy
109 (example_id, (model_input, (thy_id, probl_id, meth_id))) (the_data thy)
112 (*POSTPONED Specify.check_input \<longrightarrow> specify.sml*)
113 fun check_input _ = 123
125 Outer_Syntax.command \<^command_keyword>\<open>Example_TEST\<close>
126 "prepare ISAC problem type and register it to Knowledge Store"
127 (Parse.name -- Parse.!!! ( \<^keyword>\<open>Specification\<close> -- \<^keyword>\<open>:\<close> --
128 \<^keyword>\<open>Model\<close> -- \<^keyword>\<open>:\<close> |-- Problem.parse_pos_model_input --
129 (\<^keyword>\<open>References\<close> -- \<^keyword>\<open>:\<close> |-- Parse.!!! References.parse_input_pos
130 (** )-- ( \<^keyword>\<open>Solution\<close> -- keyword>\<open>:\<close>)( ** )WHAT IS WRONG HEREWITH?( **)) ) >>
131 (fn (example_id, (model_input,
132 ((thy_id, thy_id_pos), ((probl_id, probl_id_pos), (meth_id, meth_id_pos)) ) )) =>
133 Toplevel.theory (fn thy =>
137 Ctree.EmptyPtree => Preliminary.init_ctree_TEST thy example_id
140 val {origin = (_, o_ref, _), spec = spec_ref, ctxt, ...} =
141 Ctree.get_obj I state [] |> Ctree.rep_specify_data
142 val thy_id' = References.for_parse thy_id (#1 spec_ref) (#1 o_ref)
143 val (model, where_) = Model_Pattern.parse_pos_TEST ctxt model_input
145 val _ = re_eval References.empty References.empty
148 Preliminary.update_state_TEST thy
149 (example_id, (model_input, (thy_id, probl_id, meth_id))) (the_data thy)
151 in set_data state thy end)));
153 \<close> ML \<open> (*Example_TEST below*)
156 subsection \<open>Mirror from src/../VSCode_Example.thy for testing purposes\<close>
158 subsubsection \<open>Complete Specification at once\<close>
161 Just a test, that this works also in $ISABELLE_ISAC_TEST
163 Example "Diff_App-No.123a" (*complete Specification*)
166 Given: \<open>Constants [r = 7]\<close>
167 Where: \<open>0 < r\<close>
168 Find: \<open>Maximum A\<close> \<open>AdditionalValues [u, v]\<close>
169 Relate: \<open>Extremum A = 2 * u * v - u \<up> 2\<close>
170 \<open>SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\<close>
172 Theory_Ref: "Diff_App"
173 (*\<Otimes>*) Problem_Ref: "univariate_calculus/Optimisation"
174 (*\<Odot>*) Method_Ref: "Optimisation/by_univariate_calculus"
178 Check complete \<open>Model\<close>, infer empty \<open>References\<close> from data hidden in "Diff_App-No.123a"
181 Example: no syntax check of terms, OK.
182 Example_TEST: proper syntax check of terms with Model_Pattern.parse_pos,
183 but with parse_pos_TEST ERROR Malformed YXML: unbalanced element "input"
186 (** )Example_TEST( **) "Diff_App-No.123a" (*complete Model, empty References*)
189 Given: \<open>Constants [r = 7]\<close>
190 Where: \<open>0 < r\<close>
191 Find: \<open>Maximum A\<close> \<open>AdditionalValues [u, v]\<close>
192 Relate: \<open>Extremum (A = 2 * u * v - u \<up> 2)\<close>
193 \<open>SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\<close>
196 (*\<Odot>*) Problem_Ref: "__/__"
197 (*\<Otimes>*) Method_Ref: "__/__"
200 subsubsection \<open>Empty Specification ready for input by students\<close>
202 In order to help the student (similar to a personal instructur helping a beginner)
203 the \<open>Specification\<close> is given as a template,
204 where so-called \<open>descriptor\<close>s give hints about the input requested
205 (in native language!) and delimiters are (partially) given.
207 For the same reason \<open>Where\<close> is already filled; most beginners are
208 not aware of "where_-conditions", i.e. of preconditions.
211 Example "Diff_App-No.123a"
214 Given: \<open>Constants [__=__, __=__]\<close>
215 Where: \<open>0 < r\<close>
216 Find: \<open>Maximum __\<close> \<open>AdditionalValues [__, __]\<close>
217 Relate: \<open>Extremum __\<close>
218 \<open>SideConditions [__=__, __=__]\<close>
221 (*\<Odot>*) Problem_Ref: "__/__"
222 (*\<Otimes>*) Method_Ref: "__/__"
225 subsubsection \<open>Start Example with a CAS_Cmd\<close>
227 The student wants to use Isabelle/Isac like an Algebra System and issues a CAS_Cmd.
228 The CAS_Cmd triggers implicit Specification (which usually is not requested
231 This user-requirement is not reflected so far. Three possible solutions are sketched below.
233 (*----------------------------------------* )
235 Specification (\<open>Simplify (2*a + 3*a)\<close>):
237 \<open>2*a + 3*a\<close>
239 ( *-----------------------------------------*)
241 (*----------------------------------------* )
242 Example \<open>Simplify (2*a + 3*a)\<close>
245 \<open>2*a + 3*a\<close>
247 ( *----------------------------------------*)
249 (*----------------------------------------* )
250 \<open>Simplify (2*a + 3*a)\<close>
253 \<open>2*a + 3*a\<close>
255 ( *----------------------------------------*)
257 subsubsection \<open>Specification step by step\<close>
260 In an electronic textbook there shall be references to examples given, for instance,
261 by \<open>Example "Diff_App-No.123a"\<close>. Such a reference shall be easily "activated"
262 to start a Specification + Solution at the spot ?and?or? to open a separate window.
264 Activating the reference \<open>Example "Diff_App-No.123a"\<close> shall result in a threefold alternative,
265 where (2)=(3) holds for the parsers:
266 (1) the Example presents a "normal problem" with a Specification (preferred by engineers),
267 see above subsubsection \<open>Empty Specification\<close>,
268 (2) the Example presents a "normal problem" without a Specification (preferred in high-school):
269 |Example "Diff_App-No.123a"
272 | ..first formula as given by the specifid Method..
273 (3) the Example presents a "CAS_Cmd":
274 |Example \<open>Simplify (2*a + 3*a)\<close>
277 | solve (x + 1 = 2, x)
278 \<open>Specification\<close> is always visible in order to remind of the existence.
279 \<open>Outer_Syntax.command \<^command_keyword>\<open>Example\<close>\<close> shall be able to parse all three cases
280 (while still skipping considerations about \<open>Specification\<close> and sub-problems).
282 Below is the Example with case (1):
283 * The lines \<open>text --- remove this line and make content Isar input---\\<close>
284 and ---------- remove this line and make content Isar input---/
285 will be deleted after correct implementation
286 * The \<open>ML \<open>blocks\<close>\<close> in between show, that ISAC is able of "next step guidance";
287 these can be deleted as well.
288 * This Example also shows the toggle between \<open>\<Otimes>\<close> and \<open>\<Odot>\<close>.
292 # 1: ISAC starts the Example by presenting an "empty" Specification.
294 "Presenting" should mean: by "activation" of Example the system presents
295 the empty Specification as a template, where the items give hints on the input format.
297 The field \<open>Where\<close> is already filled, but editable and shows missing input by \<open>False\<close>.
300 \<close> ML \<open> (* # 1: At the first call of \<open>Example\<close> ISAC initialises a calculation *)
301 val p = ([], Pos.Pbl);
302 val pt = Preliminary.update_state @{theory} (*here we have Ctree.EmptyPtree and thus call init_ctree*)
304 ( [("#Given", [("Constants [r = 7]", Position.none)]),
305 ("#Where", [("0 < r", Position.none)]),
306 ("#Find", [("Maximum A", Position.none), ("AdditionalValues [u, v]", Position.none)]),
307 ("#Relate", [("Extremum A = 2 * u * v - u \<up> 2", Position.none),
308 ("SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]", Position.none)])
310 ("Diff_App", "univariate_calculus/Optimisation", "Optimisation/by_univariate_calculus")
315 Example "Diff_App-No.123a"
318 Given: \<open>Constants [__=__, __=__]\<close>
319 Where: \<open>0 < r\<close>
320 Find: \<open>Maximum __\<close> \<open>AdditionalValues [__, __]\<close>
321 Relate: \<open>Extremum __\<close>
322 \<open>SideConditions [__=__, __=__]\<close>
325 (*\<Odot>*) Problem_Ref: "__/__"
326 (*\<Otimes>*) Method_Ref: "__/__"
330 # 2: Somewhere in the Model, the user inputs a next item, which is marked "correct" by ISAC.
332 By this input Where: \<open>0 < r\<close> is not rendered \<open>False\<close> anymore.
334 ML \<open> (* # 2: Somewhere in the Model, the user inputs a next item *)
335 val ("ok", ([(Tactic.Add_Given "Constants [r = 7]", _, _)], _, ptp))
336 = Step.specify_do_next ptp;
338 Example "Diff_App-No.123a"
341 Given: \<open>Constants [r = 7]\<close>
342 Where: \<open>0 < r\<close>
343 Find: \<open>Maximum _\<close> \<open>AdditionalValues [__, __]\<close>
344 Relate: \<open>Extremum _\<close> \<open>SideConditions [__=__, __=__]\<close>
347 (*\<Odot>*) Problem_Ref: "__/__"
348 (*\<Otimes>*) Method_Ref: "__/__"
352 # 3: The user inputs a next item somewhere in the \<open>Specification\<close>;
353 Since this item requests for a list, \<open>AdditionalValues\<close> is marked "incomplete":
355 ML \<open> (* 3: ISAC suggests a next item within a term list *)
356 val ("ok", ([(Tactic.Add_Find "Maximum A", _, _)], _, ptp))
357 = Step.specify_do_next ptp;
359 Example "Diff_App-No.123a"
362 Given: \<open>Constants r = 7\<close>
363 Where: \<open>0 < r\<close>
364 Find: \<open>Maximum _\<close> \<open>AdditionalValues [u]\<close>
365 Relate: \<open>Extremum _\<close> \<open>SideConditions [__=__, __=__]\<close>
368 (*\<Odot>*) Problem_Ref: "__/__"
369 (*\<Otimes>*) Method_Ref: "__/__"
373 # 4: The user inputs a next item, and the item \<open>AdditionalValues\<close> is marked "correct":
375 ML \<open> (* # 4: ISAC suggests a next step on request, even a next element within a list *)
376 val ("ok", ([(Tactic.Add_Find "AdditionalValues [u]", _, _)], _, ptp))
377 = Step.specify_do_next ptp;
380 Example "Diff_App-No.123a"
383 Given: \<open>Constants r = 7\<close>
384 Where: \<open>0 < r\<close>
385 Find: \<open>Maximum _\<close> \<open>AdditionalValues [u, v]\<close>
386 Relate: \<open>Extremum _\<close> \<open>SideConditions [__=__, __=__]\<close>
389 (*\<Odot>*) Problem_Ref: "__/__"
390 (*\<Otimes>*) Method_Ref: "__/__"
394 # 5: Input to \<open>Problem_Ref\<close> is according to the (hidden) formalisation:
396 ML \<open> (* # 5: Input to \<open>Problem_Ref\<close> might change the \<open>Model\<close> *)
398 Example "Diff_App-No.123a"
401 Given: \<open>Constants r = 7\<close>
402 Where: \<open>0 < r\<close>
403 Find: \<open>Maximum _\<close> \<open>AdditionalValues [u, v]\<close>
404 Relate: \<open>Extremum _\<close> \<open>SideConditions [__=__, __=__]\<close>
407 (*\<Odot>*) Problem_Ref: "__/__"
408 (*\<Otimes>*) Method_Ref: "__/__"
412 # 6: Input to \<open>Method_Ref\<close> changes the \<open>Model\<close> to the respective \<open>Method\<close>;
413 There is also a feature to change the \<open>Model\<close> according to
414 direct manipulation of \<open>\<Otimes>\<close> and \<open>\<Odot>\<close>.
416 ML \<open> (* # 6: Input to \<open>Method_Ref\<close> changes the \<open>Model\<close> to the respective \<open>Method\<close> *)
418 Example "Diff_App-No.123a"
420 Model: (* FIXME: lookup model of method *)
421 Given: \<open>Constants r = 7\<close>
422 Where: \<open>0 < r\<close>
423 Find: \<open>Maximum _\<close> \<open>AdditionalValues [u, v]\<close>
424 Relate: \<open>Extremum _\<close> \<open>SideConditions [_]\<close>
427 (*\<Odot>*) Problem_Ref: "univariate_calculus/Optimisation"
428 (*\<Otimes>*) Method_Ref: "Optimisation/by_univariate_calculus"
434 ML \<open> (* # 7: ISAC suggests a next step on request *)
436 text \<open> --- remove this line and make content Isar input---\
437 ---------- remove this line and make content Isar input---/
443 ML \<open> (* # 8: ISAC suggests a next step on request *)
445 text \<open> --- remove this line and make content Isar input---\
446 ---------- remove this line and make content Isar input---/
452 ML \<open> (* # 9: ISAC suggests a next step on request *)
454 text \<open> --- remove this line and make content Isar input---\
455 ---------- remove this line and make content Isar input---/