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.
     1 (*  Title: 	Relation.ML
     2     ID:         $Id$
     3     Authors: 	Riccardo Mattolini, Dip. Sistemi e Informatica
     4         	Lawrence C Paulson, Cambridge University Computer Laboratory
     5     Copyright   1994 Universita' di Firenze
     6     Copyright   1993  University of Cambridge
     7 *)
     8 
     9 val RSLIST = curry (op MRS);
    10 
    11 open Relation;
    12 
    13 (** Identity relation **)
    14 
    15 goalw Relation.thy [id_def] "(a,a) : id";  
    16 by (rtac CollectI 1);
    17 by (rtac exI 1);
    18 by (rtac refl 1);
    19 qed "idI";
    20 
    21 val major::prems = goalw Relation.thy [id_def]
    22     "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
    23 \    |] ==>  P";  
    24 by (rtac (major RS CollectE) 1);
    25 by (etac exE 1);
    26 by (eresolve_tac prems 1);
    27 qed "idE";
    28 
    29 goalw Relation.thy [id_def] "(a,b):id = (a=b)";
    30 by(fast_tac prod_cs 1);
    31 qed "pair_in_id_conv";
    32 
    33 
    34 (** Composition of two relations **)
    35 
    36 val prems = goalw Relation.thy [comp_def]
    37     "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
    38 by (fast_tac (set_cs addIs prems) 1);
    39 qed "compI";
    40 
    41 (*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    42 val prems = goalw Relation.thy [comp_def]
    43     "[| xz : r O s;  \
    44 \       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
    45 \    |] ==> P";
    46 by (cut_facts_tac prems 1);
    47 by (REPEAT (eresolve_tac [CollectE, exE, conjE] 1 ORELSE ares_tac prems 1));
    48 qed "compE";
    49 
    50 val prems = goal Relation.thy
    51     "[| (a,c) : r O s;  \
    52 \       !!y. [| (a,y):s;  (y,c):r |] ==> P \
    53 \    |] ==> P";
    54 by (rtac compE 1);
    55 by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
    56 qed "compEpair";
    57 
    58 val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
    59 
    60 goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    61 by (fast_tac comp_cs 1);
    62 qed "comp_mono";
    63 
    64 goal Relation.thy
    65     "!!r s. [| s <= Sigma A (%x.B);  r <= Sigma B (%x.C) |] ==> \
    66 \           (r O s) <= Sigma A (%x.C)";
    67 by (fast_tac comp_cs 1);
    68 qed "comp_subset_Sigma";
    69 
    70 (** Natural deduction for trans(r) **)
    71 
    72 val prems = goalw Relation.thy [trans_def]
    73     "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    74 by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    75 qed "transI";
    76 
    77 val major::prems = goalw Relation.thy [trans_def]
    78     "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    79 by (cut_facts_tac [major] 1);
    80 by (fast_tac (HOL_cs addIs prems) 1);
    81 qed "transD";
    82 
    83 (** Natural deduction for converse(r) **)
    84 
    85 goalw Relation.thy [converse_def] "!!a b r. (a,b):r ==> (b,a):converse(r)";
    86 by (simp_tac prod_ss 1);
    87 by (fast_tac set_cs 1);
    88 qed "converseI";
    89 
    90 goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
    91 by (fast_tac comp_cs 1);
    92 qed "converseD";
    93 
    94 qed_goalw "converseE" Relation.thy [converse_def]
    95     "[| yx : converse(r);  \
    96 \       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
    97 \    |] ==> P"
    98  (fn [major,minor]=>
    99   [ (rtac (major RS CollectE) 1),
   100     (REPEAT (eresolve_tac [bexE,exE, conjE, minor] 1)),
   101     (hyp_subst_tac 1),
   102     (assume_tac 1) ]);
   103 
   104 val converse_cs = comp_cs addSIs [converseI] 
   105 			  addSEs [converseD,converseE];
   106 
   107 (** Domain **)
   108 
   109 qed_goalw "Domain_iff" Relation.thy [Domain_def]
   110     "a: Domain(r) = (EX y. (a,y): r)"
   111  (fn _=> [ (fast_tac comp_cs 1) ]);
   112 
   113 qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   114  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   115 
   116 qed_goal "DomainE" Relation.thy
   117     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   118  (fn prems=>
   119   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   120     (REPEAT (ares_tac prems 1)) ]);
   121 
   122 (** Range **)
   123 
   124 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   125  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   126 
   127 qed_goalw "RangeE" Relation.thy [Range_def]
   128     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   129  (fn major::prems=>
   130   [ (rtac (major RS DomainE) 1),
   131     (resolve_tac prems 1),
   132     (etac converseD 1) ]);
   133 
   134 (*** Image of a set under a relation ***)
   135 
   136 qed_goalw "Image_iff" Relation.thy [Image_def]
   137     "b : r^^A = (? x:A. (x,b):r)"
   138  (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
   139 
   140 qed_goal "Image_singleton_iff" Relation.thy
   141     "(b : r^^{a}) = ((a,b):r)"
   142  (fn _ => [ rtac (Image_iff RS trans) 1,
   143 	    fast_tac comp_cs 1 ]);
   144 
   145 qed_goalw "ImageI" Relation.thy [Image_def]
   146     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   147  (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
   148             (resolve_tac [conjI ] 1),
   149             (resolve_tac [RangeI] 1),
   150             (REPEAT (fast_tac set_cs 1))]);
   151 
   152 qed_goalw "ImageE" Relation.thy [Image_def]
   153     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   154  (fn major::prems=>
   155   [ (rtac (major RS CollectE) 1),
   156     (safe_tac set_cs),
   157     (etac RangeE 1),
   158     (rtac (hd prems) 1),
   159     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   160 
   161 qed_goal "Image_subset" Relation.thy
   162     "!!A B r. r <= Sigma A (%x.B) ==> r^^C <= B"
   163  (fn _ =>
   164   [ (rtac subsetI 1),
   165     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   166 
   167 val rel_cs = converse_cs addSIs [converseI] 
   168                          addIs  [ImageI, DomainI, RangeI]
   169                          addSEs [ImageE, DomainE, RangeE];
   170 
   171 val rel_eq_cs = rel_cs addSIs [equalityI];
   172 
   173 val rel_ss = prod_ss addsimps [pair_in_id_conv];