src/HOL/Relation.ML
author nipkow
Thu Jun 05 14:39:22 1997 +0200 (1997-06-05)
changeset 3413 c1f63cc3a768
parent 2891 d8f254ad1ab9
child 3439 54785105178c
permissions -rw-r--r--
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.

Relation.ML Trancl.ML: more thms

WF.ML WF.thy: added `acyclic'
WF_Rel.ML: moved some thms back into WF and added some new ones.
     1 (*  Title:      Relation.ML
     2     ID:         $Id$
     3     Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 *)
     6 
     7 open Relation;
     8 
     9 (** Identity relation **)
    10 
    11 goalw Relation.thy [id_def] "(a,a) : id";  
    12 by (Blast_tac 1);
    13 qed "idI";
    14 
    15 val major::prems = goalw Relation.thy [id_def]
    16     "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
    17 \    |] ==>  P";  
    18 by (rtac (major RS CollectE) 1);
    19 by (etac exE 1);
    20 by (eresolve_tac prems 1);
    21 qed "idE";
    22 
    23 goalw Relation.thy [id_def] "(a,b):id = (a=b)";
    24 by (Blast_tac 1);
    25 qed "pair_in_id_conv";
    26 Addsimps [pair_in_id_conv];
    27 
    28 
    29 (** Composition of two relations **)
    30 
    31 goalw Relation.thy [comp_def]
    32     "!!r s. [| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
    33 by (Blast_tac 1);
    34 qed "compI";
    35 
    36 (*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    37 val prems = goalw Relation.thy [comp_def]
    38     "[| xz : r O s;  \
    39 \       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
    40 \    |] ==> P";
    41 by (cut_facts_tac prems 1);
    42 by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 
    43      ORELSE ares_tac prems 1));
    44 qed "compE";
    45 
    46 val prems = goal Relation.thy
    47     "[| (a,c) : r O s;  \
    48 \       !!y. [| (a,y):s;  (y,c):r |] ==> P \
    49 \    |] ==> P";
    50 by (rtac compE 1);
    51 by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
    52 qed "compEpair";
    53 
    54 AddIs [compI, idI];
    55 AddSEs [compE, idE];
    56 
    57 goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    58 by (Blast_tac 1);
    59 qed "comp_mono";
    60 
    61 goal Relation.thy
    62     "!!r s. [| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
    63 by (Blast_tac 1);
    64 qed "comp_subset_Sigma";
    65 
    66 (** Natural deduction for trans(r) **)
    67 
    68 val prems = goalw Relation.thy [trans_def]
    69     "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    70 by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    71 qed "transI";
    72 
    73 goalw Relation.thy [trans_def]
    74     "!!r. [| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    75 by (Blast_tac 1);
    76 qed "transD";
    77 
    78 (** Natural deduction for converse(r) **)
    79 
    80 goalw Relation.thy [converse_def] "!!a b r. ((a,b):converse r) = ((b,a):r)";
    81 by (Simp_tac 1);
    82 qed "converse_iff";
    83 
    84 AddIffs [converse_iff];
    85 
    86 goalw Relation.thy [converse_def] "!!a b r. (a,b):r ==> (b,a):converse(r)";
    87 by (Simp_tac 1);
    88 qed "converseI";
    89 
    90 goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
    91 by (Blast_tac 1);
    92 qed "converseD";
    93 
    94 (*More general than converseD, as it "splits" the member of the relation*)
    95 qed_goalw "converseE" Relation.thy [converse_def]
    96     "[| yx : converse(r);  \
    97 \       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
    98 \    |] ==> P"
    99  (fn [major,minor]=>
   100   [ (rtac (major RS CollectE) 1),
   101     (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
   102     (assume_tac 1) ]);
   103 
   104 AddSEs [converseE];
   105 
   106 goalw Relation.thy [converse_def] "converse(converse R) = R";
   107 by (Blast_tac 1);
   108 qed "converse_converse";
   109 Addsimps [converse_converse];
   110 
   111 goal Relation.thy "converse(r O s) = converse s O converse r";
   112 by(Blast_tac 1);
   113 qed "converse_comp";
   114 
   115 (** Domain **)
   116 
   117 qed_goalw "Domain_iff" Relation.thy [Domain_def]
   118     "a: Domain(r) = (EX y. (a,y): r)"
   119  (fn _=> [ (Blast_tac 1) ]);
   120 
   121 qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   122  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   123 
   124 qed_goal "DomainE" Relation.thy
   125     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   126  (fn prems=>
   127   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   128     (REPEAT (ares_tac prems 1)) ]);
   129 
   130 AddIs  [DomainI];
   131 AddSEs [DomainE];
   132 
   133 (** Range **)
   134 
   135 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   136  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   137 
   138 qed_goalw "RangeE" Relation.thy [Range_def]
   139     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   140  (fn major::prems=>
   141   [ (rtac (major RS DomainE) 1),
   142     (resolve_tac prems 1),
   143     (etac converseD 1) ]);
   144 
   145 AddIs  [RangeI];
   146 AddSEs [RangeE];
   147 
   148 (*** Image of a set under a relation ***)
   149 
   150 qed_goalw "Image_iff" Relation.thy [Image_def]
   151     "b : r^^A = (? x:A. (x,b):r)"
   152  (fn _ => [ Blast_tac 1 ]);
   153 
   154 qed_goal "Image_singleton_iff" Relation.thy
   155     "(b : r^^{a}) = ((a,b):r)"
   156  (fn _ => [ rtac (Image_iff RS trans) 1,
   157             Blast_tac 1 ]);
   158 
   159 qed_goalw "ImageI" Relation.thy [Image_def]
   160     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   161  (fn _ => [ (Blast_tac 1)]);
   162 
   163 qed_goalw "ImageE" Relation.thy [Image_def]
   164     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   165  (fn major::prems=>
   166   [ (rtac (major RS CollectE) 1),
   167     (Step_tac 1),
   168     (rtac (hd prems) 1),
   169     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   170 
   171 AddIs  [ImageI];
   172 AddSEs [ImageE];
   173 
   174 qed_goal "Image_subset" Relation.thy
   175     "!!A B r. r <= A Times B ==> r^^C <= B"
   176  (fn _ =>
   177   [ (rtac subsetI 1),
   178     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   179 
   180 goal Relation.thy "R O id = R";
   181 by (fast_tac (!claset addbefore split_all_tac) 1);
   182 qed "R_O_id";
   183 
   184 goal Relation.thy "id O R = R";
   185 by (fast_tac (!claset addbefore split_all_tac) 1);
   186 qed "id_O_R";
   187 
   188 Addsimps [R_O_id,id_O_R];