486
|
1 |
(* Title: ZF/ex/Term.ML
|
0
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
486
|
4 |
Copyright 1994 University of Cambridge
|
0
|
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
|
486
|
11 |
(val thy = List.thy;
|
|
12 |
val thy_name = "Term";
|
0
|
13 |
val rec_specs =
|
|
14 |
[("term", "univ(A)",
|
445
|
15 |
[(["Apply"], "[i,i]=>i", NoSyn)])];
|
486
|
16 |
val rec_styp = "i=>i";
|
|
17 |
val sintrs = ["[| a: A; l: list(term(A)) |] ==> Apply(a,l) : term(A)"];
|
|
18 |
val monos = [list_mono];
|
|
19 |
val type_intrs = (list_univ RS subsetD) :: datatype_intrs;
|
|
20 |
val type_elims = []);
|
0
|
21 |
|
|
22 |
val [ApplyI] = Term.intrs;
|
|
23 |
|
434
|
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();
|