1 (* Title: src/Tools/isac/BridgeJEdit/Calculation.thy
2 Author: Walther Neuper, JKU Linz
4 Outer syntax for Isabelle/Isac's Calculation interactive via Isabelle/PIDE.
5 Second trial following Makarius' definition of "problem" already existing in this repository.
10 (**)"$ISABELLE_ISAC/Knowledge/Build_Thydata" (*remove after devel.of BridgeJEdit*)
11 (**)"$ISABELLE_ISAC/MathEngine/MathEngine"
12 (** )"SPARK_FDL" ( * remove after devel.of BridgeJEdit*)
13 keywords "Example" :: thy_decl
14 and "Problem" "Specification" "Model" "References" "Solution"
19 ML_file "preliminary.sml"
21 section \<open>new code for Outer_Syntax Example ...\<close>
23 stepwise development starts at changeset
24 https://hg.risc.uni-linz.ac.at/wneuper/isa/rev/9d98791b4080
25 and can be inspected following the subsequent changesets..
31 structure Data = Theory_Data
33 type T = Ctree.ctree option;
39 val set_data = Data.put o SOME;
41 case Data.get thy of NONE => Ctree.EmptyPtree
42 | SOME ctree => ctree;
45 A provisional Example collection.
47 For notes from ISAC's discontinued Java front-end see
48 https://isac.miraheze.org/wiki/Extend_ISAC_Knowledge#Add_an_example_in_XML_format
50 type description = string
51 type example = (description * Formalise.T)
52 val example_store = []: (string * example) list
54 val example_store = AList.update op= ("Diff_App/No.123 a",
55 ("The efficiency of an electrical coil depends on the mass of the kernel." ^
56 "Given is a kernel with cross-sectional area determined by two rectangles" ^
57 "of same shape as shown in the figure." ^
58 "Given a radius r = 7, determine the length u and width v of the rectangles" ^
59 "such that the cross-sectional area A (and thus the mass of the kernel) is a" ^
61 (["[r = 7]", "[A, [u, v]]", "[A = 2 \<sqdot> u \<sqdot> v - u 2 , ( 2 u ) 2 + ( 2 v ) 2 = r 2 ]",
62 "{0 < .. < r}"]: TermC.as_string list,
63 (*TODO: compare paper + test/../Diff_App: more than one list of Model_Def.form_model? *)
64 ("Diff_App", ["univariate_calculus", "Optimisation"],
65 ["Optimisation", "by_univariate_calculus"]): References.T)): example) example_store
67 case AList.lookup op= example_store "Diff_App/No.123 a" of
68 SOME (_, (["[r = 7]", "[A, [u, v]]", "[A = 2 \<sqdot> u \<sqdot> v - u 2 , ( 2 u ) 2 + ( 2 v ) 2 = r 2 ]", "{0 < .. < r}"],
69 ("Diff_App", ["univariate_calculus", "Optimisation"] ,["Optimisation", "by_univariate_calculus"])))
71 | _ => error "intermed. example_store CHANGED";
74 (*? I_Model.* or Problem.* ?*)
75 fun check_input (*ctxt o-model ??*) (_: Problem.model_input) = []: I_Model.T
77 fun update_state (model, (thy_id, probl_id, meth_id)) (*at the first encounter of an Example*)
79 Ctree.Nd (Ctree.PblObj {
80 fmz = Formalise.empty, origin = (O_Model.empty, References.empty, TermC.empty),
81 spec = (thy_id, probl_id, meth_id), probl = check_input model, meth = []: Model_Def.i_model,
82 ctxt = ContextC.empty, loc = (NONE, NONE),
83 branch = Ctree.NoBranch, ostate = Ctree.Incomplete, result = (TermC.empty, [])}, [])
84 | update_state (model, (thy_id, probl_id, meth_id)) (*TODO +switch RProblem | RMethod*)
85 (Ctree.Nd (Ctree.PblObj {fmz, origin, spec = _, probl = _, meth, ctxt, loc, branch, ostate, result},
87 Ctree.Nd (Ctree.PblObj {
88 fmz = fmz, origin = origin,
89 spec = (thy_id, probl_id, meth_id), probl = check_input model, meth = meth,
90 ctxt = ctxt, loc = loc,
91 branch = branch, ostate = ostate, result = result}, children)
92 | update_state _ _ = raise ERROR "update_state: uncovered case in fun.def."
94 update_state: Problem.model_input * (ThyC.id * Problem.id * MethodC.id)
95 -> Ctree.ctree -> Ctree.ctree
97 type references_input = (string * (string * string))
99 val parse_references_input =
100 Parse.!!! ( \<^keyword>\<open>Theory_Ref\<close> -- \<^keyword>\<open>Theory_Ref\<close> |-- Parse.name --
101 Parse.!!! ( \<^keyword>\<open>Problem_Ref\<close> -- \<^keyword>\<open>Theory_Ref\<close> |-- Parse.name --
102 Parse.!!! ( \<^keyword>\<open>Method_Ref\<close> -- \<^keyword>\<open>Theory_Ref\<close> |-- Parse.name)))
104 parse_references_input: references_input parser (*TODO: dpes not yet work,
105 thus in Outer_Syntax.command \<^command_keyword>\<open>Example\<close> replacced by Problem.parse_cas*)
107 op -- : ('a -> 'b * 'c) * ('c -> 'd * 'e) -> 'a -> ('b * 'd) * 'e;
108 op |-- : ('a -> 'b * 'c) * ('c -> 'd * 'e) -> 'a -> 'd * 'e
113 Outer_Syntax.command \<^command_keyword>\<open>Example\<close>
114 "prepare ISAC problem type and register it to Knowledge Store"
115 (Parse.name -- Parse.!!! ( \<^keyword>\<open>Problem\<close> |-- Parse.name --
116 Parse.!!! ( \<^keyword>\<open>Specification\<close> -- \<^keyword>\<open>:\<close> --
117 \<^keyword>\<open>Model\<close> -- \<^keyword>\<open>:\<close> |-- Problem.parse_model_input --
118 Parse.!!! ( \<^keyword>\<open>References\<close> -- \<^keyword>\<open>:\<close> |-- (*parse_references_input*)Problem.parse_cas))) >>
119 (fn (_(*exp_id*), (_(*probl_id'*), (model_input, _(*references_input*)))) =>
120 Toplevel.theory (fn thy =>
122 val (thy_id, (probl_id, meth_id)) = (*references_input*)("Diff_App", ("univariate_calculus/Optimisation", "Optimisation/by_univariate_calculus"))
123 val input = update_state (model_input,
124 (thy_id, References_Def.explode_id probl_id, References_Def.explode_id meth_id))
126 in set_data input thy end)));
129 (*/----------------------------------------------------------------------------\*)
130 Parse.name -- Parse.!!! ( \<^keyword>\<open>Problem\<close> |-- Parse.name --
131 Parse.!!! ( \<^keyword>\<open>Specification\<close> -- \<^keyword>\<open>:\<close> --
132 \<^keyword>\<open>Model\<close> -- \<^keyword>\<open>:\<close> |-- Problem.parse_model_input --
133 Parse.!!! ( \<^keyword>\<open>References\<close> -- \<^keyword>\<open>:\<close> |-- parse_references_input)))
134 : (string * (string * (Problem.model_input * references_input))) parser
135 (*\----------------------------------------------------------------------------/*)
137 (*/----------------------------------------------------------------------------\*)
138 (string * (string * (Problem.model_input * references_input)))
139 (*\----------------------------------------------------------------------------/*)
141 (*/----------------------------------------------------------------------------\* )
142 the type above is the type of the argument of \<open>(fn (_(*name*),..\<close>
143 ( *\----------------------------------------------------------------------------/*)