---
title: GameTheory Package for Equilibrium Analysis
url: https://www.emergentmind.com/topics/gametheory-package
type: topic
---

# GameTheory Package for Equilibrium Analysis

GameTheory is a package for Macaulay2 for computing equilibria in finite normal-form games. In version 1.0, available since Macaulay2 version 1.25.05, it organizes four equilibrium notions—Nash, correlated, dependency, and conditional independence equilibria—within a single framework that uses algebraic, combinatorial, polyhedral, and algebraic-statistical methods rather than a single numerical paradigm [2507.16755]. A finite game is encoded as a list of payoff tensors, and the package exposes different computational objects according to the equilibrium notion under study: polynomial rings and ideals for Nash equilibria, polyhedra for correlated equilibria, determinantal ideals and Konstanz matrices for dependency equilibria, and graphical-model conditional-independence ideals together with saturated intersections for conditional independence equilibria.

## 1. Scope, representation, and package entry points

The package works with finite normal-form games. An \(n\)-player game is encoded by a list
\[
X=(X^{(0)},\dots,X^{(n-1)})
\]
of payoff tensors, each of format \((d_0,\dots,d_{n-1})\), where \(d_i\) is the number of pure strategies for player \(i\). The entry \(X^{(i)}_{j_0\cdots j_{n-1}}\) is the payoff to player \(i\) when player \(k\) chooses strategy \(j_k\). In this representation, a game is an ordered list of tensors; games can be constructed manually with `zeroTensor {d_0,...,d_(n-1)}` and explicit entry assignment, or generated with `randomTensor` and `randomGame`. The default coefficient ring is \(\mathbb Q\), and it can be changed with `CoefficientRing => R` [2507.16755].

The package is loaded by the standard Macaulay2 command:

```m2
needsPackage "GameTheory"
```

The computational approach depends on the equilibrium notion under consideration.

| Equilibrium notion | Primary computational object | Representative commands |
|---|---|---|
| Nash | Polynomial rings and ideals | `nashEquilibriumRing`, `nashEquilibriumIdeal` |
| Correlated | Polyhedra | `probabilityRing`, `correlatedEquilibria` |
| Dependency | Spohn matrices, determinantal ideals, Konstanz matrices | `spohnMatrices`, `spohnIdeal`, `konstanzMatrix` |
| Conditional independence | CI ideals and Spohn-CI ideals | `ciIdeal`, `spohnCI`, `intersectWithCImodel` |

A basic example used throughout is the 2-player Bach or Stravinsky game with payoff matrices
\[
X^{(0)}= \begin{pmatrix} 3 & 0 \\ 0 & 2 \end{pmatrix},
\qquad
X^{(1)}= \begin{pmatrix} 2 & 0 \\ 0 & 3 \end{pmatrix},
\]
entered by constructing two \(2\times2\) tensors and setting `X = {A,B}` [2507.16755].

## 2. Nash equilibria as multilinear polynomial systems

For Nash equilibria, the package uses the standard mixed-strategy model. If player \(i\) has \(d_i\) pure strategies, then a mixed strategy is given by probabilities \(p^{(i)}_j\) satisfying
\[
\sum_{j=0}^{d_i-1} p^{(i)}_j = 1.
\]
A mixed-strategy profile is
\[
\mathbf p \in \Delta_{d_0-1}\times\cdots\times\Delta_{d_{n-1}-1},
\]
and the expected payoff to player \(i\) is
\[
\pi_i(\mathbf p) =
\sum_{j_0=0}^{d_0-1}\cdots\sum_{j_{n-1}=0}^{d_{n-1}-1}
X^{(i)}_{j_0\cdots j_{n-1}}
\,p^{(0)}_{j_0}\cdots p^{(n-1)}_{j_{n-1}}.
\]
The package emphasizes totally mixed Nash equilibria, where every \(p^{(i)}_j>0\). These are characterized by a multilinear polynomial system, together with the simplex equations \(\sum_j p^{(i)}_j=1\) for all \(i\) [2507.16755].

The main Nash commands are `nashEquilibriumRing X`, which constructs the polynomial ring in variables \(p_{i,j}\), and `nashEquilibriumIdeal(R,X)`, which builds the ideal generated by the multilinear Nash equations and simplex constraints. In the \((2\times2\times2)\)-game from McLennan, the package computes:

```m2
R = nashEquilibriumRing Y;
J = nashEquilibriumIdeal(R, Y);
```

and the resulting ideal satisfies
\[
\dim J = 0,\qquad \deg J = 2.
\]
Its decomposition reveals a unique totally mixed Nash equilibrium at
\[
\Bigl((\tfrac12,\tfrac12),(\tfrac12,\tfrac12),(\tfrac12,\tfrac12)\Bigr),
\]
but as a double point of the equilibrium ideal [2507.16755].

The package also supports symbolic perturbation. In the same example, after perturbing one payoff tensor over \(S=\mathbb Q[e]\), the last generator of the decomposition is
\[
12\bigl(p^{(2)}_1\bigr)^2 + (2e-12)p^{(2)}_1 + 3.
\]
From this, the paper infers two totally mixed Nash equilibria for \(-\frac32<e<0\), one double equilibrium at \(e=0\), and none otherwise [2507.16755].

For generic games, the package also addresses upper bounds for the number of isolated totally mixed Nash equilibria. By Bernstein’s theorem, the count is bounded by the mixed volume of Newton polytopes. The command `deltaList` constructs the relevant polytope list, `numberTMNE {d_0,...,d_(n-1)}` computes the mixed-volume count via a vector bundle/Chern class formula, and `blockDerangements` computes the corresponding combinatorial count. For a generic \((2,2,2)\)-game,
\[
\texttt{numberTMNE \{2,2,2\} = 2.
\]
The paper notes that for \((3,3,3)\), `numberTMNE` and `blockDerangements` remain fast whereas direct `mixedVolume(deltaList {3,3,3})` is impractically slow [2507.16755].

## 3. Correlated equilibria as convex polyhedra

For correlated equilibria, the package replaces independent mixed strategies by a joint probability distribution. If the game has format \((d_0,\dots,d_{n-1})\), then the variable
\[
p_{j_0\cdots j_{n-1}}
\]
represents the probability of the pure strategy profile \((j_0,\dots,j_{n-1})\). These variables lie in the simplex
\[
\Delta_{d_0\cdots d_{n-1}-1},
\]
with nonnegativity and normalization constraints [2507.16755].

The correlated equilibrium inequalities are linear:
\[
\sum_{j_0=0}^{d_0-1}\cdots \widehat{\sum_{j_i=0}^{d_i-1}} \cdots \sum_{j_{n-1}=0}^{d_{n-1}-1}
\left(
X^{(i)}_{j_0\cdots j_{i-1}k j_{i+1}\cdots j_{n-1}}
-
X^{(i)}_{j_0\cdots j_{i-1}l j_{i+1}\cdots j_{n-1}}
\right)
p_{j_0\cdots j_{i-1}k j_{i+1}\cdots j_{n-1}}
\ge 0
\]
for all players \(i\) and pure strategies \(k,l\). Together with simplex constraints, these define the correlated equilibrium polytope \(P_X\) [2507.16755].

The package uses `probabilityRing Di` to construct the ring of joint-probability variables and `correlatedEquilibria X` to return a `Polyhedron` object through Polyhedra.m2. In the Bach or Stravinsky example, the paper identifies three Nash equilibria inside the correlated equilibrium set: two pure equilibria,
\[
(1,0,0,0),\qquad (0,0,0,1),
\]
and one totally mixed equilibrium,
\[
\left(\frac{6}{25},\frac{9}{25},\frac{4}{25},\frac{6}{25}\right).
\]
A mediator that recommends \((\mathrm{B},\mathrm{B})\) on heads and \((\mathrm{S},\mathrm{S})\) on tails yields a Pareto-optimal correlated equilibrium. The computed polytope \(P_X\) is 3-dimensional with five vertices, and the paper interprets it geometrically as a double pyramid over a triangle associated with the Nash equilibria [2507.16755].

## 4. Dependency equilibria and the Spohn variety

Dependency equilibria are defined on joint distributions but impose a different optimality condition from correlated equilibria. For player \(i\), conditioned on choosing pure strategy \(k\),
\[
\mathbb E^{(i)}_k(p)
=
\sum
X^{(i)}_{j_0\cdots k\cdots j_{n-1}}
\frac{p_{j_0\cdots k\cdots j_{n-1}}}
{p_{+\cdots +\,k\,+\cdots +}}.
\]
For \(p\) in the interior of the simplex, \(p\) is a dependency equilibrium if
\[
\mathbb E^{(i)}_k(p)\ge \mathbb E^{(i)}_{k'}(p)
\quad\text{for all }i,k,k'.
\]
Because all pairwise inequalities hold, one obtains
\[
\mathbb E^{(i)}_k(p)=\mathbb E^{(i)}_{k'}(p).
\]
This condition is encoded algebraically by the Spohn variety \(\mathcal V_X\), defined by the vanishing of the \(2\times2\) minors of the Spohn matrices \(M_i(p)\) [2507.16755].

The corresponding commands are `spohnMatrices(PR,X)` and `spohnIdeal(PR,X)`. For generic payoff tensors, the paper recalls a theorem stating that the Spohn variety is irreducible of codimension
\[
d_0+\cdots+d_{n-1}-n
\]
and degree
\[
d_0d_1\cdots d_{n-1},
\]
and that its intersection with the Segre variety inside the open simplex is exactly the set of totally mixed Nash equilibria. For a random \((2,2,2)\)-game, the package verifies
\[
\operatorname{codim}(spohnI)=3,\qquad \deg(spohnI)=8,\qquad \texttt{isPrime spohnI}=\texttt{true}
\]
as predicted by the generic theory [2507.16755].

An alternative representation uses the Konstanz matrix \(K_X(z)\), characterized by
\[
K_X(z)\cdot p = 0
\quad\text{for some } z\in (\mathbb P^1)^d.
\]
The package provides `konstanzMatrix(PR,X)` for this representation. In Bach or Stravinsky, the Spohn variety is reducible, and the paper verifies computationally that if \(P\) is the vectorization of the probability tensor \(p\), then
\[
K\cdot P = (spohnM_0\cdot (k_0,-1)^T)\ \|\ (spohnM_1\cdot (k_1,-1)^T),
\]
matching the theoretical definition [2507.16755].

## 5. Conditional independence equilibria and graphical-model structure

The final equilibrium notion combines dependency equilibria with conditional independence constraints from algebraic statistics. A conditional independence statement has the form
\[
X_A \perp X_B \mid X_C
\]
for disjoint sets \(A,B,C\) of players, and is encoded by the standard \(2\times2\)-minor equations
\[
p_{i_A i_B i_C}\, p_{j_A j_B i_C} - p_{i_A j_B i_C}\, p_{j_A i_B i_C} =0.
\]
Given a set \(\mathcal C\) of such statements, the corresponding CI model \(\mathcal M_{\mathcal C}\) is the variety cut out by those equations [2507.16755].

The package computes these ideals through GraphicalModels.m2. The command `ciIdeal(PR, Stmts)` accepts CI statements encoded as `{A,B,C}`, while `ciIdeal(PR, G)` uses the global Markov property of an undirected graph. Interoperability utilities include `toMarkovRing`, `mapToMarkovRing`, and `mapToProbabilityRing`. In a \((2,2,2)\)-game, the line graph on three vertices yields the same CI ideal as the statement that player 1 is independent of player 3 given player 2 [2507.16755].

The equilibrium object is the Spohn CI variety
\[
\mathcal V_{X,\mathcal C} =
\overline{\bigl(\mathcal V_X \cap \mathcal M_{\mathcal C}^{\mathrm{par}}\bigr)\setminus W},
\]
where \(W\) is the union of coordinate and marginal hyperplanes removed before closure. The main command is `spohnCI(PR, X, Stmts)` or `spohnCI(PR, X, G)`. Internally, the method computes `spohnIdeal(PR,X)`, intersects it with the CI model using `intersectWithCImodel`, and saturates by the hyperplanes
\[
\{p_{j_0\cdots j_{n-1}}=0\}
\quad\text{and}\quad
\{p_{+\cdots +}=0\}.
\]
The paper notes that this saturation can be expensive. The implementation uses the Bayer strategy for saturation, and `Verbose => true` prints progress messages such as “Completed step 1 of saturating CI ideal” [2507.16755].

A practical caveat is indexing. GraphicalModels.m2 uses one-based vertex labels, whereas GameTheory uses zero-based player and strategy indices. The package therefore permits relabeling graph vertices, including symbolic names such as `Alice`, `Bob`, and `Claire`, or explicit relabeling to `{0,1,2}` [2507.16755].

## 6. Computational style, interoperability, and limitations

GameTheory does not force a single algorithmic paradigm. Nash and dependency equilibria are treated symbolically via rings, ideals, dimensions, degrees, decompositions, and determinantal structure; correlated equilibria are treated polyhedrally through linear inequalities and convex geometry; conditional independence equilibria add graphical-model ideals and saturation procedures [2507.16755]. This division of labor is also reflected in dependencies: the package explicitly relies on Polyhedra.m2 for correlated equilibria and GraphicalModels.m2 for conditional independence models.

Several limitations are stated directly. Direct mixed-volume computation can be too slow for larger formats, as illustrated by `mixedVolume(deltaList {3,3,3})`. Saturation in `spohnCI` and `intersectWithCImodel` can be computationally expensive. The package also focuses on algebraic and combinatorial formulations rather than classical numerical equilibrium algorithms such as Lemke–Howson [2507.16755]. A plausible implication is that its natural use case is structural analysis of finite normal-form games inside the Macaulay2 ecosystem, rather than large-scale numerical equilibrium computation.

This specialization distinguishes GameTheory from other game-theoretic software lines. “Game Theory Explorer” is a browser-based tool for creating extensive-form and strategic-form games and computing all Nash equilibria of two-player games [1403.3969]. `GPGame` is an R package on CRAN for finding pure Nash equilibria in expensive black-box games by Bayesian optimization [1611.02440]. ZERO is an open-source C++ library for Reciprocally Bilinear Games and related mathematical-programming games [2111.07932]. Arena is a prototype programmable framework for tournaments of heterogeneous games played by agents across multiple rounds and game types [1807.08545]. Against that background, GameTheory occupies a distinct niche: finite normal-form games studied through algebraic geometry, polyhedral computation, and algebraic statistics rather than browser interaction, black-box optimization, mathematical-programming equilibrium search, or agent-based simulation.

## 7. Mathematical profile and place within equilibrium computation

The package’s defining feature is the coexistence of four equilibrium notions under one formal representation of a finite normal-form game. Nash equilibria appear as solutions of multilinear polynomial systems; correlated equilibria as points of a convex polytope; dependency equilibria as points on the Spohn variety cut out by \(2\times2\) minors; and conditional independence equilibria as saturated intersections of dependency-equilibrium structure with CI models from graphical models [2507.16755]. This architecture places equilibrium computation inside Macaulay2’s native strengths: ideal theory, decomposition, dimension and degree calculations, polyhedral geometry, and symbolic perturbation.

The examples in the paper show that the package is designed not only to return equilibria but to expose their geometry. In the McLennan \((2\times2\times2)\)-game, the unique totally mixed Nash equilibrium appears as a double point of the equilibrium ideal. In Bach or Stravinsky, the correlated equilibrium set becomes a 3-dimensional polyhedron with five vertices, while the dependency-equilibrium variety is reducible in the nongeneric case and becomes prime after perturbation. In random \((2,2,2)\)-games, generic codimension and degree predictions for the Spohn ideal are verified computationally [2507.16755]. These examples indicate that the package is aimed at analysis of equilibrium structure as much as at equilibrium detection itself.

In that sense, GameTheory is best understood as a Macaulay2 package for the geometry and combinatorics of equilibria in finite normal-form games. Its contribution is not to replace general-purpose numerical solvers, but to provide a unified symbolic and polyhedral environment in which Nash, correlated, dependency, and conditional independence equilibria can be represented, computed, perturbed, decomposed, and compared within a common algebraic framework [2507.16755].

Source: https://www.emergentmind.com/topics/gametheory-package