<div dir="ltr">A trick I use when I need lots of digits is to calculate the number using a series expansion.<div><br></div><div>If you calculate it using e.g. Rational, you can then get arbitrary precision and print an arbitrary number of digits.<br><div><br></div><div>Here are a few examples. I've calculated both e and pi, accurate to 1000 digits. It takes about 2.3 seconds to run on my laptop.</div><div><br></div><div><a href="https://gist.github.com/wyager/33dcc26d1e867c462808">https://gist.github.com/wyager/33dcc26d1e867c462808</a><br></div><div><br></div><div>It's also very easy to adapt to non-decimal bases.</div><div><br></div><div>Will</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 18, 2015 at 2:20 PM, Jeffrey Brown <span dir="ltr"><<a href="mailto:jeffbrown.the@gmail.com" target="_blank">jeffbrown.the@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks everybody! It turns out <a href="https://www.reddit.com/r/piano/comments/3uz8oj/the_melody_of_pi_226_digits_chromatic_%CF%80_base_12/cy39b5g" target="_blank">WolframAlpha will do the computation</a> for me. (It won't let me copy the digits, so I have to transcribe them by hand, but given how much time I'm spending reviewing the notes anyway, that is a small part of the overall labor cost.)</div><div class="gmail_extra"><span class=""><br><div class="gmail_quote">On Fri, Dec 18, 2015 at 4:31 AM, Olaf Klinke <span dir="ltr"><<a href="mailto:olf@aatal-apotheke.de" target="_blank">olf@aatal-apotheke.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As it happens, I am just studying a presentation [1] Martin Escardo gave to students at the University of Birmingham. It contains Haskell code for exact real number computation. Among other things, there is a function that computes a signed digit representation of pi/32. It computes several thousand digits in a few seconds.<br>
I did not try it yet, but many irrational numbers are fixed points of simple arithmetical expressions. For example, the golden ratio is the fixed point of \x -> 1+1/x. Infinite streams of digits should be a type where such a fixed point is computable. Or you could use a sufficiently precise rational approximation and convert that do decimal in the usual way.<br>
<br>
import Data.Ratio<br>
import Data.List (iterate)<br>
<br>
-- one step of Heron's algorithm for sqrt(a)<br>
heron :: (Fractional a) => a -> a -> a<br>
heron a x = (x+a/x)/2<br>
<br>
-- infinite stream of approximations to sqrt(a)<br>
approx :: (Fractional a) => a -> [a]<br>
approx a = iterate (heron a) 1<br>
<br>
-- Find an interval with rational end-points<br>
-- for a signed-digit real number<br>
type SDReal = [Int] -- use digits [-1,0,1]<br>
interval :: Int -> SDReal -> (Rational,Rational)<br>
interval precision x = let<br>
  f = foldr (\d g -> (a d).g) id (take precision x))<br>
  a d = \x -> ((fromIntegral d)+x)/2<br>
  in (f(-1),f(1))<br>
<br>
Cheers,<br>
Olaf<br>
<br>
[1] <a href="http://www.cs.bham.ac.uk/~mhe/.talks/phdopen2013/realreals.lhs" rel="noreferrer" target="_blank">www.cs.bham.ac.uk/~mhe/.talks/phdopen2013/realreals.lhs</a></blockquote></div><br><br clear="all"><div><br></div></span><span class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr">Jeffrey Benjamin Brown</div></div>
</font></span></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>