src/HOL/Relation.ML
author clasohm
Tue Jan 30 15:24:36 1996 +0100 (1996-01-30)
changeset 1465 5d7a7e439cec
parent 1454 d0266c81a85e
child 1552 6f71b5d46700
permissions -rw-r--r--
expanded tabs
     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 (prod_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, splitE, 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 1);
    87 qed "converseI";
    88 
    89 goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
    90 by (fast_tac comp_cs 1);
    91 qed "converseD";
    92 
    93 qed_goalw "converseE" Relation.thy [converse_def]
    94     "[| yx : converse(r);  \
    95 \       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
    96 \    |] ==> P"
    97  (fn [major,minor]=>
    98   [ (rtac (major RS CollectE) 1),
    99     (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
   100     (assume_tac 1) ]);
   101 
   102 val converse_cs = comp_cs addSIs [converseI] 
   103                           addSEs [converseD,converseE];
   104 
   105 (** Domain **)
   106 
   107 qed_goalw "Domain_iff" Relation.thy [Domain_def]
   108     "a: Domain(r) = (EX y. (a,y): r)"
   109  (fn _=> [ (fast_tac comp_cs 1) ]);
   110 
   111 qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   112  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   113 
   114 qed_goal "DomainE" Relation.thy
   115     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   116  (fn prems=>
   117   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   118     (REPEAT (ares_tac prems 1)) ]);
   119 
   120 (** Range **)
   121 
   122 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   123  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   124 
   125 qed_goalw "RangeE" Relation.thy [Range_def]
   126     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   127  (fn major::prems=>
   128   [ (rtac (major RS DomainE) 1),
   129     (resolve_tac prems 1),
   130     (etac converseD 1) ]);
   131 
   132 (*** Image of a set under a relation ***)
   133 
   134 qed_goalw "Image_iff" Relation.thy [Image_def]
   135     "b : r^^A = (? x:A. (x,b):r)"
   136  (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
   137 
   138 qed_goal "Image_singleton_iff" Relation.thy
   139     "(b : r^^{a}) = ((a,b):r)"
   140  (fn _ => [ rtac (Image_iff RS trans) 1,
   141             fast_tac comp_cs 1 ]);
   142 
   143 qed_goalw "ImageI" Relation.thy [Image_def]
   144     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   145  (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
   146             (resolve_tac [conjI ] 1),
   147             (rtac RangeI 1),
   148             (REPEAT (fast_tac set_cs 1))]);
   149 
   150 qed_goalw "ImageE" Relation.thy [Image_def]
   151     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   152  (fn major::prems=>
   153   [ (rtac (major RS CollectE) 1),
   154     (safe_tac set_cs),
   155     (etac RangeE 1),
   156     (rtac (hd prems) 1),
   157     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   158 
   159 qed_goal "Image_subset" Relation.thy
   160     "!!A B r. r <= Sigma A (%x.B) ==> r^^C <= B"
   161  (fn _ =>
   162   [ (rtac subsetI 1),
   163     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   164 
   165 val rel_cs = converse_cs addSIs [converseI] 
   166                          addIs  [ImageI, DomainI, RangeI]
   167                          addSEs [ImageE, DomainE, RangeE];
   168 
   169 val rel_eq_cs = rel_cs addSIs [equalityI];
   170 
   171 Addsimps [pair_in_id_conv];