src/HOL/Induct/Tree.thy
author wenzelm
Sun, 02 Nov 2014 18:21:45 +0100
changeset 58889 5b7a9633cfa8
parent 58310 91ea607a34d8
child 60530 44f9873d6f6f
permissions -rw-r--r--
modernized header uniformly as section;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Induct/Tree.thy
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
     2
    Author:     Stefan Berghofer,  TU Muenchen
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
     4
*)
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
     5
58889
5b7a9633cfa8 modernized header uniformly as section;
wenzelm
parents: 58310
diff changeset
     6
section {* Infinitely branching trees *}
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
     7
31602
59df8222c204 tuned header
haftmann
parents: 21404
diff changeset
     8
theory Tree
59df8222c204 tuned header
haftmann
parents: 21404
diff changeset
     9
imports Main
59df8222c204 tuned header
haftmann
parents: 21404
diff changeset
    10
begin
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    11
58310
91ea607a34d8 updated news
blanchet
parents: 58249
diff changeset
    12
datatype 'a tree =
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    13
    Atom 'a
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    14
  | Branch "nat => 'a tree"
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    15
46914
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    16
primrec map_tree :: "('a => 'b) => 'a tree => 'b tree"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    17
where
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    18
  "map_tree f (Atom a) = Atom (f a)"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    19
| "map_tree f (Branch ts) = Branch (\<lambda>x. map_tree f (ts x))"
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    20
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    21
lemma tree_map_compose: "map_tree g (map_tree f t) = map_tree (g \<circ> f) t"
12171
dc87f33db447 tuned inductions;
wenzelm
parents: 11649
diff changeset
    22
  by (induct t) simp_all
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    23
46914
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    24
primrec exists_tree :: "('a => bool) => 'a tree => bool"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    25
where
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    26
  "exists_tree P (Atom a) = P a"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    27
| "exists_tree P (Branch ts) = (\<exists>x. exists_tree P (ts x))"
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    28
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    29
lemma exists_map:
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    30
  "(!!x. P x ==> Q (f x)) ==>
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    31
    exists_tree P ts ==> exists_tree Q (map_tree f ts)"
12171
dc87f33db447 tuned inductions;
wenzelm
parents: 11649
diff changeset
    32
  by (induct ts) auto
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    33
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    34
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    35
subsection{*The Brouwer ordinals, as in ZF/Induct/Brouwer.thy.*}
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    36
58310
91ea607a34d8 updated news
blanchet
parents: 58249
diff changeset
    37
datatype brouwer = Zero | Succ "brouwer" | Lim "nat => brouwer"
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    38
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    39
text{*Addition of ordinals*}
46914
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    40
primrec add :: "[brouwer,brouwer] => brouwer"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    41
where
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    42
  "add i Zero = i"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    43
| "add i (Succ j) = Succ (add i j)"
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    44
| "add i (Lim f) = Lim (%n. add i (f n))"
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    45
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    46
lemma add_assoc: "add (add i j) k = add i (add j k)"
18242
2215049cd29c tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    47
  by (induct k) auto
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    48
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    49
text{*Multiplication of ordinals*}
46914
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    50
primrec mult :: "[brouwer,brouwer] => brouwer"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    51
where
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    52
  "mult i Zero = Zero"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    53
| "mult i (Succ j) = add (mult i j) i"
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    54
| "mult i (Lim f) = Lim (%n. mult i (f n))"
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    55
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    56
lemma add_mult_distrib: "mult i (add j k) = add (mult i j) (mult i k)"
18242
2215049cd29c tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    57
  by (induct k) (auto simp add: add_assoc)
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    58
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    59
lemma mult_assoc: "mult (mult i j) k = mult i (mult j k)"
18242
2215049cd29c tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    60
  by (induct k) (auto simp add: add_mult_distrib)
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    61
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    62
text{*We could probably instantiate some axiomatic type classes and use
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    63
the standard infix operators.*}
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    64
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    65
subsection{*A WF Ordering for The Brouwer ordinals (Michael Compton)*}
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    66
35439
888993948a1d tuned comment
krauss
parents: 35419
diff changeset
    67
text{*To use the function package we need an ordering on the Brouwer
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    68
  ordinals.  Start with a predecessor relation and form its transitive 
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    69
  closure. *} 
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    70
46914
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    71
definition brouwer_pred :: "(brouwer * brouwer) set"
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    72
  where "brouwer_pred = (\<Union>i. {(m,n). n = Succ m \<or> (EX f. n = Lim f & m = f i)})"
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    73
46914
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    74
definition brouwer_order :: "(brouwer * brouwer) set"
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    75
  where "brouwer_order = brouwer_pred^+"
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    76
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    77
lemma wf_brouwer_pred: "wf brouwer_pred"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    78
  by(unfold wf_def brouwer_pred_def, clarify, induct_tac x, blast+)
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    79
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    80
lemma wf_brouwer_order[simp]: "wf brouwer_order"
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    81
  by(unfold brouwer_order_def, rule wf_trancl[OF wf_brouwer_pred])
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    82
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    83
lemma [simp]: "(j, Succ j) : brouwer_order"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    84
  by(auto simp add: brouwer_order_def brouwer_pred_def)
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    85
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    86
lemma [simp]: "(f n, Lim f) : brouwer_order"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    87
  by(auto simp add: brouwer_order_def brouwer_pred_def)
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    88
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    89
text{*Example of a general function*}
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    90
46914
c2ca2c3d23a6 misc tuning;
wenzelm
parents: 39246
diff changeset
    91
function add2 :: "brouwer \<Rightarrow> brouwer \<Rightarrow> brouwer"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    92
where
39246
9e58f0499f57 modernized primrec
haftmann
parents: 35439
diff changeset
    93
  "add2 i Zero = i"
9e58f0499f57 modernized primrec
haftmann
parents: 35439
diff changeset
    94
| "add2 i (Succ j) = Succ (add2 i j)"
9e58f0499f57 modernized primrec
haftmann
parents: 35439
diff changeset
    95
| "add2 i (Lim f) = Lim (\<lambda>n. add2 i (f n))"
35419
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    96
by pat_completeness auto
d78659d1723e more recdef (and old primrec) hunting
krauss
parents: 31602
diff changeset
    97
termination by (relation "inv_image brouwer_order snd") auto
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    98
39246
9e58f0499f57 modernized primrec
haftmann
parents: 35439
diff changeset
    99
lemma add2_assoc: "add2 (add2 i j) k = add2 i (add2 j k)"
18242
2215049cd29c tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   100
  by (induct k) auto
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
   101
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
   102
end