src/HOL/Relation.ML
author nipkow
Sat Apr 27 12:07:31 1996 +0200 (1996-04-27)
changeset 1694 3452958f85a8
parent 1642 21db0cf9a1a4
child 1754 852093aeb0ab
permissions -rw-r--r--
Added R_O_id and id_O_R
     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 Addsimps [pair_in_id_conv];
    33 
    34 
    35 (** Composition of two relations **)
    36 
    37 val prems = goalw Relation.thy [comp_def]
    38     "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
    39 by (fast_tac (prod_cs addIs prems) 1);
    40 qed "compI";
    41 
    42 (*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    43 val prems = goalw Relation.thy [comp_def]
    44     "[| xz : r O s;  \
    45 \       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
    46 \    |] ==> P";
    47 by (cut_facts_tac prems 1);
    48 by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 ORELSE ares_tac prems 1));
    49 qed "compE";
    50 
    51 val prems = goal Relation.thy
    52     "[| (a,c) : r O s;  \
    53 \       !!y. [| (a,y):s;  (y,c):r |] ==> P \
    54 \    |] ==> P";
    55 by (rtac compE 1);
    56 by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
    57 qed "compEpair";
    58 
    59 val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
    60 
    61 goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    62 by (fast_tac comp_cs 1);
    63 qed "comp_mono";
    64 
    65 goal Relation.thy
    66     "!!r s. [| s <= A Times B;  r <= B Times C |] ==> \
    67 \           (r O s) <= A Times C";
    68 by (fast_tac comp_cs 1);
    69 qed "comp_subset_Sigma";
    70 
    71 (** Natural deduction for trans(r) **)
    72 
    73 val prems = goalw Relation.thy [trans_def]
    74     "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    75 by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    76 qed "transI";
    77 
    78 val major::prems = goalw Relation.thy [trans_def]
    79     "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    80 by (cut_facts_tac [major] 1);
    81 by (fast_tac (HOL_cs addIs prems) 1);
    82 qed "transD";
    83 
    84 (** Natural deduction for converse(r) **)
    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 (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 [splitE, bexE,exE, conjE, minor] 1)),
   101     (assume_tac 1) ]);
   102 
   103 val converse_cs = comp_cs addSIs [converseI] 
   104                           addSEs [converseD,converseE];
   105 
   106 goalw Relation.thy [converse_def] "converse(converse R) = R";
   107 by(fast_tac (prod_cs addSIs [equalityI]) 1);
   108 qed "converse_converse";
   109 
   110 (** Domain **)
   111 
   112 qed_goalw "Domain_iff" Relation.thy [Domain_def]
   113     "a: Domain(r) = (EX y. (a,y): r)"
   114  (fn _=> [ (fast_tac comp_cs 1) ]);
   115 
   116 qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   117  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   118 
   119 qed_goal "DomainE" Relation.thy
   120     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   121  (fn prems=>
   122   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   123     (REPEAT (ares_tac prems 1)) ]);
   124 
   125 (** Range **)
   126 
   127 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   128  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   129 
   130 qed_goalw "RangeE" Relation.thy [Range_def]
   131     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   132  (fn major::prems=>
   133   [ (rtac (major RS DomainE) 1),
   134     (resolve_tac prems 1),
   135     (etac converseD 1) ]);
   136 
   137 (*** Image of a set under a relation ***)
   138 
   139 qed_goalw "Image_iff" Relation.thy [Image_def]
   140     "b : r^^A = (? x:A. (x,b):r)"
   141  (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
   142 
   143 qed_goal "Image_singleton_iff" Relation.thy
   144     "(b : r^^{a}) = ((a,b):r)"
   145  (fn _ => [ rtac (Image_iff RS trans) 1,
   146             fast_tac comp_cs 1 ]);
   147 
   148 qed_goalw "ImageI" Relation.thy [Image_def]
   149     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   150  (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
   151             (resolve_tac [conjI ] 1),
   152             (rtac RangeI 1),
   153             (REPEAT (fast_tac set_cs 1))]);
   154 
   155 qed_goalw "ImageE" Relation.thy [Image_def]
   156     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   157  (fn major::prems=>
   158   [ (rtac (major RS CollectE) 1),
   159     (safe_tac set_cs),
   160     (etac RangeE 1),
   161     (rtac (hd prems) 1),
   162     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   163 
   164 qed_goal "Image_subset" Relation.thy
   165     "!!A B r. r <= A Times B ==> r^^C <= B"
   166  (fn _ =>
   167   [ (rtac subsetI 1),
   168     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   169 
   170 val rel_cs = converse_cs addSIs [converseI] 
   171                          addIs  [ImageI, DomainI, RangeI]
   172                          addSEs [ImageE, DomainE, RangeE];
   173 
   174 val rel_eq_cs = rel_cs addSIs [equalityI];
   175 
   176 goal Relation.thy "R O id = R";
   177 by(fast_tac (rel_cs addIs [set_ext] addbefore (split_all_tac 1)) 1);
   178 qed "R_O_id";
   179 
   180 goal Relation.thy "id O R = R";
   181 by(fast_tac (rel_cs addIs [set_ext] addbefore (split_all_tac 1)) 1);
   182 qed "id_O_R";
   183 
   184 Addsimps [R_O_id,id_O_R];