(* Title: HOL/NthRoot.thy Author: Jacques D. Fleuriot, 1998 Author: Lawrence C Paulson, 2004 *)
section‹Nth Roots of Real Numbers›
theory NthRoot imports Deriv begin
subsection‹Existence of Nth Root›
text‹Existence follows from the Intermediate Value Theorem›
lemma realpow_pos_nth: fixes a :: real assumes n: "0 < n" and a: "0 < a" shows"∃r>0. r ^ n = a" proof - have"∃r≥0. r ≤ (max 1 a) ∧ r ^ n = a" proof (rule IVT) show"0 ^ n ≤ a" using n a by (simp add: power_0_left) show"0 ≤ max 1 a" by simp from n have n1: "1 ≤ n" by simp have"a ≤ max 1 a ^ 1" by simp alsohave"max 1 a ^ 1 ≤ max 1 a ^ n" using n1 by (rule power_increasing) simp finallyshow"a ≤ max 1 a ^ n" . show"∀r. 0 ≤ r ∧ r ≤ max 1 a ⟶ isCont (λx. x ^ n) r" by simp qed thenobtain r where r: "0 ≤ r ∧ r ^ n = a" by fast with n a have"r ≠ 0" by (auto simp add: power_0_left) with r have"0 < r ∧ r ^ n = a" by simp thenshow ?thesis .. qed
(* Used by Integration/RealRandVar.thy in AFP *) lemma realpow_pos_nth2: "(0::real) < a ==>∃r>0. r ^ Suc n = a" by (blast intro: realpow_pos_nth)
text‹Uniqueness of nth positive root.› lemma realpow_pos_nth_unique: "0 < n ==> 0 < a ==>∃!r. 0 < r ∧ r ^ n = a"for a :: real by (auto intro!: realpow_pos_nth simp: power_eq_iff_eq_base)
subsection‹Nth Root›
text‹ We define roots of negative reals such that ‹root n (- x) = - root n x›.
This allows us to omit side conditions from many theorems. ›
lemma inj_sgn_power: assumes"0 < n" shows"inj (λy. sgn y * ∣y∣^n :: real)"
(is"inj ?f") proof (rule injI) have x: "(0 < a ∧ b < 0) ∨ (a < 0 ∧ 0 < b) ==> a ≠ b"for a b :: real by auto fix x y assume"?f x = ?f y" with power_eq_iff_eq_base[of n "∣x∣""∣y∣"] ‹0 🚫›show"x = y" by (cases rule: linorder_cases[of 0 x, case_product linorder_cases[of 0 y]])
(simp_all add: x) qed
lemma sgn_power_injE: "sgn a * ∣a∣ ^ n = x ==> x = sgn b * ∣b∣ ^ n ==> 0 < n ==> a = b" for a b :: real using inj_sgn_power[THEN injD, of n a b] by simp
definition root :: "nat ==> real ==> real" where"root n x = (if n = 0 then 0 else the_inv (λy. sgn y * ∣y∣^n) x)"
lemma root_0 [simp]: "root 0 x = 0" by (simp add: root_def)
lemma root_sgn_power: "0 < n ==> root n (sgn y * ∣y∣^n) = y" using the_inv_f_f[OF inj_sgn_power] by (simp add: root_def)
lemma sgn_power_root: assumes"0 < n" shows"sgn (root n x) * ∣(root n x)∣^n = x"
(is"?f (root n x) = x") proof (cases "x = 0") case True with assms root_sgn_power[of n 0] show ?thesis by simp next case False with realpow_pos_nth[OF ‹0 🚫›, of "∣x∣"] obtain r where"0 < r""r ^ n = ∣x∣" by auto with‹x ≠ 0›have S: "x ∈ range ?f" by (intro image_eqI[of _ _ "sgn x * r"])
(auto simp: abs_mult sgn_mult power_mult_distrib abs_sgn_eq mult_sgn_abs) from‹0 🚫› f_the_inv_into_f[OF inj_sgn_power[OF ‹0 🚫›] this] show ?thesis by (simp add: root_def) qed
lemma split_root: "P (root n x) ⟷ (n = 0 ⟶ P 0) ∧ (0 < n ⟶ (∀y. sgn y * ∣y∣^n = x ⟶ P y))" proof (cases "n = 0") case True thenshow ?thesis by simp next case False thenshow ?thesis by simp (metis root_sgn_power sgn_power_root) qed
lemma real_root_zero [simp]: "root n 0 = 0" by (simp split: split_root add: sgn_zero_iff)
lemma real_root_minus: "root n (- x) = - root n x" by (clarsimp split: split_root elim!: sgn_power_injE simp: sgn_minus)
lemma real_root_less_mono: "0 < n ==> x < y ==> root n x < root n y" proof (clarsimp split: split_root) have *: "0 < b ==> a < 0 ==>¬ a > b"for a b :: real by auto fix a b :: real assume"0 < n""sgn a * ∣a∣ ^ n < sgn b * ∣b∣ ^ n" thenshow"a < b" using power_less_imp_less_base[of a n b]
power_less_imp_less_base[of "- b" n "- a"] by (simp add: sgn_real_def * [of "a ^ n""- ((- b) ^ n)"]
split: if_split_asm) qed
lemma real_root_gt_zero: "0 < n ==> 0 < x ==> 0 < root n x" using real_root_less_mono[of n 0 x] by simp
lemma real_root_ge_zero: "0 ≤ x ==> 0 ≤ root n x" using real_root_gt_zero[of n x] by (cases "n = 0") (auto simp add: le_less)
lemma real_root_pow_pos: "0 < n ==> 0 < x ==> root n x ^ n = x"(* TODO: rename *) using sgn_power_root[of n x] real_root_gt_zero[of n x] by simp
lemma real_root_pow_pos2 [simp]: "0 < n ==> 0 ≤ x ==> root n x ^ n = x"(* TODO: rename *) by (auto simp add: order_le_less real_root_pow_pos)
lemma sgn_root: "0 < n ==> sgn (root n x) = sgn x" by (auto split: split_root simp: sgn_real_def)
lemma odd_real_root_pow: "odd n ==> root n x ^ n = x" using sgn_power_root[of n x] by (simp add: odd_pos sgn_real_def split: if_split_asm)
lemma real_root_power_cancel: "0 < n ==> 0 ≤ x ==> root n (x ^ n) = x" using root_sgn_power[of n x] by (auto simp add: le_less power_0_left)
lemma odd_real_root_power_cancel: "odd n ==> root n (x ^ n) = x" using root_sgn_power[of n x] by (simp add: odd_pos sgn_real_def power_0_left split: if_split_asm)
lemma real_root_pos_unique: "0 < n ==> 0 ≤ y ==> y ^ n = x ==> root n x = y" using real_root_power_cancel by blast
lemma odd_real_root_unique: "odd n ==> y ^ n = x ==> root n x = y" using odd_real_root_power_cancel by blast
lemma real_root_one [simp]: "0 < n ==> root n 1 = 1" by (simp add: real_root_pos_unique)
text‹Root function is strictly monotonic, hence injective.›
lemma real_root_le_mono: "0 < n ==> x ≤ y ==> root n x ≤ root n y" by (auto simp add: order_le_less real_root_less_mono)
lemma real_root_less_iff [simp]: "0 < n ==> root n x < root n y ⟷ x < y" by (cases "x < y") (simp_all add: real_root_less_mono linorder_not_less real_root_le_mono)
lemma real_root_le_iff [simp]: "0 < n ==> root n x ≤ root n y ⟷ x ≤ y" by (cases "x ≤ y") (simp_all add: real_root_le_mono linorder_not_le real_root_less_mono)
lemma real_root_eq_iff [simp]: "0 < n ==> root n x = root n y ⟷ x = y" by (simp add: order_eq_iff)
lemma real_root_gt_1_iff [simp]: "0 < n ==> 1 < root n y ⟷ 1 < y" using real_root_less_iff [where x=1] by simp
lemma real_root_lt_1_iff [simp]: "0 < n ==> root n x < 1 ⟷ x < 1" using real_root_less_iff [where y=1] by simp
lemma real_root_ge_1_iff [simp]: "0 < n ==> 1 ≤ root n y ⟷ 1 ≤ y" using real_root_le_iff [where x=1] by simp
lemma real_root_le_1_iff [simp]: "0 < n ==> root n x ≤ 1 ⟷ x ≤ 1" using real_root_le_iff [where y=1] by simp
lemma real_root_eq_1_iff [simp]: "0 < n ==> root n x = 1 ⟷ x = 1" using real_root_eq_iff [where y=1] by simp
text‹Roots of multiplication and division.›
lemma real_root_mult: "root n (x * y) = root n x * root n y" by (auto split: split_root elim!: sgn_power_injE
simp: sgn_mult abs_mult power_mult_distrib)
lemma real_root_inverse: "root n (inverse x) = inverse (root n x)" by (auto split: split_root elim!: sgn_power_injE
simp: power_inverse)
lemma real_root_divide: "root n (x / y) = root n x / root n y" by (simp add: divide_inverse real_root_mult real_root_inverse)
lemma real_root_abs: "0 < n ==> root n ∣x∣ = ∣root n x∣" by (simp add: abs_if real_root_minus)
lemma root_abs_power: "n > 0 ==> abs (root n (y ^n)) = abs y" using root_sgn_power [of n] by (metis abs_ge_zero power_abs real_root_abs real_root_power_cancel)
lemma real_root_power: "0 < n ==> root n (x ^ k) = root n x ^ k" by (induct k) (simp_all add: real_root_mult)
text‹Roots of roots.›
lemma real_root_Suc_0 [simp]: "root (Suc 0) x = x" by (simp add: odd_real_root_unique)
lemma real_root_mult_exp: "root (m * n) x = root m (root n x)" by (auto split: split_root elim!: sgn_power_injE
simp: sgn_zero_iff sgn_mult power_mult[symmetric]
abs_mult power_mult_distrib abs_sgn_eq)
lemma real_root_commute: "root m (root n x) = root n (root m x)" by (simp add: real_root_mult_exp [symmetric] mult.commute)
text‹Monotonicity in first argument.›
lemma real_root_strict_decreasing: assumes"0 < n""n < N""1 < x" shows"root N x < root n x" proof - from assms have"root n (root N x) ^ n < root N (root n x) ^ N" by (simp add: real_root_commute power_strict_increasing del: real_root_pow_pos2) with assms show ?thesis by simp qed
lemma real_root_strict_increasing: assumes"0 < n""n < N""0 < x""x < 1" shows"root n x < root N x" proof - from assms have"root N (root n x) ^ N < root n (root N x) ^ n" by (simp add: real_root_commute power_strict_decreasing del: real_root_pow_pos2) with assms show ?thesis by simp qed
lemma real_root_decreasing: "0 < n ==> n ≤ N ==> 1 ≤ x ==> root N x ≤ root n x" by (auto simp add: order_le_less real_root_strict_decreasing)
lemma real_root_increasing: "0 < n ==> n ≤ N ==> 0 ≤ x ==> x ≤ 1 ==> root n x ≤ root N x" by (auto simp add: order_le_less real_root_strict_increasing)
text‹Continuity and derivatives.›
lemma isCont_real_root: "isCont (root n) x" proof (cases "n > 0") case True let ?f = "λy::real. sgn y * ∣y∣^n" have"continuous_on ({0..} ∪ {.. 0}) (λx. if 0 < x then x ^ n else - ((-x) ^ n) :: real)" using True by (intro continuous_on_If continuous_intros) auto thenhave"continuous_on UNIV ?f" by (rule continuous_on_cong[THEN iffD1, rotated 2]) (auto simp: not_less le_less True) thenhave [simp]: "isCont ?f x"for x by (simp add: continuous_on_eq_continuous_at) have"isCont (root n) (?f (root n x))" by (rule isCont_inverse_function [where f="?f"and d=1]) (auto simp: root_sgn_power True) thenshow ?thesis by (simp add: sgn_power_root True) next case False thenshow ?thesis by (simp add: root_def[abs_def]) qed
lemma tendsto_real_root [tendsto_intros]: "(f ---> x) F ==> ((λx. root n (f x)) ---> root n x) F" using isCont_tendsto_compose[OF isCont_real_root, of f x F] .
lemma continuous_real_root [continuous_intros]: "continuous F f ==> continuous F (λx. root n (f x))" unfolding continuous_def by (rule tendsto_real_root)
lemma continuous_on_real_root [continuous_intros]: "continuous_on s f ==> continuous_on s (λx. root n (f x))" unfolding continuous_on_def by (auto intro: tendsto_real_root)
lemma DERIV_real_root: assumes n: "0 < n" and x: "0 < x" shows"DERIV (root n) x :> inverse (real n * root n x ^ (n - Suc 0))" proof (rule DERIV_inverse_function) show"0 < x" using x . show"x < x + 1" by simp show"DERIV (λx. x ^ n) (root n x) :> real n * root n x ^ (n - Suc 0)" by (rule DERIV_pow) show"real n * root n x ^ (n - Suc 0) ≠ 0" using n x by simp show"isCont (root n) x" by (rule isCont_real_root) qed (use n in auto)
lemma DERIV_odd_real_root: assumes n: "odd n" and x: "x ≠ 0" shows"DERIV (root n) x :> inverse (real n * root n x ^ (n - Suc 0))" proof (rule DERIV_inverse_function) show"x - 1 < x""x < x + 1" by auto show"DERIV (λx. x ^ n) (root n x) :> real n * root n x ^ (n - Suc 0)" by (rule DERIV_pow) show"real n * root n x ^ (n - Suc 0) ≠ 0" using odd_pos [OF n] x by simp show"isCont (root n) x" by (rule isCont_real_root) qed (use n odd_real_root_pow in auto)
lemma DERIV_even_real_root: assumes n: "0 < n" and"even n" and x: "x < 0" shows"DERIV (root n) x :> inverse (- real n * root n x ^ (n - Suc 0))" proof (rule DERIV_inverse_function) show"x - 1 < x" by simp show"x < 0" using x . show"- (root n y ^ n) = y"if"x - 1 < y"and"y < 0"for y proof - have"root n (-y) ^ n = -y" using that ‹0 🚫›by simp with real_root_minus and‹even n› show"- (root n y ^ n) = y"by simp qed show"DERIV (λx. - (x ^ n)) (root n x) :> - real n * root n x ^ (n - Suc 0)" by (auto intro!: derivative_eq_intros) show"- real n * root n x ^ (n - Suc 0) ≠ 0" using n x by simp show"isCont (root n) x" by (rule isCont_real_root) qed
lemma DERIV_real_root_generic: assumes"0 < n" and"x ≠ 0" and"even n ==> 0 < x ==> D = inverse (real n * root n x ^ (n - Suc 0))" and"even n ==> x < 0 ==> D = - inverse (real n * root n x ^ (n - Suc 0))" and"odd n ==> D = inverse (real n * root n x ^ (n - Suc 0))" shows"DERIV (root n) x :> D" using assms by (cases "even n", cases "0 < x")
(auto intro: DERIV_real_root[THEN DERIV_cong]
DERIV_odd_real_root[THEN DERIV_cong]
DERIV_even_real_root[THEN DERIV_cong])
lemma power_tendsto_0_iff [simp]: fixes f :: "'a ==> real" assumes"n > 0" shows"((λx. f x ^ n) ---> 0) F ⟷ (f ---> 0) F" proof - have"((λx. ∣root n (f x ^ n)∣) ---> 0) F ==> (f ---> 0) F" by (auto simp: assms root_abs_power tendsto_rabs_zero_iff) thenhave"((λx. f x ^ n) ---> 0) F ==> (f ---> 0) F" by (metis tendsto_real_root abs_0 real_root_zero tendsto_rabs) with assms show ?thesis by (auto simp: tendsto_null_power) qed
lemma real_sqrt_divide: "sqrt (x / y) = sqrt x / sqrt y" unfolding sqrt_def by (rule real_root_divide)
lemma real_sqrt_power: "sqrt (x ^ k) = sqrt x ^ k" unfolding sqrt_def by (rule real_root_power [OF pos2])
lemma real_sqrt_gt_zero: "0 < x ==> 0 < sqrt x" unfolding sqrt_def by (rule real_root_gt_zero [OF pos2])
lemma real_sqrt_ge_zero: "0 ≤ x ==> 0 ≤ sqrt x" unfolding sqrt_def by (rule real_root_ge_zero)
lemma real_sqrt_less_mono: "x < y ==> sqrt x < sqrt y" unfolding sqrt_def by (rule real_root_less_mono [OF pos2])
lemma real_sqrt_le_mono: "x ≤ y ==> sqrt x ≤ sqrt y" unfolding sqrt_def by (rule real_root_le_mono [OF pos2])
lemma real_sqrt_less_iff [simp]: "sqrt x < sqrt y ⟷ x < y" unfolding sqrt_def by (rule real_root_less_iff [OF pos2])
lemma real_sqrt_le_iff [simp]: "sqrt x ≤ sqrt y ⟷ x ≤ y" unfolding sqrt_def by (rule real_root_le_iff [OF pos2])
lemma real_sqrt_eq_iff [simp]: "sqrt x = sqrt y ⟷ x = y" unfolding sqrt_def by (rule real_root_eq_iff [OF pos2])
lemma real_less_lsqrt: "0 ≤ y ==> x < y🪙2 ==> sqrt x < y" using real_sqrt_less_iff[of x "y🪙2"] by simp
lemma real_le_lsqrt: "0 ≤ y ==> x ≤ y🪙2 ==> sqrt x ≤ y" using real_sqrt_le_iff[of x "y🪙2"] by simp
lemma real_le_rsqrt: "x🪙2 ≤ y ==> x ≤ sqrt y" using real_sqrt_le_mono[of "x🪙2" y] by simp
lemma real_less_rsqrt: "x🪙2 < y ==> x < sqrt y" using real_sqrt_less_mono[of "x🪙2" y] by simp
lemma real_sqrt_power_even: assumes"even n""x ≥ 0" shows"sqrt x ^ n = x ^ (n div 2)" proof - from assms obtain k where"n = 2*k"by (auto elim!: evenE) with assms show ?thesis by (simp add: power_mult) qed
lemma sqrt_le_D: "sqrt x ≤ y ==> x ≤ y🪙2" by (meson not_le real_less_rsqrt)
lemma sqrt_ge_absD: "∣x∣≤ sqrt y ==> x🪙2 ≤ y" using real_sqrt_le_iff[of "x🪙2"] by simp
lemma sqrt_even_pow2: assumes n: "even n" shows"sqrt (2 ^ n) = 2 ^ (n div 2)" proof - from n obtain m where m: "n = 2 * m" .. from m have"sqrt (2 ^ n) = sqrt ((2 ^ m)🪙2)" by (simp only: power_mult[symmetric] mult.commute) thenshow ?thesis using m by simp qed
lemma continuous_real_sqrt [continuous_intros]: "continuous F f ==> continuous F (λx. sqrt (f x))" unfolding sqrt_def by (rule continuous_real_root)
lemma continuous_on_real_sqrt [continuous_intros]: "continuous_on s f ==> continuous_on s (λx. sqrt (f x))" unfolding sqrt_def by (rule continuous_on_real_root)
lemma DERIV_real_sqrt_generic: assumes"x ≠ 0" and"x > 0 ==> D = inverse (sqrt x) / 2" and"x < 0 ==> D = - inverse (sqrt x) / 2" shows"DERIV sqrt x :> D" using assms unfolding sqrt_def by (auto intro!: DERIV_real_root_generic)
lemma DERIV_real_sqrt: "0 < x ==> DERIV sqrt x :> inverse (sqrt x) / 2" using DERIV_real_sqrt_generic by simp
lemma real_inv_sqrt_pow2: "0 < x ==> (inverse (sqrt x))🪙2 = inverse x" by (simp add: power_inverse)
lemma real_sqrt_eq_zero_cancel: "0 ≤ x ==> sqrt x = 0 ==> x = 0" by simp
lemma real_sqrt_ge_one: "1 ≤ x ==> 1 ≤ sqrt x" by simp
lemma sqrt_divide_self_eq: assumes nneg: "0 ≤ x" shows"sqrt x / x = inverse (sqrt x)" proof (cases "x = 0") case True thenshow ?thesis by simp next case False thenhave pos: "0 < x" using nneg by arith show ?thesis proof (rule right_inverse_eq [THEN iffD1, symmetric]) show"sqrt x / x ≠ 0" by (simp add: divide_inverse nneg False) show"inverse (sqrt x) / (sqrt x / x) = 1" by (simp add: divide_inverse mult.assoc [symmetric]
power2_eq_square [symmetric] real_inv_sqrt_pow2 pos False) qed qed
lemma real_div_sqrt: "0 ≤ x ==> x / sqrt x = sqrt x" by (cases "x = 0") (simp_all add: sqrt_divide_self_eq [of x] field_simps)
lemma real_divide_square_eq [simp]: "(r * a) / (r * r) = a / r" for a r :: real by (cases "r = 0") (simp_all add: divide_inverse ac_simps)
lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u" by (simp add: divide_less_eq)
lemma four_x_squared: "4 * x🪙2 = (2 * x)🪙2" for x :: real by (simp add: power2_eq_square)
lemma sqrt_at_top: "LIM x at_top. sqrt x :: real :> at_top" by (rule filterlim_at_top_at_top[where Q="λx. True"and P="λx. 0 < x"and g="power2"])
(auto intro: eventually_gt_at_top)
subsection‹Square Root of Sum of Squares›
lemma sum_squares_bound: "2 * x * y ≤ x🪙2 + y🪙2" for x y :: "'a::linordered_field" proof - have"(x - y)🪙2 = x * x - 2 * x * y + y * y" by algebra thenhave"0 ≤ x🪙2 - 2 * x * y + y🪙2" by (metis sum_power2_ge_zero zero_le_double_add_iff_zero_le_single_add power2_eq_square) thenshow ?thesis by arith qed
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.