src/HOL/Extraction/Euclid.thy
changeset 37291 bc874e1a7758
parent 37288 2b1c6dd48995
child 37335 381b391351b5
equal deleted inserted replaced
37290:3464d7232670 37291:bc874e1a7758
     7 header {* Euclid's theorem *}
     7 header {* Euclid's theorem *}
     8 
     8 
     9 theory Euclid
     9 theory Euclid
    10 imports "~~/src/HOL/Number_Theory/UniqueFactorization" Util Efficient_Nat
    10 imports "~~/src/HOL/Number_Theory/UniqueFactorization" Util Efficient_Nat
    11 begin
    11 begin
    12 
       
    13 lemma list_nonempty_induct [consumes 1, case_names single cons]:
       
    14   assumes "xs \<noteq> []"
       
    15   assumes single: "\<And>x. P [x]"
       
    16   assumes cons: "\<And>x xs. xs \<noteq> [] \<Longrightarrow> P xs \<Longrightarrow> P (x # xs)"
       
    17   shows "P xs"
       
    18 using `xs \<noteq> []` proof (induct xs)
       
    19   case Nil then show ?case by simp
       
    20 next
       
    21   case (Cons x xs) show ?case proof (cases xs)
       
    22     case Nil with single show ?thesis by simp
       
    23   next
       
    24     case Cons then have "xs \<noteq> []" by simp
       
    25     moreover with Cons.hyps have "P xs" .
       
    26     ultimately show ?thesis by (rule cons)
       
    27   qed
       
    28 qed
       
    29 
    12 
    30 text {*
    13 text {*
    31 A constructive version of the proof of Euclid's theorem by
    14 A constructive version of the proof of Euclid's theorem by
    32 Markus Wenzel and Freek Wiedijk \cite{Wenzel-Wiedijk-JAR2002}.
    15 Markus Wenzel and Freek Wiedijk \cite{Wenzel-Wiedijk-JAR2002}.
    33 *}
    16 *}
   283 lemma "factor_exists 1007 = [53, 19]" by evaluation
   266 lemma "factor_exists 1007 = [53, 19]" by evaluation
   284 lemma "factor_exists 567 = [7, 3, 3, 3, 3]" by evaluation
   267 lemma "factor_exists 567 = [7, 3, 3, 3, 3]" by evaluation
   285 lemma "factor_exists 345 = [23, 5, 3]" by evaluation
   268 lemma "factor_exists 345 = [23, 5, 3]" by evaluation
   286 lemma "factor_exists 999 = [37, 3, 3, 3]" by evaluation
   269 lemma "factor_exists 999 = [37, 3, 3, 3]" by evaluation
   287 lemma "factor_exists 876 = [73, 3, 2, 2]" by evaluation
   270 lemma "factor_exists 876 = [73, 3, 2, 2]" by evaluation
       
   271 
   288 lemma "iterate 4 Euclid 0 = [2, 3, 7, 71]" by evaluation
   272 lemma "iterate 4 Euclid 0 = [2, 3, 7, 71]" by evaluation
   289 
   273 
   290 end
   274 end