377 by (induct z, simp add: complex_cnj complex_of_real_def power2_eq_square) |
380 by (induct z, simp add: complex_cnj complex_of_real_def power2_eq_square) |
378 |
381 |
379 |
382 |
380 subsection{*Modulus*} |
383 subsection{*Modulus*} |
381 |
384 |
382 instance complex :: norm .. |
385 instance complex :: norm |
383 |
386 complex_norm_def: "norm z \<equiv> sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)" .. |
384 defs (overloaded) |
|
385 complex_norm_def: "norm z == sqrt(Re(z) ^ 2 + Im(z) ^ 2)" |
|
386 |
387 |
387 abbreviation |
388 abbreviation |
388 cmod :: "complex => real" where |
389 cmod :: "complex \<Rightarrow> real" where |
389 "cmod == norm" |
390 "cmod \<equiv> norm" |
390 |
391 |
391 lemmas cmod_def = complex_norm_def |
392 lemmas cmod_def = complex_norm_def |
392 |
393 |
393 lemma complex_mod [simp]: "cmod (Complex x y) = sqrt(x ^ 2 + y ^ 2)" |
394 lemma complex_mod [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)" |
394 by (simp add: cmod_def) |
395 by (simp add: cmod_def) |
395 |
396 |
396 lemma complex_mod_zero [simp]: "cmod(0) = 0" |
397 lemma complex_mod_triangle_ineq [simp]: "cmod (x + y) \<le> cmod x + cmod y" |
397 by (simp add: cmod_def) |
398 apply (simp add: cmod_def) |
398 |
399 apply (rule real_sqrt_sum_squares_triangle_ineq) |
399 lemma complex_mod_one [simp]: "cmod(1) = 1" |
400 done |
400 by (simp add: cmod_def power2_eq_square) |
401 |
401 |
402 lemma complex_mod_mult: "cmod (x * y) = cmod x * cmod y" |
402 lemma complex_mod_complex_of_real [simp]: "cmod(complex_of_real x) = abs x" |
|
403 by (simp add: complex_of_real_def power2_eq_square) |
|
404 |
|
405 lemma complex_of_real_abs: |
|
406 "complex_of_real (abs x) = complex_of_real(cmod(complex_of_real x))" |
|
407 by simp |
|
408 |
|
409 lemma complex_mod_eq_zero_cancel [simp]: "(cmod x = 0) = (x = 0)" |
|
410 apply (induct x) |
|
411 apply (auto iff: real_0_le_add_iff |
|
412 intro: real_sum_squares_cancel real_sum_squares_cancel2 |
|
413 simp add: complex_mod complex_zero_def power2_eq_square) |
|
414 done |
|
415 |
|
416 lemma complex_mod_complex_of_real_of_nat [simp]: |
|
417 "cmod (complex_of_real(real (n::nat))) = real n" |
|
418 by simp |
|
419 |
|
420 lemma complex_mod_minus [simp]: "cmod (-x) = cmod(x)" |
|
421 by (induct x, simp add: power2_eq_square) |
|
422 |
|
423 lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z" |
|
424 by (induct z, simp add: complex_cnj power2_eq_square) |
|
425 |
|
426 lemma complex_mod_mult_cnj: "cmod(z * cnj(z)) = cmod(z) ^ 2" |
|
427 apply (induct z, simp add: complex_mod complex_cnj complex_mult) |
|
428 apply (simp add: power2_eq_square abs_if linorder_not_less real_0_le_add_iff) |
|
429 done |
|
430 |
|
431 lemma complex_mod_squared: "cmod(Complex x y) ^ 2 = x ^ 2 + y ^ 2" |
|
432 by (simp add: cmod_def) |
|
433 |
|
434 lemma complex_mod_ge_zero [simp]: "0 \<le> cmod x" |
|
435 by (simp add: cmod_def) |
|
436 |
|
437 lemma abs_cmod_cancel [simp]: "abs(cmod x) = cmod x" |
|
438 by (simp add: abs_if linorder_not_less) |
|
439 |
|
440 lemma complex_mod_mult: "cmod(x*y) = cmod(x) * cmod(y)" |
|
441 apply (induct x, induct y) |
403 apply (induct x, induct y) |
442 apply (auto simp add: complex_mult complex_mod real_sqrt_mult_distrib2[symmetric]) |
404 apply (simp add: real_sqrt_mult_distrib [symmetric]) |
443 apply (rule_tac n = 1 in power_inject_base) |
405 apply (rule_tac f=sqrt in arg_cong) |
444 apply (auto simp add: power2_eq_square [symmetric] simp del: realpow_Suc) |
406 apply (simp add: power2_sum power2_diff power_mult_distrib ring_distrib) |
445 apply (auto simp add: real_diff_def power2_eq_square right_distrib left_distrib |
407 done |
446 add_ac mult_ac) |
408 |
447 done |
409 lemma complex_mod_complex_of_real: "cmod (complex_of_real x) = \<bar>x\<bar>" |
448 |
410 by (simp add: complex_of_real_def) |
449 lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1" |
|
450 by (simp add: cmod_def) |
|
451 |
|
452 lemma cmod_complex_polar [simp]: |
|
453 "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r" |
|
454 by (simp only: cmod_unit_one complex_mod_mult, simp) |
|
455 |
|
456 lemma complex_mod_add_squared_eq: |
|
457 "cmod(x + y) ^ 2 = cmod(x) ^ 2 + cmod(y) ^ 2 + 2 * Re(x * cnj y)" |
|
458 apply (induct x, induct y) |
|
459 apply (auto simp add: complex_mod_squared complex_cnj real_diff_def simp del: realpow_Suc) |
|
460 apply (auto simp add: right_distrib left_distrib power2_eq_square mult_ac add_ac) |
|
461 done |
|
462 |
|
463 lemma complex_Re_mult_cnj_le_cmod [simp]: "Re(x * cnj y) \<le> cmod(x * cnj y)" |
|
464 apply (induct x, induct y) |
|
465 apply (auto simp add: complex_mod complex_cnj diff_def simp del: realpow_Suc) |
|
466 done |
|
467 |
|
468 lemma complex_Re_mult_cnj_le_cmod2 [simp]: "Re(x * cnj y) \<le> cmod(x * y)" |
|
469 by (insert complex_Re_mult_cnj_le_cmod [of x y], simp add: complex_mod_mult) |
|
470 |
|
471 lemma real_sum_squared_expand: |
|
472 "((x::real) + y) ^ 2 = x ^ 2 + y ^ 2 + 2 * x * y" |
|
473 by (simp add: left_distrib right_distrib power2_eq_square) |
|
474 |
|
475 lemma complex_mod_triangle_squared [simp]: |
|
476 "cmod (x + y) ^ 2 \<le> (cmod(x) + cmod(y)) ^ 2" |
|
477 by (simp add: real_sum_squared_expand complex_mod_add_squared_eq real_mult_assoc complex_mod_mult [symmetric]) |
|
478 |
|
479 lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x" |
|
480 by (rule order_trans [OF _ complex_mod_ge_zero], simp) |
|
481 |
|
482 lemma complex_mod_triangle_ineq [simp]: "cmod (x + y) \<le> cmod(x) + cmod(y)" |
|
483 apply (rule_tac n = 1 in realpow_increasing) |
|
484 apply (auto intro: order_trans [OF _ complex_mod_ge_zero] |
|
485 simp add: add_increasing power2_eq_square [symmetric]) |
|
486 done |
|
487 |
411 |
488 lemma complex_norm_scaleR: |
412 lemma complex_norm_scaleR: |
489 "norm (scaleR a x) = \<bar>a\<bar> * norm (x::complex)" |
413 "norm (scaleR a x) = \<bar>a\<bar> * norm (x::complex)" |
490 by (simp only: |
414 unfolding scaleR_conv_of_real |
491 scaleR_conv_of_real complex_mod_mult complex_mod_complex_of_real) |
415 by (simp only: complex_mod_mult complex_mod_complex_of_real) |
492 |
416 |
493 instance complex :: real_normed_field |
417 instance complex :: real_normed_field |
494 proof |
418 proof |
495 fix r :: real |
419 fix r :: real |
496 fix x y :: complex |
420 fix x y :: complex |
497 show "0 \<le> cmod x" |
421 show "0 \<le> cmod x" |
498 by (rule complex_mod_ge_zero) |
422 by (induct x) simp |
499 show "(cmod x = 0) = (x = 0)" |
423 show "(cmod x = 0) = (x = 0)" |
500 by (rule complex_mod_eq_zero_cancel) |
424 by (induct x) simp |
501 show "cmod (x + y) \<le> cmod x + cmod y" |
425 show "cmod (x + y) \<le> cmod x + cmod y" |
502 by (rule complex_mod_triangle_ineq) |
426 by (rule complex_mod_triangle_ineq) |
503 show "cmod (scaleR r x) = \<bar>r\<bar> * cmod x" |
427 show "cmod (scaleR r x) = \<bar>r\<bar> * cmod x" |
504 by (rule complex_norm_scaleR) |
428 by (rule complex_norm_scaleR) |
505 show "cmod (x * y) = cmod x * cmod y" |
429 show "cmod (x * y) = cmod x * cmod y" |
506 by (rule complex_mod_mult) |
430 by (rule complex_mod_mult) |
507 qed |
431 qed |
508 |
432 |
|
433 lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z" |
|
434 by (induct z, simp add: complex_cnj) |
|
435 |
|
436 lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>" |
|
437 by (simp add: complex_mod_mult power2_eq_square) |
|
438 |
|
439 lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1" |
|
440 by simp |
|
441 |
|
442 lemma cmod_complex_polar [simp]: |
|
443 "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r" |
|
444 apply (simp only: cmod_unit_one complex_mod_mult) |
|
445 apply (simp add: complex_mod_complex_of_real) |
|
446 done |
|
447 |
|
448 lemma complex_Re_le_cmod: "Re x \<le> cmod x" |
|
449 unfolding complex_norm_def |
|
450 by (rule real_sqrt_sum_squares_ge1) |
|
451 |
|
452 lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x" |
|
453 by (rule order_trans [OF _ norm_ge_zero], simp) |
|
454 |
509 lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a" |
455 lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a" |
510 by (insert complex_mod_triangle_ineq [THEN add_right_mono, of b a"-cmod b"], simp) |
456 by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp) |
511 |
|
512 lemma complex_mod_diff_commute: "cmod (x - y) = cmod (y - x)" |
|
513 by (rule norm_minus_commute) |
|
514 |
457 |
515 lemma complex_mod_add_less: |
458 lemma complex_mod_add_less: |
516 "[| cmod x < r; cmod y < s |] ==> cmod (x + y) < r + s" |
459 "[| cmod x < r; cmod y < s |] ==> cmod (x + y) < r + s" |
517 by (auto intro: order_le_less_trans complex_mod_triangle_ineq) |
460 by (auto intro: order_le_less_trans complex_mod_triangle_ineq) |
518 |
461 |
519 lemma complex_mod_mult_less: |
462 lemma complex_mod_mult_less: |
520 "[| cmod x < r; cmod y < s |] ==> cmod (x * y) < r * s" |
463 "[| cmod x < r; cmod y < s |] ==> cmod (x * y) < r * s" |
521 by (auto intro: real_mult_less_mono' simp add: complex_mod_mult) |
464 by (auto intro: real_mult_less_mono' simp add: complex_mod_mult) |
522 |
465 |
523 lemma complex_mod_diff_ineq [simp]: "cmod(a) - cmod(b) \<le> cmod(a + b)" |
466 lemma complex_mod_diff_ineq [simp]: "cmod(a) - cmod(b) \<le> cmod(a + b)" |
|
467 (* TODO: generalize *) |
524 proof - |
468 proof - |
525 have "cmod a - cmod b = cmod a - cmod (- b)" by simp |
469 have "cmod a - cmod b = cmod a - cmod (- b)" by simp |
526 also have "\<dots> \<le> cmod (a - - b)" by (rule norm_triangle_ineq2) |
470 also have "\<dots> \<le> cmod (a - - b)" by (rule norm_triangle_ineq2) |
527 also have "\<dots> = cmod (a + b)" by simp |
471 also have "\<dots> = cmod (a + b)" by simp |
528 finally show ?thesis . |
472 finally show ?thesis . |
529 qed |
473 qed |
530 |
474 |
531 lemma complex_Re_le_cmod [simp]: "Re z \<le> cmod z" |
475 lemmas real_sum_squared_expand = power2_sum [where 'a=real] |
532 by (induct z, simp) |
|
533 |
|
534 lemma complex_mod_gt_zero: "z \<noteq> 0 ==> 0 < cmod z" |
|
535 by (rule zero_less_norm_iff [THEN iffD2]) |
|
536 |
|
537 lemma complex_mod_inverse: "cmod(inverse x) = inverse(cmod x)" |
|
538 by (rule norm_inverse) |
|
539 |
|
540 lemma complex_mod_divide: "cmod(x/y) = cmod(x)/(cmod y)" |
|
541 by (rule norm_divide) |
|
542 |
476 |
543 |
477 |
544 subsection{*Exponentiation*} |
478 subsection{*Exponentiation*} |
545 |
479 |
546 primrec |
480 primrec |