In Prolog, both facts and rules are used to define knowledge and relationships within a program. However, they have different structures and serve distinct purposes:
Fact :* A fact in Prolog is a simple statement that represents a piece of knowledge or a true proposition about the world.
* It consists of a predicate followed by a comma-separated list of arguments enclosed in parentheses.
* Facts are used to represent ground truths, static information, or base cases.
* Facts are considered to be true by default and do not have any associated conditions or body.
* Examples of facts :
likes(john, pizza).
parent(john, sarah).
color(red).​
Rule :* A rule in Prolog is a logical statement that defines a relationship or a condition.
* It consists of a head and a body, separated by an implication symbol (:-).
* The head of a rule represents a predicate or a goal that is to be proven or satisfied.
* The body of a rule consists of one or more goals or subgoals, which define the conditions or constraints for the head to be true.
* Rules are used to express logical relationships, implications, and inference.
* Examples of rules :
mortal(X) :- human(X).
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
even(N) :- 0 is mod(N, 2).​