DrNLA: Extending Verification to Non-linear Programs through Dual Re-writing

Yuandong Cyrus Liu, Ton-Chanh Le, Timos Antonopoulos, Eric Koskinen, ThanhVu NguyenarXiv 2023

Abstract

For many decades, advances in static verification have focused on linear integer arithmetic (LIA) programs. Many real-world programs are, however, written with non-linear integer arithmetic (NLA) expressions, such as programs that model physical events, control systems, or nonlinear activation functions in neural networks. While there are some approaches to reasoning about such NLA programs, still many verification tools fall short when trying to analyze them. To expand the scope of existing tools, we introduce a new method of converting programs with NLA expressions into semantically equivalent LIA programs via a technique we call dual rewriting. Dual rewriting discovers a linear replacement for an NLA Boolean expression, simultaneously exploring both the positive and negative side of the condition, and using a combination of static validation and dynamic generalization of counterexamples. We built a new tool DrNLA and show it can discover LIA replacements for a variety of NLA programs. We then applied our work to branching-time verification of NLA programs, showing that DrNLA's rewriting enable tools such as FuncTion and T2 to verify CTL properties of 42 programs that previously could not be verified.

The Challenge of Non-linear Verification

Static verification—the process of mathematically proving that software behaves correctly—has become highly effective for programs using Linear Integer Arithmetic (LIA). However, the real world is rarely linear. Programs modeling physical systems, control logic, or neural networks frequently use Non-linear Integer Arithmetic (NLA), such as $x^2 + y^2 < z$. Most state-of-the-art verification tools and SMT solvers struggle with NLA, often returning "unknown" or timing out. This is especially problematic for branching-time logic (CTL), which reasons about all possible future paths of a program. In CTL verification, simple over-approximations don't work because a "then" branch's over-approximation is effectively an under-approximation of the "else" branch. To verify these programs, we need precision that current tools simply cannot provide for non-linear expressions.

Dual Rewriting Framework

The authors introduce a technique called Dual Re-writing. Instead of trying to build a better non-linear solver, they transform the non-linear program into an equivalent linear one that existing tools already understand. The core of DrNLA is an integrated mix of static and dynamic analysis.

The overall refinement loop of DrNLA, integrating dynamic analysis and static validation to synthesize linear replacements.

As illustrated in the framework above, the process involves:

  1. Dual Synthesis: For a given non-linear condition $b$, the tool simultaneously synthesizes two linear expressions: $b_{pos}$ (representing when the condition is true) and $b_{neg}$ (representing when it is false). Tracking both sides helps the algorithm "box in" the truth values more effectively.
  2. Context-Sensitive Validation: A key insight is that the linear replacement doesn't have to be globally equivalent to the non-linear one—it just needs to behave the same way within the specific context of that program. DrNLA uses a program transformation to turn this equivalence check into a simple reachability problem for an SMT solver.
  3. Refinement Loop: If the initial guess is wrong, the tool uses Dynamic Generalization. It generates counterexample states and uses dynamic learning to infer a broader linear condition that fixes the error.

Geometric Intuition and Refinement

Many complex non-linear conditions in code actually boil down to simple linear intervals in practice. For example, $x^2 > 49$ is equivalent to the linear disjunction $(x > 7 \lor x < -7)$. DrNLA exploits this by trading non-linear complexity for Boolean combinations of linear constraints. By focusing on reachable states rather than mathematical identity, DrNLA can find simple linear replacements for complex polynomials.

Geometric representation of the four counterexample cases (Expand/Trim for Pos/Neg) used to refine the linear candidates.

Synthesizing $b_{pos}$ and $b_{neg}$ together allows the tool to use counterexamples from one side to refine the other. The refinement process handles four distinct cases: ExpandPos, ExpandNeg, TrimPos, and TrimNeg. These cases ensure that the synthesized linear regions correctly cover the truth values of the original non-linear expression within the program's state space.

Key Results and Impact

The authors evaluated DrNLA on a new suite of 92 benchmarks, including programs adapted from NLA termination research and handcrafted high-degree non-linear challenges.

  • High Success Rate: DrNLA successfully synthesized correct LIA replacements for 86 out of 92 benchmarks.
  • Enabling New Verification: Using DrNLA as a pre-processor allowed off-the-shelf tools (T2 and FuncTion) to verify 42 programs that they previously could not handle at all.
  • Efficiency: Most replacements were found within a few minutes. Once rewritten, the actual verification by CTL tools usually took less than a second. The execution speed of the rewritten programs remained within 4% of the original non-linear versions.

Limitations and Future Work

Currently, DrNLA focuses on non-linear expressions in branch conditions and loop guards. It does not yet handle non-linear logic inside variable assignments (e.g., x = y * z), which is a primary goal for future work. Additionally, while the refinement loop is highly effective, it is not guaranteed to terminate for all possible polynomials, currently employing a hard cap on iterations to ensure practical performance.

Summary updated

BibTeX
@misc{liu2023drnla,
  author = {Yuandong Cyrus Liu and Ton-Chanh Le and Timos Antonopoulos and Eric Koskinen and ThanhVu Nguyen},
  title = {{DrNLA: Extending Verification to Non-linear Programs through Dual Re-writing}},
  year = {2023},
  eprint = {2306.15584},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.15584},
}
Figure