src/HOL/Product_Type.thy
author nipkow
Thu Oct 12 18:44:35 2000 +0200 (2000-10-12)
changeset 10213 01c2744a3786
child 10289 475ea668c67d
permissions -rw-r--r--
*** empty log message ***
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
nipkow@10213
     5
nipkow@10213
     6
Ordered Pairs and the Cartesian product type.
nipkow@10213
     7
The unit type.
nipkow@10213
     8
*)
nipkow@10213
     9
nipkow@10213
    10
Product_Type = Fun + equalities +
nipkow@10213
    11
nipkow@10213
    12
nipkow@10213
    13
(** products **)
nipkow@10213
    14
nipkow@10213
    15
(* type definition *)
nipkow@10213
    16
nipkow@10213
    17
constdefs
nipkow@10213
    18
  Pair_Rep      :: ['a, 'b] => ['a, 'b] => bool
nipkow@10213
    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)
nipkow@10213
    25
    = "{f. ? a b. f = Pair_Rep (a::'a) (b::'b)}"
nipkow@10213
    26
nipkow@10213
    27
syntax (symbols)
nipkow@10213
    28
  "*"           :: [type, type] => type         ("(_ \\<times>/ _)" [21, 20] 20)
nipkow@10213
    29
nipkow@10213
    30
syntax (HTML output)
nipkow@10213
    31
  "*"           :: [type, type] => type         ("(_ \\<times>/ _)" [21, 20] 20)
nipkow@10213
    32
nipkow@10213
    33
nipkow@10213
    34
(* abstract constants and syntax *)
nipkow@10213
    35
nipkow@10213
    36
consts
nipkow@10213
    37
  fst           :: "'a * 'b => 'a"
nipkow@10213
    38
  snd           :: "'a * 'b => 'b"
nipkow@10213
    39
  split         :: "[['a, 'b] => 'c, 'a * 'b] => 'c"
nipkow@10213
    40
  prod_fun      :: "['a => 'b, 'c => 'd, 'a * 'c] => 'b * 'd"
nipkow@10213
    41
  Pair          :: "['a, 'b] => 'a * 'b"
nipkow@10213
    42
  Sigma         :: "['a set, 'a => 'b set] => ('a * 'b) set"
nipkow@10213
    43
nipkow@10213
    44
nipkow@10213
    45
(* patterns -- extends pre-defined type "pttrn" used in abstractions *)
nipkow@10213
    46
nipkow@10213
    47
nonterminals
nipkow@10213
    48
  tuple_args patterns
nipkow@10213
    49
nipkow@10213
    50
syntax
nipkow@10213
    51
  "_tuple"      :: "'a => tuple_args => 'a * 'b"        ("(1'(_,/ _'))")
nipkow@10213
    52
  "_tuple_arg"  :: "'a => tuple_args"                   ("_")
nipkow@10213
    53
  "_tuple_args" :: "'a => tuple_args => tuple_args"     ("_,/ _")
nipkow@10213
    54
  "_pattern"    :: [pttrn, patterns] => pttrn           ("'(_,/ _')")
nipkow@10213
    55
  ""            :: pttrn => patterns                    ("_")
nipkow@10213
    56
  "_patterns"   :: [pttrn, patterns] => patterns        ("_,/ _")
nipkow@10213
    57
  "@Sigma"      :: "[pttrn, 'a set, 'b set] => ('a * 'b) set"   ("(3SIGMA _:_./ _)" 10)
nipkow@10213
    58
  "@Times"      :: "['a set, 'a => 'b set] => ('a * 'b) set"    (infixr "<*>" 80)
nipkow@10213
    59
nipkow@10213
    60
translations
nipkow@10213
    61
  "(x, y)"       == "Pair x y"
nipkow@10213
    62
  "_tuple x (_tuple_args y z)" == "_tuple x (_tuple_arg (_tuple y z))"
nipkow@10213
    63
  "%(x,y,zs).b"  == "split(%x (y,zs).b)"
nipkow@10213
    64
  "%(x,y).b"     == "split(%x y. b)"
nipkow@10213
    65
  "_abs (Pair x y) t" => "%(x,y).t"
nipkow@10213
    66
  (* The last rule accommodates tuples in `case C ... (x,y) ... => ...'
nipkow@10213
    67
     The (x,y) is parsed as `Pair x y' because it is logic, not pttrn *)
nipkow@10213
    68
nipkow@10213
    69
  "SIGMA x:A. B" => "Sigma A (%x. B)"
nipkow@10213
    70
  "A <*> B"      => "Sigma A (_K B)"
nipkow@10213
    71
nipkow@10213
    72
syntax (symbols)
nipkow@10213
    73
  "@Sigma"      :: "[pttrn, 'a set, 'b set] => ('a * 'b) set"   ("(3\\<Sigma> _\\<in>_./ _)" 10)
nipkow@10213
    74
  "@Times"      :: "['a set, 'a => 'b set] => ('a * 'b) set"    ("_ \\<times> _" [81, 80] 80)
nipkow@10213
    75
nipkow@10213
    76
nipkow@10213
    77
(* definitions *)
nipkow@10213
    78
nipkow@10213
    79
local
nipkow@10213
    80
nipkow@10213
    81
defs
nipkow@10213
    82
  Pair_def      "Pair a b == Abs_Prod(Pair_Rep a b)"
nipkow@10213
    83
  fst_def       "fst p == @a. ? b. p = (a, b)"
nipkow@10213
    84
  snd_def       "snd p == @b. ? a. p = (a, b)"
nipkow@10213
    85
  split_def     "split == (%c p. c (fst p) (snd p))"
nipkow@10213
    86
  prod_fun_def  "prod_fun f g == split(%x y.(f(x), g(y)))"
nipkow@10213
    87
  Sigma_def     "Sigma A B == UN x:A. UN y:B(x). {(x, y)}"
nipkow@10213
    88
nipkow@10213
    89
nipkow@10213
    90
nipkow@10213
    91
(** unit **)
nipkow@10213
    92
nipkow@10213
    93
global
nipkow@10213
    94
nipkow@10213
    95
typedef  unit = "{True}"
nipkow@10213
    96
nipkow@10213
    97
consts
nipkow@10213
    98
  "()"          :: unit                           ("'(')")
nipkow@10213
    99
nipkow@10213
   100
local
nipkow@10213
   101
nipkow@10213
   102
defs
nipkow@10213
   103
  Unity_def     "() == Abs_unit True"
nipkow@10213
   104
nipkow@10213
   105
end
nipkow@10213
   106
nipkow@10213
   107
ML
nipkow@10213
   108
nipkow@10213
   109
val print_translation = [("Sigma", dependent_tr' ("@Sigma", "@Times"))];