src/HOL/Arith.thy
author pusch
Tue Feb 25 15:11:12 1997 +0100 (1997-02-25)
changeset 2681 93ed51a91622
parent 2099 c5f004bfcbab
child 2887 00b8ee790d89
permissions -rw-r--r--
definitions of +,-,* replaced by primrec definitions
clasohm@923
     1
(*  Title:      HOL/Arith.thy
clasohm@923
     2
    ID:         $Id$
clasohm@923
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1993  University of Cambridge
clasohm@923
     5
clasohm@923
     6
Arithmetic operators and their definitions
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
Arith = Nat +
clasohm@923
    10
clasohm@923
    11
instance
clasohm@923
    12
  nat :: {plus, minus, times}
clasohm@923
    13
clasohm@923
    14
consts
clasohm@1370
    15
  pred      :: nat => nat
clasohm@1370
    16
  div, mod  :: [nat, nat] => nat  (infixl 70)
clasohm@923
    17
clasohm@923
    18
defs
nipkow@2099
    19
  pred_def  "pred(m) == case m of 0 => 0 | Suc n => n"
paulson@1796
    20
paulson@1796
    21
  mod_def   "m mod n == wfrec (trancl pred_nat)
clasohm@1475
    22
                          (%f j. if j<n then j else f (j-n)) m"
paulson@1796
    23
  div_def   "m div n == wfrec (trancl pred_nat) 
clasohm@1475
    24
                          (%f j. if j<n then 0 else Suc (f (j-n))) m"
pusch@2681
    25
pusch@2681
    26
pusch@2681
    27
primrec "op +" nat 
pusch@2681
    28
"0 + n = n"
pusch@2681
    29
"Suc m + n = Suc(m + n)"
pusch@2681
    30
pusch@2681
    31
pusch@2681
    32
primrec "op -" nat 
pusch@2681
    33
"m - 0 = m"
pusch@2681
    34
"m - Suc n = pred(m - n)"
pusch@2681
    35
pusch@2681
    36
primrec "op *"  nat 
pusch@2681
    37
"0 * n = 0"
pusch@2681
    38
"Suc m * n = n + (m * n)"
pusch@2681
    39
pusch@2681
    40
clasohm@923
    41
end
clasohm@923
    42
clasohm@923
    43
(*"Difference" is subtraction of natural numbers.
clasohm@923
    44
  There are no negative numbers; we have
clasohm@972
    45
     m - n = 0  iff  m<=n   and     m - n = Suc(k) iff m)n.
berghofe@1824
    46
  Also, nat_rec(0, %z w.z, m) is pred(m).   *)
clasohm@923
    47