src/HOL/Finite_Set.thy
changeset 25571 c9e39eafc7a0
parent 25502 9200b36280c0
child 26041 c2e15e65165f
equal deleted inserted replaced
25570:fdfbbb92dadf 25571:c9e39eafc7a0
  2663   by (rule finite_subset [OF subset_UNIV finite_UNIV])
  2663   by (rule finite_subset [OF subset_UNIV finite_UNIV])
  2664 
  2664 
  2665 lemma univ_unit [noatp]:
  2665 lemma univ_unit [noatp]:
  2666   "UNIV = {()}" by auto
  2666   "UNIV = {()}" by auto
  2667 
  2667 
  2668 instance unit :: finite
  2668 instantiation unit :: finite
  2669   "Finite_Set.itself \<equiv> TYPE(unit)"
  2669 begin
  2670 proof
  2670 
       
  2671 definition
       
  2672   "itself = TYPE(unit)"
       
  2673 
       
  2674 instance proof
  2671   have "finite {()}" by simp
  2675   have "finite {()}" by simp
  2672   also note univ_unit [symmetric]
  2676   also note univ_unit [symmetric]
  2673   finally show "finite (UNIV :: unit set)" .
  2677   finally show "finite (UNIV :: unit set)" .
  2674 qed
  2678 qed
  2675 
  2679 
       
  2680 end
       
  2681 
  2676 lemmas [code func] = univ_unit
  2682 lemmas [code func] = univ_unit
  2677 
  2683 
  2678 lemma univ_bool [noatp]:
  2684 lemma univ_bool [noatp]:
  2679   "UNIV = {False, True}" by auto
  2685   "UNIV = {False, True}" by auto
  2680 
  2686 
  2681 instance bool :: finite
  2687 instantiation bool :: finite
  2682   "itself \<equiv> TYPE(bool)"
  2688 begin
  2683 proof
  2689 
       
  2690 definition
       
  2691   "itself = TYPE(bool)"
       
  2692 
       
  2693 instance proof
  2684   have "finite {False, True}" by simp
  2694   have "finite {False, True}" by simp
  2685   also note univ_bool [symmetric]
  2695   also note univ_bool [symmetric]
  2686   finally show "finite (UNIV :: bool set)" .
  2696   finally show "finite (UNIV :: bool set)" .
  2687 qed
  2697 qed
  2688 
  2698 
       
  2699 end
       
  2700 
  2689 lemmas [code func] = univ_bool
  2701 lemmas [code func] = univ_bool
  2690 
  2702 
  2691 instance * :: (finite, finite) finite
  2703 instantiation * :: (finite, finite) finite
  2692   "itself \<equiv> TYPE('a \<times> 'b)"
  2704 begin
  2693 proof
  2705 
       
  2706 definition
       
  2707   "itself = TYPE('a \<times> 'b)"
       
  2708 
       
  2709 instance proof
  2694   show "finite (UNIV :: ('a \<times> 'b) set)"
  2710   show "finite (UNIV :: ('a \<times> 'b) set)"
  2695   proof (rule finite_Prod_UNIV)
  2711   proof (rule finite_Prod_UNIV)
  2696     show "finite (UNIV :: 'a set)" by (rule finite)
  2712     show "finite (UNIV :: 'a set)" by (rule finite)
  2697     show "finite (UNIV :: 'b set)" by (rule finite)
  2713     show "finite (UNIV :: 'b set)" by (rule finite)
  2698   qed
  2714   qed
  2699 qed
  2715 qed
  2700 
  2716 
       
  2717 end
       
  2718 
  2701 lemma univ_prod [noatp, code func]:
  2719 lemma univ_prod [noatp, code func]:
  2702   "UNIV = (UNIV \<Colon> 'a\<Colon>finite set) \<times> (UNIV \<Colon> 'b\<Colon>finite set)"
  2720   "UNIV = (UNIV \<Colon> 'a\<Colon>finite set) \<times> (UNIV \<Colon> 'b\<Colon>finite set)"
  2703   unfolding UNIV_Times_UNIV ..
  2721   unfolding UNIV_Times_UNIV ..
  2704 
  2722 
  2705 instance "+" :: (finite, finite) finite
  2723 instantiation "+" :: (finite, finite) finite
  2706   "itself \<equiv> TYPE('a + 'b)"
  2724 begin
  2707 proof
  2725 
       
  2726 definition
       
  2727   "itself = TYPE('a + 'b)"
       
  2728 
       
  2729 instance proof
  2708   have a: "finite (UNIV :: 'a set)" by (rule finite)
  2730   have a: "finite (UNIV :: 'a set)" by (rule finite)
  2709   have b: "finite (UNIV :: 'b set)" by (rule finite)
  2731   have b: "finite (UNIV :: 'b set)" by (rule finite)
  2710   from a b have "finite ((UNIV :: 'a set) <+> (UNIV :: 'b set))"
  2732   from a b have "finite ((UNIV :: 'a set) <+> (UNIV :: 'b set))"
  2711     by (rule finite_Plus)
  2733     by (rule finite_Plus)
  2712   thus "finite (UNIV :: ('a + 'b) set)" by simp
  2734   thus "finite (UNIV :: ('a + 'b) set)" by simp
  2713 qed
  2735 qed
  2714 
  2736 
       
  2737 end
       
  2738 
  2715 lemma univ_sum [noatp, code func]:
  2739 lemma univ_sum [noatp, code func]:
  2716   "UNIV = (UNIV \<Colon> 'a\<Colon>finite set) <+> (UNIV \<Colon> 'b\<Colon>finite set)"
  2740   "UNIV = (UNIV \<Colon> 'a\<Colon>finite set) <+> (UNIV \<Colon> 'b\<Colon>finite set)"
  2717   unfolding UNIV_Plus_UNIV ..
  2741   unfolding UNIV_Plus_UNIV ..
  2718 
  2742 
  2719 instance set :: (finite) finite
  2743 instantiation set :: (finite) finite
  2720   "itself \<equiv> TYPE('a set)"
  2744 begin
  2721 proof
  2745 
       
  2746 definition
       
  2747   "itself = TYPE('a set)"
       
  2748 
       
  2749 instance proof
  2722   have "finite (UNIV :: 'a set)" by (rule finite)
  2750   have "finite (UNIV :: 'a set)" by (rule finite)
  2723   hence "finite (Pow (UNIV :: 'a set))"
  2751   hence "finite (Pow (UNIV :: 'a set))"
  2724     by (rule finite_Pow_iff [THEN iffD2])
  2752     by (rule finite_Pow_iff [THEN iffD2])
  2725   thus "finite (UNIV :: 'a set set)" by simp
  2753   thus "finite (UNIV :: 'a set set)" by simp
  2726 qed
  2754 qed
  2727 
  2755 
       
  2756 end
       
  2757 
  2728 lemma univ_set [noatp, code func]:
  2758 lemma univ_set [noatp, code func]:
  2729   "UNIV = Pow (UNIV \<Colon> 'a\<Colon>finite set)" unfolding Pow_UNIV ..
  2759   "UNIV = Pow (UNIV \<Colon> 'a\<Colon>finite set)" unfolding Pow_UNIV ..
  2730 
  2760 
  2731 lemma inj_graph: "inj (%f. {(x, y). y = f x})"
  2761 lemma inj_graph: "inj (%f. {(x, y). y = f x})"
  2732   by (rule inj_onI, auto simp add: expand_set_eq expand_fun_eq)
  2762   by (rule inj_onI, auto simp add: expand_set_eq expand_fun_eq)
  2733 
  2763 
  2734 instance "fun" :: (finite, finite) finite
  2764 instantiation "fun" :: (finite, finite) finite
       
  2765 begin
       
  2766 
       
  2767 definition
  2735   "itself \<equiv> TYPE('a \<Rightarrow> 'b)"
  2768   "itself \<equiv> TYPE('a \<Rightarrow> 'b)"
  2736 proof
  2769 
       
  2770 instance proof
  2737   show "finite (UNIV :: ('a => 'b) set)"
  2771   show "finite (UNIV :: ('a => 'b) set)"
  2738   proof (rule finite_imageD)
  2772   proof (rule finite_imageD)
  2739     let ?graph = "%f::'a => 'b. {(x, y). y = f x}"
  2773     let ?graph = "%f::'a => 'b. {(x, y). y = f x}"
  2740     show "finite (range ?graph)" by (rule finite)
  2774     show "finite (range ?graph)" by (rule finite)
  2741     show "inj ?graph" by (rule inj_graph)
  2775     show "inj ?graph" by (rule inj_graph)
  2742   qed
  2776   qed
  2743 qed
  2777 qed
  2744 
  2778 
       
  2779 end
       
  2780 
  2745 hide (open) const itself
  2781 hide (open) const itself
  2746 
  2782 
  2747 subsection {* Equality and order on functions *}
  2783 subsection {* Equality and order on functions *}
  2748 
  2784 
  2749 instance "fun" :: (finite, eq) eq ..
  2785 instance "fun" :: (finite, eq) eq ..