You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-7Lines changed: 16 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,15 @@ All scripts are included in the `scripts/` folder of this repository. Each scrip
6
6
7
7
The following is a brief description of the included functions, divided into rough categories.
8
8
9
+
## Analysis Functions
10
+
11
+
A variety of scripts dealing with functions and sets, which may have some uses for managing data structures.
12
+
13
+
*[`_integer_to_natural`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_integer_to_natural/_integer_to_natural.gml): Converts an integer to a unique natural number using the zig-zagging bijection from _0, 1, -1, 2, -2, ..._ to _0, 1, 2, 3, 4, ..._. The inverse of `_natural_to_integer`.
14
+
*[`_natural_to_integer`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_natural_to_integer/_natural_to_integer.gml): Converts a natural number to a unique integer using the zig-zagging bijection from _0, 1, 2, 3, 4, ..._ to _0, 1, -1, 2, -2, ..._. The inverse of `_integer_to_natural`.
15
+
*[`_natural_to_pair`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_natural_to_pair/_natural_to_pair.gml): Converts a natural number to a unique ordered pair of natural numbers using the [inverse Cantor pairing function](https://en.wikipedia.org/wiki/Pairing_function#Inverting_the_Cantor_pairing_function). The inverse of `_pair_to_natural`.
16
+
*[`_pair_to_natural`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_pair_to_natural/_pair_to_natural.gml): Converts an ordered pair of natural numbers to a unique natural number using the [Cantor pairing function](https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function). The inverse of `_pair_to_natural`.
17
+
9
18
## Array Functions
10
19
11
20
Common array functions (such as searching and counting).
@@ -23,20 +32,20 @@ Common array functions (such as searching and counting).
23
32
24
33
Numerical algorithms for computational mathematics.
25
34
26
-
*[`_cubic_spline_coefficients`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_cubic_spline_coefficients/_cubic_spline_coefficients.gml): Calculates vectors of coefficients for the natural cubic polynomial interpolating a given data set.
35
+
*[`_cubic_spline_coefficients`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_cubic_spline_coefficients/_cubic_spline_coefficients.gml): Calculates vectors of polynomial coefficients for the natural [cubic spline](https://en.wikipedia.org/wiki/Spline_interpolation) interpolating a given data set.
27
36
*[`_cubic_spline_evaluate`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_cubic_spline_evaluate/_cubic_spline_evaluate.gml): Evaluates a piecewise cubic polynomial at a specific value given a given set of coefficient vectors and intervals.
28
-
*[`_root_bisection`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_root_bisection/_root_bisection.gml): Finds a function root on a specified interval using the bisection method.
29
-
*[`_root_newton`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_root_newton/_root_newton.gml): Finds a function root given a derivative and an initial guess using Newton's method.
37
+
*[`_root_bisection`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_root_bisection/_root_bisection.gml): Finds a function root on a specified interval using the [bisection method](https://en.wikipedia.org/wiki/Bisection_method).
38
+
*[`_root_newton`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_root_newton/_root_newton.gml): Finds a function root given a derivative and an initial guess using [Newton's method](https://en.wikipedia.org/wiki/Newton%27s_method).
30
39
31
40
## Linear Algebra Functions
32
41
33
-
Common linear algebra algorithms for dealing with matrices and vectors. In all functions, _vectors_ are considered to be 1D arrays while _matrices_ are 2D arrays.
42
+
Common linear algebra algorithms for dealing with matrices and vectors. In all functions, _vectors_ are considered to be 1D arrays while _matrices_ are 2D arrays (i.e. arrays of arrays).
34
43
35
-
*[`_linear_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_linear_solve/_linear_solve.gml): Solves a linear system given a coefficient matrix and righthand vector (using Gaussian elimination with partial pivoting).
44
+
*[`_linear_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_linear_solve/_linear_solve.gml): Solves a linear system given a coefficient matrix and righthand vector (using [Gaussian elimination with partial pivoting](https://en.wikipedia.org/wiki/Pivot_element)).
36
45
*[`_matrix_multiply`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_matrix_multiply/_matrix_multiply.gml): Performs matrix-matrix, matrix-vector, and vector-vector multiplication.
37
46
*[`_matrix_transpose`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_matrix_transpose/_matrix_transpose.gml): Transposes a 2D matrix.
38
-
*[`_tridiagonal_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_tridiagonal_solve/_tridiagonal_solve.gml): Solves a tridiagonal system (using the Thomas algorithm).
39
-
*[`_triangular_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_triangular_solve/_triangular_solve.gml): Solves an upper or lower triangular system (using forward or back substitution).
47
+
*[`_tridiagonal_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_tridiagonal_solve/_tridiagonal_solve.gml): Solves a tridiagonal system (using the [Thomas algorithm](https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm)).
48
+
*[`_triangular_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_triangular_solve/_triangular_solve.gml): Solves an upper or lower triangular system (using [forward or back substitution](https://www.cs.cornell.edu/~bindel/class/cs6210-f12/notes/lec08.pdf)).
40
49
*[`_unit_vector`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_unit_vector/_unit_vector.gml): Defines a unit direction vector between two coordinates.
41
50
*[`_vector_angle`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_vector_angle/_vector_angle.gml): Calculates the acute angle between two vectors.
42
51
*[`_vector_distance`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_vector_distance/_vector_distance.gml): Calculates the Lp-distance between two vectors.
/// @desc Returns a unique natural number (beginning with 0) for a given integer, according to the straightforward zig-zagging bijection (0, 1, -1, 2, -2, ...).
3
+
/// @param {int} n Integer for which to generate a unique natural number.
4
+
/// @return {int} Natural number (at least 0) corresponding to integer n.
5
+
/**
6
+
* This function is meant to be the inverse of the _nautral_to_integer()
7
+
* function. Both are based on the bijection which maps (0, 1, -1, 2, -2, ...)
8
+
* to (0, 1, 2, 3, 4, ...).
9
+
*
10
+
* For the Z -> N bijection we use the following piecewise definition:
11
+
* |2n|-1 if n > 0
12
+
* |2n| if n <= 0
13
+
*/
14
+
15
+
function _integer_to_natural(n)
16
+
{
17
+
// Apply piecewise definition depending on the sign of n
/// @desc Returns a unique integer for a given natural number (beginning with 0), according to the straightforward zig-zagging bijection (0, 1, -1, 2, -2, ...).
3
+
/// @param {int} n Natural number for which to generate a unique integer.
4
+
/// @return {int} Integer corresponding to natural number n.
5
+
/**
6
+
* This function is meant to be the inverse of the _integer_to_natural()
7
+
* function. Both are based on the bijection which maps (0, 1, 2, 3, 4, ...)
8
+
* to (0, 1, -1, 2, -2, ...).
9
+
*
10
+
* For the N -> Z bijection we use the following piecewise definition:
11
+
* -n/2 if n is even
12
+
* (n+1)/2 if n is odd
13
+
*/
14
+
15
+
function _natural_to_integer(n)
16
+
{
17
+
// Apply piecewise definition depending on the parity of n
0 commit comments