In mathematical logic and logic programming, a Horn clause is a logical formula of a particular rule-like form which gives it useful properties for use in logic programming, formal specification, and model theory. Horn clauses are named for the logician Alfred Horn, who first pointed out their significance in 1951.
Conversely, a disjunction of literals with at most one negated literal is called a dual-Horn clause.
A Horn clause with exactly one positive literal is a definite clause; a definite clause with no negative literals is sometimes called a fact; and a Horn clause without a positive literal is sometimes called a goal clause (note that the empty clause consisting of no literals is a goal clause). These three kinds of Horn clauses are illustrated in the following propositional example:
|Disjunction form||Implication form||Read intuitively as|
|Definite clause||¬p ∨ ¬q ∨ ... ∨ ¬t ∨ u||u ← p ∧ q ∧ ... ∧ t||assume that,
if p and q and ... and t all hold, then also u holds
|Goal clause||¬p ∨ ¬q ∨ ... ∨ ¬t||false ← p ∧ q ∧ ... ∧ t||show that
p and q and ... and t all hold [note 1]
In the non-propositional case, all variables in a clause are implicitly universally quantified with scope the entire clause. Thus, for example:
- ¬ human(X) ∨ mortal(X)
- ∀X( ¬ human(X) ∨ mortal(X) )
which is logically equivalent to:
- ∀X ( human(X) → mortal(X) )
Horn clauses play a basic role in constructive logic and computational logic. They are important in automated theorem proving by first-order resolution, because the resolvent of two Horn clauses is itself a Horn clause, and the resolvent of a goal clause and a definite clause is a goal clause. These properties of Horn clauses can lead to greater efficiencies in proving a theorem (represented as the negation of a goal clause).
Propositional Horn clauses are also of interest in computational complexity. The problem of finding truth value assignments to make a conjunction of propositional Horn clauses true is a P-complete problem, solvable in linear time, and sometimes called HORNSAT. (The unrestricted Boolean satisfiability problem is an NP-complete problem however.) Satisfiability of first-order Horn clauses is undecidable.
Horn clauses are also the basis of logic programming, where it is common to write definite clauses in the form of an implication:
- (p ∧ q ∧ ... ∧ t) → u
In fact, the resolution of a goal clause with a definite clause to produce a new goal clause is the basis of the SLD resolution inference rule, used to implement logic programming in the programming language Prolog.
In logic programming a definite clause behaves as a goal-reduction procedure. For example, the Horn clause written above behaves as the procedure:
- to show u, show p and show q and ... and show t.
To emphasize this reverse use of the clause, it is often written in the reverse form:
- u ← (p ∧ q ∧ ... ∧ t)
In Prolog this is written as:
u :- p, q, ..., t.
In logic programming and datalog, computation and query evaluation are performed by representing the negation of a problem to be solved as a goal clause. For example, the problem of solving the existentially quantified conjunction of positive literals:
- ∃X (p ∧ q ∧ ... ∧ t)
is represented by negating the problem (denying that it has a solution), and representing it in the logically equivalent form of a goal clause:
- ∀X (false ← p ∧ q ∧ ... ∧ t)
In Prolog this is written as:
:- p, q, ..., t.
Solving the problem amounts to deriving a contradiction, which is represented by the empty clause (or "false"). The solution of the problem is a substitution of terms for the variables in the goal clause, which can be extracted from the proof of contradiction. Used in this way, goal clauses are similar to conjunctive queries in relational databases, and Horn clause logic is equivalent in computational power to a universal Turing machine.
The Prolog notation is actually ambiguous, and the term “goal clause” is sometimes also used ambiguously. The variables in a goal clause can be read as universally or existentially quantified, and deriving “false” can be interpreted either as deriving a contradiction or as deriving a successful solution of the problem to be solved.
Van Emden and Kowalski (1976) investigated the model theoretic properties of Horn clauses in the context of logic programming, showing that every set of definite clauses D has a unique minimal model M. An atomic formula A is logically implied by D if and only if A is true in M. It follows that a problem P represented by an existentially quantified conjunction of positive literals is logically implied by D if and only if P is true in M. The minimal model semantics of Horn clauses is the basis for the stable model semantics of logic programs.
- Like in resolution theorem proving, intuitive meanings "show φ" and "assume ¬φ" are synonymous (indirect proof); they both correspond to the same formula, viz. ¬φ. This way, a mechanical proving tool needs to maintain only one set of formulas (assumptions), rather than two sets (assumptions and (sub)goals).
- Horn, Alfred (1951). "On sentences which are true of direct unions of algebras". Journal of Symbolic Logic 16 (1): 14–21. doi:10.2307/2268661.
- Dowling, William F.; Gallier, Jean H. (1984). "Linear-time algorithms for testing the satisfiability of propositional Horn formulae". Journal of Logic Programming 1 (3): 267–284. doi:10.1016/0743-1066(84)90014-1.
- van Emden, M. H.; Kowalski, R. A. (1976). "The semantics of predicate logic as a programming language" (PDF). Journal of the ACM 23 (4): 733–742. doi:10.1145/321978.321991.