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