[STATEMENT]
lemma mtf2_effect:
    "q \<in> set xs \<Longrightarrow> distinct xs \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow>( index (mtf2 n q xs) (xs!i) = index xs (xs!i) \<and> index xs q < index (mtf2 n q xs) (xs!i) \<and> index (mtf2 n q xs) (xs!i) < length xs))
    \<and> (index xs q = i \<longrightarrow> (index (mtf2 n q xs) (xs!i) = index xs q - n \<and> index (mtf2 n q xs) (xs!i) = index xs q - n))
    \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> (index (mtf2 n q xs) (xs!i) = Suc (index xs (xs!i)) \<and> index xs q - n < index (mtf2 n q xs) (xs!i) \<and> index (mtf2 n q xs) (xs!i) \<le> index xs q))
    \<and> (i < index xs q - n \<longrightarrow> (index (mtf2 n q xs) (xs!i) = index xs (xs!i) \<and> index (mtf2 n q xs) (xs!i) < index xs q - n))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (mtf2 n q xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (mtf2 n q xs) (xs ! i) \<and> index (mtf2 n q xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (mtf2 n q xs) (xs ! i) = index xs q - n \<and> index (mtf2 n q xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (mtf2 n q xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (mtf2 n q xs) (xs ! i) \<and> index (mtf2 n q xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (mtf2 n q xs) (xs ! i) = index xs (xs ! i) \<and> index (mtf2 n q xs) (xs ! i) < index xs q - n)
[PROOF STEP]
unfolding mtf2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n)
[PROOF STEP]
apply (induct n)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
 2. \<And>n. \<lbrakk>\<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n); q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
 2. \<And>n. \<lbrakk>\<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n); q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
case (Suc n)
[PROOF STATE]
proof (state)
this:
\<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n)
q \<in> set xs
distinct xs

goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
 2. \<And>n. \<lbrakk>\<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n); q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
note indH=Suc(1)[OF Suc(2) Suc(3), simplified Suc(2) if_True]
[PROOF STATE]
proof (state)
this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < index xs q - n)

goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
 2. \<And>n. \<lbrakk>\<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n); q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
note qinxs=Suc(2)[simp]
[PROOF STATE]
proof (state)
this:
q \<in> set xs

goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
 2. \<And>n. \<lbrakk>\<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n); q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
note distxs=Suc(3)[simp]
[PROOF STATE]
proof (state)
this:
distinct xs

goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
 2. \<And>n. \<lbrakk>\<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - n..<index xs q] xs else xs) (xs ! i) < index xs q - n); q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
show ?case (is ?toshow)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
apply(simp only: qinxs if_True)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
proof (cases "index xs q \<ge> Suc n")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
Suc n \<le> index xs q

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
note True1=this
[PROOF STATE]
proof (state)
this:
Suc n \<le> index xs q

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
from True
[PROOF STATE]
proof (chain)
picking this:
Suc n \<le> index xs q
[PROOF STEP]
have onemore: "[index xs q - Suc n..<index xs q] = (index xs q - Suc n) # [index xs q - n..<index xs q]"
[PROOF STATE]
proof (prove)
using this:
Suc n \<le> index xs q

goal (1 subgoal):
 1. [index xs q - Suc n..<index xs q] = (index xs q - Suc n) # [index xs q - n..<index xs q]
[PROOF STEP]
using Suc_diff_Suc upt_rec
[PROOF STATE]
proof (prove)
using this:
Suc n \<le> index xs q
?n < ?m \<Longrightarrow> Suc (?m - Suc ?n) = ?m - ?n
[?i..<?j] = (if ?i < ?j then ?i # [Suc ?i..<?j] else [])

goal (1 subgoal):
 1. [index xs q - Suc n..<index xs q] = (index xs q - Suc n) # [index xs q - n..<index xs q]
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
[index xs q - Suc n..<index xs q] = (index xs q - Suc n) # [index xs q - n..<index xs q]

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
from onemore
[PROOF STATE]
proof (chain)
picking this:
[index xs q - Suc n..<index xs q] = (index xs q - Suc n) # [index xs q - n..<index xs q]
[PROOF STEP]
have yeah: "swaps [index xs q - Suc n..<index xs q] xs
            = swap (index xs q - Suc n) (swaps  [index xs q - n..<index xs q] xs)"
[PROOF STATE]
proof (prove)
using this:
[index xs q - Suc n..<index xs q] = (index xs q - Suc n) # [index xs q - n..<index xs q]

goal (1 subgoal):
 1. swaps [index xs q - Suc n..<index xs q] xs = swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
swaps [index xs q - Suc n..<index xs q] xs = swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
have sis: "Suc (index xs q - Suc n) = index xs q - n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) = index xs q - n
[PROOF STEP]
using True Suc_diff_Suc
[PROOF STATE]
proof (prove)
using this:
Suc n \<le> index xs q
?n < ?m \<Longrightarrow> Suc (?m - Suc ?n) = ?m - ?n

goal (1 subgoal):
 1. Suc (index xs q - Suc n) = index xs q - n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Suc (index xs q - Suc n) = index xs q - n

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
have indq: "index xs q < length xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q < length xs
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. q \<in> set xs
 2. length xs \<le> length xs
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q < length xs

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
let ?i' = "index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i)"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
let ?x = "(xs!i)" and  ?xs="(swaps  [index xs q - n..<index xs q] xs)"
              and ?n="(index xs q - Suc n)"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
have "?i'
          =  index (swap (index xs q - Suc n) (swaps  [index xs q - n..<index xs q] xs)) (xs!i)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index (swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)) (xs ! i)
[PROOF STEP]
using yeah
[PROOF STATE]
proof (prove)
using this:
swaps [index xs q - Suc n..<index xs q] xs = swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index (swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)) (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index (swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)) (xs ! i)

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index (swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)) (xs ! i)

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
have "\<dots> = (if ?x = ?xs ! ?n then Suc ?n else if ?x = ?xs ! Suc ?n then ?n else index ?xs ?x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)) (xs ! i) = (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i))
[PROOF STEP]
apply(rule index_swap_distinct)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
[PROOF STEP]
apply(simp add: sis)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - n < length xs
[PROOF STEP]
using indq
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs

goal (1 subgoal):
 1. index xs q - n < length xs
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
index (swap (index xs q - Suc n) (swaps [index xs q - n..<index xs q] xs)) (xs ! i) = (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i))

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i))
[PROOF STEP]
have i': "?i' = (if ?x = ?xs ! ?n then Suc ?n else if ?x = ?xs ! Suc ?n then ?n else index ?xs ?x)"
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i))

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i))
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i))

goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
let ?i''="index (swaps [index xs q - n..<index xs q] xs) (xs ! i)"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
 2. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
show "(index xs q < i \<and> i < length xs \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and>
     index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and>
    (index xs q = i \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and>
    (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and>
     index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and>
    (i < index xs q - Suc n \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
apply(intro conjI)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
apply(intro impI)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. index xs q < i \<and> i < length xs \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
apply(elim conjE)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
prefer 4
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
 2. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 3. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 4. index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
apply(intro impI)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
 2. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 3. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 4. index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
prefer 4
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
 3. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 4. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
[PROOF STEP]
apply(intro impI)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. index xs q - Suc n \<le> i \<and> i < index xs q \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
 3. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 4. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
[PROOF STEP]
apply(elim conjE)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
 3. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 4. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
[PROOF STEP]
prefer 4
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
 4. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
[PROOF STEP]
apply(intro impI)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
 4. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
[PROOF STEP]
prefer 4
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
proof (goal_cases)
[PROOF STATE]
proof (state)
goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
case 1
[PROOF STATE]
proof (state)
this:
index xs q < i
i < length xs

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have indH1: "(index xs q < i \<and> i < length xs \<longrightarrow>
                      ?i'' =  index xs (xs ! i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
using indH
[PROOF STATE]
proof (prove)
using this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < index xs q - n)

goal (1 subgoal):
 1. index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
assume ass: "index xs q < i" and ass2:"i < length xs"
[PROOF STATE]
proof (state)
this:
index xs q < i
i < length xs

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
index xs q < i
i < length xs
[PROOF STEP]
have a: "?i'' =  index xs (xs ! i)"
[PROOF STATE]
proof (prove)
using this:
index xs q < i
i < length xs

goal (1 subgoal):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
using indH1
[PROOF STATE]
proof (prove)
using this:
index xs q < i
i < length xs
index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have a': "\<dots> = i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs (xs ! i) = i
[PROOF STEP]
apply(rule index_nth_id)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
using ass2
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
by(auto)
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) = i

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = i
[PROOF STEP]
have ii: "?i'' = i"
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = i

goal (1 subgoal):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = i
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = i

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have fstF: "~ ?x = ?xs ! ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)
[PROOF STEP]
apply(rule difind_difelem[where j="index (swaps [index xs q - n..<index xs q] xs) (xs!i)"])
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using indq
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs

goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply (simp add: less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 3. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 4. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ass2
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ass2
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ii ass
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = i
index xs q < i

goal (1 subgoal):
 1. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have sndF: "~ ?x = ?xs ! Suc ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
[PROOF STEP]
apply(rule difind_difelem[where j="index (swaps [index xs q - n..<index xs q] xs) (xs!i)"])
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using indq True
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs
Suc n \<le> index xs q

goal (5 subgoals):
 1. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply (simp add: Suc_diff_Suc less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 3. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 4. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ass2
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 2. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ass2
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 2. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ii ass Suc_diff_Suc True
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = i
index xs q < i
?n < ?m \<Longrightarrow> Suc (?m - Suc ?n) = ?m - ?n
Suc n \<le> index xs q

goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have "?i' = index xs (xs ! i)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
unfolding i'
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = index xs (xs ! i)
[PROOF STEP]
using fstF sndF a
[PROOF STATE]
proof (prove)
using this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = index xs (xs ! i)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (4 subgoals):
 1. \<lbrakk>index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
 2. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 3. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 4. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
[PROOF STEP]
using a' ass ass2
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
index xs (xs ! i) = i
index xs q < i
i < length xs

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
case 2
[PROOF STATE]
proof (state)
this:
index xs q = i

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have indH2: "index xs q = i \<longrightarrow> ?i'' = index xs (xs ! i) - n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) - n
[PROOF STEP]
using indH
[PROOF STATE]
proof (prove)
using this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < index xs q - n)

goal (1 subgoal):
 1. index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) - n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) - n

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
assume "index xs q = i"
[PROOF STATE]
proof (state)
this:
index xs q = i

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
index xs q = i
[PROOF STEP]
have ass: "i = index xs q"
[PROOF STATE]
proof (prove)
using this:
index xs q = i

goal (1 subgoal):
 1. i = index xs q
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i = index xs q

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
with indH2
[PROOF STATE]
proof (chain)
picking this:
index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) - n
i = index xs q
[PROOF STEP]
have a: "i - n = ?i''"
[PROOF STATE]
proof (prove)
using this:
index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) - n
i = index xs q

goal (1 subgoal):
 1. i - n = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i - n = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
from ass
[PROOF STATE]
proof (chain)
picking this:
i = index xs q
[PROOF STEP]
have c: "index xs (xs ! i) = i"
[PROOF STATE]
proof (prove)
using this:
i = index xs q

goal (1 subgoal):
 1. index xs (xs ! i) = i
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) = i

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have "Suc (index xs q - Suc n) = i - n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) = i - n
[PROOF STEP]
using ass True Suc_diff_Suc
[PROOF STATE]
proof (prove)
using this:
i = index xs q
Suc n \<le> index xs q
?n < ?m \<Longrightarrow> Suc (?m - Suc ?n) = ?m - ?n

goal (1 subgoal):
 1. Suc (index xs q - Suc n) = i - n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Suc (index xs q - Suc n) = i - n

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
Suc (index xs q - Suc n) = i - n

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have "\<dots> = ?i''"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i - n = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using a
[PROOF STATE]
proof (prove)
using this:
i - n = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)

goal (1 subgoal):
 1. i - n = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i - n = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
Suc (index xs q - Suc n) = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
have a: "Suc ?n = ?i''"
[PROOF STATE]
proof (prove)
using this:
Suc (index xs q - Suc n) = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)

goal (1 subgoal):
 1. Suc (index xs q - Suc n) = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
Suc (index xs q - Suc n) = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have sndTrue: "?x = ?xs ! Suc ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
[PROOF STEP]
apply(simp add: a)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i = swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index[symmetric])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
[PROOF STEP]
by (simp add: ass)
[PROOF STATE]
proof (state)
this:
xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have fstFalse: "~ ?x = ?xs ! ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)
[PROOF STEP]
apply(rule difind_difelem[where j="index (swaps [index xs q - n..<index xs q] xs) (xs!i)"])
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using indq True
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs
Suc n \<le> index xs q

goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply (simp add: Suc_diff_Suc less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 3. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 4. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ass
[PROOF STATE]
proof (prove)
using this:
i = index xs q

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ass
[PROOF STATE]
proof (prove)
using this:
i = index xs q

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using a
[PROOF STATE]
proof (prove)
using this:
Suc (index xs q - Suc n) = index (swaps [index xs q - n..<index xs q] xs) (xs ! i)

goal (1 subgoal):
 1. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have "?i' = index xs (xs ! index xs q) - Suc n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! index xs q) - Suc n
[PROOF STEP]
unfolding i'
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = index xs (xs ! index xs q) - Suc n
[PROOF STEP]
using sndTrue fstFalse
[PROOF STATE]
proof (prove)
using this:
xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)

goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = index xs (xs ! index xs q) - Suc n
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! index xs q) - Suc n

goal (3 subgoals):
 1. index xs q = i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
 2. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 3. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
with ass
[PROOF STATE]
proof (chain)
picking this:
i = index xs q
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! index xs q) - Suc n
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
i = index xs q
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! index xs q) - Suc n

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n

goal (2 subgoals):
 1. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
case 3
[PROOF STATE]
proof (state)
this:
index xs q - Suc n \<le> i
i < index xs q

goal (2 subgoals):
 1. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have indH3: "index xs q - n \<le> i \<and> i < index xs q
              \<longrightarrow>  ?i'' = Suc (index xs (xs ! i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
[PROOF STEP]
using indH
[PROOF STATE]
proof (prove)
using this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < index xs q - n)

goal (1 subgoal):
 1. index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))

goal (2 subgoals):
 1. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
assume ass: "index xs q - Suc n \<le> i" and
              ass2: "i < index xs q"
[PROOF STATE]
proof (state)
this:
index xs q - Suc n \<le> i
i < index xs q

goal (2 subgoals):
 1. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
from ass2
[PROOF STATE]
proof (chain)
picking this:
i < index xs q
[PROOF STEP]
have ilen: "i < length xs"
[PROOF STATE]
proof (prove)
using this:
i < index xs q

goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
using indq dual_order.strict_trans
[PROOF STATE]
proof (prove)
using this:
i < index xs q
index xs q < length xs
\<lbrakk>?b < ?a; ?c < ?b\<rbrakk> \<Longrightarrow> ?c < ?a

goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
i < length xs

goal (2 subgoals):
 1. \<lbrakk>index xs q - Suc n \<le> i; i < index xs q\<rbrakk> \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
proof (cases "index xs q - n \<le> i")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> index xs q - n \<le> i

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> index xs q - n \<le> i
[PROOF STEP]
have "i < index xs q - n"
[PROOF STATE]
proof (prove)
using this:
\<not> index xs q - n \<le> i

goal (1 subgoal):
 1. i < index xs q - n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i < index xs q - n

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
i < index xs q - n

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have "(i < index xs q - n \<longrightarrow> ?i'' = index xs (xs ! i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
using indH
[PROOF STATE]
proof (prove)
using this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < index xs q - n)

goal (1 subgoal):
 1. i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
i < index xs q - n
i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
have d: "?i'' = index xs (xs ! i)"
[PROOF STATE]
proof (prove)
using this:
i < index xs q - n
i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
from False ass
[PROOF STATE]
proof (chain)
picking this:
\<not> index xs q - n \<le> i
index xs q - Suc n \<le> i
[PROOF STEP]
have b: "index xs q - Suc n = i"
[PROOF STATE]
proof (prove)
using this:
\<not> index xs q - n \<le> i
index xs q - Suc n \<le> i

goal (1 subgoal):
 1. index xs q - Suc n = i
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q - Suc n = i

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have "index xs q < length xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q < length xs
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. q \<in> set xs
 2. length xs \<le> length xs
[PROOF STEP]
by (auto)
[PROOF STATE]
proof (state)
this:
index xs q < length xs

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have c: "index xs (xs ! i) = i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs (xs ! i) = i
[PROOF STEP]
apply(rule index_nth_id)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
using indq ass2
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs
i < index xs q

goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
using less_trans
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs
i < index xs q
\<lbrakk>?x < ?y; ?y < ?z\<rbrakk> \<Longrightarrow> ?x < ?z

goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) = i

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
from b c d
[PROOF STATE]
proof (chain)
picking this:
index xs q - Suc n = i
index xs (xs ! i) = i
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
have f: "?i'' = index xs q - Suc n"
[PROOF STATE]
proof (prove)
using this:
index xs q - Suc n = i
index xs (xs ! i) = i
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - Suc n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - Suc n

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have fstT: "?xs ! ?n = ?x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) = xs ! i
[PROOF STEP]
apply(simp only: f[symmetric])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
[PROOF STEP]
by (simp add: ilen)
[PROOF STATE]
proof (state)
this:
swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) = xs ! i

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have "?i' = Suc (index xs q - Suc n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs q - Suc n)
[PROOF STEP]
unfolding i'
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = Suc (index xs q - Suc n)
[PROOF STEP]
using fstT
[PROOF STATE]
proof (prove)
using this:
swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) = xs ! i

goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = Suc (index xs q - Suc n)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs q - Suc n)

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs q - Suc n)

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have "\<dots> = Suc (index xs (xs ! i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) = Suc (index xs (xs ! i))
[PROOF STEP]
by(simp only: b c)
[PROOF STATE]
proof (state)
this:
Suc (index xs q - Suc n) = Suc (index xs (xs ! i))

goal (2 subgoals):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
 2. \<not> index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
using c False ass
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
index xs (xs ! i) = i
\<not> index xs q - n \<le> i
index xs q - Suc n \<le> i

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q

goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
index xs q - n \<le> i

goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
with ass2 indH3
[PROOF STATE]
proof (chain)
picking this:
i < index xs q
index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
index xs q - n \<le> i
[PROOF STEP]
have a: "?i'' = Suc (index xs (xs ! i))"
[PROOF STATE]
proof (prove)
using this:
i < index xs q
index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
index xs q - n \<le> i

goal (1 subgoal):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))

goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have jo: "index xs (xs ! i) = i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs (xs ! i) = i
[PROOF STEP]
apply(rule index_nth_id)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
by(auto)
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) = i

goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have fstF: "~ ?x = ?xs ! ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)
[PROOF STEP]
apply(rule difind_difelem[where j="index (swaps [index xs q - n..<index xs q] xs) (xs!i)"])
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using indq
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs

goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply (simp add: less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 3. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 4. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp only: a jo)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - Suc n \<noteq> Suc i
[PROOF STEP]
using True
[PROOF STATE]
proof (prove)
using this:
index xs q - n \<le> i

goal (1 subgoal):
 1. index xs q - Suc n \<noteq> Suc i
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)

goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have sndF: "~ ?x = ?xs ! Suc ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
[PROOF STEP]
apply(rule difind_difelem[where j="index (swaps [index xs q - n..<index xs q] xs) (xs!i)"])
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using True1
[PROOF STATE]
proof (prove)
using this:
Suc n \<le> index xs q

goal (5 subgoals):
 1. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply (simp add: Suc_diff_Suc less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 3. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 4. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 2. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 2. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp only: a jo)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> Suc i
[PROOF STEP]
using True1
[PROOF STATE]
proof (prove)
using this:
Suc n \<le> index xs q

goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> Suc i
[PROOF STEP]
apply (simp add: Suc_diff_Suc less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc n \<le> index xs q \<Longrightarrow> index xs q - n \<noteq> Suc i
[PROOF STEP]
using True
[PROOF STATE]
proof (prove)
using this:
index xs q - n \<le> i

goal (1 subgoal):
 1. Suc n \<le> index xs q \<Longrightarrow> index xs q - n \<noteq> Suc i
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)

goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
have "?i' = Suc (index xs (xs ! i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
[PROOF STEP]
unfolding i'
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = Suc (index xs (xs ! i))
[PROOF STEP]
using fstF sndF a
[PROOF STATE]
proof (prove)
using this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))

goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = Suc (index xs (xs ! i))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))

goal (1 subgoal):
 1. index xs q - n \<le> i \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
using ass ass2 jo
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i))
index xs q - Suc n \<le> i
i < index xs q
index xs (xs ! i) = i

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
case 4
[PROOF STATE]
proof (state)
this:
i < index xs q - Suc n

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
assume ass: "i < index xs q - Suc n"
[PROOF STATE]
proof (state)
this:
i < index xs q - Suc n

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
i < index xs q - Suc n
[PROOF STEP]
have ass2: "i < index xs q - n"
[PROOF STATE]
proof (prove)
using this:
i < index xs q - Suc n

goal (1 subgoal):
 1. i < index xs q - n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i < index xs q - n

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
i < index xs q - n

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have "(i < index xs q - n \<longrightarrow> ?i'' = index xs (xs ! i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
using indH
[PROOF STATE]
proof (prove)
using this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < index xs q - n)

goal (1 subgoal):
 1. i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
i < index xs q - n
i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
have a: "?i'' = index xs (xs ! i)"
[PROOF STATE]
proof (prove)
using this:
i < index xs q - n
i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
from ass2
[PROOF STATE]
proof (chain)
picking this:
i < index xs q - n
[PROOF STEP]
have "i < index xs q"
[PROOF STATE]
proof (prove)
using this:
i < index xs q - n

goal (1 subgoal):
 1. i < index xs q
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i < index xs q

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
i < index xs q
[PROOF STEP]
have ilen: "i < length xs"
[PROOF STATE]
proof (prove)
using this:
i < index xs q

goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
using indq dual_order.strict_trans
[PROOF STATE]
proof (prove)
using this:
i < index xs q
index xs q < length xs
\<lbrakk>?b < ?a; ?c < ?b\<rbrakk> \<Longrightarrow> ?c < ?a

goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
i < length xs

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have jo: "index xs (xs ! i) = i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs (xs ! i) = i
[PROOF STEP]
apply(rule index_nth_id)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
by(auto)
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) = i

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have fstF: "~ ?x = ?xs ! ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)
[PROOF STEP]
apply(rule difind_difelem[where j="index (swaps [index xs q - n..<index xs q] xs) (xs!i)"])
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using indq
[PROOF STATE]
proof (prove)
using this:
index xs q < length xs

goal (5 subgoals):
 1. index xs q - Suc n < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply (simp add: less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 3. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 4. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 2. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - Suc n \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp only: a jo)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q - Suc n \<noteq> i
[PROOF STEP]
using ass
[PROOF STATE]
proof (prove)
using this:
i < index xs q - Suc n

goal (1 subgoal):
 1. index xs q - Suc n \<noteq> i
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have sndF: "~ ?x = ?xs ! Suc ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
[PROOF STEP]
apply(rule difind_difelem[where j="index (swaps [index xs q - n..<index xs q] xs) (xs!i)"])
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using True1
[PROOF STATE]
proof (prove)
using this:
Suc n \<le> index xs q

goal (5 subgoals):
 1. Suc (index xs q - Suc n) < length (swaps [index xs q - n..<index xs q] xs)
 2. distinct (swaps [index xs q - n..<index xs q] xs)
 3. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 4. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 5. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply (simp add: Suc_diff_Suc less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. distinct (swaps [index xs q - n..<index xs q] xs)
 2. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 3. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 4. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. swaps [index xs q - n..<index xs q] xs ! index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = xs ! i
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule nth_index)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length (swaps [index xs q - n..<index xs q] xs)
 2. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set (swaps [index xs q - n..<index xs q] xs)
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
using ilen
[PROOF STATE]
proof (prove)
using this:
i < length xs

goal (3 subgoals):
 1. xs ! i \<in> set xs
 2. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 3. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. length (swaps [index xs q - n..<index xs q] xs) \<le> length (swaps [index xs q - n..<index xs q] xs)
 2. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> index (swaps [index xs q - n..<index xs q] xs) (xs ! i)
[PROOF STEP]
apply(simp only: a jo)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> i
[PROOF STEP]
using True1
[PROOF STATE]
proof (prove)
using this:
Suc n \<le> index xs q

goal (1 subgoal):
 1. Suc (index xs q - Suc n) \<noteq> i
[PROOF STEP]
apply (simp add: Suc_diff_Suc less_imp_diff_less)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc n \<le> index xs q \<Longrightarrow> index xs q - n \<noteq> i
[PROOF STEP]
using ass
[PROOF STATE]
proof (prove)
using this:
i < index xs q - Suc n

goal (1 subgoal):
 1. Suc n \<le> index xs q \<Longrightarrow> index xs q - n \<noteq> i
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
have "?i' = (index xs (xs ! i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
unfolding i'
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = index xs (xs ! i)
[PROOF STEP]
using fstF sndF a
[PROOF STATE]
proof (prove)
using this:
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n)
xs ! i \<noteq> swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n)
index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. (if xs ! i = swaps [index xs q - n..<index xs q] xs ! (index xs q - Suc n) then Suc (index xs q - Suc n) else if xs ! i = swaps [index xs q - n..<index xs q] xs ! Suc (index xs q - Suc n) then index xs q - Suc n else index (swaps [index xs q - n..<index xs q] xs) (xs ! i)) = index xs (xs ! i)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. i < index xs q - Suc n \<Longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
using jo ass
[PROOF STATE]
proof (prove)
using this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i)
index xs (xs ! i) = i
i < index xs q - Suc n

goal (1 subgoal):
 1. index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)

goal (1 subgoal):
 1. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> Suc n \<le> index xs q

goal (1 subgoal):
 1. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> Suc n \<le> index xs q
[PROOF STEP]
have smalla: "index xs q - Suc n = index xs q - n"
[PROOF STATE]
proof (prove)
using this:
\<not> Suc n \<le> index xs q

goal (1 subgoal):
 1. index xs q - Suc n = index xs q - n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q - Suc n = index xs q - n

goal (1 subgoal):
 1. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
index xs q - Suc n = index xs q - n
[PROOF STEP]
have nomore: "swaps [index xs q - Suc n..<index xs q] xs
            =swaps [index xs q - n..<index xs q] xs"
[PROOF STATE]
proof (prove)
using this:
index xs q - Suc n = index xs q - n

goal (1 subgoal):
 1. swaps [index xs q - Suc n..<index xs q] xs = swaps [index xs q - n..<index xs q] xs
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
swaps [index xs q - Suc n..<index xs q] xs = swaps [index xs q - n..<index xs q] xs

goal (1 subgoal):
 1. \<not> Suc n \<le> index xs q \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
show "(index xs q < i \<and> i < length xs \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and>
     index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and>
    (index xs q = i \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and>
    (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and>
     index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and>
    (i < index xs q - Suc n \<longrightarrow>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and>
     index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)
[PROOF STEP]
unfolding nomore smalla
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs q - n) \<and> (index xs q - n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - n < index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - n \<longrightarrow> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - n..<index xs q] xs) (xs ! i) < index xs q - n)
[PROOF STEP]
by (rule indH)
[PROOF STATE]
proof (state)
this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) = index xs (xs ! i) \<and> index (swaps [index xs q - Suc n..<index xs q] xs) (xs ! i) < index xs q - Suc n)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs q - Suc n) \<and> (index xs q - Suc n \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - Suc n < index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - Suc n \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - Suc n..<index xs q] xs else xs) (xs ! i) < index xs q - Suc n)

goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:
q \<in> set xs
distinct xs

goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
q \<in> set xs
distinct xs
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
q \<in> set xs
distinct xs

goal (1 subgoal):
 1. (index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> (index xs q < i \<and> i < length xs \<longrightarrow> index xs q < index xs (xs ! i)) \<and> (index xs q = i \<longrightarrow> index xs (xs ! i) = i) \<and> (i < index xs q \<longrightarrow> index xs (xs ! i) < index xs q)
[PROOF STEP]
proof (safe, goal_cases)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs; index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index xs q < index xs (xs ! i)
 2. \<lbrakk>q \<in> set xs; distinct xs; i = index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! index xs q) = index xs q
 3. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
case 1
[PROOF STATE]
proof (state)
this:
q \<in> set xs
distinct xs
index xs q < i
i < length xs

goal (3 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs; index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index xs q < index xs (xs ! i)
 2. \<lbrakk>q \<in> set xs; distinct xs; i = index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! index xs q) = index xs q
 3. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
have " index xs (xs ! i) = i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs (xs ! i) = i
[PROOF STEP]
apply(rule index_nth_id)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
using 1
[PROOF STATE]
proof (prove)
using this:
q \<in> set xs
distinct xs
index xs q < i
i < length xs

goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) = i

goal (3 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs; index xs q < i; i < length xs\<rbrakk> \<Longrightarrow> index xs q < index xs (xs ! i)
 2. \<lbrakk>q \<in> set xs; distinct xs; i = index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! index xs q) = index xs q
 3. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
with 1
[PROOF STATE]
proof (chain)
picking this:
q \<in> set xs
distinct xs
index xs q < i
i < length xs
index xs (xs ! i) = i
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
q \<in> set xs
distinct xs
index xs q < i
i < length xs
index xs (xs ! i) = i

goal (1 subgoal):
 1. index xs q < index xs (xs ! i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q < index xs (xs ! i)

goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs; i = index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! index xs q) = index xs q
 2. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs; i = index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! index xs q) = index xs q
 2. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
case 2
[PROOF STATE]
proof (state)
this:
q \<in> set xs
distinct xs
i = index xs q

goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs; i = index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! index xs q) = index xs q
 2. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
have "xs ! index xs q = q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. xs ! index xs q = q
[PROOF STEP]
using 2
[PROOF STATE]
proof (prove)
using this:
q \<in> set xs
distinct xs
i = index xs q

goal (1 subgoal):
 1. xs ! index xs q = q
[PROOF STEP]
by(auto)
[PROOF STATE]
proof (state)
this:
xs ! index xs q = q

goal (2 subgoals):
 1. \<lbrakk>q \<in> set xs; distinct xs; i = index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! index xs q) = index xs q
 2. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
with 2
[PROOF STATE]
proof (chain)
picking this:
q \<in> set xs
distinct xs
i = index xs q
xs ! index xs q = q
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
q \<in> set xs
distinct xs
i = index xs q
xs ! index xs q = q

goal (1 subgoal):
 1. index xs (xs ! index xs q) = index xs q
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs (xs ! index xs q) = index xs q

goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
case 3
[PROOF STATE]
proof (state)
this:
q \<in> set xs
distinct xs
i < index xs q

goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
have a: "index xs q < length xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs q < length xs
[PROOF STEP]
apply(rule index_less)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. q \<in> set xs
 2. length xs \<le> length xs
[PROOF STEP]
using 3
[PROOF STATE]
proof (prove)
using this:
q \<in> set xs
distinct xs
i < index xs q

goal (2 subgoals):
 1. q \<in> set xs
 2. length xs \<le> length xs
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs q < length xs

goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
have "index xs (xs ! i) = i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. index xs (xs ! i) = i
[PROOF STEP]
apply(rule index_nth_id)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. distinct xs
 2. i < length xs
[PROOF STEP]
apply(fact 3(2))
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
using 3(3) a
[PROOF STATE]
proof (prove)
using this:
i < index xs q
index xs q < length xs

goal (1 subgoal):
 1. i < length xs
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) = i

goal (1 subgoal):
 1. \<lbrakk>q \<in> set xs; distinct xs; i < index xs q\<rbrakk> \<Longrightarrow> index xs (xs ! i) < index xs q
[PROOF STEP]
with 3
[PROOF STATE]
proof (chain)
picking this:
q \<in> set xs
distinct xs
i < index xs q
index xs (xs ! i) = i
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
q \<in> set xs
distinct xs
i < index xs q
index xs (xs ! i) = i

goal (1 subgoal):
 1. index xs (xs ! i) < index xs q
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
index xs (xs ! i) < index xs q

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(index xs q < i \<and> i < length xs \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index xs q < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < length xs) \<and> (index xs q = i \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0 \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs q - 0) \<and> (index xs q - 0 \<le> i \<and> i < index xs q \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = Suc (index xs (xs ! i)) \<and> index xs q - 0 < index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) \<le> index xs q) \<and> (i < index xs q - 0 \<longrightarrow> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) = index xs (xs ! i) \<and> index (if q \<in> set xs then swaps [index xs q - 0..<index xs q] xs else xs) (xs ! i) < index xs q - 0)

goal:
No subgoals!
[PROOF STEP]
qed