src/HOL/Quickcheck_Examples/Completeness.thy
changeset 63167 0909deb8059b
parent 58889 5b7a9633cfa8
equal deleted inserted replaced
63166:143f58bb34f9 63167:0909deb8059b
     1 (*  Title:      HOL/Quickcheck_Examples/Completeness.thy
     1 (*  Title:      HOL/Quickcheck_Examples/Completeness.thy
     2     Author:     Lukas Bulwahn
     2     Author:     Lukas Bulwahn
     3     Copyright   2012 TU Muenchen
     3     Copyright   2012 TU Muenchen
     4 *)
     4 *)
     5 
     5 
     6 section {* Proving completeness of exhaustive generators *}
     6 section \<open>Proving completeness of exhaustive generators\<close>
     7 
     7 
     8 theory Completeness
     8 theory Completeness
     9 imports Main
     9 imports Main
    10 begin
    10 begin
    11 
    11 
    12 subsection {* Preliminaries *}
    12 subsection \<open>Preliminaries\<close>
    13 
    13 
    14 primrec is_some
    14 primrec is_some
    15 where
    15 where
    16   "is_some (Some t) = True"
    16   "is_some (Some t) = True"
    17 | "is_some None = False"
    17 | "is_some None = False"
    20   "is_some x \<longleftrightarrow> x \<noteq> None"
    20   "is_some x \<longleftrightarrow> x \<noteq> None"
    21   by (cases x) simp_all
    21   by (cases x) simp_all
    22 
    22 
    23 setup Exhaustive_Generators.setup_exhaustive_datatype_interpretation
    23 setup Exhaustive_Generators.setup_exhaustive_datatype_interpretation
    24 
    24 
    25 subsection {* Defining the size of values *}
    25 subsection \<open>Defining the size of values\<close>
    26 
    26 
    27 hide_const size
    27 hide_const size
    28 
    28 
    29 class size =
    29 class size =
    30   fixes size :: "'a => nat"
    30   fixes size :: "'a => nat"
    72 
    72 
    73 instance ..
    73 instance ..
    74 
    74 
    75 end
    75 end
    76 
    76 
    77 subsection {* Completeness *}
    77 subsection \<open>Completeness\<close>
    78 
    78 
    79 class complete = exhaustive + size +
    79 class complete = exhaustive + size +
    80 assumes
    80 assumes
    81    complete: "(\<exists> v. size v \<le> n \<and> is_some (f v)) \<longleftrightarrow> is_some (exhaustive_class.exhaustive f (natural_of_nat n))"
    81    complete: "(\<exists> v. size v \<le> n \<and> is_some (f v)) \<longleftrightarrow> is_some (exhaustive_class.exhaustive f (natural_of_nat n))"
    82 
    82 
    87 lemma complete_imp2:
    87 lemma complete_imp2:
    88   assumes "is_some (exhaustive_class.exhaustive f (natural_of_nat n))"
    88   assumes "is_some (exhaustive_class.exhaustive f (natural_of_nat n))"
    89   obtains v where "size (v :: 'a :: complete) \<le> n" "is_some (f v)"
    89   obtains v where "size (v :: 'a :: complete) \<le> n" "is_some (f v)"
    90 using assms by (metis complete)
    90 using assms by (metis complete)
    91 
    91 
    92 subsubsection {* Instance Proofs *}
    92 subsubsection \<open>Instance Proofs\<close>
    93 
    93 
    94 declare exhaustive_int'.simps [simp del]
    94 declare exhaustive_int'.simps [simp del]
    95 
    95 
    96 lemma complete_exhaustive':
    96 lemma complete_exhaustive':
    97   "(\<exists> i. j <= i & i <= k & is_some (f i)) \<longleftrightarrow> is_some (Quickcheck_Exhaustive.exhaustive_int' f k j)"
    97   "(\<exists> i. j <= i & i <= k & is_some (f i)) \<longleftrightarrow> is_some (Quickcheck_Exhaustive.exhaustive_int' f k j)"