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