A Horn clause is a clause, meaning a disjunction of literals, that contains at most one positive literal. Written as an implication, it reads as a single conclusion that follows from a conjunction of conditions, such as “grandparent(X, Z) if parent(X, Y) and parent(Y, Z)”. Within Symbolic AI & reasoning, a branch of artificial intelligence, Horn clauses are the standard rule format of logic programming, deductive databases and many rule-based expert systems.
The restriction looks small, but it changes the computational picture decisively. Satisfiability of propositional Horn formulas is decidable in linear time, whereas general propositional satisfiability is NP-complete. This balance between expressiveness and tractability explains why Horn clauses underpin Prolog, Datalog and much of practical automated reasoning. The form is named after the logician Alfred Horn, who described its algebraic properties in 1951.
Structure and types of Horn clauses
Every Horn clause belongs to one of three types, determined by whether it has a positive literal (the head) and whether it has negative literals (the body). In implication form, the head is the conclusion and the body is the list of conditions joined by conjunction. The table below shows the three types in clausal notation and in Prolog-style notation.
| Type | Clausal form | Prolog notation | Meaning |
|---|---|---|---|
| Definite clause (rule) | ¬p ∨ ¬q ∨ r | r :- p, q. | r holds if p and q hold |
| Fact (unit clause) | r | r. | r holds unconditionally |
| Goal clause (query) | ¬p ∨ ¬q | ?- p, q. | Ask whether p and q can both hold |
Rules and facts together are called definite clauses, because each has exactly one positive literal. A goal clause has none; in refutation-based proving, a query is posed by adding its negation as a goal clause and searching for a contradiction. In first-order logic, the literals may contain variables, constants and function symbols, and all variables are implicitly universally quantified.
Why Horn clauses enable efficient inference
The single-head restriction guarantees that a set of definite clauses has a unique least Herbrand model, the smallest set of ground facts that satisfies every clause. That model is exactly the set of facts derivable from the program, which gives Horn programs a clean declarative semantics with no ambiguity about what follows.
Two classic inference strategies exploit this property. Forward chaining starts from the facts and repeatedly fires rules whose bodies are satisfied, adding their heads until nothing new appears. Backward chaining starts from the goal and works toward facts, replacing each subgoal with the body of a matching rule. Both procedures are sound and complete for Horn clause entailment, and the propositional versions run in linear time using the Dowling–Gallier algorithm or unit propagation.
In the first-order setting, the corresponding procedure is SLD resolution (selective linear definite clause resolution), which combines resolution with unification of terms. SLD resolution is refutation-complete for definite programs, although the depth-first search order used by Prolog may still fail to terminate on left-recursive rules.
The following table contrasts inference over Horn clauses with inference over unrestricted clause sets, which shows where the practical advantage comes from.
| Property | Horn clauses | General clauses |
|---|---|---|
| Propositional satisfiability | Linear time | NP-complete |
| Model structure | Unique least model | Many minimal models possible |
| Main proof method | SLD resolution, chaining | Full resolution, DPLL, CDCL |
| Disjunctive conclusions | Not expressible | Expressible |
| Typical systems | Prolog, Datalog, rule engines | SAT solvers, theorem provers |
Horn clauses in logic programming and databases
Prolog is the best-known language built on Horn clauses: a program is a list of definite clauses, and execution is SLD resolution with a fixed, top-down, left-to-right search. Datalog restricts Horn clauses further by forbidding function symbols, which guarantees finite models and termination and makes it suitable for deductive databases, static program analysis and access-control policies.
Several neighboring formalisms extend or restrict the Horn fragment in different directions. The table summarizes how each relates to plain definite clauses.
| Formalism | Relation to Horn clauses | Typical use |
|---|---|---|
| Prolog | Definite clauses plus negation as failure and cut | General logic programming |
| Datalog | Function-free Horn clauses | Deductive databases, program analysis |
| Answer set programming | Adds default negation and disjunction | Combinatorial search and planning |
| Constrained Horn clauses | Horn clauses over background theories | Software verification with SMT |
| Description logic EL | Close to Horn expressiveness | Large ontologies in medicine |
Rule engines in expert systems often encode knowledge as production rules that behave like definite clauses, and the Rete algorithm accelerates their forward chaining. Constrained Horn clauses have become a common intermediate language in program verification, where tools translate loops and procedures into Horn constraints and an SMT-based solver searches for inductive invariants.
Limits of the Horn fragment
The efficiency of Horn clauses comes at a cost in expressive power. Some knowledge cannot be written as a set of Horn clauses at all, and practitioners must recognize these cases early instead of forcing a model into an unsuitable form.
- Disjunctive facts such as “the package is in Prague or in Brno” cannot be stated, because a Horn clause allows only one positive conclusion.
- Classical negation in the head is not available; Prolog substitutes negation as failure, which relies on the closed-world assumption and is non-monotonic.
- Existential conclusions such as “every person has some parent” require function symbols or extensions such as existential rules.
- Termination is not guaranteed in full first-order Horn logic, since function symbols allow infinite derivations.
Common practical mistakes follow from these limits. The table lists frequent symptoms, their causes and the usual remedies.
| Symptom | Cause | Remedy |
|---|---|---|
| Query never terminates | Left-recursive rule under depth-first search | Reorder goals or use tabling |
| Missing conclusions | Knowledge is inherently disjunctive | Move to answer set programming or SAT |
| Unexpected negative answers | Negation as failure on incomplete data | Make the closed-world assumption explicit |
| Exploding derivations | Unrestricted function symbols | Restrict to Datalog or add depth bounds |
Choosing Horn clauses for a reasoning task
Horn clauses are the right choice when knowledge naturally takes the form of if-then rules with a single conclusion and when predictable, scalable inference matters more than maximal expressiveness. Typical examples include eligibility rules, taxonomy inheritance, graph reachability and dependency resolution.
When the domain requires reasoning by cases, explicit negation or the search for one of many possible configurations, a more expressive formalism is usually better, such as full first-order theorem proving, answer set programming or a SAT solver. A frequent hybrid design keeps the Horn core for fast deduction and delegates the rare disjunctive parts to a specialized solver.
A non-technical view
A Horn clause is a rule with one conclusion. It says that if certain things are true, then one specific thing is also true. “If it rains and you are outside, then you get wet” has this shape.
Because every rule points to just one result, a computer can follow the rules step by step. It never has to guess between options. That makes reasoning fast and reliable. The price is that some ideas do not fit. A rule cannot say “then either this or that is true”.
A concrete example
A university registrar encodes graduation requirements as a small Datalog program. Facts record which courses each student has passed, and rules state conditions such as “a student meets the math requirement if the student passed Calculus I and passed Linear Algebra”. A final rule concludes that a student is eligible to graduate if every requirement holds.
Each night, a forward-chaining engine loads about 40,000 course records and roughly 300 rules, derives every eligibility fact and finishes in a few seconds. Because every rule is a Horn clause, the result is deterministic and fully explainable: an advisor can trace exactly which facts produced each conclusion. When the faculty later added a requirement that allowed “either a thesis or two seminars”, the team expressed it as two separate rules with the same head, which keeps the program within the Horn fragment.