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