src/HOL/Relation.thy
changeset 21404 eb85850d3eb7
parent 21210 c17fd2df4e9e
child 22172 e7d6cb237b5e
equal deleted inserted replaced
21403:dd58f13a8eb4 21404:eb85850d3eb7
    11 begin
    11 begin
    12 
    12 
    13 subsection {* Definitions *}
    13 subsection {* Definitions *}
    14 
    14 
    15 definition
    15 definition
    16   converse :: "('a * 'b) set => ('b * 'a) set"    ("(_^-1)" [1000] 999)
    16   converse :: "('a * 'b) set => ('b * 'a) set"
       
    17     ("(_^-1)" [1000] 999) where
    17   "r^-1 == {(y, x). (x, y) : r}"
    18   "r^-1 == {(y, x). (x, y) : r}"
    18 
    19 
    19 notation (xsymbols)
    20 notation (xsymbols)
    20   converse  ("(_\<inverse>)" [1000] 999)
    21   converse  ("(_\<inverse>)" [1000] 999)
    21 
    22 
    22 definition
    23 definition
    23   rel_comp  :: "[('b * 'c) set, ('a * 'b) set] => ('a * 'c) set"  (infixr "O" 75)
    24   rel_comp  :: "[('b * 'c) set, ('a * 'b) set] => ('a * 'c) set"
       
    25     (infixr "O" 75) where
    24   "r O s == {(x,z). EX y. (x, y) : s & (y, z) : r}"
    26   "r O s == {(x,z). EX y. (x, y) : s & (y, z) : r}"
    25 
    27 
    26   Image :: "[('a * 'b) set, 'a set] => 'b set"                (infixl "``" 90)
    28 definition
       
    29   Image :: "[('a * 'b) set, 'a set] => 'b set"
       
    30     (infixl "``" 90) where
    27   "r `` s == {y. EX x:s. (x,y):r}"
    31   "r `` s == {y. EX x:s. (x,y):r}"
    28 
    32 
    29   Id    :: "('a * 'a) set"  -- {* the identity relation *}
    33 definition
       
    34   Id :: "('a * 'a) set" where -- {* the identity relation *}
    30   "Id == {p. EX x. p = (x,x)}"
    35   "Id == {p. EX x. p = (x,x)}"
    31 
    36 
    32   diag  :: "'a set => ('a * 'a) set"  -- {* diagonal: identity over a set *}
    37 definition
       
    38   diag  :: "'a set => ('a * 'a) set" where -- {* diagonal: identity over a set *}
    33   "diag A == \<Union>x\<in>A. {(x,x)}"
    39   "diag A == \<Union>x\<in>A. {(x,x)}"
    34 
    40 
    35   Domain :: "('a * 'b) set => 'a set"
    41 definition
       
    42   Domain :: "('a * 'b) set => 'a set" where
    36   "Domain r == {x. EX y. (x,y):r}"
    43   "Domain r == {x. EX y. (x,y):r}"
    37 
    44 
    38   Range  :: "('a * 'b) set => 'b set"
    45 definition
       
    46   Range  :: "('a * 'b) set => 'b set" where
    39   "Range r == Domain(r^-1)"
    47   "Range r == Domain(r^-1)"
    40 
    48 
    41   Field :: "('a * 'a) set => 'a set"
    49 definition
       
    50   Field :: "('a * 'a) set => 'a set" where
    42   "Field r == Domain r \<union> Range r"
    51   "Field r == Domain r \<union> Range r"
    43 
    52 
    44   refl   :: "['a set, ('a * 'a) set] => bool"  -- {* reflexivity over a set *}
    53 definition
       
    54   refl :: "['a set, ('a * 'a) set] => bool" where -- {* reflexivity over a set *}
    45   "refl A r == r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)"
    55   "refl A r == r \<subseteq> A \<times> A & (ALL x: A. (x,x) : r)"
    46 
    56 
    47   sym    :: "('a * 'a) set => bool"  -- {* symmetry predicate *}
    57 definition
       
    58   sym :: "('a * 'a) set => bool" where -- {* symmetry predicate *}
    48   "sym r == ALL x y. (x,y): r --> (y,x): r"
    59   "sym r == ALL x y. (x,y): r --> (y,x): r"
    49 
    60 
    50   antisym:: "('a * 'a) set => bool"  -- {* antisymmetry predicate *}
    61 definition
       
    62   antisym :: "('a * 'a) set => bool" where -- {* antisymmetry predicate *}
    51   "antisym r == ALL x y. (x,y):r --> (y,x):r --> x=y"
    63   "antisym r == ALL x y. (x,y):r --> (y,x):r --> x=y"
    52 
    64 
    53   trans  :: "('a * 'a) set => bool"  -- {* transitivity predicate *}
    65 definition
       
    66   trans :: "('a * 'a) set => bool" where -- {* transitivity predicate *}
    54   "trans r == (ALL x y z. (x,y):r --> (y,z):r --> (x,z):r)"
    67   "trans r == (ALL x y z. (x,y):r --> (y,z):r --> (x,z):r)"
    55 
    68 
    56   single_valued :: "('a * 'b) set => bool"
    69 definition
       
    70   single_valued :: "('a * 'b) set => bool" where
    57   "single_valued r == ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z)"
    71   "single_valued r == ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z)"
    58 
    72 
    59   inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set"
    73 definition
       
    74   inv_image :: "('b * 'b) set => ('a => 'b) => ('a * 'a) set" where
    60   "inv_image r f == {(x, y). (f x, f y) : r}"
    75   "inv_image r f == {(x, y). (f x, f y) : r}"
    61 
    76 
    62 abbreviation
    77 abbreviation
    63   reflexive :: "('a * 'a) set => bool"  -- {* reflexivity over a type *}
    78   reflexive :: "('a * 'a) set => bool" where -- {* reflexivity over a type *}
    64   "reflexive == refl UNIV"
    79   "reflexive == refl UNIV"
    65 
    80 
    66 
    81 
    67 subsection {* The identity relation *}
    82 subsection {* The identity relation *}
    68 
    83