453 |
453 |
454 (* Simplification *) |
454 (* Simplification *) |
455 |
455 |
456 fun maxcoeff:: "num \<Rightarrow> int" |
456 fun maxcoeff:: "num \<Rightarrow> int" |
457 where |
457 where |
458 "maxcoeff (C i) = abs i" |
458 "maxcoeff (C i) = \<bar>i\<bar>" |
459 | "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)" |
459 | "maxcoeff (CN n c t) = max \<bar>c\<bar> (maxcoeff t)" |
460 | "maxcoeff t = 1" |
460 | "maxcoeff t = 1" |
461 |
461 |
462 lemma maxcoeff_pos: "maxcoeff t \<ge> 0" |
462 lemma maxcoeff_pos: "maxcoeff t \<ge> 0" |
463 by (induct t rule: maxcoeff.induct, auto) |
463 by (induct t rule: maxcoeff.induct, auto) |
464 |
464 |
496 using dgt' gdg |
496 using dgt' gdg |
497 by (induct t rule: dvdnumcoeff.induct) (simp_all add: gdg dvd_trans[OF gdg]) |
497 by (induct t rule: dvdnumcoeff.induct) (simp_all add: gdg dvd_trans[OF gdg]) |
498 |
498 |
499 declare dvd_trans [trans add] |
499 declare dvd_trans [trans add] |
500 |
500 |
501 lemma natabs0: "nat (abs x) = 0 \<longleftrightarrow> x = 0" |
501 lemma natabs0: "nat \<bar>x\<bar> = 0 \<longleftrightarrow> x = 0" |
502 by arith |
502 by arith |
503 |
503 |
504 lemma numgcd0: |
504 lemma numgcd0: |
505 assumes g0: "numgcd t = 0" |
505 assumes g0: "numgcd t = 0" |
506 shows "Inum bs t = 0" |
506 shows "Inum bs t = 0" |
534 by (simp add: real_of_int_div[OF gd] algebra_simps) |
534 by (simp add: real_of_int_div[OF gd] algebra_simps) |
535 qed (auto simp add: numgcd_def gp) |
535 qed (auto simp add: numgcd_def gp) |
536 |
536 |
537 fun ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" |
537 fun ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" |
538 where |
538 where |
539 "ismaxcoeff (C i) = (\<lambda>x. abs i \<le> x)" |
539 "ismaxcoeff (C i) = (\<lambda>x. \<bar>i\<bar> \<le> x)" |
540 | "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> ismaxcoeff t x)" |
540 | "ismaxcoeff (CN n c t) = (\<lambda>x. \<bar>c\<bar> \<le> x \<and> ismaxcoeff t x)" |
541 | "ismaxcoeff t = (\<lambda>x. True)" |
541 | "ismaxcoeff t = (\<lambda>x. True)" |
542 |
542 |
543 lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'" |
543 lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'" |
544 by (induct t rule: ismaxcoeff.induct) auto |
544 by (induct t rule: ismaxcoeff.induct) auto |
545 |
545 |
546 lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)" |
546 lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)" |
547 proof (induct t rule: maxcoeff.induct) |
547 proof (induct t rule: maxcoeff.induct) |
548 case (2 n c t) |
548 case (2 n c t) |
549 then have H:"ismaxcoeff t (maxcoeff t)" . |
549 then have H:"ismaxcoeff t (maxcoeff t)" . |
550 have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" |
550 have thh: "maxcoeff t \<le> max \<bar>c\<bar> (maxcoeff t)" |
551 by simp |
551 by simp |
552 from ismaxcoeff_mono[OF H thh] show ?case |
552 from ismaxcoeff_mono[OF H thh] show ?case |
553 by simp |
553 by simp |
554 qed simp_all |
554 qed simp_all |
555 |
555 |
556 lemma zgcd_gt1: "gcd i j > (1::int) \<Longrightarrow> |
556 lemma zgcd_gt1: "gcd i j > (1::int) \<Longrightarrow> |
557 abs i > 1 \<and> abs j > 1 \<or> abs i = 0 \<and> abs j > 1 \<or> abs i > 1 \<and> abs j = 0" |
557 \<bar>i\<bar> > 1 \<and> \<bar>j\<bar> > 1 \<or> \<bar>i\<bar> = 0 \<and> \<bar>j\<bar> > 1 \<or> \<bar>i\<bar> > 1 \<and> \<bar>j\<bar> = 0" |
558 apply (cases "abs i = 0", simp_all add: gcd_int_def) |
558 apply (cases "\<bar>i\<bar> = 0", simp_all add: gcd_int_def) |
559 apply (cases "abs j = 0", simp_all) |
559 apply (cases "\<bar>j\<bar> = 0", simp_all) |
560 apply (cases "abs i = 1", simp_all) |
560 apply (cases "\<bar>i\<bar> = 1", simp_all) |
561 apply (cases "abs j = 1", simp_all) |
561 apply (cases "\<bar>j\<bar> = 1", simp_all) |
562 apply auto |
562 apply auto |
563 done |
563 done |
564 |
564 |
565 lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow> m =0" |
565 lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow> m =0" |
566 by (induct t rule: numgcdh.induct) auto |
566 by (induct t rule: numgcdh.induct) auto |
575 case (2 n c t) |
575 case (2 n c t) |
576 let ?g = "numgcdh t m" |
576 let ?g = "numgcdh t m" |
577 from 2 have th: "gcd c ?g > 1" |
577 from 2 have th: "gcd c ?g > 1" |
578 by simp |
578 by simp |
579 from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] |
579 from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] |
580 consider "abs c > 1" "?g > 1" | "abs c = 0" "?g > 1" | "?g = 0" |
580 consider "\<bar>c\<bar> > 1" "?g > 1" | "\<bar>c\<bar> = 0" "?g > 1" | "?g = 0" |
581 by auto |
581 by auto |
582 then show ?case |
582 then show ?case |
583 proof cases |
583 proof cases |
584 case 1 |
584 case 1 |
585 with 2 have th: "dvdnumcoeff t ?g" |
585 with 2 have th: "dvdnumcoeff t ?g" |
742 by (induct t) (simp_all add: numadd_nz numneg_nz numsub_nz nummul_nz) |
742 by (induct t) (simp_all add: numadd_nz numneg_nz numsub_nz nummul_nz) |
743 |
743 |
744 lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0" |
744 lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0" |
745 proof (induct t rule: maxcoeff.induct) |
745 proof (induct t rule: maxcoeff.induct) |
746 case (2 n c t) |
746 case (2 n c t) |
747 then have cnz: "c \<noteq> 0" and mx: "max (abs c) (maxcoeff t) = 0" |
747 then have cnz: "c \<noteq> 0" and mx: "max \<bar>c\<bar> (maxcoeff t) = 0" |
748 by simp_all |
748 by simp_all |
749 have "max (abs c) (maxcoeff t) \<ge> abs c" |
749 have "max \<bar>c\<bar> (maxcoeff t) \<ge> \<bar>c\<bar>" |
750 by simp |
750 by simp |
751 with cnz have "max (abs c) (maxcoeff t) > 0" |
751 with cnz have "max \<bar>c\<bar> (maxcoeff t) > 0" |
752 by arith |
752 by arith |
753 with 2 show ?case |
753 with 2 show ?case |
754 by simp |
754 by simp |
755 qed auto |
755 qed auto |
756 |
756 |