Message Boards Message Boards

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

Discriminate arbitrary integers into prime numbers and composite numbers

Posted 4 years ago

Prime numbers greater than $5$ belong to either ( $6n-1$) or ( $6n+1$) type. There are no prime numbers greater than $5$ that do not belong to these two sequences. These two sequences ( $6n±1$) are composed of prime numbers and composite numbers. Even numbers do not belong to this sequence. Some odd numbers do not belong to this sequence. The theme is to discriminate any positive integer into a prime number and a composite number. Integers not belonging to the sequence are excluded from the discrimination.

This time, the following four equations are used for the prime number judgment.

$$\begin{eqnarray} n_{test}&=&36 s_1^2-1+(36 s_1-6)\cdot(m_1-1)\tag{1a} \\ n_{test}&=&36 s_2^2+36 s_2+5+(36 s_2+6)\cdot(m_2-1)\tag{1b} \\ n_{test}&=&36 s_3^2-12 s_3+1+(36 s_3-6)\cdot(m_3-1)\tag{1c}\\ n_{test}&=&36 s_4^2+12 s_4+1+(36 s_4+6)\cdot(m_4-1)\tag{1d} \end{eqnarray}$$

$$\begin{align*} &m=1,2,3\cdots, s=1,2,3\cdots \\ &n_{test} \text{ : Positive integer to determine whether it is a prime or composite}\\ \end{align*} $$

Equations ( $1{\rm a}$) and ( $1{\rm b}$) relate to ( $6n-1$) type primes, and equations ( $1{\rm c}$) and ( $1{\rm d}$) relate to ( $6n+1$) type primes. Give an arbitrary $n_{test}$ to equation ( $1$). If there are integer solutions for $m$ and $s$, then $n_{test}$ is a composite number. If there are no integer solutions in $m$ and $s$, then $n_{test}$ is a prime number.

Solving equation ( $1$) for $m$ yields equation ( $2$).

$$\begin{eqnarray} m_1&=&\frac{n_{test}-5+36s_1-36s_1^2}{6\cdot(6s_1-1)}\tag{2a} \\ m_2&=&\frac{n_{test}+1-36s_2^2}{6\cdot(6s_2+1)}\tag{2b} \\ m_3&=&\frac{n_{test}-7+48s_3-36s_3^2}{6\cdot(6s_3-1)}\tag{2c}\\ m_4&=&\frac{n_{test}+5+24s_4-36s_4^2}{6\cdot(6s_4+1)}\tag{2d} \end{eqnarray}$$

$$\begin{align*} & s=1,2,3\cdots \\ &n_{test} \text{ : Positive integer to determine whether it is a prime or composite}\\ \end{align*} $$

$$\begin{equation} m= \left \{ \begin{array}{l} {\text {If there is an integer solution : }}n_{test}{\text { is the composite number}} \; \\ {\text {If there is no integer solution : }}n_{test}{\text { is a prime number}} \end{array} \right.\\ \end{equation} $$

Give the positive integer to test, $n_{test}$, on the right hand side of equation ( $2$). Search from $s=1$ to $s=s_{max}$ to see if there is an integer solution in $m$. $s_{max}$ is determined depending on $n_{test}$, and the relationship is given by equation ( $3$).

$$\begin{eqnarray} s_{max}=\frac{\sqrt{n_{test}}}{6}+1\tag{3}\\ \end{eqnarray}$$

$$\begin{align*} &s_{max} :{\text {Starting from }s=1{\text { in equation ($2$), the upper limit of the search range}}} \\ &n_{test} \text{ : Positive integer to determine whether it is a prime or composite}\\ \end{align*} $$

The program is shown below.

ntest = 5;

"**********************************************";
nm = (ntest + 1)/6;
np = (ntest - 1)/6;
smax = IntegerPart[Sqrt[ntest]/6] + 1;
Print["====== The calculation results are shown below. ======"];
Clear[f, s1, s2, s3, s4, m1, m2, m3, m4];
If[IntegerQ[nm], nnm = 1, nnm = 0];
If[IntegerQ[np], nnp = 1, nnp = 0];
f = 0;
func1[s_] := If[nnm > 0, (-5 + ntest + 36*s - 36*s^2)/(-6 + 36*s)];
func2[s_] := If[nnm > 0, (1 + ntest - 36*s^2)/(6 + 36*s)];
func3[s_] := If[nnp > 0, (-7 + ntest + 48*s - 36*s^2)/(-6 + 36*s)];
func4[s_] := If[nnp > 0, (5 + ntest + 24*s - 36*s^2)/(6 + 36*s)];

If[IntegerQ[ntest] && ntest > 1 && (nnm + nnp) > 0,
  Print["ntest= ", ntest];
  Print["----------------"];

  Do[
   If[IntegerQ[func1[s]] && func1[s] > 0, {m1 = func1[s], s1 = s}, 
    m1 = 0];
   If[IntegerQ[func2[s]] && func2[s] > 0, {m2 = func2[s], s2 = s}, 
    m2 = 0];
   If[IntegerQ[func3[s]] && func3[s] > 0, {m3 = func3[s], s3 = s}, 
    m3 = 0];
   If[IntegerQ[func4[s]] && func4[s] > 0, {m4 = func4[s], s4 = s}, 
    m4 = 0];

   If[m1 > 0, Print["m1= ", m1, ", s1= ", s1], ""];
   If[m2 > 0, Print["m2= ", m2, ", s2= ", s2], ""];
   If[m3 > 0, Print["m3= ", m3, ", s3= ", s3], ""];
   If[m4 > 0, Print["m4= ", m4, ", s4= ", s4], ""];

   f = f + m1 + m2 + m3 + m4;
   If[s == smax, Break[]], {s, 1, smax}];

  If[f == 0 && ntest < 99999999999999999999, 
   Print[ntest " is a prime number"]];
  If[f >= 1 && ntest < 99999999999999999999, 
   Print[ntest " is the composite number."]];
  If[f == 0 || f >= 1, 
   Print["PrimeQ[ ", ntest, " ]= ", PrimeQ[ntest]]], 
  Print["!! It is a numerical value that is not subject to \
evaluation."]];

This is an example where $n_{test}=5$. The calculation result is output as follows.

====== The calculation results are shown below. ======
ntest= 5
----------------
5  is a prime number
PrimeQ[ 5 ]= True

$5$ was determined to be a prime number. The judgment is confirmed by ${\rm PrimeQ} []$.

Next, let's set $n_{test}=21$. The result is displayed as follows:

====== The calculation results are shown below. ======
!! It is a numerical value that is not subject to evaluation.

Because $21$ does not belong to the sequence ( $6n±1$).

Let's check with a slightly larger number. Try $n_{test}=2999622475821$. This is ${\rm Prime}[999999999999]$. The result is output as follows:

====== The calculation results are shown below. ======
ntest= 29996224275821
----------------
29996224275821  is a prime number
PrimeQ[ 29996224275821 ]= True

$n_{test}=2999622475821$ was judged to be prime. It is a natural result.

As another example, what if $n_{test}=3141592653589793$ ? The result is as follows.

====== The calculation results are shown below. ======
ntest= 3141592653589793
----------------
m2= 40276828892175, s2= 2
m2= 2172609027339, s2= 40
m2= 167123770815, s2= 522
3141592653589793  is the composite number.
PrimeQ[ 3141592653589793 ]= False

As a result of the judgment, $n_{test}=3141592653589793$ is the composite number. In the case of composite numbers, a set of $m$ and $s$ that are integer solutions in equation ( $2$) is displayed.

Entering too large a value for $n_{test}$ takes a long time to calculate. Also, it seems to stop the calculation if it is too large.

POSTED BY: Koichi Ohno
2 Replies
Posted 4 years ago

John Hendrickson -san

Thank you for your comment.

I enjoy posting to this WOLFRAM COMMUNITY as an amateur interested in prime numbers.

The reason I can post with confidence is that Mathematica's PrimeQ [] makes it easy to judge the pass or fail of the calculation results.

POSTED BY: Koichi Ohno
Anonymous User
Anonymous User
Posted 4 years ago

If you find a new "higher" prime number than Mathematica knows of you can "certify" it, which adds it to Mathematica's known prime number list (some that are by formula, others simply stored).

POSTED BY: Anonymous User
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