| 1 | initial version |
It seems log(int(n), 2) fails for a specific set of values of n.
Take n of the form 2^a * (k * 2^b + 1) where a + b = 32, 2 <= a <= 30, k >= 1.
Then log(int(n), 2) incorrectly returns a.
The smallest instance would be for 2^2 * (2^30 + 1) ie 4294967300.
| 2 | No.2 Revision |
Yes, this is a bug.
It seems log(int(n), 2) fails for a specific set of values of n.
Take n of the form 2^a * (k * 2^b + 1) where a + b = 32, 2 <= a <= 30, k >= 1.
Then log(int(n), 2) incorrectly returns a.
The smallest instance would be for 2^2 * (2^30 + 1) ie 4294967300.
Similar past bug: https://github.com/sagemath/sage/issues/25979.
| 3 | No.3 Revision |
Yes, this is a bug.
It seems log(int(n), 2) fails for a specific set of values of n.
Take of the form n2^a * (k * 2^b + 1) where a + b = 32, a, b, k with 2 <= a <= 30, a + b = 32, k >= 1.
Then incorrectly returns log(int(n), log(int(2^a * (k * 2^b + 1)), 2)a.
The smallest instance would be for Smallest case: 2^2 * (2^30 + 1) ie 4294967300.
If n is an int, calling log(n, 2) calls logb(n, 2).
So the following illustrates the bug for each (a, b) and the first few k.
sage: from sage.functions.log import logb
sage: n_py = lambda a, b: int(2)**a * int(b)
sage: n_zz = lambda a, b: ZZ(2)**a * ZZ(b)
sage: f_py = lambda a, b: logb(n_py(a, b), 2)
sage: f_zz = lambda a, b: logb(n_zz(a, b), 2)
sage: mismatch = lambda a, b: f_py(a, b) != f_zz(a, b)
sage: aa = range(2, 31)
sage: kk = range(1, 4)
sage: ab = [(a, k * c + 1) for a in aa for c in [2**(32 - a)] for k in kk)
sage: all(mismatch(a, b) for a, b in ab)
True
sage: min((2**a * b, (a, b)) for a, b in ab)
(4294967300, (2, 1073741825))
Similar past bug: https://trac.sagemath.org/ticket/25979/,
moved to https://github.com/sagemath/sage/issues/25979.
| 4 | No.4 Revision |
Yes, this is a bug.
It seems log(int(n), 2) fails for a specific set of values of n.
Take a, b, k with 2 <= a <= 30, a + b = 32, k >= 1.
Then log(int(2^a * (k * 2^b + 1)), 2) incorrectly returns a.
Smallest case: 2^2 * (2^30 + 1) ie 4294967300.
If n is an int, calling log(n, 2) calls logb(n, 2).
So the following illustrates the bug for each (a, b) and the first few k.
sage: from sage.functions.log import logb
sage: n_py = lambda a, b: int(2)**a * int(b)
sage: n_zz = lambda a, b: ZZ(2)**a * ZZ(b)
sage: f_py = lambda a, b: logb(n_py(a, b), 2)
sage: f_zz = lambda a, b: logb(n_zz(a, b), 2)
sage: mismatch = lambda a, b: f_py(a, b) != f_zz(a, b)
sage: aa = range(2, 31)
sage: kk = range(1, 4)
sage: ab = [(a, k * c + 1) for a in aa for c in [2**(32 - a)] for k in kk)
sage: all(mismatch(a, b) for a, b in ab)
True
sage: min((2**a * b, (a, b)) for a, b in ab)
(4294967300, (2, 1073741825))
Similar past bug: https://trac.sagemath.org/ticket/25979/,
moved to https://github.com/sagemath/sage/issues/25979.
Edit. The logb function in sage.functions.log calls Ginac's log
which lives in the file src/sage/symbolic/ginac/inifcns_trans.cpp
currently at
| 5 | No.5 Revision |
Yes, this is a bug.
It seems log(int(n), 2) fails for a specific set of values of n.
Take a, b, k with 2 <= a <= 30, a + b = 32, k >= 1.
Then log(int(2^a * (k * 2^b + 1)), 2) incorrectly returns a.
Smallest case: 2^2 * (2^30 + 1) ie 4294967300.
If n is an int, calling log(n, 2) calls logb(n, 2).
So the following illustrates the bug for each (a, b) and the first few k.
sage: from sage.functions.log import logb
sage: n_py = lambda a, b: int(2)**a * int(b)
sage: n_zz = lambda a, b: ZZ(2)**a * ZZ(b)
sage: f_py = lambda a, b: logb(n_py(a, b), 2)
sage: f_zz = lambda a, b: logb(n_zz(a, b), 2)
sage: mismatch = lambda a, b: f_py(a, b) != f_zz(a, b)
sage: aa = range(2, 31)
sage: kk = range(1, 4)
sage: ab = [(a, k * c + 1) for a in aa for c in [2**(32 - a)] for k in kk)
sage: all(mismatch(a, b) for a, b in ab)
True
sage: min((2**a * b, (a, b)) for a, b in ab)
(4294967300, (2, 1073741825))
Similar past bug: https://trac.sagemath.org/ticket/25979/,
moved to https://github.com/sagemath/sage/issues/25979.
Edit. The logb function in sage.functions.log calls Ginac's log
which lives in .
Not sure whether it is the file one in src/sage/symbolic/ginac/numeric.cpp or src/sage/symbolic/ginac/inifcns_trans.cpp
currently at, see
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.