author | clasohm |
Sun, 24 Apr 1994 11:27:38 +0200 | |
changeset 70 | 9459592608e2 |
parent 51 | 934a58983311 |
child 111 | 361521bc7c47 |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: HOL/univ.thy |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
Move LEAST to nat.thy??? Could it be defined for all types 'a::ord? |
|
7 |
||
8 |
Declares the type 'a node, a subtype of (nat=>nat) * ('a+nat) |
|
9 |
||
10 |
Defines "Cartesian Product" and "Disjoint Sum" as set operations. |
|
11 |
Could <*> be generalized to a general summation (Sigma)? |
|
12 |
*) |
|
13 |
||
14 |
Univ = Arith + |
|
51 | 15 |
|
16 |
types |
|
17 |
'a node |
|
18 |
||
19 |
arities |
|
20 |
node :: (term)term |
|
21 |
||
0 | 22 |
consts |
23 |
Least :: "(nat=>bool) => nat" (binder "LEAST " 10) |
|
24 |
||
25 |
apfst :: "['a=>'c, 'a*'b] => 'c*'b" |
|
26 |
Push :: "[nat, nat=>nat] => (nat=>nat)" |
|
27 |
||
28 |
Node :: "((nat=>nat) * ('a+nat)) set" |
|
29 |
Rep_Node :: "'a node => (nat=>nat) * ('a+nat)" |
|
30 |
Abs_Node :: "(nat=>nat) * ('a+nat) => 'a node" |
|
31 |
Push_Node :: "[nat, 'a node] => 'a node" |
|
32 |
ndepth :: "'a node => nat" |
|
33 |
||
34 |
Atom :: "('a+nat) => 'a node set" |
|
35 |
Leaf :: "'a => 'a node set" |
|
36 |
Numb :: "nat => 'a node set" |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
37 |
"$" :: "['a node set, 'a node set]=> 'a node set" (infixr 60) |
0 | 38 |
In0,In1 :: "'a node set => 'a node set" |
39 |
||
40 |
ntrunc :: "[nat, 'a node set] => 'a node set" |
|
41 |
||
42 |
"<*>" :: "['a node set set, 'a node set set]=> 'a node set set" (infixr 80) |
|
43 |
"<+>" :: "['a node set set, 'a node set set]=> 'a node set set" (infixr 70) |
|
44 |
||
45 |
Split :: "['a node set, ['a node set, 'a node set]=>'b] => 'b" |
|
46 |
Case :: "['a node set, ['a node set]=>'b, ['a node set]=>'b] => 'b" |
|
47 |
||
48 |
diag :: "'a set => ('a * 'a)set" |
|
49 |
"<**>" :: "[('a node set * 'a node set)set, ('a node set * 'a node set)set] \ |
|
50 |
\ => ('a node set * 'a node set)set" (infixr 80) |
|
51 |
"<++>" :: "[('a node set * 'a node set)set, ('a node set * 'a node set)set] \ |
|
52 |
\ => ('a node set * 'a node set)set" (infixr 70) |
|
53 |
||
54 |
rules |
|
55 |
||
56 |
(*least number operator*) |
|
57 |
Least_def "Least(P) == @k. P(k) & (ALL j. j<k --> ~P(j))" |
|
58 |
||
59 |
(** lists, trees will be sets of nodes **) |
|
60 |
Node_def "Node == {p. EX f x k. p = <f,x> & f(k)=0}" |
|
61 |
(*faking the type definition 'a node == (nat=>nat) * ('a+nat) *) |
|
62 |
Rep_Node "Rep_Node(n): Node" |
|
63 |
Rep_Node_inverse "Abs_Node(Rep_Node(n)) = n" |
|
64 |
Abs_Node_inverse "p: Node ==> Rep_Node(Abs_Node(p)) = p" |
|
65 |
Push_Node_def "Push_Node == (%n x. Abs_Node (apfst(Push(n),Rep_Node(x))))" |
|
66 |
||
67 |
(*crude "lists" of nats -- needed for the constructions*) |
|
68 |
apfst_def "apfst == (%f p.split(p, %x y. <f(x),y>))" |
|
69 |
Push_def "Push == (%b h n. nat_case(n,Suc(b),h))" |
|
70 |
||
71 |
(** operations on S-expressions -- sets of nodes **) |
|
72 |
||
73 |
(*S-expression constructors*) |
|
74 |
Atom_def "Atom == (%x. {Abs_Node(<%k.0, x>)})" |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
75 |
Scons_def "M$N == (Push_Node(0) `` M) Un (Push_Node(Suc(0)) `` N)" |
0 | 76 |
|
77 |
(*Leaf nodes, with arbitrary or nat labels*) |
|
78 |
Leaf_def "Leaf == Atom o Inl" |
|
79 |
Numb_def "Numb == Atom o Inr" |
|
80 |
||
81 |
(*Injections of the "disjoint sum"*) |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
82 |
In0_def "In0(M) == Numb(0) $ M" |
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
83 |
In1_def "In1(M) == Numb(Suc(0)) $ M" |
0 | 84 |
|
85 |
(*the set of nodes with depth less than k*) |
|
86 |
ndepth_def "ndepth(n) == split(Rep_Node(n), %f x. LEAST k. f(k)=0)" |
|
87 |
ntrunc_def "ntrunc(k,N) == {n. n:N & ndepth(n)<k}" |
|
88 |
||
89 |
(*products and sums for the "universe"*) |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
90 |
uprod_def "A<*>B == UN x:A. UN y:B. { (x$y) }" |
0 | 91 |
usum_def "A<+>B == In0``A Un In1``B" |
92 |
||
93 |
(*the corresponding eliminators*) |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
94 |
Split_def "Split(M,c) == @u. ? x y. M = x$y & u = c(x,y)" |
0 | 95 |
|
96 |
Case_def "Case(M,c,d) == @u. (? x . M = In0(x) & u = c(x)) \ |
|
97 |
\ | (? y . M = In1(y) & u = d(y))" |
|
98 |
||
99 |
||
100 |
(** diagonal sets and equality for the "universe" **) |
|
101 |
||
102 |
diag_def "diag(A) == UN x:A. {<x,x>}" |
|
103 |
||
104 |
dprod_def "r<**>s == UN u:r. UN v:s. \ |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
105 |
\ split(u, %x x'. split(v, %y y'. {<x$y,x'$y'>}))" |
0 | 106 |
|
107 |
dsum_def "r<++>s == (UN u:r. split(u, %x x'. {<In0(x),In0(x')>})) Un \ |
|
108 |
\ (UN v:s. split(v, %y y'. {<In1(y),In1(y')>}))" |
|
109 |
||
110 |
end |