Let $k$ be a field with $p$ elements. Consider the following computational problem



> 
> *Input*: a natural number $n$, $n^2$ linear forms $M\_{ij}$, $i,j=1,\ldots n$ in $n^2$ variables $X\_{11}, \ldots X\_{nn}$. 
> 
> 
> *Problem:* Is there an assignement of values to the variables $X\_{ij}$ so that the matrix $M\_{ij}$ is invertible?
> 
> 
> 


${}$



> 
> **Question:** What is known about algorithms for this problem?
> 
> 
> 


As usually, let's assume the addition and multiplication in the field to have computational cost $1$.


The naive algorithm of checking each assignment of the variables $X\_{ij}$ takes time bounded by a polynomial in $p^{n^2}$. I'd be interested to know if there is an improvement to polynomial in $p^n$ (or better). 


EDIT: Below Emil Jeřábek shows that the problem is NP-complete, but the reduction from 3-SAT is done in such a way that it still could be that there is an improvement to $p^n$ without proving anything unexpected about 3-SAT.


EDIT: The special case when each $M\_{ij}$ is equal either to $0$ or to $X\_{ij}$ is solved below by Emil Jeřábek.


EDIT: I've decided to ask a [more specific follow-up question](https://mathoverflow.net/questions/82892/3-sat-and-linear-forms-representing-a-non-degenerate-matrix).



determining if a matrix of linear forms represents a non-degenerate matrix
The determinant of $M$, considered as a matrix over the polynomial ring $R=k[X\_{11},\dots,X\_{nn}]$, is a polynomial $f\in R$, and your problem is to determine whether $f$ defines the constant $0$ function over $k$.


There are several division-free algorithms for computation of determinant in any commutative ring using polynomially many ring operations. In principle, you can use such an algorithm to compute $f$, but this may result in a long expression, since $f$ may have exponentially many terms. It is better to combine this with a polynomial identity testing algorithm: since $f$ has degree $n$, the Schwartz–Zippel lemma tells you that $f(a\_{11},\dots,a\_{nn})\ne0$ for randomly chosen $a\_{ij}\in k$ with probability at least $1-n/p$, as long as $f\ne0$ and $p>n$. Thus, if (say) $p>2n$, you don’t actually have to evaluate $f$, you have a simple probabilistic polynomial-time algorithm: choose random assignment to your variables, and test whether the resulting matrix is nonsingular.


In the special case where each $M\_{ij}$ is either $0$ or $X\_{ij}$, things are much simpler: it is easy to see that there is an assignment making the matrix nonsingular if and only if there is a permutation $\pi$ such that $M\_{i\pi(i)}\ne0$ for each $i$, in other words, if and only if the bipartite graph whose biadjacency matrix is defined from $M$ by replacing every $X\_{ij}$ with $1$ has a perfect matching. There are various efficient algorithm for finding perfect matchings and/or checking their existence, see e.g. <http://en.wikipedia.org/wiki/Perfect_matching#Algorithms_and_computational_complexity> .


EDIT: For a fixed $p$, the full problem is NP-complete. The reduction is simplest for $\mathbb F\_2$. Assume we are given a $3$-CNF $C(x\_1,\dots,x\_n)=\bigwedge\_{i< m}\bigvee\_{j< 3}l\_{ij}$, where each $l\_{ij}$ is either some $x\_k$ or $\neg x\_k$. We identify $\neg x\_k$ with the linear polynomial $1+x\_k$. Then $C$ is satisfiable if and only if the polynomial $f(x\_1,\dots,x\_n)=\prod\_i(1+\prod\_jl\_{ij})$ assumes a nonzero value for some assignment over $\mathbb F\_2$. Let $M$ be the block diagonal matrix consisting of $m$ blocks $M\_i$, where
$$M\_i=\begin{pmatrix}1&l\_{i0}&0\\\0&1&l\_{i1}\\\\l\_{i2}&0&1\end{pmatrix}.$$
Then $\det(M)=f$, thus there is an assignment in $\mathbb F\_2$ making $M$ invertible iff $C$ is satisfiable. One can get rid of the constants $1$ in the matrix as follows: we include in $M$ the identity matrix as yet another block, and then we replace $1$ with a new variable $x\_0$ everywhere (i.e., in the $1$ entries as well as in the entries of the form $1+x\_k$). Any assignment making the new matrix invertible must have $x\_0=1$, and then it works as before. The new matrix has only entries of the form $0$, $x\_k$, $x\_0+x\_k$.


