Primal–dual LP foundations

Q1. How can linear inequalities prove either that a network stores its patterns or that every choice of weights fails?

A linear program optimizes a linear function subject to linear constraints; its dual searches for weighted combinations of those constraints.

We first work with ordinary inequalities in two variables, then construct the network's constraint matrix. The experiment's solver discussion uses this formulation; D1 states the resulting network alternative.

1. Linear expressions, coefficient vectors and constraint rows

For a variable vector \(\theta\in\mathbb R^d\), a linear function has the form

$$\ell:\mathbb R^d\to\mathbb R,\qquad \ell(\theta)=\sum_{j=1}^d a_j\theta_j=a^\top\theta.$$

The coefficient vector \(a=(a_1,\ldots,a_d)^\top\) lists the coefficients of the variables in their chosen order. For example,

$$\ell(\theta)=2\theta_1-3\theta_2, \qquad a=\begin{pmatrix}2\\-3\end{pmatrix}.$$

The coefficients are fixed; the value \(\ell(\theta)\) changes with \(\theta\). With a constant term, \(a^\top\theta+\beta\) is an affine function, and \(\beta\) is not part of \(a\).

For \(N\) inequalities, put the coefficient vectors into the rows of a matrix:

$$A=\begin{pmatrix}a_1^\top\\\vdots\\a_N^\top\end{pmatrix} \in\mathbb R^{N\times d},\qquad b\in\mathbb R^N.$$ $$A\theta\ge b\quad\Longleftrightarrow\quad a_k^\top\theta\ge b_k\quad(k=1,\ldots,N).$$

All vector inequalities on this page are coordinatewise; \(A\theta>0\) means every coordinate is strictly positive.

$$\begin{aligned}2\theta_1-3\theta_2&\ge1,\\ \theta_1+\theta_2&\ge4\end{aligned}$$ $$\Longleftrightarrow\quad \begin{pmatrix}2&-3\\1&1\end{pmatrix}\theta \ge\begin{pmatrix}1\\4\end{pmatrix}.$$

A feasible point satisfies all the inequalities; their intersection is the feasible set. In two dimensions each inequality specifies a half-plane.

Q1.1. Which points satisfy both inequalities?

Change one constraint, then move the test point by dragging it or using its sliders.

1: blue2: amberGreen: intersection

Edit one constraint
Test point θ
Figure 1. The feasible set contains exactly the points whose two residuals are nonnegative.
$$r_k=a_k^\top\theta-b_k,\qquad A\theta\ge b\iff r_1,r_2\ge0.$$

Solid boundaries are included; the arrow is parallel to the edited row's coefficient vector and points toward increasing values of \(a_k^\top\theta\). The window clips the half-planes; it adds no bounds on \(\theta\).

Why does the coefficient vector point into its half-plane?

For a nonzero row \(a_k\), start on its boundary and move in direction \(a_k\):

$$a_k^\top\theta_0=b_k,\quad t>0,$$ $$a_k^\top(\theta_0+t a_k) =b_k+t\lVert a_k\rVert^2>b_k.$$

If \(a_k=0\), its constraint is instead either all of \(\mathbb R^2\) or the empty set, according as \(b_k\le0\) or \(b_k>0\).

Related interactive examples

For further widgets, the most useful next steps are adjustable row weights in Q2 and simultaneous primal/dual points in Q3.

Antolín Camarena, Thinking of linear programs geometrically · Desmos examples
Each one is drawn as a translucent half-plane, where the half-planes overlap their colors combine.

Used here: separate half-plane layers and a common feasible region. Original passage and interactive examples.

Grand and Klamkin, lpviz (2026) · §1.1
users simply click on the canvas grid to incrementally build the feasible region.

Its interface edits vertices and converts them to inequalities; this widget edits coefficient rows to match Section 1. Original passage · Live tool.

Robbins et al., GILP (SIGCSE 2023) · §3
The iteration slider moves through iterations of the Simplex algorithm.

Best suited to a later solver widget: highlight the current vertex and its corresponding algebra together. Original passage · Interactive examples.

Q2. Why may we multiply vector inequalities by nonnegative weights?

Fix \(A\in\mathbb R^{N\times d}\), \(\theta\in\mathbb R^d\), and \(\lambda\in\mathbb R^N\). Let \(\mathbf1_N\) denote the vector of \(N\) ones.

$$\left.\begin{aligned}A\theta&\ge\mathbf1_N,\\\lambda&\ge0\end{aligned}\right\} \quad\Longrightarrow\quad \lambda^\top A\theta\ge\mathbf1_N^\top\lambda.$$

The matrix products, written out

Set \(u=A\theta\in\mathbb R^N\). Each \(u_k\ge1\); multiplying it by \(\lambda_k\ge0\) preserves the inequality, so

$$\begin{aligned} \lambda^\top A\theta &=\begin{pmatrix}\lambda_1&\cdots&\lambda_N\end{pmatrix} \begin{pmatrix}u_1\\\vdots\\u_N\end{pmatrix}\\ &\ge\begin{pmatrix}\lambda_1&\cdots&\lambda_N\end{pmatrix} \begin{pmatrix}1\\\vdots\\1\end{pmatrix}\\ &=\sum_{k=1}^N\lambda_k. \end{aligned}$$

The right-hand side is the same sum:

$$\begin{aligned} \mathbf1_N^\top\lambda &=\begin{pmatrix}1&\cdots&1\end{pmatrix} \begin{pmatrix}\lambda_1\\\vdots\\\lambda_N\end{pmatrix}\\ &=\sum_{k=1}^N\lambda_k =\lambda^\top\mathbf1_N. \end{aligned}$$

Both products have size \(1\times1\). The transpose moves because transposing a scalar leaves it unchanged:

$$\lambda^\top\mathbf1_N =(\lambda^\top\mathbf1_N)^\top =\mathbf1_N^\top\lambda.$$

This is a dot-product identity; matrix products cannot generally be swapped.

In general the transpose collects the weighted coefficients:

$$A^\top:\mathbb R^N\to\mathbb R^d,\qquad \lambda\mapsto\sum_{k=1}^N\lambda_k a_k.$$
$$\begin{gathered} \lambda\ge0,\quad\mathbf1_N^\top\lambda=1,\quad A^\top\lambda=0\\ \Longrightarrow\quad \text{no }\theta\text{ satisfies }A\theta\ge\mathbf1_N. \end{gathered}$$

Such a \(\lambda\) is a certificate of infeasibility: a proposed feasible point would imply \(0\ge1\). Any nonzero nonnegative cancellation can be normalized by its positive total weight; zero entries are allowed.

This argument shows that a certificate rules out feasibility. Section 6 proves that a certificate exists whenever strict feasibility fails.

Q3. What do a primal LP and its dual optimize?

Fix a matrix \(B\in\mathbb R^{q\times p}\), a right-hand side \(b\in\mathbb R^q\), and an objective vector \(c\in\mathbb R^p\). Consider this choice of primal and dual conventions:

$$\begin{aligned} \text{Primal: }&\inf_{x\in\mathbb R^p}c^\top x\\ &\text{subject to }Bx\ge b,\ x\ge0. \end{aligned}$$ $$\begin{aligned} \text{Dual: }&\sup_{y\in\mathbb R^q}b^\top y\\ &\text{subject to }B^\top y\le c,\ y\ge0. \end{aligned}$$

The primal chooses a feasible point; the dual chooses weights that give a lower bound on every feasible objective value.

Weak duality

For every primal-feasible \(x\) and dual-feasible \(y\),

$$\underbrace{b^\top y}_{\text{dual value}} \le y^\top Bx =(B^\top y)^\top x \le\underbrace{c^\top x}_{\text{primal value}}.$$

The first inequality uses \(y\ge0\); the last uses \(x\ge0\). Taking the best values gives \(\sup b^\top y\le\inf c^\top x\) when both feasible sets are nonempty.

Why these dual constraints, and what changes for free variables?

The condition \(y\ge0\) lets us add the primal inequalities. Requiring \(B^\top y\le c\) makes the weighted left-hand side at most the objective for every \(x\ge0\).

If a coordinate \(x_j\) can have either sign, that argument requires \((B^\top y)_j=c_j\). Otherwise choose the sign of \(x_j\) to violate the proposed bound. Thus free primal variables produce equality constraints in the dual.

A complete example, without a network

$$\begin{aligned} \text{Primal: }\min\ &x_1+2x_2\\ \text{subject to }&x_1+x_2\ge3,\\ &x_1+3x_2\ge4,\quad x_1,x_2\ge0. \end{aligned}$$ $$\begin{aligned} \text{Dual: }\max\ &3y_1+4y_2\\ \text{subject to }&y_1+y_2\le1,\\ &y_1+3y_2\le2,\quad y_1,y_2\ge0. \end{aligned}$$

Weights \(y=(1,0)\) give the bound \(3\); weights \(y_*=(1/2,1/2)\) give the bound \(7/2\).

$$x_*=(5/2,1/2),\qquad c^\top x_*=\tfrac72=b^\top y_*.$$

These two feasible points prove that both optima equal \(7/2\). Equality of optimal values is called strong duality; this example proves equality by exhibiting matching values.

Figure 2. The dual bound increases until its objective line touches the feasible region at the optimum.

For \(0\le t\le1\), \(y=t(1/2,1/2)\) is dual feasible and proves \(x_1+2x_2\ge7t/2\). The plotted window truncates an unbounded feasible region.

Q4. How do network margins become rows of a matrix?

Fix integers \(n\ge2,m\ge1\) and patterns \(s^1,\ldots,s^m\in\{-1,1\}^n\). We seek symmetric weights and fields:

$$J\in\mathbb R^{n\times n},\quad J=J^\top,\quad J_{ii}=0, \qquad h\in\mathbb R^n.$$

For neuron \(i\) in pattern \(\mu\), define the local field \(H_i^\mu\) and signed margin \(g_i^\mu\):

$$H_i^\mu=\sum_{j\ne i}J_{ij}s_j^\mu+h_i, \qquad g_i^\mu=s_i^\mu H_i^\mu.$$

The pattern is strictly stored when \(g_i^\mu>0\) for every neuron; the same \(J,h\) must store every pattern.

$$\begin{gathered} d=n+\binom n2,\qquad N=nm,\\ \theta=(h_1,\ldots,h_n,(J_{pq})_{p<q})\in\mathbb R^d. \end{gathered}$$

For fixed \(s^\mu\), the margin is a linear function \(g_i^\mu:\mathbb R^d\to\mathbb R\). Its coefficient vector \(a_i^\mu\in\mathbb R^d\) is defined by

$$g_i^\mu(\theta)=(a_i^\mu)^\top\theta.$$ $$\begin{aligned} (a_i^\mu)_{h_k}&=\begin{cases}s_i^\mu,&k=i,\\0,&k\ne i,\end{cases}\\ (a_i^\mu)_{J_{pq}}&=\begin{cases}s_p^\mu s_q^\mu,&i\in\{p,q\},\\0,&i\notin\{p,q\}. \end{cases} \end{aligned}$$

Thus “coefficient vector of the margin” means the coefficients of this particular linear function, in the chosen parameter order.

For \(n=3\), order the parameters as \((h_1,h_2,h_3,J_{12},J_{13},J_{23})\). If \(s^\mu=(1,-1,1)\), neuron 2 has

$$g_2^\mu=-h_2-J_{12}-J_{23},$$ $$a_2^\mu=(0,-1,0,-1,0,-1)^\top.$$

Stack all \(nm\) rows \((a_i^\mu)^\top\) into \(A\in\mathbb R^{N\times d}\), ordered first by pattern and then by neuron. Then

$$A:\mathbb R^d\to\mathbb R^N,\qquad \theta\mapsto(g_i^\mu(\theta))_{\mu,i}.$$
$$\begin{aligned}F&\iff\exists\theta:\ A\theta>0\\ &\iff\exists\theta:\ A\theta\ge\mathbf1_N. \end{aligned}$$

Here \(F\) means that the fixed sample admits symmetric storage; \(F^c\) means that it does not.

Why can we replace “positive” by “at least one”?

There are finitely many margins. If all are positive,

$$\delta=\min_{i,\mu}g_i^\mu(\theta)>0, \qquad A(\theta/\delta)\ge\mathbf1_N.$$

The converse follows from \(1>0\). This rescaling uses unbounded parameter size and the absence of a fixed constant term in the margins; it need not preserve imposed weight bounds.

What does coefficient cancellation require?

A multiplier \(\lambda_i^\mu\ge0\) weights one margin. The coefficient of each field in \(A^\top\lambda\) is

$$ (A^\top\lambda)_{h_i}=\sum_{\mu=1}^m\lambda_i^\mu s_i^\mu.$$

Each shared edge appears in both endpoint neurons' margins:

$$ (A^\top\lambda)_{J_{ij}} =\sum_{\mu=1}^m(\lambda_i^\mu+\lambda_j^\mu)s_i^\mu s_j^\mu, \qquad i<j.$$

Setting these \(d\) coefficients to zero cancels every network parameter, giving exactly D1's equations.

The two-neuron example computes both a storing network and a failure certificate.