Ask Your Question
1

log base 2 in sagemath

asked 2018-11-29 11:08:40 -0600

panther gravatar image

How to compute log base 2 in sagemath? I tried log(1000,2). It answers log(1000)/log(2). I want an exact numerical answer.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2018-11-29 11:54:54 -0600

Emmanuel Charpentier gravatar image

What's wrong with :

sage: log(1000,2).n()
9.96578428466209

Note that this isn't an exact answer (the exact answer is log(1000)/log(2)). But it's a reasonable numerical approximation of a quantity whose "exact" numerical expression would be infinite...

Further discussion deserves reading part III of this excellent book as a prerequisite...

edit flag offensive delete link more

Comments

Nice! I wasn't aware of that book.

dazedANDconfused gravatar imagedazedANDconfused ( 2018-11-29 12:09:16 -0600 )edit
2

answered 2018-11-29 11:52:50 -0600

dazedANDconfused gravatar image

updated 2018-11-29 11:56:04 -0600

You've done it correctly and SAGE gives you the exact answer. If you try log(8,2) you'll get 3 because that's the exact answer and no logs are required. To force a numerical answer try, for example log(1000,2).n(digits=9) to get an approximate answer of 9.96578429. You can check if that's close by typing 2^9.96578429 to get 1000.00000369996. Want a closer answer? Change to digits=12 and repeat. Same thing with other functions such as sqrt(2).n(digits=4)

Alternatively, the documentation gives n(log(1000,2)) which gives you the approximation 9.96578428466209 with less key strokes. You can find the log function documentation here

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-11-29 11:08:40 -0600

Seen: 51 times

Last updated: Nov 29