axiom-mail
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-mail] Why no mod function?


From: Alasdair McAndrew
Subject: Re: [Axiom-mail] Why no mod function?
Date: Tue, 10 Jul 2007 16:20:16 +1000

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?

-Alasdair

On 7/10/07, Bill Page <address@hidden> wrote:
On 7/9/07, Alasdair McAndrew wrote:
> Why is there no modulus function in Axiom?  Such as
>
> -13 mod 10 producing 7.
>
> There's rem, but if you want a positive value you have to tweak the result.

I guess you are looking for a function of the following type?

  mod: (Integer, PositiveInteger) -> Integer

> I can get x mod n with (x::ZMOD n)::INT but that's a bit of a kludge,

To the best of my knowledge that is how one might be expected to write
it in the Axiom interpreter. This emphasizes the notion of ZMOD(n) as
a type

(12) -> mod(i,n) == i::ZMOD(n)::Integer
                                                         Type: Void
(13) -> mod(-13,10)
   Cannot compile conversion for types involving local variables. In
      particular, could not compile the _expression_ involving :: ZMOD #2

   AXIOM will attempt to step through and interpret the code.

   (13)  7
                                            Type: PositiveInteger

The problem here is that ZMOD(n) is not a type *constant*. This is ok
in the Axiom interpreter but not in the Spad or Aldor compilers.

> and if I put it in a program the compiler doesn't like it.
>

I would suggest that in Spad you should programming something like

(24) -> mod(i,n) == (i>0 => i rem n; n + (i rem n))
   Compiled code for mod has been cleared.
   1 old definition(s) deleted for function or rule mod
                                                          Type: Void
(25) -> mod(-13,10)
   Compiling function mod with type
       (Integer,PositiveInteger) -> Integer

   (25)  7
                                            Type: PositiveInteger

If you need help with this just let me know.

Regards,
Bill Page.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]