DLQ Quantified Datalog
A deductive database language: Datalog with quantifier expressions that read “does not exist” or “does not exist yet”, a counter type that numbers derived facts, and aggregates. It runs in your browser.
Minimal paths, step by step
A path is extended only while no shorter one is known yet; the result keeps the paths no shorter one exists for at all.
declare node(point string) ext; arc(beg string, end_ string, len int) ext; path(num counter, old_ int, beg string, end_ string, len int); minpath(num int, old_ int, beg string, end_ string, len int); rules path(CNT, 0, P, P, 0) :- node(P); path(CNT, OLD, A, B, LAX + LXB) :- path(OLD, _, A, X, LAX), arc(X, B, LXB), ~{ path(_, _, A, X, L1), lt(L1, LAX) }, ~{ path(_, _, A, B, L2), lt(L2, LAX + LXB) }; minpath(N, OLD, A, B, LEN) :- path(N, OLD, A, B, LEN), ~[ path(_, _, A, B, L1), lt(L1, LEN) ];
Open it in the IDE — the program is the first example there, with a graph of each fact's derivation.
The language
[ … ] and ~[ … ]
Full attributives: “exists” and “does not exist” in the complete model of the lower strata.
{ … } and ~{ … }
Partial attributives: “already exists” and “does not exist yet” among the facts derived before the current step.
counter
A system type that numbers each derived fact, so alternatives that look alike stay distinct.
Aggregates
count, sum, min, max, avg in rule heads, grouped by the other columns.
Restrictions and goals
Integrity constraints with messages, and a goal that computes only what it depends on.
Weak constraints new
penalty(weight, level) :- body; gives a model a cost for each way the body holds;
model search keeps the cheapest models, the higher level first.
Data
Facts from CSV files or SQLite databases; results as an SQL script or CSV.
Two evaluation modes
Step-wise evaluation
Semi-naive bottom-up evaluation to a fixpoint: each step sees the facts of the steps before it, and every combination of facts is used once — the minimality principle that keeps counters finite.
Model search new
Every order of deriving facts one at a time. It also runs programs that negate themselves inside a recursive cycle, which step-wise evaluation must reject; for programs without counters the models it finds are the answer sets (stable models) of answer set programming, as DLV finds them.
The IDE draws the program as graphs — predicate dependencies, relations and rules, argument and variable dependencies — and explains how each fact was derived. It plays a result as a picture: the rings of the Towers of Hanoi moving, a map coloured, shortest paths found step by step, or the model search itself, every choice, dead end and model in turn; and it records the picture as a video.
Background
- 2004
- DLQ was defined in the PhD dissertation Methods and means for deductive databases organization (Kharkiv National University of Radioelectronics). Its system, written in Delphi, translated DLQ programs into SQL and ran them on a relational database: InterBase, Oracle or MS SQL Server.
- 2026
- A new implementation, written from scratch in Rust: the same language, no longer tied to a database, compiled to WebAssembly so that it runs in the browser. What it adds to the language of 2004 is listed under New since 2004. Its source code is on GitHub.
New since 2004
The dissertation defined the language and its step-wise evaluation; they stay as they were. Everything added since then is listed here, the newest first.
2026
- DLQ in Lean. The semantics of the dissertation written down in Lean 4, so that a computer checks its definitions and proofs, the dissertation's propositions and theorems one by one; and of model search, proved to find exactly the stable models, the cheapest ones under weak constraints; see DLQ in Lean.
- Weak constraints, as in DLV: a
weaksection ofpenalty(weight, level) :- body;items. Each distinct way a body holds adds its weight to the model's cost at its level, and model search keeps only the cheapest models, comparing the higher levels first. The dissertation's way remains: alternatives kept apart inside one model by the counter and compared by aggregates. - A standalone engine. Written from scratch in Rust: it evaluates programs itself instead of translating them into SQL for a database server, and it runs in the browser.
- Model search, a second evaluation mode. It tries every order of deriving
facts, so it also runs programs that negate themselves inside a recursive cycle, which the 2004
system had to reject. For programs without counters its models are the answer sets (stable
models); a stable variant also requires every
~{ … }to hold at the end. - The search as a film. The engine records the order a search goes in: each choice, each state explored before, each dead end and each model. The IDE plays it beside the tree of the search.
- The IDE. The program graphs of the dissertation's chapter 3 drawn for any program; the derivation of each fact; pictures of the results, played as animations and recorded as video.
- Data files. Facts read from CSV files and SQLite databases; results written as an SQL script or as CSV.
- Examples. Planning by step-wise evaluation (the Towers of Hanoi, the blocks world) and examples of the DLV User Manual.
Every change is in the history of the source code.
DLQ in Lean 
The semantics of the 2004 dissertation is written down in Lean 4 with Mathlib, so that a computer checks every definition and every proof: every proposition, corollary and theorem of its section 2, one by one. Then come the additions listed under New since 2004, starting with model search and weak constraints.
| Dissertation | Statement | In Lean |
|---|---|---|
| §2.1 | Composing substitutions is applying them one after the other: t(θσ) = (tθ)σ | Term.subst_compproved |
| §2.1 | The example of substitution: ¬p(a, X, Y, b){X/c, Y/X} = ¬p(a, c, X, b) | exampleproved |
| §2.2 | Safety conditions 1 and 2, decided for any program | Program.safedefined |
| §2.2 | Herbrand interpretations; the truth of facts and rules; models | IsModeldefined |
| §2.2 | TS is monotone on the lattice of subsets of HB | Program.T_monoproved |
| §2.2 | M(S) = lfp(TS) is the least model: the intersection of all models | Program.M_eq_sInterproved |
| §2.2 | Derivation is sound and complete: S ⊢ G ⟺ S ⊨ G | Program.derives_iff_entailsproved |
| §2.2 | The example: {p(a), q(a)} is the minimal model of p(a). q(X) :- p(X). | I₁_minimalproved |
| §2.2 | Stratified Datalog¬: M¬(S), built stratum by stratum, is a model | Program.Mneg_modelproved |
| §2.2 | A negation is decided once: the strata below a rule settle it for good | Program.negation_settledproved |
| §2.2 | M¬(S) = Mn; a program without negation is one stratum, and M¬(S) = M(S) | Program.Mneg_eq_Mstratproved |
| §2.2 | Strata also need the positive condition the dissertation takes from [16]: without it, no model | rqp_not_modelproved |
| §2.3.1 | Attributives [..], ~[..], nested; the truth of a rule with attributives |
Item.satdefined |
| §2.3.1 | The reduction T-α of the example output(N, X) is exactly the four rules of the dissertation |
output_reduceproved |
| §2.3.1 | Proposition 2.1: a rule with attributives is true iff the rules T-α makes of it are true | ProgramA.isModel_iff_reduceproved |
| §2.3.1 | Corollary 2.1: MI(S) = M¬(T-α(S)) is a model of S with its attributives | ProgramA.reduce_Mneg_modelproved |
| §2.3.2 | Partial attributives {..}, ~{..}: the steps ℑi of T*S, read “already exists”, “does not exist yet” |
ProgramA.stepsdefined |
| §2.3.2 | Proposition 2.2: the steps stay in Pred(S) × Const(S)maxarity, so they converge | ProgramA.MII_convergesproved |
| §2.3.2 | Proposition 2.2: complete — nothing more follows from MII(S); consistent — partial attributives only hold inference back | ProgramA.MII_model, MII_sub_Mproved |
| §2.3.2 | Corollary 2.2: stratum by stratum, each stratum converges and is closed under its rules | ProgramA.MIIs_convergesproved |
| §2.3.2 | “Not yet” is not “not”: b :- a, ~{c}. c :- a. gives {a, b, c}, where ~[c] leaves out b |
abc_MIIproved |
| §2.4.1 | Types string, integer, real, date; consistency is an order, and not commutative | Ty.not_commproved |
| §2.4.1 | Safety condition 4: a well-typed program derives only facts that fit their schemas | Program.M_conformsproved |
| §2.4.1–2.4.2 | Built-in predicates, function terms; safety conditions 5–7; recursive argument positions | FProgram.safe7defined |
| §2.4.2 | Theorem 2.1: without function terms at recursive argument positions of heads, the model is finite | FProgram.finite_modelproved |
| §2.4.2 | …and the condition is needed: nat(succ(X)) :- nat(X). derives infinitely many facts |
nat_infiniteproved |
| §2.4.3 | The counter: a counted fact is its derivation, numbered by the machine; the minimality principle makes each derivation once | CProgram.CHoldsdefined |
| §2.4.3, §3.3.2 | Theorem 2.2: a program without counting-recursive predicates has a finite model | CProgram.finite_modelproved |
| §3.3.2 | Without the minimality principle no convergence: naive evaluation numbers old derivations anew at every step | CProgram.naive_divergesproved |
| §2.4.3 | The example r(N, X) :- p(X).: a finite model of numbered facts, and naive evaluation never stops |
rp_finite, rp_naive_divergesproved |
| New | Model search: the models it finds are exactly the finite stable models (answer sets) of the program | Program.searchModel_iff_stableproved |
| New | Restrictions: with them, exactly the stable models they accept | searchModel_iff_stable_restrictedproved |
| New | p :- not q. q :- not p. has the models {p} and {q}; p :- not p. has none |
choosePQ_models, liar_no_modelproved |
| New | Weak constraints: costs compare from the highest level, a missing level counting as 0 — a linear order | Cost.lt_iffproved |
| New | The search keeps exactly the stable models of least cost: the optimal answer sets | mem_keepCheapest_modelsproved |
| Reference | An evaluator in Lean, proved to compute the stratified model and exactly the stable models | Ref.stratExec_spec, stableExec_specproved |
| Engine | Random programs through the engine and the reference, models compared fact by fact on every change; it found two bugs in model search, both fixed | difftest.mjstested |
What “checked” means, on the dissertation’s own example:
-- §2.1: L = ¬p(a, X, Y, b), θ = {X/c, Y/X}, Lθ = ¬p(a, c, X, b) example : (Literal.neg ⟨"p", [.const "a", .var "X", .var "Y", .const "b"]⟩).subst [("X", .const "c"), ("Y", .var "X")] = .neg ⟨"p", [.const "a", .const "c", .var "X", .const "b"]⟩ := by decide -- and for every substitution and term: t(θσ) = (tθ)σ theorem Term.subst_comp (θ σ : Subst) (t : Term) : t.subst (θ.comp σ) = (t.subst θ).subst σ
Learn Lean with DLQ. Each stage comes with exercises: statements left for the reader to prove, in lean/DLQ/Exercises. The lean folder says how to set up Lean; Theorem Proving in Lean 4 and the Natural Number Game teach the language.
The proofs check the language as the definitions in Lean state it. The engine itself is tested against them: a reference evaluator, proved correct in Lean, and the engine run the same random programs, and their models are compared on every change.
Contact
Questions, ideas or programs you would like to run: write to dlq (at) dlq-lang.org.