src/HOL/ex/Primes.thy
author paulson
Tue, 23 May 2000 18:08:52 +0200
changeset 8936 a1c426541757
parent 8698 8812dad6ef12
child 9824 c6eee0626d28
permissions -rw-r--r--
Now that 0 is overloaded, constant "zero" and its type class "zero" are no longer needed. Also IntRingDefs is redundant
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
3495
04739732b13e New comments on how to deal with unproved termination conditions
paulson
parents: 3376
diff changeset
     7
8698
8812dad6ef12 made mod_less_divisor a simplification rule.
nipkow
parents: 6455
diff changeset
     8
The "simpset" clause in the recdef declaration used to be necessary when the
8812dad6ef12 made mod_less_divisor a simplification rule.
nipkow
parents: 6455
diff changeset
     9
two lemmas where not part of the default simpset.
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    10
*)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    11
6455
34c6c2944908 Main is the correct parent
paulson
parents: 5184
diff changeset
    12
Primes = Main +
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    13
consts
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    14
  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
    15
  gcd     :: "nat*nat=>nat"               (*Euclid's algorithm *)
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    16
  coprime :: [nat,nat]=>bool
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
    17
  prime   :: nat set
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    18
  
3495
04739732b13e New comments on how to deal with unproved termination conditions
paulson
parents: 3376
diff changeset
    19
recdef gcd "measure ((%(m,n).n) ::nat*nat=>nat)"
6455
34c6c2944908 Main is the correct parent
paulson
parents: 5184
diff changeset
    20
(*  simpset "simpset() addsimps [mod_less_divisor, zero_less_eq]" *)
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    21
    "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
    22
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    23
defs
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    24
  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
    25
                               (ALL d. d dvd m & d dvd n --> d dvd p)"
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    26
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    27
  coprime_def "coprime m n == gcd(m,n) = 1"
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    28
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
    29
  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
    30
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    31
end