Primal–dual LP foundations
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.
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.
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.
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.$$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:
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.
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}.$$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.
The two-neuron example computes both a storing network and a failure certificate.
Q5. How does an LP decide whether these patterns can be stored?
Fix \(m\ge1\) patterns \(s^1,\ldots,s^m\in\{-1,1\}^n\), with \(n\ge2\) neurons. We seek one symmetric matrix \(J\in\mathbb R^{n\times n}\), with \(J_{ii}=0\), and fields \(h\in\mathbb R^n\) that make every signed margin positive:
$$g_i^\mu=s_i^\mu\left(h_i+\sum_{j\ne i}J_{ij}s_j^\mu\right)>0 .$$A positive margin means the local field has the prescribed neuron's sign. Let \(\theta\in\mathbb R^d\) collect the \(n\) fields and the \(\binom n2\) shared edge weights; these parameters may have either sign and have no size bound.
$$d=n+\binom n2,\qquad N=nm.$$The patterns determine a matrix \(A\in\mathbb R^{N\times d}\), whose linear map returns all the margins:
$$A:\mathbb R^d\to\mathbb R^N,\qquad \theta\mapsto(g_i^\mu(\theta))_{\mu,i}.$$Each row is the coefficient vector of one margin; Q4 gives its entries.
The fixed-sample storage question
$$F\iff\exists\theta\in\mathbb R^d:\ A\theta>0.$$\(F^c\) is the complement: every choice of \(\theta\) has at least one margin at most zero.
Positive margins can be scaled to unit margins. If the smallest margin is \(\delta>0\), dividing all parameters by \(\delta\) gives
$$A(\theta/\delta)\ge\mathbf1_N.$$ $$F\iff\exists\widehat\theta\in\mathbb R^d:\ A\widehat\theta\ge\mathbf1_N.$$Here \(\mathbf1_N\) is the column of \(N\) ones. This normalization uses the finite number of constraints and the absence of parameter bounds.
Example 5.1. Add one pattern to a two-neuron network
Set \(n=2\) and \(\theta=(h_1,h_2,J_{12})^\top\). With the single pattern \(s^1=(1,1)\), choose
$$A=\begin{pmatrix}1&0&1\\0&1&1\end{pmatrix},\qquad \theta=\begin{pmatrix}0\\0\\1\end{pmatrix}.$$ $$A\theta=\begin{pmatrix}1\\1\end{pmatrix}.$$These parameters store the single pattern with unit margins.
Now add \(s^2=(1,-1)\), keeping the first pattern. In pattern-then-neuron order, the enlarged margin map is
$$A=\begin{pmatrix}1&0&1\\0&1&1\\1&0&-1\\0&-1&-1\end{pmatrix},$$ $$A\theta=\begin{pmatrix}h_1+J_{12}\\h_2+J_{12}\\h_1-J_{12}\\-h_2-J_{12}\end{pmatrix}.$$For the enlarged sample, give the second and fourth rows weight \(1/2\) each, and the other rows weight zero:
$$\lambda=\begin{pmatrix}0\\1/2\\0\\1/2\end{pmatrix},\qquad A^\top\lambda=\begin{pmatrix}0\\0\\0\end{pmatrix}.$$The weights sum to one. If every margin were at least one, averaging the second and fourth would give
$$\begin{aligned} 0&=\tfrac12(h_2+J_{12})\\ &\quad+\tfrac12(-h_2-J_{12})\ge1. \end{aligned}$$That contradiction rules out unit margins, hence also strictly positive margins.
This failure already affects neuron 2 without symmetry. The symmetry-only example isolates the additional restriction imposed by shared weights.
The primal minimizes a common shortfall
Write the rows of \(A\) as \(a_k^\top\), for \(k=1,\ldots,N\). Introduce one scalar \(r\ge0\), added to every margin requirement:
$$a_k^\top\theta+r\ge1 \iff a_k^\top\theta\ge1-r.$$At \(r=0\) we require unit margins; at \(r=1\), the zero network is allowed. The primal LP minimizes this common relaxation:
Every instance is feasible at \((\theta,r)=(0,1)\); no feasible value is negative. Thus the optimum lies between zero and one.
Why there are no intermediate optimal values
$$P(A)=\begin{cases}0,&F,\\1,&F^c.\end{cases}$$Proof
Step 1. If \(F\) holds, scale a storing network to unit margins and take \(r=0\), the smallest permitted objective.
Step 2. Any feasible point with \(r<1\) already has strictly positive margins:
$$A\theta\ge(1-r)\mathbf1_N>0.$$So if \(F^c\) holds, every feasible \(r\) is at least one, and \((0,1)\) attains that value.
\(r\) is a relaxation of a normalized margin, not a fraction of failed memories. The zero–one answer relies on allowing arbitrary parameter size.
The dual weights requirements until the parameters cancel
Assign \(y_k\ge0\) to row \(k\), one weight per neuron–pattern requirement. These are auxiliary weights on inequalities; they are not entries of the network matrix \(J\).
Multiplying each primal inequality by its weight and adding gives
$$\sum_{k=1}^N y_k a_k^\top\theta +r\sum_{k=1}^N y_k\ge\sum_{k=1}^N y_k.$$Require the coefficient of every free parameter to vanish:
$$A^\top y=\sum_{k=1}^N y_k a_k=0.$$Also require the total weight to be at most one. Since \(r\ge0\),
$$\mathbf1_N^\top y\le r\mathbf1_N^\top y\le r.$$Thus each such \(y\) supplies a lower bound on every feasible \(r\). The dual LP seeks the largest bound:
This inequality is weak duality. The choice \(y=0\) always works, but only proves the trivial lower bound zero.
Why are these exactly the dual constraints?
The Lagrangian subtracts weighted constraint residuals from the objective:
$$\begin{aligned} L(\theta,r;y)&=r-y^\top(A\theta+r\mathbf1_N-\mathbf1_N)\\ &=\mathbf1_N^\top y-\theta^\top A^\top y\\ &\quad+r(1-\mathbf1_N^\top y). \end{aligned}$$Its domain is \(\mathbb R^d\times[0,\infty)\times[0,\infty)^N\), with scalar output. For fixed \(y\ge0\), it is at most \(r\) at every primal-feasible point.
Step 1. If \(c=A^\top y\ne0\), choose \(\theta=t c\) and let \(t\to\infty\), keeping \(r=0\):
$$L(tc,0;y)=\mathbf1_N^\top y-t\lVert c\rVert^2\to-\infty.$$A finite lower bound therefore requires \(A^\top y=0\).
Step 2. If the total weight exceeds one, letting \(r\to\infty\) again sends \(L\) to \(-\infty\).
Step 3. Otherwise the remaining coefficient of \(r\) is nonnegative, so its infimum over \(r\ge0\) is attained at zero:
$$\inf_{\theta,\ r\ge0}L(\theta,r;y)=\mathbf1_N^\top y.$$Maximizing these finite lower bounds gives the dual above. The infimum ranges over the parameter domain, before imposing the primal inequalities.
Why does a nonzero cancellation prove failure?
A failure certificate is a nonnegative, nonzero vector whose weighted rows cancel. Divide it by the sum of its entries to obtain \(\lambda\):
$$\lambda\ge0,\qquad A^\top\lambda=0,\qquad \mathbf1_N^\top\lambda=1.$$If unit margins were possible, the weighted inequalities would give a contradiction:
$$\lambda^\top A\theta=(A^\top\lambda)^\top\theta=0,$$ $$\lambda^\top A\theta\ge\lambda^\top\mathbf1_N=1.$$The dual variable \(y\) and certificate \(\lambda\) weight the same rows. The dual allows total mass up to one, including zero; \(\lambda\) denotes a certificate normalized to mass exactly one.
Compute both LP values for the two-neuron example
For the first pattern alone, the displayed network has unit margins: \(r=0\) and \(y=0\) give matching values zero.
After adding the second pattern, the same cancellation weights applied to the relaxed constraints give
$$\begin{aligned} &\tfrac12(h_2+J_{12}+r)\\ &\quad+\tfrac12(-h_2-J_{12}+r)\ge1 \end{aligned},$$ $$r\ge1.$$The dual point \(y=\lambda\) gives value one; \((\theta,r)=(0,1)\) attains it in the primal. Hence \(P(A)=D(A)=1\).
Strong duality: the best bound equals the minimum relaxation
A positive-margin network proves success. A normalized cancellation proves failure. To show that these two certificates cover every matrix, we still need the existence argument in Q6.
Proof from Q6
Step 1. Under \(F\), a unit-margin network with \(r=0\) and the dual point \(y=0\) have matching values zero.
Step 2. Under \(F^c\), Q6 supplies a normalized cancellation. Taking \(y=\lambda\) gives dual value one; \((0,1)\) gives primal value one.
Weak duality forces equality in each case, and both optima are attained. This proves strong duality for this LP pair without assuming the general LP duality theorem.
What can a numerical solver certify?
A solver can search either LP. Its candidate network must have verified positive margins; its candidate cancellation must satisfy the certificate conditions with a rigorous check.
A timeout or a small floating-point residual alone decides neither case. The experiment also uses verified residual bounds to prove failure when cancellation is not represented exactly.
Q6. Why must one of these certificates exist?
Fix any real matrix \(A\in\mathbb R^{N\times d}\), with \(N\ge1\), and write its rows as \(a_k^\top\). A cancellation averages these coefficient vectors to zero; a storing parameter vector makes their dot products all positive.
The convex hull \(K\subseteq\mathbb R^d\) is the set of all their nonnegative weighted averages:
$$K=\left\{\sum_{k=1}^N\lambda_k a_k:\ \lambda\ge0,\ \sum_{k=1}^N\lambda_k=1\right\}.$$Exactly one of the following holds:
$$\exists\theta\in\mathbb R^d:\ A\theta>0;$$or there is a vector \(\lambda\in\mathbb R^N\) with
$$\lambda\ge0,\quad A^\top\lambda=0,\quad \mathbf1_N^\top\lambda=1.$$This is Gordan's alternative: Border, Alternative Linear Inequalities, Theorem 41 and Corollary 43, p. 19. The second case is exactly \(0\in K\); the first puts every row strictly on one side of a hyperplane through zero.
The picture uses coefficient space
The earlier half-plane widget plotted possible parameters \(\theta\). Here the plotted points are the fixed row vectors \(a_k\); the green arrow gives a candidate parameter direction against which to test them.
Use a two-dimensional family with three rows:
$$a_1=(1,0)^\top,\quad a_2=(0,1)^\top,$$ $$a_3=(t,-1)^\top.$$ $$A(t)=\begin{pmatrix}1&0\\0&1\\t&-1\end{pmatrix}, \qquad -2\le t\le2.$$This illustrates the matrix alternative; its rows need not come from a network. In the graph, \(z=(z_1,z_2)\) denotes a point in coefficient space.
Blue: rows and their convex hull. Red: zero and the dashed separating line. Green: the direction \(\theta\).
How are the displayed witnesses computed?
For \(t\le0\), cancel the two coordinates separately and normalize:
$$(-t)a_1+a_2+a_3=0,$$ $$\lambda=\frac{1}{2-t}(-t,1,1)^\top.$$At \(t=0\), the first weight is zero; zero weights are allowed. At \(t=-1\), all three weights are \(1/3\).
For \(t>0\), choose \(\theta=(2,t)^\top\). Its margins are
$$A(t)\theta=(2,t,t)^\top>0.$$Because \(t\le2\), dividing by the smallest margin \(t\) gives a unit-margin primal point:
$$\widehat\theta=(2/t,1)^\top,\qquad A(t)\widehat\theta=(2/t,1,1)^\top\ge\mathbf1_3.$$Why the picture proves the alternative
A finite convex hull either contains zero or has a closest point to zero. These cases supply the two certificates.
-
Step 1. A hull containing zero supplies a cancellation
If \(0\in K\), some \(\lambda\in\mathbb R^N\) satisfies
$$\lambda\ge0,\qquad A^\top\lambda=0,$$ $$\mathbf1_N^\top\lambda=1.$$No vector \(\theta\) can then give strictly positive margins.
Proof
By the definition of \(K\), zero is a convex combination of the rows. For any \(\theta\), that combination of its margins is zero:
$$\sum_{k=1}^N\lambda_k a_k^\top\theta=0.$$If every margin were positive, the sum would be positive: at least one weight is positive because their sum is one. This is a contradiction.
-
Step 2. A hull missing zero has a nonzero closest point
If \(0\notin K\), some \(v\in K\) minimizes the Euclidean norm, and
$$\lVert v\rVert>0.$$Proof
The possible weights form a closed, bounded simplex in \(\mathbb R^N\):
$$\Delta=\{\lambda\ge0:\mathbf1_N^\top\lambda=1\}.$$It is compact in finite dimension. The continuous map \(\lambda\mapsto A^\top\lambda\), from \(\Delta\) to \(\mathbb R^d\), has image \(K\), so \(K\) is compact too. The continuous norm attains its minimum on \(K\); the minimizer is nonzero since zero is not in \(K\).
-
Step 3. The closest point supplies strictly positive margins
For that minimum-norm point \(v\) and every row \(k\),
$$a_k^\top v\ge\lVert v\rVert^2>0.$$Thus \(\theta=v\) is a strict solution; dividing it by \(\lVert v\rVert^2\) gives unit margins.
Proof
For any \(z\in K\), convexity puts \(v+\tau(z-v)\) in \(K\) whenever \(0\le\tau\le1\). The minimum property gives
$$\begin{aligned} 0&\le\lVert v+\tau(z-v)\rVert^2-\lVert v\rVert^2\\ &=2\tau v^\top(z-v)+\tau^2\lVert z-v\rVert^2. \end{aligned}$$Divide by \(\tau>0\), then let \(\tau\downarrow0\):
$$v^\top(z-v)\ge0,$$ $$v^\top z\ge\lVert v\rVert^2.$$Apply this to each row vector \(z=a_k\). Every row, and its entire convex hull, lies strictly on the positive side of the hyperplane \(v^\top z=0\).
Sources
The argument proves the normalized alternative stated in Border, Theorem 41 and Corollary 43, p. 19. The source writes \(pA=0\); our column-vector convention is \(A^\top\lambda=0\). Its \(p>0\) means nonnegative and nonzero; our \(A\theta>0\) means positive in every coordinate.
Q6.1. Can you build both certificates in a new case?
For rows \((2,0),(0,2),(-1,-1)\), find normalized cancellation weights and deduce the smallest relaxation \(r\). Then replace the third row by \((1,1)\) and construct unit margins.
This alternative decides a fixed sample. The experiment asks how often random samples fall into each case.