src/HOL/Product_Type.thy
author paulson
Fri Sep 26 10:34:57 2003 +0200 (2003-09-26)
changeset 14208 144f45277d5a
parent 14190 609c072edf90
child 14337 e13731554e50
permissions -rw-r--r--
misc tidying
     1 (*  Title:      HOL/Product_Type.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1992  University of Cambridge
     5 *)
     6 
     7 header {* Cartesian products *}
     8 
     9 theory Product_Type = Fun
    10 files ("Tools/split_rule.ML"):
    11 
    12 subsection {* Unit *}
    13 
    14 typedef unit = "{True}"
    15 proof
    16   show "True : ?unit" by blast
    17 qed
    18 
    19 constdefs
    20   Unity :: unit    ("'(')")
    21   "() == Abs_unit True"
    22 
    23 lemma unit_eq: "u = ()"
    24   by (induct u) (simp add: unit_def Unity_def)
    25 
    26 text {*
    27   Simplification procedure for @{thm [source] unit_eq}.  Cannot use
    28   this rule directly --- it loops!
    29 *}
    30 
    31 ML_setup {*
    32   val unit_eq_proc =
    33     let val unit_meta_eq = mk_meta_eq (thm "unit_eq") in
    34       Simplifier.simproc (Theory.sign_of (the_context ())) "unit_eq" ["x::unit"]
    35       (fn _ => fn _ => fn t => if HOLogic.is_unit t then None else Some unit_meta_eq)
    36     end;
    37 
    38   Addsimprocs [unit_eq_proc];
    39 *}
    40 
    41 lemma unit_all_eq1: "(!!x::unit. PROP P x) == PROP P ()"
    42   by simp
    43 
    44 lemma unit_all_eq2: "(!!x::unit. PROP P) == PROP P"
    45   by (rule triv_forall_equality)
    46 
    47 lemma unit_induct [induct type: unit]: "P () ==> P x"
    48   by simp
    49 
    50 text {*
    51   This rewrite counters the effect of @{text unit_eq_proc} on @{term
    52   [source] "%u::unit. f u"}, replacing it by @{term [source]
    53   f} rather than by @{term [source] "%u. f ()"}.
    54 *}
    55 
    56 lemma unit_abs_eta_conv [simp]: "(%u::unit. f ()) = f"
    57   by (rule ext) simp
    58 
    59 
    60 subsection {* Pairs *}
    61 
    62 subsubsection {* Type definition *}
    63 
    64 constdefs
    65   Pair_Rep :: "['a, 'b] => ['a, 'b] => bool"
    66   "Pair_Rep == (%a b. %x y. x=a & y=b)"
    67 
    68 global
    69 
    70 typedef (Prod)
    71   ('a, 'b) "*"    (infixr 20)
    72     = "{f. EX a b. f = Pair_Rep (a::'a) (b::'b)}"
    73 proof
    74   fix a b show "Pair_Rep a b : ?Prod"
    75     by blast
    76 qed
    77 
    78 syntax (xsymbols)
    79   "*"      :: "[type, type] => type"         ("(_ \<times>/ _)" [21, 20] 20)
    80 syntax (HTML output)
    81   "*"      :: "[type, type] => type"         ("(_ \<times>/ _)" [21, 20] 20)
    82 
    83 local
    84 
    85 
    86 subsubsection {* Abstract constants and syntax *}
    87 
    88 global
    89 
    90 consts
    91   fst      :: "'a * 'b => 'a"
    92   snd      :: "'a * 'b => 'b"
    93   split    :: "[['a, 'b] => 'c, 'a * 'b] => 'c"
    94   curry    :: "['a * 'b => 'c, 'a, 'b] => 'c"
    95   prod_fun :: "['a => 'b, 'c => 'd, 'a * 'c] => 'b * 'd"
    96   Pair     :: "['a, 'b] => 'a * 'b"
    97   Sigma    :: "['a set, 'a => 'b set] => ('a * 'b) set"
    98 
    99 local
   100 
   101 text {*
   102   Patterns -- extends pre-defined type @{typ pttrn} used in
   103   abstractions.
   104 *}
   105 
   106 nonterminals
   107   tuple_args patterns
   108 
   109 syntax
   110   "_tuple"      :: "'a => tuple_args => 'a * 'b"        ("(1'(_,/ _'))")
   111   "_tuple_arg"  :: "'a => tuple_args"                   ("_")
   112   "_tuple_args" :: "'a => tuple_args => tuple_args"     ("_,/ _")
   113   "_pattern"    :: "[pttrn, patterns] => pttrn"         ("'(_,/ _')")
   114   ""            :: "pttrn => patterns"                  ("_")
   115   "_patterns"   :: "[pttrn, patterns] => patterns"      ("_,/ _")
   116   "@Sigma" ::"[pttrn, 'a set, 'b set] => ('a * 'b) set" ("(3SIGMA _:_./ _)" 10)
   117   "@Times" ::"['a set,  'a => 'b set] => ('a * 'b) set" (infixr "<*>" 80)
   118 
   119 translations
   120   "(x, y)"       == "Pair x y"
   121   "_tuple x (_tuple_args y z)" == "_tuple x (_tuple_arg (_tuple y z))"
   122   "%(x,y,zs).b"  == "split(%x (y,zs).b)"
   123   "%(x,y).b"     == "split(%x y. b)"
   124   "_abs (Pair x y) t" => "%(x,y).t"
   125   (* The last rule accommodates tuples in `case C ... (x,y) ... => ...'
   126      The (x,y) is parsed as `Pair x y' because it is logic, not pttrn *)
   127 
   128   "SIGMA x:A. B" => "Sigma A (%x. B)"
   129   "A <*> B"      => "Sigma A (_K B)"
   130 
   131 syntax (xsymbols)
   132   "@Sigma" :: "[pttrn, 'a set, 'b set] => ('a * 'b) set"  ("(3\<Sigma> _\<in>_./ _)"   10)
   133   "@Times" :: "['a set,  'a => 'b set] => ('a * 'b) set"  ("_ \<times> _" [81, 80] 80)
   134 
   135 print_translation {* [("Sigma", dependent_tr' ("@Sigma", "@Times"))] *}
   136 
   137 
   138 subsubsection {* Definitions *}
   139 
   140 defs
   141   Pair_def:     "Pair a b == Abs_Prod(Pair_Rep a b)"
   142   fst_def:      "fst p == THE a. EX b. p = (a, b)"
   143   snd_def:      "snd p == THE b. EX a. p = (a, b)"
   144   split_def:    "split == (%c p. c (fst p) (snd p))"
   145   curry_def:    "curry == (%c x y. c (x,y))"
   146   prod_fun_def: "prod_fun f g == split(%x y.(f(x), g(y)))"
   147   Sigma_def:    "Sigma A B == UN x:A. UN y:B(x). {(x, y)}"
   148 
   149 
   150 subsubsection {* Lemmas and proof tool setup *}
   151 
   152 lemma ProdI: "Pair_Rep a b : Prod"
   153   by (unfold Prod_def) blast
   154 
   155 lemma Pair_Rep_inject: "Pair_Rep a b = Pair_Rep a' b' ==> a = a' & b = b'"
   156   apply (unfold Pair_Rep_def)
   157   apply (drule fun_cong [THEN fun_cong], blast)
   158   done
   159 
   160 lemma inj_on_Abs_Prod: "inj_on Abs_Prod Prod"
   161   apply (rule inj_on_inverseI)
   162   apply (erule Abs_Prod_inverse)
   163   done
   164 
   165 lemma Pair_inject:
   166   "(a, b) = (a', b') ==> (a = a' ==> b = b' ==> R) ==> R"
   167 proof -
   168   case rule_context [unfolded Pair_def]
   169   show ?thesis
   170     apply (rule inj_on_Abs_Prod [THEN inj_onD, THEN Pair_Rep_inject, THEN conjE])
   171     apply (rule rule_context ProdI)+
   172     .
   173 qed
   174 
   175 lemma Pair_eq [iff]: "((a, b) = (a', b')) = (a = a' & b = b')"
   176   by (blast elim!: Pair_inject)
   177 
   178 lemma fst_conv [simp]: "fst (a, b) = a"
   179   by (unfold fst_def) blast
   180 
   181 lemma snd_conv [simp]: "snd (a, b) = b"
   182   by (unfold snd_def) blast
   183 
   184 lemma fst_eqD: "fst (x, y) = a ==> x = a"
   185   by simp
   186 
   187 lemma snd_eqD: "snd (x, y) = a ==> y = a"
   188   by simp
   189 
   190 lemma PairE_lemma: "EX x y. p = (x, y)"
   191   apply (unfold Pair_def)
   192   apply (rule Rep_Prod [unfolded Prod_def, THEN CollectE])
   193   apply (erule exE, erule exE, rule exI, rule exI)
   194   apply (rule Rep_Prod_inverse [symmetric, THEN trans])
   195   apply (erule arg_cong)
   196   done
   197 
   198 lemma PairE [cases type: *]: "(!!x y. p = (x, y) ==> Q) ==> Q"
   199   by (insert PairE_lemma [of p]) blast
   200 
   201 ML_setup {*
   202   local val PairE = thm "PairE" in
   203     fun pair_tac s =
   204       EVERY' [res_inst_tac [("p", s)] PairE, hyp_subst_tac, K prune_params_tac];
   205   end;
   206 *}
   207 
   208 lemma surjective_pairing: "p = (fst p, snd p)"
   209   -- {* Do not add as rewrite rule: invalidates some proofs in IMP *}
   210   by (cases p) simp
   211 
   212 declare surjective_pairing [symmetric, simp]
   213 
   214 lemma surj_pair [simp]: "EX x y. z = (x, y)"
   215   apply (rule exI)
   216   apply (rule exI)
   217   apply (rule surjective_pairing)
   218   done
   219 
   220 lemma split_paired_all: "(!!x. PROP P x) == (!!a b. PROP P (a, b))"
   221 proof
   222   fix a b
   223   assume "!!x. PROP P x"
   224   thus "PROP P (a, b)" .
   225 next
   226   fix x
   227   assume "!!a b. PROP P (a, b)"
   228   hence "PROP P (fst x, snd x)" .
   229   thus "PROP P x" by simp
   230 qed
   231 
   232 lemmas split_tupled_all = split_paired_all unit_all_eq2
   233 
   234 text {*
   235   The rule @{thm [source] split_paired_all} does not work with the
   236   Simplifier because it also affects premises in congrence rules,
   237   where this can lead to premises of the form @{text "!!a b. ... =
   238   ?P(a, b)"} which cannot be solved by reflexivity.
   239 *}
   240 
   241 ML_setup "
   242   (* replace parameters of product type by individual component parameters *)
   243   val safe_full_simp_tac = generic_simp_tac true (true, false, false);
   244   local (* filtering with exists_paired_all is an essential optimization *)
   245     fun exists_paired_all (Const (\"all\", _) $ Abs (_, T, t)) =
   246           can HOLogic.dest_prodT T orelse exists_paired_all t
   247       | exists_paired_all (t $ u) = exists_paired_all t orelse exists_paired_all u
   248       | exists_paired_all (Abs (_, _, t)) = exists_paired_all t
   249       | exists_paired_all _ = false;
   250     val ss = HOL_basic_ss
   251       addsimps [thm \"split_paired_all\", thm \"unit_all_eq2\", thm \"unit_abs_eta_conv\"]
   252       addsimprocs [unit_eq_proc];
   253   in
   254     val split_all_tac = SUBGOAL (fn (t, i) =>
   255       if exists_paired_all t then safe_full_simp_tac ss i else no_tac);
   256     val unsafe_split_all_tac = SUBGOAL (fn (t, i) =>
   257       if exists_paired_all t then full_simp_tac ss i else no_tac);
   258     fun split_all th =
   259    if exists_paired_all (#prop (Thm.rep_thm th)) then full_simplify ss th else th;
   260   end;
   261 
   262 claset_ref() := claset() addSbefore (\"split_all_tac\", split_all_tac);
   263 "
   264 
   265 lemma split_paired_All [simp]: "(ALL x. P x) = (ALL a b. P (a, b))"
   266   -- {* @{text "[iff]"} is not a good idea because it makes @{text blast} loop *}
   267   by fast
   268 
   269 lemma curry_split [simp]: "curry (split f) = f"
   270   by (simp add: curry_def split_def)
   271 
   272 lemma split_curry [simp]: "split (curry f) = f"
   273   by (simp add: curry_def split_def)
   274 
   275 lemma curryI [intro!]: "f (a,b) ==> curry f a b"
   276   by (simp add: curry_def)
   277 
   278 lemma curryD [dest!]: "curry f a b ==> f (a,b)"
   279   by (simp add: curry_def)
   280 
   281 lemma curryE: "[| curry f a b ; f (a,b) ==> Q |] ==> Q"
   282   by (simp add: curry_def)
   283 
   284 lemma curry_conv [simp]: "curry f a b = f (a,b)"
   285   by (simp add: curry_def)
   286 
   287 lemma prod_induct [induct type: *]: "!!x. (!!a b. P (a, b)) ==> P x"
   288   by fast
   289 
   290 lemma split_paired_Ex [simp]: "(EX x. P x) = (EX a b. P (a, b))"
   291   by fast
   292 
   293 lemma split_conv [simp]: "split c (a, b) = c a b"
   294   by (simp add: split_def)
   295 
   296 lemmas split = split_conv  -- {* for backwards compatibility *}
   297 
   298 lemmas splitI = split_conv [THEN iffD2, standard]
   299 lemmas splitD = split_conv [THEN iffD1, standard]
   300 
   301 lemma split_Pair_apply: "split (%x y. f (x, y)) = f"
   302   -- {* Subsumes the old @{text split_Pair} when @{term f} is the identity function. *}
   303   apply (rule ext)
   304   apply (tactic {* pair_tac "x" 1 *}, simp)
   305   done
   306 
   307 lemma split_paired_The: "(THE x. P x) = (THE (a, b). P (a, b))"
   308   -- {* Can't be added to simpset: loops! *}
   309   by (simp add: split_Pair_apply)
   310 
   311 lemma The_split: "The (split P) = (THE xy. P (fst xy) (snd xy))"
   312   by (simp add: split_def)
   313 
   314 lemma Pair_fst_snd_eq: "!!s t. (s = t) = (fst s = fst t & snd s = snd t)"
   315 by (simp only: split_tupled_all, simp)
   316 
   317 lemma prod_eqI [intro?]: "fst p = fst q ==> snd p = snd q ==> p = q"
   318   by (simp add: Pair_fst_snd_eq)
   319 
   320 lemma split_weak_cong: "p = q ==> split c p = split c q"
   321   -- {* Prevents simplification of @{term c}: much faster *}
   322   by (erule arg_cong)
   323 
   324 lemma split_eta: "(%(x, y). f (x, y)) = f"
   325   apply (rule ext)
   326   apply (simp only: split_tupled_all)
   327   apply (rule split_conv)
   328   done
   329 
   330 lemma cond_split_eta: "(!!x y. f x y = g (x, y)) ==> (%(x, y). f x y) = g"
   331   by (simp add: split_eta)
   332 
   333 text {*
   334   Simplification procedure for @{thm [source] cond_split_eta}.  Using
   335   @{thm [source] split_eta} as a rewrite rule is not general enough,
   336   and using @{thm [source] cond_split_eta} directly would render some
   337   existing proofs very inefficient; similarly for @{text
   338   split_beta}. *}
   339 
   340 ML_setup {*
   341 
   342 local
   343   val cond_split_eta = thm "cond_split_eta";
   344   fun  Pair_pat k 0 (Bound m) = (m = k)
   345   |    Pair_pat k i (Const ("Pair",  _) $ Bound m $ t) = i > 0 andalso
   346                         m = k+i andalso Pair_pat k (i-1) t
   347   |    Pair_pat _ _ _ = false;
   348   fun no_args k i (Abs (_, _, t)) = no_args (k+1) i t
   349   |   no_args k i (t $ u) = no_args k i t andalso no_args k i u
   350   |   no_args k i (Bound m) = m < k orelse m > k+i
   351   |   no_args _ _ _ = true;
   352   fun split_pat tp i (Abs  (_,_,t)) = if tp 0 i t then Some (i,t) else None
   353   |   split_pat tp i (Const ("split", _) $ Abs (_, _, t)) = split_pat tp (i+1) t
   354   |   split_pat tp i _ = None;
   355   fun metaeq sg lhs rhs = mk_meta_eq (Tactic.prove sg [] []
   356         (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs,rhs)))
   357         (K (simp_tac (HOL_basic_ss addsimps [cond_split_eta]) 1)));
   358 
   359   fun beta_term_pat k i (Abs (_, _, t)) = beta_term_pat (k+1) i t
   360   |   beta_term_pat k i (t $ u) = Pair_pat k i (t $ u) orelse
   361                         (beta_term_pat k i t andalso beta_term_pat k i u)
   362   |   beta_term_pat k i t = no_args k i t;
   363   fun  eta_term_pat k i (f $ arg) = no_args k i f andalso Pair_pat k i arg
   364   |    eta_term_pat _ _ _ = false;
   365   fun subst arg k i (Abs (x, T, t)) = Abs (x, T, subst arg (k+1) i t)
   366   |   subst arg k i (t $ u) = if Pair_pat k i (t $ u) then incr_boundvars k arg
   367                               else (subst arg k i t $ subst arg k i u)
   368   |   subst arg k i t = t;
   369   fun beta_proc sg _ (s as Const ("split", _) $ Abs (_, _, t) $ arg) =
   370         (case split_pat beta_term_pat 1 t of
   371         Some (i,f) => Some (metaeq sg s (subst arg 0 i f))
   372         | None => None)
   373   |   beta_proc _ _ _ = None;
   374   fun eta_proc sg _ (s as Const ("split", _) $ Abs (_, _, t)) =
   375         (case split_pat eta_term_pat 1 t of
   376           Some (_,ft) => Some (metaeq sg s (let val (f $ arg) = ft in f end))
   377         | None => None)
   378   |   eta_proc _ _ _ = None;
   379 in
   380   val split_beta_proc = Simplifier.simproc (Theory.sign_of (the_context ()))
   381     "split_beta" ["split f z"] beta_proc;
   382   val split_eta_proc = Simplifier.simproc (Theory.sign_of (the_context ()))
   383     "split_eta" ["split f"] eta_proc;
   384 end;
   385 
   386 Addsimprocs [split_beta_proc, split_eta_proc];
   387 *}
   388 
   389 lemma split_beta: "(%(x, y). P x y) z = P (fst z) (snd z)"
   390   by (subst surjective_pairing, rule split_conv)
   391 
   392 lemma split_split: "R (split c p) = (ALL x y. p = (x, y) --> R (c x y))"
   393   -- {* For use with @{text split} and the Simplifier. *}
   394   apply (subst surjective_pairing)
   395   apply (subst split_conv, blast)
   396   done
   397 
   398 text {*
   399   @{thm [source] split_split} could be declared as @{text "[split]"}
   400   done after the Splitter has been speeded up significantly;
   401   precompute the constants involved and don't do anything unless the
   402   current goal contains one of those constants.
   403 *}
   404 
   405 lemma split_split_asm: "R (split c p) = (~(EX x y. p = (x, y) & (~R (c x y))))"
   406 by (subst split_split, simp)
   407 
   408 
   409 text {*
   410   \medskip @{term split} used as a logical connective or set former.
   411 
   412   \medskip These rules are for use with @{text blast}; could instead
   413   call @{text simp} using @{thm [source] split} as rewrite. *}
   414 
   415 lemma splitI2: "!!p. [| !!a b. p = (a, b) ==> c a b |] ==> split c p"
   416   apply (simp only: split_tupled_all)
   417   apply (simp (no_asm_simp))
   418   done
   419 
   420 lemma splitI2': "!!p. [| !!a b. (a, b) = p ==> c a b x |] ==> split c p x"
   421   apply (simp only: split_tupled_all)
   422   apply (simp (no_asm_simp))
   423   done
   424 
   425 lemma splitE: "split c p ==> (!!x y. p = (x, y) ==> c x y ==> Q) ==> Q"
   426   by (induct p) (auto simp add: split_def)
   427 
   428 lemma splitE': "split c p z ==> (!!x y. p = (x, y) ==> c x y z ==> Q) ==> Q"
   429   by (induct p) (auto simp add: split_def)
   430 
   431 lemma splitE2:
   432   "[| Q (split P z);  !!x y. [|z = (x, y); Q (P x y)|] ==> R |] ==> R"
   433 proof -
   434   assume q: "Q (split P z)"
   435   assume r: "!!x y. [|z = (x, y); Q (P x y)|] ==> R"
   436   show R
   437     apply (rule r surjective_pairing)+
   438     apply (rule split_beta [THEN subst], rule q)
   439     done
   440 qed
   441 
   442 lemma splitD': "split R (a,b) c ==> R a b c"
   443   by simp
   444 
   445 lemma mem_splitI: "z: c a b ==> z: split c (a, b)"
   446   by simp
   447 
   448 lemma mem_splitI2: "!!p. [| !!a b. p = (a, b) ==> z: c a b |] ==> z: split c p"
   449 by (simp only: split_tupled_all, simp)
   450 
   451 lemma mem_splitE: "[| z: split c p; !!x y. [| p = (x,y); z: c x y |] ==> Q |] ==> Q"
   452 proof -
   453   case rule_context [unfolded split_def]
   454   show ?thesis by (rule rule_context surjective_pairing)+
   455 qed
   456 
   457 declare mem_splitI2 [intro!] mem_splitI [intro!] splitI2' [intro!] splitI2 [intro!] splitI [intro!]
   458 declare mem_splitE [elim!] splitE' [elim!] splitE [elim!]
   459 
   460 ML_setup "
   461 local (* filtering with exists_p_split is an essential optimization *)
   462   fun exists_p_split (Const (\"split\",_) $ _ $ (Const (\"Pair\",_)$_$_)) = true
   463     | exists_p_split (t $ u) = exists_p_split t orelse exists_p_split u
   464     | exists_p_split (Abs (_, _, t)) = exists_p_split t
   465     | exists_p_split _ = false;
   466   val ss = HOL_basic_ss addsimps [thm \"split_conv\"];
   467 in
   468 val split_conv_tac = SUBGOAL (fn (t, i) =>
   469     if exists_p_split t then safe_full_simp_tac ss i else no_tac);
   470 end;
   471 (* This prevents applications of splitE for already splitted arguments leading
   472    to quite time-consuming computations (in particular for nested tuples) *)
   473 claset_ref() := claset() addSbefore (\"split_conv_tac\", split_conv_tac);
   474 "
   475 
   476 lemma split_eta_SetCompr [simp]: "(%u. EX x y. u = (x, y) & P (x, y)) = P"
   477 by (rule ext, fast)
   478 
   479 lemma split_eta_SetCompr2 [simp]: "(%u. EX x y. u = (x, y) & P x y) = split P"
   480 by (rule ext, fast)
   481 
   482 lemma split_part [simp]: "(%(a,b). P & Q a b) = (%ab. P & split Q ab)"
   483   -- {* Allows simplifications of nested splits in case of independent predicates. *}
   484   apply (rule ext, blast)
   485   done
   486 
   487 lemma split_comp_eq [simp]: 
   488 "(%u. f (g (fst u)) (snd u)) = (split (%x. f (g x)))"
   489 by (rule ext, auto)
   490 
   491 lemma The_split_eq [simp]: "(THE (x',y'). x = x' & y = y') = (x, y)"
   492   by blast
   493 
   494 (*
   495 the following  would be slightly more general,
   496 but cannot be used as rewrite rule:
   497 ### Cannot add premise as rewrite rule because it contains (type) unknowns:
   498 ### ?y = .x
   499 Goal "[| P y; !!x. P x ==> x = y |] ==> (@(x',y). x = x' & P y) = (x,y)"
   500 by (rtac some_equality 1)
   501 by ( Simp_tac 1)
   502 by (split_all_tac 1)
   503 by (Asm_full_simp_tac 1)
   504 qed "The_split_eq";
   505 *)
   506 
   507 lemma injective_fst_snd: "!!x y. [|fst x = fst y; snd x = snd y|] ==> x = y"
   508   by auto
   509 
   510 
   511 text {*
   512   \bigskip @{term prod_fun} --- action of the product functor upon
   513   functions.
   514 *}
   515 
   516 lemma prod_fun [simp]: "prod_fun f g (a, b) = (f a, g b)"
   517   by (simp add: prod_fun_def)
   518 
   519 lemma prod_fun_compose: "prod_fun (f1 o f2) (g1 o g2) = (prod_fun f1 g1 o prod_fun f2 g2)"
   520   apply (rule ext)
   521   apply (tactic {* pair_tac "x" 1 *}, simp)
   522   done
   523 
   524 lemma prod_fun_ident [simp]: "prod_fun (%x. x) (%y. y) = (%z. z)"
   525   apply (rule ext)
   526   apply (tactic {* pair_tac "z" 1 *}, simp)
   527   done
   528 
   529 lemma prod_fun_imageI [intro]: "(a, b) : r ==> (f a, g b) : prod_fun f g ` r"
   530   apply (rule image_eqI)
   531   apply (rule prod_fun [symmetric], assumption)
   532   done
   533 
   534 lemma prod_fun_imageE [elim!]:
   535   "[| c: (prod_fun f g)`r;  !!x y. [| c=(f(x),g(y));  (x,y):r |] ==> P
   536     |] ==> P"
   537 proof -
   538   case rule_context
   539   assume major: "c: (prod_fun f g)`r"
   540   show ?thesis
   541     apply (rule major [THEN imageE])
   542     apply (rule_tac p = x in PairE)
   543     apply (rule rule_context)
   544      prefer 2
   545      apply blast
   546     apply (blast intro: prod_fun)
   547     done
   548 qed
   549 
   550 
   551 constdefs
   552   upd_fst :: "('a => 'c) => 'a * 'b => 'c * 'b"
   553  "upd_fst f == prod_fun f id"
   554 
   555   upd_snd :: "('b => 'c) => 'a * 'b => 'a * 'c"
   556  "upd_snd f == prod_fun id f"
   557 
   558 lemma upd_fst_conv [simp]: "upd_fst f (x,y) = (f x,y)" 
   559 by (simp add: upd_fst_def)
   560 
   561 lemma upd_snd_conv [simp]: "upd_snd f (x,y) = (x,f y)" 
   562 by (simp add: upd_snd_def)
   563 
   564 text {*
   565   \bigskip Disjoint union of a family of sets -- Sigma.
   566 *}
   567 
   568 lemma SigmaI [intro!]: "[| a:A;  b:B(a) |] ==> (a,b) : Sigma A B"
   569   by (unfold Sigma_def) blast
   570 
   571 
   572 lemma SigmaE:
   573     "[| c: Sigma A B;
   574         !!x y.[| x:A;  y:B(x);  c=(x,y) |] ==> P
   575      |] ==> P"
   576   -- {* The general elimination rule. *}
   577   by (unfold Sigma_def) blast
   578 
   579 text {*
   580   Elimination of @{term "(a, b) : A \<times> B"} -- introduces no
   581   eigenvariables.
   582 *}
   583 
   584 lemma SigmaD1: "(a, b) : Sigma A B ==> a : A"
   585 by (erule SigmaE, blast)
   586 
   587 lemma SigmaD2: "(a, b) : Sigma A B ==> b : B a"
   588 by (erule SigmaE, blast)
   589 
   590 lemma SigmaE2:
   591     "[| (a, b) : Sigma A B;
   592         [| a:A;  b:B(a) |] ==> P
   593      |] ==> P"
   594   by (blast dest: SigmaD1 SigmaD2)
   595 
   596 declare SigmaE [elim!] SigmaE2 [elim!]
   597 
   598 lemma Sigma_mono: "[| A <= C; !!x. x:A ==> B x <= D x |] ==> Sigma A B <= Sigma C D"
   599   by blast
   600 
   601 lemma Sigma_empty1 [simp]: "Sigma {} B = {}"
   602   by blast
   603 
   604 lemma Sigma_empty2 [simp]: "A <*> {} = {}"
   605   by blast
   606 
   607 lemma UNIV_Times_UNIV [simp]: "UNIV <*> UNIV = UNIV"
   608   by auto
   609 
   610 lemma Compl_Times_UNIV1 [simp]: "- (UNIV <*> A) = UNIV <*> (-A)"
   611   by auto
   612 
   613 lemma Compl_Times_UNIV2 [simp]: "- (A <*> UNIV) = (-A) <*> UNIV"
   614   by auto
   615 
   616 lemma mem_Sigma_iff [iff]: "((a,b): Sigma A B) = (a:A & b:B(a))"
   617   by blast
   618 
   619 lemma Times_subset_cancel2: "x:C ==> (A <*> C <= B <*> C) = (A <= B)"
   620   by blast
   621 
   622 lemma Times_eq_cancel2: "x:C ==> (A <*> C = B <*> C) = (A = B)"
   623   by (blast elim: equalityE)
   624 
   625 lemma SetCompr_Sigma_eq:
   626     "Collect (split (%x y. P x & Q x y)) = (SIGMA x:Collect P. Collect (Q x))"
   627   by blast
   628 
   629 text {*
   630   \bigskip Complex rules for Sigma.
   631 *}
   632 
   633 lemma Collect_split [simp]: "{(a,b). P a & Q b} = Collect P <*> Collect Q"
   634   by blast
   635 
   636 lemma UN_Times_distrib:
   637   "(UN (a,b):(A <*> B). E a <*> F b) = (UNION A E) <*> (UNION B F)"
   638   -- {* Suggested by Pierre Chartier *}
   639   by blast
   640 
   641 lemma split_paired_Ball_Sigma [simp]:
   642     "(ALL z: Sigma A B. P z) = (ALL x:A. ALL y: B x. P(x,y))"
   643   by blast
   644 
   645 lemma split_paired_Bex_Sigma [simp]:
   646     "(EX z: Sigma A B. P z) = (EX x:A. EX y: B x. P(x,y))"
   647   by blast
   648 
   649 lemma Sigma_Un_distrib1: "(SIGMA i:I Un J. C(i)) = (SIGMA i:I. C(i)) Un (SIGMA j:J. C(j))"
   650   by blast
   651 
   652 lemma Sigma_Un_distrib2: "(SIGMA i:I. A(i) Un B(i)) = (SIGMA i:I. A(i)) Un (SIGMA i:I. B(i))"
   653   by blast
   654 
   655 lemma Sigma_Int_distrib1: "(SIGMA i:I Int J. C(i)) = (SIGMA i:I. C(i)) Int (SIGMA j:J. C(j))"
   656   by blast
   657 
   658 lemma Sigma_Int_distrib2: "(SIGMA i:I. A(i) Int B(i)) = (SIGMA i:I. A(i)) Int (SIGMA i:I. B(i))"
   659   by blast
   660 
   661 lemma Sigma_Diff_distrib1: "(SIGMA i:I - J. C(i)) = (SIGMA i:I. C(i)) - (SIGMA j:J. C(j))"
   662   by blast
   663 
   664 lemma Sigma_Diff_distrib2: "(SIGMA i:I. A(i) - B(i)) = (SIGMA i:I. A(i)) - (SIGMA i:I. B(i))"
   665   by blast
   666 
   667 lemma Sigma_Union: "Sigma (Union X) B = (UN A:X. Sigma A B)"
   668   by blast
   669 
   670 text {*
   671   Non-dependent versions are needed to avoid the need for higher-order
   672   matching, especially when the rules are re-oriented.
   673 *}
   674 
   675 lemma Times_Un_distrib1: "(A Un B) <*> C = (A <*> C) Un (B <*> C)"
   676   by blast
   677 
   678 lemma Times_Int_distrib1: "(A Int B) <*> C = (A <*> C) Int (B <*> C)"
   679   by blast
   680 
   681 lemma Times_Diff_distrib1: "(A - B) <*> C = (A <*> C) - (B <*> C)"
   682   by blast
   683 
   684 
   685 lemma pair_imageI [intro]: "(a, b) : A ==> f a b : (%(a, b). f a b) ` A"
   686   apply (rule_tac x = "(a, b)" in image_eqI)
   687    apply auto
   688   done
   689 
   690 
   691 text {*
   692   Setup of internal @{text split_rule}.
   693 *}
   694 
   695 constdefs
   696   internal_split :: "('a => 'b => 'c) => 'a * 'b => 'c"
   697   "internal_split == split"
   698 
   699 lemma internal_split_conv: "internal_split c (a, b) = c a b"
   700   by (simp only: internal_split_def split_conv)
   701 
   702 hide const internal_split
   703 
   704 use "Tools/split_rule.ML"
   705 setup SplitRule.setup
   706 
   707 end