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