[STATEMENT]
lemma card_derangements:
  assumes "finite S" "card S = n"
  shows "card (derangements S) = count_derangements n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (derangements S) = count_derangements n
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
finite S
card S = n

goal (1 subgoal):
 1. card (derangements S) = count_derangements n
[PROOF STEP]
proof (induct n arbitrary: S rule: count_derangements.induct)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>S. \<lbrakk>finite S; card S = 0\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements 0
 2. \<And>S. \<lbrakk>finite S; card S = Suc 0\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc 0)
 3. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
case 1
[PROOF STATE]
proof (state)
this:
finite S
card S = 0

goal (3 subgoals):
 1. \<And>S. \<lbrakk>finite S; card S = 0\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements 0
 2. \<And>S. \<lbrakk>finite S; card S = Suc 0\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc 0)
 3. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
finite S
card S = 0
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
finite S
card S = 0

goal (1 subgoal):
 1. card (derangements S) = count_derangements 0
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
card (derangements S) = count_derangements 0

goal (2 subgoals):
 1. \<And>S. \<lbrakk>finite S; card S = Suc 0\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc 0)
 2. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>S. \<lbrakk>finite S; card S = Suc 0\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc 0)
 2. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
case 2
[PROOF STATE]
proof (state)
this:
finite S
card S = Suc 0

goal (2 subgoals):
 1. \<And>S. \<lbrakk>finite S; card S = Suc 0\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc 0)
 2. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from this derangements_singleton finite_derangements
[PROOF STATE]
proof (chain)
picking this:
finite S
card S = Suc 0
derangements {?x} = {}
finite ?A \<Longrightarrow> finite (derangements ?A)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
finite S
card S = Suc 0
derangements {?x} = {}
finite ?A \<Longrightarrow> finite (derangements ?A)

goal (1 subgoal):
 1. card (derangements S) = count_derangements (Suc 0)
[PROOF STEP]
using Finite_Set.card_0_eq card_eq_SucD count_derangements.simps(2)
[PROOF STATE]
proof (prove)
using this:
finite S
card S = Suc 0
derangements {?x} = {}
finite ?A \<Longrightarrow> finite (derangements ?A)
finite ?A \<Longrightarrow> (card ?A = 0) = (?A = {})
card ?A = Suc ?k \<Longrightarrow> \<exists>b B. ?A = insert b B \<and> b \<notin> B \<and> card B = ?k \<and> (?k = 0 \<longrightarrow> B = {})
count_derangements (Suc 0) = 0

goal (1 subgoal):
 1. card (derangements S) = count_derangements (Suc 0)
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
card (derangements S) = count_derangements (Suc 0)

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
case (3 n)
[PROOF STATE]
proof (state)
this:
\<lbrakk>finite ?S; card ?S = Suc n\<rbrakk> \<Longrightarrow> card (derangements ?S) = count_derangements (Suc n)
\<lbrakk>finite ?S; card ?S = n\<rbrakk> \<Longrightarrow> card (derangements ?S) = count_derangements n
finite S
card S = Suc (Suc n)

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from 3(4)
[PROOF STATE]
proof (chain)
picking this:
card S = Suc (Suc n)
[PROOF STEP]
obtain x where "x \<in> S"
[PROOF STATE]
proof (prove)
using this:
card S = Suc (Suc n)

goal (1 subgoal):
 1. (\<And>x. x \<in> S \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using card_eq_SucD insertI1
[PROOF STATE]
proof (prove)
using this:
card S = Suc (Suc n)
card ?A = Suc ?k \<Longrightarrow> \<exists>b B. ?A = insert b B \<and> b \<notin> B \<and> card B = ?k \<and> (?k = 0 \<longrightarrow> B = {})
?a \<in> insert ?a ?B

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

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
let ?D1 = "(\<lambda>(y, d). Fun.swap x y d) ` {(y, d). y \<in> S & y \<noteq> x & d : derangements (S - {x, y})}"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
let ?D2 = "(\<lambda>(y, f). f(x:=y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from \<open>x \<in> S\<close>
[PROOF STATE]
proof (chain)
picking this:
x \<in> S
[PROOF STEP]
have subset1: "?D1 \<subseteq> derangements S"
[PROOF STATE]
proof (prove)
using this:
x \<in> S

goal (1 subgoal):
 1. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<subseteq> derangements S
[PROOF STEP]
proof (auto)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b. \<lbrakk>x \<in> S; a \<in> S; a \<noteq> x; b \<in> derangements (S - {x, a})\<rbrakk> \<Longrightarrow> b \<circ> Transposition.transpose x a \<in> derangements S
[PROOF STEP]
fix y d
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b. \<lbrakk>x \<in> S; a \<in> S; a \<noteq> x; b \<in> derangements (S - {x, a})\<rbrakk> \<Longrightarrow> b \<circ> Transposition.transpose x a \<in> derangements S
[PROOF STEP]
assume "y \<in> S" "y \<noteq> x"
[PROOF STATE]
proof (state)
this:
y \<in> S
y \<noteq> x

goal (1 subgoal):
 1. \<And>a b. \<lbrakk>x \<in> S; a \<in> S; a \<noteq> x; b \<in> derangements (S - {x, a})\<rbrakk> \<Longrightarrow> b \<circ> Transposition.transpose x a \<in> derangements S
[PROOF STEP]
assume d: "d \<in> derangements (S - {x, y})"
[PROOF STATE]
proof (state)
this:
d \<in> derangements (S - {x, y})

goal (1 subgoal):
 1. \<And>a b. \<lbrakk>x \<in> S; a \<in> S; a \<noteq> x; b \<in> derangements (S - {x, a})\<rbrakk> \<Longrightarrow> b \<circ> Transposition.transpose x a \<in> derangements S
[PROOF STEP]
from \<open>x : S\<close> \<open>y : S\<close>
[PROOF STATE]
proof (chain)
picking this:
x \<in> S
y \<in> S
[PROOF STEP]
have S: "S = insert x (insert y (S - {x, y}))"
[PROOF STATE]
proof (prove)
using this:
x \<in> S
y \<in> S

goal (1 subgoal):
 1. S = insert x (insert y (S - {x, y}))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
S = insert x (insert y (S - {x, y}))

goal (1 subgoal):
 1. \<And>a b. \<lbrakk>x \<in> S; a \<in> S; a \<noteq> x; b \<in> derangements (S - {x, a})\<rbrakk> \<Longrightarrow> b \<circ> Transposition.transpose x a \<in> derangements S
[PROOF STEP]
from d \<open>x : S\<close> \<open>y : S\<close> \<open>y \<noteq> x\<close>
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements (S - {x, y})
x \<in> S
y \<in> S
y \<noteq> x
[PROOF STEP]
show "Fun.swap x y d \<in> derangements S"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements (S - {x, y})
x \<in> S
y \<in> S
y \<noteq> x

goal (1 subgoal):
 1. d \<circ> Transposition.transpose x y \<in> derangements S
[PROOF STEP]
by (subst S) (auto intro!: derangements_swap)
[PROOF STATE]
proof (state)
this:
d \<circ> Transposition.transpose x y \<in> derangements S

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<subseteq> derangements S

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have subset2: "?D2 \<subseteq> derangements S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<subseteq> derangements S
[PROOF STEP]
proof (rule subsetI, erule imageE, simp split: prod.split_asm, (erule conjE)+)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>xa xaa x1 x2. \<lbrakk>xaa = (x1, x2); xa = x2(x := x1, inv x2 x1 := x); x1 \<in> S; x1 \<noteq> x; x2 \<in> derangements (S - {x})\<rbrakk> \<Longrightarrow> x2(x := x1, inv x2 x1 := x) \<in> derangements S
[PROOF STEP]
fix d y
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>xa xaa x1 x2. \<lbrakk>xaa = (x1, x2); xa = x2(x := x1, inv x2 x1 := x); x1 \<in> S; x1 \<noteq> x; x2 \<in> derangements (S - {x})\<rbrakk> \<Longrightarrow> x2(x := x1, inv x2 x1 := x) \<in> derangements S
[PROOF STEP]
assume "d : derangements (S - {x})" "y : S" "y \<noteq> x"
[PROOF STATE]
proof (state)
this:
d \<in> derangements (S - {x})
y \<in> S
y \<noteq> x

goal (1 subgoal):
 1. \<And>xa xaa x1 x2. \<lbrakk>xaa = (x1, x2); xa = x2(x := x1, inv x2 x1 := x); x1 \<in> S; x1 \<noteq> x; x2 \<in> derangements (S - {x})\<rbrakk> \<Longrightarrow> x2(x := x1, inv x2 x1 := x) \<in> derangements S
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements (S - {x})
y \<in> S
y \<noteq> x
[PROOF STEP]
have "d(x := y, inv d y := x) \<in> derangements (insert x (S - {x}))"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements (S - {x})
y \<in> S
y \<noteq> x

goal (1 subgoal):
 1. d(x := y, inv d y := x) \<in> derangements (insert x (S - {x}))
[PROOF STEP]
by (intro derangements_add_one) auto
[PROOF STATE]
proof (state)
this:
d(x := y, inv d y := x) \<in> derangements (insert x (S - {x}))

goal (1 subgoal):
 1. \<And>xa xaa x1 x2. \<lbrakk>xaa = (x1, x2); xa = x2(x := x1, inv x2 x1 := x); x1 \<in> S; x1 \<noteq> x; x2 \<in> derangements (S - {x})\<rbrakk> \<Longrightarrow> x2(x := x1, inv x2 x1 := x) \<in> derangements S
[PROOF STEP]
from this \<open>x : S\<close>
[PROOF STATE]
proof (chain)
picking this:
d(x := y, inv d y := x) \<in> derangements (insert x (S - {x}))
x \<in> S
[PROOF STEP]
show "d(x := y, inv d y := x) \<in> derangements S"
[PROOF STATE]
proof (prove)
using this:
d(x := y, inv d y := x) \<in> derangements (insert x (S - {x}))
x \<in> S

goal (1 subgoal):
 1. d(x := y, inv d y := x) \<in> derangements S
[PROOF STEP]
using insert_Diff
[PROOF STATE]
proof (prove)
using this:
d(x := y, inv d y := x) \<in> derangements (insert x (S - {x}))
x \<in> S
?a \<in> ?A \<Longrightarrow> insert ?a (?A - {?a}) = ?A

goal (1 subgoal):
 1. d(x := y, inv d y := x) \<in> derangements S
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
d(x := y, inv d y := x) \<in> derangements S

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<subseteq> derangements S

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have split: "derangements S = ?D1 \<union> ?D2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. derangements S = (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. derangements S \<subseteq> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
 2. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<subseteq> derangements S
[PROOF STEP]
from subset1 subset2
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<subseteq> derangements S
(\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<subseteq> derangements S
[PROOF STEP]
show "?D1 \<union> ?D2 \<subseteq> derangements S"
[PROOF STATE]
proof (prove)
using this:
(\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<subseteq> derangements S
(\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<subseteq> derangements S

goal (1 subgoal):
 1. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<subseteq> derangements S
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<subseteq> derangements S

goal (1 subgoal):
 1. derangements S \<subseteq> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. derangements S \<subseteq> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
show "derangements S \<subseteq> ?D1 \<union> ?D2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. derangements S \<subseteq> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>xa. xa \<in> derangements S \<Longrightarrow> xa \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
fix d
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>xa. xa \<in> derangements S \<Longrightarrow> xa \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
assume d: "d : derangements S"
[PROOF STATE]
proof (state)
this:
d \<in> derangements S

goal (1 subgoal):
 1. \<And>xa. xa \<in> derangements S \<Longrightarrow> xa \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
show "d : ?D1 \<union> ?D2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
proof (cases "d (d x) = x")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. d (d x) = x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
 2. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
d (d x) = x

goal (2 subgoals):
 1. d (d x) = x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
 2. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from \<open>x : S\<close> d
[PROOF STATE]
proof (chain)
picking this:
x \<in> S
d \<in> derangements S
[PROOF STEP]
have "d x \<in> S" "d x \<noteq> x"
[PROOF STATE]
proof (prove)
using this:
x \<in> S
d \<in> derangements S

goal (1 subgoal):
 1. d x \<in> S &&& d x \<noteq> x
[PROOF STEP]
by (auto simp add: derangements_in_image derangements_no_fixpoint)
[PROOF STATE]
proof (state)
this:
d x \<in> S
d x \<noteq> x

goal (2 subgoals):
 1. d (d x) = x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
 2. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from d True
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements S
d (d x) = x
[PROOF STEP]
have "Fun.swap x (d x) d \<in> derangements (S - {x, d x})"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements S
d (d x) = x

goal (1 subgoal):
 1. d \<circ> Transposition.transpose x (d x) \<in> derangements (S - {x, d x})
[PROOF STEP]
by (rule derangements_drop_minimal_cycle)
[PROOF STATE]
proof (state)
this:
d \<circ> Transposition.transpose x (d x) \<in> derangements (S - {x, d x})

goal (2 subgoals):
 1. d (d x) = x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
 2. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
with \<open>d x \<in> S\<close> \<open>d x \<noteq> x\<close>
[PROOF STATE]
proof (chain)
picking this:
d x \<in> S
d x \<noteq> x
d \<circ> Transposition.transpose x (d x) \<in> derangements (S - {x, d x})
[PROOF STEP]
have \<open>d \<in> ?D1\<close>
[PROOF STATE]
proof (prove)
using this:
d x \<in> S
d x \<noteq> x
d \<circ> Transposition.transpose x (d x) \<in> derangements (S - {x, d x})

goal (1 subgoal):
 1. d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}
[PROOF STEP]
by (auto intro!: image_eqI [where x = \<open>(d x, Fun.swap x (d x) d)\<close>])
[PROOF STATE]
proof (state)
this:
d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}

goal (2 subgoals):
 1. d (d x) = x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
 2. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}

goal (1 subgoal):
 1. d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
d (d x) \<noteq> x

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from d
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements S
[PROOF STEP]
have bij: "bij d"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements S

goal (1 subgoal):
 1. bij d
[PROOF STEP]
by (auto elim: derangementsE simp add: permutes_imp_bij')
[PROOF STATE]
proof (state)
this:
bij d

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from d \<open>x : S\<close>
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements S
x \<in> S
[PROOF STEP]
have that: "d x : S - {x}"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements S
x \<in> S

goal (1 subgoal):
 1. d x \<in> S - {x}
[PROOF STEP]
by (intro derangements_in_image_strong)
[PROOF STATE]
proof (state)
this:
d x \<in> S - {x}

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from d \<open>x : S\<close> False
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements S
x \<in> S
d (d x) \<noteq> x
[PROOF STEP]
have derangements: "d(x:=x, inv d x:= d x) : derangements (S - {x})"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements S
x \<in> S
d (d x) \<noteq> x

goal (1 subgoal):
 1. d(x := x, inv d x := d x) \<in> derangements (S - {x})
[PROOF STEP]
by (auto intro: derangements_skip_one)
[PROOF STATE]
proof (state)
this:
d(x := x, inv d x := d x) \<in> derangements (S - {x})

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
d(x := x, inv d x := d x) \<in> derangements (S - {x})
[PROOF STEP]
have "bij (d(x := x, inv d x:= d x))"
[PROOF STATE]
proof (prove)
using this:
d(x := x, inv d x := d x) \<in> derangements (S - {x})

goal (1 subgoal):
 1. bij (d(x := x, inv d x := d x))
[PROOF STEP]
by (metis derangementsE permutes_imp_bij')+
[PROOF STATE]
proof (state)
this:
bij (d(x := x, inv d x := d x))

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
bij (d(x := x, inv d x := d x))
[PROOF STEP]
have a: "inv (d(x := x, inv d x := d x)) (d x) = inv d x"
[PROOF STATE]
proof (prove)
using this:
bij (d(x := x, inv d x := d x))

goal (1 subgoal):
 1. inv (d(x := x, inv d x := d x)) (d x) = inv d x
[PROOF STEP]
by (metis bij_inv_eq_iff fun_upd_same)
[PROOF STATE]
proof (state)
this:
inv (d(x := x, inv d x := d x)) (d x) = inv d x

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from bij
[PROOF STATE]
proof (chain)
picking this:
bij d
[PROOF STEP]
have x: "d (inv d x) = x"
[PROOF STATE]
proof (prove)
using this:
bij d

goal (1 subgoal):
 1. d (inv d x) = x
[PROOF STEP]
by (meson bij_inv_eq_iff)
[PROOF STATE]
proof (state)
this:
d (inv d x) = x

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from d derangements_inv[of d] \<open>x : S\<close>
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements S
d \<in> derangements ?S \<Longrightarrow> inv d \<in> derangements ?S
x \<in> S
[PROOF STEP]
have "inv d x \<noteq> x" "d x \<noteq> x"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements S
d \<in> derangements ?S \<Longrightarrow> inv d \<in> derangements ?S
x \<in> S

goal (1 subgoal):
 1. inv d x \<noteq> x &&& d x \<noteq> x
[PROOF STEP]
by (auto dest: derangements_no_fixpoint)
[PROOF STATE]
proof (state)
this:
inv d x \<noteq> x
d x \<noteq> x

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from this a x
[PROOF STATE]
proof (chain)
picking this:
inv d x \<noteq> x
d x \<noteq> x
inv (d(x := x, inv d x := d x)) (d x) = inv d x
d (inv d x) = x
[PROOF STEP]
have d_eq: "d = d(inv d x := d x, x := d x, inv (d(x := x, inv d x := d x)) (d x) := x)"
[PROOF STATE]
proof (prove)
using this:
inv d x \<noteq> x
d x \<noteq> x
inv (d(x := x, inv d x := d x)) (d x) = inv d x
d (inv d x) = x

goal (1 subgoal):
 1. d = d(inv d x := d x, x := d x, inv (d(x := x, inv d x := d x)) (d x) := x)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
d = d(inv d x := d x, x := d x, inv (d(x := x, inv d x := d x)) (d x) := x)

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from derangements that
[PROOF STATE]
proof (chain)
picking this:
d(x := x, inv d x := d x) \<in> derangements (S - {x})
d x \<in> S - {x}
[PROOF STEP]
have "(d x, d(x:=x, inv d x:=d x)) : ((S - {x}) \<times> derangements (S - {x}))"
[PROOF STATE]
proof (prove)
using this:
d(x := x, inv d x := d x) \<in> derangements (S - {x})
d x \<in> S - {x}

goal (1 subgoal):
 1. (d x, d(x := x, inv d x := d x)) \<in> (S - {x}) \<times> derangements (S - {x})
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(d x, d(x := x, inv d x := d x)) \<in> (S - {x}) \<times> derangements (S - {x})

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from d_eq this
[PROOF STATE]
proof (chain)
picking this:
d = d(inv d x := d x, x := d x, inv (d(x := x, inv d x := d x)) (d x) := x)
(d x, d(x := x, inv d x := d x)) \<in> (S - {x}) \<times> derangements (S - {x})
[PROOF STEP]
have "d : ?D2"
[PROOF STATE]
proof (prove)
using this:
d = d(inv d x := d x, x := d x, inv (d(x := x, inv d x := d x)) (d x) := x)
(d x, d(x := x, inv d x := d x)) \<in> (S - {x}) \<times> derangements (S - {x})

goal (1 subgoal):
 1. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
by (auto intro: image_eqI[where x = "(d x, d(x:=x, inv d x:=d x))"])
[PROOF STATE]
proof (state)
this:
d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. d (d x) \<noteq> x \<Longrightarrow> d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
derangements S \<subseteq> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
derangements S = (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<union> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have no_intersect: "?D1 \<inter> ?D2 = {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<inter> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) = {}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<inter> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) = {}
[PROOF STEP]
have that: "\<And>d. d \<in> ?D1 \<Longrightarrow> d (d x) = x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<Longrightarrow> d (d x) = x
[PROOF STEP]
using Diff_iff Diff_insert2 derangements_fixpoint insertI1 swap_apply(2)
[PROOF STATE]
proof (prove)
using this:
(?c \<in> ?A - ?B) = (?c \<in> ?A \<and> ?c \<notin> ?B)
?A - insert ?a ?B = ?A - {?a} - ?B
\<lbrakk>?d \<in> derangements ?A; ?x \<notin> ?A\<rbrakk> \<Longrightarrow> ?d ?x = ?x
?a \<in> insert ?a ?B
(?f \<circ> Transposition.transpose ?a ?b) ?b = ?f ?a

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<Longrightarrow> d (d x) = x
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<Longrightarrow> ?d (?d x) = x

goal (1 subgoal):
 1. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<inter> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) = {}
[PROOF STEP]
have "\<And>d. d \<in> ?D2 \<Longrightarrow> d (d x) \<noteq> x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
fix d
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
assume a: "d \<in> ?D2"
[PROOF STATE]
proof (state)
this:
d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from a
[PROOF STATE]
proof (chain)
picking this:
d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
obtain y d' where d: "d = d'(x := y, inv d' y := x)"
        "d' \<in> derangements (S - {x})" "y \<in> S - {x}"
[PROOF STATE]
proof (prove)
using this:
d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. (\<And>d' y. \<lbrakk>d = d'(x := y, inv d' y := x); d' \<in> derangements (S - {x}); y \<in> S - {x}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
d = d'(x := y, inv d' y := x)
d' \<in> derangements (S - {x})
y \<in> S - {x}

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from d(2)
[PROOF STATE]
proof (chain)
picking this:
d' \<in> derangements (S - {x})
[PROOF STEP]
have inv: "inv d' \<in> derangements (S - {x})"
[PROOF STATE]
proof (prove)
using this:
d' \<in> derangements (S - {x})

goal (1 subgoal):
 1. inv d' \<in> derangements (S - {x})
[PROOF STEP]
by (rule derangements_inv)
[PROOF STATE]
proof (state)
this:
inv d' \<in> derangements (S - {x})

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from d
[PROOF STATE]
proof (chain)
picking this:
d = d'(x := y, inv d' y := x)
d' \<in> derangements (S - {x})
y \<in> S - {x}
[PROOF STEP]
have inv_x: "inv d' y \<noteq> x"
[PROOF STATE]
proof (prove)
using this:
d = d'(x := y, inv d' y := x)
d' \<in> derangements (S - {x})
y \<in> S - {x}

goal (1 subgoal):
 1. inv d' y \<noteq> x
[PROOF STEP]
by (auto dest: derangements_inverse_in_image)
[PROOF STATE]
proof (state)
this:
inv d' y \<noteq> x

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from inv
[PROOF STATE]
proof (chain)
picking this:
inv d' \<in> derangements (S - {x})
[PROOF STEP]
have inv_y: "inv d' y \<noteq> y"
[PROOF STATE]
proof (prove)
using this:
inv d' \<in> derangements (S - {x})

goal (1 subgoal):
 1. inv d' y \<noteq> y
[PROOF STEP]
using d(3) derangements_no_fixpoint
[PROOF STATE]
proof (prove)
using this:
inv d' \<in> derangements (S - {x})
y \<in> S - {x}
\<lbrakk>?d \<in> derangements ?A; ?x \<in> ?A\<rbrakk> \<Longrightarrow> ?d ?x \<noteq> ?x

goal (1 subgoal):
 1. inv d' y \<noteq> y
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
inv d' y \<noteq> y

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from d inv_x
[PROOF STATE]
proof (chain)
picking this:
d = d'(x := y, inv d' y := x)
d' \<in> derangements (S - {x})
y \<in> S - {x}
inv d' y \<noteq> x
[PROOF STEP]
have 1: "d x = y"
[PROOF STATE]
proof (prove)
using this:
d = d'(x := y, inv d' y := x)
d' \<in> derangements (S - {x})
y \<in> S - {x}
inv d' y \<noteq> x

goal (1 subgoal):
 1. d x = y
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
d x = y

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from d inv_y
[PROOF STATE]
proof (chain)
picking this:
d = d'(x := y, inv d' y := x)
d' \<in> derangements (S - {x})
y \<in> S - {x}
inv d' y \<noteq> y
[PROOF STEP]
have 2: "d y = d' y"
[PROOF STATE]
proof (prove)
using this:
d = d'(x := y, inv d' y := x)
d' \<in> derangements (S - {x})
y \<in> S - {x}
inv d' y \<noteq> y

goal (1 subgoal):
 1. d y = d' y
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
d y = d' y

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from d(2, 3)
[PROOF STATE]
proof (chain)
picking this:
d' \<in> derangements (S - {x})
y \<in> S - {x}
[PROOF STEP]
have 3: "d' y \<in> S - {x}"
[PROOF STATE]
proof (prove)
using this:
d' \<in> derangements (S - {x})
y \<in> S - {x}

goal (1 subgoal):
 1. d' y \<in> S - {x}
[PROOF STEP]
by (auto dest: derangements_in_image)
[PROOF STATE]
proof (state)
this:
d' y \<in> S - {x}

goal (1 subgoal):
 1. \<And>d. d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> d (d x) \<noteq> x
[PROOF STEP]
from 1 2 3
[PROOF STATE]
proof (chain)
picking this:
d x = y
d y = d' y
d' y \<in> S - {x}
[PROOF STEP]
show "d (d x) \<noteq> x"
[PROOF STATE]
proof (prove)
using this:
d x = y
d y = d' y
d' y \<in> S - {x}

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

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> ?d (?d x) \<noteq> x

goal (1 subgoal):
 1. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<inter> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) = {}
[PROOF STEP]
from this that
[PROOF STATE]
proof (chain)
picking this:
?d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> ?d (?d x) \<noteq> x
?d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<Longrightarrow> ?d (?d x) = x
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
?d \<in> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) \<Longrightarrow> ?d (?d x) \<noteq> x
?d \<in> (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<Longrightarrow> ?d (?d x) = x

goal (1 subgoal):
 1. (\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<inter> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) = {}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
(\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<inter> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) = {}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})} \<inter> (\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})) = {}

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have inj: "inj_on (\<lambda>(y, f). Fun.swap x y f) {(y, f). y \<in> S & y \<noteq> x & f : derangements (S - {x, y})}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f \<circ> Transposition.transpose x y) {(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})}
[PROOF STEP]
unfolding inj_on_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>xa\<in>{(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})}. \<forall>y\<in>{(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})}. (case xa of (y, f) \<Rightarrow> f \<circ> Transposition.transpose x y) = (case y of (y, f) \<Rightarrow> f \<circ> Transposition.transpose x y) \<longrightarrow> xa = y
[PROOF STEP]
by (clarify; metis DiffD2 derangements_fixpoint insertI1 insert_commute swap_apply(1) swap_nilpotent)
[PROOF STATE]
proof (state)
this:
inj_on (\<lambda>(y, f). f \<circ> Transposition.transpose x y) {(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})}

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have eq: "{(y, f). y \<in> S & y \<noteq> x & f : derangements (S - {x, y})} = {(y, f). y \<in> S - {x} & f : derangements (S - {x, y})}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})} = {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
{(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})} = {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})}

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have eq': "{(y, f). y \<in> S & y \<noteq> x & f : derangements (S - {x, y})} = Sigma (S - {x}) (%y. derangements (S - {x, y}))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})} = (SIGMA y:S - {x}. derangements (S - {x, y}))
[PROOF STEP]
unfolding Sigma_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})} = (\<Union>xa\<in>S - {x}. \<Union>y\<in>derangements (S - {x, xa}). {(xa, y)})
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
{(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})} = (SIGMA y:S - {x}. derangements (S - {x, y}))

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have card: "\<And> y. y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>y. y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>y. y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n
[PROOF STEP]
fix y
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>y. y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n
[PROOF STEP]
assume "y \<in> S - {x}"
[PROOF STATE]
proof (state)
this:
y \<in> S - {x}

goal (1 subgoal):
 1. \<And>y. y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n
[PROOF STEP]
from 3(3, 4) \<open>x \<in> S\<close> this
[PROOF STATE]
proof (chain)
picking this:
finite S
card S = Suc (Suc n)
x \<in> S
y \<in> S - {x}
[PROOF STEP]
have "card (S - {x, y}) = n"
[PROOF STATE]
proof (prove)
using this:
finite S
card S = Suc (Suc n)
x \<in> S
y \<in> S - {x}

goal (1 subgoal):
 1. card (S - {x, y}) = n
[PROOF STEP]
by (metis Diff_insert2 card_Diff_singleton diff_Suc_1 finite_Diff)
[PROOF STATE]
proof (state)
this:
card (S - {x, y}) = n

goal (1 subgoal):
 1. \<And>y. y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n
[PROOF STEP]
from 3(3) 3(2)[OF _ this]
[PROOF STATE]
proof (chain)
picking this:
finite S
finite (S - {x, y}) \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n
[PROOF STEP]
show "card (derangements (S - {x, y})) = count_derangements n"
[PROOF STATE]
proof (prove)
using this:
finite S
finite (S - {x, y}) \<Longrightarrow> card (derangements (S - {x, y})) = count_derangements n

goal (1 subgoal):
 1. card (derangements (S - {x, y})) = count_derangements n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
card (derangements (S - {x, y})) = count_derangements n

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, ?y})) = count_derangements n

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from 3(3, 4) \<open>x : S\<close>
[PROOF STATE]
proof (chain)
picking this:
finite S
card S = Suc (Suc n)
x \<in> S
[PROOF STEP]
have card2: "card (S - {x}) = Suc n"
[PROOF STATE]
proof (prove)
using this:
finite S
card S = Suc (Suc n)
x \<in> S

goal (1 subgoal):
 1. card (S - {x}) = Suc n
[PROOF STEP]
by (simp add: card.insert_remove insert_absorb)
[PROOF STATE]
proof (state)
this:
card (S - {x}) = Suc n

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from inj
[PROOF STATE]
proof (chain)
picking this:
inj_on (\<lambda>(y, f). f \<circ> Transposition.transpose x y) {(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})}
[PROOF STEP]
have "card ?D1 = card {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})}"
[PROOF STATE]
proof (prove)
using this:
inj_on (\<lambda>(y, f). f \<circ> Transposition.transpose x y) {(y, f). y \<in> S \<and> y \<noteq> x \<and> f \<in> derangements (S - {x, y})}

goal (1 subgoal):
 1. card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = card {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})}
[PROOF STEP]
by (simp add: card_image)
[PROOF STATE]
proof (state)
this:
card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = card {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})}

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = card {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})}

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from 3(3)
[PROOF STATE]
proof (chain)
picking this:
finite S
[PROOF STEP]
have "... = (\<Sum>y\<in>S - {x}. card (derangements (S - {x, y})))"
[PROOF STATE]
proof (prove)
using this:
finite S

goal (1 subgoal):
 1. card {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})} = (\<Sum>y\<in>S - {x}. card (derangements (S - {x, y})))
[PROOF STEP]
by (subst card_product_dependent) (simp add: finite_derangements)+
[PROOF STATE]
proof (state)
this:
card {(y, f). y \<in> S - {x} \<and> f \<in> derangements (S - {x, y})} = (\<Sum>y\<in>S - {x}. card (derangements (S - {x, y})))

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = (\<Sum>y\<in>S - {x}. card (derangements (S - {x, y})))
[PROOF STEP]
have card_1: "card ?D1 =(Suc n) * count_derangements n"
[PROOF STATE]
proof (prove)
using this:
card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = (\<Sum>y\<in>S - {x}. card (derangements (S - {x, y})))

goal (1 subgoal):
 1. card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = Suc n * count_derangements n
[PROOF STEP]
using card card2
[PROOF STATE]
proof (prove)
using this:
card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = (\<Sum>y\<in>S - {x}. card (derangements (S - {x, y})))
?y \<in> S - {x} \<Longrightarrow> card (derangements (S - {x, ?y})) = count_derangements n
card (S - {x}) = Suc n

goal (1 subgoal):
 1. card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = Suc n * count_derangements n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
card ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})}) = Suc n * count_derangements n

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
have inj_2: "inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
{
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
fix d d' y y'
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
assume 1: "d \<in> derangements (S - {x})" "d' \<in> derangements (S - {x})"
[PROOF STATE]
proof (state)
this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
assume 2: "y \<in> S" "y \<noteq> x" "y' \<in> S" "y' \<noteq> x"
[PROOF STATE]
proof (state)
this:
y \<in> S
y \<noteq> x
y' \<in> S
y' \<noteq> x

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
assume eq: "d(x := y, inv d y := x) = d'(x := y', inv d' y' := x)"
[PROOF STATE]
proof (state)
this:
d(x := y, inv d y := x) = d'(x := y', inv d' y' := x)

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from 1 2 eq \<open>x \<in> S\<close>
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})
y \<in> S
y \<noteq> x
y' \<in> S
y' \<noteq> x
d(x := y, inv d y := x) = d'(x := y', inv d' y' := x)
x \<in> S
[PROOF STEP]
have y: "y = y'"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})
y \<in> S
y \<noteq> x
y' \<in> S
y' \<noteq> x
d(x := y, inv d y := x) = d'(x := y', inv d' y' := x)
x \<in> S

goal (1 subgoal):
 1. y = y'
[PROOF STEP]
by (metis Diff_insert_absorb derangements_in_image derangements_inv
          fun_upd_same fun_upd_twist insert_iff mk_disjoint_insert)
[PROOF STATE]
proof (state)
this:
y = y'

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
have "d = d'"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. d = d'
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. d x = d' x
[PROOF STEP]
fix z
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. d x = d' x
[PROOF STEP]
from 1
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})
[PROOF STEP]
have d_x: "d x = d' x"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})

goal (1 subgoal):
 1. d x = d' x
[PROOF STEP]
by (auto dest!: derangements_fixpoint)
[PROOF STATE]
proof (state)
this:
d x = d' x

goal (1 subgoal):
 1. \<And>x. d x = d' x
[PROOF STEP]
from 1
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})
[PROOF STEP]
have bij: "bij d" "bij d'"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})

goal (1 subgoal):
 1. bij d &&& bij d'
[PROOF STEP]
by (metis derangementsE permutes_imp_bij')+
[PROOF STATE]
proof (state)
this:
bij d
bij d'

goal (1 subgoal):
 1. \<And>x. d x = d' x
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
bij d
bij d'
[PROOF STEP]
have d_d: "d (inv d y) = y" "d' (inv d' y') = y'"
[PROOF STATE]
proof (prove)
using this:
bij d
bij d'

goal (1 subgoal):
 1. d (inv d y) = y &&& d' (inv d' y') = y'
[PROOF STEP]
by (simp add: bij_is_surj surj_f_inv_f)+
[PROOF STATE]
proof (state)
this:
d (inv d y) = y
d' (inv d' y') = y'

goal (1 subgoal):
 1. \<And>x. d x = d' x
[PROOF STEP]
from 1 2 bij
[PROOF STATE]
proof (chain)
picking this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})
y \<in> S
y \<noteq> x
y' \<in> S
y' \<noteq> x
bij d
bij d'
[PROOF STEP]
have neq: "d (inv d' y') \<noteq> x \<and> d' (inv d y) \<noteq> x"
[PROOF STATE]
proof (prove)
using this:
d \<in> derangements (S - {x})
d' \<in> derangements (S - {x})
y \<in> S
y \<noteq> x
y' \<in> S
y' \<noteq> x
bij d
bij d'

goal (1 subgoal):
 1. d (inv d' y') \<noteq> x \<and> d' (inv d y) \<noteq> x
[PROOF STEP]
by (metis Diff_iff bij_inv_eq_iff derangements_fixpoint singletonI)
[PROOF STATE]
proof (state)
this:
d (inv d' y') \<noteq> x \<and> d' (inv d y) \<noteq> x

goal (1 subgoal):
 1. \<And>x. d x = d' x
[PROOF STEP]
from eq
[PROOF STATE]
proof (chain)
picking this:
d(x := y, inv d y := x) = d'(x := y', inv d' y' := x)
[PROOF STEP]
have "(d(x := y, inv d y := x)) z = (d'(x := y', inv d' y' := x)) z"
[PROOF STATE]
proof (prove)
using this:
d(x := y, inv d y := x) = d'(x := y', inv d' y' := x)

goal (1 subgoal):
 1. (d(x := y, inv d y := x)) z = (d'(x := y', inv d' y' := x)) z
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(d(x := y, inv d y := x)) z = (d'(x := y', inv d' y' := x)) z

goal (1 subgoal):
 1. \<And>x. d x = d' x
[PROOF STEP]
from y d_x d_d neq this
[PROOF STATE]
proof (chain)
picking this:
y = y'
d x = d' x
d (inv d y) = y
d' (inv d' y') = y'
d (inv d' y') \<noteq> x \<and> d' (inv d y) \<noteq> x
(d(x := y, inv d y := x)) z = (d'(x := y', inv d' y' := x)) z
[PROOF STEP]
show "d z = d' z"
[PROOF STATE]
proof (prove)
using this:
y = y'
d x = d' x
d (inv d y) = y
d' (inv d' y') = y'
d (inv d' y') \<noteq> x \<and> d' (inv d y) \<noteq> x
(d(x := y, inv d y := x)) z = (d'(x := y', inv d' y' := x)) z

goal (1 subgoal):
 1. d z = d' z
[PROOF STEP]
by (auto split: if_split_asm)
[PROOF STATE]
proof (state)
this:
d z = d' z

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
d = d'

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from y this
[PROOF STATE]
proof (chain)
picking this:
y = y'
d = d'
[PROOF STEP]
have "y = y' & d = d'"
[PROOF STATE]
proof (prove)
using this:
y = y'
d = d'

goal (1 subgoal):
 1. y = y' \<and> d = d'
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
y = y' \<and> d = d'

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
}
[PROOF STATE]
proof (state)
this:
\<lbrakk>?d2 \<in> derangements (S - {x}); ?d'2 \<in> derangements (S - {x}); ?y2 \<in> S; ?y2 \<noteq> x; ?y'2 \<in> S; ?y'2 \<noteq> x; ?d2(x := ?y2, inv ?d2 ?y2 := x) = ?d'2(x := ?y'2, inv ?d'2 ?y'2 := x)\<rbrakk> \<Longrightarrow> ?y2 = ?y'2 \<and> ?d2 = ?d'2

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>?d2 \<in> derangements (S - {x}); ?d'2 \<in> derangements (S - {x}); ?y2 \<in> S; ?y2 \<noteq> x; ?y'2 \<in> S; ?y'2 \<noteq> x; ?d2(x := ?y2, inv ?d2 ?y2 := x) = ?d'2(x := ?y'2, inv ?d'2 ?y'2 := x)\<rbrakk> \<Longrightarrow> ?y2 = ?y'2 \<and> ?d2 = ?d'2
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?d2 \<in> derangements (S - {x}); ?d'2 \<in> derangements (S - {x}); ?y2 \<in> S; ?y2 \<noteq> x; ?y'2 \<in> S; ?y'2 \<noteq> x; ?d2(x := ?y2, inv ?d2 ?y2 := x) = ?d'2(x := ?y'2, inv ?d'2 ?y'2 := x)\<rbrakk> \<Longrightarrow> ?y2 = ?y'2 \<and> ?d2 = ?d'2

goal (1 subgoal):
 1. inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
unfolding inj_on_def
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?d2 \<in> derangements (S - {x}); ?d'2 \<in> derangements (S - {x}); ?y2 \<in> S; ?y2 \<noteq> x; ?y'2 \<in> S; ?y'2 \<noteq> x; ?d2(x := ?y2, inv ?d2 ?y2 := x) = ?d'2(x := ?y'2, inv ?d'2 ?y'2 := x)\<rbrakk> \<Longrightarrow> ?y2 = ?y'2 \<and> ?d2 = ?d'2

goal (1 subgoal):
 1. \<forall>xa\<in>(S - {x}) \<times> derangements (S - {x}). \<forall>y\<in>(S - {x}) \<times> derangements (S - {x}). (case xa of (y, f) \<Rightarrow> f(x := y, inv f y := x)) = (case y of (y, f) \<Rightarrow> f(x := y, inv f y := x)) \<longrightarrow> xa = y
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from 3(3) 3(1)[OF _ card2]
[PROOF STATE]
proof (chain)
picking this:
finite S
finite (S - {x}) \<Longrightarrow> card (derangements (S - {x})) = count_derangements (Suc n)
[PROOF STEP]
have card3: "card (derangements (S - {x})) = count_derangements (Suc n)"
[PROOF STATE]
proof (prove)
using this:
finite S
finite (S - {x}) \<Longrightarrow> card (derangements (S - {x})) = count_derangements (Suc n)

goal (1 subgoal):
 1. card (derangements (S - {x})) = count_derangements (Suc n)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
card (derangements (S - {x})) = count_derangements (Suc n)

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from 3(3) inj_2
[PROOF STATE]
proof (chain)
picking this:
finite S
inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))
[PROOF STEP]
have card_2: "card ?D2 = (Suc n) * count_derangements (Suc n)"
[PROOF STATE]
proof (prove)
using this:
finite S
inj_on (\<lambda>(y, f). f(x := y, inv f y := x)) ((S - {x}) \<times> derangements (S - {x}))

goal (1 subgoal):
 1. card ((\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))) = Suc n * count_derangements (Suc n)
[PROOF STEP]
by (simp only: card_image) (auto simp add: card_cartesian_product card3 card2)
[PROOF STATE]
proof (state)
this:
card ((\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x}))) = Suc n * count_derangements (Suc n)

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from \<open>finite S\<close>
[PROOF STATE]
proof (chain)
picking this:
finite S
[PROOF STEP]
have finite1: "finite ?D1"
[PROOF STATE]
proof (prove)
using this:
finite S

goal (1 subgoal):
 1. finite ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})})
[PROOF STEP]
unfolding eq'
[PROOF STATE]
proof (prove)
using this:
finite S

goal (1 subgoal):
 1. finite ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` (SIGMA y:S - {x}. derangements (S - {x, y})))
[PROOF STEP]
by (auto intro: finite_derangements)
[PROOF STATE]
proof (state)
this:
finite ((\<lambda>(y, d). d \<circ> Transposition.transpose x y) ` {(y, d). y \<in> S \<and> y \<noteq> x \<and> d \<in> derangements (S - {x, y})})

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
from \<open>finite S\<close>
[PROOF STATE]
proof (chain)
picking this:
finite S
[PROOF STEP]
have finite2: "finite ?D2"
[PROOF STATE]
proof (prove)
using this:
finite S

goal (1 subgoal):
 1. finite ((\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})))
[PROOF STEP]
by (auto intro: finite_cartesian_product finite_derangements)
[PROOF STATE]
proof (state)
this:
finite ((\<lambda>(y, f). f(x := y, inv f y := x)) ` ((S - {x}) \<times> derangements (S - {x})))

goal (1 subgoal):
 1. \<And>n S. \<lbrakk>\<And>S. \<lbrakk>finite S; card S = Suc n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc n); \<And>S. \<lbrakk>finite S; card S = n\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements n; finite S; card S = Suc (Suc n)\<rbrakk> \<Longrightarrow> card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (derangements S) = count_derangements (Suc (Suc n))
[PROOF STEP]
by (simp add: split card_Un_disjoint finite1 finite2 no_intersect card_1 card_2 field_simps)
[PROOF STATE]
proof (state)
this:
card (derangements S) = count_derangements (Suc (Suc n))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma inner_conv_angle: "(a - b) \<bullet> (c - b) = dist a b * dist c b * cos (angle a b c)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a - b) \<bullet> (c - b) = dist a b * dist c b * cos (angle a b c)
[PROOF STEP]
by (simp add: cos_angle)


[STATEMENT]
lemma DERIV_odd_real_root:
  assumes n: "odd n"
    and x: "x \<noteq> 0"
  shows "DERIV (root n) x :> inverse (real n * root n x ^ (n - Suc 0))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (root n has_real_derivative inverse (real n * root n x ^ (n - Suc 0))) (at x)
[PROOF STEP]
proof (rule DERIV_inverse_function)
[PROOF STATE]
proof (state)
goal (6 subgoals):
 1. (?f has_real_derivative real n * root n x ^ (n - Suc 0)) (at (root n x))
 2. real n * root n x ^ (n - Suc 0) \<noteq> 0
 3. ?a < x
 4. x < ?b
 5. \<And>y. \<lbrakk>?a < y; y < ?b\<rbrakk> \<Longrightarrow> ?f (root n y) = y
 6. isCont (root n) x
[PROOF STEP]
show "x - 1 < x" "x < x + 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x - 1 < x &&& x < x + 1
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
x - 1 < x
x < x + 1

goal (4 subgoals):
 1. (?f has_real_derivative real n * root n x ^ (n - Suc 0)) (at (root n x))
 2. real n * root n x ^ (n - Suc 0) \<noteq> 0
 3. \<And>y. \<lbrakk>x - 1 < y; y < x + 1\<rbrakk> \<Longrightarrow> ?f (root n y) = y
 4. isCont (root n) x
[PROOF STEP]
show "DERIV (\<lambda>x. x ^ n) (root n x) :> real n * root n x ^ (n - Suc 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. x ^ n) has_real_derivative real n * root n x ^ (n - Suc 0)) (at (root n x))
[PROOF STEP]
by (rule DERIV_pow)
[PROOF STATE]
proof (state)
this:
((\<lambda>x. x ^ n) has_real_derivative real n * root n x ^ (n - Suc 0)) (at (root n x))

goal (3 subgoals):
 1. real n * root n x ^ (n - Suc 0) \<noteq> 0
 2. \<And>y. \<lbrakk>x - 1 < y; y < x + 1\<rbrakk> \<Longrightarrow> root n y ^ n = y
 3. isCont (root n) x
[PROOF STEP]
show "real n * root n x ^ (n - Suc 0) \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real n * root n x ^ (n - Suc 0) \<noteq> 0
[PROOF STEP]
using odd_pos [OF n] x
[PROOF STATE]
proof (prove)
using this:
0 < n
x \<noteq> 0

goal (1 subgoal):
 1. real n * root n x ^ (n - Suc 0) \<noteq> 0
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
real n * root n x ^ (n - Suc 0) \<noteq> 0

goal (2 subgoals):
 1. \<And>y. \<lbrakk>x - 1 < y; y < x + 1\<rbrakk> \<Longrightarrow> root n y ^ n = y
 2. isCont (root n) x
[PROOF STEP]
show "isCont (root n) x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. isCont (root n) x
[PROOF STEP]
by (rule isCont_real_root)
[PROOF STATE]
proof (state)
this:
isCont (root n) x

goal (1 subgoal):
 1. \<And>y. \<lbrakk>x - 1 < y; y < x + 1\<rbrakk> \<Longrightarrow> root n y ^ n = y
[PROOF STEP]
qed (use n odd_real_root_pow in auto)


[STATEMENT]
lemma USUP_list_conv:
  "(\<Squnion> i \<in> {0..<length(xs)} \<bullet> f (xs ! i)) = foldr (\<and>) (map f xs) true"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Squnion> i \<in> dom\<^sub>l xs \<bullet> f (xs ! i)) = foldr (\<and>) (map f xs) true
[PROOF STEP]
apply (induct xs)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. (\<Squnion> i \<in> dom\<^sub>l [] \<bullet> f ([] ! i)) = foldr (\<and>) (map f []) true
 2. \<And>a xs. (\<Squnion> i \<in> dom\<^sub>l xs \<bullet> f (xs ! i)) = foldr (\<and>) (map f xs) true \<Longrightarrow> (\<Squnion> i \<in> dom\<^sub>l (a # xs) \<bullet> f ((a # xs) ! i)) = foldr (\<and>) (map f (a # xs)) true
[PROOF STEP]
apply (rel_auto)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a xs. (\<Squnion> i \<in> dom\<^sub>l xs \<bullet> f (xs ! i)) = foldr (\<and>) (map f xs) true \<Longrightarrow> (\<Squnion> i \<in> dom\<^sub>l (a # xs) \<bullet> f ((a # xs) ! i)) = foldr (\<and>) (map f (a # xs)) true
[PROOF STEP]
apply (simp_all add: USUP_upto_expand_first USUP_Suc_shift)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma pac_ideal_idemp: \<open>pac_ideal (pac_ideal A) = pac_ideal A\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pac_ideal (pac_ideal A) = pac_ideal A
[PROOF STEP]
by (metis dual_order.antisym ideal.span_subset_spanI ideal.span_superset le_sup_iff pac_ideal_def)


[STATEMENT]
lemma inner_axis: "inner x (axis i y) = inner (x $ i) y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inner x (axis i y) = inner (x $ i) y
[PROOF STEP]
by (simp add: inner_vec_def axis_def sum.remove [where x=i])


[STATEMENT]
lemma mat_mult_scalar: "A ** B = mk_mat (\<lambda> i j. scalar_product (row i A) (column j B))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A ** B = HMA_Connect.mk_mat (\<lambda>i j. scalar_product (row i A) (column j B))
[PROOF STEP]
unfolding vec_eq_iff matrix_matrix_mult_def scalar_product_def mk_mat_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>i ia. (\<chi>i j. \<Sum>k\<in>UNIV. A $h i $h k * B $h k $h j) $h i $h ia = (\<chi>i j. \<Sum>ia\<in>UNIV. row i A $h ia * column j B $h ia) $h i $h ia
[PROOF STEP]
by (auto simp: row_def column_def)


[STATEMENT]
lemma filter_odd_nth: "2*j < l \<Longrightarrow> 2*x = l \<Longrightarrow> (filter odd [0..<l] ! j) = (2*j+1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>2 * j < l; 2 * x = l\<rbrakk> \<Longrightarrow> filter odd [0..<l] ! j = 2 * j + 1
[PROOF STEP]
using filter_odd_map[of x] nth_map[of j "filter even [0..<l]" "(*) 2"]
[PROOF STATE]
proof (prove)
using this:
filter odd [0..<2 * x] = map (\<lambda>y. 2 * y + 1) [0..<x]
j < length (filter even [0..<l]) \<Longrightarrow> map ((*) 2) (filter even [0..<l]) ! j = 2 * filter even [0..<l] ! j

goal (1 subgoal):
 1. \<lbrakk>2 * j < l; 2 * x = l\<rbrakk> \<Longrightarrow> filter odd [0..<l] ! j = 2 * j + 1
[PROOF STEP]
by auto


[STATEMENT]
lemma SUP_img_rule_complete:
  "(\<forall>x. x\<in>S \<longrightarrow> f x \<le> SPEC \<Phi>) \<longleftrightarrow> Sup (f ` S) \<le> SPEC \<Phi>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<forall>x. x \<in> S \<longrightarrow> f x \<le> SPEC \<Phi>) = (Sup (f ` S) \<le> SPEC \<Phi>)
[PROOF STEP]
using Sup_img_rule_complete [of S f]
[PROOF STATE]
proof (prove)
using this:
(\<forall>x. x \<in> S \<longrightarrow> f x \<le> SPEC ?\<Phi>) = (Sup (f ` S) \<le> SPEC ?\<Phi>)

goal (1 subgoal):
 1. (\<forall>x. x \<in> S \<longrightarrow> f x \<le> SPEC \<Phi>) = (Sup (f ` S) \<le> SPEC \<Phi>)
[PROOF STEP]
by simp


[STATEMENT]
lemma powrat_zero_eq_one [simp]: "x pow\<^sub>\<rat> 0 = 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x pow\<^sub>\<rat> 0 = 1
[PROOF STEP]
by (simp add: powrat_def)


[STATEMENT]
lemma isCont_powser_converges_everywhere:
  fixes K x :: "'a::{real_normed_field,banach}"
  assumes "\<And>y. summable (\<lambda>n. c n * y ^ n)"
  shows "isCont (\<lambda>x. \<Sum>n. c n * x^n) x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. isCont (\<lambda>x. \<Sum>n. c n * x ^ n) x
[PROOF STEP]
using termdiffs_strong[OF assms[of "of_real (norm x + 1)"], of x]
[PROOF STATE]
proof (prove)
using this:
norm x < norm (of_real (norm x + 1)) \<Longrightarrow> ((\<lambda>x. \<Sum>n. c n * x ^ n) has_field_derivative (\<Sum>n. diffs c n * x ^ n)) (at x)

goal (1 subgoal):
 1. isCont (\<lambda>x. \<Sum>n. c n * x ^ n) x
[PROOF STEP]
by (force intro!: DERIV_isCont simp del: of_real_add)


[STATEMENT]
lemma "filterlim (\<lambda>x::real. (x - 4) / (sqrt x - 2)) (nhds 4) (at 4)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>x. (x - 4) / (sqrt x - 2)) \<midarrow>4\<rightarrow> 4
[PROOF STEP]
by real_asymp


[STATEMENT]
lemma ac_comp_fun_commute:
  assumes "\<And> x y. f x y = f y x" and "\<And> x y z. f x (f y z) = f (f x y) z"
  shows "comp_fun_commute f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. comp_fun_commute f
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
f ?x ?y = f ?y ?x
f ?x (f ?y ?z) = f (f ?x ?y) ?z

goal (1 subgoal):
 1. comp_fun_commute f
[PROOF STEP]
unfolding comp_fun_commute_def
[PROOF STATE]
proof (prove)
using this:
f ?x ?y = f ?y ?x
f ?x (f ?y ?z) = f (f ?x ?y) ?z

goal (1 subgoal):
 1. \<forall>y x. f y \<circ> f x = f x \<circ> f y
[PROOF STEP]
by (auto simp: comp_def) fastforce


[STATEMENT]
lemma sin_paired: "(\<lambda>n. (- 1) ^ n / (fact (2 * n + 1)) * x ^ (2 * n + 1)) sums  sin x"
  for x :: real
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. (- 1) ^ n / fact (2 * n + 1) * x ^ (2 * n + 1)) sums sin x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<lambda>n. (- 1) ^ n / fact (2 * n + 1) * x ^ (2 * n + 1)) sums sin x
[PROOF STEP]
have "(\<lambda>n. \<Sum>k = n*2..<n * 2 + 2. sin_coeff k * x ^ k) sums sin x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. sin_coeff k * x ^ k) sums sin x
[PROOF STEP]
by (rule sums_group) (use sin_converges [of x, unfolded scaleR_conv_of_real] in auto)
[PROOF STATE]
proof (state)
this:
(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. sin_coeff k * x ^ k) sums sin x

goal (1 subgoal):
 1. (\<lambda>n. (- 1) ^ n / fact (2 * n + 1) * x ^ (2 * n + 1)) sums sin x
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. sin_coeff k * x ^ k) sums sin x
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. sin_coeff k * x ^ k) sums sin x

goal (1 subgoal):
 1. (\<lambda>n. (- 1) ^ n / fact (2 * n + 1) * x ^ (2 * n + 1)) sums sin x
[PROOF STEP]
by (simp add: sin_coeff_def ac_simps)
[PROOF STATE]
proof (state)
this:
(\<lambda>n. (- 1) ^ n / fact (2 * n + 1) * x ^ (2 * n + 1)) sums sin x

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma power_smallo_exponential:
  fixes b :: real
  assumes b: "b > 1"
  shows "(\<lambda>x. x powr n) \<in> o(\<lambda>x. b powr x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>x. x powr n) \<in> o((powr) b)
[PROOF STEP]
proof (rule smalloI_tendsto)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
 2. \<forall>\<^sub>F x in at_top. b powr x \<noteq> 0
[PROOF STEP]
from assms
[PROOF STATE]
proof (chain)
picking this:
1 < b
[PROOF STEP]
have "filterlim (\<lambda>x. x * ln b - n * ln x) at_top at_top"
[PROOF STATE]
proof (prove)
using this:
1 < b

goal (1 subgoal):
 1. LIM x at_top. x * ln b - n * ln x :> at_top
[PROOF STEP]
using [[simproc add: simplify_landau_sum]]
[PROOF STATE]
proof (prove)
using this:
1 < b

goal (1 subgoal):
 1. LIM x at_top. x * ln b - n * ln x :> at_top
[PROOF STEP]
by (simp add: filterlim_at_top_iff_smallomega eventually_nonzero_simps)
[PROOF STATE]
proof (state)
this:
LIM x at_top. x * ln b - n * ln x :> at_top

goal (2 subgoals):
 1. ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
 2. \<forall>\<^sub>F x in at_top. b powr x \<noteq> 0
[PROOF STEP]
hence "((\<lambda>x. exp (-(x * ln b - n * ln x))) \<longlongrightarrow> 0) at_top" (is ?A)
[PROOF STATE]
proof (prove)
using this:
LIM x at_top. x * ln b - n * ln x :> at_top

goal (1 subgoal):
 1. ((\<lambda>x. exp (- (x * ln b - n * ln x))) \<longlongrightarrow> 0) at_top
[PROOF STEP]
by (intro filterlim_compose[OF exp_at_bot]
              filterlim_compose[OF filterlim_uminus_at_bot_at_top])
[PROOF STATE]
proof (state)
this:
((\<lambda>x. exp (- (x * ln b - n * ln x))) \<longlongrightarrow> 0) at_top

goal (2 subgoals):
 1. ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
 2. \<forall>\<^sub>F x in at_top. b powr x \<noteq> 0
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
((\<lambda>x. exp (- (x * ln b - n * ln x))) \<longlongrightarrow> 0) at_top

goal (2 subgoals):
 1. ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
 2. \<forall>\<^sub>F x in at_top. b powr x \<noteq> 0
[PROOF STEP]
have "?A \<longleftrightarrow> ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. exp (- (x * ln b - n * ln x))) \<longlongrightarrow> 0) at_top = ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
[PROOF STEP]
using b eventually_gt_at_top[of 0]
[PROOF STATE]
proof (prove)
using this:
1 < b
eventually ((<) (0::?'a1)) at_top

goal (1 subgoal):
 1. ((\<lambda>x. exp (- (x * ln b - n * ln x))) \<longlongrightarrow> 0) at_top = ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
[PROOF STEP]
by (intro tendsto_cong)
       (auto simp: exp_diff powr_def field_simps exp_of_nat_mult elim: eventually_mono)
[PROOF STATE]
proof (state)
this:
((\<lambda>x. exp (- (x * ln b - n * ln x))) \<longlongrightarrow> 0) at_top = ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top

goal (2 subgoals):
 1. ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
 2. \<forall>\<^sub>F x in at_top. b powr x \<noteq> 0
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
[PROOF STEP]
show "((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top"
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top

goal (1 subgoal):
 1. ((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
((\<lambda>x. x powr n / b powr x) \<longlongrightarrow> 0) at_top

goal (1 subgoal):
 1. \<forall>\<^sub>F x in at_top. b powr x \<noteq> 0
[PROOF STEP]
qed (insert assms, simp_all add: eventually_nonzero_simps)


[STATEMENT]
lemma cos_le_zero': "x \<in> {-3*pi/2..-pi/2} \<Longrightarrow> cos x \<le> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<in> {- 3 * pi / 2..- pi / 2} \<Longrightarrow> cos x \<le> 0
[PROOF STEP]
using cos_le_zero[of "-x"]
[PROOF STATE]
proof (prove)
using this:
- x \<in> {pi / 2..3 * pi / 2} \<Longrightarrow> cos (- x) \<le> 0

goal (1 subgoal):
 1. x \<in> {- 3 * pi / 2..- pi / 2} \<Longrightarrow> cos x \<le> 0
[PROOF STEP]
by simp


[STATEMENT]
lemma mod_eq_dvd_iff_poly: "((x::'a mod_ring poly) mod n = y mod n) = (n dvd x - y)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x mod n = y mod n) = (n dvd x - y)
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. x mod n = y mod n \<Longrightarrow> n dvd x - y
 2. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
assume H: "x mod n = y mod n"
[PROOF STATE]
proof (state)
this:
x mod n = y mod n

goal (2 subgoals):
 1. x mod n = y mod n \<Longrightarrow> n dvd x - y
 2. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
hence "x mod n - y mod n = 0"
[PROOF STATE]
proof (prove)
using this:
x mod n = y mod n

goal (1 subgoal):
 1. x mod n - y mod n = 0
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
x mod n - y mod n = 0

goal (2 subgoals):
 1. x mod n = y mod n \<Longrightarrow> n dvd x - y
 2. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
hence "(x mod n - y mod n) mod n = 0"
[PROOF STATE]
proof (prove)
using this:
x mod n - y mod n = 0

goal (1 subgoal):
 1. (x mod n - y mod n) mod n = 0
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(x mod n - y mod n) mod n = 0

goal (2 subgoals):
 1. x mod n = y mod n \<Longrightarrow> n dvd x - y
 2. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
hence "(x - y) mod n = 0"
[PROOF STATE]
proof (prove)
using this:
(x mod n - y mod n) mod n = 0

goal (1 subgoal):
 1. (x - y) mod n = 0
[PROOF STEP]
by (simp add: mod_diff_eq)
[PROOF STATE]
proof (state)
this:
(x - y) mod n = 0

goal (2 subgoals):
 1. x mod n = y mod n \<Longrightarrow> n dvd x - y
 2. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
thus "n dvd x - y"
[PROOF STATE]
proof (prove)
using this:
(x - y) mod n = 0

goal (1 subgoal):
 1. n dvd x - y
[PROOF STEP]
by (simp add: dvd_eq_mod_eq_0)
[PROOF STATE]
proof (state)
this:
n dvd x - y

goal (1 subgoal):
 1. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
assume H: "n dvd x - y"
[PROOF STATE]
proof (state)
this:
n dvd x - y

goal (1 subgoal):
 1. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
n dvd x - y
[PROOF STEP]
obtain k where k: "x-y = n*k"
[PROOF STATE]
proof (prove)
using this:
n dvd x - y

goal (1 subgoal):
 1. (\<And>k. x - y = n * k \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
unfolding dvd_def
[PROOF STATE]
proof (prove)
using this:
\<exists>k. x - y = n * k

goal (1 subgoal):
 1. (\<And>k. x - y = n * k \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
x - y = n * k

goal (1 subgoal):
 1. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
hence "x = n*k + y"
[PROOF STATE]
proof (prove)
using this:
x - y = n * k

goal (1 subgoal):
 1. x = n * k + y
[PROOF STEP]
using diff_eq_eq
[PROOF STATE]
proof (prove)
using this:
x - y = n * k
(?a - ?b = ?c) = (?a = ?c + ?b)

goal (1 subgoal):
 1. x = n * k + y
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
x = n * k + y

goal (1 subgoal):
 1. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
hence "x mod n = (n*k + y) mod n"
[PROOF STATE]
proof (prove)
using this:
x = n * k + y

goal (1 subgoal):
 1. x mod n = (n * k + y) mod n
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
x mod n = (n * k + y) mod n

goal (1 subgoal):
 1. n dvd x - y \<Longrightarrow> x mod n = y mod n
[PROOF STEP]
thus "x mod n = y mod n"
[PROOF STATE]
proof (prove)
using this:
x mod n = (n * k + y) mod n

goal (1 subgoal):
 1. x mod n = y mod n
[PROOF STEP]
by (simp add: mod_add_left_eq)
[PROOF STATE]
proof (state)
this:
x mod n = y mod n

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma nth_root_nat_mono:
  assumes "m \<le> n"
  shows   "nth_root_nat k m \<le> nth_root_nat k n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_root_nat k m \<le> nth_root_nat k n
[PROOF STEP]
proof (cases "k = 0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. k = 0 \<Longrightarrow> nth_root_nat k m \<le> nth_root_nat k n
 2. k \<noteq> 0 \<Longrightarrow> nth_root_nat k m \<le> nth_root_nat k n
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
k \<noteq> 0

goal (2 subgoals):
 1. k = 0 \<Longrightarrow> nth_root_nat k m \<le> nth_root_nat k n
 2. k \<noteq> 0 \<Longrightarrow> nth_root_nat k m \<le> nth_root_nat k n
[PROOF STEP]
with assms
[PROOF STATE]
proof (chain)
picking this:
m \<le> n
k \<noteq> 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
m \<le> n
k \<noteq> 0

goal (1 subgoal):
 1. nth_root_nat k m \<le> nth_root_nat k n
[PROOF STEP]
unfolding nth_root_nat_def
[PROOF STATE]
proof (prove)
using this:
m \<le> n
k \<noteq> 0

goal (1 subgoal):
 1. (if k = 0 then 0 else Max {ma. ma ^ k \<le> m}) \<le> (if k = 0 then 0 else Max {m. m ^ k \<le> n})
[PROOF STEP]
using nth_root_nat_aux2[of k m] nth_root_nat_aux2[of k n]
[PROOF STATE]
proof (prove)
using this:
m \<le> n
k \<noteq> 0
0 < k \<Longrightarrow> finite {ma. ma ^ k \<le> m}
0 < k \<Longrightarrow> {ma. ma ^ k \<le> m} \<noteq> {}
0 < k \<Longrightarrow> finite {m. m ^ k \<le> n}
0 < k \<Longrightarrow> {m. m ^ k \<le> n} \<noteq> {}

goal (1 subgoal):
 1. (if k = 0 then 0 else Max {ma. ma ^ k \<le> m}) \<le> (if k = 0 then 0 else Max {m. m ^ k \<le> n})
[PROOF STEP]
by (auto intro!: Max_mono)
[PROOF STATE]
proof (state)
this:
nth_root_nat k m \<le> nth_root_nat k n

goal (1 subgoal):
 1. k = 0 \<Longrightarrow> nth_root_nat k m \<le> nth_root_nat k n
[PROOF STEP]
qed auto


[STATEMENT]
lemma mod_type_forall_eq [simp]: "(\<forall>j::'a. (to_nat j)<CARD('a) \<longrightarrow> P j) = (\<forall>a. P a)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<forall>j. mod_type_class.to_nat j < CARD('a) \<longrightarrow> P j) = (\<forall>a. P a)
[PROOF STEP]
proof (auto)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a. \<forall>j. mod_type_class.to_nat j < CARD('a) \<longrightarrow> P j \<Longrightarrow> P a
[PROOF STEP]
fix a
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a. \<forall>j. mod_type_class.to_nat j < CARD('a) \<longrightarrow> P j \<Longrightarrow> P a
[PROOF STEP]
assume a: "\<forall>j. (to_nat::'a=>nat) j < CARD('a) \<longrightarrow> P j"
[PROOF STATE]
proof (state)
this:
\<forall>j. mod_type_class.to_nat j < CARD('a) \<longrightarrow> P j

goal (1 subgoal):
 1. \<And>a. \<forall>j. mod_type_class.to_nat j < CARD('a) \<longrightarrow> P j \<Longrightarrow> P a
[PROOF STEP]
have "(to_nat::'a=>nat) a < CARD('a)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mod_type_class.to_nat a < CARD('a)
[PROOF STEP]
using bij_to_nat
[PROOF STATE]
proof (prove)
using this:
bij_betw mod_type_class.to_nat UNIV {0..<CARD('a)}

goal (1 subgoal):
 1. mod_type_class.to_nat a < CARD('a)
[PROOF STEP]
unfolding bij_betw_def
[PROOF STATE]
proof (prove)
using this:
inj mod_type_class.to_nat \<and> range mod_type_class.to_nat = {0..<CARD('a)}

goal (1 subgoal):
 1. mod_type_class.to_nat a < CARD('a)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
mod_type_class.to_nat a < CARD('a)

goal (1 subgoal):
 1. \<And>a. \<forall>j. mod_type_class.to_nat j < CARD('a) \<longrightarrow> P j \<Longrightarrow> P a
[PROOF STEP]
thus "P a"
[PROOF STATE]
proof (prove)
using this:
mod_type_class.to_nat a < CARD('a)

goal (1 subgoal):
 1. P a
[PROOF STEP]
using a
[PROOF STATE]
proof (prove)
using this:
mod_type_class.to_nat a < CARD('a)
\<forall>j. mod_type_class.to_nat j < CARD('a) \<longrightarrow> P j

goal (1 subgoal):
 1. P a
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
P a

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma sublist_snoc: \<open>lo < hi \<Longrightarrow> hi < length xs \<Longrightarrow> sublist xs lo hi = sublist xs lo (hi-1) @ [xs!hi]\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>lo < hi; hi < length xs\<rbrakk> \<Longrightarrow> WB_Sort.sublist xs lo hi = WB_Sort.sublist xs lo (hi - 1) @ [xs ! hi]
[PROOF STEP]
apply (simp add: sublist_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>lo < hi; hi < length xs\<rbrakk> \<Longrightarrow> take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>lo < hi; hi < length xs\<rbrakk> \<Longrightarrow> take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]
[PROOF STEP]
assume a1: "lo < hi"
[PROOF STATE]
proof (state)
this:
lo < hi

goal (1 subgoal):
 1. \<lbrakk>lo < hi; hi < length xs\<rbrakk> \<Longrightarrow> take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]
[PROOF STEP]
assume "hi < length xs"
[PROOF STATE]
proof (state)
this:
hi < length xs

goal (1 subgoal):
 1. \<lbrakk>lo < hi; hi < length xs\<rbrakk> \<Longrightarrow> take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
hi < length xs
[PROOF STEP]
have "take lo xs @ take (Suc hi - lo) (drop lo xs) = (take lo xs @ take (hi - lo) (drop lo xs)) @ [xs ! hi]"
[PROOF STATE]
proof (prove)
using this:
hi < length xs

goal (1 subgoal):
 1. take lo xs @ take (Suc hi - lo) (drop lo xs) = (take lo xs @ take (hi - lo) (drop lo xs)) @ [xs ! hi]
[PROOF STEP]
using a1
[PROOF STATE]
proof (prove)
using this:
hi < length xs
lo < hi

goal (1 subgoal):
 1. take lo xs @ take (Suc hi - lo) (drop lo xs) = (take lo xs @ take (hi - lo) (drop lo xs)) @ [xs ! hi]
[PROOF STEP]
by (metis (no_types) Suc_diff_le add_Suc_right hd_drop_conv_nth le_add_diff_inverse less_imp_le_nat take_add take_hd_drop)
[PROOF STATE]
proof (state)
this:
take lo xs @ take (Suc hi - lo) (drop lo xs) = (take lo xs @ take (hi - lo) (drop lo xs)) @ [xs ! hi]

goal (1 subgoal):
 1. \<lbrakk>lo < hi; hi < length xs\<rbrakk> \<Longrightarrow> take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
take lo xs @ take (Suc hi - lo) (drop lo xs) = (take lo xs @ take (hi - lo) (drop lo xs)) @ [xs ! hi]
[PROOF STEP]
show "take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]"
[PROOF STATE]
proof (prove)
using this:
take lo xs @ take (Suc hi - lo) (drop lo xs) = (take lo xs @ take (hi - lo) (drop lo xs)) @ [xs ! hi]

goal (1 subgoal):
 1. take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
take (Suc hi - lo) (drop lo xs) = take (hi - lo) (drop lo xs) @ [xs ! hi]

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma N_row_list_map: "i < \<v> \<Longrightarrow>
    row N i = map_vec (\<lambda> bl . if ((\<V>s ! i) \<in> bl) then 1 else 0) (vec_of_list \<B>s)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i < \<v> \<Longrightarrow> row N i = map_vec (\<lambda>bl. if \<V>s ! i \<in> bl then 1 else 0) (vec_of_list \<B>s)
[PROOF STEP]
by (simp add: inc_mat_row_list_map points_list_length blocks_list_length)


[STATEMENT]
lemma prime_square_sum_nat_decomp_code [code]:
  "prime_square_sum_nat_decomp p =
     (if prime p \<and> (p = 2 \<or> [p = 1] (mod 4))
      then the_elem (Set.filter (\<lambda>(x,y). x ^ 2 + y ^ 2 = p) (SIGMA x:{0..p}. {x..p}))
      else (0, 0))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. prime_square_sum_nat_decomp p = (if prime p \<and> (p = 2 \<or> [p = 1] (mod 4)) then the_elem (Set.filter (\<lambda>(x, y). x\<^sup>2 + y\<^sup>2 = p) (SIGMA x:{0..p}. {x..p})) else (0, 0))
[PROOF STEP]
using prime_square_sum_nat_decomp_code_aux[of p]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>prime p; p = 2 \<or> [p = 1] (mod 4)\<rbrakk> \<Longrightarrow> prime_square_sum_nat_decomp p = the_elem (Set.filter (\<lambda>(x, y). x\<^sup>2 + y\<^sup>2 = p) (SIGMA x:{0..p}. {x..p}))

goal (1 subgoal):
 1. prime_square_sum_nat_decomp p = (if prime p \<and> (p = 2 \<or> [p = 1] (mod 4)) then the_elem (Set.filter (\<lambda>(x, y). x\<^sup>2 + y\<^sup>2 = p) (SIGMA x:{0..p}. {x..p})) else (0, 0))
[PROOF STEP]
by (auto simp: prime_square_sum_nat_decomp_def)