[STATEMENT]
theorem mrbst_push_down_correct:
  fixes A B :: "'a :: linorder set"
  assumes "finite A" "finite B" "\<And>y. y \<in> A \<Longrightarrow> y < x" "\<And>y. y \<in> B \<Longrightarrow> x < y"
  shows   "do {l \<leftarrow> random_bst A; r \<leftarrow> random_bst B; mrbst_push_down l x r} =
             random_bst ({x} \<union> A \<union> B)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
from assms
[PROOF STATE]
proof (chain)
picking this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y
[PROOF STEP]
have "finite (A \<union> B)"
[PROOF STATE]
proof (prove)
using this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y

goal (1 subgoal):
 1. finite (A \<union> B)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
finite (A \<union> B)

goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
from this and assms
[PROOF STATE]
proof (chain)
picking this:
finite (A \<union> B)
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
finite (A \<union> B)
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y

goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
proof (induction "A \<union> B" arbitrary: A B rule: finite_psubset_induct)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
case (psubset A B)
[PROOF STATE]
proof (state)
this:
finite (A \<union> B)
\<lbrakk>?A \<union> ?B \<subset> A \<union> B; finite ?A; finite ?B; \<And>y. y \<in> ?A \<Longrightarrow> y < x; \<And>y. y \<in> ?B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst ?A \<bind> (\<lambda>l. random_bst ?B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> ?A \<union> ?B)
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
define m n where "m = card A" and "n = card B"
[PROOF STATE]
proof (state)
this:
m = card A
n = card B

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have A_ne: "A \<noteq> {}" if "m > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<noteq> {}
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
0 < m

goal (1 subgoal):
 1. A \<noteq> {}
[PROOF STEP]
by (auto simp: m_def)
[PROOF STATE]
proof (state)
this:
0 < m \<Longrightarrow> A \<noteq> {}

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have B_ne: "B \<noteq> {}" if "n > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. B \<noteq> {}
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
0 < n

goal (1 subgoal):
 1. B \<noteq> {}
[PROOF STEP]
by (auto simp: n_def)
[PROOF STATE]
proof (state)
this:
0 < n \<Longrightarrow> B \<noteq> {}

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
include monad_normalisation
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "do {l \<leftarrow> random_bst A; r \<leftarrow> random_bst B; mrbst_push_down l x r} =
          do {l \<leftarrow> random_bst A;
              r \<leftarrow> random_bst B;
              k \<leftarrow> pmf_of_set {0..m + n};
              if k < m then
                case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (\<lambda>r'. \<langle>ll, y, r'\<rangle>) (mrbst_push_down lr x r)
              else if k < m + n then
                case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl)
              else
                return_pmf \<langle>l, x, r\<rangle>
             }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r) else if k < m + n then case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl) else return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
using psubset.prems
[PROOF STATE]
proof (prove)
using this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y

goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r) else if k < m + n then case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl) else return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
by (subst mrbst_push_down.simps, intro bind_pmf_cong refl)
         (auto simp: size_random_bst m_def n_def)
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r) else if k < m + n then case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl) else return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r) else if k < m + n then case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl) else return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "\<dots> = do {k \<leftarrow> pmf_of_set {0..m + n};
                        if k < m then do {
                          l \<leftarrow> random_bst A;
                          r \<leftarrow> random_bst B;
                          case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (\<lambda>r'. \<langle>ll, y, r'\<rangle>) (mrbst_push_down lr x r)
                        } else if k < m + n then do {
                          l \<leftarrow> random_bst A;
                          r \<leftarrow> random_bst B;
                          case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl)
                        } else do {
                          l \<leftarrow> random_bst A;
                          r \<leftarrow> random_bst B;
                          return_pmf \<langle>l, x, r\<rangle>
                        }
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r) else if k < m + n then case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl) else return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) else if k < m + n then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
by (simp cong: if_cong)
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r) else if k < m + n then case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl) else return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) else if k < m + n then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r) else if k < m + n then case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl) else return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) else if k < m + n then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "\<dots> = do {k \<leftarrow> pmf_of_set {0..m + n};
                        if k < m then do {
                          y \<leftarrow> pmf_of_set A;
                          ll \<leftarrow> random_bst {z\<in>A. z < y};
                          r' \<leftarrow> do {lr \<leftarrow> random_bst {z\<in>A. z > y};
                                    r \<leftarrow> random_bst B;
                                    mrbst_push_down lr x r};
                          return_pmf \<langle>ll, y, r'\<rangle>
                        } else if k < m + n then do {
                          y \<leftarrow> pmf_of_set B;
                          l' \<leftarrow> do {l \<leftarrow> random_bst A;
                                    rl \<leftarrow> random_bst {z\<in>B. z < y};
                                    mrbst_push_down l x rl};
                          rr \<leftarrow> random_bst {z\<in>B. z > y};
                          return_pmf \<langle>l', y, rr\<rangle>
                        } else do {
                          l \<leftarrow> random_bst A;
                          r \<leftarrow> random_bst B;
                          return_pmf \<langle>l, x, r\<rangle>
                        }
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) else if k < m + n then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
proof (intro bind_pmf_cong refl if_cong, goal_cases)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) = pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>)))
 2. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
case (1 k)
[PROOF STATE]
proof (state)
this:
k \<in> set_pmf (pmf_of_set {0..m + n})
k < m

goal (2 subgoals):
 1. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) = pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>)))
 2. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
hence "A \<noteq> {}"
[PROOF STATE]
proof (prove)
using this:
k \<in> set_pmf (pmf_of_set {0..m + n})
k < m

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

goal (2 subgoals):
 1. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) = pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>)))
 2. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
with \<open>finite A\<close>
[PROOF STATE]
proof (chain)
picking this:
finite A
A \<noteq> {}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
finite A
A \<noteq> {}

goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) = pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>)))
[PROOF STEP]
by (simp add: random_bst_reduce map_pmf_def)
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) = pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>)))

goal (1 subgoal):
 1. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
case (2 k)
[PROOF STATE]
proof (state)
this:
k \<in> set_pmf (pmf_of_set {0..m + n})
\<not> k < m
k < m + n

goal (1 subgoal):
 1. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
hence "B \<noteq> {}"
[PROOF STATE]
proof (prove)
using this:
k \<in> set_pmf (pmf_of_set {0..m + n})
\<not> k < m
k < m + n

goal (1 subgoal):
 1. B \<noteq> {}
[PROOF STEP]
by (auto simp: m_def n_def)
[PROOF STATE]
proof (state)
this:
B \<noteq> {}

goal (1 subgoal):
 1. \<And>xa. \<lbrakk>xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
with \<open>finite B\<close>
[PROOF STATE]
proof (chain)
picking this:
finite B
B \<noteq> {}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
finite B
B \<noteq> {}

goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))
[PROOF STEP]
by (simp add: random_bst_reduce map_pmf_def)
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) = pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>)))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) else if k < m + n then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case l of \<langle>ll, y, lr\<rangle> \<Rightarrow> map_pmf (Node ll y) (mrbst_push_down lr x r))) else if k < m + n then random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. case r of \<langle>rl, y, rr\<rangle> \<Rightarrow> map_pmf (\<lambda>l'. \<langle>l', y, rr\<rangle>) (mrbst_push_down l x rl))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "\<dots> = do {k \<leftarrow> pmf_of_set {0..m + n};
                        if k < m then do {
                          y \<leftarrow> pmf_of_set A;
                          ll \<leftarrow> random_bst {z\<in>A. z < y};
                          r' \<leftarrow> random_bst ({x} \<union> {z\<in>A. z > y} \<union> B);
                          return_pmf \<langle>ll, y, r'\<rangle>
                        } else if k < m + n then do {
                          y \<leftarrow> pmf_of_set B;
                          l' \<leftarrow> random_bst ({x} \<union> A \<union> {z\<in>B. z < y});
                          rr \<leftarrow> random_bst {z\<in>B. z > y};
                          return_pmf \<langle>l', y, rr\<rangle>
                        } else do {
                          l \<leftarrow> random_bst A;
                          r \<leftarrow> random_bst B;
                          return_pmf \<langle>l, x, r\<rangle>
                        }
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
using psubset.prems A_ne B_ne
[PROOF STATE]
proof (prove)
using this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y
0 < m \<Longrightarrow> A \<noteq> {}
0 < n \<Longrightarrow> B \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
proof (intro bind_pmf_cong refl if_cong psubset)
[PROOF STATE]
proof (state)
goal (8 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> {z \<in> A. xaa < z} \<union> B \<subset> A \<union> B
 2. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 4. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 5. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> A \<union> {z \<in> B. z < xaa} \<subset> A \<union> B
 6. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 7. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 8. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
fix k y
[PROOF STATE]
proof (state)
goal (8 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> {z \<in> A. xaa < z} \<union> B \<subset> A \<union> B
 2. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 4. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 5. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> A \<union> {z \<in> B. z < xaa} \<subset> A \<union> B
 6. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 7. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 8. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
assume "k < m" "y \<in> set_pmf (pmf_of_set A)"
[PROOF STATE]
proof (state)
this:
k < m
y \<in> set_pmf (pmf_of_set A)

goal (8 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> {z \<in> A. xaa < z} \<union> B \<subset> A \<union> B
 2. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 4. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 5. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> A \<union> {z \<in> B. z < xaa} \<subset> A \<union> B
 6. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 7. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 8. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
thus "{z\<in>A. z > y} \<union> B \<subset> A \<union> B"
[PROOF STATE]
proof (prove)
using this:
k < m
y \<in> set_pmf (pmf_of_set A)

goal (1 subgoal):
 1. {z \<in> A. y < z} \<union> B \<subset> A \<union> B
[PROOF STEP]
using psubset.prems A_ne
[PROOF STATE]
proof (prove)
using this:
k < m
y \<in> set_pmf (pmf_of_set A)
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y
0 < m \<Longrightarrow> A \<noteq> {}

goal (1 subgoal):
 1. {z \<in> A. y < z} \<union> B \<subset> A \<union> B
[PROOF STEP]
by (fastforce dest!: in_set_pmf_of_setD)
[PROOF STATE]
proof (state)
this:
{z \<in> A. y < z} \<union> B \<subset> A \<union> B

goal (7 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 2. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 4. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> A \<union> {z \<in> B. z < xaa} \<subset> A \<union> B
 5. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 6. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 7. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (7 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 2. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 4. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> A \<union> {z \<in> B. z < xaa} \<subset> A \<union> B
 5. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 6. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 7. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
fix k y
[PROOF STATE]
proof (state)
goal (7 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 2. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 4. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> A \<union> {z \<in> B. z < xaa} \<subset> A \<union> B
 5. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 6. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 7. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
assume "\<not>k < m" "k < m + n" "y \<in> set_pmf (pmf_of_set B)"
[PROOF STATE]
proof (state)
this:
\<not> k < m
k < m + n
y \<in> set_pmf (pmf_of_set B)

goal (7 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 2. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 4. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> A \<union> {z \<in> B. z < xaa} \<subset> A \<union> B
 5. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 6. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 7. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
thus "A \<union> {z\<in>B. z < y} \<subset> A \<union> B"
[PROOF STATE]
proof (prove)
using this:
\<not> k < m
k < m + n
y \<in> set_pmf (pmf_of_set B)

goal (1 subgoal):
 1. A \<union> {z \<in> B. z < y} \<subset> A \<union> B
[PROOF STEP]
using psubset.prems B_ne
[PROOF STATE]
proof (prove)
using this:
\<not> k < m
k < m + n
y \<in> set_pmf (pmf_of_set B)
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y
0 < n \<Longrightarrow> B \<noteq> {}

goal (1 subgoal):
 1. A \<union> {z \<in> B. z < y} \<subset> A \<union> B
[PROOF STEP]
by (fastforce dest!: in_set_pmf_of_setD)
[PROOF STATE]
proof (state)
this:
A \<union> {z \<in> B. z < y} \<subset> A \<union> B

goal (6 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa})\<rbrakk> \<Longrightarrow> finite {z \<in> A. xaa < z}
 2. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> {z \<in> A. xaa < z}\<rbrakk> \<Longrightarrow> y \<in> A
 3. \<And>xa xaa xb y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); xa < m; xaa \<in> set_pmf (pmf_of_set A); xb \<in> set_pmf (random_bst {z \<in> A. z < xaa}); y \<in> B\<rbrakk> \<Longrightarrow> y \<in> B
 4. \<And>xa xaa. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B)\<rbrakk> \<Longrightarrow> finite {z \<in> B. z < xaa}
 5. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> A\<rbrakk> \<Longrightarrow> y \<in> A
 6. \<And>xa xaa y. \<lbrakk>finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y; 0 < m \<Longrightarrow> A \<noteq> {}; 0 < n \<Longrightarrow> B \<noteq> {}; xa \<in> set_pmf (pmf_of_set {0..m + n}); \<not> xa < m; xa < m + n; xaa \<in> set_pmf (pmf_of_set B); y \<in> {z \<in> B. z < xaa}\<rbrakk> \<Longrightarrow> y \<in> B
[PROOF STEP]
qed auto
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> A. y < z} \<bind> (\<lambda>lr. random_bst B \<bind> mrbst_push_down lr x) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst A \<bind> (\<lambda>l. random_bst {z \<in> B. z < y} \<bind> mrbst_push_down l x) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "\<dots> = do {k \<leftarrow> pmf_of_set {0..m + n};
                        if k < m then do {
                          y \<leftarrow> pmf_of_set A;
                          ll \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z < y};
                          r' \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z > y};
                          return_pmf \<langle>ll, y, r'\<rangle>
                        } else if k < m + n then do {
                          y \<leftarrow> pmf_of_set B;
                          l' \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z < y};
                          rr \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z > y};
                          return_pmf \<langle>l', y, rr\<rangle>
                        } else do {
                          l \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z < x};
                          r \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z > x};
                          return_pmf \<langle>l, x, r\<rangle>
                        }
                       }"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst {z \<in> {x} \<union> A \<union> B. z < x} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. x < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
using psubset.prems A_ne B_ne
[PROOF STATE]
proof (prove)
using this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y
0 < m \<Longrightarrow> A \<noteq> {}
0 < n \<Longrightarrow> B \<noteq> {}

goal (1 subgoal):
 1. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst {z \<in> {x} \<union> A \<union> B. z < x} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. x < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))
[PROOF STEP]
by (intro bind_pmf_cong if_cong refl arg_cong[of _ _ random_bst];
          force dest: psubset.prems(3,4))
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst {z \<in> {x} \<union> A \<union> B. z < x} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. x < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> A. z < y} \<bind> (\<lambda>ll. random_bst ({x} \<union> {z \<in> A. y < z} \<union> B) \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst ({x} \<union> A \<union> {z \<in> B. z < y}) \<bind> (\<lambda>l'. random_bst {z \<in> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst A \<bind> (\<lambda>l. random_bst B \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst {z \<in> {x} \<union> A \<union> B. z < x} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. x < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "\<dots> = do {k \<leftarrow> pmf_of_set {0..m + n};
                        if k < m then do {
                          y \<leftarrow> pmf_of_set A;
                          ll \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z < y};
                          r' \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z > y};
                          return_pmf \<langle>ll, y, r'\<rangle>
                        } else if k < m + n then do {
                          y \<leftarrow> pmf_of_set B;
                          l' \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z < y};
                          rr \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z > y};
                          return_pmf \<langle>l', y, rr\<rangle>
                        } else do {
                          y \<leftarrow> pmf_of_set {x};
                          l \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z < y};
                          r \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z > y};
                          return_pmf \<langle>l, x, r\<rangle>
                        }
                       }" (is "_ = ?X {0..m+n}")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst {z \<in> {x} \<union> A \<union> B. z < x} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. x < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))))
[PROOF STEP]
by (simp add: pmf_of_set_singleton cong: if_cong)
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst {z \<in> {x} \<union> A \<union> B. z < x} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. x < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else random_bst {z \<in> {x} \<union> A \<union> B. z < x} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. x < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))) = pmf_of_set {0..m + n} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>))))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "{0..m + n} = {..<card (A \<union> B \<union> {x})}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {0..m + n} = {..<card (A \<union> B \<union> {x})}
[PROOF STEP]
using psubset.prems
[PROOF STATE]
proof (prove)
using this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y

goal (1 subgoal):
 1. {0..m + n} = {..<card (A \<union> B \<union> {x})}
[PROOF STEP]
by (subst card_Un_disjoint, simp, simp, force)+
         (auto simp: m_def n_def)
[PROOF STATE]
proof (state)
this:
{0..m + n} = {..<card (A \<union> B \<union> {x})}

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
{0..m + n} = {..<card (A \<union> B \<union> {x})}

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "?X \<dots> = do {y \<leftarrow> pmf_of_set ({x} \<union> A \<union> B);
                           l \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z < y};
                           r \<leftarrow> random_bst {z\<in>{x} \<union> A \<union> B. z > y};
                           return_pmf \<langle>l, y, r\<rangle>}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {..<card (A \<union> B \<union> {x})} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))) = pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>)))
[PROOF STEP]
unfolding m_def n_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set {..<card (A \<union> B \<union> {x})} \<bind> (\<lambda>k. if k < card A then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < card A + card B then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))) = pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>)))
[PROOF STEP]
using psubset.prems
[PROOF STATE]
proof (prove)
using this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y

goal (1 subgoal):
 1. pmf_of_set {..<card (A \<union> B \<union> {x})} \<bind> (\<lambda>k. if k < card A then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < card A + card B then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))) = pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>)))
[PROOF STEP]
by (subst pmf_of_set_3way_split [symmetric])
         (auto dest!: psubset.prems(3,4) cong: if_cong intro: bind_pmf_cong)
[PROOF STATE]
proof (state)
this:
pmf_of_set {..<card (A \<union> B \<union> {x})} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))) = pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
pmf_of_set {..<card (A \<union> B \<union> {x})} \<bind> (\<lambda>k. if k < m then pmf_of_set A \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>ll. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r'. return_pmf \<langle>ll, y, r'\<rangle>))) else if k < m + n then pmf_of_set B \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l'. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>rr. return_pmf \<langle>l', y, rr\<rangle>))) else pmf_of_set {x} \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, x, r\<rangle>)))) = pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>)))

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
have "\<dots> = random_bst ({x} \<union> A \<union> B)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>))) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
using psubset.prems
[PROOF STATE]
proof (prove)
using this:
finite A
finite B
?y \<in> A \<Longrightarrow> ?y < x
?y \<in> B \<Longrightarrow> x < ?y

goal (1 subgoal):
 1. pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>))) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
by (simp add: random_bst_reduce)
[PROOF STATE]
proof (state)
this:
pmf_of_set ({x} \<union> A \<union> B) \<bind> (\<lambda>y. random_bst {z \<in> {x} \<union> A \<union> B. z < y} \<bind> (\<lambda>l. random_bst {z \<in> {x} \<union> A \<union> B. y < z} \<bind> (\<lambda>r. return_pmf \<langle>l, y, r\<rangle>))) = random_bst ({x} \<union> A \<union> B)

goal (1 subgoal):
 1. \<And>A B. \<lbrakk>finite (A \<union> B); \<And>Aa Ba. \<lbrakk>Aa \<union> Ba \<subset> A \<union> B; finite Aa; finite Ba; \<And>y. y \<in> Aa \<Longrightarrow> y < x; \<And>y. y \<in> Ba \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst Aa \<bind> (\<lambda>l. random_bst Ba \<bind> mrbst_push_down l x) = random_bst ({x} \<union> Aa \<union> Ba); finite A; finite B; \<And>y. y \<in> A \<Longrightarrow> y < x; \<And>y. y \<in> B \<Longrightarrow> x < y\<rbrakk> \<Longrightarrow> random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)

goal (1 subgoal):
 1. random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
random_bst A \<bind> (\<lambda>l. random_bst B \<bind> mrbst_push_down l x) = random_bst ({x} \<union> A \<union> B)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma arcs_ends_conv: "arcs_ends G = (\<lambda>e. (tail G e, head G e)) ` arcs G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. arcs_ends G = (\<lambda>e. (tail G e, head G e)) ` arcs G
[PROOF STEP]
by (auto simp: arc_to_ends_def arcs_ends_def)


[STATEMENT]
lemma ind_in_set_inj':
  fixes A B :: "nat set"
  assumes "B \<subseteq> A"
  shows "inj_on (ind_in_set A) B"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on (ind_in_set A) B
[PROOF STEP]
proof (rule inj_onI)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> B; y \<in> B; ind_in_set A x = ind_in_set A y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
fix x y
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> B; y \<in> B; ind_in_set A x = ind_in_set A y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
assume x: "x \<in> B" and y: "y \<in> B" and eq: "ind_in_set A x = ind_in_set A y"
[PROOF STATE]
proof (state)
this:
x \<in> B
y \<in> B
ind_in_set A x = ind_in_set A y

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> B; y \<in> B; ind_in_set A x = ind_in_set A y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
have x': "x \<in> A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<in> A
[PROOF STEP]
using x assms
[PROOF STATE]
proof (prove)
using this:
x \<in> B
B \<subseteq> A

goal (1 subgoal):
 1. x \<in> A
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
x \<in> A

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> B; y \<in> B; ind_in_set A x = ind_in_set A y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
have y': "y \<in> A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. y \<in> A
[PROOF STEP]
using y assms
[PROOF STATE]
proof (prove)
using this:
y \<in> B
B \<subseteq> A

goal (1 subgoal):
 1. y \<in> A
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
y \<in> A

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> B; y \<in> B; ind_in_set A x = ind_in_set A y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
show "x = y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x = y
[PROOF STEP]
by (rule ind_in_set_inj[OF x' y' eq])
[PROOF STATE]
proof (state)
this:
x = y

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma similar_mat_wit_refl: assumes A: "A \<in> carrier_mat n n"
  shows "similar_mat_wit A A (1\<^sub>m n) (1\<^sub>m n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. similar_mat_wit A A (1\<^sub>m n) (1\<^sub>m n)
[PROOF STEP]
by (rule similar_mat_witI[OF _ _ _ A], insert A, auto)


[STATEMENT]
theorem infinite_transfer (*[intro]*) :
"infinite B \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> infinite A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>infinite B; B \<subseteq> f ` A\<rbrakk> \<Longrightarrow> infinite A
[PROOF STEP]
using infinite_super
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?S \<subseteq> ?T; infinite ?S\<rbrakk> \<Longrightarrow> infinite ?T

goal (1 subgoal):
 1. \<lbrakk>infinite B; B \<subseteq> f ` A\<rbrakk> \<Longrightarrow> infinite A
[PROOF STEP]
apply (blast)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma of_nat_eq_add:
  fixes d::hypnat
  shows "of_nat m = of_nat n + d \<Longrightarrow> d \<in> range of_nat"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_nat m = of_nat n + d \<Longrightarrow> d \<in> range of_nat
[PROOF STEP]
proof (induct n arbitrary: d)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>d. of_nat m = of_nat 0 + d \<Longrightarrow> d \<in> range of_nat
 2. \<And>n d. \<lbrakk>\<And>d. of_nat m = of_nat n + d \<Longrightarrow> d \<in> range of_nat; of_nat m = of_nat (Suc n) + d\<rbrakk> \<Longrightarrow> d \<in> range of_nat
[PROOF STEP]
case (Suc n)
[PROOF STATE]
proof (state)
this:
of_nat m = of_nat n + ?d \<Longrightarrow> ?d \<in> range of_nat
of_nat m = of_nat (Suc n) + d

goal (2 subgoals):
 1. \<And>d. of_nat m = of_nat 0 + d \<Longrightarrow> d \<in> range of_nat
 2. \<And>n d. \<lbrakk>\<And>d. of_nat m = of_nat n + d \<Longrightarrow> d \<in> range of_nat; of_nat m = of_nat (Suc n) + d\<rbrakk> \<Longrightarrow> d \<in> range of_nat
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
of_nat m = of_nat n + ?d \<Longrightarrow> ?d \<in> range of_nat
of_nat m = of_nat (Suc n) + d
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
of_nat m = of_nat n + ?d \<Longrightarrow> ?d \<in> range of_nat
of_nat m = of_nat (Suc n) + d

goal (1 subgoal):
 1. d \<in> range of_nat
[PROOF STEP]
by (metis Nats_def Nats_eq_Standard Standard_simps(4) hypnat_diff_add_inverse of_nat_in_Nats)
[PROOF STATE]
proof (state)
this:
d \<in> range of_nat

goal (1 subgoal):
 1. \<And>d. of_nat m = of_nat 0 + d \<Longrightarrow> d \<in> range of_nat
[PROOF STEP]
qed auto


[STATEMENT]
lemma is_binqueue_children:
  assumes "is_bintree_list l ts"
  and "is_heap_list t ts"
  shows "is_binqueue 0 (map Some (rev ts))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. is_binqueue 0 (map Some (rev ts))
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
is_bintree_list l ts
is_heap_list t ts

goal (1 subgoal):
 1. is_binqueue 0 (map Some (rev ts))
[PROOF STEP]
by (induct ts) (auto simp add: is_binqueue_append)


[STATEMENT]
lemma map2_length:
  assumes "length Al = length Bl"
  shows "length (map2 f Al Bl) = length Al"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length (map2 f Al Bl) = length Al
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
length Al = length Bl

goal (1 subgoal):
 1. length (map2 f Al Bl) = length Al
[PROOF STEP]
by simp


[STATEMENT]
lemma push_bit_of_Suc_0 [simp]:
  \<open>push_bit n (Suc 0) = 2 ^ n\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. push_bit n (Suc 0) = 2 ^ n
[PROOF STEP]
using push_bit_of_1 [where ?'a = nat]
[PROOF STATE]
proof (prove)
using this:
push_bit ?n 1 = 2 ^ ?n

goal (1 subgoal):
 1. push_bit n (Suc 0) = 2 ^ n
[PROOF STEP]
by simp


[STATEMENT]
lemma reflp_llist_all2: "reflp R \<Longrightarrow> reflp (llist_all2 R)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reflp R \<Longrightarrow> reflp (llist_all2 R)
[PROOF STEP]
by (rule reflpI) (auto simp add: llist_all2_conv_all_lnth elim: reflpE)


[STATEMENT]
lemma extensional_subset: "f \<in> extensional A \<Longrightarrow> A \<subseteq> B \<Longrightarrow> f \<in> extensional B"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>f \<in> extensional A; A \<subseteq> B\<rbrakk> \<Longrightarrow> f \<in> extensional B
[PROOF STEP]
unfolding extensional_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>f \<in> {f. \<forall>x. x \<notin> A \<longrightarrow> f x = undefined}; A \<subseteq> B\<rbrakk> \<Longrightarrow> f \<in> {f. \<forall>x. x \<notin> B \<longrightarrow> f x = undefined}
[PROOF STEP]
by auto


[STATEMENT]
lemma vsubset_vintersection_rightD[dest]:
  assumes "A \<subseteq>\<^sub>\<circ> (B \<inter>\<^sub>\<circ> C)"
  shows "A \<subseteq>\<^sub>\<circ> B" and "A \<subseteq>\<^sub>\<circ> C"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<subseteq>\<^sub>\<circ> B &&& A \<subseteq>\<^sub>\<circ> C
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
A \<subseteq>\<^sub>\<circ> B \<inter>\<^sub>\<circ> C

goal (1 subgoal):
 1. A \<subseteq>\<^sub>\<circ> B &&& A \<subseteq>\<^sub>\<circ> C
[PROOF STEP]
by auto