src/HOL/ex/Primes.thy
author paulson
Thu, 08 Jul 1999 13:48:11 +0200
changeset 6921 78a2ce8fb8df
parent 6455 34c6c2944908
child 8698 8812dad6ef12
permissions -rw-r--r--
Renaming of theorems from _nat0 to _int0 and _nat1 to _int1
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
04739732b13e New comments on how to deal with unproved termination conditions
paulson
parents: 3376
diff changeset
     8
The "simpset" clause in the recdef declaration is omitted on purpose:
04739732b13e New comments on how to deal with unproved termination conditions
paulson
parents: 3376
diff changeset
     9
	in order to demonstrate the treatment of definitions that have
04739732b13e New comments on how to deal with unproved termination conditions
paulson
parents: 3376
diff changeset
    10
	unproved termination conditions.  Restoring the clause lets
04739732b13e New comments on how to deal with unproved termination conditions
paulson
parents: 3376
diff changeset
    11
	Isabelle prove those conditions.
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    12
*)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    13
6455
34c6c2944908 Main is the correct parent
paulson
parents: 5184
diff changeset
    14
Primes = Main +
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    15
consts
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    16
  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
    17
  gcd     :: "nat*nat=>nat"               (*Euclid's algorithm *)
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    18
  coprime :: [nat,nat]=>bool
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
    19
  prime   :: nat set
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    20
  
3495
04739732b13e New comments on how to deal with unproved termination conditions
paulson
parents: 3376
diff changeset
    21
recdef gcd "measure ((%(m,n).n) ::nat*nat=>nat)"
6455
34c6c2944908 Main is the correct parent
paulson
parents: 5184
diff changeset
    22
(*  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
    23
    "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
    24
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    25
defs
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    26
  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
    27
                               (ALL d. d dvd m & d dvd n --> d dvd p)"
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    28
3242
406ae5ced4e9 Renamed egcd and gcd; defined the gcd function using TFL
paulson
parents: 1804
diff changeset
    29
  coprime_def "coprime m n == gcd(m,n) = 1"
1804
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    30
3376
0cc2eaa8b0f9 Now "primes" is a set
paulson
parents: 3242
diff changeset
    31
  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
    32
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    33
end