Menu

#4337 Function multiplies-in-nth-power in expense.lisp is broken

None
open
nobody
None
5
2024-09-09
2024-08-01
No

Hi,
the function multiplies-in-nth-power in expense.lisp is broken because the loop runs indefinitely which results in the error
"The value 4611686018427387904 is not of type FIXNUM"

I propose the following fix:

(defun multiplies-in-nth-power (n)
  "Calculate the number of multiplications required to compute a^n."
  (let ((multiplications 0)
        (power n))
    (while (> power 1)
      (if (evenp power)
          (progn
            (setq power (/ power 2))
            (incf multiplications)) ; Counting the squaring operation
          (progn
            (setq power (- power 1))
            (incf multiplications) ; Counting the multiplication to reduce the power
            )))
    (cond ((< multiplications $cost_float_power) multiplications)
                       (t $cost_float_power))     
    ))

I am not 100% what exactly the function is supposed to do but I think the proposed fix captures the indented functionality reasonably well.

The function is needed by reducon.

I this is helpful, I could also prepare a pull request. If so, should I clone the project on github?

Cheers,
Jens

Discussion

  • Stavros Macrakis

    It would be good to include some Maxima-level (not Lisp) tests to include in the test suite.

     
  • Jens Geisler

    Jens Geisler - 2024-08-03

    Yes, I could write a test. Could you point me to an example how such a test should look like?

     
    • Stavros Macrakis

      Tests are found in .../share/maxima/5.47.0/tests/ and there is a README.how-to.

      Basically, you provide an input and a correct output, both in linear format (display2d=false or string(...)), e.g.,

      integrate(x^3,x);
      x^4/4;
      

      If there is a corresponding bug report at sourceforge, reference it in a comment:

      /* See SF Bug # 123456 */
      integrate(x^3,x);
      x^4/4;
      

      See the README for more info.

             -s
      
       

      Last edit: Robert Dodier 2024-08-18
  • Robert Dodier

    Robert Dodier - 2024-08-18
     
  • Robert Dodier

    Robert Dodier - 2024-08-18

    Jens, thanks for the bug report, and thanks for volunteering to fix it. Sourceforge has what they call "merge requests" instead of "pull requests", but the general idea is the same. You will have to look up the SF documentation for merge requests as I don't remember the steps at the moment. You can send a message to the maxima-discuss mailing list (https://sourceforge.net/projects/maxima/lists/maxima-discuss) to ask for information for any purpose.

     
  • Jens Geisler

    Jens Geisler - 2024-09-09

    Hi, I have now submitted a merge request for the fix including an rtest. I hope this works for you and I did everything correctly.

     

Log in to post a comment.