src/HOL/Relation.ML
author berghofe
Thu May 23 15:15:20 1996 +0200 (1996-05-23)
changeset 1761 29e08d527ba1
parent 1754 852093aeb0ab
child 1786 8a31d85d27b8
permissions -rw-r--r--
Removed equalityI from some proofs (because it is now included
in the default claset)
     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 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 (!claset 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 AddIs [compI, idI];
    60 AddSEs [compE, idE];
    61 
    62 val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
    63 
    64 goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    65 by (Fast_tac 1);
    66 qed "comp_mono";
    67 
    68 goal Relation.thy
    69     "!!r s. [| s <= A Times B;  r <= B Times C |] ==> \
    70 \           (r O s) <= A Times C";
    71 by (Fast_tac 1);
    72 qed "comp_subset_Sigma";
    73 
    74 (** Natural deduction for trans(r) **)
    75 
    76 val prems = goalw Relation.thy [trans_def]
    77     "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    78 by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    79 qed "transI";
    80 
    81 val major::prems = goalw Relation.thy [trans_def]
    82     "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    83 by (cut_facts_tac [major] 1);
    84 by (fast_tac (!claset addIs prems) 1);
    85 qed "transD";
    86 
    87 (** Natural deduction for converse(r) **)
    88 
    89 goalw Relation.thy [converse_def] "!!a b r. (a,b):r ==> (b,a):converse(r)";
    90 by (Simp_tac 1);
    91 qed "converseI";
    92 
    93 goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
    94 by (Fast_tac 1);
    95 qed "converseD";
    96 
    97 qed_goalw "converseE" Relation.thy [converse_def]
    98     "[| yx : converse(r);  \
    99 \       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
   100 \    |] ==> P"
   101  (fn [major,minor]=>
   102   [ (rtac (major RS CollectE) 1),
   103     (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
   104     (assume_tac 1) ]);
   105 
   106 AddSIs [converseI];
   107 AddSEs [converseD,converseE];
   108 
   109 val converse_cs = comp_cs addSIs [converseI]
   110                           addSEs [converseD,converseE];
   111 
   112 goalw Relation.thy [converse_def] "converse(converse R) = R";
   113 by(Fast_tac 1);
   114 qed "converse_converse";
   115 
   116 (** Domain **)
   117 
   118 qed_goalw "Domain_iff" Relation.thy [Domain_def]
   119     "a: Domain(r) = (EX y. (a,y): r)"
   120  (fn _=> [ (Fast_tac 1) ]);
   121 
   122 qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   123  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   124 
   125 qed_goal "DomainE" Relation.thy
   126     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   127  (fn prems=>
   128   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   129     (REPEAT (ares_tac prems 1)) ]);
   130 
   131 (** Range **)
   132 
   133 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   134  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   135 
   136 qed_goalw "RangeE" Relation.thy [Range_def]
   137     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   138  (fn major::prems=>
   139   [ (rtac (major RS DomainE) 1),
   140     (resolve_tac prems 1),
   141     (etac converseD 1) ]);
   142 
   143 (*** Image of a set under a relation ***)
   144 
   145 qed_goalw "Image_iff" Relation.thy [Image_def]
   146     "b : r^^A = (? x:A. (x,b):r)"
   147  (fn _ => [ fast_tac (!claset addIs [RangeI]) 1 ]);
   148 
   149 qed_goal "Image_singleton_iff" Relation.thy
   150     "(b : r^^{a}) = ((a,b):r)"
   151  (fn _ => [ rtac (Image_iff RS trans) 1,
   152             Fast_tac 1 ]);
   153 
   154 qed_goalw "ImageI" Relation.thy [Image_def]
   155     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   156  (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
   157             (resolve_tac [conjI ] 1),
   158             (rtac RangeI 1),
   159             (REPEAT (Fast_tac 1))]);
   160 
   161 qed_goalw "ImageE" Relation.thy [Image_def]
   162     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   163  (fn major::prems=>
   164   [ (rtac (major RS CollectE) 1),
   165     (safe_tac set_cs),
   166     (etac RangeE 1),
   167     (rtac (hd prems) 1),
   168     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   169 
   170 qed_goal "Image_subset" Relation.thy
   171     "!!A B r. r <= A Times B ==> r^^C <= B"
   172  (fn _ =>
   173   [ (rtac subsetI 1),
   174     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   175 
   176 AddSIs [converseI]; 
   177 AddIs  [ImageI, DomainI, RangeI];
   178 AddSEs [ImageE, DomainE, RangeE];
   179 
   180 val rel_cs = converse_cs addSIs [converseI] 
   181                          addIs  [ImageI, DomainI, RangeI]
   182                          addSEs [ImageE, DomainE, RangeE];
   183 
   184 AddSIs [equalityI];
   185 
   186 val rel_eq_cs = rel_cs addSIs [equalityI];
   187 
   188 goal Relation.thy "R O id = R";
   189 by(fast_tac (!claset addIs [set_ext] addbefore (split_all_tac 1)) 1);
   190 qed "R_O_id";
   191 
   192 goal Relation.thy "id O R = R";
   193 by(fast_tac (!claset addIs [set_ext] addbefore (split_all_tac 1)) 1);
   194 qed "id_O_R";
   195 
   196 Addsimps [R_O_id,id_O_R];