src/HOL/Prod.ML
author clasohm
Wed Oct 04 13:10:03 1995 +0100 (1995-10-04)
changeset 1264 3eb91524b938
parent 972 e61b058d58d2
child 1301 42782316d510
permissions -rw-r--r--
added local simpsets; removed IOA from 'make test'
clasohm@923
     1
(*  Title: 	HOL/prod
clasohm@923
     2
    ID:         $Id$
clasohm@923
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1991  University of Cambridge
clasohm@923
     5
clasohm@923
     6
For prod.thy.  Ordered Pairs, the Cartesian product type, the unit type
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
open Prod;
clasohm@923
    10
clasohm@923
    11
(*This counts as a non-emptiness result for admitting 'a * 'b as a type*)
clasohm@923
    12
goalw Prod.thy [Prod_def] "Pair_Rep a b : Prod";
clasohm@923
    13
by (EVERY1 [rtac CollectI, rtac exI, rtac exI, rtac refl]);
clasohm@923
    14
qed "ProdI";
clasohm@923
    15
clasohm@923
    16
val [major] = goalw Prod.thy [Pair_Rep_def]
clasohm@923
    17
    "Pair_Rep a b = Pair_Rep a' b' ==> a=a' & b=b'";
clasohm@923
    18
by (EVERY1 [rtac (major RS fun_cong RS fun_cong RS subst), 
clasohm@923
    19
	    rtac conjI, rtac refl, rtac refl]);
clasohm@923
    20
qed "Pair_Rep_inject";
clasohm@923
    21
clasohm@923
    22
goal Prod.thy "inj_onto Abs_Prod Prod";
clasohm@923
    23
by (rtac inj_onto_inverseI 1);
clasohm@923
    24
by (etac Abs_Prod_inverse 1);
clasohm@923
    25
qed "inj_onto_Abs_Prod";
clasohm@923
    26
clasohm@923
    27
val prems = goalw Prod.thy [Pair_def]
clasohm@972
    28
    "[| (a, b) = (a',b');  [| a=a';  b=b' |] ==> R |] ==> R";
clasohm@923
    29
by (rtac (inj_onto_Abs_Prod RS inj_ontoD RS Pair_Rep_inject RS conjE) 1);
clasohm@923
    30
by (REPEAT (ares_tac (prems@[ProdI]) 1));
clasohm@923
    31
qed "Pair_inject";
clasohm@923
    32
clasohm@972
    33
goal Prod.thy "((a,b) = (a',b')) = (a=a' & b=b')";
clasohm@923
    34
by (fast_tac (set_cs addIs [Pair_inject]) 1);
clasohm@923
    35
qed "Pair_eq";
clasohm@923
    36
clasohm@972
    37
goalw Prod.thy [fst_def] "fst((a,b)) = a";
clasohm@923
    38
by (fast_tac (set_cs addIs [select_equality] addSEs [Pair_inject]) 1);
clasohm@923
    39
qed "fst_conv";
clasohm@923
    40
clasohm@972
    41
goalw Prod.thy [snd_def] "snd((a,b)) = b";
clasohm@923
    42
by (fast_tac (set_cs addIs [select_equality] addSEs [Pair_inject]) 1);
clasohm@923
    43
qed "snd_conv";
clasohm@923
    44
clasohm@972
    45
goalw Prod.thy [Pair_def] "? x y. p = (x,y)";
clasohm@923
    46
by (rtac (rewrite_rule [Prod_def] Rep_Prod RS CollectE) 1);
clasohm@923
    47
by (EVERY1[etac exE, etac exE, rtac exI, rtac exI,
clasohm@923
    48
	   rtac (Rep_Prod_inverse RS sym RS trans),  etac arg_cong]);
clasohm@923
    49
qed "PairE_lemma";
clasohm@923
    50
clasohm@972
    51
val [prem] = goal Prod.thy "[| !!x y. p = (x,y) ==> Q |] ==> Q";
clasohm@923
    52
by (rtac (PairE_lemma RS exE) 1);
clasohm@923
    53
by (REPEAT (eresolve_tac [prem,exE] 1));
clasohm@923
    54
qed "PairE";
clasohm@923
    55
clasohm@972
    56
goalw Prod.thy [split_def] "split c (a,b) = c a b";
clasohm@923
    57
by (sstac [fst_conv, snd_conv] 1);
clasohm@923
    58
by (rtac refl 1);
clasohm@923
    59
qed "split";
clasohm@923
    60
clasohm@1264
    61
Addsimps [fst_conv, snd_conv, split, Pair_eq];
clasohm@923
    62
clasohm@923
    63
goal Prod.thy "(s=t) = (fst(s)=fst(t) & snd(s)=snd(t))";
clasohm@923
    64
by (res_inst_tac[("p","s")] PairE 1);
clasohm@923
    65
by (res_inst_tac[("p","t")] PairE 1);
clasohm@1264
    66
by (Asm_simp_tac 1);
clasohm@923
    67
qed "Pair_fst_snd_eq";
clasohm@923
    68
clasohm@923
    69
(*Prevents simplification of c: much faster*)
clasohm@923
    70
qed_goal "split_weak_cong" Prod.thy
clasohm@923
    71
  "p=q ==> split c p = split c q"
clasohm@923
    72
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
clasohm@923
    73
clasohm@923
    74
(* Do not add as rewrite rule: invalidates some proofs in IMP *)
clasohm@972
    75
goal Prod.thy "p = (fst(p),snd(p))";
clasohm@923
    76
by (res_inst_tac [("p","p")] PairE 1);
clasohm@1264
    77
by (Asm_simp_tac 1);
clasohm@923
    78
qed "surjective_pairing";
clasohm@923
    79
clasohm@972
    80
goal Prod.thy "p = split (%x y.(x,y)) p";
clasohm@923
    81
by (res_inst_tac [("p","p")] PairE 1);
clasohm@1264
    82
by (Asm_simp_tac 1);
clasohm@923
    83
qed "surjective_pairing2";
clasohm@923
    84
clasohm@923
    85
(*For use with split_tac and the simplifier*)
clasohm@972
    86
goal Prod.thy "R(split c p) = (! x y. p = (x,y) --> R(c x y))";
clasohm@923
    87
by (stac surjective_pairing 1);
clasohm@923
    88
by (stac split 1);
clasohm@923
    89
by (fast_tac (HOL_cs addSEs [Pair_inject]) 1);
clasohm@923
    90
qed "expand_split";
clasohm@923
    91
clasohm@923
    92
(** split used as a logical connective or set former **)
clasohm@923
    93
clasohm@923
    94
(*These rules are for use with fast_tac.
clasohm@923
    95
  Could instead call simp_tac/asm_full_simp_tac using split as rewrite.*)
clasohm@923
    96
clasohm@972
    97
goal Prod.thy "!!a b c. c a b ==> split c (a,b)";
clasohm@1264
    98
by (Asm_simp_tac 1);
clasohm@923
    99
qed "splitI";
clasohm@923
   100
clasohm@923
   101
val prems = goalw Prod.thy [split_def]
clasohm@972
   102
    "[| split c p;  !!x y. [| p = (x,y);  c x y |] ==> Q |] ==> Q";
clasohm@923
   103
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
clasohm@923
   104
qed "splitE";
clasohm@923
   105
clasohm@972
   106
goal Prod.thy "!!R a b. split R (a,b) ==> R a b";
clasohm@923
   107
by (etac (split RS iffD1) 1);
clasohm@923
   108
qed "splitD";
clasohm@923
   109
clasohm@972
   110
goal Prod.thy "!!a b c. z: c a b ==> z: split c (a,b)";
clasohm@1264
   111
by (Asm_simp_tac 1);
clasohm@923
   112
qed "mem_splitI";
clasohm@923
   113
clasohm@923
   114
val prems = goalw Prod.thy [split_def]
clasohm@972
   115
    "[| z: split c p;  !!x y. [| p = (x,y);  z: c x y |] ==> Q |] ==> Q";
clasohm@923
   116
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
clasohm@923
   117
qed "mem_splitE";
clasohm@923
   118
clasohm@923
   119
(*** prod_fun -- action of the product functor upon functions ***)
clasohm@923
   120
clasohm@972
   121
goalw Prod.thy [prod_fun_def] "prod_fun f g (a,b) = (f(a),g(b))";
clasohm@923
   122
by (rtac split 1);
clasohm@923
   123
qed "prod_fun";
clasohm@923
   124
clasohm@923
   125
goal Prod.thy 
clasohm@923
   126
    "prod_fun (f1 o f2) (g1 o g2) = ((prod_fun f1 g1) o (prod_fun f2 g2))";
clasohm@923
   127
by (rtac ext 1);
clasohm@923
   128
by (res_inst_tac [("p","x")] PairE 1);
clasohm@1264
   129
by (asm_simp_tac (!simpset addsimps [prod_fun,o_def]) 1);
clasohm@923
   130
qed "prod_fun_compose";
clasohm@923
   131
clasohm@923
   132
goal Prod.thy "prod_fun (%x.x) (%y.y) = (%z.z)";
clasohm@923
   133
by (rtac ext 1);
clasohm@923
   134
by (res_inst_tac [("p","z")] PairE 1);
clasohm@1264
   135
by (asm_simp_tac (!simpset addsimps [prod_fun]) 1);
clasohm@923
   136
qed "prod_fun_ident";
clasohm@923
   137
clasohm@972
   138
val prems = goal Prod.thy "(a,b):r ==> (f(a),g(b)) : (prod_fun f g)``r";
clasohm@923
   139
by (rtac image_eqI 1);
clasohm@923
   140
by (rtac (prod_fun RS sym) 1);
clasohm@923
   141
by (resolve_tac prems 1);
clasohm@923
   142
qed "prod_fun_imageI";
clasohm@923
   143
clasohm@923
   144
val major::prems = goal Prod.thy
clasohm@972
   145
    "[| c: (prod_fun f g)``r;  !!x y. [| c=(f(x),g(y));  (x,y):r |] ==> P  \
clasohm@923
   146
\    |] ==> P";
clasohm@923
   147
by (rtac (major RS imageE) 1);
clasohm@923
   148
by (res_inst_tac [("p","x")] PairE 1);
clasohm@923
   149
by (resolve_tac prems 1);
clasohm@923
   150
by (fast_tac HOL_cs 2);
clasohm@923
   151
by (fast_tac (HOL_cs addIs [prod_fun]) 1);
clasohm@923
   152
qed "prod_fun_imageE";
clasohm@923
   153
clasohm@923
   154
(*** Disjoint union of a family of sets - Sigma ***)
clasohm@923
   155
clasohm@923
   156
qed_goalw "SigmaI" Prod.thy [Sigma_def]
clasohm@972
   157
    "[| a:A;  b:B(a) |] ==> (a,b) : Sigma A B"
clasohm@923
   158
 (fn prems=> [ (REPEAT (resolve_tac (prems@[singletonI,UN_I]) 1)) ]);
clasohm@923
   159
clasohm@923
   160
(*The general elimination rule*)
clasohm@923
   161
qed_goalw "SigmaE" Prod.thy [Sigma_def]
clasohm@923
   162
    "[| c: Sigma A B;  \
clasohm@972
   163
\       !!x y.[| x:A;  y:B(x);  c=(x,y) |] ==> P \
clasohm@923
   164
\    |] ==> P"
clasohm@923
   165
 (fn major::prems=>
clasohm@923
   166
  [ (cut_facts_tac [major] 1),
clasohm@923
   167
    (REPEAT (eresolve_tac [UN_E, singletonE] 1 ORELSE ares_tac prems 1)) ]);
clasohm@923
   168
clasohm@972
   169
(** Elimination of (a,b):A*B -- introduces no eigenvariables **)
clasohm@972
   170
qed_goal "SigmaD1" Prod.thy "(a,b) : Sigma A B ==> a : A"
clasohm@923
   171
 (fn [major]=>
clasohm@923
   172
  [ (rtac (major RS SigmaE) 1),
clasohm@923
   173
    (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]);
clasohm@923
   174
clasohm@972
   175
qed_goal "SigmaD2" Prod.thy "(a,b) : Sigma A B ==> b : B(a)"
clasohm@923
   176
 (fn [major]=>
clasohm@923
   177
  [ (rtac (major RS SigmaE) 1),
clasohm@923
   178
    (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]);
clasohm@923
   179
clasohm@923
   180
qed_goal "SigmaE2" Prod.thy
clasohm@972
   181
    "[| (a,b) : Sigma A B;    \
clasohm@923
   182
\       [| a:A;  b:B(a) |] ==> P   \
clasohm@923
   183
\    |] ==> P"
clasohm@923
   184
 (fn [major,minor]=>
clasohm@923
   185
  [ (rtac minor 1),
clasohm@923
   186
    (rtac (major RS SigmaD1) 1),
clasohm@923
   187
    (rtac (major RS SigmaD2) 1) ]);
clasohm@923
   188
clasohm@923
   189
(*** Domain of a relation ***)
clasohm@923
   190
clasohm@972
   191
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> a : fst``r";
clasohm@923
   192
by (rtac CollectI 1);
clasohm@923
   193
by (rtac bexI 1);
clasohm@923
   194
by (rtac (fst_conv RS sym) 1);
clasohm@923
   195
by (resolve_tac prems 1);
clasohm@923
   196
qed "fst_imageI";
clasohm@923
   197
clasohm@923
   198
val major::prems = goal Prod.thy
clasohm@972
   199
    "[| a : fst``r;  !!y.[| (a,y) : r |] ==> P |] ==> P"; 
clasohm@923
   200
by (rtac (major RS imageE) 1);
clasohm@923
   201
by (resolve_tac prems 1);
clasohm@923
   202
by (etac ssubst 1);
clasohm@923
   203
by (rtac (surjective_pairing RS subst) 1);
clasohm@923
   204
by (assume_tac 1);
clasohm@923
   205
qed "fst_imageE";
clasohm@923
   206
clasohm@923
   207
(*** Range of a relation ***)
clasohm@923
   208
clasohm@972
   209
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> b : snd``r";
clasohm@923
   210
by (rtac CollectI 1);
clasohm@923
   211
by (rtac bexI 1);
clasohm@923
   212
by (rtac (snd_conv RS sym) 1);
clasohm@923
   213
by (resolve_tac prems 1);
clasohm@923
   214
qed "snd_imageI";
clasohm@923
   215
clasohm@923
   216
val major::prems = goal Prod.thy
clasohm@972
   217
    "[| a : snd``r;  !!y.[| (y,a) : r |] ==> P |] ==> P"; 
clasohm@923
   218
by (rtac (major RS imageE) 1);
clasohm@923
   219
by (resolve_tac prems 1);
clasohm@923
   220
by (etac ssubst 1);
clasohm@923
   221
by (rtac (surjective_pairing RS subst) 1);
clasohm@923
   222
by (assume_tac 1);
clasohm@923
   223
qed "snd_imageE";
clasohm@923
   224
clasohm@923
   225
(** Exhaustion rule for unit -- a degenerate form of induction **)
clasohm@923
   226
clasohm@923
   227
goalw Prod.thy [Unity_def]
clasohm@972
   228
    "u = ()";
clasohm@923
   229
by (stac (rewrite_rule [Unit_def] Rep_Unit RS CollectD RS sym) 1);
clasohm@923
   230
by (rtac (Rep_Unit_inverse RS sym) 1);
clasohm@923
   231
qed "unit_eq";
clasohm@923
   232
clasohm@923
   233
val prod_cs = set_cs addSIs [SigmaI, mem_splitI] 
clasohm@923
   234
                     addIs  [fst_imageI, snd_imageI, prod_fun_imageI]
clasohm@923
   235
                     addSEs [SigmaE2, SigmaE, mem_splitE, 
clasohm@923
   236
			     fst_imageE, snd_imageE, prod_fun_imageE,
clasohm@923
   237
			     Pair_inject];