Let $ A$ be a complex $ n$ by $ n$ matrix and $ x\_1, \dots, x\_n$ be a set of commuting variables. Let $ X\_i = \sum\_i a\_{ij}x\_j$. MacMahon's Master Theorem (MMT) states that
\begin{align}
 [x\_1^{p\_1} \dots x\_n^{p\_n}] X\_1^{p\_1} \dots X\_n^{p\_n} = [s\_1^{p\_1} \dots s\_n^{p\_n}] \det(I- SA)^{-1}
\end{align}
where $[m]P$ means the coefficient of the monomial $m$ in the polynomial or formal power series $P$ and $ S = \text{Diag}(s\_1,\dots, s\_n)$. Is there any similar result in the literature for
\begin{align}
 [x\_1^{p\_1} \dots x\_n^{p\_n}] X\_1^{q\_1} \dots X\_n^{q\_n}
\end{align}
where $ \sum\_i p\_i = \sum\_i q\_i$ ?


There are numerous generalizations of MMT. However, I am
unable to find any result for this particular case.



MacMahon Master Theorem for non-matching coefficients
The reason I asked this question is that I found such a generalization of MMT and didn't know if it exists in the literature. The proof makes extensive use of **operator calculus**: the differential operators are manipulated as if they were numbers. The MMT and its generalization are immediate consequences of the following result.


**Lemma.**
Let $S,A$ be $ n\times n$ matrices of commuting variables, then
\begin{align}\label{eq:sa}
 \exp ( \partial\_x^T S \partial\_y ) \exp (y^T A x)|\_{x=y=0} = \det(I-S A)^{-1}
\end{align}
where both sides are interpreted as formal power series in $ (s\_{ij}), (a\_{ij})$.


**Proof.**
Let $C, M$ be symmetric $n \times n$ matrices and $ X \sim \mathcal N(0, C)$ (formally). Then
\begin{align\*}
 \exp \left( \frac{1}{2}\partial\_u^T C \partial\_u \right) \exp \left(-\frac{1}{2}u^T M u \right) \Big|\_{u=0} &= \mathbb E \exp(\partial\_u^T X) \exp \left( -\frac{1}{2}u^T M u \right) \Big|\_{u=0} \\
 &= \mathbb E \exp \left( -\frac{1}{2}X^T M X \right) \\
 &= \det(I+CM)^{-1/2},
\end{align\*}
The result of the lemma is obtained by choosing
\begin{align\*}
C = \begin{pmatrix} O & S \\ S^T & O \end{pmatrix}, \quad M=-\begin{pmatrix} O & A^T \\ A & O\end{pmatrix}, \quad u=\begin{pmatrix} x \\ y\end{pmatrix} \quad \blacksquare
\end{align\*}


Now let $ E$ be any subset of $ [n]^2$ and $ S$ be a $ n$ by $ n$ matrix supported in $ E$, i.e. $ s\_{ij}=0$ if $ (i,j) \notin E$. By the lemma
\begin{align}
 \det(I-S A)^{-1} &= \exp \left( \sum\_{(i,j)\in E} s\_{ij} \partial\_{x\_i} \partial\_{y\_j} \right) \exp(y^T A x)|\_{x=y=0}
\end{align}
which gives
\begin{align}
 \left[ \prod\_{(i,j)\in E} s\_{ij}^{k\_{ij}} \right] \det(I-SA)^{-1} &= \left( \prod\_{(i,j) \in E} \frac{\partial\_{x\_i}^{k\_{ij}} \partial\_{y\_j}^{k\_{ij}} }{k\_{ij}!} \right) \exp(y^T A x)|\_{x=y=0}\\
 &= \frac{1}{\prod\_{(i,j)\in E} k\_{ij}!} p\_1!\dots p\_n! [x\_1^{p\_1} \dots x\_n^{p\_n}] X\_1^{q\_1} \dots X\_n^{q\_n}
\end{align}
where
\begin{align}
 p\_i = \sum\_i k\_{ij}, \quad q\_j = \sum\_j k\_{ij} \tag{1}
\end{align}
Therefore
\begin{align}
 [x\_1^{p\_1} \dots x\_n^{p\_n}] X\_1^{q\_1} \dots X\_n^{q\_n} = \frac{\prod\_{(i,j)\in E} k\_{ij}!}{p\_1!\dots p\_n!} \left[\prod\_{(i,j)\in E} s\_{ij}^{k\_{ij}} \right] \det(I - SA)^{-1} \tag{2}
\end{align}
When $E$ is the diagonal we get the MMT. For general $ p\_1, \dots, p\_n, q\_1, \dots, q\_n$ such that $\sum\_i p\_i = \sum\_i q\_i$ we can find a $E \subset [n]^2$ with no more than $ 2n+1$ elements and nonnegative integers $k\_{ij}$ for $(i,j)\in E$ such that $(1)$ satisfies, and $(2)$ gives a generalization of MMT.


