[STATEMENT]
lemma dist_stereographic_finite:
  assumes "stereographic M1 = of_complex m1"  and "stereographic M2 = of_complex m2"
  shows "dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
stereographic M1 = of_complex m1
stereographic M2 = of_complex m2

goal (1 subgoal):
 1. dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
have *: "M1 = inv_stereographic (of_complex m1)"  "M2 = inv_stereographic (of_complex m2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. M1 = inv_stereographic (of_complex m1) &&& M2 = inv_stereographic (of_complex m2)
[PROOF STEP]
using inv_stereographic_is_inv assms
[PROOF STATE]
proof (prove)
using this:
inv_stereographic = inv stereographic
stereographic M1 = of_complex m1
stereographic M2 = of_complex m2

goal (1 subgoal):
 1. M1 = inv_stereographic (of_complex m1) &&& M2 = inv_stereographic (of_complex m2)
[PROOF STEP]
by (metis inv_stereographic_stereographic)+
[PROOF STATE]
proof (state)
this:
M1 = inv_stereographic (of_complex m1)
M2 = inv_stereographic (of_complex m2)

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
have "(1 + (cmod m1)\<^sup>2) \<noteq> 0"  "(1 + (cmod m2)\<^sup>2) \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 1 + (cmod m1)\<^sup>2 \<noteq> 0 &&& 1 + (cmod m2)\<^sup>2 \<noteq> 0
[PROOF STEP]
by (smt power2_less_0)+
[PROOF STATE]
proof (state)
this:
1 + (cmod m1)\<^sup>2 \<noteq> 0
1 + (cmod m2)\<^sup>2 \<noteq> 0

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
have "(1 + (cmod m1)\<^sup>2) > 0"  "(1 + (cmod m2)\<^sup>2) > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < 1 + (cmod m1)\<^sup>2 &&& 0 < 1 + (cmod m2)\<^sup>2
[PROOF STEP]
by (smt realpow_square_minus_le)+
[PROOF STATE]
proof (state)
this:
0 < 1 + (cmod m1)\<^sup>2
0 < 1 + (cmod m2)\<^sup>2

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
hence "(1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) > 0"
[PROOF STATE]
proof (prove)
using this:
0 < 1 + (cmod m1)\<^sup>2
0 < 1 + (cmod m2)\<^sup>2

goal (1 subgoal):
 1. 0 < (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)
[PROOF STEP]
by (metis norm_mult_less norm_zero power2_eq_square zero_power2)
[PROOF STATE]
proof (state)
this:
0 < (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
hence ++: "sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2)) > 0"
[PROOF STATE]
proof (prove)
using this:
0 < (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)

goal (1 subgoal):
 1. 0 < sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))
[PROOF STEP]
using real_sqrt_gt_0_iff
[PROOF STATE]
proof (prove)
using this:
0 < (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)
(0 < sqrt ?y) = (0 < ?y)

goal (1 subgoal):
 1. 0 < sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))
[PROOF STEP]
by (simp add: power2_eq_square)
[PROOF STATE]
proof (state)
this:
0 < sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
hence **: "(2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))) \<ge> 0 \<longleftrightarrow> cmod (m1 - m2) \<ge> 0"
[PROOF STATE]
proof (prove)
using this:
0 < sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))

goal (1 subgoal):
 1. (0 \<le> 2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))) = (0 \<le> cmod (m1 - m2))
[PROOF STEP]
by (metis diff_self divide_nonneg_pos mult_2 norm_ge_zero norm_triangle_ineq4 norm_zero)
[PROOF STATE]
proof (state)
this:
(0 \<le> 2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))) = (0 \<le> cmod (m1 - m2))

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
have "(dist_riemann_sphere' M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (dist_riemann_sphere' M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
using *
[PROOF STATE]
proof (prove)
using this:
M1 = inv_stereographic (of_complex m1)
M2 = inv_stereographic (of_complex m2)

goal (1 subgoal):
 1. (dist_riemann_sphere' M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
proof (transfer, transfer)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>M1 m1 M2 m2 M1a m1a M2a m2a. \<lbrakk>M1 \<in> unit_sphere; M1 = inv_stereographic_cvec_r3 (of_complex_cvec m1); M2 \<in> unit_sphere; M2 = inv_stereographic_cvec_r3 (of_complex_cvec m2); M1a \<in> unit_sphere; M1a = inv_stereographic_hcoords_r3 (of_complex_hcoords m1a); M2a \<in> unit_sphere; M2a = inv_stereographic_hcoords_r3 (of_complex_hcoords m2a)\<rbrakk> \<Longrightarrow> (dist_riemann_sphere_r3 M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
fix m1 m2 M1 M2
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>M1 m1 M2 m2 M1a m1a M2a m2a. \<lbrakk>M1 \<in> unit_sphere; M1 = inv_stereographic_cvec_r3 (of_complex_cvec m1); M2 \<in> unit_sphere; M2 = inv_stereographic_cvec_r3 (of_complex_cvec m2); M1a \<in> unit_sphere; M1a = inv_stereographic_hcoords_r3 (of_complex_hcoords m1a); M2a \<in> unit_sphere; M2a = inv_stereographic_hcoords_r3 (of_complex_hcoords m2a)\<rbrakk> \<Longrightarrow> (dist_riemann_sphere_r3 M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
assume us: "M1 \<in> unit_sphere" "M2 \<in> unit_sphere" and
        *: "M1 = inv_stereographic_cvec_r3 (of_complex_cvec m1)" "M2 = inv_stereographic_cvec_r3 (of_complex_cvec m2)"
[PROOF STATE]
proof (state)
this:
M1 \<in> unit_sphere
M2 \<in> unit_sphere
M1 = inv_stereographic_cvec_r3 (of_complex_cvec m1)
M2 = inv_stereographic_cvec_r3 (of_complex_cvec m2)

goal (1 subgoal):
 1. \<And>M1 m1 M2 m2 M1a m1a M2a m2a. \<lbrakk>M1 \<in> unit_sphere; M1 = inv_stereographic_cvec_r3 (of_complex_cvec m1); M2 \<in> unit_sphere; M2 = inv_stereographic_cvec_r3 (of_complex_cvec m2); M1a \<in> unit_sphere; M1a = inv_stereographic_hcoords_r3 (of_complex_hcoords m1a); M2a \<in> unit_sphere; M2a = inv_stereographic_hcoords_r3 (of_complex_hcoords m2a)\<rbrakk> \<Longrightarrow> (dist_riemann_sphere_r3 M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
have "(1 + (cmod m1)\<^sup>2) \<noteq> 0"  "(1 + (cmod m2)\<^sup>2) \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 1 + (cmod m1)\<^sup>2 \<noteq> 0 &&& 1 + (cmod m2)\<^sup>2 \<noteq> 0
[PROOF STEP]
by (smt power2_less_0)+
[PROOF STATE]
proof (state)
this:
1 + (cmod m1)\<^sup>2 \<noteq> 0
1 + (cmod m2)\<^sup>2 \<noteq> 0

goal (1 subgoal):
 1. \<And>M1 m1 M2 m2 M1a m1a M2a m2a. \<lbrakk>M1 \<in> unit_sphere; M1 = inv_stereographic_cvec_r3 (of_complex_cvec m1); M2 \<in> unit_sphere; M2 = inv_stereographic_cvec_r3 (of_complex_cvec m2); M1a \<in> unit_sphere; M1a = inv_stereographic_hcoords_r3 (of_complex_hcoords m1a); M2a \<in> unit_sphere; M2a = inv_stereographic_hcoords_r3 (of_complex_hcoords m2a)\<rbrakk> \<Longrightarrow> (dist_riemann_sphere_r3 M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
thus "(dist_riemann_sphere_r3 M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) =
          4 * (cmod (m1 - m2))\<^sup>2"
[PROOF STATE]
proof (prove)
using this:
1 + (cmod m1)\<^sup>2 \<noteq> 0
1 + (cmod m2)\<^sup>2 \<noteq> 0

goal (1 subgoal):
 1. (dist_riemann_sphere_r3 M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst dist_riemann_sphere_r3_inner[OF us])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> (2 - 2 * inner M1 M2) * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst *)+
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> (2 - 2 * inner (inv_stereographic_cvec_r3 (of_complex_cvec m1)) (inv_stereographic_cvec_r3 (of_complex_cvec m2))) * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (simp add: dist_riemann_sphere_r3_inner[OF us] complex_mult_cnj_cmod)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> (2 - (8 * (Re m1 * Re m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) + (8 * (Im m1 * Im m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))))) * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst left_diff_distrib[of 2])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> (2 * (1 + (cmod m1)\<^sup>2) - (8 * (Re m1 * Re m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) + (8 * (Im m1 * Im m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)))) * (1 + (cmod m1)\<^sup>2)) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst left_diff_distrib[of "2*(1+(cmod m1)\<^sup>2)"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> 2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) + (8 * (Im m1 * Im m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)))) * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst distrib_right[of _ _ "(1 + (cmod m1)\<^sup>2)"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> 2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) * (1 + (cmod m1)\<^sup>2) + (8 * (Im m1 * Im m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))) * (1 + (cmod m1)\<^sup>2)) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst distrib_right[of _ _ "(1 + (cmod m1)\<^sup>2)"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> 2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) * (1 + (cmod m1)\<^sup>2) + (8 * (Im m1 * Im m2) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) * (1 + (cmod m1)\<^sup>2) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) * (1 + (cmod m1)\<^sup>2))) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply simp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> (2 + 2 * (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) / (1 + (cmod m2)\<^sup>2) + (8 * (Im m1 * Im m2) / (1 + (cmod m2)\<^sup>2) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / (1 + (cmod m2)\<^sup>2))) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst distrib_right[of _ _ "(1 + (cmod m2)\<^sup>2)"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> 2 * (1 + (cmod m2)\<^sup>2) + 2 * (cmod m1)\<^sup>2 * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) / (1 + (cmod m2)\<^sup>2) + (8 * (Im m1 * Im m2) / (1 + (cmod m2)\<^sup>2) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / (1 + (cmod m2)\<^sup>2))) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst distrib_right[of _ _ "(1 + (cmod m2)\<^sup>2)"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> 2 * (1 + (cmod m2)\<^sup>2) + 2 * (cmod m1)\<^sup>2 * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) / (1 + (cmod m2)\<^sup>2) * (1 + (cmod m2)\<^sup>2) + (8 * (Im m1 * Im m2) / (1 + (cmod m2)\<^sup>2) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / (1 + (cmod m2)\<^sup>2)) * (1 + (cmod m2)\<^sup>2)) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst distrib_right[of _ _ "(1 + (cmod m2)\<^sup>2)"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> 2 * (1 + (cmod m2)\<^sup>2) + 2 * (cmod m1)\<^sup>2 * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) / (1 + (cmod m2)\<^sup>2) * (1 + (cmod m2)\<^sup>2) + (8 * (Im m1 * Im m2) / (1 + (cmod m2)\<^sup>2) * (1 + (cmod m2)\<^sup>2) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)) / (1 + (cmod m2)\<^sup>2) * (1 + (cmod m2)\<^sup>2))) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply simp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + (cmod m1)\<^sup>2 \<noteq> 0; 1 + (cmod m2)\<^sup>2 \<noteq> 0\<rbrakk> \<Longrightarrow> 2 + 2 * (cmod m2)\<^sup>2 + 2 * (cmod m1)\<^sup>2 * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) + (8 * (Im m1 * Im m2) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)))) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst (asm) cmod_square)+
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + Re (m1 * cnj m1) \<noteq> 0; 1 + Re (m2 * cnj m2) \<noteq> 0\<rbrakk> \<Longrightarrow> 2 + 2 * (cmod m2)\<^sup>2 + 2 * (cmod m1)\<^sup>2 * (1 + (cmod m2)\<^sup>2) - (8 * (Re m1 * Re m2) + (8 * (Im m1 * Im m2) + 2 * (((cmod m1)\<^sup>2 - 1) * ((cmod m2)\<^sup>2 - 1)))) = 4 * (cmod (m1 - m2))\<^sup>2
[PROOF STEP]
apply (subst cmod_square)+
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>1 + Re (m1 * cnj m1) \<noteq> 0; 1 + Re (m2 * cnj m2) \<noteq> 0\<rbrakk> \<Longrightarrow> 2 + 2 * Re (m2 * cnj m2) + 2 * Re (m1 * cnj m1) * (1 + Re (m2 * cnj m2)) - (8 * (Re m1 * Re m2) + (8 * (Im m1 * Im m2) + 2 * ((Re (m1 * cnj m1) - 1) * (Re (m2 * cnj m2) - 1)))) = 4 * Re ((m1 - m2) * cnj (m1 - m2))
[PROOF STEP]
apply (simp add: field_simps)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
(dist_riemann_sphere_r3 M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(dist_riemann_sphere' M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
hence "(dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))"
[PROOF STATE]
proof (prove)
using this:
(dist_riemann_sphere' M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2

goal (1 subgoal):
 1. (dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
using \<open>(1 + (cmod m1)\<^sup>2) \<noteq> 0\<close>  \<open>(1 + (cmod m2)\<^sup>2) \<noteq> 0\<close>
[PROOF STATE]
proof (prove)
using this:
(dist_riemann_sphere' M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
1 + (cmod m1)\<^sup>2 \<noteq> 0
1 + (cmod m2)\<^sup>2 \<noteq> 0

goal (1 subgoal):
 1. (dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
using eq_divide_imp[of "(1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)" "(dist_riemann_sphere' M1 M2)\<^sup>2" "4 * (cmod (m1 - m2))\<^sup>2"]
[PROOF STATE]
proof (prove)
using this:
(dist_riemann_sphere' M1 M2)\<^sup>2 * (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) = 4 * (cmod (m1 - m2))\<^sup>2
1 + (cmod m1)\<^sup>2 \<noteq> 0
1 + (cmod m2)\<^sup>2 \<noteq> 0
\<lbrakk>(1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) \<noteq> 0; (dist_riemann_sphere' M1 M2)\<^sup>2 * ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) = 4 * (cmod (m1 - m2))\<^sup>2\<rbrakk> \<Longrightarrow> (dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))

goal (1 subgoal):
 1. (dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))

goal (1 subgoal):
 1. \<lbrakk>stereographic M1 = of_complex m1; stereographic M2 = of_complex m2\<rbrakk> \<Longrightarrow> dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
thus "dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))"
[PROOF STATE]
proof (prove)
using this:
(dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))

goal (1 subgoal):
 1. dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
using power2_eq_iff[of "dist_riemann_sphere' M1 M2" "2 * (cmod (m1 - m2)) / sqrt ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))"]
[PROOF STATE]
proof (prove)
using this:
(dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))
((dist_riemann_sphere' M1 M2)\<^sup>2 = (2 * cmod (m1 - m2) / sqrt ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)))\<^sup>2) = (dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / sqrt ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) \<or> dist_riemann_sphere' M1 M2 = - (2 * cmod (m1 - m2) / sqrt ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))))

goal (1 subgoal):
 1. dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
using \<open>(1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2) > 0\<close>  \<open>(1 + (cmod m1)\<^sup>2) > 0\<close> \<open>(1 + (cmod m2)\<^sup>2) > 0\<close>
[PROOF STATE]
proof (prove)
using this:
(dist_riemann_sphere' M1 M2)\<^sup>2 = 4 * (cmod (m1 - m2))\<^sup>2 / ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))
((dist_riemann_sphere' M1 M2)\<^sup>2 = (2 * cmod (m1 - m2) / sqrt ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)))\<^sup>2) = (dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / sqrt ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)) \<or> dist_riemann_sphere' M1 M2 = - (2 * cmod (m1 - m2) / sqrt ((1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2))))
0 < (1 + (cmod m1)\<^sup>2) * (1 + (cmod m2)\<^sup>2)
0 < 1 + (cmod m1)\<^sup>2
0 < 1 + (cmod m2)\<^sup>2

goal (1 subgoal):
 1. dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))
[PROOF STEP]
apply (auto simp add: power2_eq_square real_sqrt_mult[symmetric])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < 1 + cmod m1 * cmod m1; 0 < 1 + cmod m2 * cmod m2; dist_riemann_sphere' M1 M2 = - (2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2)))\<rbrakk> \<Longrightarrow> m1 = m2
[PROOF STEP]
using dist_riemann_sphere_ge_0[of M1 M2] **
[PROOF STATE]
proof (prove)
using this:
0 \<le> dist_riemann_sphere' M1 M2
(0 \<le> 2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))) = (0 \<le> cmod (m1 - m2))

goal (1 subgoal):
 1. \<lbrakk>0 < 1 + cmod m1 * cmod m1; 0 < 1 + cmod m2 * cmod m2; dist_riemann_sphere' M1 M2 = - (2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2)))\<rbrakk> \<Longrightarrow> m1 = m2
[PROOF STEP]
using ++ divide_le_0_iff
[PROOF STATE]
proof (prove)
using this:
0 \<le> dist_riemann_sphere' M1 M2
(0 \<le> 2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))) = (0 \<le> cmod (m1 - m2))
0 < sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2))
(?a / ?b \<le> (0::?'a)) = ((0::?'a) \<le> ?a \<and> ?b \<le> (0::?'a) \<or> ?a \<le> (0::?'a) \<and> (0::?'a) \<le> ?b)

goal (1 subgoal):
 1. \<lbrakk>0 < 1 + cmod m1 * cmod m1; 0 < 1 + cmod m2 * cmod m2; dist_riemann_sphere' M1 M2 = - (2 * cmod (m1 - m2) / sqrt ((1 + cmod m1 * cmod m1) * (1 + cmod m2 * cmod m2)))\<rbrakk> \<Longrightarrow> m1 = m2
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
dist_riemann_sphere' M1 M2 = 2 * cmod (m1 - m2) / (sqrt (1 + (cmod m1)\<^sup>2) * sqrt (1 + (cmod m2)\<^sup>2))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma oppositeLiteralListIdempotency [simp]:
  fixes literalList :: "Literal list"
  shows "oppositeLiteralList (oppositeLiteralList literalList) = literalList"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. oppositeLiteralList (oppositeLiteralList literalList) = literalList
[PROOF STEP]
unfolding oppositeLiteralList_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map opposite (map opposite literalList) = literalList
[PROOF STEP]
by (induct literalList) auto


[STATEMENT]
lemma surj_uni_samp:
  assumes inj: "inj_on  (\<lambda>(b :: nat). (y + b) mod q ) {..<q}"
  shows "(\<lambda>(b :: nat). (y + b) mod q) ` {..< q} =  {..< q}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>b. (y + b) mod q) ` {..<q} = {..<q}
[PROOF STEP]
apply(rule endo_inj_surj)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. finite {..<q}
 2. (\<lambda>b. (y + b) mod q) ` {..<q} \<subseteq> {..<q}
 3. inj_on (\<lambda>b. (y + b) mod q) {..<q}
[PROOF STEP]
using inj
[PROOF STATE]
proof (prove)
using this:
inj_on (\<lambda>b. (y + b) mod q) {..<q}

goal (3 subgoals):
 1. finite {..<q}
 2. (\<lambda>b. (y + b) mod q) ` {..<q} \<subseteq> {..<q}
 3. inj_on (\<lambda>b. (y + b) mod q) {..<q}
[PROOF STEP]
by auto


[STATEMENT]
lemma wi_to_ipt_ipv4range: "\<Union>(set (map ipt_iprange_to_set (wi_to_ipt_iprange wi))) = wordinterval_to_set wi"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange wi))) = wordinterval_to_set wi
[PROOF STEP]
apply(induction wi)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>x1 x2. \<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange (WordInterval x1 x2)))) = wordinterval_to_set (WordInterval x1 x2)
 2. \<And>wi1 wi2. \<lbrakk>\<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange wi1))) = wordinterval_to_set wi1; \<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange wi2))) = wordinterval_to_set wi2\<rbrakk> \<Longrightarrow> \<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange (RangeUnion wi1 wi2)))) = wordinterval_to_set (RangeUnion wi1 wi2)
[PROOF STEP]
apply(simp add: interval_to_wi_to_ipt_ipv4range)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>wi1 wi2. \<lbrakk>\<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange wi1))) = wordinterval_to_set wi1; \<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange wi2))) = wordinterval_to_set wi2\<rbrakk> \<Longrightarrow> \<Union> (set (map ipt_iprange_to_set (wi_to_ipt_iprange (RangeUnion wi1 wi2)))) = wordinterval_to_set (RangeUnion wi1 wi2)
[PROOF STEP]
apply(simp)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma NSLIMSEQ_norm_zero: "(\<lambda>n. norm (X n)) \<longlonglongrightarrow>\<^sub>N\<^sub>S 0 \<longleftrightarrow> X \<longlonglongrightarrow>\<^sub>N\<^sub>S 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. norm (X n)) \<longlonglongrightarrow>\<^sub>N\<^sub>S 0 = X \<longlonglongrightarrow>\<^sub>N\<^sub>S (0::'a)
[PROOF STEP]
by (simp add: LIMSEQ_NSLIMSEQ_iff [symmetric] tendsto_norm_zero_iff)


[STATEMENT]
lemma sq_p_eval: "peval (P[^2]) p = (peval P p)^2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. peval (P [^2]) p = (peval P p)\<^sup>2
[PROOF STEP]
unfolding sq_p_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. peval (P [*] P) p = (peval P p)\<^sup>2
[PROOF STEP]
by (simp add: power2_eq_square)


[STATEMENT]
lemma mpoly_degree_mult_eq:
  fixes p q :: "'a :: idom mpoly"
  assumes "p \<noteq> 0" "q \<noteq> 0"
  shows   "MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x
[PROOF STEP]
interpret transfer_mpoly_to_mpoly_poly x
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
.
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x
[PROOF STEP]
define deg :: "'a mpoly \<Rightarrow> nat" where "deg = (\<lambda>p. MPoly_Type.degree p x)"
[PROOF STATE]
proof (state)
this:
deg = (\<lambda>p. MPoly_Type.degree p x)

goal (1 subgoal):
 1. MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x
[PROOF STEP]
have [transfer_rule]: "rel_fun R (=) Polynomial.degree deg"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. rel_fun R (=) Polynomial.degree deg
[PROOF STEP]
using transfer_degree
[PROOF STATE]
proof (prove)
using this:
rel_fun R (=) Polynomial.degree (\<lambda>p. MPoly_Type.degree p x)

goal (1 subgoal):
 1. rel_fun R (=) Polynomial.degree deg
[PROOF STEP]
unfolding deg_def
[PROOF STATE]
proof (prove)
using this:
rel_fun R (=) Polynomial.degree (\<lambda>p. MPoly_Type.degree p x)

goal (1 subgoal):
 1. rel_fun R (=) Polynomial.degree (\<lambda>p. MPoly_Type.degree p x)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
rel_fun R (=) Polynomial.degree deg

goal (1 subgoal):
 1. MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x
[PROOF STEP]
have "deg (p * q) = deg p + deg q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. deg (p * q) = deg p + deg q
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
p \<noteq> 0
q \<noteq> 0

goal (1 subgoal):
 1. deg (p * q) = deg p + deg q
[PROOF STEP]
unfolding deg_def [symmetric]
[PROOF STATE]
proof (prove)
using this:
p \<noteq> 0
q \<noteq> 0

goal (1 subgoal):
 1. deg (p * q) = deg p + deg q
[PROOF STEP]
by transfer (simp add: degree_mult_eq)
[PROOF STATE]
proof (state)
this:
deg (p * q) = deg p + deg q

goal (1 subgoal):
 1. MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
deg (p * q) = deg p + deg q

goal (1 subgoal):
 1. MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x
[PROOF STEP]
by (simp add: deg_def)
[PROOF STATE]
proof (state)
this:
MPoly_Type.degree (p * q) x = MPoly_Type.degree p x + MPoly_Type.degree q x

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma geometric_increasing_sum: "(\<Sum>k<n. (k+1)*r^k) = (1 - (n+1)*r^n + n*r^(n+1)) / (1-r)^2"
  if "r \<noteq> 1" for n::nat and r::real
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. real (k + 1) * r ^ k) = (1 - real (n + 1) * r ^ n + real n * r ^ (n + 1)) / (1 - r)\<^sup>2
[PROOF STEP]
by (subst geometric_increasing_sum_aux[THEN sym], simp add: that)


[STATEMENT]
lemma set_encode_insert [simp]: "finite A \<Longrightarrow> n \<notin> A \<Longrightarrow> set_encode (insert n A) = 2^n + set_encode A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>finite A; n \<notin> A\<rbrakk> \<Longrightarrow> set_encode (insert n A) = 2 ^ n + set_encode A
[PROOF STEP]
by (simp add: set_encode_def)


[STATEMENT]
lemma nsets_image_funcset:
  assumes "g \<in> S \<rightarrow> T" and "inj_on g S"
  shows "(\<lambda>X. g ` X) \<in> [S]\<^bsup>k\<^esup> \<rightarrow> [T]\<^bsup>k\<^esup>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (`) g \<in> [S]\<^bsup>k\<^esup> \<rightarrow> [T]\<^bsup>k\<^esup>
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
g \<in> S \<rightarrow> T
inj_on g S

goal (1 subgoal):
 1. (`) g \<in> [S]\<^bsup>k\<^esup> \<rightarrow> [T]\<^bsup>k\<^esup>
[PROOF STEP]
by (fastforce simp add: nsets_def card_image inj_on_subset subset_iff simp flip: image_subset_iff_funcset)


[STATEMENT]
lemma Suc_times_gbinomial: "of_nat (Suc k) * ((a + 1) gchoose (Suc k)) = (a + 1) * (a gchoose k)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
proof (cases k)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. k = 0 \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
 2. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:
k = 0

goal (2 subgoals):
 1. k = 0 \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
 2. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
k = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
k = 0

goal (1 subgoal):
 1. of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)

goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
case (Suc b)
[PROOF STATE]
proof (state)
this:
k = Suc b

goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
k = Suc b
[PROOF STEP]
have "((a + 1) gchoose (Suc (Suc b))) = (\<Prod>i = 0..Suc b. a + (1 - of_nat i)) / fact (b + 2)"
[PROOF STATE]
proof (prove)
using this:
k = Suc b

goal (1 subgoal):
 1. a + (1::'a) gchoose Suc (Suc b) = (\<Prod>i = 0..Suc b. a + ((1::'a) - of_nat i)) / fact (b + 2)
[PROOF STEP]
by (simp add: field_simps gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost)
[PROOF STATE]
proof (state)
this:
a + (1::'a) gchoose Suc (Suc b) = (\<Prod>i = 0..Suc b. a + ((1::'a) - of_nat i)) / fact (b + 2)

goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
a + (1::'a) gchoose Suc (Suc b) = (\<Prod>i = 0..Suc b. a + ((1::'a) - of_nat i)) / fact (b + 2)

goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
have "(\<Prod>i = 0..Suc b. a + (1 - of_nat i)) = (a + 1) * (\<Prod>i = 0..b. a - of_nat i)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Prod>i = 0..Suc b. a + ((1::'a) - of_nat i)) = (a + (1::'a)) * (\<Prod>i = 0..b. a - of_nat i)
[PROOF STEP]
by (simp add: prod.atLeast0_atMost_Suc_shift del: prod.cl_ivl_Suc)
[PROOF STATE]
proof (state)
this:
(\<Prod>i = 0..Suc b. a + ((1::'a) - of_nat i)) = (a + (1::'a)) * (\<Prod>i = 0..b. a - of_nat i)

goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Prod>i = 0..Suc b. a + ((1::'a) - of_nat i)) = (a + (1::'a)) * (\<Prod>i = 0..b. a - of_nat i)

goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
have "\<dots> / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a + (1::'a)) * (\<Prod>i = 0..b. a - of_nat i) / fact (b + 2) = (a + (1::'a)) / of_nat (Suc (Suc b)) * (a gchoose Suc b)
[PROOF STEP]
by (simp_all add: gbinomial_prod_rev atLeastLessThanSuc_atLeastAtMost)
[PROOF STATE]
proof (state)
this:
(a + (1::'a)) * (\<Prod>i = 0..b. a - of_nat i) / fact (b + 2) = (a + (1::'a)) / of_nat (Suc (Suc b)) * (a gchoose Suc b)

goal (1 subgoal):
 1. \<And>nat. k = Suc nat \<Longrightarrow> of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
a + (1::'a) gchoose Suc (Suc b) = (a + (1::'a)) / of_nat (Suc (Suc b)) * (a gchoose Suc b)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
a + (1::'a) gchoose Suc (Suc b) = (a + (1::'a)) / of_nat (Suc (Suc b)) * (a gchoose Suc b)

goal (1 subgoal):
 1. of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)
[PROOF STEP]
by (simp add: Suc field_simps del: of_nat_Suc)
[PROOF STATE]
proof (state)
this:
of_nat (Suc k) * (a + (1::'a) gchoose Suc k) = (a + (1::'a)) * (a gchoose k)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma gcd_mult_lcm [simp]: "gcd a b * lcm a b = normalize a * normalize b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. gcd a b * lcm a b = normalize a * normalize b
[PROOF STEP]
by (simp add: lcm_gcd normalize_mult dvd_normalize_div)


[STATEMENT]
lemma isomorphic_homology_imp_path_components:
  assumes "homology_group 0 X \<cong> homology_group 0 Y"
  shows "path_components_of X \<approx> path_components_of Y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
have "free_Abelian_group (path_components_of X) \<cong> homology_group 0 X"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. free_Abelian_group (path_components_of X) \<cong> homology_group 0 X
[PROOF STEP]
by (rule group.iso_sym) (auto simp: zeroth_homology_group)
[PROOF STATE]
proof (state)
this:
free_Abelian_group (path_components_of X) \<cong> homology_group 0 X

goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
free_Abelian_group (path_components_of X) \<cong> homology_group 0 X

goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
have "\<dots> \<cong> homology_group 0 Y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. homology_group 0 X \<cong> homology_group 0 Y
[PROOF STEP]
by (rule assms)
[PROOF STATE]
proof (state)
this:
homology_group 0 X \<cong> homology_group 0 Y

goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
homology_group 0 X \<cong> homology_group 0 Y

goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
have "\<dots> \<cong> free_Abelian_group (path_components_of Y)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. homology_group 0 Y \<cong> free_Abelian_group (path_components_of Y)
[PROOF STEP]
by (rule zeroth_homology_group)
[PROOF STATE]
proof (state)
this:
homology_group 0 Y \<cong> free_Abelian_group (path_components_of Y)

goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
free_Abelian_group (path_components_of X) \<cong> free_Abelian_group (path_components_of Y)
[PROOF STEP]
have "free_Abelian_group (path_components_of X) \<cong> free_Abelian_group (path_components_of Y)"
[PROOF STATE]
proof (prove)
using this:
free_Abelian_group (path_components_of X) \<cong> free_Abelian_group (path_components_of Y)

goal (1 subgoal):
 1. free_Abelian_group (path_components_of X) \<cong> free_Abelian_group (path_components_of Y)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
free_Abelian_group (path_components_of X) \<cong> free_Abelian_group (path_components_of Y)

goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
free_Abelian_group (path_components_of X) \<cong> free_Abelian_group (path_components_of Y)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
free_Abelian_group (path_components_of X) \<cong> free_Abelian_group (path_components_of Y)

goal (1 subgoal):
 1. path_components_of X \<approx> path_components_of Y
[PROOF STEP]
by (simp add: isomorphic_free_Abelian_groups)
[PROOF STATE]
proof (state)
this:
path_components_of X \<approx> path_components_of Y

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma cblinfun_eq_0_on_span:
  fixes S::\<open>'a::complex_normed_vector set\<close>
  assumes "x \<in> cspan S"
    and "\<And>s. s\<in>S \<Longrightarrow> F *\<^sub>V s = 0"
  shows \<open>F *\<^sub>V x = 0\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. F *\<^sub>V x = (0::'b)
[PROOF STEP]
apply (rule complex_vector.linear_eq_0_on_span[where f=F])
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. clinear ((*\<^sub>V) F)
 2. \<And>x. x \<in> ?b \<Longrightarrow> F *\<^sub>V x = (0::'b)
 3. x \<in> cspan ?b
[PROOF STEP]
using bounded_clinear.axioms(1) cblinfun_apply assms
[PROOF STATE]
proof (prove)
using this:
bounded_clinear ?f \<Longrightarrow> clinear ?f
(*\<^sub>V) ?x \<in> {f. bounded_clinear f}
x \<in> cspan S
?s \<in> S \<Longrightarrow> F *\<^sub>V ?s = (0::'b)

goal (3 subgoals):
 1. clinear ((*\<^sub>V) F)
 2. \<And>x. x \<in> ?b \<Longrightarrow> F *\<^sub>V x = (0::'b)
 3. x \<in> cspan ?b
[PROOF STEP]
by auto


[STATEMENT]
lemma mtx_vec_scaleR_commute: "A *\<^sub>V (c *\<^sub>R x) = c *\<^sub>R (A *\<^sub>V x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A *\<^sub>V (c *\<^sub>R x) = c *\<^sub>R A *\<^sub>V x
[PROOF STEP]
unfolding scaleR_sq_mtx_def sq_mtx_vec_mult_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map_fun to_vec id (*v) A (c *\<^sub>R x) = c *\<^sub>R map_fun to_vec id (*v) A x
[PROOF STEP]
apply(simp, transfer)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>A c x. A *v c *\<^sub>R x = c *\<^sub>R (A *v x)
[PROOF STEP]
by (simp add: vector_scaleR_commute)


[STATEMENT]
lemma IVT2:
  fixes f :: "'a::linear_continuum_topology \<Rightarrow> 'b::linorder_topology"
  shows "f b \<le> y \<Longrightarrow> y \<le> f a \<Longrightarrow> a \<le> b \<Longrightarrow> (\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x) \<Longrightarrow>
    \<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>f b \<le> y; y \<le> f a; a \<le> b; \<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x\<rbrakk> \<Longrightarrow> \<exists>x\<ge>a. x \<le> b \<and> f x = y
[PROOF STEP]
by (rule IVT2') (auto intro: continuous_at_imp_continuous_on)


[STATEMENT]
lemma imirror_bounds_Max: "
  \<lbrakk> finite I; I \<noteq> {}; Max I \<le> l + r \<rbrakk> \<Longrightarrow>
  Max (imirror_bounds I l r) = l + r - iMin I"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r\<rbrakk> \<Longrightarrow> Max (imirror_bounds I l r) = l + r - iMin I
[PROOF STEP]
apply (unfold imirror_bounds_def nat_mirror_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r\<rbrakk> \<Longrightarrow> Max ((-) (l + r) ` I) = l + r - iMin I
[PROOF STEP]
apply (rule Max_equality)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r\<rbrakk> \<Longrightarrow> l + r - iMin I \<in> (-) (l + r) ` I
 2. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r\<rbrakk> \<Longrightarrow> finite ((-) (l + r) ` I)
 3. \<And>x. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r; x \<in> (-) (l + r) ` I\<rbrakk> \<Longrightarrow> x \<le> l + r - iMin I
[PROOF STEP]
apply (blast intro: iMinI)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r\<rbrakk> \<Longrightarrow> finite ((-) (l + r) ` I)
 2. \<And>x. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r; x \<in> (-) (l + r) ` I\<rbrakk> \<Longrightarrow> x \<le> l + r - iMin I
[PROOF STEP]
apply simp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x. \<lbrakk>finite I; I \<noteq> {}; Max I \<le> l + r; x \<in> (-) (l + r) ` I\<rbrakk> \<Longrightarrow> x \<le> l + r - iMin I
[PROOF STEP]
apply (blast intro: iMin_le diff_le_mono2)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma cosh_poincare_distance_cross_ratio_average:
  assumes "u \<in> unit_disc" "v \<in> unit_disc" "u \<noteq> v" "ideal_points (poincare_line u v) = {i1, i2}"
  shows "cosh_dist u v =
           ((Re_cross_ratio u i1 v i2) + (Re_cross_ratio v i1 u i2)) / 2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
let ?cr = "cross_ratio u i1 v i2"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
let ?crRe = "Re (to_complex ?cr)"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
have "?cr \<noteq> \<infinity>\<^sub>h" "is_real (to_complex ?cr)" "?crRe > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cross_ratio u i1 v i2 \<noteq> \<infinity>\<^sub>h &&& is_real (to_complex (cross_ratio u i1 v i2)) &&& 0 < Re_cross_ratio u i1 v i2
[PROOF STEP]
using distance_cross_ratio_real_positive[OF assms(1-3)] assms(4)
[PROOF STATE]
proof (prove)
using this:
\<forall>i1 i2. ideal_points (poincare_line u v) = {i1, i2} \<longrightarrow> cross_ratio u i1 v i2 \<noteq> \<infinity>\<^sub>h \<and> is_real (to_complex (cross_ratio u i1 v i2)) \<and> 0 < Re_cross_ratio u i1 v i2
ideal_points (poincare_line u v) = {i1, i2}

goal (1 subgoal):
 1. cross_ratio u i1 v i2 \<noteq> \<infinity>\<^sub>h &&& is_real (to_complex (cross_ratio u i1 v i2)) &&& 0 < Re_cross_ratio u i1 v i2
[PROOF STEP]
by simp_all
[PROOF STATE]
proof (state)
this:
cross_ratio u i1 v i2 \<noteq> \<infinity>\<^sub>h
is_real (to_complex (cross_ratio u i1 v i2))
0 < Re_cross_ratio u i1 v i2

goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
cross_ratio u i1 v i2 \<noteq> \<infinity>\<^sub>h
is_real (to_complex (cross_ratio u i1 v i2))
0 < Re_cross_ratio u i1 v i2
[PROOF STEP]
obtain cr where *: "cross_ratio u i1 v i2 = of_complex cr" "cr \<noteq> 0" "is_real cr" "Re cr > 0"
[PROOF STATE]
proof (prove)
using this:
cross_ratio u i1 v i2 \<noteq> \<infinity>\<^sub>h
is_real (to_complex (cross_ratio u i1 v i2))
0 < Re_cross_ratio u i1 v i2

goal (1 subgoal):
 1. (\<And>cr. \<lbrakk>cross_ratio u i1 v i2 = of_complex cr; cr \<noteq> 0; is_real cr; 0 < Re cr\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using inf_or_of_complex[of "cross_ratio u i1 v i2"]
[PROOF STATE]
proof (prove)
using this:
cross_ratio u i1 v i2 \<noteq> \<infinity>\<^sub>h
is_real (to_complex (cross_ratio u i1 v i2))
0 < Re_cross_ratio u i1 v i2
cross_ratio u i1 v i2 = \<infinity>\<^sub>h \<or> (\<exists>x. cross_ratio u i1 v i2 = of_complex x)

goal (1 subgoal):
 1. (\<And>cr. \<lbrakk>cross_ratio u i1 v i2 = of_complex cr; cr \<noteq> 0; is_real cr; 0 < Re cr\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (smt to_complex_of_complex zero_complex.simps(1))
[PROOF STATE]
proof (state)
this:
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr

goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr

goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
using *
[PROOF STATE]
proof (prove)
using this:
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr

goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
using assms cross_ratio_commute_13[of v i1 u i2]
[PROOF STATE]
proof (prove)
using this:
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr
u \<in> unit_disc
v \<in> unit_disc
u \<noteq> v
ideal_points (poincare_line u v) = {i1, i2}
cross_ratio v i1 u i2 = reciprocal (cross_ratio u i1 v i2)

goal (1 subgoal):
 1. cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
unfolding poincare_distance_I[OF assms] calc_poincare_distance_def cosh_def
[PROOF STATE]
proof (prove)
using this:
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr
cross_ratio u i1 v i2 = of_complex cr
cr \<noteq> 0
is_real cr
0 < Re cr
u \<in> unit_disc
v \<in> unit_disc
u \<noteq> v
ideal_points (poincare_line u v) = {i1, i2}
cross_ratio v i1 u i2 = reciprocal (cross_ratio u i1 v i2)

goal (1 subgoal):
 1. (exp \<bar>ln (Re_cross_ratio u i1 v i2)\<bar> + exp (- \<bar>ln (Re_cross_ratio u i1 v i2)\<bar>)) /\<^sub>R 2 = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2
[PROOF STEP]
by (cases "Re cr \<ge> 1")
       (auto simp add: ln_div[of 0] exp_minus field_simps Re_divide power2_eq_square complex.expand)
[PROOF STATE]
proof (state)
this:
cosh_dist u v = (Re_cross_ratio u i1 v i2 + Re_cross_ratio v i1 u i2) / 2

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma pair_map_pmf1: "pair_pmf (map_pmf f A) B = map_pmf (apfst f) (pair_pmf A B)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pair_pmf (map_pmf f A) B = map_pmf (apfst f) (pair_pmf A B)
[PROOF STEP]
proof (safe intro!: pmf_eqI)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b. pmf (pair_pmf (map_pmf f A) B) (a, b) = pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b)
[PROOF STEP]
fix a :: "'a" and b :: "'b"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>a b. pmf (pair_pmf (map_pmf f A) B) (a, b) = pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b)
[PROOF STEP]
have [simp]: "\<And>c d. indicator (apfst f -` {(a, b)}) (c, d) = indicator (f -` {a}) c * (indicator {b} d::ennreal)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>c d. indicator (apfst f -` {(a, b)}) (c, d) = indicator (f -` {a}) c * indicator {b} d
[PROOF STEP]
by (auto split: split_indicator)
[PROOF STATE]
proof (state)
this:
indicator (apfst f -` {(a, b)}) (?c, ?d) = indicator (f -` {a}) ?c * indicator {b} ?d

goal (1 subgoal):
 1. \<And>a b. pmf (pair_pmf (map_pmf f A) B) (a, b) = pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b)
[PROOF STEP]
have "ennreal (pmf (pair_pmf (map_pmf f A) B) (a, b)) =
         ennreal (pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ennreal (pmf (pair_pmf (map_pmf f A) B) (a, b)) = ennreal (pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b))
[PROOF STEP]
unfolding pmf_pair ennreal_pmf_map
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ennreal (pmf (map_pmf f A) a * pmf B b) = integral\<^sup>N (measure_pmf (pair_pmf A B)) (indicator (apfst f -` {(a, b)}))
[PROOF STEP]
by (simp add: nn_integral_pair_pmf' max_def emeasure_pmf_single nn_integral_multc pmf_nonneg
                  emeasure_map_pmf[symmetric] ennreal_mult del: emeasure_map_pmf)
[PROOF STATE]
proof (state)
this:
ennreal (pmf (pair_pmf (map_pmf f A) B) (a, b)) = ennreal (pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b))

goal (1 subgoal):
 1. \<And>a b. pmf (pair_pmf (map_pmf f A) B) (a, b) = pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
ennreal (pmf (pair_pmf (map_pmf f A) B) (a, b)) = ennreal (pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b))
[PROOF STEP]
show "pmf (pair_pmf (map_pmf f A) B) (a, b) = pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b)"
[PROOF STATE]
proof (prove)
using this:
ennreal (pmf (pair_pmf (map_pmf f A) B) (a, b)) = ennreal (pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b))

goal (1 subgoal):
 1. pmf (pair_pmf (map_pmf f A) B) (a, b) = pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b)
[PROOF STEP]
by (simp add: pmf_nonneg)
[PROOF STATE]
proof (state)
this:
pmf (pair_pmf (map_pmf f A) B) (a, b) = pmf (map_pmf (apfst f) (pair_pmf A B)) (a, b)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma prime_factorization_primorial':
  "prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
have "prime_factorization (primorial' k) = (\<Sum>i<k. prime_factorization (nth_prime i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. prime_factorization (primorial' k) = (\<Sum>i<k. prime_factorization (nth_prime i))
[PROOF STEP]
unfolding primorial'_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. prime_factorization (prod nth_prime {..<k}) = (\<Sum>i<k. prime_factorization (nth_prime i))
[PROOF STEP]
by (subst prime_factorization_prod) (auto intro: prime_gt_0_nat)
[PROOF STATE]
proof (state)
this:
prime_factorization (primorial' k) = (\<Sum>i<k. prime_factorization (nth_prime i))

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
prime_factorization (primorial' k) = (\<Sum>i<k. prime_factorization (nth_prime i))

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
have "\<dots> = (\<Sum>i<k. {#nth_prime i#})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<k. prime_factorization (nth_prime i)) = (\<Sum>i<k. {#nth_prime i#})
[PROOF STEP]
by (intro sum.cong prime_factorization_prime) auto
[PROOF STATE]
proof (state)
this:
(\<Sum>i<k. prime_factorization (nth_prime i)) = (\<Sum>i<k. {#nth_prime i#})

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>i<k. prime_factorization (nth_prime i)) = (\<Sum>i<k. {#nth_prime i#})

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
have "\<dots> = (\<Sum>p\<in>nth_prime ` {..<k}. {#p#})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<k. {#nth_prime i#}) = (\<Sum>p\<in>nth_prime ` {..<k}. {#p#})
[PROOF STEP]
by (subst sum.reindex) (auto intro: inj_onI)
[PROOF STATE]
proof (state)
this:
(\<Sum>i<k. {#nth_prime i#}) = (\<Sum>p\<in>nth_prime ` {..<k}. {#p#})

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>i<k. {#nth_prime i#}) = (\<Sum>p\<in>nth_prime ` {..<k}. {#p#})

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
have "\<dots> = mset_set (nth_prime ` {..<k})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>p\<in>nth_prime ` {..<k}. {#p#}) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>p\<in>nth_prime ` {..<k}. {#p#}) = mset_set (nth_prime ` {..<k})

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})

goal (1 subgoal):
 1. prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
prime_factorization (primorial' k) = mset_set (nth_prime ` {..<k})

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma esize_union_disjoint[simp]:
    assumes "A \<inter> B = {}"
    shows "esize (A \<union> B) = esize A + esize B"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. esize (A \<union> B) = esize A + esize B
[PROOF STEP]
proof (cases "finite (A \<union> B)")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. finite (A \<union> B) \<Longrightarrow> esize (A \<union> B) = esize A + esize B
 2. infinite (A \<union> B) \<Longrightarrow> esize (A \<union> B) = esize A + esize B
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
finite (A \<union> B)

goal (2 subgoals):
 1. finite (A \<union> B) \<Longrightarrow> esize (A \<union> B) = esize A + esize B
 2. infinite (A \<union> B) \<Longrightarrow> esize (A \<union> B) = esize A + esize B
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. esize (A \<union> B) = esize A + esize B
[PROOF STEP]
using card_Un_disjoint assms True
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>finite ?A; finite ?B; ?A \<inter> ?B = {}\<rbrakk> \<Longrightarrow> card (?A \<union> ?B) = card ?A + card ?B
A \<inter> B = {}
finite (A \<union> B)

goal (1 subgoal):
 1. esize (A \<union> B) = esize A + esize B
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
esize (A \<union> B) = esize A + esize B

goal (1 subgoal):
 1. infinite (A \<union> B) \<Longrightarrow> esize (A \<union> B) = esize A + esize B
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. infinite (A \<union> B) \<Longrightarrow> esize (A \<union> B) = esize A + esize B
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
infinite (A \<union> B)

goal (1 subgoal):
 1. infinite (A \<union> B) \<Longrightarrow> esize (A \<union> B) = esize A + esize B
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. esize (A \<union> B) = esize A + esize B
[PROOF STEP]
using False
[PROOF STATE]
proof (prove)
using this:
infinite (A \<union> B)

goal (1 subgoal):
 1. esize (A \<union> B) = esize A + esize B
[PROOF STEP]
by (cases "finite A", auto)
[PROOF STATE]
proof (state)
this:
esize (A \<union> B) = esize A + esize B

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
theorem select_rec_threeway_partition:
  assumes "d > 0" "k < length xs"
  shows "select k xs = (
           let (ls, es, gs) = threeway_partition x xs;
               nl = length ls; ne = length es
           in
             if k < nl then select k ls
             else if k < nl + ne then x
             else select (k - nl - ne) gs
          )" (is "_ = ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
define ls es gs where "ls = filter (\<lambda>y. y < x) xs" and "es = filter (\<lambda>y. y = x) xs"
                    and "gs = filter (\<lambda>y. y > x) xs"
[PROOF STATE]
proof (state)
this:
ls = filter (\<lambda>y. y < x) xs
es = filter (\<lambda>y. y = x) xs
gs = filter ((<) x) xs

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
define nl ne where [simp]: "nl = length ls" "ne = length es"
[PROOF STATE]
proof (state)
this:
nl = length ls
ne = length es

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have mset_eq: "mset xs = mset ls + mset es + mset gs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mset xs = mset ls + mset es + mset gs
[PROOF STEP]
unfolding ls_def es_def gs_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mset xs = mset (filter (\<lambda>y. y < x) xs) + mset (filter (\<lambda>y. y = x) xs) + mset (filter ((<) x) xs)
[PROOF STEP]
by (induction xs) auto
[PROOF STATE]
proof (state)
this:
mset xs = mset ls + mset es + mset gs

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have length_eq: "length xs = length ls + length es + length gs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length xs = length ls + length es + length gs
[PROOF STEP]
unfolding ls_def es_def gs_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length xs = length (filter (\<lambda>y. y < x) xs) + length (filter (\<lambda>y. y = x) xs) + length (filter ((<) x) xs)
[PROOF STEP]
by (induction xs) (auto simp del: filter_True)
[PROOF STATE]
proof (state)
this:
length xs = length ls + length es + length gs

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have [simp]: "select i es = x" if "i < length es" for i
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select i es = x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. select i es = x
[PROOF STEP]
have "select i es \<in> set (sort es)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select i es \<in> set (sort es)
[PROOF STEP]
unfolding select_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sort es ! i \<in> set (sort es)
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
i < length es

goal (1 subgoal):
 1. sort es ! i \<in> set (sort es)
[PROOF STEP]
by (intro nth_mem) auto
[PROOF STATE]
proof (state)
this:
select i es \<in> set (sort es)

goal (1 subgoal):
 1. select i es = x
[PROOF STEP]
hence "select i es \<in> set es"
[PROOF STATE]
proof (prove)
using this:
select i es \<in> set (sort es)

goal (1 subgoal):
 1. select i es \<in> set es
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
select i es \<in> set (sort es)
i < length es

goal (1 subgoal):
 1. select i es \<in> set es
[PROOF STEP]
by (auto simp: select_def)
[PROOF STATE]
proof (state)
this:
select i es \<in> set es

goal (1 subgoal):
 1. select i es = x
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
select i es \<in> set es

goal (1 subgoal):
 1. select i es = x
[PROOF STEP]
have "set es \<subseteq> {x}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set es \<subseteq> {x}
[PROOF STEP]
unfolding es_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set (filter (\<lambda>y. y = x) xs) \<subseteq> {x}
[PROOF STEP]
by (induction es) auto
[PROOF STATE]
proof (state)
this:
set es \<subseteq> {x}

goal (1 subgoal):
 1. select i es = x
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
select i es \<in> {x}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
select i es \<in> {x}

goal (1 subgoal):
 1. select i es = x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
select i es = x

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?i < length es \<Longrightarrow> select ?i es = x

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have "select k xs = select k (ls @ (es @ gs))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select k xs = select k (ls @ es @ gs)
[PROOF STEP]
by (intro select_cong) (simp_all add: mset_eq)
[PROOF STATE]
proof (state)
this:
select k xs = select k (ls @ es @ gs)

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
select k xs = select k (ls @ es @ gs)

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have "\<dots> = (if k < nl then select k ls else select (k - nl) (es @ gs))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select k (ls @ es @ gs) = (if k < nl then select k ls else select (k - nl) (es @ gs))
[PROOF STEP]
unfolding nl_ne_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select k (ls @ es @ gs) = (if k < length ls then select k ls else select (k - length ls) (es @ gs))
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
(0::'a) < d
k < length xs

goal (1 subgoal):
 1. select k (ls @ es @ gs) = (if k < length ls then select k ls else select (k - length ls) (es @ gs))
[PROOF STEP]
by (intro select_append') (auto simp: ls_def es_def gs_def length_eq)
[PROOF STATE]
proof (state)
this:
select k (ls @ es @ gs) = (if k < nl then select k ls else select (k - nl) (es @ gs))

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
select k (ls @ es @ gs) = (if k < nl then select k ls else select (k - nl) (es @ gs))

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have "\<dots> = (if k < nl then select k ls else if k < nl + ne then x
                    else select (k - nl - ne) gs)" (is "?lhs' = ?rhs'")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
proof (cases "k < nl")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> k < nl

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
hence "?lhs' = select (k - nl) (es @ gs)"
[PROOF STATE]
proof (prove)
using this:
\<not> k < nl

goal (1 subgoal):
 1. (if k < nl then select k ls else select (k - nl) (es @ gs)) = select (k - nl) (es @ gs)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(if k < nl then select k ls else select (k - nl) (es @ gs)) = select (k - nl) (es @ gs)

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if k < nl then select k ls else select (k - nl) (es @ gs)) = select (k - nl) (es @ gs)

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have "\<dots> = (if k - nl < ne then select (k - nl) es else select (k - nl - ne) gs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select (k - nl) (es @ gs) = (if k - nl < ne then select (k - nl) es else select (k - nl - ne) gs)
[PROOF STEP]
unfolding nl_ne_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. select (k - length ls) (es @ gs) = (if k - length ls < length es then select (k - length ls) es else select (k - length ls - length es) gs)
[PROOF STEP]
using assms False
[PROOF STATE]
proof (prove)
using this:
(0::'a) < d
k < length xs
\<not> k < nl

goal (1 subgoal):
 1. select (k - length ls) (es @ gs) = (if k - length ls < length es then select (k - length ls) es else select (k - length ls - length es) gs)
[PROOF STEP]
by (intro select_append') (auto simp: ls_def es_def gs_def length_eq)
[PROOF STATE]
proof (state)
this:
select (k - nl) (es @ gs) = (if k - nl < ne then select (k - nl) es else select (k - nl - ne) gs)

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
select (k - nl) (es @ gs) = (if k - nl < ne then select (k - nl) es else select (k - nl - ne) gs)

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have "\<dots> = (if k - nl < ne then x else select (k - nl - ne) gs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if k - nl < ne then select (k - nl) es else select (k - nl - ne) gs) = (if k - nl < ne then x else select (k - nl - ne) gs)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(if k - nl < ne then select (k - nl) es else select (k - nl - ne) gs) = (if k - nl < ne then x else select (k - nl - ne) gs)

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if k - nl < ne then select (k - nl) es else select (k - nl - ne) gs) = (if k - nl < ne then x else select (k - nl - ne) gs)

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
from False
[PROOF STATE]
proof (chain)
picking this:
\<not> k < nl
[PROOF STEP]
have "\<dots> = ?rhs'"
[PROOF STATE]
proof (prove)
using this:
\<not> k < nl

goal (1 subgoal):
 1. (if k - nl < ne then x else select (k - nl - ne) gs) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if k - nl < ne then x else select (k - nl - ne) gs) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal (2 subgoals):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
 2. \<not> k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal (1 subgoal):
 1. (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal (1 subgoal):
 1. k < nl \<Longrightarrow> (if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
qed simp_all
[PROOF STATE]
proof (state)
this:
(if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if k < nl then select k ls else select (k - nl) (es @ gs)) = (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
have "\<dots> = ?rhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs) = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
by (simp add: threeway_partition_def Let_def ls_def es_def gs_def)
[PROOF STATE]
proof (state)
this:
(if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs) = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal (1 subgoal):
 1. select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
select k xs = (let (ls, es, gs) = threeway_partition x xs; nl = length ls; ne = length es in if k < nl then select k ls else if k < nl + ne then x else select (k - nl - ne) gs)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma independent_distinct: "independent K Us \<Longrightarrow> distinct Us"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. local.independent K Us \<Longrightarrow> distinct Us
[PROOF STEP]
proof (induct Us rule: list.induct)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. local.independent K [] \<Longrightarrow> distinct []
 2. \<And>x1 x2. \<lbrakk>local.independent K x2 \<Longrightarrow> distinct x2; local.independent K (x1 # x2)\<rbrakk> \<Longrightarrow> distinct (x1 # x2)
[PROOF STEP]
case Nil
[PROOF STATE]
proof (state)
this:
local.independent K []

goal (2 subgoals):
 1. local.independent K [] \<Longrightarrow> distinct []
 2. \<And>x1 x2. \<lbrakk>local.independent K x2 \<Longrightarrow> distinct x2; local.independent K (x1 # x2)\<rbrakk> \<Longrightarrow> distinct (x1 # x2)
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
local.independent K []

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

goal (1 subgoal):
 1. \<And>x1 x2. \<lbrakk>local.independent K x2 \<Longrightarrow> distinct x2; local.independent K (x1 # x2)\<rbrakk> \<Longrightarrow> distinct (x1 # x2)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x1 x2. \<lbrakk>local.independent K x2 \<Longrightarrow> distinct x2; local.independent K (x1 # x2)\<rbrakk> \<Longrightarrow> distinct (x1 # x2)
[PROOF STEP]
case Cons
[PROOF STATE]
proof (state)
this:
local.independent K x2_ \<Longrightarrow> distinct x2_
local.independent K (x1_ # x2_)

goal (1 subgoal):
 1. \<And>x1 x2. \<lbrakk>local.independent K x2 \<Longrightarrow> distinct x2; local.independent K (x1 # x2)\<rbrakk> \<Longrightarrow> distinct (x1 # x2)
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
local.independent K x2_ \<Longrightarrow> distinct x2_
local.independent K (x1_ # x2_)

goal (1 subgoal):
 1. distinct (x1_ # x2_)
[PROOF STEP]
using independent_backwards[OF Cons(2)]
          independent_in_carrier[OF Cons(2)]
          Span_base_incl
[PROOF STATE]
proof (prove)
using this:
local.independent K x2_ \<Longrightarrow> distinct x2_
local.independent K (x1_ # x2_)
x1_ \<notin> Span K x2_
local.independent K x2_
x1_ \<in> carrier R
set (x1_ # x2_) \<subseteq> carrier R
set ?Us \<subseteq> carrier R \<Longrightarrow> set ?Us \<subseteq> Span K ?Us

goal (1 subgoal):
 1. distinct (x1_ # x2_)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
distinct (x1_ # x2_)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma card_sumset_geq2:
  shows "card(int.sumset A A) \<ge> 2 * (card A) - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 2 * card A - 1 \<le> card (int.sumset A A)
[PROOF STEP]
using card_sumset_geq1 [of A]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>A \<noteq> {}; finite A; ?B \<noteq> {}; finite ?B\<rbrakk> \<Longrightarrow> card A + card ?B - 1 \<le> card (int.sumset A ?B)

goal (1 subgoal):
 1. 2 * card A - 1 \<le> card (int.sumset A A)
[PROOF STEP]
by (metis mult.commute Nat.add_0_right card_eq_0_iff diff_0_eq_0 le0 mult_2_right)


[STATEMENT]
lemma sum_list_concat: "sum_list (concat xs) = sum_list (map sum_list xs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum_list (concat xs) = sum_list (map sum_list xs)
[PROOF STEP]
by (induct xs, auto)


[STATEMENT]
lemma det3_eq_det: "det3 (xa, ya) (xb, yb) (xc, yc) =
  det (vector [vector [xa, ya, 1], vector [xb, yb, 1], vector [xc, yc, 1]]::real^3^3)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det3 (xa, ya) (xb, yb) (xc, yc) = det (vector [vector [xa, ya, 1], vector [xb, yb, 1], vector [xc, yc, 1]])
[PROOF STEP]
unfolding Determinants.det_def UNIV_3
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det3 (xa, ya) (xb, yb) (xc, yc) = (\<Sum>p | p permutes {1, 2, 3}. real_of_int (sign p) * (\<Prod>i\<in>{1, 2, 3}. vector [vector [xa, ya, 1], vector [xb, yb, 1], vector [xc, yc, 1]] $ i $ p i))
[PROOF STEP]
by (auto simp: sum_over_permutations_insert
    vector_3 sign_swap_id permutation_swap_id sign_compose)


[STATEMENT]
lemma ln_2_40_decimals:
  "\<bar>ln 2 - 0.6931471805599453094172321214581765680755\<bar>
      \<le> inverse (10^40 :: real)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>ln 2 - 6931471805599453094172321214581765680755 / 10 ^ 40\<bar> \<le> inverse (10 ^ 40)
[PROOF STEP]
apply (rule ln_approx_abs''[where n = 40], simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ln_approx_aux1 (6931471805599453094172321214581765680755 / 10 ^ 40) (inverse (10 ^ 40)) 40 2
[PROOF STEP]
apply (simp, simp add: ln_approx_aux1_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ln_approx_aux2 (1386294361119890618834464242916353136151 / 2000000000000000000000000000000000000000) (1 / 10000000000000000000000000000000000000000) 40 (1 / 3)
[PROOF STEP]
apply (simp add: ln_approx_aux2_def power2_eq_square power_divide)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ln_approx_aux3 (1386294361119890618834464242916353136151 / 2000000000000000000000000000000000000000) (1 / 10000000000000000000000000000000000000000) 40 (1 / 3) (1 / 31926707153498719436273973404578792281816)
[PROOF STEP]
apply (simp add: ln_approx_aux3_def power2_eq_square)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>2 * (\<Sum>k<40. inverse (1 + 2 * real k) * (1 / 9) ^ k) / 3 - 5532476762002668606650923253863934299838063163113583244044097734262260626191277 / 7981676788374679859068493351144698070454000000000000000000000000000000000000000\<bar> * 39908383941873399295342466755723490352270000000000000000000000000000000000000000 \<le> 2740838394187339929534246675572349035227
[PROOF STEP]
apply (simp add: sum_poly_horner_expand)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma less_eq_Max_lit: "C \<noteq> {#} \<Longrightarrow> C \<le> D \<Longrightarrow> Max_mset C \<le> Max_mset D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>C \<noteq> {#}; C \<le> D\<rbrakk> \<Longrightarrow> Max_mset C \<le> Max_mset D
[PROOF STEP]
proof (unfold less_eq_multiset\<^sub>H\<^sub>O)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<lbrakk>C \<noteq> {#}; \<forall>y. count D y < count C y \<longrightarrow> (\<exists>x>y. count C x < count D x)\<rbrakk> \<Longrightarrow> Max_mset C \<le> Max_mset D
[PROOF STEP]
assume
    ne: "C \<noteq> {#}" and
    ex_gt: "\<forall>x. count D x < count C x \<longrightarrow> (\<exists>y > x. count C y < count D y)"
[PROOF STATE]
proof (state)
this:
C \<noteq> {#}
\<forall>x. count D x < count C x \<longrightarrow> (\<exists>y>x. count C y < count D y)

goal (1 subgoal):
 1. \<lbrakk>C \<noteq> {#}; \<forall>y. count D y < count C y \<longrightarrow> (\<exists>x>y. count C x < count D x)\<rbrakk> \<Longrightarrow> Max_mset C \<le> Max_mset D
[PROOF STEP]
from ne
[PROOF STATE]
proof (chain)
picking this:
C \<noteq> {#}
[PROOF STEP]
have "Max_mset C \<in># C"
[PROOF STATE]
proof (prove)
using this:
C \<noteq> {#}

goal (1 subgoal):
 1. Max_mset C \<in># C
[PROOF STEP]
by (fast intro: Max_in_lits)
[PROOF STATE]
proof (state)
this:
Max_mset C \<in># C

goal (1 subgoal):
 1. \<lbrakk>C \<noteq> {#}; \<forall>y. count D y < count C y \<longrightarrow> (\<exists>x>y. count C x < count D x)\<rbrakk> \<Longrightarrow> Max_mset C \<le> Max_mset D
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
Max_mset C \<in># C
[PROOF STEP]
have "\<exists>l. l \<in># D \<and> \<not> l < Max_mset C"
[PROOF STATE]
proof (prove)
using this:
Max_mset C \<in># C

goal (1 subgoal):
 1. \<exists>l. l \<in># D \<and> \<not> l < Max_mset C
[PROOF STEP]
using ex_gt
[PROOF STATE]
proof (prove)
using this:
Max_mset C \<in># C
\<forall>x. count D x < count C x \<longrightarrow> (\<exists>y>x. count C y < count D y)

goal (1 subgoal):
 1. \<exists>l. l \<in># D \<and> \<not> l < Max_mset C
[PROOF STEP]
by (metis count_greater_zero_iff count_inI less_not_sym)
[PROOF STATE]
proof (state)
this:
\<exists>l. l \<in># D \<and> \<not> l < Max_mset C

goal (1 subgoal):
 1. \<lbrakk>C \<noteq> {#}; \<forall>y. count D y < count C y \<longrightarrow> (\<exists>x>y. count C x < count D x)\<rbrakk> \<Longrightarrow> Max_mset C \<le> Max_mset D
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<exists>l. l \<in># D \<and> \<not> l < Max_mset C
[PROOF STEP]
have "\<not> Max_mset D < Max_mset C"
[PROOF STATE]
proof (prove)
using this:
\<exists>l. l \<in># D \<and> \<not> l < Max_mset C

goal (1 subgoal):
 1. \<not> Max_mset D < Max_mset C
[PROOF STEP]
by (metis Max.coboundedI[OF finite_set_mset] le_less_trans)
[PROOF STATE]
proof (state)
this:
\<not> Max_mset D < Max_mset C

goal (1 subgoal):
 1. \<lbrakk>C \<noteq> {#}; \<forall>y. count D y < count C y \<longrightarrow> (\<exists>x>y. count C x < count D x)\<rbrakk> \<Longrightarrow> Max_mset C \<le> Max_mset D
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> Max_mset D < Max_mset C
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<not> Max_mset D < Max_mset C

goal (1 subgoal):
 1. Max_mset C \<le> Max_mset D
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Max_mset C \<le> Max_mset D

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma inverse_mat_base_case:
  shows "inverts_mat (mat_of_rows_list 2 [[1/2, 1/2], [1/2, -(1/2)]]::rat mat) (mat_of_rows_list 2 [[1, 1], [1, -1]]::rat mat)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inverts_mat (mat_of_rows_list 2 [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) (mat_of_rows_list 2 [[1, 1], [1, - 1]])
[PROOF STEP]
unfolding inverts_mat_def mat_of_rows_list_def mat_eq_iff
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. dim_row (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y) * mat (length [[1, 1], [1, - 1]]) 2 (\<lambda>(i, y). [[1, 1], [1, - 1]] ! i ! y)) = dim_row (1\<^sub>m (dim_row (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y)))) \<and> dim_col (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y) * mat (length [[1, 1], [1, - 1]]) 2 (\<lambda>(i, y). [[1, 1], [1, - 1]] ! i ! y)) = dim_col (1\<^sub>m (dim_row (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y)))) \<and> (\<forall>i j. i < dim_row (1\<^sub>m (dim_row (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y)))) \<longrightarrow> j < dim_col (1\<^sub>m (dim_row (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y)))) \<longrightarrow> (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y) * mat (length [[1, 1], [1, - 1]]) 2 (\<lambda>(i, y). [[1, 1], [1, - 1]] ! i ! y)) $$ (i, j) = 1\<^sub>m (dim_row (mat (length [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]]) 2 (\<lambda>(i, y). [[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i ! y))) $$ (i, j))
[PROOF STEP]
apply auto
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>j. j < Suc (Suc 0) \<Longrightarrow> vec 2 ((!) ([[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! j)) \<bullet> vec (Suc (Suc 0)) (\<lambda>i. [[1, 1], [1, - 1]] ! i ! j) = 1
 2. \<And>i j. \<lbrakk>i < Suc (Suc 0); i \<noteq> j; j < Suc (Suc 0)\<rbrakk> \<Longrightarrow> vec 2 ((!) ([[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i)) \<bullet> vec (Suc (Suc 0)) (\<lambda>i. [[1, 1], [1, - 1]] ! i ! j) = 0
[PROOF STEP]
unfolding less_two
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>j. j = 0 \<or> j = 1 \<Longrightarrow> vec 2 ((!) ([[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! j)) \<bullet> vec (Suc (Suc 0)) (\<lambda>i. [[1, 1], [1, - 1]] ! i ! j) = 1
 2. \<And>i j. \<lbrakk>i = 0 \<or> i = 1; i \<noteq> j; j = 0 \<or> j = 1\<rbrakk> \<Longrightarrow> vec 2 ((!) ([[1 / 2, 1 / 2], [1 / 2, - (1 / 2)]] ! i)) \<bullet> vec (Suc (Suc 0)) (\<lambda>i. [[1, 1], [1, - 1]] ! i ! j) = 0
[PROOF STEP]
by (auto simp add: scalar_prod_def)


[STATEMENT]
lemma Max_Suc_Suc_Max:
  \<open>finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> Max (insert 0 (Suc ` A)) =
    Suc (Max (insert 0 A))\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> Max (insert 0 (Suc ` A)) = Suc (Max (insert 0 A))
[PROOF STEP]
by (induction rule: finite_induct)
   (auto simp: hom_Max_commute)


[STATEMENT]
lemma nth_append_Cons: "(xs @ y # zs) ! i =
  (if i < length xs then xs ! i else if i = length xs then y else zs ! (i - Suc (length xs)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (xs @ y # zs) ! i = (if i < length xs then xs ! i else if i = length xs then y else zs ! (i - Suc (length xs)))
[PROOF STEP]
by (cases i "length xs" rule: linorder_cases, auto simp: nth_append)


[STATEMENT]
lemma circle_polar_smooth: "(circle_polar) C1_differentiable_on {0..1}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. circle_polar C1_differentiable_on {0..1}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. circle_polar C1_differentiable_on {0..1}
[PROOF STEP]
have "inj ((*) (2 * pi))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj ((*) (2 * pi))
[PROOF STEP]
by (auto simp: inj_on_def)
[PROOF STATE]
proof (state)
this:
inj ((*) (2 * pi))

goal (1 subgoal):
 1. circle_polar C1_differentiable_on {0..1}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
inj ((*) (2 * pi))
[PROOF STEP]
have *: "\<And>x. finite ({0..1} \<inter> (*) (2 * pi) -` {x})"
[PROOF STATE]
proof (prove)
using this:
inj ((*) (2 * pi))

goal (1 subgoal):
 1. \<And>x. finite ({0..1} \<inter> (*) (2 * pi) -` {x})
[PROOF STEP]
by (simp add: finite_vimageI)
[PROOF STATE]
proof (state)
this:
finite ({0..1} \<inter> (*) (2 * pi) -` {?x4})

goal (1 subgoal):
 1. circle_polar C1_differentiable_on {0..1}
[PROOF STEP]
have "(\<lambda>t. ((d/2)  * cos (2 * pi * t), (d/2) * sin (2 * pi * t))) C1_differentiable_on {0..1}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>t. (d / 2 * cos (2 * pi * t), d / 2 * sin (2 * pi * t))) C1_differentiable_on {0..1}
[PROOF STEP]
by (rule * derivative_intros)+
[PROOF STATE]
proof (state)
this:
(\<lambda>t. (d / 2 * cos (2 * pi * t), d / 2 * sin (2 * pi * t))) C1_differentiable_on {0..1}

goal (1 subgoal):
 1. circle_polar C1_differentiable_on {0..1}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>t. (d / 2 * cos (2 * pi * t), d / 2 * sin (2 * pi * t))) C1_differentiable_on {0..1}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<lambda>t. (d / 2 * cos (2 * pi * t), d / 2 * sin (2 * pi * t))) C1_differentiable_on {0..1}

goal (1 subgoal):
 1. circle_polar C1_differentiable_on {0..1}
[PROOF STEP]
apply (rule eq_smooth_gen)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>x. (d / 2 * cos (2 * pi * x), d / 2 * sin (2 * pi * x)) = circle_polar x
[PROOF STEP]
by(simp add: circle_polar_def)
[PROOF STATE]
proof (state)
this:
circle_polar C1_differentiable_on {0..1}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma proj_psi_is_projection:
  "proj_psi * proj_psi = proj_psi"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. proj_psi * proj_psi = proj_psi
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. proj_psi * proj_psi = proj_psi
[PROOF STEP]
have "proj_psi * proj_psi = inner_prod \<psi> \<psi> \<cdot>\<^sub>m proj_psi"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. proj_psi * proj_psi = inner_prod \<psi> \<psi> \<cdot>\<^sub>m proj_psi
[PROOF STEP]
unfolding proj_psi_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. outer_prod \<psi> \<psi> * outer_prod \<psi> \<psi> = inner_prod \<psi> \<psi> \<cdot>\<^sub>m outer_prod \<psi> \<psi>
[PROOF STEP]
apply (subst outer_prod_mult_outer_prod)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. \<psi> \<in> carrier_vec ?d1.0
 2. \<psi> \<in> carrier_vec ?d2.0
 3. \<psi> \<in> carrier_vec ?d3.0
 4. inner_prod \<psi> \<psi> \<cdot>\<^sub>m outer_prod \<psi> \<psi> = inner_prod \<psi> \<psi> \<cdot>\<^sub>m outer_prod \<psi> \<psi>
[PROOF STEP]
using  \<psi>_def
[PROOF STATE]
proof (prove)
using this:
\<psi> = Matrix.vec N (\<lambda>x. complex_of_real (1 / sqrt (real N)))

goal (4 subgoals):
 1. \<psi> \<in> carrier_vec ?d1.0
 2. \<psi> \<in> carrier_vec ?d2.0
 3. \<psi> \<in> carrier_vec ?d3.0
 4. inner_prod \<psi> \<psi> \<cdot>\<^sub>m outer_prod \<psi> \<psi> = inner_prod \<psi> \<psi> \<cdot>\<^sub>m outer_prod \<psi> \<psi>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
proj_psi * proj_psi = inner_prod \<psi> \<psi> \<cdot>\<^sub>m proj_psi

goal (1 subgoal):
 1. proj_psi * proj_psi = proj_psi
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
proj_psi * proj_psi = inner_prod \<psi> \<psi> \<cdot>\<^sub>m proj_psi

goal (1 subgoal):
 1. proj_psi * proj_psi = proj_psi
[PROOF STEP]
have "\<dots> = proj_psi"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inner_prod \<psi> \<psi> \<cdot>\<^sub>m proj_psi = proj_psi
[PROOF STEP]
using \<psi>_inner
[PROOF STATE]
proof (prove)
using this:
inner_prod \<psi> \<psi> = 1

goal (1 subgoal):
 1. inner_prod \<psi> \<psi> \<cdot>\<^sub>m proj_psi = proj_psi
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
inner_prod \<psi> \<psi> \<cdot>\<^sub>m proj_psi = proj_psi

goal (1 subgoal):
 1. proj_psi * proj_psi = proj_psi
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
proj_psi * proj_psi = proj_psi
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
proj_psi * proj_psi = proj_psi

goal (1 subgoal):
 1. proj_psi * proj_psi = proj_psi
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
proj_psi * proj_psi = proj_psi

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma lconjseq_alternating_order2_repeats:
  fixes   s t :: 'a and k :: nat
  defines altst: "altst \<equiv> \<lambda>n. alternating_list n s t"
  and     altts: "altts \<equiv> \<lambda>n. alternating_list n t s"
  assumes st: "s+s=0" "t+t=0" "(s+t)+^k = 0"
  shows   "lconjseq (altst (2*k)) = lconjseq (altst k) @ lconjseq (altst k)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. lconjseq (altst (2 * k)) = lconjseq (altst k) @ lconjseq (altst k)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. lconjseq (altst (2 * k)) = lconjseq (altst k) @ lconjseq (altst k)
[PROOF STEP]
from altst altts
[PROOF STATE]
proof (chain)
picking this:
altst \<equiv> \<lambda>n. alternating_list n s t
altts \<equiv> \<lambda>n. alternating_list n t s
[PROOF STEP]
have "lconjseq (altst (2*k)) = lconjseq (altst k) @
            map (lconjby (sum_list (altst k)))
              (lconjseq (if even k then altst k else altts k))"
[PROOF STATE]
proof (prove)
using this:
altst \<equiv> \<lambda>n. alternating_list n s t
altts \<equiv> \<lambda>n. alternating_list n t s

goal (1 subgoal):
 1. lconjseq (altst (2 * k)) = lconjseq (altst k) @ map (lconjby (sum_list (altst k))) (lconjseq (if even k then altst k else altts k))
[PROOF STEP]
using alternating_list_append[THEN sym, of k k s t]
[PROOF STATE]
proof (prove)
using this:
altst \<equiv> \<lambda>n. alternating_list n s t
altts \<equiv> \<lambda>n. alternating_list n t s
even k \<Longrightarrow> alternating_list (k + k) s t = alternating_list k s t @ alternating_list k s t
odd k \<Longrightarrow> alternating_list (k + k) s t = alternating_list k s t @ alternating_list k t s

goal (1 subgoal):
 1. lconjseq (altst (2 * k)) = lconjseq (altst k) @ map (lconjby (sum_list (altst k))) (lconjseq (if even k then altst k else altts k))
[PROOF STEP]
by    (auto simp add: times2_conv_add lconjseq_append)
[PROOF STATE]
proof (state)
this:
lconjseq (altst (2 * k)) = lconjseq (altst k) @ map (lconjby (sum_list (altst k))) (lconjseq (if even k then altst k else altts k))

goal (1 subgoal):
 1. lconjseq (altst (2 * k)) = lconjseq (altst k) @ lconjseq (altst k)
[PROOF STEP]
with altst altts st
[PROOF STATE]
proof (chain)
picking this:
altst \<equiv> \<lambda>n. alternating_list n s t
altts \<equiv> \<lambda>n. alternating_list n t s
s + s = (0::'a)
t + t = (0::'a)
(s + t) +^ k = (0::'a)
lconjseq (altst (2 * k)) = lconjseq (altst k) @ map (lconjby (sum_list (altst k))) (lconjseq (if even k then altst k else altts k))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
altst \<equiv> \<lambda>n. alternating_list n s t
altts \<equiv> \<lambda>n. alternating_list n t s
s + s = (0::'a)
t + t = (0::'a)
(s + t) +^ k = (0::'a)
lconjseq (altst (2 * k)) = lconjseq (altst k) @ map (lconjby (sum_list (altst k))) (lconjseq (if even k then altst k else altts k))

goal (1 subgoal):
 1. lconjseq (altst (2 * k)) = lconjseq (altst k) @ lconjseq (altst k)
[PROOF STEP]
using lconjseq_alternating_order2_repeats'[of s t k k]
[PROOF STATE]
proof (prove)
using this:
altst \<equiv> \<lambda>n. alternating_list n s t
altts \<equiv> \<lambda>n. alternating_list n t s
s + s = (0::'a)
t + t = (0::'a)
(s + t) +^ k = (0::'a)
lconjseq (altst (2 * k)) = lconjseq (altst k) @ map (lconjby (sum_list (altst k))) (lconjseq (if even k then altst k else altts k))
\<lbrakk>s + s = (0::'a); t + t = (0::'a); (s + t) +^ k = (0::'a)\<rbrakk> \<Longrightarrow> map (lconjby (sum_list (alternating_list k s t))) (lconjseq (if even k then alternating_list k s t else alternating_list k t s)) = lconjseq (alternating_list k s t)

goal (1 subgoal):
 1. lconjseq (altst (2 * k)) = lconjseq (altst k) @ lconjseq (altst k)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
lconjseq (altst (2 * k)) = lconjseq (altst k) @ lconjseq (altst k)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma finite_monotonic_image:
  fixes A B :: "nat set"
  assumes "\<And>i. i \<in> A \<Longrightarrow> i \<le> f i"
  assumes "f ` A = B"
  shows "finite A \<longleftrightarrow> finite B"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite A = finite B
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. finite A \<Longrightarrow> finite B
 2. finite B \<Longrightarrow> finite A
[PROOF STEP]
assume "finite B"
[PROOF STATE]
proof (state)
this:
finite B

goal (2 subgoals):
 1. finite A \<Longrightarrow> finite B
 2. finite B \<Longrightarrow> finite A
[PROOF STEP]
thus "finite A"
[PROOF STATE]
proof (prove)
using this:
finite B

goal (1 subgoal):
 1. finite A
[PROOF STEP]
proof (cases "B \<noteq> {}")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<lbrakk>finite B; B \<noteq> {}\<rbrakk> \<Longrightarrow> finite A
 2. \<lbrakk>finite B; \<not> B \<noteq> {}\<rbrakk> \<Longrightarrow> finite A
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
B \<noteq> {}

goal (2 subgoals):
 1. \<lbrakk>finite B; B \<noteq> {}\<rbrakk> \<Longrightarrow> finite A
 2. \<lbrakk>finite B; \<not> B \<noteq> {}\<rbrakk> \<Longrightarrow> finite A
[PROOF STEP]
hence "\<And>i. i \<in> A \<Longrightarrow> i \<le> Max B"
[PROOF STATE]
proof (prove)
using this:
B \<noteq> {}

goal (1 subgoal):
 1. \<And>i. i \<in> A \<Longrightarrow> i \<le> Max B
[PROOF STEP]
by (metis assms Max_ge_iff \<open>finite B\<close> imageI)
[PROOF STATE]
proof (state)
this:
?i \<in> A \<Longrightarrow> ?i \<le> Max B

goal (2 subgoals):
 1. \<lbrakk>finite B; B \<noteq> {}\<rbrakk> \<Longrightarrow> finite A
 2. \<lbrakk>finite B; \<not> B \<noteq> {}\<rbrakk> \<Longrightarrow> finite A
[PROOF STEP]
thus "finite A"
[PROOF STATE]
proof (prove)
using this:
?i \<in> A \<Longrightarrow> ?i \<le> Max B

goal (1 subgoal):
 1. finite A
[PROOF STEP]
unfolding finite_nat_set_iff_bounded_le
[PROOF STATE]
proof (prove)
using this:
?i \<in> A \<Longrightarrow> ?i \<le> Max B

goal (1 subgoal):
 1. \<exists>m. \<forall>n\<in>A. n \<le> m
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
finite A

goal (1 subgoal):
 1. \<lbrakk>finite B; \<not> B \<noteq> {}\<rbrakk> \<Longrightarrow> finite A
[PROOF STEP]
qed (metis assms(2) image_is_empty)
[PROOF STATE]
proof (state)
this:
finite A

goal (1 subgoal):
 1. finite A \<Longrightarrow> finite B
[PROOF STEP]
qed (metis assms(2) finite_imageI)