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