Skip to content

Rationale of Design Decisions

Jorj X. McKie edited this page Mar 22, 2017 · 1 revision

These scripts were developed for my own requirements. I know that other / better implementations may (and probably do) exist - especially when not confining oneself to Python.

And I do know that there are big free mathematical packages out there, including some in Python like SAGE.

For what I do, I just needed something to qickly determine primalities (and being in full control of the interface) without having to leave my beloved Python environment, and also without having to start my SAGE virtual machine (I am a Windows user).

As space is not an issue anymore, prime numbers once calculated can be stored away and looked up when needed. This avoids to primality test integers over and over again, thus reducing the performance penalty incurred using a Python environment.

The type of storage I chose is the array module: my prime numbers are not larger than unsigned 32 bit integers can express = about 4.3 billion. So an array.array of type L is the appropriate Python type to choose - rather than general lists. Other advantages of this choice are, that you can directly store such arrays to disk - no need to pickle or JSONize it.

So in my case, if I have an array of n prime numbers, I can store it into a binary file of size 4*n. I decided to ZIP this file on top, which gives me a 3 to 5 factor space reduction - depending on the Python version: LZMA available under Python 3 is of course a lot better.

Clone this wiki locally