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 |
|
515
|
12 |
open Ntree;
|
486
|
13 |
|
|
14 |
goal Ntree.thy "ntree(A) = A * (UN n: nat. n -> ntree(A))";
|
515
|
15 |
by (rtac (ntree.unfold RS trans) 1);
|
|
16 |
bws ntree.con_defs;
|
|
17 |
br equalityI 1;
|
|
18 |
by (fast_tac sum_cs 1);
|
|
19 |
by (fast_tac (sum_cs addIs datatype_intrs
|
|
20 |
addDs [ntree.dom_subset RS subsetD]
|
|
21 |
addEs [nat_fun_into_univ]) 1);
|
486
|
22 |
val ntree_unfold = result();
|
|
23 |
|
|
24 |
(*A nicer induction rule than the standard one*)
|
|
25 |
val major::prems = goal Ntree.thy
|
|
26 |
"[| t: ntree(A); \
|
|
27 |
\ !!x n h. [| x: A; n: nat; h: n -> ntree(A); ALL i:n. P(h`i) \
|
|
28 |
\ |] ==> P(Branch(x,h)) \
|
|
29 |
\ |] ==> P(t)";
|
515
|
30 |
by (rtac (major RS ntree.induct) 1);
|
|
31 |
by (etac UN_E 1);
|
486
|
32 |
by (REPEAT_SOME (ares_tac prems));
|
|
33 |
by (fast_tac (ZF_cs addEs [fun_weaken_type]) 1);
|
|
34 |
by (fast_tac (ZF_cs addDs [apply_type]) 1);
|
|
35 |
val ntree_induct2 = result();
|
|
36 |
|
|
37 |
(*Induction on ntree(A) to prove an equation*)
|
|
38 |
val major::prems = goal Ntree.thy
|
|
39 |
"[| t: ntree(A); f: ntree(A)->B; g: ntree(A)->B; \
|
|
40 |
\ !!x n h. [| x: A; n: nat; h: n -> ntree(A); f O h = g O h |] ==> \
|
|
41 |
\ f ` Branch(x,h) = g ` Branch(x,h) \
|
|
42 |
\ |] ==> f`t=g`t";
|
|
43 |
by (rtac (major RS ntree_induct2) 1);
|
|
44 |
by (REPEAT_SOME (ares_tac prems));
|
|
45 |
by (cut_facts_tac prems 1);
|
|
46 |
br fun_extension 1;
|
|
47 |
by (REPEAT_SOME (ares_tac [comp_fun]));
|
|
48 |
by (asm_simp_tac (ZF_ss addsimps [comp_fun_apply]) 1);
|
|
49 |
val ntree_induct_eqn = result();
|
|
50 |
|
|
51 |
(** Lemmas to justify using "Ntree" in other recursive type definitions **)
|
|
52 |
|
515
|
53 |
goalw Ntree.thy ntree.defs "!!A B. A<=B ==> ntree(A) <= ntree(B)";
|
486
|
54 |
by (rtac lfp_mono 1);
|
515
|
55 |
by (REPEAT (rtac ntree.bnd_mono 1));
|
486
|
56 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
|
|
57 |
val ntree_mono = result();
|
|
58 |
|
|
59 |
(*Easily provable by induction also*)
|
515
|
60 |
goalw Ntree.thy (ntree.defs@ntree.con_defs) "ntree(univ(A)) <= univ(A)";
|
486
|
61 |
by (rtac lfp_lowerbound 1);
|
|
62 |
by (rtac (A_subset_univ RS univ_mono) 2);
|
|
63 |
by (safe_tac ZF_cs);
|
|
64 |
by (REPEAT (ares_tac [Pair_in_univ, nat_fun_univ RS subsetD] 1));
|
|
65 |
val ntree_univ = result();
|
|
66 |
|
|
67 |
val ntree_subset_univ =
|
|
68 |
[ntree_mono, ntree_univ] MRS subset_trans |> standard;
|
|
69 |
|
|
70 |
goal Ntree.thy "!!t A B. [| t: ntree(A); A <= univ(B) |] ==> t: univ(B)";
|
|
71 |
by (REPEAT (ares_tac [ntree_subset_univ RS subsetD] 1));
|
|
72 |
val ntree_into_univ = result();
|