src/HOL/ex/Primes.thy
author paulson
Fri, 30 May 1997 15:23:49 +0200
changeset 3376 0cc2eaa8b0f9
parent 3242 406ae5ced4e9
child 3495 04739732b13e
permissions -rw-r--r--
Now "primes" is a set
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     1
(*  Title:      HOL/ex/Primes.thy
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     2
    ID:         $Id$
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     3
    Author:     Christophe Tabacznyj and Lawrence C Paulson
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     5
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
     6
The Greatest Common Divisor and Euclid's algorithm
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     7
*)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     8
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
     9
Primes = Divides + WF_Rel +
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    10
consts
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    11
  is_gcd  :: [nat,nat,nat]=>bool          (*gcd as a relation*)
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    12
  gcd     :: "nat*nat=>nat"               (*Euclid's algorithm *)
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    13
  coprime :: [nat,nat]=>bool
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
    14
  prime   :: nat set
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    15
  
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    16
recdef gcd "measure ((%(x,y).y) ::nat*nat=>nat)"
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    17
    "gcd (m, n) = (if n=0 then m else gcd(n, m mod n))"
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    18
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    19
defs
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    20
  is_gcd_def  "is_gcd p m n == p dvd m  &  p dvd n  &
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    21
                               (ALL d. d dvd m & d dvd n --> d dvd p)"
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    22
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    23
  coprime_def "coprime m n == gcd(m,n) = 1"
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    24
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
    25
  prime_def   "prime == {p. 1<p & (ALL m. m dvd p --> m=1 | m=p)}"
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    26
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    27
end