src/HOL/Induct/Tree.thy
author wenzelm
Sat, 27 May 2006 17:42:02 +0200
changeset 19736 d8d0f8f51d69
parent 18242 2215049cd29c
child 21404 eb85850d3eb7
permissions -rw-r--r--
tuned;
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
    ID:         $Id$
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
     3
    Author:     Stefan Berghofer,  TU Muenchen
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
     4
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
     5
*)
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
     6
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
     7
header {* Infinitely branching trees *}
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
     8
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 16174
diff changeset
     9
theory Tree imports Main begin
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    10
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    11
datatype 'a tree =
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    12
    Atom 'a
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    13
  | Branch "nat => 'a tree"
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    14
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    15
consts
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    16
  map_tree :: "('a => 'b) => 'a tree => 'b tree"
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    17
primrec
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    18
  "map_tree f (Atom a) = Atom (f a)"
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    19
  "map_tree f (Branch ts) = Branch (\<lambda>x. map_tree f (ts x))"
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
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    24
consts
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    25
  exists_tree :: "('a => bool) => 'a tree => bool"
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    26
primrec
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    27
  "exists_tree P (Atom a) = P a"
11046
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    28
  "exists_tree P (Branch ts) = (\<exists>x. exists_tree P (ts x))"
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    29
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    30
lemma exists_map:
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    31
  "(!!x. P x ==> Q (f x)) ==>
b5f5942781a0 Induct: converted some theories to new-style format;
wenzelm
parents: 7018
diff changeset
    32
    exists_tree P ts ==> exists_tree Q (map_tree f ts)"
12171
dc87f33db447 tuned inductions;
wenzelm
parents: 11649
diff changeset
    33
  by (induct ts) auto
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
    34
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    35
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    36
subsection{*The Brouwer ordinals, as in ZF/Induct/Brouwer.thy.*}
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    37
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    38
datatype brouwer = Zero | Succ "brouwer" | Lim "nat => brouwer"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    39
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    40
text{*Addition of ordinals*}
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    41
consts
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    42
  add :: "[brouwer,brouwer] => brouwer"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    43
primrec
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    44
  "add i Zero = i"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    45
  "add i (Succ j) = Succ (add i j)"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    46
  "add i (Lim f) = Lim (%n. add i (f n))"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    47
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    48
lemma add_assoc: "add (add i j) k = add i (add j k)"
18242
2215049cd29c tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    49
  by (induct k) auto
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    50
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    51
text{*Multiplication of ordinals*}
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    52
consts
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    53
  mult :: "[brouwer,brouwer] => brouwer"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    54
primrec
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    55
  "mult i Zero = Zero"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    56
  "mult i (Succ j) = add (mult i j) i"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    57
  "mult i (Lim f) = Lim (%n. mult i (f n))"
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    58
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    59
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
    60
  by (induct k) (auto simp add: add_assoc)
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    61
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    62
lemma mult_assoc: "mult (mult i j) k = mult i (mult j k)"
18242
2215049cd29c tuned induct proofs;
wenzelm
parents: 16417
diff changeset
    63
  by (induct k) (auto simp add: add_mult_distrib)
16078
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    64
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    65
text{*We could probably instantiate some axiomatic type classes and use
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    66
the standard infix operators.*}
e1364521a250 new Brouwer ordinal example
paulson
parents: 14981
diff changeset
    67
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    68
subsection{*A WF Ordering for The Brouwer ordinals (Michael Compton)*}
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    69
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    70
text{*To define recdef style functions we need an ordering on the Brouwer
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    71
  ordinals.  Start with a predecessor relation and form its transitive 
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    72
  closure. *} 
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    73
19736
wenzelm
parents: 18242
diff changeset
    74
definition
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    75
  brouwer_pred :: "(brouwer * brouwer) set"
19736
wenzelm
parents: 18242
diff changeset
    76
  "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
    77
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    78
  brouwer_order :: "(brouwer * brouwer) set"
19736
wenzelm
parents: 18242
diff changeset
    79
  "brouwer_order = brouwer_pred^+"
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    80
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    81
lemma wf_brouwer_pred: "wf brouwer_pred"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    82
  by(unfold wf_def brouwer_pred_def, clarify, induct_tac x, blast+)
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    83
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    84
lemma wf_brouwer_order: "wf brouwer_order"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    85
  by(unfold brouwer_order_def, rule wf_trancl[OF wf_brouwer_pred])
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    86
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    87
lemma [simp]: "(j, Succ j) : brouwer_order"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    88
  by(auto simp add: brouwer_order_def brouwer_pred_def)
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    89
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    90
lemma [simp]: "(f n, Lim f) : brouwer_order"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    91
  by(auto simp add: brouwer_order_def brouwer_pred_def)
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    92
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    93
text{*Example of a recdef*}
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    94
consts
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    95
  add2 :: "(brouwer*brouwer) => brouwer"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    96
recdef add2 "inv_image brouwer_order (\<lambda> (x,y). y)"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    97
  "add2 (i, Zero) = i"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    98
  "add2 (i, (Succ j)) = Succ (add2 (i, j))"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
    99
  "add2 (i, (Lim f)) = Lim (\<lambda> n. add2 (i, (f n)))"
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
   100
  (hints recdef_wf: wf_brouwer_order)
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
   101
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
   102
lemma add2_assoc: "add2 (add2 (i, j), k) = add2 (i, add2 (j, k))"
18242
2215049cd29c tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   103
  by (induct k) auto
16174
a55c796b1f79 ordering for the ordinals
paulson
parents: 16078
diff changeset
   104
7018
ae18bb3075c3 Infinitely branching trees.
berghofe
parents:
diff changeset
   105
end