Assignment
Assignment
Prolog was invented by Alain Colmerauer, a French computer scientist, along with
his collaborator Philippe Roussel. They developed the language in the early 1970s at
the University of Marseille, France.
In Prolog, a program is essentially a set of facts and rules about relationships between
objects, and queries are posed to infer new facts based on those rules.
Key features of Prolog include:
1. Facts: Statements that are unconditionally true.
2. Rules: Conditional statements that define relationships or how facts can be derived.
3. Queries: Requests to find information or prove certain facts based on the knowledge
base.
Applications :
Prolog is highly used in artificial intelligence(AI). Prolog is also used for pattern
matching over natural language parse trees.
2. HISTORY:
The history of Prolog dates back to the late 1960s and early 1970s, when it was
developed as part of research into artificial intelligence and computational logic.
1. Expert Systems
• Knowledge Representation: Prolog is particularly well-suited for expert systems,
which require encoding knowledge about a specific domain.
• Inference Engines: The language’s inference mechanism, based on logical reasoning,
can be used to draw conclusions from a set of rules and facts. This makes Prolog a
good fit for systems that mimic the decision-making abilities of human experts.
4. Knowledge-Based Systems
• In AI, knowledge-based Prolog’s rule-based approach makes it ideal for creating
systems that manage large knowledge bases and reason over them effectively.
• Semantic Networks: Prolog can be used to represent and work with semantic
networks or ontologies, which are graphical representations of relationships between
concepts in a domain of knowledge.
7. Robotics
• Prolog used in robotic systems, particularly for tasks like pathfinding, decision-
making, and reasoning about the robot’s environment. Prolog’s ability to represent
and reason about spatial relationships, actions, and goals makes it a useful tool in
some robotics applications.
9. Game AI
• Prolog can be used to implement simple game AI, especially in logic-based games or
puzzle-solving games, where reasoning and decision-making are central. It can help
design AI.
4. SYNTAX:
1. Facts
• Facts are the most basic kind of knowledge in Prolog. They represent unconditionally
true statements.
• A fact is written as a predicate followed by its arguments.
• The predicate is usually a noun (or a descriptive name), and the arguments are the values
it relates to.
Example:
likes(john, pizza).
likes(mary, apple).
Here, likes(john, pizza) and likes(mary, apple) are facts. They mean "John likes pizza" and
2. Rules
• Rules define relationships between facts and allow Prolog to infer new facts.
• A rule has a head (a conclusion) and a body (a set of conditions that must be true for
the head to be true).
head :- body.
Example:
3. Queries
• Queries are used to ask Prolog to find facts or prove something based on the facts and
rules defined.
• Prolog will try to find solutions to the query by looking through the facts and rules.
Example:
?- likes(john, pizza).
This query asks, "Does John like pizza?" If there is a fact likes(john, pizza). in the
knowledge base, Prolog will respond with true. If not, it will return false.
4. Variables
• Variables in Prolog begin with an uppercase letter or an underscore (_). They represent
placeholders for any value.
Example:
likes(X, pizza). % This means "X likes pizza", where X can be any person.
• Prolog will try to match X with any value that satisfies the rule or fact.
5. Negation
• Prolog allows negation in queries, but negation is handled using the \+ operator.
Example:
?- \+ likes(john, pizza).
This query asks, "Does John not like pizza?" Prolog will return true if likes(john, pizza) is
false.
6. Lists
• Lists in Prolog are written with square brackets [], and elements are separated by
commas.
• A list can be an empty list [] or a non-empty list [Head | Tail], where Head is the first
element and Tail is the rest of the list.
Example:
my_list([1, 2, 3, 4]).
This rule says, "The first element of a list is the head of the list."
7. Comments
• Comments in Prolog are written with a percent sign (%). Anything after the % on the
same line is treated as a comment.
Example:
% This is a comment
likes(john, pizza). % John likes pizza
8. Arity
• For example, likes(john, pizza) has arity 2 because it takes two arguments.
Example:
Here’s a simple Prolog program that includes facts, rules, and a query:
% Facts
likes(john, pizza).
likes(mary, apple).
edible(pizza).
edible(apple).
% Rule
% Query
In this example:
• likes(john, pizza) and likes(mary, apple) are facts.
• The rule likes_food(Person, Food) checks if a person likes a food and if it is edible.
• The queries ask Prolog to check if john likes pizza and if mary likes pizza.
Advantages of Prolog:
1. Declarative Nature:
o This high-level, declarative style is especially helpful for problems where the
logic and relationships are more important than the step-by-step procedural
approach. You define facts, rules, and relationships, and Prolog handles the
process of reasoning and finding solutions.
3. Symbolic Reasoning:
o Prolog can handle complex queries and reasoning tasks efficiently, especially
when the relationships between entities are intricate.
o Prolog programs can often be much shorter and more compact than equivalent
programs written in imperative languages.
Disadvantages of Prolog:
1. Performance Issues:
o Prolog is generally slower than imperative programming languages like C,
Java, or Python, especially for tasks that involve heavy computation or large
amounts of data. Prolog performs backtracking and searches exhaustively for
solutions, it can become inefficient for problems that require searching large
solution spaces.
2. Limited Use Cases:
o Compared to more popular languages like Python, Java, or C++, Prolog has a
smaller ecosystem and fewer pre-built libraries or frameworks, especially in
newer fields like web development, mobile apps, or cloud computing.
o While Prolog is well-suited for AI applications, the limited library support can
make it harder to integrate with other technologies or modern development
environments.
6. Memory Management:
o In certain complex queries, Prolog may not be able to handle the memory
requirements or time constraints.
o Prolog is not ideal for programming tasks that involve state changes, such as
interactive systems or systems with side effects (e.g., GUI development or
handling user input in real-time).
Advantages Disadvantages
Strong in symbolic reasoning and Steep learning curve for those unfamiliar
logical inference with logic programming