DLQ Open the IDE

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.

Try it in the browser See an example

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

Every change is in the history of the source code.

DLQ in Lean Lean build status

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.

DissertationStatementIn Lean
§2.1Composing substitutions is applying them one after the other: t(θσ) = (tθ)σ Term.subst_compproved
§2.1The example of substitution: ¬p(a, X, Y, b){X/c, Y/X} = ¬p(a, c, X, b) exampleproved
§2.2Safety conditions 1 and 2, decided for any program Program.safedefined
§2.2Herbrand interpretations; the truth of facts and rules; models IsModeldefined
§2.2TS is monotone on the lattice of subsets of HB Program.T_monoproved
§2.2M(S) = lfp(TS) is the least model: the intersection of all models Program.M_eq_sInterproved
§2.2Derivation is sound and complete: S ⊢ G ⟺ S ⊨ G Program.derives_iff_entailsproved
§2.2The example: {p(a), q(a)} is the minimal model of p(a). q(X) :- p(X). I₁_minimalproved
§2.2Stratified Datalog¬: M¬(S), built stratum by stratum, is a model Program.Mneg_modelproved
§2.2A negation is decided once: the strata below a rule settle it for good Program.negation_settledproved
§2.2M¬(S) = Mn; a program without negation is one stratum, and M¬(S) = M(S) Program.Mneg_eq_Mstratproved
§2.2Strata also need the positive condition the dissertation takes from [16]: without it, no model rqp_not_modelproved
§2.3.1Attributives [..], ~[..], nested; the truth of a rule with attributives Item.satdefined
§2.3.1The reduction T-α of the example output(N, X) is exactly the four rules of the dissertation output_reduceproved
§2.3.1Proposition 2.1: a rule with attributives is true iff the rules T-α makes of it are true ProgramA.isModel_iff_reduceproved
§2.3.1Corollary 2.1: MI(S) = M¬(T-α(S)) is a model of S with its attributives ProgramA.reduce_Mneg_modelproved
§2.3.2Partial attributives {..}, ~{..}: the steps ℑi of T*S, read “already exists”, “does not exist yet” ProgramA.stepsdefined
§2.3.2Proposition 2.2: the steps stay in Pred(S) × Const(S)maxarity, so they converge ProgramA.MII_convergesproved
§2.3.2Proposition 2.2: complete — nothing more follows from MII(S); consistent — partial attributives only hold inference back ProgramA.MII_model, MII_sub_Mproved
§2.3.2Corollary 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.1Types string, integer, real, date; consistency is an order, and not commutative Ty.not_commproved
§2.4.1Safety condition 4: a well-typed program derives only facts that fit their schemas Program.M_conformsproved
§2.4.1–2.4.2Built-in predicates, function terms; safety conditions 5–7; recursive argument positions FProgram.safe7defined
§2.4.2Theorem 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.3The 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.2Theorem 2.2: a program without counting-recursive predicates has a finite model CProgram.finite_modelproved
§3.3.2Without the minimality principle no convergence: naive evaluation numbers old derivations anew at every step CProgram.naive_divergesproved
§2.4.3The example r(N, X) :- p(X).: a finite model of numbered facts, and naive evaluation never stops rp_finite, rp_naive_divergesproved
NewModel search: the models it finds are exactly the finite stable models (answer sets) of the program Program.searchModel_iff_stableproved
NewRestrictions: with them, exactly the stable models they accept searchModel_iff_stable_restrictedproved
Newp :- not q. q :- not p. has the models {p} and {q}; p :- not p. has none choosePQ_models, liar_no_modelproved
NewWeak constraints: costs compare from the highest level, a missing level counting as 0 — a linear order Cost.lt_iffproved
NewThe search keeps exactly the stable models of least cost: the optimal answer sets mem_keepCheapest_modelsproved
ReferenceAn evaluator in Lean, proved to compute the stratified model and exactly the stable models Ref.stratExec_spec, stableExec_specproved
EngineRandom 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.

Authors

Prof. N. N. Buslik

Mykola Mykolaiovych Buslik · Буслік Микола Миколайович

Doctor of Technical Sciences, Professor of the Department of Artificial Intelligence, Kharkiv National University of Radioelectronics. Scientific supervisor of the DLQ dissertation and co-author of its publications.

Dmytro Letuchiy

Летучий Дмитро Олександрович

Author of the 2004 dissertation that defined DLQ, and of this implementation.

Publications on DLQ (in Russian)

  1. Buslik N. N., Kopylov G. V., Letuchy D. A. On an approach to optimizing the programs of a logical database. Bulletin of Kharkiv State Polytechnic University, 2000, no. 117, pp. 9–13.
  2. Buslik N. N., Letuchy D. A. Negative literals and the computational paradigm of Datalog. Problems of Bionics, 2001, issue 55, pp. 3–8.
  3. Buslik N. N., Letuchy D. A. On an extension of the computational paradigm of Datalog. 5th International Youth Forum “Radioelectronics and Youth in the 21st Century”, Kharkiv, 2001, part 1, pp. 432–433.
  4. Buslik N. N., Letuchy D. A. Organizing an object-oriented predictive parser. Problems of Bionics, 2002, issue 56, pp. 21–25.
  5. Letuchy D. A., Kuzmenok A. E. The architecture of deductive database management systems. 6th International Youth Forum “Radioelectronics and Youth in the 21st Century”, Kharkiv, 2002, part 2, pp. 444–445.
  6. Buslik N. N., Letuchy D. A., Kopylov G. V. On current trends in the development of data processing languages. 8th International Conference “Theory and Technique of Information Transmission, Reception and Processing”, Kharkiv, 2002, pp. 35–37.
  7. Buslik N. N., Letuchy D. A. Deductive database technology in decision support systems. Eastern-European Journal of Enterprise Technologies, Kharkiv, 2003, no. 6, pp. 21–24.
  8. Letuchy D. A. An extended model of negation in deductive databases. Conference “Computers. Programs. Internet. 2003”, Kyiv, 2003.

Contact

Questions, ideas or programs you would like to run: write to dlq (at) dlq-lang.org.