81 (*"~:" :: "[i, i] => o" (infixl 50) (*negated membership relation*)*) |
80 (*"~:" :: "[i, i] => o" (infixl 50) (*negated membership relation*)*) |
82 |
81 |
83 |
82 |
84 types |
83 types |
85 is |
84 is |
|
85 pttrns |
86 |
86 |
87 syntax |
87 syntax |
88 "" :: "i => is" ("_") |
88 "" :: "i => is" ("_") |
89 "@Enum" :: "[i, is] => is" ("_,/ _") |
89 "@Enum" :: "[i, is] => is" ("_,/ _") |
90 "~:" :: "[i, i] => o" (infixl 50) |
90 "~:" :: "[i, i] => o" (infixl 50) |
91 "@Finset" :: "is => i" ("{(_)}") |
91 "@Finset" :: "is => i" ("{(_)}") |
92 "@Tuple" :: "[i, is] => i" ("<(_,/ _)>") |
92 "@Tuple" :: "[i, is] => i" ("<(_,/ _)>") |
93 "@Collect" :: "[idt, i, o] => i" ("(1{_: _ ./ _})") |
93 "@Collect" :: "[pttrn, i, o] => i" ("(1{_: _ ./ _})") |
94 "@Replace" :: "[idt, idt, i, o] => i" ("(1{_ ./ _: _, _})") |
94 "@Replace" :: "[pttrn, pttrn, i, o] => i" ("(1{_ ./ _: _, _})") |
95 "@RepFun" :: "[i, idt, i] => i" ("(1{_ ./ _: _})" [51,0,51]) |
95 "@RepFun" :: "[i, pttrn, i] => i" ("(1{_ ./ _: _})" [51,0,51]) |
96 "@INTER" :: "[idt, i, i] => i" ("(3INT _:_./ _)" 10) |
96 "@INTER" :: "[pttrn, i, i] => i" ("(3INT _:_./ _)" 10) |
97 "@UNION" :: "[idt, i, i] => i" ("(3UN _:_./ _)" 10) |
97 "@UNION" :: "[pttrn, i, i] => i" ("(3UN _:_./ _)" 10) |
98 "@PROD" :: "[idt, i, i] => i" ("(3PROD _:_./ _)" 10) |
98 "@PROD" :: "[pttrn, i, i] => i" ("(3PROD _:_./ _)" 10) |
99 "@SUM" :: "[idt, i, i] => i" ("(3SUM _:_./ _)" 10) |
99 "@SUM" :: "[pttrn, i, i] => i" ("(3SUM _:_./ _)" 10) |
100 "->" :: "[i, i] => i" (infixr 60) |
100 "->" :: "[i, i] => i" (infixr 60) |
101 "*" :: "[i, i] => i" (infixr 80) |
101 "*" :: "[i, i] => i" (infixr 80) |
102 "@lam" :: "[idt, i, i] => i" ("(3lam _:_./ _)" 10) |
102 "@lam" :: "[pttrn, i, i] => i" ("(3lam _:_./ _)" 10) |
103 "@Ball" :: "[idt, i, o] => o" ("(3ALL _:_./ _)" 10) |
103 "@Ball" :: "[pttrn, i, o] => o" ("(3ALL _:_./ _)" 10) |
104 "@Bex" :: "[idt, i, o] => o" ("(3EX _:_./ _)" 10) |
104 "@Bex" :: "[pttrn, i, o] => o" ("(3EX _:_./ _)" 10) |
|
105 |
|
106 (** Patterns -- extends pre-defined type "pttrn" used in abstractions **) |
|
107 |
|
108 "@pttrn" :: "pttrns => pttrn" ("<_>") |
|
109 "" :: " pttrn => pttrns" ("_") |
|
110 "@pttrns" :: "[pttrn,pttrns] => pttrns" ("_,/_") |
105 |
111 |
106 translations |
112 translations |
107 "x ~: y" == "~ (x : y)" |
113 "x ~: y" == "~ (x : y)" |
108 "{x, xs}" == "cons(x, {xs})" |
114 "{x, xs}" == "cons(x, {xs})" |
109 "{x}" == "cons(x, 0)" |
115 "{x}" == "cons(x, 0)" |
110 "<x, y, z>" == "<x, <y, z>>" |
|
111 "<x, y>" == "Pair(x, y)" |
|
112 "{x:A. P}" == "Collect(A, %x. P)" |
116 "{x:A. P}" == "Collect(A, %x. P)" |
113 "{y. x:A, Q}" == "Replace(A, %x y. Q)" |
117 "{y. x:A, Q}" == "Replace(A, %x y. Q)" |
114 "{b. x:A}" == "RepFun(A, %x. b)" |
118 "{b. x:A}" == "RepFun(A, %x. b)" |
115 "INT x:A. B" == "Inter({B. x:A})" |
119 "INT x:A. B" == "Inter({B. x:A})" |
116 "UN x:A. B" == "Union({B. x:A})" |
120 "UN x:A. B" == "Union({B. x:A})" |
120 "A * B" => "Sigma(A, _K(B))" |
124 "A * B" => "Sigma(A, _K(B))" |
121 "lam x:A. f" == "Lambda(A, %x. f)" |
125 "lam x:A. f" == "Lambda(A, %x. f)" |
122 "ALL x:A. P" == "Ball(A, %x. P)" |
126 "ALL x:A. P" == "Ball(A, %x. P)" |
123 "EX x:A. P" == "Bex(A, %x. P)" |
127 "EX x:A. P" == "Bex(A, %x. P)" |
124 |
128 |
|
129 "<x, y, z>" == "<x, <y, z>>" |
|
130 "<x, y>" == "Pair(x, y)" |
|
131 "%<x,y,zs>.b" => "split(%x <y,zs>.b)" |
|
132 "%<x,y>.b" => "split(%x y.b)" |
|
133 (* The <= direction fails if split has more than one argument because |
|
134 ast-matching fails. Otherwise it would work fine *) |
125 |
135 |
126 defs |
136 defs |
127 |
137 |
128 (* Bounded Quantifiers *) |
138 (* Bounded Quantifiers *) |
129 Ball_def "Ball(A, P) == ALL x. x:A --> P(x)" |
139 Ball_def "Ball(A, P) == ALL x. x:A --> P(x)" |
189 |
199 |
190 (* Ordered pairs and disjoint union of a family of sets *) |
200 (* Ordered pairs and disjoint union of a family of sets *) |
191 |
201 |
192 (* this "symmetric" definition works better than {{a}, {a,b}} *) |
202 (* this "symmetric" definition works better than {{a}, {a,b}} *) |
193 Pair_def "<a,b> == {{a,a}, {a,b}}" |
203 Pair_def "<a,b> == {{a,a}, {a,b}}" |
194 fst_def "fst == split(%x y.x)" |
204 fst_def "fst(p) == THE a. EX b. p=<a,b>" |
195 snd_def "snd == split(%x y.y)" |
205 snd_def "snd(p) == THE b. EX a. p=<a,b>" |
196 split_def "split(c,p) == THE y. EX a b. p=<a,b> & y=c(a,b)" |
206 split_def "split(c,p) == c(fst(p), snd(p))" |
197 fsplit_def "fsplit(R,z) == EX x y. z=<x,y> & R(x,y)" |
|
198 Sigma_def "Sigma(A,B) == UN x:A. UN y:B(x). {<x,y>}" |
207 Sigma_def "Sigma(A,B) == UN x:A. UN y:B(x). {<x,y>}" |
199 |
208 |
200 (* Operations on relations *) |
209 (* Operations on relations *) |
201 |
210 |
202 (*converse of relation r, inverse of function*) |
211 (*converse of relation r, inverse of function*) |
222 end |
231 end |
223 |
232 |
224 |
233 |
225 ML |
234 ML |
226 |
235 |
227 (* 'Dependent' type operators *) |
236 (* Pattern-matching and 'Dependent' type operators *) |
228 |
237 |
229 val print_translation = |
238 local open Syntax |
230 [("Pi", dependent_tr' ("@PROD", "op ->")), |
239 |
|
240 fun pttrn s = const"@pttrn" $ s; |
|
241 fun pttrns s t = const"@pttrns" $ s $ t; |
|
242 |
|
243 fun split2(Abs(x,T,t)) = |
|
244 let val (pats,u) = split1 t |
|
245 in (pttrns (Free(x,T)) pats, subst_bounds([free x],u)) end |
|
246 | split2(Const("split",_) $ r) = |
|
247 let val (pats,s) = split2(r) |
|
248 val (pats2,t) = split1(s) |
|
249 in (pttrns (pttrn pats) pats2, t) end |
|
250 and split1(Abs(x,T,t)) = (Free(x,T), subst_bounds([free x],t)) |
|
251 | split1(Const("split",_)$t) = split2(t); |
|
252 |
|
253 fun split_tr'(t::args) = |
|
254 let val (pats,ft) = split2(t) |
|
255 in list_comb(const"_lambda" $ pttrn pats $ ft, args) end; |
|
256 |
|
257 in |
|
258 |
|
259 val print_translation = |
|
260 [("split", split_tr'), |
|
261 ("Pi", dependent_tr' ("@PROD", "op ->")), |
231 ("Sigma", dependent_tr' ("@SUM", "op *"))]; |
262 ("Sigma", dependent_tr' ("@SUM", "op *"))]; |
|
263 |
|
264 end; |