src/HOL/Relation.ML
author nipkow
Sat Apr 27 12:07:31 1996 +0200 (1996-04-27)
changeset 1694 3452958f85a8
parent 1642 21db0cf9a1a4
child 1754 852093aeb0ab
permissions -rw-r--r--
Added R_O_id and id_O_R
clasohm@1465
     1
(*  Title:      Relation.ML
nipkow@1128
     2
    ID:         $Id$
clasohm@1465
     3
    Authors:    Riccardo Mattolini, Dip. Sistemi e Informatica
clasohm@1465
     4
                Lawrence C Paulson, Cambridge University Computer Laboratory
nipkow@1128
     5
    Copyright   1994 Universita' di Firenze
nipkow@1128
     6
    Copyright   1993  University of Cambridge
nipkow@1128
     7
*)
nipkow@1128
     8
nipkow@1128
     9
val RSLIST = curry (op MRS);
nipkow@1128
    10
nipkow@1128
    11
open Relation;
nipkow@1128
    12
nipkow@1128
    13
(** Identity relation **)
nipkow@1128
    14
nipkow@1128
    15
goalw Relation.thy [id_def] "(a,a) : id";  
nipkow@1128
    16
by (rtac CollectI 1);
nipkow@1128
    17
by (rtac exI 1);
nipkow@1128
    18
by (rtac refl 1);
nipkow@1128
    19
qed "idI";
nipkow@1128
    20
nipkow@1128
    21
val major::prems = goalw Relation.thy [id_def]
nipkow@1128
    22
    "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
nipkow@1128
    23
\    |] ==>  P";  
nipkow@1128
    24
by (rtac (major RS CollectE) 1);
nipkow@1128
    25
by (etac exE 1);
nipkow@1128
    26
by (eresolve_tac prems 1);
nipkow@1128
    27
qed "idE";
nipkow@1128
    28
nipkow@1128
    29
goalw Relation.thy [id_def] "(a,b):id = (a=b)";
paulson@1552
    30
by (fast_tac prod_cs 1);
nipkow@1128
    31
qed "pair_in_id_conv";
nipkow@1694
    32
Addsimps [pair_in_id_conv];
nipkow@1128
    33
nipkow@1128
    34
nipkow@1128
    35
(** Composition of two relations **)
nipkow@1128
    36
nipkow@1128
    37
val prems = goalw Relation.thy [comp_def]
nipkow@1128
    38
    "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
nipkow@1454
    39
by (fast_tac (prod_cs addIs prems) 1);
nipkow@1128
    40
qed "compI";
nipkow@1128
    41
nipkow@1128
    42
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
nipkow@1128
    43
val prems = goalw Relation.thy [comp_def]
nipkow@1128
    44
    "[| xz : r O s;  \
nipkow@1128
    45
\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
nipkow@1128
    46
\    |] ==> P";
nipkow@1128
    47
by (cut_facts_tac prems 1);
nipkow@1454
    48
by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 ORELSE ares_tac prems 1));
nipkow@1128
    49
qed "compE";
nipkow@1128
    50
nipkow@1128
    51
val prems = goal Relation.thy
nipkow@1128
    52
    "[| (a,c) : r O s;  \
nipkow@1128
    53
\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
nipkow@1128
    54
\    |] ==> P";
nipkow@1128
    55
by (rtac compE 1);
nipkow@1128
    56
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
nipkow@1128
    57
qed "compEpair";
nipkow@1128
    58
nipkow@1128
    59
val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
nipkow@1128
    60
nipkow@1128
    61
goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
nipkow@1128
    62
by (fast_tac comp_cs 1);
nipkow@1128
    63
qed "comp_mono";
nipkow@1128
    64
nipkow@1128
    65
goal Relation.thy
paulson@1642
    66
    "!!r s. [| s <= A Times B;  r <= B Times C |] ==> \
paulson@1642
    67
\           (r O s) <= A Times C";
nipkow@1128
    68
by (fast_tac comp_cs 1);
nipkow@1128
    69
qed "comp_subset_Sigma";
nipkow@1128
    70
nipkow@1128
    71
(** Natural deduction for trans(r) **)
nipkow@1128
    72
nipkow@1128
    73
val prems = goalw Relation.thy [trans_def]
nipkow@1128
    74
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
    75
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
    76
qed "transI";
nipkow@1128
    77
nipkow@1128
    78
val major::prems = goalw Relation.thy [trans_def]
nipkow@1128
    79
    "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
nipkow@1128
    80
by (cut_facts_tac [major] 1);
nipkow@1128
    81
by (fast_tac (HOL_cs addIs prems) 1);
nipkow@1128
    82
qed "transD";
nipkow@1128
    83
nipkow@1128
    84
(** Natural deduction for converse(r) **)
nipkow@1128
    85
nipkow@1128
    86
goalw Relation.thy [converse_def] "!!a b r. (a,b):r ==> (b,a):converse(r)";
clasohm@1264
    87
by (Simp_tac 1);
nipkow@1128
    88
qed "converseI";
nipkow@1128
    89
nipkow@1128
    90
goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
nipkow@1128
    91
by (fast_tac comp_cs 1);
nipkow@1128
    92
qed "converseD";
nipkow@1128
    93
nipkow@1128
    94
qed_goalw "converseE" Relation.thy [converse_def]
nipkow@1128
    95
    "[| yx : converse(r);  \
nipkow@1128
    96
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
    97
\    |] ==> P"
nipkow@1128
    98
 (fn [major,minor]=>
nipkow@1128
    99
  [ (rtac (major RS CollectE) 1),
nipkow@1454
   100
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   101
    (assume_tac 1) ]);
nipkow@1128
   102
nipkow@1128
   103
val converse_cs = comp_cs addSIs [converseI] 
clasohm@1465
   104
                          addSEs [converseD,converseE];
nipkow@1128
   105
nipkow@1605
   106
goalw Relation.thy [converse_def] "converse(converse R) = R";
nipkow@1605
   107
by(fast_tac (prod_cs addSIs [equalityI]) 1);
nipkow@1605
   108
qed "converse_converse";
nipkow@1605
   109
nipkow@1128
   110
(** Domain **)
nipkow@1128
   111
nipkow@1128
   112
qed_goalw "Domain_iff" Relation.thy [Domain_def]
nipkow@1128
   113
    "a: Domain(r) = (EX y. (a,y): r)"
nipkow@1128
   114
 (fn _=> [ (fast_tac comp_cs 1) ]);
nipkow@1128
   115
nipkow@1128
   116
qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   117
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   118
nipkow@1128
   119
qed_goal "DomainE" Relation.thy
nipkow@1128
   120
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   121
 (fn prems=>
nipkow@1128
   122
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   123
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   124
nipkow@1128
   125
(** Range **)
nipkow@1128
   126
nipkow@1128
   127
qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
nipkow@1128
   128
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   129
nipkow@1128
   130
qed_goalw "RangeE" Relation.thy [Range_def]
nipkow@1128
   131
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   132
 (fn major::prems=>
nipkow@1128
   133
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   134
    (resolve_tac prems 1),
nipkow@1128
   135
    (etac converseD 1) ]);
nipkow@1128
   136
nipkow@1128
   137
(*** Image of a set under a relation ***)
nipkow@1128
   138
nipkow@1128
   139
qed_goalw "Image_iff" Relation.thy [Image_def]
nipkow@1128
   140
    "b : r^^A = (? x:A. (x,b):r)"
nipkow@1128
   141
 (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
nipkow@1128
   142
nipkow@1128
   143
qed_goal "Image_singleton_iff" Relation.thy
nipkow@1128
   144
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   145
 (fn _ => [ rtac (Image_iff RS trans) 1,
clasohm@1465
   146
            fast_tac comp_cs 1 ]);
nipkow@1128
   147
nipkow@1128
   148
qed_goalw "ImageI" Relation.thy [Image_def]
nipkow@1128
   149
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
nipkow@1128
   150
 (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
nipkow@1128
   151
            (resolve_tac [conjI ] 1),
clasohm@1465
   152
            (rtac RangeI 1),
nipkow@1128
   153
            (REPEAT (fast_tac set_cs 1))]);
nipkow@1128
   154
nipkow@1128
   155
qed_goalw "ImageE" Relation.thy [Image_def]
nipkow@1128
   156
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   157
 (fn major::prems=>
nipkow@1128
   158
  [ (rtac (major RS CollectE) 1),
nipkow@1128
   159
    (safe_tac set_cs),
nipkow@1128
   160
    (etac RangeE 1),
nipkow@1128
   161
    (rtac (hd prems) 1),
nipkow@1128
   162
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   163
nipkow@1128
   164
qed_goal "Image_subset" Relation.thy
paulson@1642
   165
    "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   166
 (fn _ =>
nipkow@1128
   167
  [ (rtac subsetI 1),
nipkow@1128
   168
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   169
nipkow@1128
   170
val rel_cs = converse_cs addSIs [converseI] 
nipkow@1128
   171
                         addIs  [ImageI, DomainI, RangeI]
nipkow@1128
   172
                         addSEs [ImageE, DomainE, RangeE];
nipkow@1128
   173
nipkow@1128
   174
val rel_eq_cs = rel_cs addSIs [equalityI];
nipkow@1128
   175
nipkow@1694
   176
goal Relation.thy "R O id = R";
nipkow@1694
   177
by(fast_tac (rel_cs addIs [set_ext] addbefore (split_all_tac 1)) 1);
nipkow@1694
   178
qed "R_O_id";
nipkow@1694
   179
nipkow@1694
   180
goal Relation.thy "id O R = R";
nipkow@1694
   181
by(fast_tac (rel_cs addIs [set_ext] addbefore (split_all_tac 1)) 1);
nipkow@1694
   182
qed "id_O_R";
nipkow@1694
   183
nipkow@1694
   184
Addsimps [R_O_id,id_O_R];