src/HOL/Relation.ML
author paulson
Thu Apr 04 11:45:01 1996 +0200 (1996-04-04)
changeset 1642 21db0cf9a1a4
parent 1605 248e1e125ca0
child 1694 3452958f85a8
permissions -rw-r--r--
Using new "Times" infix
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@1128
    32
nipkow@1128
    33
nipkow@1128
    34
(** Composition of two relations **)
nipkow@1128
    35
nipkow@1128
    36
val prems = goalw Relation.thy [comp_def]
nipkow@1128
    37
    "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
nipkow@1454
    38
by (fast_tac (prod_cs addIs prems) 1);
nipkow@1128
    39
qed "compI";
nipkow@1128
    40
nipkow@1128
    41
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
nipkow@1128
    42
val prems = goalw Relation.thy [comp_def]
nipkow@1128
    43
    "[| xz : r O s;  \
nipkow@1128
    44
\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
nipkow@1128
    45
\    |] ==> P";
nipkow@1128
    46
by (cut_facts_tac prems 1);
nipkow@1454
    47
by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 ORELSE ares_tac prems 1));
nipkow@1128
    48
qed "compE";
nipkow@1128
    49
nipkow@1128
    50
val prems = goal Relation.thy
nipkow@1128
    51
    "[| (a,c) : r O s;  \
nipkow@1128
    52
\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
nipkow@1128
    53
\    |] ==> P";
nipkow@1128
    54
by (rtac compE 1);
nipkow@1128
    55
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
nipkow@1128
    56
qed "compEpair";
nipkow@1128
    57
nipkow@1128
    58
val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
nipkow@1128
    59
nipkow@1128
    60
goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
nipkow@1128
    61
by (fast_tac comp_cs 1);
nipkow@1128
    62
qed "comp_mono";
nipkow@1128
    63
nipkow@1128
    64
goal Relation.thy
paulson@1642
    65
    "!!r s. [| s <= A Times B;  r <= B Times C |] ==> \
paulson@1642
    66
\           (r O s) <= A Times C";
nipkow@1128
    67
by (fast_tac comp_cs 1);
nipkow@1128
    68
qed "comp_subset_Sigma";
nipkow@1128
    69
nipkow@1128
    70
(** Natural deduction for trans(r) **)
nipkow@1128
    71
nipkow@1128
    72
val prems = goalw Relation.thy [trans_def]
nipkow@1128
    73
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
    74
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
    75
qed "transI";
nipkow@1128
    76
nipkow@1128
    77
val major::prems = goalw Relation.thy [trans_def]
nipkow@1128
    78
    "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
nipkow@1128
    79
by (cut_facts_tac [major] 1);
nipkow@1128
    80
by (fast_tac (HOL_cs addIs prems) 1);
nipkow@1128
    81
qed "transD";
nipkow@1128
    82
nipkow@1128
    83
(** Natural deduction for converse(r) **)
nipkow@1128
    84
nipkow@1128
    85
goalw Relation.thy [converse_def] "!!a b r. (a,b):r ==> (b,a):converse(r)";
clasohm@1264
    86
by (Simp_tac 1);
nipkow@1128
    87
qed "converseI";
nipkow@1128
    88
nipkow@1128
    89
goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
nipkow@1128
    90
by (fast_tac comp_cs 1);
nipkow@1128
    91
qed "converseD";
nipkow@1128
    92
nipkow@1128
    93
qed_goalw "converseE" Relation.thy [converse_def]
nipkow@1128
    94
    "[| yx : converse(r);  \
nipkow@1128
    95
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
    96
\    |] ==> P"
nipkow@1128
    97
 (fn [major,minor]=>
nipkow@1128
    98
  [ (rtac (major RS CollectE) 1),
nipkow@1454
    99
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   100
    (assume_tac 1) ]);
nipkow@1128
   101
nipkow@1128
   102
val converse_cs = comp_cs addSIs [converseI] 
clasohm@1465
   103
                          addSEs [converseD,converseE];
nipkow@1128
   104
nipkow@1605
   105
goalw Relation.thy [converse_def] "converse(converse R) = R";
nipkow@1605
   106
by(fast_tac (prod_cs addSIs [equalityI]) 1);
nipkow@1605
   107
qed "converse_converse";
nipkow@1605
   108
nipkow@1128
   109
(** Domain **)
nipkow@1128
   110
nipkow@1128
   111
qed_goalw "Domain_iff" Relation.thy [Domain_def]
nipkow@1128
   112
    "a: Domain(r) = (EX y. (a,y): r)"
nipkow@1128
   113
 (fn _=> [ (fast_tac comp_cs 1) ]);
nipkow@1128
   114
nipkow@1128
   115
qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   116
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   117
nipkow@1128
   118
qed_goal "DomainE" Relation.thy
nipkow@1128
   119
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   120
 (fn prems=>
nipkow@1128
   121
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   122
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   123
nipkow@1128
   124
(** Range **)
nipkow@1128
   125
nipkow@1128
   126
qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
nipkow@1128
   127
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   128
nipkow@1128
   129
qed_goalw "RangeE" Relation.thy [Range_def]
nipkow@1128
   130
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   131
 (fn major::prems=>
nipkow@1128
   132
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   133
    (resolve_tac prems 1),
nipkow@1128
   134
    (etac converseD 1) ]);
nipkow@1128
   135
nipkow@1128
   136
(*** Image of a set under a relation ***)
nipkow@1128
   137
nipkow@1128
   138
qed_goalw "Image_iff" Relation.thy [Image_def]
nipkow@1128
   139
    "b : r^^A = (? x:A. (x,b):r)"
nipkow@1128
   140
 (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
nipkow@1128
   141
nipkow@1128
   142
qed_goal "Image_singleton_iff" Relation.thy
nipkow@1128
   143
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   144
 (fn _ => [ rtac (Image_iff RS trans) 1,
clasohm@1465
   145
            fast_tac comp_cs 1 ]);
nipkow@1128
   146
nipkow@1128
   147
qed_goalw "ImageI" Relation.thy [Image_def]
nipkow@1128
   148
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
nipkow@1128
   149
 (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
nipkow@1128
   150
            (resolve_tac [conjI ] 1),
clasohm@1465
   151
            (rtac RangeI 1),
nipkow@1128
   152
            (REPEAT (fast_tac set_cs 1))]);
nipkow@1128
   153
nipkow@1128
   154
qed_goalw "ImageE" Relation.thy [Image_def]
nipkow@1128
   155
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   156
 (fn major::prems=>
nipkow@1128
   157
  [ (rtac (major RS CollectE) 1),
nipkow@1128
   158
    (safe_tac set_cs),
nipkow@1128
   159
    (etac RangeE 1),
nipkow@1128
   160
    (rtac (hd prems) 1),
nipkow@1128
   161
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   162
nipkow@1128
   163
qed_goal "Image_subset" Relation.thy
paulson@1642
   164
    "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   165
 (fn _ =>
nipkow@1128
   166
  [ (rtac subsetI 1),
nipkow@1128
   167
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   168
nipkow@1128
   169
val rel_cs = converse_cs addSIs [converseI] 
nipkow@1128
   170
                         addIs  [ImageI, DomainI, RangeI]
nipkow@1128
   171
                         addSEs [ImageE, DomainE, RangeE];
nipkow@1128
   172
nipkow@1128
   173
val rel_eq_cs = rel_cs addSIs [equalityI];
nipkow@1128
   174
clasohm@1264
   175
Addsimps [pair_in_id_conv];