How this calculation works
Complete partly fixed -1/0/+1 square matrices under alternating-sign row/column constraints and give the distribution by negative-one count. Margin-only contingency tables do not enforce alternating prefix sums and allow different integer entries.
aᵢⱼ∈{−1,0,1}; every row/column prefix sum is 0 or 1 and every final sum is 1.A worked example
The 3×3 matrix [[0,1,0],[1,−1,1],[0,1,0]] is an ASM with one negative entry. Together with six permutation matrices it gives the seven ASMs of order three.
Good to know
Order 1–5; fixed entries or blanks; ≤2 million row-prefix branches; count all completions exactly, display ≤100 matrices.
Reference: SageMath: Alternating sign matrices (opens in a new tab) ↗
Alternating signs and prefix sums
An alternating sign matrix is square and has entries −1, 0 or 1. The nonzero entries alternate along every row and column, beginning and ending with +1.
Every row and column sums to one. These sums alone are insufficient: the alternating pattern is the additional structure that separates ASMs from arbitrary signed matrices with the same margins.
Compare this with the Integer matrix contingency table count calculator from margins. Complete partly fixed -1/0/+1 square matrices under alternating-sign row/column constraints and give the distribution by negative-one count. Margin-only contingency tables do not enforce alternating prefix sums and allow different integer entries.
Partial fixed-entry input
The alternating rule is equivalent to requiring all row and column prefix sums to stay in {0,1}, with final sums one. This gives a compact exact validation test.
A prefix sum of −1 exposes a negative entry appearing too early, while a prefix sum of two exposes a second positive entry before a compensating negative. Either violates the ASM condition. For a3×3 blank matrix there are seven completions: six permutation matrices and one matrix containing a central−1. The negative-one distribution therefore separates six completions at zero negatives from one at a single negative. This small example distinguishes alternating-sign matrices from ordinary nonnegative contingency tables with row and column totals one. A negative entry is allowed only when balanced by surrounding positive entries in the alternating sequence.
Legal row-pattern generation
For partial input, fixed entries are constraints and blank cells remain choices. Generate legal row patterns first, respecting row prefixes and the row’s final total.
As rows are placed, update each column prefix. Reject any partial matrix whose column prefix leaves {0,1}, and require every column total to equal one after the final row.
Column-prefix completion search
Count all completions exactly and refine the count by the number of −1 entries. The coefficient for zero negatives counts compatible permutation matrices, since a nonnegative ASM is a permutation matrix.
A sample list illustrates completions but need not display every matrix. Its truncation must not change the total or the refinement coefficients, whose sum must equal the completion count. The implementation generates rows whose cumulative sums stay in {0,1} and end at one. As rows are appended, every column must obey the same prefix condition. At the final row every column must end at one as well. These prefix constraints imply alternating nonzero signs without explicitly deleting zeros and rescanning every completed line. Fixed entries are checked during generation; null denotes an unknown, whereas zero is a genuine fixed value that can forbid an otherwise valid completion.
Refinement by negative entries
At order three, six permutation matrices provide the six zero-negative ASMs. One additional matrix has center −1 and ones at the four side-center positions, giving exactly one negative entry.
Thus the refined count is six at degree zero and one at degree one. The total is seven, and each prefix of the displayed nonpermutation example can be checked by hand.
The seven order-three matrices
The figure colors the center negative entry separately from positive entries. Prefix strips can show how its middle row evolves through sums 1,0,1, explaining why a negative entry is allowed there.
Orders two, three and four have totals 2,7 and 42 when no entries are fixed. These independent totals help detect row-generation and column-pruning mistakes without duplicating the implementation logic. The count includes all completions under the work cap, even when the example display stops at one hundred matrices. An impossible fixed pattern has count zero after complete search, not a silently relaxed set of constraints. Orders above five are outside this enumeration. The familiar product formula for completely blank ASM counts is a useful independent check, but it cannot replace the constrained search when some entries are prescribed.
Exact totals, samples and computation caps
The finite completion search grows much faster than its small matrix dimensions suggest. A work cap must leave the total unresolved if not all branches were counted.
A fixed −1 in the top-left cell makes the first row and column prefixes negative immediately, proving zero completions. Such structural negative examples are useful alongside unrestricted enumeration totals.
A few questions, answered
May an ASM contain negative entries?
Yes. Negative entries are permitted when the nonzero row and column entries alternate correctly.
Why do prefix sums stay zero or one?
That is equivalent to the alternating-sign rule together with final row and column sums one.
Is every permutation matrix an ASM?
Yes. It has one +1 per row and column and no negative entries.
Does a displayed sample represent every completion?
No. The sample is bounded; the exact total and refinement distribution count all completions after a completed search.