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