[STATEMENT]
lemma permutes_decompose:
  assumes "f permutes S" "finite S"
  shows "\<exists>C. (\<forall>c \<in> C. cyclic_on f c) \<and> \<Union>C = S \<and> (\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>C. (\<forall>c\<in>C. cyclic_on f c) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
using assms(2,1)
[PROOF STATE]
proof (prove)
using this:
finite S
f permutes S

goal (1 subgoal):
 1. \<exists>C. (\<forall>c\<in>C. cyclic_on f c) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
proof (induction arbitrary: f rule: finite_psubset_induct)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>A f. \<lbrakk>finite A; \<And>B f. \<lbrakk>B \<subset> A; f permutes B\<rbrakk> \<Longrightarrow> \<exists>C. Ball C (cyclic_on f) \<and> \<Union> C = B \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}); f permutes A\<rbrakk> \<Longrightarrow> \<exists>C. Ball C (cyclic_on f) \<and> \<Union> C = A \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
case (psubset S)
[PROOF STATE]
proof (state)
this:
finite S
\<lbrakk>?B \<subset> S; ?f permutes ?B\<rbrakk> \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on ?f a) \<and> \<Union> C = ?B \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
f permutes S

goal (1 subgoal):
 1. \<And>A f. \<lbrakk>finite A; \<And>B f. \<lbrakk>B \<subset> A; f permutes B\<rbrakk> \<Longrightarrow> \<exists>C. Ball C (cyclic_on f) \<and> \<Union> C = B \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}); f permutes A\<rbrakk> \<Longrightarrow> \<exists>C. Ball C (cyclic_on f) \<and> \<Union> C = A \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
proof (cases "S = {}")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. S = {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
 2. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
S = {}

goal (2 subgoals):
 1. S = {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
 2. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
S = {}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
S = {}

goal (1 subgoal):
 1. \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
by (intro exI[where x="{}"]) auto
[PROOF STATE]
proof (state)
this:
\<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
S \<noteq> {}

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
S \<noteq> {}
[PROOF STEP]
obtain s where "s \<in> S"
[PROOF STATE]
proof (prove)
using this:
S \<noteq> {}

goal (1 subgoal):
 1. (\<And>s. s \<in> S \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
s \<in> S

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
with \<open>f permutes S\<close>
[PROOF STATE]
proof (chain)
picking this:
f permutes S
s \<in> S
[PROOF STEP]
have "orbit f s \<subseteq> S"
[PROOF STATE]
proof (prove)
using this:
f permutes S
s \<in> S

goal (1 subgoal):
 1. orbit f s \<subseteq> S
[PROOF STEP]
by (rule permutes_orbit_subset)
[PROOF STATE]
proof (state)
this:
orbit f s \<subseteq> S

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
have cyclic_orbit: "cyclic_on f (orbit f s)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cyclic_on f (orbit f s)
[PROOF STEP]
using \<open>f permutes S\<close> \<open>finite S\<close>
[PROOF STATE]
proof (prove)
using this:
f permutes S
finite S

goal (1 subgoal):
 1. cyclic_on f (orbit f s)
[PROOF STEP]
by (rule cyclic_on_orbit)
[PROOF STATE]
proof (state)
this:
cyclic_on f (orbit f s)

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
let ?f' = "perm_restrict f (S - orbit f s)"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
have "f s \<in> S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f s \<in> S
[PROOF STEP]
using \<open>f permutes S\<close> \<open>s \<in> S\<close>
[PROOF STATE]
proof (prove)
using this:
f permutes S
s \<in> S

goal (1 subgoal):
 1. f s \<in> S
[PROOF STEP]
by (auto simp: permutes_in_image)
[PROOF STATE]
proof (state)
this:
f s \<in> S

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
f s \<in> S
[PROOF STEP]
have "S - orbit f s \<subset> S"
[PROOF STATE]
proof (prove)
using this:
f s \<in> S

goal (1 subgoal):
 1. S - orbit f s \<subset> S
[PROOF STEP]
using orbit.base[of f s] \<open>s \<in> S\<close>
[PROOF STATE]
proof (prove)
using this:
f s \<in> S
f s \<in> orbit f s
s \<in> S

goal (1 subgoal):
 1. S - orbit f s \<subset> S
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
S - orbit f s \<subset> S

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
S - orbit f s \<subset> S

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
have "?f' permutes (S - orbit f s)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. perm_restrict f (S - orbit f s) permutes S - orbit f s
[PROOF STEP]
using \<open>f permutes S\<close> cyclic_orbit
[PROOF STATE]
proof (prove)
using this:
f permutes S
cyclic_on f (orbit f s)

goal (1 subgoal):
 1. perm_restrict f (S - orbit f s) permutes S - orbit f s
[PROOF STEP]
by (rule perm_restrict_diff_cyclic)
[PROOF STATE]
proof (state)
this:
perm_restrict f (S - orbit f s) permutes S - orbit f s

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
S - orbit f s \<subset> S
perm_restrict f (S - orbit f s) permutes S - orbit f s
[PROOF STEP]
obtain C where C: "\<And>c. c \<in> C \<Longrightarrow> cyclic_on ?f' c" "\<Union>C = S - orbit f s"
        "\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}"
[PROOF STATE]
proof (prove)
using this:
S - orbit f s \<subset> S
perm_restrict f (S - orbit f s) permutes S - orbit f s

goal (1 subgoal):
 1. (\<And>C. \<lbrakk>\<And>c. c \<in> C \<Longrightarrow> cyclic_on (perm_restrict f (S - orbit f s)) c; \<Union> C = S - orbit f s; \<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using psubset.IH
[PROOF STATE]
proof (prove)
using this:
S - orbit f s \<subset> S
perm_restrict f (S - orbit f s) permutes S - orbit f s
\<lbrakk>?B \<subset> S; ?f permutes ?B\<rbrakk> \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on ?f a) \<and> \<Union> C = ?B \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})

goal (1 subgoal):
 1. (\<And>C. \<lbrakk>\<And>c. c \<in> C \<Longrightarrow> cyclic_on (perm_restrict f (S - orbit f s)) c; \<Union> C = S - orbit f s; \<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
?c \<in> C \<Longrightarrow> cyclic_on (perm_restrict f (S - orbit f s)) ?c
\<Union> C = S - orbit f s
\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
{
[PROOF STATE]
proof (state)
this:
?c \<in> C \<Longrightarrow> cyclic_on (perm_restrict f (S - orbit f s)) ?c
\<Union> C = S - orbit f s
\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
fix c
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
assume "c \<in> C"
[PROOF STATE]
proof (state)
this:
c \<in> C

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
c \<in> C
[PROOF STEP]
have *: "\<And>x. x \<in> c \<Longrightarrow> perm_restrict f (S - orbit f s) x = f x"
[PROOF STATE]
proof (prove)
using this:
c \<in> C

goal (1 subgoal):
 1. \<And>x. x \<in> c \<Longrightarrow> perm_restrict f (S - orbit f s) x = f x
[PROOF STEP]
using C(2) \<open>f permutes S\<close>
[PROOF STATE]
proof (prove)
using this:
c \<in> C
\<Union> C = S - orbit f s
f permutes S

goal (1 subgoal):
 1. \<And>x. x \<in> c \<Longrightarrow> perm_restrict f (S - orbit f s) x = f x
[PROOF STEP]
by (auto simp add: perm_restrict_def)
[PROOF STATE]
proof (state)
this:
?x \<in> c \<Longrightarrow> perm_restrict f (S - orbit f s) ?x = f ?x

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?x \<in> c \<Longrightarrow> perm_restrict f (S - orbit f s) ?x = f ?x
[PROOF STEP]
have "cyclic_on f c"
[PROOF STATE]
proof (prove)
using this:
?x \<in> c \<Longrightarrow> perm_restrict f (S - orbit f s) ?x = f ?x

goal (1 subgoal):
 1. cyclic_on f c
[PROOF STEP]
using C(1)[OF \<open>c \<in> C\<close>]
[PROOF STATE]
proof (prove)
using this:
?x \<in> c \<Longrightarrow> perm_restrict f (S - orbit f s) ?x = f ?x
cyclic_on (perm_restrict f (S - orbit f s)) c

goal (1 subgoal):
 1. cyclic_on f c
[PROOF STEP]
by (simp cong: cyclic_cong add: *)
[PROOF STATE]
proof (state)
this:
cyclic_on f c

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
}
[PROOF STATE]
proof (state)
this:
?c2 \<in> C \<Longrightarrow> cyclic_on f ?c2

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
note in_C_cyclic = this
[PROOF STATE]
proof (state)
this:
?c2 \<in> C \<Longrightarrow> cyclic_on f ?c2

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
have Un_ins: "\<Union>(insert (orbit f s) C) = S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<Union> (insert (orbit f s) C) = S
[PROOF STEP]
using \<open>\<Union>C = _\<close>  \<open>orbit f s \<subseteq> S\<close>
[PROOF STATE]
proof (prove)
using this:
\<Union> C = S - orbit f s
orbit f s \<subseteq> S

goal (1 subgoal):
 1. \<Union> (insert (orbit f s) C) = S
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
\<Union> (insert (orbit f s) C) = S

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
have Disj_ins: "(\<forall>c1 \<in> insert (orbit f s) C. \<forall>c2 \<in> insert (orbit f s) C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>c1\<in>insert (orbit f s) C. \<forall>c2\<in>insert (orbit f s) C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}
[PROOF STEP]
using C
[PROOF STATE]
proof (prove)
using this:
?c \<in> C \<Longrightarrow> cyclic_on (perm_restrict f (S - orbit f s)) ?c
\<Union> C = S - orbit f s
\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}

goal (1 subgoal):
 1. \<forall>c1\<in>insert (orbit f s) C. \<forall>c2\<in>insert (orbit f s) C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<forall>c1\<in>insert (orbit f s) C. \<forall>c2\<in>insert (orbit f s) C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}

goal (1 subgoal):
 1. S \<noteq> {} \<Longrightarrow> \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})
[PROOF STEP]
by (intro conjI Un_ins Disj_ins exI[where x="insert (orbit f s) C"])
        (auto simp: cyclic_orbit in_C_cyclic)
[PROOF STATE]
proof (state)
this:
\<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<exists>C. (\<forall>a\<in>C. cyclic_on f a) \<and> \<Union> C = S \<and> (\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {})

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma sym_group_carrier: "p \<in> carrier (sym_group n) \<longleftrightarrow> p permutes {1..n}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (p \<in> carrier (sym_group n)) = (p permutes {1..n})
[PROOF STEP]
unfolding sym_group_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (p \<in> carrier \<lparr>carrier = {p. p permutes {1..n}}, monoid.mult = (\<circ>), one = id\<rparr>) = (p permutes {1..n})
[PROOF STEP]
by simp


[STATEMENT]
lemma distinct_map_of_rev: "distinct (map fst xs) \<Longrightarrow> map_of (rev xs) = map_of xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. distinct (map fst xs) \<Longrightarrow> map_of (rev xs) = map_of xs
[PROOF STEP]
by(induct xs)(auto 4 3 simp add: map_add_def intro!: ext split: option.split intro: rev_image_eqI)


[STATEMENT]
lemma vdw_lemma_imp_vdw:
  assumes "vdw_lemma k k l N"
  shows   "vdw k (Suc l) N"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. vdw k (Suc l) N
[PROOF STEP]
unfolding vdw_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>a b col. a + int N \<le> b + 1 \<and> col \<in> {a..b} \<rightarrow> {..<k} \<longrightarrow> (\<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b})
[PROOF STEP]
proof (safe, goal_cases)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
text \<open>Idea: Proof uses pigeonhole principle to guarantee the existence of an arithmetic
            progression of length $l+1$ with the same colour. \<close>
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
case (1 a b col)
[PROOF STATE]
proof (state)
this:
a + int N \<le> b + 1
col \<in> {a..b} \<rightarrow> {..<k}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
obtain start steps where prog:
    "\<And>i. i < k \<Longrightarrow> steps i > 0"
    "is_multi_arith_prog_on (l+1) k start steps a b"
    "let f = multi_arith_prog k start steps
     in  \<forall>c \<in> {0..<k} \<rightarrow> {0..l}. \<forall>s<k. (\<forall> j \<le> s. c j < l) \<longrightarrow>
            col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>steps start. \<lbrakk>\<And>i. i < k \<Longrightarrow> 0 < steps i; is_multi_arith_prog_on (l + 1) k start steps a b; let f = multi_arith_prog k start steps in \<forall>c\<in>{0..<k} \<rightarrow> {0..l}. \<forall>s<k. (\<forall>j\<le>s. c j < l) \<longrightarrow> col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using assms 1
[PROOF STATE]
proof (prove)
using this:
vdw_lemma k k l N
a + int N \<le> b + 1
col \<in> {a..b} \<rightarrow> {..<k}

goal (1 subgoal):
 1. (\<And>steps start. \<lbrakk>\<And>i. i < k \<Longrightarrow> 0 < steps i; is_multi_arith_prog_on (l + 1) k start steps a b; let f = multi_arith_prog k start steps in \<forall>c\<in>{0..<k} \<rightarrow> {0..l}. \<forall>s<k. (\<forall>j\<le>s. c j < l) \<longrightarrow> col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (elim vdw_lemmaE[where a=a and b=b and col=col and m=k
          and k=k and l=l and n=N]) auto
[PROOF STATE]
proof (state)
this:
?i < k \<Longrightarrow> 0 < steps ?i
is_multi_arith_prog_on (l + 1) k start steps a b
let f = multi_arith_prog k start steps in \<forall>c\<in>{0..<k} \<rightarrow> {0..l}. \<forall>s<k. (\<forall>j\<le>s. c j < l) \<longrightarrow> col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
text \<open> Obtain a $k$-fold arithmetic progression $f$ of length $l$ from assumptions. \<close>
[PROOF STATE]
proof (state)
this:
?i < k \<Longrightarrow> 0 < steps ?i
is_multi_arith_prog_on (l + 1) k start steps a b
let f = multi_arith_prog k start steps in \<forall>c\<in>{0..<k} \<rightarrow> {0..l}. \<forall>s<k. (\<forall>j\<le>s. c j < l) \<longrightarrow> col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
define f where "f = multi_arith_prog k start steps"
[PROOF STATE]
proof (state)
this:
f = multi_arith_prog k start steps

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have rel_propE: "col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))"
    if "c \<in> {0..<k} \<rightarrow> {0..l}" "s<k" "\<forall> j \<le> s. c j < l"
    for c s
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))
[PROOF STEP]
using prog(3) that
[PROOF STATE]
proof (prove)
using this:
let f = multi_arith_prog k start steps in \<forall>c\<in>{0..<k} \<rightarrow> {0..l}. \<forall>s<k. (\<forall>j\<le>s. c j < l) \<longrightarrow> col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))
c \<in> {0..<k} \<rightarrow> {0..l}
s < k
\<forall>j\<le>s. c j < l

goal (1 subgoal):
 1. col (f c) = col (f (\<lambda>i. if i \<le> s then 0 else c i))
[PROOF STEP]
unfolding f_def Let_def
[PROOF STATE]
proof (prove)
using this:
\<forall>c\<in>{0..<k} \<rightarrow> {0..l}. \<forall>s<k. (\<forall>j\<le>s. c j < l) \<longrightarrow> col (multi_arith_prog k start steps c) = col (multi_arith_prog k start steps (\<lambda>i. if i \<le> s then 0 else c i))
c \<in> {0..<k} \<rightarrow> {0..l}
s < k
\<forall>j\<le>s. c j < l

goal (1 subgoal):
 1. col (multi_arith_prog k start steps c) = col (multi_arith_prog k start steps (\<lambda>i. if i \<le> s then 0 else c i))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<lbrakk>?c \<in> {0..<k} \<rightarrow> {0..l}; ?s < k; \<forall>j\<le>?s. ?c j < l\<rbrakk> \<Longrightarrow> col (f ?c) = col (f (\<lambda>i. if i \<le> ?s then 0 else ?c i))

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
text \<open>There are $k+1$ values $a_r = f(0,\dots,0,l,\dots,l)$ with $0\leq r\leq k$ zeros.\<close>
[PROOF STATE]
proof (state)
this:
\<lbrakk>?c \<in> {0..<k} \<rightarrow> {0..l}; ?s < k; \<forall>j\<le>?s. ?c j < l\<rbrakk> \<Longrightarrow> col (f ?c) = col (f (\<lambda>i. if i \<le> ?s then 0 else ?c i))

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
define a_r where "a_r = (\<lambda>r. f (\<lambda>i. (if i<r then 0 else l)))"
[PROOF STATE]
proof (state)
this:
a_r = (\<lambda>r. f (\<lambda>i. if i < r then 0 else l))

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have range_col_a_r: "col (a_r x) < k" if "x < k+1" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. col (a_r x) < k
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. col (a_r x) < k
[PROOF STEP]
have "a_r x \<in> {a..b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a_r x \<in> {a..b}
[PROOF STEP]
unfolding a_r_def f_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. multi_arith_prog k start steps (\<lambda>i. if i < x then 0 else l) \<in> {a..b}
[PROOF STEP]
by (intro is_multi_arith_prog_onD[OF prog(2)]) auto
[PROOF STATE]
proof (state)
this:
a_r x \<in> {a..b}

goal (1 subgoal):
 1. col (a_r x) < k
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
a_r x \<in> {a..b}

goal (1 subgoal):
 1. col (a_r x) < k
[PROOF STEP]
using 1
[PROOF STATE]
proof (prove)
using this:
a_r x \<in> {a..b}
a + int N \<le> b + 1
col \<in> {a..b} \<rightarrow> {..<k}

goal (1 subgoal):
 1. col (a_r x) < k
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
col (a_r x) < k

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?x < k + 1 \<Longrightarrow> col (a_r ?x) < k

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?x < k + 1 \<Longrightarrow> col (a_r ?x) < k
[PROOF STEP]
have "(col \<circ> a_r) ` {..<k + 1} \<subseteq> {..<k}"
[PROOF STATE]
proof (prove)
using this:
?x < k + 1 \<Longrightarrow> col (a_r ?x) < k

goal (1 subgoal):
 1. (col \<circ> a_r) ` {..<k + 1} \<subseteq> {..<k}
[PROOF STEP]
using 1(2)
[PROOF STATE]
proof (prove)
using this:
?x < k + 1 \<Longrightarrow> col (a_r ?x) < k
col \<in> {a..b} \<rightarrow> {..<k}

goal (1 subgoal):
 1. (col \<circ> a_r) ` {..<k + 1} \<subseteq> {..<k}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(col \<circ> a_r) ` {..<k + 1} \<subseteq> {..<k}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(col \<circ> a_r) ` {..<k + 1} \<subseteq> {..<k}
[PROOF STEP]
have "card ((col \<circ> a_r) ` {..<k + 1}) \<le> card {..<k}"
[PROOF STATE]
proof (prove)
using this:
(col \<circ> a_r) ` {..<k + 1} \<subseteq> {..<k}

goal (1 subgoal):
 1. card ((col \<circ> a_r) ` {..<k + 1}) \<le> card {..<k}
[PROOF STEP]
by (intro card_mono) auto
[PROOF STATE]
proof (state)
this:
card ((col \<circ> a_r) ` {..<k + 1}) \<le> card {..<k}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
card ((col \<circ> a_r) ` {..<k + 1}) \<le> card {..<k}
[PROOF STEP]
have "\<not> inj_on (col \<circ> a_r) {..<k+1}"
[PROOF STATE]
proof (prove)
using this:
card ((col \<circ> a_r) ` {..<k + 1}) \<le> card {..<k}

goal (1 subgoal):
 1. \<not> inj_on (col \<circ> a_r) {..<k + 1}
[PROOF STEP]
using pigeonhole[of "col \<circ> a_r" "{..<k+1}"]
[PROOF STATE]
proof (prove)
using this:
card ((col \<circ> a_r) ` {..<k + 1}) \<le> card {..<k}
card ((col \<circ> a_r) ` {..<k + 1}) < card {..<k + 1} \<Longrightarrow> \<not> inj_on (col \<circ> a_r) {..<k + 1}

goal (1 subgoal):
 1. \<not> inj_on (col \<circ> a_r) {..<k + 1}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<not> inj_on (col \<circ> a_r) {..<k + 1}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
text \<open>Using the pigeonhole principle get $r_1$ and $r_2$ where $a_{r_1}$ and $a_{r_2}$ have the
    same colour.\<close>
[PROOF STATE]
proof (state)
this:
\<not> inj_on (col \<circ> a_r) {..<k + 1}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> inj_on (col \<circ> a_r) {..<k + 1}
[PROOF STEP]
obtain r1 r2 where pigeon_cols:
      "r1\<in>{..<k+1}"
      "r2\<in>{..<k+1}"
      "r1 < r2"
      "(col \<circ> a_r) r1 = (col \<circ> a_r) r2"
[PROOF STATE]
proof (prove)
using this:
\<not> inj_on (col \<circ> a_r) {..<k + 1}

goal (1 subgoal):
 1. (\<And>r1 r2. \<lbrakk>r1 \<in> {..<k + 1}; r2 \<in> {..<k + 1}; r1 < r2; (col \<circ> a_r) r1 = (col \<circ> a_r) r2\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (metis (mono_tags, lifting) linear linorder_inj_onI)
[PROOF STATE]
proof (state)
this:
r1 \<in> {..<k + 1}
r2 \<in> {..<k + 1}
r1 < r2
(col \<circ> a_r) r1 = (col \<circ> a_r) r2

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
text \<open> Show that the following function $h$ is an arithmetic progression which fulfills all
         properties for Van der Waerden's Theorem. \<close>
[PROOF STATE]
proof (state)
this:
r1 \<in> {..<k + 1}
r2 \<in> {..<k + 1}
r1 < r2
(col \<circ> a_r) r1 = (col \<circ> a_r) r2

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
define h where
    "h = (\<lambda>x. f (\<lambda>i. (if i<r1 then 0 else (if i<r2 then x else l))))"
[PROOF STATE]
proof (state)
this:
h = (\<lambda>x. f (\<lambda>i. if i < r1 then 0 else if i < r2 then x else l))

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have "h 0 = a_r r2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. h 0 = a_r r2
[PROOF STEP]
unfolding h_def a_r_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f (\<lambda>i. if i < r1 then 0 else if i < r2 then 0 else l) = f (\<lambda>i. if i < r2 then 0 else l)
[PROOF STEP]
using \<open>r1<r2\<close>
[PROOF STATE]
proof (prove)
using this:
r1 < r2

goal (1 subgoal):
 1. f (\<lambda>i. if i < r1 then 0 else if i < r2 then 0 else l) = f (\<lambda>i. if i < r2 then 0 else l)
[PROOF STEP]
by (intro arg_cong[where f = f]) auto
[PROOF STATE]
proof (state)
this:
h 0 = a_r r2

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
h 0 = a_r r2

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have "h l = a_r r1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. h l = a_r r1
[PROOF STEP]
unfolding h_def a_r_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f (\<lambda>i. if i < r1 then 0 else if i < r2 then l else l) = f (\<lambda>i. if i < r1 then 0 else l)
[PROOF STEP]
using \<open>r1<r2\<close>
[PROOF STATE]
proof (prove)
using this:
r1 < r2

goal (1 subgoal):
 1. f (\<lambda>i. if i < r1 then 0 else if i < r2 then l else l) = f (\<lambda>i. if i < r1 then 0 else l)
[PROOF STEP]
by (metis le_eq_less_or_eq less_le_trans)
[PROOF STATE]
proof (state)
this:
h l = a_r r1

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
h 0 = a_r r2
h l = a_r r1
[PROOF STEP]
have "col (h 0) = col (h l)"
[PROOF STATE]
proof (prove)
using this:
h 0 = a_r r2
h l = a_r r1

goal (1 subgoal):
 1. col (h 0) = col (h l)
[PROOF STEP]
using pigeon_cols(4)
[PROOF STATE]
proof (prove)
using this:
h 0 = a_r r2
h l = a_r r1
(col \<circ> a_r) r1 = (col \<circ> a_r) r2

goal (1 subgoal):
 1. col (h 0) = col (h l)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
col (h 0) = col (h l)

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have h_col: "col (h 0) = col (h i)" if "i\<in>{..<l+1}" for i
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. col (h 0) = col (h i)
[PROOF STEP]
proof (cases "i=l")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. i = l \<Longrightarrow> col (h 0) = col (h i)
 2. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
i = l

goal (2 subgoals):
 1. i = l \<Longrightarrow> col (h 0) = col (h i)
 2. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
i = l
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
i = l

goal (1 subgoal):
 1. col (h 0) = col (h i)
[PROOF STEP]
using \<open>col (h 0) = col (h l)\<close>
[PROOF STATE]
proof (prove)
using this:
i = l
col (h 0) = col (h l)

goal (1 subgoal):
 1. col (h 0) = col (h i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
col (h 0) = col (h i)

goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
i \<noteq> l

goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
i \<noteq> l
[PROOF STEP]
have "i<l"
[PROOF STATE]
proof (prove)
using this:
i \<noteq> l

goal (1 subgoal):
 1. i < l
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
i \<noteq> l
i \<in> {..<l + 1}

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

goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
let ?c = "(\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
have "?c\<in>{0..<k} \<rightarrow> {0..l}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
i \<in> {..<l + 1}

goal (1 subgoal):
 1. (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}

goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}

goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
have "(\<forall>j\<le>r2-1. ?c j < l)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>j\<le>r2 - 1. (if j < r1 then 0 else if j < r2 then i else l) < l
[PROOF STEP]
using \<open>i<l\<close> pigeon_cols(3)
[PROOF STATE]
proof (prove)
using this:
i < l
r1 < r2

goal (1 subgoal):
 1. \<forall>j\<le>r2 - 1. (if j < r1 then 0 else if j < r2 then i else l) < l
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
\<forall>j\<le>r2 - 1. (if j < r1 then 0 else if j < r2 then i else l) < l

goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}
\<forall>j\<le>r2 - 1. (if j < r1 then 0 else if j < r2 then i else l) < l
[PROOF STEP]
have "col (f ?c) =
      col (f (\<lambda>i. if i \<le> r2-1 then 0 else ?c i))"
[PROOF STATE]
proof (prove)
using this:
(\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}
\<forall>j\<le>r2 - 1. (if j < r1 then 0 else if j < r2 then i else l) < l

goal (1 subgoal):
 1. col (f (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)) = col (f (\<lambda>ia. if ia \<le> r2 - 1 then 0 else if ia < r1 then 0 else if ia < r2 then i else l))
[PROOF STEP]
using rel_propE[of ?c "r2-1"] pigeon_cols
[PROOF STATE]
proof (prove)
using this:
(\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}
\<forall>j\<le>r2 - 1. (if j < r1 then 0 else if j < r2 then i else l) < l
\<lbrakk>(\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l) \<in> {0..<k} \<rightarrow> {0..l}; r2 - 1 < k; \<forall>j\<le>r2 - 1. (if j < r1 then 0 else if j < r2 then i else l) < l\<rbrakk> \<Longrightarrow> col (f (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)) = col (f (\<lambda>ia. if ia \<le> r2 - 1 then 0 else if ia < r1 then 0 else if ia < r2 then i else l))
r1 \<in> {..<k + 1}
r2 \<in> {..<k + 1}
r1 < r2
(col \<circ> a_r) r1 = (col \<circ> a_r) r2

goal (1 subgoal):
 1. col (f (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)) = col (f (\<lambda>ia. if ia \<le> r2 - 1 then 0 else if ia < r1 then 0 else if ia < r2 then i else l))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
col (f (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)) = col (f (\<lambda>ia. if ia \<le> r2 - 1 then 0 else if ia < r1 then 0 else if ia < r2 then i else l))

goal (1 subgoal):
 1. i \<noteq> l \<Longrightarrow> col (h 0) = col (h i)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
col (f (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)) = col (f (\<lambda>ia. if ia \<le> r2 - 1 then 0 else if ia < r1 then 0 else if ia < r2 then i else l))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
col (f (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)) = col (f (\<lambda>ia. if ia \<le> r2 - 1 then 0 else if ia < r1 then 0 else if ia < r2 then i else l))

goal (1 subgoal):
 1. col (h 0) = col (h i)
[PROOF STEP]
unfolding h_def f_def
[PROOF STATE]
proof (prove)
using this:
col (multi_arith_prog k start steps (\<lambda>idx. if idx < r1 then 0 else if idx < r2 then i else l)) = col (multi_arith_prog k start steps (\<lambda>ia. if ia \<le> r2 - 1 then 0 else if ia < r1 then 0 else if ia < r2 then i else l))

goal (1 subgoal):
 1. col (multi_arith_prog k start steps (\<lambda>i. if i < r1 then 0 else if i < r2 then 0 else l)) = col (multi_arith_prog k start steps (\<lambda>ia. if ia < r1 then 0 else if ia < r2 then i else l))
[PROOF STEP]
by (smt (z3) Nat.lessE One_nat_def add_diff_cancel_left'
          le_less less_Suc_eq_le multi_arith_prog_mono plus_1_eq_Suc)
[PROOF STATE]
proof (state)
this:
col (h 0) = col (h i)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?i \<in> {..<l + 1} \<Longrightarrow> col (h 0) = col (h ?i)

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
define h_start where "h_start = start + l*(\<Sum>i\<in>{r2..<k}. steps i)"
[PROOF STATE]
proof (state)
this:
h_start = start + int (l * sum steps {r2..<k})

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
define h_step where "h_step = (\<Sum>i\<in>{r1..<r2}. steps i)"
[PROOF STATE]
proof (state)
this:
h_step = sum steps {r1..<r2}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have h_arith_prog: "h = arith_prog h_start h_step"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. h = arith_prog h_start h_step
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. h = arith_prog h_start h_step
[PROOF STEP]
have "(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l)
        * int (steps x)) =
      int l * (\<Sum>x = r2..<k. int (steps x)) +
        int y * (\<Sum>x = r1..<r2. int (steps x))"
      for y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
proof (cases "r2 = k")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
r2 = k

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
r2 = k
[PROOF STEP]
have "r1<k"
[PROOF STATE]
proof (prove)
using this:
r2 = k

goal (1 subgoal):
 1. r1 < k
[PROOF STEP]
using pigeon_cols
[PROOF STATE]
proof (prove)
using this:
r2 = k
r1 \<in> {..<k + 1}
r2 \<in> {..<k + 1}
r1 < r2
(col \<circ> a_r) r1 = (col \<circ> a_r) r2

goal (1 subgoal):
 1. r1 < k
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
r1 < k

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
with True
[PROOF STATE]
proof (chain)
picking this:
r2 = k
r1 < k
[PROOF STEP]
have
        "(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l)
           * int (steps x)) =
         (\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x))"
[PROOF STATE]
proof (prove)
using this:
r2 = k
r1 < k

goal (1 subgoal):
 1. (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = (\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x))
[PROOF STEP]
by (intro sum.cong) auto
[PROOF STATE]
proof (state)
this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = (\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x))

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = (\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x))

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "\<dots> = (\<Sum>x<r1. int (if x < r1 then 0 else y) *
          int (steps x)) + (\<Sum>x=r1..<k. int (if x < r1 then 0 else y)
          * int (steps x))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x)) = (\<Sum>x<r1. int (if x < r1 then 0 else y) * int (steps x)) + (\<Sum>x = r1..<k. int (if x < r1 then 0 else y) * int (steps x))
[PROOF STEP]
using split_sum_mid_less[of r1 k
            "(\<lambda>x. int (if x < r1 then 0 else y) * int (steps x))"]
            \<open>r1<k\<close>
[PROOF STATE]
proof (prove)
using this:
r1 < k \<Longrightarrow> (\<Sum>j<k. int (if j < r1 then 0 else y) * int (steps j)) = (\<Sum>j<r1. int (if j < r1 then 0 else y) * int (steps j)) + (\<Sum>j = r1..<k. int (if j < r1 then 0 else y) * int (steps j))
r1 < k

goal (1 subgoal):
 1. (\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x)) = (\<Sum>x<r1. int (if x < r1 then 0 else y) * int (steps x)) + (\<Sum>x = r1..<k. int (if x < r1 then 0 else y) * int (steps x))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x)) = (\<Sum>x<r1. int (if x < r1 then 0 else y) * int (steps x)) + (\<Sum>x = r1..<k. int (if x < r1 then 0 else y) * int (steps x))

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>x<k. int (if x < r1 then 0 else y) * int (steps x)) = (\<Sum>x<r1. int (if x < r1 then 0 else y) * int (steps x)) + (\<Sum>x = r1..<k. int (if x < r1 then 0 else y) * int (steps x))

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "\<dots> = (\<Sum>x=r1..<k. int y * int (steps x))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>x<r1. int (if x < r1 then 0 else y) * int (steps x)) + (\<Sum>x = r1..<k. int (if x < r1 then 0 else y) * int (steps x)) = (\<Sum>x = r1..<k. int y * int (steps x))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>x<r1. int (if x < r1 then 0 else y) * int (steps x)) + (\<Sum>x = r1..<k. int (if x < r1 then 0 else y) * int (steps x)) = (\<Sum>x = r1..<k. int y * int (steps x))

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>x<r1. int (if x < r1 then 0 else y) * int (steps x)) + (\<Sum>x = r1..<k. int (if x < r1 then 0 else y) * int (steps x)) = (\<Sum>x = r1..<k. int y * int (steps x))

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "\<dots> = int y * (\<Sum>x=r1..<k. int (steps x))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>x = r1..<k. int y * int (steps x)) = int y * (\<Sum>x = r1..<k. int (steps x))
[PROOF STEP]
by (auto simp: sum_distrib_left[of "int y"])
[PROOF STATE]
proof (state)
this:
(\<Sum>x = r1..<k. int y * int (steps x)) = int y * (\<Sum>x = r1..<k. int (steps x))

goal (2 subgoals):
 1. r2 = k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
 2. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int y * (\<Sum>x = r1..<k. int (steps x))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int y * (\<Sum>x = r1..<k. int (steps x))

goal (1 subgoal):
 1. (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
using True
[PROOF STATE]
proof (prove)
using this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int y * (\<Sum>x = r1..<k. int (steps x))
r2 = k

goal (1 subgoal):
 1. (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
r2 \<noteq> k

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
r2 \<noteq> k
[PROOF STEP]
have "r2<k"
[PROOF STATE]
proof (prove)
using this:
r2 \<noteq> k

goal (1 subgoal):
 1. r2 < k
[PROOF STEP]
using pigeon_cols
[PROOF STATE]
proof (prove)
using this:
r2 \<noteq> k
r1 \<in> {..<k + 1}
r2 \<in> {..<k + 1}
r1 < r2
(col \<circ> a_r) r1 = (col \<circ> a_r) r2

goal (1 subgoal):
 1. r2 < k
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
r2 < k

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
define aux_left where "aux_left =
        (\<lambda>x. int (if x < r1 then 0 else if x < r2 then y else l)
          * int (steps x))"
[PROOF STATE]
proof (state)
this:
aux_left = (\<lambda>x. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x))

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "(\<Sum>x<k. aux_left x) = (\<Sum>x=r1..<k. aux_left x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum aux_left {..<k} = sum aux_left {r1..<k}
[PROOF STEP]
by (intro sum.mono_neutral_right) (auto simp: aux_left_def)
[PROOF STATE]
proof (state)
this:
sum aux_left {..<k} = sum aux_left {r1..<k}

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
sum aux_left {..<k} = sum aux_left {r1..<k}

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "{r1..<k} = {r1..<r2} \<union> {r2..<k}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {r1..<k} = {r1..<r2} \<union> {r2..<k}
[PROOF STEP]
using \<open>r1 < r2\<close> \<open>r2 < k\<close>
[PROOF STATE]
proof (prove)
using this:
r1 < r2
r2 < k

goal (1 subgoal):
 1. {r1..<k} = {r1..<r2} \<union> {r2..<k}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
{r1..<k} = {r1..<r2} \<union> {r2..<k}

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
{r1..<k} = {r1..<r2} \<union> {r2..<k}

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "(\<Sum>x\<in>\<dots>. aux_left x) = (\<Sum>x=r1..<r2. aux_left x) +
        (\<Sum>x=r2..<k. aux_left x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum aux_left ({r1..<r2} \<union> {r2..<k}) = sum aux_left {r1..<r2} + sum aux_left {r2..<k}
[PROOF STEP]
by (intro sum.union_disjoint) auto
[PROOF STATE]
proof (state)
this:
sum aux_left ({r1..<r2} \<union> {r2..<k}) = sum aux_left {r1..<r2} + sum aux_left {r2..<k}

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
sum aux_left ({r1..<r2} \<union> {r2..<k}) = sum aux_left {r1..<r2} + sum aux_left {r2..<k}

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "(\<Sum>x=r1..<r2. aux_left x) =
        (\<Sum>x=r1..<r2. int y * int (steps x))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum aux_left {r1..<r2} = (\<Sum>x = r1..<r2. int y * int (steps x))
[PROOF STEP]
by (intro sum.cong) (auto simp: aux_left_def)
[PROOF STATE]
proof (state)
this:
sum aux_left {r1..<r2} = (\<Sum>x = r1..<r2. int y * int (steps x))

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
sum aux_left {r1..<r2} = (\<Sum>x = r1..<r2. int y * int (steps x))

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
have "(\<Sum>x=r2..<k. aux_left x) =
        (\<Sum>x=r2..<k. int l * int (steps x))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum aux_left {r2..<k} = (\<Sum>x = r2..<k. int l * int (steps x))
[PROOF STEP]
using \<open>r1 < r2\<close>
[PROOF STATE]
proof (prove)
using this:
r1 < r2

goal (1 subgoal):
 1. sum aux_left {r2..<k} = (\<Sum>x = r2..<k. int l * int (steps x))
[PROOF STEP]
by (intro sum.cong) (auto simp: aux_left_def)
[PROOF STATE]
proof (state)
this:
sum aux_left {r2..<k} = (\<Sum>x = r2..<k. int l * int (steps x))

goal (1 subgoal):
 1. r2 \<noteq> k \<Longrightarrow> (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
sum aux_left {..<k} = (\<Sum>x = r1..<r2. int y * int (steps x)) + (\<Sum>x = r2..<k. int l * int (steps x))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
sum aux_left {..<k} = (\<Sum>x = r1..<r2. int y * int (steps x)) + (\<Sum>x = r2..<k. int l * int (steps x))

goal (1 subgoal):
 1. (\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
by (simp add: aux_left_def sum_distrib_left)
[PROOF STATE]
proof (state)
this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int y * (\<Sum>x = r1..<r2. int (steps x))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then ?y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int ?y * (\<Sum>x = r1..<r2. int (steps x))

goal (1 subgoal):
 1. h = arith_prog h_start h_step
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then ?y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int ?y * (\<Sum>x = r1..<r2. int (steps x))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then ?y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int ?y * (\<Sum>x = r1..<r2. int (steps x))

goal (1 subgoal):
 1. h = arith_prog h_start h_step
[PROOF STEP]
unfolding arith_prog_def h_start_def h_step_def h_def f_def
        multi_arith_prog_def
[PROOF STATE]
proof (prove)
using this:
(\<Sum>x<k. int (if x < r1 then 0 else if x < r2 then ?y else l) * int (steps x)) = int l * (\<Sum>x = r2..<k. int (steps x)) + int ?y * (\<Sum>x = r1..<r2. int (steps x))

goal (1 subgoal):
 1. (\<lambda>x. start + int (\<Sum>i<k. (if i < r1 then 0 else if i < r2 then x else l) * steps i)) = (\<lambda>i. start + int (l * sum steps {r2..<k}) + int (i * sum steps {r1..<r2}))
[PROOF STEP]
by (auto split:if_splits)
[PROOF STATE]
proof (state)
this:
h = arith_prog h_start h_step

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
h = arith_prog h_start h_step

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
define j where "j = col (h 0)"
[PROOF STATE]
proof (state)
this:
j = col (h 0)

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have case_j: "j<k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j < k
[PROOF STEP]
using 1 range_col_a_r \<open>col (h 0) = col (h l)\<close>
      \<open>h l = a_r r1\<close> j_def pigeon_cols(1)
[PROOF STATE]
proof (prove)
using this:
a + int N \<le> b + 1
col \<in> {a..b} \<rightarrow> {..<k}
?x < k + 1 \<Longrightarrow> col (a_r ?x) < k
col (h 0) = col (h l)
h l = a_r r1
j = col (h 0)
r1 \<in> {..<k + 1}

goal (1 subgoal):
 1. j < k
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
j < k

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have case_step: "h_step > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < h_step
[PROOF STEP]
unfolding h_step_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < sum steps {r1..<r2}
[PROOF STEP]
using pigeon_cols
[PROOF STATE]
proof (prove)
using this:
r1 \<in> {..<k + 1}
r2 \<in> {..<k + 1}
r1 < r2
(col \<circ> a_r) r1 = (col \<circ> a_r) r2

goal (1 subgoal):
 1. 0 < sum steps {r1..<r2}
[PROOF STEP]
by (intro sum_pos prog(1)) auto
[PROOF STATE]
proof (state)
this:
0 < h_step

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have range_h: "h i \<in> {a..b}" if "i < l + 1" for i
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. h i \<in> {a..b}
[PROOF STEP]
unfolding h_def f_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. multi_arith_prog k start steps (\<lambda>ia. if ia < r1 then 0 else if ia < r2 then i else l) \<in> {a..b}
[PROOF STEP]
by (rule is_multi_arith_prog_onD[OF prog(2)])
      (use that in auto)
[PROOF STATE]
proof (state)
this:
?i < l + 1 \<Longrightarrow> h ?i \<in> {a..b}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have case_on: "is_arith_prog_on (l+1) h_start h_step a b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. is_arith_prog_on (l + 1) h_start h_step a b
[PROOF STEP]
unfolding is_arith_prog_on_def h_arith_prog
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a \<le> h_start \<and> arith_prog h_start h_step (l + 1 - 1) \<le> b
[PROOF STEP]
using range_h[of 0] range_h[of l]
[PROOF STATE]
proof (prove)
using this:
0 < l + 1 \<Longrightarrow> h 0 \<in> {a..b}
l < l + 1 \<Longrightarrow> h l \<in> {a..b}

goal (1 subgoal):
 1. a \<le> h_start \<and> arith_prog h_start h_step (l + 1 - 1) \<le> b
[PROOF STEP]
by (auto simp: Max_ge[of "{a..b}"] Min_le[of "{a..b}"]
        h_arith_prog arith_prog_def)
[PROOF STATE]
proof (state)
this:
is_arith_prog_on (l + 1) h_start h_step a b

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
have case_col: "h ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. h ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
using h_col range_h
[PROOF STATE]
proof (prove)
using this:
?i \<in> {..<l + 1} \<Longrightarrow> col (h 0) = col (h ?i)
?i < l + 1 \<Longrightarrow> h ?i \<in> {a..b}

goal (1 subgoal):
 1. h ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
unfolding j_def
[PROOF STATE]
proof (prove)
using this:
?i \<in> {..<l + 1} \<Longrightarrow> col (h 0) = col (h ?i)
?i < l + 1 \<Longrightarrow> h ?i \<in> {a..b}

goal (1 subgoal):
 1. h ` {..<Suc l} \<subseteq> col -` {col (h 0)} \<inter> {a..b}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
h ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}

goal (1 subgoal):
 1. \<And>a b col. \<lbrakk>a + int N \<le> b + 1; col \<in> {a..b} \<rightarrow> {..<k}\<rbrakk> \<Longrightarrow> \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
using case_j case_step case_on case_col
[PROOF STATE]
proof (prove)
using this:
j < k
0 < h_step
is_arith_prog_on (l + 1) h_start h_step a b
h ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}

goal (1 subgoal):
 1. \<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}
[PROOF STEP]
by (auto simp: h_arith_prog)
[PROOF STATE]
proof (state)
this:
\<exists>j start step. j < k \<and> 0 < step \<and> is_arith_prog_on (Suc l) start step a b \<and> arith_prog start step ` {..<Suc l} \<subseteq> col -` {j} \<inter> {a..b}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma FV0_code[code]:
  "FV0 x (Eq is i off) = Option.these (set (map_index (\<lambda>i x. if x = 0 then None else Some i) is))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. FV0 x (presb.Eq is i off) = Option.these (set (map_index (\<lambda>i x. if x = 0 then None else Some i) is))
[PROOF STEP]
unfolding FV0_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (case presb.Eq is i off of presb.Eq is x xa \<Rightarrow> {n. n < length is \<and> is ! n \<noteq> 0}) = Option.these (set (map_index (\<lambda>i x. if x = 0 then None else Some i) is))
[PROOF STEP]
by (force simp: Option.these_def image_iff)


[STATEMENT]
lemma subset_snd_imageI: "A \<times> B \<subseteq> S \<Longrightarrow> x \<in> A \<Longrightarrow> B \<subseteq> snd ` S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>A \<times> B \<subseteq> S; x \<in> A\<rbrakk> \<Longrightarrow> B \<subseteq> snd ` S
[PROOF STEP]
unfolding image_def subset_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<forall>x\<in>A \<times> B. x \<in> S; x \<in> A\<rbrakk> \<Longrightarrow> \<forall>x\<in>B. x \<in> {y. \<exists>x\<in>S. y = snd x}
[PROOF STEP]
by force


[STATEMENT]
lemma vdiff_iff[simp]: "x \<in>\<^sub>\<circ> A -\<^sub>\<circ> B \<longleftrightarrow> x \<in>\<^sub>\<circ> A \<and> x \<notin>\<^sub>\<circ> B"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x \<in>\<^sub>\<circ> A -\<^sub>\<circ> B) = (x \<in>\<^sub>\<circ> A \<and> x \<notin>\<^sub>\<circ> B)
[PROOF STEP]
unfolding vdiff_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x \<in>\<^sub>\<circ> set {x. x \<in>\<^sub>\<circ> A \<and> x \<notin>\<^sub>\<circ> B}) = (x \<in>\<^sub>\<circ> A \<and> x \<notin>\<^sub>\<circ> B)
[PROOF STEP]
by simp


[STATEMENT]
lemma separating_dense_span:
  assumes \<open>\<And>F G :: 'a::chilbert_space \<Rightarrow> 'b::{complex_normed_vector,not_singleton}.
           bounded_clinear F \<Longrightarrow> bounded_clinear G \<Longrightarrow> (\<forall>x\<in>S. F x = G x) \<Longrightarrow> F = G\<close>
  shows \<open>closure (cspan S) = UNIV\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. closure (cspan S) = UNIV
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. closure (cspan S) = UNIV
[PROOF STEP]
have \<open>\<psi> = 0\<close> if \<open>\<psi> \<in> orthogonal_complement S\<close> for \<psi>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> = (0::'a)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<psi> = (0::'a)
[PROOF STEP]
obtain \<phi> :: 'b where \<open>\<phi> \<noteq> 0\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>\<phi>. \<phi> \<noteq> (0::'b) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
\<phi> \<noteq> (0::'b)

goal (1 subgoal):
 1. \<psi> = (0::'a)
[PROOF STEP]
have \<open>(\<lambda>x. cinner \<psi> x *\<^sub>C \<phi>) = (\<lambda>_. 0)\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>x. (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi>) = (\<lambda>_. 0::'b)
[PROOF STEP]
apply (rule assms[rule_format])
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. bounded_clinear (\<lambda>x. (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi>)
 2. bounded_clinear (\<lambda>_. 0::'b)
 3. \<And>x. x \<in> S \<Longrightarrow> (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi> = (0::'b)
[PROOF STEP]
using orthogonal_complement_orthoI that
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?x \<in> orthogonal_complement ?M; ?y \<in> ?M\<rbrakk> \<Longrightarrow> is_orthogonal ?x ?y
\<psi> \<in> orthogonal_complement S

goal (3 subgoals):
 1. bounded_clinear (\<lambda>x. (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi>)
 2. bounded_clinear (\<lambda>_. 0::'b)
 3. \<And>x. x \<in> S \<Longrightarrow> (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi> = (0::'b)
[PROOF STEP]
by (auto simp add: bounded_clinear_cinner_right bounded_clinear_scaleC_const)
[PROOF STATE]
proof (state)
this:
(\<lambda>x. (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi>) = (\<lambda>_. 0::'b)

goal (1 subgoal):
 1. \<psi> = (0::'a)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>x. (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi>) = (\<lambda>_. 0::'b)
[PROOF STEP]
have \<open>cinner \<psi> \<psi> = 0\<close>
[PROOF STATE]
proof (prove)
using this:
(\<lambda>x. (\<psi> \<bullet>\<^sub>C x) *\<^sub>C \<phi>) = (\<lambda>_. 0::'b)

goal (1 subgoal):
 1. is_orthogonal \<psi> \<psi>
[PROOF STEP]
by (meson \<open>\<phi> \<noteq> 0\<close> scaleC_eq_0_iff)
[PROOF STATE]
proof (state)
this:
is_orthogonal \<psi> \<psi>

goal (1 subgoal):
 1. \<psi> = (0::'a)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
is_orthogonal \<psi> \<psi>
[PROOF STEP]
show \<open>\<psi> = 0\<close>
[PROOF STATE]
proof (prove)
using this:
is_orthogonal \<psi> \<psi>

goal (1 subgoal):
 1. \<psi> = (0::'a)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<psi> = (0::'a)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?\<psi> \<in> orthogonal_complement S \<Longrightarrow> ?\<psi> = (0::'a)

goal (1 subgoal):
 1. closure (cspan S) = UNIV
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?\<psi> \<in> orthogonal_complement S \<Longrightarrow> ?\<psi> = (0::'a)
[PROOF STEP]
have \<open>orthogonal_complement (orthogonal_complement S) = UNIV\<close>
[PROOF STATE]
proof (prove)
using this:
?\<psi> \<in> orthogonal_complement S \<Longrightarrow> ?\<psi> = (0::'a)

goal (1 subgoal):
 1. orthogonal_complement (orthogonal_complement S) = UNIV
[PROOF STEP]
by (metis UNIV_eq_I cinner_zero_right orthogonal_complementI)
[PROOF STATE]
proof (state)
this:
orthogonal_complement (orthogonal_complement S) = UNIV

goal (1 subgoal):
 1. closure (cspan S) = UNIV
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
orthogonal_complement (orthogonal_complement S) = UNIV
[PROOF STEP]
show \<open>closure (cspan S) = UNIV\<close>
[PROOF STATE]
proof (prove)
using this:
orthogonal_complement (orthogonal_complement S) = UNIV

goal (1 subgoal):
 1. closure (cspan S) = UNIV
[PROOF STEP]
by (simp add: orthogonal_complement_orthogonal_complement_closure_cspan)
[PROOF STATE]
proof (state)
this:
closure (cspan S) = UNIV

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma le_le_imp_sum_mult_le_sum_mult:
assumes "i \<le> j" "m \<le> (n::nat)"
shows "i * n + j * m \<le> i * m + j * n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i * n + j * m \<le> i * m + j * n
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i * n + j * m \<le> i * m + j * n
[PROOF STEP]
have "i * m + i * (n - m) + j * m \<le> i * m + j * m + j * (n - m)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i * m + i * (n - m) + j * m \<le> i * m + j * m + j * (n - m)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
i \<le> j
m \<le> n

goal (1 subgoal):
 1. i * m + i * (n - m) + j * m \<le> i * m + j * m + j * (n - m)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
i * m + i * (n - m) + j * m \<le> i * m + j * m + j * (n - m)

goal (1 subgoal):
 1. i * n + j * m \<le> i * m + j * n
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
i * m + i * (n - m) + j * m \<le> i * m + j * m + j * (n - m)

goal (1 subgoal):
 1. i * n + j * m \<le> i * m + j * n
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
i * m + i * (n - m) + j * m \<le> i * m + j * m + j * (n - m)
i \<le> j
m \<le> n

goal (1 subgoal):
 1. i * n + j * m \<le> i * m + j * n
[PROOF STEP]
by (simp add: diff_mult_distrib2)
[PROOF STATE]
proof (state)
this:
i * n + j * m \<le> i * m + j * n

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma var0_match:
assumes "wf A" "M \<subseteq> {<n}" "a < n \<and> a \<notin> M"
shows "var0 A (M \<union> {a}) < var0 A M"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. var0 A (M \<union> {a}) < var0 A M
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. var0 A (M \<union> {a}) < var0 A M
[PROOF STEP]
have 2: "M \<subset> {<n}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. M \<subset> {<n}
[PROOF STEP]
using assms(2-3)
[PROOF STATE]
proof (prove)
using this:
M \<subseteq> {<n}
a < n \<and> a \<notin> M

goal (1 subgoal):
 1. M \<subset> {<n}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
M \<subset> {<n}

goal (1 subgoal):
 1. var0 A (M \<union> {a}) < var0 A M
[PROOF STEP]
have 3: "card M < n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card M < n
[PROOF STEP]
using psubset_card_mono[OF _ 2]
[PROOF STATE]
proof (prove)
using this:
finite {<n} \<Longrightarrow> card M < card {<n}

goal (1 subgoal):
 1. card M < n
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
card M < n

goal (1 subgoal):
 1. var0 A (M \<union> {a}) < var0 A M
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
card M < n
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
card M < n

goal (1 subgoal):
 1. var0 A (M \<union> {a}) < var0 A M
[PROOF STEP]
using sumA_ub[OF assms(1)] assms(3) finite_subset[OF assms(2)]
[PROOF STATE]
proof (prove)
using this:
card M < n
sum ((!) A) {..<n} \<le> n * (n - 1)
a < n \<and> a \<notin> M
finite {<n} \<Longrightarrow> finite M

goal (1 subgoal):
 1. var0 A (M \<union> {a}) < var0 A M
[PROOF STEP]
by (simp add: power2_eq_square algebra_simps le_diff_conv2)
[PROOF STATE]
proof (state)
this:
var0 A (M \<union> {a}) < var0 A M

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma length_msort: "length(msort xs) = length xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length (msort xs) = length xs
[PROOF STEP]
proof (induction xs rule: msort.induct)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>xs. \<lbrakk>\<And>x. \<lbrakk>x = length xs; \<not> x \<le> 1\<rbrakk> \<Longrightarrow> length (msort (take (x div 2) xs)) = length (take (x div 2) xs); \<And>x. \<lbrakk>x = length xs; \<not> x \<le> 1\<rbrakk> \<Longrightarrow> length (msort (drop (x div 2) xs)) = length (drop (x div 2) xs)\<rbrakk> \<Longrightarrow> length (msort xs) = length xs
[PROOF STEP]
case (1 xs)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?x = length xs; \<not> ?x \<le> 1\<rbrakk> \<Longrightarrow> length (msort (take (?x div 2) xs)) = length (take (?x div 2) xs)
\<lbrakk>?x = length xs; \<not> ?x \<le> 1\<rbrakk> \<Longrightarrow> length (msort (drop (?x div 2) xs)) = length (drop (?x div 2) xs)

goal (1 subgoal):
 1. \<And>xs. \<lbrakk>\<And>x. \<lbrakk>x = length xs; \<not> x \<le> 1\<rbrakk> \<Longrightarrow> length (msort (take (x div 2) xs)) = length (take (x div 2) xs); \<And>x. \<lbrakk>x = length xs; \<not> x \<le> 1\<rbrakk> \<Longrightarrow> length (msort (drop (x div 2) xs)) = length (drop (x div 2) xs)\<rbrakk> \<Longrightarrow> length (msort xs) = length xs
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length (msort xs) = length xs
[PROOF STEP]
by (auto simp: msort.simps [of xs] 1 length_merge)
[PROOF STATE]
proof (state)
this:
length (msort xs) = length xs

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma height_size1_Delta:
  "wbt t \<Longrightarrow> (1 + 1/\<Delta>) ^ (height t) \<le> size1 t"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. wbt t \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t \<le> real (size1 t)
[PROOF STEP]
proof(induction  t)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. wbt \<langle>\<rangle> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>\<rangle> \<le> real (size1 \<langle>\<rangle>)
 2. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
case Leaf
[PROOF STATE]
proof (state)
this:
wbt \<langle>\<rangle>

goal (2 subgoals):
 1. wbt \<langle>\<rangle> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>\<rangle> \<le> real (size1 \<langle>\<rangle>)
 2. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
wbt \<langle>\<rangle>

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height \<langle>\<rangle> \<le> real (size1 \<langle>\<rangle>)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>\<rangle> \<le> real (size1 \<langle>\<rangle>)

goal (1 subgoal):
 1. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
case (Node l a r)
[PROOF STATE]
proof (state)
this:
wbt l \<Longrightarrow> (1 + 1 / \<Delta>) ^ height l \<le> real (size1 l)
wbt r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height r \<le> real (size1 r)
wbt \<langle>l, a, r\<rangle>

goal (1 subgoal):
 1. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
let ?t = "Node l a r"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
let ?s = "size1 ?t"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
let ?d = "1 + 1/\<Delta>"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
from Node.prems(1)
[PROOF STATE]
proof (chain)
picking this:
wbt \<langle>l, a, r\<rangle>
[PROOF STEP]
have 1: "size1 l * ?d \<le> ?s" and 2: "size1 r * ?d  \<le> ?s"
[PROOF STATE]
proof (prove)
using this:
wbt \<langle>l, a, r\<rangle>

goal (1 subgoal):
 1. real (size1 l) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>) &&& real (size1 r) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
using Delta
[PROOF STATE]
proof (prove)
using this:
wbt \<langle>l, a, r\<rangle>
1 \<le> \<Delta>

goal (1 subgoal):
 1. real (size1 l) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>) &&& real (size1 r) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
by (auto simp: Let_def field_simps add_pos_pos neq0_if)
[PROOF STATE]
proof (state)
this:
real (size1 l) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)
real (size1 r) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (1 subgoal):
 1. \<And>t1 x2 t2. \<lbrakk>wbt t1 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t1 \<le> real (size1 t1); wbt t2 \<Longrightarrow> (1 + 1 / \<Delta>) ^ height t2 \<le> real (size1 t2); wbt \<langle>t1, x2, t2\<rangle>\<rbrakk> \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>t1, x2, t2\<rangle> \<le> real (size1 \<langle>t1, x2, t2\<rangle>)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
proof (cases "height l \<le> height r")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
 2. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
height l \<le> height r

goal (2 subgoals):
 1. height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
 2. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
hence "?d ^ (height ?t) = ?d ^ (height r) * ?d"
[PROOF STATE]
proof (prove)
using this:
height l \<le> height r

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> = (1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>)
[PROOF STEP]
by(simp)
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> = (1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>)

goal (2 subgoals):
 1. height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
 2. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> = (1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>)

goal (2 subgoals):
 1. height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
 2. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
have "\<dots> \<le> size1 r * ?d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>) \<le> real (size1 r) * (1 + 1 / \<Delta>)
[PROOF STEP]
using Node.IH(2) Node.prems Delta
[PROOF STATE]
proof (prove)
using this:
wbt r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height r \<le> real (size1 r)
wbt \<langle>l, a, r\<rangle>
1 \<le> \<Delta>

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>) \<le> real (size1 r) * (1 + 1 / \<Delta>)
[PROOF STEP]
unfolding wbt.simps
[PROOF STATE]
proof (prove)
using this:
wbt r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height r \<le> real (size1 r)
balanced1 l r \<and> balanced1 r l \<and> wbt l \<and> wbt r
1 \<le> \<Delta>

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>) \<le> real (size1 r) * (1 + 1 / \<Delta>)
[PROOF STEP]
by (smt (verit) divide_nonneg_nonneg mult_mono of_nat_0_le_iff)
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>) \<le> real (size1 r) * (1 + 1 / \<Delta>)

goal (2 subgoals):
 1. height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
 2. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height r * (1 + 1 / \<Delta>) \<le> real (size1 r) * (1 + 1 / \<Delta>)

goal (2 subgoals):
 1. height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
 2. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
have "\<dots> \<le> ?s"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (size1 r) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
using 2
[PROOF STATE]
proof (prove)
using this:
real (size1 r) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (1 subgoal):
 1. real (size1 r) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
by (simp)
[PROOF STATE]
proof (state)
this:
real (size1 r) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (2 subgoals):
 1. height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
 2. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> height l \<le> height r

goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
hence "?d ^ (height ?t) = ?d ^ (height l) * ?d"
[PROOF STATE]
proof (prove)
using this:
\<not> height l \<le> height r

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> = (1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>)
[PROOF STEP]
by(simp)
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> = (1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>)

goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> = (1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>)

goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
have "\<dots> \<le> size1 l * ?d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>) \<le> real (size1 l) * (1 + 1 / \<Delta>)
[PROOF STEP]
using Node.IH(1) Node.prems Delta
[PROOF STATE]
proof (prove)
using this:
wbt l \<Longrightarrow> (1 + 1 / \<Delta>) ^ height l \<le> real (size1 l)
wbt \<langle>l, a, r\<rangle>
1 \<le> \<Delta>

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>) \<le> real (size1 l) * (1 + 1 / \<Delta>)
[PROOF STEP]
unfolding wbt.simps
[PROOF STATE]
proof (prove)
using this:
wbt l \<Longrightarrow> (1 + 1 / \<Delta>) ^ height l \<le> real (size1 l)
balanced1 l r \<and> balanced1 r l \<and> wbt l \<and> wbt r
1 \<le> \<Delta>

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>) \<le> real (size1 l) * (1 + 1 / \<Delta>)
[PROOF STEP]
by (smt (verit) divide_nonneg_nonneg mult_mono of_nat_0_le_iff)
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>) \<le> real (size1 l) * (1 + 1 / \<Delta>)

goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height l * (1 + 1 / \<Delta>) \<le> real (size1 l) * (1 + 1 / \<Delta>)

goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
have "\<dots> \<le> ?s"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (size1 l) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
using 1
[PROOF STATE]
proof (prove)
using this:
real (size1 l) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (1 subgoal):
 1. real (size1 l) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
by (simp)
[PROOF STATE]
proof (state)
this:
real (size1 l) * (1 + 1 / \<Delta>) \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (1 subgoal):
 1. \<not> height l \<le> height r \<Longrightarrow> (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)

goal (1 subgoal):
 1. (1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(1 + 1 / \<Delta>) ^ height \<langle>l, a, r\<rangle> \<le> real (size1 \<langle>l, a, r\<rangle>)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma f_join_f_expand_iT_Mult: "
  0 < k \<Longrightarrow> xs \<odot>\<^sub>f k \<Join>\<^sub>f (I \<otimes> k) = xs \<Join>\<^sub>f I"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < k \<Longrightarrow> xs \<odot> k \<Join>\<^sub> (I \<otimes> k) = xs \<Join>\<^sub> I
[PROOF STEP]
apply (case_tac "I = {}")
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>0 < k; I = {}\<rbrakk> \<Longrightarrow> xs \<odot> k \<Join>\<^sub> (I \<otimes> k) = xs \<Join>\<^sub> I
 2. \<lbrakk>0 < k; I \<noteq> {}\<rbrakk> \<Longrightarrow> xs \<odot> k \<Join>\<^sub> (I \<otimes> k) = xs \<Join>\<^sub> I
[PROOF STEP]
apply (simp add: iT_Mult_empty f_join_empty)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < k; I \<noteq> {}\<rbrakk> \<Longrightarrow> xs \<odot> k \<Join>\<^sub> (I \<otimes> k) = xs \<Join>\<^sub> I
[PROOF STEP]
apply (simp add: list_eq_iff f_join_length)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < k; I \<noteq> {}\<rbrakk> \<Longrightarrow> card ((I \<otimes> k) \<down>< (length xs * k)) = card (I \<down>< length xs) \<and> (\<forall>i<card ((I \<otimes> k) \<down>< (length xs * k)). xs \<odot> k \<Join>\<^sub> (I \<otimes> k) ! i = xs \<Join>\<^sub> I ! i)
[PROOF STEP]
apply (clarsimp simp: iT_Mult_cut_less2 iT_Mult_card)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>i. \<lbrakk>0 < k; I \<noteq> {}; i < card (I \<down>< length xs)\<rbrakk> \<Longrightarrow> xs \<odot> k \<Join>\<^sub> (I \<otimes> k) ! i = xs \<Join>\<^sub> I ! i
[PROOF STEP]
apply (simp add: f_join_nth2 iT_Mult_cut_less2 iT_Mult_card)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>i. \<lbrakk>0 < k; I \<noteq> {}; i < card (I \<down>< length xs)\<rbrakk> \<Longrightarrow> xs \<odot> k ! ((I \<otimes> k) \<rightarrow> i) = xs ! (I \<rightarrow> i)
[PROOF STEP]
apply (drule less_card_cut_less_imp_inext_nth_less)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>i. \<lbrakk>0 < k; I \<noteq> {}; I \<rightarrow> i < length xs\<rbrakk> \<Longrightarrow> xs \<odot> k ! ((I \<otimes> k) \<rightarrow> i) = xs ! (I \<rightarrow> i)
[PROOF STEP]
apply (simp add: iT_Mult_inext_nth f_expand_nth_mult)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done