As part of my work I need to define the set of all $n\times n$ matrices with entries in $\{0,1,\ldots,n\}$ (considered as a subset of $\mathbb{Z}$), such that each row and column of the matrix sums to $n$.
Is there an easy way to do this in MAGMA?
As part of my work I need to define the set of all $n\times n$ matrices with entries in $\{0,1,\ldots,n\}$ (considered as a subset of $\mathbb{Z}$), such that each row and column of the matrix sums to $n$.
Is there an easy way to do this in MAGMA?
Copyright © 2021 JogjaFile Inc.
Here is one idea towards a solution. It only works (practically) until $n=3$ on my computer, because with $n=4$ it has to sift through $5^{16}$ different matrices. Perhaps someone can refine my method, or introduce one that is not so crude, ie, one that uses a little more theory than I have used. Essentially, all I've done is defined a function NSumMatrix($m$) which returns true if $m$ has the desired property.
First, define a RowSum($A$,$i$) function as follows:
Define a function similarly for the column sum. Then, define the following aforementioned function:
Now, define a matrix algebra:
And finally, construct the desired set using the function:
For $n=3$, if you print $S$, you'll find all $55$ matrices whose rows and column sums are all $3$.