Re: Integer residue-classes [was: Questions about srfi-77 Generic Arithmetic] Bradley Lucier 26 Feb 2006 17:09 UTC

About certain issues that have been raised recently on this list (and
some other random observations):

1.  I now understand Egner et al.'s  motivation of having (div x 0)
=> 0 and (mod x 0) => x. I still disagree with having it in a
programming language; see (2).

2.  If someone passes 0 as the second argument to a division/quotient/
remainder/modulo/div/mod operator, I think it is infinitely more
likely to be an error than to mean return 0 (as div) or return the
first argument (as mod), because the programmer was thinking of the
result of the homomorphism of mapping the integers onto the quotient
ring of the integers by the zero ideal (which again happens to be
isomorphic to the integers).

3.  I agree with Bawden and Egner et al. that there should be a
division operator associated with the modulo operation, in the same
way that current quotient is related to current remainder.

4.  I cannot remember any argument to say that the modulo function
(mod x n) with representatives from -n/2 (inclusive) to n/2
(exclusive) is of use in programs.  I can't think of any examples
where it's useful.  Furthermore, the only reason I can remember which
end of the interval containing the result is inclusive is because of
an analogy with hardware implementations of twos complement
arithmetic, so I think that perhaps there is no natural choice of
which endpoint is inclusive.

5.  I still really dislike choosing what operation is done by the
sign of the second argument.

6.  I think (quotient x n) => (round-to-zero (/ x n)) is a natural
operator for those who've been taught long division in school; and so
I find no problem with the associated operator (remainder x n) => (-
x (* n (quotient x n))).

7.  When n is positive, the (mathematical) modulo operation has the
definition (modulo x n) => (- x (* n (floor (/ x n)))).  The current
definition in Scheme of modulo retains this definition for negative
n, which I have no problem with (but I'm open to considering other
options).  So, like I said in (3) above, I would welcome a new
operator that implements the operation (/ (- x (modulo x n)) n),
whatever the definition of modulo.

Brad