Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logarithm with base 0 should raise an error #38971

Open
2 tasks done
DaveWitteMorris opened this issue Nov 15, 2024 · 4 comments
Open
2 tasks done

logarithm with base 0 should raise an error #38971

DaveWitteMorris opened this issue Nov 15, 2024 · 4 comments
Labels

Comments

@DaveWitteMorris
Copy link
Member

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:

sage: log(2, 0)
0
sage: log(2.0, 0)
-0.000000000000000
sage: log(x, 0)
0

Additional Information

No response

Environment

  • OS: MacOS 14.6.1
  • Sage Version: 10.5.b9

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@user202729
Copy link
Contributor

user202729 commented Nov 16, 2024

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.

@DaveWitteMorris
Copy link
Member Author

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.

@DaveWitteMorris
Copy link
Member Author

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.

@user202729
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants