Latin squares and designs
A design arranges points into blocks so that every pair of points meets equally often. Latin squares, finite geometries and Steiner triple systems are all designs, and their existence is a question about arithmetic in finite fields.
Latin squares
import { cyclicLatinSquare, isLatinSquare, orthogonalLatinSquares, areOrthogonal } from "@ratmath/discrete";
isLatinSquare(cyclicLatinSquare(6)); // { latin: true, problem: null }
const L = orthogonalLatinSquares(5); // 4 squares: L_a[i][j] = a·i + j mod 5
areOrthogonal(L[0], L[1]); // { orthogonal: true, repeated: null }
Each symbol appears once in every row and column. Two squares are orthogonal when superimposing them gives every ordered pair of symbols exactly once. For a prime , the squares with are mutually orthogonal, since and force when . At most squares of order can be mutually orthogonal, so this is a complete set. Euler's 36 officers () have no orthogonal pair at all.
Block designs
import { blockDesign, projectivePlane, affinePlane, fromDifferenceSet, steinerTripleSystem } from "@ratmath/discrete";
const fano = blockDesign(projectivePlane(2));
[fano.v, fano.b, fano.k, fano.r, fano.lambda]; // [7, 7, 3, 3, 1]: the Fano plane
blockDesign(fromDifferenceSet([1, 3, 4, 5, 9], 11)).lambda; // 2: the squares mod 11
blockDesign(steinerTripleSystem(15)).b; // 35 triples
A design has points and blocks of size , with every pair of points in exactly blocks. Counting pairs gives the necessary conditions
and Fisher's inequality . blockDesign computes from the blocks and checks these relations, returning lambda: null when pairs are not balanced.
Finite geometry
The projective plane of order has the one-dimensional subspaces of as points and the two-dimensional ones as lines: of each, points on a line, and any two points on exactly one line. Removing one line and its points leaves the affine plane, points in lines. A difference set , where every non-zero residue is a difference of elements of exactly times, gives a design with blocks . Steiner triple systems (, ) exist exactly when or ; Bose's construction covers .
@ratmath/discrete and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.