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