
Walther@60465: (*  Title:      src/Tools/isac/BridgeJEdit/VSCode_Example.thy
Walther@60433:     Author:     Walther Neuper, JKU Linz
Walther@60433:     (c) due to copyright terms
Walther@60433: 
Walther@60465: Runnig example for developing Isabelle/Isac via Isabelle/PIDE in BridgeJEdit.
Walther@60465: File will go to test/Tools/isac/BridgeJEdit/VSCode_Example.thy
Walther@60465: compare         test/Tools/isac/BridgeJEdit/vscode-example.sml
Walther@60433: *)
Walther@60433: 
Walther@60465: theory VSCode_Example 
Walther@60433:   imports Calculation
Walther@60433: begin
Walther@60433: 
Walther@60465: section \<open>Boilerplate, the example for Isabelle Workshop 2022\<close>
Walther@60433: 
Walther@60433: subsection \<open>Specification Phase\<close>
Walther@60433: text \<open>Goal for Isabelle Workshop 2022: this part of the example should be ready for demonstration:
Walther@60434:   1. The keyword \<open>Example\<close> inserts the template underneath
Walther@60433:   2. The template is filled from a (hidden) formalisation with the following items in the
Walther@60434:     2.1. \<open>Model\<close>:
Walther@60433:         * Constants _  ("_" indicates some kind of place holder for input)
Walther@60433:         * the complete Where-field (the pre-condition), items marked as True | False
Walther@60433:         * Maximum _, AdditionalValues _
Walther@60433:         * Extremum _, SideCondition _
Walther@60434:     2.2 \<open>References\<close>:
Walther@60433:         * place holders "_" for input
Walther@60444:         * The toggle switch before \<open>Problem_Ref\<close> | \<open>Method_Ref\<close> is set to \<open>Problem_Ref\<close>
Walther@60433:           This might be postponed after the Isabelle Workshop.
Walther@60433:   3. Input to 2.1 is 
Walther@60433:     * type checked and marked as Type-Error
Walther@60433:     * marked as Correct | Superfluous | Incomplete | Unknown (compare Specify/p-model.sml)
Walther@60433:   4. Input to 2.2 by selection from a list / tree
Walther@60444:   5. On update of \<open>Problem_Ref\<close> (in the root problem) also \<open>Problem\<close> is updated;
Walther@60434:      The argument of \<open>Problem\<close> comes with the template and is read-only.
Walther@60444: 
Walther@60444: The specific representation of the Demo_Example demonstrate different situations
Walther@60444: in educational settings.
Walther@60433: \<close>
Walther@60433: 
Walther@60433: subsubsection \<open>Complete Specification\<close>
Walther@60433: text \<open>
Walther@60444: * This is one correct result of interactive Specification.
Walther@60444: * Or this might be presented to the student in one go in order to start Solution immediately
Walther@60444:   (and nevertheless make the Specification explicit)
Walther@60444: Note that \<open>Problem "univariate_calculus/Optimisation"\<close> and 
Walther@60444: \<open>Problem_Ref: "univariate_calculus/Optimisation"\<close> are redundant; the latter is for input,
Walther@60444: the former is given initially and needs to be updated in accordance to \<open>Problem_Ref\<close>.
Walther@60444: \<close>
Walther@60444: text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
Walther@60444: 
Walther@60510: Example "Diff_App-No.123a"
Walther@60498:   Specification:
Walther@60498:     Model:
Walther@60498:       Given: \<open>Constants r = 7\<close>
Walther@60498:       Where: \<open>0 < r\<close>
Walther@60498:       Find:  \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
Walther@60498:       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:     References:
Walther@60498:        Theory_Ref: "Diff_App"
Walther@60498:     \<Otimes> Problem_Ref: "univariate_calculus/Optimisation"
Walther@60498:     \<Odot> Method_Ref: "Optimisation/by_univariate_calculus"
Walther@60498:   Solution:
Walther@60444: 
Walther@60444:        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
Walther@60433: 
Walther@60433: subsubsection \<open>Empty Specification\<close>
Walther@60433: text \<open>
Walther@60444:   This is presented to the student in one go in order to start interactive Specification.
Walther@60444: \<close>
Walther@60444: text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
Walther@60444: 
Walther@60510: Example "Diff_App-No.123a"
Walther@60498:   Specification:
Walther@60498:     Model:
Walther@60498:       Given: \<open>Constants _\<close>
Walther@60498:       Where: \<open>0 < r\<close>
Walther@60498:       Find:  \<open>Maximum _\<close> \<open>AdditionalValues _\<close>
Walther@60498:       Relate: \<open>Extremum _\<close> \<open>SideCondition _\<close>     References:
Walther@60444:          Theory_Ref: "_"
Walther@60498:     \<Otimes> Problem_Ref: "_/_"
Walther@60498:     \<Odot> Method_Ref: "_/_"
Walther@60433:     Solution:
Walther@60444: 
Walther@60444:        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
Walther@60444: 
Walther@60444: subsubsection \<open>Plain Example\<close>
Walther@60444: text \<open>
Walther@60444:   This can occur in between text offering to start an interactive Calculation by using
Walther@60510:   "Diff_App-No.123a" as a link.
Walther@60433: \<close>
Walther@60444: text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
Walther@60444: 
Walther@60510: Example "Diff_App-No.123a"
Walther@60444: 
Walther@60444:        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
Walther@60444: 
Walther@60444: subsubsection \<open>Immediate Start of Interactive Solving\<close>
Walther@60444: text \<open>
Walther@60486:   This is requested by teachers in case of CAS_Cmd, e.g. "solve (x+1=2, x)"
Walther@60486:   where Specification usually is not interesting to students
Walther@60486:   and thus done automatically by ISAC in the background.
Walther@60444: \<close>
Walther@60444: text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
Walther@60444: 
Walther@60510: Example "Diff_App-No.123a"
Walther@60444:   Problem "univariate_calculus/Optimisation"
Walther@60444:     Specification:
Walther@60444:     Solution:
Walther@60444: 
Walther@60444:        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
Walther@60444: 
Walther@60444: subsubsection \<open>Show the Model associated to Method_Ref\<close>
Walther@60444: text \<open>
Walther@60444:   The Model of a method usually comprises more items than the model of a Problem: all these
Walther@60444:   are required to run the program such that it automatically generates a Solution. For instance,
Walther@60444:   compare \<open>problem pbl_bieg\<close> and \<open>method met_biege_2\<close> in \<open>Biegelinie.thy\<close>
Walther@60444:   (TODO: method/program for \<open>Problem "univariate_calculus/Optimisation"\<close>)
Walther@60444:   The Model of a method is usually called a guard.
Walther@60444: \<close>
Walther@60444: text \<open> (*.. remove as soon as this works as Isabelle/Isar commands ..*)
Walther@60444: 
Walther@60510: Example "Diff_App-No.123a"
Walther@60444:   Problem "univariate_calculus/Optimisation"
Walther@60444:     Specification:
Walther@60444:       Model:
Walther@60444:         Given: \<open>Constants r = 7\<close>
Walther@60444:         Where: \<open>0 < r\<close>
Walther@60444:         Find:  \<open>Maximum A\<close> \<open>AdditionalValues u, v\<close>
Walther@60444:         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:       References:
Walther@60444:          Theory_Ref: "Diff_App"
Walther@60444:       \<Odot> Problem_Ref: "univariate_calculus/Optimisation"
Walther@60444:       \<Otimes> Method_Ref: "Optimisation/by_univariate_calculus"
Walther@60444:     Solution:
Walther@60444: 
Walther@60444:        (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \<close>
Walther@60444: 
Walther@60433: 
Walther@60433: section \<open>Stepwise Development\<close>
Walther@60434: 
Walther@60460: subsection \<open>preparing VSCode_Example\<close>
Walther@60460: ML \<open>
Walther@60460: (**** preparing VSCode_Example ########################################################### ****)
Walther@60460: "----------- preparing VSCode_Example ----------------------------------------------------------";
Walther@60460: "----------- preparing VSCode_Example ----------------------------------------------------------";
Walther@60460: \<close> text \<open>
Walther@60460: --- maximum example with Step.specify_do_next --- from test/../step.sml
Walther@60460: val fmz = [
Walther@60460: (*Problem model:*)
Walther@60460:   "fixedValues [r=Arbfix]", "maximum A",
Walther@60460:   "valuesFor [a,b::real]",
Walther@60460:   "relations [A=a*(b::real), (a/2) \<up> 2 + (b/2) \<up> 2 = (r::real) \<up> 2]",
Walther@60460:   "relations [A=a*(b::real), (a/2) \<up> 2 + (b/2) \<up> 2 = (r::real) \<up> 2]",
Walther@60460:   "relations [A=a*(b::real), a/2=r*sin alpha, b/2 = (r::real)*cos (alpha::real)]",
Walther@60460: (*MethodC model:*)
Walther@60460:   "boundVariable a", "boundVariable b", "boundVariable alpha",
Walther@60460:   "interval {x::real. 0 <= x & x <= 2*r}",
Walther@60460:   "interval {x::real. 0 <= x & x <= 2*r}",
Walther@60460:   "interval {x::real. 0 <= x & x <= pi}",
Walther@60460:   "errorBound (eps=(0::real))"];
Walther@60460: val (dI',pI',mI') = 
Walther@60460: ("Diff_App", ["maximum_of", "function"], ["Diff_App", "max_by_calculus"]);
Walther@60460: \<close> text \<open>
Walther@60460: from paper "Towards Accessible Formal Mathematics with ISAC and Isabelle/VSCode"
Walther@60460: 
Walther@60460: 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: --- type conflict ^^ ----------^^
Walther@60460: 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: \<close> ML \<open>
Walther@60460: val fmz = [
Walther@60460: (*Problem model:*)
Walther@60460:   "Constants [r = (7::real)]", "Maximum A", "AdditionalValues [u, v]",
Walther@60460:   "Extremum (A = 2 * u * v - u \<up> 2)",
Walther@60464:   "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
Walther@60464:   "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]",
Walther@60464:   "SideConditions [(u::real) / 2 = r * sin \<alpha>, 2 / v = r * cos \<alpha>]",
Walther@60460: (*MethodC model:*)
Walther@60460:   "FunctionVariable a", "FunctionVariable b", "FunctionVariable \<alpha>",
Walther@60460:   "Domain {0 <..< r}",
Walther@60460:   "Domain {0 <..< r}",
Walther@60460:   "Domain {0 <..< \<pi> / 2}",
Walther@60467:   "ErrorBound (\<epsilon> = (0::real))"
Walther@60460: ]: TermC.as_string list;
Walther@60460: val refs = 
Walther@60460: ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"]);
Walther@60460: \<close> ML \<open>
Walther@60460: \<close>
Walther@60460: 
Walther@60433: subsection \<open>Specification Phase\<close>
Walther@60441: text \<open> 
Walther@60444:   Stepwise development of \<open>Outer_Syntax.command \<^command_keyword>\<open>Example\<close>\<close> begins with 
Walther@60444:   the changeset https://hg.risc.uni-linz.ac.at/wneuper/isa/rev/9d98791b4080
Walther@60444:   in the repository.
Walther@60444: 
Walther@60444:   The intermediate steps below will be deleted as soon as all above representations 
Walther@60510:   of Example "Diff_App-No.123a" work out.
Walther@60434: \<close>
Walther@60433: 
Walther@60486: subsubsection \<open>Complete Specification at once\<close>
Walther@60505: Example "Diff_App-No.123a"
Walther@60490:   Specification:
Walther@60490:     Model:
Walther@60490:       Given: \<open>Constants [r = 7]\<close>
Walther@60490:       Where: \<open>0 < r\<close>
Walther@60490:       Find:  \<open>Maximum A\<close> \<open>AdditionalValues [u, v]\<close>
Walther@60490:       Relate: \<open>Extremum A = 2 * u * v - u \<up> 2\<close> 
Walther@60490:         \<open>SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\<close>
Walther@60490:     References:
Walther@60485: (**  )
Walther@60455:          Theory_Ref: "Diff_App"
Walther@60455:   (*\<Odot>*) Problem_Ref: "univariate_calculus/Optimisation"
Walther@60455:   (*\<Otimes>*) Method_Ref: "Optimisation/by_univariate_calculus"
Walther@60490:   Solution:
Walther@60485: (  **)
Walther@60439: ML \<open>
Walther@60489: val state = the_data @{theory}; (* state filled from the above Example by \<open>fun update_state\<close> *)
Walther@60453: \<close> ML \<open>
Walther@60479: val (o_model, refs, _) = Ctree.get_obj Ctree.g_origin state []
Walther@60479: val problem_model = Ctree.get_obj Ctree.g_pbl state []
Walther@60479: val method_model = Ctree.get_obj Ctree.g_met state []
Walther@60489: \<close> text \<open> (* this was with Specify.finish_phasePIDE in init_ctree, cf. 28da4f69d32d *)
Walther@60467: if length o_model = 12  andalso refs = 
Walther@60467:   ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"])
Walther@60479:   andalso length problem_model = 5 andalso length method_model = 8
Walther@60467: then () else error "initialised state CHANGED";
Walther@60434: \<close> ML \<open>
Walther@60489: if length o_model = 12  andalso refs = 
Walther@60489:   ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"])
Walther@60489:   andalso length problem_model = 0 andalso length method_model = 0
Walther@60489: then () else error "initialised state CHANGED";
Walther@60434: \<close> ML \<open>
Walther@60434: \<close>
Walther@60433: 
Walther@60486: subsubsection \<open>Specification step by step\<close>
Walther@60491: text \<open>
Walther@60491:   see $ISABELLE_ISAC_TEST/Tools/isac/BridgeJEdit/Test_VSCode_Example.thy
Walther@60491: \<close>
Walther@60486: 
Walther@60453: end
Walther@60457: 
Walther@60457: 
Walther@60457: 




