src/Tools/isac/BridgeJEdit/Calculation.thy
author Walther Neuper <walther.neuper@jku.at>
Fri, 22 Jan 2021 12:31:19 +0100
changeset 60148 c421bae56b93
parent 60147 d3cb5af53d3d
child 60149 f01072d28542
permissions -rw-r--r--
step 5.3: separate code for keyword Problem to preliminary file
     1 (*  Title:      src/Tools/isac/BridgeJEdit/Calculation.thy
     2     Author:     Walther Neuper, JKU Linz
     3     (c) due to copyright terms
     4 
     5 Outer syntax for Isabelle/Isac's Calculation.
     6 *)
     7 
     8 theory Calculation
     9 imports
    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 *)
    13 keywords
    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 *)
    22 begin
    23 
    24 (**)ML_file parseC.sml(**)
    25 (**)ML_file preliminary.sml(**)
    26 (**)ML_file "~~/test/Tools/isac/BridgeJEdit/preliminary.sml"(*remove with next step*)
    27 
    28 
    29 section \<open>new code for Outer_Syntax Example, Problem, ...\<close>
    30 
    31 subsection \<open>code for Problem\<close>
    32 text \<open>
    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.
    36 \<close> ML \<open>
    37 \<close> ML \<open>
    38 \<close> 
    39 
    40 subsubsection \<open>TODO\<close>
    41 ML \<open>
    42 \<close> ML \<open>
    43 \<close> ML \<open>
    44 \<close>
    45 
    46 subsubsection \<open>TODO\<close>
    47 ML \<open>
    48 \<close> ML \<open>
    49 \<close> ML \<open>
    50 \<close>
    51 
    52 subsubsection \<open>TODO\<close>
    53 ML \<open>
    54 \<close> ML \<open>
    55 \<close> ML \<open>
    56 \<close>
    57 
    58 section \<open>setup command_keyword \<close>
    59 ML \<open>
    60 \<close> ML \<open>
    61 val _ =                                                  
    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)));
    65 \<close> ML \<open>
    66 val _ =
    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);
    70 \<close> ML \<open>
    71 Preliminary.prove_vc: ParseC.problem -> Proof.context -> Proof.state;
    72 SPARK_Commands.prove_vc: string -> Proof.context -> Proof.state
    73 \<close> ML \<open>
    74 \<close>
    75 
    76 subsection \<open>test runs with Example\<close>
    77 subsubsection \<open>with new code\<close>
    78 text \<open>
    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
    81 
    82     Example \<open>/usr/local/isabisac/src/Tools/isac/Examples/exp_Statics_Biegel_Timischl_7-70\<close>
    83 
    84   This now gives no error, but also no <Output>. See child of 3ea616c84845.
    85 \<close>
    86 
    87 subsubsection \<open>with original SPARK code\<close>
    88 text \<open>
    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".
    92 
    93   spark_proof_functions is required for proof below..
    94 \<close>
    95 (*//------------------- outcomment before creating session Isac ----------------------------\\* )
    96 (**)
    97   spark_proof_functions gcd = "gcd :: int \<Rightarrow> int \<Rightarrow> int"
    98 (**)
    99 spark_open \<open>~~/src/HOL/SPARK/Examples/Gcd/greatest_common_divisor/g_c_d\<close>
   100 (*Output..* )
   101 The following verification conditions remain to be proved:
   102   procedure_g_c_d_4
   103   procedure_g_c_d_11
   104 ( **)
   105 spark_vc procedure_g_c_d_4
   106 proof -
   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])
   110 (** )
   111 proof -
   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])
   115 next
   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)
   118 qed
   119 ( **)oops(**)
   120 (** )sorry( **)
   121 
   122 spark_vc procedure_g_c_d_11
   123   sorry
   124 (** )
   125 spark_end
   126 ( *Bad path binding: "$ISABELLE_HOME/src/HOL/SPARK/Examples/Gcd/greatest_common_divisor/g_c_d.prv"*)
   127 
   128 ( *\\------------------- outcomment before creating session Isac ----------------------------//*)
   129 
   130 
   131 section \<open>Notes: adapt spark_vc to Problem using Naproche as model\<close>
   132 
   133 subsection \<open>survey on steps of investigation\<close>
   134 text \<open>
   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.
   139 
   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).
   146 
   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.
   150 
   151   Tracing the calls of Output.report shows some properties of handling proofs,
   152   see text in SPARK/Examples/Gcd/Greatest_Common_Divisor.thy.
   153 \<close>
   154 
   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 - ...
   158 *)