author | clasohm |
Fri, 01 Jul 1994 11:04:12 +0200 | |
changeset 445 | 7b6d8b8d4580 |
parent 434 | 89d45187f04d |
child 477 | 53fc8ad84b33 |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: ZF/ex/term.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
Datatype definition of terms over an alphabet. |
|
7 |
Illustrates the list functor (essentially the same type as in Trees & Forests) |
|
8 |
*) |
|
9 |
||
10 |
structure Term = Datatype_Fun |
|
11 |
(val thy = List.thy; |
|
12 |
val rec_specs = |
|
13 |
[("term", "univ(A)", |
|
445 | 14 |
[(["Apply"], "[i,i]=>i", NoSyn)])]; |
0 | 15 |
val rec_styp = "i=>i"; |
16 |
val sintrs = ["[| a: A; l: list(term(A)) |] ==> Apply(a,l) : term(A)"]; |
|
17 |
val monos = [list_mono]; |
|
71
729fe026c5f3
sample datatype defs now use datatype_intrs, datatype_elims
lcp
parents:
56
diff
changeset
|
18 |
val type_intrs = datatype_intrs; |
56 | 19 |
val type_elims = [make_elim (list_univ RS subsetD)]); |
0 | 20 |
|
21 |
val [ApplyI] = Term.intrs; |
|
22 |
||
434 | 23 |
(*Note that Apply is the identity function*) |
24 |
goal Term.thy "term(A) = A * list(term(A))"; |
|
25 |
by (rtac (Term.unfold RS trans) 1); |
|
26 |
bws Term.con_defs; |
|
27 |
by (fast_tac (sum_cs addIs ([equalityI] @ datatype_intrs) |
|
28 |
addDs [Term.dom_subset RS subsetD] |
|
29 |
addEs [A_into_univ, list_into_univ]) 1); |
|
30 |
val term_unfold = result(); |
|
31 |
||
0 | 32 |
(*Induction on term(A) followed by induction on List *) |
33 |
val major::prems = goal Term.thy |
|
34 |
"[| t: term(A); \ |
|
35 |
\ !!x. [| x: A |] ==> P(Apply(x,Nil)); \ |
|
36 |
\ !!x z zs. [| x: A; z: term(A); zs: list(term(A)); P(Apply(x,zs)) \ |
|
37 |
\ |] ==> P(Apply(x, Cons(z,zs))) \ |
|
38 |
\ |] ==> P(t)"; |
|
39 |
by (rtac (major RS Term.induct) 1); |
|
40 |
by (etac List.induct 1); |
|
41 |
by (etac CollectE 2); |
|
42 |
by (REPEAT (ares_tac (prems@[list_CollectD]) 1)); |
|
43 |
val term_induct2 = result(); |
|
44 |
||
45 |
(*Induction on term(A) to prove an equation*) |
|
46 |
val major::prems = goal (merge_theories(Term.thy,ListFn.thy)) |
|
47 |
"[| t: term(A); \ |
|
48 |
\ !!x zs. [| x: A; zs: list(term(A)); map(f,zs) = map(g,zs) |] ==> \ |
|
49 |
\ f(Apply(x,zs)) = g(Apply(x,zs)) \ |
|
50 |
\ |] ==> f(t)=g(t)"; |
|
51 |
by (rtac (major RS Term.induct) 1); |
|
52 |
by (resolve_tac prems 1); |
|
53 |
by (REPEAT (eresolve_tac [asm_rl, map_list_Collect, list_CollectD] 1)); |
|
54 |
val term_induct_eqn = result(); |
|
55 |
||
56 |
(** Lemmas to justify using "term" in other recursive type definitions **) |
|
57 |
||
58 |
goalw Term.thy Term.defs "!!A B. A<=B ==> term(A) <= term(B)"; |
|
59 |
by (rtac lfp_mono 1); |
|
60 |
by (REPEAT (rtac Term.bnd_mono 1)); |
|
61 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1)); |
|
62 |
val term_mono = result(); |
|
63 |
||
64 |
(*Easily provable by induction also*) |
|
65 |
goalw Term.thy (Term.defs@Term.con_defs) "term(univ(A)) <= univ(A)"; |
|
66 |
by (rtac lfp_lowerbound 1); |
|
67 |
by (rtac (A_subset_univ RS univ_mono) 2); |
|
68 |
by (safe_tac ZF_cs); |
|
69 |
by (REPEAT (ares_tac [Pair_in_univ, list_univ RS subsetD] 1)); |
|
70 |
val term_univ = result(); |
|
71 |
||
434 | 72 |
val term_subset_univ = |
73 |
term_mono RS (term_univ RSN (2,subset_trans)) |> standard; |
|
0 | 74 |
|
434 | 75 |
goal Term.thy "!!t A B. [| t: term(A); A <= univ(B) |] ==> t: univ(B)"; |
76 |
by (REPEAT (ares_tac [term_subset_univ RS subsetD] 1)); |
|
77 |
val term_into_univ = result(); |