Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

sympy does not recognize `ceil(log2(n))` is an integer for integer `n`

Open anurudhp opened this issue 5 months ago • 0 comments

The following does not simplify (i.e. floor is not removed), because we use log2 = sympy.codegen.cfunctions.log2 which doesn't seem to play well with ceil.

import sympy
from qualtran.symbolics import ceil, log2, floor

n = sympy.Symbol('n', integer=True, positive=True)
floor(2**ceil(log2(n)))

Where I ran into this issue:

import sympy
from qualtran.symbolics import ceil, log2, bit_length

n = sympy.Symbol('n', integer=True, positive=True)
bitsize = ceil(log2(n))
bit_length(2**bitsize - 1)

Prints $\lceil \log_2 (\lfloor 2^{\lceil \log_2 (n) \rceil} \rfloor) \rceil$ instead of $\lceil \log_2 (n) \rceil$

anurudhp avatar Aug 25 '24 11:08 anurudhp