||integer square root, by Martin Guy's method

square_root :: num->num
square_root x 
  = loop x 0 one, x>0
  = 0, x=0
  = error "square_root of negative arg", otherwise
    where
    one = last(takewhile(<=x)(iterate (*4) 1))
    ||largest power of 4 <= x

loop :: num->num->num->num
loop op res one
  = res, one=0
  = loop op' (res' div 2) (one div 4), otherwise
    where
    (op',res')
      = (op-res-one,res+2*one), op >= res+one
      = (op,res), otherwise

||This seems to work ok -- DT
