src/HOL/SPARK/Examples/Gcd/Greatest_Common_Divisor.thy
author Walther Neuper <walther.neuper@jku.at>
Mon, 26 Oct 2020 13:52:26 +0100
changeset 60095 5fcd4f0c3886
parent 60094 918d4f85b5bc
child 60096 c161c3af5b8d
permissions -rw-r--r--
copy Outer_Syntax.command..spark_open as model for Isac Calculation
     1 (*  Title:      HOL/SPARK/Examples/Gcd/Greatest_Common_Divisor.thy
     2     Author:     Stefan Berghofer
     3     Copyright:  secunet Security Networks AG
     4 *)
     5 
     6 theory Greatest_Common_Divisor
     7 imports "HOL-SPARK.SPARK"
     8 begin
     9 
    10 spark_proof_functions
    11   gcd = "gcd :: int \<Rightarrow> int \<Rightarrow> int"
    12 
    13 spark_open \<open>greatest_common_divisor/g_c_d\<close> (*..from 3 files
    14   ./greatest_common_divisor/g_c_d.siv, *.fdl, *.rls open *.siv and
    15   find the following 2 open verification conditions (VC): *)
    16 
    17 spark_vc procedure_g_c_d_4 (*..select 1st VC for proof: *)
    18 proof -
    19   from \<open>0 < d\<close> have "0 \<le> c mod d" by (rule pos_mod_sign)
    20   with \<open>0 \<le> c\<close> \<open>0 < d\<close> \<open>c - c sdiv d * d \<noteq> 0\<close> show ?C1
    21     by (simp add: sdiv_pos_pos minus_div_mult_eq_mod [symmetric])
    22 next
    23   from \<open>0 \<le> c\<close> \<open>0 < d\<close> \<open>gcd c d = gcd m n\<close> show ?C2
    24     by (simp add: sdiv_pos_pos minus_div_mult_eq_mod [symmetric] gcd_non_0_int)
    25 qed
    26 
    27 spark_vc procedure_g_c_d_11 (*..select 2nd VC for proof: *)
    28 proof -
    29   from \<open>0 \<le> c\<close> \<open>0 < d\<close> \<open>c - c sdiv d * d = 0\<close>
    30   have "d dvd c"
    31     by (auto simp add: sdiv_pos_pos dvd_def ac_simps)
    32   with \<open>0 < d\<close> \<open>gcd c d = gcd m n\<close> show ?C1
    33     by simp
    34 qed
    35 
    36 spark_end
    37 
    38 end