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