[Purdue-pm] a Perl 6 quick example

Mark Daniel Ward mdw at purdue.edu
Wed Dec 14 13:09:10 PST 2016


Dear Mark,

OK, I know the algorithm you are referring to.  Thanks!

Is this the book that you helped him to typeset?

http://bookstore.ams.org/stml-68/

Mark



On 12/14/16 3:53 PM, Mark Senn wrote:
> Mark Ward,
>
> 1.  I helped Dr. Wagstaff typeset a book having to do with factoring
> large integers and haven't been sending him stuff because I think he's
> already aware of anything I've ever heard of.  I will bcc this to him in
> case he or he would like his students to use Perl 6 (I also recommend
> Mathematica) to easily experiment with ideas without having to write
> much code.
>
> 2.  Perl 6's is-prime sub/method uses the "Rabin-Miller" (also known as the
> "Miller-Rabin") algorithm.  See
>      http://examples.perl6.org/categories/99-problems/P36-ovid.html
> for a simple example of how to factor integers using Perl 6.
>
> Some more information about Perl 6:
>
>      Another simplification that can be done to the code below.
>          # "(2..*)" can be simplified to "2..*"
>          (grep {.is-prime}, 2..*)[^3]
>          (2 3 5)
>
>      Type
>          <<a "butterfly wings" c>>.permutations
>      to print all permutations of "a", "butterfly wings", and c.)
>
> Mark Senn
>
>
>
>
> Cc: purdue-pm at pm.org
> X-Mailer: iPhone Mail (13G36)
> From: Mark Daniel Ward <mdw at purdue.edu>
> Subject: Re: [Purdue-pm] a Perl 6 quick example
> Date: Wed, 14 Dec 2016 04:51:25 -0500
> To: Mark Senn <mark at purdue.edu>
> X-PerlMx-URL-Scanned: Yes
> X-PerlMx-Virus-Scanned: Yes
> X-ECN-MailServer-Origination: mailhub247.itcs.purdue.edu 128.210.5.247
> X-ECN-MailServer-SpamScanAdvice: DoNotScan (-7.9/5.0)
> X-ECN-MailServer-VirusScanned: by ecn-av-milter
>
> Mark Daniel Ward <mdw at purdue.edu> wrote on 2016-12-14 at 0451:
> Dear Mark,
>
> Thank you again for your email.  This email alone might have finally
> convinced me to consider moving from Perl 5 to Perl 6.
>
> I have two things for you to consider.
>
> 1.  You might send your email to Sam Wagstaff, who is one of Purdue's
> experts on primes and factoring.
>
> 2.  I am curious what kinds of algorithms that Perl 6 is using under the
> hood, for its factoring algorithms.  Here is a classic kind of
> challenge: if you give Perl 6 a 200 digit number that has only 2
> factors, each of which are about 100 digits long, how does it know if
> the 200 digit number is prime or not?  What algorthm(s) is Perl 6
> trying, under the hood, to perform such a calculation?
>
> I am genuinely curious to know.
>
> Mark
>
>> On Dec 14, 2016, at 12:59 AM, Mark Senn <mark at purdue.edu> wrote:
>>
>> # The "is-prime" sub is defined in Perl 6.
>> is-prime(5)
>> True
>>
>> # The parentheses are not needed.
>> is-prime 5
>> True
>>
>> # The "is-prime" method is defined in Perl 6.
>> 5.is-prime
>> True
>>
>> # Get all primes from 2 to 10.
>> grep {$_.is-prime}, (2..10)
>> (2 3 5 7)
>>
>> # If an object is not specified, "$_" is assumed.
>> grep {.is-prime}, (2..10)
>> (2 3 5 7)
>>
>> # Get first three primes---I know the third prime comes before 10.
>> (grep {.is-prime}, (2..10))[0..2]
>> (2 3 5)
>>
>> # Using "^3" will give first three also---I think of "^3"
>> # as from 0 up to but not including 3.
>> (grep {.is-prime), (2..10))[^3]
>> (2 3 5)
>>
>> # Let Perl 6 generate as many candidate integers
>> # as we need (from 2 to infinity) to test for
>> # primality but stop after we get 3 primes.
>> (grep {.is-prime}, (2..Inf))[^3]
>> (2 3 5)
>>
>> # Use "*" ("whatever") instead of "Inf".
>> # Instead of 2 to infinity think of it
>> # as 2 to whatever.
>> (grep {.is-prime}, (2..*))[^3]
>> (2 3 5)
>>
>> # Exercise for the reader, do the previous
>> # computation in Perl 5 but make the code
>> # at least as clear as the Perl 6 solution.
>>
>> # Perl 6 uses really big integers in software
>> # if an integer is too big for machine computation.
>> 10**1000 - 3
>> 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999!
>   99!
>> 99999999997
>>
>> -mark
>> _______________________________________________
>> Purdue-pm mailing list
>> Purdue-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/purdue-pm




More information about the Purdue-pm mailing list