Efficient Generation of Binary Magic Squares

πŸ“… 2025-11-01
πŸ“ˆ Citations: 0
✨ Influential: 0
πŸ“„ PDF
πŸ€– AI Summary
This paper addresses the efficient construction of binary magic squares (BMS)β€”i.e., {0,1}-matrices with equal row and column sums. It formally defines and characterizes the existence conditions for non-square BMS: an *m*Γ—*n* BMS with target sum *s* exists if and only if ⌈max(*m*,*n*)/2βŒ‰ ≀ *s* ≀ ⌊min(*m*,*n*)/2βŒ‹. We propose a constructive algorithm based on mathematical induction, achieving optimal theoretical time complexity *O*(*mn*). The algorithm is implemented with dual CPU/GPU backends supporting parallel batch generation, guaranteeing correctness of all outputs. Our contributions include: (i) the first necessary and sufficient existence theorem for rectangular BMS; (ii) the first deterministic, asymptotically optimal construction algorithm; and (iii) an industrial-grade, open-source Python toolkit enabling real-time generation of million-scale BMS instances.

Technology Category

Application Category

πŸ“ Abstract
We propose a simple algorithm for generating Binary Magic Squares (BMS), i.e., square binary matrices where the sum of all rows and all columns are equal. We show by induction that our algorithm always returns valid BMS with optimal theoretical complexity. We then extend our study to non-square Binary Magic Squares, formalize conditions on the sum of rows and columns for these BMS to exist, and show that a slight variant of our first algorithm can generate provably generate them. Finally, we publicly release two implementations of our algorithm as Python packages, including one that can generate several BMS in parallel using GPU acceleration.
Problem

Research questions and friction points this paper is trying to address.

Generating binary magic squares efficiently
Extending algorithm to non-square binary matrices
Providing theoretical complexity guarantees for generation
Innovation

Methods, ideas, or system contributions that make the work stand out.

Simple algorithm generates binary magic squares
Extended method handles non-square magic squares
GPU-accelerated parallel implementation for fast generation
πŸ”Ž Similar Papers
No similar papers found.