src/HOL/Datatype_Universe.thy
author nipkow
Fri, 24 Nov 2000 16:49:27 +0100
changeset 10519 ade64af4c57c
parent 10214 77349ed89f45
child 10832 e33b47e4246d
permissions -rw-r--r--
hide many names from Datatype_Universe.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Datatype_Universe.thy
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     2
    ID:         $Id$
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     5
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     6
Declares the type ('a, 'b) node, a subtype of (nat=>'b+nat) * ('a+nat)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     7
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     8
Defines "Cartesian Product" and "Disjoint Sum" as set operations.
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
     9
Could <*> be generalized to a general summation (Sigma)?
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    10
*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    11
10214
77349ed89f45 *** empty log message ***
nipkow
parents: 10213
diff changeset
    12
Datatype_Universe = NatArith + Sum_Type +
10213
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    13
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    14
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    15
(** lists, trees will be sets of nodes **)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    16
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    17
typedef (Node)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    18
  ('a, 'b) node = "{p. EX f x k. p = (f::nat=>'b+nat, x::'a+nat) & f k = Inr 0}"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    19
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    20
types
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    21
  'a item = ('a, unit) node set
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    22
  ('a, 'b) dtree = ('a, 'b) node set
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    23
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    24
consts
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    25
  apfst     :: "['a=>'c, 'a*'b] => 'c*'b"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    26
  Push      :: "[('b + nat), nat => ('b + nat)] => (nat => ('b + nat))"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    27
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    28
  Push_Node :: "[('b + nat), ('a, 'b) node] => ('a, 'b) node"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    29
  ndepth    :: ('a, 'b) node => nat
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    30
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    31
  Atom      :: "('a + nat) => ('a, 'b) dtree"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    32
  Leaf      :: 'a => ('a, 'b) dtree
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    33
  Numb      :: nat => ('a, 'b) dtree
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    34
  Scons     :: [('a, 'b) dtree, ('a, 'b) dtree] => ('a, 'b) dtree
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    35
  In0,In1   :: ('a, 'b) dtree => ('a, 'b) dtree
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    36
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    37
  Lim       :: ('b => ('a, 'b) dtree) => ('a, 'b) dtree
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    38
  Funs      :: "'u set => ('t => 'u) set"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    39
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    40
  ntrunc    :: [nat, ('a, 'b) dtree] => ('a, 'b) dtree
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    41
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    42
  uprod     :: [('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    43
  usum      :: [('a, 'b) dtree set, ('a, 'b) dtree set]=> ('a, 'b) dtree set
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    44
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    45
  Split     :: [[('a, 'b) dtree, ('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    46
  Case      :: [[('a, 'b) dtree]=>'c, [('a, 'b) dtree]=>'c, ('a, 'b) dtree] => 'c
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    47
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    48
  dprod     :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set] 
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    49
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    50
  dsum      :: "[(('a, 'b) dtree * ('a, 'b) dtree)set, (('a, 'b) dtree * ('a, 'b) dtree)set] 
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    51
                => (('a, 'b) dtree * ('a, 'b) dtree)set"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    52
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    53
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    54
defs
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    55
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    56
  Push_Node_def  "Push_Node == (%n x. Abs_Node (apfst (Push n) (Rep_Node x)))"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    57
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    58
  (*crude "lists" of nats -- needed for the constructions*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    59
  apfst_def  "apfst == (%f (x,y). (f(x),y))"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    60
  Push_def   "Push == (%b h. nat_case b h)"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    61
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    62
  (** operations on S-expressions -- sets of nodes **)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    63
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    64
  (*S-expression constructors*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    65
  Atom_def   "Atom == (%x. {Abs_Node((%k. Inr 0, x))})"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    66
  Scons_def  "Scons M N == (Push_Node (Inr 1) `` M) Un (Push_Node (Inr 2) `` N)"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    67
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    68
  (*Leaf nodes, with arbitrary or nat labels*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    69
  Leaf_def   "Leaf == Atom o Inl"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    70
  Numb_def   "Numb == Atom o Inr"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    71
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    72
  (*Injections of the "disjoint sum"*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    73
  In0_def    "In0(M) == Scons (Numb 0) M"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    74
  In1_def    "In1(M) == Scons (Numb 1) M"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    75
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    76
  (*Function spaces*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    77
  Lim_def "Lim f == Union {z. ? x. z = Push_Node (Inl x) `` (f x)}"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    78
  Funs_def "Funs S == {f. range f <= S}"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    79
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    80
  (*the set of nodes with depth less than k*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    81
  ndepth_def "ndepth(n) == (%(f,x). LEAST k. f k = Inr 0) (Rep_Node n)"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    82
  ntrunc_def "ntrunc k N == {n. n:N & ndepth(n)<k}"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    83
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    84
  (*products and sums for the "universe"*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    85
  uprod_def  "uprod A B == UN x:A. UN y:B. { Scons x y }"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    86
  usum_def   "usum A B == In0``A Un In1``B"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    87
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    88
  (*the corresponding eliminators*)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    89
  Split_def  "Split c M == @u. ? x y. M = Scons x y & u = c x y"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    90
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    91
  Case_def   "Case c d M == @u.  (? x . M = In0(x) & u = c(x)) 
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    92
                               | (? y . M = In1(y) & u = d(y))"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    93
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    94
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    95
  (** equality for the "universe" **)
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    96
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    97
  dprod_def  "dprod r s == UN (x,x'):r. UN (y,y'):s. {(Scons x y, Scons x' y')}"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    98
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
    99
  dsum_def   "dsum r s == (UN (x,x'):r. {(In0(x),In0(x'))}) Un 
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
   100
                          (UN (y,y'):s. {(In1(y),In1(y'))})"
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
   101
01c2744a3786 *** empty log message ***
nipkow
parents:
diff changeset
   102
end