src/HOL/NumberTheory/BijectionRel.thy
author haftmann
Wed Sep 26 20:27:55 2007 +0200 (2007-09-26)
changeset 24728 e2b3a1065676
parent 23755 1c4672d130b1
permissions -rw-r--r--
moved Finite_Set before Datatype
     1 (*  Title:      HOL/NumberTheory/BijectionRel.thy
     2     ID:         $Id$
     3     Author:     Thomas M. Rasmussen
     4     Copyright   2000  University of Cambridge
     5 *)
     6 
     7 header {* Bijections between sets *}
     8 
     9 theory BijectionRel imports Main begin
    10 
    11 text {*
    12   Inductive definitions of bijections between two different sets and
    13   between the same set.  Theorem for relating the two definitions.
    14 
    15   \bigskip
    16 *}
    17 
    18 inductive_set
    19   bijR :: "('a => 'b => bool) => ('a set * 'b set) set"
    20   for P :: "'a => 'b => bool"
    21 where
    22   empty [simp]: "({}, {}) \<in> bijR P"
    23 | insert: "P a b ==> a \<notin> A ==> b \<notin> B ==> (A, B) \<in> bijR P
    24     ==> (insert a A, insert b B) \<in> bijR P"
    25 
    26 text {*
    27   Add extra condition to @{term insert}: @{term "\<forall>b \<in> B. \<not> P a b"}
    28   (and similar for @{term A}).
    29 *}
    30 
    31 definition
    32   bijP :: "('a => 'a => bool) => 'a set => bool" where
    33   "bijP P F = (\<forall>a b. a \<in> F \<and> P a b --> b \<in> F)"
    34 
    35 definition
    36   uniqP :: "('a => 'a => bool) => bool" where
    37   "uniqP P = (\<forall>a b c d. P a b \<and> P c d --> (a = c) = (b = d))"
    38 
    39 definition
    40   symP :: "('a => 'a => bool) => bool" where
    41   "symP P = (\<forall>a b. P a b = P b a)"
    42 
    43 inductive_set
    44   bijER :: "('a => 'a => bool) => 'a set set"
    45   for P :: "'a => 'a => bool"
    46 where
    47   empty [simp]: "{} \<in> bijER P"
    48 | insert1: "P a a ==> a \<notin> A ==> A \<in> bijER P ==> insert a A \<in> bijER P"
    49 | insert2: "P a b ==> a \<noteq> b ==> a \<notin> A ==> b \<notin> A ==> A \<in> bijER P
    50     ==> insert a (insert b A) \<in> bijER P"
    51 
    52 
    53 text {* \medskip @{term bijR} *}
    54 
    55 lemma fin_bijRl: "(A, B) \<in> bijR P ==> finite A"
    56   apply (erule bijR.induct)
    57   apply auto
    58   done
    59 
    60 lemma fin_bijRr: "(A, B) \<in> bijR P ==> finite B"
    61   apply (erule bijR.induct)
    62   apply auto
    63   done
    64 
    65 lemma aux_induct:
    66   assumes major: "finite F"
    67     and subs: "F \<subseteq> A"
    68     and cases: "P {}"
    69       "!!F a. F \<subseteq> A ==> a \<in> A ==> a \<notin> F ==> P F ==> P (insert a F)"
    70   shows "P F"
    71   using major subs
    72   apply (induct set: finite)
    73    apply (blast intro: cases)+
    74   done
    75 
    76 
    77 lemma inj_func_bijR_aux1:
    78     "A \<subseteq> B ==> a \<notin> A ==> a \<in> B ==> inj_on f B ==> f a \<notin> f ` A"
    79   apply (unfold inj_on_def)
    80   apply auto
    81   done
    82 
    83 lemma inj_func_bijR_aux2:
    84   "\<forall>a. a \<in> A --> P a (f a) ==> inj_on f A ==> finite A ==> F <= A
    85     ==> (F, f ` F) \<in> bijR P"
    86   apply (rule_tac F = F and A = A in aux_induct)
    87      apply (rule finite_subset)
    88       apply auto
    89   apply (rule bijR.insert)
    90      apply (rule_tac [3] inj_func_bijR_aux1)
    91         apply auto
    92   done
    93 
    94 lemma inj_func_bijR:
    95   "\<forall>a. a \<in> A --> P a (f a) ==> inj_on f A ==> finite A
    96     ==> (A, f ` A) \<in> bijR P"
    97   apply (rule inj_func_bijR_aux2)
    98      apply auto
    99   done
   100 
   101 
   102 text {* \medskip @{term bijER} *}
   103 
   104 lemma fin_bijER: "A \<in> bijER P ==> finite A"
   105   apply (erule bijER.induct)
   106     apply auto
   107   done
   108 
   109 lemma aux1:
   110   "a \<notin> A ==> a \<notin> B ==> F \<subseteq> insert a A ==> F \<subseteq> insert a B ==> a \<in> F
   111     ==> \<exists>C. F = insert a C \<and> a \<notin> C \<and> C <= A \<and> C <= B"
   112   apply (rule_tac x = "F - {a}" in exI)
   113   apply auto
   114   done
   115 
   116 lemma aux2: "a \<noteq> b ==> a \<notin> A ==> b \<notin> B ==> a \<in> F ==> b \<in> F
   117     ==> F \<subseteq> insert a A ==> F \<subseteq> insert b B
   118     ==> \<exists>C. F = insert a (insert b C) \<and> a \<notin> C \<and> b \<notin> C \<and> C \<subseteq> A \<and> C \<subseteq> B"
   119   apply (rule_tac x = "F - {a, b}" in exI)
   120   apply auto
   121   done
   122 
   123 lemma aux_uniq: "uniqP P ==> P a b ==> P c d ==> (a = c) = (b = d)"
   124   apply (unfold uniqP_def)
   125   apply auto
   126   done
   127 
   128 lemma aux_sym: "symP P ==> P a b = P b a"
   129   apply (unfold symP_def)
   130   apply auto
   131   done
   132 
   133 lemma aux_in1:
   134     "uniqP P ==> b \<notin> C ==> P b b ==> bijP P (insert b C) ==> bijP P C"
   135   apply (unfold bijP_def)
   136   apply auto
   137   apply (subgoal_tac "b \<noteq> a")
   138    prefer 2
   139    apply clarify
   140   apply (simp add: aux_uniq)
   141   apply auto
   142   done
   143 
   144 lemma aux_in2:
   145   "symP P ==> uniqP P ==> a \<notin> C ==> b \<notin> C ==> a \<noteq> b ==> P a b
   146     ==> bijP P (insert a (insert b C)) ==> bijP P C"
   147   apply (unfold bijP_def)
   148   apply auto
   149   apply (subgoal_tac "aa \<noteq> a")
   150    prefer 2
   151    apply clarify
   152   apply (subgoal_tac "aa \<noteq> b")
   153    prefer 2
   154    apply clarify
   155   apply (simp add: aux_uniq)
   156   apply (subgoal_tac "ba \<noteq> a")
   157    apply auto
   158   apply (subgoal_tac "P a aa")
   159    prefer 2
   160    apply (simp add: aux_sym)
   161   apply (subgoal_tac "b = aa")
   162    apply (rule_tac [2] iffD1)
   163     apply (rule_tac [2] a = a and c = a and P = P in aux_uniq)
   164       apply auto
   165   done
   166 
   167 lemma aux_foo: "\<forall>a b. Q a \<and> P a b --> R b ==> P a b ==> Q a ==> R b"
   168   apply auto
   169   done
   170 
   171 lemma aux_bij: "bijP P F ==> symP P ==> P a b ==> (a \<in> F) = (b \<in> F)"
   172   apply (unfold bijP_def)
   173   apply (rule iffI)
   174   apply (erule_tac [!] aux_foo)
   175       apply simp_all
   176   apply (rule iffD2)
   177    apply (rule_tac P = P in aux_sym)
   178    apply simp_all
   179   done
   180 
   181 
   182 lemma aux_bijRER:
   183   "(A, B) \<in> bijR P ==> uniqP P ==> symP P
   184     ==> \<forall>F. bijP P F \<and> F \<subseteq> A \<and> F \<subseteq> B --> F \<in> bijER P"
   185   apply (erule bijR.induct)
   186    apply simp
   187   apply (case_tac "a = b")
   188    apply clarify
   189    apply (case_tac "b \<in> F")
   190     prefer 2
   191     apply (simp add: subset_insert)
   192    apply (cut_tac F = F and a = b and A = A and B = B in aux1)
   193         prefer 6
   194         apply clarify
   195         apply (rule bijER.insert1)
   196           apply simp_all
   197    apply (subgoal_tac "bijP P C")
   198     apply simp
   199    apply (rule aux_in1)
   200       apply simp_all
   201   apply clarify
   202   apply (case_tac "a \<in> F")
   203    apply (case_tac [!] "b \<in> F")
   204      apply (cut_tac F = F and a = a and b = b and A = A and B = B
   205        in aux2)
   206             apply (simp_all add: subset_insert)
   207     apply clarify
   208     apply (rule bijER.insert2)
   209         apply simp_all
   210     apply (subgoal_tac "bijP P C")
   211      apply simp
   212     apply (rule aux_in2)
   213           apply simp_all
   214    apply (subgoal_tac "b \<in> F")
   215     apply (rule_tac [2] iffD1)
   216      apply (rule_tac [2] a = a and F = F and P = P in aux_bij)
   217        apply (simp_all (no_asm_simp))
   218    apply (subgoal_tac [2] "a \<in> F")
   219     apply (rule_tac [3] iffD2)
   220      apply (rule_tac [3] b = b and F = F and P = P in aux_bij)
   221        apply auto
   222   done
   223 
   224 lemma bijR_bijER:
   225   "(A, A) \<in> bijR P ==>
   226     bijP P A ==> uniqP P ==> symP P ==> A \<in> bijER P"
   227   apply (cut_tac A = A and B = A and P = P in aux_bijRER)
   228      apply auto
   229   done
   230 
   231 end