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