Linear Algebraic Partial Evaluation of Logic Programs

Tuan Nguyen, Katsumi Inoue, Chiaki Sakama

Abstract

This paper extends linear algebraic partial evaluation (PE) for logic programs to handle disjunctions (Or-rules) and recursive cycles. By representing logic programs as matrices and utilizing matrix decomposition techniques like Jordan Normal Form, the authors provide a framework for "pre-computing" logical inferences in vector spaces, even for complex, cyclic programs.

Introduction

In logic programming, Partial Evaluation (PE) is an optimization technique that "unfolds" rules in advance to accelerate inference. Recent advancements have leveraged linear algebra—representing logic programs as matrices and using matrix multiplication for unfolding. However, previous methods were limited to acyclic programs and struggled with "Or-rules" (disjunctions). This paper addresses these limitations, making linear algebraic PE viable for a wider range of real-world logic programs.

Methodology

The proposed framework involves several key steps to translate logic into a matrix-based environment:

Standardization and Matrix Representation

Logic programs are first transformed into a standard form consisting of distinct And-rules and Or-rules. These are then mapped to separate matrices ($M_{\Pi^\wedge}$ and $M_{\Pi^\vee}$). As shown in Figure 1, rules are converted into sparse matrices where values represent the relationship between atoms.

Matrix and vector representations of a standardized logic program

Cycle-Resolving and Iteration

To handle recursion, the authors introduce algorithms that identify Strongly Connected Components (SCCs) in the program's dependency graph. For And-rules, unsatisfiable cycles are removed; for Or-rules, cycles are "collapsed" to account for external dependencies. Figure 2 illustrates the translation of a normal logic program into these structural graphs.

Dependency graphs of a normal logic program and its standardized version

Partial evaluation is performed by repeatedly squaring the program matrix ($M, M^2, M^4...$) until a "fixed point" is reached. For a more analytical approach, the authors explore using Eigendecomposition and Jordan Normal Form (JNF) to compute any power $M^k$ instantly, though this remains computationally challenging.

Experimental Evaluation

The methods were evaluated on synthetic datasets (Artificial Samples I & II) and real-world benchmarks from Failure Modes and Effects Analysis (FMEA), including versions with manually injected random cycles (lengths 2-5).

Key Results

  • Efficiency of Sparse Iteration: The iteration method using sparse matrices (CSR format) was significantly faster than other approaches. On "Artificial Samples I," it completed in ~545ms, compared to over 7,000,000ms for the decomposition method.
  • Cycle Resolution: The proposed algorithms successfully allowed the iteration to reach a fixed point in cyclic programs that would otherwise loop infinitely.
  • Decomposition Limitations: While mathematically elegant, JNF decomposition proved numerically unstable and slow, currently limited to matrices with fewer than 100 atoms due to reliance on symbolic math libraries.

Conclusion

This research demonstrates that while matrix decomposition offers a promising theoretical "escape hatch" for complex logic, sparse iteration remains the most practical approach for current systems. Future work will focus on improving numerical stability and addressing "global" cycles that mix And and Or rules, potentially leveraging Spectral Graph Theory to reason about program properties.

Summary updated

Abstract

In logic programming, partial evaluation (PE) performs unfolding rules in advance to reduce the cost of inferencing. Recently, PE of logic programs has been implemented in vector spaces by computing the powers of matrix representations. It has been reported that linear algebraic PE substantially enhances the practical performance of linear algebraic methods for logic programming. However, most recent research has focused exclusively on And-rules, assuming that their dependency graph is acyclic. In this paper, we introduce cycle-resolving techniques to ensure that linear algebraic PE works effectively even with cycles in the program. Additionally, we demonstrate that linear algebraic PE can also be extended to accommodate Or-rules. Moreover, we propose using eigendecomposition and Jordan normal form to conduct PE in vector spaces. We compare the proposed techniques on a set of acyclic and cyclic logic programs to evaluate their effectiveness. It is shown that the iteration method for PE, especially with sparse format, is the most efficient one in general cases. However, the decomposition method has the potential for future research to leverage eigenvalues and eigenvectors of program matrices for reasoning.
BibTeX
@inproceedings{nguyen2024linear,
  author = {Tuan Nguyen and Katsumi Inoue and Chiaki Sakama},
  title = {{Linear Algebraic Partial Evaluation of Logic Programs}},
  booktitle = {NMR},
  year = {2024},
}

Loading related content...

Figure