Menu

#264 GCL / polymod bug, was: mod(-2,4) => -2 not 2

None
maybe-fixed
5
2022-11-02
2003-03-19
No

mod(-2,4) => -2

It should be 2 to be consistent with mod(2,4), mod(6,4), etc. Otherwise there are FIVE distinct values for mod(x,4) instead of four.

Maxima 5.9.0 GCL 2.5.0 mingw Windows 2000

Discussion

  • Wolfgang Jenkner

    Logged In: YES
    user_id=581700

    For both Clisp and SBCL I get

    (C1) makelist(mod(i,4),i,-4,-1);
    (D1) [0, 1, 2, - 1]

    Wolfgang

     
  • Wolfgang Jenkner

    Logged In: YES
    user_id=581700

    GCL imports some symbols for modular arithmetic from the SYSTEM
    package (see maxima-package.lisp). In particular,

    >(lisp-implementation-version)
    "GCL-2-5.2000000000000002"

    >(let ((si:modulus 4)) (si:cmod 2))
    2

    >(let ((si:modulus 4)) (si:cmod -2))
    -2

    The other lisps define this in rat3a.lisp

    * (let ((modulus 4)) (cmod 2))
    2
    * (let ((modulus 4)) (cmod -2))
    2

     
  • Robert Dodier

    Robert Dodier - 2005-12-12

    Logged In: YES
    user_id=501686

    Post-5.9.2, mod was renamed to polymod and nummod was
    renamed to mod. Relabeling this report accordingly.

     
  • Robert Dodier

    Robert Dodier - 2005-12-12
    • summary: mod(-2,4) => -2 not 2 --> polymod bug, was: mod(-2,4) => -2 not 2
     
  • Robert Dodier

    Robert Dodier - 2006-07-04
    • labels: --> Lisp Core
    • summary: polymod bug, was: mod(-2,4) => -2 not 2 --> GCL / polymod bug, was: mod(-2,4) => -2 not 2
     
  • Robert Dodier

    Robert Dodier - 2006-07-04

    Logged In: YES
    user_id=501686

    Per comment below this is a GCL-specific bug. Relabeling
    accordingly.

    Proposed solution: For GCL, instead of importing SI:CMOD,
    implement Maxima CMOD in rat3a in terms of SI:CMOD. That way
    we can get the presumed speed-up as well as consistency with
    other Lisp implementations.

    Incidentally Maxima 5.9.3cvs / gcl 2.6.7 yields:

    (%i3) makelist(polymod(i,4),i,-8,8);
    (%o3) [0, 1, - 2, - 1, 0, 1, - 2, - 1, 0, 1, 2, - 1, 0, 1,
    2, - 1, 0]

    So there are indeed just 4 distinct values, but a different
    4 than sbcl or clisp. E.g. sbcl =>

    (%i1) makelist(polymod(i,4),i,-8,8);
    (%o1) [0, 1, 2, - 1, 0, 1, 2, - 1, 0, 1, 2, - 1, 0, 1, 2, -
    1, 0]

     
  • Dan Gildea

    Dan Gildea - 2016-11-19
    • status: open --> closed
    • assigned_to: Dan Gildea
    • Group: --> None
     
  • Dan Gildea

    Dan Gildea - 2016-11-19

    Seems to be fixed now.

    Maxima branch_5_38_base_351_ge2a6f50 http://maxima.sourceforge.net
    using Lisp GNU Common Lisp (GCL) GCL 2.6.12
    (%i5)  makelist(polymod(i,4),i,-8,8);
    (%o5) [0,1,2,-1,0,1,2,-1,0,1,2,-1,0,1,2,-1,0]
    
     
  • Robert Dodier

    Robert Dodier - 2022-11-02
    • labels: Lisp Core --> mod, polymod, gcl
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,8 +1,6 @@
    -mod\(-2,4\) => -2
    +`mod(-2,4)` =>  `-2`
    
    -It should be 2 to be consistent with mod\(2,4\), mod\(6,4\), 
    -etc.  Otherwise there are FIVE distinct values for mod
    -\(x,4\) instead of four.
    +It should be 2 to be consistent with `mod(2,4)`, `mod(6,4)`,  etc.  Otherwise there are FIVE distinct values for `mod(x,4)` instead of four.
    
     Maxima 5.9.0 GCL 2.5.0 mingw Windows 2000
    
    • status: closed --> maybe-fixed
    • assigned_to: Dan Gildea --> Robert Dodier
     
  • Robert Dodier

    Robert Dodier - 2022-11-02

    Marking this "maybe fixed", I think I'd like to review this and verify the status of it.

     

Log in to post a comment.