Walther@60433
|
1 |
(* Title: src/Tools/isac/BridgeJEdit/Demo_Example.thy
|
Walther@60433
|
2 |
Author: Walther Neuper, JKU Linz
|
Walther@60433
|
3 |
(c) due to copyright terms
|
Walther@60433
|
4 |
|
Walther@60433
|
5 |
Runnig example for developing Isabelle/Isac via Isabelle/PIDE in BridgeJEdit
|
Walther@60433
|
6 |
*)
|
Walther@60433
|
7 |
|
Walther@60433
|
8 |
theory Demo_Example
|
Walther@60433
|
9 |
imports Calculation
|
Walther@60433
|
10 |
begin
|
Walther@60433
|
11 |
|
Walther@60434
|
12 |
section \<open>Boilerplate, the example from Isabelle Workshop 2022\<close>
|
Walther@60433
|
13 |
|
Walther@60433
|
14 |
subsection \<open>Specification Phase\<close>
|
Walther@60433
|
15 |
text \<open>Goal for Isabelle Workshop 2022: this part of the example should be ready for demonstration:
|
Walther@60434
|
16 |
1. The keyword \<open>Example\<close> inserts the template underneath
|
Walther@60433
|
17 |
2. The template is filled from a (hidden) formalisation with the following items in the
|
Walther@60434
|
18 |
2.1. \<open>Model\<close>:
|
Walther@60433
|
19 |
* Constants _ ("_" indicates some kind of place holder for input)
|
Walther@60433
|
20 |
* the complete Where-field (the pre-condition), items marked as True | False
|
Walther@60433
|
21 |
* Maximum _, AdditionalValues _
|
Walther@60433
|
22 |
* Extremum _, SideCondition _
|
Walther@60434
|
23 |
2.2 \<open>References\<close>:
|
Walther@60433
|
24 |
* place holders "_" for input
|
Walther@60444
|
25 |
* The toggle switch before \<open>Problem_Ref\<close> | \<open>Method_Ref\<close> is set to \<open>Problem_Ref\<close>
|
Walther@60433
|
26 |
This might be postponed after the Isabelle Workshop.
|
Walther@60433
|
27 |
3. Input to 2.1 is
|
Walther@60433
|
28 |
* type checked and marked as Type-Error
|
Walther@60433
|
29 |
* marked as Correct | Superfluous | Incomplete | Unknown (compare Specify/p-model.sml)
|
Walther@60433
|
30 |
4. Input to 2.2 by selection from a list / tree
|
Walther@60444
|
31 |
5. On update of \<open>Problem_Ref\<close> (in the root problem) also \<open>Problem\<close> is updated;
|
Walther@60434
|
32 |
The argument of \<open>Problem\<close> comes with the template and is read-only.
|
Walther@60444
|
33 |
|
Walther@60444
|
34 |
The specific representation of the Demo_Example demonstrate different situations
|
Walther@60444
|
35 |
in educational settings.
|
Walther@60433
|
36 |
\<close>
|
Walther@60433
|
37 |
|
Walther@60433
|
38 |
subsubsection \<open>Complete Specification\<close>
|
Walther@60433
|
39 |
text \<open>
|
Walther@60444
|
40 |
* This is one correct result of interactive Specification.
|
Walther@60444
|
41 |
* Or this might be presented to the student in one go in order to start Solution immediately
|
Walther@60444
|
42 |
(and nevertheless make the Specification explicit)
|
Walther@60444
|
43 |
Note that \<open>Problem "univariate_calculus/Optimisation"\<close> and
|
Walther@60444
|
44 |
\<open>Problem_Ref: "univariate_calculus/Optimisation"\<close> are redundant; the latter is for input,
|
Walther@60444
|
45 |
the former is given initially and needs to be updated in accordance to \<open>Problem_Ref\<close>.
|
Walther@60444
|
46 |
\<close>
|
Walther@60444
|
47 |
text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
|
Walther@60444
|
48 |
|
Walther@60444
|
49 |
Example "Diff_App/No.123 a"
|
Walther@60444
|
50 |
Problem "univariate_calculus/Optimisation"
|
Walther@60433
|
51 |
Specification:
|
Walther@60433
|
52 |
Model:
|
Walther@60444
|
53 |
Given: \<open>Constants r = 7\<close>
|
Walther@60444
|
54 |
Where: \<open>0 < r\<close>
|
Walther@60444
|
55 |
Find: \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
|
Walther@60444
|
56 |
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>
|
Walther@60433
|
57 |
References:
|
Walther@60444
|
58 |
Theory_Ref: "Diff_App"
|
Walther@60444
|
59 |
\<Otimes> Problem_Ref: "univariate_calculus/Optimisation"
|
Walther@60444
|
60 |
\<Odot> Method_Ref: "Optimisation/by_univariate_calculus"
|
Walther@60433
|
61 |
Solution:
|
Walther@60444
|
62 |
|
Walther@60444
|
63 |
(* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
|
Walther@60433
|
64 |
|
Walther@60433
|
65 |
subsubsection \<open>Empty Specification\<close>
|
Walther@60433
|
66 |
text \<open>
|
Walther@60444
|
67 |
This is presented to the student in one go in order to start interactive Specification.
|
Walther@60444
|
68 |
\<close>
|
Walther@60444
|
69 |
text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
|
Walther@60444
|
70 |
|
Walther@60444
|
71 |
Example "Diff_App/No.123 a"
|
Walther@60444
|
72 |
Problem "univariate_calculus/Optimisation"
|
Walther@60433
|
73 |
Specification:
|
Walther@60433
|
74 |
Model:
|
Walther@60444
|
75 |
Given: \<open>Constants _\<close>
|
Walther@60444
|
76 |
Where: \<open>0 < r\<close>
|
Walther@60444
|
77 |
Find: \<open>Maximum _\<close> \<open>AdditionalValues _\<close>
|
Walther@60444
|
78 |
Relate: \<open>Extremum _\<close> \<open>SideCondition _\<close>
|
Walther@60433
|
79 |
References:
|
Walther@60444
|
80 |
Theory_Ref: "_"
|
Walther@60444
|
81 |
\<Otimes> Problem_Ref: "_"
|
Walther@60444
|
82 |
\<Odot> Method_Ref: "_"
|
Walther@60433
|
83 |
Solution:
|
Walther@60444
|
84 |
|
Walther@60444
|
85 |
(* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
|
Walther@60444
|
86 |
|
Walther@60444
|
87 |
subsubsection \<open>Plain Example\<close>
|
Walther@60444
|
88 |
text \<open>
|
Walther@60444
|
89 |
This can occur in between text offering to start an interactive Calculation by using
|
Walther@60444
|
90 |
"Diff_App/No.123 a" as a link.
|
Walther@60433
|
91 |
\<close>
|
Walther@60444
|
92 |
text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
|
Walther@60444
|
93 |
|
Walther@60444
|
94 |
Example "Diff_App/No.123 a"
|
Walther@60444
|
95 |
|
Walther@60444
|
96 |
(* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
|
Walther@60444
|
97 |
|
Walther@60444
|
98 |
subsubsection \<open>Immediate Start of Interactive Solving\<close>
|
Walther@60444
|
99 |
text \<open>
|
Walther@60444
|
100 |
This
|
Walther@60444
|
101 |
\<close>
|
Walther@60444
|
102 |
text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
|
Walther@60444
|
103 |
|
Walther@60444
|
104 |
Example "Diff_App/No.123 a"
|
Walther@60444
|
105 |
Problem "univariate_calculus/Optimisation"
|
Walther@60444
|
106 |
Specification:
|
Walther@60444
|
107 |
Solution:
|
Walther@60444
|
108 |
|
Walther@60444
|
109 |
(* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
|
Walther@60444
|
110 |
|
Walther@60444
|
111 |
subsubsection \<open>Show the Model associated to Method_Ref\<close>
|
Walther@60444
|
112 |
text \<open>
|
Walther@60444
|
113 |
The Model of a method usually comprises more items than the model of a Problem: all these
|
Walther@60444
|
114 |
are required to run the program such that it automatically generates a Solution. For instance,
|
Walther@60444
|
115 |
compare \<open>problem pbl_bieg\<close> and \<open>method met_biege_2\<close> in \<open>Biegelinie.thy\<close>
|
Walther@60444
|
116 |
(TODO: method/program for \<open>Problem "univariate_calculus/Optimisation"\<close>)
|
Walther@60444
|
117 |
The Model of a method is usually called a guard.
|
Walther@60444
|
118 |
\<close>
|
Walther@60444
|
119 |
text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
|
Walther@60444
|
120 |
|
Walther@60444
|
121 |
Example "Diff_App/No.123 a"
|
Walther@60444
|
122 |
Problem "univariate_calculus/Optimisation"
|
Walther@60444
|
123 |
Specification:
|
Walther@60444
|
124 |
Model:
|
Walther@60444
|
125 |
Given: \<open>Constants r = 7\<close>
|
Walther@60444
|
126 |
Where: \<open>0 < r\<close>
|
Walther@60444
|
127 |
Find: \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
|
Walther@60444
|
128 |
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>
|
Walther@60444
|
129 |
References:
|
Walther@60444
|
130 |
Theory_Ref: "Diff_App"
|
Walther@60444
|
131 |
\<Odot> Problem_Ref: "univariate_calculus/Optimisation"
|
Walther@60444
|
132 |
\<Otimes> Method_Ref: "Optimisation/by_univariate_calculus"
|
Walther@60444
|
133 |
Solution:
|
Walther@60444
|
134 |
|
Walther@60444
|
135 |
(* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
|
Walther@60444
|
136 |
|
Walther@60433
|
137 |
|
Walther@60433
|
138 |
section \<open>Stepwise Development\<close>
|
Walther@60434
|
139 |
|
Walther@60460
|
140 |
subsection \<open>preparing VSCode_Example\<close>
|
Walther@60460
|
141 |
ML \<open>
|
Walther@60460
|
142 |
(**** preparing VSCode_Example ########################################################### ****)
|
Walther@60460
|
143 |
"----------- preparing VSCode_Example ----------------------------------------------------------";
|
Walther@60460
|
144 |
"----------- preparing VSCode_Example ----------------------------------------------------------";
|
Walther@60460
|
145 |
\<close> text \<open>
|
Walther@60460
|
146 |
--- maximum example with Step.specify_do_next --- from test/../step.sml
|
Walther@60460
|
147 |
val fmz = [
|
Walther@60460
|
148 |
(*Problem model:*)
|
Walther@60460
|
149 |
"fixedValues [r=Arbfix]", "maximum A",
|
Walther@60460
|
150 |
"valuesFor [a,b::real]",
|
Walther@60460
|
151 |
"relations [A=a*(b::real), (a/2) \<up> 2 + (b/2) \<up> 2 = (r::real) \<up> 2]",
|
Walther@60460
|
152 |
"relations [A=a*(b::real), (a/2) \<up> 2 + (b/2) \<up> 2 = (r::real) \<up> 2]",
|
Walther@60460
|
153 |
"relations [A=a*(b::real), a/2=r*sin alpha, b/2 = (r::real)*cos (alpha::real)]",
|
Walther@60460
|
154 |
(*MethodC model:*)
|
Walther@60460
|
155 |
"boundVariable a", "boundVariable b", "boundVariable alpha",
|
Walther@60460
|
156 |
"interval {x::real. 0 <= x & x <= 2*r}",
|
Walther@60460
|
157 |
"interval {x::real. 0 <= x & x <= 2*r}",
|
Walther@60460
|
158 |
"interval {x::real. 0 <= x & x <= pi}",
|
Walther@60460
|
159 |
"errorBound (eps=(0::real))"];
|
Walther@60460
|
160 |
val (dI',pI',mI') =
|
Walther@60460
|
161 |
("Diff_App", ["maximum_of", "function"], ["Diff_App", "max_by_calculus"]);
|
Walther@60460
|
162 |
\<close> text \<open>
|
Walther@60460
|
163 |
from paper "Towards Accessible Formal Mathematics with ISAC and Isabelle/VSCode"
|
Walther@60460
|
164 |
|
Walther@60460
|
165 |
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} ]
|
Walther@60460
|
166 |
--- type conflict ^^ ----------^^
|
Walther@60460
|
167 |
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} ]
|
Walther@60460
|
168 |
\<close> ML \<open>
|
Walther@60460
|
169 |
val fmz = [
|
Walther@60460
|
170 |
(*Problem model:*)
|
Walther@60460
|
171 |
"Constants [r = (7::real)]", "Maximum A", "AdditionalValues [u, v]",
|
Walther@60460
|
172 |
"Extremum (A = 2 * u * v - u \<up> 2)",
|
Walther@60464
|
173 |
"SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
|
Walther@60464
|
174 |
"SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
|
Walther@60464
|
175 |
"SideConditions [(u::real) / 2 = r * sin \<alpha>, 2 / v = r * cos \<alpha>]",
|
Walther@60460
|
176 |
(*MethodC model:*)
|
Walther@60460
|
177 |
"FunctionVariable a", "FunctionVariable b", "FunctionVariable \<alpha>",
|
Walther@60460
|
178 |
"Domain {0 <..< r}",
|
Walther@60460
|
179 |
"Domain {0 <..< r}",
|
Walther@60460
|
180 |
"Domain {0 <..< \<pi> / 2}",
|
Walther@60460
|
181 |
"ErrorBound (\<epsilon> = (0::real))"
|
Walther@60460
|
182 |
]: TermC.as_string list;
|
Walther@60460
|
183 |
\<close> ML \<open>
|
Walther@60460
|
184 |
if (fmz |> map (TermC.parseNEW @{context}) |> filter is_some |> length) = 14
|
Walther@60460
|
185 |
then () else error "Formalise.model not parsed completely";
|
Walther@60460
|
186 |
\<close> ML \<open>
|
Walther@60460
|
187 |
val refs =
|
Walther@60460
|
188 |
("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"]);
|
Walther@60460
|
189 |
\<close> ML \<open>
|
Walther@60460
|
190 |
\<close> ML \<open>
|
Walther@60460
|
191 |
\<close> ML \<open>
|
Walther@60460
|
192 |
\<close> ML \<open>
|
Walther@60460
|
193 |
\<close>
|
Walther@60460
|
194 |
|
Walther@60460
|
195 |
|
Walther@60433
|
196 |
subsection \<open>Specification Phase\<close>
|
Walther@60441
|
197 |
text \<open>
|
Walther@60444
|
198 |
Stepwise development of \<open>Outer_Syntax.command \<^command_keyword>\<open>Example\<close>\<close> begins with
|
Walther@60444
|
199 |
the changeset https://hg.risc.uni-linz.ac.at/wneuper/isa/rev/9d98791b4080
|
Walther@60444
|
200 |
in the repository.
|
Walther@60444
|
201 |
|
Walther@60444
|
202 |
The intermediate steps below will be deleted as soon as all above representations
|
Walther@60444
|
203 |
of \<open>Example "Diff_App/No.123 a"\<close> work out.
|
Walther@60434
|
204 |
\<close>
|
Walther@60433
|
205 |
|
Walther@60454
|
206 |
Example "Diff_App/No.123 a"
|
Walther@60452
|
207 |
Problem "univariate_calculus/Optimisation"
|
Walther@60451
|
208 |
Specification:
|
Walther@60451
|
209 |
Model:
|
Walther@60460
|
210 |
Given: \<open>Constants [r = 7]\<close>
|
Walther@60454
|
211 |
Where: \<open>0 < r\<close>
|
Walther@60460
|
212 |
Find: \<open>Maximum A\<close> \<open>AdditionalValues [u, v]\<close>
|
Walther@60460
|
213 |
Relate: \<open>Extremum A = 2 * u * v - u \<up> 2\<close> \<open>SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\<close>
|
Walther@60455
|
214 |
References:
|
Walther@60456
|
215 |
(** )
|
Walther@60455
|
216 |
Theory_Ref: "Diff_App"
|
Walther@60455
|
217 |
(*\<Odot>*) Problem_Ref: "univariate_calculus/Optimisation"
|
Walther@60455
|
218 |
(*\<Otimes>*) Method_Ref: "Optimisation/by_univariate_calculus"
|
Walther@60456
|
219 |
( **)
|
Walther@60439
|
220 |
ML \<open>
|
Walther@60443
|
221 |
val state = the_data @{theory};
|
Walther@60453
|
222 |
\<close> ML \<open>
|
Walther@60443
|
223 |
if Ctree.get_obj Ctree.g_spec state [] =
|
Walther@60455
|
224 |
("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"])
|
Walther@60455
|
225 |
then () else error "Example's values not stored correctly";
|
Walther@60436
|
226 |
\<close> ML \<open>
|
Walther@60453
|
227 |
Ctree.get_obj Ctree.g_spec state []
|
Walther@60434
|
228 |
\<close> ML \<open>
|
Walther@60434
|
229 |
\<close> ML \<open>
|
Walther@60434
|
230 |
\<close>
|
Walther@60433
|
231 |
|
Walther@60453
|
232 |
end
|
Walther@60457
|
233 |
|
Walther@60457
|
234 |
|
Walther@60457
|
235 |
|