Giter Club home page Giter Club logo

prime's Introduction

Prime

An attempt to optimise the search for Prime.

Abstract

Prime numbers are defined as numbers greater than 1 that have no positive divisors other than 1 and themselves. 1 is self-Prime. The sequence of Prime numbers starts with 2, 3, 5, 7, 11, and so on.

A Prime is any number only divisible by 1 and itself searching first that a number is not even if it divides by 2, optimising using a "Vignette Sieve" that if not only up to n/2 needs to be tested as a divisor, then 3 if not only up to n/3 needs to be tested as divisor, n/5, n/7, n/11, n/13, n/17, n/19, n/23, n/29, n/31 & so on so that only divisibility by a Prime needs to be checked for to prove not Prime & since for example we have ruled out that the number is a factor of three or two so there is no natural number greater than n/3 that can be a divisor.

Usage

On first run use prime.py firstrun to build the data table. The data table may be provided. It can find up to 104729 the 10,000th Prime in under 6 seconds and can possibly be accellerated with mpiexec

$py prime.py firstrun
Firstrun: Building _data
Completed creating data to 10000 Primes
Largest Prime in Index:104729
--- 5.355212926864624 Seconds ---

Future implementation in development

prime.py [number to check]

Output: List of Prime numbers up to the input. If only the output Prime or not prime is required edit prime.py.

File _data contains the raw found Prime data.

Operation

prime.py will use the data table of found Prime numbers to optimise the search for Prime up to the Vignette Sieve fraction necessary & when searching above found Primes will search for additional Prime numbers & add these to the data to test the input for Prime. This approach is optimised heavily because it is only necessary to check up to the highest fraction divisor of the number already checked n/x. The Vignette Seive is a convergance function I have written as the Integral described in Image1
The Integral of is x Prime
Image1: The Integral of is x Prime. Professor. Damian A. James Williamson
Links to: WolframAlpha

It should be possible to run with mpiexec Build a Raspberry Pi cluster computer

Professor. Damian A. James Williamson

=======

Appendix

Future Optimisations

Notes: LinkedIn comments

Optimising further than checking only if a number is not even it is possible to check only if a number is one more or less than a factor of 6 so counting for 5 is +2 for 7 and +4 for 11 and so forth. Then when counting from a high number counting back to a number divisible by 6 if it is 1 less add 4 to the number we started with and if it is 5 less add 2 then continue as previously.

It should be possible to have in addition to a find next Prime function a find next number to check from unknown sequence and find next number from known position in sequence. The approach is to build the functions necessary into firstrun that searches by magnitude providing a proof and then build main that validates an individual number. The easiest wat to check whether to check a number is to check if it is dividible by 6 and then if it is one number more or less than 6, say if we look at 11 it is not divisible by 6 and it is one less than 6 so we try. This saves a lot of computation with larger numbers.

Professor. Damian A. James Williamson

Reference

The mpmath development team. (2023). mpmath - Python library for arbitrary-precision floating-point arithmetic. Retrieved February 2, 2024, from https://mpmath.org/

Mathematics Stack Exchange. (2013). multiplicative function - How to find the nearest multiple of 16 to my given number n - Mathematics Stack Exchange. Retrieved February 2, 2024, from https://math.stackexchange.com/questions/291468/how-to-find-the-nearest-multiple-of-16-to-my-given-number-n

Stack Overflow. (2010). How to extract numbers from a string in Python? - Stack Overflow. Retrieved February 2, 2024, from https://stackoverflow.com/questions/4289331/how-to-extract-numbers-from-a-string-in-python

Stack Overflow. (2010). python - Checking whether a variable is an integer or not - Stack Overflow. Retrieved February 2, 2024, from https://stackoverflow.com/questions/3501382/checking-whether-a-variable-is-an-integer-or-not

Phillips, C. (2015). Writing Mathematics in Plain Text Email. Retrieved January 24, 2024, from https://pages.uoregon.edu/ncp/Courses/MathInPlainTextEmail.html

prime's People

Contributors

willtech avatar

Stargazers

 avatar

Watchers

 avatar

prime's Issues

Convert to LevelDB

Looking at the use of a tuple to store the computed Prime and to load them from storage, it seems apparent that the program operation would benefit through increased speed from the use of LevelDB. The use of a tuple is faster than a list however, as the size of the tuple grows past 10,000 Prime the speed slows from 6 seconds to many days for computing 10,000,000 Prime. LevelDB allows for lookup and storage in memory of only the relevant Prime needed for computation an optimisation designed to increase the speed average of searching for more Prime.

LevelDB Features:

  • Key-Value Store: Data is stored as key-value pairs, where both keys and values are arbitrary byte arrays.
  • Ordered Data: The data is stored sorted by key, which allows for efficient range queries.
  • Atomic Batches: Multiple changes can be made in one atomic batch, ensuring data integrity.
  • Compression: Supports compression of the data via Google's Snappy compression library, reducing storage space. (although we should not use it)
  • Simple API: Offers basic operations like Get, Put, and Delete, making it easy to use.

Are the first 1,000,000 Prime?

A statistical analysis using an online tool shows it is very likely the first 1,000,000 numbers found in _data release WIPPPING IT are Prime both that they are and the 1,000,000th number 15485863 is the 1,000,000th Prime.

If anybody wants to perform some sort of empirical validation it is a worthwhile assignment I can include your comments.

Professor. Damian A. James Williamson

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.