Group Abstract Group Abstract

Message Boards Message Boards

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

Function for "Primorials"?

Posted 5 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 5 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
POSTED BY: Michael Gmirkin
Posted 4 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 4 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 4 years ago
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
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