Affine Planes Documentation
Safe HaskellSafe-Inferred

MOLS

Synopsis

Documentation

type LatinSquare = [[Int]] #

Type alias for a Latin Square, represented as a list of lists of Ints

primeMols :: Int -> [LatinSquare] #

Generates all order-1 prime Mutually Orthogonal Latin Squares (MOLS) of a given order.

Parameters

  • order: The order of the Latin Squares.

Examples

>>> primeMols 3
[[[0,1,2],[1,2,0],[2,0,1]],[[0,1,2],[2,0,1],[1,2,0]]]
[
   [
       [0,1,2],
       [1,2,0],
       [2,0,1]
   ],
   [
       [0,1,2],
       [2,0,1],
       [1,2,0]
   ]
]

mols4 :: [LatinSquare] #

A predefined set of 4x4 Mutually Orthogonal Latin Squares.

containsAll :: [Int] -> Int -> Bool #

Check if a list contains all elements from 0 to n-1

checkColumns :: LatinSquare -> Int -> Bool #

Check if each column contains all elements from 0 to n-1

isLatinSquare :: LatinSquare -> Bool #

Check if each row and column contains all elements from 0 to n-1 === Examples

>>> isLatinSquare [[0,1,2],[1,2,0],[2,0,1]]
True
>>> isLatinSquare (primeMols 3 !! 0)
True
>>> isLatinSquare [[0,1,2],[1,2,2],[2,0,1]]
False

isMO :: LatinSquare -> LatinSquare -> Bool #

Check if two Latin squares are mutually orthogonal.

Parameters

  • xs: The first Latin square.
  • ys: The second Latin square.

Examples

>>> isMO [[0,1,2],[1,2,0],[2,0,1]] [[0,1,2],[2,0,1],[1,2,0]]
True
>>> isMO [[0,1,2],[1,2,0],[2,0,1]] [[0,1,2],[1,2,0],[2,0,1]]
False
>>> isMO ((primeMols 4) !! 0) ((primeMols 4) !! 2)
False

molsVerify :: [LatinSquare] -> Bool #

Verify if a list of MOLS forms a mutually orthogonal set. Function expects that no Latin square is repeated.

Parameters

  • mols: The list of Latin squares.

Examples

>>> molsVerify (primeMols 3)
True
>>> molsVerify (primeMols 4)
False
>>> molsVerify mols4
True