Horn Clauses in Deductive Databases

Horn clause is clause (a disjunction of literals) with at most one positive, i.e. unnegated, literal. A clause with at most one positive (unnegated) literal is called a Horn Clause.

Deductive Database:
A type of database which can make conclusions based on sets of well-defined rules, stored in database. RDBMS and logic programming are combined using this. Deductive database designing is done with help of pure declarative programming language known as Datalog.

Types of Horn Clauses :

  • Definite clause / Strict Horn clause –
    It has exactly one positive literal.
  • Unit clause –
    Definite clause with no negative literals.
  • Goal clause –
    Horn clause without a positive literal.

In Datalog, rules are expressed as a restricted form of clauses called Horn clauses, in which a clause can contain at most one positive literal.

A formula can have following quantifiers:

  • Universal quantifier –
    It can be understood as – “For all x, P(x) holds”, meaning P(x) is true for every object x in universe. For example, all trucks has wheels.
  • Existential quantifier –
    It can be understood as – “There exists an x such that P(x)”, meaning P(x) is true for at least one object x of universe. For example, someone cares for you.

Forms of a Horn Clause :

  1. NOT(P1) OR NOT(P2) OR ... OR NOT(Pn) OR Q
  2. NOT(P1) OR NOT(P2) OR ... OR NOT (Pn)

Transformation of Horn Clause :
The Horn clause in (1) can be transformed into clause –

P1 AND P2 AND ... AND Pn → Q 

which is written in Datalog as following rules

Q :- P1, P2, ..., Pn 

The above Datalog Rule, is hence a Horn clause.

If predicates P1 AND P2 AND … AND Pn, are all true for a particular binding to their variable arguments, then Q is also true and can hence be inferred.

The Horn clause in (2) can be transformed into –

P1 AND P2 AND ... AND Pn → 

which is written in Datalog as follows:

P1, P2, ..., Pn 

The above Datalog expression can be considered as an integrity constraint, where all predicates must be true to satisfy query.

A query in Datalog consists of two components:

  • A Datalog program, which is a finite set of rules.
  • A literal P(X1, X2, X3, … Xn), where each X is a variable or a constant.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.