author | wenzelm |
Tue, 28 Oct 1997 17:58:35 +0100 | |
changeset 4029 | 22f2d1b17f97 |
parent 2496 | 40efb87985b5 |
child 4091 | 771b1f6422a8 |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/ex/Ntree.ML |
486 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
486 | 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 |
|
539 | 14 |
(** ntree **) |
15 |
||
486 | 16 |
goal Ntree.thy "ntree(A) = A * (UN n: nat. n -> ntree(A))"; |
529
f0d16216e394
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
515
diff
changeset
|
17 |
let open ntree; val rew = rewrite_rule con_defs in |
2496 | 18 |
by (fast_tac (!claset addSIs (map rew intrs) addEs [rew elim]) 1) |
529
f0d16216e394
ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents:
515
diff
changeset
|
19 |
end; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
20 |
qed "ntree_unfold"; |
486 | 21 |
|
22 |
(*A nicer induction rule than the standard one*) |
|
23 |
val major::prems = goal Ntree.thy |
|
1461 | 24 |
"[| t: ntree(A); \ |
486 | 25 |
\ !!x n h. [| x: A; n: nat; h: n -> ntree(A); ALL i:n. P(h`i) \ |
1461 | 26 |
\ |] ==> P(Branch(x,h)) \ |
486 | 27 |
\ |] ==> P(t)"; |
515 | 28 |
by (rtac (major RS ntree.induct) 1); |
29 |
by (etac UN_E 1); |
|
486 | 30 |
by (REPEAT_SOME (ares_tac prems)); |
2469 | 31 |
by (fast_tac (!claset addEs [fun_weaken_type]) 1); |
32 |
by (fast_tac (!claset addDs [apply_type]) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
33 |
qed "ntree_induct"; |
486 | 34 |
|
35 |
(*Induction on ntree(A) to prove an equation*) |
|
36 |
val major::prems = goal Ntree.thy |
|
1461 | 37 |
"[| t: ntree(A); f: ntree(A)->B; g: ntree(A)->B; \ |
486 | 38 |
\ !!x n h. [| x: A; n: nat; h: n -> ntree(A); f O h = g O h |] ==> \ |
1461 | 39 |
\ f ` Branch(x,h) = g ` Branch(x,h) \ |
486 | 40 |
\ |] ==> f`t=g`t"; |
539 | 41 |
by (rtac (major RS ntree_induct) 1); |
486 | 42 |
by (REPEAT_SOME (ares_tac prems)); |
43 |
by (cut_facts_tac prems 1); |
|
1461 | 44 |
by (rtac fun_extension 1); |
486 | 45 |
by (REPEAT_SOME (ares_tac [comp_fun])); |
2469 | 46 |
by (asm_simp_tac (!simpset addsimps [comp_fun_apply]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
47 |
qed "ntree_induct_eqn"; |
486 | 48 |
|
49 |
(** Lemmas to justify using "Ntree" in other recursive type definitions **) |
|
50 |
||
515 | 51 |
goalw Ntree.thy ntree.defs "!!A B. A<=B ==> ntree(A) <= ntree(B)"; |
486 | 52 |
by (rtac lfp_mono 1); |
515 | 53 |
by (REPEAT (rtac ntree.bnd_mono 1)); |
486 | 54 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
55 |
qed "ntree_mono"; |
486 | 56 |
|
57 |
(*Easily provable by induction also*) |
|
515 | 58 |
goalw Ntree.thy (ntree.defs@ntree.con_defs) "ntree(univ(A)) <= univ(A)"; |
486 | 59 |
by (rtac lfp_lowerbound 1); |
60 |
by (rtac (A_subset_univ RS univ_mono) 2); |
|
2469 | 61 |
by (safe_tac (!claset)); |
486 | 62 |
by (REPEAT (ares_tac [Pair_in_univ, nat_fun_univ RS subsetD] 1)); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
63 |
qed "ntree_univ"; |
486 | 64 |
|
539 | 65 |
val ntree_subset_univ = [ntree_mono, ntree_univ] MRS subset_trans |> standard; |
66 |
||
67 |
||
68 |
(** maptree **) |
|
69 |
||
70 |
goal Ntree.thy "maptree(A) = A * (maptree(A) -||> maptree(A))"; |
|
71 |
let open maptree; val rew = rewrite_rule con_defs in |
|
2496 | 72 |
by (fast_tac (!claset addSIs (map rew intrs) addEs [rew elim]) 1) |
539 | 73 |
end; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
74 |
qed "maptree_unfold"; |
486 | 75 |
|
539 | 76 |
(*A nicer induction rule than the standard one*) |
77 |
val major::prems = goal Ntree.thy |
|
1461 | 78 |
"[| t: maptree(A); \ |
79 |
\ !!x n h. [| x: A; h: maptree(A) -||> maptree(A); \ |
|
80 |
\ ALL y: field(h). P(y) \ |
|
81 |
\ |] ==> P(Sons(x,h)) \ |
|
539 | 82 |
\ |] ==> P(t)"; |
83 |
by (rtac (major RS maptree.induct) 1); |
|
84 |
by (REPEAT_SOME (ares_tac prems)); |
|
85 |
by (eresolve_tac [Collect_subset RS FiniteFun_mono1 RS subsetD] 1); |
|
86 |
by (dresolve_tac [FiniteFun.dom_subset RS subsetD] 1); |
|
87 |
by (dresolve_tac [Fin.dom_subset RS subsetD] 1); |
|
2469 | 88 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
89 |
qed "maptree_induct"; |
539 | 90 |
|
91 |
||
92 |
(** maptree2 **) |
|
93 |
||
94 |
goal Ntree.thy "maptree2(A,B) = A * (B -||> maptree2(A,B))"; |
|
95 |
let open maptree2; val rew = rewrite_rule con_defs in |
|
2496 | 96 |
by (fast_tac (!claset addSIs (map rew intrs) addEs [rew elim]) 1) |
539 | 97 |
end; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
98 |
qed "maptree2_unfold"; |
539 | 99 |
|
100 |
(*A nicer induction rule than the standard one*) |
|
101 |
val major::prems = goal Ntree.thy |
|
1461 | 102 |
"[| t: maptree2(A,B); \ |
539 | 103 |
\ !!x n h. [| x: A; h: B -||> maptree2(A,B); ALL y:range(h). P(y) \ |
1461 | 104 |
\ |] ==> P(Sons2(x,h)) \ |
539 | 105 |
\ |] ==> P(t)"; |
106 |
by (rtac (major RS maptree2.induct) 1); |
|
107 |
by (REPEAT_SOME (ares_tac prems)); |
|
108 |
by (eresolve_tac [[subset_refl, Collect_subset] MRS |
|
1461 | 109 |
FiniteFun_mono RS subsetD] 1); |
539 | 110 |
by (dresolve_tac [FiniteFun.dom_subset RS subsetD] 1); |
111 |
by (dresolve_tac [Fin.dom_subset RS subsetD] 1); |
|
2469 | 112 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
539
diff
changeset
|
113 |
qed "maptree2_induct"; |
539 | 114 |