src/HOL/Relation.thy
author haftmann
Sun Feb 26 15:28:48 2012 +0100 (2012-02-26)
changeset 46689 f559866a7aa2
parent 46664 1f6c140f9c72
child 46691 72d81e789106
permissions -rw-r--r--
marked candidates for rule declarations
wenzelm@10358
     1
(*  Title:      HOL/Relation.thy
haftmann@46664
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory; Stefan Berghofer, TU Muenchen
nipkow@1128
     3
*)
nipkow@1128
     4
haftmann@46664
     5
header {* Relations – as sets of pairs, and binary predicates *}
berghofe@12905
     6
nipkow@15131
     7
theory Relation
haftmann@32850
     8
imports Datatype Finite_Set
nipkow@15131
     9
begin
paulson@5978
    10
haftmann@46664
    11
notation
haftmann@46664
    12
  bot ("\<bottom>") and
haftmann@46664
    13
  top ("\<top>") and
haftmann@46664
    14
  inf (infixl "\<sqinter>" 70) and
haftmann@46664
    15
  sup (infixl "\<squnion>" 65) and
haftmann@46664
    16
  Inf ("\<Sqinter>_" [900] 900) and
haftmann@46664
    17
  Sup ("\<Squnion>_" [900] 900)
haftmann@46664
    18
haftmann@46664
    19
syntax (xsymbols)
haftmann@46664
    20
  "_INF1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Sqinter>_./ _)" [0, 10] 10)
haftmann@46664
    21
  "_INF"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sqinter>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@46664
    22
  "_SUP1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Squnion>_./ _)" [0, 10] 10)
haftmann@46664
    23
  "_SUP"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Squnion>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@46664
    24
haftmann@46664
    25
haftmann@46664
    26
subsection {* Classical rules for reasoning on predicates *}
haftmann@46664
    27
haftmann@46689
    28
(* CANDIDATE declare predicate1I [Pure.intro!, intro!] *)
haftmann@46664
    29
declare predicate1D [Pure.dest?, dest?]
haftmann@46689
    30
(* CANDIDATE declare predicate1D [Pure.dest, dest] *)
haftmann@46664
    31
declare predicate2I [Pure.intro!, intro!]
haftmann@46664
    32
declare predicate2D [Pure.dest, dest]
haftmann@46664
    33
declare bot1E [elim!]
haftmann@46664
    34
declare bot2E [elim!]
haftmann@46664
    35
declare top1I [intro!]
haftmann@46664
    36
declare top2I [intro!]
haftmann@46664
    37
declare inf1I [intro!]
haftmann@46664
    38
declare inf2I [intro!]
haftmann@46664
    39
declare inf1E [elim!]
haftmann@46664
    40
declare inf2E [elim!]
haftmann@46664
    41
declare sup1I1 [intro?]
haftmann@46664
    42
declare sup2I1 [intro?]
haftmann@46664
    43
declare sup1I2 [intro?]
haftmann@46664
    44
declare sup2I2 [intro?]
haftmann@46664
    45
declare sup1E [elim!]
haftmann@46664
    46
declare sup2E [elim!]
haftmann@46664
    47
declare sup1CI [intro!]
haftmann@46664
    48
declare sup2CI [intro!]
haftmann@46664
    49
declare INF1_I [intro!]
haftmann@46664
    50
declare INF2_I [intro!]
haftmann@46664
    51
declare INF1_D [elim]
haftmann@46664
    52
declare INF2_D [elim]
haftmann@46664
    53
declare INF1_E [elim]
haftmann@46664
    54
declare INF2_E [elim]
haftmann@46664
    55
declare SUP1_I [intro]
haftmann@46664
    56
declare SUP2_I [intro]
haftmann@46664
    57
declare SUP1_E [elim!]
haftmann@46664
    58
declare SUP2_E [elim!]
haftmann@46664
    59
haftmann@46664
    60
haftmann@46664
    61
subsection {* Conversions between set and predicate relations *}
haftmann@46664
    62
haftmann@46664
    63
lemma pred_equals_eq [pred_set_conv]: "((\<lambda>x. x \<in> R) = (\<lambda>x. x \<in> S)) \<longleftrightarrow> (R = S)"
haftmann@46664
    64
  by (simp add: set_eq_iff fun_eq_iff)
haftmann@46664
    65
haftmann@46664
    66
lemma pred_equals_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) = (\<lambda>x y. (x, y) \<in> S)) \<longleftrightarrow> (R = S)"
haftmann@46664
    67
  by (simp add: set_eq_iff fun_eq_iff)
haftmann@46664
    68
haftmann@46664
    69
lemma pred_subset_eq [pred_set_conv]: "((\<lambda>x. x \<in> R) \<le> (\<lambda>x. x \<in> S)) \<longleftrightarrow> (R \<subseteq> S)"
haftmann@46664
    70
  by (simp add: subset_iff le_fun_def)
haftmann@46664
    71
haftmann@46664
    72
lemma pred_subset_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) \<le> (\<lambda>x y. (x, y) \<in> S)) \<longleftrightarrow> (R \<subseteq> S)"
haftmann@46664
    73
  by (simp add: subset_iff le_fun_def)
haftmann@46664
    74
haftmann@46689
    75
lemma bot_empty_eq (* CANDIDATE [pred_set_conv] *): "\<bottom> = (\<lambda>x. x \<in> {})"
haftmann@46689
    76
  by (auto simp add: fun_eq_iff)
haftmann@46689
    77
haftmann@46689
    78
lemma bot_empty_eq2 (* CANDIDATE [pred_set_conv] *): "\<bottom> = (\<lambda>x y. (x, y) \<in> {})"
haftmann@46664
    79
  by (auto simp add: fun_eq_iff)
haftmann@46664
    80
haftmann@46689
    81
(* CANDIDATE lemma top_empty_eq [pred_set_conv]: "\<top> = (\<lambda>x. x \<in> UNIV)"
haftmann@46689
    82
  by (auto simp add: fun_eq_iff) *)
haftmann@46689
    83
haftmann@46689
    84
(* CANDIDATE lemma top_empty_eq2 [pred_set_conv]: "\<top> = (\<lambda>x y. (x, y) \<in> UNIV)"
haftmann@46689
    85
  by (auto simp add: fun_eq_iff) *)
haftmann@46664
    86
haftmann@46664
    87
lemma inf_Int_eq [pred_set_conv]: "(\<lambda>x. x \<in> R) \<sqinter> (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<inter> S)"
haftmann@46664
    88
  by (simp add: inf_fun_def)
haftmann@46664
    89
haftmann@46664
    90
lemma inf_Int_eq2 [pred_set_conv]: "(\<lambda>x y. (x, y) \<in> R) \<sqinter> (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<inter> S)"
haftmann@46664
    91
  by (simp add: inf_fun_def)
haftmann@46664
    92
haftmann@46664
    93
lemma sup_Un_eq [pred_set_conv]: "(\<lambda>x. x \<in> R) \<squnion> (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<union> S)"
haftmann@46664
    94
  by (simp add: sup_fun_def)
haftmann@46664
    95
haftmann@46664
    96
lemma sup_Un_eq2 [pred_set_conv]: "(\<lambda>x y. (x, y) \<in> R) \<squnion> (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<union> S)"
haftmann@46664
    97
  by (simp add: sup_fun_def)
haftmann@46664
    98
haftmann@46689
    99
lemma INF_INT_eq (* CANDIDATE [pred_set_conv] *): "(\<Sqinter>i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (\<Inter>i. r i))"
haftmann@46664
   100
  by (simp add: INF_apply fun_eq_iff)
haftmann@46664
   101
haftmann@46689
   102
lemma INF_INT_eq2 (* CANDIDATE [pred_set_conv] *): "(\<Sqinter>i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (\<Inter>i. r i))"
haftmann@46664
   103
  by (simp add: INF_apply fun_eq_iff)
haftmann@46664
   104
haftmann@46664
   105
lemma SUP_UN_eq [pred_set_conv]: "(\<Squnion>i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (\<Union>i. r i))"
haftmann@46664
   106
  by (simp add: SUP_apply fun_eq_iff)
haftmann@46664
   107
haftmann@46664
   108
lemma SUP_UN_eq2 [pred_set_conv]: "(\<Squnion>i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (\<Union>i. r i))"
haftmann@46664
   109
  by (simp add: SUP_apply fun_eq_iff)
haftmann@46664
   110
haftmann@46664
   111
haftmann@46664
   112
subsection {* Relations as sets of pairs *}
wenzelm@12913
   113
nipkow@46372
   114
type_synonym 'a rel = "('a * 'a) set"
nipkow@46372
   115
wenzelm@19656
   116
definition
wenzelm@21404
   117
  converse :: "('a * 'b) set => ('b * 'a) set"
wenzelm@21404
   118
    ("(_^-1)" [1000] 999) where
haftmann@45137
   119
  "r^-1 = {(y, x). (x, y) : r}"
paulson@7912
   120
wenzelm@21210
   121
notation (xsymbols)
wenzelm@19656
   122
  converse  ("(_\<inverse>)" [1000] 999)
wenzelm@19656
   123
wenzelm@19656
   124
definition
krauss@32235
   125
  rel_comp  :: "[('a * 'b) set, ('b * 'c) set] => ('a * 'c) set"
wenzelm@21404
   126
    (infixr "O" 75) where
haftmann@45137
   127
  "r O s = {(x,z). EX y. (x, y) : r & (y, z) : s}"
wenzelm@12913
   128
wenzelm@21404
   129
definition
wenzelm@21404
   130
  Image :: "[('a * 'b) set, 'a set] => 'b set"
wenzelm@21404
   131
    (infixl "``" 90) where
haftmann@45137
   132
  "r `` s = {y. EX x:s. (x,y):r}"
paulson@7912
   133
wenzelm@21404
   134
definition
wenzelm@21404
   135
  Id :: "('a * 'a) set" where -- {* the identity relation *}
haftmann@45137
   136
  "Id = {p. EX x. p = (x,x)}"
paulson@7912
   137
wenzelm@21404
   138
definition
nipkow@30198
   139
  Id_on  :: "'a set => ('a * 'a) set" where -- {* diagonal: identity over a set *}
haftmann@45137
   140
  "Id_on A = (\<Union>x\<in>A. {(x,x)})"
wenzelm@12913
   141
wenzelm@21404
   142
definition
wenzelm@21404
   143
  Domain :: "('a * 'b) set => 'a set" where
haftmann@45137
   144
  "Domain r = {x. EX y. (x,y):r}"
paulson@5978
   145
wenzelm@21404
   146
definition
wenzelm@21404
   147
  Range  :: "('a * 'b) set => 'b set" where
haftmann@45137
   148
  "Range r = Domain(r^-1)"
paulson@5978
   149
wenzelm@21404
   150
definition
wenzelm@21404
   151
  Field :: "('a * 'a) set => 'a set" where
haftmann@45137
   152
  "Field r = Domain r \<union> Range r"
paulson@10786
   153
wenzelm@21404
   154
definition
nipkow@30198
   155
  refl_on :: "['a set, ('a * 'a) set] => bool" where -- {* reflexivity over a set *}
haftmann@45137
   156
  "refl_on A r \<longleftrightarrow> r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)"
paulson@6806
   157
nipkow@26297
   158
abbreviation
nipkow@30198
   159
  refl :: "('a * 'a) set => bool" where -- {* reflexivity over a type *}
haftmann@45137
   160
  "refl \<equiv> refl_on UNIV"
nipkow@26297
   161
wenzelm@21404
   162
definition
wenzelm@21404
   163
  sym :: "('a * 'a) set => bool" where -- {* symmetry predicate *}
haftmann@45137
   164
  "sym r \<longleftrightarrow> (ALL x y. (x,y): r --> (y,x): r)"
paulson@6806
   165
wenzelm@21404
   166
definition
wenzelm@21404
   167
  antisym :: "('a * 'a) set => bool" where -- {* antisymmetry predicate *}
haftmann@45137
   168
  "antisym r \<longleftrightarrow> (ALL x y. (x,y):r --> (y,x):r --> x=y)"
paulson@6806
   169
wenzelm@21404
   170
definition
wenzelm@21404
   171
  trans :: "('a * 'a) set => bool" where -- {* transitivity predicate *}
haftmann@45137
   172
  "trans r \<longleftrightarrow> (ALL x y z. (x,y):r --> (y,z):r --> (x,z):r)"
paulson@5978
   173
wenzelm@21404
   174
definition
haftmann@45137
   175
  irrefl :: "('a * 'a) set => bool" where
haftmann@45137
   176
  "irrefl r \<longleftrightarrow> (\<forall>x. (x,x) \<notin> r)"
nipkow@29859
   177
nipkow@29859
   178
definition
haftmann@45137
   179
  total_on :: "'a set => ('a * 'a) set => bool" where
haftmann@45137
   180
  "total_on A r \<longleftrightarrow> (\<forall>x\<in>A.\<forall>y\<in>A. x\<noteq>y \<longrightarrow> (x,y)\<in>r \<or> (y,x)\<in>r)"
nipkow@29859
   181
nipkow@29859
   182
abbreviation "total \<equiv> total_on UNIV"
nipkow@29859
   183
nipkow@29859
   184
definition
wenzelm@21404
   185
  single_valued :: "('a * 'b) set => bool" where
haftmann@45137
   186
  "single_valued r \<longleftrightarrow> (ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z))"
berghofe@7014
   187
wenzelm@21404
   188
definition
wenzelm@21404
   189
  inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set" where
haftmann@45137
   190
  "inv_image r f = {(x, y). (f x, f y) : r}"
oheimb@11136
   191
berghofe@12905
   192
haftmann@46664
   193
subsubsection {* The identity relation *}
berghofe@12905
   194
berghofe@12905
   195
lemma IdI [intro]: "(a, a) : Id"
nipkow@26271
   196
by (simp add: Id_def)
berghofe@12905
   197
berghofe@12905
   198
lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P"
nipkow@26271
   199
by (unfold Id_def) (iprover elim: CollectE)
berghofe@12905
   200
berghofe@12905
   201
lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)"
nipkow@26271
   202
by (unfold Id_def) blast
berghofe@12905
   203
nipkow@30198
   204
lemma refl_Id: "refl Id"
nipkow@30198
   205
by (simp add: refl_on_def)
berghofe@12905
   206
berghofe@12905
   207
lemma antisym_Id: "antisym Id"
berghofe@12905
   208
  -- {* A strange result, since @{text Id} is also symmetric. *}
nipkow@26271
   209
by (simp add: antisym_def)
berghofe@12905
   210
huffman@19228
   211
lemma sym_Id: "sym Id"
nipkow@26271
   212
by (simp add: sym_def)
huffman@19228
   213
berghofe@12905
   214
lemma trans_Id: "trans Id"
nipkow@26271
   215
by (simp add: trans_def)
berghofe@12905
   216
berghofe@12905
   217
haftmann@46664
   218
subsubsection {* Diagonal: identity over a set *}
berghofe@12905
   219
nipkow@30198
   220
lemma Id_on_empty [simp]: "Id_on {} = {}"
nipkow@30198
   221
by (simp add: Id_on_def) 
paulson@13812
   222
nipkow@30198
   223
lemma Id_on_eqI: "a = b ==> a : A ==> (a, b) : Id_on A"
nipkow@30198
   224
by (simp add: Id_on_def)
berghofe@12905
   225
blanchet@35828
   226
lemma Id_onI [intro!,no_atp]: "a : A ==> (a, a) : Id_on A"
nipkow@30198
   227
by (rule Id_on_eqI) (rule refl)
berghofe@12905
   228
nipkow@30198
   229
lemma Id_onE [elim!]:
nipkow@30198
   230
  "c : Id_on A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
wenzelm@12913
   231
  -- {* The general elimination rule. *}
nipkow@30198
   232
by (unfold Id_on_def) (iprover elim!: UN_E singletonE)
berghofe@12905
   233
nipkow@30198
   234
lemma Id_on_iff: "((x, y) : Id_on A) = (x = y & x : A)"
nipkow@26271
   235
by blast
berghofe@12905
   236
haftmann@45967
   237
lemma Id_on_def' [nitpick_unfold]:
haftmann@44278
   238
  "Id_on {x. A x} = Collect (\<lambda>(x, y). x = y \<and> A x)"
haftmann@44278
   239
by auto
bulwahn@40923
   240
nipkow@30198
   241
lemma Id_on_subset_Times: "Id_on A \<subseteq> A \<times> A"
nipkow@26271
   242
by blast
berghofe@12905
   243
berghofe@12905
   244
haftmann@46664
   245
subsubsection {* Composition of two relations *}
berghofe@12905
   246
wenzelm@12913
   247
lemma rel_compI [intro]:
krauss@32235
   248
  "(a, b) : r ==> (b, c) : s ==> (a, c) : r O s"
nipkow@26271
   249
by (unfold rel_comp_def) blast
berghofe@12905
   250
wenzelm@12913
   251
lemma rel_compE [elim!]: "xz : r O s ==>
krauss@32235
   252
  (!!x y z. xz = (x, z) ==> (x, y) : r ==> (y, z) : s  ==> P) ==> P"
nipkow@26271
   253
by (unfold rel_comp_def) (iprover elim!: CollectE splitE exE conjE)
berghofe@12905
   254
berghofe@12905
   255
lemma rel_compEpair:
krauss@32235
   256
  "(a, c) : r O s ==> (!!y. (a, y) : r ==> (y, c) : s ==> P) ==> P"
nipkow@26271
   257
by (iprover elim: rel_compE Pair_inject ssubst)
berghofe@12905
   258
berghofe@12905
   259
lemma R_O_Id [simp]: "R O Id = R"
nipkow@26271
   260
by fast
berghofe@12905
   261
berghofe@12905
   262
lemma Id_O_R [simp]: "Id O R = R"
nipkow@26271
   263
by fast
berghofe@12905
   264
krauss@23185
   265
lemma rel_comp_empty1[simp]: "{} O R = {}"
nipkow@26271
   266
by blast
krauss@23185
   267
krauss@23185
   268
lemma rel_comp_empty2[simp]: "R O {} = {}"
nipkow@26271
   269
by blast
krauss@23185
   270
berghofe@12905
   271
lemma O_assoc: "(R O S) O T = R O (S O T)"
nipkow@26271
   272
by blast
berghofe@12905
   273
wenzelm@12913
   274
lemma trans_O_subset: "trans r ==> r O r \<subseteq> r"
nipkow@26271
   275
by (unfold trans_def) blast
berghofe@12905
   276
wenzelm@12913
   277
lemma rel_comp_mono: "r' \<subseteq> r ==> s' \<subseteq> s ==> (r' O s') \<subseteq> (r O s)"
nipkow@26271
   278
by blast
berghofe@12905
   279
berghofe@12905
   280
lemma rel_comp_subset_Sigma:
krauss@32235
   281
    "r \<subseteq> A \<times> B ==> s \<subseteq> B \<times> C ==> (r O s) \<subseteq> A \<times> C"
nipkow@26271
   282
by blast
berghofe@12905
   283
krauss@28008
   284
lemma rel_comp_distrib[simp]: "R O (S \<union> T) = (R O S) \<union> (R O T)" 
krauss@28008
   285
by auto
krauss@28008
   286
krauss@28008
   287
lemma rel_comp_distrib2[simp]: "(S \<union> T) O R = (S O R) \<union> (T O R)"
krauss@28008
   288
by auto
krauss@28008
   289
krauss@36772
   290
lemma rel_comp_UNION_distrib: "s O UNION I r = UNION I (%i. s O r i)"
krauss@36772
   291
by auto
krauss@36772
   292
krauss@36772
   293
lemma rel_comp_UNION_distrib2: "UNION I r O s = UNION I (%i. r i O s)"
krauss@36772
   294
by auto
krauss@36772
   295
wenzelm@12913
   296
haftmann@46664
   297
subsubsection {* Reflexivity *}
wenzelm@12913
   298
nipkow@30198
   299
lemma refl_onI: "r \<subseteq> A \<times> A ==> (!!x. x : A ==> (x, x) : r) ==> refl_on A r"
nipkow@30198
   300
by (unfold refl_on_def) (iprover intro!: ballI)
berghofe@12905
   301
nipkow@30198
   302
lemma refl_onD: "refl_on A r ==> a : A ==> (a, a) : r"
nipkow@30198
   303
by (unfold refl_on_def) blast
berghofe@12905
   304
nipkow@30198
   305
lemma refl_onD1: "refl_on A r ==> (x, y) : r ==> x : A"
nipkow@30198
   306
by (unfold refl_on_def) blast
huffman@19228
   307
nipkow@30198
   308
lemma refl_onD2: "refl_on A r ==> (x, y) : r ==> y : A"
nipkow@30198
   309
by (unfold refl_on_def) blast
huffman@19228
   310
nipkow@30198
   311
lemma refl_on_Int: "refl_on A r ==> refl_on B s ==> refl_on (A \<inter> B) (r \<inter> s)"
nipkow@30198
   312
by (unfold refl_on_def) blast
huffman@19228
   313
nipkow@30198
   314
lemma refl_on_Un: "refl_on A r ==> refl_on B s ==> refl_on (A \<union> B) (r \<union> s)"
nipkow@30198
   315
by (unfold refl_on_def) blast
huffman@19228
   316
nipkow@30198
   317
lemma refl_on_INTER:
nipkow@30198
   318
  "ALL x:S. refl_on (A x) (r x) ==> refl_on (INTER S A) (INTER S r)"
nipkow@30198
   319
by (unfold refl_on_def) fast
huffman@19228
   320
nipkow@30198
   321
lemma refl_on_UNION:
nipkow@30198
   322
  "ALL x:S. refl_on (A x) (r x) \<Longrightarrow> refl_on (UNION S A) (UNION S r)"
nipkow@30198
   323
by (unfold refl_on_def) blast
huffman@19228
   324
nipkow@30198
   325
lemma refl_on_empty[simp]: "refl_on {} {}"
nipkow@30198
   326
by(simp add:refl_on_def)
nipkow@26297
   327
nipkow@30198
   328
lemma refl_on_Id_on: "refl_on A (Id_on A)"
nipkow@30198
   329
by (rule refl_onI [OF Id_on_subset_Times Id_onI])
huffman@19228
   330
blanchet@41792
   331
lemma refl_on_def' [nitpick_unfold, code]:
bulwahn@41056
   332
  "refl_on A r = ((\<forall>(x, y) \<in> r. x : A \<and> y : A) \<and> (\<forall>x \<in> A. (x, x) : r))"
bulwahn@41056
   333
by (auto intro: refl_onI dest: refl_onD refl_onD1 refl_onD2)
wenzelm@12913
   334
haftmann@46664
   335
haftmann@46664
   336
subsubsection {* Antisymmetry *}
berghofe@12905
   337
berghofe@12905
   338
lemma antisymI:
berghofe@12905
   339
  "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
nipkow@26271
   340
by (unfold antisym_def) iprover
berghofe@12905
   341
berghofe@12905
   342
lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
nipkow@26271
   343
by (unfold antisym_def) iprover
berghofe@12905
   344
huffman@19228
   345
lemma antisym_subset: "r \<subseteq> s ==> antisym s ==> antisym r"
nipkow@26271
   346
by (unfold antisym_def) blast
wenzelm@12913
   347
huffman@19228
   348
lemma antisym_empty [simp]: "antisym {}"
nipkow@26271
   349
by (unfold antisym_def) blast
huffman@19228
   350
nipkow@30198
   351
lemma antisym_Id_on [simp]: "antisym (Id_on A)"
nipkow@26271
   352
by (unfold antisym_def) blast
huffman@19228
   353
huffman@19228
   354
haftmann@46664
   355
subsubsection {* Symmetry *}
huffman@19228
   356
huffman@19228
   357
lemma symI: "(!!a b. (a, b) : r ==> (b, a) : r) ==> sym r"
nipkow@26271
   358
by (unfold sym_def) iprover
paulson@15177
   359
paulson@15177
   360
lemma symD: "sym r ==> (a, b) : r ==> (b, a) : r"
nipkow@26271
   361
by (unfold sym_def, blast)
berghofe@12905
   362
huffman@19228
   363
lemma sym_Int: "sym r ==> sym s ==> sym (r \<inter> s)"
nipkow@26271
   364
by (fast intro: symI dest: symD)
huffman@19228
   365
huffman@19228
   366
lemma sym_Un: "sym r ==> sym s ==> sym (r \<union> s)"
nipkow@26271
   367
by (fast intro: symI dest: symD)
huffman@19228
   368
huffman@19228
   369
lemma sym_INTER: "ALL x:S. sym (r x) ==> sym (INTER S r)"
nipkow@26271
   370
by (fast intro: symI dest: symD)
huffman@19228
   371
huffman@19228
   372
lemma sym_UNION: "ALL x:S. sym (r x) ==> sym (UNION S r)"
nipkow@26271
   373
by (fast intro: symI dest: symD)
huffman@19228
   374
nipkow@30198
   375
lemma sym_Id_on [simp]: "sym (Id_on A)"
nipkow@26271
   376
by (rule symI) clarify
huffman@19228
   377
huffman@19228
   378
haftmann@46664
   379
subsubsection {* Transitivity *}
huffman@19228
   380
haftmann@46127
   381
lemma trans_join [code]:
haftmann@45012
   382
  "trans r \<longleftrightarrow> (\<forall>(x, y1) \<in> r. \<forall>(y2, z) \<in> r. y1 = y2 \<longrightarrow> (x, z) \<in> r)"
haftmann@45012
   383
  by (auto simp add: trans_def)
haftmann@45012
   384
berghofe@12905
   385
lemma transI:
berghofe@12905
   386
  "(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r"
nipkow@26271
   387
by (unfold trans_def) iprover
berghofe@12905
   388
berghofe@12905
   389
lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r"
nipkow@26271
   390
by (unfold trans_def) iprover
berghofe@12905
   391
huffman@19228
   392
lemma trans_Int: "trans r ==> trans s ==> trans (r \<inter> s)"
nipkow@26271
   393
by (fast intro: transI elim: transD)
huffman@19228
   394
huffman@19228
   395
lemma trans_INTER: "ALL x:S. trans (r x) ==> trans (INTER S r)"
nipkow@26271
   396
by (fast intro: transI elim: transD)
huffman@19228
   397
nipkow@30198
   398
lemma trans_Id_on [simp]: "trans (Id_on A)"
nipkow@26271
   399
by (fast intro: transI elim: transD)
huffman@19228
   400
nipkow@29859
   401
lemma trans_diff_Id: " trans r \<Longrightarrow> antisym r \<Longrightarrow> trans (r-Id)"
nipkow@29859
   402
unfolding antisym_def trans_def by blast
nipkow@29859
   403
haftmann@46664
   404
haftmann@46664
   405
subsubsection {* Irreflexivity *}
nipkow@29859
   406
haftmann@46127
   407
lemma irrefl_distinct [code]:
haftmann@45012
   408
  "irrefl r \<longleftrightarrow> (\<forall>(x, y) \<in> r. x \<noteq> y)"
haftmann@45012
   409
  by (auto simp add: irrefl_def)
haftmann@45012
   410
nipkow@29859
   411
lemma irrefl_diff_Id[simp]: "irrefl(r-Id)"
nipkow@29859
   412
by(simp add:irrefl_def)
nipkow@29859
   413
haftmann@45139
   414
haftmann@46664
   415
subsubsection {* Totality *}
nipkow@29859
   416
nipkow@29859
   417
lemma total_on_empty[simp]: "total_on {} r"
nipkow@29859
   418
by(simp add:total_on_def)
nipkow@29859
   419
nipkow@29859
   420
lemma total_on_diff_Id[simp]: "total_on A (r-Id) = total_on A r"
nipkow@29859
   421
by(simp add: total_on_def)
berghofe@12905
   422
haftmann@46664
   423
haftmann@46664
   424
subsubsection {* Converse *}
wenzelm@12913
   425
wenzelm@12913
   426
lemma converse_iff [iff]: "((a,b): r^-1) = ((b,a) : r)"
nipkow@26271
   427
by (simp add: converse_def)
berghofe@12905
   428
nipkow@13343
   429
lemma converseI[sym]: "(a, b) : r ==> (b, a) : r^-1"
nipkow@26271
   430
by (simp add: converse_def)
berghofe@12905
   431
nipkow@13343
   432
lemma converseD[sym]: "(a,b) : r^-1 ==> (b, a) : r"
nipkow@26271
   433
by (simp add: converse_def)
berghofe@12905
   434
berghofe@12905
   435
lemma converseE [elim!]:
berghofe@12905
   436
  "yx : r^-1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P"
wenzelm@12913
   437
    -- {* More general than @{text converseD}, as it ``splits'' the member of the relation. *}
nipkow@26271
   438
by (unfold converse_def) (iprover elim!: CollectE splitE bexE)
berghofe@12905
   439
berghofe@12905
   440
lemma converse_converse [simp]: "(r^-1)^-1 = r"
nipkow@26271
   441
by (unfold converse_def) blast
berghofe@12905
   442
berghofe@12905
   443
lemma converse_rel_comp: "(r O s)^-1 = s^-1 O r^-1"
nipkow@26271
   444
by blast
berghofe@12905
   445
huffman@19228
   446
lemma converse_Int: "(r \<inter> s)^-1 = r^-1 \<inter> s^-1"
nipkow@26271
   447
by blast
huffman@19228
   448
huffman@19228
   449
lemma converse_Un: "(r \<union> s)^-1 = r^-1 \<union> s^-1"
nipkow@26271
   450
by blast
huffman@19228
   451
huffman@19228
   452
lemma converse_INTER: "(INTER S r)^-1 = (INT x:S. (r x)^-1)"
nipkow@26271
   453
by fast
huffman@19228
   454
huffman@19228
   455
lemma converse_UNION: "(UNION S r)^-1 = (UN x:S. (r x)^-1)"
nipkow@26271
   456
by blast
huffman@19228
   457
berghofe@12905
   458
lemma converse_Id [simp]: "Id^-1 = Id"
nipkow@26271
   459
by blast
berghofe@12905
   460
nipkow@30198
   461
lemma converse_Id_on [simp]: "(Id_on A)^-1 = Id_on A"
nipkow@26271
   462
by blast
berghofe@12905
   463
nipkow@30198
   464
lemma refl_on_converse [simp]: "refl_on A (converse r) = refl_on A r"
nipkow@30198
   465
by (unfold refl_on_def) auto
berghofe@12905
   466
huffman@19228
   467
lemma sym_converse [simp]: "sym (converse r) = sym r"
nipkow@26271
   468
by (unfold sym_def) blast
huffman@19228
   469
huffman@19228
   470
lemma antisym_converse [simp]: "antisym (converse r) = antisym r"
nipkow@26271
   471
by (unfold antisym_def) blast
berghofe@12905
   472
huffman@19228
   473
lemma trans_converse [simp]: "trans (converse r) = trans r"
nipkow@26271
   474
by (unfold trans_def) blast
berghofe@12905
   475
huffman@19228
   476
lemma sym_conv_converse_eq: "sym r = (r^-1 = r)"
nipkow@26271
   477
by (unfold sym_def) fast
huffman@19228
   478
huffman@19228
   479
lemma sym_Un_converse: "sym (r \<union> r^-1)"
nipkow@26271
   480
by (unfold sym_def) blast
huffman@19228
   481
huffman@19228
   482
lemma sym_Int_converse: "sym (r \<inter> r^-1)"
nipkow@26271
   483
by (unfold sym_def) blast
huffman@19228
   484
nipkow@29859
   485
lemma total_on_converse[simp]: "total_on A (r^-1) = total_on A r"
nipkow@29859
   486
by (auto simp: total_on_def)
nipkow@29859
   487
wenzelm@12913
   488
haftmann@46664
   489
subsubsection {* Domain *}
berghofe@12905
   490
blanchet@35828
   491
declare Domain_def [no_atp]
paulson@24286
   492
berghofe@12905
   493
lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)"
nipkow@26271
   494
by (unfold Domain_def) blast
berghofe@12905
   495
berghofe@12905
   496
lemma DomainI [intro]: "(a, b) : r ==> a : Domain r"
nipkow@26271
   497
by (iprover intro!: iffD2 [OF Domain_iff])
berghofe@12905
   498
berghofe@12905
   499
lemma DomainE [elim!]:
berghofe@12905
   500
  "a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P"
nipkow@26271
   501
by (iprover dest!: iffD1 [OF Domain_iff])
berghofe@12905
   502
haftmann@46127
   503
lemma Domain_fst [code]:
haftmann@45012
   504
  "Domain r = fst ` r"
haftmann@45012
   505
  by (auto simp add: image_def Bex_def)
haftmann@45012
   506
berghofe@12905
   507
lemma Domain_empty [simp]: "Domain {} = {}"
nipkow@26271
   508
by blast
berghofe@12905
   509
paulson@32876
   510
lemma Domain_empty_iff: "Domain r = {} \<longleftrightarrow> r = {}"
paulson@32876
   511
  by auto
paulson@32876
   512
berghofe@12905
   513
lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)"
nipkow@26271
   514
by blast
berghofe@12905
   515
berghofe@12905
   516
lemma Domain_Id [simp]: "Domain Id = UNIV"
nipkow@26271
   517
by blast
berghofe@12905
   518
nipkow@30198
   519
lemma Domain_Id_on [simp]: "Domain (Id_on A) = A"
nipkow@26271
   520
by blast
berghofe@12905
   521
paulson@13830
   522
lemma Domain_Un_eq: "Domain(A \<union> B) = Domain(A) \<union> Domain(B)"
nipkow@26271
   523
by blast
berghofe@12905
   524
paulson@13830
   525
lemma Domain_Int_subset: "Domain(A \<inter> B) \<subseteq> Domain(A) \<inter> Domain(B)"
nipkow@26271
   526
by blast
berghofe@12905
   527
wenzelm@12913
   528
lemma Domain_Diff_subset: "Domain(A) - Domain(B) \<subseteq> Domain(A - B)"
nipkow@26271
   529
by blast
berghofe@12905
   530
paulson@13830
   531
lemma Domain_Union: "Domain (Union S) = (\<Union>A\<in>S. Domain A)"
nipkow@26271
   532
by blast
nipkow@26271
   533
nipkow@26271
   534
lemma Domain_converse[simp]: "Domain(r^-1) = Range r"
nipkow@26271
   535
by(auto simp:Range_def)
berghofe@12905
   536
wenzelm@12913
   537
lemma Domain_mono: "r \<subseteq> s ==> Domain r \<subseteq> Domain s"
nipkow@26271
   538
by blast
berghofe@12905
   539
krauss@36729
   540
lemma fst_eq_Domain: "fst ` R = Domain R"
huffman@44921
   541
  by force
paulson@22172
   542
haftmann@29609
   543
lemma Domain_dprod [simp]: "Domain (dprod r s) = uprod (Domain r) (Domain s)"
haftmann@29609
   544
by auto
haftmann@29609
   545
haftmann@29609
   546
lemma Domain_dsum [simp]: "Domain (dsum r s) = usum (Domain r) (Domain s)"
haftmann@29609
   547
by auto
haftmann@29609
   548
berghofe@12905
   549
haftmann@46664
   550
subsubsection {* Range *}
berghofe@12905
   551
berghofe@12905
   552
lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)"
nipkow@26271
   553
by (simp add: Domain_def Range_def)
berghofe@12905
   554
berghofe@12905
   555
lemma RangeI [intro]: "(a, b) : r ==> b : Range r"
nipkow@26271
   556
by (unfold Range_def) (iprover intro!: converseI DomainI)
berghofe@12905
   557
berghofe@12905
   558
lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P"
nipkow@26271
   559
by (unfold Range_def) (iprover elim!: DomainE dest!: converseD)
berghofe@12905
   560
haftmann@46127
   561
lemma Range_snd [code]:
haftmann@45012
   562
  "Range r = snd ` r"
haftmann@45012
   563
  by (auto simp add: image_def Bex_def)
haftmann@45012
   564
berghofe@12905
   565
lemma Range_empty [simp]: "Range {} = {}"
nipkow@26271
   566
by blast
berghofe@12905
   567
paulson@32876
   568
lemma Range_empty_iff: "Range r = {} \<longleftrightarrow> r = {}"
paulson@32876
   569
  by auto
paulson@32876
   570
berghofe@12905
   571
lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)"
nipkow@26271
   572
by blast
berghofe@12905
   573
berghofe@12905
   574
lemma Range_Id [simp]: "Range Id = UNIV"
nipkow@26271
   575
by blast
berghofe@12905
   576
nipkow@30198
   577
lemma Range_Id_on [simp]: "Range (Id_on A) = A"
nipkow@26271
   578
by auto
berghofe@12905
   579
paulson@13830
   580
lemma Range_Un_eq: "Range(A \<union> B) = Range(A) \<union> Range(B)"
nipkow@26271
   581
by blast
berghofe@12905
   582
paulson@13830
   583
lemma Range_Int_subset: "Range(A \<inter> B) \<subseteq> Range(A) \<inter> Range(B)"
nipkow@26271
   584
by blast
berghofe@12905
   585
wenzelm@12913
   586
lemma Range_Diff_subset: "Range(A) - Range(B) \<subseteq> Range(A - B)"
nipkow@26271
   587
by blast
berghofe@12905
   588
paulson@13830
   589
lemma Range_Union: "Range (Union S) = (\<Union>A\<in>S. Range A)"
nipkow@26271
   590
by blast
nipkow@26271
   591
nipkow@26271
   592
lemma Range_converse[simp]: "Range(r^-1) = Domain r"
nipkow@26271
   593
by blast
berghofe@12905
   594
krauss@36729
   595
lemma snd_eq_Range: "snd ` R = Range R"
huffman@44921
   596
  by force
nipkow@26271
   597
nipkow@26271
   598
haftmann@46664
   599
subsubsection {* Field *}
nipkow@26271
   600
nipkow@26271
   601
lemma mono_Field: "r \<subseteq> s \<Longrightarrow> Field r \<subseteq> Field s"
nipkow@26271
   602
by(auto simp:Field_def Domain_def Range_def)
nipkow@26271
   603
nipkow@26271
   604
lemma Field_empty[simp]: "Field {} = {}"
nipkow@26271
   605
by(auto simp:Field_def)
nipkow@26271
   606
nipkow@26271
   607
lemma Field_insert[simp]: "Field (insert (a,b) r) = {a,b} \<union> Field r"
nipkow@26271
   608
by(auto simp:Field_def)
nipkow@26271
   609
nipkow@26271
   610
lemma Field_Un[simp]: "Field (r \<union> s) = Field r \<union> Field s"
nipkow@26271
   611
by(auto simp:Field_def)
nipkow@26271
   612
nipkow@26271
   613
lemma Field_Union[simp]: "Field (\<Union>R) = \<Union>(Field ` R)"
nipkow@26271
   614
by(auto simp:Field_def)
nipkow@26271
   615
nipkow@26271
   616
lemma Field_converse[simp]: "Field(r^-1) = Field r"
nipkow@26271
   617
by(auto simp:Field_def)
paulson@22172
   618
berghofe@12905
   619
haftmann@46664
   620
subsubsection {* Image of a set under a relation *}
berghofe@12905
   621
blanchet@35828
   622
declare Image_def [no_atp]
paulson@24286
   623
wenzelm@12913
   624
lemma Image_iff: "(b : r``A) = (EX x:A. (x, b) : r)"
nipkow@26271
   625
by (simp add: Image_def)
berghofe@12905
   626
wenzelm@12913
   627
lemma Image_singleton: "r``{a} = {b. (a, b) : r}"
nipkow@26271
   628
by (simp add: Image_def)
berghofe@12905
   629
wenzelm@12913
   630
lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a, b) : r)"
nipkow@26271
   631
by (rule Image_iff [THEN trans]) simp
berghofe@12905
   632
blanchet@35828
   633
lemma ImageI [intro,no_atp]: "(a, b) : r ==> a : A ==> b : r``A"
nipkow@26271
   634
by (unfold Image_def) blast
berghofe@12905
   635
berghofe@12905
   636
lemma ImageE [elim!]:
wenzelm@12913
   637
    "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
nipkow@26271
   638
by (unfold Image_def) (iprover elim!: CollectE bexE)
berghofe@12905
   639
berghofe@12905
   640
lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
berghofe@12905
   641
  -- {* This version's more effective when we already have the required @{text a} *}
nipkow@26271
   642
by blast
berghofe@12905
   643
berghofe@12905
   644
lemma Image_empty [simp]: "R``{} = {}"
nipkow@26271
   645
by blast
berghofe@12905
   646
berghofe@12905
   647
lemma Image_Id [simp]: "Id `` A = A"
nipkow@26271
   648
by blast
berghofe@12905
   649
nipkow@30198
   650
lemma Image_Id_on [simp]: "Id_on A `` B = A \<inter> B"
nipkow@26271
   651
by blast
paulson@13830
   652
paulson@13830
   653
lemma Image_Int_subset: "R `` (A \<inter> B) \<subseteq> R `` A \<inter> R `` B"
nipkow@26271
   654
by blast
berghofe@12905
   655
paulson@13830
   656
lemma Image_Int_eq:
paulson@13830
   657
     "single_valued (converse R) ==> R `` (A \<inter> B) = R `` A \<inter> R `` B"
nipkow@26271
   658
by (simp add: single_valued_def, blast) 
berghofe@12905
   659
paulson@13830
   660
lemma Image_Un: "R `` (A \<union> B) = R `` A \<union> R `` B"
nipkow@26271
   661
by blast
berghofe@12905
   662
paulson@13812
   663
lemma Un_Image: "(R \<union> S) `` A = R `` A \<union> S `` A"
nipkow@26271
   664
by blast
paulson@13812
   665
wenzelm@12913
   666
lemma Image_subset: "r \<subseteq> A \<times> B ==> r``C \<subseteq> B"
nipkow@26271
   667
by (iprover intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
berghofe@12905
   668
paulson@13830
   669
lemma Image_eq_UN: "r``B = (\<Union>y\<in> B. r``{y})"
berghofe@12905
   670
  -- {* NOT suitable for rewriting *}
nipkow@26271
   671
by blast
berghofe@12905
   672
wenzelm@12913
   673
lemma Image_mono: "r' \<subseteq> r ==> A' \<subseteq> A ==> (r' `` A') \<subseteq> (r `` A)"
nipkow@26271
   674
by blast
berghofe@12905
   675
paulson@13830
   676
lemma Image_UN: "(r `` (UNION A B)) = (\<Union>x\<in>A. r `` (B x))"
nipkow@26271
   677
by blast
paulson@13830
   678
paulson@13830
   679
lemma Image_INT_subset: "(r `` INTER A B) \<subseteq> (\<Inter>x\<in>A. r `` (B x))"
nipkow@26271
   680
by blast
berghofe@12905
   681
paulson@13830
   682
text{*Converse inclusion requires some assumptions*}
paulson@13830
   683
lemma Image_INT_eq:
paulson@13830
   684
     "[|single_valued (r\<inverse>); A\<noteq>{}|] ==> r `` INTER A B = (\<Inter>x\<in>A. r `` B x)"
paulson@13830
   685
apply (rule equalityI)
paulson@13830
   686
 apply (rule Image_INT_subset) 
paulson@13830
   687
apply  (simp add: single_valued_def, blast)
paulson@13830
   688
done
berghofe@12905
   689
wenzelm@12913
   690
lemma Image_subset_eq: "(r``A \<subseteq> B) = (A \<subseteq> - ((r^-1) `` (-B)))"
nipkow@26271
   691
by blast
berghofe@12905
   692
berghofe@12905
   693
haftmann@46664
   694
subsubsection {* Single valued relations *}
wenzelm@12913
   695
wenzelm@12913
   696
lemma single_valuedI:
berghofe@12905
   697
  "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
nipkow@26271
   698
by (unfold single_valued_def)
berghofe@12905
   699
berghofe@12905
   700
lemma single_valuedD:
berghofe@12905
   701
  "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
nipkow@26271
   702
by (simp add: single_valued_def)
berghofe@12905
   703
huffman@19228
   704
lemma single_valued_rel_comp:
huffman@19228
   705
  "single_valued r ==> single_valued s ==> single_valued (r O s)"
nipkow@26271
   706
by (unfold single_valued_def) blast
huffman@19228
   707
huffman@19228
   708
lemma single_valued_subset:
huffman@19228
   709
  "r \<subseteq> s ==> single_valued s ==> single_valued r"
nipkow@26271
   710
by (unfold single_valued_def) blast
huffman@19228
   711
huffman@19228
   712
lemma single_valued_Id [simp]: "single_valued Id"
nipkow@26271
   713
by (unfold single_valued_def) blast
huffman@19228
   714
nipkow@30198
   715
lemma single_valued_Id_on [simp]: "single_valued (Id_on A)"
nipkow@26271
   716
by (unfold single_valued_def) blast
huffman@19228
   717
berghofe@12905
   718
haftmann@46664
   719
subsubsection {* Graphs given by @{text Collect} *}
berghofe@12905
   720
berghofe@12905
   721
lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}"
nipkow@26271
   722
by auto
berghofe@12905
   723
berghofe@12905
   724
lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}"
nipkow@26271
   725
by auto
berghofe@12905
   726
berghofe@12905
   727
lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}"
nipkow@26271
   728
by auto
berghofe@12905
   729
berghofe@12905
   730
haftmann@46664
   731
subsubsection {* Inverse image *}
berghofe@12905
   732
huffman@19228
   733
lemma sym_inv_image: "sym r ==> sym (inv_image r f)"
nipkow@26271
   734
by (unfold sym_def inv_image_def) blast
huffman@19228
   735
wenzelm@12913
   736
lemma trans_inv_image: "trans r ==> trans (inv_image r f)"
berghofe@12905
   737
  apply (unfold trans_def inv_image_def)
berghofe@12905
   738
  apply (simp (no_asm))
berghofe@12905
   739
  apply blast
berghofe@12905
   740
  done
berghofe@12905
   741
krauss@32463
   742
lemma in_inv_image[simp]: "((x,y) : inv_image r f) = ((f x, f y) : r)"
krauss@32463
   743
  by (auto simp:inv_image_def)
krauss@32463
   744
krauss@33218
   745
lemma converse_inv_image[simp]: "(inv_image R f)^-1 = inv_image (R^-1) f"
krauss@33218
   746
unfolding inv_image_def converse_def by auto
krauss@33218
   747
haftmann@23709
   748
haftmann@46664
   749
subsubsection {* Finiteness *}
haftmann@29609
   750
haftmann@29609
   751
lemma finite_converse [iff]: "finite (r^-1) = finite r"
haftmann@29609
   752
  apply (subgoal_tac "r^-1 = (%(x,y). (y,x))`r")
haftmann@29609
   753
   apply simp
haftmann@29609
   754
   apply (rule iffI)
haftmann@29609
   755
    apply (erule finite_imageD [unfolded inj_on_def])
haftmann@29609
   756
    apply (simp split add: split_split)
haftmann@29609
   757
   apply (erule finite_imageI)
haftmann@29609
   758
  apply (simp add: converse_def image_def, auto)
haftmann@29609
   759
  apply (rule bexI)
haftmann@29609
   760
   prefer 2 apply assumption
haftmann@29609
   761
  apply simp
haftmann@29609
   762
  done
haftmann@29609
   763
paulson@32876
   764
lemma finite_Domain: "finite r ==> finite (Domain r)"
paulson@32876
   765
  by (induct set: finite) (auto simp add: Domain_insert)
paulson@32876
   766
paulson@32876
   767
lemma finite_Range: "finite r ==> finite (Range r)"
paulson@32876
   768
  by (induct set: finite) (auto simp add: Range_insert)
haftmann@29609
   769
haftmann@29609
   770
lemma finite_Field: "finite r ==> finite (Field r)"
haftmann@29609
   771
  -- {* A finite relation has a finite field (@{text "= domain \<union> range"}. *}
haftmann@29609
   772
  apply (induct set: finite)
haftmann@29609
   773
   apply (auto simp add: Field_def Domain_insert Range_insert)
haftmann@29609
   774
  done
haftmann@29609
   775
haftmann@29609
   776
haftmann@46664
   777
subsubsection {* Miscellaneous *}
krauss@36728
   778
krauss@36728
   779
text {* Version of @{thm[source] lfp_induct} for binary relations *}
haftmann@23709
   780
haftmann@23709
   781
lemmas lfp_induct2 = 
haftmann@23709
   782
  lfp_induct_set [of "(a, b)", split_format (complete)]
haftmann@23709
   783
krauss@36728
   784
text {* Version of @{thm[source] subsetI} for binary relations *}
krauss@36728
   785
krauss@36728
   786
lemma subrelI: "(\<And>x y. (x, y) \<in> r \<Longrightarrow> (x, y) \<in> s) \<Longrightarrow> r \<subseteq> s"
krauss@36728
   787
by auto
krauss@36728
   788
haftmann@46664
   789
haftmann@46664
   790
subsection {* Relations as binary predicates *}
haftmann@46664
   791
haftmann@46664
   792
subsubsection {* Composition *}
haftmann@46664
   793
haftmann@46664
   794
inductive pred_comp  :: "['a \<Rightarrow> 'b \<Rightarrow> bool, 'b \<Rightarrow> 'c \<Rightarrow> bool] \<Rightarrow> 'a \<Rightarrow> 'c \<Rightarrow> bool" (infixr "OO" 75)
haftmann@46664
   795
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" and s :: "'b \<Rightarrow> 'c \<Rightarrow> bool" where
haftmann@46664
   796
  pred_compI [intro]: "r a b \<Longrightarrow> s b c \<Longrightarrow> (r OO s) a c"
haftmann@46664
   797
haftmann@46664
   798
inductive_cases pred_compE [elim!]: "(r OO s) a c"
haftmann@46664
   799
haftmann@46664
   800
lemma pred_comp_rel_comp_eq [pred_set_conv]:
haftmann@46664
   801
  "((\<lambda>x y. (x, y) \<in> r) OO (\<lambda>x y. (x, y) \<in> s)) = (\<lambda>x y. (x, y) \<in> r O s)"
haftmann@46664
   802
  by (auto simp add: fun_eq_iff)
haftmann@46664
   803
haftmann@46664
   804
haftmann@46664
   805
subsubsection {* Converse *}
haftmann@46664
   806
haftmann@46664
   807
inductive conversep :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> bool" ("(_^--1)" [1000] 1000)
haftmann@46664
   808
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where
haftmann@46664
   809
  conversepI: "r a b \<Longrightarrow> r^--1 b a"
haftmann@46664
   810
haftmann@46664
   811
notation (xsymbols)
haftmann@46664
   812
  conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
haftmann@46664
   813
haftmann@46664
   814
lemma conversepD:
haftmann@46664
   815
  assumes ab: "r^--1 a b"
haftmann@46664
   816
  shows "r b a" using ab
haftmann@46664
   817
  by cases simp
haftmann@46664
   818
haftmann@46664
   819
lemma conversep_iff [iff]: "r^--1 a b = r b a"
haftmann@46664
   820
  by (iprover intro: conversepI dest: conversepD)
haftmann@46664
   821
haftmann@46664
   822
lemma conversep_converse_eq [pred_set_conv]:
haftmann@46664
   823
  "(\<lambda>x y. (x, y) \<in> r)^--1 = (\<lambda>x y. (x, y) \<in> r^-1)"
haftmann@46664
   824
  by (auto simp add: fun_eq_iff)
haftmann@46664
   825
haftmann@46664
   826
lemma conversep_conversep [simp]: "(r^--1)^--1 = r"
haftmann@46664
   827
  by (iprover intro: order_antisym conversepI dest: conversepD)
haftmann@46664
   828
haftmann@46664
   829
lemma converse_pred_comp: "(r OO s)^--1 = s^--1 OO r^--1"
haftmann@46664
   830
  by (iprover intro: order_antisym conversepI pred_compI
haftmann@46664
   831
    elim: pred_compE dest: conversepD)
haftmann@46664
   832
haftmann@46664
   833
lemma converse_meet: "(r \<sqinter> s)^--1 = r^--1 \<sqinter> s^--1"
haftmann@46664
   834
  by (simp add: inf_fun_def) (iprover intro: conversepI ext dest: conversepD)
haftmann@46664
   835
haftmann@46664
   836
lemma converse_join: "(r \<squnion> s)^--1 = r^--1 \<squnion> s^--1"
haftmann@46664
   837
  by (simp add: sup_fun_def) (iprover intro: conversepI ext dest: conversepD)
haftmann@46664
   838
haftmann@46664
   839
lemma conversep_noteq [simp]: "(op \<noteq>)^--1 = op \<noteq>"
haftmann@46664
   840
  by (auto simp add: fun_eq_iff)
haftmann@46664
   841
haftmann@46664
   842
lemma conversep_eq [simp]: "(op =)^--1 = op ="
haftmann@46664
   843
  by (auto simp add: fun_eq_iff)
haftmann@46664
   844
haftmann@46664
   845
haftmann@46664
   846
subsubsection {* Domain *}
haftmann@46664
   847
haftmann@46664
   848
inductive DomainP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@46664
   849
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where
haftmann@46664
   850
  DomainPI [intro]: "r a b \<Longrightarrow> DomainP r a"
haftmann@46664
   851
haftmann@46664
   852
inductive_cases DomainPE [elim!]: "DomainP r a"
haftmann@46664
   853
haftmann@46664
   854
lemma DomainP_Domain_eq [pred_set_conv]: "DomainP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Domain r)"
haftmann@46664
   855
  by (blast intro!: Orderings.order_antisym predicate1I)
haftmann@46664
   856
haftmann@46664
   857
haftmann@46664
   858
subsubsection {* Range *}
haftmann@46664
   859
haftmann@46664
   860
inductive RangeP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'b \<Rightarrow> bool"
haftmann@46664
   861
  for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where
haftmann@46664
   862
  RangePI [intro]: "r a b \<Longrightarrow> RangeP r b"
haftmann@46664
   863
haftmann@46664
   864
inductive_cases RangePE [elim!]: "RangeP r b"
haftmann@46664
   865
haftmann@46664
   866
lemma RangeP_Range_eq [pred_set_conv]: "RangeP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Range r)"
haftmann@46664
   867
  by (blast intro!: Orderings.order_antisym predicate1I)
haftmann@46664
   868
haftmann@46664
   869
haftmann@46664
   870
subsubsection {* Inverse image *}
haftmann@46664
   871
haftmann@46664
   872
definition inv_imagep :: "('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" where
haftmann@46664
   873
  "inv_imagep r f = (\<lambda>x y. r (f x) (f y))"
haftmann@46664
   874
haftmann@46664
   875
lemma [pred_set_conv]: "inv_imagep (\<lambda>x y. (x, y) \<in> r) f = (\<lambda>x y. (x, y) \<in> inv_image r f)"
haftmann@46664
   876
  by (simp add: inv_image_def inv_imagep_def)
haftmann@46664
   877
haftmann@46664
   878
lemma in_inv_imagep [simp]: "inv_imagep r f x y = r (f x) (f y)"
haftmann@46664
   879
  by (simp add: inv_imagep_def)
haftmann@46664
   880
haftmann@46664
   881
haftmann@46664
   882
subsubsection {* Powerset *}
haftmann@46664
   883
haftmann@46664
   884
definition Powp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@46664
   885
  "Powp A = (\<lambda>B. \<forall>x \<in> B. A x)"
haftmann@46664
   886
haftmann@46664
   887
lemma Powp_Pow_eq [pred_set_conv]: "Powp (\<lambda>x. x \<in> A) = (\<lambda>x. x \<in> Pow A)"
haftmann@46664
   888
  by (auto simp add: Powp_def fun_eq_iff)
haftmann@46664
   889
haftmann@46664
   890
lemmas Powp_mono [mono] = Pow_mono [to_pred]
haftmann@46664
   891
haftmann@46664
   892
haftmann@46664
   893
subsubsection {* Properties of predicate relations *}
haftmann@46664
   894
haftmann@46664
   895
abbreviation antisymP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46664
   896
  "antisymP r \<equiv> antisym {(x, y). r x y}"
haftmann@46664
   897
haftmann@46664
   898
abbreviation transP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46664
   899
  "transP r \<equiv> trans {(x, y). r x y}"
haftmann@46664
   900
haftmann@46664
   901
abbreviation single_valuedP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46664
   902
  "single_valuedP r \<equiv> single_valued {(x, y). r x y}"
haftmann@46664
   903
haftmann@46664
   904
(*FIXME inconsistencies: abbreviations vs. definitions, suffix `P` vs. suffix `p`*)
haftmann@46664
   905
haftmann@46664
   906
definition reflp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46664
   907
  "reflp r \<longleftrightarrow> refl {(x, y). r x y}"
haftmann@46664
   908
haftmann@46664
   909
definition symp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46664
   910
  "symp r \<longleftrightarrow> sym {(x, y). r x y}"
haftmann@46664
   911
haftmann@46664
   912
definition transp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@46664
   913
  "transp r \<longleftrightarrow> trans {(x, y). r x y}"
haftmann@46664
   914
haftmann@46664
   915
lemma reflpI:
haftmann@46664
   916
  "(\<And>x. r x x) \<Longrightarrow> reflp r"
haftmann@46664
   917
  by (auto intro: refl_onI simp add: reflp_def)
haftmann@46664
   918
haftmann@46664
   919
lemma reflpE:
haftmann@46664
   920
  assumes "reflp r"
haftmann@46664
   921
  obtains "r x x"
haftmann@46664
   922
  using assms by (auto dest: refl_onD simp add: reflp_def)
haftmann@46664
   923
haftmann@46664
   924
lemma sympI:
haftmann@46664
   925
  "(\<And>x y. r x y \<Longrightarrow> r y x) \<Longrightarrow> symp r"
haftmann@46664
   926
  by (auto intro: symI simp add: symp_def)
haftmann@46664
   927
haftmann@46664
   928
lemma sympE:
haftmann@46664
   929
  assumes "symp r" and "r x y"
haftmann@46664
   930
  obtains "r y x"
haftmann@46664
   931
  using assms by (auto dest: symD simp add: symp_def)
haftmann@46664
   932
haftmann@46664
   933
lemma transpI:
haftmann@46664
   934
  "(\<And>x y z. r x y \<Longrightarrow> r y z \<Longrightarrow> r x z) \<Longrightarrow> transp r"
haftmann@46664
   935
  by (auto intro: transI simp add: transp_def)
haftmann@46664
   936
  
haftmann@46664
   937
lemma transpE:
haftmann@46664
   938
  assumes "transp r" and "r x y" and "r y z"
haftmann@46664
   939
  obtains "r x z"
haftmann@46664
   940
  using assms by (auto dest: transD simp add: transp_def)
haftmann@46664
   941
haftmann@46664
   942
no_notation
haftmann@46664
   943
  bot ("\<bottom>") and
haftmann@46664
   944
  top ("\<top>") and
haftmann@46664
   945
  inf (infixl "\<sqinter>" 70) and
haftmann@46664
   946
  sup (infixl "\<squnion>" 65) and
haftmann@46664
   947
  Inf ("\<Sqinter>_" [900] 900) and
haftmann@46664
   948
  Sup ("\<Squnion>_" [900] 900)
haftmann@46664
   949
haftmann@46664
   950
no_syntax (xsymbols)
haftmann@46664
   951
  "_INF1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Sqinter>_./ _)" [0, 10] 10)
haftmann@46664
   952
  "_INF"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sqinter>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@46664
   953
  "_SUP1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Squnion>_./ _)" [0, 10] 10)
haftmann@46664
   954
  "_SUP"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Squnion>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@46664
   955
nipkow@1128
   956
end
haftmann@46689
   957