Prolog Lab Guide
Prolog Lab Guide
PROLOG
Facts, Rules and Queries in Prolog
• Facts
• Facts are statements about the world that we consider to be true.
• In Prolog, facts are used to represent basic information or assertions.
• They consist of a predicate (a term representing a relationship or property)
followed by a list of arguments.
• Facts are usually defined at the beginning of a Prolog program and remain
constant throughout execution.
• Example: student(john, 20, male). Here, student is a predicate, and john, 20,
and male are arguments representing a student's name, age, and gender,
respectively.
Facts, Rules and Queries in Prolog
• Rules
• Rules define relationships or properties based on other facts or rules.
• They consist of a head (the thing being defined) and a body (the conditions
that must be true for the rule to be true).
• Rules are used to infer new information from existing facts or rules.
• They can involve logical operators like conjunction (,) and disjunction (;) to
express complex conditions.
• Example: parent(X, Y) :- father(X, Y); mother(X, Y). Here, parent(X, Y) is the
head, and father(X, Y); mother(X, Y) is the body. This rule defines parent
based on either father or mother relationships.
Facts, Rules and Queries in Prolog
• Queries
• Queries are questions posed to the Prolog system to retrieve information or
check if a certain statement is true.
• They consist of a predicate followed by variables or specific values to be
queried.
• Prolog attempts to find values for the variables that make the query true,
based on the facts and rules defined in the program.
• Queries are typically entered interactively at the Prolog interpreter prompt.
• Example: ?- student(john, Age, male). Here, student(john, Age, male) is the
query, asking for the age of the student named John who is male.
THE END