[STATEMENT]
lemma card_set_of_intersecting_sets_by_card:
  assumes "A \<subseteq> I" "finite I" "k \<le> n" "n \<le> card I" "k \<le> card A"
  shows "card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * ((card I - card A) choose (n - k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
note finite_A = finite_subset[OF assms(1,2)]
[PROOF STATE]
proof (state)
this:
finite A

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
have "card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = card ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})" (is "card ?lhs = card ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = card ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
proof (rule bij_betw_same_card[symmetric])
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. bij_betw ?f ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
let ?f = "\<lambda>(K, B'). K \<union> B'"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. bij_betw ?f ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
have "inj_on ?f ?rhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
by (blast intro: inj_onI)
[PROOF STATE]
proof (state)
this:
inj_on (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (1 subgoal):
 1. bij_betw ?f ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
inj_on (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (1 subgoal):
 1. bij_betw ?f ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
have "?f ` ?rhs = ?lhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
proof (rule set_eqI, rule iffI)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>x. x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) \<Longrightarrow> x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
 2. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
fix B
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>x. x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) \<Longrightarrow> x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
 2. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
assume "B \<in> ?f ` ?rhs"
[PROOF STATE]
proof (state)
this:
B \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (2 subgoals):
 1. \<And>x. x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) \<Longrightarrow> x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
 2. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
B \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
obtain K B' where K: "K \<subseteq> A" "card K = k" "B' \<subseteq> I - A" "card B' = n - k" "K \<union> B' = B"
[PROOF STATE]
proof (prove)
using this:
B \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (1 subgoal):
 1. (\<And>K B'. \<lbrakk>K \<subseteq> A; card K = k; B' \<subseteq> I - A; card B' = n - k; K \<union> B' = B\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
K \<subseteq> A
card K = k
B' \<subseteq> I - A
card B' = n - k
K \<union> B' = B

goal (2 subgoals):
 1. \<And>x. x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) \<Longrightarrow> x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
 2. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
show "B \<in> ?lhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. B \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
proof safe
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>x. x \<in> B \<Longrightarrow> x \<in> I
 2. card B = n
 3. card (A \<inter> B) = k
[PROOF STEP]
fix x
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>x. x \<in> B \<Longrightarrow> x \<in> I
 2. card B = n
 3. card (A \<inter> B) = k
[PROOF STEP]
assume "x \<in> B"
[PROOF STATE]
proof (state)
this:
x \<in> B

goal (3 subgoals):
 1. \<And>x. x \<in> B \<Longrightarrow> x \<in> I
 2. card B = n
 3. card (A \<inter> B) = k
[PROOF STEP]
thus "x \<in> I"
[PROOF STATE]
proof (prove)
using this:
x \<in> B

goal (1 subgoal):
 1. x \<in> I
[PROOF STEP]
using K \<open>A \<subseteq> I\<close>
[PROOF STATE]
proof (prove)
using this:
x \<in> B
K \<subseteq> A
card K = k
B' \<subseteq> I - A
card B' = n - k
K \<union> B' = B
A \<subseteq> I

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

goal (2 subgoals):
 1. card B = n
 2. card (A \<inter> B) = k
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. card B = n
 2. card (A \<inter> B) = k
[PROOF STEP]
have "card B = card K + card B' - card (K \<inter> B')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card B = card K + card B' - card (K \<inter> B')
[PROOF STEP]
using K assms
[PROOF STATE]
proof (prove)
using this:
K \<subseteq> A
card K = k
B' \<subseteq> I - A
card B' = n - k
K \<union> B' = B
A \<subseteq> I
finite I
k \<le> n
n \<le> card I
k \<le> card A

goal (1 subgoal):
 1. card B = card K + card B' - card (K \<inter> B')
[PROOF STEP]
by (metis card_union finite_A finite_subset finite_Diff)
[PROOF STATE]
proof (state)
this:
card B = card K + card B' - card (K \<inter> B')

goal (2 subgoals):
 1. card B = n
 2. card (A \<inter> B) = k
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
card B = card K + card B' - card (K \<inter> B')

goal (2 subgoals):
 1. card B = n
 2. card (A \<inter> B) = k
[PROOF STEP]
have "K \<inter> B' = {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. K \<inter> B' = {}
[PROOF STEP]
using K assms
[PROOF STATE]
proof (prove)
using this:
K \<subseteq> A
card K = k
B' \<subseteq> I - A
card B' = n - k
K \<union> B' = B
A \<subseteq> I
finite I
k \<le> n
n \<le> card I
k \<le> card A

goal (1 subgoal):
 1. K \<inter> B' = {}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
K \<inter> B' = {}

goal (2 subgoals):
 1. card B = n
 2. card (A \<inter> B) = k
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
card B = card K + card B' - card (K \<inter> B')
K \<inter> B' = {}
[PROOF STEP]
show "card B = n"
[PROOF STATE]
proof (prove)
using this:
card B = card K + card B' - card (K \<inter> B')
K \<inter> B' = {}

goal (1 subgoal):
 1. card B = n
[PROOF STEP]
using K assms
[PROOF STATE]
proof (prove)
using this:
card B = card K + card B' - card (K \<inter> B')
K \<inter> B' = {}
K \<subseteq> A
card K = k
B' \<subseteq> I - A
card B' = n - k
K \<union> B' = B
A \<subseteq> I
finite I
k \<le> n
n \<le> card I
k \<le> card A

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

goal (1 subgoal):
 1. card (A \<inter> B) = k
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. card (A \<inter> B) = k
[PROOF STEP]
have "A \<inter> B = K"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<inter> B = K
[PROOF STEP]
using K assms(1)
[PROOF STATE]
proof (prove)
using this:
K \<subseteq> A
card K = k
B' \<subseteq> I - A
card B' = n - k
K \<union> B' = B
A \<subseteq> I

goal (1 subgoal):
 1. A \<inter> B = K
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
A \<inter> B = K

goal (1 subgoal):
 1. card (A \<inter> B) = k
[PROOF STEP]
thus "card (A \<inter> B) = k"
[PROOF STATE]
proof (prove)
using this:
A \<inter> B = K

goal (1 subgoal):
 1. card (A \<inter> B) = k
[PROOF STEP]
using K
[PROOF STATE]
proof (prove)
using this:
A \<inter> B = K
K \<subseteq> A
card K = k
B' \<subseteq> I - A
card B' = n - k
K \<union> B' = B

goal (1 subgoal):
 1. card (A \<inter> B) = k
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
card (A \<inter> B) = k

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
B \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
fix B
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
assume "B \<in> ?lhs"
[PROOF STATE]
proof (state)
this:
B \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
hence B: "B \<subseteq> I" "card B = n" "card (A \<inter> B) = k"
[PROOF STATE]
proof (prove)
using this:
B \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}

goal (1 subgoal):
 1. B \<subseteq> I &&& card B = n &&& card (A \<inter> B) = k
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
B \<subseteq> I
card B = n
card (A \<inter> B) = k

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
let ?K = "A \<inter> B"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
let ?B' = "B - A"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
have "?K \<subseteq> A" "card ?K = k" "?B' \<subseteq> I - A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<inter> B \<subseteq> A &&& card (A \<inter> B) = k &&& B - A \<subseteq> I - A
[PROOF STEP]
using B
[PROOF STATE]
proof (prove)
using this:
B \<subseteq> I
card B = n
card (A \<inter> B) = k

goal (1 subgoal):
 1. A \<inter> B \<subseteq> A &&& card (A \<inter> B) = k &&& B - A \<subseteq> I - A
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A \<inter> B \<subseteq> A
card (A \<inter> B) = k
B - A \<subseteq> I - A

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
A \<inter> B \<subseteq> A
card (A \<inter> B) = k
B - A \<subseteq> I - A

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
have "card ?B' = n - k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (B - A) = n - k
[PROOF STEP]
using B finite_A assms(1)
[PROOF STATE]
proof (prove)
using this:
B \<subseteq> I
card B = n
card (A \<inter> B) = k
finite A
A \<subseteq> I

goal (1 subgoal):
 1. card (B - A) = n - k
[PROOF STEP]
by (metis Int_commute card_Diff_subset_Int finite_Un inf.left_idem le_iff_inf sup_absorb2)
[PROOF STATE]
proof (state)
this:
card (B - A) = n - k

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
A \<inter> B \<subseteq> A
card (A \<inter> B) = k
B - A \<subseteq> I - A
card (B - A) = n - k
[PROOF STEP]
have "(?K, ?B') \<in> ?rhs"
[PROOF STATE]
proof (prove)
using this:
A \<inter> B \<subseteq> A
card (A \<inter> B) = k
B - A \<subseteq> I - A
card (B - A) = n - k

goal (1 subgoal):
 1. (A \<inter> B, B - A) \<in> {K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
(A \<inter> B, B - A) \<in> {K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(A \<inter> B, B - A) \<in> {K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
have "B = ?f (?K, ?B')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. B = (case (A \<inter> B, B - A) of (x, xa) \<Rightarrow> x \<union> xa)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
B = (case (A \<inter> B, B - A) of (x, xa) \<Rightarrow> x \<union> xa)

goal (1 subgoal):
 1. \<And>x. x \<in> {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} \<Longrightarrow> x \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(A \<inter> B, B - A) \<in> {K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}
B = (case (A \<inter> B, B - A) of (x, xa) \<Rightarrow> x \<union> xa)
[PROOF STEP]
show "B \<in> ?f ` ?rhs"
[PROOF STATE]
proof (prove)
using this:
(A \<inter> B, B - A) \<in> {K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}
B = (case (A \<inter> B, B - A) of (x, xa) \<Rightarrow> x \<union> xa)

goal (1 subgoal):
 1. B \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
B \<in> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}

goal (1 subgoal):
 1. bij_betw ?f ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
inj_on (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
(\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
show "bij_betw ?f ?rhs ?lhs"
[PROOF STATE]
proof (prove)
using this:
inj_on (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
(\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}

goal (1 subgoal):
 1. bij_betw (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
unfolding bij_betw_def
[PROOF STATE]
proof (prove)
using this:
inj_on (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})
(\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}

goal (1 subgoal):
 1. inj_on (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) \<and> (\<lambda>(x, y). x \<union> y) ` ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}
[PROOF STEP]
..
[PROOF STATE]
proof (state)
this:
bij_betw (\<lambda>(x, y). x \<union> y) ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = card ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = card ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
have "\<dots> = (\<Sum>K | K \<subseteq> A \<and> card K = k. card {B'. B' \<subseteq> I - A \<and> card B' = n - k})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = (\<Sum>K | K \<subseteq> A \<and> card K = k. card {B'. B' \<subseteq> I - A \<and> card B' = n - k})
[PROOF STEP]
proof (rule card_SigmaI, safe)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. finite {K. K \<subseteq> A \<and> card K = k}
 2. \<And>K. \<lbrakk>K \<subseteq> A; k = card K\<rbrakk> \<Longrightarrow> finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}
[PROOF STEP]
show "finite {K. K \<subseteq> A \<and> card K = k}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite {K. K \<subseteq> A \<and> card K = k}
[PROOF STEP]
by (blast intro: finite_subset[where B = "Pow A"] finite_A)
[PROOF STATE]
proof (state)
this:
finite {K. K \<subseteq> A \<and> card K = k}

goal (1 subgoal):
 1. \<And>K. \<lbrakk>K \<subseteq> A; k = card K\<rbrakk> \<Longrightarrow> finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>K. \<lbrakk>K \<subseteq> A; k = card K\<rbrakk> \<Longrightarrow> finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}
[PROOF STEP]
fix K
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>K. \<lbrakk>K \<subseteq> A; k = card K\<rbrakk> \<Longrightarrow> finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}
[PROOF STEP]
assume "K \<subseteq> A"
[PROOF STATE]
proof (state)
this:
K \<subseteq> A

goal (1 subgoal):
 1. \<And>K. \<lbrakk>K \<subseteq> A; k = card K\<rbrakk> \<Longrightarrow> finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}
[PROOF STEP]
thus "finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}"
[PROOF STATE]
proof (prove)
using this:
K \<subseteq> A

goal (1 subgoal):
 1. finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
K \<subseteq> A
A \<subseteq> I
finite I
k \<le> n
n \<le> card I
k \<le> card A

goal (1 subgoal):
 1. finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
finite {B'. B' \<subseteq> I - A \<and> card B' = n - card K}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
card ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = (\<Sum>K | K \<subseteq> A \<and> card K = k. card {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card ({K. K \<subseteq> A \<and> card K = k} \<times> {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = (\<Sum>K | K \<subseteq> A \<and> card K = k. card {B'. B' \<subseteq> I - A \<and> card B' = n - k})

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
have "\<dots> = card {K. K \<subseteq> A \<and> card K = k} * card {B'. B' \<subseteq> I - A \<and> card B' = n - k}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>K | K \<subseteq> A \<and> card K = k. card {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = card {K. K \<subseteq> A \<and> card K = k} * card {B'. B' \<subseteq> I - A \<and> card B' = n - k}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>K | K \<subseteq> A \<and> card K = k. card {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = card {K. K \<subseteq> A \<and> card K = k} * card {B'. B' \<subseteq> I - A \<and> card B' = n - k}

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>K | K \<subseteq> A \<and> card K = k. card {B'. B' \<subseteq> I - A \<and> card B' = n - k}) = card {K. K \<subseteq> A \<and> card K = k} * card {B'. B' \<subseteq> I - A \<and> card B' = n - k}

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
have "\<dots> = (card A choose k) * (card (I - A) choose (n - k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card {K. K \<subseteq> A \<and> card K = k} * card {B'. B' \<subseteq> I - A \<and> card B' = n - k} = (card A choose k) * (card (I - A) choose (n - k))
[PROOF STEP]
by (simp only: n_subsets[OF finite_A] n_subsets[OF finite_Diff[OF assms(2)]])
[PROOF STATE]
proof (state)
this:
card {K. K \<subseteq> A \<and> card K = k} * card {B'. B' \<subseteq> I - A \<and> card B' = n - k} = (card A choose k) * (card (I - A) choose (n - k))

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card {K. K \<subseteq> A \<and> card K = k} * card {B'. B' \<subseteq> I - A \<and> card B' = n - k} = (card A choose k) * (card (I - A) choose (n - k))

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
have "\<dots> = (card A choose k) * ((card I - card A) choose (n - k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (card A choose k) * (card (I - A) choose (n - k)) = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
by (simp only: card_Diff_subset[OF finite_A assms(1)])
[PROOF STATE]
proof (state)
this:
(card A choose k) * (card (I - A) choose (n - k)) = (card A choose k) * (card I - card A choose (n - k))

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))

goal (1 subgoal):
 1. card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
card {B. B \<subseteq> I \<and> card B = n \<and> card (A \<inter> B) = k} = (card A choose k) * (card I - card A choose (n - k))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma inner_prod_minus_distrib_right:
  fixes u v w :: "('a::conjugatable_field) vec"
  assumes dimu: "u \<in> carrier_vec n" and dimv:"v \<in> carrier_vec n" and dimw: "w \<in> carrier_vec n"
  shows "inner_prod u (v - w) = inner_prod u v - inner_prod u w" (is "?lhs = ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
have dimvw: "v - w \<in> carrier_vec n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. v - w \<in> carrier_vec n
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
u \<in> carrier_vec n
v \<in> carrier_vec n
w \<in> carrier_vec n

goal (1 subgoal):
 1. v - w \<in> carrier_vec n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
v - w \<in> carrier_vec n

goal (1 subgoal):
 1. inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
have dimcu: "conjugate u \<in> carrier_vec n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. conjugate u \<in> carrier_vec n
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
u \<in> carrier_vec n
v \<in> carrier_vec n
w \<in> carrier_vec n

goal (1 subgoal):
 1. conjugate u \<in> carrier_vec n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
conjugate u \<in> carrier_vec n

goal (1 subgoal):
 1. inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
have "(v - w) \<bullet> (conjugate u) = v \<bullet> conjugate u - w \<bullet> conjugate u"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
apply (simp add: comm_scalar_prod[OF dimvw dimcu])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. conjugate u \<bullet> (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
apply (simp add: scalar_prod_minus_distrib[OF dimcu dimv dimw])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. conjugate u \<bullet> v - conjugate u \<bullet> w = inner_prod u v - inner_prod u w
[PROOF STEP]
apply (insert dimv dimw dimcu, simp add: comm_scalar_prod[of _ n])
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
inner_prod u (v - w) = inner_prod u v - inner_prod u w

goal (1 subgoal):
 1. inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
inner_prod u (v - w) = inner_prod u v - inner_prod u w

goal (1 subgoal):
 1. inner_prod u (v - w) = inner_prod u v - inner_prod u w
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
inner_prod u (v - w) = inner_prod u v - inner_prod u w

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma inverse_matrix_code_rings[code_unfold]:
  fixes A::"'a::{euclidean_ring}^'n::{mod_type}^'n::{mod_type}"
  shows "inverse_matrix A = (let d=det A in if is_unit d then Some ((1 div d) *k adjugate A) else None)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inverse_matrix A = (let d = det A in if is_unit d then Some ((1::'a) div d *k adjugate A) else None)
[PROOF STEP]
using invertible_imp_matrix_inv[of A]
[PROOF STATE]
proof (prove)
using this:
invertible A \<Longrightarrow> matrix_inv A = (1::'a) div det A *k adjugate A

goal (1 subgoal):
 1. inverse_matrix A = (let d = det A in if is_unit d then Some ((1::'a) div d *k adjugate A) else None)
[PROOF STEP]
unfolding inverse_matrix_def invertible_iff_is_unit
[PROOF STATE]
proof (prove)
using this:
is_unit (det A) \<Longrightarrow> matrix_inv A = (1::'a) div det A *k adjugate A

goal (1 subgoal):
 1. (if is_unit (det A) then Some (matrix_inv A) else None) = (let d = det A in if is_unit d then Some ((1::'a) div d *k adjugate A) else None)
[PROOF STEP]
by auto


[STATEMENT]
lemma bounded_hyperplane_eq_trivial_0:
  fixes a :: "'a::euclidean_space"
  assumes "a \<noteq> 0"
  shows "bounded {x. a \<bullet> x = 0} \<longleftrightarrow> DIM('a) = 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bounded {x. a \<bullet> x = 0} = (DIM('a) = 1)
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. bounded {x. a \<bullet> x = 0} \<Longrightarrow> DIM('a) = 1
 2. DIM('a) = 1 \<Longrightarrow> bounded {x. a \<bullet> x = 0}
[PROOF STEP]
assume "bounded {x. a \<bullet> x = 0}"
[PROOF STATE]
proof (state)
this:
bounded {x. a \<bullet> x = 0}

goal (2 subgoals):
 1. bounded {x. a \<bullet> x = 0} \<Longrightarrow> DIM('a) = 1
 2. DIM('a) = 1 \<Longrightarrow> bounded {x. a \<bullet> x = 0}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
bounded {x. a \<bullet> x = 0}
[PROOF STEP]
have "aff_dim {x. a \<bullet> x = 0} \<le> 0"
[PROOF STATE]
proof (prove)
using this:
bounded {x. a \<bullet> x = 0}

goal (1 subgoal):
 1. aff_dim {x. a \<bullet> x = 0} \<le> 0
[PROOF STEP]
by (simp add: affine_bounded_eq_lowdim affine_hyperplane)
[PROOF STATE]
proof (state)
this:
aff_dim {x. a \<bullet> x = 0} \<le> 0

goal (2 subgoals):
 1. bounded {x. a \<bullet> x = 0} \<Longrightarrow> DIM('a) = 1
 2. DIM('a) = 1 \<Longrightarrow> bounded {x. a \<bullet> x = 0}
[PROOF STEP]
with assms
[PROOF STATE]
proof (chain)
picking this:
a \<noteq> (0::'a)
aff_dim {x. a \<bullet> x = 0} \<le> 0
[PROOF STEP]
show "DIM('a) = 1"
[PROOF STATE]
proof (prove)
using this:
a \<noteq> (0::'a)
aff_dim {x. a \<bullet> x = 0} \<le> 0

goal (1 subgoal):
 1. DIM('a) = 1
[PROOF STEP]
by (simp add: le_Suc_eq)
[PROOF STATE]
proof (state)
this:
DIM('a) = 1

goal (1 subgoal):
 1. DIM('a) = 1 \<Longrightarrow> bounded {x. a \<bullet> x = 0}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. DIM('a) = 1 \<Longrightarrow> bounded {x. a \<bullet> x = 0}
[PROOF STEP]
assume "DIM('a) = 1"
[PROOF STATE]
proof (state)
this:
DIM('a) = 1

goal (1 subgoal):
 1. DIM('a) = 1 \<Longrightarrow> bounded {x. a \<bullet> x = 0}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
DIM('a) = 1
[PROOF STEP]
show "bounded {x. a \<bullet> x = 0}"
[PROOF STATE]
proof (prove)
using this:
DIM('a) = 1

goal (1 subgoal):
 1. bounded {x. a \<bullet> x = 0}
[PROOF STEP]
by (simp add: affine_bounded_eq_lowdim affine_hyperplane assms)
[PROOF STATE]
proof (state)
this:
bounded {x. a \<bullet> x = 0}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma fermat_theorem:
  fixes p a :: nat
  assumes "prime p" and "\<not> p dvd a"
  shows "[a ^ (p - 1) = 1] (mod p)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. [a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
from assms prime_imp_coprime [of p a]
[PROOF STATE]
proof (chain)
picking this:
prime p
\<not> p dvd a
\<lbrakk>prime p; \<not> p dvd a\<rbrakk> \<Longrightarrow> coprime p a
[PROOF STEP]
have "coprime a p"
[PROOF STATE]
proof (prove)
using this:
prime p
\<not> p dvd a
\<lbrakk>prime p; \<not> p dvd a\<rbrakk> \<Longrightarrow> coprime p a

goal (1 subgoal):
 1. coprime a p
[PROOF STEP]
by (auto simp add: ac_simps)
[PROOF STATE]
proof (state)
this:
coprime a p

goal (1 subgoal):
 1. [a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
coprime a p
[PROOF STEP]
have "[a ^ totient p = 1] (mod p)"
[PROOF STATE]
proof (prove)
using this:
coprime a p

goal (1 subgoal):
 1. [a ^ totient p = 1] (mod p)
[PROOF STEP]
by (rule euler_theorem)
[PROOF STATE]
proof (state)
this:
[a ^ totient p = 1] (mod p)

goal (1 subgoal):
 1. [a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
[a ^ totient p = 1] (mod p)

goal (1 subgoal):
 1. [a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
have "totient p = p - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. totient p = p - 1
[PROOF STEP]
by (rule totient_prime) (rule assms)
[PROOF STATE]
proof (state)
this:
totient p = p - 1

goal (1 subgoal):
 1. [a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
[a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
[a ^ (p - 1) = 1] (mod p)

goal (1 subgoal):
 1. [a ^ (p - 1) = 1] (mod p)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
[a ^ (p - 1) = 1] (mod p)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma ivl_integral_bound:
  fixes f::"real \<Rightarrow> 'a::banach"
  assumes "continuous_on (closed_segment a b) f"
  assumes "\<And>t. t \<in> (closed_segment a b) \<Longrightarrow> norm (f t) \<le> B"
  shows "norm (ivl_integral a b f) \<le> B * abs (b - a)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. norm (ivl_integral a b f) \<le> B * \<bar>b - a\<bar>
[PROOF STEP]
using integral_bound[of a b f B]
    integral_bound[of b a f B]
    assms
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>a \<le> b; continuous_on {a..b} f; \<And>t. t \<in> {a..b} \<Longrightarrow> norm (f t) \<le> B\<rbrakk> \<Longrightarrow> norm (integral {a..b} f) \<le> B * (b - a)
\<lbrakk>b \<le> a; continuous_on {b..a} f; \<And>t. t \<in> {b..a} \<Longrightarrow> norm (f t) \<le> B\<rbrakk> \<Longrightarrow> norm (integral {b..a} f) \<le> B * (a - b)
continuous_on (closed_segment a b) f
?t \<in> closed_segment a b \<Longrightarrow> norm (f ?t) \<le> B

goal (1 subgoal):
 1. norm (ivl_integral a b f) \<le> B * \<bar>b - a\<bar>
[PROOF STEP]
by (auto simp: closed_segment_eq_real_ivl has_ivl_integral_def ivl_integral_def split: if_splits)


[STATEMENT]
lemma lemma2:
  "[| P A n ; P B m ; ! A n. P A n --> P A (Suc n) |]
  ==> ? n . P A n & P B n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>P A n; P B m; \<forall>A n. P A n \<longrightarrow> P A (Suc n)\<rbrakk> \<Longrightarrow> \<exists>n. P A n \<and> P B n
[PROOF STEP]
apply (rule exI[of _ "n+m"], rule)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>P A n; P B m; \<forall>A n. P A n \<longrightarrow> P A (Suc n)\<rbrakk> \<Longrightarrow> P A (n + m)
 2. \<lbrakk>P A n; P B m; \<forall>A n. P A n \<longrightarrow> P A (Suc n)\<rbrakk> \<Longrightarrow> P B (n + m)
[PROOF STEP]
apply(blast intro!: lemma1)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>P A n; P B m; \<forall>A n. P A n \<longrightarrow> P A (Suc n)\<rbrakk> \<Longrightarrow> P B (n + m)
[PROOF STEP]
apply(rule subst[OF add.commute])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>P A n; P B m; \<forall>A n. P A n \<longrightarrow> P A (Suc n)\<rbrakk> \<Longrightarrow> P B (m + n)
[PROOF STEP]
apply(blast intro!: lemma1)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma nn_integral_0_1_ln_times_power:
  "(\<integral>\<^sup>+y\<in>{0<..<1}. ennreal (-ln y * y ^ n) \<partial>lborel) = ennreal (1 / (n + 1)\<^sup>2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / (real n + 1)\<^sup>2)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / (real n + 1)\<^sup>2)
[PROOF STEP]
have "(\<integral>\<^sup>+y\<in>{0<..<1}. ennreal (-ln y * y ^ n) \<partial>lborel) =
          (\<integral>\<^sup>+y\<in>{0<..<1}. ennreal (-ln y * y powr real n) \<partial>lborel)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x powr real n)\<partial>lborel
[PROOF STEP]
by (intro set_nn_integral_cong) (auto simp: powr_realpow)
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x powr real n)\<partial>lborel

goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / (real n + 1)\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x powr real n)\<partial>lborel

goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / (real n + 1)\<^sup>2)
[PROOF STEP]
have "\<dots> = ennreal (1 / (n + 1)^2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x powr real n)\<partial>lborel = ennreal (1 / real ((n + 1)\<^sup>2))
[PROOF STEP]
by (subst nn_integral_0_1_ln_times_powr) auto
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x powr real n)\<partial>lborel = ennreal (1 / real ((n + 1)\<^sup>2))

goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / (real n + 1)\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
\<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / real ((n + 1)\<^sup>2))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / real ((n + 1)\<^sup>2))

goal (1 subgoal):
 1. \<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / (real n + 1)\<^sup>2)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+x\<in>{0<..<1}. ennreal (- ln x * x ^ n)\<partial>lborel = ennreal (1 / (real n + 1)\<^sup>2)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma x_times_x_minus_1_nonneg: "x \<le> 0 \<or> x \<ge> 1 \<Longrightarrow> (x::_::linordered_idom) * (x - 1) \<ge> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<le> (0::'a) \<or> (1::'a) \<le> x \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
[PROOF STEP]
proof (elim disjE)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. x \<le> (0::'a) \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
 2. (1::'a) \<le> x \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
[PROOF STEP]
assume x: "x \<le> 0"
[PROOF STATE]
proof (state)
this:
x \<le> (0::'a)

goal (2 subgoals):
 1. x \<le> (0::'a) \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
 2. (1::'a) \<le> x \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
x \<le> (0::'a)

goal (2 subgoals):
 1. x \<le> (0::'a) \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
 2. (1::'a) \<le> x \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
[PROOF STEP]
have "0 \<le> x^2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0::'a) \<le> x\<^sup>2
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(0::'a) \<le> x\<^sup>2

goal (2 subgoals):
 1. x \<le> (0::'a) \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
 2. (1::'a) \<le> x \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
x \<le> x\<^sup>2
[PROOF STEP]
show "x * (x - 1) \<ge> 0"
[PROOF STATE]
proof (prove)
using this:
x \<le> x\<^sup>2

goal (1 subgoal):
 1. (0::'a) \<le> x * (x - (1::'a))
[PROOF STEP]
by (simp add: power2_eq_square algebra_simps)
[PROOF STATE]
proof (state)
this:
(0::'a) \<le> x * (x - (1::'a))

goal (1 subgoal):
 1. (1::'a) \<le> x \<Longrightarrow> (0::'a) \<le> x * (x - (1::'a))
[PROOF STEP]
qed simp


[STATEMENT]
lemma crb_lem_pos:
  fixes x:: "real"
  fixes p:: "real poly"
  assumes x: "poly p x = 0"
  assumes p: "p \<noteq> 0"
  shows "x < crb p"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x < real_of_int (crb p)
[PROOF STEP]
using cauchy_root_bound[of p x]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>poly p x = 0; p \<noteq> 0\<rbrakk> \<Longrightarrow> norm x \<le> 1 + max_list_non_empty (map (\<lambda>i. norm (coeff p i)) [0..<degree p]) / norm (lead_coeff p)

goal (1 subgoal):
 1. x < real_of_int (crb p)
[PROOF STEP]
apply (auto)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lbrakk>poly p x = 0; p \<noteq> 0\<rbrakk> \<Longrightarrow> \<bar>x\<bar> \<le> 1 + max_list_non_empty (map (\<lambda>i. \<bar>coeff p i\<bar>) [0..<degree p]) / \<bar>lead_coeff p\<bar>) \<Longrightarrow> x < real_of_int (crb p)
[PROOF STEP]
unfolding crb_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lbrakk>poly p x = 0; p \<noteq> 0\<rbrakk> \<Longrightarrow> \<bar>x\<bar> \<le> 1 + max_list_non_empty (map (\<lambda>i. \<bar>coeff p i\<bar>) [0..<degree p]) / \<bar>lead_coeff p\<bar>) \<Longrightarrow> x < real_of_int \<lceil>2 + max_list_non_empty (map (\<lambda>i. norm (coeff p i)) [0..<degree p]) / norm (lead_coeff p)\<rceil>
[PROOF STEP]
apply (auto)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lbrakk>poly p x = 0; p \<noteq> 0\<rbrakk> \<Longrightarrow> \<bar>x\<bar> \<le> 1 + max_list_non_empty (map (\<lambda>i. \<bar>coeff p i\<bar>) [0..<degree p]) / \<bar>lead_coeff p\<bar>) \<Longrightarrow> x < real_of_int \<lceil>2 + max_list_non_empty (map (\<lambda>i. \<bar>coeff p i\<bar>) [0..<degree p]) / \<bar>lead_coeff p\<bar>\<rceil>
[PROOF STEP]
using p x
[PROOF STATE]
proof (prove)
using this:
p \<noteq> 0
poly p x = 0

goal (1 subgoal):
 1. (\<lbrakk>poly p x = 0; p \<noteq> 0\<rbrakk> \<Longrightarrow> \<bar>x\<bar> \<le> 1 + max_list_non_empty (map (\<lambda>i. \<bar>coeff p i\<bar>) [0..<degree p]) / \<bar>lead_coeff p\<bar>) \<Longrightarrow> x < real_of_int \<lceil>2 + max_list_non_empty (map (\<lambda>i. \<bar>coeff p i\<bar>) [0..<degree p]) / \<bar>lead_coeff p\<bar>\<rceil>
[PROOF STEP]
by linarith


[STATEMENT]
lemma mems_le_finite:
  fixes s :: "nat set" and k :: nat
  shows "\<And>(s :: nat set) k. (\<forall> x. x \<in> s \<longrightarrow> x \<le> k) \<Longrightarrow> finite s"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>s k. \<forall>x. x \<in> s \<longrightarrow> x \<le> k \<Longrightarrow> finite s
[PROOF STEP]
using mems_le_finite_i
[PROOF STATE]
proof (prove)
using this:
\<forall>x. x \<in> ?s \<longrightarrow> x \<le> ?k \<Longrightarrow> finite ?s

goal (1 subgoal):
 1. \<And>s k. \<forall>x. x \<in> s \<longrightarrow> x \<le> k \<Longrightarrow> finite s
[PROOF STEP]
by auto

\<comment> \<open>NOTE translated `s` to `nat set` (more generality wasn't required.).\<close>


[STATEMENT]
lemma tendsto_of_int_floor:
  fixes f::"'a \<Rightarrow> 'b::{order_topology,floor_ceiling}"
  assumes "(f \<longlongrightarrow> l) F"
    and "l \<notin> \<int>"
  shows "((\<lambda>x. of_int (floor (f x)) :: 'c::{ring_1,topological_space}) \<longlongrightarrow> of_int (floor l)) F"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. of_int \<lfloor>f x\<rfloor>) \<longlongrightarrow> of_int \<lfloor>l\<rfloor>) F
[PROOF STEP]
using eventually_floor_eq[OF assms]
[PROOF STATE]
proof (prove)
using this:
\<forall>\<^sub>F x in F. \<lfloor>f x\<rfloor> = \<lfloor>l\<rfloor>

goal (1 subgoal):
 1. ((\<lambda>x. of_int \<lfloor>f x\<rfloor>) \<longlongrightarrow> of_int \<lfloor>l\<rfloor>) F
[PROOF STEP]
by (simp add: eventually_mono topological_tendstoI)


[STATEMENT]
lemma ceiling_log_nat_eq_powr_iff: fixes b n k :: nat
  shows "\<lbrakk> b \<ge> 2; k > 0 \<rbrakk> \<Longrightarrow>
  ceiling (log b (real k)) = int n + 1 \<longleftrightarrow> (b^n < k \<and> k \<le> b^(n+1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>2 \<le> b; 0 < k\<rbrakk> \<Longrightarrow> (\<lceil>log (real b) (real k)\<rceil> = int n + 1) = (b ^ n < k \<and> k \<le> b ^ (n + 1))
[PROOF STEP]
using ceiling_log_eq_powr_iff
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>0 < ?x; 1 < ?b\<rbrakk> \<Longrightarrow> (\<lceil>log ?b ?x\<rceil> = int ?k + 1) = (?b powr real ?k < ?x \<and> ?x \<le> ?b powr real (?k + 1))

goal (1 subgoal):
 1. \<lbrakk>2 \<le> b; 0 < k\<rbrakk> \<Longrightarrow> (\<lceil>log (real b) (real k)\<rceil> = int n + 1) = (b ^ n < k \<and> k \<le> b ^ (n + 1))
[PROOF STEP]
by (auto simp: powr_add powr_realpow of_nat_power[symmetric] of_nat_mult[symmetric] ac_simps
         simp del: of_nat_power of_nat_mult)


[STATEMENT]
theorem FreeGroup_universal_property:
  fixes f :: "'a \<Rightarrow> 'b::group_add"
  shows "\<exists>!T::'a freeword\<Rightarrow>'b. (\<forall>s\<in>S. T (Abs_freeletter s) = f s) \<and>
          GroupHom (FreeGroup S) T"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>!T. (\<forall>s\<in>S. T (Abs_freeletter s) = f s) \<and> GroupHom (FreeGroup S) T
[PROOF STEP]
proof (rule ex1I, rule conjI)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<forall>s\<in>S. ?a (Abs_freeletter s) = f s
 2. GroupHom (FreeGroup S) ?a
 3. \<And>T. (\<forall>s\<in>S. T (Abs_freeletter s) = f s) \<and> GroupHom (FreeGroup S) T \<Longrightarrow> T = ?a
[PROOF STEP]
show "\<forall>s\<in>S. res_freeword_funlift f S (Abs_freeletter s) = f s"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>s\<in>S. res_freeword_funlift f S (Abs_freeletter s) = f s
[PROOF STEP]
using Abs_freeletter_in_FreeGroup_iff[of _ S] freeword_funlift_Abs_freeletter
[PROOF STATE]
proof (prove)
using this:
(Abs_freeletter ?s \<in> FreeGroup S) = (?s \<in> S)
freeword_funlift ?f (Abs_freeletter ?s) = ?f ?s

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

goal (2 subgoals):
 1. GroupHom (FreeGroup S) (res_freeword_funlift f S)
 2. \<And>T. (\<forall>s\<in>S. T (Abs_freeletter s) = f s) \<and> GroupHom (FreeGroup S) T \<Longrightarrow> T = res_freeword_funlift f S
[PROOF STEP]
show "\<And>T. (\<forall>s\<in>S. T (Abs_freeletter s) = f s) \<and>
          GroupHom (FreeGroup S) T \<Longrightarrow>
          T = restrict0 (freeword_funlift f) (FreeGroup S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>T. (\<forall>s\<in>S. T (Abs_freeletter s) = f s) \<and> GroupHom (FreeGroup S) T \<Longrightarrow> T = res_freeword_funlift f S
[PROOF STEP]
using uniqueness_of_restricted_lift
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>GroupHom (FreeGroup ?S) ?T; \<forall>s\<in>?S. ?T (Abs_freeletter s) = ?f s\<rbrakk> \<Longrightarrow> ?T = res_freeword_funlift ?f ?S

goal (1 subgoal):
 1. \<And>T. (\<forall>s\<in>S. T (Abs_freeletter s) = f s) \<and> GroupHom (FreeGroup S) T \<Longrightarrow> T = res_freeword_funlift f S
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<forall>s\<in>S. ?T (Abs_freeletter s) = f s) \<and> GroupHom (FreeGroup S) ?T \<Longrightarrow> ?T = res_freeword_funlift f S

goal (1 subgoal):
 1. GroupHom (FreeGroup S) (res_freeword_funlift f S)
[PROOF STEP]
qed (rule hom_restrict0_freeword_funlift)


[STATEMENT]
lemma has_vector_derivative_scaleR[derivative_intros]:
  "(f has_field_derivative f') (at x within s) \<Longrightarrow> (g has_vector_derivative g') (at x within s) \<Longrightarrow>
    ((\<lambda>x. f x *\<^sub>R g x) has_vector_derivative (f x *\<^sub>R g' + f' *\<^sub>R g x)) (at x within s)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>(f has_real_derivative f') (at x within s); (g has_vector_derivative g') (at x within s)\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x *\<^sub>R g x) has_vector_derivative f x *\<^sub>R g' + f' *\<^sub>R g x) (at x within s)
[PROOF STEP]
unfolding has_real_derivative_iff_has_vector_derivative
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>(f has_vector_derivative f') (at x within s); (g has_vector_derivative g') (at x within s)\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x *\<^sub>R g x) has_vector_derivative f x *\<^sub>R g' + f' *\<^sub>R g x) (at x within s)
[PROOF STEP]
by (rule bounded_bilinear.has_vector_derivative[OF bounded_bilinear_scaleR])


[STATEMENT]
lemma card_eq_1_singleton:
  assumes "card A = 1"
  obtains x where "A = {x}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>x. A = {x} \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using assms[simplified]
[PROOF STATE]
proof (prove)
using this:
card A = Suc 0

goal (1 subgoal):
 1. (\<And>x. A = {x} \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by - (drule card_eq_SucD, auto)


[STATEMENT]
theorem effective_matrix_Tensor_elements2:
 fixes M1 M2
 assumes "mat (row_length M1) (length M1) M1"
     and "mat (row_length M2) (length M2) M2"
 shows
  "(\<forall>i <((row_length M1)*(row_length M2)).
    \<forall>j < ((length M1)*(length M2))
       .((M1 \<otimes> M2)!j!i) = f (M1!(j div (length M2))!(i div (row_length M2)))
                             (M2!(j mod length M2)!(i mod (row_length M2))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>i<row_length M1 * row_length M2. \<forall>j<length M1 * length M2. (M1 \<otimes> M2) ! j ! i = M1 ! (j div length M2) ! (i div row_length M2) * M2 ! (j mod length M2) ! (i mod row_length M2)
[PROOF STEP]
using matrix_Tensor_elements assms
[PROOF STATE]
proof (prove)
using this:
\<forall>i j. (i < row_length ?M1.0 * row_length ?M2.0 \<and> j < length ?M1.0 * length ?M2.0) \<and> mat (row_length ?M1.0) (length ?M1.0) ?M1.0 \<and> mat (row_length ?M2.0) (length ?M2.0) ?M2.0 \<longrightarrow> (?M1.0 \<otimes> ?M2.0) ! j ! i = ?M1.0 ! (j div length ?M2.0) ! (i div row_length ?M2.0) * ?M2.0 ! (j mod length ?M2.0) ! (i mod row_length ?M2.0)
mat (row_length M1) (length M1) M1
mat (row_length M2) (length M2) M2

goal (1 subgoal):
 1. \<forall>i<row_length M1 * row_length M2. \<forall>j<length M1 * length M2. (M1 \<otimes> M2) ! j ! i = M1 ! (j div length M2) ! (i div row_length M2) * M2 ! (j mod length M2) ! (i mod row_length M2)
[PROOF STEP]
by auto


[STATEMENT]
lemma SA_nat_pow_closed:
  assumes "is_semialg_function n f"
  shows "f [^]\<^bsub>SA n\<^esub> (k::nat) \<in> carrier (SA n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f [^]\<^bsub>SA n\<^esub> k \<in> carrier (SA n)
[PROOF STEP]
apply(induction k)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. f [^]\<^bsub>SA n\<^esub> 0 \<in> carrier (SA n)
 2. \<And>k. f [^]\<^bsub>SA n\<^esub> k \<in> carrier (SA n) \<Longrightarrow> f [^]\<^bsub>SA n\<^esub> Suc k \<in> carrier (SA n)
[PROOF STEP]
using nat_pow_def[of "SA n" f ]
[PROOF STATE]
proof (prove)
using this:
f [^]\<^bsub>SA n\<^esub> ?n = rec_nat \<one>\<^bsub>SA n\<^esub> (\<lambda>u b. b \<otimes>\<^bsub>SA n\<^esub> f) ?n

goal (2 subgoals):
 1. f [^]\<^bsub>SA n\<^esub> 0 \<in> carrier (SA n)
 2. \<And>k. f [^]\<^bsub>SA n\<^esub> k \<in> carrier (SA n) \<Longrightarrow> f [^]\<^bsub>SA n\<^esub> Suc k \<in> carrier (SA n)
[PROOF STEP]
apply (metis Group.nat_pow_0  monoid.one_closed SA_is_monoid)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. f [^]\<^bsub>SA n\<^esub> k \<in> carrier (SA n) \<Longrightarrow> f [^]\<^bsub>SA n\<^esub> Suc k \<in> carrier (SA n)
[PROOF STEP]
by (metis Group.nat_pow_Suc SA_car assms(1) assms SA_mult_closed semialg_functions_memE(1))


[STATEMENT]
lemma card_lists_distinct_length_eq:
  assumes "finite A" "k \<le> card A"
  shows "card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1 .. card A}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
finite A
k \<le> card A

goal (1 subgoal):
 1. card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}
[PROOF STEP]
proof (induct k)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>finite A; 0 \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - 0 + 1..card A}
 2. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:
finite A
0 \<le> card A

goal (2 subgoals):
 1. \<lbrakk>finite A; 0 \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - 0 + 1..card A}
 2. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
finite A
0 \<le> card A
[PROOF STEP]
have "{xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = {[]}"
[PROOF STATE]
proof (prove)
using this:
finite A
0 \<le> card A

goal (1 subgoal):
 1. {xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = {[]}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
{xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = {[]}

goal (2 subgoals):
 1. \<lbrakk>finite A; 0 \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - 0 + 1..card A}
 2. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
{xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = {[]}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
{xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = {[]}

goal (1 subgoal):
 1. card {xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - 0 + 1..card A}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
card {xs. length xs = 0 \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - 0 + 1..card A}

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
case (Suc k)
[PROOF STATE]
proof (state)
this:
\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}
finite A
Suc k \<le> card A

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
let "?k_list" = "\<lambda>k xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
have inj_Cons: "\<And>A. inj_on (\<lambda>(xs, n). n # xs) A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>A. inj_on (\<lambda>(xs, n). n # xs) A
[PROOF STEP]
by (rule inj_onI) auto
[PROOF STATE]
proof (state)
this:
inj_on (\<lambda>(xs, n). n # xs) ?A

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
from Suc
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}
finite A
Suc k \<le> card A
[PROOF STEP]
have "k \<le> card A"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}
finite A
Suc k \<le> card A

goal (1 subgoal):
 1. k \<le> card A
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
k \<le> card A

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
k \<le> card A

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
note \<open>finite A\<close>
[PROOF STATE]
proof (state)
this:
finite A

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
finite A

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
have "finite {xs. ?k_list k xs}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}
[PROOF STEP]
by (rule finite_subset) (use finite_lists_length_eq[OF \<open>finite A\<close>, of k] in auto)
[PROOF STATE]
proof (state)
this:
finite {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
finite {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
have "\<And>i j. i \<noteq> j \<longrightarrow> {i} \<times> (A - set i) \<inter> {j} \<times> (A - set j) = {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>i j. i \<noteq> j \<longrightarrow> {i} \<times> (A - set i) \<inter> {j} \<times> (A - set j) = {}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?i1 \<noteq> ?j1 \<longrightarrow> {?i1} \<times> (A - set ?i1) \<inter> {?j1} \<times> (A - set ?j1) = {}

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
?i1 \<noteq> ?j1 \<longrightarrow> {?i1} \<times> (A - set ?i1) \<inter> {?j1} \<times> (A - set ?j1) = {}

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
have "\<And>i. i \<in> {xs. ?k_list k xs} \<Longrightarrow> card (A - set i) = card A - k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>i. i \<in> {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} \<Longrightarrow> card (A - set i) = card A - k
[PROOF STEP]
by (simp add: card_Diff_subset distinct_card)
[PROOF STATE]
proof (state)
this:
?i1 \<in> {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} \<Longrightarrow> card (A - set ?i1) = card A - k

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
?i1 \<in> {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} \<Longrightarrow> card (A - set ?i1) = card A - k

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
have "{xs. ?k_list (Suc k) xs} =
      (\<lambda>(xs, n). n#xs) ` \<Union>((\<lambda>xs. {xs} \<times> (A - set xs)) ` {xs. ?k_list k xs})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = (\<lambda>(xs, n). n # xs) ` (\<Union>xs\<in>{xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}. {xs} \<times> (A - set xs))
[PROOF STEP]
by (auto simp: length_Suc_conv)
[PROOF STATE]
proof (state)
this:
{xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = (\<lambda>(xs, n). n # xs) ` (\<Union>xs\<in>{xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}. {xs} \<times> (A - set xs))

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
{xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = (\<lambda>(xs, n). n # xs) ` (\<Union>xs\<in>{xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}. {xs} \<times> (A - set xs))

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
have "Suc (card A - Suc k) = card A - k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Suc (card A - Suc k) = card A - k
[PROOF STEP]
using Suc.prems
[PROOF STATE]
proof (prove)
using this:
finite A
Suc k \<le> card A

goal (1 subgoal):
 1. Suc (card A - Suc k) = card A - k
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Suc (card A - Suc k) = card A - k

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
Suc (card A - Suc k) = card A - k
[PROOF STEP]
have "(card A - k) * \<Prod>{Suc (card A - k)..card A} = \<Prod>{Suc (card A - Suc k)..card A}"
[PROOF STATE]
proof (prove)
using this:
Suc (card A - Suc k) = card A - k

goal (1 subgoal):
 1. (card A - k) * \<Prod>{Suc (card A - k)..card A} = \<Prod>{Suc (card A - Suc k)..card A}
[PROOF STEP]
by (subst prod.insert[symmetric]) (simp add: atLeastAtMost_insertL)+
[PROOF STATE]
proof (state)
this:
(card A - k) * \<Prod>{Suc (card A - k)..card A} = \<Prod>{Suc (card A - Suc k)..card A}

goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<lbrakk>finite A; k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - k + 1..card A}; finite A; Suc k \<le> card A\<rbrakk> \<Longrightarrow> card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
k \<le> card A
finite A
finite {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}
?i1 \<noteq> ?j1 \<longrightarrow> {?i1} \<times> (A - set ?i1) \<inter> {?j1} \<times> (A - set ?j1) = {}
?i1 \<in> {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} \<Longrightarrow> card (A - set ?i1) = card A - k
{xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = (\<lambda>(xs, n). n # xs) ` (\<Union>xs\<in>{xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}. {xs} \<times> (A - set xs))
(card A - k) * \<Prod>{Suc (card A - k)..card A} = \<Prod>{Suc (card A - Suc k)..card A}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
k \<le> card A
finite A
finite {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}
?i1 \<noteq> ?j1 \<longrightarrow> {?i1} \<times> (A - set ?i1) \<inter> {?j1} \<times> (A - set ?j1) = {}
?i1 \<in> {xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A} \<Longrightarrow> card (A - set ?i1) = card A - k
{xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = (\<lambda>(xs, n). n # xs) ` (\<Union>xs\<in>{xs. length xs = k \<and> distinct xs \<and> set xs \<subseteq> A}. {xs} \<times> (A - set xs))
(card A - k) * \<Prod>{Suc (card A - k)..card A} = \<Prod>{Suc (card A - Suc k)..card A}

goal (1 subgoal):
 1. card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}
[PROOF STEP]
by (simp add: card_image inj_Cons card_UN_disjoint Suc.hyps algebra_simps)
[PROOF STATE]
proof (state)
this:
card {xs. length xs = Suc k \<and> distinct xs \<and> set xs \<subseteq> A} = \<Prod>{card A - Suc k + 1..card A}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma set_rel_alt: "\<langle>R\<rangle>set_rel = {(A,B). A \<subseteq> R\<inverse>``B \<and> B \<subseteq> R``A}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<langle>R\<rangle>set_rel = {(A, B). A \<subseteq> R\<inverse> `` B \<and> B \<subseteq> R `` A}
[PROOF STEP]
unfolding set_rel_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {(A, B). (\<forall>x\<in>A. \<exists>y\<in>B. (x, y) \<in> R) \<and> (\<forall>y\<in>B. \<exists>x\<in>A. (x, y) \<in> R)} = {(A, B). A \<subseteq> R\<inverse> `` B \<and> B \<subseteq> R `` A}
[PROOF STEP]
by auto


[STATEMENT]
lemma index_component_mult:
assumes "i < dim_vec v" "i < dim_vec w"
shows "component_mult v w $ i = v $ i * w $ i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. component_mult v w $ i = v $ i * w $ i
[PROOF STEP]
unfolding component_mult_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. vec (min (dim_vec v) (dim_vec w)) (\<lambda>i. v $ i * w $ i) $ i = v $ i * w $ i
[PROOF STEP]
using assms index_vec
[PROOF STATE]
proof (prove)
using this:
i < dim_vec v
i < dim_vec w
?i < ?n \<Longrightarrow> vec ?n ?f $ ?i = ?f ?i

goal (1 subgoal):
 1. vec (min (dim_vec v) (dim_vec w)) (\<lambda>i. v $ i * w $ i) $ i = v $ i * w $ i
[PROOF STEP]
by auto


[STATEMENT]
lemma filterlim_at_bot_linear_iff:
  fixes f::"'a::linordered_field \<Rightarrow> 'b"
  assumes "c\<noteq>0"
  shows "(LIM x at_bot. f (x * c + b) :> F2) \<longleftrightarrow> (if c>0 then (LIM x at_bot. f x :> F2)
            else (LIM x at_top. f x :> F2)) "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (LIM x at_bot. f (x * c + b) :> F2) = (if (0::'a) < c then filterlim f F2 at_bot else filterlim f F2 at_top)
[PROOF STEP]
unfolding filterlim_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (filtermap (\<lambda>x. f (x * c + b)) at_bot \<le> F2) = (if (0::'a) < c then filtermap f at_bot \<le> F2 else filtermap f at_top \<le> F2)
[PROOF STEP]
apply (subst filtermap_filtermap[of f "\<lambda>x. x * c + b",symmetric])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (filtermap f (filtermap (\<lambda>x. x * c + b) at_bot) \<le> F2) = (if (0::'a) < c then filtermap f at_bot \<le> F2 else filtermap f at_top \<le> F2)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
c \<noteq> (0::'a)

goal (1 subgoal):
 1. (filtermap f (filtermap (\<lambda>x. x * c + b) at_bot) \<le> F2) = (if (0::'a) < c then filtermap f at_bot \<le> F2 else filtermap f at_top \<le> F2)
[PROOF STEP]
by (auto simp add:filtermap_at_bot_linear_eq)


[STATEMENT]
lemma matrix_mult_index:
 assumes "m1 \<noteq> []"
  and  wf1: "mat nr n m1"
  and wf2: "mat n nc m2"
    and i: "i < nr"
    and j: "j < nc"
 shows  "matrix_mult  m1 m2 ! j ! i = scalar_product  (row m1 i) (col m2 j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (m1 \<circ> m2) ! j ! i = scalar_product (row m1 i) (col m2 j)
[PROOF STEP]
using matrix_index unique_row_col assms
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>mat (row_length ?m1.0) ?n ?m1.0; mat ?n ?nc ?m2.0; ?i < row_length ?m1.0; ?j < ?nc\<rbrakk> \<Longrightarrow> (?m1.0 \<circ> ?m2.0) ! ?j ! ?i = scalar_product (row ?m1.0 ?i) (col ?m2.0 ?j)
\<lbrakk>mat ?nr1.0 ?nc1.0 ?M; mat ?nr2.0 ?nc2.0 ?M; ?M \<noteq> []\<rbrakk> \<Longrightarrow> ?nr1.0 = ?nr2.0
\<lbrakk>mat ?nr1.0 ?nc1.0 ?M; mat ?nr2.0 ?nc2.0 ?M; ?M \<noteq> []\<rbrakk> \<Longrightarrow> ?nc1.0 = ?nc2.0
m1 \<noteq> []
mat nr n m1
mat n nc m2
i < nr
j < nc

goal (1 subgoal):
 1. (m1 \<circ> m2) ! j ! i = scalar_product (row m1 i) (col m2 j)
[PROOF STEP]
by (metis matrix_row_length)


[STATEMENT]
lemma subgroup_inter:
  assumes "subgroup A" and "subgroup B"
  shows "subgroup (A \<inter> B)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. subgroup (A \<inter> B)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
subgroup A
subgroup B

goal (1 subgoal):
 1. subgroup (A \<inter> B)
[PROOF STEP]
unfolding subgroup_def
[PROOF STATE]
proof (prove)
using this:
(0::'a) \<in> A \<and> (\<forall>a\<in>A. \<forall>b\<in>A. a + b \<in> A) \<and> (\<forall>a\<in>A. - a \<in> A)
(0::'a) \<in> B \<and> (\<forall>a\<in>B. \<forall>b\<in>B. a + b \<in> B) \<and> (\<forall>a\<in>B. - a \<in> B)

goal (1 subgoal):
 1. (0::'a) \<in> A \<inter> B \<and> (\<forall>a\<in>A \<inter> B. \<forall>b\<in>A \<inter> B. a + b \<in> A \<inter> B) \<and> (\<forall>a\<in>A \<inter> B. - a \<in> A \<inter> B)
[PROOF STEP]
by blast


[STATEMENT]
lemma rank_argument:
  fixes M :: "('c :: {conjugatable_ordered_field}) mat"
  assumes "M \<in> carrier_mat x y"
  assumes "vec_space.rank x (M* M\<^sup>T) = x"
  shows "x \<le> y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
let ?B = "(M * M\<^sup>T)"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
have Mt_car: "M\<^sup>T \<in> carrier_mat y x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. M\<^sup>T \<in> carrier_mat y x
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
M \<in> carrier_mat x y
rank x (M * M\<^sup>T) = x

goal (1 subgoal):
 1. M\<^sup>T \<in> carrier_mat y x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
M\<^sup>T \<in> carrier_mat y x

goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
have b_car: "?B \<in> carrier_mat x x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. M * M\<^sup>T \<in> carrier_mat x x
[PROOF STEP]
using transpose_carrier_mat assms
[PROOF STATE]
proof (prove)
using this:
(?A\<^sup>T \<in> carrier_mat ?nc ?nr) = (?A \<in> carrier_mat ?nr ?nc)
M \<in> carrier_mat x y
rank x (M * M\<^sup>T) = x

goal (1 subgoal):
 1. M * M\<^sup>T \<in> carrier_mat x x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
M * M\<^sup>T \<in> carrier_mat x x

goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
M * M\<^sup>T \<in> carrier_mat x x
[PROOF STEP]
have "rank x ?B \<le> min (rank x M) (rank y M\<^sup>T)"
[PROOF STATE]
proof (prove)
using this:
M * M\<^sup>T \<in> carrier_mat x x

goal (1 subgoal):
 1. rank x (M * M\<^sup>T) \<le> min (rank x M) (rank y M\<^sup>T)
[PROOF STEP]
using rank_mat_mult_lt_min_rank_factor Mt_car b_car assms(1)
[PROOF STATE]
proof (prove)
using this:
M * M\<^sup>T \<in> carrier_mat x x
\<lbrakk>?A \<in> carrier_mat ?n ?m; ?B \<in> carrier_mat ?m ?nc\<rbrakk> \<Longrightarrow> rank ?n (?A * ?B) \<le> min (rank ?n ?A) (rank ?m ?B)
M\<^sup>T \<in> carrier_mat y x
M * M\<^sup>T \<in> carrier_mat x x
M \<in> carrier_mat x y

goal (1 subgoal):
 1. rank x (M * M\<^sup>T) \<le> min (rank x M) (rank y M\<^sup>T)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
rank x (M * M\<^sup>T) \<le> min (rank x M) (rank y M\<^sup>T)

goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
rank x (M * M\<^sup>T) \<le> min (rank x M) (rank y M\<^sup>T)

goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
using le_trans vec_space.rank_le_nc
[PROOF STATE]
proof (prove)
using this:
rank x (M * M\<^sup>T) \<le> min (rank x M) (rank y M\<^sup>T)
\<lbrakk>?i \<le> ?j; ?j \<le> ?k\<rbrakk> \<Longrightarrow> ?i \<le> ?k
?A \<in> carrier_mat ?n ?nc \<Longrightarrow> rank ?n ?A \<le> ?nc

goal (1 subgoal):
 1. x \<le> y
[PROOF STEP]
by (metis assms(1) assms(2) min.bounded_iff)
[PROOF STATE]
proof (state)
this:
x \<le> y

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma metric_bound_lemma: "cmod (x - y) \<le> \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cmod (x - y) \<le> \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>
[PROOF STEP]
using real_sqrt_sum_squares_triangle_ineq[of "Re x - Re y" 0 0 "Im x - Im y"]
[PROOF STATE]
proof (prove)
using this:
sqrt ((Re x - Re y + 0)\<^sup>2 + (0 + (Im x - Im y))\<^sup>2) \<le> sqrt ((Re x - Re y)\<^sup>2 + 0\<^sup>2) + sqrt (0\<^sup>2 + (Im x - Im y)\<^sup>2)

goal (1 subgoal):
 1. cmod (x - y) \<le> \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>
[PROOF STEP]
unfolding cmod_def
[PROOF STATE]
proof (prove)
using this:
sqrt ((Re x - Re y + 0)\<^sup>2 + (0 + (Im x - Im y))\<^sup>2) \<le> sqrt ((Re x - Re y)\<^sup>2 + 0\<^sup>2) + sqrt (0\<^sup>2 + (Im x - Im y)\<^sup>2)

goal (1 subgoal):
 1. sqrt ((Re (x - y))\<^sup>2 + (Im (x - y))\<^sup>2) \<le> \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>
[PROOF STEP]
by simp


[STATEMENT]
lemma Ilsm_Ilam: "$(I^{l}s)^{m}_n = (1+i)^n * $(I^{l}a)^{m}_n"
  if "l \<noteq> 0" "m \<noteq> 0" for l n m :: nat
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. $(I^{l}s)^{m}_n = (1 + i) ^ n * $(I^{l}a)^{m}_n
[PROOF STEP]
unfolding acc_incr_def ann_incr_def v_pres_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n * m. (1 + i) .^ (real n - real (k + 1) / real m) * real_of_int \<lceil>real (l * (k + 1)) / real m\<rceil> / (real l * real m)) = (1 + i) ^ n * (\<Sum>k<n * m. (1 / (1 + i)) .^ (real (k + 1) / real m) * real_of_int \<lceil>real (l * (k + 1)) / real m\<rceil> / (real l * real m))
[PROOF STEP]
using v_futr_pos powr_realpow
[PROOF STATE]
proof (prove)
using this:
0 < 1 + i
0 < ?x \<Longrightarrow> ?x .^ real ?n = ?x ^ ?n

goal (1 subgoal):
 1. (\<Sum>k<n * m. (1 + i) .^ (real n - real (k + 1) / real m) * real_of_int \<lceil>real (l * (k + 1)) / real m\<rceil> / (real l * real m)) = (1 + i) ^ n * (\<Sum>k<n * m. (1 / (1 + i)) .^ (real (k + 1) / real m) * real_of_int \<lceil>real (l * (k + 1)) / real m\<rceil> / (real l * real m))
[PROOF STEP]
apply (subst inverse_powr, simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < 1 + i; \<And>x n. 0 < x \<Longrightarrow> x .^ real n = x ^ n\<rbrakk> \<Longrightarrow> (\<Sum>k<n * m. (1 + i) .^ (real n - real (k + 1) / real m) * real_of_int \<lceil>real (l * (k + 1)) / real m\<rceil> / (real l * real m)) = (1 + i) ^ n * (\<Sum>k<n * m. (1 + i) .^ - (real (k + 1) / real m) * real_of_int \<lceil>real (l * (k + 1)) / real m\<rceil> / (real l * real m))
[PROOF STEP]
apply (subst sum_distrib_left)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < 1 + i; \<And>x n. 0 < x \<Longrightarrow> x .^ real n = x ^ n\<rbrakk> \<Longrightarrow> (\<Sum>k<n * m. (1 + i) .^ (real n - real (k + 1) / real m) * real_of_int \<lceil>real (l * (k + 1)) / real m\<rceil> / (real l * real m)) = (\<Sum>na<n * m. (1 + i) ^ n * ((1 + i) .^ - (real (na + 1) / real m) * real_of_int \<lceil>real (l * (na + 1)) / real m\<rceil> / (real l * real m)))
[PROOF STEP]
by (subst minus_real_def, subst powr_add, subst times_divide_eq_right, subst mult.assoc, simp)


[STATEMENT]
lemma measure_Union_AE:
  "finite F \<Longrightarrow> (\<And>S. S \<in> F \<Longrightarrow> S \<in> fmeasurable M) \<Longrightarrow> pairwise (\<lambda>S T. AE x in M. x \<notin> S \<or> x \<notin> T) F \<Longrightarrow>
    measure M (\<Union>F) = (\<Sum>S\<in>F. measure M S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>finite F; \<And>S. S \<in> F \<Longrightarrow> S \<in> fmeasurable M; pairwise (\<lambda>S T. AE x in M. x \<notin> S \<or> x \<notin> T) F\<rbrakk> \<Longrightarrow> Sigma_Algebra.measure M (\<Union> F) = sum (Sigma_Algebra.measure M) F
[PROOF STEP]
using measure_UNION_AE[of F "\<lambda>x. x" M]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>finite F; \<And>i. i \<in> F \<Longrightarrow> i \<in> fmeasurable M; pairwise (\<lambda>i j. AE x in M. x \<notin> i \<or> x \<notin> j) F\<rbrakk> \<Longrightarrow> Sigma_Algebra.measure M (\<Union>i\<in>F. i) = sum (Sigma_Algebra.measure M) F

goal (1 subgoal):
 1. \<lbrakk>finite F; \<And>S. S \<in> F \<Longrightarrow> S \<in> fmeasurable M; pairwise (\<lambda>S T. AE x in M. x \<notin> S \<or> x \<notin> T) F\<rbrakk> \<Longrightarrow> Sigma_Algebra.measure M (\<Union> F) = sum (Sigma_Algebra.measure M) F
[PROOF STEP]
by simp


[STATEMENT]
lemma rank_matrix_dim_range:
assumes lf: "linear ((*s)) ((*s)) f"
shows "rank (matrix f::'a::{field}^'cols::{mod_type}^'rows::{mod_type}) = vec.dim (range f)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. rank (matrix f) = vec.dim (range f)
[PROOF STEP]
unfolding rank_col_rank[of "matrix f"] col_rank_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. vec.dim (col_space (matrix f)) = vec.dim (range f)
[PROOF STEP]
unfolding col_space_eq'
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. vec.dim (range ((*v) (matrix f))) = vec.dim (range f)
[PROOF STEP]
using matrix_works[OF lf]
[PROOF STATE]
proof (prove)
using this:
matrix f *v ?x = f ?x

goal (1 subgoal):
 1. vec.dim (range ((*v) (matrix f))) = vec.dim (range f)
[PROOF STEP]
by metis


[STATEMENT]
lemma lowdim_subset_hyperplane:
  fixes S :: "'a::euclidean_space set"
  assumes d: "dim S < DIM('a)"
  shows "\<exists>a::'a. a \<noteq> 0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
{
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
assume "span S = UNIV"
[PROOF STATE]
proof (state)
this:
span S = UNIV

goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
span S = UNIV
[PROOF STEP]
have "dim (span S) = dim (UNIV :: ('a) set)"
[PROOF STATE]
proof (prove)
using this:
span S = UNIV

goal (1 subgoal):
 1. dim (span S) = dim UNIV
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
dim (span S) = dim UNIV

goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
dim (span S) = dim UNIV
[PROOF STEP]
have "dim S = DIM('a)"
[PROOF STATE]
proof (prove)
using this:
dim (span S) = dim UNIV

goal (1 subgoal):
 1. dim S = DIM('a)
[PROOF STEP]
by (metis Euclidean_Space.dim_UNIV dim_span)
[PROOF STATE]
proof (state)
this:
dim S = DIM('a)

goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
with d
[PROOF STATE]
proof (chain)
picking this:
dim S < DIM('a)
dim S = DIM('a)
[PROOF STEP]
have False
[PROOF STATE]
proof (prove)
using this:
dim S < DIM('a)
dim S = DIM('a)

goal (1 subgoal):
 1. False
[PROOF STEP]
by arith
[PROOF STATE]
proof (state)
this:
False

goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
}
[PROOF STATE]
proof (state)
this:
span S = UNIV \<Longrightarrow> False

goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
span S = UNIV \<Longrightarrow> False
[PROOF STEP]
have th: "span S \<noteq> UNIV"
[PROOF STATE]
proof (prove)
using this:
span S = UNIV \<Longrightarrow> False

goal (1 subgoal):
 1. span S \<noteq> UNIV
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
span S \<noteq> UNIV

goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
from span_not_univ_subset_hyperplane[OF th]
[PROOF STATE]
proof (chain)
picking this:
\<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}

goal (1 subgoal):
 1. \<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
\<exists>a. a \<noteq> (0::'a) \<and> span S \<subseteq> {x. a \<bullet> x = 0}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma select_index_suc_odd:
  fixes n k i:: nat
  assumes "k \<le> 2^n -1" and "select_index n i k"
  shows "select_index (Suc n) i (2*k+1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
have "((2*k+1) mod 2^(Suc n - i) \<ge> 2^(n - i)) =
(((2*k+1) div 2) mod 2^(n - i) \<ge> 2^(n-1-i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
[PROOF STEP]
have "2*k+1 < 2^(n + 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 2 * k + 1 < 2 ^ (n + 1)
[PROOF STEP]
using assms(1)
[PROOF STATE]
proof (prove)
using this:
k \<le> 2 ^ n - 1

goal (1 subgoal):
 1. 2 * k + 1 < 2 ^ (n + 1)
[PROOF STEP]
by (smt Suc_1 Suc_eq_plus1 Suc_le_lessD Suc_le_mono add_Suc_right distrib_left_numeral le_add_diff_inverse mult_le_mono2 nat_mult_1_right one_le_numeral one_le_power plus_1_eq_Suc power_add power_one_right)
[PROOF STATE]
proof (state)
this:
2 * k + 1 < 2 ^ (n + 1)

goal (1 subgoal):
 1. (2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
2 * k + 1 < 2 ^ (n + 1)

goal (1 subgoal):
 1. (2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
[PROOF STEP]
have "i < n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i < n
[PROOF STEP]
using assms(2) select_index_def
[PROOF STATE]
proof (prove)
using this:
select_index n i k
select_index ?n ?i ?j \<equiv> ?i \<le> ?n - 1 \<and> ?j \<le> 2 ^ ?n - 1 \<and> 2 ^ (?n - 1 - ?i) \<le> ?j mod 2 ^ (?n - ?i)

goal (1 subgoal):
 1. i < n
[PROOF STEP]
by (metis (no_types, opaque_lifting) add_cancel_left_left add_diff_inverse_nat diff_le_self div_by_1 le_antisym less_le_trans less_one mod_div_trivial not_le power_0)
[PROOF STATE]
proof (state)
this:
i < n

goal (1 subgoal):
 1. (2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
2 * k + 1 < 2 ^ (n + 1)
i < n
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
2 * k + 1 < 2 ^ (n + 1)
i < n

goal (1 subgoal):
 1. (2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
[PROOF STEP]
using select_index_div_2[of "2*k+1" "n" i] select_index_def
[PROOF STATE]
proof (prove)
using this:
2 * k + 1 < 2 ^ (n + 1)
i < n
\<lbrakk>2 * k + 1 < 2 ^ (n + 1); i < n\<rbrakk> \<Longrightarrow> select_index n i ((2 * k + 1) div 2) = select_index (n + 1) i (2 * k + 1)
select_index ?n ?i ?j \<equiv> ?i \<le> ?n - 1 \<and> ?j \<le> 2 ^ ?n - 1 \<and> 2 ^ (?n - 1 - ?i) \<le> ?j mod 2 ^ (?n - ?i)

goal (1 subgoal):
 1. (2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
[PROOF STEP]
by (metis Nat.le_diff_conv2 Suc_eq_plus1 Suc_leI assms(2) diff_Suc_1 less_imp_le less_power_add_imp_div_less one_le_numeral one_le_power power_one_right)
[PROOF STATE]
proof (state)
this:
(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))

goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))

goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
have "\<dots> = (k mod 2^(n - i) \<ge> 2^(n-1-i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))

goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
(2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))
(2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))

goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)); (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))\<rbrakk> \<Longrightarrow> select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
have "i \<le> Suc n -1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i \<le> Suc n - 1
[PROOF STEP]
using assms(2) select_index_def
[PROOF STATE]
proof (prove)
using this:
select_index n i k
select_index ?n ?i ?j \<equiv> ?i \<le> ?n - 1 \<and> ?j \<le> 2 ^ ?n - 1 \<and> 2 ^ (?n - 1 - ?i) \<le> ?j mod 2 ^ (?n - ?i)

goal (1 subgoal):
 1. i \<le> Suc n - 1
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i \<le> Suc n - 1

goal (1 subgoal):
 1. \<lbrakk>(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)); (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))\<rbrakk> \<Longrightarrow> select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
i \<le> Suc n - 1

goal (1 subgoal):
 1. \<lbrakk>(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)); (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))\<rbrakk> \<Longrightarrow> select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
have "2*k+1 \<le> 2^(Suc n)-1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 2 * k + 1 \<le> 2 ^ Suc n - 1
[PROOF STEP]
using assms(1)
[PROOF STATE]
proof (prove)
using this:
k \<le> 2 ^ n - 1

goal (1 subgoal):
 1. 2 * k + 1 \<le> 2 ^ Suc n - 1
[PROOF STEP]
by (smt Suc_diff_1 Suc_eq_plus1 add_diff_cancel_right' diff_Suc_diff_eq2 diff_diff_left diff_is_0_eq diff_mult_distrib2 le_add2 mult_2 mult_Suc_right plus_1_eq_Suc pos2 power_Suc zero_less_power)
[PROOF STATE]
proof (state)
this:
2 * k + 1 \<le> 2 ^ Suc n - 1

goal (1 subgoal):
 1. \<lbrakk>(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)); (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))\<rbrakk> \<Longrightarrow> select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
i \<le> Suc n - 1
2 * k + 1 \<le> 2 ^ Suc n - 1
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
i \<le> Suc n - 1
2 * k + 1 \<le> 2 ^ Suc n - 1

goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
using select_index_def
[PROOF STATE]
proof (prove)
using this:
i \<le> Suc n - 1
2 * k + 1 \<le> 2 ^ Suc n - 1
select_index ?n ?i ?j \<equiv> ?i \<le> ?n - 1 \<and> ?j \<le> 2 ^ ?n - 1 \<and> 2 ^ (?n - 1 - ?i) \<le> ?j mod 2 ^ (?n - ?i)

goal (1 subgoal):
 1. select_index (Suc n) i (2 * k + 1)
[PROOF STEP]
by (metis \<open>(2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \<le> k mod 2 ^ (n - i))\<close> \<open>(2 ^ (n - i) \<le> (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \<le> (2 * k + 1) div 2 mod 2 ^ (n - i))\<close> assms(2) diff_Suc_1)
[PROOF STATE]
proof (state)
this:
select_index (Suc n) i (2 * k + 1)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
select_index (Suc n) i (2 * k + 1)

goal:
No subgoals!
[PROOF STEP]
qed