mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2022-02-04, 15:54   #1
robert44444uk
 
robert44444uk's Avatar
 
Jun 2003
Suva, Fiji

37708 Posts
Default Primes in order in pi

I am a little surprised I can't find any mention on the web, of the sequence of primes, in order, that might be found in the decimal expansion of pi (3.1415926535..)

The first instance of 2 is at the 6th decimal position, the first 3 thereafter at the 9th position, the first 5 thereafter at the 10th, etc.

For definition's sake, the first 71 is not at the 1757th position following 67 at the 1756th, as the 1757th position was also used to ascertain 67. Instead, 71 is found at the 1923rd.

A file of the decimal positions of all primes up to 8713 which are to be found in order in the first 10,000,000 decimal positions of pi is attached.

A graph is also shown, showing the positions of each prime, supporting the hypothesis that pi is normal. Some of the results are shown below


Code:
14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527...
The calculation is trivial. My average 7 year old desktop carried out the following perl program in less than 10 seconds.

Code:
#!/usr/bin/env perl
use warnings;
use strict;
use Math::Prime::Util qw/:all/;
use feature ':5.10';

$|=1;

my $pie = substr(Pi(10_000_000),2);
my $maxprime = 100_000;
my $prevplace = 0;
forprimes {
	my $i = 1+index($pie,$_,$prevplace);
	say $_, " ", $i;
	$prevplace = $i+length($_)-1; 
	if ( $i==0){
		last;
	}
} 2,$maxprime;
So...the challenge (as this is the puzzle subsection) is to expand the series, and perhaps find quite large gaps or close instances..and post to OEIS
Attached Thumbnails
Click image for larger version

Name:	primesinpi.JPG
Views:	119
Size:	51.6 KB
ID:	26499  
Attached Files
File Type: txt pieres.txt (14.3 KB, 62 views)
robert44444uk is offline   Reply With Quote
Old 2022-02-04, 16:29   #2
Uncwilly
6809 > 6502
 
Uncwilly's Avatar
 
"""""""""""""""""""
Aug 2003
101×103 Posts

2A2816 Posts
Default

That inflection point around 1000 looks interesting. Any insight into that?
Uncwilly is offline   Reply With Quote
Old 2022-02-04, 17:04   #3
robert44444uk
 
robert44444uk's Avatar
 
Jun 2003
Suva, Fiji

23·3·5·17 Posts
Default

Quote:
Originally Posted by Uncwilly View Post
That inflection point around 1000 looks interesting. Any insight into that?
That's the point at which the next prime has 4 digits. There would be similar inflections at 2 to 3 and 1 to 2 digits as well.

When I inferred that pi is normal in the OP, I meant pi behaves as a normal number.

Last fiddled with by robert44444uk on 2022-02-04 at 17:48
robert44444uk is offline   Reply With Quote
Old 2022-02-05, 01:48   #4
newalex
 
Feb 2019

100002 Posts
Default

Here is my result for 100b digits of Pi.
All primes up to 1042333 were found in order in these 100b digits.
Attached Files
File Type: zip primesinpi.zip (463.5 KB, 63 views)
newalex is offline   Reply With Quote
Old 2022-02-05, 14:50   #5
Dr Sardonicus
 
Dr Sardonicus's Avatar
 
Feb 2017
Nowhere

31·197 Posts
Default

Assume pi is a normal number to base ten.

It occurred to me to wonder how many times the block of decimal digits representing a prime p can reasonably be expected to occur before it occurs in its proper place in the sequence of primes.
Dr Sardonicus is offline   Reply With Quote
Old 2022-02-05, 14:59   #6
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

1,237 Posts
Default

Quote:
Originally Posted by newalex View Post
Here is my result for 100b digits of Pi.
All primes up to 1042333 were found in order in these 100b digits.
Would you mind sharing/PM'ing your program? I could run it on 1t digits I have. And maybe some other constants.
kruoli is offline   Reply With Quote
Old 2022-02-05, 17:05   #7
newalex
 
Feb 2019

208 Posts
Default

Quote:
Originally Posted by kruoli View Post
Would you mind sharing/PM'ing your program? I could run it on 1t digits I have. And maybe some other constants.
Yes, of course. But I am not sure if it would be suitable for you. It is written in Java and stores all digits in memory. So you need 1 Tb of RAM to run it for 1t. It can be fixed easily but need some work.
Here is the source code
Code:
import java.io.*;

public class PrimesInPi {

    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("pi.txt");
        long piSize = 100000000000L;
        final int maxArraySize = 1000000000;
        int chunkSize = (piSize>maxArraySize) ? maxArraySize : (int) piSize;
        char[][] pi;
        pi = new char[(int) (piSize/chunkSize)][chunkSize];
        fr.read();
        fr.read();
        for (int i=0; i<piSize/chunkSize; i++) {
            fr.read(pi[i], 0, chunkSize);
        }
        fr.close();
        BufferedReader primesReader = new BufferedReader(new FileReader("primes.txt"));
        String prime = primesReader.readLine();
        FileWriter result = new FileWriter("output.txt");
        long pos = 0;
        int i=0, j=0;
        while (pos<piSize) {
            if (isCurrentPrime(pi, prime, i, j)) {
                result.write(prime+" "+(pos+1)+"\n");
                prime = primesReader.readLine();
                j+=prime.length();
                pos+=prime.length();
                if (j>=chunkSize) {
                    j-=chunkSize;
                    i++;
                }
            } else {
                pos++;
                j++;
                if (j==chunkSize) {
                    j=0;
                    i++;
                }
            }
        }
        primesReader.close();
        result.close();
    }

    private static boolean isCurrentPrime(char[][] pi, String prime, int i, int j) {
        boolean result = true;
        int i1 = i, j1 = j;
        for (int k=0; k<prime.length(); k++) {
            if (prime.charAt(k) == pi[i1][j1]) {
                j1++;
                if (j1 == pi[i1].length) {
                    j1 = 0;
                    i1++;
                }
                if (i1 == pi.length) {
                    result = false;
                    break;
                }
            } else {
                result = false;
                break;
            }
        }
        return result;
    }
}
The program expects to have pi.txt and primes.txt files in the same folder. It ignores first 2 symbols in pi.txt file to start from fraction part(assuming the file starts with 3. ). primes.txt is a list of primes(one line - one prime).
piSize variable should set to count of pi digits which we want to process.
newalex is offline   Reply With Quote
Old 2022-02-05, 17:16   #8
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

1,237 Posts
Default

Thank you!

For some reason I was expecting that the straightforward approach would be inefficient but you are correct that this approach can be applied to a file that is not fully stored in memory. I'll code up something later. I like your idea to have the primes precalculated in a file. This makes the code way less complex.
kruoli is offline   Reply With Quote
Old 2022-02-05, 17:59   #9
uau
 
Jan 2017

32×17 Posts
Default

Quote:
Originally Posted by Dr Sardonicus View Post
It occurred to me to wonder how many times the block of decimal digits representing a prime p can reasonably be expected to occur before it occurs in its proper place in the sequence of primes.
Each sequence of n digits should occur equally often. Thus if you sequentially search for 50 6-digit sequences, you should on average expect to have seen 50 of the last sequence - on average encountering it once before finding each of the earlier 49 ones.

So the expected number should be (number of earlier equally long target sequences) + (number of one earlier one digit shorter target sequences)/10 + (two shorter)/100 and so on.
uau is offline   Reply With Quote
Old 2022-02-07, 09:15   #10
robert44444uk
 
robert44444uk's Avatar
 
Jun 2003
Suva, Fiji

111111110002 Posts
Default

You have to love the projected result of this exercise - there is exists within the decimal representation of pi, (which is itself just one of an infinite number of irrationals), all of the infinity of primes, in order.

I would expect that this projected result will be the same for all integer bases, i.e. the representations of the primes in any integer base can be found in order within the representation of pi in that base. I can almost visualise this must be true for base 2.

Can we go further to project or hypothesise that the primes, as depicted in any integer base are in order in the representation of any irrational number in the same integer base?

As integers represented in irrational bases appear themselves irrational, then we can safely say that the primes in order, represented in irrational base form, cannot be found in the representation of the irrational in that base, as the irrational in its own base will have a simple non-irrational form.

Because the representation of the irrational form is infinite, I would hypothesise that the primes represented in irrational base form (which I think are irrational representations themselves) are not included in order in the representation of an irrational number presented in an different rational or irrational base.

Have I covered all the permutations here?

PS: My teacher at school did day "don't mess with infinity, it bites"
robert44444uk is offline   Reply With Quote
Old 2022-02-07, 12:11   #11
uau
 
Jan 2017

32·17 Posts
Default

Quote:
Originally Posted by robert44444uk View Post
You have to love the projected result of this exercise - there is exists within the decimal representation of pi, (which is itself just one of an infinite number of irrationals), all of the infinity of primes, in order.
I don't find it too interesting myself. Any random sequence would eventually produce a match. So would a sequence like 1 2 3 4 5 ... (you would get more matches arbitrarily late as parts of larger numbers).

Quote:
Can we go further to project or hypothesise that the primes, as depicted in any integer base are in order in the representation of any irrational number in the same integer base?
No, you can easily construct an irrational number whose decimal representation consists of only 0 and 1.
uau is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database of multiplicative order of 2 mod p bur Miscellaneous Math 9 2021-05-26 13:53
order of a function =/= p-1 bhelmes Math 5 2018-09-13 16:23
ECM curve group order Brain Miscellaneous Math 1 2010-12-08 01:00
Number of groups for given order Raman Puzzles 6 2010-09-05 17:43
Forum order? Xyzzy Forum Feedback 5 2007-01-28 10:35

All times are UTC. The time now is 01:37.


Sat Dec 10 01:37:34 UTC 2022 up 113 days, 23:06, 0 users, load averages: 0.42, 0.68, 0.73

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔