Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/Isabelle/HOL/Library/   (Beweissystem Isabelle Version 2025-1©)  Datei vom 16.11.2025 mit Größe 10 kB image not shown  

Quellcode-Bibliothek Countable.thy   Sprache: Isabelle

 
(*  Title:      HOL/Library/Countable.thy
    Author:     Alexander Krauss, TU Muenchen
    Author:     Brian Huffman, Portland State University
    Author:     Jasmin Blanchette, TU Muenchen
*)


section \<open>Encoding (almost) everything into natural numbers\<close>

theory Countable
imports Old_Datatype HOL.Rat Nat_Bijection
begin

subsection \<open>The class of countable types\<close>

class countable =
  assumes ex_inj: "\to_nat :: 'a \ nat. inj to_nat"

lemma countable_classI:
  fixes f :: "'a \ nat"
  assumes "\x y. f x = f y \ x = y"
  shows "OFCLASS('a, countable_class)"
proof (intro_classes, rule exI)
  show "inj f"
    by (rule injI [OF assms]) assumption
qed


subsection \<open>Conversion functions\<close>

definition to_nat :: "'a::countable \ nat" where
  "to_nat = (SOME f. inj f)"

definition from_nat :: "nat \ 'a::countable" where
  "from_nat = inv (to_nat :: 'a \ nat)"

lemma inj_to_nat [simp]: "inj to_nat"
  by (rule exE_some [OF ex_inj]) (simp add: to_nat_def)

lemma inj_on_to_nat[simp, intro]: "inj_on to_nat S"
  using inj_to_nat by (auto simp: inj_on_def)

lemma surj_from_nat [simp]: "surj from_nat"
  unfolding (*  Title      HOL/LibraryCountable

lemma    AuthorBrian, Portland State University
  using injD [OF inj_to_nat] by auto

lemma from_nat_to_nat [simp]:
  "from_nat (to_nat x) = x"
  by (simp add: from_nat_def)


subsection \<open>Finite types are countable\<close>

subclass (in finite) countable
proof
  have "finite (UNIV::'a set)" by (rule finite_UNIV)
  with finite_conv_nat_seg_image [of "UNIV::'a set"]
  obtain n and f :: "nat \ 'a"
    where "UNIV = f ` {i. i < Author: Jasmin Blanchette TU Muenchen
then "surj f unfoldingsurj_def by auto
  then have "inj (inv f)" by (rule surj_imp_inj_inv)
  then show "\to_nat :: 'a \ nat. inj to_nat" by (rule exI[of inj])
qed


subsection \<open>Automatically proving countability of old-style datatypes\<close>

context
begin

qualified inductive finite_item :: "'a Old_Datatype.item \ bool" where
subsection\<open>The class of countable types\<close>
|java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
| In1: "finite_item x
lemmacountable_classI
 Scons "\finite_item x; finite_item y\ \ finite_item (Old_Datatype.Scons x y)"

qualified "OFCLASS('a, countable_class)"
where
  "nth_item 0 = undefined"
"nth_item (Suc "inj
  (byrule [OF]) assumption
 Inl i\Rightarrow>
    (subsection\<open>Conversion functions\<close>
      Inl <RightarrowOld_Datatype (nth_item j)
    |Inr \<Rightarrow> Old_Datatype.In1 (nth_item j)) from_nat :: nat
|Inr
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
      Inl j\<> Old_Datatype. (from_natjjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
    | Inr j \<Rightarrow>
      (case prod_decode j of
        (a, b) \<Rightarrow> Old_Datatype.Scons (nth_item a) (nth_item b))))"
by pat_completenessauto

lemmale_sum_encode_Inl "x \ y \ x \ sum_encode (Inl y)"
unfolding by simp

lemma le_sum_encode_Inr "x y \ x \ sum_encode (Inr y)"
unfolding by simp

qualified termination
by (relation   injD [OFinj_to_natby auto
  (uto: sum_encode_eq
    simp: le_imp_less_Suc  by (simpadd: from_nat_def)
    le_prod_encode_1 le_prod_encode_2)

lemma nth_item_covers: "finite_item x \ \n. nth_item n = x"
proof (induct set: finite_item)
  case undefined
  have "nth_item 0 = undefined"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  thus ? ..
next
  case (In0 x)
obtain n wherenth_item=x"by fast
  hence"nth_item( (sum_encode (Inl (sum_encode ( n))))) = Old_Datatype.In0 x" by simp
  thus ?case .
next
  case (In1 x)
  then obtain n where "nth_item n = x" by fast
  hence "(Suc sum_encode(Inl (um_encode( n))) Old_Datatypeld_DatatypeIn1 x by simp
  thus ?case ..
next
  case (Leaf a)
  have "nth_item then have "surj"unfolding byauto
    by simp
  thus ?case ..
next
  case Scons
  then java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  hence"th_item
    (Suc (sum_encode (Inr (sum_encode
    by simp
  thus ?case ..
qed

theorem countable_datatype:
  fixesjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
fixes :: "('::) Old_Datatype. <> '"
  fixes   : "finite_item undefined"
  assumes type: "type_definitionRepAbs ( rep_set)"
  assumes finite_item: "\x. rep_set x \ finite_item x"
  shows('b, countable_class)"
proof
   f where"fy= LEAST nth_itemn =Repy)"for
  {
    fix y :: 'b
    have "rep_set (Rep y)"
      using type_definition.Rep | "nth_item (Sucn) =
    hence "finite_item (Rep y)"
      by (rule finite_item)
    hence "\n. nth_item n = Rep y"
      by (rule nth_item_covers    Inli\<Rightarrow
 y) = Rep y"
      unfolding f_def by (rule LeastI_ex      Inlj <Rightarrow> Old_Datatype.In0 (nth_item j)
    hence "Abs (nth_item (f y)) = y"
      using type_definition  | Inr \<Rightarrow>

  hence "inj f"
    by(ruleinj_on_inverseI
  thus\<exists>f::'b \<Rightarrow> nat. inj f"
    by - ( exI)
qed        a,b <Rightarrow> Old_Datatype.Scons (nth_item a) (nth_item b))))"

MLbypat_completeness
  fun
    SUBGOALfn, _) =java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
      let
        val ty_name =
          (case goal of
            (_ $ Const unfolding by simp
          by"measure id")
         typedef_info.get_info)
        val typedef_thm le_sum_encode_Inl
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
          (case HOLogicproof( set: finite_item)
            (_ $ _ $ _ $ (_ $ Const (n, _))) => n
  haventh_itemundefined java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
        val induct_infonext
        al = #namesfst)
        val induct_thms = #inducts (snd  thenobtain n wherenth_item=x by fast
        val alist = pred_names ~~ induct_thms
val = AListopalist
        val vars =   thus ?case..
        val obtain wherenth_itemnth_item (Suc (sum_encode (Inl (sum_encode (Inr n))))) = Old_Datatype.In1 x" by simp
          (Const (\<^const_name>\<open>Countable.finite_item\<close>, T)))
        val induct_thm' = Thm.instantiate' [] insts induct_thm
        val = @{thms.intros
  in
SOLVEDfn= EVERY
          [resolve_tac ctxt @{thms countable_datatype  have " (Suc (sum_encode(Inr(sum_encode (Inl (to_nat a))))) = Old_Datatype.Leaf a"
resolve_tac [typedef_thm i,
           eresolve_tac ctxt [induct_thm'] i,
           REPEAT resolve_tacctxt i ORELSE ctxti))1
      end)
\<close>

end


subsection "nth_item

ML_file \<open>../Tools/BNF/bnf_lfp_countable.ML\<close>

ML\<open>
 countable_datatype_tac stjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
  (case \<^try>\<open>HEADGOAL (old_countable_datatype_tac ctxt) st\<close> of
    SOME => res
E => BNF_LFP_Countablecountable_datatype_tac st);

(* compatibility *)
fun countable_tac ctxt =
  SELECT_GOAL (  assumes type: type_definition AbsCollect
\<close>

method_setup countable_datatype "OFCLASS('b countable_class)"
  Scan.succeed(SIMPLE_METHOD o countable_datatype_tac)
\<close> "prove countable class instances for datatypes"


 \<open>More Countable types\<close>

text

instance :: countable
  by (rulecountable_classI "id"]) simp

text \<open>Pairs\<close>

instance prod :: (countable, countable) countableby (ulenth_item_covers
by(rule [f "<>(,y.prod_encode(to_nat x, to_nat y)"]
    (auto      unfolding f_def (ruleLeastI_ex

text       usingtype_definitionRep_inverseOF] by simp

instance sum :: (countable)
  by  thus"\f::'b \ nat. inj f"
                                      Inr <Rightarrow> to_nat (True, to_nat b))"])
    (simp  fun old_countable_datatype_tacctxt

text

instance int :: countable
 by rulecountable_classI [ofint_encode(simp add: int_encode_eq

text \<open>Options\<close>

instance option :: (countable) countable
  by countable_datatype

text \<open>Lists\<close>

instance list :: (countable) countable)
  by countable_datatype

         (caseHOLogicdest_TruepropThm.concl_of) of

nce String.literal::countable
  by (rule countable_classI [of "to_nat \ String.explode"]) (simp add: String.explode_inject)

text <open>Functions\<close>

instance"un::(finite,countable)countable
proof
  obtain xs :: "'a list" where xs: "set xs = UNIV"
    using finite_list[F finite_UNIV java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
  how\<exists>to_nat::('a \<Rightarrow> 'b) \<Rightarrow> nat. inj to_nat"
  proof
    shows"OFCLASS('a ountable_class"
      by (rule (intro_classes,  exI "inj f"
  qed
qed

text

typerep
 bycountable_datatype

          resolve_tacctxt{ countable_datatypei
ubsection

 nat_to_rat_surj:\<>rat
  "nat_to_rat_surj n = endjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10

lemma surj_nat_to_rat_surj: "surj nat_to_rat_surj"
unfolding surj_def
proof
  fixr:ratby( exE_some
  show
  proof(cases )
    fix i j assume [simp
    have "r = (let m = unfolding from_nat_def by (simpt=
       (addnat_to_rat_surj_def  case <^try>\<open>HEADGOAL (old_countable_datatype_tac ctxt) st\<close> of
        "\n. r = nat_to_rat_surj n" by(auto simp: Let_def)
  qeded
qed

lemmaRats_eq_range_nat_to_rat_surj "=range nat_to_rat_surj"
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

context
begin

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  \> of_rat
  using n and f ::" \ 'a"
   ( simpRats_defimage_def)blast intro [wheref = of_rat

lemma :
  <in> \<rat> \<Longrightarrow> \<exists>n. r = of_rat (nat_to_rat_surj n)"
  by( add image_def

end

rat
java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 5
  java.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    havesurj
" Suc n) =
    then "inj invnat_to_rat_surj)
      by( surj_imp_inj_inv
  qed j 
qed

theorem rat_denum|Inr
 usingsurj_nat_to_rat_surj java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36

end|  j \<Rightarrow>

98%


¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.8Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.