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
     1 (*  Title:      src/Tools/isac/BridgeJEdit/VSCode_Example.thy
     2     Author:     Walther Neuper, JKU Linz
     3     (c) due to copyright terms
     4 
     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
     8 *)
     9 
    10 theory VSCode_Example 
    11   imports Calculation
    12 begin
    13 
    14 section \<open>Boilerplate, the example for Isabelle Workshop 2022\<close>
    15 
    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.
    29   3. Input to 2.1 is 
    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.
    35 
    36 The specific representation of the Demo_Example demonstrate different situations
    37 in educational settings.
    38 \<close>
    39 
    40 subsubsection \<open>Complete Specification\<close>
    41 text \<open>
    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>.
    48 \<close>
    49 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
    50 
    51 Example "Diff_App-No.123a"
    52   Specification:
    53     Model:
    54       Given: \<open>Constants r = 7\<close>
    55       Where: \<open>0 < r\<close>
    56       Find:  \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
    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>
    58     References:
    59        Theory_Ref: "Diff_App"
    60     \<Otimes> Problem_Ref: "univariate_calculus/Optimisation"
    61     \<Odot> Method_Ref: "Optimisation/by_univariate_calculus"
    62   Solution:
    63 
    64        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
    65 
    66 subsubsection \<open>Empty Specification\<close>
    67 text \<open>
    68   This is presented to the student in one go in order to start interactive Specification.
    69 \<close>
    70 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
    71 
    72 Example "Diff_App-No.123a"
    73   Specification:
    74     Model:
    75       Given: \<open>Constants _\<close>
    76       Where: \<open>0 < r\<close>
    77       Find:  \<open>Maximum _\<close> \<open>AdditionalValues _\<close>
    78       Relate: \<open>Extremum _\<close> \<open>SideCondition _\<close>     References:
    79          Theory_Ref: "_"
    80     \<Otimes> Problem_Ref: "_/_"
    81     \<Odot> Method_Ref: "_/_"
    82     Solution:
    83 
    84        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
    85 
    86 subsubsection \<open>Plain Example\<close>
    87 text \<open>
    88   This can occur in between text offering to start an interactive Calculation by using
    89   "Diff_App-No.123a" as a link.
    90 \<close>
    91 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
    92 
    93 Example "Diff_App-No.123a"
    94 
    95        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
    96 
    97 subsubsection \<open>Immediate Start of Interactive Solving\<close>
    98 text \<open>
    99   This is requested by teachers in case of CAS_Cmd, e.g. "solve (x+1=2, x)"
   100   where Specification usually is not interesting to students
   101   and thus done automatically by ISAC in the background.
   102 \<close>
   103 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
   104 
   105 Example "Diff_App-No.123a"
   106   Problem "univariate_calculus/Optimisation"
   107     Specification:
   108     Solution:
   109 
   110        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
   111 
   112 subsubsection \<open>Show the Model associated to Method_Ref\<close>
   113 text \<open>
   114   The Model of a method usually comprises more items than the model of a Problem: all these
   115   are required to run the program such that it automatically generates a Solution. For instance,
   116   compare \<open>problem pbl_bieg\<close> and \<open>method met_biege_2\<close> in \<open>Biegelinie.thy\<close>
   117   (TODO: method/program for \<open>Problem "univariate_calculus/Optimisation"\<close>)
   118   The Model of a method is usually called a guard.
   119 \<close>
   120 text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
   121 
   122 Example "Diff_App-No.123a"
   123   Problem "univariate_calculus/Optimisation"
   124     Specification:
   125       Model:
   126         Given: \<open>Constants r = 7\<close>
   127         Where: \<open>0 < r\<close>
   128         Find:  \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
   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>
   130       References:
   131          Theory_Ref: "Diff_App"
   132       \<Odot> Problem_Ref: "univariate_calculus/Optimisation"
   133       \<Otimes> Method_Ref: "Optimisation/by_univariate_calculus"
   134     Solution:
   135 
   136        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
   137 
   138 
   139 section \<open>Stepwise Development\<close>
   140 
   141 subsection \<open>preparing VSCode_Example\<close>
   142 ML \<open>
   143 (**** preparing VSCode_Example ########################################################### ****)
   144 "----------- preparing VSCode_Example ----------------------------------------------------------";
   145 "----------- preparing VSCode_Example ----------------------------------------------------------";
   146 \<close> text \<open>
   147 --- maximum example with Step.specify_do_next --- from test/../step.sml
   148 val fmz = [
   149 (*Problem model:*)
   150   "fixedValues [r=Arbfix]", "maximum A",
   151   "valuesFor [a,b::real]",
   152   "relations [A=a*(b::real), (a/2) \<up> 2 + (b/2) \<up> 2 = (r::real) \<up> 2]",
   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=r*sin alpha, b/2 = (r::real)*cos (alpha::real)]",
   155 (*MethodC model:*)
   156   "boundVariable a", "boundVariable b", "boundVariable alpha",
   157   "interval {x::real. 0 <= x & x <= 2*r}",
   158   "interval {x::real. 0 <= x & x <= 2*r}",
   159   "interval {x::real. 0 <= x & x <= pi}",
   160   "errorBound (eps=(0::real))"];
   161 val (dI',pI',mI') = 
   162 ("Diff_App", ["maximum_of", "function"], ["Diff_App", "max_by_calculus"]);
   163 \<close> text \<open>
   164 from paper "Towards Accessible Formal Mathematics with ISAC and Isabelle/VSCode"
   165 
   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} ]
   167 --- type conflict ^^ ----------^^
   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} ]
   169 \<close> ML \<open>
   170 val fmz = [
   171 (*Problem model:*)
   172   "Constants [r = (7::real)]", "Maximum A", "AdditionalValues [u, v]",
   173   "Extremum (A = 2 * u * v - u \<up> 2)",
   174   "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
   175   "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
   176   "SideConditions [(u::real) / 2 = r * sin \<alpha>, 2 / v = r * cos \<alpha>]",
   177 (*MethodC model:*)
   178   "FunctionVariable a", "FunctionVariable b", "FunctionVariable \<alpha>",
   179   "Domain {0 <..< r}",
   180   "Domain {0 <..< r}",
   181   "Domain {0 <..< \<pi> / 2}",
   182   "ErrorBound (\<epsilon> = (0::real))"
   183 ]: TermC.as_string list;
   184 val refs = 
   185 ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"]);
   186 \<close> ML \<open>
   187 \<close>
   188 
   189 subsection \<open>Specification Phase\<close>
   190 text \<open> 
   191   Stepwise development of \<open>Outer_Syntax.command \<^command_keyword>\<open>Example\<close>\<close> begins with 
   192   the changeset https://hg.risc.uni-linz.ac.at/wneuper/isa/rev/9d98791b4080
   193   in the repository.
   194 
   195   The intermediate steps below will be deleted as soon as all above representations 
   196   of Example "Diff_App-No.123a" work out.
   197 \<close>
   198 
   199 subsubsection \<open>Complete Specification at once\<close>
   200 Example "Diff_App-No.123a"
   201   Specification:
   202     Model:
   203       Given: \<open>Constants [r = 7]\<close>
   204       Where: \<open>0 < r\<close>
   205       Find:  \<open>Maximum A\<close> \<open>AdditionalValues [u, v]\<close>
   206       Relate: \<open>Extremum A = 2 * u * v - u \<up> 2\<close> 
   207         \<open>SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\<close>
   208     References:
   209 (**  )
   210          Theory_Ref: "Diff_App"
   211   (*\<Odot>*) Problem_Ref: "univariate_calculus/Optimisation"
   212   (*\<Otimes>*) Method_Ref: "Optimisation/by_univariate_calculus"
   213   Solution:
   214 (  **)
   215 ML \<open>
   216 val state = the_data @{theory}; (* state filled from the above Example by \<open>fun update_state\<close> *)
   217 \<close> ML \<open>
   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 []
   221 \<close> text \<open> (* this was with Specify.finish_phasePIDE in init_ctree, cf. 28da4f69d32d *)
   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";
   226 \<close> ML \<open>
   227 if length o_model = 12  andalso refs = 
   228   ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"])
   229   andalso length problem_model = 0 andalso length method_model = 0
   230 then () else error "initialised state CHANGED";
   231 \<close> ML \<open>
   232 \<close>
   233 
   234 subsubsection \<open>Specification step by step\<close>
   235 text \<open>
   236   see $ISABELLE_ISAC_TEST/Tools/isac/BridgeJEdit/Test_VSCode_Example.thy
   237 \<close>
   238 
   239 end
   240 
   241 
   242