[Chicago] Latest hack

Joshua Herman zitterbewegung at gmail.com
Tue Apr 9 18:45:45 CEST 2013


If you represent the number symbolically as an equation and then do
arbitrary precision calculations when you need the nth digit as a number
then that is a practical way of doing things. Most computer algebra systems
do this and I think sympy does this too http://sympy.org/en/index.html .
Usually you have a function that you call that gets the digit
representation.

---Profile:---
http://www.google.com/profiles/zitterbewegung



On Tue, Apr 9, 2013 at 11:02 AM, kirby urner <kirby.urner at gmail.com> wrote:

> This is slightly branching to a connected topic, still philosophy of real
> numbers:
>
> *def pi_digits():
> **    k, a, b, a1, b1 = 2, 4, 1, 12, 4
>     while True:**        p, q, k = k*k, 2*k+1, k+1**        a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1**        d, d1 = a/b, a1/b1**        while d == d1:**            yield int(d)**            a, a1 = 10*(a%b), 10*(a1%b1)**            d, d1 = a/b, a1/b1
>
> >>> from anyproject import pi_digits
> >>> pigen = pi_digits()
> >>> "".join([str(next(pigen)) for x in range(100)])
> '3141592653589793238462643383279502884197169399375105820
>
>
> 974944592307816406286208998628034825342117067'
>
> *
>
> *Validation check:
> http://www.eveandersson.com/pi/digits/100
>
> *
>
> Pretty cool huh?
>
> We've been kicking it around on edu-sig [1] but none there are the author
> and none have explained how it works.
>
> Michel Paul, a high school mathematics teacher who "gets it" (one of the
> "abducted" who uses Python and related tools in the math curriculum), said
> it came from one of his students, but I don't know if the student claimed
> authorship either.
>
> Does anyone here in Chicago area recognize the above algorithm? [2]
>
> "Real Numbers" is a nice unifying heuristic, but sometimes a "number" is
> just a Python generator in disguise.
>
> Kirby
>
> [1]  http://mail.python.org/pipermail/edu-sig/2012-December/date.html
>
>  [2]  At the risk of being tedious:
>
> Compare:
>
> http://www.factmonster.com/ipka/A0876705.html
>
>
> >>> f = open("pi.txt","w")
> >>> pigen = pi_digits()
> >>> print("".join([str(next(pigen)) for x in range(1000)]), file=f)  #
> Python3
> >>> f.close()
>
> Last few digits of pi.txt:  9216420198  match!
>
> On Tue, Apr 9, 2013 at 7:05 AM, Jonathan Hayward <
> jonathan.hayward at pobox.com> wrote:
>
>> I have posted "ABSOLUTE Precision Arithmetic and Arbitrary Precision
>> OUTPUT" at http://JonathansCorner.com/arithmetic/ .
>>
>> "Arbitrary precision arithmetic" usually means "something like a float,
>> but you can choose the number of decimal places." The same corruption
>> issues appear as with floats, but you can choose a longer fuse, in many
>> cases long enough to get your work done.
>>
>
>
>> This is a slightly different approach, and any comments would be welcome.
>>
>>
>>
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> http://mail.python.org/mailman/listinfo/chicago
>>
>>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20130409/a27d08d5/attachment.html>


More information about the Chicago mailing list