equal
deleted
inserted
replaced
11 |
11 |
12 datatype 'a tree = |
12 datatype 'a tree = |
13 Atom 'a |
13 Atom 'a |
14 | Branch "nat => 'a tree" |
14 | Branch "nat => 'a tree" |
15 |
15 |
16 primrec |
16 primrec map_tree :: "('a => 'b) => 'a tree => 'b tree" |
17 map_tree :: "('a => 'b) => 'a tree => 'b tree" |
|
18 where |
17 where |
19 "map_tree f (Atom a) = Atom (f a)" |
18 "map_tree f (Atom a) = Atom (f a)" |
20 | "map_tree f (Branch ts) = Branch (\<lambda>x. map_tree f (ts x))" |
19 | "map_tree f (Branch ts) = Branch (\<lambda>x. map_tree f (ts x))" |
21 |
20 |
22 lemma tree_map_compose: "map_tree g (map_tree f t) = map_tree (g \<circ> f) t" |
21 lemma tree_map_compose: "map_tree g (map_tree f t) = map_tree (g \<circ> f) t" |
23 by (induct t) simp_all |
22 by (induct t) simp_all |
24 |
23 |
25 primrec |
24 primrec exists_tree :: "('a => bool) => 'a tree => bool" |
26 exists_tree :: "('a => bool) => 'a tree => bool" |
|
27 where |
25 where |
28 "exists_tree P (Atom a) = P a" |
26 "exists_tree P (Atom a) = P a" |
29 | "exists_tree P (Branch ts) = (\<exists>x. exists_tree P (ts x))" |
27 | "exists_tree P (Branch ts) = (\<exists>x. exists_tree P (ts x))" |
30 |
28 |
31 lemma exists_map: |
29 lemma exists_map: |
37 subsection{*The Brouwer ordinals, as in ZF/Induct/Brouwer.thy.*} |
35 subsection{*The Brouwer ordinals, as in ZF/Induct/Brouwer.thy.*} |
38 |
36 |
39 datatype brouwer = Zero | Succ "brouwer" | Lim "nat => brouwer" |
37 datatype brouwer = Zero | Succ "brouwer" | Lim "nat => brouwer" |
40 |
38 |
41 text{*Addition of ordinals*} |
39 text{*Addition of ordinals*} |
42 primrec |
40 primrec add :: "[brouwer,brouwer] => brouwer" |
43 add :: "[brouwer,brouwer] => brouwer" |
|
44 where |
41 where |
45 "add i Zero = i" |
42 "add i Zero = i" |
46 | "add i (Succ j) = Succ (add i j)" |
43 | "add i (Succ j) = Succ (add i j)" |
47 | "add i (Lim f) = Lim (%n. add i (f n))" |
44 | "add i (Lim f) = Lim (%n. add i (f n))" |
48 |
45 |
49 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)" |
50 by (induct k) auto |
47 by (induct k) auto |
51 |
48 |
52 text{*Multiplication of ordinals*} |
49 text{*Multiplication of ordinals*} |
53 primrec |
50 primrec mult :: "[brouwer,brouwer] => brouwer" |
54 mult :: "[brouwer,brouwer] => brouwer" |
|
55 where |
51 where |
56 "mult i Zero = Zero" |
52 "mult i Zero = Zero" |
57 | "mult i (Succ j) = add (mult i j) i" |
53 | "mult i (Succ j) = add (mult i j) i" |
58 | "mult i (Lim f) = Lim (%n. mult i (f n))" |
54 | "mult i (Lim f) = Lim (%n. mult i (f n))" |
59 |
55 |
70 |
66 |
71 text{*To use the function package we need an ordering on the Brouwer |
67 text{*To use the function package we need an ordering on the Brouwer |
72 ordinals. Start with a predecessor relation and form its transitive |
68 ordinals. Start with a predecessor relation and form its transitive |
73 closure. *} |
69 closure. *} |
74 |
70 |
75 definition |
71 definition brouwer_pred :: "(brouwer * brouwer) set" |
76 brouwer_pred :: "(brouwer * brouwer) set" where |
72 where "brouwer_pred = (\<Union>i. {(m,n). n = Succ m \<or> (EX f. n = Lim f & m = f i)})" |
77 "brouwer_pred = (\<Union>i. {(m,n). n = Succ m \<or> (EX f. n = Lim f & m = f i)})" |
|
78 |
73 |
79 definition |
74 definition brouwer_order :: "(brouwer * brouwer) set" |
80 brouwer_order :: "(brouwer * brouwer) set" where |
75 where "brouwer_order = brouwer_pred^+" |
81 "brouwer_order = brouwer_pred^+" |
|
82 |
76 |
83 lemma wf_brouwer_pred: "wf brouwer_pred" |
77 lemma wf_brouwer_pred: "wf brouwer_pred" |
84 by(unfold wf_def brouwer_pred_def, clarify, induct_tac x, blast+) |
78 by(unfold wf_def brouwer_pred_def, clarify, induct_tac x, blast+) |
85 |
79 |
86 lemma wf_brouwer_order[simp]: "wf brouwer_order" |
80 lemma wf_brouwer_order[simp]: "wf brouwer_order" |
92 lemma [simp]: "(f n, Lim f) : brouwer_order" |
86 lemma [simp]: "(f n, Lim f) : brouwer_order" |
93 by(auto simp add: brouwer_order_def brouwer_pred_def) |
87 by(auto simp add: brouwer_order_def brouwer_pred_def) |
94 |
88 |
95 text{*Example of a general function*} |
89 text{*Example of a general function*} |
96 |
90 |
97 function |
91 function add2 :: "brouwer \<Rightarrow> brouwer \<Rightarrow> brouwer" |
98 add2 :: "brouwer \<Rightarrow> brouwer \<Rightarrow> brouwer" |
|
99 where |
92 where |
100 "add2 i Zero = i" |
93 "add2 i Zero = i" |
101 | "add2 i (Succ j) = Succ (add2 i j)" |
94 | "add2 i (Succ j) = Succ (add2 i j)" |
102 | "add2 i (Lim f) = Lim (\<lambda>n. add2 i (f n))" |
95 | "add2 i (Lim f) = Lim (\<lambda>n. add2 i (f n))" |
103 by pat_completeness auto |
96 by pat_completeness auto |