Is it cheating to use the sign function when sieving for twin primes?

186 Views Asked by At

Let:

$$x=2$$

$$t(1,1)=1$$ $$t(2,1)=0$$ $$t(3,1)=0$$

$$\text{ If }n=k \text{ then } t(n,k)= 1$$

$$\text{ if } n>3 \text{ else if } k=1 \text{ then }$$ $$t(n,k)= \text{sgn}((2- \prod _{i=1}^{n-1} t(n,i+k)- \prod _{i=1}^{n-1-x} t(n-x,i+k)) \cdot (2- \prod _{i=1}^{n-1} t(n,i+k)- \prod _{i=1}^{n-1+x} t(n+x,i+k)))$$

$$\text{ else if } n \bmod k=0 \text{ then } t(n,k) = t\left(\frac{n}{k},1\right) \text{ else } 1 \text{ else } 1$$

where $$\text{sgn}(x)$$ is the sign function.

This produces a characteristic sequence of non-twin primes for $n>2$ starting:

1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,

which for $n>2$ is equal to $1$ if it is not a twin prime and equal to $0$ if it is a twin prime.

The positions of $0$ are at twin primes and the primes $2$ and $3$:

2, 3, 5, 7, 11, 13, 17, 19, 29, 31, 41, 43, 59, 61, 71, 73, 101, 103,

where the only non-twin prime is $2$.

https://oeis.org/A001097

I might have gotten the latex not entirely correct but the program below does what it is supposed to.

(*Mathematica start*)
Clear[t, n, k, i, nn];
nn = 1000;
t[1, 1] = 1;
t[2, 1] = 0;
t[3, 1] = 0;
t[n_, k_] := 
  t[n, k] = 
   If[n == k, 1, 
    If[n > 3, 
     If[k == 1, 
      Sign[(2 - Product[t[n, k + i], {i, 1, n - 1}]/1 - 
          Product[t[n - 2, k + i], {i, 1, n - 1 - 2}]/1)*(2 - 
          Product[t[n, k + i], {i, 1, n - 1}]/1 - 
          Product[t[n + 2, k + i], {i, 1, n - 1 + 2}]/1)], 
      If[Mod[n, k] == 0, t[n/k, 1], 1], 1]]];
Monitor[a = Table[t[n, 1], {n, 1, nn}];, n];
Flatten[Position[a, 0]]
Flatten[Position[a, 1]]
(*Mathematica end*)

So my question is:

Is it considered cheating to use the sign function when sieving for twin primes?

With "cheating" I mean that nothing useful can come out of the sign function because $$\frac{0}{0}=\text{indeterminate}$$

The sequence without the sign function looks like this:

1, 0, 0, 2, 0, 4, 0, 4, 1, 4, 0, 4, 0, 4, 1, 4, 0, 4, 0, 4, 1, 4, 1, 4, 2, 4, 2, 4, 0, 4, 0, 4, 2, 4, 2, 4, 1, 4, 1, 4, 0, 4, 0, 4, 1, 4, 1, 4, 2, 4, 2, 4, 1, 4, 2, 4, 2, 4, 0, 4, 0, 4, 2, 4, 2, 4, 1, 4, 1,

2

There are 2 best solutions below

0
On BEST ANSWER

There is a way to avoid using the sign function:

Clear[t, n, k, i, nn]; nn = 90; t[1, 1] = 1; t[2, 1] = 0; 
t[n_, k_] := 
 t[n, k] = 
  If[n == k, 1, 
   If[n > 2, 
    If[k == 1, (1 - 
        Product[t[n, k + i], {i, 1, n - 1}]*
         Product[t[n - 2, k + i], {i, 1, n - 1 - 2}])*(1 - 
        Product[t[n, k + i], {i, 1, n - 1}]*
         Product[t[n + 2, k + i], {i, 1, n - 1 + 2}]), 
     If[Mod[n, k] == 0, t[n/k, 1], 1], 1]]]; Monitor[
 a = Table[t[n, 1], {n, 1, nn}], n]

$t(n) =\;$1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0,

which is zero when $n=2$ or $n=$ a twin prime, and one otherwise.

The notation for the recurrence should be:

$t(1)=1$

$t(2)=0$

$n>2:$ $$t(n) = \left(1-\left({\prod_{d|n}}_\limits{d<n} t(d)\right)\left({\prod_{d|(n-2)}}_\limits{d<n} t(d)\right)\right)\left(1-\left({\prod_{d|n}}_\limits{d<n} t(d)\right)\left({\prod_{d|(n+2)}}_\limits{d<n} t(d)\right)\right)$$

if I am correct.

0
On

In most mathematics, the fact that an operation occasionally yields indeterminate results is not considered a reason not to use it. In fact, most operations are like that, in a sense - if you try to apply $+$ to things that are not numbers, for example, you'll get an undefined result. "Indeterminate" is just another option for the output of a function.

Another example: $\frac{x^2}{x}$ simplifies to $x$, even though when $x = 0$ we have $\frac{x^2}{x} = \frac{0}{0}$. That doesn't mean that the simplification was illegal or "cheating", it just means it doesn't work if $x = 0$. Likewise, the process you've outlined just happens to produce indeterminate results in certain situations.

In math, there is no such thing as "cheating" or "fair play" (except when it comes to course grades or similar). It either works or it doesn't. For example, a perfectly reasonable (though a little overkill) method for telling whether $x = 0$ is to ask "Is $\frac{x}{x}$ defined?" In this situation, the "undefined" or "indeterminate" response is just a different kind of information.