src/HOL/Arith.thy
author nipkow
Fri May 23 09:17:26 1997 +0200 (1997-05-23)
changeset 3308 da002cef7090
parent 3235 351565b7321b
child 3366 2402c6ab1561
permissions -rw-r--r--
Added overloaded function `size' for all datatypes.
     1 (*  Title:      HOL/Arith.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1993  University of Cambridge
     5 
     6 Arithmetic operators and their definitions
     7 *)
     8 
     9 Arith = Nat +
    10 
    11 instance
    12   nat :: {plus, minus, times}
    13 
    14 consts
    15   pred      :: nat => nat
    16   div, mod  :: [nat, nat] => nat  (infixl 70)
    17   (* size of a datatype value; overloaded *)
    18   size      :: 'a => nat
    19 
    20 defs
    21   pred_def  "pred(m) == case m of 0 => 0 | Suc n => n"
    22 
    23   mod_def   "m mod n == wfrec (trancl pred_nat)
    24                           (%f j. if j<n then j else f (j-n)) m"
    25   div_def   "m div n == wfrec (trancl pred_nat) 
    26                           (%f j. if j<n then 0 else Suc (f (j-n))) m"
    27 
    28 primrec "op +" nat 
    29   "0 + n = n"
    30   "Suc m + n = Suc(m + n)"
    31 
    32 primrec "op -" nat 
    33   diff_0   "m - 0 = m"
    34   diff_Suc "m - Suc n = pred(m - n)"
    35 
    36 primrec "op *"  nat 
    37   "0 * n = 0"
    38   "Suc m * n = n + (m * n)"
    39 
    40 end