Menu ▾ ▴

#5382 hypergeometric([-3],[-1,-5],2) signals a Lisp division-by-zero error

closed
5
2026-10-06
2026-09-27
No

This bug was discovered by Claude Opus 5.5 and reproduced on Maxima Git commit c62924c (2026-09-26) with SBCL 2.2.9.

Where: src/hypergeometric.lisp, CLASSIFY-HYPERGEOMETRIC

The undefinedness test needs the greatest nonpositive integer in b, which gives the first zero denominator, but the loop keeps the least one (-5 instead of -1). The call is then classified as a polynomial and evaluating it divides by zero instead of returning a noun form, as hypergeometric([-3],[-1],x) already does.

Steps

  1. Verify that the existing behavior is incorrect: run the reproducer below; it gives the result under "Before the fix". Judge for yourself that this is wrong instead of relying on the ticket: where the bug allows it, try some related inputs of your own, or check the result another way, for example numerically or against the documentation. A Lisp error is wrong in itself.
  2. Edit the file src/hypergeometric.lisp as described under "Fix".
  3. Rebuild Maxima.
  4. Verify that the behavior is now correct: the reproducer gives the result under "Correct result". Judge for yourself that this is right, not only that it matches: where the bug allows it, try some related inputs of your own, including some that the fix should leave unchanged.
  5. Add the test case(s) under "Test cases" to tests/rtest_hg.mac, at the end of the file.
  6. Run the complete test suite, share tests included (make check, or run_testsuite(share_tests=true); in ./maxima-local), and check that the change breaks no test. Failures that also occur without the change (a run on the unchanged build shows which) are pre-existing and can be ignored.
  7. Add the line * \#5382 hypergeometric([-3],[-1,-5],2) signals a Lisp division-by-zero error to ChangeLog, under "Bug fixes for numbered bugs:".
  8. Commit the fix; a proposed Git commit message is under "Commit message".
  9. Push the commit. Then set this ticket's status to "closed" and add a comment naming the commit, for example Fixed by commit [1a2b3c]., with the first six characters of the commit's SHA in the brackets (git rev-parse HEAD | cut -c1-6 prints them). SourceForge links this to the commit.

Reproducer

hypergeometric([-3],[-1,-5],2);

Before the fix:

Maxima encountered a Lisp error: arithmetic error DIVISION-BY-ZERO signalled (with 2.0 instead of 2: pquotient: attempted quotient by zero.)

Correct result:

hypergeometric([-3],[-5,-1],2)

Fix

In src/hypergeometric.lisp (CLASSIFY-HYPERGEOMETRIC, "(or (eq bh nil) (< bk bh))"), replace

    ;; Let bh = the least member of b that is a negative integer. If there is
    ;; no such member, set bh = nil.

    (dolist (bk b)
      (if (and (integerp bk) (<= bk 0) (or (eq bh nil) (< bk bh))) (setq bh bk)))

with

    ;; Let bh = the greatest member of b that is a negative integer. If there is
    ;; no such member, set bh = nil.

    (dolist (bk b)
      (if (and (integerp bk) (<= bk 0) (or (eq bh nil) (> bk bh))) (setq bh bk)))

In src/hypergeometric.lisp (CLASSIFY-HYPERGEOMETRIC, ";; non-nil and ah >= bh"), replace

    ;; non-nil and ah >= bh, and each member of a and b are numbers. (We don't

with

    ;; non-nil and bh >= ah, and each member of a and b are numbers. (We don't

Test cases

Add these lines to tests/rtest_hg.mac, separated from the tests before them by two empty lines:

/* Bug #5382: "hypergeometric([-3],[-1,-5],2) signals a Lisp division-by-zero error" */

args(hypergeometric([-3],[-1,-5],2));
[[-3],[-5,-1],2]$

args(hypergeometric([-3],[-1,-5],2.0));
[[-3],[-5,-1],2.0]$

Commit message

hypergeometric.lisp: fix hypergeometric([-3],[-1,-5],2)

The undefinedness test in CLASSIFY-HYPERGEOMETRIC needs the greatest
nonpositive integer in b, which gives the first zero denominator, but
the loop kept the least one. hypergeometric([-3],[-1,-5],2) was then
taken for a polynomial and dividing by zero gave a Lisp error. It now
stays unevaluated, as hypergeometric([-3],[-1],x) does.

This fixes bug #5382.

Found and fixed by Claude Opus 5.5.

Discussion

  • Barton Willis

    Barton Willis - 2026-10-02
    • Description has changed:

    Diff:

    
    
    • assigned_to: Barton Willis
    • Priority: --> 5
     
  • Barton Willis

    Barton Willis - 2026-10-06
    • status: open --> closed
     
  • Barton Willis

    Barton Willis - 2026-10-06

    Fixed by Commit [7d3fce] . Closing this ticket.

     

    Related

    Commit: [7d3fce]


Log in to post a comment.