src/HOL/Product_Type.thy
author wenzelm
Wed Oct 17 20:24:03 2001 +0200 (2001-10-17)
changeset 11820 015a82d4ee96
parent 11777 b03c8a3fcc6d
child 11838 02d75712061d
permissions -rw-r--r--
proper proof of split_paired_all (presently unused);
     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 {* Finite products (including unit) *}
     8 
     9 theory Product_Type = Fun
    10 files ("Product_Type_lemmas.ML") ("Tools/split_rule.ML"):
    11 
    12 
    13 subsection {* Products *}
    14 
    15 subsubsection {* Type definition *}
    16 
    17 constdefs
    18   Pair_Rep :: "['a, 'b] => ['a, 'b] => bool"
    19   "Pair_Rep == (%a b. %x y. x=a & y=b)"
    20 
    21 global
    22 
    23 typedef (Prod)
    24   ('a, 'b) "*"          (infixr 20)
    25     = "{f. EX a b. f = Pair_Rep (a::'a) (b::'b)}"
    26 proof
    27   fix a b show "Pair_Rep a b : ?Prod"
    28     by blast
    29 qed
    30 
    31 syntax (symbols)
    32   "*"      :: "[type, type] => type"         ("(_ \<times>/ _)" [21, 20] 20)
    33 syntax (HTML output)
    34   "*"      :: "[type, type] => type"         ("(_ \<times>/ _)" [21, 20] 20)
    35 
    36 local
    37 
    38 
    39 subsubsection {* Abstract constants and syntax *}
    40 
    41 global
    42 
    43 consts
    44   fst      :: "'a * 'b => 'a"
    45   snd      :: "'a * 'b => 'b"
    46   split    :: "[['a, 'b] => 'c, 'a * 'b] => 'c"
    47   prod_fun :: "['a => 'b, 'c => 'd, 'a * 'c] => 'b * 'd"
    48   Pair     :: "['a, 'b] => 'a * 'b"
    49   Sigma    :: "['a set, 'a => 'b set] => ('a * 'b) set"
    50 
    51 local
    52 
    53 text {*
    54   Patterns -- extends pre-defined type @{typ pttrn} used in
    55   abstractions.
    56 *}
    57 
    58 nonterminals
    59   tuple_args patterns
    60 
    61 syntax
    62   "_tuple"      :: "'a => tuple_args => 'a * 'b"        ("(1'(_,/ _'))")
    63   "_tuple_arg"  :: "'a => tuple_args"                   ("_")
    64   "_tuple_args" :: "'a => tuple_args => tuple_args"     ("_,/ _")
    65   "_pattern"    :: "[pttrn, patterns] => pttrn"         ("'(_,/ _')")
    66   ""            :: "pttrn => patterns"                  ("_")
    67   "_patterns"   :: "[pttrn, patterns] => patterns"      ("_,/ _")
    68   "@Sigma" ::"[pttrn, 'a set, 'b set] => ('a * 'b) set" ("(3SIGMA _:_./ _)" 10)
    69   "@Times" ::"['a set,  'a => 'b set] => ('a * 'b) set" (infixr "<*>" 80)
    70 
    71 translations
    72   "(x, y)"       == "Pair x y"
    73   "_tuple x (_tuple_args y z)" == "_tuple x (_tuple_arg (_tuple y z))"
    74   "%(x,y,zs).b"  == "split(%x (y,zs).b)"
    75   "%(x,y).b"     == "split(%x y. b)"
    76   "_abs (Pair x y) t" => "%(x,y).t"
    77   (* The last rule accommodates tuples in `case C ... (x,y) ... => ...'
    78      The (x,y) is parsed as `Pair x y' because it is logic, not pttrn *)
    79 
    80   "SIGMA x:A. B" => "Sigma A (%x. B)"
    81   "A <*> B"      => "Sigma A (_K B)"
    82 
    83 syntax (symbols)
    84   "@Sigma" :: "[pttrn, 'a set, 'b set] => ('a * 'b) set"  ("(3\<Sigma> _\<in>_./ _)"   10)
    85   "@Times" :: "['a set,  'a => 'b set] => ('a * 'b) set"  ("_ \<times> _" [81, 80] 80)
    86 
    87 print_translation {* [("Sigma", dependent_tr' ("@Sigma", "@Times"))] *}
    88 
    89 
    90 subsubsection {* Definitions *}
    91 
    92 defs
    93   Pair_def:     "Pair a b == Abs_Prod(Pair_Rep a b)"
    94   fst_def:      "fst p == THE a. EX b. p = (a, b)"
    95   snd_def:      "snd p == THE b. EX a. p = (a, b)"
    96   split_def:    "split == (%c p. c (fst p) (snd p))"
    97   prod_fun_def: "prod_fun f g == split(%x y.(f(x), g(y)))"
    98   Sigma_def:    "Sigma A B == UN x:A. UN y:B(x). {(x, y)}"
    99 
   100 
   101 subsection {* Unit *}
   102 
   103 typedef unit = "{True}"
   104 proof
   105   show "True : ?unit"
   106     by blast
   107 qed
   108 
   109 constdefs
   110   Unity :: unit    ("'(')")
   111   "() == Abs_unit True"
   112 
   113 
   114 subsection {* Lemmas and tool setup *}
   115 
   116 use "Product_Type_lemmas.ML"
   117 
   118 lemma (*split_paired_all:*) "(!!x. PROP P x) == (!!a b. PROP P (a, b))"   (* FIXME unused *)
   119 proof
   120   fix a b
   121   assume "!!x. PROP P x"
   122   thus "PROP P (a, b)" .
   123 next
   124   fix x
   125   assume "!!a b. PROP P (a, b)"
   126   hence "PROP P (fst x, snd x)" .
   127   thus "PROP P x" by simp
   128 qed
   129 
   130 lemma pair_imageI [intro]: "(a, b) : A ==> f a b : (%(a, b). f a b) ` A"
   131   apply (rule_tac x = "(a, b)" in image_eqI)
   132    apply auto
   133   done
   134 
   135 
   136 constdefs
   137   internal_split :: "('a => 'b => 'c) => 'a * 'b => 'c"
   138   "internal_split == split"
   139 
   140 lemma internal_split_conv: "internal_split c (a, b) = c a b"
   141   by (simp only: internal_split_def split_conv)
   142 
   143 hide const internal_split
   144 
   145 use "Tools/split_rule.ML"
   146 setup SplitRule.setup
   147 
   148 end