src/HOL/Number_Theory/Primes.thy
author Manuel Eberl <eberlm@in.tum.de>
Fri, 26 Feb 2016 22:15:09 +0100
changeset 62429 25271ff79171
parent 62410 2fc7a8d9c529
child 62481 b5d8e57826df
permissions -rw-r--r--
Tuned Euclidean Rings/GCD rings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32479
521cc9bf2958 some reorganization of number theory
haftmann
parents: 32415
diff changeset
     1
(*  Authors:    Christophe Tabacznyj, Lawrence C. Paulson, Amine Chaieb,
31798
fe9a3043d36c Cleaned up GCD
nipkow
parents: 31766
diff changeset
     2
                Thomas M. Rasmussen, Jeremy Avigad, Tobias Nipkow
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
     3
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
     4
32479
521cc9bf2958 some reorganization of number theory
haftmann
parents: 32415
diff changeset
     5
This file deals with properties of primes. Definitions and lemmas are
521cc9bf2958 some reorganization of number theory
haftmann
parents: 32415
diff changeset
     6
proved uniformly for the natural numbers and integers.
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
     7
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
     8
This file combines and revises a number of prior developments.
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
     9
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    10
The original theories "GCD" and "Primes" were by Christophe Tabacznyj
58623
2db1df2c8467 more bibtex entries;
wenzelm
parents: 57512
diff changeset
    11
and Lawrence C. Paulson, based on @{cite davenport92}. They introduced
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    12
gcd, lcm, and prime for the natural numbers.
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    13
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    14
The original theory "IntPrimes" was by Thomas M. Rasmussen, and
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    15
extended gcd, lcm, primes to the integers. Amine Chaieb provided
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    16
another extension of the notions to the integers, and added a number
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    17
of results to "Primes" and "GCD". IntPrimes also defined and developed
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    18
the congruence relations on the integers. The notion was extended to
33718
06e9aff51d17 Fixed a typo in a comment.
webertj
parents: 32479
diff changeset
    19
the natural numbers by Chaieb.
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    20
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
    21
Jeremy Avigad combined all of these, made everything uniform for the
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
    22
natural numbers and the integers, and added a number of new theorems.
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
    23
31798
fe9a3043d36c Cleaned up GCD
nipkow
parents: 31766
diff changeset
    24
Tobias Nipkow cleaned up a lot.
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    25
*)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    26
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    27
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
    28
section \<open>Primes\<close>
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    29
32479
521cc9bf2958 some reorganization of number theory
haftmann
parents: 32415
diff changeset
    30
theory Primes
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
    31
imports "~~/src/HOL/GCD" "~~/src/HOL/Binomial"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    32
begin
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    33
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    34
declare [[coercion int]]
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    35
declare [[coercion_enabled]]
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    36
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    37
definition prime :: "nat \<Rightarrow> bool"
60804
080a979a985b formal class for factorial (semi)rings
haftmann
parents: 60688
diff changeset
    38
  where "prime p = (1 < p \<and> (\<forall>m. m dvd p \<longrightarrow> m = 1 \<or> m = p))"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    39
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
    40
subsection \<open>Primes\<close>
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    41
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    42
lemma prime_odd_nat: "prime p \<Longrightarrow> p > 2 \<Longrightarrow> odd p"
62410
2fc7a8d9c529 partial tidy-up of Sylow's theorem
paulson <lp15@cam.ac.uk>
parents: 62349
diff changeset
    43
  using nat_dvd_1_iff_1 odd_one prime_def by blast
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    44
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    45
lemma prime_gt_0_nat: "prime p \<Longrightarrow> p > 0"
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    46
  unfolding prime_def by auto
22027
e4a08629c4bd A few lemmas about relative primes when dividing trough gcd
chaieb
parents: 21404
diff changeset
    47
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    48
lemma prime_ge_1_nat: "prime p \<Longrightarrow> p >= 1"
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    49
  unfolding prime_def by auto
22027
e4a08629c4bd A few lemmas about relative primes when dividing trough gcd
chaieb
parents: 21404
diff changeset
    50
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    51
lemma prime_gt_1_nat: "prime p \<Longrightarrow> p > 1"
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    52
  unfolding prime_def by auto
22367
6860f09242bf tuned document;
wenzelm
parents: 22027
diff changeset
    53
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    54
lemma prime_ge_Suc_0_nat: "prime p \<Longrightarrow> p >= Suc 0"
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    55
  unfolding prime_def by auto
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    56
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    57
lemma prime_gt_Suc_0_nat: "prime p \<Longrightarrow> p > Suc 0"
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    58
  unfolding prime_def by auto
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    59
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    60
lemma prime_ge_2_nat: "prime p \<Longrightarrow> p >= 2"
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    61
  unfolding prime_def by auto
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    62
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    63
lemma prime_imp_coprime_nat: "prime p \<Longrightarrow> \<not> p dvd n \<Longrightarrow> coprime p n"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
    64
  apply (unfold prime_def)
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
    65
  apply (metis gcd_dvd1 gcd_dvd2)
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    66
  done
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    67
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
    68
lemma prime_int_altdef:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    69
  "prime p = (1 < p \<and> (\<forall>m::int. m \<ge> 0 \<longrightarrow> m dvd p \<longrightarrow>
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    70
    m = 1 \<or> m = p))"
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    71
  apply (simp add: prime_def)
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    72
  apply (auto simp add: )
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
    73
  apply (metis One_nat_def of_nat_1 nat_0_le nat_dvd_iff)
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    74
  apply (metis zdvd_int One_nat_def le0 of_nat_0 of_nat_1 of_nat_eq_iff of_nat_le_iff)
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    75
  done
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    76
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    77
lemma prime_imp_coprime_int:
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    78
  fixes n::int shows "prime p \<Longrightarrow> \<not> p dvd n \<Longrightarrow> coprime p n"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    79
  apply (unfold prime_int_altdef)
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
    80
  apply (metis gcd_dvd1 gcd_dvd2 gcd_ge_0_int)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
    81
  done
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
    82
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    83
lemma prime_dvd_mult_nat: "prime p \<Longrightarrow> p dvd m * n \<Longrightarrow> p dvd m \<or> p dvd n"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
    84
  by (blast intro: coprime_dvd_mult prime_imp_coprime_nat)
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    85
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
    86
lemma prime_dvd_mult_int:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    87
  fixes n::int shows "prime p \<Longrightarrow> p dvd m * n \<Longrightarrow> p dvd m \<or> p dvd n"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
    88
  by (blast intro: coprime_dvd_mult prime_imp_coprime_int)
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    89
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    90
lemma prime_dvd_mult_eq_nat [simp]: "prime p \<Longrightarrow>
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
    91
    p dvd m * n = (p dvd m \<or> p dvd n)"
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
    92
  by (rule iffI, rule prime_dvd_mult_nat, auto)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
    93
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    94
lemma prime_dvd_mult_eq_int [simp]:
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
    95
  fixes n::int
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
    96
  shows "prime p \<Longrightarrow> p dvd m * n = (p dvd m \<or> p dvd n)"
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
    97
  by (rule iffI, rule prime_dvd_mult_int, auto)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
    98
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
    99
lemma not_prime_eq_prod_nat: "(n::nat) > 1 \<Longrightarrow> ~ prime n \<Longrightarrow>
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   100
    EX m k. n = m * k & 1 < m & m < n & 1 < k & k < n"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   101
  unfolding prime_def dvd_def apply auto
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55337
diff changeset
   102
  by (metis mult.commute linorder_neq_iff linorder_not_le mult_1
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   103
      n_less_n_mult_m one_le_mult_iff less_imp_le_nat)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
   104
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   105
lemma prime_dvd_power_nat: "prime p \<Longrightarrow> p dvd x^n \<Longrightarrow> p dvd x"
53598
2bd8d459ebae remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents: 47108
diff changeset
   106
  by (induct n) auto
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
   107
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   108
lemma prime_dvd_power_int:
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   109
  fixes x::int shows "prime p \<Longrightarrow> p dvd x^n \<Longrightarrow> p dvd x"
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   110
  by (induct n) auto
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   111
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   112
lemma prime_dvd_power_nat_iff: "prime p \<Longrightarrow> n > 0 \<Longrightarrow>
53598
2bd8d459ebae remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents: 47108
diff changeset
   113
    p dvd x^n \<longleftrightarrow> p dvd x"
2bd8d459ebae remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents: 47108
diff changeset
   114
  by (cases n) (auto elim: prime_dvd_power_nat)
2bd8d459ebae remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents: 47108
diff changeset
   115
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   116
lemma prime_dvd_power_int_iff:
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   117
  fixes x::int
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   118
  shows "prime p \<Longrightarrow> n > 0 \<Longrightarrow> p dvd x^n \<longleftrightarrow> p dvd x"
53598
2bd8d459ebae remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents: 47108
diff changeset
   119
  by (cases n) (auto elim: prime_dvd_power_int)
2bd8d459ebae remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents: 47108
diff changeset
   120
2bd8d459ebae remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents: 47108
diff changeset
   121
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   122
subsubsection \<open>Make prime naively executable\<close>
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   123
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   124
lemma zero_not_prime_nat [simp]: "~prime (0::nat)"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   125
  by (simp add: prime_def)
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   126
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   127
lemma one_not_prime_nat [simp]: "~prime (1::nat)"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   128
  by (simp add: prime_def)
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   129
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   130
lemma Suc_0_not_prime_nat [simp]: "~prime (Suc 0)"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   131
  by (simp add: prime_def)
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   132
37607
ebb8b1a79c4c tuned theory text
haftmann
parents: 37294
diff changeset
   133
lemma prime_nat_code [code]:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   134
    "prime p \<longleftrightarrow> p > 1 \<and> (\<forall>n \<in> {1<..<p}. ~ n dvd p)"
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   135
  apply (simp add: Ball_def)
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   136
  apply (metis One_nat_def less_not_refl prime_def dvd_triv_right not_prime_eq_prod_nat)
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   137
  done
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   138
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   139
lemma prime_nat_simp:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   140
    "prime p \<longleftrightarrow> p > 1 \<and> (\<forall>n \<in> set [2..<p]. \<not> n dvd p)"
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   141
  by (auto simp add: prime_nat_code)
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   142
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45605
diff changeset
   143
lemmas prime_nat_simp_numeral [simp] = prime_nat_simp [of "numeral m"] for m
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   144
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   145
lemma two_is_prime_nat [simp]: "prime (2::nat)"
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   146
  by simp
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   147
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   148
text\<open>A bit of regression testing:\<close>
32111
7c39fcfffd61 Tests for executability of "prime"
nipkow
parents: 32045
diff changeset
   149
58954
18750e86d5b8 reverted 1ebf0a1f12a4 after successful re-tuning of simp rules for divisibility
haftmann
parents: 58898
diff changeset
   150
lemma "prime(97::nat)" by simp
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   151
lemma "prime(997::nat)" by eval
32111
7c39fcfffd61 Tests for executability of "prime"
nipkow
parents: 32045
diff changeset
   152
32007
a2a3685f61c3 Made "prime" executable
nipkow
parents: 31996
diff changeset
   153
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   154
lemma prime_imp_power_coprime_nat: "prime p \<Longrightarrow> ~ p dvd a \<Longrightarrow> coprime a (p^m)"
62429
25271ff79171 Tuned Euclidean Rings/GCD rings
Manuel Eberl <eberlm@in.tum.de>
parents: 62410
diff changeset
   155
  by (metis coprime_exp gcd.commute prime_imp_coprime_nat)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
   156
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   157
lemma prime_imp_power_coprime_int:
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   158
  fixes a::int shows "prime p \<Longrightarrow> ~ p dvd a \<Longrightarrow> coprime a (p^m)"
62429
25271ff79171 Tuned Euclidean Rings/GCD rings
Manuel Eberl <eberlm@in.tum.de>
parents: 62410
diff changeset
   159
  by (metis coprime_exp gcd.commute prime_imp_coprime_int)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
   160
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   161
lemma primes_coprime_nat: "prime p \<Longrightarrow> prime q \<Longrightarrow> p \<noteq> q \<Longrightarrow> coprime p q"
55130
70db8d380d62 Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents: 54228
diff changeset
   162
  by (metis gcd_nat.absorb1 gcd_nat.absorb2 prime_imp_coprime_nat)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
   163
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   164
lemma primes_imp_powers_coprime_nat:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   165
    "prime p \<Longrightarrow> prime q \<Longrightarrow> p ~= q \<Longrightarrow> coprime (p^m) (q^n)"
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
   166
  by (rule coprime_exp2_nat, rule primes_coprime_nat)
27568
9949dc7a24de Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents: 27556
diff changeset
   167
62349
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   168
lemma prime_factor_nat:
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   169
  "n \<noteq> (1::nat) \<Longrightarrow> \<exists>p. prime p \<and> p dvd n"
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   170
proof (induct n rule: nat_less_induct)
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   171
  case (1 n) show ?case
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   172
  proof (cases "n = 0")
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   173
    case True then show ?thesis
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   174
    by (auto intro: two_is_prime_nat)
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   175
  next
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   176
    case False with "1.prems" have "n > 1" by simp
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   177
    with "1.hyps" show ?thesis
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   178
    by (metis One_nat_def dvd_mult dvd_refl not_prime_eq_prod_nat order_less_irrefl)
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   179
  qed
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   180
qed
23244
1630951f0512 added lcm, ilcm (lcm for integers) and some lemmas about them;
chaieb
parents: 22367
diff changeset
   181
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   182
text \<open>One property of coprimality is easier to prove via prime factors.\<close>
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   183
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
   184
lemma prime_divprod_pow_nat:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   185
  assumes p: "prime p" and ab: "coprime a b" and pab: "p^n dvd a * b"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   186
  shows "p^n dvd a \<or> p^n dvd b"
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   187
proof-
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   188
  { assume "n = 0 \<or> a = 1 \<or> b = 1" with pab have ?thesis
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   189
      apply (cases "n=0", simp_all)
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   190
      apply (cases "a=1", simp_all)
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   191
      done }
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   192
  moreover
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   193
  { assume n: "n \<noteq> 0" and a: "a\<noteq>1" and b: "b\<noteq>1"
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   194
    then obtain m where m: "n = Suc m" by (cases n) auto
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   195
    from n have "p dvd p^n" apply (intro dvd_power) apply auto done
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   196
    also note pab
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   197
    finally have pab': "p dvd a * b".
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
   198
    from prime_dvd_mult_nat[OF p pab']
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   199
    have "p dvd a \<or> p dvd b" .
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   200
    moreover
33946
fcc20072df9a removed redundant lemma
nipkow
parents: 33718
diff changeset
   201
    { assume pa: "p dvd a"
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
   202
      from coprime_common_divisor_nat [OF ab, OF pa] p have "\<not> p dvd b" by auto
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   203
      with p have "coprime b p"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
   204
        by (subst gcd.commute, intro prime_imp_coprime_nat)
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   205
      then have pnb: "coprime (p^n) b"
62429
25271ff79171 Tuned Euclidean Rings/GCD rings
Manuel Eberl <eberlm@in.tum.de>
parents: 62410
diff changeset
   206
        by (subst gcd.commute, rule coprime_exp)
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
   207
      from coprime_dvd_mult[OF pnb pab] have ?thesis by blast }
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   208
    moreover
33946
fcc20072df9a removed redundant lemma
nipkow
parents: 33718
diff changeset
   209
    { assume pb: "p dvd b"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55337
diff changeset
   210
      have pnba: "p^n dvd b*a" using pab by (simp add: mult.commute)
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31814
diff changeset
   211
      from coprime_common_divisor_nat [OF ab, of p] pb p have "\<not> p dvd a"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   212
        by auto
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   213
      with p have "coprime a p"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
   214
        by (subst gcd.commute, intro prime_imp_coprime_nat)
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   215
      then have pna: "coprime (p^n) a"
62429
25271ff79171 Tuned Euclidean Rings/GCD rings
Manuel Eberl <eberlm@in.tum.de>
parents: 62410
diff changeset
   216
        by (subst gcd.commute, rule coprime_exp)
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61762
diff changeset
   217
      from coprime_dvd_mult[OF pna pnba] have ?thesis by blast }
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   218
    ultimately have ?thesis by blast }
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30738
diff changeset
   219
  ultimately show ?thesis by blast
23983
79dc793bec43 Added lemmas
nipkow
parents: 23951
diff changeset
   220
qed
79dc793bec43 Added lemmas
nipkow
parents: 23951
diff changeset
   221
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   222
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   223
subsection \<open>Infinitely many primes\<close>
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   224
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55238
diff changeset
   225
lemma next_prime_bound: "\<exists>p. prime p \<and> n < p \<and> p <= fact n + 1"
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   226
proof-
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   227
  have f1: "fact n + 1 \<noteq> (1::nat)" using fact_ge_1 [of n, where 'a=nat] by arith
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   228
  from prime_factor_nat [OF f1]
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   229
  obtain p where "prime p" and "p dvd fact n + 1" by auto
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   230
  then have "p \<le> fact n + 1" apply (intro dvd_imp_le) apply auto done
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   231
  { assume "p \<le> n"
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   232
    from \<open>prime p\<close> have "p \<ge> 1"
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   233
      by (cases p, simp_all)
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   234
    with \<open>p <= n\<close> have "p dvd fact n"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   235
      by (intro dvd_fact)
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   236
    with \<open>p dvd fact n + 1\<close> have "p dvd fact n + 1 - fact n"
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   237
      by (rule dvd_diff_nat)
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   238
    then have "p dvd 1" by simp
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   239
    then have "p <= 1" by auto
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   240
    moreover from \<open>prime p\<close> have "p > 1"
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   241
      using prime_def by blast
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   242
    ultimately have False by auto}
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   243
  then have "n < p" by presburger
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   244
  with \<open>prime p\<close> and \<open>p <= fact n + 1\<close> show ?thesis by auto
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   245
qed
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   246
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   247
lemma bigger_prime: "\<exists>p. prime p \<and> p > (n::nat)"
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   248
  using next_prime_bound by auto
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   249
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   250
lemma primes_infinite: "\<not> (finite {(p::nat). prime p})"
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   251
proof
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   252
  assume "finite {(p::nat). prime p}"
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   253
  with Max_ge have "(EX b. (ALL x : {(p::nat). prime p}. x <= b))"
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   254
    by auto
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   255
  then obtain b where "ALL (x::nat). prime x \<longrightarrow> x <= b"
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   256
    by auto
44872
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   257
  with bigger_prime [of b] show False
a98ef45122f3 misc tuning;
wenzelm
parents: 44821
diff changeset
   258
    by auto
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   259
qed
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 31952
diff changeset
   260
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   261
subsection\<open>Powers of Primes\<close>
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   262
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   263
text\<open>Versions for type nat only\<close>
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   264
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   265
lemma prime_product:
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   266
  fixes p::nat
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   267
  assumes "prime (p * q)"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   268
  shows "p = 1 \<or> q = 1"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   269
proof -
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   270
  from assms have
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   271
    "1 < p * q" and P: "\<And>m. m dvd p * q \<Longrightarrow> m = 1 \<or> m = p * q"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 60804
diff changeset
   272
    unfolding prime_def by auto
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   273
  from \<open>1 < p * q\<close> have "p \<noteq> 0" by (cases p) auto
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   274
  then have Q: "p = p * q \<longleftrightarrow> q = 1" by auto
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   275
  have "p dvd p * q" by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   276
  then have "p = 1 \<or> p = p * q" by (rule P)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   277
  then show ?thesis by (simp add: Q)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   278
qed
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   279
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   280
lemma prime_exp:
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   281
  fixes p::nat
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   282
  shows "prime (p^n) \<longleftrightarrow> prime p \<and> n = 1"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   283
proof(induct n)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   284
  case 0 thus ?case by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   285
next
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   286
  case (Suc n)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   287
  {assume "p = 0" hence ?case by simp}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   288
  moreover
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   289
  {assume "p=1" hence ?case by simp}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   290
  moreover
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   291
  {assume p: "p \<noteq> 0" "p\<noteq>1"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   292
    {assume pp: "prime (p^Suc n)"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   293
      hence "p = 1 \<or> p^n = 1" using prime_product[of p "p^n"] by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   294
      with p have n: "n = 0"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   295
        by (metis One_nat_def nat_power_eq_Suc_0_iff)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   296
      with pp have "prime p \<and> Suc n = 1" by simp}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   297
    moreover
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   298
    {assume n: "prime p \<and> Suc n = 1" hence "prime (p^Suc n)" by simp}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   299
    ultimately have ?case by blast}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   300
  ultimately show ?case by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   301
qed
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   302
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   303
lemma prime_power_mult:
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   304
  fixes p::nat
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   305
  assumes p: "prime p" and xy: "x * y = p ^ k"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   306
  shows "\<exists>i j. x = p ^i \<and> y = p^ j"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   307
using xy
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   308
proof(induct k arbitrary: x y)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   309
  case 0 thus ?case apply simp by (rule exI[where x="0"], simp)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   310
next
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   311
  case (Suc k x y)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   312
  from Suc.prems have pxy: "p dvd x*y" by auto
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   313
  from Primes.prime_dvd_mult_nat [OF p pxy] have pxyc: "p dvd x \<or> p dvd y" .
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   314
  from p have p0: "p \<noteq> 0" by - (rule ccontr, simp)
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   315
  {assume px: "p dvd x"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   316
    then obtain d where d: "x = p*d" unfolding dvd_def by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   317
    from Suc.prems d  have "p*d*y = p^Suc k" by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   318
    hence th: "d*y = p^k" using p0 by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   319
    from Suc.hyps[OF th] obtain i j where ij: "d = p^i" "y = p^j" by blast
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   320
    with d have "x = p^Suc i" by simp
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   321
    with ij(2) have ?case by blast}
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   322
  moreover
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   323
  {assume px: "p dvd y"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   324
    then obtain d where d: "y = p*d" unfolding dvd_def by blast
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55337
diff changeset
   325
    from Suc.prems d  have "p*d*x = p^Suc k" by (simp add: mult.commute)
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   326
    hence th: "d*x = p^k" using p0 by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   327
    from Suc.hyps[OF th] obtain i j where ij: "d = p^i" "x = p^j" by blast
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   328
    with d have "y = p^Suc i" by simp
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   329
    with ij(2) have ?case by blast}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   330
  ultimately show ?case  using pxyc by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   331
qed
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   332
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   333
lemma prime_power_exp:
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   334
  fixes p::nat
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   335
  assumes p: "prime p" and n: "n \<noteq> 0"
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   336
    and xn: "x^n = p^k" shows "\<exists>i. x = p^i"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   337
  using n xn
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   338
proof(induct n arbitrary: k)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   339
  case 0 thus ?case by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   340
next
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   341
  case (Suc n k) hence th: "x*x^n = p^k" by simp
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   342
  {assume "n = 0" with Suc have ?case by simp (rule exI[where x="k"], simp)}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   343
  moreover
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   344
  {assume n: "n \<noteq> 0"
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   345
    from prime_power_mult[OF p th]
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   346
    obtain i j where ij: "x = p^i" "x^n = p^j"by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   347
    from Suc.hyps[OF n ij(2)] have ?case .}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   348
  ultimately show ?case by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   349
qed
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   350
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   351
lemma divides_primepow:
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   352
  fixes p::nat
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   353
  assumes p: "prime p"
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   354
  shows "d dvd p^k \<longleftrightarrow> (\<exists> i. i \<le> k \<and> d = p ^i)"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   355
proof
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   356
  assume H: "d dvd p^k" then obtain e where e: "d*e = p^k"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55337
diff changeset
   357
    unfolding dvd_def  apply (auto simp add: mult.commute) by blast
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   358
  from prime_power_mult[OF p e] obtain i j where ij: "d = p^i" "e=p^j" by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   359
  from e ij have "p^(i + j) = p^k" by (simp add: power_add)
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   360
  hence "i + j = k" using p prime_gt_1_nat power_inject_exp[of p "i+j" k] by simp
55215
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   361
  hence "i \<le> k" by arith
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   362
  with ij(1) show "\<exists>i\<le>k. d = p ^ i" by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   363
next
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   364
  {fix i assume H: "i \<le> k" "d = p^i"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   365
    then obtain j where j: "k = i + j"
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   366
      by (metis le_add_diff_inverse)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   367
    hence "p^k = p^j*d" using H(2) by (simp add: power_add)
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   368
    hence "d dvd p^k" unfolding dvd_def by auto}
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   369
  thus "\<exists>i\<le>k. d = p ^ i \<Longrightarrow> d dvd p ^ k" by blast
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   370
qed
b6c926e67350 Restoring some proofs from the equivalent file in Old_Number_Theory.
paulson <lp15@cam.ac.uk>
parents: 55130
diff changeset
   371
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   372
subsection \<open>Chinese Remainder Theorem Variants\<close>
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   373
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   374
lemma bezout_gcd_nat:
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   375
  fixes a::nat shows "\<exists>x y. a * x - b * y = gcd a b \<or> b * x - a * y = gcd a b"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   376
  using bezout_nat[of a b]
62429
25271ff79171 Tuned Euclidean Rings/GCD rings
Manuel Eberl <eberlm@in.tum.de>
parents: 62410
diff changeset
   377
by (metis bezout_nat diff_add_inverse gcd_add_mult gcd.commute
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   378
  gcd_nat.right_neutral mult_0)
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   379
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   380
lemma gcd_bezout_sum_nat:
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   381
  fixes a::nat
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   382
  assumes "a * x + b * y = d"
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   383
  shows "gcd a b dvd d"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   384
proof-
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   385
  let ?g = "gcd a b"
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   386
    have dv: "?g dvd a*x" "?g dvd b * y"
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   387
      by simp_all
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   388
    from dvd_add[OF dv] assms
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   389
    show ?thesis by auto
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   390
qed
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   391
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   392
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   393
text \<open>A binary form of the Chinese Remainder Theorem.\<close>
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   394
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   395
lemma chinese_remainder:
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   396
  fixes a::nat  assumes ab: "coprime a b" and a: "a \<noteq> 0" and b: "b \<noteq> 0"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   397
  shows "\<exists>x q1 q2. x = u + q1 * a \<and> x = v + q2 * b"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   398
proof-
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   399
  from bezout_add_strong_nat[OF a, of b] bezout_add_strong_nat[OF b, of a]
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   400
  obtain d1 x1 y1 d2 x2 y2 where dxy1: "d1 dvd a" "d1 dvd b" "a * x1 = b * y1 + d1"
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   401
    and dxy2: "d2 dvd b" "d2 dvd a" "b * x2 = a * y2 + d2" by blast
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   402
  then have d12: "d1 = 1" "d2 =1"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   403
    by (metis ab coprime_nat)+
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   404
  let ?x = "v * a * x1 + u * b * x2"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   405
  let ?q1 = "v * x1 + u * y2"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   406
  let ?q2 = "v * y1 + u * x2"
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   407
  from dxy2(3)[simplified d12] dxy1(3)[simplified d12]
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   408
  have "?x = u + ?q1 * a" "?x = v + ?q2 * b"
55337
5d45fb978d5a Number_Theory no longer introduces One_nat_def as a simprule. Tidied some proofs.
paulson <lp15@cam.ac.uk>
parents: 55242
diff changeset
   409
    by algebra+
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   410
  thus ?thesis by blast
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   411
qed
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   412
60526
fad653acf58f isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   413
text \<open>Primality\<close>
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   414
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   415
lemma coprime_bezout_strong:
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   416
  fixes a::nat assumes "coprime a b"  "b \<noteq> 1"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   417
  shows "\<exists>x y. a * x = b * y + 1"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   418
by (metis assms bezout_nat gcd_nat.left_neutral)
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   419
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
   420
lemma bezout_prime:
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   421
  assumes p: "prime p" and pa: "\<not> p dvd a"
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   422
  shows "\<exists>x y. a*x = Suc (p*y)"
62349
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   423
proof -
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   424
  have ap: "coprime a p"
60688
01488b559910 avoid explicit definition of the relation of associated elements in a ring -- prefer explicit normalization instead
haftmann
parents: 60526
diff changeset
   425
    by (metis gcd.commute p pa prime_imp_coprime_nat)
62349
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   426
  moreover from p have "p \<noteq> 1" by auto
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   427
  ultimately have "\<exists>x y. a * x = p * y + 1"
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   428
    by (rule coprime_bezout_strong)
7c23469b5118 cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents: 62348
diff changeset
   429
  then show ?thesis by simp    
55238
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   430
qed
7ddb889e23bd Added material from Old_Number_Theory related to the Chinese Remainder Theorem
paulson <lp15@cam.ac.uk>
parents: 55215
diff changeset
   431
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   432
end