src/HOL/Library/Tree_Multiset.thy
author nipkow
Wed, 13 Feb 2019 07:48:42 +0100
changeset 69801 a99a0f5474c5
parent 69593 3dda49e08b9d
permissions -rw-r--r--
too agressive
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59928
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
     2
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59928
diff changeset
     3
section \<open>Multiset of Elements of Binary Tree\<close>
59928
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
     4
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
     5
theory Tree_Multiset
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
     6
imports Multiset Tree
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
     7
begin
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
     8
68484
59793df7f853 clarified document antiquotation @{theory};
wenzelm
parents: 66556
diff changeset
     9
text \<open>
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
    10
  Kept separate from theory \<^theory>\<open>HOL-Library.Tree\<close> to avoid importing all of theory \<^theory>\<open>HOL-Library.Multiset\<close> into \<^theory>\<open>HOL-Library.Tree\<close>. Should be merged if \<^theory>\<open>HOL-Library.Multiset\<close> ever becomes part of \<^theory>\<open>Main\<close>.
68484
59793df7f853 clarified document antiquotation @{theory};
wenzelm
parents: 66556
diff changeset
    11
\<close>
59928
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    12
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    13
fun mset_tree :: "'a tree \<Rightarrow> 'a multiset" where
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    14
"mset_tree Leaf = {#}" |
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    15
"mset_tree (Node l a r) = {#a#} + mset_tree l + mset_tree r"
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    16
63861
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    17
fun subtrees_mset :: "'a tree \<Rightarrow> 'a tree multiset" where
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    18
"subtrees_mset Leaf = {#Leaf#}" |
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    19
"subtrees_mset (Node l x r) = add_mset (Node l x r) (subtrees_mset l + subtrees_mset r)"
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    20
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    21
66556
2d24e2c02130 added lemma
nipkow
parents: 63861
diff changeset
    22
lemma mset_tree_empty_iff[simp]: "mset_tree t = {#} \<longleftrightarrow> t = Leaf"
2d24e2c02130 added lemma
nipkow
parents: 63861
diff changeset
    23
by (cases t) auto
2d24e2c02130 added lemma
nipkow
parents: 63861
diff changeset
    24
60495
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 59928
diff changeset
    25
lemma set_mset_tree[simp]: "set_mset (mset_tree t) = set_tree t"
59928
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    26
by(induction t) auto
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    27
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    28
lemma size_mset_tree[simp]: "size(mset_tree t) = size t"
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    29
by(induction t) auto
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    30
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    31
lemma mset_map_tree: "mset_tree (map_tree f t) = image_mset f (mset_tree t)"
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    32
by (induction t) auto
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    33
60505
9e6584184315 added funs and lemmas
nipkow
parents: 60495
diff changeset
    34
lemma mset_iff_set_tree: "x \<in># mset_tree t \<longleftrightarrow> x \<in> set_tree t"
9e6584184315 added funs and lemmas
nipkow
parents: 60495
diff changeset
    35
by(induction t arbitrary: x) auto
9e6584184315 added funs and lemmas
nipkow
parents: 60495
diff changeset
    36
60515
484559628038 renamed multiset_of -> mset
nipkow
parents: 60506
diff changeset
    37
lemma mset_preorder[simp]: "mset (preorder t) = mset_tree t"
59928
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    38
by (induction t) (auto simp: ac_simps)
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    39
60515
484559628038 renamed multiset_of -> mset
nipkow
parents: 60506
diff changeset
    40
lemma mset_inorder[simp]: "mset (inorder t) = mset_tree t"
59928
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    41
by (induction t) (auto simp: ac_simps)
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    42
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    43
lemma map_mirror: "mset_tree (mirror t) = mset_tree t"
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    44
by (induction t) (simp_all add: ac_simps)
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    45
63861
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    46
lemma in_subtrees_mset_iff[simp]: "s \<in># subtrees_mset t \<longleftrightarrow> s \<in> subtrees t"
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    47
by(induction t) auto
90360390a916 reorganization, more funs and lemmas
nipkow
parents: 60808
diff changeset
    48
59928
b9b7f913a19a new theory Library/Tree_Multiset.thy
nipkow
parents:
diff changeset
    49
end