# HG changeset patch # User Manuel Eberl # Date 1744731500 -7200 # Node ID da14e77a48b2c385b4e7bb415939045454399df6 # Parent 111b1b2a2d136ea74b390ba398bf9ff41b5fab49 lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Change_Of_Vars.thy --- a/src/HOL/Analysis/Change_Of_Vars.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Change_Of_Vars.thy Tue Apr 15 17:38:20 2025 +0200 @@ -3425,4 +3425,23 @@ using measurable_differentiable_image_eq [OF S der_f inj] assms has_measure_differentiable_image by blast +lemma has_absolute_integral_reflect_real: + fixes f :: "real \ real" + assumes "uminus ` A \ B" "uminus ` B \ A" "A \ sets lebesgue" + shows "(\x. f (-x)) absolutely_integrable_on A \ integral A (\x. f (-x)) = b \ + f absolutely_integrable_on B \ integral B f = b" +proof - + have bij: "bij_betw uminus A B" + by (rule bij_betwI[of _ _ _ uminus]) (use assms(1,2) in auto) + have "((\x. \-1\ *\<^sub>R f (-x)) absolutely_integrable_on A \ + integral A (\x. \-1\ *\<^sub>R f (-x)) = b) \ + (f absolutely_integrable_on uminus ` A \ + integral (uminus ` A) f = b)" using assms + by (intro has_absolute_integral_change_of_variables_1') (auto intro!: derivative_eq_intros) + also have "uminus ` A = B" + using bij by (simp add: bij_betw_def) + finally show ?thesis + by simp +qed + end diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Complex_Transcendental.thy --- a/src/HOL/Analysis/Complex_Transcendental.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Complex_Transcendental.thy Tue Apr 15 17:38:20 2025 +0200 @@ -1107,6 +1107,7 @@ using assms mpi_less_Im_Ln [of "exp z"] Im_Ln_le_pi [of "exp z"] by auto qed auto + subsection\<^marker>\tag unimportant\\Relation to Real Logarithm\ lemma Ln_of_real: @@ -2014,6 +2015,12 @@ lemma Arg_eq_0: "Arg z = 0 \ z \ \ \ 0 \ Re z" using Arg_def Im_Ln_eq_0 complex_eq_iff complex_is_Real_iff by auto +lemma Arg_neg_iff: "Arg x < 0 \ Im x < 0" + using Arg_less_0 linorder_not_le by blast + +lemma Arg_pos_iff: "Arg x > 0 \ Im x > 0 \ (Im x = 0 \ Re x < 0)" + by (metis Arg_eq_pi Arg_le_pi Arg_lt_pi order_less_le pi_gt_zero) + corollary\<^marker>\tag unimportant\ Arg_ne_0: assumes "z \ \\<^sub>\\<^sub>0" shows "Arg z \ 0" using assms by (auto simp: nonneg_Reals_def Arg_eq_0) @@ -2065,6 +2072,11 @@ lemma Ln_Arg: "z\0 \ Ln(z) = ln(norm z) + \ * Arg(z)" by (metis Arg_def Re_Ln complex_eq) +lemma Ln_of_real': + assumes "x \ 0" + shows "Ln (of_real x) = of_real (ln \x\) + (if x < 0 then pi else 0) * \" + by (subst Ln_Arg) (use assms in auto) + lemma continuous_at_Arg: assumes "z \ \\<^sub>\\<^sub>0" shows "continuous (at z) Arg" @@ -2079,6 +2091,20 @@ lemma continuous_within_Arg: "z \ \\<^sub>\\<^sub>0 \ continuous (at z within S) Arg" using continuous_at_Arg continuous_at_imp_continuous_within by blast + +lemma continuous_on_Arg: "continuous_on (-\\<^sub>\\<^sub>0) Arg" + using continuous_at_Arg by (simp add: continuous_at_imp_continuous_on) + +lemma continuous_on_Arg' [continuous_intros]: + assumes "continuous_on A f" "\z. z \ A \ f z \ \\<^sub>\\<^sub>0" + shows "continuous_on A (\x. Arg (f x))" + by (rule continuous_on_compose2[OF continuous_on_Arg assms(1)]) (use assms(2) in auto) + +lemma tendsto_Arg [tendsto_intros]: + assumes "(f \ z) F" "z \ \\<^sub>\\<^sub>0" + shows "((\x. Arg (f x)) \ Arg z) F" + by (rule isCont_tendsto_compose[OF continuous_at_Arg]) (use assms in auto) + lemma Arg_Re_pos: "\Arg z\ < pi / 2 \ Re z > 0 \ z = 0" using Arg_def Re_Ln_pos_lt by auto @@ -2089,6 +2115,37 @@ assumes "Arg z + Arg w \ {-pi<..pi}" "z \ 0" "w \ 0" shows "Arg (z * w) = Arg z + Arg w" using Arg_eq_Im_Ln Ln_times_simple assms by auto + +lemma Arg_unique': "r > 0 \ \ \ {-pi<..pi} \ x = rcis r \ \ Arg x = \" + by (rule Arg_unique[of r]) (auto simp: rcis_def cis_conv_exp) + +lemma Arg_times': + assumes "w \ 0" "z \ 0" + defines "x \ Arg w + Arg z" + shows "Arg (w * z) = x + (if x \ {-pi<..pi} then 0 else if x > pi then -2*pi else 2*pi)" +proof (rule Arg_unique'[of "norm w * norm z"]) + show "w * z = rcis (cmod w * cmod z) + (x + (if x \ {- pi<..pi} then 0 else if x > pi then -2*pi else 2*pi))" + by (subst (1 3) rcis_cmod_Arg [symmetric]) + (use assms in \auto simp: rcis_def simp flip: cis_mult cis_divide cis_inverse\) + show "x + (if x \ {- pi<..pi} then 0 else if pi < x then - 2 * pi else 2 * pi) \ {- pi<..pi}" + using Arg_bounded[of w] Arg_bounded[of z] by (auto simp: x_def) +qed (use assms in auto) + +lemma Arg_divide': + assumes [simp]: "z \ 0" "w \ 0" + shows "Arg (z / w) = Arg z - Arg w + + (if Arg z - Arg w > pi then -2 * pi else if Arg z - Arg w \ -pi then 2 * pi else 0)" + (is "_ = ?rhs") +proof - + have "Arg (z * inverse w) = ?rhs" + by (subst Arg_times') + (use Arg_bounded[of w] Arg_bounded[of z] + in \auto simp: Arg_inverse elim!: Reals_cases split: if_splits\)+ + also have "z * inverse w = z / w" + by (simp add: field_simps) + finally show ?thesis . +qed subsection\The Unwinding Number and the Ln product Formula\ @@ -2860,6 +2917,31 @@ by simp qed +lemma csqrt_in_nonpos_Reals_iff [simp]: "csqrt z \ \\<^sub>\\<^sub>0 \ z = 0" +proof + assume "csqrt z \ \\<^sub>\\<^sub>0" + hence "csqrt z = 0" + unfolding complex_eq_iff using csqrt_principal[of z] + by (auto simp: complex_nonpos_Reals_iff sgn_if simp del: csqrt.sel split: if_splits) + thus "z = 0" + by simp +qed auto + +lemma Im_csqrt_eq_0_iff: "Im (csqrt z) = 0 \ z \ \\<^sub>\\<^sub>0" +proof + assume *: "Im (csqrt z) = 0" + define x where "x = Re (csqrt z)" + have "z = csqrt z ^ 2" + by simp + also have "csqrt z = of_real x" + by (simp add: complex_eq_iff x_def * del: csqrt.sel) + also have "\ ^ 2 = of_real (x ^ 2)" + by simp + also have "\ \ \\<^sub>\\<^sub>0" + unfolding nonneg_Reals_of_real_iff by auto + finally show "z \ \\<^sub>\\<^sub>0" . +qed (auto elim!: nonneg_Reals_cases) + lemma csqrt_conv_powr: "csqrt z = z powr (1/2)" by (auto simp: csqrt_exp_Ln powr_def) @@ -3965,4 +4047,618 @@ apply (auto simp: Re_complex_div_eq_0 exp_of_nat_mult [symmetric] mult_ac exp_Euler) done + +subsection \Normalisation of angles\ + +text \ + The following operation normalises an angle $\varphi$, i.e.\ returns the unique + $\psi$ in the range $(-\pi, \pi]$ such that + $\varphi\equiv\psi\hskip.5em(\text{mod}\ 2\pi)$. + This is the same convention used by the \<^const>\Arg\ function. +\ +definition normalize_angle :: "real \ real" where + "normalize_angle x = x - \x / (2 * pi) - 1 / 2\ * (2 * pi)" + +lemma normalize_angle_id [simp]: + assumes "x \ {-pi<..pi}" + shows "normalize_angle x = x" +proof - + have "-1 < x / (2 * pi) - 1 / 2" "x / (2 * pi) - 1 / 2 \ 0" + using assms pi_gt3 by (auto simp: field_simps) + hence "ceiling (x / (2 * pi) - 1 / 2) = 0" + by linarith + thus ?thesis + by (simp add: normalize_angle_def) +qed + +lemma normalize_angle_normalized: "normalize_angle x \ {-pi<..pi}" +proof - + have "-1 < x / (2 * pi) - 1 / 2 - ceiling (x / (2 * pi) - 1 / 2)" + by linarith + moreover have "x / (2 * pi) - 1 / 2 - ceiling (x / (2 * pi) - 1 / 2) \ 0" + by linarith + ultimately show ?thesis + using pi_gt3 by (auto simp: field_simps normalize_angle_def) +qed + +lemma cis_normalize_angle [simp]: "cis (normalize_angle x) = cis x" +proof - + have "cis (normalize_angle x) = cis x / cis (real_of_int \x / (2 * pi) - 1 / 2\ * (2 * pi))" + by (simp add: normalize_angle_def flip: cis_divide) + also have "real_of_int \x / (2 * pi) - 1 / 2\ * (2 * pi) = + 2 * pi * real_of_int \x / (2 * pi) - 1 / 2\" + by (simp add: algebra_simps) + also have "cis \ = 1" + by (rule cis_multiple_2pi) auto + finally show ?thesis + by simp +qed + +lemma rcis_normalize_angle [simp]: "rcis r (normalize_angle x) = rcis r x" + by (simp add: rcis_def) + +lemma normalize_angle_lbound [intro]: "normalize_angle x > -pi" + and normalize_angle_ubound [intro]: "normalize_angle x \ pi" + using normalize_angle_normalized[of x] by auto + +lemma normalize_angle_idem [simp]: "normalize_angle (normalize_angle x) = normalize_angle x" + by (rule normalize_angle_id) (use normalize_angle_normalized[of x] in auto) + +lemma Arg_rcis': "r > 0 \ Arg (rcis r \) = normalize_angle \" + by (rule Arg_unique'[of r]) auto + + +subsection \Convexity of circular sectors in the complex plane\ + +text \ + In this section we will show that if we have two non-zero points $w$ and $z$ in the complex plane + whose arguments differ by less than $\pi$, then the argument of any point on the line connecting + $w$ and $z$ lies between the arguments of $w$ and $z$. Moreover, the norm of any such point is + no greater than the norms of $w$ and $z$. + + Geometrically, this means that if we have a sector around the origin with a central angle + less than $\pi$ (minus the origin itself) then that region is convex. +\ + +lemma Arg_closed_segment_aux1: + assumes "x \ 0" "y \ 0" "Re x > 0" "Re x = Re y" + assumes "z \ closed_segment x y" + shows "Arg z \ closed_segment (Arg x) (Arg y)" + using assms +proof (induction "Arg x" "Arg y" arbitrary: x y rule: linorder_wlog) + case (le x y) + from le have "Re z = Re x" "Im z \ closed_segment (Im x) (Im y)" + by (auto simp: closed_segment_same_Re) + then obtain t where t: "t \ {0..1}" "Im z = linepath (Im x) (Im y) t" + by (metis image_iff linepath_image_01) + have *: "Im x \ Im y" + using le by (auto simp: arg_conv_arctan arctan_le_iff field_simps) + have "Im x / Re x \ linepath (Im x) (Im y) t / Re x" + using le t * by (intro divide_right_mono linepath_real_ge_left) auto + hence "Arg x \ Arg z" + using t le \Re z = Re x\ by (auto simp: arg_conv_arctan arctan_le_iff) + moreover have "Im y / Re x \ linepath (Im x) (Im y) t / Re x" + using le t * by (intro divide_right_mono linepath_real_le_right) auto + hence "Arg y \ Arg z" + using t le \Re z = Re x\ by (auto simp: arg_conv_arctan arctan_le_iff) + ultimately show ?case + using le by (auto simp: closed_segment_same_Re closed_segment_eq_real_ivl) +next + case (sym x y) + have "Arg z \ closed_segment (Arg y) (Arg x)" + by (rule sym(1)) + (use sym(2-) in \simp_all add: dist_commute closed_segment_commute\) + thus ?case + by (simp add: closed_segment_commute) +qed + +lemma Arg_closed_segment_aux1': + fixes r1 r2 \1 \2 :: real + defines "x \ rcis r1 \1" and "y \ rcis r2 \2" + assumes "z \ closed_segment x y" + assumes "r1 > 0" "r2 > 0" "Re x = Re y" "Re x \ 0" "Re x = 0 \ Im x * Im y > 0" + assumes "dist \1 \2 < pi" + obtains r \ where "r \ {0<..max r1 r2}" "\ \ closed_segment \1 \2" "z = rcis r \" +proof (cases "Re x = 0") + case True + have [simp]: "cos \1 = 0" "cos \2 = 0" + using assms True by auto + have "sin \1 = 1 \ sin \2 = 1 \ sin \1 = -1 \ sin \2 = -1" + using sin_cos_squared_add[of \1] sin_cos_squared_add[of \2] assms + by (auto simp: zero_less_mult_iff power2_eq_1_iff) + thus ?thesis + proof (elim disjE conjE) + assume [simp]: "sin \1 = 1" "sin \2 = 1" + have xy_eq: "x = of_real r1 * \" "y = of_real r2 * \" + by (auto simp: complex_eq_iff x_def y_def) + hence z: "Re z = 0" "Im z \ closed_segment r1 r2" + using \z \ closed_segment x y \ by (auto simp: xy_eq closed_segment_same_Re) + have "closed_segment r1 r2 \ {0<..max r1 r2}" + by (rule closed_segment_subset) (use assms in auto) + with z have "Im z \ {0<..max r1 r2}" + by blast + show ?thesis + by (rule that[of "Im z" \1]) + (use z \Im z \ {0<..max r1 r2}\ in \auto simp: complex_eq_iff\) + next + assume [simp]: "sin \1 = -1" "sin \2 = -1" + have xy_eq: "x = -of_real r1 * \" "y = -of_real r2 * \" + by (auto simp: complex_eq_iff x_def y_def) + hence z: "Re z = 0" "Im z \ closed_segment (-r1) (-r2)" + using \z \ closed_segment x y \ by (auto simp: xy_eq closed_segment_same_Re) + have "closed_segment (-r1) (-r2) \ {-max r1 r2..<0}" + by (rule closed_segment_subset) (use assms in auto) + with z have "-Im z \ {0<..max r1 r2}" + by auto + show ?thesis + by (rule that[of "-Im z" \1]) + (use z \-Im z \ {0<..max r1 r2}\ in \auto simp: complex_eq_iff\) + qed +next + case False + hence Re_pos: "Re x > 0" + using \Re x \ 0\ by linarith + define n :: int where "n = \\1 / (2 * pi) - 1 / 2\" + define n' :: int where "n' = \\2 / (2 * pi) - 1 / 2\" + + have "Re z = Re x" + using assms by (auto simp: closed_segment_same_Re) + + have Arg_z: "Arg z \ closed_segment (Arg x) (Arg y)" + by (rule Arg_closed_segment_aux1) (use assms Re_pos in \simp_all add: dist_norm\) + + have "z \ closed_segment x y" + by fact + also have "\ \ cball 0 (max r1 r2)" + using _ _ convex_cball by (rule closed_segment_subset) (use assms in auto) + finally have "norm z \ max r1 r2" + by auto + moreover have "z \ 0" + by (intro notI) (use \Re x > 0\ \Re z = Re x\ in auto) + ultimately have norm_z: "norm z \ {0<..max r1 r2}" + by simp + + have Arg_x: "Arg x = \1 - 2 * pi * of_int n" + using assms by (simp add: x_def Arg_rcis' normalize_angle_def n_def) + have Arg_y: "Arg y = \2 - 2 * pi * of_int n'" + using assms by (simp add: x_def Arg_rcis' normalize_angle_def n'_def) + have Arg_bounds: "\Arg x\ \ pi/2" "\Arg y\ \ pi/2" + by (subst Arg_Re_nonneg; use assms in simp)+ + + have "pi * of_int (2 * \n - n'\ - 1) = 2 * pi * of_int (\n - n'\) - pi" + by (simp add: algebra_simps) + also have "\ = \2 * pi * of_int (n - n')\ - pi / 2 - pi / 2" + by (simp add: abs_mult) + also have "\ \ \2 * pi * of_int (n - n') + Arg x - Arg y\" + using Arg_bounds pi_gt_zero by linarith + also have "\ \ dist \1 \2" + using Arg_x Arg_y unfolding dist_norm real_norm_def by (simp add: algebra_simps) + also have "\ < pi * 1" + using assms by simp + finally have "2 * \n - n'\ - 1 < 1" + by (subst (asm) mult_less_cancel_left_pos) auto + hence [simp]: "n' = n" + by presburger + + show ?thesis + using norm_z + proof (rule that[of "norm z" "Arg z + 2 * pi * of_int n"]) + have "2 * pi * of_int n + Arg z \ ((+) (2 * pi * of_int n)) ` closed_segment (Arg x) (Arg y)" + using Arg_z by blast + also have "\ = closed_segment (2 * pi * real_of_int n + Arg x) (2 * pi * real_of_int n + Arg y)" + by (rule closed_segment_translation [symmetric]) + also have "2 * pi * real_of_int n + Arg x = \1" + by (simp add: Arg_x) + also have "2 * pi * real_of_int n + Arg y = \2" + by (simp add: Arg_y) + finally show "Arg z + 2 * pi * real_of_int n \ closed_segment \1 \2" + by (simp add: add_ac) + next + have "z = rcis (norm z) (Arg z)" + by (simp add: rcis_cmod_Arg) + also have "\ = rcis (cmod z) (Arg z + 2 * pi * real_of_int n)" + by (simp add: rcis_def flip: cis_mult) + finally show "z = \" . + qed +qed + +lemma Arg_closed_segment': + fixes r1 r2 \1 \2 :: real + defines "x \ rcis r1 \1" and "y \ rcis r2 \2" + assumes "r1 > 0" "r2 > 0" "dist \1 \2 < pi" "z \ closed_segment x y" + obtains r \ where "r \ {0<..max r1 r2}" "\ \ closed_segment \1 \2" "z = rcis r \" +proof - + define u_aux :: real where + "u_aux = (if Im x = Im y then pi/2 else arctan (Re (x-y) / Im (x-y)))" + define u :: real where + "u = (if Re (x * cis u_aux) < 0 then if u_aux \ 0 then u_aux + pi else u_aux - pi else u_aux)" + + have "u_aux \ {-pi/2<..pi/2}" + using arctan_lbound[of "Re (x-y) / Im (x-y)"] arctan_ubound[of "Re (x-y) / Im (x-y)"] + by (auto simp: u_aux_def) + have u_bounds: "u \ {-pi<..pi}" + using \u_aux \ _\ by (auto simp: u_def) + + have u_aux: "(Re x - Re y) * cos u_aux = (Im x - Im y) * sin u_aux" + proof (cases "Im x = Im y") + case False + hence "tan u_aux = (Re x - Re y) / (Im x - Im y)" and "cos u_aux \ 0" + by (auto simp: u_aux_def tan_arctan) + thus ?thesis using False + by (simp add: tan_def divide_simps mult_ac split: if_splits) + qed (auto simp: u_aux_def) + hence "Re (x * cis u_aux) = Re (y * cis u_aux)" + by (auto simp: algebra_simps) + hence same_Re: "Re (x * cis u) = Re (y * cis u)" + by (auto simp: u_def) + + have Re_nonneg: "Re (x * cis u) \ 0" + by (auto simp: u_def) + + have "linear (\w. w * cis u)" + by (intro linearI) (auto simp: algebra_simps) + hence "closed_segment (x * cis u) (y * cis u) = (\w. w * cis u) ` closed_segment x y" + by (intro closed_segment_linear_image) + hence z'_in: "z * cis u \ closed_segment (x * cis u) (y * cis u)" + using assms by blast + + obtain r \ where r\: + "r \ {0<..max r1 r2}" "\ \ closed_segment (\1 + u) (\2 + u)" "z * cis u = rcis r \" + proof (rule Arg_closed_segment_aux1'[of "z * cis u" r1 "\1 + u" r2 "\2 + u"]) + show "z * cis u \ closed_segment (rcis r1 (\1 + u)) (rcis r2 (\2 + u))" + using z'_in by (simp add: x_def y_def rcis_def mult.assoc flip: cis_mult) + next + show "r1 > 0" "r2 > 0" + by fact+ + next + show "Re (rcis r1 (\1 + u)) = Re (rcis r2 (\2 + u))" + using same_Re by (simp add: x_def y_def cos_add field_simps) + next + show "Re (rcis r1 (\1 + u)) \ 0" + using \r1 > 0\ Re_nonneg by (auto intro!: mult_nonneg_nonneg simp: cos_add x_def) + next + show "dist (\1 + u) (\2 + u) < pi" + using assms by (simp add: dist_norm) + next + show "Re (rcis r1 (\1 + u)) = 0 \ 0 < Im (rcis r1 (\1 + u)) * Im (rcis r2 (\2 + u))" + proof + assume *: "Re (rcis r1 (\1 + u)) = 0" + hence "cos (\1 + u) = 0" + using assms by simp + then obtain n1 where "\1 + u = real_of_int n1 * pi + pi / 2" + by (subst (asm) cos_zero_iff_int2) auto + hence n1: "\1 = real_of_int n1 * pi + pi / 2 - u" + by linarith + + have "Re (rcis r1 (\1 + u)) = 0" + by fact + also have "rcis r1 (\1 + u) = x * cis u" + by (simp add: x_def rcis_def cis_mult) + also have "Re (x * cis u) = Re (y * cis u)" + by (fact same_Re) + also have "y * cis u = rcis r2 (\2 + u)" + by (simp add: y_def rcis_def cis_mult) + finally have "cos (\2 + u) = 0" + using assms by simp + then obtain n2 where "\2 + u = real_of_int n2 * pi + pi / 2" + by (subst (asm) cos_zero_iff_int2) auto + hence n2: "\2 = real_of_int n2 * pi + pi / 2 - u" + by linarith + + have "pi * real_of_int \n2 - n1\ = \real_of_int (n2 - n1) * pi\" + by (simp add: abs_mult) + also have "\ = dist \1 \2" + by (simp add: n1 n2 dist_norm ring_distribs) + also have "\ < pi * 1" + using \dist \1 \2 < pi\ by simp + finally have "real_of_int \n2 - n1\ < 1" + by (subst (asm) mult_less_cancel_left_pos) auto + hence "n1 = n2" + by linarith + + have "Im (rcis r1 (\1 + u)) * Im (rcis r2 (\2 + u)) = r1 * r2 * cos (real_of_int n2 * pi) ^ 2" + by (simp add: n1 n2 sin_add \n1 = n2\ power2_eq_square) + also have "cos (real_of_int n2 * pi) ^ 2 = (cos (2 * (real_of_int n2 * pi)) + 1) / 2" + by (subst cos_double_cos) auto + also have "2 * (real_of_int n2 * pi) = 2 * pi * real_of_int n2" + by (simp add: mult_ac) + also have "(cos \ + 1) / 2 = 1" + by (subst cos_int_2pin) auto + also have "r1 * r2 * 1 > 0" + using assms by simp + finally show "Im (rcis r1 (\1 + u)) * Im (rcis r2 (\2 + u)) > 0" . + qed + qed + + show ?thesis + proof (rule that[of r "\ - u"]) + show "r \ {0<..max r1 r2}" + by fact + next + have "u + (\ - u) \ closed_segment (\1 + u) (\2 + u)" + using r\ by simp + also have "\ = (+) u ` closed_segment \1 \2" + by (subst (1 2) add.commute, rule closed_segment_translation) + finally show "\ - u \ closed_segment \1 \2" + by (subst (asm) inj_image_mem_iff) auto + next + show "z = rcis r (\ - u)" + using r\ by (simp add: rcis_def field_simps flip: cis_divide) + qed +qed + +lemma Arg_closed_segment: + assumes "x \ 0" "y \ 0" "dist (Arg x) (Arg y) < pi" "z \ closed_segment x y" + shows "Arg z \ closed_segment (Arg x) (Arg y)" +proof - + define r1 \1 where "r1 = norm x" and "\1 = Arg x" + define r2 \2 where "r2 = norm y" and "\2 = Arg y" + note defs = r1_def r2_def \1_def \2_def + obtain r \ where *: "r \ {0<..max r1 r2}" "\ \ closed_segment \1 \2" "z = rcis r \" + by (rule Arg_closed_segment'[of r1 r2 \1 \2 z]) + (use assms in \auto simp: defs rcis_cmod_Arg\) + have "Arg z = \" + proof (rule Arg_unique') + show "z = rcis r \" "r > 0" + using * by auto + next + have "\ \ closed_segment \1 \2" + by (fact *) + also have "\ \ {-pi<..pi}" + by (rule closed_segment_subset) + (use assms * Arg_bounded[of x] Arg_bounded[of y] in \auto simp: defs\) + finally show "\ \ {-pi<..pi}" + by auto + qed + with * show ?thesis + by (simp add: defs) +qed + + +subsection \Complex cones\ + +text \ + We introduce the following notation to describe the set of all complex numbers of the form + $c e^{ix}$ where $c\geq 0$ and $x\in [a, b]$. +\ +definition complex_cone :: "real \ real \ complex set" where + "complex_cone a b = (\(r,a). rcis r a) ` ({0..} \ closed_segment a b)" + +lemma in_complex_cone_iff: "z \ complex_cone a b \ (\x\closed_segment a b. z = rcis (norm z) x)" + by (auto simp: complex_cone_def image_iff) + +lemma zero_in_complex_cone [simp, intro]: "0 \ complex_cone a b" + by (auto simp: in_complex_cone_iff) + +lemma in_complex_cone_iff_Arg: + assumes "a \ {-pi<..pi}" "b \ {-pi<..pi}" + shows "z \ complex_cone a b \ z = 0 \ Arg z \ closed_segment a b" +proof + assume "z \ complex_cone a b" + then obtain r x where *: "x \ closed_segment a b" "z = rcis r x" "r \ 0" + by (auto simp: complex_cone_def) + have "closed_segment a b \ {-pi<..pi}" + by (rule closed_segment_subset) (use assms in auto) + with * have **: "x \ {-pi<..pi}" + by auto + show "z = 0 \ Arg z \ closed_segment a b" + proof (cases "z = 0") + case False + with * have "r \ 0" + by auto + with * have [simp]: "r > 0" + by simp + show ?thesis + by (use * ** in \auto simp: Arg_rcis\) + qed auto +next + assume "z = 0 \ Arg z \ closed_segment a b" + thus "z \ complex_cone a b" + proof + assume *: "Arg z \ closed_segment a b" + have "z = rcis (norm z) (Arg z)" + by (simp_all add: rcis_cmod_Arg) + thus ?thesis using * + unfolding in_complex_cone_iff by blast + qed auto +qed + +lemma complex_cone_rotate: "complex_cone (c + a) (c + b) = (*) (cis c) ` complex_cone a b" +proof - + have *: "(*) (cis c) ` complex_cone a b \ complex_cone (c + a) (c + b)" for c a b + by (auto simp: closed_segment_translation in_complex_cone_iff norm_mult rcis_def simp flip: cis_mult) + + have "complex_cone (c + a) (c + b) = (*) (cis c) ` (*) (cis (-c)) ` complex_cone (c + a) (c + b)" + by (simp add: image_image field_simps flip: cis_inverse) + also have "\ \ (*) (cis c) ` complex_cone ((-c) + (c + a)) ((-c) + (c + b))" + by (intro image_mono *) + also have "\ = (*) (cis c) ` complex_cone a b" + by simp + finally show ?thesis + using *[of c a b] by blast +qed + +lemma complex_cone_subset: + "a \ closed_segment a' b' \ b \ closed_segment a' b' \ complex_cone a b \ complex_cone a' b'" + unfolding complex_cone_def + by (intro image_mono Sigma_mono order.refl, unfold subset_closed_segment) auto + +lemma complex_cone_commute: "complex_cone a b = complex_cone b a" + by (simp add: complex_cone_def closed_segment_commute) + +lemma complex_cone_eq_UNIV: + assumes "dist a b \ 2*pi" + shows "complex_cone a b = UNIV" + using assms +proof (induction a b rule: linorder_wlog) + case (le a b) + have "bij ((*) (cis (a+pi)))" + by (rule bij_betwI[of _ _ _ "(*) (cis (-a-pi))"]) + (auto simp: field_simps simp flip: cis_inverse cis_divide cis_mult) + hence "UNIV = (*) (cis (a+pi)) ` UNIV" + unfolding bij_betw_def by blast + also have "UNIV \ complex_cone (-pi) pi" + proof safe + fix z :: complex + have "z = rcis (norm z) (Arg z)" "norm z \ 0" "Arg z \ closed_segment (-pi) pi" + using Arg_bounded[of z] by (auto simp: closed_segment_eq_real_ivl rcis_cmod_Arg) + thus "z \ complex_cone (-pi) pi" + unfolding in_complex_cone_iff by blast + qed + also have "(*) (cis (a + pi)) ` complex_cone (- pi) pi = complex_cone a (a + 2 * pi)" + using complex_cone_rotate[of "a+pi" "-pi" pi] by (simp add: add_ac) + also have "\ \ complex_cone a b" + by (rule complex_cone_subset) (use le in \auto simp: closed_segment_eq_real_ivl1 dist_norm\) + finally show ?case by blast +qed (simp_all add: complex_cone_commute dist_commute) + + +text \ + A surprisingly tough argument: cones in the complex plane are closed. +\ +lemma closed_complex_cone [continuous_intros, intro]: "closed (complex_cone a b)" +proof (induction a b rule: linorder_wlog) + case (sym a b) + thus ?case + by (simp add: complex_cone_commute) +next + case (le a b) + show ?case + proof (cases "b - a < 2 * pi") + case False + hence "complex_cone a b = UNIV" + by (intro complex_cone_eq_UNIV) (auto simp: dist_norm) + thus ?thesis + by simp + next + case True + define c where "c = (b - a) / 2" + define d where "d = (b + a) / 2" + have ab_eq: "a = d - c" "b = c + d" + by (simp_all add: c_def d_def field_simps) + have "c \ 0" "c < pi" + using True le by (simp_all add: c_def) + + define e where "e = (if c \ pi / 2 then 1 else sin c)" + have "e > 0" + proof (cases "c \ pi / 2") + case False + have "0 < pi / 2" + by simp + also have "pi / 2 < c" + using False by simp + finally have "c > 0" . + moreover have "c < pi" + using True by (simp add: c_def) + ultimately show ?thesis + using False by (auto simp: e_def intro!: sin_gt_zero) + qed (auto simp: e_def) + + define A where "A = -ball 0 1 - {z. Re z < 0} \ ({z. Im z < e} \ {z. Im z > -e})" + + have "closed (A \ (Arg -` {-c..c}))" + proof (intro continuous_closed_preimage) + show "closed A" unfolding A_def + by (intro closed_Diff closed_Compl open_Int open_halfspace_Re_lt + open_halfspace_Im_lt open_halfspace_Im_gt open_ball) + show "continuous_on A Arg" + unfolding A_def using \e > 0\ + by (intro continuous_intros) (auto elim!: nonpos_Reals_cases) + qed auto + + also have "A \ (Arg -` {-c..c}) = + (Arg -` {-c..c} - {z. Re z < 0} \ ({z. Im z < e} \ {z. Im z > -e})) - ball 0 1" + by (auto simp: A_def) + + also have "\ = Arg -` {-c..c} - ball 0 1" + proof (intro equalityI subsetI) + fix z assume z: "z \ Arg -` {-c..c} - ball 0 1" + define r where "r = norm z" + define x where "x = Arg z" + have "\x\ \ c" + using z by (auto simp: x_def) + also note \c < pi\ + finally have "\x\ < pi" . + + have False if *: "Re z < 0" "Im z < e" "Im z > -e" + proof - + have "r \ 1" + using z by (auto simp: r_def) + have z_eq: "z = rcis r x" + by (simp add: r_def x_def rcis_cmod_Arg) + from * and \r \ 1\ have "cos x < 0" + by (simp add: z_eq mult_less_0_iff) + with \\x\ < pi\ have "\x\ > pi / 2" + using cos_ge_zero[of x] by linarith + hence "c > pi / 2" + using \\x\ \ c\ by linarith + + have "sin c \ sin \x\" + proof - + have "sin (pi - c) \ sin (pi - \x\)" + by (rule sin_monotone_2pi_le) + (use \\x\ \ c\ \\x\ < pi\ \\x\ > pi / 2\ \c < pi\ in \auto simp: field_simps\) + thus ?thesis + by simp + qed + also have "sin \x\ \ 1 * \sin x\" + by (auto simp: abs_if) + also have "1 * \sin x\ \ r * \sin x\" + by (rule mult_right_mono) (use \r \ 1\ in auto) + also have "r * \sin x\ = \Im z\" + using \r \ 1\ by (simp add: z_eq abs_mult) + also have "\Im z\ < e" + using * by linarith + finally show False + using \c > pi / 2\ by (auto simp: e_def split: if_splits) + + qed + thus "z \ Arg -` {-c..c} - {z. Re z < 0} \ ({z. Im z < e} \ {z. Im z > -e}) - ball 0 1" + using z by blast + qed auto + + also have "Arg -` {-c..c} - ball 0 1 = complex_cone (-c) c - ball 0 1" + using \c < pi\ \c \ 0\ + by (auto simp: in_complex_cone_iff_Arg closed_segment_eq_real_ivl1) + + finally have "closed (complex_cone (-c) c - ball 0 1)" . + + moreover have "closed (complex_cone (-c) c \ cball 0 1)" + proof - + have "compact ((\(r,x). rcis r x) ` ({0..1} \ closed_segment (-c) c))" + by (intro compact_continuous_image) + (auto intro!: continuous_intros compact_Times simp: case_prod_unfold) + also have "((\(r,x). rcis r x) ` ({0..1} \ closed_segment (-c) c)) = complex_cone (-c) c \ cball 0 1" + by (auto simp: in_complex_cone_iff image_def) + finally show ?thesis + by (rule compact_imp_closed) + qed + + ultimately have "closed (complex_cone (-c) c - ball 0 1 \ complex_cone (-c) c \ cball 0 1)" + by (intro closed_Un) + also have "\ = complex_cone (-c) c" + by auto + finally have "closed (complex_cone (-c) c)" . + + hence "closed ((*) (cis d) ` complex_cone (-c) c)" + by (intro closed_injective_linear_image) auto + also have "\ = complex_cone a b" + using complex_cone_rotate[of d "-c" c] by (simp add: ab_eq add_ac) + finally show ?thesis . + qed +qed + +lemma norm_eq_Re_iff: "norm z = Re z \ z \ \\<^sub>\\<^sub>0" +proof + assume "norm z = Re z" + hence "norm z ^ 2 = Re z ^ 2" + by simp + hence "Im z = 0" + by (auto simp: cmod_def) + moreover have "Re z \ 0" + by (subst \norm z = Re z\ [symmetric]) auto + ultimately show "z \ \\<^sub>\\<^sub>0" + by (auto simp: complex_nonneg_Reals_iff) +qed (auto elim!: nonneg_Reals_cases) + end diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Elementary_Metric_Spaces.thy --- a/src/HOL/Analysis/Elementary_Metric_Spaces.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Elementary_Metric_Spaces.thy Tue Apr 15 17:38:20 2025 +0200 @@ -366,6 +366,12 @@ for x :: "'a::{perfect_space,metric_space}" using islimpt_UNIV [of x] by (simp add: islimpt_approachable) + +lemma pointed_ball_nonempty: + assumes "r > 0" + shows "ball x r - {x :: 'a :: {perfect_space, metric_space}} \ {}" + using perfect_choose_dist[of r x] assms by (auto simp: ball_def dist_commute) + lemma cball_eq_sing: fixes x :: "'a::{metric_space,perfect_space}" shows "cball x e = {x} \ e = 0" diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Gamma_Function.thy --- a/src/HOL/Analysis/Gamma_Function.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Gamma_Function.thy Tue Apr 15 17:38:20 2025 +0200 @@ -2395,11 +2395,15 @@ ultimately show ?thesis by force next case False - hence z: "z/2 \ \" "(z+1)/2 \ \" using Ints_diff[of "z+1" 1] by (auto elim!: Ints_cases) + hence z: "z/2 \ \ \ (z+1)/2 \ \" + by (metis Ints_1 Ints_cases Ints_of_int add.commute + add_in_Ints_iff_left divide_eq_eq_numeral1(1) + of_int_mult one_add_one zero_neq_numeral) hence z': "z/2 \ \\<^sub>\\<^sub>0" "(z+1)/2 \ \\<^sub>\\<^sub>0" by (auto elim!: nonpos_Ints_cases) from z have "1-z/2 \ \" "1-((z+1)/2) \ \" using Ints_diff[of 1 "1-z/2"] Ints_diff[of 1 "1-((z+1)/2)"] by auto - hence z'': "1-z/2 \ \\<^sub>\\<^sub>0" "1-((z+1)/2) \ \\<^sub>\\<^sub>0" by (auto elim!: nonpos_Ints_cases) + hence z'': "1-z/2 \ \\<^sub>\\<^sub>0 \ 1-((z+1)/2) \ \\<^sub>\\<^sub>0" + by blast from z have "g (z/2) * g ((z+1)/2) = (Gamma (z/2) * Gamma ((z+1)/2)) * (Gamma (1-z/2) * Gamma (1-((z+1)/2))) * (sin (of_real pi * z/2) * sin (of_real pi * (z+1)/2))" diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Homeomorphism.thy --- a/src/HOL/Analysis/Homeomorphism.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Homeomorphism.thy Tue Apr 15 17:38:20 2025 +0200 @@ -2259,4 +2259,69 @@ finally show ?thesis . qed +lemma closure_bij_homeomorphic_image_eq: + assumes bij: "bij_betw f A B" + assumes homo: "homeomorphism A B f g" + assumes cont: "continuous_on A' f" "continuous_on B' g" + assumes inv: "\x. x \ B' \ f (g x) = x" + assumes cl: "closed A'" "closed B'" and X: "X \ A" "A \ A'" "B \ B'" + shows "closure (f ` X) = f ` closure X" +proof - + have "f ` X \ f ` A" + using \X \ A\ by blast + also have "f ` A = B" + using \bij_betw f A B\ by (simp add: bij_betw_def) + finally have *: "closure (f ` X) \ closure B" + by (intro closure_mono) + + show ?thesis + proof (rule antisym) + have "g ` closure (f ` X) \ closure (g ` f ` X)" + proof (rule continuous_image_closure_subset[OF _ *]) + have "closure B \ B'" + using X cl by (simp add: closure_minimal) + thus "continuous_on (closure B) g" + by (rule continuous_on_subset[OF cont(2)]) + qed + also have "g ` f ` X = (g \ f) ` X" + by (simp add: image_image) + also have "\ = id ` X" + using homo X by (intro image_cong) (auto simp: homeomorphism_def) + finally have "g ` closure (f ` X) \ closure X" + by simp + hence "f ` g ` closure (f ` X) \ f ` closure X" + by (intro image_mono) + also have "f ` g ` closure (f ` X) = (f \ g) ` closure (f ` X)" + by (simp add: image_image) + also have "\ = id ` closure (f ` X)" + proof (rule image_cong) + fix x assume "x \ closure (f ` X)" + also have "closure (f ` X) \ closure B'" + proof (rule closure_mono) + have "f ` X \ f ` A" + using X by (intro image_mono) auto + also have "\ = B" + using bij by (simp add: bij_betw_def) + also have "\ \ B'" + by fact + finally show "f ` X \ B'" . + qed + finally have "x \ B'" + using cl by simp + thus "(f \ g) x = id x" + by (auto simp: homeomorphism_def inv) + qed auto + finally show "closure (f ` X) \ f ` closure X" + by simp + next + show "f ` closure X \ closure (f ` X)" + proof (rule continuous_image_closure_subset) + show "continuous_on A' f" + by fact + show "closure X \ A'" + using assms by (simp add: closure_minimal) + qed + qed +qed + end diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Linear_Algebra.thy --- a/src/HOL/Analysis/Linear_Algebra.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Linear_Algebra.thy Tue Apr 15 17:38:20 2025 +0200 @@ -586,6 +586,18 @@ lemma of_real_differentiable [simp,derivative_intros]: "of_real differentiable F" by (simp add: bounded_linear_imp_differentiable bounded_linear_of_real) +lemma bounded_linear_representation: + fixes B :: "'a :: euclidean_space set" + assumes "independent B" "span B = UNIV" + shows "bounded_linear (\v. representation B v b)" +proof - + have "Vector_Spaces.linear (*\<^sub>R) (*) (\v. representation B v b)" + by (rule real_vector.linear_representation) fact+ + then have "linear (\v. representation B v b)" + unfolding linear_def real_scaleR_def [abs_def] . + thus ?thesis + by (simp add: linear_conv_bounded_linear) +qed subsection\<^marker>\tag unimportant\ \We continue\ diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Ordered_Euclidean_Space.thy --- a/src/HOL/Analysis/Ordered_Euclidean_Space.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Ordered_Euclidean_Space.thy Tue Apr 15 17:38:20 2025 +0200 @@ -266,6 +266,11 @@ using convex_box[of a b] by (metis interval_cbox) +lemma bounded_Ico [simp]: "bounded {a..x. m *\<^sub>R (x::_::ordered_euclidean_space)) ` {a .. b} = (if {a .. b} = {} then {} else if 0 \ m then {m *\<^sub>R a .. m *\<^sub>R b} else {m *\<^sub>R b .. m *\<^sub>R a})" using image_smult_cbox[of m a b] diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Path_Connected.thy --- a/src/HOL/Analysis/Path_Connected.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Path_Connected.thy Tue Apr 15 17:38:20 2025 +0200 @@ -1329,6 +1329,33 @@ "(linepath a b has_vector_derivative (b - a)) (at x within S)" by (force intro: derivative_eq_intros simp add: linepath_def has_vector_derivative_def algebra_simps) +lemma linepath_real_ge_left: + fixes x y :: real + assumes "x \ y" "t \ 0" + shows "linepath x y t \ x" +proof - + have "x + 0 \ x + t *\<^sub>R (y - x)" + using assms by (intro add_left_mono) auto + also have "\ = linepath x y t" + by (simp add: linepath_def algebra_simps) + finally show ?thesis by simp +qed + +lemma linepath_real_le_right: + fixes x y :: real + assumes "x \ y" "t \ 1" + shows "linepath x y t \ y" +proof - + have "y + 0 \ y + (1 - t) *\<^sub>R (x - y)" + using assms by (intro add_left_mono) (auto intro: mult_nonneg_nonpos) + also have "y + (1 - t) *\<^sub>R (x - y) = linepath x y t" + by (simp add: linepath_def algebra_simps) + finally show ?thesis by simp +qed + +lemma linepath_translate: "(+) c \ linepath a b = linepath (a + c) (b + c)" + by (auto simp: linepath_def algebra_simps) + subsection\<^marker>\tag unimportant\\Segments via convex hulls\ diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Sparse_In.thy --- a/src/HOL/Analysis/Sparse_In.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Sparse_In.thy Tue Apr 15 17:38:20 2025 +0200 @@ -71,6 +71,19 @@ using assms unfolding sparse_in_def islimpt_Un by (metis Int_iff open_Int) +lemma sparse_in_union': "A sparse_in C \ B sparse_in C \ A \ B sparse_in C" + using sparse_in_union[of A C B C] by simp + +lemma sparse_in_Union_finite: + assumes "(\A'. A' \ A \ A' sparse_in B)" "finite A" + shows "\A sparse_in B" + using assms(2,1) by (induction rule: finite_induct) (auto intro!: sparse_in_union') + +lemma sparse_in_UN_finite: + assumes "(\x. x \ A \ f x sparse_in B)" "finite A" + shows "(\x\A. f x) sparse_in B" + by (rule sparse_in_Union_finite) (use assms in auto) + lemma sparse_in_compact_finite: assumes "pts sparse_in A" "compact A" shows "finite (A \ pts)" @@ -144,6 +157,44 @@ eventually_at_topological by blast +lemma sparse_in_translate: + fixes A B :: "'a :: real_normed_vector set" + assumes "A sparse_in B" + shows "(+) c ` A sparse_in (+) c ` B" + unfolding sparse_in_def +proof safe + fix x assume "x \ B" + from get_sparse_in_cover[OF assms] obtain B' where B': "open B'" "B \ B'" "\y\B'. \y islimpt A" + by blast + have "c + x \ (+) c ` B'" "open ((+) c ` B')" + using B' \x \ B\ by (auto intro: open_translation) + moreover have "\y\(+) c ` B'. \y islimpt ((+) c ` A)" + proof safe + fix y assume y: "y \ B'" "c + y islimpt (+) c ` A" + have "(-c) + (c + y) islimpt (+) (-c) ` (+) c ` A" + by (intro islimpt_isCont_image[OF y(2)] continuous_intros) + (auto simp: algebra_simps eventually_at_topological) + hence "y islimpt A" + by (simp add: image_image) + with y(1) B' show False + by blast + qed + ultimately show "\B. c + x \ B \ open B \ (\y\B. \ y islimpt (+) c ` A)" + by metis +qed + +lemma sparse_in_translate': + fixes A B :: "'a :: real_normed_vector set" + assumes "A sparse_in B" "C \ (+) c ` B" + shows "(+) c ` A sparse_in C" + using sparse_in_translate[OF assms(1)] assms(2) by (rule sparse_in_subset) + +lemma sparse_in_translate_UNIV: + fixes A B :: "'a :: real_normed_vector set" + assumes "A sparse_in UNIV" + shows "(+) c ` A sparse_in UNIV" + using assms by (rule sparse_in_translate') auto + subsection \Co-sparseness filter\ @@ -176,6 +227,13 @@ "\\<^sub>\x\A. P" == "CONST eventually (\x. P) (CONST cosparse A)" syntax + "_eventually_cosparse_UNIV" :: "pttrn => bool => bool" (\(\indent=3 notation=\binder \\\\\\<^sub>\_./ _)\ [0, 10] 10) +syntax_consts + "_eventually_cosparse_UNIV" == eventually +translations + "\\<^sub>\x. P" == "CONST eventually (\x. P) (CONST cosparse CONST UNIV)" + +syntax "_qeventually_cosparse" :: "pttrn \ bool \ 'a \ 'a" (\(\indent=3 notation=\binder \\\\\\<^sub>\_ | (_)./ _)\ [0, 0, 10] 10) syntax_consts "_qeventually_cosparse" == eventually diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Analysis/Topology_Euclidean_Space.thy --- a/src/HOL/Analysis/Topology_Euclidean_Space.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Analysis/Topology_Euclidean_Space.thy Tue Apr 15 17:38:20 2025 +0200 @@ -363,6 +363,12 @@ box (\i\Basis. max (a\i) (c\i) *\<^sub>R i) (\i\Basis. min (b\i) (d\i) *\<^sub>R i)" unfolding set_eq_iff and Int_iff and mem_box by auto +lemma cbox_prod: "cbox a b = cbox (fst a) (fst b) \ cbox (snd a) (snd b)" + by (cases a; cases b) auto + +lemma box_prod: "box a b = box (fst a) (fst b) \ box (snd a) (snd b)" + by (cases a; cases b) (force simp: box_def Basis_prod_def) + lemma rational_boxes: fixes x :: "'a::euclidean_space" assumes "e > 0" @@ -722,6 +728,12 @@ lemma box_complex_of_real [simp]: "box (complex_of_real x) (complex_of_real y) = {}" by (auto simp: in_box_complex_iff) +lemma cbox_complex_eq: "cbox a b = {x. Re x \ {Re a..Re b} \ Im x \ {Im a..Im b}}" + by (auto simp: in_cbox_complex_iff) + +lemma box_complex_eq: "box a b = {x. Re x \ {Re a<.. Im x \ {Im a<.. cbox c d = diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Archimedean_Field.thy --- a/src/HOL/Archimedean_Field.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Archimedean_Field.thy Tue Apr 15 17:38:20 2025 +0200 @@ -775,6 +775,55 @@ lemma frac_neg_eq_iff: "frac (-x) = frac (-y) \ frac x = frac y" using add.inverse_inverse frac_neg_frac by metis +lemma frac_eqE: + assumes "frac x = frac y" + obtains n where "x = y + of_int n" + by (rule that[of "floor x - floor y"]) (use assms in \auto simp: frac_def\) + +lemma frac_add_of_int_right [simp]: "frac (x + of_int n) = frac x" + by (auto simp: frac_def) + +lemma frac_add_of_int_left [simp]: "frac (of_int n + x) = frac x" + by (auto simp: frac_def) + +lemma frac_add_int_right: "y \ \ \ frac (x + y) = frac x" + by (elim Ints_cases) auto + +lemma frac_add_int_left: "x \ \ \ frac (x + y) = frac y" + by (elim Ints_cases) auto + +lemma bij_betw_frac: "bij_betw frac {x.. {x.. {x..of_int n\ = \a - b\" + using n by (simp add: algebra_simps) + also have "\ < 1" + using * by auto + finally have "n = 0" + by (simp flip: of_int_abs) + with n show "a = b" + by auto + qed +next + show "frac ` {x.. {0..<1}" + have "t = frac (if t \ frac x then x + t - frac x else x + t - frac x + 1)" + using frac_eq[of t] t by (auto simp: frac_def) + moreover have "(if t \ frac x then x + t - frac x else x + t - frac x + 1) \ {x.. frac ` {x..Rounding to the nearest integer\ definition round :: "'a::floor_ceiling \ int" diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Complex.thy --- a/src/HOL/Complex.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Complex.thy Tue Apr 15 17:38:20 2025 +0200 @@ -1032,6 +1032,32 @@ using filterlim_norm_at_top_imp_at_infinity by blast qed +lemma tendsto_cis [tendsto_intros]: + assumes "(f \ x) F" + shows "((\u. cis (f u)) \ cis x) F" + unfolding cis_conv_exp by (intro tendsto_intros assms) + +lemma tendsto_rcis [tendsto_intros]: + assumes "(f \ r) F" "(g \ x) F" + shows "((\u. rcis (f u) (g u)) \ rcis r x) F" + unfolding rcis_def by (intro tendsto_intros assms) + +lemma continuous_on_rcis [continuous_intros]: + "continuous_on A f \ continuous_on A g \ continuous_on A (\x. rcis (f x) (g x))" + unfolding rcis_def by (intro continuous_intros) + +lemma has_derivative_cis [derivative_intros]: + assumes "(f has_derivative d) (at x within A)" + shows "((\x. cis (f x)) has_derivative (\t. d t *\<^sub>R (\ * cis (f x)))) (at x within A)" +proof (rule has_derivative_compose[OF assms]) + have cis_eq: "cis = (\x. cos x + \ * sin x)" + by (auto simp: complex_eq_iff cos_of_real sin_of_real) + have "(cis has_vector_derivative (\ * cis (f x))) (at (f x))" + unfolding cis_eq by (auto intro!: derivative_eq_intros simp: cos_of_real sin_of_real algebra_simps) + thus "(cis has_derivative (\a. a *\<^sub>R (\ * cis (f x)))) (at (f x))" + by (simp add: has_vector_derivative_def) +qed + subsubsection \Complex argument\ definition Arg :: "complex \ real" @@ -1126,6 +1152,7 @@ lemma sin_Arg: "z \ 0 \ sin (Arg z) = Im z / norm z" by (metis Im_sgn cis.sel(2) cis_Arg) + subsection \Complex n-th roots\ lemma bij_betw_roots_unity: @@ -1365,7 +1392,7 @@ lemma csqrt_minus [simp]: assumes "Im x < 0 \ (Im x = 0 \ 0 \ Re x)" - shows "csqrt (- x) = \ * csqrt x" + shows "csqrt (-x) = \ * csqrt x" proof - have "csqrt ((\ * csqrt x)^2) = \ * csqrt x" proof (rule csqrt_square) @@ -1379,6 +1406,17 @@ finally show ?thesis . qed +lemma csqrt_neq_neg_real: + assumes "Im x = 0" "Re x < 0" + shows "csqrt z \ x" + using csqrt_principal[of z] assms by auto + +lemma csqrt_of_real: "x \ 0 \ csqrt (of_real x) = of_real (sqrt x)" + by (rule csqrt_unique) (auto simp flip: of_real_power) + +lemma csqrt_of_real': "csqrt (of_real x) = of_real (sqrt \x\) * (if x \ 0 then 1 else \)" + by (rule csqrt_unique) (auto simp flip: of_real_power simp: power_mult_distrib) + text \Legacy theorem names\ diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Computational_Algebra/Primes.thy --- a/src/HOL/Computational_Algebra/Primes.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Computational_Algebra/Primes.thy Tue Apr 15 17:38:20 2025 +0200 @@ -542,6 +542,25 @@ shows "d dvd p ^ k \ (\i\k. d = p ^ i)" using assms divides_primepow [of p d k] by (auto intro: le_imp_power_dvd) +lemma gcd_prime_int: + assumes "prime (p :: int)" + shows "gcd p k = (if p dvd k then p else 1)" +proof - + have "p \ 0" + using assms prime_ge_0_int by auto + show ?thesis + proof (cases "p dvd k") + case True + thus ?thesis using assms \p \ 0\ by auto + next + case False + hence "coprime p k" + using assms by (simp add: prime_imp_coprime) + with False show ?thesis + by auto + qed +qed + subsection \Chinese Remainder Theorem Variants\ diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Deriv.thy --- a/src/HOL/Deriv.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Deriv.thy Tue Apr 15 17:38:20 2025 +0200 @@ -1067,8 +1067,8 @@ by (simp add: DERIV_unique Uniq_def) lemma DERIV_sum[derivative_intros]: - "(\ n. n \ S \ ((\x. f x n) has_field_derivative (f' x n)) F) \ - ((\x. sum (f x) S) has_field_derivative sum (f' x) S) F" + "(\ n. n \ S \ ((\x. f x n) has_field_derivative (f' n)) F) \ + ((\x. sum (f x) S) has_field_derivative sum f' S) F" by (rule has_derivative_imp_has_field_derivative [OF has_derivative_sum]) (auto simp: sum_distrib_left mult_commute_abs dest: has_field_derivative_imp_has_derivative) diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Euclidean_Rings.thy --- a/src/HOL/Euclidean_Rings.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Euclidean_Rings.thy Tue Apr 15 17:38:20 2025 +0200 @@ -1711,6 +1711,9 @@ end +lemma of_int_div: "b dvd a \ of_int (a div b) = (of_int a / of_int b :: 'a :: field_char_0)" + by (elim dvdE) (auto simp: divide_simps mult_ac) + subsubsection \Algebraic foundations\ diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Int.thy --- a/src/HOL/Int.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Int.thy Tue Apr 15 17:38:20 2025 +0200 @@ -935,7 +935,7 @@ lemma Ints_minus [simp]: "a \ \ \ -a \ \" by (force simp add: Ints_def simp flip: of_int_minus intro: range_eqI) -lemma minus_in_Ints_iff: "-x \ \ \ x \ \" +lemma minus_in_Ints_iff [simp]: "-x \ \ \ x \ \" using Ints_minus[of x] Ints_minus[of "-x"] by auto lemma Ints_diff [simp]: "a \ \ \ b \ \ \ a - b \ \" @@ -1079,6 +1079,61 @@ finally show ?thesis . qed +lemma add_in_Ints_iff_left [simp]: "x \ \ \ x + y \ \ \ y \ \" + by (metis Ints_add Ints_diff add_diff_cancel_left') + +lemma add_in_Ints_iff_right [simp]: "y \ \ \ x + y \ \ \ x \ \" + by (subst add.commute) auto + +lemma diff_in_Ints_iff_left [simp]: "x \ \ \ x - y \ \ \ y \ \" + by (metis Ints_diff add_in_Ints_iff_left diff_add_cancel) + +lemma diff_in_Ints_iff_right [simp]: "y \ \ \ x - y \ \ \ x \ \" + by (metis Ints_minus diff_in_Ints_iff_left minus_diff_eq) + +lemmas [simp] = minus_in_Ints_iff + +lemma fraction_not_in_Ints: + assumes "\(n dvd m)" "n \ 0" + shows "of_int m / of_int n \ (\ :: 'a :: {division_ring,ring_char_0} set)" +proof + assume "of_int m / (of_int n :: 'a) \ \" + then obtain k where "of_int m / of_int n = (of_int k :: 'a)" by (elim Ints_cases) + with assms have "of_int m = (of_int (k * n) :: 'a)" by (auto simp add: field_split_simps) + hence "m = k * n" by (subst (asm) of_int_eq_iff) + hence "n dvd m" by simp + with assms(1) show False by contradiction +qed + +lemma of_int_div_of_int_in_Ints_iff: + "(of_int n / of_int m :: 'a :: {division_ring,ring_char_0}) \ \ \ m = 0 \ m dvd n" +proof + assume *: "m = 0 \ m dvd n" + have "of_int n / of_int m \ (\ :: 'a set)" if "m \ 0" "m dvd n" + proof - + from \m dvd n\ obtain k where "n = m * k" + by (elim dvdE) + hence "n = k * m" + by (simp add: mult.commute) + hence "of_int n / (of_int m :: 'a) = of_int k" + using \m \ 0\ by (simp add: field_simps) + also have "\ \ \" + by auto + finally show ?thesis . + qed + with * show "of_int n / of_int m \ (\ :: 'a set)" + by (cases "m = 0") auto +next + assume *: "(of_int n / of_int m :: 'a) \ \" + thus "m = 0 \ m dvd n" + using fraction_not_in_Ints[of m n, where ?'a = 'a] by auto +qed + +lemma fraction_numeral_not_in_Ints [simp]: + assumes "\(numeral b :: int) dvd numeral a" + shows "numeral a / numeral b \ (\ :: 'a :: {division_ring, ring_char_0} set)" + using fraction_not_in_Ints[of "numeral b" "numeral a", where ?'a = 'a] assms by simp + subsection \\<^term>\sum\ and \<^term>\prod\\ @@ -1733,6 +1788,18 @@ by (simp add: ac_simps) qed +lemma fraction_numeral_not_in_Ints' [simp]: + assumes "b \ Num.One" + shows "1 / numeral b \ (\ :: 'a :: {division_ring, ring_char_0} set)" +proof - + have *: "\numeral b dvd (1 :: int)" + using assms by simp + have "of_int 1 / of_int (numeral b) \ (\ :: 'a set)" + by (rule fraction_not_in_Ints) (use * in auto) + thus ?thesis + by simp +qed + subsection \Powers with integer exponents\ diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Number_Theory/Cong.thy --- a/src/HOL/Number_Theory/Cong.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Number_Theory/Cong.thy Tue Apr 15 17:38:20 2025 +0200 @@ -128,6 +128,46 @@ "[c mod (b * a) = d] (mod a) \ [c = d] (mod a)" using mod_mult_cong_right [of c a b d] by (simp add: ac_simps) +lemma cong_mod_leftI [simp]: + "[b = c] (mod a) \ [b mod a = c] (mod a)" + by (simp add: cong_def) + +lemma cong_mod_rightI [simp]: + "[b = c] (mod a) \ [b = c mod a] (mod a)" + by (simp add: cong_def) + +lemma cong_cmult_leftI: "[a = b] (mod m) \ [c * a = c * b] (mod (c * m))" + by (metis cong_def local.mult_mod_right) + +lemma cong_cmult_rightI: "[a = b] (mod m) \ [a * c = b * c] (mod (m * c))" + using cong_cmult_leftI[of a b m c] by (simp add: mult.commute) + +lemma cong_dvd_mono_modulus: + assumes "[a = b] (mod m)" "m' dvd m" + shows "[a = b] (mod m')" + using assms by (metis cong_def local.mod_mod_cancel) + +lemma coprime_cong_transfer_left: + assumes "coprime a b" "[a = a'] (mod b)" + shows "coprime a' b" + using assms by (metis cong_0 cong_def local.coprime_mod_left_iff) + +lemma coprime_cong_transfer_right: + assumes "coprime a b" "[b = b'] (mod a)" + shows "coprime a b'" + using coprime_cong_transfer_left[of b a b'] assms + by (simp add: coprime_commute) + +lemma coprime_cong_cong_left: + assumes "[a = a'] (mod b)" + shows "coprime a b \ coprime a' b" + using assms cong_sym_eq coprime_cong_transfer_left by blast + +lemma coprime_cong_cong_right: + assumes "[b = b'] (mod a)" + shows "coprime a b \ coprime a b'" + using coprime_cong_cong_left[OF assms] by (simp add: coprime_commute) + end context unique_euclidean_ring @@ -200,6 +240,9 @@ "[x = y] (mod m)" if "[x = y] (mod m * n)" using that by (simp add: cong_iff_dvd_diff) (rule dvd_mult_left) +lemma cong_uminus: "[x = y] (mod m) \ [-x = -y] (mod m)" + unfolding cong_minus_minus_iff . + end lemma cong_abs [simp]: diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Number_Theory/Modular_Inverse.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Number_Theory/Modular_Inverse.thy Tue Apr 15 17:38:20 2025 +0200 @@ -0,0 +1,143 @@ +section \Modular Inverses\ +theory Modular_Inverse + imports Cong "HOL-Library.FuncSet" +begin + +text \ + The following returns the unique number $m$ such that $mn \equiv 1\pmod{p}$ if there is one, + i.e.\ if $n$ and $p$ are coprime, and otherwise $0$ by convention. +\ +definition modular_inverse where + "modular_inverse p n = (if coprime p n then fst (bezout_coefficients n p) mod p else 0)" + +lemma cong_modular_inverse1: + assumes "coprime n p" + shows "[n * modular_inverse p n = 1] (mod p)" +proof - + have "[fst (bezout_coefficients n p) * n + snd (bezout_coefficients n p) * p = + modular_inverse p n * n + 0] (mod p)" + unfolding modular_inverse_def using assms + by (intro cong_add cong_mult) (auto simp: Cong.cong_def coprime_commute) + also have "fst (bezout_coefficients n p) * n + snd (bezout_coefficients n p) * p = gcd n p" + by (simp add: bezout_coefficients_fst_snd) + also have "\ = 1" + using assms by simp + finally show ?thesis + by (simp add: cong_sym mult_ac) +qed + +lemma cong_modular_inverse2: + assumes "coprime n p" + shows "[modular_inverse p n * n = 1] (mod p)" + using cong_modular_inverse1[OF assms] by (simp add: mult.commute) + +lemma coprime_modular_inverse [simp, intro]: + fixes n :: "'a :: {euclidean_ring_gcd,unique_euclidean_semiring}" + assumes "coprime n p" + shows "coprime (modular_inverse p n) p" + using cong_modular_inverse1[OF assms] assms + by (meson cong_imp_coprime cong_sym coprime_1_left coprime_mult_left_iff) + +lemma modular_inverse_int_nonneg: "p > 0 \ modular_inverse p (n :: int) \ 0" + by (simp add: modular_inverse_def) + +lemma modular_inverse_int_less: "p > 0 \ modular_inverse p (n :: int) < p" + by (simp add: modular_inverse_def) + +lemma modular_inverse_int_eqI: + fixes x y :: int + assumes "y \ {0.. = 1 * y] (mod m)" + using \coprime x m\ by (intro cong_mult cong_refl cong_modular_inverse2) + finally have "[modular_inverse m x = y] (mod m)" + by simp + thus "modular_inverse m x = y" + using assms by (simp add: Cong.cong_def modular_inverse_def) +qed + +lemma modular_inverse_1 [simp]: + assumes "m > (1 :: int)" + shows "modular_inverse m 1 = 1" + by (rule modular_inverse_int_eqI) (use assms in auto) + +lemma modular_inverse_int_mult: + fixes x y :: int + assumes "coprime x m" "coprime y m" "m > 0" + shows "modular_inverse m (x * y) = (modular_inverse m y * modular_inverse m x) mod m" +proof (rule modular_inverse_int_eqI) + show "modular_inverse m y * modular_inverse m x mod m \ {0.. = 1 * 1] (mod m)" + by (intro cong_mult cong_modular_inverse1 assms) + finally show "[x * y * (modular_inverse m y * modular_inverse m x mod m) = 1] (mod m)" + by simp +qed + +lemma bij_betw_int_remainders_mult: + fixes a n :: int + assumes a: "coprime a n" + shows "bij_betw (\m. a * m mod n) {1.. a * m mod n \ {1.. {1..n dvd (a * m)" + using m by (simp add: coprime_commute coprime_dvd_mult_right_iff zdvd_not_zless) + hence "a * m mod n > 0" + using m order_le_less by fastforce + thus "a * m mod n \ {1..m. a' * m mod n"]) auto +qed + +lemma mult_modular_inverse_of_not_coprime [simp]: "\coprime a m \ modular_inverse m a = 0" + by (simp add: coprime_commute modular_inverse_def) + +lemma mult_modular_inverse_eq_0_iff: + fixes a :: "'a :: {unique_euclidean_semiring, euclidean_ring_gcd}" + shows "\is_unit m \ modular_inverse m a = 0 \ \coprime a m" + by (metis coprime_modular_inverse mult_modular_inverse_of_not_coprime coprime_0_left_iff) + +lemma mult_modular_inverse_int_pos: "m > 1 \ coprime a m \ modular_inverse m a > (0 :: int)" + by (simp add: modular_inverse_int_nonneg mult_modular_inverse_eq_0_iff order.strict_iff_order) + +lemma abs_mult_modular_inverse_int_less: "m \ 0 \ \modular_inverse m a :: int\ < \m\" + by (auto simp: modular_inverse_def intro!: abs_mod_less) + +lemma modular_inverse_int_less': "m \ 0 \ (modular_inverse m a :: int) < \m\" + using abs_mult_modular_inverse_int_less[of m a] by linarith + +end \ No newline at end of file diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Number_Theory/Number_Theory.thy --- a/src/HOL/Number_Theory/Number_Theory.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Number_Theory/Number_Theory.thy Tue Apr 15 17:38:20 2025 +0200 @@ -11,6 +11,7 @@ Pocklington Prime_Powers Residue_Primitive_Roots + Modular_Inverse begin end diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Power.thy --- a/src/HOL/Power.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Power.thy Tue Apr 15 17:38:20 2025 +0200 @@ -836,6 +836,19 @@ using assms by (metis add.inverse_inverse linear mult_le_one neg_equal_0_iff_equal neg_le_iff_le power2_eq_square power_minus_Bit0) +lemma power2_mono: "\x\ \ \y\ \ x ^ 2 \ y ^ 2" + by (simp add: abs_le_square_iff) + +lemma power2_strict_mono: + assumes "\x\ < \y\" + shows "x ^ 2 < y ^ 2" +proof - + have "\x\ ^ 2 < \y\ ^ 2" + by (rule power_strict_mono) (use assms in auto) + thus ?thesis + by simp +qed + end subsection \Miscellaneous rules\ diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Rings.thy --- a/src/HOL/Rings.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Rings.thy Tue Apr 15 17:38:20 2025 +0200 @@ -422,6 +422,15 @@ then show "- x dvd y" .. qed +lemma dvd_diff_right_iff: + assumes "a dvd b" + shows "a dvd b - c \ a dvd c" (is "?P \ ?Q") + using dvd_add_right_iff[of a b "-c"] assms by auto + +lemma dvd_diff_left_iff: + shows "a dvd c \ a dvd b - c \ a dvd b" + using dvd_add_left_iff[of a "-c" b] by auto + lemma dvd_diff [simp]: "x dvd y \ x dvd z \ x dvd (y - z)" using dvd_add [of x y "- z"] by simp diff -r 111b1b2a2d13 -r da14e77a48b2 src/HOL/Vector_Spaces.thy --- a/src/HOL/Vector_Spaces.thy Tue Apr 15 15:17:25 2025 +0200 +++ b/src/HOL/Vector_Spaces.thy Tue Apr 15 17:38:20 2025 +0200 @@ -75,6 +75,19 @@ and linear_scale_left = module_hom_scale_left and linear_uminus = module_hom_uminus +lemma linear_representation: + assumes "independent B" "span B = UNIV" + shows "linear scale (*) (\v. representation B v b)" +proof (unfold_locales, goal_cases) + case (5 x y) + show ?case + using assms by (subst representation_add) auto +next + case (6 r x) + show ?case + using assms by (subst representation_scale) auto +qed (simp_all add: algebra_simps) + lemma linear_imp_scale: fixes D::"'a \ 'b" assumes "linear (*) scale D"