Live data from Hacker News

Multiple ways to compute e in Raku

blogs.perl.org

21–30 of 41 posts

Re: Multiple ways to compute e in Raku

#21
post #12

Earlier quoted context omitted.

Perl 5 will continue to be the official "Perl". Development on that continues, and it has an extensive community, though not nearly as large as Python, which was once its peer. What was Perl 6 will, moving forward, be known as "Raku".

Is that a "yes it is"?

No, it isn't.

Re: Multiple ways to compute e in Raku

#22
Computing e to thousands of decimal places is an interesting exercise for the mathematically inclined students in a beginning programming class. If you use the ∑1/n! series you can fairly easily do it even in a language that does not have built in arbitrary precision or an arbitrary precision library.

Let's say you want to deal with numbers to 1000 decimal places. Pick a base that is a power of 10, such as 10000. Represent a number as an array of 251 base 10000 digits, with the first item of the array being the integer part, and the remaining 250 being 250 base 10000 "decimal" digits.

You need two of these arrays. One represents 1/n!, and the other is the cumulative sum of the series so far.

You need two large precision operations. To go from 1/n! to 1/(n+1)! involves simply dividing by n+1. As long as we limit n+1 to under 10000, we only have to handle division with a single digit denominator. Limiting n thusly is not a problem--it's enough to actually support calculating e to over 35000 decimal places, so our modest goal of 1000 is no problem.

Implement the division exactly like you would do division by a single digit with pencil and paper. The only thing you have to worry about is dealing with carry. You can have intermediate values as large as the carry x the base + base - 1, and since carry can be as large as base - 1, this means you can have intermediate values as large as base^2 - 1. Just pick base (10000 in my example) so that base^2 - 1 doesn't overflow the basic integer type of the language you are using.

The other large precision operation you need is addition, to accumulate the result from the division into the sum. Same as with division--just write it using the same algorithm you would use with pencil and paper. Add digits right to left, with carry.

By using a base that is a power of 10, it is easy to figure out the base 10 representation of the final result for printing.

Re: Multiple ways to compute e in Raku

#23
post #11

> Maksymilian Piskorowski found that if you happen to have a spare eight 9s, you can compute 𝑒 = (9/9 + 9^(-9^9))^(9^(9^9)), which is accurate to a little over 369 million decimal places. Sure, because 9/9 = 1 and if you take x = 9^9^9, you get back (1 + x^(-1))^x, i.e. the first formula. It's cute, but I don't know if you could call it a "discovery".

You can see the formula Piskorowski used here [0], under "Best Approximations to e with n Copies of the Digit k". (All formulas marked with "MP").

He did in fact build up (1 + x^(-1))^x to slowly increase the accuracy of the formula.

[0] https://www2.stetson.edu/~efriedma/mathmagic/0804.html (The page may say 2004, but has been actively updated, and has references to 2019.)

Re: Multiple ways to compute e in Raku

#24

This looks surprisingly neat, honestly. I've never used Perl, let alone Perl 6, but I think I see why people cared about it.

Raku represents quite an advancement on Perl 5. Perl was a "kitchen sink" scripting language when it debuted, and Raku is a modern take on that, which means that it has lots of undiscovered corners still, places that will likely be major programming paradigms of tomorrow.

Re: Multiple ways to compute e in Raku

#25
post #10
post #6

Earlier quoted context omitted.

Is it officially appropriate to talk about Perl in the past tense?

I think technically yes, because the present tense should be referring to Raku instead.

Raku is not the direct successor to Perl, active Perl development continues.

Re: Multiple ways to compute e in Raku

#26
post #6

Earlier quoted context omitted.

Is it officially appropriate to talk about Perl in the past tense?

No, just about people caring about it. (Okay, that was flip, but Perl has really lost its niche, and not many people are very excited about it now.)

Nah, plenty of people still care about it (I should know, I'm one of them!). And with regular expressions front-and-center in perl, I still find it wonderful for text munging.

Re: Multiple ways to compute e in Raku

#27
post #26

Earlier quoted context omitted.

No, just about people caring about it. (Okay, that was flip, but Perl has really lost its niche, and not many people are very excited about it now.)

Nah, plenty of people still care about it (I should know, I'm one of them!). And with regular expressions front-and-center in perl, I still find it wonderful for text munging.

Maybe I'm just bitter because of Parrot. I so wanted to use it for my language.

Re: Multiple ways to compute e in Raku

#29
post #28

I'd rather there was a single way to do something useful in Raku than multiple ways to do something completely useless.

It sounds like your goals for Raku are incompatible with the aims of the project, to the extent that making Raku into what you want would be "use something else" with extra steps.

Re: Multiple ways to compute e in Raku

#30
post #10
post #6

Earlier quoted context omitted.

Is it officially appropriate to talk about Perl in the past tense?

I think technically yes, because the present tense should be referring to Raku instead.

No, Perl still exists (in the form of Perl 5) and is used a lot and will continue to be developed, now unhampered by Raku (formerly known as Perl 6).
Post reply on HN