src/HOL/ex/Primes.thy
author paulson
Thu, 09 Jan 1997 10:22:42 +0100
changeset 2498 7914881f47c0
parent 1804 cfa0052d5fe9
child 3242 406ae5ced4e9
permissions -rw-r--r--
New theorem add_leE
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
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     6
The "divides" relation, the greatest common divisor and Euclid's algorithm
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     7
*)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     8
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
     9
Primes = Arith +
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    10
consts
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    11
  dvd     :: [nat,nat]=>bool              (infixl 70) 
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    12
  gcd     :: [nat,nat,nat]=>bool          (* great common divisor *)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    13
  egcd    :: [nat,nat]=>nat               (* gcd by Euclid's algorithm *)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    14
  coprime :: [nat,nat]=>bool              (* coprime definition *)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    15
  prime   :: nat=>bool                    (* prime definition *)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    16
  
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    17
defs
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    18
  dvd_def     "m dvd n == EX k. n = m*k"
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    19
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    20
  gcd_def     "gcd p m n == ((p dvd m) & (p dvd n))   &
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    21
               (ALL d. (d dvd m) & (d dvd n) --> d dvd p)"
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    22
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    23
  egcd_def    "egcd m n ==   
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    24
               wfrec (pred_nat^+)
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    25
                     (%f n m. if n=0 then m else f (m mod n) n) n m"
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    26
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    27
  coprime_def "coprime m n == egcd m n = 1"
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    28
cfa0052d5fe9 New example of greatest common divisor
paulson
parents:
diff changeset
    29
  prime_def   "prime(n) == (1<n) & (ALL m. 1<m & m<n --> ~(m dvd n))"
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