# BiEntropy, TriEntropy and Primality

## Abstract

**:**

^{8}is measured using the BiEntropy function. Significant differences are detected between the primes and the non-primes. The BiEntropic prime density is shown to be quadratic with a very small Gaussian distributed error. The work is repeated in binary using a Monte Carlo simulation of a sample of natural numbers < 2

^{32}and in trinary for all natural numbers < 3

^{9}with similar but cubic results. We found a significant relationship between BiEntropy and TriEntropy such that we can discriminate between the primes and numbers divisible by six. We discuss the theoretical basis of these results and show how they generalise to give a tight bound on the variance of Pi(x)–Li(x) for all x. This bound is much tighter than the bound given by Von Koch in 1901 as an equivalence for proof of the Riemann Hypothesis. Since the primes are Gaussian due to a simple induction on the binary derivative, this implies that the twin primes conjecture is true. We also provide absolutely convergent asymptotes for the numbers of Fermat and Mersenne primes in the appendices.

## 1. Introduction

## 2. BiEntropy

#### 2.1. Shannon Entropy

_{1}, …, s

_{n}where P(s

_{I}= 1) = p (and 0 log

_{2}0 is defined to be 0) is:

_{2}p − (1 − p) log

_{2}(1− p)

#### 2.2. Binary Derivatives and Periodicity

_{1}(s), is the binary string of length n − 1 formed by XORing adjacent pairs of digits. We refer to the kth derivative of s, d

_{k}(s) as the binary derivative of d

_{k−1}(s). There are n − 1 binary derivatives of s. p(k) is the proportion of 1’s in d

_{k}.

_{k}= 0 for some k ≥ 1.

#### 2.3. BiEntropy Definition

_{n−1}is not used, as there is no variation in the contribution to the total entropy in either of its two binary states. The highest weight is assigned to the highest derivative d

_{n−2}.

#### 2.4. BiEntropy Properties

## 3. BiEntropy and Primality of the Natural Numbers < 256

**O**(x

^{2}) for very small integers. Using BiEntropy or other prime density functions we can therefore usefully speak of q(x, y, i) which is the number of primes in the ith y sized ordered interval < x. Thus q(256, 32, 8) is 14, as above. Naturally, π(256) = q(256, 256, 1) = 54.

## 4. BiEntropy& Primality of the Natural Numbers < 2^{32}

#### 4.1. Primes and Binary Derivatives

_{2}(x)) increases only as (m

^{2}− m)/2. We show in Table 4 the relationship between π(x), the number of primes, and the binary derivatives d for various x.

#### 4.2. Higher Powers of Shannon Entropy

#### 4.3. Investigating BiEntropy and Primality for x < 2^{32}

^{32}. Using a simple Excel data table, for each of 10,000 iterations, we generated a random 32 bit integer and then calculated its quadratic BiEntropy using the tenth power of the Shannon entropy of each derivative (P10 BiEntropy). We used a spreadsheet based exhaustive trial division calculation to determine the primality of each random 32 bit integer. We then sorted the sampled natural numbers and their BiEntropies into BiEntropic order and compared the prime density of this ordered interval with the natural prime density of the sample. We show the relationship between the sample’s natural and BiEntropic prime density in Figure 5 and the difference between the two densities in Figure 6.

#### 4.4. Testing the BiEntropy and Primality Monte Carlo

^{32}produced by the Excel RAND function, which we have previously scrutinised [1]. Since random numbers would be generated uniformly (i.e., linearly) in the given range, we were able to calculate, using the Prime Number Theorem, how many primes were likely to be produced during the generation of 10,000 random integers in the given range. We were then able to calculate a theoretical prime density for the Monte Carlo simulation to compare against the actual prime density of the Monte Carlo simulation.

^{2}/2) matches the actual results of the Monte Carlo simulation much more closely. By examination, the error between theoretical and actual in Figure 6 is broadly normal (mean 1.22 and St. Dev. 6.17) and omitted for brevity. It appears to be the case that BiEntropic prime density is also quadratic for integers of

**O**(2

^{32}).

## 5. TriEntropy

#### 5.1. Pairwise Addition and Differences Modulo 3

#### 5.2. Computing TriEntropy

_{i}of all the possible symbols. For the derivatives, as in Table 6 above, the p

_{i}for 0, 1, 2, are 0.111 (3/27), 0.444 (12/27), and 0.444 (12/27), respectively. Importantly, since TriEntropy would necessarily calculate the Shannon entropy of the original string, note that the p

_{i}of the 0,1,2 of the input string are 0.333, 0.333, 0.333, as they are equiprobable. Furthermore, note that only (n − 1)/2 − 1 derivatives are possible (where n is odd) as three input trits are required to compute each output trit of the derivatives. Finally, note that in BiEntropy, once a periodicity is detected, the further derivatives automatically fall to 0. This is not the case for TriEntropy, hence, derivatives that fall to 0 must have their further non-use programmed in specifically. Note n is odd.

^{9}and show the resulting natural and TriEntropic prime densities in Figure 7. In the equivalent BiEntropy diagram, for all x < 2

^{16}, BiEntropy is almost identical and was earlier omitted for brevity. We show the difference or Delta between TriEntropic prime density and natural prime density in Figure 8.

^{9}is approximately cubic. The error of the difference is approximately Gaussian, which we depict in Figure 9. The mean error is 0.00 with a standard deviation of 7.34.

## 6. Interaction between BiEntropy and TriEntropy

## 7. Theoretical Basis

#### 7.1. Introduction

#### 7.2. Periodic and Non-Periodic Numbers

#### 7.3. Periodic Binary Primes

#### 7.4. Periodic Binary Composites

^{n}∙ a) + b

- since a = b
- thenk = (2
^{n}+ 1) ∙ a - therefore, k is composite.

^{n}− 1) of even length (where a = b) cannot be prime. The odd length Mersenne numbers, e.g., 0111, seven, may be prime but are not periodic because a ≠ b. We list the periodic binary composites < 256 in Appendix A and discuss the Mersenne numbers in more detail in Appendix B.

#### 7.5. N-Periodic Binary Composites

^{n}− a − 1

^{n}∙ a) + b

^{n}∙ a) + 2

^{n}− a − 1

^{n}− 1) + 2

^{n}− 1

^{n}− 1)

- if a ≥ 1 then k is composite
- else a = 0 and b is a periodic binary composite (e.g., 1111…) of length n/2

#### 7.6. Periodic M-Ary Primes

- since a = b = 1
- thenk = ((k − 1)
^{1}∙ 1) + 1

^{(n − 1)}· a) + b where a = b = 1.

#### 7.7. Periodic M-Ary Composites

^{n}∙ a) + b

- since a = b
- thenk = (m
^{n}+ 1) ∙ a

#### 7.8. Non Periodic Numbers

## 8. Discussion

_{22}), periodic and n-periodic numbers cannot be prime in any base. Hence, the main diagonal of Figure 1 (for all x, and in all bases) is almost devoid of primes and there are no primes on the cross diagonals. Ignoring the Fermat primes, 32/256 = 12.5% of natural numbers < 256 cannot be prime due to the periodicity or n-periodicity within seven of their last eight binary derivatives.

_{0}) that is all 0’s, whereas the last used derivative d

_{6}of length 2 is all 0’s on 64 occasions and d

_{5}of length 3 is all 0’s on 32 occasions. BiEntropy measures exactly the probability that a binary string cannot be prime or may be prime with a precision given by the number of bits in d

_{0}. TriEntropy is cubic for similar reasons.

_{k}, b

_{k}, and c

_{k}, such that

_{k}.x

_{k}

^{2}+ b

_{k}.x

_{k}+ c

_{k}= Li(x

_{k}) where x

_{k}= m

^{2}, m is integer and c

_{k}= 0

_{k}, v

_{k}, and w

_{k}, such that

_{k}.x

_{k}

^{2}+ v

_{k}.x

_{k}+ w

_{k}= π(x

_{k}) where x

_{k}= m

^{2}, m is integer and w

_{k}= 0

_{k}, b

_{k}, c

_{k}and u

_{k}, v

_{k}, and w

_{k}, there exists a set of (m

^{2}− m)/2 binary derivatives from which the distribution of primes is derived with known probabilities and calculable or estimable variance. The variance in natural prime density is constrained by the variance in the BiEntropic prime densities for all x

_{k}< x because the same data—the natural numbers—is Gaussian distributed about two differing central measures—a quadratic and a logarithmic integrand.

x→∞

^{2}− m)/2, where m = log

_{2}(x), the variance in the error between the BiEntropic and Quadratic prime densities is

**O**(log(x)/x) due to the central limit theorem. Hence, the error between the Logarithmic Integrand and the natural prime densities rapidly tends to 0.

x→∞

**O**(√ x log(x))

## 9. Conclusions

^{8}. We have repeated this analysis statistically for the natural numbers < 2

^{32}and found similar results, including the prime density remaining

**O**(x

^{2}). We developed a related TriEntropy function and showed that TriEntropy changes prime density to

**O**(x

^{3}) for the natural numbers < 3

^{9}. In addition, TriEntropy has addressed a natural weakness in the detection of periods of length 3, or multiples thereof, in the BiEntropy function.

^{8}and the practicality of combining BiEntropy and TriEntropy via arithmetic addition. We have given a brief outline of the theoretical underpinnings behind this initial experimental work and shown how it generalises for all the natural numbers.

## 10. Further Work

## 11. Patents

## Supplementary Materials

## Funding

## Acknowledgments

## Conflicts of Interest

## Appendix A. Periodic Binary Composites < 256

Bits | Binary | Decimal | BiEntropy |
---|---|---|---|

4 | 1010 | 10 | 0.14 |

4 | 1111 | 15 | 0 |

6 | 10010 | 18 | 0.44 |

6 | 11011 | 27 | 0.95 |

8 | 100010 | 34 | 0.05 |

6 | 100100 | 36 | 0.95 |

6 | 101101 | 45 | 0.44 |

8 | 110011 | 51 | 0.02 |

6 | 110110 | 54 | 0.95 |

6 | 111111 | 63 | 0 |

8 | 1000100 | 68 | 0.05 |

8 | 1010101 | 85 | 0.01 |

8 | 1100110 | 102 | 0.02 |

8 | 1110111 | 119 | 0.05 |

8 | 10001000 | 136 | 0.05 |

8 | 10011001 | 153 | 0.02 |

8 | 10101010 | 170 | 0.01 |

8 | 10111011 | 187 | 0.05 |

8 | 11001100 | 204 | 0.02 |

8 | 11011101 | 221 | 0.05 |

8 | 11101110 | 238 | 0.05 |

8 | 11111111 | 255 | 0 |

## Appendix B. The Fermat and Mersenne Primes

^{2^n}+ 1. Fermat numbers are also periodic binary numbers of the form ab where a = b = 1. We show in Table A2 the five known Fermat primes.

Fermat Number | Decimal | Binary | n |
---|---|---|---|

F_{0} | 3 | 11 | 1 |

F_{1} | 5 | 0101 | 2 |

F_{2} | 17 | 00010001 | 4 |

F_{3} | 257 | 0000000100000001 | 8 |

F_{4} | 65537 | 00000000000000010000000000000001 | 16 |

^{2n}). There are 2

^{2n}binary strings of length 2n, and one, and only one, of which can be a periodic binary prime of period length n where a = b = 1.

_{n}= prime) = 1/log (2

^{2n}+ 1)

^{1024}(the spreadsheet floating point limit) and is absolutely convergent by D’Alembert’s criterion.

^{k}+ 1 which are prime, k is a power of two. As [25] discusses, further Fermat primes are highly unlikely, despite the continuation of this log approximation.

N | 2^{2n} | 2^{n}+1 | ln(2n) | ∑p(F(n)) | F | D’Alembert’s Criterion |
---|---|---|---|---|---|---|

1 | 4 | 3 | 0.6213 | 0.6213 | 1 | |

2 | 16 | 5 | 0.3530 | 0.9743 | 2 | 0.5681 |

3 | 64 | 9 | 0.2396 | 1.2138 | 2 | 0.6787 |

4 | 256 | 17 | 0.1802 | 1.3941 | 3 | 0.7523 |

5 | 1024 | 33 | 0.1442 | 1.5383 | 3 | 0.8004 |

6 | 4096 | 65 | 0.1202 | 1.6585 | 3 | 0.8334 |

7 | 16384 | 129 | 0.1030 | 1.7616 | 3 | 0.8572 |

8 | 65536 | 257 | 0.0902 | 1.8517 | 4 | 0.8750 |

9 | 262144 | 513 | 0.0801 | 1.9319 | 4 | 0.8889 |

10 | 1048576 | 1025 | 0.0721 | 2.0040 | 4 | 0.9000 |

11 | 4194304 | 2049 | 0.0656 | 2.0696 | 4 | 0.9091 |

12 | 16777216 | 4097 | 0.0601 | 2.1297 | 4 | 0.9167 |

13 | 67108864 | 8193 | 0.0555 | 2.1852 | 4 | 0.9231 |

14 | 268435456 | 16385 | 0.0515 | 2.2367 | 4 | 0.9286 |

15 | 1073741824 | 32769 | 0.0481 | 2.2848 | 4 | 0.9333 |

16 | 4294967296 | 65537 | 0.0451 | 2.3299 | 5 | 0.9375 |

17 | 17179869184 | 131073 | 0.0424 | 2.3723 | 5 | 0.9412 |

18 | 68719476736 | 262145 | 0.0401 | 2.4124 | 5 | 0.9444 |

19 | 2.74878E11 | 524289 | 0.0380 | 2.4504 | 5 | 0.9474 |

20 | 1.09951E12 | 1048577 | 0.0361 | 2.4864 | 5 | 0.9500 |

^{82,589,933}-1 being the largest as at October 2019 [30]. Further evaluation of the M

_{∞}asymptote will require a logarithmic transformation of the above formula and more appropriate software.

## References

- Croll, G.J. BiEntropy—The Approximate Entropy of a Finite Binary String. arXiv
**2013**, arXiv:1305.0954. [Google Scholar] - Hardy, G.H.; Wright, E.M. An Introduction to the Theory of Numbers; Oxford University Press: Oxford, UK, 1979. [Google Scholar]
- Croll, G.J. BiEntropy of Knots on the Simple Cubic Lattice. In Unified Field Mechanics II: Formulations and Empirical Tests-Proceedings of the Xth Symposium Honoring Noted French Mathematical Physicist Jean-Pierre Vigier; World Scientific: Singapore, 2018. [Google Scholar]
- Costa, R.; Boccardo, D.; Pirmez, L.; Rust, L.F. Hiding Cryptographic Keys of Embedded Systems. Adv. Inf. Sci. Comput. Eng.
**2015**. Available online: http://www.wseas.us/e-library/conferences/2015/Dubai/CEA/CEA-42.pdf (accessed on 5 March 2020). - Jin, R.; Zeng, K. Physical layer key agreement under signal injection attacks. In Proceedings of the 2015 IEEE Conference on Communications and Network Security (CNS), Florence, Italy, 28–30 September 2015; pp. 254–262. [Google Scholar]
- Jin, R.; Shi, L.; Zeng, K.; Pande, A.; Mohapatra, P. MagPairing: Pairing Smartphones in Close Proximity Using Magnetometers. IEEE Trans. Inf. Forensics Secur.
**2016**, 11, 1306–1320. [Google Scholar] [CrossRef] - Kotě, V.; Molata, V.; Jakovenko, J. Enhanced Generic Architecture for Safety Increase of True Random Number Generators. Electroscope
**2014**. Available online: https://otik.uk.zcu.cz/bitstream/11025/11825/1/Kote.pdf (accessed on 5 March 2020). - Stakhanova, N. An Entropy Based Encrypted Traffic Classifier. In Proceedings of the Information and Communications Security: 17th International Conference, ICICS 2015, Beijing, China, 9–11 December 2016. [Google Scholar]
- Helinski, R. BiEntropy for Python v. 1.0 (No. BiEntropy v. 1.0; 005634MLTPL00); Sandia National Lab: Albuquerque, NM, USA, 2018.
- Gurrieri, T.M.; Hamlet, J.R.; Bauer, T.M.; Helinski, R.; Pierson, L.G. US Patent for Integrated Circuit Physically Unclonable Function. U.S. Patent 10,103,733, 16 October 2018. [Google Scholar]
- Crandall, R.; Pomerance, C. Prime Numbers: A Computational Perspective; Springer: Berlin/Heidelberg, Germany, 2005. [Google Scholar]
- Guy, R. Unsolved Problems in Number Theory; Springer: Berlin/Heidelberg, Germany, 2004. [Google Scholar]
- Rassias, M. Problem-Solving and Selected Topics in Number Theory; Springer: Berlin/Heidelberg, Germany, 2011. [Google Scholar]
- Miller, S.; Takloo-Bighash, R. An Invitation to Modern Number Theory; Princeton Univ. Press: Princeton, NJ, USA, 2006. [Google Scholar]
- Nash, J.F., Jr.; Rassias, M.T. Open Problems in Mathematics; Springer: Berlin/Heidelberg, Germany, 2016. [Google Scholar]
- Croll, G.J. The importance and criticality of spreadsheets in the city of London. arXiv
**2007**, arXiv:0709.4063. [Google Scholar] - Grossman, T.A. Spreadsheet engineering: A research framework. arXiv
**2007**, arXiv:0711.0538. [Google Scholar] - Grossman, T.A. A primer on spreadsheet analytics. arXiv
**2008**, arXiv:0809.3586. [Google Scholar] - Csernoch, M.; Biró, P. Problem Solving in Sprego. arXiv
**2016**, arXiv:1603.02262. [Google Scholar] - Csernoch, M.; Biró, P. Edu-Edition Spreadsheet Competency Framework. arXiv
**2018**, arXiv:1802.00496. [Google Scholar] - Shannon, C.E. A Mathematical Theory of Communication. Bell Syst. Tech. J.
**1948**, 27, 379–423. [Google Scholar] [CrossRef][Green Version] - Nathanson, M.B. Derivatives of binary sequences. SIAM J. Appl. Math.
**1971**, 21, 407–412. [Google Scholar] [CrossRef] - Goka, T. An operator on binary sequences. SIAM Rev.
**1970**, 12, 264–266. [Google Scholar] [CrossRef] - Chaitin, G.J.; Schwartz, J.T. A note on Monte Carlo primality tests and algorithmic information theory. Pap. Algorithmic Inf. Theory
**1990**, 8, 197. [Google Scholar] - Boklan, K.D.; Conway, J.H. Expect at most one billionth of a new Fermat Prime! arXiv
**2016**, arXiv:1605.01371. [Google Scholar] [CrossRef][Green Version] - Davies, N.; Dawson, E.; Gustafson, H.; Pettitt, A.N. Testing for randomness in stream ciphers using the binary derivative. Stat. Comput.
**1995**, 5, 307–310. [Google Scholar] [CrossRef] - von Koch, H. Ueber die Riemann’sche Primzahlfunction. Math. Ann.
**1901**, 55, 441–464. [Google Scholar] [CrossRef] - Croll, G.J. BiEntropy–the Measurement and Algebras of Order and Disorder in Finite Binary Strings. In Scientific Essays in Honor of H Pierre Noyes on the Occasion of His 90th Birthday; World Scientific: Singapore, 2014. [Google Scholar]
- Guariglia, E. Primality, Fractality, and Image Analysis. Entropy
**2019**, 21, 304. [Google Scholar] [CrossRef][Green Version] - Laroche, P. GIMPS. Available online: https://www.mersenne.org/primes/press/M82589933.html (accessed on 5 March 2020).

Colour Code | BiEntropy | Count | Prime | Prime Proportion |
---|---|---|---|---|

White | <0.15 | 32 | 1 | 0.0312 |

Yellow | <0.25 | 32 | 1 | 0.0312 |

Orange | <0.50 | 64 | 15 | 0.2343 |

Red | <1.00 | 128 | 37 | 0.2890 |

Prime | Not Prime | Odd | Mersenne | Twin | |
---|---|---|---|---|---|

Mean | 0.7897 | 0.5863 | 0.5099 | 0.8134 | 0.7783 |

S.Dev | 0.2505 | 0.3444 | 0.3497 | 0.2443 | 0.2674 |

N | 54 | 202 | 75 | 4 | 33 |

Segment | BiEntropy ≤ | Primes |
---|---|---|

1 | 0.1141 | 1 |

2 | 0.2395 | 1 |

3 | 0.4558 | 8 |

4 | 0.4734 | 6 |

5 | 0.9350 | 6 |

6 | 0.9487 | 9 |

7 | 0.9506 | 9 |

8 | 0.9532 | 14 |

x | Bits(m) | π(x) | Derivatives(d) | d/π(x)% |
---|---|---|---|---|

256 | 8 | 54 | 28 | 51.85% |

65536 | 16 | 6542 | 120 | 1.83% |

4,294,967,296 | 32 | 203,280,221 | 496 | 0.00% |

0 | 1 | 2 | |

0 | 0 | 1 | 2 |

1 | 1 | 0 | 1 |

2 | 2 | 1 | 0 |

A | B | C | PTD | TriEntropy |
---|---|---|---|---|

0 | 0 | 0 | 0 | 0.168 |

0 | 0 | 1 | 2 | 0.395 |

0 | 0 | 2 | 1 | 0.395 |

0 | 1 | 0 | 2 | 0.395 |

0 | 1 | 1 | 2 | 0.395 |

0 | 1 | 2 | 1 | 0.395 |

0 | 2 | 0 | 1 | 0.395 |

0 | 2 | 1 | 1 | 0.395 |

0 | 2 | 2 | 1 | 0.395 |

1 | 0 | 0 | 2 | 0.395 |

1 | 0 | 1 | 2 | 0.395 |

1 | 0 | 2 | 1 | 0.395 |

1 | 1 | 0 | 2 | 0.395 |

1 | 1 | 1 | 0 | 0.168 |

1 | 1 | 2 | 2 | 0.395 |

1 | 2 | 0 | 1 | 0.395 |

1 | 2 | 1 | 2 | 0.395 |

1 | 2 | 2 | 2 | 0.395 |

2 | 0 | 0 | 1 | 0.395 |

2 | 0 | 1 | 1 | 0.395 |

2 | 0 | 2 | 1 | 0.395 |

2 | 1 | 0 | 1 | 0.395 |

2 | 1 | 1 | 2 | 0.395 |

2 | 1 | 2 | 2 | 0.395 |

2 | 2 | 0 | 1 | 0.395 |

2 | 2 | 1 | 2 | 0.395 |

2 | 2 | 2 | 0 | 0.168 |

Trinary Expansion of N | Len(N) | N0 | N1 | N2 | p | 1−p | −p.log(p) | −(1−p).log(1−p) | TriEn | k | 3^k | TriEn.3^k |
---|---|---|---|---|---|---|---|---|---|---|---|---|

111201101 | 9 | 2 | 6 | 1 | 0.33 | 0.67 | 0.53 | 0.39 | 0.92 | 0 | 1 | 0.92 |

0211222 | 7 | 1 | 2 | 4 | 0.40 | 0.60 | 0.53 | 0.44 | 0.97 | 1 | 3 | 2.91 |

12220 | 5 | 1 | 1 | 3 | 0.38 | 0.62 | 0.53 | 0.43 | 0.96 | 2 | 9 | 8.61 |

201 | 3 | 1 | 1 | 1 | 0.33 | 0.67 | 0.53 | 0.39 | 0.92 | 3 | 27 | 24.79 |

3.76 | 6 | 40 | 37.23 | |||||||||

TriEn(s) | 0.93 |

© 2020 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Croll, G.J. BiEntropy, TriEntropy and Primality. *Entropy* **2020**, *22*, 311.
https://doi.org/10.3390/e22030311

**AMA Style**

Croll GJ. BiEntropy, TriEntropy and Primality. *Entropy*. 2020; 22(3):311.
https://doi.org/10.3390/e22030311

**Chicago/Turabian Style**

Croll, Grenville J. 2020. "BiEntropy, TriEntropy and Primality" *Entropy* 22, no. 3: 311.
https://doi.org/10.3390/e22030311