Prime Fold is a JavaScript web application for discovering mathematical functions that generate or embed prime numbers using evolutionary algorithms and advanced fitness functions. The goal is to help you explore, visualize, and evolve mathematical formulas that reveal interesting patterns in the distribution of prime numbers.
f_x(n)
and f_y(n)
, to map numbers to 2D points. Primes and composites are visualized differently. This mode helps you discover spatial patterns and structures unique to primes. Example: f_x(n) = n, f_y(n) = n^2
or simply n, n^2
.f(n)
, to generate numbers. The app visualizes which outputs are prime and how many unique primes are produced. Example: f(n) = 2*n + 1
.Finds functions f(n) and g(n) that map prime numbers to well-distributed 2D points with interesting patterns.
Finds function f(n) that generates many unique prime numbers.
You can enter mathematical expressions to define functions for visualizing or generating primes. Expressions use the variable n
and support a variety of operators, functions, and constants.
f_x(n) = n, f_y(n) = n^2
or simply n, n^2
.f(n) = 2*n + 1
or just 2*n + 1
.Operator | Description | Example |
---|---|---|
+ | Addition | n + 2 |
- | Subtraction | n - 1 |
* | Multiplication | 2 * n |
/ | Division | n / 3 |
% | Modulo (remainder) | n % 2 |
mod | Modulo (alternative) | n mod 2 |
^ | Exponentiation | n^2 |
Function | Description | Example |
---|---|---|
sin(x) | Sine (radians) | sin(n) |
cos(x) | Cosine (radians) | cos(n) |
sind(x) | Sine (degrees) | sind(n) |
cosd(x) | Cosine (degrees) | cosd(n) |
sqrt(x) | Square root | sqrt(n) |
log(x) | Natural logarithm | log(n) |
abs(x) | Absolute value | abs(n-10) |
floor(x) | Floor (round down) | floor(n/2) |
ceil(x) | Ceiling (round up) | ceil(n/2) |
square(x) | Square (x^2) | square(n) |
cube(x) | Cube (x^3) | cube(n) |
Name | Value |
---|---|
pi | 3.141592... |
e | 2.718281... |
sqrt2 | 1.414213... |
phi | 1.618033... (golden ratio) |
()
to group expressions: (n + 1) * 2
^
and square(x)
, cube(x)
are supported for powers.mod
and %
are equivalent for modulo.sin(n)
, sqrt(n+1)
, etc.f(n) =
or f_x(n) =
/f_y(n) =
and just write the expressions directly.f_x(n) = n, f_y(n) = n^2
n, n^2
sin(n), cos(n)
n, n mod 5
sqrt(n), log(n)
f(n) = 2*n + 1
n^2 + 1
abs(n-10)
cube(n) - 1
If you enter an invalid expression, check the browser console for errors. For more details, see the README or the Expressions Guide in the repository.