486
|
1 |
(* Title: ZF/ex/Ntree.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1994 University of Cambridge
|
|
5 |
|
|
6 |
Datatype definition n-ary branching trees
|
|
7 |
Demonstrates a simple use of function space in a datatype definition
|
|
8 |
|
|
9 |
Based upon ex/Term.ML
|
|
10 |
*)
|
|
11 |
|
|
12 |
structure Ntree = Datatype_Fun
|
|
13 |
(val thy = Univ.thy;
|
|
14 |
val thy_name = "Ntree";
|
|
15 |
val rec_specs =
|
|
16 |
[("ntree", "univ(A)",
|
|
17 |
[(["Branch"], "[i,i]=>i", NoSyn)])];
|
|
18 |
val rec_styp = "i=>i";
|
|
19 |
val sintrs =
|
|
20 |
["[| a: A; n: nat; h: n -> ntree(A) |] ==> Branch(a,h) : ntree(A)"];
|
|
21 |
val monos = [Pi_mono];
|
|
22 |
val type_intrs = (nat_fun_univ RS subsetD) :: datatype_intrs;
|
|
23 |
val type_elims = []);
|
|
24 |
|
|
25 |
val [BranchI] = Ntree.intrs;
|
|
26 |
|
|
27 |
goal Ntree.thy "ntree(A) = A * (UN n: nat. n -> ntree(A))";
|
|
28 |
by (rtac (Ntree.unfold RS trans) 1);
|
|
29 |
bws Ntree.con_defs;
|
|
30 |
by (fast_tac (sum_cs addIs ([equalityI] @ datatype_intrs)
|
|
31 |
addDs [Ntree.dom_subset RS subsetD]
|
|
32 |
addEs [A_into_univ, nat_fun_into_univ]) 1);
|
|
33 |
val ntree_unfold = result();
|
|
34 |
|
|
35 |
(*A nicer induction rule than the standard one*)
|
|
36 |
val major::prems = goal Ntree.thy
|
|
37 |
"[| t: ntree(A); \
|
|
38 |
\ !!x n h. [| x: A; n: nat; h: n -> ntree(A); ALL i:n. P(h`i) \
|
|
39 |
\ |] ==> P(Branch(x,h)) \
|
|
40 |
\ |] ==> P(t)";
|
|
41 |
by (rtac (major RS Ntree.induct) 1);
|
|
42 |
by (REPEAT_SOME (ares_tac prems));
|
|
43 |
by (fast_tac (ZF_cs addEs [fun_weaken_type]) 1);
|
|
44 |
by (fast_tac (ZF_cs addDs [apply_type]) 1);
|
|
45 |
val ntree_induct2 = result();
|
|
46 |
|
|
47 |
(*Induction on ntree(A) to prove an equation*)
|
|
48 |
val major::prems = goal Ntree.thy
|
|
49 |
"[| t: ntree(A); f: ntree(A)->B; g: ntree(A)->B; \
|
|
50 |
\ !!x n h. [| x: A; n: nat; h: n -> ntree(A); f O h = g O h |] ==> \
|
|
51 |
\ f ` Branch(x,h) = g ` Branch(x,h) \
|
|
52 |
\ |] ==> f`t=g`t";
|
|
53 |
by (rtac (major RS ntree_induct2) 1);
|
|
54 |
by (REPEAT_SOME (ares_tac prems));
|
|
55 |
by (cut_facts_tac prems 1);
|
|
56 |
br fun_extension 1;
|
|
57 |
by (REPEAT_SOME (ares_tac [comp_fun]));
|
|
58 |
by (asm_simp_tac (ZF_ss addsimps [comp_fun_apply]) 1);
|
|
59 |
val ntree_induct_eqn = result();
|
|
60 |
|
|
61 |
(** Lemmas to justify using "Ntree" in other recursive type definitions **)
|
|
62 |
|
|
63 |
goalw Ntree.thy Ntree.defs "!!A B. A<=B ==> ntree(A) <= ntree(B)";
|
|
64 |
by (rtac lfp_mono 1);
|
|
65 |
by (REPEAT (rtac Ntree.bnd_mono 1));
|
|
66 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
|
|
67 |
val ntree_mono = result();
|
|
68 |
|
|
69 |
(*Easily provable by induction also*)
|
|
70 |
goalw Ntree.thy (Ntree.defs@Ntree.con_defs) "ntree(univ(A)) <= univ(A)";
|
|
71 |
by (rtac lfp_lowerbound 1);
|
|
72 |
by (rtac (A_subset_univ RS univ_mono) 2);
|
|
73 |
by (safe_tac ZF_cs);
|
|
74 |
by (REPEAT (ares_tac [Pair_in_univ, nat_fun_univ RS subsetD] 1));
|
|
75 |
val ntree_univ = result();
|
|
76 |
|
|
77 |
val ntree_subset_univ =
|
|
78 |
[ntree_mono, ntree_univ] MRS subset_trans |> standard;
|
|
79 |
|
|
80 |
goal Ntree.thy "!!t A B. [| t: ntree(A); A <= univ(B) |] ==> t: univ(B)";
|
|
81 |
by (REPEAT (ares_tac [ntree_subset_univ RS subsetD] 1));
|
|
82 |
val ntree_into_univ = result();
|