src/ZF/Induct/Tree_Forest.thy
author wenzelm
Mon, 07 Jun 2010 17:13:36 +0200
changeset 37359 7b0ccc20cddc
parent 35762 af3ff2ba4c54
child 41526 54b4686704af
permissions -rw-r--r--
made SML/NJ happy again;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     1
(*  Title:      ZF/Induct/Tree_Forest.thy
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     3
    Copyright   1994  University of Cambridge
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     4
*)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     5
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     6
header {* Trees and forests, a mutually recursive type definition *}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     7
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 13535
diff changeset
     8
theory Tree_Forest imports Main begin
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     9
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    10
subsection {* Datatype definition *}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    11
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    12
consts
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    13
  tree :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    14
  forest :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    15
  tree_forest :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    16
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    17
datatype "tree(A)" = Tcons ("a \<in> A", "f \<in> forest(A)")
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    18
  and "forest(A)" = Fnil | Fcons ("t \<in> tree(A)", "f \<in> forest(A)")
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    19
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    20
(* FIXME *)
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    21
lemmas tree'induct =
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    22
    tree_forest.mutual_induct [THEN conjunct1, THEN spec, THEN [2] rev_mp, of concl: _ t, standard, consumes 1]
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    23
  and forest'induct =
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    24
    tree_forest.mutual_induct [THEN conjunct2, THEN spec, THEN [2] rev_mp, of concl: _ f, standard, consumes 1]
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    25
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    26
declare tree_forest.intros [simp, TC]
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    27
12216
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
    28
lemma tree_def: "tree(A) == Part(tree_forest(A), Inl)"
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    29
  by (simp only: tree_forest.defs)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    30
12216
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
    31
lemma forest_def: "forest(A) == Part(tree_forest(A), Inr)"
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    32
  by (simp only: tree_forest.defs)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    33
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    34
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    35
text {*
12205
wenzelm
parents: 12201
diff changeset
    36
  \medskip @{term "tree_forest(A)"} as the union of @{term "tree(A)"}
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    37
  and @{term "forest(A)"}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    38
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    39
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    40
lemma tree_subset_TF: "tree(A) \<subseteq> tree_forest(A)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    41
  apply (unfold tree_forest.defs)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    42
  apply (rule Part_subset)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    43
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    44
12243
wenzelm
parents: 12216
diff changeset
    45
lemma treeI [TC]: "x \<in> tree(A) ==> x \<in> tree_forest(A)"
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    46
  by (rule tree_subset_TF [THEN subsetD])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    47
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    48
lemma forest_subset_TF: "forest(A) \<subseteq> tree_forest(A)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    49
  apply (unfold tree_forest.defs)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    50
  apply (rule Part_subset)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    51
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    52
13535
007559e981c7 *** empty log message ***
wenzelm
parents: 12937
diff changeset
    53
lemma treeI' [TC]: "x \<in> forest(A) ==> x \<in> tree_forest(A)"
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    54
  by (rule forest_subset_TF [THEN subsetD])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    55
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    56
lemma TF_equals_Un: "tree(A) \<union> forest(A) = tree_forest(A)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    57
  apply (insert tree_subset_TF forest_subset_TF)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    58
  apply (auto intro!: equalityI tree_forest.intros elim: tree_forest.cases)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    59
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    60
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
    61
lemma
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
    62
  notes rews = tree_forest.con_defs tree_def forest_def
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
    63
  shows
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
    64
    tree_forest_unfold: "tree_forest(A) =
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
    65
      (A \<times> forest(A)) + ({0} + tree(A) \<times> forest(A))"
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    66
    -- {* NOT useful, but interesting \dots *}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    67
  apply (unfold tree_def forest_def)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    68
  apply (fast intro!: tree_forest.intros [unfolded rews, THEN PartD1]
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    69
    elim: tree_forest.cases [unfolded rews])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    70
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    71
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    72
lemma tree_forest_unfold':
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    73
  "tree_forest(A) =
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    74
    A \<times> Part(tree_forest(A), \<lambda>w. Inr(w)) +
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    75
    {0} + Part(tree_forest(A), \<lambda>w. Inl(w)) * Part(tree_forest(A), \<lambda>w. Inr(w))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    76
  by (rule tree_forest_unfold [unfolded tree_def forest_def])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    77
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    78
lemma tree_unfold: "tree(A) = {Inl(x). x \<in> A \<times> forest(A)}"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    79
  apply (unfold tree_def forest_def)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    80
  apply (rule Part_Inl [THEN subst])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    81
  apply (rule tree_forest_unfold' [THEN subst_context])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    82
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    83
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    84
lemma forest_unfold: "forest(A) = {Inr(x). x \<in> {0} + tree(A)*forest(A)}"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    85
  apply (unfold tree_def forest_def)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    86
  apply (rule Part_Inr [THEN subst])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    87
  apply (rule tree_forest_unfold' [THEN subst_context])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    88
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    89
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    90
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    91
  \medskip Type checking for recursor: Not needed; possibly interesting?
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    92
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    93
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    94
lemma TF_rec_type:
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    95
  "[| z \<in> tree_forest(A);
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    96
      !!x f r. [| x \<in> A;  f \<in> forest(A);  r \<in> C(f)
12243
wenzelm
parents: 12216
diff changeset
    97
                |] ==> b(x,f,r) \<in> C(Tcons(x,f));
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    98
      c \<in> C(Fnil);
12243
wenzelm
parents: 12216
diff changeset
    99
      !!t f r1 r2. [| t \<in> tree(A);  f \<in> forest(A);  r1 \<in> C(t); r2 \<in> C(f)
wenzelm
parents: 12216
diff changeset
   100
                    |] ==> d(t,f,r1,r2) \<in> C(Fcons(t,f))
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   101
   |] ==> tree_forest_rec(b,c,d,z) \<in> C(z)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   102
  by (induct_tac z) simp_all
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   103
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   104
lemma tree_forest_rec_type:
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   105
  "[| !!x f r. [| x \<in> A;  f \<in> forest(A);  r \<in> D(f)
12243
wenzelm
parents: 12216
diff changeset
   106
                |] ==> b(x,f,r) \<in> C(Tcons(x,f));
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   107
      c \<in> D(Fnil);
12243
wenzelm
parents: 12216
diff changeset
   108
      !!t f r1 r2. [| t \<in> tree(A);  f \<in> forest(A);  r1 \<in> C(t); r2 \<in> D(f)
wenzelm
parents: 12216
diff changeset
   109
                    |] ==> d(t,f,r1,r2) \<in> D(Fcons(t,f))
wenzelm
parents: 12216
diff changeset
   110
   |] ==> (\<forall>t \<in> tree(A).    tree_forest_rec(b,c,d,t) \<in> C(t)) \<and>
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   111
          (\<forall>f \<in> forest(A). tree_forest_rec(b,c,d,f) \<in> D(f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   112
    -- {* Mutually recursive version. *}
12243
wenzelm
parents: 12216
diff changeset
   113
  apply (unfold Ball_def)
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   114
  apply (rule tree_forest.mutual_induct)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   115
  apply simp_all
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   116
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   117
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   118
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   119
subsection {* Operations *}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   120
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   121
consts
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   122
  map :: "[i => i, i] => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   123
  size :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   124
  preorder :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   125
  list_of_TF :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   126
  of_list :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   127
  reflect :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   128
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   129
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   130
  "list_of_TF (Tcons(x,f)) = [Tcons(x,f)]"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   131
  "list_of_TF (Fnil) = []"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   132
  "list_of_TF (Fcons(t,tf)) = Cons (t, list_of_TF(tf))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   133
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   134
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   135
  "of_list([]) = Fnil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   136
  "of_list(Cons(t,l)) = Fcons(t, of_list(l))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   137
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   138
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   139
  "map (h, Tcons(x,f)) = Tcons(h(x), map(h,f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   140
  "map (h, Fnil) = Fnil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   141
  "map (h, Fcons(t,tf)) = Fcons (map(h, t), map(h, tf))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   142
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   143
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   144
  "size (Tcons(x,f)) = succ(size(f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   145
  "size (Fnil) = 0"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   146
  "size (Fcons(t,tf)) = size(t) #+ size(tf)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   147
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   148
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   149
  "preorder (Tcons(x,f)) = Cons(x, preorder(f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   150
  "preorder (Fnil) = Nil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   151
  "preorder (Fcons(t,tf)) = preorder(t) @ preorder(tf)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   152
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   153
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   154
  "reflect (Tcons(x,f)) = Tcons(x, reflect(f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   155
  "reflect (Fnil) = Fnil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   156
  "reflect (Fcons(t,tf)) =
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   157
    of_list (list_of_TF (reflect(tf)) @ Cons(reflect(t), Nil))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   158
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   159
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   160
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   161
  \medskip @{text list_of_TF} and @{text of_list}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   162
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   163
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   164
lemma list_of_TF_type [TC]:
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   165
    "z \<in> tree_forest(A) ==> list_of_TF(z) \<in> list(tree(A))"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   166
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   167
12243
wenzelm
parents: 12216
diff changeset
   168
lemma of_list_type [TC]: "l \<in> list(tree(A)) ==> of_list(l) \<in> forest(A)"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   169
  by (induct set: list) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   170
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   171
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   172
  \medskip @{text map}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   173
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   174
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
   175
lemma
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   176
  assumes "!!x. x \<in> A ==> h(x): B"
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
   177
  shows map_tree_type: "t \<in> tree(A) ==> map(h,t) \<in> tree(B)"
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
   178
    and map_forest_type: "f \<in> forest(A) ==> map(h,f) \<in> forest(B)"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   179
  using prems
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   180
  by (induct rule: tree'induct forest'induct) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   181
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   182
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   183
  \medskip @{text size}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   184
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   185
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   186
lemma size_type [TC]: "z \<in> tree_forest(A) ==> size(z) \<in> nat"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   187
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   188
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   189
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   190
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   191
  \medskip @{text preorder}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   192
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   193
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   194
lemma preorder_type [TC]: "z \<in> tree_forest(A) ==> preorder(z) \<in> list(A)"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   195
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   196
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   197
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   198
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   199
  \medskip Theorems about @{text list_of_TF} and @{text of_list}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   200
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   201
18415
eb68dc98bda2 improved proofs;
wenzelm
parents: 16417
diff changeset
   202
lemma forest_induct [consumes 1, case_names Fnil Fcons]:
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   203
  "[| f \<in> forest(A);
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   204
      R(Fnil);
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   205
      !!t f. [| t \<in> tree(A);  f \<in> forest(A);  R(f) |] ==> R(Fcons(t,f))
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   206
   |] ==> R(f)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   207
  -- {* Essentially the same as list induction. *}
12610
8b9845807f77 tuned document sources;
wenzelm
parents: 12243
diff changeset
   208
  apply (erule tree_forest.mutual_induct
8b9845807f77 tuned document sources;
wenzelm
parents: 12243
diff changeset
   209
      [THEN conjunct2, THEN spec, THEN [2] rev_mp])
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   210
    apply (rule TrueI)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   211
   apply simp
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   212
  apply simp
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   213
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   214
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   215
lemma forest_iso: "f \<in> forest(A) ==> of_list(list_of_TF(f)) = f"
18415
eb68dc98bda2 improved proofs;
wenzelm
parents: 16417
diff changeset
   216
  by (induct rule: forest_induct) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   217
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   218
lemma tree_list_iso: "ts: list(tree(A)) ==> list_of_TF(of_list(ts)) = ts"
18415
eb68dc98bda2 improved proofs;
wenzelm
parents: 16417
diff changeset
   219
  by (induct set: list) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   220
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   221
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   222
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   223
  \medskip Theorems about @{text map}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   224
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   225
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   226
lemma map_ident: "z \<in> tree_forest(A) ==> map(\<lambda>u. u, z) = z"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   227
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   228
12216
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
   229
lemma map_compose:
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
   230
    "z \<in> tree_forest(A) ==> map(h, map(j,z)) = map(\<lambda>u. h(j(u)), z)"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   231
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   232
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   233
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   234
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   235
  \medskip Theorems about @{text size}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   236
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   237
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   238
lemma size_map: "z \<in> tree_forest(A) ==> size(map(h,z)) = size(z)"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   239
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   240
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   241
lemma size_length: "z \<in> tree_forest(A) ==> size(z) = length(preorder(z))"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   242
  by (induct set: tree_forest) (simp_all add: length_app)
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   243
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   244
text {*
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   245
  \medskip Theorems about @{text preorder}.
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   246
*}
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   247
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   248
lemma preorder_map:
26056
6a0801279f4c Made theory names in ZF disjoint from HOL theory names to allow loading both developments
krauss
parents: 18460
diff changeset
   249
    "z \<in> tree_forest(A) ==> preorder(map(h,z)) = List_ZF.map(h, preorder(z))"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   250
  by (induct set: tree_forest) (simp_all add: map_app_distrib)
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   251
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   252
end