src/HOL/Relation.ML
author nipkow
Fri May 26 18:11:47 1995 +0200 (1995-05-26)
changeset 1128 64b30e3cc6d4
child 1264 3eb91524b938
permissions -rw-r--r--
Trancl is now based on Relation which used to be in Integ.
nipkow@1128
     1
(*  Title: 	Relation.ML
nipkow@1128
     2
    ID:         $Id$
nipkow@1128
     3
    Authors: 	Riccardo Mattolini, Dip. Sistemi e Informatica
nipkow@1128
     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)";
nipkow@1128
    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@1128
    38
by (fast_tac (set_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@1128
    47
by (REPEAT (eresolve_tac [CollectE, 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
nipkow@1128
    65
    "!!r s. [| s <= Sigma A (%x.B);  r <= Sigma B (%x.C) |] ==> \
nipkow@1128
    66
\           (r O s) <= Sigma A (%x.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)";
nipkow@1128
    86
by (simp_tac prod_ss 1);
nipkow@1128
    87
by (fast_tac set_cs 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@1128
   100
    (REPEAT (eresolve_tac [bexE,exE, conjE, minor] 1)),
nipkow@1128
   101
    (hyp_subst_tac 1),
nipkow@1128
   102
    (assume_tac 1) ]);
nipkow@1128
   103
nipkow@1128
   104
val converse_cs = comp_cs addSIs [converseI] 
nipkow@1128
   105
			  addSEs [converseD,converseE];
nipkow@1128
   106
nipkow@1128
   107
(** Domain **)
nipkow@1128
   108
nipkow@1128
   109
qed_goalw "Domain_iff" Relation.thy [Domain_def]
nipkow@1128
   110
    "a: Domain(r) = (EX y. (a,y): r)"
nipkow@1128
   111
 (fn _=> [ (fast_tac comp_cs 1) ]);
nipkow@1128
   112
nipkow@1128
   113
qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   114
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   115
nipkow@1128
   116
qed_goal "DomainE" Relation.thy
nipkow@1128
   117
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   118
 (fn prems=>
nipkow@1128
   119
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   120
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   121
nipkow@1128
   122
(** Range **)
nipkow@1128
   123
nipkow@1128
   124
qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
nipkow@1128
   125
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   126
nipkow@1128
   127
qed_goalw "RangeE" Relation.thy [Range_def]
nipkow@1128
   128
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   129
 (fn major::prems=>
nipkow@1128
   130
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   131
    (resolve_tac prems 1),
nipkow@1128
   132
    (etac converseD 1) ]);
nipkow@1128
   133
nipkow@1128
   134
(*** Image of a set under a relation ***)
nipkow@1128
   135
nipkow@1128
   136
qed_goalw "Image_iff" Relation.thy [Image_def]
nipkow@1128
   137
    "b : r^^A = (? x:A. (x,b):r)"
nipkow@1128
   138
 (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
nipkow@1128
   139
nipkow@1128
   140
qed_goal "Image_singleton_iff" Relation.thy
nipkow@1128
   141
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   142
 (fn _ => [ rtac (Image_iff RS trans) 1,
nipkow@1128
   143
	    fast_tac comp_cs 1 ]);
nipkow@1128
   144
nipkow@1128
   145
qed_goalw "ImageI" Relation.thy [Image_def]
nipkow@1128
   146
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
nipkow@1128
   147
 (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
nipkow@1128
   148
            (resolve_tac [conjI ] 1),
nipkow@1128
   149
            (resolve_tac [RangeI] 1),
nipkow@1128
   150
            (REPEAT (fast_tac set_cs 1))]);
nipkow@1128
   151
nipkow@1128
   152
qed_goalw "ImageE" Relation.thy [Image_def]
nipkow@1128
   153
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   154
 (fn major::prems=>
nipkow@1128
   155
  [ (rtac (major RS CollectE) 1),
nipkow@1128
   156
    (safe_tac set_cs),
nipkow@1128
   157
    (etac RangeE 1),
nipkow@1128
   158
    (rtac (hd prems) 1),
nipkow@1128
   159
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   160
nipkow@1128
   161
qed_goal "Image_subset" Relation.thy
nipkow@1128
   162
    "!!A B r. r <= Sigma A (%x.B) ==> r^^C <= B"
nipkow@1128
   163
 (fn _ =>
nipkow@1128
   164
  [ (rtac subsetI 1),
nipkow@1128
   165
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   166
nipkow@1128
   167
val rel_cs = converse_cs addSIs [converseI] 
nipkow@1128
   168
                         addIs  [ImageI, DomainI, RangeI]
nipkow@1128
   169
                         addSEs [ImageE, DomainE, RangeE];
nipkow@1128
   170
nipkow@1128
   171
val rel_eq_cs = rel_cs addSIs [equalityI];
nipkow@1128
   172
nipkow@1128
   173
val rel_ss = prod_ss addsimps [pair_in_id_conv];