src/HOL/Relation.ML
author berghofe
Mon Jun 03 17:10:56 1996 +0200 (1996-06-03)
changeset 1786 8a31d85d27b8
parent 1761 29e08d527ba1
child 1842 a9c36056d320
permissions -rw-r--r--
best_tac, deepen_tac and safe_tac now also use default claset.
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)";
berghofe@1754
    30
by (Fast_tac 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";
berghofe@1754
    39
by (fast_tac (!claset 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
berghofe@1754
    59
AddIs [compI, idI];
berghofe@1754
    60
AddSEs [compE, idE];
berghofe@1754
    61
nipkow@1128
    62
val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
nipkow@1128
    63
nipkow@1128
    64
goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
berghofe@1754
    65
by (Fast_tac 1);
nipkow@1128
    66
qed "comp_mono";
nipkow@1128
    67
nipkow@1128
    68
goal Relation.thy
paulson@1642
    69
    "!!r s. [| s <= A Times B;  r <= B Times C |] ==> \
paulson@1642
    70
\           (r O s) <= A Times C";
berghofe@1754
    71
by (Fast_tac 1);
nipkow@1128
    72
qed "comp_subset_Sigma";
nipkow@1128
    73
nipkow@1128
    74
(** Natural deduction for trans(r) **)
nipkow@1128
    75
nipkow@1128
    76
val prems = goalw Relation.thy [trans_def]
nipkow@1128
    77
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
    78
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
    79
qed "transI";
nipkow@1128
    80
nipkow@1128
    81
val major::prems = goalw Relation.thy [trans_def]
nipkow@1128
    82
    "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
nipkow@1128
    83
by (cut_facts_tac [major] 1);
berghofe@1754
    84
by (fast_tac (!claset addIs prems) 1);
nipkow@1128
    85
qed "transD";
nipkow@1128
    86
nipkow@1128
    87
(** Natural deduction for converse(r) **)
nipkow@1128
    88
nipkow@1128
    89
goalw Relation.thy [converse_def] "!!a b r. (a,b):r ==> (b,a):converse(r)";
clasohm@1264
    90
by (Simp_tac 1);
nipkow@1128
    91
qed "converseI";
nipkow@1128
    92
nipkow@1128
    93
goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
berghofe@1754
    94
by (Fast_tac 1);
nipkow@1128
    95
qed "converseD";
nipkow@1128
    96
nipkow@1128
    97
qed_goalw "converseE" Relation.thy [converse_def]
nipkow@1128
    98
    "[| yx : converse(r);  \
nipkow@1128
    99
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
   100
\    |] ==> P"
nipkow@1128
   101
 (fn [major,minor]=>
nipkow@1128
   102
  [ (rtac (major RS CollectE) 1),
nipkow@1454
   103
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   104
    (assume_tac 1) ]);
nipkow@1128
   105
berghofe@1754
   106
AddSIs [converseI];
berghofe@1754
   107
AddSEs [converseD,converseE];
berghofe@1754
   108
berghofe@1754
   109
val converse_cs = comp_cs addSIs [converseI]
clasohm@1465
   110
                          addSEs [converseD,converseE];
nipkow@1128
   111
nipkow@1605
   112
goalw Relation.thy [converse_def] "converse(converse R) = R";
berghofe@1761
   113
by(Fast_tac 1);
nipkow@1605
   114
qed "converse_converse";
nipkow@1605
   115
nipkow@1128
   116
(** Domain **)
nipkow@1128
   117
nipkow@1128
   118
qed_goalw "Domain_iff" Relation.thy [Domain_def]
nipkow@1128
   119
    "a: Domain(r) = (EX y. (a,y): r)"
berghofe@1754
   120
 (fn _=> [ (Fast_tac 1) ]);
nipkow@1128
   121
nipkow@1128
   122
qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   123
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   124
nipkow@1128
   125
qed_goal "DomainE" Relation.thy
nipkow@1128
   126
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   127
 (fn prems=>
nipkow@1128
   128
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   129
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   130
nipkow@1128
   131
(** Range **)
nipkow@1128
   132
nipkow@1128
   133
qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
nipkow@1128
   134
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   135
nipkow@1128
   136
qed_goalw "RangeE" Relation.thy [Range_def]
nipkow@1128
   137
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   138
 (fn major::prems=>
nipkow@1128
   139
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   140
    (resolve_tac prems 1),
nipkow@1128
   141
    (etac converseD 1) ]);
nipkow@1128
   142
nipkow@1128
   143
(*** Image of a set under a relation ***)
nipkow@1128
   144
nipkow@1128
   145
qed_goalw "Image_iff" Relation.thy [Image_def]
nipkow@1128
   146
    "b : r^^A = (? x:A. (x,b):r)"
berghofe@1754
   147
 (fn _ => [ fast_tac (!claset addIs [RangeI]) 1 ]);
nipkow@1128
   148
nipkow@1128
   149
qed_goal "Image_singleton_iff" Relation.thy
nipkow@1128
   150
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   151
 (fn _ => [ rtac (Image_iff RS trans) 1,
berghofe@1754
   152
            Fast_tac 1 ]);
nipkow@1128
   153
nipkow@1128
   154
qed_goalw "ImageI" Relation.thy [Image_def]
nipkow@1128
   155
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
nipkow@1128
   156
 (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
nipkow@1128
   157
            (resolve_tac [conjI ] 1),
clasohm@1465
   158
            (rtac RangeI 1),
berghofe@1754
   159
            (REPEAT (Fast_tac 1))]);
nipkow@1128
   160
nipkow@1128
   161
qed_goalw "ImageE" Relation.thy [Image_def]
nipkow@1128
   162
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   163
 (fn major::prems=>
nipkow@1128
   164
  [ (rtac (major RS CollectE) 1),
berghofe@1786
   165
    (safe_tac (!claset)),
nipkow@1128
   166
    (etac RangeE 1),
nipkow@1128
   167
    (rtac (hd prems) 1),
nipkow@1128
   168
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   169
nipkow@1128
   170
qed_goal "Image_subset" Relation.thy
paulson@1642
   171
    "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   172
 (fn _ =>
nipkow@1128
   173
  [ (rtac subsetI 1),
nipkow@1128
   174
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   175
berghofe@1754
   176
AddSIs [converseI]; 
berghofe@1754
   177
AddIs  [ImageI, DomainI, RangeI];
berghofe@1754
   178
AddSEs [ImageE, DomainE, RangeE];
berghofe@1754
   179
nipkow@1128
   180
val rel_cs = converse_cs addSIs [converseI] 
nipkow@1128
   181
                         addIs  [ImageI, DomainI, RangeI]
nipkow@1128
   182
                         addSEs [ImageE, DomainE, RangeE];
nipkow@1128
   183
berghofe@1754
   184
AddSIs [equalityI];
berghofe@1754
   185
nipkow@1128
   186
val rel_eq_cs = rel_cs addSIs [equalityI];
nipkow@1128
   187
nipkow@1694
   188
goal Relation.thy "R O id = R";
berghofe@1754
   189
by(fast_tac (!claset addIs [set_ext] addbefore (split_all_tac 1)) 1);
nipkow@1694
   190
qed "R_O_id";
nipkow@1694
   191
nipkow@1694
   192
goal Relation.thy "id O R = R";
berghofe@1754
   193
by(fast_tac (!claset addIs [set_ext] addbefore (split_all_tac 1)) 1);
nipkow@1694
   194
qed "id_O_R";
nipkow@1694
   195
nipkow@1694
   196
Addsimps [R_O_id,id_O_R];