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 \Boilerplate, the example for Isabelle Workshop 2022\ Walther@60433: Walther@60433: subsection \Specification Phase\ Walther@60433: text \Goal for Isabelle Workshop 2022: this part of the example should be ready for demonstration: Walther@60434: 1. The keyword \Example\ 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. \Model\: 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 \References\: Walther@60433: * place holders "_" for input Walther@60444: * The toggle switch before \Problem_Ref\ | \Method_Ref\ is set to \Problem_Ref\ 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 \Problem_Ref\ (in the root problem) also \Problem\ is updated; Walther@60434: The argument of \Problem\ 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: \ Walther@60433: Walther@60433: subsubsection \Complete Specification\ Walther@60433: text \ 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 \Problem "univariate_calculus/Optimisation"\ and Walther@60444: \Problem_Ref: "univariate_calculus/Optimisation"\ are redundant; the latter is for input, Walther@60444: the former is given initially and needs to be updated in accordance to \Problem_Ref\. Walther@60444: \ Walther@60444: text \ (*.. 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: \Constants r = 7\ Walther@60498: Where: \0 < r\ Walther@60498: Find: \Maximum A\ \AdditionalValues u, v\ Walther@60498: Relate: \Extremum A = 2 \ u \ v − u \ 2\ \SideCondition (u / 2) \ 2 + (2 / v) \ 2 = r \ 2\ Walther@60498: References: Walther@60498: Theory_Ref: "Diff_App" Walther@60498: \ Problem_Ref: "univariate_calculus/Optimisation" Walther@60498: \ Method_Ref: "Optimisation/by_univariate_calculus" Walther@60498: Solution: Walther@60444: Walther@60444: (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \ Walther@60433: Walther@60433: subsubsection \Empty Specification\ Walther@60433: text \ Walther@60444: This is presented to the student in one go in order to start interactive Specification. Walther@60444: \ Walther@60444: text \ (*.. 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: \Constants _\ Walther@60498: Where: \0 < r\ Walther@60498: Find: \Maximum _\ \AdditionalValues _\ Walther@60498: Relate: \Extremum _\ \SideCondition _\ References: Walther@60444: Theory_Ref: "_" Walther@60498: \ Problem_Ref: "_/_" Walther@60498: \ Method_Ref: "_/_" Walther@60433: Solution: Walther@60444: Walther@60444: (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \ Walther@60444: Walther@60444: subsubsection \Plain Example\ Walther@60444: text \ 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: \ Walther@60444: text \ (*.. 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 ..*) \ Walther@60444: Walther@60444: subsubsection \Immediate Start of Interactive Solving\ Walther@60444: text \ 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: \ Walther@60444: text \ (*.. 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 ..*) \ Walther@60444: Walther@60444: subsubsection \Show the Model associated to Method_Ref\ Walther@60444: text \ 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 \problem pbl_bieg\ and \method met_biege_2\ in \Biegelinie.thy\ Walther@60444: (TODO: method/program for \Problem "univariate_calculus/Optimisation"\) Walther@60444: The Model of a method is usually called a guard. Walther@60444: \ Walther@60444: text \ (*.. 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: \Constants r = 7\ Walther@60444: Where: \0 < r\ Walther@60444: Find: \Maximum A\ \AdditionalValues u, v\ Walther@60444: Relate: \Extremum A = 2 \ u \ v − u \ 2\ \SideCondition (u / 2) \ 2 + (2 / v) \ 2 = r \ 2\ Walther@60444: References: Walther@60444: Theory_Ref: "Diff_App" Walther@60444: \ Problem_Ref: "univariate_calculus/Optimisation" Walther@60444: \ Method_Ref: "Optimisation/by_univariate_calculus" Walther@60444: Solution: Walther@60444: Walther@60444: (* remove as soon as this ^^^ works as Isabelle/Isar commands ..*) \ Walther@60444: Walther@60433: Walther@60433: section \Stepwise Development\ Walther@60434: Walther@60460: subsection \preparing VSCode_Example\ Walther@60460: ML \ Walther@60460: (**** preparing VSCode_Example ########################################################### ****) Walther@60460: "----------- preparing VSCode_Example ----------------------------------------------------------"; Walther@60460: "----------- preparing VSCode_Example ----------------------------------------------------------"; Walther@60460: \ text \ 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) \ 2 + (b/2) \ 2 = (r::real) \ 2]", Walther@60460: "relations [A=a*(b::real), (a/2) \ 2 + (b/2) \ 2 = (r::real) \ 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: \ text \ Walther@60460: from paper "Towards Accessible Formal Mathematics with ISAC and Isabelle/VSCode" Walther@60460: Walther@60460: F_I \ [ [r = 7], [A, [u, v]], [A = 2 * u * v - u \ 2 , ( 2 / u ) \ 2 + ( 2 / v ) \ 2 = r \ 2], {0 <..< r} ] Walther@60460: --- type conflict ^^ ----------^^ Walther@60460: F_II \ [ [r = 7], [A, \], [A = 2 * u * v - u \ 2 , u / 2 = r * sin \, 2 / v = r * cos \], {0 <..< \ / 2} ] Walther@60460: \ ML \ 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 \ 2)", Walther@60464: "SideConditions [((u::real) / 2) \ 2 + (2 / v) \ 2 = r \ 2]", Walther@60464: "SideConditions [((u::real) / 2) \ 2 + (2 / v) \ 2 = r \ 2]", Walther@60464: "SideConditions [(u::real) / 2 = r * sin \, 2 / v = r * cos \]", Walther@60460: (*MethodC model:*) Walther@60460: "FunctionVariable a", "FunctionVariable b", "FunctionVariable \", Walther@60460: "Domain {0 <..< r}", Walther@60460: "Domain {0 <..< r}", Walther@60460: "Domain {0 <..< \ / 2}", Walther@60467: "ErrorBound (\ = (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: \ ML \ Walther@60460: \ Walther@60460: Walther@60433: subsection \Specification Phase\ Walther@60441: text \ Walther@60444: Stepwise development of \Outer_Syntax.command \<^command_keyword>\Example\\ 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: \ Walther@60433: Walther@60486: subsubsection \Complete Specification at once\ Walther@60505: Example "Diff_App-No.123a" Walther@60490: Specification: Walther@60490: Model: Walther@60490: Given: \Constants [r = 7]\ Walther@60490: Where: \0 < r\ Walther@60490: Find: \Maximum A\ \AdditionalValues [u, v]\ Walther@60490: Relate: \Extremum A = 2 * u * v - u \ 2\ Walther@60490: \SideConditions [((u::real) / 2) \ 2 + (2 / v) \ 2 = r \ 2]\ Walther@60490: References: Walther@60485: (** ) Walther@60455: Theory_Ref: "Diff_App" Walther@60455: (*\*) Problem_Ref: "univariate_calculus/Optimisation" Walther@60455: (*\*) Method_Ref: "Optimisation/by_univariate_calculus" Walther@60490: Solution: Walther@60485: ( **) Walther@60439: ML \ Walther@60489: val state = the_data @{theory}; (* state filled from the above Example by \fun update_state\ *) Walther@60453: \ ML \ 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: \ text \ (* 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: \ ML \ 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: \ ML \ Walther@60434: \ Walther@60433: Walther@60486: subsubsection \Specification step by step\ Walther@60491: text \ Walther@60491: see $ISABELLE_ISAC_TEST/Tools/isac/BridgeJEdit/Test_VSCode_Example.thy Walther@60491: \ Walther@60486: Walther@60453: end Walther@60457: Walther@60457: Walther@60457: