src/HOL/Relation.ML
author paulson
Thu Apr 04 11:45:01 1996 +0200 (1996-04-04)
changeset 1642 21db0cf9a1a4
parent 1605 248e1e125ca0
child 1694 3452958f85a8
permissions -rw-r--r--
Using new "Times" infix
     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 <= A Times B;  r <= B Times C |] ==> \
    66 \           (r O s) <= A Times 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 goalw Relation.thy [converse_def] "converse(converse R) = R";
   106 by(fast_tac (prod_cs addSIs [equalityI]) 1);
   107 qed "converse_converse";
   108 
   109 (** Domain **)
   110 
   111 qed_goalw "Domain_iff" Relation.thy [Domain_def]
   112     "a: Domain(r) = (EX y. (a,y): r)"
   113  (fn _=> [ (fast_tac comp_cs 1) ]);
   114 
   115 qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   116  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   117 
   118 qed_goal "DomainE" Relation.thy
   119     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   120  (fn prems=>
   121   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   122     (REPEAT (ares_tac prems 1)) ]);
   123 
   124 (** Range **)
   125 
   126 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   127  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   128 
   129 qed_goalw "RangeE" Relation.thy [Range_def]
   130     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   131  (fn major::prems=>
   132   [ (rtac (major RS DomainE) 1),
   133     (resolve_tac prems 1),
   134     (etac converseD 1) ]);
   135 
   136 (*** Image of a set under a relation ***)
   137 
   138 qed_goalw "Image_iff" Relation.thy [Image_def]
   139     "b : r^^A = (? x:A. (x,b):r)"
   140  (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
   141 
   142 qed_goal "Image_singleton_iff" Relation.thy
   143     "(b : r^^{a}) = ((a,b):r)"
   144  (fn _ => [ rtac (Image_iff RS trans) 1,
   145             fast_tac comp_cs 1 ]);
   146 
   147 qed_goalw "ImageI" Relation.thy [Image_def]
   148     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   149  (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
   150             (resolve_tac [conjI ] 1),
   151             (rtac RangeI 1),
   152             (REPEAT (fast_tac set_cs 1))]);
   153 
   154 qed_goalw "ImageE" Relation.thy [Image_def]
   155     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   156  (fn major::prems=>
   157   [ (rtac (major RS CollectE) 1),
   158     (safe_tac set_cs),
   159     (etac RangeE 1),
   160     (rtac (hd prems) 1),
   161     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   162 
   163 qed_goal "Image_subset" Relation.thy
   164     "!!A B r. r <= A Times B ==> r^^C <= B"
   165  (fn _ =>
   166   [ (rtac subsetI 1),
   167     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   168 
   169 val rel_cs = converse_cs addSIs [converseI] 
   170                          addIs  [ImageI, DomainI, RangeI]
   171                          addSEs [ImageE, DomainE, RangeE];
   172 
   173 val rel_eq_cs = rel_cs addSIs [equalityI];
   174 
   175 Addsimps [pair_in_id_conv];