ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 29 Nov 2018 19:09:16 +0100log base 2 in sagemathhttps://ask.sagemath.org/question/44505/log-base-2-in-sagemath/ 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.Thu, 29 Nov 2018 18:08:40 +0100https://ask.sagemath.org/question/44505/log-base-2-in-sagemath/Answer by Emmanuel Charpentier for <p>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.</p>
https://ask.sagemath.org/question/44505/log-base-2-in-sagemath/?answer=44507#post-id-44507What'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](http://sagebook.gforge.inria.fr/english.html) as a prerequisite...Thu, 29 Nov 2018 18:54:54 +0100https://ask.sagemath.org/question/44505/log-base-2-in-sagemath/?answer=44507#post-id-44507Comment by dazedANDconfused for <p>What's wrong with :</p>
<pre><code>sage: log(1000,2).n()
9.96578428466209
</code></pre>
<p>Note that this isn't an <em>exact</em> answer (the exact answer <em>is</em> log(1000)/log(2)). But it's a reasonable numerical approximation of a quantity whose "exact" numerical expression would be infinite...</p>
<p>Further discussion deserves reading part III of this excellent <a href="http://sagebook.gforge.inria.fr/english.html">book</a> as a prerequisite...</p>
https://ask.sagemath.org/question/44505/log-base-2-in-sagemath/?comment=44509#post-id-44509Nice! I wasn't aware of that book.Thu, 29 Nov 2018 19:09:16 +0100https://ask.sagemath.org/question/44505/log-base-2-in-sagemath/?comment=44509#post-id-44509Answer by dazedANDconfused for <p>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.</p>
https://ask.sagemath.org/question/44505/log-base-2-in-sagemath/?answer=44506#post-id-44506You'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](http://doc.sagemath.org/html/en/reference/functions/sage/functions/log.html?highlight=log#module-sage.functions.log)Thu, 29 Nov 2018 18:52:50 +0100https://ask.sagemath.org/question/44505/log-base-2-in-sagemath/?answer=44506#post-id-44506