sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.46k stars 482 forks source link

log(int(0), 2) hangs #38969

Closed katestange closed 1 week ago

katestange commented 1 week ago

Steps To Reproduce

In Sage 10.5.beta6 in Jupyter notebook, or on https://sagecell.sagemath.org/ (as of today), run:

for i in range(1):
    floor(log(i,2))

and the kernel appears to hang.

Expected Behavior

By contrast, the supposedly equivalent command

floor(log(0,2))

gives an error ValueError: Calling floor() on infinity or NaN which is the expected behaviour.

Actual Behavior

Kernel appears to hang. Becomes unresponsive, even to user interrupt. Must restart.

Additional Information

No response

Environment

Checklist

DaveWitteMorris commented 1 week ago

Thanks for the bug report. I confirm the error (in 10.5.b9 on intel MacOS 14.8.1).

The two commands are not equivalent, because range returns python integers, whereas floor(log(0,2)) is preparsed to replace 0 with Integer(0) so it is taking the log of a sage integer, not a python integer. The equivalent command is floor(log(int(0), 2)) which does hang. For a for loop that does not hang (because it uses sage integers), change range to srange.

The minimal example seems to be log(int(0), 2), which puts sage into an uninterruptible hang.

DaveWitteMorris commented 1 week ago

This is a duplicate of #37794.