src/ZF/Induct/Tree_Forest.thy
author wenzelm
Mon, 24 Apr 2017 23:10:01 +0200
changeset 65576 8376f83f9094
parent 65449 c82e63b11b8b
child 68233 5e0e9376b2b0
permissions -rw-r--r--
recovered document from 0f3fdf689bf9;
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
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
     6
section \<open>Trees and forests, a mutually recursive type definition\<close>
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     7
65449
c82e63b11b8b clarified main ZF.thy / ZFC.thy, and avoid name clash with global HOL/Main.thy;
wenzelm
parents: 61798
diff changeset
     8
theory Tree_Forest imports ZF begin
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
     9
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
    10
subsection \<open>Datatype definition\<close>
12201
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 =
45602
2a858377c3d2 eliminated obsolete "standard";
wenzelm
parents: 41526
diff changeset
    22
    tree_forest.mutual_induct [THEN conjunct1, THEN spec, THEN [2] rev_mp, of concl: _ t, consumes 1]
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    23
  and forest'induct =
45602
2a858377c3d2 eliminated obsolete "standard";
wenzelm
parents: 41526
diff changeset
    24
    tree_forest.mutual_induct [THEN conjunct2, THEN spec, THEN [2] rev_mp, of concl: _ f, consumes 1]
2a858377c3d2 eliminated obsolete "standard";
wenzelm
parents: 41526
diff changeset
    25
  for t
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
    26
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    27
declare tree_forest.intros [simp, TC]
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    28
12216
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
    29
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
    30
  by (simp only: tree_forest.defs)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    31
12216
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
    32
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
    33
  by (simp only: tree_forest.defs)
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
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
    36
text \<open>
12205
wenzelm
parents: 12201
diff changeset
    37
  \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
    38
  and @{term "forest(A)"}.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
    39
\<close>
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    40
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    41
lemma tree_subset_TF: "tree(A) \<subseteq> tree_forest(A)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    42
  apply (unfold tree_forest.defs)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    43
  apply (rule Part_subset)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    44
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    45
12243
wenzelm
parents: 12216
diff changeset
    46
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
    47
  by (rule tree_subset_TF [THEN subsetD])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    48
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    49
lemma forest_subset_TF: "forest(A) \<subseteq> tree_forest(A)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    50
  apply (unfold tree_forest.defs)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    51
  apply (rule Part_subset)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    52
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    53
13535
007559e981c7 *** empty log message ***
wenzelm
parents: 12937
diff changeset
    54
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
    55
  by (rule forest_subset_TF [THEN subsetD])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    56
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    57
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
    58
  apply (insert tree_subset_TF forest_subset_TF)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    59
  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
    60
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    61
60375
wenzelm
parents: 58871
diff changeset
    62
lemma tree_forest_unfold:
wenzelm
parents: 58871
diff changeset
    63
  "tree_forest(A) = (A \<times> forest(A)) + ({0} + tree(A) \<times> forest(A))"
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
    64
    \<comment> \<open>NOT useful, but interesting \dots\<close>
60375
wenzelm
parents: 58871
diff changeset
    65
  supply rews = tree_forest.con_defs tree_def forest_def
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    66
  apply (unfold tree_def forest_def)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    67
  apply (fast intro!: tree_forest.intros [unfolded rews, THEN PartD1]
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    68
    elim: tree_forest.cases [unfolded rews])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    69
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    70
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    71
lemma tree_forest_unfold':
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    72
  "tree_forest(A) =
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    73
    A \<times> Part(tree_forest(A), \<lambda>w. Inr(w)) +
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    74
    {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
    75
  by (rule tree_forest_unfold [unfolded tree_def forest_def])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    76
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    77
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
    78
  apply (unfold tree_def forest_def)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    79
  apply (rule Part_Inl [THEN subst])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    80
  apply (rule tree_forest_unfold' [THEN subst_context])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    81
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    82
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    83
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
    84
  apply (unfold tree_def forest_def)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    85
  apply (rule Part_Inr [THEN subst])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    86
  apply (rule tree_forest_unfold' [THEN subst_context])
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    87
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    88
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
    89
text \<open>
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    90
  \medskip Type checking for recursor: Not needed; possibly interesting?
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
    91
\<close>
12201
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
lemma TF_rec_type:
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    94
  "[| z \<in> tree_forest(A);
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    95
      !!x f r. [| x \<in> A;  f \<in> forest(A);  r \<in> C(f)
12243
wenzelm
parents: 12216
diff changeset
    96
                |] ==> b(x,f,r) \<in> C(Tcons(x,f));
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
    97
      c \<in> C(Fnil);
12243
wenzelm
parents: 12216
diff changeset
    98
      !!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
    99
                    |] ==> 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
   100
   |] ==> tree_forest_rec(b,c,d,z) \<in> C(z)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   101
  by (induct_tac z) simp_all
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   102
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   103
lemma tree_forest_rec_type:
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   104
  "[| !!x f r. [| x \<in> A;  f \<in> forest(A);  r \<in> D(f)
12243
wenzelm
parents: 12216
diff changeset
   105
                |] ==> b(x,f,r) \<in> C(Tcons(x,f));
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   106
      c \<in> D(Fnil);
12243
wenzelm
parents: 12216
diff changeset
   107
      !!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
   108
                    |] ==> d(t,f,r1,r2) \<in> D(Fcons(t,f))
wenzelm
parents: 12216
diff changeset
   109
   |] ==> (\<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
   110
          (\<forall>f \<in> forest(A). tree_forest_rec(b,c,d,f) \<in> D(f))"
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   111
    \<comment> \<open>Mutually recursive version.\<close>
12243
wenzelm
parents: 12216
diff changeset
   112
  apply (unfold Ball_def)
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   113
  apply (rule tree_forest.mutual_induct)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   114
  apply simp_all
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   115
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   116
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   117
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   118
subsection \<open>Operations\<close>
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   119
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   120
consts
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   121
  map :: "[i => i, i] => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   122
  size :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   123
  preorder :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   124
  list_of_TF :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   125
  of_list :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   126
  reflect :: "i => i"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   127
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   128
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   129
  "list_of_TF (Tcons(x,f)) = [Tcons(x,f)]"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   130
  "list_of_TF (Fnil) = []"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   131
  "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
   132
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   133
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   134
  "of_list([]) = Fnil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   135
  "of_list(Cons(t,l)) = Fcons(t, of_list(l))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   136
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   137
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   138
  "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
   139
  "map (h, Fnil) = Fnil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   140
  "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
   141
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   142
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   143
  "size (Tcons(x,f)) = succ(size(f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   144
  "size (Fnil) = 0"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   145
  "size (Fcons(t,tf)) = size(t) #+ size(tf)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   146
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   147
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   148
  "preorder (Tcons(x,f)) = Cons(x, preorder(f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   149
  "preorder (Fnil) = Nil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   150
  "preorder (Fcons(t,tf)) = preorder(t) @ preorder(tf)"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   151
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   152
primrec
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   153
  "reflect (Tcons(x,f)) = Tcons(x, reflect(f))"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   154
  "reflect (Fnil) = Fnil"
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   155
  "reflect (Fcons(t,tf)) =
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   156
    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
   157
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   158
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   159
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   160
  \medskip \<open>list_of_TF\<close> and \<open>of_list\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   161
\<close>
12201
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
lemma list_of_TF_type [TC]:
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   164
    "z \<in> tree_forest(A) ==> list_of_TF(z) \<in> list(tree(A))"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   165
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   166
12243
wenzelm
parents: 12216
diff changeset
   167
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
   168
  by (induct set: list) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   169
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   170
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   171
  \medskip \<open>map\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   172
\<close>
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   173
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
   174
lemma
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   175
  assumes "!!x. x \<in> A ==> h(x): B"
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12610
diff changeset
   176
  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
   177
    and map_forest_type: "f \<in> forest(A) ==> map(h,f) \<in> forest(B)"
41526
54b4686704af eliminated global prems;
wenzelm
parents: 35762
diff changeset
   178
  using assms
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   179
  by (induct rule: tree'induct forest'induct) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   180
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   181
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   182
  \medskip \<open>size\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   183
\<close>
12201
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
lemma size_type [TC]: "z \<in> tree_forest(A) ==> size(z) \<in> nat"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   186
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   187
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   188
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   189
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   190
  \medskip \<open>preorder\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   191
\<close>
12201
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
lemma preorder_type [TC]: "z \<in> tree_forest(A) ==> preorder(z) \<in> list(A)"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   194
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   195
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   196
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   197
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   198
  \medskip Theorems about \<open>list_of_TF\<close> and \<open>of_list\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   199
\<close>
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   200
18415
eb68dc98bda2 improved proofs;
wenzelm
parents: 16417
diff changeset
   201
lemma forest_induct [consumes 1, case_names Fnil Fcons]:
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   202
  "[| f \<in> forest(A);
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   203
      R(Fnil);
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   204
      !!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
   205
   |] ==> R(f)"
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   206
  \<comment> \<open>Essentially the same as list induction.\<close>
12610
8b9845807f77 tuned document sources;
wenzelm
parents: 12243
diff changeset
   207
  apply (erule tree_forest.mutual_induct
8b9845807f77 tuned document sources;
wenzelm
parents: 12243
diff changeset
   208
      [THEN conjunct2, THEN spec, THEN [2] rev_mp])
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   209
    apply (rule TrueI)
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   210
   apply simp
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
  done
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   213
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   214
lemma forest_iso: "f \<in> forest(A) ==> of_list(list_of_TF(f)) = f"
18415
eb68dc98bda2 improved proofs;
wenzelm
parents: 16417
diff changeset
   215
  by (induct rule: forest_induct) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   216
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   217
lemma tree_list_iso: "ts: list(tree(A)) ==> list_of_TF(of_list(ts)) = ts"
18415
eb68dc98bda2 improved proofs;
wenzelm
parents: 16417
diff changeset
   218
  by (induct set: list) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   219
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   220
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   221
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   222
  \medskip Theorems about \<open>map\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   223
\<close>
12201
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
lemma map_ident: "z \<in> tree_forest(A) ==> map(\<lambda>u. u, z) = z"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   226
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   227
12216
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
   228
lemma map_compose:
dda8c04a8fb4 isatool unsymbolize;
wenzelm
parents: 12205
diff changeset
   229
    "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
   230
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   231
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   232
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   233
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   234
  \medskip Theorems about \<open>size\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   235
\<close>
12201
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
lemma size_map: "z \<in> tree_forest(A) ==> size(map(h,z)) = size(z)"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   238
  by (induct set: tree_forest) simp_all
12201
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   239
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   240
lemma size_length: "z \<in> tree_forest(A) ==> size(z) = length(preorder(z))"
18460
9a1458cb2956 tuned induct proofs;
wenzelm
parents: 18415
diff changeset
   241
  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
   242
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   243
text \<open>
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 60770
diff changeset
   244
  \medskip Theorems about \<open>preorder\<close>.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60375
diff changeset
   245
\<close>
12201
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
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
   248
    "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
   249
  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
   250
7198f403a2f9 added Term and Tree_Forest (from converted ZF/ex);
wenzelm
parents:
diff changeset
   251
end