%%================================================================== \section{Further worked applications}\label{sec:more}\enlargethispage{4pt} %%================================================================== The applications of Section~\ref{sec:applications} used one Boolean variable per vertex or per clause variable, one algebra generator, and constraints of the simplest kind. This section works out eight further families in which one of these three choices is made differently: several generators record several linear statistics at once; the variables range over a finite domain and the objective is a cut into several classes; the variables sit on the edges of a bounded-degree graph and the constraints at the vertices; the algebra is $\Q$ but the factor is the Fortuin--Kasteleyn weight of an edge, which reaches the Tutte polynomial on a hyperbola; the constraints are the parity checks of a linear code; the constraints are the incidences of a hypergraph; the constraints are the gates of a circuit; and the constraints are the rows of an integer program, linear inequalities with coefficients of arbitrary size. In each case the proof consists of naming the variables, the factors and the algebra, checking the three hypotheses of Theorem~\ref{thm:weighted} or Theorem~\ref{thm:domain}, and reading the answer off the resulting element of the algebra. We use throughout that $\rhon$ is increasing on $[20,\infty)$,\footnote{With $u=\log x$ and $u'=1/(x\ln 2)$ the logarithmic derivative of $\rhon(x)=x(\log u)^2/\sqrt u$ is $1/x+2u'/(u\ln 2\,\log u)-u'/(2u)$, and the negative term is at most $1/(2x\,u\ln 2)<1/x$ for $u\ge 1$.} so that $\rhon(m)\le\rhon(Cn)\le 4C\rhon(n)$ whenever $20\le m\le Cn$ and $n\ge C$, as in the proof of Theorem~\ref{thm:domain}. \subsection{Several linear side constraints}\label{ssec:linear} Corollary~\ref{cor:hamming} and Proposition~\ref{prop:modular} recorded one linear statistic of the assignment in the exponent of the single generator $W$. With the algebra $\A_{N_1,\dots,N_s}$ of \eqref{eq:ANs} one records $s$ of them at once, and a fixed number of linear equations or congruences may be imposed on the solutions of a sparse constraint system. \begin{theorem}[Linear statistics]\label{thm:linear} Fix integers $k,c,s\ge1$. Let $(\Phi_f)_{f\in\F}$ be a factor system on $n\ge20$ Boolean variables with at most $cn$ factors of scope at most $k$, with values in $\A_{N_0}$ for some $N_0\ge1$ and coefficients that are polynomials in $W_0$ with integer coefficients of at most $L$ bits, and let $\omega^{(1)},\dots,\omega^{(s)}\in\{0,1,\dots,\Omega\}^n$ be weight vectors. \begin{enumerate}[label=\textup{(\roman*)},leftmargin=2.2em] \item\label{it:lineq} The elements \[ r(j_1,\dots,j_s)=\sum_{x\in\{0,1\}^n:\ \sum_v\omega^{(i)}_vx_v=j_i\ (1\le i\le s)} \ \prod_{f\in\F}\Phi_f(x)\ \in\A_{N_0} \] are computed, for all $(j_1,\dots,j_s)$ at once, in time $\poly\bigl(n,L,N_0,(1+n\Omega)^s\bigr)2^{O_{k,c}(\rhon(n))}$. \item\label{it:lincong} For moduli $M_1,\dots,M_s\ge1$ the same holds for the sums over the $x$ with $\sum_v\omega^{(i)}_vx_v\equiv j_i\pmod{M_i}$ for all $i$, in time $\poly(n,L,N_0,M_1\cdots M_s,\log\Omega)2^{O_{k,c}(\rhon(n))}$; equations and congruences may be mixed. \end{enumerate} \end{theorem} \begin{proof} \ref{it:lineq} Put $N_i=1+\sum_v\omega^{(i)}_v\le 1+n\Omega$ for $1\le i\le s$ and $\A=\A_{N_0,N_1,\dots,N_s}$, of dimension $N=N_0N_1\cdots N_s$. Keep the given factors, now read in $\A$, and add for each variable $v$ the factor \[ \Psi_v=1+\Bigl(\prod_{i=1}^{s}W_i^{\omega^{(i)}_v}-1\Bigr)Y_v , \] the multilinear extension of $\prod_iW_i^{\omega^{(i)}_vx_v}$ on the scope $\{v\}$, of degree one in $Y_v$ and with coefficients that are polynomials in the generators with integer coefficients of absolute value at most $1$.\footnote{The product $\prod_i\bigl(1+(W_i^{\omega^{(i)}_v}-1)Y_v\bigr)$ takes the same values at $Y_v\in\{0,1\}$, but it has degree $s$ in $Y_v$ and differs from $\Psi_v$ at the non-Boolean inputs $\ip{\PP_{f,v}(t)}{x}$ of the routine; at $W_1=2$, $W_2=3$, $Y_v=\frac12$ and unit weights it equals $3$, while $\Psi_v=\frac72$.} The new system has at most $(c+1)n$ factors of scope at most $k$, and its sum is \[ \sum_x\prod_f\Phi_f(x)\prod_{i=1}^{s}W_i^{\sum_v\omega^{(i)}_vx_v} =\sum_{(j_1,\dots,j_s)}r(j_1,\dots,j_s)\,W_1^{j_1}\cdots W_s^{j_s}, \] with nothing lost to the truncation because every exponent of $W_i$ is less than $N_i$. Theorem~\ref{thm:weighted} computes the sum with $\poly(n)2^{O_{k,c}(\rhon(n))}$ operations in $\A$, and Lemma~\ref{lem:bits}, with $|\F|\le(c+1)n$ and the bound $\max(L,1)$ on the coefficient bits, turns this into $\poly(n,L,N)2^{O_{k,c}(\rhon(n))}$ bit operations. \ref{it:lincong} Replace $W_i^{N_i}=0$ by $W_i^{M_i}=1$, that is take $\A=\A_{N_0}\otimes\Q[W_1,\dots,W_s]/(W_1^{M_1}-1,\dots,W_s^{M_s}-1)$, with the exponents $\omega^{(i)}_v$ reduced modulo $M_i$ at a cost of $O(\log\Omega)$ bits each; the sum is then $\sum_jr(j)W^{j}$ with $j$ running over the residues. The proof of Lemma~\ref{lem:bits} used of the algebra only that the product of two basis monomials is a basis monomial or zero, which holds here, so the bit bound follows with $N=N_0M_1\cdots M_s$. A mixture of equations and congruences uses $W_i^{N_i}=0$ for the former and $W_i^{M_i}=1$ for the latter. \end{proof} \begin{corollary}\label{cor:linear} Fix $k,c,s\ge1$ and $\Delta\ge1$. Each of the following is computed deterministically in time $\poly(n,\Omega^s)2^{O(\rhon(n))}$, the implied constant depending on $k,c,s$ or $\Delta,s$. \begin{enumerate}[label=\textup{(\alph*)},leftmargin=2.2em] \item For a $k$-CNF formula with $n$ variables and at most $cn$ clauses and weight vectors $\omega^{(1)},\dots,\omega^{(s)}\in[0,\Omega]^n$: the number of satisfying assignments $x$ with $\sum_v\omega^{(i)}_vx_v=j_i$ for all $i$, for every tuple $(j_1,\dots,j_s)$; in particular whether a satisfying assignment of prescribed weights exists. \item For a constraint system as in Theorem~\ref{thm:profile}: the number of assignments that satisfy constraints of total weight exactly $j$ and have Hamming weight exactly $i$, for all $(i,j)$. \item For a graph of maximum degree $\Delta$ with vertex weights $\omega^{(1)},\omega^{(2)}\in[0,\Omega]^V$ and a budget $B$: the maximum of $\omega^{(1)}(S)$ over the independent sets $S$ with $\omega^{(2)}(S)\le B$, and the number of independent sets attaining it. \end{enumerate} \end{corollary} \begin{proof} (a) is Theorem~\ref{thm:linear}\ref{it:lineq} with the clause indicators as factors and $N_0=1$. (b) is the theorem with the factors of the proof of Theorem~\ref{thm:profile}, which take values in $\A_{N_0}$ with $N_0=1+\sum_f\omega_f$ and have coefficients of at most $k$ bits, and the single weight vector $\omega^{(1)}=(1,\dots,1)$. (c) is the theorem with the edge factors $1-Y_uY_v$ of the proof of Theorem~\ref{thm:indep}, at most $\Delta n/2$ factors of scope $2$, $N_0=1$, and the two weight vectors: the maximum is the largest $j_1$ with $\sum_{j_2\le B}r(j_1,j_2)>0$ and the count is that sum. \end{proof} \subsection{Finite domains: cuts into several classes}\label{ssec:qcut} Theorem~\ref{thm:profile} dealt with Boolean variables. Over a finite domain the same profile is obtained from Theorem~\ref{thm:domain}, and the extra generators of Theorem~\ref{thm:linear} record the sizes of the classes of a partition. \begin{theorem}[Profiles over a finite domain]\label{thm:domainprofile} Fix $D\ge2$ and $k,c\ge1$. Given $n\ge20$ variables with values in $[D]$ and $m\le cn$ constraints $C_f:[D]^{I_f}\to\{0,1\}$ with $|I_f|\le k$, given by their tables, with integer weights $\omega_f\in[0,\Omega]$, the numbers \[ p_j=\#\Bigl\{\sigma\in[D]^n:\ \sum_f\omega_fC_f(\sigma|_{I_f})=j\Bigr\},\qquad 0\le j\le\textstyle\sum_f\omega_f, \] are computed deterministically in time $\poly(n,\Omega)2^{O_{D,k,c}(\rhon(n))}$. \end{theorem} \begin{proof} Apply Theorem~\ref{thm:domain} with $\A=\A_N$, $N=1+\sum_f\omega_f\le 1+cn\Omega$, and the tables $\phi_f(\sigma)=W^{\omega_fC_f(\sigma)}$, whose entries are monomials with coefficient $1$, so $L=1$. The sum is $\sum_\sigma W^{\sum_f\omega_fC_f(\sigma|_{I_f})}=\sum_jp_jW^{j}$, with no term truncated. \end{proof} \begin{corollary}[Max-$k$-Lin, Max-$q$-Cut and balanced partitions]\label{cor:qcut} Fix $p,q,k,c\ge2$. The following are computed deterministically in time $\poly(n,\Omega)2^{O(\rhon(n))}$, the implied constant depending on the fixed parameters. \begin{enumerate}[label=\textup{(\roman*)},leftmargin=2.2em] \item\label{it:klin} For a system of $m\le cn$ linear equations over $\Z/p\Z$ in $n$ unknowns, each equation involving at most $k$ unknowns, with weights $\omega_f\in[0,\Omega]$: the number of assignments satisfying equations of total weight exactly $j$, for every $j$; hence the maximum satisfiable weight and the number of optimal assignments. \item\label{it:qcut} For a graph $G$ with $n$ vertices and $m\le cn$ edges with weights $\omega_e\in[0,\Omega]$: the number of maps $\sigma:V\to[q]$ for which the edges $uv$ with $\sigma_u\ne\sigma_v$ have total weight exactly $j$, for every $j$; hence the maximum $q$-cut, and the minimum, which is the least weight of edges left monochromatic by a $q$-colouring, with the number of optimal maps. \item\label{it:balanced} In the situation of \ref{it:qcut}, the number of maps $\sigma$ with $|\sigma^{-1}(a)|=i_a$ for $a0\}$. For a received word $y\in\Ftwo^n$ the distance distribution of $y$ is $A_i(y)=\#\{x\in\mathcal C:\operatorname{wt}(x+y)=i\}$, the weight enumerator of the coset $y+\mathcal C$; a codeword at distance $\min\{i:A_i(y)>0\}$ from $y$ is a maximum-likelihood decoding of $y$ on the binary symmetric channel. The codes whose parity-check matrix has rows of bounded weight are the low-density parity-check codes of Gallager \cite{Gal62}. \begin{theorem}[Sparse parity checks]\label{thm:codes} Fix $k,c\ge1$. Let $\mathcal C\subseteq\Ftwo^n$ be given by a parity-check matrix with $m\le cn$ rows, each of weight at most $k$. \begin{enumerate}[label=\textup{(\roman*)},leftmargin=2.2em] \item\label{it:wenum} The weight enumerator $(A_i)_{0\le i\le n}$, and hence $d(\mathcal C)$ and the number of minimum-weight codewords, are computed deterministically in time $\poly(n)2^{O_{k,c}(\rhon(n))}$. \item\label{it:coset} For every $y\in\Ftwo^n$ the distance distribution $(A_i(y))_i$ is computed in the same time, and a codeword nearest to $y$ is found in $2n+1$ times that time. \item\label{it:qary} For a code over a finite field $\mathbb F_Q$, or over any alphabet of fixed size $Q$ with the checks given as tables on $[Q]^{k}$, given by $m\le cn$ checks each involving at most $k$ coordinates, the Hamming weight enumerator and the distance distribution of every received word are computed in time $\poly(n)2^{O_{Q,k,c}(\rhon(n))}$; so is the complete weight enumerator, the number of codewords with $i_s$ coordinates equal to $s$ for each symbol $s$, in time $\poly(n^{Q})2^{O_{Q,k,c}(\rhon(n))}$. \end{enumerate} \end{theorem} \begin{proof} \ref{it:wenum} Boolean variables $x_1,\dots,x_n$ and $\A=\A_{n+1}$. For each row $h$ of $H$ take the multilinear extension of the indicator, on the scope $\operatorname{supp}(h)$ of size at most $k$, that $\sum_{v\in\operatorname{supp}(h)}x_v$ is even; its coefficients are integers of absolute value at most $2^{k}$. For each coordinate take $1+(W-1)Y_v$. There are at most $(c+1)n$ factors of scope at most $k$, and the sum is $\sum_{x\in\mathcal C}W^{\operatorname{wt}(x)}=\sum_iA_iW^{i}$, with no truncation. Theorem~\ref{thm:weighted} and Lemma~\ref{lem:bits} with $N=n+1$, $L=k$ give the time; $d(\mathcal C)$ and $A_{d}$ are read off. \ref{it:coset} Replace the coordinate factor by the multilinear extension of $W^{[x_v\ne y_v]}$, which is $1+(W-1)Y_v$ if $y_v=0$ and $W+(1-W)Y_v$ if $y_v=1$; the sum is $\sum_{x\in\mathcal C}W^{\operatorname{wt}(x+y)}=\sum_iA_i(y)W^{i}$. For the nearest codeword let $i_0=\min\{i:A_i(y)>0\}$ and fix the coordinates one at a time: fixing $x_1=\epsilon$ replaces every row containing coordinate $1$ by the indicator that the remaining coordinates have parity $\epsilon h_1$, a factor of smaller scope, and leaves the system sparse; compute the two distance distributions, keep a value $\epsilon$ for which the coefficient of $W^{i_0}$ is positive, and continue with the next coordinate. After $n$ steps the assignment is a codeword at distance $i_0$ from $y$, and $2n+1$ distributions have been computed. \ref{it:qary} Apply Theorem~\ref{thm:domain} with $D=Q$: the variables take values in the alphabet, each check is a table on at most $k$ coordinates, and the coordinate factor has the table $s\mapsto W^{[s\ne0]}$, or $s\mapsto W^{[s\ne y_v]}$ for the distance to $y$, in $\A_{n+1}$; for the complete weight enumerator the table is $s\mapsto W_s$ in $\A_{n+1,\dots,n+1}$ with one generator per symbol, of dimension $(n+1)^{Q}$. \end{proof} \begin{remark} Computing the minimum distance of a binary linear code is NP-hard \cite{Var97}, and so is maximum-likelihood decoding \cite{BMT78}; both are posed with the code given by a generator or a parity-check matrix of unrestricted density. For the low-density codes of Gallager, with $m\le n$ rows of bounded weight, Theorem~\ref{thm:codes} gives the exact minimum distance, the complete weight enumerator and exact maximum-likelihood decoding of every received word in deterministic time $2^{o(n)}$, where the previously known exact methods are exponential in the dimension or the redundancy of the code. No bound on the column weights is needed, by Lemma~\ref{lem:frequent}. \end{remark} \subsection{Bounded-degree hypergraphs}\label{ssec:hypergraphs} A hypergraph $\mathcal H=(V,\mathcal E)$ has vertex set $V$, $|V|=n$, and a multiset $\mathcal E$ of edges $e\subseteq V$. A matching is a set of pairwise disjoint edges, a perfect matching or exact cover is a matching whose union is $V$, a transversal is a set of vertices meeting every edge, an independent set is a set of vertices containing no edge, and a strong independent set is a set of vertices no two of which lie in a common edge. A $q$-colouring of $V$ is proper if no edge of size at least two is monochromatic. \begin{theorem}[Hypergraphs]\label{thm:hypergraphs} Fix $k,\Delta,c\ge1$ and $q\ge2$, and let $\mathcal H$ have $n$ vertices and edges of size at most $k$. \begin{enumerate}[label=\textup{(\roman*)},leftmargin=2.2em] \item\label{it:hmatch} If every vertex lies in at most $\Delta$ edges and the edges have integer weights in $[0,\Omega]$: the number of matchings of each weight and the number of exact covers of each weight, hence the maximum weight of a packing and the number of exact covers, in time $\poly(n,\Omega)2^{O_{k,\Delta}(\rhon(n))}$. \item\label{it:hindep} If $|\mathcal E|\le cn$ and the vertices have integer weights in $[0,\Omega]$: the number of transversals, of independent sets and of strong independent sets of each weight, in time $\poly(n,\Omega)2^{O_{k,c}(\rhon(n))}$. \item\label{it:hcol} If $|\mathcal E|\le cn$: the number of proper $q$-colourings, and the number of $q$-colourings with exactly $j$ monochromatic edges for every $j$, in time $\poly(n)2^{O_{q,k,c}(\rhon(n))}$. \end{enumerate} \end{theorem} \begin{proof} \ref{it:hmatch} A vertex in no edge lies in no exact cover and in every matching trivially; delete such vertices, so that $n\le k|\mathcal E|$, and if $|\mathcal E|<20$ list the subsets. Boolean variables $y_e$, $e\in\mathcal E$; for each vertex $v$ the multilinear extension on the scope $\{e:v\in e\}$, of size at most $\Delta$, of the indicator that at most one (for matchings) or exactly one (for exact covers) incident edge is chosen; for each edge $1+(W^{\omega_e}-1)Y_e$. There are $n+|\mathcal E|\le(k+1)|\mathcal E|$ factors of scope at most $\Delta$, the sum is $\sum_M W^{\omega(M)}$ over the matchings, or over the exact covers, in $\A_N$ with $N=1+\sum_e\omega_e$, and Theorem~\ref{thm:weighted} on $|\mathcal E|\le\Delta n$ variables with the constants $\Delta$ and $k+1$, with Lemma~\ref{lem:bits}, $L=\Delta$, gives the bound; $\rhon(|\mathcal E|)=O_\Delta(\rhon(n))$. \ref{it:hindep} Boolean variables $x_v$; for each edge $e$ the multilinear extension, on the scope $e$, of the indicator that some $x_v$, $v\in e$, is $1$ (transversals), that not all are $1$ (independent sets), or that at most one is $1$ (strong independent sets); for each vertex $1+(W^{\omega_v}-1)Y_v$. At most $(c+1)n$ factors of scope at most $k$; Theorem~\ref{thm:weighted} and Lemma~\ref{lem:bits} with $L=k$. \ref{it:hcol} Theorem~\ref{thm:domainprofile} with $D=q$ and, for each edge of size at least two, the constraint that it is monochromatic, of weight $1$: the coefficient $p_j$ counts the colourings with $j$ monochromatic edges and $p_0$ the proper ones. \end{proof} \subsection{Circuits of linear size}\label{ssec:circuits} A Boolean circuit with $n$ inputs is a sequence of gates $g_1,\dots,g_s$, each computing a function of at most $k$ earlier gates or inputs given by its truth table, with $t$ of the gates designated as outputs. Its size is $s$. \begin{theorem}[Linear-size circuits of bounded fan-in]\label{thm:circuits} Fix $k,c\ge1$. Let $C$ be a circuit with $n\ge20$ inputs, $s\le cn$ gates of fan-in at most $k$, and outputs $o_1,\dots,o_t$ with integer weights $\omega_1,\dots,\omega_t\in[0,\Omega]$. The numbers \[ N_{i,j}=\#\Bigl\{x\in\{0,1\}^n:\ \operatorname{wt}(x)=i,\ \sum_{l=1}^{t}\omega_l\,o_l(x)=j\Bigr\} \] are computed deterministically, for all $(i,j)$, in time $\poly(n,\Omega)2^{O_{k,c}(\rhon(n))}$. In particular the number of inputs accepted by a single-output circuit, and the maximum over the inputs of a weighted sum of its output bits with the number of inputs attaining it, are computed in that time. \end{theorem} \begin{proof} Take the $n+s$ Boolean variables $x_1,\dots,x_n,g_1,\dots,g_s$ and $\A=\A_{n+1,\,1+\sum_l\omega_l}$ with generators $U$ and $W$. For each gate $g$ take the multilinear extension, on the scope consisting of $g$ and its at most $k$ arguments, of the indicator that $g$ equals the value of its function at the arguments; for each input $1+(U-1)Y_{x_v}$; for each output $o_l$ the factor $1+(W^{\omega_l}-1)Y_{o_l}$. There are $s+n+t\le(2c+1)n\le(2c+1)(n+s)$ factors of scope at most $k+1$, with coefficients of absolute value at most $2^{k+1}$. For each input $x$ exactly one assignment of the gate variables makes every gate factor $1$, the one in which each $g$ carries its value at $x$, and every other assignment makes some gate factor $0$; so the sum over the cube is $\sum_xU^{\operatorname{wt}(x)}W^{\sum_l\omega_lo_l(x)}=\sum_{i,j}N_{i,j}U^{i}W^{j}$, with nothing truncated. Theorem~\ref{thm:weighted} on $n+s\le(c+1)n$ variables with the constants $k+1$ and $2c+1$, and Lemma~\ref{lem:bits} with $L=k+1$, give the time, since $\rhon(n+s)\le\rhon((c+1)n)=O_c(\rhon(n))$. \end{proof} \begin{remark} The count of the accepted inputs of a circuit with $s$ gates is, through the Tseitin encoding used in the proof, the count of the satisfying assignments of a $(k+1)$-CNF formula with $n+s$ variables, so for every $s$ it is contained in \oai{}'s Theorem~1.1 with the exponent $o(n+s)$; their Corollary~1.4 draws a circuit lower bound from exactly this fact. Theorem~\ref{thm:circuits} adds the Hamming weight of the input and the weighted output profile for the sparse case, which turns any objective computable by a linear-size circuit of bounded fan-in on $n$ Boolean variables into one that is maximised exactly in time $2^{o(n)}$, together with the number of maximisers. Theorems \ref{thm:profile}, \ref{thm:edges} and \ref{thm:codes} are instances, since their constraints are computed by such circuits; the direct encodings given there avoid the gate variables and have smaller constants. \end{remark} \subsection{Integer programs with sparse rows}\label{ssec:ip} A $0$-$1$ integer program asks for a vector $x\in\{0,1\}^n$ satisfying a system of linear inequalities and maximising a linear objective. Its rows need not be clauses, cuts or parity checks: a row is an arbitrary linear form with integer coefficients, compared with an integer by $\le$, $=$ or $\ge$. When every row involves at most $k$ variables and there are $O(n)$ of them, each row is a local constraint, and Theorem~\ref{thm:linear} adds a fixed number of dense rows and the objective as linear statistics. \begin{theorem}[Sparse integer programs]\label{thm:ip} Fix integers $k,c\ge1$ and $s\ge0$. Consider $n\ge20$ variables, $m\le cn$ sparse rows \[ \sum_{v\in I_f}a_{f,v}x_v\ \bowtie_f\ b_f,\qquad |I_f|\le k,\quad {\bowtie_f}\in\{\le,=,\ge\},\quad a_{f,v},b_f\in\Z, \] with coefficients of arbitrary size, a cost vector $\gamma$ and dense rows $\alpha^{(1)},\dots,\alpha^{(s)}$ in $\{-\Omega,\dots,\Omega\}^n$, $\Omega\ge1$, and let $P\subseteq\{0,1\}^n$ be the set of vectors satisfying the sparse rows. \begin{enumerate}[label=\textup{(\roman*)},leftmargin=2.2em] \item\label{it:ip01} The numbers \[ p(j_0,\dots,j_s)=\#\bigl\{x\in P:\ \gamma\cdot x=j_0,\ \alpha^{(i)}\cdot x=j_i\ (1\le i\le s)\bigr\} \] are computed for all tuples in time $\poly\bigl(\ell,(1+2n\Omega)^{s+2}\bigr)\,2^{O_{k,c,s}(\rhon(n))}$, where $\ell$ is the bit length of the input. Hence the largest and the smallest value of $\gamma\cdot x$ over the $x\in P$ with $\alpha^{(i)}\cdot x\bowtie_i\beta_i$ for prescribed relations $\bowtie_i$ and integers $\beta_i$, and the number of vectors attaining each, are computed within the same time. \item\label{it:ipD} For a fixed $D\ge1$ the same holds for vectors $x\in\{0,1,\dots,D\}^n$, with time $\poly\bigl(\ell,(1+4Dn\Omega)^{s+2}\bigr)\,2^{O_{D,k,c,s}(\rhon(n))}$. \end{enumerate} \end{theorem} \begin{proof} \ref{it:ip01} For each sparse row let $\phi_f:\{0,1\}^{I_f}\to\{0,1\}$ be the indicator that the row holds, and let $\Phi_f$ be its multilinear extension \eqref{eq:multilinear}. The table of $\phi_f$ has at most $2^k$ entries, each found by one evaluation of the row, at a cost of $\poly(\ell)$ bit operations; the coefficients of $\Phi_f$ are integers of absolute value at most $2^k$. So $(\Phi_f)$ is a factor system with at most $cn$ factors of scope at most $k$ and values in $\Q$, and its product at $x\in\{0,1\}^n$ is the indicator of $P$. To bring the statistics to nonnegative weights, put $\omega^{(0)}_v=\gamma_v+\Omega$, $\omega^{(i)}_v=\alpha^{(i)}_v+\Omega$ for $1\le i\le s$, and $\omega^{(s+1)}_v=1$, all in $[0,2\Omega]$. For every $x$, \[ \gamma\cdot x=\omega^{(0)}\cdot x-\Omega\,|x|,\qquad \alpha^{(i)}\cdot x=\omega^{(i)}\cdot x-\Omega\,|x|,\qquad |x|=\omega^{(s+1)}\cdot x . \] Theorem~\ref{thm:linear}\ref{it:lineq} with $N_0=1$, the $s+2$ weight vectors $\omega^{(0)},\dots,\omega^{(s+1)}$ and the weight bound $2\Omega$ computes the numbers $r(j'_0,\dots,j'_{s+1})$ of $x\in P$ with $\omega^{(i)}\cdot x=j'_i$ for all $i$, in time $\poly(n,(1+2n\Omega)^{s+2})2^{O_{k,c,s}(\rhon(n))}$, to which the cost $cn2^k\poly(\ell)$ of the tables is added. Then \[ p(j_0,\dots,j_s)=\sum_{t=0}^{n}r\bigl(j_0+\Omega t,\ j_1+\Omega t,\dots,\ j_s+\Omega t,\ t\bigr), \] because a vector with $|x|=t$ has $\omega^{(i)}\cdot x=\alpha^{(i)}\cdot x+\Omega t$. The optimum over the $x\in P$ with $\alpha^{(i)}\cdot x\bowtie_i\beta_i$ is the largest, or smallest, $j_0$ for which $\sum p(j_0,j_1,\dots,j_s)>0$, the sum taken over the tuples with $j_i\bowtie_i\beta_i$, and that sum counts the optimal vectors. \ref{it:ipD} Let $T=\lceil\log_2(D+1)\rceil$ and replace each $x_v$ by $T$ Boolean variables $x_{v,0},\dots,x_{v,T-1}$ with $x_v=\sum_t2^tx_{v,t}$. A sparse row becomes a sparse row in the new variables, with the coefficients $2^ta_{f,v}$ and at most $kT$ variables; add for each $v$ the row $\sum_t2^tx_{v,t}\le D$, which involves $T$ variables. The cost and the dense rows become vectors with entries $2^t\gamma_v$ and $2^t\alpha^{(i)}_v$, of absolute value at most $2^T\Omega\le2(D+1)\Omega\le4D\Omega$. The new program has $n'=Tn$ variables and at most $(c+1)n\le(c+1)n'$ sparse rows of at most $kT$ variables, and its feasible vectors correspond bijectively to the vectors of $\{0,\dots,D\}^n$ satisfying the original sparse rows, with the same values of $\gamma\cdot x$ and $\alpha^{(i)}\cdot x$. Part \ref{it:ip01} applies, with $\rhon(Tn)\le4T\rhon(n)$ for $n\ge T$. \end{proof} The theorem places no bound on the coefficients of the sparse rows, only on their number of variables; the polynomial bound $\Omega$ is needed only for the objective and the dense rows, which enter through the exponents of the generators. Three classical problems that are NP-hard in the strong sense fall under it. \begin{corollary}\label{cor:ip} Fix $k,c,s\ge1$. Each of the following is computed deterministically in time $\poly(\ell,\Omega^{s+2})\,2^{O(\rhon(n))}$, where $\ell$ is the length of the input, together with the number of optimal solutions, the implied constant depending on $k,c,s$. \begin{enumerate}[label=\textup{(\alph*)},leftmargin=2.2em] \item\label{it:exactcover} For $n$ sets over a universe of at most $cn$ elements, each element lying in at most $k$ of the sets, with costs in $[0,\Omega]$: the least cost of an exact cover, of a set cover and the largest cost of a set packing. Exact cover by $3$-sets is NP-complete already when every element lies in exactly three sets \cite{Gon85}. \item\label{it:poknap} For $n$ items with values and $s$ weight vectors in $[0,\Omega]$, capacities $B_1,\dots,B_s$ and a partial order given by at most $cn$ relations $u\prec v$: the largest value of a set of items within the capacities that contains, with each item, every item below it. For $s=1$ this is the partially ordered knapsack problem, which is NP-complete in the strong sense \cite{JN83}. \item\label{it:exactsat} For a system of at most $cn$ linear equations $\sum_{v\in I_f}a_{f,v}x_v=b_f$ with integer coefficients, $|I_f|\le k$, and a cost vector in $[-\Omega,\Omega]^n$: the number of its $0$-$1$ solutions of each cost, and the least and largest cost; in particular the number of solutions of a $1$-in-$k$-SAT instance with at most $cn$ clauses, and its solutions with the fewest true variables. \end{enumerate} \end{corollary} \begin{proof} \ref{it:exactcover} Take a variable for each set and, for each element, the row $\sum_{S\ni e}x_S=1$, $\ge1$ or $\le1$; each row involves at most $k$ variables, and there are at most $cn$ rows. The cost is $\gamma$, with $s=0$. \ref{it:poknap} Take a variable for each item, the row $x_v-x_u\le0$, which says that $x_v=1$ forces $x_u=1$, for each relation $u\prec v$, and the weight vectors as dense rows with $\beta_i=B_i$ and $\bowtie_i$ the relation $\le$; the downward closure of the chosen set under the given relations is equivalent to its closure under the order they generate. \ref{it:exactsat} The equations are the sparse rows; for $1$-in-$k$-SAT a clause on the literals $\ell_1,\dots,\ell_k$ is the equation $\sum_i\ell_i=1$, where a negated literal $1-x_v$ moves the constant $1$ to the right side. All three are Theorem~\ref{thm:ip}\ref{it:ip01}. \end{proof} \subsection{Growing density}\label{ssec:density} Every statement so far fixes the ratio $c$ of factors to variables. The parameters of Lemma~\ref{lem:params} do not depend on the degree ratio $\kappa$, and the exponent of Theorem~\ref{thm:bounded-occ} is linear in it. When $\kappa$ grows with $n$ it pays to let the parameters follow it: fewer groups, and so a smaller $Q/R$ in the Taylor count, in exchange for a larger share of the cost spent on one group. With the entropy bound of Lemma~\ref{lem:entropy} in place of \eqref{eq:logCq}, this extends the subexponential regime to every ratio $\kappa=o(\sqrt{\log n/\log\log n})$. Throughout, $\lambda=\lceil\log n\rceil$, $\nu=\lceil\log\lambda\rceil$, and \[ g(x)=x\,\bigl(\log(1/x)\bigr)^{3/2}\qquad(00$ with the following property. Let $n\ge n_1$, let $k\ge1$ be an integer and $c\ge1$ a real number with \[ \theta_n:=ck\sqrt{\frac{\log\log n}{\log n}}\le\theta_1, \] and let a factor system on $n$ variables have at most $cn$ factors, each of scope at most $k$, with values in a commutative $\Q$-algebra $\A$. Then $Z$ in \eqref{eq:Z} is computed deterministically with at most \[ \poly(n)\,2^{\,4800\,n\,g(\theta_n)}\ \le\ \poly(n)\,2^{\,1700\,ck\,\rhon(n)} \] operations in $\A$, evaluations of the factors at inputs in $\Q[z]/(z^{J})$, $J\le n$, and bit operations on rationals, in polynomial space; the polynomial is absolute. In particular the bound is $2^{o(n)}$ whenever $ck=o\bigl(\sqrt{\log n/\log\log n}\bigr)$. If the coefficients of the factors are polynomials in the generators of $\A=\A_N$ or $\A_{N_1,\dots,N_s}$ with integer coefficients of at most $L$ bits, the bound holds for bit operations after multiplication by a polynomial in $n$, $N$ and $L$. \end{theorem} \begin{proof} Put $\theta_1=2^{-18}$ and $\varepsilon_n=\sqrt{\log\log n/\log n}$, so that $\theta_n=ck\,\varepsilon_n\ge\varepsilon_n$. Let $n_1$ be so large that for $n\ge n_1$ one has $\lambda-1\ge\lambda_0$, the absolute constant of Theorem~\ref{thm:explicit}, and $\theta_1\sqrt{\log n/\log\log n}\le\lambda/2$, so that $ck\le\lambda/2$. Apply Lemma~\ref{lem:frequent}: fewer than $2^{n/\lambda}$ assignments $y$, each leaving a system on $n'\ge n-n/\lambda\ge n/2$ variables with $\lambda'=\lceil\log n'\rceil\in\{\lambda-1,\lambda\}$, $\nu'\le\nu$, scopes at most $k\le\lambda'^2$, occurrence numbers at most $ck\lambda\le\lambda^2/2\le\lambda'^2-1$, and total degree at most $kcn\le2ck\,n'$. Theorem~\ref{thm:explicit} applies with $a=2ck$ and \[ \theta'=2ck\sqrt{\nu'/\lambda'}\le2ck\sqrt{2\nu/\lambda}\le6\,ck\,\varepsilon_n=6\theta_n\le2^{-15}, \] where $\nu\le\log\log n+2\le3\log\log n$ and $\lambda\ge\log n$ were used for $n\ge20$. As $g$ is increasing on $(0,2^{-3}]$, $g(\theta')\le g(6\theta_n)\le6\theta_n\log^{3/2}(1/\theta_n)=6\,g(\theta_n)$. Each $Z_y$ costs at most $cn\,\poly(n)\,2^{4740\,n\,g(\theta_n)}$ operations, and $cn\le n^2$. The branching adds the factor $2^{n/\lambda}\le2^{n\varepsilon_n}\le2^{n\,g(\theta_n)}$, since $1/\lambda\le1/\log n\le\varepsilon_n\le\theta_n$ and $\log(1/\theta_n)\ge18$. The total is at most $\poly(n)2^{4741\,n\,g(\theta_n)}$, which gives the first bound. For the second, $\log(1/\theta_n)\le\log(1/\varepsilon_n)\le\frac12\log\log n$, so $g(\theta_n)\le ck\,\varepsilon_n(\log\log n)^{3/2}/2^{3/2}=ck\,\rhon(n)/(2^{3/2}n)$, and $4800/2^{3/2}<1700$. If $ck=o(\sqrt{\log n/\log\log n})$ then $\theta_n\to0$ and $g(\theta_n)\to0$. The space bound and $J\le n'\le n$ come from Theorem~\ref{thm:explicit}, and the bit complexity is Lemma~\ref{lem:bits}: its proof uses of the parameters only $Q,\lambda=O(\log n)$, $R0$ and parameters with $s\log(n\Omega)\le\varepsilon n$. A graph $G$ covered by the theorem is determined by $w_1,\dots,w_s$, $C$, the edge set of $H$ and the restriction of the adjacency of $G$ to $E(H)$, since $\eta$ is then the difference of that restriction and $\omega$. There are at most \[ (\Omega+1)^{ns}(2\Omega+1)^{s^2}\,n^{2d(n)n}\,2^{d(n)n} \] such choices. Because $s\le n$, both $ns\log(\Omega+1)$ and $s^2\log(2\Omega+1)$ are at most $2n\,s\log(n\Omega)\le2\varepsilon n^2$, and $d(n)n(2\log n+1)=o(n^2)$, so the count is at most $2^{5\varepsilon n^2}$ for $n$ large, while there are $2^{n(n-1)/2}$ graphs on $V$. As $\varepsilon$ is arbitrary, the proportion of graphs on $V$ covered by the theorem with parameters for which its bound is $2^{o(n)}$ tends to $0$, and the random graph $G(n,\frac12)$ is covered with probability tending to $0$. The exact maximum cut of every graph in time $2^{o(n)}$ is therefore not a consequence of the theorem, and it is not proved in this paper. \end{remark} The bookkeeping of Corollary~\ref{cor:complement} applies as well to the profiles of Theorem~\ref{thm:profile} and to the programs of Theorem~\ref{thm:ip}. \begin{corollary}[Max-$k$-SAT and integer programs at growing density]\label{cor:densitysat} Let $d=d(n)\ge1$ satisfy $\delta_n\to0$, and fix $k\ge1$ and $s\ge0$. \begin{enumerate}[label=(\roman*),leftmargin=2.2em] \item\label{it:densesat} For a $k$-CNF formula with $n$ variables and at most $d(n)\,n$ clauses with integer weights in $[0,\Omega]$, the profile \eqref{eq:csprofile}, and with it the maximum satisfiable weight and the number of assignments attaining it, is computed in time $\poly(n,\Omega)\,2^{O_k(n\,g(\delta_n))}=\poly(\Omega)\,2^{o(n)}$. \item\label{it:denseip} For a program as in Theorem~\ref{thm:ip} with at most $d(n)\,n$ sparse rows, each involving at most $k$ variables, the numbers $p(j_0,\dots,j_s)$ of Theorem~\ref{thm:ip}\ref{it:ip01} are computed in time $\poly\bigl(\ell,(1+2n\Omega)^{s+2}\bigr)\,2^{O_{k}(n\,g(\delta_n))}$. \end{enumerate} \end{corollary} \begin{proof} \ref{it:densesat} The factor system of the proof of Theorem~\ref{thm:profile} has at most $d(n)n$ factors of scope at most $k$, with values in $\A_N$, $N=1+\sum_f\omega_f\le1+d(n)n\Omega$, and coefficients of at most $k$ bits. Theorem~\ref{thm:density} with $c=d(n)$ applies once $k\delta_n\le\theta_1$ and gives $\poly(n)2^{4800\,n\,g(k\delta_n)}$ operations, with $g(k\delta_n)\le k\,g(\delta_n)$; Lemma~\ref{lem:bits} gives the time bound. \ref{it:denseip} The factor system of the proof of Theorem~\ref{thm:ip}, through that of Theorem~\ref{thm:linear}, consists of the at most $d(n)n$ indicator factors of the sparse rows and the $n$ factors $\Psi_v$ of scope $1$, at most $2d(n)n$ factors of scope at most $k$, with values in an algebra of dimension at most $(1+2n\Omega)^{s+2}$ and coefficients of at most $k+1$ bits. Theorem~\ref{thm:density} with $c=2d(n)$ and Lemma~\ref{lem:bits} compute its sum, and the numbers $p(j_0,\dots,j_s)$ are read off as in the proof of Theorem~\ref{thm:ip}. \end{proof} \begin{remark}\label{rem:densityend} The regime of Theorem~\ref{thm:density} ends at $ck$ of order $\sqrt{\log n/\log\log n}$. Below that order the exponent is $o(n)$; at that order $\theta_n$ is bounded away from $0$ and \eqref{eq:explicit} is no better than enumeration. The routine of Proposition~\ref{prop:routine} cannot reach quadratic density with any design at all. The balance condition \eqref{eq:balance} and $M\le bn$ give $D^2\le M/(2(b+w))