src/HOL/Prod.thy
author nipkow
Wed, 03 May 1995 08:21:53 +0200
changeset 1081 884c6ef06fbf
parent 1068 e0f2dffab506
child 1114 c8dfb56a7e95
permissions -rw-r--r--
Corrected display of split f t: no more let. Also replaced "_abs" by "_lambda" --- the former was a mistake which happended to work.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     1
(*  Title:      HOL/Prod.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         Prod.thy,v 1.5 1994/08/19 09:04:27 lcp Exp
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1992  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Ordered Pairs and the Cartesian product type.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
The unit type.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
Prod = Fun +
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
(** Products **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
(* type definition *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
consts
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
  Pair_Rep      :: "['a, 'b] => ['a, 'b] => bool"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
defs
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
  Pair_Rep_def  "Pair_Rep == (%a b. %x y. x=a & y=b)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
subtype (Prod)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
  ('a, 'b) "*"          (infixr 20)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
    = "{f. ? a b. f = Pair_Rep (a::'a) (b::'b)}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
(* abstract constants and syntax *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
consts
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
  fst           :: "'a * 'b => 'a"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
  snd           :: "'a * 'b => 'b"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
  split         :: "[['a, 'b] => 'c, 'a * 'b] => 'c"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
  prod_fun      :: "['a => 'b, 'c => 'd, 'a * 'c] => 'b * 'd"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
  Pair          :: "['a, 'b] => 'a * 'b"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
  Sigma         :: "['a set, 'a => 'b set] => ('a * 'b) set"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    37
(** Patterns -- extends pre-defined type "pttrn" used in abstractions **)
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    38
types pttrns
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    39
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
syntax
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    41
  "@Tuple"      :: "['a, args] => 'a * 'b"            ("(1'(_,/ _'))")
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    43
  "@pttrn"  :: "pttrns => pttrn"            ("'(_')")
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    44
  ""        :: " pttrn           => pttrns" ("_")
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    45
  "@pttrns" :: "[pttrn,pttrns]   => pttrns" ("_,/_")
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    46
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
translations
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    48
  "(x, y, z)"   == "(x, (y, z))"
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    49
  "(x, y)"      == "Pair x y"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    51
  "%(x,y,zs).b"   => "split(%x (y,zs).b)"
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    52
  "%(x,y).b"      => "split(%x y.b)"
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    53
(* The <= direction fails if split has more than one argument because
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    54
   ast-matching fails. Otherwise it would work fine *)
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    55
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
defs
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
  Pair_def      "Pair a b == Abs_Prod(Pair_Rep a b)"
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    58
  fst_def       "fst(p) == @a. ? b. p = (a, b)"
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    59
  snd_def       "snd(p) == @b. ? a. p = (a, b)"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
  split_def     "split c p == c (fst p) (snd p)"
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    61
  prod_fun_def  "prod_fun f g == split(%x y.(f(x), g(y)))"
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    62
  Sigma_def     "Sigma A B == UN x:A. UN y:B(x). {(x, y)}"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
(** Unit **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
subtype (Unit)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
  unit = "{p. p = True}"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
consts
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    72
  "()"          :: "unit"                           ("'(')")
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
defs
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 967
diff changeset
    75
  Unity_def     "() == Abs_Unit(True)"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
end
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    78
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    79
ML
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    80
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    81
local open Syntax
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    82
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    83
fun pttrn s = const"@pttrn" $ s;
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    84
fun pttrns s t = const"@pttrns" $ s $ t;
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    85
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    86
fun split2(Abs(x,T,t)) =
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    87
      let val (pats,u) = split1 t
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    88
      in (pttrns (Free(x,T)) pats, subst_bounds([free x],u)) end
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    89
  | split2(Const("split",_) $ r) =
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    90
      let val (pats,s) = split2(r)
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    91
          val (pats2,t) = split1(s)
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    92
      in (pttrns (pttrn pats) pats2, t) end
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    93
and split1(Abs(x,T,t)) =  (Free(x,T), subst_bounds([free x],t))
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    94
  | split1(Const("split",_)$t) = split2(t);
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    95
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    96
fun split_tr'(t::args) =
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    97
  let val (pats,ft) = split2(t)
1081
884c6ef06fbf Corrected display of split f t: no more let.
nipkow
parents: 1068
diff changeset
    98
  in list_comb(const"_lambda" $ pttrn pats $ ft, args) end;
1068
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
    99
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
   100
in
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
   101
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
   102
val print_translation = [("split", split_tr')];
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
   103
e0f2dffab506 HOL.thy:
nipkow
parents: 972
diff changeset
   104
end;