[STATEMENT]
theorem split_random_bst:
  assumes "finite A"
  shows   "map_pmf (split_bst x) (random_bst A) =
             pair_pmf (random_bst {y\<in>A. y < x}) (random_bst {y\<in>A. y > x})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
finite A

goal (1 subgoal):
 1. map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
proof (induction A rule: random_bst.induct)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>A. \<lbrakk>\<And>xa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); finite {y \<in> A. y < xa}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. y < xa}) = pair_pmf (random_bst {y \<in> {y \<in> A. y < xa}. y < x}) (random_bst {y \<in> {y \<in> A. y < xa}. x < y}); \<And>xa xaa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); xaa \<in> set_pmf (random_bst {y \<in> A. y < xa}); finite {y \<in> A. xa < y}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. xa < y}) = pair_pmf (random_bst {y \<in> {y \<in> A. xa < y}. y < x}) (random_bst {y \<in> {y \<in> A. xa < y}. x < y}); finite A\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
case (1 A)
[PROOF STATE]
proof (state)
this:
\<lbrakk>\<not> (infinite A \<or> A = {}); ?x \<in> set_pmf (pmf_of_set A); finite {y \<in> A. y < ?x}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. y < ?x}) = pair_pmf (random_bst {y \<in> {y \<in> A. y < ?x}. y < x}) (random_bst {y \<in> {y \<in> A. y < ?x}. x < y})
\<lbrakk>\<not> (infinite A \<or> A = {}); ?x \<in> set_pmf (pmf_of_set A); ?xa \<in> set_pmf (random_bst {y \<in> A. y < ?x}); finite {y \<in> A. ?x < y}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. ?x < y}) = pair_pmf (random_bst {y \<in> {y \<in> A. ?x < y}. y < x}) (random_bst {y \<in> {y \<in> A. ?x < y}. x < y})
finite A

goal (1 subgoal):
 1. \<And>A. \<lbrakk>\<And>xa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); finite {y \<in> A. y < xa}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. y < xa}) = pair_pmf (random_bst {y \<in> {y \<in> A. y < xa}. y < x}) (random_bst {y \<in> {y \<in> A. y < xa}. x < y}); \<And>xa xaa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); xaa \<in> set_pmf (random_bst {y \<in> A. y < xa}); finite {y \<in> A. xa < y}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. xa < y}) = pair_pmf (random_bst {y \<in> {y \<in> A. xa < y}. y < x}) (random_bst {y \<in> {y \<in> A. xa < y}. x < y}); finite A\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
define A\<^sub>1 A\<^sub>2 where "A\<^sub>1 = {y\<in>A. y < x}" and "A\<^sub>2 = {y\<in>A. y > x}"
[PROOF STATE]
proof (state)
this:
A\<^sub>1 = {y \<in> A. y < x}
A\<^sub>2 = {y \<in> A. x < y}

goal (1 subgoal):
 1. \<And>A. \<lbrakk>\<And>xa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); finite {y \<in> A. y < xa}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. y < xa}) = pair_pmf (random_bst {y \<in> {y \<in> A. y < xa}. y < x}) (random_bst {y \<in> {y \<in> A. y < xa}. x < y}); \<And>xa xaa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); xaa \<in> set_pmf (random_bst {y \<in> A. y < xa}); finite {y \<in> A. xa < y}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. xa < y}) = pair_pmf (random_bst {y \<in> {y \<in> A. xa < y}. y < x}) (random_bst {y \<in> {y \<in> A. xa < y}. x < y}); finite A\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have [simp]: "\<not>x \<in> A\<^sub>2" if "x \<in> A\<^sub>1" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<notin> A\<^sub>2
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
x \<in> A\<^sub>1

goal (1 subgoal):
 1. x \<notin> A\<^sub>2
[PROOF STEP]
by (auto simp: A\<^sub>1_def A\<^sub>2_def)
[PROOF STATE]
proof (state)
this:
?x \<in> A\<^sub>1 \<Longrightarrow> ?x \<notin> A\<^sub>2

goal (1 subgoal):
 1. \<And>A. \<lbrakk>\<And>xa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); finite {y \<in> A. y < xa}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. y < xa}) = pair_pmf (random_bst {y \<in> {y \<in> A. y < xa}. y < x}) (random_bst {y \<in> {y \<in> A. y < xa}. x < y}); \<And>xa xaa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); xaa \<in> set_pmf (random_bst {y \<in> A. y < xa}); finite {y \<in> A. xa < y}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. xa < y}) = pair_pmf (random_bst {y \<in> {y \<in> A. xa < y}. y < x}) (random_bst {y \<in> {y \<in> A. xa < y}. x < y}); finite A\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
from \<open>finite A\<close>
[PROOF STATE]
proof (chain)
picking this:
finite A
[PROOF STEP]
have [simp]: "finite A\<^sub>1" "finite A\<^sub>2"
[PROOF STATE]
proof (prove)
using this:
finite A

goal (1 subgoal):
 1. finite A\<^sub>1 &&& finite A\<^sub>2
[PROOF STEP]
by (auto simp: A\<^sub>1_def A\<^sub>2_def)
[PROOF STATE]
proof (state)
this:
finite A\<^sub>1
finite A\<^sub>2

goal (1 subgoal):
 1. \<And>A. \<lbrakk>\<And>xa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); finite {y \<in> A. y < xa}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. y < xa}) = pair_pmf (random_bst {y \<in> {y \<in> A. y < xa}. y < x}) (random_bst {y \<in> {y \<in> A. y < xa}. x < y}); \<And>xa xaa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); xaa \<in> set_pmf (random_bst {y \<in> A. y < xa}); finite {y \<in> A. xa < y}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. xa < y}) = pair_pmf (random_bst {y \<in> {y \<in> A. xa < y}. y < x}) (random_bst {y \<in> {y \<in> A. xa < y}. x < y}); finite A\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
include monad_normalisation
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>A. \<lbrakk>\<And>xa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); finite {y \<in> A. y < xa}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. y < xa}) = pair_pmf (random_bst {y \<in> {y \<in> A. y < xa}. y < x}) (random_bst {y \<in> {y \<in> A. y < xa}. x < y}); \<And>xa xaa. \<lbrakk>\<not> (infinite A \<or> A = {}); xa \<in> set_pmf (pmf_of_set A); xaa \<in> set_pmf (random_bst {y \<in> A. y < xa}); finite {y \<in> A. xa < y}\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst {y \<in> A. xa < y}) = pair_pmf (random_bst {y \<in> {y \<in> A. xa < y}. y < x}) (random_bst {y \<in> {y \<in> A. xa < y}. x < y}); finite A\<rbrakk> \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
proof (cases "A = {}")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. A = {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
 2. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
A = {}

goal (2 subgoals):
 1. A = {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
 2. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
A = {}

goal (1 subgoal):
 1. map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
by (auto simp: pair_return_pmf1)
[PROOF STATE]
proof (state)
this:
map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
A \<noteq> {}

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have "map_pmf (split_bst x) (random_bst A) =
            do {y \<leftarrow> pmf_of_set A;
                if y < x then
                  do {
                    l \<leftarrow> random_bst {z\<in>A. z < y};
                    (t1, t2) \<leftarrow> map_pmf (split_bst x) (random_bst {z\<in>A. z > y});
                    return_pmf (\<langle>l, y, t1\<rangle>, t2)
                  }
                else if y > x then
                  do {
                    (t1, t2) \<leftarrow> map_pmf (split_bst x) (random_bst {z\<in>A. z < y});
                    r \<leftarrow> random_bst {z\<in>A. z > y};
                    return_pmf (t1, (\<langle>t2, y, r\<rangle>))
                  }
                else
                  do {
                    l \<leftarrow> random_bst {z\<in>A. z < y};
                    r \<leftarrow> random_bst {z\<in>A. z > y};
                    return_pmf (l, r)
                  }
               }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map_pmf (split_bst x) (random_bst A) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))
[PROOF STEP]
using "1.prems" False
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}

goal (1 subgoal):
 1. map_pmf (split_bst x) (random_bst A) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))
[PROOF STEP]
by (subst random_bst.simps)
         (simp add: map_bind_pmf bind_map_pmf return_pmf_if case_prod_unfold cong: if_cong)
[PROOF STATE]
proof (state)
this:
map_pmf (split_bst x) (random_bst A) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
map_pmf (split_bst x) (random_bst A) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have "\<dots> = do {y \<leftarrow> pmf_of_set A;
                        if y < x then
                          do {
                            l \<leftarrow> random_bst {z\<in>A. z < y};
                            (t1, t2) \<leftarrow> pair_pmf (random_bst {z\<in>{z\<in>A. z > y}. z < x})
                                                 (random_bst {z\<in>{z\<in>A. z > y}. z > x});
                            return_pmf (\<langle>l, y, t1\<rangle>, t2)
                          }
                        else if y > x then
                          do {
                            (t1, t2) \<leftarrow> pair_pmf (random_bst {z\<in>{z\<in>A. z < y}. z < x})
                                                 (random_bst {z\<in>{z\<in>A. z < y}. z > x});
                            r \<leftarrow> random_bst {z\<in>A. z > y};
                            return_pmf (t1, (\<langle>t2, y, r\<rangle>))
                          }
                         else
                           do {
                             l \<leftarrow> random_bst {z\<in>A. z < y};
                             r \<leftarrow> random_bst {z\<in>A. z > y};
                             return_pmf (l, r)
                           }
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))
[PROOF STEP]
using \<open>finite A\<close> and \<open>A \<noteq> {}\<close>
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))
[PROOF STEP]
thm "1.IH"
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))
[PROOF STEP]
by (intro bind_pmf_cong if_cong refl "1.IH") auto
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. map_pmf (split_bst x) (random_bst {z \<in> A. y < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then map_pmf (split_bst x) (random_bst {z \<in> A. z < y}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have "\<dots> = do {y \<leftarrow> pmf_of_set A;
                        if y < x then
                          do {
                            l \<leftarrow> random_bst {z\<in>A. z < y};
                            t1 \<leftarrow> random_bst {z\<in>{z\<in>A. z > y}. z < x};
                            t2 \<leftarrow> random_bst {z\<in>{z\<in>A. z > y}. z > x};
                            return_pmf (\<langle>l, y, t1\<rangle>, t2)
                          }
                        else if y > x then
                          do {
                            t1 \<leftarrow> random_bst {z\<in>{z\<in>A. z < y}. z < x};
                            t2 \<leftarrow> random_bst {z\<in>{z\<in>A. z < y}. z > x};
                            r \<leftarrow> random_bst {z\<in>A. z > y};
                            return_pmf (t1, (\<langle>t2, y, r\<rangle>))
                          }
                         else
                           do {
                             l \<leftarrow> random_bst {z\<in>A. z < y};
                             r \<leftarrow> random_bst {z\<in>A. z > y};
                             return_pmf (l, r)
                           }
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {z \<in> A. y < z}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. y < z}. x < z} \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if x < y then random_bst {z \<in> {z \<in> A. z < y}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. z < y}. x < z} \<bind> (\<lambda>t2. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))
[PROOF STEP]
by (simp add: pair_pmf_def cong: if_cong)
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {z \<in> A. y < z}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. y < z}. x < z} \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if x < y then random_bst {z \<in> {z \<in> A. z < y}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. z < y}. x < z} \<bind> (\<lambda>t2. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. pair_pmf (random_bst {z \<in> {z \<in> A. y < z}. z < x}) (random_bst {z \<in> {z \<in> A. y < z}. x < z}) \<bind> (\<lambda>(t1, t2). return_pmf (\<langle>l, y, t1\<rangle>, t2))) else if x < y then pair_pmf (random_bst {z \<in> {z \<in> A. z < y}. z < x}) (random_bst {z \<in> {z \<in> A. z < y}. x < z}) \<bind> (\<lambda>(t1, t2). random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {z \<in> A. y < z}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. y < z}. x < z} \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if x < y then random_bst {z \<in> {z \<in> A. z < y}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. z < y}. x < z} \<bind> (\<lambda>t2. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r))))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have "\<dots> = do {y \<leftarrow> pmf_of_set A;
                        if y \<in> A\<^sub>1 then
                          do {
                            l \<leftarrow> random_bst {z\<in>A\<^sub>1. z < y};
                            t1 \<leftarrow> random_bst {z\<in>A\<^sub>1. z > y};
                            t2 \<leftarrow> random_bst A\<^sub>2;
                            return_pmf (\<langle>l, y, t1\<rangle>, t2)
                          }
                        else if y \<in> A\<^sub>2 then
                          do {
                            t1 \<leftarrow> random_bst A\<^sub>1;
                            t2 \<leftarrow> random_bst {z\<in>A\<^sub>2. z < y};
                            r \<leftarrow> random_bst {z\<in>A\<^sub>2. z > y};
                            return_pmf (t1, (\<langle>t2, y, r\<rangle>))
                          }
                         else
                           pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {z \<in> A. y < z}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. y < z}. x < z} \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if x < y then random_bst {z \<in> {z \<in> A. z < y}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. z < y}. x < z} \<bind> (\<lambda>t2. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))
[PROOF STEP]
using \<open>finite A\<close> \<open>A \<noteq> {}\<close>
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {z \<in> A. y < z}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. y < z}. x < z} \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if x < y then random_bst {z \<in> {z \<in> A. z < y}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. z < y}. x < z} \<bind> (\<lambda>t2. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))
[PROOF STEP]
by (intro bind_pmf_cong refl if_cong arg_cong[of _ _ random_bst])
         (auto simp: A\<^sub>1_def A\<^sub>2_def pair_pmf_def)
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {z \<in> A. y < z}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. y < z}. x < z} \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if x < y then random_bst {z \<in> {z \<in> A. z < y}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. z < y}. x < z} \<bind> (\<lambda>t2. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y < x then random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {z \<in> A. y < z}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. y < z}. x < z} \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if x < y then random_bst {z \<in> {z \<in> A. z < y}. z < x} \<bind> (\<lambda>t1. random_bst {z \<in> {z \<in> A. z < y}. x < z} \<bind> (\<lambda>t2. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else random_bst {z \<in> A. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A. y < z} \<bind> (\<lambda>r. return_pmf (l, r)))) = pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have "\<dots> = do {i \<leftarrow> pmf_of_set {..<card A};
                        if i < card A\<^sub>1 then
                          do {
                            y \<leftarrow> pmf_of_set A\<^sub>1;
                            l \<leftarrow> random_bst {z\<in>A\<^sub>1. z < y};
                            t1 \<leftarrow> random_bst {z\<in>A\<^sub>1. z > y};
                            t2 \<leftarrow> random_bst A\<^sub>2;
                            return_pmf (\<langle>l, y, t1\<rangle>, t2)
                          }
                        else if i < card A\<^sub>1 + card A\<^sub>2 then
                          do {
                            y \<leftarrow> pmf_of_set A\<^sub>2;
                            t1 \<leftarrow> random_bst A\<^sub>1;
                            t2 \<leftarrow> random_bst {z\<in>A\<^sub>2. z < y};
                            r \<leftarrow> random_bst {z\<in>A\<^sub>2. z > y};
                            return_pmf (t1, (\<langle>t2, y, r\<rangle>))
                          }
                         else do {
                           y \<leftarrow> pmf_of_set (if x \<in> A then {x} else {});
                           pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
                         }
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)))
[PROOF STEP]
using \<open>finite A\<close> \<open>A \<noteq> {}\<close>
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)))
[PROOF STEP]
by (intro pmf_of_set_3way_split) (auto simp: A\<^sub>1_def A\<^sub>2_def not_less_iff_gr_or_eq)
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set A \<bind> (\<lambda>y. if y \<in> A\<^sub>1 then random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2)))) else if y \<in> A\<^sub>2 then random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>)))) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have "\<dots> = do {i \<leftarrow> pmf_of_set {..<card A};
                        if i < card A\<^sub>1 then
                          pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
                        else if i < card A\<^sub>1 + card A\<^sub>2 then
                          pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
                         else
                          pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else if i < card A\<^sub>1 + card A\<^sub>2 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))
[PROOF STEP]
using \<open>finite A\<close> \<open>A \<noteq> {}\<close>
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else if i < card A\<^sub>1 + card A\<^sub>2 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))
[PROOF STEP]
proof (intro bind_pmf_cong refl if_cong, goal_cases)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); x < card A\<^sub>1\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 2. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); \<not> x < card A\<^sub>1; x < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 3. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
case (1 i)
[PROOF STATE]
proof (state)
this:
finite A
A \<noteq> {}
i \<in> set_pmf (pmf_of_set {..<card A})
i < card A\<^sub>1

goal (3 subgoals):
 1. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); x < card A\<^sub>1\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 2. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); \<not> x < card A\<^sub>1; x < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 3. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
hence "A\<^sub>1 \<noteq> {}"
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}
i \<in> set_pmf (pmf_of_set {..<card A})
i < card A\<^sub>1

goal (1 subgoal):
 1. A\<^sub>1 \<noteq> {}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A\<^sub>1 \<noteq> {}

goal (3 subgoals):
 1. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); x < card A\<^sub>1\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 2. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); \<not> x < card A\<^sub>1; x < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 3. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
A\<^sub>1 \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
using \<open>finite A\<close>
[PROOF STATE]
proof (prove)
using this:
A\<^sub>1 \<noteq> {}
finite A

goal (1 subgoal):
 1. pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
by (simp add: pair_pmf_def random_bst_reduce)
[PROOF STATE]
proof (state)
this:
pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)

goal (2 subgoals):
 1. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); \<not> x < card A\<^sub>1; x < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 2. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); \<not> x < card A\<^sub>1; x < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 2. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
case (2 i)
[PROOF STATE]
proof (state)
this:
finite A
A \<noteq> {}
i \<in> set_pmf (pmf_of_set {..<card A})
\<not> i < card A\<^sub>1
i < card A\<^sub>1 + card A\<^sub>2

goal (2 subgoals):
 1. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); \<not> x < card A\<^sub>1; x < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 2. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
hence "A\<^sub>2 \<noteq> {}"
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}
i \<in> set_pmf (pmf_of_set {..<card A})
\<not> i < card A\<^sub>1
i < card A\<^sub>1 + card A\<^sub>2

goal (1 subgoal):
 1. A\<^sub>2 \<noteq> {}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A\<^sub>2 \<noteq> {}

goal (2 subgoals):
 1. \<And>x. \<lbrakk>finite A; A \<noteq> {}; x \<in> set_pmf (pmf_of_set {..<card A}); \<not> x < card A\<^sub>1; x < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
 2. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
A\<^sub>2 \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
using \<open>finite A\<close>
[PROOF STATE]
proof (prove)
using this:
A\<^sub>2 \<noteq> {}
finite A

goal (1 subgoal):
 1. pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
by (simp add: pair_pmf_def random_bst_reduce)
[PROOF STATE]
proof (state)
this:
pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)

goal (1 subgoal):
 1. \<And>xa. \<lbrakk>finite A; A \<noteq> {}; xa \<in> set_pmf (pmf_of_set {..<card A}); \<not> xa < card A\<^sub>1; \<not> xa < card A\<^sub>1 + card A\<^sub>2\<rbrakk> \<Longrightarrow> pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
qed auto
[PROOF STATE]
proof (state)
this:
pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else if i < card A\<^sub>1 + card A\<^sub>2 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pmf_of_set A\<^sub>1 \<bind> (\<lambda>y. random_bst {z \<in> A\<^sub>1. z < y} \<bind> (\<lambda>l. random_bst {z \<in> A\<^sub>1. y < z} \<bind> (\<lambda>t1. random_bst A\<^sub>2 \<bind> (\<lambda>t2. return_pmf (\<langle>l, y, t1\<rangle>, t2))))) else if i < card A\<^sub>1 + card A\<^sub>2 then pmf_of_set A\<^sub>2 \<bind> (\<lambda>y. random_bst A\<^sub>1 \<bind> (\<lambda>t1. random_bst {z \<in> A\<^sub>2. z < y} \<bind> (\<lambda>t2. random_bst {z \<in> A\<^sub>2. y < z} \<bind> (\<lambda>r. return_pmf (t1, \<langle>t2, y, r\<rangle>))))) else pmf_of_set (if x \<in> A then {x} else {}) \<bind> (\<lambda>y. pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))) = pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else if i < card A\<^sub>1 + card A\<^sub>2 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2))

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
have "\<dots> = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else if i < card A\<^sub>1 + card A\<^sub>2 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
by (simp cong: if_cong)
[PROOF STATE]
proof (state)
this:
pmf_of_set {..<card A} \<bind> (\<lambda>i. if i < card A\<^sub>1 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else if i < card A\<^sub>1 + card A\<^sub>2 then pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2) else pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)

goal (1 subgoal):
 1. A \<noteq> {} \<Longrightarrow> map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst A\<^sub>1) (random_bst A\<^sub>2)

goal (1 subgoal):
 1. map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})
[PROOF STEP]
by (simp add: A\<^sub>1_def A\<^sub>2_def)
[PROOF STATE]
proof (state)
this:
map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
map_pmf (split_bst x) (random_bst A) = pair_pmf (random_bst {y \<in> A. y < x}) (random_bst {y \<in> A. x < y})

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma minus_mod_cancel:
  assumes "a - b > 0" "a - b mod q > 0"
  shows "[a - b + c = a - b mod q + c] (mod q)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [a - b + c = a - b mod q + c] (mod q)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. [a - b + c = a - b mod q + c] (mod q)
[PROOF STEP]
have "(b - b mod q + (a - b)) mod q = (0 + (a - b)) mod q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (b - b mod q + (a - b)) mod q = (0 + (a - b)) mod q
[PROOF STEP]
using  cong_def mod_add_cong neq0_conv q_gt_0
[PROOF STATE]
proof (prove)
using this:
[?b = ?c] (mod ?a) = (?b mod ?a = ?c mod ?a)
\<lbrakk>?a mod ?c = ?a' mod ?c; ?b mod ?c = ?b' mod ?c\<rbrakk> \<Longrightarrow> (?a + ?b) mod ?c = (?a' + ?b') mod ?c
(?n \<noteq> 0) = (0 < ?n)
0 < q

goal (1 subgoal):
 1. (b - b mod q + (a - b)) mod q = (0 + (a - b)) mod q
[PROOF STEP]
by (simp add: minus_mod_eq_mult_div)
[PROOF STATE]
proof (state)
this:
(b - b mod q + (a - b)) mod q = (0 + (a - b)) mod q

goal (1 subgoal):
 1. [a - b + c = a - b mod q + c] (mod q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(b - b mod q + (a - b)) mod q = (0 + (a - b)) mod q
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(b - b mod q + (a - b)) mod q = (0 + (a - b)) mod q

goal (1 subgoal):
 1. [a - b + c = a - b mod q + c] (mod q)
[PROOF STEP]
by (metis (no_types) Divides.mod_less_eq_dividend Nat.add_diff_assoc2 add_diff_inverse_nat assms(1) cong_def diff_is_0_eq' less_or_eq_imp_le mod_add_cong neq0_conv)
[PROOF STATE]
proof (state)
this:
[a - b + c = a - b mod q + c] (mod q)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma Rolle_pderiv:
  fixes q:: "real poly"
  fixes x1 x2:: "real"
  shows "(x1 < x2 \<and> poly q x1 = 0 \<and> poly q x2 = 0) \<longrightarrow> (\<exists>w. x1 < w \<and> w < x2 \<and> poly (pderiv q) w = 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x1 < x2 \<and> poly q x1 = 0 \<and> poly q x2 = 0 \<longrightarrow> (\<exists>w>x1. w < x2 \<and> poly (pderiv q) w = 0)
[PROOF STEP]
using Rolle_deriv
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?a < ?b; ?f ?a = ?f ?b; continuous_on {?a..?b} ?f; \<And>x. \<lbrakk>?a < x; x < ?b\<rbrakk> \<Longrightarrow> (?f has_derivative ?f' x) (at x)\<rbrakk> \<Longrightarrow> \<exists>z>?a. z < ?b \<and> ?f' z = (\<lambda>v. 0)

goal (1 subgoal):
 1. x1 < x2 \<and> poly q x1 = 0 \<and> poly q x2 = 0 \<longrightarrow> (\<exists>w>x1. w < x2 \<and> poly (pderiv q) w = 0)
[PROOF STEP]
apply (auto)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<And>a b f f'. \<lbrakk>a < b; f a = f b; continuous_on {a..b} f; \<And>x. \<lbrakk>a < x; x < b\<rbrakk> \<Longrightarrow> (f has_derivative f' x) (at x)\<rbrakk> \<Longrightarrow> \<exists>z>a. z < b \<and> f' z = (\<lambda>v. 0); x1 < x2; poly q x1 = 0; poly q x2 = 0\<rbrakk> \<Longrightarrow> \<exists>w>x1. w < x2 \<and> poly (pderiv q) w = 0
[PROOF STEP]
by (metis DERIV_unique Rolle continuous_at_imp_continuous_on poly_DERIV poly_differentiable poly_isCont)


[STATEMENT]
lemma digit_shift_inserts_zero_least_siginificant_digit:
  assumes "t>0" and "b>1"
  shows "nth_digit (1 + b * y) t b = nth_digit (b * y) t b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_digit (1 + b * y) t b = nth_digit (b * y) t b
[PROOF STEP]
using nth_digit_def assms
[PROOF STATE]
proof (prove)
using this:
nth_digit ?num ?k ?base = ?num div ?base ^ ?k mod ?base
0 < t
1 < b

goal (1 subgoal):
 1. nth_digit (1 + b * y) t b = nth_digit (b * y) t b
[PROOF STEP]
apply auto
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<And>num k base. nth_digit num k base = num div base ^ k mod base; 0 < t; Suc 0 < b\<rbrakk> \<Longrightarrow> Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>\<And>num k base. nth_digit num k base = num div base ^ k mod base; 0 < t; Suc 0 < b\<rbrakk> \<Longrightarrow> Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
assume "0 < t"
[PROOF STATE]
proof (state)
this:
0 < t

goal (1 subgoal):
 1. \<lbrakk>\<And>num k base. nth_digit num k base = num div base ^ k mod base; 0 < t; Suc 0 < b\<rbrakk> \<Longrightarrow> Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
assume "Suc 0 < b"
[PROOF STATE]
proof (state)
this:
Suc 0 < b

goal (1 subgoal):
 1. \<lbrakk>\<And>num k base. nth_digit num k base = num div base ^ k mod base; 0 < t; Suc 0 < b\<rbrakk> \<Longrightarrow> Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
hence "Suc (b * y) mod b = 1"
[PROOF STATE]
proof (prove)
using this:
Suc 0 < b

goal (1 subgoal):
 1. Suc (b * y) mod b = 1
[PROOF STEP]
by (simp add: Suc_times_mod_eq)
[PROOF STATE]
proof (state)
this:
Suc (b * y) mod b = 1

goal (1 subgoal):
 1. \<lbrakk>\<And>num k base. nth_digit num k base = num div base ^ k mod base; 0 < t; Suc 0 < b\<rbrakk> \<Longrightarrow> Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
hence "b * y div b = Suc (b * y) div b"
[PROOF STATE]
proof (prove)
using this:
Suc (b * y) mod b = 1

goal (1 subgoal):
 1. b * y div b = Suc (b * y) div b
[PROOF STEP]
using \<open>b>1\<close>
[PROOF STATE]
proof (prove)
using this:
Suc (b * y) mod b = 1
1 < b

goal (1 subgoal):
 1. b * y div b = Suc (b * y) div b
[PROOF STEP]
by (metis (no_types) One_nat_def diff_Suc_Suc gr_implies_not0 minus_mod_eq_div_mult
                 mod_mult_self1_is_0 nonzero_mult_div_cancel_right)
[PROOF STATE]
proof (state)
this:
b * y div b = Suc (b * y) div b

goal (1 subgoal):
 1. \<lbrakk>\<And>num k base. nth_digit num k base = num div base ^ k mod base; 0 < t; Suc 0 < b\<rbrakk> \<Longrightarrow> Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
b * y div b = Suc (b * y) div b
[PROOF STEP]
show "Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b"
[PROOF STATE]
proof (prove)
using this:
b * y div b = Suc (b * y) div b

goal (1 subgoal):
 1. Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
using \<open>t>0\<close>
[PROOF STATE]
proof (prove)
using this:
b * y div b = Suc (b * y) div b
0 < t

goal (1 subgoal):
 1. Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b
[PROOF STEP]
by (metis Suc_pred div_mult2_eq power_Suc)
[PROOF STATE]
proof (state)
this:
Suc (b * y) div b ^ t mod b = b * y div b ^ t mod b

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma similar_mat_refl: "A \<in> carrier_mat n n \<Longrightarrow> similar_mat A A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<in> carrier_mat n n \<Longrightarrow> similar_mat A A
[PROOF STEP]
using similar_mat_wit_refl
[PROOF STATE]
proof (prove)
using this:
?A \<in> carrier_mat ?n ?n \<Longrightarrow> similar_mat_wit ?A ?A (1\<^sub>m ?n) (1\<^sub>m ?n)

goal (1 subgoal):
 1. A \<in> carrier_mat n n \<Longrightarrow> similar_mat A A
[PROOF STEP]
unfolding similar_mat_def
[PROOF STATE]
proof (prove)
using this:
?A \<in> carrier_mat ?n ?n \<Longrightarrow> similar_mat_wit ?A ?A (1\<^sub>m ?n) (1\<^sub>m ?n)

goal (1 subgoal):
 1. A \<in> carrier_mat n n \<Longrightarrow> \<exists>P. Ex (similar_mat_wit A A P)
[PROOF STEP]
by blast


[STATEMENT]
lemma norm_vec_index_unit_vec_is_1 [simp]:
  assumes "j < n" and "j = i"
  shows "cmod ((unit_vec n i) $ j) = 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cmod (unit_vec n i $ j) = 1
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cmod (unit_vec n i $ j) = 1
[PROOF STEP]
have f:"(unit_vec n i) $ j = 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. unit_vec n i $ j = (1::'a)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
j < n
j = i

goal (1 subgoal):
 1. unit_vec n i $ j = (1::'a)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
unit_vec n i $ j = (1::?'a1)

goal (1 subgoal):
 1. cmod (unit_vec n i $ j) = 1
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
unit_vec n i $ j = (1::?'a1)

goal (1 subgoal):
 1. cmod (unit_vec n i $ j) = 1
[PROOF STEP]
by (simp add: f cmod_def)
[PROOF STATE]
proof (state)
this:
cmod (unit_vec n i $ j) = 1

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma SNF_first_divides_all:
  assumes SNF_A: "Smith_normal_form_mat A" and A: "(A::('a::comm_ring_1) mat) \<in> carrier_mat m n"
  and i: "i < m" and j: "j<n"
shows "A $$ (0,0) dvd A $$ (i,j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
proof (cases "i=j")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. i = j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
 2. i \<noteq> j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
i = j

goal (2 subgoals):
 1. i = j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
 2. i \<noteq> j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
i = j
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
i = j

goal (1 subgoal):
 1. A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
using assms SNF_first_divides
[PROOF STATE]
proof (prove)
using this:
i = j
Smith_normal_form_mat A
A \<in> carrier_mat m n
i < m
j < n
\<lbrakk>Smith_normal_form_mat ?A; ?A \<in> carrier_mat ?n ?m; ?i < min (dim_row ?A) (dim_col ?A)\<rbrakk> \<Longrightarrow> ?A $$ (0, 0) dvd ?A $$ (?i, ?i)

goal (1 subgoal):
 1. A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
by (metis carrier_matD min_less_iff_conj)
[PROOF STATE]
proof (state)
this:
A $$ (0, 0) dvd A $$ (i, j)

goal (1 subgoal):
 1. i \<noteq> j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i \<noteq> j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
i \<noteq> j

goal (1 subgoal):
 1. i \<noteq> j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
hence "A$$(i,j) = 0"
[PROOF STATE]
proof (prove)
using this:
i \<noteq> j

goal (1 subgoal):
 1. A $$ (i, j) = (0::'a)
[PROOF STEP]
using SNF_A i j A
[PROOF STATE]
proof (prove)
using this:
i \<noteq> j
Smith_normal_form_mat A
i < m
j < n
A \<in> carrier_mat m n

goal (1 subgoal):
 1. A $$ (i, j) = (0::'a)
[PROOF STEP]
unfolding Smith_normal_form_mat_def isDiagonal_mat_def
[PROOF STATE]
proof (prove)
using this:
i \<noteq> j
(\<forall>a. a + 1 < min (dim_row A) (dim_col A) \<longrightarrow> A $$ (a, a) dvd A $$ (a + 1, a + 1)) \<and> (\<forall>i j. i \<noteq> j \<and> i < dim_row A \<and> j < dim_col A \<longrightarrow> A $$ (i, j) = (0::'a))
i < m
j < n
A \<in> carrier_mat m n

goal (1 subgoal):
 1. A $$ (i, j) = (0::'a)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A $$ (i, j) = (0::'a)

goal (1 subgoal):
 1. i \<noteq> j \<Longrightarrow> A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
A $$ (i, j) = (0::'a)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
A $$ (i, j) = (0::'a)

goal (1 subgoal):
 1. A $$ (0, 0) dvd A $$ (i, j)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A $$ (0, 0) dvd A $$ (i, j)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma ereal_limsup_add_mono:
  fixes u v::"nat \<Rightarrow> ereal"
  shows "limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
proof (cases)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. ?P \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
 2. \<not> ?P \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
assume "(limsup u = \<infinity>) \<or> (limsup v = \<infinity>)"
[PROOF STATE]
proof (state)
this:
limsup u = \<infinity> \<or> limsup v = \<infinity>

goal (2 subgoals):
 1. ?P \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
 2. \<not> ?P \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limsup u = \<infinity> \<or> limsup v = \<infinity>
[PROOF STEP]
have "limsup u + limsup v = \<infinity>"
[PROOF STATE]
proof (prove)
using this:
limsup u = \<infinity> \<or> limsup v = \<infinity>

goal (1 subgoal):
 1. limsup u + limsup v = \<infinity>
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
limsup u + limsup v = \<infinity>

goal (2 subgoals):
 1. ?P \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
 2. \<not> ?P \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limsup u + limsup v = \<infinity>
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
limsup u + limsup v = \<infinity>

goal (1 subgoal):
 1. limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
assume "\<not>((limsup u = \<infinity>) \<or> (limsup v = \<infinity>))"
[PROOF STATE]
proof (state)
this:
\<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>)
[PROOF STEP]
have "limsup u < \<infinity>" "limsup v < \<infinity>"
[PROOF STATE]
proof (prove)
using this:
\<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>)

goal (1 subgoal):
 1. limsup u < \<infinity> &&& limsup v < \<infinity>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
limsup u < \<infinity>
limsup v < \<infinity>

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
define w where "w = (\<lambda>n. u n + v n)"
[PROOF STATE]
proof (state)
this:
w = (\<lambda>n. u n + v n)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
obtain r where r: "strict_mono r" "(w o r) \<longlonglongrightarrow> limsup w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>r. \<lbrakk>strict_mono r; (w \<circ> r) \<longlonglongrightarrow> limsup w\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using limsup_subseq_lim
[PROOF STATE]
proof (prove)
using this:
\<exists>r. strict_mono r \<and> (?u \<circ> r) \<longlonglongrightarrow> limsup ?u

goal (1 subgoal):
 1. (\<And>r. \<lbrakk>strict_mono r; (w \<circ> r) \<longlonglongrightarrow> limsup w\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
strict_mono r
(w \<circ> r) \<longlonglongrightarrow> limsup w

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
obtain s where s: "strict_mono s" "(u o r o s) \<longlonglongrightarrow> limsup (u o r)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>s. \<lbrakk>strict_mono s; (u \<circ> r \<circ> s) \<longlonglongrightarrow> limsup (u \<circ> r)\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using limsup_subseq_lim
[PROOF STATE]
proof (prove)
using this:
\<exists>r. strict_mono r \<and> (?u \<circ> r) \<longlonglongrightarrow> limsup ?u

goal (1 subgoal):
 1. (\<And>s. \<lbrakk>strict_mono s; (u \<circ> r \<circ> s) \<longlonglongrightarrow> limsup (u \<circ> r)\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
strict_mono s
(u \<circ> r \<circ> s) \<longlonglongrightarrow> limsup (u \<circ> r)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
obtain t where t: "strict_mono t" "(v o r o s o t) \<longlonglongrightarrow> limsup (v o r o s)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>t. \<lbrakk>strict_mono t; (v \<circ> r \<circ> s \<circ> t) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using limsup_subseq_lim
[PROOF STATE]
proof (prove)
using this:
\<exists>r. strict_mono r \<and> (?u \<circ> r) \<longlonglongrightarrow> limsup ?u

goal (1 subgoal):
 1. (\<And>t. \<lbrakk>strict_mono t; (v \<circ> r \<circ> s \<circ> t) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
strict_mono t
(v \<circ> r \<circ> s \<circ> t) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
define a where "a = r o s o t"
[PROOF STATE]
proof (state)
this:
a = r \<circ> s \<circ> t

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
have "strict_mono a"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. strict_mono a
[PROOF STEP]
using r s t
[PROOF STATE]
proof (prove)
using this:
strict_mono r
(w \<circ> r) \<longlonglongrightarrow> limsup w
strict_mono s
(u \<circ> r \<circ> s) \<longlonglongrightarrow> limsup (u \<circ> r)
strict_mono t
(v \<circ> r \<circ> s \<circ> t) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. strict_mono a
[PROOF STEP]
by (simp add: a_def strict_mono_o)
[PROOF STATE]
proof (state)
this:
strict_mono a

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
have l:"(w o a) \<longlonglongrightarrow> limsup w"
         "(u o a) \<longlonglongrightarrow> limsup (u o r)"
         "(v o a) \<longlonglongrightarrow> limsup (v o r o s)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (w \<circ> a) \<longlonglongrightarrow> limsup w &&& (u \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r) &&& (v \<circ> a) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)
[PROOF STEP]
apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. (u \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r)
 2. (v \<circ> a) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)
[PROOF STEP]
apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (v \<circ> a) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)
[PROOF STEP]
apply (metis (no_types, lifting) t(2) a_def comp_assoc)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
(w \<circ> a) \<longlonglongrightarrow> limsup w
(u \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r)
(v \<circ> a) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
have "limsup (u o r) \<le> limsup u"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. limsup (u \<circ> r) \<le> limsup u
[PROOF STEP]
by (simp add: limsup_subseq_mono r(1))
[PROOF STATE]
proof (state)
this:
limsup (u \<circ> r) \<le> limsup u

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limsup (u \<circ> r) \<le> limsup u
[PROOF STEP]
have a: "limsup (u o r) \<noteq> \<infinity>"
[PROOF STATE]
proof (prove)
using this:
limsup (u \<circ> r) \<le> limsup u

goal (1 subgoal):
 1. limsup (u \<circ> r) \<noteq> \<infinity>
[PROOF STEP]
using \<open>limsup u < \<infinity>\<close>
[PROOF STATE]
proof (prove)
using this:
limsup (u \<circ> r) \<le> limsup u
limsup u < \<infinity>

goal (1 subgoal):
 1. limsup (u \<circ> r) \<noteq> \<infinity>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
limsup (u \<circ> r) \<noteq> \<infinity>

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
have "limsup (v o r o s) \<le> limsup v"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. limsup (v \<circ> r \<circ> s) \<le> limsup v
[PROOF STEP]
by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) strict_mono_o)
[PROOF STATE]
proof (state)
this:
limsup (v \<circ> r \<circ> s) \<le> limsup v

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limsup (v \<circ> r \<circ> s) \<le> limsup v
[PROOF STEP]
have b: "limsup (v o r o s) \<noteq> \<infinity>"
[PROOF STATE]
proof (prove)
using this:
limsup (v \<circ> r \<circ> s) \<le> limsup v

goal (1 subgoal):
 1. limsup (v \<circ> r \<circ> s) \<noteq> \<infinity>
[PROOF STEP]
using \<open>limsup v < \<infinity>\<close>
[PROOF STATE]
proof (prove)
using this:
limsup (v \<circ> r \<circ> s) \<le> limsup v
limsup v < \<infinity>

goal (1 subgoal):
 1. limsup (v \<circ> r \<circ> s) \<noteq> \<infinity>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
limsup (v \<circ> r \<circ> s) \<noteq> \<infinity>

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
[PROOF STEP]
using l tendsto_add_ereal_general a b
[PROOF STATE]
proof (prove)
using this:
(w \<circ> a) \<longlonglongrightarrow> limsup w
(u \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r)
(v \<circ> a) \<longlonglongrightarrow> limsup (v \<circ> r \<circ> s)
\<lbrakk>\<not> (?x = \<infinity> \<and> ?y = - \<infinity> \<or> ?x = - \<infinity> \<and> ?y = \<infinity>); (?f \<longlongrightarrow> ?x) ?F; (?g \<longlongrightarrow> ?y) ?F\<rbrakk> \<Longrightarrow> ((\<lambda>x. ?f x + ?g x) \<longlongrightarrow> ?x + ?y) ?F
limsup (u \<circ> r) \<noteq> \<infinity>
limsup (v \<circ> r \<circ> s) \<noteq> \<infinity>

goal (1 subgoal):
 1. (\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
(\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) = w \<circ> a
[PROOF STEP]
unfolding w_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) = (\<lambda>n. u n + v n) \<circ> a
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) = w \<circ> a

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
(\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) = w \<circ> a
[PROOF STEP]
have "(w o a) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)"
[PROOF STATE]
proof (prove)
using this:
(\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
(\<lambda>n. (u \<circ> a) n + (v \<circ> a) n) = w \<circ> a

goal (1 subgoal):
 1. (w \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(w \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(w \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
[PROOF STEP]
have "limsup w = limsup (u o r) + limsup (v o r o s)"
[PROOF STATE]
proof (prove)
using this:
(w \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. limsup w = limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
[PROOF STEP]
using l(1) LIMSEQ_unique
[PROOF STATE]
proof (prove)
using this:
(w \<circ> a) \<longlonglongrightarrow> limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
(w \<circ> a) \<longlonglongrightarrow> limsup w
\<lbrakk>?X \<longlonglongrightarrow> ?a; ?X \<longlonglongrightarrow> ?b\<rbrakk> \<Longrightarrow> ?a = ?b

goal (1 subgoal):
 1. limsup w = limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
limsup w = limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limsup w = limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
[PROOF STEP]
have "limsup w \<le> limsup u + limsup v"
[PROOF STATE]
proof (prove)
using this:
limsup w = limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)

goal (1 subgoal):
 1. limsup w \<le> limsup u + limsup v
[PROOF STEP]
using \<open>limsup (u o r) \<le> limsup u\<close> \<open>limsup (v o r o s) \<le> limsup v\<close> add_mono
[PROOF STATE]
proof (prove)
using this:
limsup w = limsup (u \<circ> r) + limsup (v \<circ> r \<circ> s)
limsup (u \<circ> r) \<le> limsup u
limsup (v \<circ> r \<circ> s) \<le> limsup v
\<lbrakk>?a \<le> ?b; ?c \<le> ?d\<rbrakk> \<Longrightarrow> ?a + ?c \<le> ?b + ?d

goal (1 subgoal):
 1. limsup w \<le> limsup u + limsup v
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
limsup w \<le> limsup u + limsup v

goal (1 subgoal):
 1. \<not> (limsup u = \<infinity> \<or> limsup v = \<infinity>) \<Longrightarrow> limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limsup w \<le> limsup u + limsup v
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
limsup w \<le> limsup u + limsup v

goal (1 subgoal):
 1. limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
unfolding w_def
[PROOF STATE]
proof (prove)
using this:
limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v

goal (1 subgoal):
 1. limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma cos_angle: "cos (angle a b c) = (a - b) \<bullet> (c - b) / (dist a b * dist c b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cos (angle a b c) = (a - b) \<bullet> (c - b) / (dist a b * dist c b)
[PROOF STEP]
by (simp add: angle_def cos_vangle dist_norm)