src/HOL/Relation.ML
author paulson
Fri Apr 04 11:18:52 1997 +0200 (1997-04-04)
changeset 2891 d8f254ad1ab9
parent 2637 e9b203f854ae
child 3413 c1f63cc3a768
permissions -rw-r--r--
Calls Blast_tac
clasohm@1465
     1
(*  Title:      Relation.ML
nipkow@1128
     2
    ID:         $Id$
paulson@1985
     3
    Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1985
     4
    Copyright   1996  University of Cambridge
nipkow@1128
     5
*)
nipkow@1128
     6
nipkow@1128
     7
open Relation;
nipkow@1128
     8
nipkow@1128
     9
(** Identity relation **)
nipkow@1128
    10
nipkow@1128
    11
goalw Relation.thy [id_def] "(a,a) : id";  
paulson@2891
    12
by (Blast_tac 1);
nipkow@1128
    13
qed "idI";
nipkow@1128
    14
nipkow@1128
    15
val major::prems = goalw Relation.thy [id_def]
nipkow@1128
    16
    "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
nipkow@1128
    17
\    |] ==>  P";  
nipkow@1128
    18
by (rtac (major RS CollectE) 1);
nipkow@1128
    19
by (etac exE 1);
nipkow@1128
    20
by (eresolve_tac prems 1);
nipkow@1128
    21
qed "idE";
nipkow@1128
    22
nipkow@1128
    23
goalw Relation.thy [id_def] "(a,b):id = (a=b)";
paulson@2891
    24
by (Blast_tac 1);
nipkow@1128
    25
qed "pair_in_id_conv";
nipkow@1694
    26
Addsimps [pair_in_id_conv];
nipkow@1128
    27
nipkow@1128
    28
nipkow@1128
    29
(** Composition of two relations **)
nipkow@1128
    30
paulson@1985
    31
goalw Relation.thy [comp_def]
paulson@1985
    32
    "!!r s. [| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
paulson@2891
    33
by (Blast_tac 1);
nipkow@1128
    34
qed "compI";
nipkow@1128
    35
nipkow@1128
    36
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
nipkow@1128
    37
val prems = goalw Relation.thy [comp_def]
nipkow@1128
    38
    "[| xz : r O s;  \
nipkow@1128
    39
\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
nipkow@1128
    40
\    |] ==> P";
nipkow@1128
    41
by (cut_facts_tac prems 1);
paulson@1985
    42
by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 
paulson@1985
    43
     ORELSE ares_tac prems 1));
nipkow@1128
    44
qed "compE";
nipkow@1128
    45
nipkow@1128
    46
val prems = goal Relation.thy
nipkow@1128
    47
    "[| (a,c) : r O s;  \
nipkow@1128
    48
\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
nipkow@1128
    49
\    |] ==> P";
nipkow@1128
    50
by (rtac compE 1);
nipkow@1128
    51
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
nipkow@1128
    52
qed "compEpair";
nipkow@1128
    53
berghofe@1754
    54
AddIs [compI, idI];
berghofe@1754
    55
AddSEs [compE, idE];
berghofe@1754
    56
nipkow@1128
    57
goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
paulson@2891
    58
by (Blast_tac 1);
nipkow@1128
    59
qed "comp_mono";
nipkow@1128
    60
nipkow@1128
    61
goal Relation.thy
paulson@1985
    62
    "!!r s. [| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
paulson@2891
    63
by (Blast_tac 1);
nipkow@1128
    64
qed "comp_subset_Sigma";
nipkow@1128
    65
nipkow@1128
    66
(** Natural deduction for trans(r) **)
nipkow@1128
    67
nipkow@1128
    68
val prems = goalw Relation.thy [trans_def]
nipkow@1128
    69
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
    70
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
    71
qed "transI";
nipkow@1128
    72
paulson@1985
    73
goalw Relation.thy [trans_def]
paulson@1985
    74
    "!!r. [| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
paulson@2891
    75
by (Blast_tac 1);
nipkow@1128
    76
qed "transD";
nipkow@1128
    77
nipkow@1128
    78
(** Natural deduction for converse(r) **)
nipkow@1128
    79
paulson@1985
    80
goalw Relation.thy [converse_def] "!!a b r. ((a,b):converse r) = ((b,a):r)";
paulson@1985
    81
by (Simp_tac 1);
paulson@1985
    82
qed "converse_iff";
paulson@1985
    83
paulson@1985
    84
AddIffs [converse_iff];
paulson@1985
    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";
paulson@2891
    91
by (Blast_tac 1);
nipkow@1128
    92
qed "converseD";
nipkow@1128
    93
paulson@1985
    94
(*More general than converseD, as it "splits" the member of the relation*)
nipkow@1128
    95
qed_goalw "converseE" Relation.thy [converse_def]
nipkow@1128
    96
    "[| yx : converse(r);  \
nipkow@1128
    97
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
    98
\    |] ==> P"
nipkow@1128
    99
 (fn [major,minor]=>
nipkow@1128
   100
  [ (rtac (major RS CollectE) 1),
nipkow@1454
   101
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   102
    (assume_tac 1) ]);
nipkow@1128
   103
paulson@1985
   104
AddSEs [converseE];
nipkow@1128
   105
nipkow@1605
   106
goalw Relation.thy [converse_def] "converse(converse R) = R";
paulson@2891
   107
by (Blast_tac 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)"
paulson@2891
   114
 (fn _=> [ (Blast_tac 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
paulson@1985
   125
AddIs  [DomainI];
paulson@1985
   126
AddSEs [DomainE];
paulson@1985
   127
nipkow@1128
   128
(** Range **)
nipkow@1128
   129
nipkow@1128
   130
qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
nipkow@1128
   131
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   132
nipkow@1128
   133
qed_goalw "RangeE" Relation.thy [Range_def]
nipkow@1128
   134
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   135
 (fn major::prems=>
nipkow@1128
   136
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   137
    (resolve_tac prems 1),
nipkow@1128
   138
    (etac converseD 1) ]);
nipkow@1128
   139
paulson@1985
   140
AddIs  [RangeI];
paulson@1985
   141
AddSEs [RangeE];
paulson@1985
   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)"
paulson@2891
   147
 (fn _ => [ Blast_tac 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,
paulson@2891
   152
            Blast_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"
paulson@2891
   156
 (fn _ => [ (Blast_tac 1)]);
nipkow@1128
   157
nipkow@1128
   158
qed_goalw "ImageE" Relation.thy [Image_def]
nipkow@1128
   159
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   160
 (fn major::prems=>
nipkow@1128
   161
  [ (rtac (major RS CollectE) 1),
paulson@1985
   162
    (Step_tac 1),
nipkow@1128
   163
    (rtac (hd prems) 1),
nipkow@1128
   164
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   165
paulson@1985
   166
AddIs  [ImageI];
paulson@1985
   167
AddSEs [ImageE];
paulson@1985
   168
nipkow@1128
   169
qed_goal "Image_subset" Relation.thy
paulson@1642
   170
    "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   171
 (fn _ =>
nipkow@1128
   172
  [ (rtac subsetI 1),
nipkow@1128
   173
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   174
nipkow@1694
   175
goal Relation.thy "R O id = R";
oheimb@2637
   176
by (fast_tac (!claset addbefore split_all_tac) 1);
nipkow@1694
   177
qed "R_O_id";
nipkow@1694
   178
nipkow@1694
   179
goal Relation.thy "id O R = R";
oheimb@2637
   180
by (fast_tac (!claset addbefore split_all_tac) 1);
nipkow@1694
   181
qed "id_O_R";
nipkow@1694
   182
nipkow@1694
   183
Addsimps [R_O_id,id_O_R];