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

Machine Learning: Matrix & Tensor MethodsConstraint Satisfaction and Optimization: Other Foundations of Constraint SatisfactionSearch and Optimization: Mixed Discrete/Continuous Search

Application Category

Graph Algorithms and Modeling for the Web: Efficient manipulation of static and dynamic Web-related graphsSecurity and Privacy: Large-scale security measurementsSystems and Infrastructure for Web, Mobile and WoT: Applied ML and AI for Web-based mobile applications
📝 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.
💼 Related Jobs
No related jobs found.