src/HOL/Library/Tree_Multiset.thy
author Manuel Eberl <eberlm@in.tum.de>
Mon Mar 26 16:14:16 2018 +0200 (19 months ago)
changeset 67951 655aa11359dc
parent 66556 2d24e2c02130
child 68484 59793df7f853
permissions -rw-r--r--
Removed some uses of deprecated _tac methods. (Patch from Viorel Preoteasa)
nipkow@59928
     1
(* Author: Tobias Nipkow *)
nipkow@59928
     2
wenzelm@60500
     3
section \<open>Multiset of Elements of Binary Tree\<close>
nipkow@59928
     4
nipkow@59928
     5
theory Tree_Multiset
nipkow@59928
     6
imports Multiset Tree
nipkow@59928
     7
begin
nipkow@59928
     8
wenzelm@60500
     9
text\<open>Kept separate from theory @{theory Tree} to avoid importing all of
nipkow@59928
    10
theory @{theory Multiset} into @{theory Tree}. Should be merged if
wenzelm@60500
    11
@{theory Multiset} ever becomes part of @{theory Main}.\<close>
nipkow@59928
    12
nipkow@59928
    13
fun mset_tree :: "'a tree \<Rightarrow> 'a multiset" where
nipkow@59928
    14
"mset_tree Leaf = {#}" |
nipkow@59928
    15
"mset_tree (Node l a r) = {#a#} + mset_tree l + mset_tree r"
nipkow@59928
    16
nipkow@63861
    17
fun subtrees_mset :: "'a tree \<Rightarrow> 'a tree multiset" where
nipkow@63861
    18
"subtrees_mset Leaf = {#Leaf#}" |
nipkow@63861
    19
"subtrees_mset (Node l x r) = add_mset (Node l x r) (subtrees_mset l + subtrees_mset r)"
nipkow@63861
    20
nipkow@63861
    21
nipkow@66556
    22
lemma mset_tree_empty_iff[simp]: "mset_tree t = {#} \<longleftrightarrow> t = Leaf"
nipkow@66556
    23
by (cases t) auto
nipkow@66556
    24
nipkow@60495
    25
lemma set_mset_tree[simp]: "set_mset (mset_tree t) = set_tree t"
nipkow@59928
    26
by(induction t) auto
nipkow@59928
    27
nipkow@59928
    28
lemma size_mset_tree[simp]: "size(mset_tree t) = size t"
nipkow@59928
    29
by(induction t) auto
nipkow@59928
    30
nipkow@59928
    31
lemma mset_map_tree: "mset_tree (map_tree f t) = image_mset f (mset_tree t)"
nipkow@59928
    32
by (induction t) auto
nipkow@59928
    33
nipkow@60505
    34
lemma mset_iff_set_tree: "x \<in># mset_tree t \<longleftrightarrow> x \<in> set_tree t"
nipkow@60505
    35
by(induction t arbitrary: x) auto
nipkow@60505
    36
nipkow@60515
    37
lemma mset_preorder[simp]: "mset (preorder t) = mset_tree t"
nipkow@59928
    38
by (induction t) (auto simp: ac_simps)
nipkow@59928
    39
nipkow@60515
    40
lemma mset_inorder[simp]: "mset (inorder t) = mset_tree t"
nipkow@59928
    41
by (induction t) (auto simp: ac_simps)
nipkow@59928
    42
nipkow@59928
    43
lemma map_mirror: "mset_tree (mirror t) = mset_tree t"
nipkow@59928
    44
by (induction t) (simp_all add: ac_simps)
nipkow@59928
    45
nipkow@63861
    46
lemma in_subtrees_mset_iff[simp]: "s \<in># subtrees_mset t \<longleftrightarrow> s \<in> subtrees t"
nipkow@63861
    47
by(induction t) auto
nipkow@63861
    48
nipkow@59928
    49
end