347 definition sqrt :: "real \<Rightarrow> real" where |
347 definition sqrt :: "real \<Rightarrow> real" where |
348 "sqrt = root 2" |
348 "sqrt = root 2" |
349 |
349 |
350 lemma pos2: "0 < (2::nat)" by simp |
350 lemma pos2: "0 < (2::nat)" by simp |
351 |
351 |
352 lemma real_sqrt_unique: "\<lbrakk>y\<twosuperior> = x; 0 \<le> y\<rbrakk> \<Longrightarrow> sqrt x = y" |
352 lemma real_sqrt_unique: "\<lbrakk>y\<^sup>2 = x; 0 \<le> y\<rbrakk> \<Longrightarrow> sqrt x = y" |
353 unfolding sqrt_def by (rule real_root_pos_unique [OF pos2]) |
353 unfolding sqrt_def by (rule real_root_pos_unique [OF pos2]) |
354 |
354 |
355 lemma real_sqrt_abs [simp]: "sqrt (x\<twosuperior>) = \<bar>x\<bar>" |
355 lemma real_sqrt_abs [simp]: "sqrt (x\<^sup>2) = \<bar>x\<bar>" |
356 apply (rule real_sqrt_unique) |
356 apply (rule real_sqrt_unique) |
357 apply (rule power2_abs) |
357 apply (rule power2_abs) |
358 apply (rule abs_ge_zero) |
358 apply (rule abs_ge_zero) |
359 done |
359 done |
360 |
360 |
361 lemma real_sqrt_pow2 [simp]: "0 \<le> x \<Longrightarrow> (sqrt x)\<twosuperior> = x" |
361 lemma real_sqrt_pow2 [simp]: "0 \<le> x \<Longrightarrow> (sqrt x)\<^sup>2 = x" |
362 unfolding sqrt_def by (rule real_root_pow_pos2 [OF pos2]) |
362 unfolding sqrt_def by (rule real_root_pow_pos2 [OF pos2]) |
363 |
363 |
364 lemma real_sqrt_pow2_iff [simp]: "((sqrt x)\<twosuperior> = x) = (0 \<le> x)" |
364 lemma real_sqrt_pow2_iff [simp]: "((sqrt x)\<^sup>2 = x) = (0 \<le> x)" |
365 apply (rule iffI) |
365 apply (rule iffI) |
366 apply (erule subst) |
366 apply (erule subst) |
367 apply (rule zero_le_power2) |
367 apply (rule zero_le_power2) |
368 apply (erule real_sqrt_pow2) |
368 apply (erule real_sqrt_pow2) |
369 done |
369 done |
499 lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u" |
499 lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u" |
500 by (simp add: divide_less_eq) |
500 by (simp add: divide_less_eq) |
501 |
501 |
502 lemma four_x_squared: |
502 lemma four_x_squared: |
503 fixes x::real |
503 fixes x::real |
504 shows "4 * x\<twosuperior> = (2 * x)\<twosuperior>" |
504 shows "4 * x\<^sup>2 = (2 * x)\<^sup>2" |
505 by (simp add: power2_eq_square) |
505 by (simp add: power2_eq_square) |
506 |
506 |
507 subsection {* Square Root of Sum of Squares *} |
507 subsection {* Square Root of Sum of Squares *} |
508 |
508 |
509 lemma real_sqrt_sum_squares_ge_zero: "0 \<le> sqrt (x\<twosuperior> + y\<twosuperior>)" |
509 lemma real_sqrt_sum_squares_ge_zero: "0 \<le> sqrt (x\<^sup>2 + y\<^sup>2)" |
510 by simp (* TODO: delete *) |
510 by simp (* TODO: delete *) |
511 |
511 |
512 declare real_sqrt_sum_squares_ge_zero [THEN abs_of_nonneg, simp] |
512 declare real_sqrt_sum_squares_ge_zero [THEN abs_of_nonneg, simp] |
513 |
513 |
514 lemma real_sqrt_sum_squares_mult_ge_zero [simp]: |
514 lemma real_sqrt_sum_squares_mult_ge_zero [simp]: |
515 "0 \<le> sqrt ((x\<twosuperior> + y\<twosuperior>)*(xa\<twosuperior> + ya\<twosuperior>))" |
515 "0 \<le> sqrt ((x\<^sup>2 + y\<^sup>2)*(xa\<^sup>2 + ya\<^sup>2))" |
516 by (simp add: zero_le_mult_iff) |
516 by (simp add: zero_le_mult_iff) |
517 |
517 |
518 lemma real_sqrt_sum_squares_mult_squared_eq [simp]: |
518 lemma real_sqrt_sum_squares_mult_squared_eq [simp]: |
519 "sqrt ((x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)) ^ 2 = (x\<twosuperior> + y\<twosuperior>) * (xa\<twosuperior> + ya\<twosuperior>)" |
519 "sqrt ((x\<^sup>2 + y\<^sup>2) * (xa\<^sup>2 + ya\<^sup>2)) ^ 2 = (x\<^sup>2 + y\<^sup>2) * (xa\<^sup>2 + ya\<^sup>2)" |
520 by (simp add: zero_le_mult_iff) |
520 by (simp add: zero_le_mult_iff) |
521 |
521 |
522 lemma real_sqrt_sum_squares_eq_cancel: "sqrt (x\<twosuperior> + y\<twosuperior>) = x \<Longrightarrow> y = 0" |
522 lemma real_sqrt_sum_squares_eq_cancel: "sqrt (x\<^sup>2 + y\<^sup>2) = x \<Longrightarrow> y = 0" |
523 by (drule_tac f = "%x. x\<twosuperior>" in arg_cong, simp) |
523 by (drule_tac f = "%x. x\<^sup>2" in arg_cong, simp) |
524 |
524 |
525 lemma real_sqrt_sum_squares_eq_cancel2: "sqrt (x\<twosuperior> + y\<twosuperior>) = y \<Longrightarrow> x = 0" |
525 lemma real_sqrt_sum_squares_eq_cancel2: "sqrt (x\<^sup>2 + y\<^sup>2) = y \<Longrightarrow> x = 0" |
526 by (drule_tac f = "%x. x\<twosuperior>" in arg_cong, simp) |
526 by (drule_tac f = "%x. x\<^sup>2" in arg_cong, simp) |
527 |
527 |
528 lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt (x\<twosuperior> + y\<twosuperior>)" |
528 lemma real_sqrt_sum_squares_ge1 [simp]: "x \<le> sqrt (x\<^sup>2 + y\<^sup>2)" |
529 by (rule power2_le_imp_le, simp_all) |
529 by (rule power2_le_imp_le, simp_all) |
530 |
530 |
531 lemma real_sqrt_sum_squares_ge2 [simp]: "y \<le> sqrt (x\<twosuperior> + y\<twosuperior>)" |
531 lemma real_sqrt_sum_squares_ge2 [simp]: "y \<le> sqrt (x\<^sup>2 + y\<^sup>2)" |
532 by (rule power2_le_imp_le, simp_all) |
532 by (rule power2_le_imp_le, simp_all) |
533 |
533 |
534 lemma real_sqrt_ge_abs1 [simp]: "\<bar>x\<bar> \<le> sqrt (x\<twosuperior> + y\<twosuperior>)" |
534 lemma real_sqrt_ge_abs1 [simp]: "\<bar>x\<bar> \<le> sqrt (x\<^sup>2 + y\<^sup>2)" |
535 by (rule power2_le_imp_le, simp_all) |
535 by (rule power2_le_imp_le, simp_all) |
536 |
536 |
537 lemma real_sqrt_ge_abs2 [simp]: "\<bar>y\<bar> \<le> sqrt (x\<twosuperior> + y\<twosuperior>)" |
537 lemma real_sqrt_ge_abs2 [simp]: "\<bar>y\<bar> \<le> sqrt (x\<^sup>2 + y\<^sup>2)" |
538 by (rule power2_le_imp_le, simp_all) |
538 by (rule power2_le_imp_le, simp_all) |
539 |
539 |
540 lemma le_real_sqrt_sumsq [simp]: "x \<le> sqrt (x * x + y * y)" |
540 lemma le_real_sqrt_sumsq [simp]: "x \<le> sqrt (x * x + y * y)" |
541 by (simp add: power2_eq_square [symmetric]) |
541 by (simp add: power2_eq_square [symmetric]) |
542 |
542 |
543 lemma real_sqrt_sum_squares_triangle_ineq: |
543 lemma real_sqrt_sum_squares_triangle_ineq: |
544 "sqrt ((a + c)\<twosuperior> + (b + d)\<twosuperior>) \<le> sqrt (a\<twosuperior> + b\<twosuperior>) + sqrt (c\<twosuperior> + d\<twosuperior>)" |
544 "sqrt ((a + c)\<^sup>2 + (b + d)\<^sup>2) \<le> sqrt (a\<^sup>2 + b\<^sup>2) + sqrt (c\<^sup>2 + d\<^sup>2)" |
545 apply (rule power2_le_imp_le, simp) |
545 apply (rule power2_le_imp_le, simp) |
546 apply (simp add: power2_sum) |
546 apply (simp add: power2_sum) |
547 apply (simp only: mult_assoc distrib_left [symmetric]) |
547 apply (simp only: mult_assoc distrib_left [symmetric]) |
548 apply (rule mult_left_mono) |
548 apply (rule mult_left_mono) |
549 apply (rule power2_le_imp_le) |
549 apply (rule power2_le_imp_le) |
550 apply (simp add: power2_sum power_mult_distrib) |
550 apply (simp add: power2_sum power_mult_distrib) |
551 apply (simp add: ring_distribs) |
551 apply (simp add: ring_distribs) |
552 apply (subgoal_tac "0 \<le> b\<twosuperior> * c\<twosuperior> + a\<twosuperior> * d\<twosuperior> - 2 * (a * c) * (b * d)", simp) |
552 apply (subgoal_tac "0 \<le> b\<^sup>2 * c\<^sup>2 + a\<^sup>2 * d\<^sup>2 - 2 * (a * c) * (b * d)", simp) |
553 apply (rule_tac b="(a * d - b * c)\<twosuperior>" in ord_le_eq_trans) |
553 apply (rule_tac b="(a * d - b * c)\<^sup>2" in ord_le_eq_trans) |
554 apply (rule zero_le_power2) |
554 apply (rule zero_le_power2) |
555 apply (simp add: power2_diff power_mult_distrib) |
555 apply (simp add: power2_diff power_mult_distrib) |
556 apply (simp add: mult_nonneg_nonneg) |
556 apply (simp add: mult_nonneg_nonneg) |
557 apply simp |
557 apply simp |
558 apply (simp add: add_increasing) |
558 apply (simp add: add_increasing) |
559 done |
559 done |
560 |
560 |
561 lemma real_sqrt_sum_squares_less: |
561 lemma real_sqrt_sum_squares_less: |
562 "\<lbrakk>\<bar>x\<bar> < u / sqrt 2; \<bar>y\<bar> < u / sqrt 2\<rbrakk> \<Longrightarrow> sqrt (x\<twosuperior> + y\<twosuperior>) < u" |
562 "\<lbrakk>\<bar>x\<bar> < u / sqrt 2; \<bar>y\<bar> < u / sqrt 2\<rbrakk> \<Longrightarrow> sqrt (x\<^sup>2 + y\<^sup>2) < u" |
563 apply (rule power2_less_imp_less, simp) |
563 apply (rule power2_less_imp_less, simp) |
564 apply (drule power_strict_mono [OF _ abs_ge_zero pos2]) |
564 apply (drule power_strict_mono [OF _ abs_ge_zero pos2]) |
565 apply (drule power_strict_mono [OF _ abs_ge_zero pos2]) |
565 apply (drule power_strict_mono [OF _ abs_ge_zero pos2]) |
566 apply (simp add: power_divide) |
566 apply (simp add: power_divide) |
567 apply (drule order_le_less_trans [OF abs_ge_zero]) |
567 apply (drule order_le_less_trans [OF abs_ge_zero]) |