Wang tiles and finite tilesets
DefinitionDominoProblem_WangTiledomino-problemtilingwang-tiles
A Wang tile is an oriented square with a natural-number color on each of its four edges. Its colors, in west, north, south, east order, uniquely determine the tile. A tileset is a finite set of these tiles; rotations and reflections are not added automatically. The equivalence with ordered quadruples gives a denumerable encoding of tiles.
Definition code
import Mathlib.Data.Finset.Basic import Mathlib.Logic.Denumerable namespace DominoProblem /-- An oriented Wang tile with a natural-number color on each edge. -/ structure Tile where W : ℕ N : ℕ S : ℕ E : ℕ deriving DecidableEq /-- The four edge colors of a tile, in constructor order. -/ def Tile.codeEquiv : Tile ≃ ℕ × ℕ × ℕ × ℕ where toFun t := (t.W, t.N, t.S, t.E) invFun p := ⟨p.1, p.2.1, p.2.2.1, p.2.2.2⟩ left_inv _ := rfl right_inv _ := rfl instance : Denumerable Tile := Denumerable.ofEquiv _ Tile.codeEquiv /-- A finite set of allowed Wang tiles. -/ abbrev Tileset := Finset Tile end DominoProblem
Source
Mathematical definition: Hao Wang, “Proving Theorems by Pattern Recognition — II,” Bell System Technical Journal 40 (1961), §4.1, “A Generalized Game of Dominoes,” p. 22. https://doi.org/10.1002/j.1538-7305.1961.tb03975.x
Lean representation and encoding: Alex P. Klinkhamer, PeriodicDomino/Basic.lean, lines 10–28 (0BSD). https://github.com/ProtocolConvergence/periodic-domino-lean/blob/af6699cbf84ea7e57a0eddcead118c59f0e3dbe9/PeriodicDomino/Basic.lean#L10-L28