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