Open DaveWitteMorris opened 1 week ago
Probably because log(2, 0) = log(2)/log(0) = log(2)/(-Infinity) = 0
.
We do have $\lim_(x → 0) \log(2)/\log(x) = 0$ anyway, so the behavior is not entirely unreasonable. Besides, the change breaks backwards compatibility.
On the other hand the behavior is not entirely consistent either:
sage: 8.log(0)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
...
ValueError: log base must be positive
sage: (8.0).log(0.0)
-0.000000000000000
But:
sage: (8).log(-2)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
...
ValueError: log base must be positive
sage: (8.0).log(-2.0)
0.139260970636224 - 0.631180872623791*I
And:
sage: log(8, oo)
0
Meanwhile the documentation of log
says
Signature: log(*args, **kwds)
Docstring:
Return the logarithm of the first argument to the base of the
second argument which if missing defaults to "e".
It calls the "log" method of the first argument when computing the
logarithm, thus allowing the use of logarithm on any object
containing a "log" method. In other words, "log" works on more than
just real numbers.
Because of the limit interpretation, the value of 0 probably makes sense to a physicist (or engineer), but I think it is clearly incorrect from a mathematical point of view, because the definition of log
is: b^log(a,b) = a
and this is clearly not true when b = 0
. (If someone wants a limit, they can take a limit.) So I think the current behaviour counts as a bug and needs to be changed (even if it breaks some code).
If anyone thinks this may be controversial, we should ask for opinions on sage-devel.
Actually, since the change could break code (and the bug has been around for a long time, so fixing it is not urgent), I think the first step would be to deprecate the use of 0 as a base. (I expect 10.5 to be released soon, so I think this will have to wait for 10.6.) A year later, we can make it raise an error. Probably the deprecation should be mentioned on sage-devel, to see if there are any objections.
There's also the issue that testing if a symbolic expression is zero is a very nontrivial problem, but I'm not sure this is a serious roadblock here.
Steps To Reproduce
No response
Expected Behavior
Logarithms with a base of 0 do not exist, so trying to calculate one should raise a
ValueError
.Actual Behavior
Sagemath seems to think that logarithms with a base of 0 are equal to 0:
Additional Information
No response
Environment
Checklist