[STATEMENT]
lemma round_count_inv [rule_format]:
 "index_less index key \<longrightarrow> bn_inv p q t \<longrightarrow> add_inv n t \<longrightarrow> count_inv f t \<longrightarrow>
    count_inv f (round index key p q r t)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index_less index key \<longrightarrow> bn_inv p q t \<longrightarrow> add_inv n t \<longrightarrow> count_inv f t \<longrightarrow> count_inv f (round index key p q r t)
[PROOF STEP]
proof (induction index key p q r t arbitrary: n f rule: round.induct,
 (rule_tac [!] impI)+, simp, simp, simp_all only: simp_thms)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>index key p q r u ns xs n f. \<lbrakk>\<And>n f. bn_inv p q (u, ns, tl xs) \<longrightarrow> add_inv n (u, ns, tl xs) \<longrightarrow> count_inv f (u, ns, tl xs) \<longrightarrow> count_inv f (round index key p q r (u, ns, tl xs)); index_less index key; bn_inv p q (u, Suc 0 # ns, xs); add_inv n (u, Suc 0 # ns, xs); count_inv f (u, Suc 0 # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc 0 # ns, xs))
 2. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
fix index p q r u ns xs n f and key :: "'a \<Rightarrow> 'b"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>index key p q r u ns xs n f. \<lbrakk>\<And>n f. bn_inv p q (u, ns, tl xs) \<longrightarrow> add_inv n (u, ns, tl xs) \<longrightarrow> count_inv f (u, ns, tl xs) \<longrightarrow> count_inv f (round index key p q r (u, ns, tl xs)); index_less index key; bn_inv p q (u, Suc 0 # ns, xs); add_inv n (u, Suc 0 # ns, xs); count_inv f (u, Suc 0 # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc 0 # ns, xs))
 2. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
let ?t = "round index key p q r (u, ns, tl xs)"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>index key p q r u ns xs n f. \<lbrakk>\<And>n f. bn_inv p q (u, ns, tl xs) \<longrightarrow> add_inv n (u, ns, tl xs) \<longrightarrow> count_inv f (u, ns, tl xs) \<longrightarrow> count_inv f (round index key p q r (u, ns, tl xs)); index_less index key; bn_inv p q (u, Suc 0 # ns, xs); add_inv n (u, Suc 0 # ns, xs); count_inv f (u, Suc 0 # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc 0 # ns, xs))
 2. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
assume
   "\<And>n f. bn_inv p q (u, ns, tl xs) \<longrightarrow> add_inv n (u, ns, tl xs) \<longrightarrow>
      count_inv f (u, ns, tl xs) \<longrightarrow> count_inv f ?t" and
   "bn_inv p q (u, Suc 0 # ns, xs)" and
   "add_inv n (u, Suc 0 # ns, xs)" and
   "count_inv f (u, Suc 0 # ns, xs)"
[PROOF STATE]
proof (state)
this:
bn_inv p q (u, ns, tl xs) \<longrightarrow> add_inv ?n (u, ns, tl xs) \<longrightarrow> count_inv ?f (u, ns, tl xs) \<longrightarrow> count_inv ?f (round index key p q r (u, ns, tl xs))
bn_inv p q (u, Suc 0 # ns, xs)
add_inv n (u, Suc 0 # ns, xs)
count_inv f (u, Suc 0 # ns, xs)

goal (2 subgoals):
 1. \<And>index key p q r u ns xs n f. \<lbrakk>\<And>n f. bn_inv p q (u, ns, tl xs) \<longrightarrow> add_inv n (u, ns, tl xs) \<longrightarrow> count_inv f (u, ns, tl xs) \<longrightarrow> count_inv f (round index key p q r (u, ns, tl xs)); index_less index key; bn_inv p q (u, Suc 0 # ns, xs); add_inv n (u, Suc 0 # ns, xs); count_inv f (u, Suc 0 # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc 0 # ns, xs))
 2. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
thus "count_inv f (round index key p q r (u, Suc 0 # ns, xs))"
[PROOF STATE]
proof (prove)
using this:
bn_inv p q (u, ns, tl xs) \<longrightarrow> add_inv ?n (u, ns, tl xs) \<longrightarrow> count_inv ?f (u, ns, tl xs) \<longrightarrow> count_inv ?f (round index key p q r (u, ns, tl xs))
bn_inv p q (u, Suc 0 # ns, xs)
add_inv n (u, Suc 0 # ns, xs)
count_inv f (u, Suc 0 # ns, xs)

goal (1 subgoal):
 1. count_inv f (round index key p q r (u, Suc 0 # ns, xs))
[PROOF STEP]
proof (cases ?t, simp add: add_suc, rule_tac allI, cases xs,
   simp_all add: disj_imp split: if_split_asm)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
fix y ys x and xs' :: "'a list"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
assume "\<And>n f. foldl (+) 0 ns = n \<and> length ys = n \<longrightarrow>
      (\<forall>x. count (mset ys) x = f x) \<longrightarrow> (\<forall>x. count (mset xs') x = f x)"
[PROOF STATE]
proof (state)
this:
foldl (+) 0 ns = ?n \<and> length ys = ?n \<longrightarrow> (\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
foldl (+) 0 ns = ?n \<and> length ys = ?n \<longrightarrow> (\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
assume "Suc (foldl (+) 0 ns) = n" and "Suc (length ys) = n"
[PROOF STATE]
proof (state)
this:
Suc (foldl (+) 0 ns) = n
Suc (length ys) = n

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
foldl (+) 0 ns = ?n \<and> length ys = ?n \<longrightarrow> (\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)
Suc (foldl (+) 0 ns) = n
Suc (length ys) = n
[PROOF STEP]
have "\<And>n f. (\<forall>x. count (mset ys) x = f x) \<longrightarrow>
      (\<forall>x. count (mset xs') x = f x)"
[PROOF STATE]
proof (prove)
using this:
foldl (+) 0 ns = ?n \<and> length ys = ?n \<longrightarrow> (\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)
Suc (foldl (+) 0 ns) = n
Suc (length ys) = n

goal (1 subgoal):
 1. \<And>n f. (\<forall>x. count (mset ys) x = f x) \<longrightarrow> (\<forall>x. count (mset xs') x = f x)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
(\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
assume A: "\<forall>x. (y = x \<longrightarrow> Suc (count (mset ys) x) = f x) \<and>
      (y \<noteq> x \<longrightarrow> count (mset ys) x = f x)"
[PROOF STATE]
proof (state)
this:
\<forall>x. (y = x \<longrightarrow> Suc (count (mset ys) x) = f x) \<and> (y \<noteq> x \<longrightarrow> count (mset ys) x = f x)

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
have "\<forall>x. count (mset ys) x = (f(y := f y - Suc 0)) x"
      (is "\<forall>x. _ = ?f' x")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>x. count (mset ys) x = (f(y := f y - Suc 0)) x
[PROOF STEP]
by (simp add: A, insert spec [OF A, where x = y], simp)
[PROOF STATE]
proof (state)
this:
\<forall>x. count (mset ys) x = (f(y := f y - Suc 0)) x

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)
\<forall>x. count (mset ys) x = (f(y := f y - Suc 0)) x
[PROOF STEP]
have "\<forall>x. count (mset xs') x = ?f' x"
[PROOF STATE]
proof (prove)
using this:
(\<forall>x. count (mset ys) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)
\<forall>x. count (mset ys) x = (f(y := f y - Suc 0)) x

goal (1 subgoal):
 1. \<forall>x. count (mset xs') x = (f(y := f y - Suc 0)) x
[PROOF STEP]
..
[PROOF STATE]
proof (state)
this:
\<forall>x. count (mset xs') x = (f(y := f y - Suc 0)) x

goal (1 subgoal):
 1. \<And>a b c x aa list. \<lbrakk>\<forall>x. (aa = x \<longrightarrow> Suc (count (mset list) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset list) x = f x); round index key p q r (u, ns, list) = (a, b, c); \<And>n f. foldl (+) 0 ns = n \<and> length list = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); foldl (+) (Suc 0) ns = n; xs = aa # list; \<And>n f. foldl (+) 0 ns = n \<and> n - Suc 0 = n \<longrightarrow> (\<forall>x. count (mset list) x = f x) \<longrightarrow> (\<forall>x. count (mset c) x = f x); \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (foldl (+) 0 ns) = n; Suc (length list) = n\<rbrakk> \<Longrightarrow> (aa = x \<longrightarrow> Suc (count (mset c) x) = f x) \<and> (aa \<noteq> x \<longrightarrow> count (mset c) x = f x)
[PROOF STEP]
thus "(y = x \<longrightarrow> Suc (count (mset xs') x) = f x) \<and>
      (y \<noteq> x \<longrightarrow> count (mset xs') x = f x)"
[PROOF STATE]
proof (prove)
using this:
\<forall>x. count (mset xs') x = (f(y := f y - Suc 0)) x

goal (1 subgoal):
 1. (y = x \<longrightarrow> Suc (count (mset xs') x) = f x) \<and> (y \<noteq> x \<longrightarrow> count (mset xs') x = f x)
[PROOF STEP]
by (simp, insert spec [OF A, where x = y], rule_tac impI, simp)
[PROOF STATE]
proof (state)
this:
(y = x \<longrightarrow> Suc (count (mset xs') x) = f x) \<and> (y \<noteq> x \<longrightarrow> count (mset xs') x = f x)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
count_inv f (round index key p q r (u, Suc 0 # ns, xs))

goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
fix index p q r u m ns n f and key :: "'a \<Rightarrow> 'b" and xs :: "'a list"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
let ?ws = "take (Suc (Suc m)) xs"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
let ?ys = "drop (Suc (Suc m)) xs"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
let ?r = "\<lambda>m'. round_suc_suc index key ?ws m m' u"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
let ?t = "\<lambda>r' v. round index key p q r' (v, ns, ?ys)"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
assume A: "index_less index key"
[PROOF STATE]
proof (state)
this:
index_less index key

goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
assume
   "\<And>ws a b c d e g h i n f.
      ws = ?ws \<Longrightarrow> a = bn_comp m p q r \<Longrightarrow> (b, c) = bn_comp m p q r \<Longrightarrow>
      d = ?r b \<Longrightarrow> (e, g) = ?r b \<Longrightarrow> (h, i) = g \<Longrightarrow>
        bn_inv p q (e, ns, ?ys) \<longrightarrow> add_inv n (e, ns, ?ys) \<longrightarrow>
          count_inv f (e, ns, ?ys) \<longrightarrow> count_inv f (?t c e)" and
   "bn_inv p q (u, Suc (Suc m) # ns, xs)" and
   "add_inv n (u, Suc (Suc m) # ns, xs)" and
   "count_inv f (u, Suc (Suc m) # ns, xs)"
[PROOF STATE]
proof (state)
this:
\<lbrakk>?ws = take (Suc (Suc m)) xs; ?a = bn_comp m p q r; (?b, ?c) = bn_comp m p q r; ?d = round_suc_suc index key (take (Suc (Suc m)) xs) m ?b u; (?e, ?g) = round_suc_suc index key (take (Suc (Suc m)) xs) m ?b u; (?h, ?i) = ?g\<rbrakk> \<Longrightarrow> bn_inv p q (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> add_inv ?n (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> count_inv ?f (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> count_inv ?f (round index key p q ?c (?e, ns, drop (Suc (Suc m)) xs))
bn_inv p q (u, Suc (Suc m) # ns, xs)
add_inv n (u, Suc (Suc m) # ns, xs)
count_inv f (u, Suc (Suc m) # ns, xs)

goal (1 subgoal):
 1. \<And>index key p q r u n ns xs na f. \<lbrakk>\<And>x xa xb y xaa xc ya xd yb na f. \<lbrakk>x = take (Suc (Suc n)) xs; xa = bn_comp n p q r; (xb, y) = bn_comp n p q r; xaa = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xc, ya) = round_suc_suc index key (take (Suc (Suc n)) xs) n xb u; (xd, yb) = ya\<rbrakk> \<Longrightarrow> bn_inv p q (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> add_inv na (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (xc, ns, drop (Suc (Suc n)) xs) \<longrightarrow> count_inv f (round index key p q y (xc, ns, drop (Suc (Suc n)) xs)); index_less index key; bn_inv p q (u, Suc (Suc n) # ns, xs); add_inv na (u, Suc (Suc n) # ns, xs); count_inv f (u, Suc (Suc n) # ns, xs)\<rbrakk> \<Longrightarrow> count_inv f (round index key p q r (u, Suc (Suc n) # ns, xs))
[PROOF STEP]
thus "count_inv f (round index key p q r (u, Suc (Suc m) # ns, xs))"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?ws = take (Suc (Suc m)) xs; ?a = bn_comp m p q r; (?b, ?c) = bn_comp m p q r; ?d = round_suc_suc index key (take (Suc (Suc m)) xs) m ?b u; (?e, ?g) = round_suc_suc index key (take (Suc (Suc m)) xs) m ?b u; (?h, ?i) = ?g\<rbrakk> \<Longrightarrow> bn_inv p q (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> add_inv ?n (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> count_inv ?f (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> count_inv ?f (round index key p q ?c (?e, ns, drop (Suc (Suc m)) xs))
bn_inv p q (u, Suc (Suc m) # ns, xs)
add_inv n (u, Suc (Suc m) # ns, xs)
count_inv f (u, Suc (Suc m) # ns, xs)

goal (1 subgoal):
 1. count_inv f (round index key p q r (u, Suc (Suc m) # ns, xs))
[PROOF STEP]
using [[simproc del: defined_all]]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?ws = take (Suc (Suc m)) xs; ?a = bn_comp m p q r; (?b, ?c) = bn_comp m p q r; ?d = round_suc_suc index key (take (Suc (Suc m)) xs) m ?b u; (?e, ?g) = round_suc_suc index key (take (Suc (Suc m)) xs) m ?b u; (?h, ?i) = ?g\<rbrakk> \<Longrightarrow> bn_inv p q (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> add_inv ?n (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> count_inv ?f (?e, ns, drop (Suc (Suc m)) xs) \<longrightarrow> count_inv ?f (round index key p q ?c (?e, ns, drop (Suc (Suc m)) xs))
bn_inv p q (u, Suc (Suc m) # ns, xs)
add_inv n (u, Suc (Suc m) # ns, xs)
count_inv f (u, Suc (Suc m) # ns, xs)

goal (1 subgoal):
 1. count_inv f (round index key p q r (u, Suc (Suc m) # ns, xs))
[PROOF STEP]
proof (simp split: prod.split, ((rule_tac allI)+, ((rule_tac impI)+)?)+,
   (erule_tac conjE)+, subst (asm) (2) add_base_zero, simp)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
fix m' r' v ms' ws' xs' x
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
assume
      B: "?r m' = (v, ms', ws')" and
      C: "bn_comp m p q r = (m', r')" and
      D: "bn_valid m p q" and
      E: "Suc (Suc (foldl (+) 0 ns + m)) = n" and
      F: "length xs = n"
[PROOF STATE]
proof (state)
this:
round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = (v, ms', ws')
bn_comp m p q r = (m', r')
bn_valid m p q
Suc (Suc (foldl (+) 0 ns + m)) = n
length xs = n

goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
assume "\<And>ws a b c d e g h i n' f.
      ws = ?ws \<Longrightarrow> a = (m', r') \<Longrightarrow> b = m' \<and> c = r' \<Longrightarrow>
      d = (v, ms', ws') \<Longrightarrow> e = v \<and> g = (ms', ws') \<Longrightarrow> h = ms' \<and> i = ws' \<Longrightarrow>
        foldl (+) 0 ns = n' \<and> n - Suc (Suc m) = n' \<longrightarrow>
          (\<forall>x. count (mset ?ys) x = f x) \<longrightarrow> (\<forall>x. count (mset xs') x = f x)"
[PROOF STATE]
proof (state)
this:
\<lbrakk>?ws = take (Suc (Suc m)) xs; ?a = (m', r'); ?b = m' \<and> ?c = r'; ?d = (v, ms', ws'); ?e = v \<and> ?g = (ms', ws'); ?h = ms' \<and> ?i = ws'\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = ?n' \<and> n - Suc (Suc m) = ?n' \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)

goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
hence "foldl (+) 0 ns = n - Suc (Suc m) \<longrightarrow>
      (\<forall>x. count (mset xs') x = count (mset ?ys) x)"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?ws = take (Suc (Suc m)) xs; ?a = (m', r'); ?b = m' \<and> ?c = r'; ?d = (v, ms', ws'); ?e = v \<and> ?g = (ms', ws'); ?h = ms' \<and> ?i = ws'\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = ?n' \<and> n - Suc (Suc m) = ?n' \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = ?f x) \<longrightarrow> (\<forall>x. count (mset xs') x = ?f x)

goal (1 subgoal):
 1. foldl (+) 0 ns = n - Suc (Suc m) \<longrightarrow> (\<forall>x. count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
foldl (+) 0 ns = n - Suc (Suc m) \<longrightarrow> (\<forall>x. count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x)

goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
hence "count (mset xs') x = count (mset ?ys) x"
[PROOF STATE]
proof (prove)
using this:
foldl (+) 0 ns = n - Suc (Suc m) \<longrightarrow> (\<forall>x. count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x)

goal (1 subgoal):
 1. count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x
[PROOF STEP]
using E
[PROOF STATE]
proof (prove)
using this:
foldl (+) 0 ns = n - Suc (Suc m) \<longrightarrow> (\<forall>x. count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x)
Suc (Suc (foldl (+) 0 ns + m)) = n

goal (1 subgoal):
 1. count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
assume "\<forall>x. count (mset xs) x = f x"
[PROOF STATE]
proof (state)
this:
\<forall>x. count (mset xs) x = f x

goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x
\<forall>x. count (mset xs) x = f x
[PROOF STEP]
have "f x = count (mset ?ws) x + count (mset xs') x"
[PROOF STATE]
proof (prove)
using this:
count (mset xs') x = count (mset (drop (Suc (Suc m)) xs)) x
\<forall>x. count (mset xs) x = f x

goal (1 subgoal):
 1. f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x
[PROOF STEP]
by (subst (asm) append_take_drop_id [of "Suc (Suc m)", symmetric],
       subst (asm) mset_append, simp)
[PROOF STATE]
proof (state)
this:
f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x

goal (1 subgoal):
 1. \<And>x1 x2 x1a a b x1b aa ba x. \<lbrakk>\<And>ws aa bb c d e g h i n f. \<lbrakk>ws = take (Suc (Suc m)) xs; aa = (x1, x2); bb = x1 \<and> c = x2; d = (x1a, a, b); e = x1a \<and> g = (a, b); h = a \<and> i = b\<rbrakk> \<Longrightarrow> foldl (+) 0 ns = n \<and> n - Suc (Suc m) = n \<longrightarrow> (\<forall>x. count (mset (drop (Suc (Suc m)) xs)) x = f x) \<longrightarrow> (\<forall>x. count (mset ba) x = f x); \<forall>x. count (mset xs) x = f x; foldl (+) (Suc (Suc m)) ns = n; round index key p q x2 (x1a, ns, drop (Suc (Suc m)) xs) = (x1b, aa, ba); round_suc_suc index key (take (Suc (Suc m)) xs) m x1 u = (x1a, a, b); bn_comp m p q r = (x1, x2); bn_valid m p q; \<forall>x\<in>set ns. case x of 0 \<Rightarrow> True | Suc 0 \<Rightarrow> True | Suc (Suc m) \<Rightarrow> bn_valid m p q; Suc (Suc (foldl (+) 0 ns + m)) = n; length xs = n\<rbrakk> \<Longrightarrow> count (mset b) x + count (mset ba) x = f x
[PROOF STEP]
with B [symmetric]
[PROOF STATE]
proof (chain)
picking this:
(v, ms', ws') = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u
f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x
[PROOF STEP]
show "count (mset ws') x + count (mset xs') x = f x"
[PROOF STATE]
proof (prove)
using this:
(v, ms', ws') = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u
f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x

goal (1 subgoal):
 1. count (mset ws') x + count (mset xs') x = f x
[PROOF STEP]
proof (simp add: round_suc_suc_def Let_def del: count_add_mset mset_map
     split: if_split_asm, subst (1 2) add_mset_add_single, simp
     only: count_single count_union)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?nmi = "mini ?ws key"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?nma = "maxi ?ws key"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?xmi = "?ws ! ?nmi"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?xma = "?ws ! ?nma"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?mi = "key ?xmi"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?ma = "key ?xma"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?k = "case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?zs = "nths ?ws (- {?nmi, ?nma})"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?ms = "enum ?zs index key ?k ?mi ?ma"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
let ?A = "{i. i < Suc (Suc m) \<and> (i = ?nmi \<or> i = ?nma) \<and> ?ws ! i = x}"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
have G: "length ?ws = Suc (Suc m)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length (take (Suc (Suc m)) xs) = Suc (Suc m)
[PROOF STEP]
using E and F
[PROOF STATE]
proof (prove)
using this:
Suc (Suc (foldl (+) 0 ns + m)) = n
length xs = n

goal (1 subgoal):
 1. length (take (Suc (Suc m)) xs) = Suc (Suc m)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)

goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
hence H: "card ?A \<le> count (mset ?ws) x"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)

goal (1 subgoal):
 1. card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} \<le> count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
by (simp add: count_mset length_filter_conv_card, rule_tac card_mono,
         simp, blast)
[PROOF STATE]
proof (state)
this:
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} \<le> count (mset (take (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. \<lbrakk>count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x; key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key) \<noteq> key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key); v = u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') \<and> ms' = Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0] \<and> ws' = take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]; (u + m' - (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m'), Suc 0 # enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key)) @ [Suc 0], take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key # map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) @ [take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key]) = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; True; round_suc_suc index key (take (Suc (Suc m)) xs) m m' u = round_suc_suc index key (take (Suc (Suc m)) xs) m m' u; f x = count (mset (take (Suc (Suc m)) xs)) x + count (mset xs') x\<rbrakk> \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
show "count (mset (map the (fill ?zs (offs ?ms 0) index key m ?mi ?ma))) x
        + (if ?xma = x then 1 else 0) + (if ?xmi = x then 1 else 0) =
        count (mset ?ws) x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
proof (cases "m = 0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. m = 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
 2. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
m = 0

goal (2 subgoals):
 1. m = 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
 2. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
hence I: "length ?zs = 0"
[PROOF STATE]
proof (prove)
using this:
m = 0

goal (1 subgoal):
 1. length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0
[PROOF STEP]
using G
[PROOF STATE]
proof (prove)
using this:
m = 0
length (take (Suc (Suc m)) xs) = Suc (Suc m)

goal (1 subgoal):
 1. length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0
[PROOF STEP]
by (simp add: mini_maxi_nths)
[PROOF STATE]
proof (state)
this:
length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0

goal (2 subgoals):
 1. m = 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
 2. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
have "count (mset ?zs) x = count (mset ?ws) x - card ?A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}
[PROOF STEP]
using G
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)

goal (1 subgoal):
 1. count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}
[PROOF STEP]
by (subst nths_count, simp)
[PROOF STATE]
proof (state)
this:
count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}

goal (2 subgoals):
 1. m = 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
 2. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
hence J: "count (mset ?ws) x = card ?A"
[PROOF STATE]
proof (prove)
using this:
count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}

goal (1 subgoal):
 1. count (mset (take (Suc (Suc m)) xs)) x = card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}
[PROOF STEP]
using H and I
[PROOF STATE]
proof (prove)
using this:
count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} \<le> count (mset (take (Suc (Suc m)) xs)) x
length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0

goal (1 subgoal):
 1. count (mset (take (Suc (Suc m)) xs)) x = card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
count (mset (take (Suc (Suc m)) xs)) x = card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}

goal (2 subgoals):
 1. m = 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
 2. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
from I
[PROOF STATE]
proof (chain)
picking this:
length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0

goal (1 subgoal):
 1. count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
proof (simp, (rule_tac [!] conjI, rule_tac [!] impI)+,
         simp_all (no_asm_simp) add: True)
[PROOF STATE]
proof (state)
goal (4 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 4. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
assume "?xmi = x" and "?xma = x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (4 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 4. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x
[PROOF STEP]
have "?A = {?nmi, ?nma}"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, erule_tac disjE,
             insert mini_less [of ?ws key], insert maxi_less [of ?ws key],
             simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}

goal (4 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 4. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}
[PROOF STEP]
have "card ?A = Suc (Suc 0)"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}

goal (1 subgoal):
 1. card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)
[PROOF STEP]
by (simp, subst card_insert_disjoint, simp_all,
             rule_tac mini_maxi_neq, simp)
[PROOF STATE]
proof (state)
this:
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)

goal (4 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 4. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
thus "Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x"
[PROOF STATE]
proof (prove)
using this:
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)

goal (1 subgoal):
 1. Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x
[PROOF STEP]
using True and J
[PROOF STATE]
proof (prove)
using this:
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)
m = 0
count (mset (take (Suc (Suc m)) xs)) x = card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}

goal (1 subgoal):
 1. Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Suc (Suc 0) = count (mset (take (Suc (Suc 0)) xs)) x

goal (3 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
assume "?xmi \<noteq> x" and "?xma = x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (3 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x
[PROOF STEP]
have "?A = {?nma}"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, (erule_tac conjE)+,
             erule_tac disjE, insert maxi_less [of ?ws key], simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}

goal (3 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 3. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
thus "Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x"
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}

goal (1 subgoal):
 1. Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
[PROOF STEP]
using True and J
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}
m = 0
count (mset (take (Suc (Suc m)) xs)) x = card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}

goal (1 subgoal):
 1. Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x

goal (2 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
assume "?xmi = x" and "?xma \<noteq> x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (2 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x
[PROOF STEP]
have "?A = {?nmi}"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, (erule_tac conjE)+,
             erule_tac disjE, insert mini_less [of ?ws key], simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}

goal (2 subgoals):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
 2. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
thus "Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x"
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}

goal (1 subgoal):
 1. Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
[PROOF STEP]
using True and J
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}
m = 0
count (mset (take (Suc (Suc m)) xs)) x = card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}

goal (1 subgoal):
 1. Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Suc 0 = count (mset (take (Suc (Suc 0)) xs)) x

goal (1 subgoal):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
assume "?xmi \<noteq> x" and "?xma \<noteq> x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (1 subgoal):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
hence "?A = {}"
[PROOF STATE]
proof (prove)
using this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, (erule_tac conjE)+,
             erule_tac disjE, simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {}

goal (1 subgoal):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
hence "count (mset ?ws) x = 0"
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {}

goal (1 subgoal):
 1. count (mset (take (Suc (Suc m)) xs)) x = 0
[PROOF STEP]
using J
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {}
count (mset (take (Suc (Suc m)) xs)) x = card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}

goal (1 subgoal):
 1. count (mset (take (Suc (Suc m)) xs)) x = 0
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
count (mset (take (Suc (Suc m)) xs)) x = 0

goal (1 subgoal):
 1. \<lbrakk>nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}) = []; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x; length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) = 0\<rbrakk> \<Longrightarrow> x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
thus "x \<notin> set (take (Suc (Suc 0)) xs)"
[PROOF STATE]
proof (prove)
using this:
count (mset (take (Suc (Suc m)) xs)) x = 0

goal (1 subgoal):
 1. x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
using True
[PROOF STATE]
proof (prove)
using this:
count (mset (take (Suc (Suc m)) xs)) x = 0
m = 0

goal (1 subgoal):
 1. x \<notin> set (take (Suc (Suc 0)) xs)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
x \<notin> set (take (Suc (Suc 0)) xs)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
m \<noteq> 0

goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
hence "0 < ?k"
[PROOF STATE]
proof (prove)
using this:
m \<noteq> 0

goal (1 subgoal):
 1. 0 < (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m')
[PROOF STEP]
by (simp, drule_tac bn_comp_fst_nonzero [OF D], subst (asm) C,
           simp split: nat.split)
[PROOF STATE]
proof (state)
this:
0 < (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m')

goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
hence "count (mset (map the (fill ?zs (offs ?ms 0) index key
          (length ?zs) ?mi ?ma))) x = count (mset ?zs) x"
[PROOF STATE]
proof (prove)
using this:
0 < (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m')

goal (1 subgoal):
 1. count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key (length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x
[PROOF STEP]
by (rule_tac fill_offs_enum_count_item [OF A], simp, rule_tac conjI,
           ((rule_tac mini_lb | rule_tac maxi_ub), erule_tac in_set_nthsD)+)
[PROOF STATE]
proof (state)
this:
count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key (length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x

goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key (length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key (length (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}))) x

goal (1 subgoal):
 1. count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
proof (simp, (rule_tac [!] conjI, rule_tac [!] impI)+,
         simp_all add: mini_maxi_nths nths_count)
[PROOF STATE]
proof (state)
goal (4 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key x)) 0) index key m (key x) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x})) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 4. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
assume "?xmi = x" and "?xma = x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (4 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key x)) 0) index key m (key x) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x})) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 4. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x
[PROOF STEP]
have "?A = {?nmi, ?nma}"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, erule_tac disjE,
             insert mini_less [of ?ws key], insert maxi_less [of ?ws key],
             simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}

goal (4 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key x)) 0) index key m (key x) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x})) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 4. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}
[PROOF STEP]
have "card ?A = Suc (Suc 0)"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key}

goal (1 subgoal):
 1. card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)
[PROOF STEP]
by (simp, subst card_insert_disjoint, simp_all,
             rule_tac mini_maxi_neq, simp)
[PROOF STATE]
proof (state)
this:
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)

goal (4 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key x)) 0) index key m (key x) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x})) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 4. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
thus "Suc (Suc (count (mset ?ws) x - card ?A)) = count (mset ?ws) x"
[PROOF STATE]
proof (prove)
using this:
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)

goal (1 subgoal):
 1. Suc (Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x})) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
using H
[PROOF STATE]
proof (prove)
using this:
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = Suc (Suc 0)
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} \<le> count (mset (take (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. Suc (Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x})) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Suc (Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x})) = count (mset (take (Suc (Suc m)) xs)) x

goal (3 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
assume "?xmi \<noteq> x" and "?xma = x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (3 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x
[PROOF STEP]
have "?A = {?nma}"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, (erule_tac conjE)+,
             erule_tac disjE, insert maxi_less [of ?ws key], simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}

goal (3 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key x)))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 3. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
thus "Suc (count (mset ?ws) x - card ?A) = count (mset ?ws) x"
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}

goal (1 subgoal):
 1. Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
using H
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {maxi (take (Suc (Suc m)) xs) key}
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} \<le> count (mset (take (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x

goal (2 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
assume "?xmi = x" and "?xma \<noteq> x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (2 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
with G
[PROOF STATE]
proof (chain)
picking this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x
[PROOF STEP]
have "?A = {?nmi}"
[PROOF STATE]
proof (prove)
using this:
length (take (Suc (Suc m)) xs) = Suc (Suc m)
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, (erule_tac conjE)+,
             erule_tac disjE, insert mini_less [of ?ws key], simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}

goal (2 subgoals):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key x) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x\<rbrakk> \<Longrightarrow> Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
 2. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
thus "Suc (count (mset ?ws) x - card ?A) = count (mset ?ws) x"
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}

goal (1 subgoal):
 1. Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
using H
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {mini (take (Suc (Suc m)) xs) key}
card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} \<le> count (mset (take (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Suc (count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}) = count (mset (take (Suc (Suc m)) xs)) x

goal (1 subgoal):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
assume "?xmi \<noteq> x" and "?xma \<noteq> x"
[PROOF STATE]
proof (state)
this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (1 subgoal):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
hence "?A = {}"
[PROOF STATE]
proof (prove)
using this:
take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x
take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x

goal (1 subgoal):
 1. {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {}
[PROOF STEP]
by (rule_tac set_eqI, rule_tac iffI, simp_all, (erule_tac conjE)+,
             erule_tac disjE, simp_all)
[PROOF STATE]
proof (state)
this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {}

goal (1 subgoal):
 1. \<lbrakk>min (length xs) (Suc (Suc m)) = Suc (Suc m); count (image_mset the (mset (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x = count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x}; take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key \<noteq> x; take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key \<noteq> x\<rbrakk> \<Longrightarrow> count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
thus "count (mset ?ws) x - card ?A = count (mset ?ws) x"
[PROOF STATE]
proof (prove)
using this:
{i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = {}

goal (1 subgoal):
 1. count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x
[PROOF STEP]
by (simp (no_asm_simp))
[PROOF STATE]
proof (state)
this:
count (mset (take (Suc (Suc m)) xs)) x - card {i. i < Suc (Suc m) \<and> (i = mini (take (Suc (Suc m)) xs) key \<or> i = maxi (take (Suc (Suc m)) xs) key) \<and> take (Suc (Suc m)) xs ! i = x} = count (mset (take (Suc (Suc m)) xs)) x

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
count (mset (map the (fill (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) (offs (enum (nths (take (Suc (Suc m)) xs) (- {mini (take (Suc (Suc m)) xs) key, maxi (take (Suc (Suc m)) xs) key})) index key (case m of 0 \<Rightarrow> m | Suc 0 \<Rightarrow> m | Suc (Suc i) \<Rightarrow> u + m') (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))) 0) index key m (key (take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key)) (key (take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key))))) x + (if take (Suc (Suc m)) xs ! maxi (take (Suc (Suc m)) xs) key = x then 1 else 0) + (if take (Suc (Suc m)) xs ! mini (take (Suc (Suc m)) xs) key = x then 1 else 0) = count (mset (take (Suc (Suc m)) xs)) x

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
count (mset ws') x + count (mset xs') x = f x

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
count_inv f (round index key p q r (u, Suc (Suc m) # ns, xs))

goal:
No subgoals!
[PROOF STEP]
qed