src/HOL/Prod.ML
author paulson
Tue May 07 18:14:39 1996 +0200 (1996-05-07)
changeset 1727 7d0fbdc46e8e
parent 1655 5be64540f275
child 1746 f0c6aabc6c02
permissions -rw-r--r--
Now split_all_tac works for i>1 !
clasohm@1465
     1
(*  Title:      HOL/prod
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     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@1465
    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@1465
    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
nipkow@1301
    56
(* replace parameters of product type by individual component parameters *)
nipkow@1301
    57
local
nipkow@1301
    58
fun is_pair (_,Type("*",_)) = true
nipkow@1301
    59
  | is_pair _ = false;
nipkow@1301
    60
paulson@1727
    61
fun find_pair_param prem =
paulson@1727
    62
  let val params = Logic.strip_params prem
nipkow@1301
    63
  in if exists is_pair params
paulson@1727
    64
     then let val params = rev(rename_wrt_term prem params)
nipkow@1301
    65
                           (*as they are printed*)
nipkow@1301
    66
          in apsome fst (find_first is_pair params) end
nipkow@1301
    67
     else None
nipkow@1301
    68
  end;
nipkow@1301
    69
nipkow@1301
    70
in
nipkow@1301
    71
paulson@1727
    72
val split_all_tac = REPEAT o SUBGOAL (fn (prem,i) =>
paulson@1727
    73
  case find_pair_param prem of
nipkow@1301
    74
    None => no_tac
paulson@1727
    75
  | Some x => EVERY[res_inst_tac[("p",x)] PairE i,
paulson@1727
    76
                    REPEAT(hyp_subst_tac i), prune_params_tac]);
nipkow@1301
    77
nipkow@1301
    78
end;
nipkow@1301
    79
nipkow@1301
    80
goal Prod.thy "(!x. P x) = (!a b. P(a,b))";
paulson@1552
    81
by (fast_tac (HOL_cs addbefore split_all_tac 1) 1);
nipkow@1301
    82
qed "split_paired_All";
nipkow@1301
    83
clasohm@972
    84
goalw Prod.thy [split_def] "split c (a,b) = c a b";
nipkow@1485
    85
by (EVERY1[stac fst_conv, stac snd_conv]);
clasohm@923
    86
by (rtac refl 1);
clasohm@923
    87
qed "split";
clasohm@923
    88
nipkow@1301
    89
Addsimps [fst_conv, snd_conv, split_paired_All, split, Pair_eq];
clasohm@923
    90
clasohm@923
    91
goal Prod.thy "(s=t) = (fst(s)=fst(t) & snd(s)=snd(t))";
clasohm@923
    92
by (res_inst_tac[("p","s")] PairE 1);
clasohm@923
    93
by (res_inst_tac[("p","t")] PairE 1);
clasohm@1264
    94
by (Asm_simp_tac 1);
clasohm@923
    95
qed "Pair_fst_snd_eq";
clasohm@923
    96
clasohm@923
    97
(*Prevents simplification of c: much faster*)
clasohm@923
    98
qed_goal "split_weak_cong" Prod.thy
clasohm@923
    99
  "p=q ==> split c p = split c q"
clasohm@923
   100
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
clasohm@923
   101
clasohm@923
   102
(* Do not add as rewrite rule: invalidates some proofs in IMP *)
clasohm@972
   103
goal Prod.thy "p = (fst(p),snd(p))";
clasohm@923
   104
by (res_inst_tac [("p","p")] PairE 1);
clasohm@1264
   105
by (Asm_simp_tac 1);
clasohm@923
   106
qed "surjective_pairing";
clasohm@923
   107
clasohm@972
   108
goal Prod.thy "p = split (%x y.(x,y)) p";
clasohm@923
   109
by (res_inst_tac [("p","p")] PairE 1);
clasohm@1264
   110
by (Asm_simp_tac 1);
clasohm@923
   111
qed "surjective_pairing2";
clasohm@923
   112
nipkow@1655
   113
qed_goal "split_eta" Prod.thy "(%(x,y). f(x,y)) = f"
nipkow@1655
   114
  (fn _ => [rtac ext 1, split_all_tac 1, rtac split 1]);
nipkow@1655
   115
clasohm@923
   116
(*For use with split_tac and the simplifier*)
clasohm@972
   117
goal Prod.thy "R(split c p) = (! x y. p = (x,y) --> R(c x y))";
clasohm@923
   118
by (stac surjective_pairing 1);
clasohm@923
   119
by (stac split 1);
clasohm@923
   120
by (fast_tac (HOL_cs addSEs [Pair_inject]) 1);
clasohm@923
   121
qed "expand_split";
clasohm@923
   122
clasohm@923
   123
(** split used as a logical connective or set former **)
clasohm@923
   124
clasohm@923
   125
(*These rules are for use with fast_tac.
clasohm@923
   126
  Could instead call simp_tac/asm_full_simp_tac using split as rewrite.*)
clasohm@923
   127
nipkow@1454
   128
goal Prod.thy "!!p. [| !!a b. p=(a,b) ==> c a b |] ==> split c p";
paulson@1552
   129
by (split_all_tac 1);
nipkow@1454
   130
by (Asm_simp_tac 1);
nipkow@1454
   131
qed "splitI2";
nipkow@1454
   132
clasohm@972
   133
goal Prod.thy "!!a b c. c a b ==> split c (a,b)";
clasohm@1264
   134
by (Asm_simp_tac 1);
clasohm@923
   135
qed "splitI";
clasohm@923
   136
clasohm@923
   137
val prems = goalw Prod.thy [split_def]
clasohm@972
   138
    "[| split c p;  !!x y. [| p = (x,y);  c x y |] ==> Q |] ==> Q";
clasohm@923
   139
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
clasohm@923
   140
qed "splitE";
clasohm@923
   141
clasohm@972
   142
goal Prod.thy "!!R a b. split R (a,b) ==> R a b";
clasohm@923
   143
by (etac (split RS iffD1) 1);
clasohm@923
   144
qed "splitD";
clasohm@923
   145
clasohm@972
   146
goal Prod.thy "!!a b c. z: c a b ==> z: split c (a,b)";
clasohm@1264
   147
by (Asm_simp_tac 1);
clasohm@923
   148
qed "mem_splitI";
clasohm@923
   149
nipkow@1454
   150
goal Prod.thy "!!p. [| !!a b. p=(a,b) ==> z: c a b |] ==> z: split c p";
paulson@1552
   151
by (split_all_tac 1);
nipkow@1454
   152
by (Asm_simp_tac 1);
nipkow@1454
   153
qed "mem_splitI2";
nipkow@1454
   154
clasohm@923
   155
val prems = goalw Prod.thy [split_def]
clasohm@972
   156
    "[| z: split c p;  !!x y. [| p = (x,y);  z: c x y |] ==> Q |] ==> Q";
clasohm@923
   157
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
clasohm@923
   158
qed "mem_splitE";
clasohm@923
   159
clasohm@923
   160
(*** prod_fun -- action of the product functor upon functions ***)
clasohm@923
   161
clasohm@972
   162
goalw Prod.thy [prod_fun_def] "prod_fun f g (a,b) = (f(a),g(b))";
clasohm@923
   163
by (rtac split 1);
clasohm@923
   164
qed "prod_fun";
clasohm@923
   165
clasohm@923
   166
goal Prod.thy 
clasohm@923
   167
    "prod_fun (f1 o f2) (g1 o g2) = ((prod_fun f1 g1) o (prod_fun f2 g2))";
clasohm@923
   168
by (rtac ext 1);
clasohm@923
   169
by (res_inst_tac [("p","x")] PairE 1);
clasohm@1264
   170
by (asm_simp_tac (!simpset addsimps [prod_fun,o_def]) 1);
clasohm@923
   171
qed "prod_fun_compose";
clasohm@923
   172
clasohm@923
   173
goal Prod.thy "prod_fun (%x.x) (%y.y) = (%z.z)";
clasohm@923
   174
by (rtac ext 1);
clasohm@923
   175
by (res_inst_tac [("p","z")] PairE 1);
clasohm@1264
   176
by (asm_simp_tac (!simpset addsimps [prod_fun]) 1);
clasohm@923
   177
qed "prod_fun_ident";
clasohm@923
   178
clasohm@972
   179
val prems = goal Prod.thy "(a,b):r ==> (f(a),g(b)) : (prod_fun f g)``r";
clasohm@923
   180
by (rtac image_eqI 1);
clasohm@923
   181
by (rtac (prod_fun RS sym) 1);
clasohm@923
   182
by (resolve_tac prems 1);
clasohm@923
   183
qed "prod_fun_imageI";
clasohm@923
   184
clasohm@923
   185
val major::prems = goal Prod.thy
clasohm@972
   186
    "[| c: (prod_fun f g)``r;  !!x y. [| c=(f(x),g(y));  (x,y):r |] ==> P  \
clasohm@923
   187
\    |] ==> P";
clasohm@923
   188
by (rtac (major RS imageE) 1);
clasohm@923
   189
by (res_inst_tac [("p","x")] PairE 1);
clasohm@923
   190
by (resolve_tac prems 1);
clasohm@923
   191
by (fast_tac HOL_cs 2);
clasohm@923
   192
by (fast_tac (HOL_cs addIs [prod_fun]) 1);
clasohm@923
   193
qed "prod_fun_imageE";
clasohm@923
   194
clasohm@923
   195
(*** Disjoint union of a family of sets - Sigma ***)
clasohm@923
   196
clasohm@923
   197
qed_goalw "SigmaI" Prod.thy [Sigma_def]
clasohm@972
   198
    "[| a:A;  b:B(a) |] ==> (a,b) : Sigma A B"
clasohm@923
   199
 (fn prems=> [ (REPEAT (resolve_tac (prems@[singletonI,UN_I]) 1)) ]);
clasohm@923
   200
clasohm@923
   201
(*The general elimination rule*)
clasohm@923
   202
qed_goalw "SigmaE" Prod.thy [Sigma_def]
clasohm@923
   203
    "[| c: Sigma A B;  \
clasohm@972
   204
\       !!x y.[| x:A;  y:B(x);  c=(x,y) |] ==> P \
clasohm@923
   205
\    |] ==> P"
clasohm@923
   206
 (fn major::prems=>
clasohm@923
   207
  [ (cut_facts_tac [major] 1),
clasohm@923
   208
    (REPEAT (eresolve_tac [UN_E, singletonE] 1 ORELSE ares_tac prems 1)) ]);
clasohm@923
   209
clasohm@972
   210
(** Elimination of (a,b):A*B -- introduces no eigenvariables **)
clasohm@972
   211
qed_goal "SigmaD1" Prod.thy "(a,b) : Sigma A B ==> a : A"
clasohm@923
   212
 (fn [major]=>
clasohm@923
   213
  [ (rtac (major RS SigmaE) 1),
clasohm@923
   214
    (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]);
clasohm@923
   215
clasohm@972
   216
qed_goal "SigmaD2" Prod.thy "(a,b) : Sigma A B ==> b : B(a)"
clasohm@923
   217
 (fn [major]=>
clasohm@923
   218
  [ (rtac (major RS SigmaE) 1),
clasohm@923
   219
    (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]);
clasohm@923
   220
clasohm@923
   221
qed_goal "SigmaE2" Prod.thy
clasohm@972
   222
    "[| (a,b) : Sigma A B;    \
clasohm@923
   223
\       [| a:A;  b:B(a) |] ==> P   \
clasohm@923
   224
\    |] ==> P"
clasohm@923
   225
 (fn [major,minor]=>
clasohm@923
   226
  [ (rtac minor 1),
clasohm@923
   227
    (rtac (major RS SigmaD1) 1),
clasohm@923
   228
    (rtac (major RS SigmaD2) 1) ]);
clasohm@923
   229
nipkow@1515
   230
val prems = goal Prod.thy
paulson@1642
   231
    "[| A<=C;  !!x. x:A ==> B x <= D x |] ==> Sigma A B <= Sigma C D";
nipkow@1515
   232
by (cut_facts_tac prems 1);
nipkow@1515
   233
by (fast_tac (set_cs addIs (prems RL [subsetD]) 
nipkow@1515
   234
                     addSIs [SigmaI] 
nipkow@1515
   235
                     addSEs [SigmaE]) 1);
nipkow@1515
   236
qed "Sigma_mono";
nipkow@1515
   237
paulson@1618
   238
qed_goal "Sigma_empty1" Prod.thy "Sigma {} B = {}"
paulson@1618
   239
 (fn _ => [ (fast_tac (eq_cs addSEs [SigmaE]) 1) ]);
paulson@1618
   240
paulson@1642
   241
qed_goal "Sigma_empty2" Prod.thy "A Times {} = {}"
paulson@1618
   242
 (fn _ => [ (fast_tac (eq_cs addSEs [SigmaE]) 1) ]);
paulson@1618
   243
paulson@1618
   244
Addsimps [Sigma_empty1,Sigma_empty2]; 
paulson@1618
   245
paulson@1618
   246
goal Prod.thy "((a,b): Sigma A B) = (a:A & b:B(a))";
paulson@1618
   247
by (fast_tac (eq_cs addSIs [SigmaI] addSEs [SigmaE, Pair_inject]) 1);
paulson@1618
   248
qed "mem_Sigma_iff";
paulson@1618
   249
Addsimps [mem_Sigma_iff]; 
paulson@1618
   250
nipkow@1515
   251
clasohm@923
   252
(*** Domain of a relation ***)
clasohm@923
   253
clasohm@972
   254
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> a : fst``r";
clasohm@923
   255
by (rtac CollectI 1);
clasohm@923
   256
by (rtac bexI 1);
clasohm@923
   257
by (rtac (fst_conv RS sym) 1);
clasohm@923
   258
by (resolve_tac prems 1);
clasohm@923
   259
qed "fst_imageI";
clasohm@923
   260
clasohm@923
   261
val major::prems = goal Prod.thy
clasohm@972
   262
    "[| a : fst``r;  !!y.[| (a,y) : r |] ==> P |] ==> P"; 
clasohm@923
   263
by (rtac (major RS imageE) 1);
clasohm@923
   264
by (resolve_tac prems 1);
clasohm@923
   265
by (etac ssubst 1);
clasohm@923
   266
by (rtac (surjective_pairing RS subst) 1);
clasohm@923
   267
by (assume_tac 1);
clasohm@923
   268
qed "fst_imageE";
clasohm@923
   269
clasohm@923
   270
(*** Range of a relation ***)
clasohm@923
   271
clasohm@972
   272
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> b : snd``r";
clasohm@923
   273
by (rtac CollectI 1);
clasohm@923
   274
by (rtac bexI 1);
clasohm@923
   275
by (rtac (snd_conv RS sym) 1);
clasohm@923
   276
by (resolve_tac prems 1);
clasohm@923
   277
qed "snd_imageI";
clasohm@923
   278
clasohm@923
   279
val major::prems = goal Prod.thy
clasohm@972
   280
    "[| a : snd``r;  !!y.[| (y,a) : r |] ==> P |] ==> P"; 
clasohm@923
   281
by (rtac (major RS imageE) 1);
clasohm@923
   282
by (resolve_tac prems 1);
clasohm@923
   283
by (etac ssubst 1);
clasohm@923
   284
by (rtac (surjective_pairing RS subst) 1);
clasohm@923
   285
by (assume_tac 1);
clasohm@923
   286
qed "snd_imageE";
clasohm@923
   287
clasohm@923
   288
(** Exhaustion rule for unit -- a degenerate form of induction **)
clasohm@923
   289
clasohm@923
   290
goalw Prod.thy [Unity_def]
clasohm@972
   291
    "u = ()";
clasohm@923
   292
by (stac (rewrite_rule [Unit_def] Rep_Unit RS CollectD RS sym) 1);
clasohm@923
   293
by (rtac (Rep_Unit_inverse RS sym) 1);
clasohm@923
   294
qed "unit_eq";
clasohm@923
   295
nipkow@1454
   296
val prod_cs = set_cs addSIs [SigmaI, splitI, splitI2, mem_splitI, mem_splitI2] 
clasohm@923
   297
                     addIs  [fst_imageI, snd_imageI, prod_fun_imageI]
nipkow@1454
   298
                     addSEs [SigmaE2, SigmaE, splitE, mem_splitE, 
clasohm@1465
   299
                             fst_imageE, snd_imageE, prod_fun_imageE,
clasohm@1465
   300
                             Pair_inject];