Hostname: page-component-74656f9884-8rzl6 Total loading time: 0 Render date: 2026-11-06T01:29:08.988Z Has data issue: false hasContentIssue false

Diamonds Are Forever: Stabilization Semantics for Unrestricted Aggregation and Recursion in Logica

Published online by Cambridge University Press:  22 October 2026

EVGENY SKVORTSOV
Affiliation:
Google LLC, USA (e-mail: evgskv@google.com)
YILIN XIA
Affiliation:
University of Illinois, Urbana-Champaign, USA (e-mail: yilinx2@illinois.edu)
OJASWA GARG
Affiliation:
Google LLC, USA (e-mail: ojaswagarg@google.com)
SHAWN BOWERS
Affiliation:
Gonzaga University, USA (e-mail: bowers@gonzaga.edu)
BERTRAM LUDÄSCHER
Affiliation:
University of Illinois, Urbana-Champaign, USA (e-mail: ludaesch@illinois.edu)
Rights & Permissions [Opens in a new window]

Abstract

Logica is an open-source logic programming language that compiles to SQL and runs on platforms including DuckDB, SQLite, PostgreSQL, and BigQuery. Unlike classic Datalog, Logica permits the free combination of recursion and aggregation, enabling concise formulations of algorithms from shortest paths to PageRank. This expressiveness introduces fundamental semantic challenges: aggregate predicates are updated by replacement rather than accumulation, evaluation is sensitive to rule scheduling, and programs may converge to meaningful results without ever reaching a fixpoint, placing them outside the scope of traditional fixpoint semantics. We address these challenges with Defendant-Opponent (DO) semantics, a stabilization-based framework for nonmonotonic logic programs. Program evaluation is modeled as a rewrite system over derivation states. A ground atom is true if, from every reachable state, there exists a continuation after which the atom persists in all further derivations. This notion admits two equivalent characterizations: (1) game-theoretically, truth is what a Defendant can defend against any Opponent in a three-turn derivation game; and (2) modally, a formula $t$ is a theorem precisely when the condition $\Box \mkern 1.33mu{\LARGE \Diamond }\Box \mkern 1.33mu\,t$ holds in the derivation graph viewed as a Kripke structure. We show that DO semantics coincides with classic least fixpoint semantics for positive Datalog programs and is compatible with both the Well-Founded Semantics (the two never disagree on definite answers) and the Stable Model Semantics (every stable model is a DO interpretation). For programs that converge without reaching a fixpoint, we introduce $\omega$-limit interpretations, giving rigorous meaning to iterative computations such as PageRank. DO semantics thus offers a coherent framework that complements existing logic programming semantics while supporting recursive aggregation.

Information

Type
Original Article
Creative Commons
Creative Common License - CCCreative Common License - BYCreative Common License - ND
This is an Open Access article, distributed under the terms of the Creative Commons Attribution-NoDerivatives licence (https://creativecommons.org/licenses/by-nd/4.0/), which permits re-use, distribution, and reproduction in any medium, provided that no alterations are made and the original article is properly cited.
Copyright
© The Author(s), 2026. Published by Cambridge University Press
Figure 0

Fig. 1. The seven distinct S4 modalities (left, strongest ◻t$\Box \,t$ at bottom) with their DO-semantics interpretations (right). Here ◻$\Box$ is “necessarily” and ◊$\huge \Diamond$ is “possibly” in the standard modal reading; the right side shows what each modality means for derivations. Arrows point upward in the direction of implication: a lower (stronger) modality entails a higher (weaker) one, for example, ◻◊◻t$\Box \mkern 1.33mu{\LARGE \Diamond }\Box \mkern 1.33mu\,t$ (theorem) implies ◻◊t$\Box {\huge \Diamond }\,t$ (always derivable). Note: “axiom” means t$t$ holds at the current state; “non-removable axiom” (◻t$\Box \,t$) means t$t$ holds at every reachable state.

Figure 1

Fig. 2. Two logic programs and their derivation graphs. Monotonic program (left): derivation flows upward to the unique fixpoint {a,b,c,d}$\{a,b,c,d\}$. Nonmonotonic program (right): we$\mathtt {w_e}$ causes oscillation (red edges) between {a,b,d}$\{a,b,d\}$ and {a,b,d,e}$\{a,b,d,e\}$; {a,c,d}$\{a,c,d\}$ is a separate fixpoint. Green nodes are axioms; blue nodes are static interpretations (sink SCC nodes). Edge labels identify rewrite rules; gray self-loops indicate rules that leave the state unchanged.

Figure 2

Fig. 3. Derivation graph for the Left/Right program (L and R abbreviate Left and Right). Green: axiom; blue: sole static interpretation (fixpoint). The left branch stabilizes; the right diverges (X$X$ grows without bound). Since the blue node is unreachable from the right branch, no irreducible truth exists. Dashed gray: self-loops.

Figure 3

Fig. 4. Left: derivation graph for the program with rules wb:{b←a,¬b}$\mathtt {w_b{:}\,\{b \leftarrow a, \neg \, b\}}$ and wc:{c←b;c←c}$\mathtt {w_c{:}\, \{ c \leftarrow b; \, c \leftarrow c\}}$. Right: Ground nonmonotonic system with rules wp(a):{p(a)←¬q(a)}$\mathtt {w_{p(a)}{:}\, \{p(a) \leftarrow \neg q(a)\}}$; wp(b):{p(b)←¬q(b)}$\mathtt {w_{p(b)}{:}\, \{p(b) \leftarrow \neg q(b)\}}$; wq(a):{q(a)←¬p(a)}$\mathtt {w_{q(a)}{:}\, \{q(a) \leftarrow \neg p(a)\}}$; and wq(b):{q(b)←¬p(b)}$\mathtt {w_{q(b)}{:}\, \{ q(b) \leftarrow \neg p(b)\}}$. In both figures, green nodes represent axioms ({a}$\mathtt {\{a\}}$ and ∅$\emptyset$, respectively); blue nodes are static interpretations; dashed gray loops are rule applications that leave the state unchanged; red edges mark oscillation (caused by wb$\mathtt {w_b}$ on the left).

Supplementary material: File

Skvortsov et al. supplementary material

Skvortsov et al. supplementary material
Download Skvortsov et al. supplementary material(File)
File 186 KB