1 (* Title: src/Tools/isac/BridgeJEdit/Calculation.thy
2 Author: Walther Neuper, JKU Linz
3 (c) due to copyright terms
5 Outer syntax for Isabelle/Isac's Calculation.
10 "~~/src/Tools/isac/MathEngine/MathEngine"
11 (**)"HOL-SPARK.SPARK" (** ) preliminarily for parsing Example files *)
12 (** )"HOL-Word.Word"( ** ) trial on ERROR in definition sdiv below *)
14 "Example" :: thy_load ("str") (* "spark_vc" :: thy_goal *)
15 and "Problem" :: thy_decl (* root-problem + recursively in Solution;
16 "spark_vc" :: thy_goal *)
17 and "Specification" "Model" "References" "Solution" (* structure only *)
18 and "Given" "Find" "Relate" "Where" (* await input of term *)
19 and "RTheory" (* await input of string; "R" distingues "Problem".."RProblem" *)
20 and "RProblem" "RMethod" (* await input of string list *)
21 "Tactic" (* optional for each step 0..end of calculation *)
24 (**)ML_file parseC.sml(**)
25 (**)ML_file preliminary.sml(**)
26 (**)ML_file "~~/test/Tools/isac/BridgeJEdit/preliminary.sml"(*remove with next step*)
29 section \<open>new code for Outer_Syntax Example, Problem, ...\<close>
31 subsection \<open>code for Problem\<close>
33 Again, we copy code from spark_vc into Calculation.thy and
34 add functionality for Problem
35 such that the code keeps running during adaption from spark_vc to Problem.
40 subsubsection \<open>TODO\<close>
46 subsubsection \<open>TODO\<close>
52 subsubsection \<open>TODO\<close>
58 section \<open>setup command_keyword \<close>
62 Outer_Syntax.command \<^command_keyword>\<open>Example\<close> "start a Calculation from a Formalise-file"
63 (Resources.provide_parse_files "Example" -- Parse.parname
64 >> (Toplevel.theory o (Preliminary.load_formalisation ParseC.formalisation)));
67 Outer_Syntax.local_theory_to_proof \<^command_keyword>\<open>Problem\<close>
68 "start a Specification, either from scratch or from preceding 'Example'"
69 (ParseC.problem >> Preliminary.prove_vc);
71 Preliminary.prove_vc: ParseC.problem -> Proof.context -> Proof.state;
72 SPARK_Commands.prove_vc: string -> Proof.context -> Proof.state
76 subsection \<open>test runs with Example\<close>
77 subsubsection \<open>with new code\<close>
79 Starting the Calculation for the Example requires session Isac with Isac.Biegelinie etc.
80 So, do ~~$ ./zcoding-to-test.sh and use Test_Some.thy to evaluate
82 Example \<open>/usr/local/isabisac/src/Tools/isac/Examples/exp_Statics_Biegel_Timischl_7-70\<close>
84 This now gives no error, but also no <Output>. See child of 3ea616c84845.
87 subsubsection \<open>with original SPARK code\<close>
89 The sequence of code below is copied from SPARK/Examples/Gcd/Greatest_Common_Divisor.thy.
90 But here the code works only partially (see ERROR at end).
91 Thus it is advisable to run tests in Test_Some.thy, where "Example" has "Biegelinie".
93 spark_proof_functions is required for proof below..
95 (*//------------------- outcomment before creating session Isac ----------------------------\\* )
97 spark_proof_functions gcd = "gcd :: int \<Rightarrow> int \<Rightarrow> int"
99 spark_open \<open>~~/src/HOL/SPARK/Examples/Gcd/greatest_common_divisor/g_c_d\<close>
101 The following verification conditions remain to be proved:
105 spark_vc procedure_g_c_d_4
107 from \<open>0 < d\<close> have "0 \<le> c mod d" by (rule pos_mod_sign)
108 with \<open>0 \<le> c\<close> \<open>0 < d\<close> \<open>c - c sdiv d * d \<noteq> 0\<close> show ?C1
109 by (simp add: sdiv_pos_pos minus_div_mult_eq_mod [symmetric])
112 from \<open>0 < d\<close> have "0 \<le> c mod d" by (rule pos_mod_sign)
113 with \<open>0 \<le> c\<close> \<open>0 < d\<close> \<open>c - c sdiv d * d \<noteq> 0\<close> show ?C1
114 by (simp add: sdiv_pos_pos minus_div_mult_eq_mod [symmetric])
116 from \<open>0 \<le> c\<close> \<open>0 < d\<close> \<open>gcd c d = gcd m n\<close> show ?C2
117 by (simp add: sdiv_pos_pos minus_div_mult_eq_mod [symmetric] gcd_non_0_int)
122 spark_vc procedure_g_c_d_11
126 ( *Bad path binding: "$ISABELLE_HOME/src/HOL/SPARK/Examples/Gcd/greatest_common_divisor/g_c_d.prv"*)
128 ( *\\------------------- outcomment before creating session Isac ----------------------------//*)
131 section \<open>Notes: adapt spark_vc to Problem using Naproche as model\<close>
133 subsection \<open>survey on steps of investigation\<close>
135 We stopped step 3.4 going down from Outer_Syntax.local_theory_to_proof into proof.
136 Now we go the other way: Naproche checks the input via the Isabelle/server
137 and outputs highlighting, semantic annotations and errors via PIDE ---
138 and we investigate the output.
140 Investigation of Naproche showed, that annotations are ONLY sent bY
141 Output.report: string list -> unit, where string holds markup.
142 For Output.report @ {print} is NOT available, so we trace all respective CALLS.
143 However, NO @ {print} available in src/Pure is reached by "spark_vc procedure_g_c_d_4",
144 so tracing is done by writeln (which breaks build between Main and Complex_Main
145 by writing longer strings, see Pure/General/output.ML).
147 Tracing is implemented in (1) Isabelle_Naproche and in (2) isabisac in parallel;
148 (1) requires only Pure, thus is built quicker, but does NOT handle proofs within ML
149 (2) requires HOL.SPARK, there is full proof handling, but this is complex.
151 Tracing the calls of Output.report shows some properties of handling proofs,
152 see text in SPARK/Examples/Gcd/Greatest_Common_Divisor.thy.
155 end(* SEE "outcomment before creating session Isac" ABOVE !!! OTHERWISE YOU HAVE..
156 ERROR: Found the end of the theory, but the last SPARK environment is still open.
157 ..is acceptable for testing spark_vc .. proof - ...