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.
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 :
NOT(P1) OR NOT(P2) OR ... OR NOT(Pn) OR Q
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 DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Clausal Form in Deductive Databases
- Applications of Commercial Deductive Database Systems
- Types of Databases
- Active Databases
- Denormalization in Databases
- Indexing in Databases | Set 1
- Concepts of Distributed databases
- Primary Indexing in Databases
- Introduction to Graph Databases
- Horizontal and Vertical Scaling In Databases
- How to Store and Extract XML Documents from Databases
- Various properties of CAP Theorem
- Difference between Hierarchical and Relational data model
- Difference between Hierarchical and Network Data Model
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.