Message Boards Message Boards

1
|
5956 Views
|
8 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Function for "Primorials"?

Posted 4 years ago

So, been trying to figure out how to do something, and researching it online, and came across the term "Primorial(s)"... Meaning the Product of the first n Prime Numbers. (Say, multiplying the first n=10 Prime Numbers together, etc.)

https://en.wikipedia.org/wiki/Primorial

Is there a function in Mathematica for this? I'm having a tough time finding one. Seems fairly basic. Like I'm pretty sure there's a function to list the n-th Prime number. Yep:

https://reference.wolfram.com/language/ref/Prime.html

So, one would think it would be simple to implement a Function that multiplies the first n such primes together, and call that function "Primorial [n]," or whatever?

I see an entry on Math World:

https://mathworld.wolfram.com/Primorial.html

But, I'm having a hard time locating an actual Mathematica function for it? Is there one?

If not, could Wolfram please create one and add it perhaps to the next iterative .x release of Mathematica? For those of us interested in Prime #'s, Prime Theory, Prime Sieving, and such.

There's actually a fairly real-world usage case for it in Sieving. Would be handy to have a simple function for it. Where you could just be like Primorial[10]; and have it return the answer... Which looks to be around ... jeez, even Wolfram|Alpha can't parse my input "Product of the first 10 prime numbers." It'll do "Sum" fine. Sigh Okay, doing it manually... Around ... 6,469,693,230

So, yeah, it'd be nice if one had a simple function to input:

Primorial[10];

and get output:

6,469,693,230

Yeah?

Does this exist, or can it be added?

If it doesn't exist? How can it be done in Mathematica? Can one do like a table / array or something and the take the product of all of it?

And then, for the thing I kind of want to do, count the digits of the result with "IntegerLength[]"?

https://reference.wolfram.com/language/ref/IntegerLength.html

POSTED BY: Michael Gmirkin
8 Replies
Posted 4 years ago

Hi Michael,

One way to implement primorial.

primorial[n_?Positive] := Product[Prime[i], {i, 1, n}];

primorial[10]
(* 6469693230 *)
POSTED BY: Rohit Namjoshi

Hmm, yeah, that does seem a perhaps slightly more compact way to do it than what I did. :)

Thx!

Would be nifty if they just had a straight function for it, of course...

POSTED BY: Michael Gmirkin

Just for kicks-and-giggles, suppressing a bunch of display output to get a final number:

The Product of the first 10,000 Primes renders a 45,337-digit composite number.

n=100,000: 563,921-digits long.

n=1,000,000: 6,722,809-digits long

n=10,000,000: 77,919,922-digits long (that took a minute to compute!)

n=100,000,000: 885,105,237-digits long. (Heh! That took a while... Almost there)

n=200,000,000: ...we'll have to see how long this takes, assuming it can complete it. ;)

I suspect a 1 billion+ digit Product will fall somewhere between the Products of the first 100mil & 200mil primes. But, what do I know? I just play here. ^_^ (If 200mil primes is over 1bn digits, I can probably narrow it down by halving the difference and halving again 'til narrowed down to exactly how many Primes are needed for the Product to cross the 1bn threshold... Might take a while and a few iterations, tho'...)

EDIT: Well, darn, seems like the Mathematica Kernel craps out after about 20 minutes to 1/2 hour on trying to compute on 200,000,000. Sigh ;)

POSTED BY: Michael Gmirkin
Posted 3 years ago

I have worked this same problem. I see no contact for you, you can reach out at bill.mceachen@gmail.com I have had the same desire for a built-in function

POSTED BY: Bill McEachen
Posted 3 years ago

Hi Bill,

Did you look at the primorial function implementation I provided as an answer? Were you looking for something different?

POSTED BY: Rohit Namjoshi
Posted 3 years ago

I am not looking for anything, just trying to assist Mr Gmirkin up at his higher range. I understand the code completely.

POSTED BY: Bill McEachen

A back-of-the-envelope computation suggests that to get n digits, one requires in the ballpark of LogIntegral[Log[10.]*10^n] primes. For n=10^9, that's around 112,307,000.

Quick check at 10^5. Approximate the count:

In[1002]:= LogIntegral[Log[10.]*10^5]

(* Out[1002]= 20500.5 *)

Check how many digits we get:

In[1004]:= Log[10., Product[Prime[j], {j, 20500}] // N]

(* Out[1004]= 100068. *)
POSTED BY: Daniel Lichtblau

Okay, sort of solved my own problem after a bit of laborious searching out functions...

FirstPrime = 1;
LastPrime = 8;
PrimeRange = Range[FirstPrime, LastPrime];
PrimeList = Prime[PrimeRange]
Times @@ PrimeList
IntegerLength[Times @@ PrimeList]

Outputs:

{2, 3, 5, 7, 11, 13, 17, 19}

9699690

7

Guess that gets done what I wanted to get done.

But, would be really nice if Mathematica had a built-in "Primorial [n]" function to do the heavy lifting of the first part (mutliplying the first n Prime Numbers together).

Seems like it would be pretty simple to put together an official function, based on the above... Something that'd basically just be like:

Primorial [8]

Out: 9699690

Then one could say, like:

IntegerLength[Primorial[8]]

Out: 7

Yeah?

Why does this matter? Well, for one it's just sort of interesting from a pure math perspective.

My particular interest is actually wondering how many ordinal Prime Numbers one would have to multiply together in order to get a billion digit number (not itself Prime, obviously, as it would be composite of multiple Primes but getting into like billion-digit+ territory).

POSTED BY: Michael Gmirkin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract