src/HOL/NthRoot.thy
 author paulson Tue Nov 10 14:18:41 2015 +0000 (2015-11-10) changeset 61609 77b453bd616f parent 60867 86e7560e07d0 child 61649 268d88ec9087 permissions -rw-r--r--
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson@12196 ` 1` ```(* Title : NthRoot.thy ``` paulson@12196 ` 2` ``` Author : Jacques D. Fleuriot ``` paulson@12196 ` 3` ``` Copyright : 1998 University of Cambridge ``` paulson@14477 ` 4` ``` Conversion to Isar and new proofs by Lawrence C Paulson, 2004 ``` paulson@12196 ` 5` ```*) ``` paulson@12196 ` 6` wenzelm@60758 ` 7` ```section \Nth Roots of Real Numbers\ ``` paulson@14324 ` 8` nipkow@15131 ` 9` ```theory NthRoot ``` lp15@60141 ` 10` ```imports Deriv Binomial ``` nipkow@15131 ` 11` ```begin ``` paulson@14324 ` 12` hoelzl@51483 ` 13` ```lemma abs_sgn_eq: "abs (sgn x :: real) = (if x = 0 then 0 else 1)" ``` hoelzl@51483 ` 14` ``` by (simp add: sgn_real_def) ``` hoelzl@51483 ` 15` hoelzl@51483 ` 16` ```lemma inverse_sgn: "sgn (inverse a) = inverse (sgn a :: real)" ``` hoelzl@51483 ` 17` ``` by (simp add: sgn_real_def) ``` hoelzl@51483 ` 18` lp15@61609 ` 19` ```lemma power_eq_iff_eq_base: ``` hoelzl@51483 ` 20` ``` fixes a b :: "_ :: linordered_semidom" ``` hoelzl@51483 ` 21` ``` shows "0 < n \ 0 \ a \ 0 \ b \ a ^ n = b ^ n \ a = b" ``` hoelzl@51483 ` 22` ``` using power_eq_imp_eq_base[of a n b] by auto ``` hoelzl@51483 ` 23` wenzelm@60758 ` 24` ```subsection \Existence of Nth Root\ ``` huffman@20687 ` 25` wenzelm@60758 ` 26` ```text \Existence follows from the Intermediate Value Theorem\ ``` paulson@14324 ` 27` huffman@23009 ` 28` ```lemma realpow_pos_nth: ``` huffman@23009 ` 29` ``` assumes n: "0 < n" ``` huffman@23009 ` 30` ``` assumes a: "0 < a" ``` huffman@23009 ` 31` ``` shows "\r>0. r ^ n = (a::real)" ``` huffman@23009 ` 32` ```proof - ``` huffman@23009 ` 33` ``` have "\r\0. r \ (max 1 a) \ r ^ n = a" ``` huffman@23009 ` 34` ``` proof (rule IVT) ``` huffman@23009 ` 35` ``` show "0 ^ n \ a" using n a by (simp add: power_0_left) ``` huffman@23009 ` 36` ``` show "0 \ max 1 a" by simp ``` huffman@23009 ` 37` ``` from n have n1: "1 \ n" by simp ``` huffman@23009 ` 38` ``` have "a \ max 1 a ^ 1" by simp ``` huffman@23009 ` 39` ``` also have "max 1 a ^ 1 \ max 1 a ^ n" ``` huffman@23009 ` 40` ``` using n1 by (rule power_increasing, simp) ``` huffman@23009 ` 41` ``` finally show "a \ max 1 a ^ n" . ``` huffman@23009 ` 42` ``` show "\r. 0 \ r \ r \ max 1 a \ isCont (\x. x ^ n) r" ``` huffman@44289 ` 43` ``` by simp ``` huffman@23009 ` 44` ``` qed ``` huffman@23009 ` 45` ``` then obtain r where r: "0 \ r \ r ^ n = a" by fast ``` huffman@23009 ` 46` ``` with n a have "r \ 0" by (auto simp add: power_0_left) ``` huffman@23009 ` 47` ``` with r have "0 < r \ r ^ n = a" by simp ``` huffman@23009 ` 48` ``` thus ?thesis .. ``` huffman@23009 ` 49` ```qed ``` paulson@14325 ` 50` huffman@23047 ` 51` ```(* Used by Integration/RealRandVar.thy in AFP *) ``` huffman@23047 ` 52` ```lemma realpow_pos_nth2: "(0::real) < a \ \r>0. r ^ Suc n = a" ``` huffman@23047 ` 53` ```by (blast intro: realpow_pos_nth) ``` huffman@23047 ` 54` wenzelm@60758 ` 55` ```text \Uniqueness of nth positive root\ ``` paulson@14324 ` 56` hoelzl@51483 ` 57` ```lemma realpow_pos_nth_unique: "\0 < n; 0 < a\ \ \!r. 0 < r \ r ^ n = (a::real)" ``` hoelzl@51483 ` 58` ``` by (auto intro!: realpow_pos_nth simp: power_eq_iff_eq_base) ``` paulson@14324 ` 59` wenzelm@60758 ` 60` ```subsection \Nth Root\ ``` huffman@20687 ` 61` wenzelm@60758 ` 62` ```text \We define roots of negative reals such that ``` huffman@22956 ` 63` ``` @{term "root n (- x) = - root n x"}. This allows ``` wenzelm@60758 ` 64` ``` us to omit side conditions from many theorems.\ ``` huffman@20687 ` 65` hoelzl@51483 ` 66` ```lemma inj_sgn_power: assumes "0 < n" shows "inj (\y. sgn y * \y\^n :: real)" (is "inj ?f") ``` hoelzl@51483 ` 67` ```proof (rule injI) ``` hoelzl@51483 ` 68` ``` have x: "\a b :: real. (0 < a \ b < 0) \ (a < 0 \ 0 < b) \ a \ b" by auto ``` wenzelm@60758 ` 69` ``` fix x y assume "?f x = ?f y" with power_eq_iff_eq_base[of n "\x\" "\y\"] \0 show "x = y" ``` hoelzl@51483 ` 70` ``` by (cases rule: linorder_cases[of 0 x, case_product linorder_cases[of 0 y]]) ``` hoelzl@51483 ` 71` ``` (simp_all add: x) ``` hoelzl@51483 ` 72` ```qed ``` hoelzl@51483 ` 73` hoelzl@51483 ` 74` ```lemma sgn_power_injE: "sgn a * \a\ ^ n = x \ x = sgn b * \b\ ^ n \ 0 < n \ a = (b::real)" ``` hoelzl@51483 ` 75` ``` using inj_sgn_power[THEN injD, of n a b] by simp ``` hoelzl@51483 ` 76` hoelzl@51483 ` 77` ```definition root :: "nat \ real \ real" where ``` hoelzl@51483 ` 78` ``` "root n x = (if n = 0 then 0 else the_inv (\y. sgn y * \y\^n) x)" ``` hoelzl@51483 ` 79` hoelzl@51483 ` 80` ```lemma root_0 [simp]: "root 0 x = 0" ``` hoelzl@51483 ` 81` ``` by (simp add: root_def) ``` hoelzl@51483 ` 82` hoelzl@51483 ` 83` ```lemma root_sgn_power: "0 < n \ root n (sgn y * \y\^n) = y" ``` hoelzl@51483 ` 84` ``` using the_inv_f_f[OF inj_sgn_power] by (simp add: root_def) ``` hoelzl@51483 ` 85` hoelzl@51483 ` 86` ```lemma sgn_power_root: ``` hoelzl@51483 ` 87` ``` assumes "0 < n" shows "sgn (root n x) * \(root n x)\^n = x" (is "?f (root n x) = x") ``` hoelzl@51483 ` 88` ```proof cases ``` hoelzl@51483 ` 89` ``` assume "x \ 0" ``` wenzelm@60758 ` 90` ``` with realpow_pos_nth[OF \0 < n\, of "\x\"] obtain r where "0 < r" "r ^ n = \x\" by auto ``` wenzelm@60758 ` 91` ``` with \x \ 0\ have S: "x \ range ?f" ``` hoelzl@51483 ` 92` ``` by (intro image_eqI[of _ _ "sgn x * r"]) ``` hoelzl@51483 ` 93` ``` (auto simp: abs_mult sgn_mult power_mult_distrib abs_sgn_eq mult_sgn_abs) ``` wenzelm@60758 ` 94` ``` from \0 < n\ f_the_inv_into_f[OF inj_sgn_power[OF \0 < n\] this] show ?thesis ``` hoelzl@51483 ` 95` ``` by (simp add: root_def) ``` wenzelm@60758 ` 96` ```qed (insert \0 < n\ root_sgn_power[of n 0], simp) ``` hoelzl@51483 ` 97` hoelzl@51483 ` 98` ```lemma split_root: "P (root n x) \ (n = 0 \ P 0) \ (0 < n \ (\y. sgn y * \y\^n = x \ P y))" ``` hoelzl@51483 ` 99` ``` apply (cases "n = 0") ``` hoelzl@51483 ` 100` ``` apply simp_all ``` hoelzl@51483 ` 101` ``` apply (metis root_sgn_power sgn_power_root) ``` hoelzl@51483 ` 102` ``` done ``` huffman@20687 ` 103` huffman@22956 ` 104` ```lemma real_root_zero [simp]: "root n 0 = 0" ``` hoelzl@51483 ` 105` ``` by (simp split: split_root add: sgn_zero_iff) ``` hoelzl@51483 ` 106` hoelzl@51483 ` 107` ```lemma real_root_minus: "root n (- x) = - root n x" ``` hoelzl@51483 ` 108` ``` by (clarsimp split: split_root elim!: sgn_power_injE simp: sgn_minus) ``` huffman@22956 ` 109` hoelzl@51483 ` 110` ```lemma real_root_less_mono: "\0 < n; x < y\ \ root n x < root n y" ``` hoelzl@51483 ` 111` ```proof (clarsimp split: split_root) ``` hoelzl@51483 ` 112` ``` have x: "\a b :: real. (0 < b \ a < 0) \ \ a > b" by auto ``` hoelzl@51483 ` 113` ``` fix a b :: real assume "0 < n" "sgn a * \a\ ^ n < sgn b * \b\ ^ n" then show "a < b" ``` hoelzl@51483 ` 114` ``` using power_less_imp_less_base[of a n b] power_less_imp_less_base[of "-b" n "-a"] ``` haftmann@60867 ` 115` ``` by (simp add: sgn_real_def x [of "a ^ n" "- ((- b) ^ n)"] split: split_if_asm) ``` hoelzl@51483 ` 116` ```qed ``` huffman@22956 ` 117` huffman@22956 ` 118` ```lemma real_root_gt_zero: "\0 < n; 0 < x\ \ 0 < root n x" ``` hoelzl@51483 ` 119` ``` using real_root_less_mono[of n 0 x] by simp ``` hoelzl@51483 ` 120` hoelzl@51483 ` 121` ```lemma real_root_ge_zero: "0 \ x \ 0 \ root n x" ``` hoelzl@51483 ` 122` ``` using real_root_gt_zero[of n x] by (cases "n = 0") (auto simp add: le_less) ``` huffman@20687 ` 123` huffman@22956 ` 124` ```lemma real_root_pow_pos: (* TODO: rename *) ``` huffman@22956 ` 125` ``` "\0 < n; 0 < x\ \ root n x ^ n = x" ``` hoelzl@51483 ` 126` ``` using sgn_power_root[of n x] real_root_gt_zero[of n x] by simp ``` huffman@20687 ` 127` huffman@22956 ` 128` ```lemma real_root_pow_pos2 [simp]: (* TODO: rename *) ``` huffman@22956 ` 129` ``` "\0 < n; 0 \ x\ \ root n x ^ n = x" ``` huffman@22956 ` 130` ```by (auto simp add: order_le_less real_root_pow_pos) ``` huffman@22956 ` 131` hoelzl@51483 ` 132` ```lemma sgn_root: "0 < n \ sgn (root n x) = sgn x" ``` haftmann@60867 ` 133` ``` by (auto split: split_root simp: sgn_real_def) ``` hoelzl@51483 ` 134` huffman@23046 ` 135` ```lemma odd_real_root_pow: "odd n \ root n x ^ n = x" ``` hoelzl@51483 ` 136` ``` using sgn_power_root[of n x] by (simp add: odd_pos sgn_real_def split: split_if_asm) ``` huffman@20687 ` 137` huffman@22956 ` 138` ```lemma real_root_power_cancel: "\0 < n; 0 \ x\ \ root n (x ^ n) = x" ``` hoelzl@51483 ` 139` ``` using root_sgn_power[of n x] by (auto simp add: le_less power_0_left) ``` huffman@20687 ` 140` huffman@23046 ` 141` ```lemma odd_real_root_power_cancel: "odd n \ root n (x ^ n) = x" ``` hoelzl@51483 ` 142` ``` using root_sgn_power[of n x] by (simp add: odd_pos sgn_real_def power_0_left split: split_if_asm) ``` huffman@23046 ` 143` hoelzl@51483 ` 144` ```lemma real_root_pos_unique: "\0 < n; 0 \ y; y ^ n = x\ \ root n x = y" ``` hoelzl@51483 ` 145` ``` using root_sgn_power[of n y] by (auto simp add: le_less power_0_left) ``` huffman@22956 ` 146` huffman@23046 ` 147` ```lemma odd_real_root_unique: ``` huffman@23046 ` 148` ``` "\odd n; y ^ n = x\ \ root n x = y" ``` huffman@23046 ` 149` ```by (erule subst, rule odd_real_root_power_cancel) ``` huffman@23046 ` 150` huffman@22956 ` 151` ```lemma real_root_one [simp]: "0 < n \ root n 1 = 1" ``` huffman@22956 ` 152` ```by (simp add: real_root_pos_unique) ``` huffman@22956 ` 153` wenzelm@60758 ` 154` ```text \Root function is strictly monotonic, hence injective\ ``` huffman@22956 ` 155` huffman@22956 ` 156` ```lemma real_root_le_mono: "\0 < n; x \ y\ \ root n x \ root n y" ``` hoelzl@51483 ` 157` ``` by (auto simp add: order_le_less real_root_less_mono) ``` huffman@22956 ` 158` huffman@22721 ` 159` ```lemma real_root_less_iff [simp]: ``` huffman@22956 ` 160` ``` "0 < n \ (root n x < root n y) = (x < y)" ``` huffman@22956 ` 161` ```apply (cases "x < y") ``` huffman@22956 ` 162` ```apply (simp add: real_root_less_mono) ``` huffman@22956 ` 163` ```apply (simp add: linorder_not_less real_root_le_mono) ``` huffman@22721 ` 164` ```done ``` huffman@22721 ` 165` huffman@22721 ` 166` ```lemma real_root_le_iff [simp]: ``` huffman@22956 ` 167` ``` "0 < n \ (root n x \ root n y) = (x \ y)" ``` huffman@22956 ` 168` ```apply (cases "x \ y") ``` huffman@22956 ` 169` ```apply (simp add: real_root_le_mono) ``` huffman@22956 ` 170` ```apply (simp add: linorder_not_le real_root_less_mono) ``` huffman@22721 ` 171` ```done ``` huffman@22721 ` 172` huffman@22721 ` 173` ```lemma real_root_eq_iff [simp]: ``` huffman@22956 ` 174` ``` "0 < n \ (root n x = root n y) = (x = y)" ``` huffman@22956 ` 175` ```by (simp add: order_eq_iff) ``` huffman@22956 ` 176` huffman@22956 ` 177` ```lemmas real_root_gt_0_iff [simp] = real_root_less_iff [where x=0, simplified] ``` huffman@22956 ` 178` ```lemmas real_root_lt_0_iff [simp] = real_root_less_iff [where y=0, simplified] ``` huffman@22956 ` 179` ```lemmas real_root_ge_0_iff [simp] = real_root_le_iff [where x=0, simplified] ``` huffman@22956 ` 180` ```lemmas real_root_le_0_iff [simp] = real_root_le_iff [where y=0, simplified] ``` huffman@22956 ` 181` ```lemmas real_root_eq_0_iff [simp] = real_root_eq_iff [where y=0, simplified] ``` huffman@22721 ` 182` huffman@23257 ` 183` ```lemma real_root_gt_1_iff [simp]: "0 < n \ (1 < root n y) = (1 < y)" ``` huffman@23257 ` 184` ```by (insert real_root_less_iff [where x=1], simp) ``` huffman@23257 ` 185` huffman@23257 ` 186` ```lemma real_root_lt_1_iff [simp]: "0 < n \ (root n x < 1) = (x < 1)" ``` huffman@23257 ` 187` ```by (insert real_root_less_iff [where y=1], simp) ``` huffman@23257 ` 188` huffman@23257 ` 189` ```lemma real_root_ge_1_iff [simp]: "0 < n \ (1 \ root n y) = (1 \ y)" ``` huffman@23257 ` 190` ```by (insert real_root_le_iff [where x=1], simp) ``` huffman@23257 ` 191` huffman@23257 ` 192` ```lemma real_root_le_1_iff [simp]: "0 < n \ (root n x \ 1) = (x \ 1)" ``` huffman@23257 ` 193` ```by (insert real_root_le_iff [where y=1], simp) ``` huffman@23257 ` 194` huffman@23257 ` 195` ```lemma real_root_eq_1_iff [simp]: "0 < n \ (root n x = 1) = (x = 1)" ``` huffman@23257 ` 196` ```by (insert real_root_eq_iff [where y=1], simp) ``` huffman@23257 ` 197` wenzelm@60758 ` 198` ```text \Roots of multiplication and division\ ``` hoelzl@51483 ` 199` hoelzl@51483 ` 200` ```lemma real_root_mult: "root n (x * y) = root n x * root n y" ``` hoelzl@51483 ` 201` ``` by (auto split: split_root elim!: sgn_power_injE simp: sgn_mult abs_mult power_mult_distrib) ``` hoelzl@51483 ` 202` hoelzl@51483 ` 203` ```lemma real_root_inverse: "root n (inverse x) = inverse (root n x)" ``` hoelzl@51483 ` 204` ``` by (auto split: split_root elim!: sgn_power_injE simp: inverse_sgn power_inverse) ``` hoelzl@51483 ` 205` hoelzl@51483 ` 206` ```lemma real_root_divide: "root n (x / y) = root n x / root n y" ``` hoelzl@51483 ` 207` ``` by (simp add: divide_inverse real_root_mult real_root_inverse) ``` hoelzl@51483 ` 208` hoelzl@51483 ` 209` ```lemma real_root_abs: "0 < n \ root n \x\ = \root n x\" ``` hoelzl@51483 ` 210` ``` by (simp add: abs_if real_root_minus) ``` hoelzl@51483 ` 211` hoelzl@51483 ` 212` ```lemma real_root_power: "0 < n \ root n (x ^ k) = root n x ^ k" ``` hoelzl@51483 ` 213` ``` by (induct k) (simp_all add: real_root_mult) ``` hoelzl@51483 ` 214` wenzelm@60758 ` 215` ```text \Roots of roots\ ``` huffman@23257 ` 216` huffman@23257 ` 217` ```lemma real_root_Suc_0 [simp]: "root (Suc 0) x = x" ``` huffman@23257 ` 218` ```by (simp add: odd_real_root_unique) ``` huffman@23257 ` 219` hoelzl@51483 ` 220` ```lemma real_root_mult_exp: "root (m * n) x = root m (root n x)" ``` hoelzl@51483 ` 221` ``` by (auto split: split_root elim!: sgn_power_injE ``` hoelzl@51483 ` 222` ``` simp: sgn_zero_iff sgn_mult power_mult[symmetric] abs_mult power_mult_distrib abs_sgn_eq) ``` huffman@23257 ` 223` hoelzl@51483 ` 224` ```lemma real_root_commute: "root m (root n x) = root n (root m x)" ``` haftmann@57512 ` 225` ``` by (simp add: real_root_mult_exp [symmetric] mult.commute) ``` huffman@23257 ` 226` wenzelm@60758 ` 227` ```text \Monotonicity in first argument\ ``` huffman@23257 ` 228` huffman@23257 ` 229` ```lemma real_root_strict_decreasing: ``` huffman@23257 ` 230` ``` "\0 < n; n < N; 1 < x\ \ root N x < root n x" ``` huffman@23257 ` 231` ```apply (subgoal_tac "root n (root N x) ^ n < root N (root n x) ^ N", simp) ``` huffman@23257 ` 232` ```apply (simp add: real_root_commute power_strict_increasing ``` huffman@23257 ` 233` ``` del: real_root_pow_pos2) ``` huffman@23257 ` 234` ```done ``` huffman@23257 ` 235` huffman@23257 ` 236` ```lemma real_root_strict_increasing: ``` huffman@23257 ` 237` ``` "\0 < n; n < N; 0 < x; x < 1\ \ root n x < root N x" ``` huffman@23257 ` 238` ```apply (subgoal_tac "root N (root n x) ^ N < root n (root N x) ^ n", simp) ``` huffman@23257 ` 239` ```apply (simp add: real_root_commute power_strict_decreasing ``` huffman@23257 ` 240` ``` del: real_root_pow_pos2) ``` huffman@23257 ` 241` ```done ``` huffman@23257 ` 242` huffman@23257 ` 243` ```lemma real_root_decreasing: ``` huffman@23257 ` 244` ``` "\0 < n; n < N; 1 \ x\ \ root N x \ root n x" ``` huffman@23257 ` 245` ```by (auto simp add: order_le_less real_root_strict_decreasing) ``` huffman@23257 ` 246` huffman@23257 ` 247` ```lemma real_root_increasing: ``` huffman@23257 ` 248` ``` "\0 < n; n < N; 0 \ x; x \ 1\ \ root n x \ root N x" ``` huffman@23257 ` 249` ```by (auto simp add: order_le_less real_root_strict_increasing) ``` huffman@23257 ` 250` wenzelm@60758 ` 251` ```text \Continuity and derivatives\ ``` huffman@23042 ` 252` hoelzl@51483 ` 253` ```lemma isCont_real_root: "isCont (root n) x" ``` hoelzl@51483 ` 254` ```proof cases ``` hoelzl@51483 ` 255` ``` assume n: "0 < n" ``` hoelzl@51483 ` 256` ``` let ?f = "\y::real. sgn y * \y\^n" ``` hoelzl@51483 ` 257` ``` have "continuous_on ({0..} \ {.. 0}) (\x. if 0 < x then x ^ n else - ((-x) ^ n) :: real)" ``` hoelzl@56371 ` 258` ``` using n by (intro continuous_on_If continuous_intros) auto ``` hoelzl@51483 ` 259` ``` then have "continuous_on UNIV ?f" ``` hoelzl@51483 ` 260` ``` by (rule continuous_on_cong[THEN iffD1, rotated 2]) (auto simp: not_less real_sgn_neg le_less n) ``` hoelzl@51483 ` 261` ``` then have [simp]: "\x. isCont ?f x" ``` hoelzl@51483 ` 262` ``` by (simp add: continuous_on_eq_continuous_at) ``` huffman@23042 ` 263` hoelzl@51483 ` 264` ``` have "isCont (root n) (?f (root n x))" ``` hoelzl@51483 ` 265` ``` by (rule isCont_inverse_function [where f="?f" and d=1]) (auto simp: root_sgn_power n) ``` hoelzl@51483 ` 266` ``` then show ?thesis ``` hoelzl@51483 ` 267` ``` by (simp add: sgn_power_root n) ``` hoelzl@51483 ` 268` ```qed (simp add: root_def[abs_def]) ``` huffman@23042 ` 269` hoelzl@51478 ` 270` ```lemma tendsto_real_root[tendsto_intros]: ``` hoelzl@51483 ` 271` ``` "(f ---> x) F \ ((\x. root n (f x)) ---> root n x) F" ``` hoelzl@51483 ` 272` ``` using isCont_tendsto_compose[OF isCont_real_root, of f x F] . ``` hoelzl@51478 ` 273` hoelzl@51478 ` 274` ```lemma continuous_real_root[continuous_intros]: ``` hoelzl@51483 ` 275` ``` "continuous F f \ continuous F (\x. root n (f x))" ``` hoelzl@51478 ` 276` ``` unfolding continuous_def by (rule tendsto_real_root) ``` lp15@61609 ` 277` hoelzl@56371 ` 278` ```lemma continuous_on_real_root[continuous_intros]: ``` hoelzl@51483 ` 279` ``` "continuous_on s f \ continuous_on s (\x. root n (f x))" ``` hoelzl@51478 ` 280` ``` unfolding continuous_on_def by (auto intro: tendsto_real_root) ``` hoelzl@51478 ` 281` huffman@23042 ` 282` ```lemma DERIV_real_root: ``` huffman@23042 ` 283` ``` assumes n: "0 < n" ``` huffman@23042 ` 284` ``` assumes x: "0 < x" ``` huffman@23042 ` 285` ``` shows "DERIV (root n) x :> inverse (real n * root n x ^ (n - Suc 0))" ``` huffman@23042 ` 286` ```proof (rule DERIV_inverse_function) ``` huffman@23044 ` 287` ``` show "0 < x" using x . ``` huffman@23044 ` 288` ``` show "x < x + 1" by simp ``` huffman@23044 ` 289` ``` show "\y. 0 < y \ y < x + 1 \ root n y ^ n = y" ``` huffman@23042 ` 290` ``` using n by simp ``` huffman@23042 ` 291` ``` show "DERIV (\x. x ^ n) (root n x) :> real n * root n x ^ (n - Suc 0)" ``` huffman@23042 ` 292` ``` by (rule DERIV_pow) ``` huffman@23042 ` 293` ``` show "real n * root n x ^ (n - Suc 0) \ 0" ``` huffman@23042 ` 294` ``` using n x by simp ``` hoelzl@51483 ` 295` ```qed (rule isCont_real_root) ``` huffman@23042 ` 296` huffman@23046 ` 297` ```lemma DERIV_odd_real_root: ``` huffman@23046 ` 298` ``` assumes n: "odd n" ``` huffman@23046 ` 299` ``` assumes x: "x \ 0" ``` huffman@23046 ` 300` ``` shows "DERIV (root n) x :> inverse (real n * root n x ^ (n - Suc 0))" ``` huffman@23046 ` 301` ```proof (rule DERIV_inverse_function) ``` huffman@23046 ` 302` ``` show "x - 1 < x" by simp ``` huffman@23046 ` 303` ``` show "x < x + 1" by simp ``` huffman@23046 ` 304` ``` show "\y. x - 1 < y \ y < x + 1 \ root n y ^ n = y" ``` huffman@23046 ` 305` ``` using n by (simp add: odd_real_root_pow) ``` huffman@23046 ` 306` ``` show "DERIV (\x. x ^ n) (root n x) :> real n * root n x ^ (n - Suc 0)" ``` huffman@23046 ` 307` ``` by (rule DERIV_pow) ``` huffman@23046 ` 308` ``` show "real n * root n x ^ (n - Suc 0) \ 0" ``` huffman@23046 ` 309` ``` using odd_pos [OF n] x by simp ``` hoelzl@51483 ` 310` ```qed (rule isCont_real_root) ``` huffman@23046 ` 311` hoelzl@31880 ` 312` ```lemma DERIV_even_real_root: ``` hoelzl@31880 ` 313` ``` assumes n: "0 < n" and "even n" ``` hoelzl@31880 ` 314` ``` assumes x: "x < 0" ``` hoelzl@31880 ` 315` ``` shows "DERIV (root n) x :> inverse (- real n * root n x ^ (n - Suc 0))" ``` hoelzl@31880 ` 316` ```proof (rule DERIV_inverse_function) ``` hoelzl@31880 ` 317` ``` show "x - 1 < x" by simp ``` hoelzl@31880 ` 318` ``` show "x < 0" using x . ``` hoelzl@31880 ` 319` ```next ``` hoelzl@31880 ` 320` ``` show "\y. x - 1 < y \ y < 0 \ - (root n y ^ n) = y" ``` hoelzl@31880 ` 321` ``` proof (rule allI, rule impI, erule conjE) ``` hoelzl@31880 ` 322` ``` fix y assume "x - 1 < y" and "y < 0" ``` wenzelm@60758 ` 323` ``` hence "root n (-y) ^ n = -y" using \0 < n\ by simp ``` wenzelm@60758 ` 324` ``` with real_root_minus and \even n\ ``` hoelzl@31880 ` 325` ``` show "- (root n y ^ n) = y" by simp ``` hoelzl@31880 ` 326` ``` qed ``` hoelzl@31880 ` 327` ```next ``` hoelzl@31880 ` 328` ``` show "DERIV (\x. - (x ^ n)) (root n x) :> - real n * root n x ^ (n - Suc 0)" ``` lp15@61609 ` 329` ``` by (auto intro!: derivative_eq_intros) ``` hoelzl@31880 ` 330` ``` show "- real n * root n x ^ (n - Suc 0) \ 0" ``` hoelzl@31880 ` 331` ``` using n x by simp ``` hoelzl@51483 ` 332` ```qed (rule isCont_real_root) ``` hoelzl@31880 ` 333` hoelzl@31880 ` 334` ```lemma DERIV_real_root_generic: ``` hoelzl@31880 ` 335` ``` assumes "0 < n" and "x \ 0" ``` wenzelm@49753 ` 336` ``` and "\ even n ; 0 < x \ \ D = inverse (real n * root n x ^ (n - Suc 0))" ``` wenzelm@49753 ` 337` ``` and "\ even n ; x < 0 \ \ D = - inverse (real n * root n x ^ (n - Suc 0))" ``` wenzelm@49753 ` 338` ``` and "odd n \ D = inverse (real n * root n x ^ (n - Suc 0))" ``` hoelzl@31880 ` 339` ``` shows "DERIV (root n) x :> D" ``` hoelzl@31880 ` 340` ```using assms by (cases "even n", cases "0 < x", ``` hoelzl@31880 ` 341` ``` auto intro: DERIV_real_root[THEN DERIV_cong] ``` hoelzl@31880 ` 342` ``` DERIV_odd_real_root[THEN DERIV_cong] ``` hoelzl@31880 ` 343` ``` DERIV_even_real_root[THEN DERIV_cong]) ``` hoelzl@31880 ` 344` wenzelm@60758 ` 345` ```subsection \Square Root\ ``` huffman@20687 ` 346` hoelzl@51483 ` 347` ```definition sqrt :: "real \ real" where ``` huffman@22956 ` 348` ``` "sqrt = root 2" ``` huffman@20687 ` 349` huffman@22956 ` 350` ```lemma pos2: "0 < (2::nat)" by simp ``` huffman@22956 ` 351` wenzelm@53015 ` 352` ```lemma real_sqrt_unique: "\y\<^sup>2 = x; 0 \ y\ \ sqrt x = y" ``` huffman@22956 ` 353` ```unfolding sqrt_def by (rule real_root_pos_unique [OF pos2]) ``` huffman@20687 ` 354` wenzelm@53015 ` 355` ```lemma real_sqrt_abs [simp]: "sqrt (x\<^sup>2) = \x\" ``` huffman@22956 ` 356` ```apply (rule real_sqrt_unique) ``` huffman@22956 ` 357` ```apply (rule power2_abs) ``` huffman@22956 ` 358` ```apply (rule abs_ge_zero) ``` huffman@22956 ` 359` ```done ``` huffman@20687 ` 360` wenzelm@53015 ` 361` ```lemma real_sqrt_pow2 [simp]: "0 \ x \ (sqrt x)\<^sup>2 = x" ``` huffman@22956 ` 362` ```unfolding sqrt_def by (rule real_root_pow_pos2 [OF pos2]) ``` huffman@22856 ` 363` wenzelm@53015 ` 364` ```lemma real_sqrt_pow2_iff [simp]: "((sqrt x)\<^sup>2 = x) = (0 \ x)" ``` huffman@22856 ` 365` ```apply (rule iffI) ``` huffman@22856 ` 366` ```apply (erule subst) ``` huffman@22856 ` 367` ```apply (rule zero_le_power2) ``` huffman@22856 ` 368` ```apply (erule real_sqrt_pow2) ``` huffman@20687 ` 369` ```done ``` huffman@20687 ` 370` huffman@22956 ` 371` ```lemma real_sqrt_zero [simp]: "sqrt 0 = 0" ``` huffman@22956 ` 372` ```unfolding sqrt_def by (rule real_root_zero) ``` huffman@22956 ` 373` huffman@22956 ` 374` ```lemma real_sqrt_one [simp]: "sqrt 1 = 1" ``` huffman@22956 ` 375` ```unfolding sqrt_def by (rule real_root_one [OF pos2]) ``` huffman@22956 ` 376` hoelzl@56889 ` 377` ```lemma real_sqrt_four [simp]: "sqrt 4 = 2" ``` hoelzl@56889 ` 378` ``` using real_sqrt_abs[of 2] by simp ``` hoelzl@56889 ` 379` huffman@22956 ` 380` ```lemma real_sqrt_minus: "sqrt (- x) = - sqrt x" ``` hoelzl@51483 ` 381` ```unfolding sqrt_def by (rule real_root_minus) ``` huffman@22956 ` 382` huffman@22956 ` 383` ```lemma real_sqrt_mult: "sqrt (x * y) = sqrt x * sqrt y" ``` hoelzl@51483 ` 384` ```unfolding sqrt_def by (rule real_root_mult) ``` huffman@22956 ` 385` hoelzl@56889 ` 386` ```lemma real_sqrt_mult_self[simp]: "sqrt a * sqrt a = \a\" ``` hoelzl@56889 ` 387` ``` using real_sqrt_abs[of a] unfolding power2_eq_square real_sqrt_mult . ``` hoelzl@56889 ` 388` huffman@22956 ` 389` ```lemma real_sqrt_inverse: "sqrt (inverse x) = inverse (sqrt x)" ``` hoelzl@51483 ` 390` ```unfolding sqrt_def by (rule real_root_inverse) ``` huffman@22956 ` 391` huffman@22956 ` 392` ```lemma real_sqrt_divide: "sqrt (x / y) = sqrt x / sqrt y" ``` hoelzl@51483 ` 393` ```unfolding sqrt_def by (rule real_root_divide) ``` huffman@22956 ` 394` huffman@22956 ` 395` ```lemma real_sqrt_power: "sqrt (x ^ k) = sqrt x ^ k" ``` huffman@22956 ` 396` ```unfolding sqrt_def by (rule real_root_power [OF pos2]) ``` huffman@22956 ` 397` huffman@22956 ` 398` ```lemma real_sqrt_gt_zero: "0 < x \ 0 < sqrt x" ``` huffman@22956 ` 399` ```unfolding sqrt_def by (rule real_root_gt_zero [OF pos2]) ``` huffman@22956 ` 400` huffman@22956 ` 401` ```lemma real_sqrt_ge_zero: "0 \ x \ 0 \ sqrt x" ``` hoelzl@51483 ` 402` ```unfolding sqrt_def by (rule real_root_ge_zero) ``` huffman@20687 ` 403` huffman@22956 ` 404` ```lemma real_sqrt_less_mono: "x < y \ sqrt x < sqrt y" ``` huffman@22956 ` 405` ```unfolding sqrt_def by (rule real_root_less_mono [OF pos2]) ``` huffman@22956 ` 406` huffman@22956 ` 407` ```lemma real_sqrt_le_mono: "x \ y \ sqrt x \ sqrt y" ``` huffman@22956 ` 408` ```unfolding sqrt_def by (rule real_root_le_mono [OF pos2]) ``` huffman@22956 ` 409` huffman@22956 ` 410` ```lemma real_sqrt_less_iff [simp]: "(sqrt x < sqrt y) = (x < y)" ``` huffman@22956 ` 411` ```unfolding sqrt_def by (rule real_root_less_iff [OF pos2]) ``` huffman@22956 ` 412` huffman@22956 ` 413` ```lemma real_sqrt_le_iff [simp]: "(sqrt x \ sqrt y) = (x \ y)" ``` huffman@22956 ` 414` ```unfolding sqrt_def by (rule real_root_le_iff [OF pos2]) ``` huffman@22956 ` 415` huffman@22956 ` 416` ```lemma real_sqrt_eq_iff [simp]: "(sqrt x = sqrt y) = (x = y)" ``` huffman@22956 ` 417` ```unfolding sqrt_def by (rule real_root_eq_iff [OF pos2]) ``` huffman@22956 ` 418` hoelzl@54413 ` 419` ```lemma real_le_lsqrt: "0 \ x \ 0 \ y \ x \ y\<^sup>2 \ sqrt x \ y" ``` hoelzl@54413 ` 420` ``` using real_sqrt_le_iff[of x "y\<^sup>2"] by simp ``` hoelzl@54413 ` 421` hoelzl@54413 ` 422` ```lemma real_le_rsqrt: "x\<^sup>2 \ y \ x \ sqrt y" ``` hoelzl@54413 ` 423` ``` using real_sqrt_le_mono[of "x\<^sup>2" y] by simp ``` hoelzl@54413 ` 424` hoelzl@54413 ` 425` ```lemma real_less_rsqrt: "x\<^sup>2 < y \ x < sqrt y" ``` hoelzl@54413 ` 426` ``` using real_sqrt_less_mono[of "x\<^sup>2" y] by simp ``` hoelzl@54413 ` 427` hoelzl@54413 ` 428` ```lemma sqrt_even_pow2: ``` hoelzl@54413 ` 429` ``` assumes n: "even n" ``` hoelzl@54413 ` 430` ``` shows "sqrt (2 ^ n) = 2 ^ (n div 2)" ``` hoelzl@54413 ` 431` ```proof - ``` haftmann@58709 ` 432` ``` from n obtain m where m: "n = 2 * m" .. ``` hoelzl@54413 ` 433` ``` from m have "sqrt (2 ^ n) = sqrt ((2 ^ m)\<^sup>2)" ``` haftmann@57512 ` 434` ``` by (simp only: power_mult[symmetric] mult.commute) ``` hoelzl@54413 ` 435` ``` then show ?thesis ``` hoelzl@54413 ` 436` ``` using m by simp ``` hoelzl@54413 ` 437` ```qed ``` hoelzl@54413 ` 438` huffman@53594 ` 439` ```lemmas real_sqrt_gt_0_iff [simp] = real_sqrt_less_iff [where x=0, unfolded real_sqrt_zero] ``` huffman@53594 ` 440` ```lemmas real_sqrt_lt_0_iff [simp] = real_sqrt_less_iff [where y=0, unfolded real_sqrt_zero] ``` huffman@53594 ` 441` ```lemmas real_sqrt_ge_0_iff [simp] = real_sqrt_le_iff [where x=0, unfolded real_sqrt_zero] ``` huffman@53594 ` 442` ```lemmas real_sqrt_le_0_iff [simp] = real_sqrt_le_iff [where y=0, unfolded real_sqrt_zero] ``` huffman@53594 ` 443` ```lemmas real_sqrt_eq_0_iff [simp] = real_sqrt_eq_iff [where y=0, unfolded real_sqrt_zero] ``` huffman@22956 ` 444` huffman@53594 ` 445` ```lemmas real_sqrt_gt_1_iff [simp] = real_sqrt_less_iff [where x=1, unfolded real_sqrt_one] ``` huffman@53594 ` 446` ```lemmas real_sqrt_lt_1_iff [simp] = real_sqrt_less_iff [where y=1, unfolded real_sqrt_one] ``` huffman@53594 ` 447` ```lemmas real_sqrt_ge_1_iff [simp] = real_sqrt_le_iff [where x=1, unfolded real_sqrt_one] ``` huffman@53594 ` 448` ```lemmas real_sqrt_le_1_iff [simp] = real_sqrt_le_iff [where y=1, unfolded real_sqrt_one] ``` huffman@53594 ` 449` ```lemmas real_sqrt_eq_1_iff [simp] = real_sqrt_eq_iff [where y=1, unfolded real_sqrt_one] ``` huffman@20687 ` 450` lp15@60615 ` 451` ```lemma sqrt_add_le_add_sqrt: ``` lp15@60615 ` 452` ``` assumes "0 \ x" "0 \ y" ``` lp15@60615 ` 453` ``` shows "sqrt (x + y) \ sqrt x + sqrt y" ``` lp15@60615 ` 454` ```by (rule power2_le_imp_le) (simp_all add: power2_sum assms) ``` lp15@60615 ` 455` huffman@23042 ` 456` ```lemma isCont_real_sqrt: "isCont sqrt x" ``` hoelzl@51483 ` 457` ```unfolding sqrt_def by (rule isCont_real_root) ``` huffman@23042 ` 458` hoelzl@51478 ` 459` ```lemma tendsto_real_sqrt[tendsto_intros]: ``` hoelzl@51478 ` 460` ``` "(f ---> x) F \ ((\x. sqrt (f x)) ---> sqrt x) F" ``` hoelzl@51483 ` 461` ``` unfolding sqrt_def by (rule tendsto_real_root) ``` hoelzl@51478 ` 462` hoelzl@51478 ` 463` ```lemma continuous_real_sqrt[continuous_intros]: ``` hoelzl@51478 ` 464` ``` "continuous F f \ continuous F (\x. sqrt (f x))" ``` hoelzl@51483 ` 465` ``` unfolding sqrt_def by (rule continuous_real_root) ``` lp15@61609 ` 466` hoelzl@56371 ` 467` ```lemma continuous_on_real_sqrt[continuous_intros]: ``` hoelzl@57155 ` 468` ``` "continuous_on s f \ continuous_on s (\x. sqrt (f x))" ``` hoelzl@51483 ` 469` ``` unfolding sqrt_def by (rule continuous_on_real_root) ``` hoelzl@51478 ` 470` hoelzl@31880 ` 471` ```lemma DERIV_real_sqrt_generic: ``` hoelzl@31880 ` 472` ``` assumes "x \ 0" ``` hoelzl@31880 ` 473` ``` assumes "x > 0 \ D = inverse (sqrt x) / 2" ``` hoelzl@31880 ` 474` ``` assumes "x < 0 \ D = - inverse (sqrt x) / 2" ``` hoelzl@31880 ` 475` ``` shows "DERIV sqrt x :> D" ``` hoelzl@31880 ` 476` ``` using assms unfolding sqrt_def ``` hoelzl@31880 ` 477` ``` by (auto intro!: DERIV_real_root_generic) ``` hoelzl@31880 ` 478` huffman@23042 ` 479` ```lemma DERIV_real_sqrt: ``` huffman@23042 ` 480` ``` "0 < x \ DERIV sqrt x :> inverse (sqrt x) / 2" ``` hoelzl@31880 ` 481` ``` using DERIV_real_sqrt_generic by simp ``` hoelzl@31880 ` 482` hoelzl@31880 ` 483` ```declare ``` hoelzl@56381 ` 484` ``` DERIV_real_sqrt_generic[THEN DERIV_chain2, derivative_intros] ``` hoelzl@56381 ` 485` ``` DERIV_real_root_generic[THEN DERIV_chain2, derivative_intros] ``` huffman@23042 ` 486` huffman@20687 ` 487` ```lemma not_real_square_gt_zero [simp]: "(~ (0::real) < x*x) = (x = 0)" ``` huffman@20687 ` 488` ```apply auto ``` huffman@20687 ` 489` ```apply (cut_tac x = x and y = 0 in linorder_less_linear) ``` huffman@20687 ` 490` ```apply (simp add: zero_less_mult_iff) ``` huffman@20687 ` 491` ```done ``` huffman@20687 ` 492` huffman@20687 ` 493` ```lemma real_sqrt_abs2 [simp]: "sqrt(x*x) = \x\" ``` huffman@22856 ` 494` ```apply (subst power2_eq_square [symmetric]) ``` huffman@20687 ` 495` ```apply (rule real_sqrt_abs) ``` huffman@20687 ` 496` ```done ``` huffman@20687 ` 497` wenzelm@53076 ` 498` ```lemma real_inv_sqrt_pow2: "0 < x ==> (inverse (sqrt x))\<^sup>2 = inverse x" ``` haftmann@60867 ` 499` ```by (simp add: power_inverse) ``` huffman@20687 ` 500` huffman@20687 ` 501` ```lemma real_sqrt_eq_zero_cancel: "[| 0 \ x; sqrt(x) = 0|] ==> x = 0" ``` huffman@22956 ` 502` ```by simp ``` huffman@20687 ` 503` huffman@20687 ` 504` ```lemma real_sqrt_ge_one: "1 \ x ==> 1 \ sqrt x" ``` huffman@22956 ` 505` ```by simp ``` huffman@20687 ` 506` huffman@22443 ` 507` ```lemma sqrt_divide_self_eq: ``` huffman@22443 ` 508` ``` assumes nneg: "0 \ x" ``` huffman@22443 ` 509` ``` shows "sqrt x / x = inverse (sqrt x)" ``` huffman@22443 ` 510` ```proof cases ``` huffman@22443 ` 511` ``` assume "x=0" thus ?thesis by simp ``` huffman@22443 ` 512` ```next ``` lp15@61609 ` 513` ``` assume nz: "x\0" ``` huffman@22443 ` 514` ``` hence pos: "0 0" by (simp add: divide_inverse nneg nz) ``` huffman@22443 ` 518` ``` show "inverse (sqrt x) / (sqrt x / x) = 1" ``` lp15@61609 ` 519` ``` by (simp add: divide_inverse mult.assoc [symmetric] ``` lp15@61609 ` 520` ``` power2_eq_square [symmetric] real_inv_sqrt_pow2 pos nz) ``` huffman@22443 ` 521` ``` qed ``` huffman@22443 ` 522` ```qed ``` huffman@22443 ` 523` hoelzl@54413 ` 524` ```lemma real_div_sqrt: "0 \ x \ x / sqrt x = sqrt x" ``` hoelzl@54413 ` 525` ``` apply (cases "x = 0") ``` hoelzl@54413 ` 526` ``` apply simp_all ``` hoelzl@54413 ` 527` ``` using sqrt_divide_self_eq[of x] ``` haftmann@60867 ` 528` ``` apply (simp add: field_simps) ``` hoelzl@54413 ` 529` ``` done ``` hoelzl@54413 ` 530` huffman@22721 ` 531` ```lemma real_divide_square_eq [simp]: "(((r::real) * a) / (r * r)) = a / r" ``` huffman@22721 ` 532` ```apply (simp add: divide_inverse) ``` huffman@22721 ` 533` ```apply (case_tac "r=0") ``` haftmann@57514 ` 534` ```apply (auto simp add: ac_simps) ``` huffman@22721 ` 535` ```done ``` huffman@22721 ` 536` huffman@23049 ` 537` ```lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u" ``` huffman@35216 ` 538` ```by (simp add: divide_less_eq) ``` huffman@23049 ` 539` lp15@61609 ` 540` ```lemma four_x_squared: ``` huffman@23049 ` 541` ``` fixes x::real ``` wenzelm@53015 ` 542` ``` shows "4 * x\<^sup>2 = (2 * x)\<^sup>2" ``` huffman@23049 ` 543` ```by (simp add: power2_eq_square) ``` huffman@23049 ` 544` hoelzl@57275 ` 545` ```lemma sqrt_at_top: "LIM x at_top. sqrt x :: real :> at_top" ``` hoelzl@57275 ` 546` ``` by (rule filterlim_at_top_at_top[where Q="\x. True" and P="\x. 0 < x" and g="power2"]) ``` hoelzl@57275 ` 547` ``` (auto intro: eventually_gt_at_top) ``` hoelzl@57275 ` 548` wenzelm@60758 ` 549` ```subsection \Square Root of Sum of Squares\ ``` huffman@22856 ` 550` lp15@61609 ` 551` ```lemma sum_squares_bound: ``` lp15@55967 ` 552` ``` fixes x:: "'a::linordered_field" ``` lp15@55967 ` 553` ``` shows "2*x*y \ x^2 + y^2" ``` lp15@55967 ` 554` ```proof - ``` lp15@55967 ` 555` ``` have "(x-y)^2 = x*x - 2*x*y + y*y" ``` lp15@55967 ` 556` ``` by algebra ``` lp15@55967 ` 557` ``` then have "0 \ x^2 - 2*x*y + y^2" ``` lp15@55967 ` 558` ``` by (metis sum_power2_ge_zero zero_le_double_add_iff_zero_le_single_add power2_eq_square) ``` lp15@55967 ` 559` ``` then show ?thesis ``` lp15@55967 ` 560` ``` by arith ``` lp15@55967 ` 561` ```qed ``` huffman@22856 ` 562` lp15@61609 ` 563` ```lemma arith_geo_mean: ``` lp15@55967 ` 564` ``` fixes u:: "'a::linordered_field" assumes "u\<^sup>2 = x*y" "x\0" "y\0" shows "u \ (x + y)/2" ``` lp15@55967 ` 565` ``` apply (rule power2_le_imp_le) ``` lp15@55967 ` 566` ``` using sum_squares_bound assms ``` lp15@55967 ` 567` ``` apply (auto simp: zero_le_mult_iff) ``` lp15@55967 ` 568` ``` by (auto simp: algebra_simps power2_eq_square) ``` lp15@55967 ` 569` lp15@61609 ` 570` ```lemma arith_geo_mean_sqrt: ``` lp15@55967 ` 571` ``` fixes x::real assumes "x\0" "y\0" shows "sqrt(x*y) \ (x + y)/2" ``` lp15@55967 ` 572` ``` apply (rule arith_geo_mean) ``` lp15@55967 ` 573` ``` using assms ``` lp15@55967 ` 574` ``` apply (auto simp: zero_le_mult_iff) ``` lp15@55967 ` 575` ``` done ``` huffman@23049 ` 576` huffman@22856 ` 577` ```lemma real_sqrt_sum_squares_mult_ge_zero [simp]: ``` wenzelm@53015 ` 578` ``` "0 \ sqrt ((x\<^sup>2 + y\<^sup>2)*(xa\<^sup>2 + ya\<^sup>2))" ``` lp15@55967 ` 579` ``` by (metis real_sqrt_ge_0_iff split_mult_pos_le sum_power2_ge_zero) ``` huffman@22856 ` 580` huffman@22856 ` 581` ```lemma real_sqrt_sum_squares_mult_squared_eq [simp]: ``` wenzelm@53076 ` 582` ``` "(sqrt ((x\<^sup>2 + y\<^sup>2) * (xa\<^sup>2 + ya\<^sup>2)))\<^sup>2 = (x\<^sup>2 + y\<^sup>2) * (xa\<^sup>2 + ya\<^sup>2)" ``` huffman@44320 ` 583` ``` by (simp add: zero_le_mult_iff) ``` huffman@22856 ` 584` wenzelm@53015 ` 585` ```lemma real_sqrt_sum_squares_eq_cancel: "sqrt (x\<^sup>2 + y\<^sup>2) = x \ y = 0" ``` wenzelm@53015 ` 586` ```by (drule_tac f = "%x. x\<^sup>2" in arg_cong, simp) ``` huffman@23049 ` 587` wenzelm@53015 ` 588` ```lemma real_sqrt_sum_squares_eq_cancel2: "sqrt (x\<^sup>2 + y\<^sup>2) = y \ x = 0" ``` wenzelm@53015 ` 589` ```by (drule_tac f = "%x. x\<^sup>2" in arg_cong, simp) ``` huffman@23049 ` 590` wenzelm@53015 ` 591` ```lemma real_sqrt_sum_squares_ge1 [simp]: "x \ sqrt (x\<^sup>2 + y\<^sup>2)" ``` huffman@22856 ` 592` ```by (rule power2_le_imp_le, simp_all) ``` huffman@22856 ` 593` wenzelm@53015 ` 594` ```lemma real_sqrt_sum_squares_ge2 [simp]: "y \ sqrt (x\<^sup>2 + y\<^sup>2)" ``` huffman@23049 ` 595` ```by (rule power2_le_imp_le, simp_all) ``` huffman@23049 ` 596` wenzelm@53015 ` 597` ```lemma real_sqrt_ge_abs1 [simp]: "\x\ \ sqrt (x\<^sup>2 + y\<^sup>2)" ``` huffman@22856 ` 598` ```by (rule power2_le_imp_le, simp_all) ``` huffman@22856 ` 599` wenzelm@53015 ` 600` ```lemma real_sqrt_ge_abs2 [simp]: "\y\ \ sqrt (x\<^sup>2 + y\<^sup>2)" ``` huffman@23049 ` 601` ```by (rule power2_le_imp_le, simp_all) ``` huffman@23049 ` 602` huffman@23049 ` 603` ```lemma le_real_sqrt_sumsq [simp]: "x \ sqrt (x * x + y * y)" ``` huffman@23049 ` 604` ```by (simp add: power2_eq_square [symmetric]) ``` huffman@23049 ` 605` huffman@22858 ` 606` ```lemma real_sqrt_sum_squares_triangle_ineq: ``` wenzelm@53015 ` 607` ``` "sqrt ((a + c)\<^sup>2 + (b + d)\<^sup>2) \ sqrt (a\<^sup>2 + b\<^sup>2) + sqrt (c\<^sup>2 + d\<^sup>2)" ``` huffman@22858 ` 608` ```apply (rule power2_le_imp_le, simp) ``` huffman@22858 ` 609` ```apply (simp add: power2_sum) ``` haftmann@57512 ` 610` ```apply (simp only: mult.assoc distrib_left [symmetric]) ``` huffman@22858 ` 611` ```apply (rule mult_left_mono) ``` huffman@22858 ` 612` ```apply (rule power2_le_imp_le) ``` huffman@22858 ` 613` ```apply (simp add: power2_sum power_mult_distrib) ``` nipkow@23477 ` 614` ```apply (simp add: ring_distribs) ``` wenzelm@53015 ` 615` ```apply (subgoal_tac "0 \ b\<^sup>2 * c\<^sup>2 + a\<^sup>2 * d\<^sup>2 - 2 * (a * c) * (b * d)", simp) ``` wenzelm@53015 ` 616` ```apply (rule_tac b="(a * d - b * c)\<^sup>2" in ord_le_eq_trans) ``` huffman@22858 ` 617` ```apply (rule zero_le_power2) ``` huffman@22858 ` 618` ```apply (simp add: power2_diff power_mult_distrib) ``` nipkow@56536 ` 619` ```apply (simp) ``` huffman@22858 ` 620` ```apply simp ``` huffman@22858 ` 621` ```apply (simp add: add_increasing) ``` huffman@22858 ` 622` ```done ``` huffman@22858 ` 623` huffman@23122 ` 624` ```lemma real_sqrt_sum_squares_less: ``` wenzelm@53015 ` 625` ``` "\\x\ < u / sqrt 2; \y\ < u / sqrt 2\ \ sqrt (x\<^sup>2 + y\<^sup>2) < u" ``` huffman@23122 ` 626` ```apply (rule power2_less_imp_less, simp) ``` huffman@23122 ` 627` ```apply (drule power_strict_mono [OF _ abs_ge_zero pos2]) ``` huffman@23122 ` 628` ```apply (drule power_strict_mono [OF _ abs_ge_zero pos2]) ``` huffman@23122 ` 629` ```apply (simp add: power_divide) ``` huffman@23122 ` 630` ```apply (drule order_le_less_trans [OF abs_ge_zero]) ``` huffman@23122 ` 631` ```apply (simp add: zero_less_divide_iff) ``` huffman@23122 ` 632` ```done ``` huffman@23122 ` 633` lp15@59741 ` 634` ```lemma sqrt2_less_2: "sqrt 2 < (2::real)" ``` lp15@59741 ` 635` ``` by (metis not_less not_less_iff_gr_or_eq numeral_less_iff real_sqrt_four real_sqrt_le_iff semiring_norm(75) semiring_norm(78) semiring_norm(85)) ``` lp15@59741 ` 636` lp15@59741 ` 637` wenzelm@60758 ` 638` ```text\Needed for the infinitely close relation over the nonstandard ``` wenzelm@60758 ` 639` ``` complex numbers\ ``` huffman@23049 ` 640` ```lemma lemma_sqrt_hcomplex_capprox: ``` wenzelm@53015 ` 641` ``` "[| 0 < u; x < u/2; y < u/2; 0 \ x; 0 \ y |] ==> sqrt (x\<^sup>2 + y\<^sup>2) < u" ``` lp15@59741 ` 642` ``` apply (rule real_sqrt_sum_squares_less) ``` lp15@59741 ` 643` ``` apply (auto simp add: abs_if field_simps) ``` lp15@59741 ` 644` ``` apply (rule le_less_trans [where y = "x*2"]) ``` lp15@59741 ` 645` ``` using less_eq_real_def sqrt2_less_2 apply force ``` lp15@59741 ` 646` ``` apply assumption ``` lp15@59741 ` 647` ``` apply (rule le_less_trans [where y = "y*2"]) ``` lp15@61609 ` 648` ``` using less_eq_real_def sqrt2_less_2 mult_le_cancel_left ``` lp15@61609 ` 649` ``` apply auto ``` lp15@59741 ` 650` ``` done ``` lp15@61609 ` 651` lp15@60141 ` 652` ```lemma LIMSEQ_root: "(\n. root n n) ----> 1" ``` lp15@60141 ` 653` ```proof - ``` lp15@60141 ` 654` ``` def x \ "\n. root n n - 1" ``` lp15@60141 ` 655` ``` have "x ----> sqrt 0" ``` lp15@60141 ` 656` ``` proof (rule tendsto_sandwich[OF _ _ tendsto_const]) ``` lp15@60141 ` 657` ``` show "(\x. sqrt (2 / x)) ----> sqrt 0" ``` lp15@60141 ` 658` ``` by (intro tendsto_intros tendsto_divide_0[OF tendsto_const] filterlim_mono[OF filterlim_real_sequentially]) ``` lp15@60141 ` 659` ``` (simp_all add: at_infinity_eq_at_top_bot) ``` lp15@60141 ` 660` ``` { fix n :: nat assume "2 < n" ``` lp15@60141 ` 661` ``` have "1 + (real (n - 1) * n) / 2 * x n^2 = 1 + of_nat (n choose 2) * x n^2" ``` wenzelm@60758 ` 662` ``` using \2 < n\ unfolding gbinomial_def binomial_gbinomial ``` lp15@61609 ` 663` ``` by (simp add: atLeast0AtMost atMost_Suc field_simps of_nat_diff numeral_2_eq_2) ``` lp15@60141 ` 664` ``` also have "\ \ (\k\{0, 2}. of_nat (n choose k) * x n^k)" ``` lp15@60141 ` 665` ``` by (simp add: x_def) ``` lp15@60141 ` 666` ``` also have "\ \ (\k=0..n. of_nat (n choose k) * x n^k)" ``` wenzelm@60758 ` 667` ``` using \2 < n\ by (intro setsum_mono2) (auto intro!: mult_nonneg_nonneg zero_le_power simp: x_def le_diff_eq) ``` lp15@60141 ` 668` ``` also have "\ = (x n + 1) ^ n" ``` lp15@60141 ` 669` ``` by (simp add: binomial_ring) ``` lp15@60141 ` 670` ``` also have "\ = n" ``` wenzelm@60758 ` 671` ``` using \2 < n\ by (simp add: x_def) ``` lp15@60141 ` 672` ``` finally have "real (n - 1) * (real n / 2 * (x n)\<^sup>2) \ real (n - 1) * 1" ``` lp15@60141 ` 673` ``` by simp ``` lp15@60141 ` 674` ``` then have "(x n)\<^sup>2 \ 2 / real n" ``` wenzelm@60758 ` 675` ``` using \2 < n\ unfolding mult_le_cancel_left by (simp add: field_simps) ``` lp15@60141 ` 676` ``` from real_sqrt_le_mono[OF this] have "x n \ sqrt (2 / real n)" ``` lp15@60141 ` 677` ``` by simp } ``` lp15@60141 ` 678` ``` then show "eventually (\n. x n \ sqrt (2 / real n)) sequentially" ``` lp15@60141 ` 679` ``` by (auto intro!: exI[of _ 3] simp: eventually_sequentially) ``` lp15@60141 ` 680` ``` show "eventually (\n. sqrt 0 \ x n) sequentially" ``` lp15@60141 ` 681` ``` by (auto intro!: exI[of _ 1] simp: eventually_sequentially le_diff_eq x_def) ``` lp15@60141 ` 682` ``` qed ``` lp15@60141 ` 683` ``` from tendsto_add[OF this tendsto_const[of 1]] show ?thesis ``` lp15@60141 ` 684` ``` by (simp add: x_def) ``` lp15@60141 ` 685` ```qed ``` lp15@60141 ` 686` lp15@60141 ` 687` ```lemma LIMSEQ_root_const: ``` lp15@60141 ` 688` ``` assumes "0 < c" ``` lp15@60141 ` 689` ``` shows "(\n. root n c) ----> 1" ``` lp15@60141 ` 690` ```proof - ``` lp15@60141 ` 691` ``` { fix c :: real assume "1 \ c" ``` lp15@60141 ` 692` ``` def x \ "\n. root n c - 1" ``` lp15@60141 ` 693` ``` have "x ----> 0" ``` lp15@60141 ` 694` ``` proof (rule tendsto_sandwich[OF _ _ tendsto_const]) ``` lp15@60141 ` 695` ``` show "(\n. c / n) ----> 0" ``` lp15@60141 ` 696` ``` by (intro tendsto_divide_0[OF tendsto_const] filterlim_mono[OF filterlim_real_sequentially]) ``` lp15@60141 ` 697` ``` (simp_all add: at_infinity_eq_at_top_bot) ``` lp15@60141 ` 698` ``` { fix n :: nat assume "1 < n" ``` lp15@60141 ` 699` ``` have "1 + x n * n = 1 + of_nat (n choose 1) * x n^1" ``` lp15@61609 ` 700` ``` using \1 < n\ unfolding gbinomial_def binomial_gbinomial by simp ``` lp15@60141 ` 701` ``` also have "\ \ (\k\{0, 1}. of_nat (n choose k) * x n^k)" ``` lp15@60141 ` 702` ``` by (simp add: x_def) ``` lp15@60141 ` 703` ``` also have "\ \ (\k=0..n. of_nat (n choose k) * x n^k)" ``` wenzelm@60758 ` 704` ``` using \1 < n\ \1 \ c\ by (intro setsum_mono2) (auto intro!: mult_nonneg_nonneg zero_le_power simp: x_def le_diff_eq) ``` lp15@60141 ` 705` ``` also have "\ = (x n + 1) ^ n" ``` lp15@60141 ` 706` ``` by (simp add: binomial_ring) ``` lp15@60141 ` 707` ``` also have "\ = c" ``` wenzelm@60758 ` 708` ``` using \1 < n\ \1 \ c\ by (simp add: x_def) ``` lp15@60141 ` 709` ``` finally have "x n \ c / n" ``` wenzelm@60758 ` 710` ``` using \1 \ c\ \1 < n\ by (simp add: field_simps) } ``` lp15@60141 ` 711` ``` then show "eventually (\n. x n \ c / n) sequentially" ``` lp15@60141 ` 712` ``` by (auto intro!: exI[of _ 3] simp: eventually_sequentially) ``` lp15@60141 ` 713` ``` show "eventually (\n. 0 \ x n) sequentially" ``` wenzelm@60758 ` 714` ``` using \1 \ c\ by (auto intro!: exI[of _ 1] simp: eventually_sequentially le_diff_eq x_def) ``` lp15@60141 ` 715` ``` qed ``` lp15@60141 ` 716` ``` from tendsto_add[OF this tendsto_const[of 1]] have "(\n. root n c) ----> 1" ``` lp15@60141 ` 717` ``` by (simp add: x_def) } ``` lp15@60141 ` 718` ``` note ge_1 = this ``` lp15@60141 ` 719` lp15@60141 ` 720` ``` show ?thesis ``` lp15@60141 ` 721` ``` proof cases ``` lp15@60141 ` 722` ``` assume "1 \ c" with ge_1 show ?thesis by blast ``` lp15@60141 ` 723` ``` next ``` lp15@60141 ` 724` ``` assume "\ 1 \ c" ``` wenzelm@60758 ` 725` ``` with \0 < c\ have "1 \ 1 / c" ``` lp15@60141 ` 726` ``` by simp ``` lp15@60141 ` 727` ``` then have "(\n. 1 / root n (1 / c)) ----> 1 / 1" ``` wenzelm@60758 ` 728` ``` by (intro tendsto_divide tendsto_const ge_1 \1 \ 1 / c\ one_neq_zero) ``` lp15@60141 ` 729` ``` then show ?thesis ``` lp15@60141 ` 730` ``` by (rule filterlim_cong[THEN iffD1, rotated 3]) ``` lp15@60141 ` 731` ``` (auto intro!: exI[of _ 1] simp: eventually_sequentially real_root_divide) ``` lp15@60141 ` 732` ``` qed ``` lp15@60141 ` 733` ```qed ``` lp15@60141 ` 734` lp15@60141 ` 735` huffman@22956 ` 736` ```text "Legacy theorem names:" ``` huffman@22956 ` 737` ```lemmas real_root_pos2 = real_root_power_cancel ``` huffman@22956 ` 738` ```lemmas real_root_pos_pos = real_root_gt_zero [THEN order_less_imp_le] ``` huffman@22956 ` 739` ```lemmas real_root_pos_pos_le = real_root_ge_zero ``` huffman@22956 ` 740` ```lemmas real_sqrt_mult_distrib = real_sqrt_mult ``` huffman@22956 ` 741` ```lemmas real_sqrt_mult_distrib2 = real_sqrt_mult ``` huffman@22956 ` 742` ```lemmas real_sqrt_eq_zero_cancel_iff = real_sqrt_eq_0_iff ``` huffman@22956 ` 743` huffman@22956 ` 744` ```(* needed for CauchysMeanTheorem.het_base from AFP *) ``` huffman@22956 ` 745` ```lemma real_root_pos: "0 < x \ root (Suc n) (x ^ (Suc n)) = x" ``` huffman@22956 ` 746` ```by (rule real_root_power_cancel [OF zero_less_Suc order_less_imp_le]) ``` huffman@22956 ` 747` paulson@14324 ` 748` ```end ```