|
From: | Alasdair McAndrew |
Subject: | Re: [Axiom-mail] Why no mod function? |
Date: | Wed, 11 Jul 2007 17:31:19 +1000 |
Well, positiveRemainder should be renamed "mod". Also, addmod, submod, mulmod assume that their first two parameters are positive, which is an unreasonable restriction. For example:
(1) -> addmod(-13,0,10)
(1) - 13
(2) -> mulmod(-13,1,10)
(2) - 3
(3) -> submod(-13,0,10)
(3) - 3
(4) -> submod(0,13,10)
(4) -3
In fact, there should be two mod commands: x mod n, which produces a result between 0 and n-1, and x bmod n (for "balanced mod") which produces a result between -(n-1)/2 and (n-1)/2 if n is odd, and between -(n-2)/2 and n/2 if n is even.
Looking through si.spad, it could easily be extended by
x mod y == MOD(x,y)$Lisp::INT
or some such.
cheers,
AlasdairOn 7/11/07, Bill Page <address@hidden> wrote:On 7/10/07, Alasdair McAndrew wrote:
> Yes, that's pretty much what I did. But surely such an important function
> as mod should be available without having to write it yourself?
> ...
Digging a little deeper I found in the domain 'Integer':
(1) -> positiveRemainder(-13,10)
(1) 7
Type: PositiveInteger
I presume this is what you were looking for?
Also take a look at
(2) -> addmod(13,1,10)
(2) 4
Type: PositiveInteger
(3) -> submod(13,1,10)
(3) 12
Type: PositiveInteger
(4) -> mulmod(13,2,10)
(4) 6
Type: PositiveInteger
Regards,
Bill Page.
[Prev in Thread] | Current Thread | [Next in Thread] |