What is a Magic Square?

A magic square is an nร—n grid of distinct positive integers where every row, column, and both main diagonals sum to the same value โ€” the magic constant.

We present a framework that embeds magic squares as point clouds in โ„ยณ, revealing that they are uniquely characterized by zero spatial-value covariance. This provides a continuous formulation of discrete constraints and enables polynomial-time generation algorithms.

The Lo Shu Square

The oldest known magic square, dating back to ancient China (~2200 BCE).

2
7
6
9
5
1
4
3
8

Magic constant: M(3) = 15

The Magic Constant

For any nร—n magic square:

\[ M(n) = \frac{n(n^2 + 1)}{2} \]
nM(n)Magic Squares
3158
4347,040
565~275 million

๐Ÿ”ฌ Key Discovery

Magic squares are characterized by zero covariance between position and value. They are the unique ground states of a natural energy functional โ€” isolated minima in a vast landscape of arrangements.

Key Research Findings

Analysis of all 880 unique 4ร—4 magic squares (enumerated by Frรฉnicle de Bessy in 1693) reveals:

๐Ÿ”ท 21 Geometric Configurations

Based on convex hull structure (vertices, face points, interior points), the 880 magic squares fall into exactly 21 distinct geometric families.

โšก Polynomial-Time Generation

Gradient descent on the covariance objective achieves O(nโด) complexity, approximately 73ร— faster than traditional backtracking methods.

๐ŸŒ Connected Manifold

The 880 squares form a single connected component in Earth Mover's Distance (EMD) space, revealing deep topological structure.

๐ŸŽฏ Fragile Uniqueness

Testing 100,000 single-swap perturbations, the minimum covariance observed was 0.2โ€”never zero. Magic squares are the unique solutions.

Mathematical Properties

The Magic Gem framework reveals exact formulas for the statistical structure of magic squares:

๐Ÿ“Š Exact Variance Formulas

For any nร—n magic square, the variances have closed forms:

\[ \text{Var}(Z) = \frac{n^4 - 1}{12}, \quad \text{Var}(X) = \text{Var}(Y) = \frac{n^2 - 1}{12} \]

Verified computationally for n = 3, 4, 5, 7 with exact agreement.

๐Ÿ“ˆ Higher-Order Moment Vanishing

The zero-covariance property extends to all higher powers:

\[ \mathbb{E}[X^k Z] = \mathbb{E}[Y^k Z] = 0 \text{ for all } k \]

This follows from equal row and column sumsโ€”a stronger form of statistical balance.

โšก Perturbation Gap Scaling

The minimum energy increase from any single swap scales as:

\[ \Delta_{\min} \propto \frac{1}{n^2} \]

Energy wells become shallower as order increases, but magic squares remain isolated local minima.

The Zero-Covariance Theorem

Theorem: A 4ร—4 arrangement of distinct integers 1โ€“16 is a magic square if and only if four specific covariances vanish:

  • Cov(row position, value) = 0
  • Cov(column position, value) = 0
  • Cov(main diagonal position, value) = 0
  • Cov(anti-diagonal position, value) = 0

Equivalently, the energy functional must equal zero:

\[ E(S) = \text{Cov}(X,Z)^2 + \text{Cov}(Y,Z)^2 + \text{Cov}(D_{\text{main}},Z)^2 + \text{Cov}(D_{\text{anti}},Z)^2 = 0 \]

This provides a continuous characterization of the discrete constraint. Magic squares achieve perfect statistical balanceโ€”center of mass at origin, zero angular momentum.

Paper & Resources

Access the full research paper with proofs, reproducible code, and additional materials:

๐Ÿ“„ Read Paper (arXiv) ๐Ÿ’ป View Code (GitHub)

Run python reproduce_all.py to regenerate all results.

References & Further Reading

Magic Gem Controls

Current Magic Square

Hull Volume โ€”
Hull Vertices โ€”
Energy 0

The Covariance Energy Landscape

Magic squares are the unique ground states of a natural energy functional. They sit at the bottom of deep wells in a vast, rugged landscape.

Energy Distribution (n=3)

All 362,880 permutations analyzed. Only 8 have E=0.

Perturbation Analysis

Every single-swap perturbation increases energy.

Scaling Properties

Peak energy scales as O(nยฒ), but gap scales as O(1/nโด).

Interactive Energy Explorer

Click cells to swap values and watch the energy change in real-time.

Energy: 0.000

๐Ÿ” New Discovery: Many Local Minima

For n=3, there are 344 local minima in the energy landscape, not just the 8 magic squares. Magic squares are the unique global minima, but the landscape is highly rugged with many metastable states.

Advanced 4ร—4 Magic Square Catalogue

Browse all 880 unique 4ร—4 magic squares with an advanced visualization tool featuring face pairing detection and arc connections.

Face Pairing Analysis

Key Features:

  • Similar Face Detection: Automatically identifies faces with identical geometry (edge lengths and angles)
  • Color Coding: Same-colored faces share the same geometric properties
  • Arc Connections: Beautiful glowing arcs connect paired faces through 3D space
  • Adjustable Epsilon: Control the similarity threshold for face matching

This reveals hidden symmetries in the Magic Gem polyhedra that aren't immediately visible.

Visualization Controls

Available Options:

  • Points/Hull/Vectors: Toggle different geometric elements
  • Orthographic Mode: Switch to orthographic projection
  • Multiple Views: Front, back, left, right, top, bottom presets
  • Point Size & Hull Opacity: Adjust visual properties
  • Axes Toggle: Show/hide coordinate axes

Statistics Dashboard

For each magic square, view detailed metrics:

  • Total Faces: Number of triangular faces in the convex hull
  • Paired Faces: How many faces have geometric twins
  • Unique Vertices: Points on the hull boundary
  • Volume: Precise volume calculation of the Magic Gem
  • Interior Points: Grid points trapped inside the hull

๐Ÿ”ฌ Research Discovery

The face pairing patterns vary significantly across the 880 squares. Some gems have many paired faces (high symmetry), while others have mostly unique faces. This geometric diversity reflects the rich structure of the 4ร—4 magic square space!

All 4ร—4 Magic Squares

Explore all unique 4ร—4 magic squares. Click any square to view its Magic Gem in 3D.

Select Magic Square

Selected Square #1

Total Faces โ€”
Paired Faces โ€”
Unique Vertices โ€”
Volume โ€”
Interior Points โ€”

Magic Square Manifold Explorer

Explore the topological structure of all 880 unique 4ร—4 magic squares in Earth Mover's Distance (EMD) space. They form a single connected component!

What is Earth Mover's Distance?

EMD measures the minimum "work" needed to transform one magic square into another by moving values between cells.

  • Structural Metric: Captures semantic similarity between squares
  • Continuous Space: Discrete objects embedded in continuous manifold
  • Distance Preserving: Similar squares cluster together geometrically
  • Connected Component: All squares reachable from any other

Key Findings

Topological Structure:

  • Single Component: No isolated clustersโ€”all squares connected
  • Dense Regions: Some areas have high concentration of similar squares
  • Symmetry Orbits: Dโ‚„ equivalence classes form geometric patterns
  • Smooth Manifold: Local neighborhood structure reveals gradual transitions

This connectivity proves the rich combinatorial structure has deep geometric unity.

๐Ÿ”ฌ Research Insight

The single connected component structure suggests that the space of magic squares is not fragmented into isolated families. Any magic square can be continuously transformed into any other through the EMD metric space, revealing a fundamental unity in their geometric structure!

Paper Craft Templates - 3ร—3 Magic Gems

Unfold the 3D Magic Gems into flat patterns. Same-colored faces have identical geometry. Start with the Lo Shu square!

Square Gallery (3ร—3)

All 8 unique 3ร—3 magic squares (Dโ‚„ orbit of Lo Shu). Simpler geometry with only 8 faces!

Creates a different net layout by starting from a different face

3D Magic Gem

2D Paper Net

Selected Square #1

Total Faces โ€”
Face Groups โ€”
Unique Edges โ€”

๐Ÿ’ก Compare the 3D gem (left) with the flat net (right). Same-colored faces match!

Paper Craft Templates - 4ร—4 Magic Gems

Unfold 4ร—4 Magic Gems into flat patterns. More complex geometry with ~20 faces!

Square Gallery (4ร—4)

Browse 4ร—4 magic squares. Each creates a unique polyhedron with richer geometry!

Creates a different net layout by starting from a different face

3D Magic Gem

2D Paper Net

Selected Square #1

Total Faces โ€”
Face Groups โ€”
Unique Edges โ€”

๐Ÿ’ก Compare the 3D gem (left) with the flat net (right). Same-colored faces match!

Interactive Explorer

Build your own magic squares and explore their properties in real-time.

Create Magic Square

Current Arrangement

Click cells to swap values

Properties

Is Magic? โ€”
Energy E(S) โ€”
Cov(X,Z) โ€”
Cov(Y,Z) โ€”
Determinant โ€”
Hull Vertices โ€”

Row/Column Sums

Eigenvalues

Covariance Matrix

3D Magic Gem Preview

Interactive Paper Craft Builder

Drag, rotate, and snap triangles together. Explore symmetries and build larger shapes!

Controls

Instructions

  • Left-click drag: Move triangle
  • Right-click: Rotate 60ยฐ
  • Shift + drag: Rotate freely
  • H key: Flip horizontally
  • V key: Flip vertically
  • U or D key: Unpair/disconnect
  • R key: Rotate 60ยฐ
  • Near edges: Auto-snap when aligned
  • Green glow: Compatible edges
  • Connected pieces: Move as group

Statistics

Pieces 12
Connected Groups 12
Snapped Edges 0

๐Ÿ’ก Try building the original magic gem by snapping all pieces together!

3D Models & STL Files

Explore physical Magic Gem models with interactive 3D viewers and download STL files for 3D printing.

About the Models

Magic Gem Variants:

  • v1: 8 vertices variant (classic Lo Shu)
  • v2: 9 vertices variant
  • v3-v7: 10-11 vertices variants
  • Weighted Ring: Physical accessory for spinning demos

Each variant represents a different 3ร—3 magic square from the Dโ‚„ symmetry group, showing how rotation and reflection create geometrically distinct polyhedra.

3D Printing Guide

Recommended Settings:

  • Layer height: 0.2mm
  • Infill: 20-30%
  • Supports: May be required for overhangs
  • Material: PLA or PETG recommended

The weighted ring can be printed separately and used to demonstrate the physical balance properties of magic square geometry.

๐Ÿ“ OpenSCAD Source Available

All models are generated using OpenSCAD parametric code. View the source code directly in the catalogue to understand how each gem is constructed and modify parameters to create your own variants!

Entrainment: Order Emerging from Chaos

Watch as random orbiting particles gradually synchronize into the perfect balance of a magic square configuration through entrainment forces.

Understanding Entrainment

What is Entrainment?

  • Chaos Mode: Particles orbit randomly on independent paths
  • Entrainment Force: A gentle force pulls particles toward balanced positions
  • Phase Locking: Particles synchronize like coupled oscillators
  • Perfect Balance: System settles into magic square geometry

Like fireflies synchronizing their flashes or pendulums phase-locking on a shared beam.

Covariance Metrics

Four balance measures converge to zero:

  • cโ‚ (Row): Row-value covariance
  • cโ‚‚ (Col): Column-value covariance
  • cโ‚ƒ (Rowยฒ): Squared row moment
  • cโ‚„ (Colยฒ): Squared column moment

Watch all four metrics simultaneously approach zero as order emerges!

๐Ÿ”ฌ Natural Phenomenon

Entrainment is found throughout nature: from the synchronization of firefly flashes to the phase-locking of coupled oscillators. Magic squares represent the perfectly entrained state where all covariances vanish!

Magic Squares as Electron Orbital Configurations

Explore the deep analogy between magic square geometry and quantum electron orbitals. Each cell's value determines its "shell distance," creating a natural mapping to atomic configurations.

Shell Configuration Analysis

Key Features:

  • Shell Grouping: Particles grouped by distance from grid center
  • Orbital Notation: Written in atomic notation (1sยฒ, 2pโถ, etc.)
  • Occupancy Diagrams: Shows which "orbitals" are filled
  • Quantum Constraints: Covariance rules act like Pauli exclusion

Quantum Analogies

Magic SquareQuantum Mechanics
Shell distance = valuePrincipal quantum number (n)
Grid position angleMagnetic quantum number (mโ„“)
Row/Col indexAngular momentum (โ„“)
Covariance = 0Energy eigenstate
880 magic squaresAllowed configurations

๐Ÿ”ฌ Deep Connection

Just as electrons fill orbitals following the Aufbau principle and Pauli exclusion, magic square values fill grid positions following covariance constraints. The 6 covariance conditions act like quantum selection rules, allowing only specific "configurations" โ€” the 880 magic squares!