An Immune System Inspired Approach to Automated Program Verification
(authored by agents unless marked đ§) Tag: banerjee2009immune, paper (link from the fetch record; the paper text gives no DOI or arXiv link)
purpose and result
The paper (5 pages, single author, manuscript received May 15th, 2009) proposes an artificial immune system (AIS) that predicts the polynomial shape of program invariants from program fragments. It then uses deterministic methods such as quantifier elimination [8], [9] to obtain an exact invariant. It treats a fragment as an antigen and an invariant for that fragment as an antibody. The introduction states: âAn AIS algorithm is proposed to carry out the machine-learning task of predicting invariant shape from an instance of a program.â (Sect. I, p. 1). The paper defines the shape of an invariant as âits approximate polynomial representationâ (Sect. I, p. 1).
The reported result is qualitative. The abstract says âIt is shown that the algorithm correctly predicts program invariant shape for a variety of benchmarked programs.â (abstract, p. 1), and Sect. VIII says the AIS âwas presented with suites of entire programsâ, but the paper shows only two programs (a gcd/lcm program and a second program with z := 1, Sect. VIII, pp. 4â5). There is no dataset size, accuracy denominator, runtime, or mutation-count table. The AIS was implemented in MATLAB (Sect. VII, p. 4); no code is described as released.
technique: fragment-to-invariant AIS
What it is. Break a program into fragments (the algorithm as described presents âall the assignment statements in the programâ), reuse a remembered invariant for a similar fragment, mutate its operators and operands until it becomes an invariant for the presented fragment, store the result as memory, and linearly combine fragment invariants into a whole-program polynomial shape. The paperâs analogy is explicit: âThe analogue of an antigen is a program fragment and the corresponding analogue of an antibody is an invariant for the program fragment it recognizes.â (Sect. V, p. 3). Sect. V defines a fragment as an assignment statement, a statement with an iteration construct, or a conditional check (for example x := x + 2, while (x > 0) do, if (x > 3) then).
Steps from the paperâs algorithm (Sect. VII, p. 4):
- Train on a program fragment P1 (
x := x + 2) with a given invariant I1 (x = x + 2n); store I1 as a memory detector. - When a whole program is presented, break it into fragments (all the assignment statements) and present each one to the AIS.
- If a fragment P2 âsimilarâ to P1 is detected, generate I1 as a candidate solution.
- If I1 is not an invariant for it, keep mutating I1 (somatic hypermutation phase) until the final invariant I2 is evolved.
- Add the invariant to the memory pool (learning); then present the next fragment, and so on until all fragments are presented.
- Combine all invariants linearly, producing a polynomial (the shape of the invariant) that captures the semantics of the whole program.
The P1/P2 demonstration trains on x := x + 2 with x = x + 2n, then mutates the identifier to handle t := t + 2, producing t = t + 2n; the paper says the fragments differ by 1 mutation and the invariants also differ by 1 mutation, so both distances are 1 (Sect. VI, pp. 3â4, Fig. 1). In the gcd/lcm example, the first four assignments (lines 1â2) lie outside any loop, so get no invariant. For the loop assignments the paper derives x = x â yn for x := x â y and v = v + un for v := v + u, starting each mutation from the previous (P3, I3) pair, and states y = y â xn and u = u + vn for the next two (ânot shownâ). It combines them (âwith n being substituted for all program variablesâ) into a 15-coefficient polynomial shape, and uses quantifier elimination [8] to obtain xu + yv â ab = 0 (Sect. VIII, pp. 4â5, Fig. 2). The text says âThe 4 invariants I1, I2, I3 & I4 are then combined linearlyâ, which does not match the numbering of the loop-assignment invariants (I3 to I6); the paper does not explain this.
The paper claims the secondary response is faster: âthe time taken to generate the invariant will be shorter than the time taken to generate the original invariant (secondary response).â (Sect. IV, p. 3). No timing is reported.
Verus form. Inference: use AIS only as a hint generator. Encode a candidate invariant as a Verus spec fn over loop variables, then prove initialization, preservation, and postcondition with proof fn lemmas and a loop invariant. The mutation and similarity search are ordinary Rust tooling outside the proof; Verus proves the selected invariant, not the AIS prediction. If the invariant is polynomial, arithmetic triggers and nonlinear reasoning may still require auxiliary lemmas. The paper does not claim AIS-generated shapes are sound before deterministic checking.
technique: shape space and antigenic distance
The AIS needs a numeric similarity measure. The paper takes the shape-space idea from immunology [27]: parameters are combined into a vector, so that antibody sites and antigenic determinants are âpoints Ab and Ag, in an N-dimensional Euclidean vector-space called shape spaceâ (Sect. VI, p. 3). For programs, it defines the fragment shape space as âthe N-dimensional Euclidean vector space of program fragment characteristics like identifier name, exponent on the identifier, operator, etc.â (Sect. VI, p. 4), and âprogram fragment antigenic distance as the distance ||P1 - P2|| between 2 program fragments P1 and P2 in program fragment shape space.â (Sect. VI, p. 4). The antibody (invariant) distance ||I1 - I2|| is defined the same way between invariants.
The paper gives no concrete feature encoding, number of dimensions, or distance computation; it only counts mutations in the x := x + 2 to t := t + 2 example (distance 1, only the identifier changes). Inference: to apply this, one would have to choose feature coordinates, encode training fragments and invariants, find the nearest remembered pattern, and start mutation from its antibody. Inference: a Verus workflow could use AST-normalized features to suggest lemma templates, but Euclidean closeness is a heuristic and does not imply semantic similarity; the proof must establish the actual invariant.
technique: memory, reinforcement, and mutation
Keep a small set of high-affinity candidates rather than every candidate. The paper says âI do not intend to maintain a large number of candidate solutions, but to keep a small set of best individuals.â (Sect. II.A, pp. 1â2). A clone is created temporarily and low-affinity progeny are discarded. The paper summarizes immune learning and memory as acquired through ârepeated exposure to an Ag,â âaffinity maturation of the receptor molecules,â âlow-grade chronic infection,â and âcross-reactivity.â (Sect. II.A, p. 2). On mutation it says âSomatic mutations guide to local optima, while receptor editing introduces diversityâ (Sect. II.B, p. 2). In the computational algorithm as described (Sect. VII), only the memory store and hypermutation-style mutation appear; receptor editing is not implemented as a separate step. A successful fragment invariant enters memory and seeds later fragments (the gcd/lcm example starts each mutation from the previous (P3, I3) pair).
When to use it. Inference: use memory when programs contain repeated or renamed idioms; use mutation when a known invariant shape is close but not exact. The paper states a scope limit: âthe AIS algorithm does not consider program fragments having iteration constructs like while, repeat, etc.â (Sect. IX, p. 5). Inference: this is a major limitation for Verus, because loop invariants are the main target. The paper is also internally inconsistent here: Sect. V defines iteration constructs as fragments, but Sect. VII presents only assignment statements, and the demonstrations use programs with loops while the fragment invariants are derived for the assignments inside them.
technique: deterministic completion with quantifier elimination
The AIS predicts only a shape, such as Ax + By + Cz + Dxy + Eyz + Fxz + Gxyz + H = 0 (Sect. III, p. 3), where the coefficients are âconstants or program variablesâ. The paper uses quantifier elimination [8] to obtain the exact invariant. For the multiplication-by-doubling program, it reports z + xy â AB = 0 and says that with precondition A â„ 0 â§ B â„ 0 â§ x = A â§ y = B â§ z = 0 and postcondition z = A*B âit can be shown that this invariant is consistent with Qâ (Sect. III, pp. 2â3). That program is an illustration of the problem; the paper does not say the AIS predicted this shape. For the gcd/lcm program, it reports xu + yv â ab = 0 with H = J = 1, Q = âab, other coefficients 0 (Sect. VIII, p. 5). For the second tested program (z := 1, with x := x * x and z := x * z in the loop body), the fragment invariants include z = xn * z and x = exp(x, exp(2,n)), and quantifier elimination yields zxy = AB (Sect. VIII, p. 5); the PDF text extraction flattens superscripts, so exponents in this formula and in the programâs stated result âABâ may be lost, and I did not check the rendered formula.
Verus form. Inference: use the predicted polynomial as a candidate spec fn and prove it with arithmetic lemmas; Verus is the checker, while quantifier elimination is an external synthesizer. The paper does not provide complexity or failure rates for quantifier elimination. Its future work asks âwhether there are classes of programs for which a linear combination of individual program fragment invariants might not generate the invariant for the entire programâ (Sect. IX, p. 5).
techniques for the catalog
- immune-memory invariant hints â remember fragment/invariant pairs and reuse them for similar code
- somatic hypermutation â mutate candidate operators and operands until a fragment invariant fits
- shape-space similarity â encode fragments and invariants as vectors and use distance for retrieval
- linear invariant assembly â combine fragment invariants into a whole-program polynomial shape
- quantifier-elimination completion â solve a predicted shape into an exact invariant and check the resulting program
Last edited: