[STATEMENT]
lemma cindexP_lineE_times:
  fixes p q::"complex poly" and a b::complex
  assumes "poly p a\<noteq>0" "poly p b\<noteq>0" "poly q a\<noteq>0" "poly q b\<noteq>0"
  shows "cindexP_lineE (p*q) a b = cindexP_lineE p a b + cindexP_lineE q a b+cdiff_aux p q a b/2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
define pR pI where "pR = map_poly Re (p \<circ>\<^sub>p [:a, b - a:])"
                 and "pI = map_poly Im (p \<circ>\<^sub>p [:a, b - a:])"
[PROOF STATE]
proof (state)
this:
pR = map_poly Re (p \<circ>\<^sub>p [:a, b - a:])
pI = map_poly Im (p \<circ>\<^sub>p [:a, b - a:])

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
define qR qI where "qR = map_poly Re (q \<circ>\<^sub>p [:a, b - a:])"
                 and "qI = map_poly Im (q \<circ>\<^sub>p [:a, b - a:])"
[PROOF STATE]
proof (state)
this:
qR = map_poly Re (q \<circ>\<^sub>p [:a, b - a:])
qI = map_poly Im (q \<circ>\<^sub>p [:a, b - a:])

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
define P1 P2 where "P1 = pR * qI + pI * qR" and "P2=pR * qR - pI * qI"
[PROOF STATE]
proof (state)
this:
P1 = pR * qI + pI * qR
P2 = pR * qR - pI * qI

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have p_poly:
      "poly pR 0 = Re (poly p a)"
      "poly pI 0 = Im (poly p a)"
      "poly pR 1 = Re (poly p b)"
      "poly pI 1 = Im (poly p b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (poly pR 0 = Re (poly p a) &&& poly pI 0 = Im (poly p a)) &&& poly pR 1 = Re (poly p b) &&& poly pI 1 = Im (poly p b)
[PROOF STEP]
unfolding pR_def pI_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (poly (map_poly Re (p \<circ>\<^sub>p [:a, b - a:])) 0 = Re (poly p a) &&& poly (map_poly Im (p \<circ>\<^sub>p [:a, b - a:])) 0 = Im (poly p a)) &&& poly (map_poly Re (p \<circ>\<^sub>p [:a, b - a:])) 1 = Re (poly p b) &&& poly (map_poly Im (p \<circ>\<^sub>p [:a, b - a:])) 1 = Im (poly p b)
[PROOF STEP]
by (simp flip:Re_poly_of_real Im_poly_of_real add:poly_pcompose)+
[PROOF STATE]
proof (state)
this:
poly pR 0 = Re (poly p a)
poly pI 0 = Im (poly p a)
poly pR 1 = Re (poly p b)
poly pI 1 = Im (poly p b)

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have q_poly:
      "poly qR 0 = Re (poly q a)"
      "poly qI 0 = Im (poly q a)"
      "poly qR 1 = Re (poly q b)"
      "poly qI 1 = Im (poly q b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (poly qR 0 = Re (poly q a) &&& poly qI 0 = Im (poly q a)) &&& poly qR 1 = Re (poly q b) &&& poly qI 1 = Im (poly q b)
[PROOF STEP]
unfolding qR_def qI_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (poly (map_poly Re (q \<circ>\<^sub>p [:a, b - a:])) 0 = Re (poly q a) &&& poly (map_poly Im (q \<circ>\<^sub>p [:a, b - a:])) 0 = Im (poly q a)) &&& poly (map_poly Re (q \<circ>\<^sub>p [:a, b - a:])) 1 = Re (poly q b) &&& poly (map_poly Im (q \<circ>\<^sub>p [:a, b - a:])) 1 = Im (poly q b)
[PROOF STEP]
by (simp flip:Re_poly_of_real Im_poly_of_real add:poly_pcompose)+
[PROOF STATE]
proof (state)
this:
poly qR 0 = Re (poly q a)
poly qI 0 = Im (poly q a)
poly qR 1 = Re (poly q b)
poly qI 1 = Im (poly q b)

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have P2_poly:
       "poly P2 0 = Re (poly (p*q) a)"
       "poly P2 1 = Re (poly (p*q) b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly P2 0 = Re (poly (p * q) a) &&& poly P2 1 = Re (poly (p * q) b)
[PROOF STEP]
unfolding P2_def pR_def qI_def pI_def qR_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly (map_poly Re (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Re (q \<circ>\<^sub>p [:a, b - a:]) - map_poly Im (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Im (q \<circ>\<^sub>p [:a, b - a:])) 0 = Re (poly (p * q) a) &&& poly (map_poly Re (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Re (q \<circ>\<^sub>p [:a, b - a:]) - map_poly Im (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Im (q \<circ>\<^sub>p [:a, b - a:])) 1 = Re (poly (p * q) b)
[PROOF STEP]
by (simp flip:Re_poly_of_real Im_poly_of_real add:poly_pcompose)+
[PROOF STATE]
proof (state)
this:
poly P2 0 = Re (poly (p * q) a)
poly P2 1 = Re (poly (p * q) b)

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have P1_poly:
       "poly P1 0 = Im (poly (p*q) a)"
       "poly P1 1 = Im (poly (p*q) b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly P1 0 = Im (poly (p * q) a) &&& poly P1 1 = Im (poly (p * q) b)
[PROOF STEP]
unfolding P1_def pR_def qI_def pI_def qR_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly (map_poly Re (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Im (q \<circ>\<^sub>p [:a, b - a:]) + map_poly Im (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Re (q \<circ>\<^sub>p [:a, b - a:])) 0 = Im (poly (p * q) a) &&& poly (map_poly Re (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Im (q \<circ>\<^sub>p [:a, b - a:]) + map_poly Im (p \<circ>\<^sub>p [:a, b - a:]) * map_poly Re (q \<circ>\<^sub>p [:a, b - a:])) 1 = Im (poly (p * q) b)
[PROOF STEP]
by (simp flip:Re_poly_of_real Im_poly_of_real add:poly_pcompose)+
[PROOF STATE]
proof (state)
this:
poly P1 0 = Im (poly (p * q) a)
poly P1 1 = Im (poly (p * q) b)

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have p_nzero:"poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0" "poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0 &&& poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0
[PROOF STEP]
unfolding p_poly
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Re (poly p a) \<noteq> 0 \<or> Im (poly p a) \<noteq> 0 &&& Re (poly p b) \<noteq> 0 \<or> Im (poly p b) \<noteq> 0
[PROOF STEP]
using assms(1,2) complex_eqI
[PROOF STATE]
proof (prove)
using this:
poly p a \<noteq> 0
poly p b \<noteq> 0
\<lbrakk>Re ?x = Re ?y; Im ?x = Im ?y\<rbrakk> \<Longrightarrow> ?x = ?y

goal (1 subgoal):
 1. Re (poly p a) \<noteq> 0 \<or> Im (poly p a) \<noteq> 0 &&& Re (poly p b) \<noteq> 0 \<or> Im (poly p b) \<noteq> 0
[PROOF STEP]
by force+
[PROOF STATE]
proof (state)
this:
poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0
poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have q_nzero:"poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0" "poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0 &&& poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0
[PROOF STEP]
unfolding q_poly
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Re (poly q a) \<noteq> 0 \<or> Im (poly q a) \<noteq> 0 &&& Re (poly q b) \<noteq> 0 \<or> Im (poly q b) \<noteq> 0
[PROOF STEP]
using assms(3,4) complex_eqI
[PROOF STATE]
proof (prove)
using this:
poly q a \<noteq> 0
poly q b \<noteq> 0
\<lbrakk>Re ?x = Re ?y; Im ?x = Im ?y\<rbrakk> \<Longrightarrow> ?x = ?y

goal (1 subgoal):
 1. Re (poly q a) \<noteq> 0 \<or> Im (poly q a) \<noteq> 0 &&& Re (poly q b) \<noteq> 0 \<or> Im (poly q b) \<noteq> 0
[PROOF STEP]
by force+
[PROOF STATE]
proof (state)
this:
poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0
poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have P12_nzero:"poly P2 0 \<noteq> 0 \<or> poly P1 0 \<noteq> 0" "poly P2 1 \<noteq> 0 \<or> poly P1 1 \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly P2 0 \<noteq> 0 \<or> poly P1 0 \<noteq> 0 &&& poly P2 1 \<noteq> 0 \<or> poly P1 1 \<noteq> 0
[PROOF STEP]
unfolding P1_poly P2_poly
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Re (poly (p * q) a) \<noteq> 0 \<or> Im (poly (p * q) a) \<noteq> 0 &&& Re (poly (p * q) b) \<noteq> 0 \<or> Im (poly (p * q) b) \<noteq> 0
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
poly p a \<noteq> 0
poly p b \<noteq> 0
poly q a \<noteq> 0
poly q b \<noteq> 0

goal (1 subgoal):
 1. Re (poly (p * q) a) \<noteq> 0 \<or> Im (poly (p * q) a) \<noteq> 0 &&& Re (poly (p * q) b) \<noteq> 0 \<or> Im (poly (p * q) b) \<noteq> 0
[PROOF STEP]
by (metis Im_poly_hom.base.hom_zero Re_poly_hom.base.hom_zero
        complex_eqI poly_mult_zero_iff)+
[PROOF STATE]
proof (state)
this:
poly P2 0 \<noteq> 0 \<or> poly P1 0 \<noteq> 0
poly P2 1 \<noteq> 0 \<or> poly P1 1 \<noteq> 0

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
define C1 C2 where "C1 = (\<lambda>p q. cindex_polyE 0 1 p q)"
                 and "C2 = (\<lambda>p q. real_of_int (cross_alt p q 0 1) /2)"
[PROOF STATE]
proof (state)
this:
C1 = cindex_polyE 0 1
C2 = (\<lambda>p q. real_of_int (cross_alt p q 0 1) / 2)

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
define CR where "CR = C2 P1 (pI * qI) +C2 P2 P1 - C2 pR pI - C2 qR qI"
[PROOF STATE]
proof (state)
this:
CR = C2 P1 (pI * qI) + C2 P2 P1 - C2 pR pI - C2 qR qI

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have "cindexP_lineE (p*q) a b =
          cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI))
              (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
have "p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI
[PROOF STEP]
using cpoly_of_decompose pI_def pR_def
[PROOF STATE]
proof (prove)
using this:
?p = cpoly_of (map_poly Re ?p) (map_poly Im ?p)
pI = map_poly Im (p \<circ>\<^sub>p [:a, b - a:])
pR = map_poly Re (p \<circ>\<^sub>p [:a, b - a:])

goal (1 subgoal):
 1. p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
have "q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI
[PROOF STEP]
using cpoly_of_decompose qI_def qR_def
[PROOF STATE]
proof (prove)
using this:
?p = cpoly_of (map_poly Re ?p) (map_poly Im ?p)
qI = map_poly Im (q \<circ>\<^sub>p [:a, b - a:])
qR = map_poly Re (q \<circ>\<^sub>p [:a, b - a:])

goal (1 subgoal):
 1. q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI
q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI
q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
apply (subst cindexP_lineE_polyE)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI; q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI\<rbrakk> \<Longrightarrow> cindex_polyE 0 1 (map_poly Im ((p * q) \<circ>\<^sub>p [:a, b - a:])) (map_poly Re ((p * q) \<circ>\<^sub>p [:a, b - a:])) = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
unfolding pcompose_mult
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>p \<circ>\<^sub>p [:a, b - a:] = cpoly_of pR pI; q \<circ>\<^sub>p [:a, b - a:] = cpoly_of qR qI\<rbrakk> \<Longrightarrow> cindex_polyE 0 1 (map_poly Im (p \<circ>\<^sub>p [:a, b - a:] * q \<circ>\<^sub>p [:a, b - a:])) (map_poly Re (p \<circ>\<^sub>p [:a, b - a:] * q \<circ>\<^sub>p [:a, b - a:])) = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
cindexP_lineE (p * q) a b = cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI))

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have "... = cindex_polyE 0 1 (pR * qI + pI * qR ) (pR * qR - pI * qI)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI)) = cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI)
[PROOF STEP]
unfolding cpoly_of_times
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 (map_poly Im (cpoly_of (pR * qR - pI * qI) (pI * qR + pR * qI))) (map_poly Re (cpoly_of (pR * qR - pI * qI) (pI * qR + pR * qI))) = cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI)
[PROOF STEP]
by (simp add:algebra_simps)
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI)) = cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI)

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 (map_poly Im (cpoly_of pR pI * cpoly_of qR qI)) (map_poly Re (cpoly_of pR pI * cpoly_of qR qI)) = cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI)

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have "... = cindex_polyE 0 1 P1 P2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI) = cindex_polyE 0 1 P1 P2
[PROOF STEP]
unfolding P1_def P2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI) = cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI) = cindex_polyE 0 1 P1 P2

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 (pR * qI + pI * qR) (pR * qR - pI * qI) = cindex_polyE 0 1 P1 P2

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have "... = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
have "C1 P2 P1 = C1 pR pI + C1 qR qI - C2 P1 (pI * qI)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. C1 P2 P1 = C1 pR pI + C1 qR qI - C2 P1 (pI * qI)
[PROOF STEP]
unfolding P1_def P2_def C1_def C2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 (pR * qR - pI * qI) (pR * qI + pI * qR) = cindex_polyE 0 1 pR pI + cindex_polyE 0 1 qR qI - real_of_int (cross_alt (pR * qI + pI * qR) (pI * qI) 0 1) / 2
[PROOF STEP]
apply (rule cindex_polyE_product)
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. 0 < 1
 2. poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0
 3. poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0
 4. poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0
 5. poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0
[PROOF STEP]
thm cindex_polyE_product
[PROOF STATE]
proof (prove)
goal (5 subgoals):
 1. 0 < 1
 2. poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0
 3. poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0
 4. poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0
 5. poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0
[PROOF STEP]
by simp fact+
[PROOF STATE]
proof (state)
this:
C1 P2 P1 = C1 pR pI + C1 qR qI - C2 P1 (pI * qI)

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
C1 P2 P1 = C1 pR pI + C1 qR qI - C2 P1 (pI * qI)

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
have "C1 P2 P1 = C2 P2 P1 - C1 P1 P2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. C1 P2 P1 = C2 P2 P1 - C1 P1 P2
[PROOF STEP]
unfolding C1_def C2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 P2 P1 = real_of_int (cross_alt P2 P1 0 1) / 2 - cindex_polyE 0 1 P1 P2
[PROOF STEP]
apply (subst cindex_polyE_inverse_add_cross'[symmetric])
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. 0 < 1
 2. poly P2 0 \<noteq> 0 \<or> poly P1 0 \<noteq> 0
 3. poly P2 1 \<noteq> 0 \<or> poly P1 1 \<noteq> 0
 4. cindex_polyE 0 1 P2 P1 = cindex_polyE 0 1 P1 P2 + cindex_polyE 0 1 P2 P1 - cindex_polyE 0 1 P1 P2
[PROOF STEP]
using P12_nzero
[PROOF STATE]
proof (prove)
using this:
poly P2 0 \<noteq> 0 \<or> poly P1 0 \<noteq> 0
poly P2 1 \<noteq> 0 \<or> poly P1 1 \<noteq> 0

goal (4 subgoals):
 1. 0 < 1
 2. poly P2 0 \<noteq> 0 \<or> poly P1 0 \<noteq> 0
 3. poly P2 1 \<noteq> 0 \<or> poly P1 1 \<noteq> 0
 4. cindex_polyE 0 1 P2 P1 = cindex_polyE 0 1 P1 P2 + cindex_polyE 0 1 P2 P1 - cindex_polyE 0 1 P1 P2
[PROOF STEP]
by simp_all
[PROOF STATE]
proof (state)
this:
C1 P2 P1 = C2 P2 P1 - C1 P1 P2

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
C1 P2 P1 = C2 P2 P1 - C1 P1 P2

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
have "C1 pR pI = C2 pR pI - C1 pI pR"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. C1 pR pI = C2 pR pI - C1 pI pR
[PROOF STEP]
unfolding C1_def C2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 pR pI = real_of_int (cross_alt pR pI 0 1) / 2 - cindex_polyE 0 1 pI pR
[PROOF STEP]
apply (subst cindex_polyE_inverse_add_cross'[symmetric])
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. 0 < 1
 2. poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0
 3. poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0
 4. cindex_polyE 0 1 pR pI = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 pR pI - cindex_polyE 0 1 pI pR
[PROOF STEP]
using p_nzero
[PROOF STATE]
proof (prove)
using this:
poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0
poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0

goal (4 subgoals):
 1. 0 < 1
 2. poly pR 0 \<noteq> 0 \<or> poly pI 0 \<noteq> 0
 3. poly pR 1 \<noteq> 0 \<or> poly pI 1 \<noteq> 0
 4. cindex_polyE 0 1 pR pI = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 pR pI - cindex_polyE 0 1 pI pR
[PROOF STEP]
by simp_all
[PROOF STATE]
proof (state)
this:
C1 pR pI = C2 pR pI - C1 pI pR

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
C1 pR pI = C2 pR pI - C1 pI pR

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
have "C1 qR qI = C2 qR qI - C1 qI qR"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. C1 qR qI = C2 qR qI - C1 qI qR
[PROOF STEP]
unfolding C1_def C2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 qR qI = real_of_int (cross_alt qR qI 0 1) / 2 - cindex_polyE 0 1 qI qR
[PROOF STEP]
apply (subst cindex_polyE_inverse_add_cross'[symmetric])
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. 0 < 1
 2. poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0
 3. poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0
 4. cindex_polyE 0 1 qR qI = cindex_polyE 0 1 qI qR + cindex_polyE 0 1 qR qI - cindex_polyE 0 1 qI qR
[PROOF STEP]
using q_nzero
[PROOF STATE]
proof (prove)
using this:
poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0
poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0

goal (4 subgoals):
 1. 0 < 1
 2. poly qR 0 \<noteq> 0 \<or> poly qI 0 \<noteq> 0
 3. poly qR 1 \<noteq> 0 \<or> poly qI 1 \<noteq> 0
 4. cindex_polyE 0 1 qR qI = cindex_polyE 0 1 qI qR + cindex_polyE 0 1 qR qI - cindex_polyE 0 1 qI qR
[PROOF STEP]
by simp_all
[PROOF STATE]
proof (state)
this:
C1 qR qI = C2 qR qI - C1 qI qR

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
C1 P2 P1 = C1 pR pI + C1 qR qI - C2 P1 (pI * qI)
C1 P2 P1 = C2 P2 P1 - C1 P1 P2
C1 pR pI = C2 pR pI - C1 pI pR
C1 qR qI = C2 qR qI - C1 qI qR
[PROOF STEP]
have "C2 P2 P1 - C1 P1 P2 = (C2 pR pI - C1 pI pR)
                        + (C2 qR qI - C1 qI qR) - C2 P1 (pI * qI)"
[PROOF STATE]
proof (prove)
using this:
C1 P2 P1 = C1 pR pI + C1 qR qI - C2 P1 (pI * qI)
C1 P2 P1 = C2 P2 P1 - C1 P1 P2
C1 pR pI = C2 pR pI - C1 pI pR
C1 qR qI = C2 qR qI - C1 qI qR

goal (1 subgoal):
 1. C2 P2 P1 - C1 P1 P2 = C2 pR pI - C1 pI pR + (C2 qR qI - C1 qI qR) - C2 P1 (pI * qI)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
C2 P2 P1 - C1 P1 P2 = C2 pR pI - C1 pI pR + (C2 qR qI - C1 qI qR) - C2 P1 (pI * qI)

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
C2 P2 P1 - C1 P1 P2 = C2 pR pI - C1 pI pR + (C2 qR qI - C1 qI qR) - C2 P1 (pI * qI)
[PROOF STEP]
have "C1 P1 P2 = C1 pI pR + C1 qI qR + CR"
[PROOF STATE]
proof (prove)
using this:
C2 P2 P1 - C1 P1 P2 = C2 pR pI - C1 pI pR + (C2 qR qI - C1 qI qR) - C2 P1 (pI * qI)

goal (1 subgoal):
 1. C1 P1 P2 = C1 pI pR + C1 qI qR + CR
[PROOF STEP]
unfolding CR_def
[PROOF STATE]
proof (prove)
using this:
C2 P2 P1 - C1 P1 P2 = C2 pR pI - C1 pI pR + (C2 qR qI - C1 qI qR) - C2 P1 (pI * qI)

goal (1 subgoal):
 1. C1 P1 P2 = C1 pI pR + C1 qI qR + (C2 P1 (pI * qI) + C2 P2 P1 - C2 pR pI - C2 qR qI)
[PROOF STEP]
by (auto simp:algebra_simps)
[PROOF STATE]
proof (state)
this:
C1 P1 P2 = C1 pI pR + C1 qI qR + CR

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
C1 P1 P2 = C1 pI pR + C1 qI qR + CR
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
C1 P1 P2 = C1 pI pR + C1 qI qR + CR

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
unfolding C1_def
[PROOF STATE]
proof (prove)
using this:
cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR

goal (1 subgoal):
 1. cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 P1 P2 = cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have "... = cindexP_lineE p a b +cindexP_lineE q a b + CR"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR = cindexP_lineE p a b + cindexP_lineE q a b + CR
[PROOF STEP]
unfolding C1_def pI_def pR_def qI_def qR_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 (map_poly Im (p \<circ>\<^sub>p [:a, b - a:])) (map_poly Re (p \<circ>\<^sub>p [:a, b - a:])) + cindex_polyE 0 1 (map_poly Im (q \<circ>\<^sub>p [:a, b - a:])) (map_poly Re (q \<circ>\<^sub>p [:a, b - a:])) + CR = cindexP_lineE p a b + cindexP_lineE q a b + CR
[PROOF STEP]
apply (subst (1 2) cindexP_lineE_polyE)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindex_polyE 0 1 (map_poly Im (p \<circ>\<^sub>p [:a, b - a:])) (map_poly Re (p \<circ>\<^sub>p [:a, b - a:])) + cindex_polyE 0 1 (map_poly Im (q \<circ>\<^sub>p [:a, b - a:])) (map_poly Re (q \<circ>\<^sub>p [:a, b - a:])) + CR = cindex_polyE 0 1 (map_poly Im (p \<circ>\<^sub>p [:a, b - a:])) (map_poly Re (p \<circ>\<^sub>p [:a, b - a:])) + cindex_polyE 0 1 (map_poly Im (q \<circ>\<^sub>p [:a, b - a:])) (map_poly Re (q \<circ>\<^sub>p [:a, b - a:])) + CR
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR = cindexP_lineE p a b + cindexP_lineE q a b + CR

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
cindex_polyE 0 1 pI pR + cindex_polyE 0 1 qI qR + CR = cindexP_lineE p a b + cindexP_lineE q a b + CR

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have "... = cindexP_lineE p a b +cindexP_lineE q a b + cdiff_aux p q a b/2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cindexP_lineE p a b + cindexP_lineE q a b + CR = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cindexP_lineE p a b + cindexP_lineE q a b + CR = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
have "CR = cdiff_aux p q a b/2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. CR = real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
unfolding CR_def C2_def cross_alt_alt cdiff_aux_def psign_aux_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of_int (sign (poly (P1 * (pI * qI)) 1) - sign (poly (P1 * (pI * qI)) 0)) / 2 + real_of_int (sign (poly (P2 * P1) 1) - sign (poly (P2 * P1) 0)) / 2 - real_of_int (sign (poly (pR * pI) 1) - sign (poly (pR * pI) 0)) / 2 - real_of_int (sign (poly (qR * qI) 1) - sign (poly (qR * qI) 0)) / 2 = real_of_int (sign (Im (poly p b * poly q b) * (Im (poly p b) * Im (poly q b))) + sign (Re (poly p b * poly q b) * Im (poly p b * poly q b)) - sign (Re (poly p b) * Im (poly p b)) - sign (Re (poly q b) * Im (poly q b)) - (sign (Im (poly p a * poly q a) * (Im (poly p a) * Im (poly q a))) + sign (Re (poly p a * poly q a) * Im (poly p a * poly q a)) - sign (Re (poly p a) * Im (poly p a)) - sign (Re (poly q a) * Im (poly q a)))) / 2
[PROOF STEP]
by (simp add:P1_poly P2_poly p_poly q_poly del:times_complex.sel)
[PROOF STATE]
proof (state)
this:
CR = real_of_int (cdiff_aux p q a b) / 2

goal (1 subgoal):
 1. cindexP_lineE p a b + cindexP_lineE q a b + CR = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
CR = real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
CR = real_of_int (cdiff_aux p q a b) / 2

goal (1 subgoal):
 1. cindexP_lineE p a b + cindexP_lineE q a b + CR = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
cindexP_lineE p a b + cindexP_lineE q a b + CR = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
cindexP_lineE p a b + cindexP_lineE q a b + CR = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2

goal (1 subgoal):
 1. cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
cindexP_lineE (p * q) a b = cindexP_lineE p a b + cindexP_lineE q a b + real_of_int (cdiff_aux p q a b) / 2

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma hd_filter_app: "\<lbrakk>filter P xs \<noteq> []; zs=xs@ys\<rbrakk> \<Longrightarrow>
       hd (filter P zs) =  hd (filter P xs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>filter P xs \<noteq> []; zs = xs @ ys\<rbrakk> \<Longrightarrow> hd (filter P zs) = hd (filter P xs)
[PROOF STEP]
by (induct xs arbitrary: n m) auto


[STATEMENT]
lemma "max_ipv6_addr = 340282366920938463463374607431768211455"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. max_ipv6_addr = 340282366920938463463374607431768211455
[PROOF STEP]
by(fact max_ipv6_addr_number)


[STATEMENT]
lemma mersenne_mod2_nonneg_strong:
  assumes "a > -(2 ^ p) + 1"
  shows   "mersenne_mod2 a p \<ge> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> mersenne_mod2 a p
[PROOF STEP]
unfolding mersenne_mod2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> mersenne_mod (mersenne_mod a p) p
[PROOF STEP]
by (rule mersenne_mod_nonneg, rule mersenne_mod_nonneg_strong) (use assms in auto)


[STATEMENT]
lemma card_states: "card (states DFA) = card (UNIV // R)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (states DFA) = card (UNIV // R)
[PROOF STEP]
using h
[PROOF STATE]
proof (prove)
using this:
bij_betw h (UNIV // R) (hfset (ord_of n))

goal (1 subgoal):
 1. card (states DFA) = card (UNIV // R)
[PROOF STEP]
by (simp add: DFA_def bij_betw_def) (metis card_image)


[STATEMENT]
lemma uniformly_continuous_onE:
  assumes "uniformly_continuous_on s f" "0 < e"
  obtains d where "d>0" "\<And>x x'. \<lbrakk>x\<in>s; x'\<in>s; dist x' x < d\<rbrakk> \<Longrightarrow> dist (f x') (f x) < e"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>d. \<lbrakk>0 < d; \<And>x x'. \<lbrakk>x \<in> s; x' \<in> s; dist x' x < d\<rbrakk> \<Longrightarrow> dist (f x') (f x) < e\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
uniformly_continuous_on s f
0 < e

goal (1 subgoal):
 1. (\<And>d. \<lbrakk>0 < d; \<And>x x'. \<lbrakk>x \<in> s; x' \<in> s; dist x' x < d\<rbrakk> \<Longrightarrow> dist (f x') (f x) < e\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (auto simp: uniformly_continuous_on_def)


[STATEMENT]
lemma compact_eq_closed:
  fixes S :: "'a::{complete_linorder,linorder_topology,second_countable_topology} set"
  shows "compact S \<longleftrightarrow> closed S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. compact S = closed S
[PROOF STEP]
using closed_Int_compact[of S, OF _ compact_UNIV] compact_imp_closed
[PROOF STATE]
proof (prove)
using this:
closed S \<Longrightarrow> compact (S \<inter> UNIV)
compact ?s \<Longrightarrow> closed ?s

goal (1 subgoal):
 1. compact S = closed S
[PROOF STEP]
by auto


[STATEMENT]
lemma enat_eSuc_iff: "enat y = eSuc x \<longleftrightarrow> (\<exists>n. y = Suc n \<and> enat n = x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (enat y = eSuc x) = (\<exists>n. y = Suc n \<and> enat n = x)
[PROOF STEP]
by (cases y) (auto simp: enat_0 eSuc_enat[symmetric])


[STATEMENT]
lemma less_ceiling_iff: "z < \<lceil>x\<rceil> \<longleftrightarrow> of_int z < x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (z < \<lceil>x\<rceil>) = (of_int z < x)
[PROOF STEP]
by (simp add: not_le [symmetric] ceiling_le_iff)


[STATEMENT]
lemma continuous_map_eq_image_closure_subset:
     "continuous_map X Y f \<longleftrightarrow> (\<forall>S. f ` (X closure_of S) \<subseteq> Y closure_of f ` S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. continuous_map X Y f = (\<forall>S. f ` (X closure_of S) \<subseteq> Y closure_of f ` S)
[PROOF STEP]
using continuous_map_subset_aux1 continuous_map_subset_aux2
[PROOF STATE]
proof (prove)
using this:
continuous_map ?X ?Y ?f \<Longrightarrow> \<forall>S. ?f ` (?X closure_of S) \<subseteq> ?Y closure_of ?f ` S
\<forall>S\<subseteq>topspace ?X. ?f ` (?X closure_of S) \<subseteq> ?Y closure_of ?f ` S \<Longrightarrow> continuous_map ?X ?Y ?f

goal (1 subgoal):
 1. continuous_map X Y f = (\<forall>S. f ` (X closure_of S) \<subseteq> Y closure_of f ` S)
[PROOF STEP]
by metis


[STATEMENT]
lemma divmod_nat_code'[code]: "Euclidean_Division.divmod_nat m n = (
  let k = integer_of_nat m; l = integer_of_nat n
  in map_prod nat_of_integer nat_of_integer
  (if k = 0 then (0, 0)
    else if l = 0 then (0,k) else
            divmod_abs' k l))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Euclidean_Division.divmod_nat m n = (let k = integer_of_nat m; l = integer_of_nat n in map_prod nat_of_integer nat_of_integer (if k = 0 then (0, 0) else if l = 0 then (0, k) else divmod_abs' k l))
[PROOF STEP]
using divmod_nat_code [of m n]
[PROOF STATE]
proof (prove)
using this:
Euclidean_Division.divmod_nat m n = (let k = integer_of_nat m; l = integer_of_nat n in map_prod nat_of_integer nat_of_integer (if k = 0 then (0, 0) else if l = 0 then (0, k) else Code_Numeral.divmod_abs k l))

goal (1 subgoal):
 1. Euclidean_Division.divmod_nat m n = (let k = integer_of_nat m; l = integer_of_nat n in map_prod nat_of_integer nat_of_integer (if k = 0 then (0, 0) else if l = 0 then (0, k) else divmod_abs' k l))
[PROOF STEP]
by (simp add: divmod_abs'_def integer_of_nat_eq_of_nat Let_def)


[STATEMENT]
lemma quot_of_fract_eq_iff [simp]: "quot_of_fract x = quot_of_fract y \<longleftrightarrow> x = y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (quot_of_fract x = quot_of_fract y) = (x = y)
[PROOF STEP]
by transfer (auto simp: normalize_quot_eq_iff)


[STATEMENT]
lemma (in Module) mHom_add:"\<lbrakk>R module N; f \<in> mHom R M N; m \<in> carrier M;
             n \<in> carrier M\<rbrakk> \<Longrightarrow> f (m \<plusminus> n) = f m \<plusminus>\<^bsub>N\<^esub> (f n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>R module N; f \<in> mHom R M N; m \<in> carrier M; n \<in> carrier M\<rbrakk> \<Longrightarrow> f (m \<plusminus> n) = f m \<plusminus>\<^bsub>N\<^esub> f n
[PROOF STEP]
apply (simp add:mHom_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>R module N; f \<in> aHom M N \<and> (\<forall>a\<in>carrier R. \<forall>m\<in>carrier M. f (a \<cdot>\<^sub>s m) = a \<cdot>\<^sub>s\<^bsub>N\<^esub> f m); m \<in> carrier M; n \<in> carrier M\<rbrakk> \<Longrightarrow> f (m \<plusminus> n) = f m \<plusminus>\<^bsub>N\<^esub> f n
[PROOF STEP]
apply (erule conjE)+
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>R module N; m \<in> carrier M; n \<in> carrier M; f \<in> aHom M N; \<forall>a\<in>carrier R. \<forall>m\<in>carrier M. f (a \<cdot>\<^sub>s m) = a \<cdot>\<^sub>s\<^bsub>N\<^esub> f m\<rbrakk> \<Longrightarrow> f (m \<plusminus> n) = f m \<plusminus>\<^bsub>N\<^esub> f n
[PROOF STEP]
apply (frule Module.module_is_ag [of N R],
       cut_tac module_is_ag)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>R module N; m \<in> carrier M; n \<in> carrier M; f \<in> aHom M N; \<forall>a\<in>carrier R. \<forall>m\<in>carrier M. f (a \<cdot>\<^sub>s m) = a \<cdot>\<^sub>s\<^bsub>N\<^esub> f m; aGroup N; aGroup M\<rbrakk> \<Longrightarrow> f (m \<plusminus> n) = f m \<plusminus>\<^bsub>N\<^esub> f n
[PROOF STEP]
apply (simp add:aHom_add)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma complement_connected_component_unions:
    "S - connected_component_set S x =
     \<Union>(connected_component_set S ` S - {connected_component_set S x})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. S - connected_component_set S x = \<Union> (connected_component_set S ` S - {connected_component_set S x})
[PROOF STEP]
apply (subst Union_connected_component [symmetric], auto)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>xa xaa xb. \<lbrakk>xaa \<in> S; connected_component S xaa xa; connected_component S x xa; connected_component S xaa xb\<rbrakk> \<Longrightarrow> connected_component S x xb
 2. \<And>xa xaa xb. \<lbrakk>xaa \<in> S; connected_component S xaa xa; connected_component S x xa; connected_component S x xb\<rbrakk> \<Longrightarrow> connected_component S xaa xb
[PROOF STEP]
apply (metis connected_component_eq_eq connected_component_in)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>xa xaa xb. \<lbrakk>xaa \<in> S; connected_component S xaa xa; connected_component S x xa; connected_component S x xb\<rbrakk> \<Longrightarrow> connected_component S xaa xb
[PROOF STEP]
by (metis connected_component_eq mem_Collect_eq)


[STATEMENT]
theorem CK_real_card:
  shows "card {f::real set \<Rightarrow> real set. CK f} = 14" (is "?lhs = ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card {f. CK f} = 14
[PROOF STEP]
proof(rule antisym[OF CK_card])
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. 14 \<le> card {f. CK f}
[PROOF STEP]
show "?rhs \<le> ?lhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 14 \<le> card {f. CK f}
[PROOF STEP]
unfolding CK_nf
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 14 \<le> card {f. CK_nf f}
[PROOF STEP]
by (rule le_trans[OF eq_imp_le[OF CK_nf_real_card[symmetric]] card_image_le])
       (simp add: CK_nf_set)
[PROOF STATE]
proof (state)
this:
14 \<le> card {f. CK f}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma vec_to_iarray_solve_consistent_rref:
fixes A::"'a::{field}^'cols::{mod_type}^'rows::{mod_type}"
assumes rref: "reduced_row_echelon_form A"
shows "vec_to_iarray (solve_consistent_rref A b) = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. vec_to_iarray (solve_consistent_rref A b) = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b)
[PROOF STEP]
proof(unfold iarray_exhaust2 list_eq_iff_nth_eq IArray.length_def[symmetric] IArray.sub_def[symmetric], rule conjI)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. IArray.length (vec_to_iarray (solve_consistent_rref A b)) = IArray.length (solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b))
 2. \<forall>i<IArray.length (vec_to_iarray (solve_consistent_rref A b)). vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
show "IArray.length (vec_to_iarray (solve_consistent_rref A b)) = IArray.length (solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. IArray.length (vec_to_iarray (solve_consistent_rref A b)) = IArray.length (solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b))
[PROOF STEP]
unfolding solve_consistent_rref_def solve_consistent_rref_iarrays_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. IArray.length (vec_to_iarray (\<chi>j. if \<exists>i. A $ i $ j = (1::'a) \<and> j = (LEAST n. A $ i $ n \<noteq> (0::'a)) then b $ (THE i. A $ i $ j = (1::'a)) else (0::'a))) = IArray.length (IArray.of_fun (\<lambda>j. if IArray.exists (\<lambda>i. matrix_to_iarray A !! i !! j = (1::'a) \<and> j = least_non_zero_position_of_vector (row_iarray i (matrix_to_iarray A))) (IArray [0..<nrows_iarray (matrix_to_iarray A)]) then vec_to_iarray b !! least_non_zero_position_of_vector (column_iarray j (matrix_to_iarray A)) else (0::'a)) (ncols_iarray (matrix_to_iarray A)))
[PROOF STEP]
unfolding ncols_iarray_def matrix_to_iarray_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. IArray.length (vec_to_iarray (\<chi>j. if \<exists>i. A $ i $ j = (1::'a) \<and> j = (LEAST n. A $ i $ n \<noteq> (0::'a)) then b $ (THE i. A $ i $ j = (1::'a)) else (0::'a))) = IArray.length (IArray.of_fun (\<lambda>j. if IArray.exists (\<lambda>i. IArray (map (vec_to_iarray \<circ> ($) A \<circ> mod_type_class.from_nat) [0..<CARD('rows)]) !! i !! j = (1::'a) \<and> j = least_non_zero_position_of_vector (row_iarray i (IArray (map (vec_to_iarray \<circ> ($) A \<circ> mod_type_class.from_nat) [0..<CARD('rows)])))) (IArray [0..<nrows_iarray (IArray (map (vec_to_iarray \<circ> ($) A \<circ> mod_type_class.from_nat) [0..<CARD('rows)]))]) then vec_to_iarray b !! least_non_zero_position_of_vector (column_iarray j (IArray (map (vec_to_iarray \<circ> ($) A \<circ> mod_type_class.from_nat) [0..<CARD('rows)]))) else (0::'a)) (IArray.length (IArray (map (vec_to_iarray \<circ> ($) A \<circ> mod_type_class.from_nat) [0..<CARD('rows)]) !! 0)))
[PROOF STEP]
by (simp add: vec_to_iarray_def)
[PROOF STATE]
proof (state)
this:
IArray.length (vec_to_iarray (solve_consistent_rref A b)) = IArray.length (solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b))

goal (1 subgoal):
 1. \<forall>i<IArray.length (vec_to_iarray (solve_consistent_rref A b)). vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
show "\<forall>i<IArray.length (vec_to_iarray (solve_consistent_rref A b)). vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>i<IArray.length (vec_to_iarray (solve_consistent_rref A b)). vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
proof (clarify)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i. i < IArray.length (vec_to_iarray (solve_consistent_rref A b)) \<Longrightarrow> vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
fix i
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i. i < IArray.length (vec_to_iarray (solve_consistent_rref A b)) \<Longrightarrow> vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
assume i: "i < IArray.length (vec_to_iarray (solve_consistent_rref A b))"
[PROOF STATE]
proof (state)
this:
i < IArray.length (vec_to_iarray (solve_consistent_rref A b))

goal (1 subgoal):
 1. \<And>i. i < IArray.length (vec_to_iarray (solve_consistent_rref A b)) \<Longrightarrow> vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
hence i_less_card: "i<CARD('cols)"
[PROOF STATE]
proof (prove)
using this:
i < IArray.length (vec_to_iarray (solve_consistent_rref A b))

goal (1 subgoal):
 1. i < CARD('cols)
[PROOF STEP]
unfolding vec_to_iarray_def
[PROOF STATE]
proof (prove)
using this:
i < IArray.length (IArray.of_fun (\<lambda>i. solve_consistent_rref A b $ mod_type_class.from_nat i) CARD('cols))

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

goal (1 subgoal):
 1. \<And>i. i < IArray.length (vec_to_iarray (solve_consistent_rref A b)) \<Longrightarrow> vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
hence i_less_ncols: "i<(ncols_iarray (matrix_to_iarray A))"
[PROOF STATE]
proof (prove)
using this:
i < CARD('cols)

goal (1 subgoal):
 1. i < ncols_iarray (matrix_to_iarray A)
[PROOF STEP]
unfolding ncols_eq_card_columns
[PROOF STATE]
proof (prove)
using this:
i < CARD('cols)

goal (1 subgoal):
 1. i < CARD('cols)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
i < ncols_iarray (matrix_to_iarray A)

goal (1 subgoal):
 1. \<And>i. i < IArray.length (vec_to_iarray (solve_consistent_rref A b)) \<Longrightarrow> vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
show "vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
unfolding vec_to_iarray_nth[OF i_less_card]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. solve_consistent_rref A b $ mod_type_class.from_nat i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
unfolding solve_consistent_rref_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<chi>j. if \<exists>i. A $ i $ j = (1::'a) \<and> j = (LEAST n. A $ i $ n \<noteq> (0::'a)) then b $ (THE i. A $ i $ j = (1::'a)) else (0::'a)) $ mod_type_class.from_nat i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
unfolding vec_lambda_beta
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then b $ (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a)) else (0::'a)) = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i
[PROOF STEP]
unfolding solve_consistent_rref_iarrays_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then b $ (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a)) else (0::'a)) = IArray.of_fun (\<lambda>j. if IArray.exists (\<lambda>i. matrix_to_iarray A !! i !! j = (1::'a) \<and> j = least_non_zero_position_of_vector (row_iarray i (matrix_to_iarray A))) (IArray [0..<nrows_iarray (matrix_to_iarray A)]) then vec_to_iarray b !! least_non_zero_position_of_vector (column_iarray j (matrix_to_iarray A)) else (0::'a)) (ncols_iarray (matrix_to_iarray A)) !! i
[PROOF STEP]
unfolding of_fun_nth[OF i_less_ncols]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then b $ (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a)) else (0::'a)) = (if IArray.exists (\<lambda>ia. matrix_to_iarray A !! ia !! i = (1::'a) \<and> i = least_non_zero_position_of_vector (row_iarray ia (matrix_to_iarray A))) (IArray [0..<nrows_iarray (matrix_to_iarray A)]) then vec_to_iarray b !! least_non_zero_position_of_vector (column_iarray i (matrix_to_iarray A)) else (0::'a))
[PROOF STEP]
unfolding exists_solve_consistent_rref[OF rref, of "from_nat i", symmetric, unfolded to_nat_from_nat_id[OF i_less_card]]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then b $ (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a)) else (0::'a)) = (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then vec_to_iarray b !! least_non_zero_position_of_vector (column_iarray i (matrix_to_iarray A)) else (0::'a))
[PROOF STEP]
using to_nat_the_solve_consistent_rref[OF rref, of "from_nat i", symmetric, unfolded to_nat_from_nat_id[OF i_less_card]]
[PROOF STATE]
proof (prove)
using this:
\<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) \<Longrightarrow> least_non_zero_position_of_vector (column_iarray i (matrix_to_iarray A)) = mod_type_class.to_nat (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a))

goal (1 subgoal):
 1. (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then b $ (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a)) else (0::'a)) = (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then vec_to_iarray b !! least_non_zero_position_of_vector (column_iarray i (matrix_to_iarray A)) else (0::'a))
[PROOF STEP]
using vec_to_iarray_nth'
[PROOF STATE]
proof (prove)
using this:
\<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) \<Longrightarrow> least_non_zero_position_of_vector (column_iarray i (matrix_to_iarray A)) = mod_type_class.to_nat (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a))
vec_to_iarray ?A !! mod_type_class.to_nat ?i = ?A $ ?i

goal (1 subgoal):
 1. (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then b $ (THE ia. A $ ia $ mod_type_class.from_nat i = (1::'a)) else (0::'a)) = (if \<exists>ia. A $ ia $ mod_type_class.from_nat i = (1::'a) \<and> mod_type_class.from_nat i = (LEAST n. A $ ia $ n \<noteq> (0::'a)) then vec_to_iarray b !! least_non_zero_position_of_vector (column_iarray i (matrix_to_iarray A)) else (0::'a))
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<forall>i<IArray.length (vec_to_iarray (solve_consistent_rref A b)). vec_to_iarray (solve_consistent_rref A b) !! i = solve_consistent_rref_iarrays (matrix_to_iarray A) (vec_to_iarray b) !! i

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma "(drop (length (takeWhile f l)) l) = dropWhile f l"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. drop (length (takeWhile f l)) l = dropWhile f l
[PROOF STEP]
by (simp add: dropWhile_eq_drop)


[STATEMENT]
lemma "x + y + z - (x + z) = y - (0::int)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x + y + z - (x + z) = y - 0
[PROOF STEP]
by simp


[STATEMENT]
theorem MTF_is_2_competitive: "compet MTF 2 {s . distinct s}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. compet MTF 2 {s. distinct s}
[PROOF STEP]
unfolding compet_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>s\<in>Collect distinct. \<exists>b\<ge>0. \<forall>rs. static s rs \<longrightarrow> real (T_on MTF s rs) \<le> 2 * real (T_opt s rs) + b
[PROOF STEP]
using compet_MTF'
[PROOF STATE]
proof (prove)
using this:
distinct ?s0.0 \<Longrightarrow> real (T_on MTF ?s0.0 ?rs) \<le> 2 * real (T_opt ?s0.0 ?rs)

goal (1 subgoal):
 1. \<forall>s\<in>Collect distinct. \<exists>b\<ge>0. \<forall>rs. static s rs \<longrightarrow> real (T_on MTF s rs) \<le> 2 * real (T_opt s rs) + b
[PROOF STEP]
by fastforce


[STATEMENT]
lemma HPow_mono_strict: "x < y \<Longrightarrow> HPow x < HPow y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x < y \<Longrightarrow> HPow x < HPow y
[PROOF STEP]
by (metis HPow_iff HPow_mono less_le_not_le order_eq_iff)


[STATEMENT]
lemma mod_0_imp_mod_mult_left_0: "
  n mod m = (0::nat) \<Longrightarrow> k * n mod m = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n mod m = 0 \<Longrightarrow> k * n mod m = 0
[PROOF STEP]
by fastforce


[STATEMENT]
lemma minus_one': "\<chi> (n - 1) \<in> {-1, 1}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
define n' where "n' = n - 2"
[PROOF STATE]
proof (state)
this:
n' = n - 2

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
have n: "n = Suc (Suc n')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n = Suc (Suc n')
[PROOF STEP]
using n
[PROOF STATE]
proof (prove)
using this:
1 < n

goal (1 subgoal):
 1. n = Suc (Suc n')
[PROOF STEP]
by (simp add: n'_def)
[PROOF STATE]
proof (state)
this:
n = Suc (Suc n')

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
have "(n - 1) ^ 2 = 1 + (n - 2) * n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (n - 1)\<^sup>2 = 1 + (n - 2) * n
[PROOF STEP]
by (simp add: power2_eq_square algebra_simps n)
[PROOF STATE]
proof (state)
this:
(n - 1)\<^sup>2 = 1 + (n - 2) * n

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(n - 1)\<^sup>2 = 1 + (n - 2) * n

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
have "\<chi> \<dots> = 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<chi> (1 + (n - 2) * n) = 1
[PROOF STEP]
by (subst periodic_mult) auto
[PROOF STATE]
proof (state)
this:
\<chi> (1 + (n - 2) * n) = 1

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
\<chi> (1 + (n - 2) * n) = 1

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
have "\<chi> ((n - 1) ^ 2) = \<chi> (n - 1) ^ 2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<chi> ((n - 1)\<^sup>2) = (\<chi> (n - 1))\<^sup>2
[PROOF STEP]
by (rule mult.power)
[PROOF STATE]
proof (state)
this:
\<chi> ((n - 1)\<^sup>2) = (\<chi> (n - 1))\<^sup>2

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<chi> (n - 1))\<^sup>2 = 1
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<chi> (n - 1))\<^sup>2 = 1

goal (1 subgoal):
 1. \<chi> (n - 1) \<in> {- 1, 1}
[PROOF STEP]
by (subst (asm) power2_eq_1_iff) auto
[PROOF STATE]
proof (state)
this:
\<chi> (n - 1) \<in> {- 1, 1}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma add_multiple_rows_index_eq_bounds:
  assumes "i < dim_row A" and "j < dim_col A" and "i < low \<or> i \<ge> up" and "up \<le> dim_row A"
  shows "add_multiple_rows a i [low..<up] A $$ (i,j) = (\<Sum>l=low..<up. a * A $$(l,j)) + A$$(i,j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. add_multiple_rows a i [low..<up] A $$ (i, j) = (\<Sum>l = low..<up. a * A $$ (l, j)) + A $$ (i, j)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. add_multiple_rows a i [low..<up] A $$ (i, j) = (\<Sum>l = low..<up. a * A $$ (l, j)) + A $$ (i, j)
[PROOF STEP]
have notin: "i \<notin> set [low..<up]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i \<notin> set [low..<up]
[PROOF STEP]
using assms(3)
[PROOF STATE]
proof (prove)
using this:
i < low \<or> up \<le> i

goal (1 subgoal):
 1. i \<notin> set [low..<up]
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i \<notin> set [low..<up]

goal (1 subgoal):
 1. add_multiple_rows a i [low..<up] A $$ (i, j) = (\<Sum>l = low..<up. a * A $$ (l, j)) + A $$ (i, j)
[PROOF STEP]
have "\<And> l . l \<in> set [low..<up] \<Longrightarrow> l < dim_row A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>l. l \<in> set [low..<up] \<Longrightarrow> l < dim_row A
[PROOF STEP]
using assms(4)
[PROOF STATE]
proof (prove)
using this:
up \<le> dim_row A

goal (1 subgoal):
 1. \<And>l. l \<in> set [low..<up] \<Longrightarrow> l < dim_row A
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?l \<in> set [low..<up] \<Longrightarrow> ?l < dim_row A

goal (1 subgoal):
 1. add_multiple_rows a i [low..<up] A $$ (i, j) = (\<Sum>l = low..<up. a * A $$ (l, j)) + A $$ (i, j)
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
?l \<in> set [low..<up] \<Longrightarrow> ?l < dim_row A

goal (1 subgoal):
 1. add_multiple_rows a i [low..<up] A $$ (i, j) = (\<Sum>l = low..<up. a * A $$ (l, j)) + A $$ (i, j)
[PROOF STEP]
using add_multiple_rows_index_eq[of i A j "[low..<up]"]
      sum_set_upt_eq_sum_list[of "\<lambda> l. a * A $$(l,j)" low up]  notin assms(1) assms(2)
[PROOF STATE]
proof (prove)
using this:
?l \<in> set [low..<up] \<Longrightarrow> ?l < dim_row A
\<lbrakk>i < dim_row A; j < dim_col A; i \<notin> set [low..<up]; \<And>l. l \<in> set [low..<up] \<Longrightarrow> l < dim_row A\<rbrakk> \<Longrightarrow> add_multiple_rows ?a i [low..<up] A $$ (i, j) = (\<Sum>l\<leftarrow>[low..<up]. ?a * A $$ (l, j)) + A $$ (i, j)
(\<Sum>i = low..<up. a * A $$ (i, j)) = (\<Sum>i\<leftarrow>[low..<up]. a * A $$ (i, j))
i \<notin> set [low..<up]
i < dim_row A
j < dim_col A

goal (1 subgoal):
 1. add_multiple_rows a i [low..<up] A $$ (i, j) = (\<Sum>l = low..<up. a * A $$ (l, j)) + A $$ (i, j)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
add_multiple_rows a i [low..<up] A $$ (i, j) = (\<Sum>l = low..<up. a * A $$ (l, j)) + A $$ (i, j)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma proots_within_union:
  "proots_within p A \<union> proots_within p B = proots_within p (A \<union> B)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. proots_within p A \<union> proots_within p B = proots_within p (A \<union> B)
[PROOF STEP]
unfolding proots_within_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {x \<in> A. poly p x = (0::'a)} \<union> {x \<in> B. poly p x = (0::'a)} = {x \<in> A \<union> B. poly p x = (0::'a)}
[PROOF STEP]
by auto


[STATEMENT]
lemma mpoly_map_vars_mpoly_of_poly [simp]:
  assumes "bij f"
  shows   "mpoly_map_vars f (mpoly_of_poly i p) = mpoly_of_poly (f i) p"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mpoly_map_vars f (mpoly_of_poly i p) = mpoly_of_poly (f i) p
[PROOF STEP]
proof (rule mpoly_eqI, goal_cases)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>mon. MPoly_Type.coeff (mpoly_map_vars f (mpoly_of_poly i p)) mon = MPoly_Type.coeff (mpoly_of_poly (f i) p) mon
[PROOF STEP]
case (1 mon)
[PROOF STATE]
proof (state)
this:

goal (1 subgoal):
 1. \<And>mon. MPoly_Type.coeff (mpoly_map_vars f (mpoly_of_poly i p)) mon = MPoly_Type.coeff (mpoly_of_poly (f i) p) mon
[PROOF STEP]
have "f -` keys mon \<subseteq> {i} \<longleftrightarrow> keys mon \<subseteq> {f i}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (f -` keys mon \<subseteq> {i}) = (keys mon \<subseteq> {f i})
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
bij f

goal (1 subgoal):
 1. (f -` keys mon \<subseteq> {i}) = (keys mon \<subseteq> {f i})
[PROOF STEP]
by (simp add: vimage_subset_eq)
[PROOF STATE]
proof (state)
this:
(f -` keys mon \<subseteq> {i}) = (keys mon \<subseteq> {f i})

goal (1 subgoal):
 1. \<And>mon. MPoly_Type.coeff (mpoly_map_vars f (mpoly_of_poly i p)) mon = MPoly_Type.coeff (mpoly_of_poly (f i) p) mon
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
(f -` keys mon \<subseteq> {i}) = (keys mon \<subseteq> {f i})

goal (1 subgoal):
 1. MPoly_Type.coeff (mpoly_map_vars f (mpoly_of_poly i p)) mon = MPoly_Type.coeff (mpoly_of_poly (f i) p) mon
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
(f -` keys mon \<subseteq> {i}) = (keys mon \<subseteq> {f i})
bij f

goal (1 subgoal):
 1. MPoly_Type.coeff (mpoly_map_vars f (mpoly_of_poly i p)) mon = MPoly_Type.coeff (mpoly_of_poly (f i) p) mon
[PROOF STEP]
by (simp add: coeff_mpoly_map_vars coeff_mpoly_of_poly lookup_permutep keys_permutep when_def)
[PROOF STATE]
proof (state)
this:
MPoly_Type.coeff (mpoly_map_vars f (mpoly_of_poly i p)) mon = MPoly_Type.coeff (mpoly_of_poly (f i) p) mon

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
theorem sorted_wrt_quicksort:
  assumes "transp R" and "total_on R (set xs)" and "reflp_on R (set xs)"
  shows   "sorted_wrt R (quicksort R xs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sorted_wrt R (quicksort R xs)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
transp R
Restricted_Predicates.total_on R (set xs)
Restricted_Predicates.reflp_on R (set xs)

goal (1 subgoal):
 1. sorted_wrt R (quicksort R xs)
[PROOF STEP]
proof (induction R xs rule: quicksort.induct)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>uu_. \<lbrakk>transp uu_; Restricted_Predicates.total_on uu_ (set []); Restricted_Predicates.reflp_on uu_ (set [])\<rbrakk> \<Longrightarrow> sorted_wrt uu_ (quicksort uu_ [])
 2. \<And>R x xs. \<lbrakk>\<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs)); \<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. \<not> R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. \<not> R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs)); transp R; Restricted_Predicates.total_on R (set (x # xs)); Restricted_Predicates.reflp_on R (set (x # xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (x # xs))
[PROOF STEP]
case (2 R x xs)
[PROOF STATE]
proof (state)
this:
\<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs))
\<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. \<not> R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. \<not> R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs))
transp R
Restricted_Predicates.total_on R (set (x # xs))
Restricted_Predicates.reflp_on R (set (x # xs))

goal (2 subgoals):
 1. \<And>uu_. \<lbrakk>transp uu_; Restricted_Predicates.total_on uu_ (set []); Restricted_Predicates.reflp_on uu_ (set [])\<rbrakk> \<Longrightarrow> sorted_wrt uu_ (quicksort uu_ [])
 2. \<And>R x xs. \<lbrakk>\<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs)); \<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. \<not> R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. \<not> R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs)); transp R; Restricted_Predicates.total_on R (set (x # xs)); Restricted_Predicates.reflp_on R (set (x # xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (x # xs))
[PROOF STEP]
have total: "R a b" if "\<not> R b a" "a \<in> set (x#xs)" "b \<in> set (x#xs)" for a b
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. R a b
[PROOF STEP]
using "2.prems" that
[PROOF STATE]
proof (prove)
using this:
transp R
Restricted_Predicates.total_on R (set (x # xs))
Restricted_Predicates.reflp_on R (set (x # xs))
\<not> R b a
a \<in> set (x # xs)
b \<in> set (x # xs)

goal (1 subgoal):
 1. R a b
[PROOF STEP]
unfolding total_on_def reflp_on_def
[PROOF STATE]
proof (prove)
using this:
transp R
\<forall>xa\<in>set (x # xs). \<forall>y\<in>set (x # xs). xa = y \<or> R xa y \<or> R y xa
\<forall>a\<in>set (x # xs). R a a
\<not> R b a
a \<in> set (x # xs)
b \<in> set (x # xs)

goal (1 subgoal):
 1. R a b
[PROOF STEP]
by (cases "a = b") auto
[PROOF STATE]
proof (state)
this:
\<lbrakk>\<not> R ?b ?a; ?a \<in> set (x # xs); ?b \<in> set (x # xs)\<rbrakk> \<Longrightarrow> R ?a ?b

goal (2 subgoals):
 1. \<And>uu_. \<lbrakk>transp uu_; Restricted_Predicates.total_on uu_ (set []); Restricted_Predicates.reflp_on uu_ (set [])\<rbrakk> \<Longrightarrow> sorted_wrt uu_ (quicksort uu_ [])
 2. \<And>R x xs. \<lbrakk>\<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs)); \<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. \<not> R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. \<not> R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs)); transp R; Restricted_Predicates.total_on R (set (x # xs)); Restricted_Predicates.reflp_on R (set (x # xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (x # xs))
[PROOF STEP]
have "sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs))"
          "sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs)) &&& sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs))
[PROOF STEP]
using "2.prems"
[PROOF STATE]
proof (prove)
using this:
transp R
Restricted_Predicates.total_on R (set (x # xs))
Restricted_Predicates.reflp_on R (set (x # xs))

goal (1 subgoal):
 1. sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs)) &&& sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs))
[PROOF STEP]
by (intro "2.IH"; auto simp: total_on_def reflp_on_def)+
[PROOF STATE]
proof (state)
this:
sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs))
sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs))

goal (2 subgoals):
 1. \<And>uu_. \<lbrakk>transp uu_; Restricted_Predicates.total_on uu_ (set []); Restricted_Predicates.reflp_on uu_ (set [])\<rbrakk> \<Longrightarrow> sorted_wrt uu_ (quicksort uu_ [])
 2. \<And>R x xs. \<lbrakk>\<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs)); \<lbrakk>transp R; Restricted_Predicates.total_on R (set (filter (\<lambda>y. \<not> R y x) xs)); Restricted_Predicates.reflp_on R (set (filter (\<lambda>y. \<not> R y x) xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs)); transp R; Restricted_Predicates.total_on R (set (x # xs)); Restricted_Predicates.reflp_on R (set (x # xs))\<rbrakk> \<Longrightarrow> sorted_wrt R (quicksort R (x # xs))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs))
sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
sorted_wrt R (quicksort R (filter (\<lambda>y. R y x) xs))
sorted_wrt R (quicksort R (filter (\<lambda>y. \<not> R y x) xs))

goal (1 subgoal):
 1. sorted_wrt R (quicksort R (x # xs))
[PROOF STEP]
by (auto simp: sorted_wrt_append \<open>transp R\<close>
     intro: transpD[OF \<open>transp R\<close>] dest!: total)
[PROOF STATE]
proof (state)
this:
sorted_wrt R (quicksort R (x # xs))

goal (1 subgoal):
 1. \<And>uu_. \<lbrakk>transp uu_; Restricted_Predicates.total_on uu_ (set []); Restricted_Predicates.reflp_on uu_ (set [])\<rbrakk> \<Longrightarrow> sorted_wrt uu_ (quicksort uu_ [])
[PROOF STEP]
qed auto


[STATEMENT]
lemma list_frag_HOL4_equiv_sublist:
  shows "list_frag_HOL4 l l' \<longleftrightarrow> sublist l' l"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. list_frag_HOL4 l l' = sublist l' l
[PROOF STEP]
unfolding list_frag_HOL4_def sublist_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<exists>pfx sfx. pfx @ l' @ sfx = l) = (\<exists>ps ss. l = ps @ l' @ ss)
[PROOF STEP]
by blast


[STATEMENT]
lemma group_closure_abs_iff [simp]:
  "\<bar>s\<bar> \<in> group_closure S \<longleftrightarrow> s \<in> group_closure S" for s :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<bar>s\<bar> \<in> group_closure S) = (s \<in> group_closure S)
[PROOF STEP]
by (simp add: abs_if)


[STATEMENT]
lemma interior_ic_ci_union:
  assumes "a < (b::real)" "b < c"
  shows "b \<notin> (interior ({a..<b} \<union> {b<..c}))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b \<notin> interior ({a..<b} \<union> {b<..c})
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. b \<notin> interior ({a..<b} \<union> {b<..c})
[PROOF STEP]
have "b \<notin> ({a..<b} \<union> {b<..c})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b \<notin> {a..<b} \<union> {b<..c}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
b \<notin> {a..<b} \<union> {b<..c}

goal (1 subgoal):
 1. b \<notin> interior ({a..<b} \<union> {b<..c})
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
b \<notin> {a..<b} \<union> {b<..c}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
b \<notin> {a..<b} \<union> {b<..c}

goal (1 subgoal):
 1. b \<notin> interior ({a..<b} \<union> {b<..c})
[PROOF STEP]
using interior_subset
[PROOF STATE]
proof (prove)
using this:
b \<notin> {a..<b} \<union> {b<..c}
interior ?S \<subseteq> ?S

goal (1 subgoal):
 1. b \<notin> interior ({a..<b} \<union> {b<..c})
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
b \<notin> interior ({a..<b} \<union> {b<..c})

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma aux2_digit_sum_repr:
  assumes "n < 2^c" "r < c"
  shows "(a*2^c+n) \<exclamdown> r = n \<exclamdown> r"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a * 2 ^ c + n) \<exclamdown> r = n \<exclamdown> r
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (a * 2 ^ c + n) \<exclamdown> r = n \<exclamdown> r
[PROOF STEP]
have [simp]: \<open>a*(2::nat) ^ c div 2 ^ r = a*2 ^ (c - r)\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a * 2 ^ c div 2 ^ r = a * 2 ^ (c - r)
[PROOF STEP]
using assms(2)
[PROOF STATE]
proof (prove)
using this:
r < c

goal (1 subgoal):
 1. a * 2 ^ c div 2 ^ r = a * 2 ^ (c - r)
[PROOF STEP]
by (auto simp: less_iff_Suc_add
          monoid_mult_class.power_add ac_simps)
[PROOF STATE]
proof (state)
this:
a * 2 ^ c div 2 ^ r = a * 2 ^ (c - r)

goal (1 subgoal):
 1. (a * 2 ^ c + n) \<exclamdown> r = n \<exclamdown> r
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a * 2 ^ c + n) \<exclamdown> r = n \<exclamdown> r
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
n < 2 ^ c
r < c

goal (1 subgoal):
 1. (a * 2 ^ c + n) \<exclamdown> r = n \<exclamdown> r
[PROOF STEP]
by (auto simp add: nth_bit_def
            div_plus_div_distrib_dvd_left
            le_imp_power_dvd
          simp flip: mod_add_left_eq)
[PROOF STATE]
proof (state)
this:
(a * 2 ^ c + n) \<exclamdown> r = n \<exclamdown> r

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma real_minus: "real_of (a - b) = real_of a - real_of b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
have "real_of (a - b) = real_of (a + - b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of (a - b) = real_of (a + - b)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
real_of (a - b) = real_of (a + - b)

goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real_of (a - b) = real_of (a + - b)

goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
have "... = real_of a + real_of (- b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of (a + - b) = real_of a + real_of (- b)
[PROOF STEP]
unfolding real_add
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of a + real_of (- b) = real_of a + real_of (- b)
[PROOF STEP]
..
[PROOF STATE]
proof (state)
this:
real_of (a + - b) = real_of a + real_of (- b)

goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real_of (a + - b) = real_of a + real_of (- b)

goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
have "... = real_of a + - real_of b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of a + real_of (- b) = real_of a + - real_of b
[PROOF STEP]
unfolding real_uminus
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of a + - real_of b = real_of a + - real_of b
[PROOF STEP]
..
[PROOF STATE]
proof (state)
this:
real_of a + real_of (- b) = real_of a + - real_of b

goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real_of a + real_of (- b) = real_of a + - real_of b

goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
have "... = real_of a - real_of b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real_of a + - real_of b = real_of a - real_of b
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
real_of a + - real_of b = real_of a - real_of b

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

goal (1 subgoal):
 1. real_of (a - b) = real_of a - real_of b
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
real_of (a - b) = real_of a - real_of b

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma emb_prepend_coinduct[rotated, case_names emb]:
  assumes "(\<And>x1 x2. X x1 x2 \<Longrightarrow>
    (\<exists>xs. x1 = LNil \<and> x2 = xs \<and> lfinite xs)
     \<or> (\<exists>xs ys x zs. x1 = LCons x xs \<and> x2 = prepend zs (LCons x ys)
       \<and> (prepend_cong1 (X xs) ys \<or> emb xs ys)))" (is "\<And>x1 x2. X x1 x2 \<Longrightarrow> ?bisim x1 x2")
  shows "X x1 x2 \<Longrightarrow> emb x1 x2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. X x1 x2 \<Longrightarrow> emb x1 x2
[PROOF STEP]
proof (erule emb.coinduct[OF prepend_cong1_base])
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x1 x2. prepend_cong1 (X x1) x2 \<Longrightarrow> (\<exists>xs. x1 = LNil \<and> x2 = xs \<and> lfinite xs) \<or> (\<exists>xs ys x zs. x1 = LCons x xs \<and> x2 = prepend zs (LCons x ys) \<and> (prepend_cong1 (X xs) ys \<or> emb xs ys))
[PROOF STEP]
fix xs zs
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x1 x2. prepend_cong1 (X x1) x2 \<Longrightarrow> (\<exists>xs. x1 = LNil \<and> x2 = xs \<and> lfinite xs) \<or> (\<exists>xs ys x zs. x1 = LCons x xs \<and> x2 = prepend zs (LCons x ys) \<and> (prepend_cong1 (X xs) ys \<or> emb xs ys))
[PROOF STEP]
assume "prepend_cong1 (X xs) zs"
[PROOF STATE]
proof (state)
this:
prepend_cong1 (X xs) zs

goal (1 subgoal):
 1. \<And>x1 x2. prepend_cong1 (X x1) x2 \<Longrightarrow> (\<exists>xs. x1 = LNil \<and> x2 = xs \<and> lfinite xs) \<or> (\<exists>xs ys x zs. x1 = LCons x xs \<and> x2 = prepend zs (LCons x ys) \<and> (prepend_cong1 (X xs) ys \<or> emb xs ys))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
prepend_cong1 (X xs) zs
[PROOF STEP]
show "?bisim xs zs"
[PROOF STATE]
proof (prove)
using this:
prepend_cong1 (X xs) zs

goal (1 subgoal):
 1. (\<exists>xsa. xs = LNil \<and> zs = xsa \<and> lfinite xsa) \<or> (\<exists>xsa ys x zsa. xs = LCons x xsa \<and> zs = prepend zsa (LCons x ys) \<and> (prepend_cong1 (X xsa) ys \<or> emb xsa ys))
[PROOF STEP]
by (induct zs rule: prepend_cong1.induct) (erule assms, force simp: prepend_prepend)
[PROOF STATE]
proof (state)
this:
(\<exists>xsa. xs = LNil \<and> zs = xsa \<and> lfinite xsa) \<or> (\<exists>xsa ys x zsa. xs = LCons x xsa \<and> zs = prepend zsa (LCons x ys) \<and> (prepend_cong1 (X xsa) ys \<or> emb xsa ys))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma det_perm_cols:
  fixes A :: "'a::comm_ring_1^^'n"
  assumes p: "p permutes UNIV"
  shows "det (perm_cols A p) = of_int (sign p) * det A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Square_Matrix.det (perm_cols A p) = of_int (sign p) * Square_Matrix.det A
[PROOF STEP]
proof (transfer fixing: p)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>A. (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p (p i)))) = of_int (sign p) * (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p i)))
[PROOF STEP]
fix A :: "'n \<Rightarrow> 'n \<Rightarrow> 'a"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>A. (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p (p i)))) = of_int (sign p) * (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p i)))
[PROOF STEP]
from p
[PROOF STATE]
proof (chain)
picking this:
p permutes UNIV
[PROOF STEP]
have "(\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) =
    (\<Sum>q | q permutes UNIV. of_int (sign (inv p \<circ> q)) * (\<Prod>i\<in>UNIV. A i (q i)))"
[PROOF STATE]
proof (prove)
using this:
p permutes UNIV

goal (1 subgoal):
 1. (\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) = (\<Sum>q | q permutes UNIV. of_int (sign (inv p \<circ> q)) * (\<Prod>i\<in>UNIV. A i (q i)))
[PROOF STEP]
by (intro sum.reindex_bij_witness[where j="\<lambda>q. p \<circ> q" and i="\<lambda>q. inv p \<circ> q"])
       (auto simp: comp_assoc[symmetric] permutes_inv_o permutes_compose permutes_inv)
[PROOF STATE]
proof (state)
this:
(\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) = (\<Sum>q | q permutes UNIV. of_int (sign (inv p \<circ> q)) * (\<Prod>i\<in>UNIV. A i (q i)))

goal (1 subgoal):
 1. \<And>A. (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p (p i)))) = of_int (sign p) * (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p i)))
[PROOF STEP]
with p
[PROOF STATE]
proof (chain)
picking this:
p permutes UNIV
(\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) = (\<Sum>q | q permutes UNIV. of_int (sign (inv p \<circ> q)) * (\<Prod>i\<in>UNIV. A i (q i)))
[PROOF STEP]
show "(\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) =
      of_int (sign p) * (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p i)))"
[PROOF STATE]
proof (prove)
using this:
p permutes UNIV
(\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) = (\<Sum>q | q permutes UNIV. of_int (sign (inv p \<circ> q)) * (\<Prod>i\<in>UNIV. A i (q i)))

goal (1 subgoal):
 1. (\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) = of_int (sign p) * (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p i)))
[PROOF STEP]
by (auto intro!: sum.cong simp: sum_distrib_left sign_compose permutes_inv sign_inverse permutes_UNIV_permutation)
[PROOF STATE]
proof (state)
this:
(\<Sum>q | q permutes UNIV. of_int (sign q) * (\<Prod>i\<in>UNIV. A i (p (q i)))) = of_int (sign p) * (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A i (p i)))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma sumA_UB:
assumes "matching A M" "M \<subseteq> {<n}" "M \<noteq> {<n}" "\<forall>a<n. preferred A a \<subseteq> match A ` M"
shows "(\<Sum>a<n. A!a) \<le> (n-1)^2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
have M: "\<forall>a\<in>M. A!a + 1 < n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>a\<in>M. A ! a + 1 < n
[PROOF STEP]
using more_choices_matched[OF assms(1-3)] assms(4)
    \<open>M \<subseteq> {<n}\<close> atLeastLessThan_iff
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>preferred A ?a \<subseteq> match A ` M; ?a \<in> M\<rbrakk> \<Longrightarrow> A ! ?a + 1 < n
\<forall>a<n. preferred A a \<subseteq> match A ` M
M \<subseteq> {<n}
(?i \<in> {?l..<?u}) = (?l \<le> ?i \<and> ?i < ?u)

goal (1 subgoal):
 1. \<forall>a\<in>M. A ! a + 1 < n
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
\<forall>a\<in>M. A ! a + 1 < n

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
note Ainj = conj12[OF assms(1)[unfolded matching_def]]
[PROOF STATE]
proof (state)
this:
local.wf A
inj_on (match A) M

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
proof (cases "\<exists>a'<n. a' \<notin> M \<and> A!a' + 1 = n")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
 2. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n

goal (2 subgoals):
 1. \<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
 2. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n
[PROOF STEP]
obtain a' where a': "a'<n" "a' \<notin> M" "A!a' + 1 = n"
[PROOF STATE]
proof (prove)
using this:
\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n

goal (1 subgoal):
 1. (\<And>a'. \<lbrakk>a' < n; a' \<notin> M; A ! a' + 1 = n\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using \<open>M \<subseteq> {<n}\<close> \<open>M \<noteq> {<n}\<close>
[PROOF STATE]
proof (prove)
using this:
\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n
M \<subseteq> {<n}
M \<noteq> {<n}

goal (1 subgoal):
 1. (\<And>a'. \<lbrakk>a' < n; a' \<notin> M; A ! a' + 1 = n\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
a' < n
a' \<notin> M
A ! a' + 1 = n

goal (2 subgoals):
 1. \<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
 2. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
hence "\<forall>a<n. a \<noteq> a' \<longrightarrow> A!a \<le> n-2"
[PROOF STATE]
proof (prove)
using this:
a' < n
a' \<notin> M
A ! a' + 1 = n

goal (1 subgoal):
 1. \<forall>a<n. a \<noteq> a' \<longrightarrow> A ! a \<le> n - 2
[PROOF STEP]
using Uniq_D[OF atmost1_final[OF assms(2) Ainj(2) assms(4)], of a'] M wf_le_n1[OF Ainj(1)]
[PROOF STATE]
proof (prove)
using this:
a' < n
a' \<notin> M
A ! a' + 1 = n
\<lbrakk>a' < n \<and> a' \<notin> M \<and> A ! a' + 1 = n; ?b < n \<and> ?b \<notin> M \<and> A ! ?b + 1 = n\<rbrakk> \<Longrightarrow> a' = ?b
\<forall>a\<in>M. A ! a + 1 < n
?a < n \<Longrightarrow> A ! ?a \<le> n - 1

goal (1 subgoal):
 1. \<forall>a<n. a \<noteq> a' \<longrightarrow> A ! a \<le> n - 2
[PROOF STEP]
by (metis Suc_1 Suc_eq_plus1 add_diff_cancel_right' add_le_imp_le_diff diff_diff_left less_eq_Suc_le order_less_le)
[PROOF STATE]
proof (state)
this:
\<forall>a<n. a \<noteq> a' \<longrightarrow> A ! a \<le> n - 2

goal (2 subgoals):
 1. \<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
 2. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
from sumA_ub2[OF a'(1) _ this] a'(3)
[PROOF STATE]
proof (chain)
picking this:
A ! a' \<le> n - 1 \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)
A ! a' + 1 = n
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
A ! a' \<le> n - 1 \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)
A ! a' + 1 = n

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
unfolding power2_eq_square
[PROOF STATE]
proof (prove)
using this:
A ! a' \<le> n - 1 \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)
A ! a' + 1 = n

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2

goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n)

goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
hence "\<forall>a'<n. a' \<notin> M \<longrightarrow> A ! a' + 1 < n"
[PROOF STATE]
proof (prove)
using this:
\<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n)

goal (1 subgoal):
 1. \<forall>a'<n. a' \<notin> M \<longrightarrow> A ! a' + 1 < n
[PROOF STEP]
by (metis Suc_eq_plus1 Suc_lessI wf_less_n[OF Ainj(1)])
[PROOF STATE]
proof (state)
this:
\<forall>a'<n. a' \<notin> M \<longrightarrow> A ! a' + 1 < n

goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
with M
[PROOF STATE]
proof (chain)
picking this:
\<forall>a\<in>M. A ! a + 1 < n
\<forall>a'<n. a' \<notin> M \<longrightarrow> A ! a' + 1 < n
[PROOF STEP]
have "\<forall>a<n. A ! a + 1 < n"
[PROOF STATE]
proof (prove)
using this:
\<forall>a\<in>M. A ! a + 1 < n
\<forall>a'<n. a' \<notin> M \<longrightarrow> A ! a' + 1 < n

goal (1 subgoal):
 1. \<forall>a<n. A ! a + 1 < n
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
\<forall>a<n. A ! a + 1 < n

goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
hence "(\<Sum>a<n. A!a) \<le> n*(n-2)"
[PROOF STATE]
proof (prove)
using this:
\<forall>a<n. A ! a + 1 < n

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> n * (n - 2)
[PROOF STEP]
using sum_bounded_above[of "{..<n}" "((!) A)" "n-2"]
[PROOF STATE]
proof (prove)
using this:
\<forall>a<n. A ! a + 1 < n
(\<And>i. i \<in> {..<n} \<Longrightarrow> A ! i \<le> n - 2) \<Longrightarrow> sum ((!) A) {..<n} \<le> of_nat (card {..<n}) * (n - 2)

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> n * (n - 2)
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
sum ((!) A) {..<n} \<le> n * (n - 2)

goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
sum ((!) A) {..<n} \<le> n * (n - 2)

goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
have "\<dots> \<le> (n-1)*(n-1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n * (n - 2) \<le> (n - 1) * (n - 1)
[PROOF STEP]
by(simp add: algebra_simps)
[PROOF STATE]
proof (state)
this:
n * (n - 2) \<le> (n - 1) * (n - 1)

goal (1 subgoal):
 1. \<not> (\<exists>a'<n. a' \<notin> M \<and> A ! a' + 1 = n) \<Longrightarrow> sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2
[PROOF STEP]
unfolding power2_eq_square
[PROOF STATE]
proof (prove)
using this:
sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)

goal (1 subgoal):
 1. sum ((!) A) {..<n} \<le> (n - 1) * (n - 1)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
sum ((!) A) {..<n} \<le> (n - 1)\<^sup>2

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma listrel_refl_on:
  assumes "refl_on A r" shows "refl_on (lists A) (listrel r)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. refl_on (lists A) (listrel r)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. refl_on (lists A) (listrel r)
[PROOF STEP]
have "l \<in> lists A \<Longrightarrow> (l, l) \<in> listrel r" for l
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. l \<in> lists A \<Longrightarrow> (l, l) \<in> listrel r
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
refl_on A r

goal (1 subgoal):
 1. l \<in> lists A \<Longrightarrow> (l, l) \<in> listrel r
[PROOF STEP]
unfolding refl_on_def
[PROOF STATE]
proof (prove)
using this:
r \<subseteq> A \<times> A \<and> (\<forall>x\<in>A. (x, x) \<in> r)

goal (1 subgoal):
 1. l \<in> lists A \<Longrightarrow> (l, l) \<in> listrel r
[PROOF STEP]
by (induction l, auto intro: listrel.intros)
[PROOF STATE]
proof (state)
this:
?l \<in> lists A \<Longrightarrow> (?l, ?l) \<in> listrel r

goal (1 subgoal):
 1. refl_on (lists A) (listrel r)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?l \<in> lists A \<Longrightarrow> (?l, ?l) \<in> listrel r
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
?l \<in> lists A \<Longrightarrow> (?l, ?l) \<in> listrel r

goal (1 subgoal):
 1. refl_on (lists A) (listrel r)
[PROOF STEP]
by (meson assms listrel_subset refl_on_def)
[PROOF STATE]
proof (state)
this:
refl_on (lists A) (listrel r)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma in_minimize_wrt_iff:
  assumes "\<And>x y. Q x y \<Longrightarrow> \<not> Q y x"
    and "sorted_wrt Q xs"
    and "\<And>x y. \<not> P x y \<Longrightarrow> Q x y"
    and "\<And>x. P x x"
  shows "x \<in> set (minimize_wrt P xs) \<longleftrightarrow> x \<in> set xs \<and> (\<forall>y\<in>set xs. P y x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x \<in> set (minimize_wrt P xs)) = (x \<in> set xs \<and> (\<forall>y\<in>set xs. P y x))
[PROOF STEP]
using assms and in_minimize_wrtD [of Q xs x P, OF assms(1,2) _ assms(3,4)]
[PROOF STATE]
proof (prove)
using this:
Q ?x ?y \<Longrightarrow> \<not> Q ?y ?x
sorted_wrt Q xs
\<not> P ?x ?y \<Longrightarrow> Q ?x ?y
P ?x ?x
\<lbrakk>\<And>x y. Q x y \<Longrightarrow> Q x y; x \<in> set (minimize_wrt P xs); \<And>x y. \<not> P x y \<Longrightarrow> \<not> P x y\<rbrakk> \<Longrightarrow> x \<in> set xs \<and> (\<forall>y\<in>set xs. P y x)

goal (1 subgoal):
 1. (x \<in> set (minimize_wrt P xs)) = (x \<in> set xs \<and> (\<forall>y\<in>set xs. P y x))
[PROOF STEP]
by (blast intro: in_minimize_wrtI)


[STATEMENT]
lemma least_mono_commute:
  assumes "finite S"
  assumes "strict_mono_on S f"
  shows "f ` least k S = least k (f ` S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
have a:"inj_on f S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on f S
[PROOF STEP]
using strict_mono_on_imp_inj_on[OF assms(2)]
[PROOF STATE]
proof (prove)
using this:
inj_on f S

goal (1 subgoal):
 1. inj_on f S
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
inj_on f S

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
have "card (least k (f ` S)) = min k (card (f ` S))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (K_Smallest.least k (f ` S)) = min k (card (f ` S))
[PROOF STEP]
by (subst card_least, auto simp add:assms)
[PROOF STATE]
proof (state)
this:
card (K_Smallest.least k (f ` S)) = min k (card (f ` S))

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card (K_Smallest.least k (f ` S)) = min k (card (f ` S))

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
have "... = min k (card S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. min k (card (f ` S)) = min k (card S)
[PROOF STEP]
by (subst card_image, metis a, auto)
[PROOF STATE]
proof (state)
this:
min k (card (f ` S)) = min k (card S)

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
min k (card (f ` S)) = min k (card S)

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
have "... = card (least k S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. min k (card S) = card (K_Smallest.least k S)
[PROOF STEP]
by (subst card_least, auto simp add:assms)
[PROOF STATE]
proof (state)
this:
min k (card S) = card (K_Smallest.least k S)

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
min k (card S) = card (K_Smallest.least k S)

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
have "... = card (f ` least k S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (K_Smallest.least k S) = card (f ` K_Smallest.least k S)
[PROOF STEP]
by (subst card_image[OF inj_on_subset[OF a]], simp_all add:least_def)
[PROOF STATE]
proof (state)
this:
card (K_Smallest.least k S) = card (f ` K_Smallest.least k S)

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
card (K_Smallest.least k (f ` S)) = card (f ` K_Smallest.least k S)
[PROOF STEP]
have b: "card (least k (f ` S)) \<le> card (f ` least k S)"
[PROOF STATE]
proof (prove)
using this:
card (K_Smallest.least k (f ` S)) = card (f ` K_Smallest.least k S)

goal (1 subgoal):
 1. card (K_Smallest.least k (f ` S)) \<le> card (f ` K_Smallest.least k S)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
card (K_Smallest.least k (f ` S)) \<le> card (f ` K_Smallest.least k S)

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
have c: "f ` least k S \<subseteq>least k (f ` S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f ` K_Smallest.least k S \<subseteq> K_Smallest.least k (f ` S)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
finite S
strict_mono_on S f

goal (1 subgoal):
 1. f ` K_Smallest.least k S \<subseteq> K_Smallest.least k (f ` S)
[PROOF STEP]
by (intro image_subsetI)
      (simp add:least_def rank_mono_commute[symmetric, where T="S"])
[PROOF STATE]
proof (state)
this:
f ` K_Smallest.least k S \<subseteq> K_Smallest.least k (f ` S)

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
using b c assms
[PROOF STATE]
proof (prove)
using this:
card (K_Smallest.least k (f ` S)) \<le> card (f ` K_Smallest.least k S)
f ` K_Smallest.least k S \<subseteq> K_Smallest.least k (f ` S)
finite S
strict_mono_on S f

goal (1 subgoal):
 1. f ` K_Smallest.least k S = K_Smallest.least k (f ` S)
[PROOF STEP]
by (intro card_seteq, simp_all add:least_def)
[PROOF STATE]
proof (state)
this:
f ` K_Smallest.least k S = K_Smallest.least k (f ` S)

goal:
No subgoals!
[PROOF STEP]
qed