1 (* Title: HOL/Induct/Tree.thy |
1 (* Title: HOL/Induct/Tree.thy |
2 Author: Stefan Berghofer, TU Muenchen |
2 Author: Stefan Berghofer, TU Muenchen |
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
4 *) |
4 *) |
5 |
5 |
6 section {* Infinitely branching trees *} |
6 section \<open>Infinitely branching trees\<close> |
7 |
7 |
8 theory Tree |
8 theory Tree |
9 imports Main |
9 imports Main |
10 begin |
10 begin |
11 |
11 |
30 "(!!x. P x ==> Q (f x)) ==> |
30 "(!!x. P x ==> Q (f x)) ==> |
31 exists_tree P ts ==> exists_tree Q (map_tree f ts)" |
31 exists_tree P ts ==> exists_tree Q (map_tree f ts)" |
32 by (induct ts) auto |
32 by (induct ts) auto |
33 |
33 |
34 |
34 |
35 subsection{*The Brouwer ordinals, as in ZF/Induct/Brouwer.thy.*} |
35 subsection\<open>The Brouwer ordinals, as in ZF/Induct/Brouwer.thy.\<close> |
36 |
36 |
37 datatype brouwer = Zero | Succ "brouwer" | Lim "nat => brouwer" |
37 datatype brouwer = Zero | Succ "brouwer" | Lim "nat => brouwer" |
38 |
38 |
39 text{*Addition of ordinals*} |
39 text\<open>Addition of ordinals\<close> |
40 primrec add :: "[brouwer,brouwer] => brouwer" |
40 primrec add :: "[brouwer,brouwer] => brouwer" |
41 where |
41 where |
42 "add i Zero = i" |
42 "add i Zero = i" |
43 | "add i (Succ j) = Succ (add i j)" |
43 | "add i (Succ j) = Succ (add i j)" |
44 | "add i (Lim f) = Lim (%n. add i (f n))" |
44 | "add i (Lim f) = Lim (%n. add i (f n))" |
45 |
45 |
46 lemma add_assoc: "add (add i j) k = add i (add j k)" |
46 lemma add_assoc: "add (add i j) k = add i (add j k)" |
47 by (induct k) auto |
47 by (induct k) auto |
48 |
48 |
49 text{*Multiplication of ordinals*} |
49 text\<open>Multiplication of ordinals\<close> |
50 primrec mult :: "[brouwer,brouwer] => brouwer" |
50 primrec mult :: "[brouwer,brouwer] => brouwer" |
51 where |
51 where |
52 "mult i Zero = Zero" |
52 "mult i Zero = Zero" |
53 | "mult i (Succ j) = add (mult i j) i" |
53 | "mult i (Succ j) = add (mult i j) i" |
54 | "mult i (Lim f) = Lim (%n. mult i (f n))" |
54 | "mult i (Lim f) = Lim (%n. mult i (f n))" |
57 by (induct k) (auto simp add: add_assoc) |
57 by (induct k) (auto simp add: add_assoc) |
58 |
58 |
59 lemma mult_assoc: "mult (mult i j) k = mult i (mult j k)" |
59 lemma mult_assoc: "mult (mult i j) k = mult i (mult j k)" |
60 by (induct k) (auto simp add: add_mult_distrib) |
60 by (induct k) (auto simp add: add_mult_distrib) |
61 |
61 |
62 text{*We could probably instantiate some axiomatic type classes and use |
62 text\<open>We could probably instantiate some axiomatic type classes and use |
63 the standard infix operators.*} |
63 the standard infix operators.\<close> |
64 |
64 |
65 subsection{*A WF Ordering for The Brouwer ordinals (Michael Compton)*} |
65 subsection\<open>A WF Ordering for The Brouwer ordinals (Michael Compton)\<close> |
66 |
66 |
67 text{*To use the function package we need an ordering on the Brouwer |
67 text\<open>To use the function package we need an ordering on the Brouwer |
68 ordinals. Start with a predecessor relation and form its transitive |
68 ordinals. Start with a predecessor relation and form its transitive |
69 closure. *} |
69 closure.\<close> |
70 |
70 |
71 definition brouwer_pred :: "(brouwer * brouwer) set" |
71 definition brouwer_pred :: "(brouwer * brouwer) set" |
72 where "brouwer_pred = (\<Union>i. {(m,n). n = Succ m \<or> (EX f. n = Lim f & m = f i)})" |
72 where "brouwer_pred = (\<Union>i. {(m,n). n = Succ m \<or> (EX f. n = Lim f & m = f i)})" |
73 |
73 |
74 definition brouwer_order :: "(brouwer * brouwer) set" |
74 definition brouwer_order :: "(brouwer * brouwer) set" |
84 by(auto simp add: brouwer_order_def brouwer_pred_def) |
84 by(auto simp add: brouwer_order_def brouwer_pred_def) |
85 |
85 |
86 lemma [simp]: "(f n, Lim f) : brouwer_order" |
86 lemma [simp]: "(f n, Lim f) : brouwer_order" |
87 by(auto simp add: brouwer_order_def brouwer_pred_def) |
87 by(auto simp add: brouwer_order_def brouwer_pred_def) |
88 |
88 |
89 text{*Example of a general function*} |
89 text\<open>Example of a general function\<close> |
90 |
90 |
91 function add2 :: "brouwer \<Rightarrow> brouwer \<Rightarrow> brouwer" |
91 function add2 :: "brouwer \<Rightarrow> brouwer \<Rightarrow> brouwer" |
92 where |
92 where |
93 "add2 i Zero = i" |
93 "add2 i Zero = i" |
94 | "add2 i (Succ j) = Succ (add2 i j)" |
94 | "add2 i (Succ j) = Succ (add2 i j)" |