# Polynomial Invariants for Affine Programs

We exhibit an algorithm to compute the strongest polynomial (or algebraic) invariants that hold at each location of a given affine program (i.e., a program having only non-deterministic (as opposed to conditional) branching and all of whose assignments are given by affine expressions). Our main tool is an algebraic result of independent interest: given a finite set of rational square matrices of the same dimension, we show how to compute the Zariski closure of the semigroup that they generate.

## Authors

• 1 publication
• 25 publications
• 10 publications
• 32 publications
02/27/2019

### Algebraic Invariants for Linear Hybrid Automata

We exhibit an algorithm to compute the strongest algebraic (or polynomia...
03/05/2021

### Algebra-based Synthesis of Loops and their Invariants (Invited Paper)

Provably correct software is one of the key challenges in our softwaredr...
01/11/2018

### Invariant Generation for Multi-Path Loops with Polynomial Assignments

Program analysis requires the generation of program properties expressin...
07/18/2019

### On the Monniaux Problem in Abstract Interpretation

The Monniaux Problem in abstract interpretation asks, roughly speaking, ...
06/12/2017

### When is a polynomial ideal binomial after an ambient automorphism?

Can an ideal I in a polynomial ring k[x] over a field be moved by a chan...
01/15/2020

### Invertible Generative Modeling using Linear Rational Splines

Normalizing flows attempt to model an arbitrary probability distribution...
12/17/2018

### Canonical projection tilings defined by patterns

We give a necessary and sufficient condition on a d-dimensional affine s...
##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1. Introduction

#### Invariants

Invariants are one of the most fundamental and useful notions in the quantitative sciences, appearing in a wide range of contexts, from gauge theory, dynamical systems, and control theory in physics, mathematics, and engineering to program verification, static analysis, abstract interpretation, and programming language semantics (among others) in computer science. In spite of decades of scientific work and progress, automated invariant synthesis remains a topic of active research, particularly in the fields of theorem proving and program analysis, and plays a central role in methods and tools seeking to establish correctness properties of computer programs; see, e.g., (Kincaid et al., 2018), and particularly Sec. 8 therein.

#### Affine Programs

Affine programs are a simple kind of nondeterministic imperative programs (which may contain arbitrarily nested loops) in which the only instructions are assignments whose right-hand sides are affine expressions, such as . A conventional imperative program can be abstracted to an affine program by replacing conditionals with nondeterminism and conservatively over-approximating non-affine assignments, see, e.g., (Bradley and Manna, 2007). In doing so, affine programs enable one to reason about more complex programs; a particularly striking example is the application of affine programs to several problems in inter-procedural analysis (Bradley and Manna, 2007; Müller-Olm and Seidl, 2004a, b; Gulwani and Necula, 2003).

#### Affine Invariants

An affine invariant for an affine program with variables assigns to each program location an affine subspace of such that the resulting family of subspaces is preserved under the transition relation of the program. Such an invariant is specified by giving a finite set of affine relations at each location. The strongest (i.e., smallest with respect to set inclusion) affine invariant is obtained by taking the affine hull of the set of reachable configurations (i.e., values of the program variables) at each program location. Equivalently, the strongest affine invariant is determined by giving, for each program location, the set of all affine relations holding at that location.

An algorithm due to Michael Karr in 1976 (Karr, 1976) computes the strongest affine invariant of an affine program. A more efficient reformulation of Karr’s algorithm was given by Müller-Olm and Seidl (Müller-Olm and Seidl, 2004a), who moreover showed that if the class of affine programs is augmented with equality guards then it becomes undecidable whether or not a given affine relation holds at a particular program location. A randomised algorithm for discovering affine relations was proposed by Gulwani and Necula (Gulwani and Necula, 2003).

#### Polynomial Invariants

A natural and more expressive generalisation of affine invariants are polynomial invariants. A polynomial invariant assigns to each program location a variety (or algebraic set, i.e., positive Boolean combination of polynomial equalities) such that the resulting family is preserved under the transition relation of the program. A polynomial invariant is specified by giving a set of polynomial relations that hold at each program location. The strongest polynomial invariant (i.e., smallest variety with respect to set inclusion) is obtained by taking the Zariski closure of the set of reachable configurations in each location.

The problem of computing polynomial invariants for affine programs and related formalisms has been extensively studied over the past fifteen years years; see, e.g., (Cachera et al., 2014; Colón, 2007; Sankaranarayanan et al., 2004; Kapur, 2013; Rodríguez-Carbonell and Kapur, 2007b, a; de Oliveira et al., 2016a; Kovács and Jebelean, 2005; Kovács, 2008; Humenberger et al., 2018; Kincaid et al., 2018; de Oliveira et al., 2016b). However, in contrast to the case of affine invariants, as of yet no method is known to compute the strongest

polynomial invariant, i.e., (a basis for) the set of all polynomial relations holding at each location of a given affine program. Existing methods are either heuristic in nature, or only known to be complete relative to restricted classes of invariants or programs. For example, it is shown in

(Müller-Olm and Seidl, 2004a) (see also (Rodríguez-Carbonell and Kapur, 2007a)) that Karr’s algorithm can be applied to compute the smallest polynomial invariant that is specified by polynomial relations of a fixed degree . (The case of affine invariants corresponds to .) The paper (de Oliveira et al., 2016a)

gives a method that finds all polynomial invariants for a highly restricted class of affine programs (in which all linear mappings have positive rational eigenvalues). The approach of

(Kovács, 2008; Humenberger et al., 2018) via so-called P-solvable loops does not encompass the whole class of affine programs either (although it does allow to handle certain classes of programs with polynomial assignments) (Kovacs, 2018).

#### Main Contribution

In this paper we give a method to compute the set of all polynomial relations that hold at a given location of an affine program, or in other words the strongest polynomial invariant. The output of the algorithm gives for each program location a finite basis of the ideal of all polynomial relations holding at that location.

Our main tool is an algebraic result of independent interest: we give an algorithm that, given a finite set of rational square matrices of the same dimension, computes the Zariski closure of the semigroup that they generate. Our algorithm generalises (and uses as a subroutine) an algorithm of Derksen, Jeandel, and Koiran (Derksen et al., 2005) to compute the Zariski closure of a finitely generated group of invertible matrices.111Related to this, Corollary 3.7 and Lemma 3.6a in (Hrushovski, 2002) reduce the question of computing the Zariski closure of a finitely generated group of invertible matrices to that of finding multiplicative relations among diagonal matrices. Note that if one begins with rational matrices, then such relations can be found simply using prime decomposition of the entries.

Our procedure for computing the Zariski closure of a matrix semigroup also generalises a result of Mandel and Simon (Mandel and Simon, 1977) and, independently, of Jacob (Jacob, 1977, 1978), to the effect that it is decidable whether a finitely generated semigroup of rational matrices is finite. Note that a variety that is given as the zero set of a polynomial ideal is finite just in case the quotient

is finite-dimensional as a vector space over

(Cox et al., 1997, Chapter 5, Sec. 3)). The latter condition can be checked by computing a Gröbner basis for .

As mentioned above, we make use of the result of (Derksen et al., 2005) that one can compute the Zariski closure of the group generated by a finite set of invertible matrices. That result itself relies on several non-trivial mathematical ingredients, including results of Masser (Masser, 1988) on computing multiplicative relations among given algebraic numbers and Schur’s theorem that every finitely generated periodic subgroup of the general linear group is finite.

Given a set of matrices , we leverage these group-theoretic results to compute the Zariski closure of the generated semigroup . To this end we use multilinear algebra as well as structural properties of matrix semigroups to identify finitely many subsemigroups of that can be used to generate the entire semigroup. Pursuing this approach requires that we first generalise the result of (Derksen et al., 2005) to show that one can compute the Zariski closure of the group generated by a constructible (as opposed to finite) set of invertible matrices.

It is worth pointing out that whether a particular configuration is reachable at a certain program location of a given affine program is in general an undecidable problem—this follows quite straightforwardly from the undecidability of the membership problem for finitely generated matrix semigroups, discussed shortly. It is therefore somewhat remarkable that the Zariski closure (i.e., the smallest algebraic superset) of the set of reachable configurations at any particular location nevertheless turns out to be a computable object.

#### Matrix Semigroups and Automata

Decision problems for matrix semigroups have also been studied for many decades, independently of program analysis. One of the most prominent such is the Membership Problem, i.e., whether a given matrix belongs to a finitely generated semigroup of integer matrices. An early and striking result on this topic is due to Markov, who showed undecidability of the Membership Problem in dimension in 1947 (Markov, 1947). Later Paterson (Paterson, 1970) improved this result to show undecidability in dimension , while decidability in dimension remains open. A breakthrough was achieved in 2017 by Potapov and Semukhin, who showed decidability of membership for semigroups generated by nonsingular integer matrices (Potapov and Semukhin, 2017). By contrast, the Membership Problem was shown to be polynomial-time decidable in any dimension by Babai et al. for commuting matrices over algebraic numbers (Babai et al., 1996). As aptly noted by Stillwell, “noncommutative semigroups are hard to understand” (Stillwell, 2016). Matrix semigroup theory also plays a central role in the analysis of weighted automata (such as probabilistic and quantum automata, see, e.g., (Blondel et al., 2005; Derksen et al., 2005)).

#### Abstract Interpretation and Other Approaches

Polynomialinvariants are stronger (i.e., more precise) than affine invariants. Various other types of domains have been considered in the setting of abstract interpretation, e.g., intervals, octagonal sets, and polyhedra (see, e.g., (Cousot and Cousot, 1977; Cousot and Halbwachs, 1978; Miné, 2001) and references in (Bradley and Manna, 2007)). The precision of such domains in general is incomparable to that of polynomial invariants.

The computation of semialgebraic and o-minimal invariants has also been considered in the context of discrete-time linear dynamical systems and linear loops (which can be viewed as highly restricted instances of affine programs); see, e.g., (Fijalkow et al., 2017; Almagor et al., 2018).

## 2. Two Illustrative Examples

We now present two simple examples to illustrate some of the ideas and concepts that are discussed in this paper. Some of the notation and terminology that we use is only introduced in later sections; should this impede understanding, we recommend that the reader return to these examples after having read Sections 3 and 4.

As a first motivating example, consider the following linear loop:

 x:=3; y:=2; {while} 2y−x≥−2 {do} (xy):=(10−86−4)(xy);

This loop never halts, although this fact is perhaps not immediately obvious. Here we show how the techniques developed in this paper can help establish non-termination. To this end, we first turn our code into an affine program consisting of two locations, as follows:

Here is the constant affine function assigning to and to , whereas

is the linear transformation associated with the matrix appearing in our while loop. Note that we have discarded the loop guard.

The collecting semantics of this affine program assigns to location the set of all values taken by the pair of variables in the unending execution of the program. As it turns out, the real Zariski closure of consists of the set

 {(x,y)∈R2:x−9x2−y+24xy−16y2=0}.

By construction, this polynomial invariant is stable under and over-approximates the set of reachable -configurations. Verifying that all tuples in this variety moreover satisfy the guard is now a simple exercise in high-school algebra, from which one concludes that our original loop will indeed never terminate.

For our second example, define to be the matrix semigroup obtained as the real Zariski closure of the semigroup generated by and , where

 S:=(0−110),T:=(1101),E:=(1000).

We show that and in the process illustrate (in a very simple setting) the approach of computing the Zariski closure of a matrix semigroup by order of decreasing rank. This approach underlies the algorithm described in Sec. 6.

Consider first . From the fact that the set of singular matrices in is Zariski closed, one can show that . Now it is well known that and generate the semigroup of integer matrices of determinant and that the real Zariski closure of is the semigroup of real matrices of determinant 222The latter fact follows from the Borel density theorem (Morris, 2001, Sec. 4.5 and Sec. 7.0), but can also be established directly by an elementary argument.; hence . More generally, we can use the algorithm of Derksen, Jeandel, and Koiran (Derksen et al., 2005) to compute the Zariski closure of any finitely generated semigroup of invertible matrices.

Now we consider the sub-semigroup of singular matrices in . This is the real Zariski closure of the semigroup generated by the (constructible) set of matrices

 {MEM′,ME,EM:M,M′∈SL2(R)}.

It is straightforward to observe that this generating set already includes all rank- matrices in and hence that the generated semigroup contains all singular matrices. We conclude that comprises all matrices in of determinant or .

## 3. Mathematical Background

### 3.1. Linear Algebra

Matrices. Let be a field. We denote by the semigroup of square matrices of dimension with entries in . We write for the subgroup of comprising all invertible matrices. Given a set of matrices , we denote by the sub-semigroup of generated by . The rank of a matrix is denoted by , its kernel by , and its image by .

Exterior Algebra and the Grassmannian. Given a vectorspace over the field , its exterior algebra is a vector space that embeds and is equipped with an associative, bilinear, and anti-symmetric map

 ∧:ΛV×ΛV→ΛV.

We can construct as a direct sum

 ΛV=Λ0V⊕Λ1V⊕Λ2V⋯,

where denotes the -exterior power of for , that is, the subspace of generated by -fold wedge products for . If is finite dimensional, with basis , then a basis of is given by , . Thus has dimension (where for ).

A basic property of the wedge product is that given vectors , if and only if is a linearly independent set. Furthermore given we have that and are scalar multiples of each other iff .

The Grassmannian is the set of -dimensional subspaces of . By the above-stated properties of the wedge product there is an injective function

 ι:Gr(r,n)→Λr(Cn)

such that for any , where is an arbitrarily chosen basis of . Note that given two basis and of , there exists such that . In other words, the particular choice of a basis for only changes the value of up to constant. Given subspaces we moreover have iff .

### 3.2. Algebraic Geometry

In this section we summarise some basic notions of algebraic geometry that will be used in the rest of the paper.

Let be a field. An affine variety is the set of common zeros of a finite collection of polynomials, i.e., a set of the form

 X={x∈Kn:p1(x)=p2(x)=⋯=pℓ(x)=0},

where . Given a polynomial ideal , by Hilbert’s basis theorem the set

 V(I)={x∈Kn:∀p∈I,p(x)=0}

is a variety, called the variety of . The two main varieties of interest to us are , which we identify with affine space in the natural way, and , which we identify with the variety

 {(A,y)∈Kn2+1:det(A)⋅y=1}.

Given an affine variety , the Zariski topology on has as closed sets the subvarieties of , i.e., those sets that are themselves affine varieties in . For example, is a Zariski closed subset of , since for we have iff all minors of vanish. Given an arbitrary set , we write for its closure in the Zariski topology on .

It is straightforward that if is a complex variety then is a real variety. It follows that the Zariski topology on coincides with the subspace topology induced on by the Zariski topology . In particular, we can compute the Zariski closure of a set of matrices by first computing the Zariski closure of in the complex variety and then intersecting with .

A set is irreducible if for all closed subsets such that we have either or . It is well known that the Zariski topology on a variety is Noetherian. In particular, any closed subset of can be written as a finite union of irreducible components, where an irreducible component of is a maximal irreducible closed subset of .

The class of constructible subsets of a variety is obtained by taking all Boolean combinations (including complementation) of Zariski closed subsets. Suppose that the underlying field is algebraically closed. Since the first-order theory of algebraically closed fields admits quantifier elimination, the constructible subsets of are exactly the subsets of that are first-order definable over .

Suppose that and are affine varieties. A function is called a regular map if it arises as the restriction of a polynomial map . Chevalley’s Theorem states that if algebraically closed and is a regular map then the image of a constructible set under is a constructible subset of . This result also follows from the fact that the theory of algebraically closed fields admits quantifier elimination.

A regular map of interest to us is matrix multiplication . In particular, we have that for constructible sets of matrices the set of products

 A⋅B:={ab:a∈A,b∈B}

is again constructible. Notice also that matrix inversion is a regular map . Thus if is a constructible set then so is . Finally, the projection yields an injective regular map . Via this map we can identify with a constructible subset of .

On several occasions we will use the facts that regular maps are continuous with respect to the Zariski topology and that the image of an irreducible set under a regular map is again irreducible. In particular, we have:

###### Lemma 1 ().

If are irreducible closed sets then is also irreducible.

### 3.3. Algorithmic Manipulation of Constructible Sets

In this subsection we briefly recall some algorithmic constructions on constructible subsets of a variety. Here, and in the rest of the paper unless noted otherwise, we assume that the underlying field is and that all ideals are generated by polynomials with algebraic coefficients.

Representing Constructible Sets. Consider a variety and let be the ideal of polynomials that vanish on . We represent Zariski closed subsets of as zero sets of ideals in the coordinate ring of . The coordinate ring of is just while the coordinate ring of is

 C[x1,1,…,xn,n,y]/(det(xi,j)y−1).

Unions and intersections of Zariski closed subsets of respectively correspond to products and sums of the corresponding ideals in . We furthermore represent constructible subsets of as Boolean expressions over Zariski closed subsets.

Irreducible Components. Let denote a Zariski closed set that is given as the variety of an . If is an irredundant decomposition of into primary ideals, then is a decomposition of into irreducible components. One can compute the primary decomposition of an ideal using Gröbner basis techniques (Becker and Weispfenning, 1993, Chapter 8).

Zariski Closure. At several points in our development, we will need to compute the Zariski closure of a constructible subset of a variety. Now an arbitrary constructible subset of a variety can be written as a union of differences of closed subsets of . Thus it suffices to be able to compute the closure of for closed sets . Furthermore, by first computing a decomposition of as a union of irreducible closed sets, we may also assume that is irreducible. But ; thus by irreducibility of we have if and otherwise . An algorithm (when using the representation above) for computing the Zariski closure of a constructible set, essentially following this recipe, is given in (Koiran, 2000, Theorem 1).

Images under Regular Maps. One can use an algorithm for quantifier elimination for the theory of algebraically closed fields in order to compute the image of a constructible set under a regular map. An explicit algorithm for this task, using Gröbner bases, is given in (Schauenburg, 2007, Sec. 4).

Real Zariski Closure. Given a complex variety , the intersection , which is a real variety, can be computed effectively. Indeed if is represented by the ideal then is represented by the ideal generated by where and respectively denote the real and imaginary parts of the polynomial . It is also straightforward to verify that for a set , we have .

## 4. Algebraic Invariants for Affine Programs

An affine function is a function of the form , where and . We write for the set of affine functions on .

An affine program of dimension is a tuple , where is a finite set of program locations, is a finite set of edges, and is the initial location.

The collecting semantics of an affine program assigns to each location the set of all those vectors that occur at location  in some execution of the program. The family can be characterised as the least solution of the following system of inclusions (see (Müller-Olm and Seidl, 2004a)):

 Xqinit ⊇ {0} Xq ⊇ f(Xp)for all (p,f,q)∈E.

Given we say that the polynomial relation holds at a program location if vanishes on . We are interested in the problem of computing for each location a finite set of polynomials that generate the ideal of all polynomial relations holding at location . The variety corresponding to ideal is , i.e., is the Zariski closure of regarded as a subset of real affine space. Thus the problem of computing the family of ideals is equivalent to the problem of computing the (family of ideals representing the) Zariski closure of the collecting semantics.

The indexed collection of varieties defines an invariant in that for every edge we have . This follows from the facts that and that is Zariski continuous. By construction we have that is the smallest algebraic invariant of the program such that .

In the remainder of this section we reduce the problem of computing the Zariski closure of the collecting semantics of an affine program to that of computing the Zariski closure of a related semigroup of matrices. The idea of this reduction is first to replace each affine assignment by a corresponding linear assignment by adding an extra dimension to the program. One then simulates a general affine program by a program with a single location.

Consider an affine program , where the set of locations is and . For each edge we define a square matrix comprising an array of blocks, with each block a matrix in . If the affine map is given by then the -th block of is

 (Ab01),

while all other blocks are zero. Notice that for we have

 (1) (Ab01)(x1)=(Ax+b1)=(f(x)1).

Given , define the projection by and define the injection by

 ini(x)=(0,…,(x,1),…,0)∈Cm(n+1),

where occurs in the -th block. We denote by .

###### Proposition 1 ().

Let be the semigroup generated by the set of matrices . Then for we have

 Sqi={x∈Qn:ini(x)∈{Mvinit:M∈M}}.
###### Proof.

For an edge of the affine program we have

 M(e)ini(x)=inj(f(x))

and

 M(e)ink(x)=0

for . Now consider a sequence of edges

 e1=(qi1,f1,qj1),(qi2,f2,qj2),…,eℓ=(qiℓ,fℓ,qjℓ).

If this sequence is a legitimate execution of , i.e., and for , then we have

 M(eℓ)⋯M(e1)vinit=injℓ(fℓ(…f1(0)…)).

If the sequence is not a legitimate execution of then we have

 M(eℓ)⋯M(e1)vinit=0.

From the above it follows that for all ,

 Sqi={x∈Qn:ini(x)∈{Mvinit:M∈M}}.

###### Theorem 2 ().

Given an affine program we can compute —the real Zariski closure of the collecting semantics.

###### Proof.

From Proposition 1 we have

 Sqi = {x∈Qn:ini(x)∈{Mvinit:M∈M}} = {x∈Qn:(x,1)∈Πi({Mvinit:M∈M})}.

By Theorem 9 we can compute the complex Zariski closure of the matrix semigroup . Since the projection and the map are both Zariski continuous, we have that

 Sqi ⊆ {x∈Cn:(x,1)∈Πi({Mvinit:M∈¯¯¯¯¯¯¯M})} ⊆ ¯¯¯¯¯¯¯Sqi.

Thus we can compute as the complex Zariski closure of

 {x∈Cn:(x,1)∈Πi({Mvinit:M∈¯¯¯¯¯¯¯M})},

since the latter is a constructible set.

Finally we can compute —the real Zariski closure of —by intersecting the complex Zariski closure with . As noted in Sec. 3.3, the intersection with is effective.

## 5. Zariski Closure of a Subgroup of GLn(C)

In this section we show how to compute the Zariski closure of the subgroup of generated by a given constructible subset of . We show this by reduction to the problem of computing the Zariski closure of a finitely generated subgroup of . An algorithm for the latter problem was given by Derksen, Jeandel, and Koiran (Derksen et al., 2005).

Recall that for we use to denote the sub-semigroup of generated by . But we have:

###### Lemma 1 ((Derksen et al., 2005)).

A closed subsemigroup of is a subgroup.

In particular, if then is a subgroup of .

Our aim is to generalise the following result.

###### Theorem 2 ((Derksen et al., 2005)).

Given matrices with algebraic entries, we can compute the closed subgroup .

The first generalisation is as follows.

###### Corollary 3 ().

Let and let be an irreducible variety containing the identity . Assume that have algebraic entries and that is presented as the zero set of a finite collection of polynomials with algebraic coefficients. We then have that is computable from and the .

###### Proof.

Let and let be the smallest Zariski closed subgroup of that contains and is closed under conjugation by (i.e., such that for ). We claim that .

To prove the claim, note that since is closed under conjugation by then is also closed under conjugation by any . Moreover, since the map is Zariski continuous for each fixed , we have that is closed under conjugation by any . It follows that is a sub-semigroup of and so is a group by Lemma 1. But

 {a1,…,ak}∪Y⊆G⋅H⊆¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯⟨a1,…,ak,Y⟩

and hence .

It remains to show that we can compute . Now we can compute by Theorem 2. To compute we use the following algorithm:

algocf[htbp]

We show that Algorithm LABEL:alg:reduce computes thesmallest subgroup of that is Zariski closed, contains , and is closed under conjugation by . To this end, notice that since contains the identity the successive values taken by in the algorithm form an increasing chain of sub-varieties of . Moreover by Lemma 1 this chain is in fact an increasing chain of irreducible sub-varieties. But such a chain has bounded length since has finite dimension and hence the algorithm must terminate.

We know that on termination. Moreover, from the loop termination condition, it clear that on termination must beclosed under conjugation by , and be a Zariski closed sub-semigroup of (and hence a sub-group of by Lemma 1). Finally, by construction, is the smallest such subgroup of . This concludes the proof. ∎

We can now prove the main result of this section.

###### Theorem 4 ().

Given a constructible subset of , we can compute .

###### Proof.

Let be the irreducible components of , which are computable from . For each , compute a point with algebraic entries (using, e.g., the procedure of (Basu et al., 2006, Chapter 12.6)). Form which is an irreducible variety containing the identity and let which by Lemma 1 is also an irreducible variety containing the identity. We then have that . Indeed, clearly and thus

 ¯¯¯¯¯¯¯¯⟨A⟩ =¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯⟨a1,…,ak,Y1⋅Y2⋯Yk⟩ =¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯⟨a1,…,ak,¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯Y1⋅Y2⋯Yk⟩.

We can compute the closure of thanks to Corollary 3. ∎

## 6. Zariski Closure of a Finitely Generated Matrix Semigroup

In this section we give a procedure to compute the Zariski closure of a finitely generated matrix semigroup. We proceed by induction on the rank of the generators. To this end, it is useful to generalise from finite sets of generators to constructible sets of generators. In particular, we will use Theorem 4 on the computability of the Zariski closure of the group generated by a constructible set of matrices.

We first introduce a graph structure on the set of generators that allows us to reason about all products of generators that have a given rank.

### 6.1. A Generating Graph

Given integers and , let be a set of matrices of rank . We define a labelled directed graph as follows:

• There is a vertex for each pair of subspaces such that , , and .

• There is a labelled edge for each pair of vertices and , and each matrix such that and .

We note in passing that can be seen as an edge-induced subgraph of the Karoubi envelope (Steinberg, 2016) of the semigroup .

A path in is a non-empty sequence of consecutive edges

 (U0,V0)a1−→(U1,V1)a2−→(U2,V2)a3−→…am−→(Um,Vm).

The length of such a path is and its label is the product . Matrix has rank since for . It is moreover clear that is precisely the set of labels over all paths in . We will denote that there is a path from to with label by writing .

The following sequence of propositions concerns the structure of the SCCs in . The respective proofs make repeated use of the fact that for each vertex of we have and that (cf. Sec. 3). We say that an SCC of is non-trivial if it contains a vertex such that there is a path from back to itself. Figure 1 summarises the structural results on .

###### Proposition 1 ().

has at most non-trivial SCCs.

###### Proof.

Let be an arbitrary finite set of vertices drawn from distinct non-trivial SCCs of . To prove the proposition it suffices to show that .

Assume that the vertices are given according to a topological ordering of SCCs—so that there is no path from back to for . By assumption, for there exists a path .

On the one hand, for all , we have (equivalently, )—for otherwise there would be path

 (Uj,Vj)\xRightarrowaj(Ui,Vj)\xRightarrowai(Ui,Vi),

contrary to the topological ordering. On the other hand we have that (equivalently, ) for all by definition of . It follows that

 ι(Uj)∉span{ι(Ui):i=1,…,j−1}

for all . Indeed, by the claim, any element in this span satisfies by bilinearity of the wedge product. We conclude that

 dimspan{ι(Ui)∈Λr(Cn):i=1,…,j}=j

for all and hence , as we wished to prove. ∎

###### Proposition 2 ().

If there is a path from and in , then there is a path from to of length at most .

###### Proof.

Let

 (2) (U0,V0)a1−→(U1,V1)a2−→…am−→(Um,Vm)

be a shortest path from to . By construction we have that for . Furthermore we have for all , for otherwise we would have a shortcut

 (Ui−1,Vi−1)ai−→(Uj,Vi)aj+1−−→(Uj+1,Vj+1),

contradicting the minimality of (2). But then for : indeed any element in this span satisfies by bilinearity of the wedge product, but we know that . We conclude that

 dimspan{ι(Vi)∈Λr(Cn):i∈{1,…,j}}=j

for all . It follows that . ∎

###### Proposition 3 ().

Given any path in , where , some vertex lies in a non-trivial SCC.

###### Proof.

The set of vectors is linearly dependent since . Thus there must exist such that . Now by definition of we have and hence . Thus by bilinearity of the wedge product there must exist such that , that is, . But then we have a path

 (Ui−1,Vi−1)ai−→(U