1 (* Title: src/Tools/isac/BridgeJEdit/VSCode_Example.thy
2 Author: Walther Neuper, JKU Linz
3 (c) due to copyright terms
5 Runnig example for developing Isabelle/Isac via Isabelle/PIDE in BridgeJEdit.
6 File will go to test/Tools/isac/BridgeJEdit/VSCode_Example.thy
7 compare test/Tools/isac/BridgeJEdit/vscode-example.sml
14 section \<open>Boilerplate, the example for Isabelle Workshop 2022\<close>
16 subsection \<open>Specification Phase\<close>
17 text \<open>Goal for Isabelle Workshop 2022: this part of the example should be ready for demonstration:
18 1. The keyword \<open>Example\<close> inserts the template underneath
19 2. The template is filled from a (hidden) formalisation with the following items in the
20 2.1. \<open>Model\<close>:
21 * Constants _ ("_" indicates some kind of place holder for input)
22 * the complete Where-field (the pre-condition), items marked as True | False
23 * Maximum _, AdditionalValues _
24 * Extremum _, SideCondition _
25 2.2 \<open>References\<close>:
26 * place holders "_" for input
27 * The toggle switch before \<open>Problem_Ref\<close> | \<open>Method_Ref\<close> is set to \<open>Problem_Ref\<close>
28 This might be postponed after the Isabelle Workshop.
30 * type checked and marked as Type-Error
31 * marked as Correct | Superfluous | Incomplete | Unknown (compare Specify/p-model.sml)
32 4. Input to 2.2 by selection from a list / tree
33 5. On update of \<open>Problem_Ref\<close> (in the root problem) also \<open>Problem\<close> is updated;
34 The argument of \<open>Problem\<close> comes with the template and is read-only.
36 The specific representation of the Demo_Example demonstrate different situations
37 in educational settings.
40 subsubsection \<open>Complete Specification\<close>
42 * This is one correct result of interactive Specification.
43 * Or this might be presented to the student in one go in order to start Solution immediately
44 (and nevertheless make the Specification explicit)
45 Note that \<open>Problem "univariate_calculus/Optimisation"\<close> and
46 \<open>Problem_Ref: "univariate_calculus/Optimisation"\<close> are redundant; the latter is for input,
47 the former is given initially and needs to be updated in accordance to \<open>Problem_Ref\<close>.
49 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
51 Example "Diff_App/No.123 a"
52 Problem "univariate_calculus/Optimisation"
55 Given: \<open>Constants r = 7\<close>
56 Where: \<open>0 < r\<close>
57 Find: \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
58 Relate: \<open>Extremum A = 2 \<sqdot> u \<sqdot> v − u \<up> 2\<close> \<open>SideCondition (u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2\<close>
60 Theory_Ref: "Diff_App"
61 \<Otimes> Problem_Ref: "univariate_calculus/Optimisation"
62 \<Odot> Method_Ref: "Optimisation/by_univariate_calculus"
65 (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
67 subsubsection \<open>Empty Specification\<close>
69 This is presented to the student in one go in order to start interactive Specification.
71 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
73 Example "Diff_App/No.123 a"
74 Problem "univariate_calculus/Optimisation"
77 Given: \<open>Constants _\<close>
78 Where: \<open>0 < r\<close>
79 Find: \<open>Maximum _\<close> \<open>AdditionalValues _\<close>
80 Relate: \<open>Extremum _\<close> \<open>SideCondition _\<close>
83 \<Otimes> Problem_Ref: "_"
84 \<Odot> Method_Ref: "_"
87 (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
89 subsubsection \<open>Plain Example\<close>
91 This can occur in between text offering to start an interactive Calculation by using
92 "Diff_App/No.123 a" as a link.
94 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
96 Example "Diff_App/No.123 a"
98 (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
100 subsubsection \<open>Immediate Start of Interactive Solving\<close>
104 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
106 Example "Diff_App/No.123 a"
107 Problem "univariate_calculus/Optimisation"
111 (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
113 subsubsection \<open>Show the Model associated to Method_Ref\<close>
115 The Model of a method usually comprises more items than the model of a Problem: all these
116 are required to run the program such that it automatically generates a Solution. For instance,
117 compare \<open>problem pbl_bieg\<close> and \<open>method met_biege_2\<close> in \<open>Biegelinie.thy\<close>
118 (TODO: method/program for \<open>Problem "univariate_calculus/Optimisation"\<close>)
119 The Model of a method is usually called a guard.
121 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
123 Example "Diff_App/No.123 a"
124 Problem "univariate_calculus/Optimisation"
127 Given: \<open>Constants r = 7\<close>
128 Where: \<open>0 < r\<close>
129 Find: \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
130 Relate: \<open>Extremum A = 2 \<sqdot> u \<sqdot> v − u \<up> 2\<close> \<open>SideCondition (u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2\<close>
132 Theory_Ref: "Diff_App"
133 \<Odot> Problem_Ref: "univariate_calculus/Optimisation"
134 \<Otimes> Method_Ref: "Optimisation/by_univariate_calculus"
137 (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
140 section \<open>Stepwise Development\<close>
142 subsection \<open>preparing VSCode_Example\<close>
144 (**** preparing VSCode_Example ########################################################### ****)
145 "----------- preparing VSCode_Example ----------------------------------------------------------";
146 "----------- preparing VSCode_Example ----------------------------------------------------------";
147 \<close> text \<open>
148 --- maximum example with Step.specify_do_next --- from test/../step.sml
151 "fixedValues [r=Arbfix]", "maximum A",
152 "valuesFor [a,b::real]",
153 "relations [A=a*(b::real), (a/2) \<up> 2 + (b/2) \<up> 2 = (r::real) \<up> 2]",
154 "relations [A=a*(b::real), (a/2) \<up> 2 + (b/2) \<up> 2 = (r::real) \<up> 2]",
155 "relations [A=a*(b::real), a/2=r*sin alpha, b/2 = (r::real)*cos (alpha::real)]",
157 "boundVariable a", "boundVariable b", "boundVariable alpha",
158 "interval {x::real. 0 <= x & x <= 2*r}",
159 "interval {x::real. 0 <= x & x <= 2*r}",
160 "interval {x::real. 0 <= x & x <= pi}",
161 "errorBound (eps=(0::real))"];
163 ("Diff_App", ["maximum_of", "function"], ["Diff_App", "max_by_calculus"]);
164 \<close> text \<open>
165 from paper "Towards Accessible Formal Mathematics with ISAC and Isabelle/VSCode"
167 F_I \<equiv> [ [r = 7], [A, [u, v]], [A = 2 * u * v - u \<up> 2 , ( 2 / u ) \<up> 2 + ( 2 / v ) \<up> 2 = r \<up> 2], {0 <..< r} ]
168 --- type conflict ^^ ----------^^
169 F_II \<equiv> [ [r = 7], [A, \<alpha>], [A = 2 * u * v - u \<up> 2 , u / 2 = r * sin \<alpha>, 2 / v = r * cos \<alpha>], {0 <..< \<pi> / 2} ]
173 "Constants [r = (7::real)]", "Maximum A", "AdditionalValues [u, v]",
174 "Extremum (A = 2 * u * v - u \<up> 2)",
175 "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
176 "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
177 "SideConditions [(u::real) / 2 = r * sin \<alpha>, 2 / v = r * cos \<alpha>]",
179 "FunctionVariable a", "FunctionVariable b", "FunctionVariable \<alpha>",
182 "Domain {0 <..< \<pi> / 2}",
183 "ErrorBound (\<epsilon> = (0::real))"
184 ]: TermC.as_string list;
186 ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"]);
190 subsection \<open>Specification Phase\<close>
192 Stepwise development of \<open>Outer_Syntax.command \<^command_keyword>\<open>Example\<close>\<close> begins with
193 the changeset https://hg.risc.uni-linz.ac.at/wneuper/isa/rev/9d98791b4080
196 The intermediate steps below will be deleted as soon as all above representations
197 of \<open>Example "Diff_App/No.123 a"\<close> work out.
200 Example "Diff_App/No.123 a"
201 Problem "univariate_calculus/Optimisation"
204 Given: \<open>Constants [r = 7]\<close>
205 Where: \<open>0 < r\<close>
206 Find: \<open>Maximum A\<close> \<open>AdditionalValues [u, v]\<close>
207 Relate: \<open>Extremum A = 2 * u * v - u \<up> 2\<close>
208 \<open>SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\<close>
211 Theory_Ref: "Diff_App"
212 (*\<Odot>*) Problem_Ref: "univariate_calculus/Optimisation"
213 (*\<Otimes>*) Method_Ref: "Optimisation/by_univariate_calculus"
216 val state = the_data @{theory};
218 val (o_model, refs, _) = Ctree.get_obj Ctree.g_origin state []
219 val problem_model = Ctree.get_obj Ctree.g_pbl state []
220 val method_model = Ctree.get_obj Ctree.g_met state []
222 if length o_model = 12 andalso refs =
223 ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"])
224 andalso length problem_model = 5 andalso length method_model = 8
225 then () else error "initialised state CHANGED";