Right, there's like a "stutter" in the inner while loop where it sometimes spits out more digits before getting back to the outer loop, so sometimes you get one or two more digits than requested.<div><br></div>
<div>That doesn't mean I understand the algorithm, i.e. why d == d1 is critical.</div><div><br><div>Kirby</div><div><br><br><div class="gmail_quote">On Sun, Dec 23, 2012 at 3:49 PM, michel paul <span dir="ltr"><<a href="mailto:pythonic.math@gmail.com" target="_blank">pythonic.math@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"><font face="tahoma,sans-serif">I realized something. This was the original version:</font><div><font face="tahoma,sans-serif"><br>
</font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote">def pi_digits():</div></div></div><div class="im"><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<div class="gmail_quote">    k, a, b, a1, b1 = 2, 4, 1, 12, 4</div></div></div></div><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote">    while True:</div>

</div></div><div class="im"><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote">        p, q, k = k*k, 2*k+1, k+1</div></div></div><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<div class="gmail_quote">        a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1</div></div></div><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote">
        d, d1 = a/b, a1/b1</div></div></div><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote">        while d == d1:</div></div></div><div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote">            yield int(d)</div></div></div></div><div class="im"><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<div class="gmail_quote">            a, a1 = 10*(a%b), 10*(a1%b1)</div></div></div><div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote">
            d, d1 = a/b, a1/b1</div></div></div></div></blockquote><div><div class="gmail_extra"><br></div><div class="gmail_extra">I forget where it came from. Like I had mentioned, I had a really bright student awhile back who was really intrigued by this, and he at one point edited it to produce the digits in binary. In the original form the generator never terminates. Somewhere along the line an edit was made to try to get it to terminate at n digits. Probably to make calling it easy to call as in list(pi_digits(n)). </div>

<div class="gmail_extra"><br></div><div class="gmail_extra">- Michel</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Sat, Dec 22, 2012 at 5:34 PM, Kirby Urner <span dir="ltr"><<a href="mailto:kurner@oreillyschool.com" target="_blank">kurner@oreillyschool.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5">Got it, no wrong digits just not always exactly the number you asked for.<br>

<br>This happens often in 3.2 as well:<br><br>>>> exp = ((n,len(list(pi_digits(n)))) for n in range(10000))  # (number asked, number got)<br>
>>> exp2 = ((a,b) for a,b in exp if a != b)  # filter on "not same"<br>>>> for i in range(10): print(next(exp2), end=", ") <br>(2, 3), (4, 5), (10, 11), (16, 17), (18, 19), (22, 23), (28, 31), (29, 31), (30, 31), (34, 36),<br>


<br>Kirby<div><div><br><br><br><div class="gmail_quote">On Sat, Dec 22, 2012 at 4:40 PM,  <span dir="ltr"><<a href="mailto:david@handysoftware.com" target="_blank">david@handysoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="arial" size="3"><p style="margin:0px;padding:0px">In each case I asked for only 79 digits, but got 79, 82, and 83 digits depending on whether I was using python 3.2, python 2.6, or python 2.6 with -Qnew, respectively. The digits all seem to be correct, but the algorithm for stopping at digit n seems to be very sensitive.</p>



<p style="margin:0px;padding:0px"> </p>
<p style="margin:0px;padding:0px">David H</p>
<p style="margin:0px;padding:0px"> <br></p></font></blockquote></div>
</div></div><br></div></div>_______________________________________________<br>
Edu-sig mailing list<br>
<a href="mailto:Edu-sig@python.org" target="_blank">Edu-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/edu-sig" target="_blank">http://mail.python.org/mailman/listinfo/edu-sig</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>==================================<br>"What I cannot create, I do not understand."</div><div><br>
</div><div>- Richard Feynman</div>==================================<br>
"Computer science is the new mathematics."<div><br></div><div>- Dr. Christos Papadimitriou<br>==================================<br></div>
</font></span></div></div></div>
<br>_______________________________________________<br>
Edu-sig mailing list<br>
<a href="mailto:Edu-sig@python.org">Edu-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/edu-sig" target="_blank">http://mail.python.org/mailman/listinfo/edu-sig</a><br>
<br></blockquote></div><br></div></div>