# HG changeset patch # User berghofe # Date 1194947680 -3600 # Node ID d4f80cb18c93fc6b4140682da0e385d41bca0f70 # Parent ddb060d37ca82b817ed2e0cecc4f2963c0cbcf42 Moved nat_eq_dec and search to Util.thy diff -r ddb060d37ca8 -r d4f80cb18c93 src/HOL/Extraction/Pigeonhole.thy --- a/src/HOL/Extraction/Pigeonhole.thy Tue Nov 13 10:53:39 2007 +0100 +++ b/src/HOL/Extraction/Pigeonhole.thy Tue Nov 13 10:54:40 2007 +0100 @@ -6,7 +6,7 @@ header {* The pigeonhole principle *} theory Pigeonhole -imports Efficient_Nat +imports Util Efficient_Nat begin text {* @@ -15,71 +15,6 @@ formalization of these proofs in {\sc Nuprl} is due to Aleksey Nogin \cite{Nogin-ENTCS-2000}. -We need decidability of equality on natural numbers: -*} - -lemma nat_eq_dec: "(m\nat) = n \ m \ n" - apply (induct m arbitrary: n) - apply (case_tac n) - apply (case_tac [3] n) - apply (simp only: nat.simps, iprover?)+ - done - -text {* -We can decide whether an array @{term "f"} of length @{term "l"} -contains an element @{term "x"}. -*} - -lemma search: "(\j<(l::nat). (x::nat) = f j) \ \ (\j (\j<0. x = f j)" - proof - assume "\j<0. x = f j" - then obtain j where j: "j < (0::nat)" by iprover - thus "False" by simp - qed - thus ?case .. -next - case (Suc l) - thus ?case - proof - assume "\j (\j f l" - have "\ (\jj l" - with j have "j < l" by simp - with nex and eq show False by iprover - qed - qed - thus ?case .. - qed - qed -qed - -text {* This proof yields a polynomial program. *} @@ -163,7 +98,7 @@ ultimately show ?case .. next case (Suc k) - from search show ?case + from search [OF nat_eq_dec] show ?case proof assume "\jj < Suc (Suc n). f (Suc (Suc n)) = f j" thus ?case by (iprover intro: le_refl) @@ -293,16 +228,23 @@ consts_code + "arbitrary :: nat" ("{* 0::nat *}") "arbitrary :: nat \ nat" ("{* (0::nat, 0::nat) *}") definition arbitrary_nat_pair :: "nat \ nat" where [symmetric, code inline]: "arbitrary_nat_pair = arbitrary" +definition + arbitrary_nat :: nat where + [symmetric, code inline]: "arbitrary_nat = arbitrary" + code_const arbitrary_nat_pair (SML "(~1, ~1)") (* this is justified since for valid inputs this "arbitrary" will be dropped in the next recursion step in pigeonhole_def *) +code_const arbitrary_nat (SML "~1") + code_module PH1 contains test = test