src/HOL/Library/Tree_Multiset.thy
author haftmann
Wed Jul 18 20:51:21 2018 +0200 (11 months ago)
changeset 68658 16cc1161ad7f
parent 68484 59793df7f853
child 69593 3dda49e08b9d
permissions -rw-r--r--
tuned equation
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@68484
     9
text \<open>
wenzelm@68484
    10
  Kept separate from theory @{theory "HOL-Library.Tree"} to avoid importing all of theory @{theory
wenzelm@68484
    11
  "HOL-Library.Multiset"} into @{theory "HOL-Library.Tree"}. Should be merged if @{theory
wenzelm@68484
    12
  "HOL-Library.Multiset"} ever becomes part of @{theory Main}.
wenzelm@68484
    13
\<close>
nipkow@59928
    14
nipkow@59928
    15
fun mset_tree :: "'a tree \<Rightarrow> 'a multiset" where
nipkow@59928
    16
"mset_tree Leaf = {#}" |
nipkow@59928
    17
"mset_tree (Node l a r) = {#a#} + mset_tree l + mset_tree r"
nipkow@59928
    18
nipkow@63861
    19
fun subtrees_mset :: "'a tree \<Rightarrow> 'a tree multiset" where
nipkow@63861
    20
"subtrees_mset Leaf = {#Leaf#}" |
nipkow@63861
    21
"subtrees_mset (Node l x r) = add_mset (Node l x r) (subtrees_mset l + subtrees_mset r)"
nipkow@63861
    22
nipkow@63861
    23
nipkow@66556
    24
lemma mset_tree_empty_iff[simp]: "mset_tree t = {#} \<longleftrightarrow> t = Leaf"
nipkow@66556
    25
by (cases t) auto
nipkow@66556
    26
nipkow@60495
    27
lemma set_mset_tree[simp]: "set_mset (mset_tree t) = set_tree t"
nipkow@59928
    28
by(induction t) auto
nipkow@59928
    29
nipkow@59928
    30
lemma size_mset_tree[simp]: "size(mset_tree t) = size t"
nipkow@59928
    31
by(induction t) auto
nipkow@59928
    32
nipkow@59928
    33
lemma mset_map_tree: "mset_tree (map_tree f t) = image_mset f (mset_tree t)"
nipkow@59928
    34
by (induction t) auto
nipkow@59928
    35
nipkow@60505
    36
lemma mset_iff_set_tree: "x \<in># mset_tree t \<longleftrightarrow> x \<in> set_tree t"
nipkow@60505
    37
by(induction t arbitrary: x) auto
nipkow@60505
    38
nipkow@60515
    39
lemma mset_preorder[simp]: "mset (preorder t) = mset_tree t"
nipkow@59928
    40
by (induction t) (auto simp: ac_simps)
nipkow@59928
    41
nipkow@60515
    42
lemma mset_inorder[simp]: "mset (inorder t) = mset_tree t"
nipkow@59928
    43
by (induction t) (auto simp: ac_simps)
nipkow@59928
    44
nipkow@59928
    45
lemma map_mirror: "mset_tree (mirror t) = mset_tree t"
nipkow@59928
    46
by (induction t) (simp_all add: ac_simps)
nipkow@59928
    47
nipkow@63861
    48
lemma in_subtrees_mset_iff[simp]: "s \<in># subtrees_mset t \<longleftrightarrow> s \<in> subtrees t"
nipkow@63861
    49
by(induction t) auto
nipkow@63861
    50
nipkow@59928
    51
end