Re: Why no mod function?
"Alasdair McAndrew" <[email protected]>
| Newsgroups | gmane.comp.mathematics.axiom.user |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> 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. > _______________________________________________ Axiom-mail mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/axiom-mail