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