src/HOL/Relation.ML
author paulson
Fri Apr 04 11:18:52 1997 +0200 (1997-04-04)
changeset 2891 d8f254ad1ab9
parent 2637 e9b203f854ae
child 3413 c1f63cc3a768
permissions -rw-r--r--
Calls Blast_tac
     1 (*  Title:      Relation.ML
     2     ID:         $Id$
     3     Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 *)
     6 
     7 open Relation;
     8 
     9 (** Identity relation **)
    10 
    11 goalw Relation.thy [id_def] "(a,a) : id";  
    12 by (Blast_tac 1);
    13 qed "idI";
    14 
    15 val major::prems = goalw Relation.thy [id_def]
    16     "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
    17 \    |] ==>  P";  
    18 by (rtac (major RS CollectE) 1);
    19 by (etac exE 1);
    20 by (eresolve_tac prems 1);
    21 qed "idE";
    22 
    23 goalw Relation.thy [id_def] "(a,b):id = (a=b)";
    24 by (Blast_tac 1);
    25 qed "pair_in_id_conv";
    26 Addsimps [pair_in_id_conv];
    27 
    28 
    29 (** Composition of two relations **)
    30 
    31 goalw Relation.thy [comp_def]
    32     "!!r s. [| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
    33 by (Blast_tac 1);
    34 qed "compI";
    35 
    36 (*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    37 val prems = goalw Relation.thy [comp_def]
    38     "[| xz : r O s;  \
    39 \       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
    40 \    |] ==> P";
    41 by (cut_facts_tac prems 1);
    42 by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 
    43      ORELSE ares_tac prems 1));
    44 qed "compE";
    45 
    46 val prems = goal Relation.thy
    47     "[| (a,c) : r O s;  \
    48 \       !!y. [| (a,y):s;  (y,c):r |] ==> P \
    49 \    |] ==> P";
    50 by (rtac compE 1);
    51 by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
    52 qed "compEpair";
    53 
    54 AddIs [compI, idI];
    55 AddSEs [compE, idE];
    56 
    57 goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    58 by (Blast_tac 1);
    59 qed "comp_mono";
    60 
    61 goal Relation.thy
    62     "!!r s. [| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
    63 by (Blast_tac 1);
    64 qed "comp_subset_Sigma";
    65 
    66 (** Natural deduction for trans(r) **)
    67 
    68 val prems = goalw Relation.thy [trans_def]
    69     "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    70 by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    71 qed "transI";
    72 
    73 goalw Relation.thy [trans_def]
    74     "!!r. [| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    75 by (Blast_tac 1);
    76 qed "transD";
    77 
    78 (** Natural deduction for converse(r) **)
    79 
    80 goalw Relation.thy [converse_def] "!!a b r. ((a,b):converse r) = ((b,a):r)";
    81 by (Simp_tac 1);
    82 qed "converse_iff";
    83 
    84 AddIffs [converse_iff];
    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 (Blast_tac 1);
    92 qed "converseD";
    93 
    94 (*More general than converseD, as it "splits" the member of the relation*)
    95 qed_goalw "converseE" Relation.thy [converse_def]
    96     "[| yx : converse(r);  \
    97 \       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
    98 \    |] ==> P"
    99  (fn [major,minor]=>
   100   [ (rtac (major RS CollectE) 1),
   101     (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
   102     (assume_tac 1) ]);
   103 
   104 AddSEs [converseE];
   105 
   106 goalw Relation.thy [converse_def] "converse(converse R) = R";
   107 by (Blast_tac 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 _=> [ (Blast_tac 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 AddIs  [DomainI];
   126 AddSEs [DomainE];
   127 
   128 (** Range **)
   129 
   130 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   131  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   132 
   133 qed_goalw "RangeE" Relation.thy [Range_def]
   134     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   135  (fn major::prems=>
   136   [ (rtac (major RS DomainE) 1),
   137     (resolve_tac prems 1),
   138     (etac converseD 1) ]);
   139 
   140 AddIs  [RangeI];
   141 AddSEs [RangeE];
   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 _ => [ Blast_tac 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             Blast_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 _ => [ (Blast_tac 1)]);
   157 
   158 qed_goalw "ImageE" Relation.thy [Image_def]
   159     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   160  (fn major::prems=>
   161   [ (rtac (major RS CollectE) 1),
   162     (Step_tac 1),
   163     (rtac (hd prems) 1),
   164     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   165 
   166 AddIs  [ImageI];
   167 AddSEs [ImageE];
   168 
   169 qed_goal "Image_subset" Relation.thy
   170     "!!A B r. r <= A Times B ==> r^^C <= B"
   171  (fn _ =>
   172   [ (rtac subsetI 1),
   173     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   174 
   175 goal Relation.thy "R O id = R";
   176 by (fast_tac (!claset addbefore split_all_tac) 1);
   177 qed "R_O_id";
   178 
   179 goal Relation.thy "id O R = R";
   180 by (fast_tac (!claset addbefore split_all_tac) 1);
   181 qed "id_O_R";
   182 
   183 Addsimps [R_O_id,id_O_R];