0 ratings0% found this document useful (0 votes) 479 views8 pagesQA Prolog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Prolog Interview Questions and
Answers
TTT eee UT EL
CR OCCUR CREEL Lg
Question:1 Explain what is prolog programming language? What is it based
on?
Answer:
Prolog is designed for Artificial Intelligence, and it deals with the declarative
and logical aspects. Prolog is a logic programming and is based on three
attributes- Facts, Rules of Inference and Questions. Facts are the known truths,
rules determine how new information can be inferred from these facts, and
questions search for answers according to the facts and rules.
Question:2 Explain what is the difference between bagof/3 and setof/3
predicate in Prolog?
Answer:
Setof/3 is similar to bagof/3 and the difference between is that bagof/3 leaves
all repeated solutions while setof/3 removes them.
Question:3. Name the sector where prolog programming language is used?
Answer:
Prolog programming language is used in sectors like
v
Automated reasoning
v
Machine learning
v
Robot planning
v
Problem solving
v
Natural language understanding
v
Intelligent data base retrieval
v
Expert systesm
Question:4 Explain with an example what is “Setof” predicate in Prolog?
Answer:
In Prolog, “Setof' predicate can be used to find out all the solutions of a
predicate. For example. you have this database:
Gurug9 (SAP, Testing Tools)
Guru99 (PHP, Perl)
And if you want to find the solutions of Guru99 (x, Y). We can enter
Setof ([ X.¥], Guru99 (X¥), Z).
Z=[[ SAP, Testing Tools], [ PHP, Perl] ]
Question:5 Explain why PROLOG language is stated as a procedural
language?
Answer:
In Prolog, procedures are referred as predicate. It is also known as a procedural
language due to the two unusual aspects of prolog like prolog is non
deterministic and has assign- once variables.Question:6 In “cuts” what is the Parent goal in Prolog?
Answer:
When running the subgoals in a rule’s body, the parent goal is referred to the
goal that caused the matching of the head of the current rule.
Question:? Explain what is List structures in Prolog?
Answer:
A Prolog list is referred as an ordered sequence of elements of arbitrary length.
Here the elements are variables, constant, structures, including other lists.
Question:8 Explain where you use \+ operator in Prolog?
Answer:
Operator \+ can be used to negate goals; these are either sub-goals in the body
of a rule or sub-goals of a query. We cannot negate facts or the heads of rules.
Question:9 Why in prolog it is said that Program and Data are the same
thing?
Answer:
In Prolog, data and program both are implemented as the bunch of trees. There
is no difference between a rule that causes operations ta happen and a rule
that just gives back a data value.
Question:10 Mention why you have to use “is” instead of “=" in Prolog when
it comes to applying calculation logic?
Answer:
> "=" triggers unification in Prolog
triggers arithmetic evaluation in PrologQuestion:16 Explain what is backtracking in Prolog?
Answer:
In Prolog, backtracking is a process adopted by Prolog. When a sub-goal fails in
Prolog, the Prolog system moves its steps backwards to the previous goal and
tries to re-satisfy it. Backtracking enables Prolog to find all alternative solutions
to a given query.
Question:17 Explain what is recursion in Prolog?
Answer:
In any language, a function that can call itself until the goal has been succeed is
referred as recursion. In Prolog, recursion happens when a predicate contains a
goal that refers to itself.
Question:18 Explain what is SWI-Prolog?
Answer:
‘SWI-Prolog is a free prolog compiler licensed under GPL. targeting primarily the
research and education.Prolog
Q1. WHAT IS PROLOG PROGRAMMING LANGUAGE?
ANS. Prolog (programming logic) rose within the realm of Artificial Intelligence. It was one of the first logic programming languages. It became popular with
Al researchers, who know more about “what and “how” intelligent behaviour is achieved. The idea behind it deals with the logical and declarative aspects
This language represents a fundamentally new approach to computing and became a serious competitor to LISP. Following are the developers of
PROLOG:
Robert Kowalski
Q2. WHAT ARE THE FEATURES OF PROLOG LANGUAGE?
ANS. FOLLOWING ARE THE FEATURES OF PROLOG LANGUAGE:
Intelligent Systems — programs which perform useful tasks by utilizing artificial intelligence techniques.
Expert Systems — intelligent systems which reproduce decision-making at the level of a human expert
Natural Language Systems — which can analysis and respond to statements made in ordinary language as opposed to approved keywords or menu
selections
Relational Database Systems.
Q3. NAME THE AREAS IN WHICH PROLOG PROGRAMMING LANGUAGE IS USED?
ANS. Fallowing are some areas in which prolog is used:
intelligent data base retrieval
natural language understanding
expert systems
specification language
machine leaming
robot planning
automated reasoning
problem solving
4, WHY WE USE PROLOG PROGRAMMING LANGUAGE?
ANS. FOLLOWING ARE SOME POINTS FOR USING PROLOG MORE:
‘SWL-Prolog is free, open-source, and very well maintained
it's much much easier to distribute SWi-Prolog applications than Java ones
Prolog is much less verbose,which is helpful when during development,
Prolog allows one to define any word or collection of “symbol characters” (e.9. >>, +, /, ,/, ===/===: ) as an infix, postfix, or prefix operator.
In Prolog, you can treat data as programs.
Prolog is interactive,
Q5. WRITE AN SAMPLE PROGRAM IN PROLOG LANGUAGE?ANS. Here is an example. of Sample programming language by displaying the message “Hello”.
SOURCE CODE
the main program (this is 3 comment)
Hello
a,
write('Hello I’).
t
Q6, NAME SOME DATA TYPES IN PROLOG PROGRAMMING LANGUAGE?
ANS. FOLLOWING ARE THE DATA TYPES SUPPORTED BY PROLOG -Prolog’s single data type is the term. Terms are
either atoms, numbers, variables or compound terms.
ATOM: An atom is a general-purpose name with no inherent meaning.
NUMBERS: Numbers are like integers,float etc.
VARIABLES: Are denoted string consisting of letters, numbers, underscore characters, and beginning with an upper-case letter or underscore.
COMPOUND TERMS: Acompoundterm is composed of an atom called a “functor” and number of arguments", which are again terms. They are written
by separating them by commas.
Q7.HOW PROLOG LANGUAGE CAN BE STATED AS PROCEDURAL LANGUAGE?
ANS. In Prolog, procedures are called predicate. Following are the two reasons because of which itis also known as pracedural language. The twa unusual
aspects of Prolog are:
prolog has assign-once variables.
Prolog is non deterministic.
8, HOW VARIABLES ARE USED IN PROLOG?
ANS. HERE IS AN EXAMPLE:
Suppose we wantto ask, “What course does ROBIN teach"?,then we can write it in prolog as
"Is there a course,x,that ROBIN teaches? “
HERE,
here x stands for an objectthat the questioner does not know about yet,sa to answer the prolog has to find the value of xifwe know the value of variable then
itis known as BOUND, ifwe don't know then known as UNBOUND.
Q9. HOW BACKTRACKING IN PROLOG IS DONE?
ANS. BACKTRACKING IS DONE AS FOLLOWS IN PROLOG:
example:
Who does ROBIN teach?
?-lectures(ROBIN, Course), studies(Student, Course).
Course = 9311
Student = jack;
Course = 9314.
Student = jill ;
Course = 9314Student = henry;
Prolog solves this problem by proceeding left to right and then backtracking.
When given the initial query, Proleg starts by trying to solve
lectures(ROBIN, Course).
There are six lectures clauses, but only two have ROBIN as their first argument.
Prolog uses the first clause that refers to ROBIN: lectures(ROBIN, 9211).
With Course = 9311, ittries to satisfy the next goal, studies(Student, 9311).
Itfinds the fact studies(jack, 9311). and hence the first solution: (Course = 9311, Student = jack).
Q10. GIVE AN EXAMPLE OF USING STRUCTURES IN PROLOG?
ANS. Functional terms can be used to construct complex data structures Here is the example. of using structure in PROLOG:
Haw do we ask, “What books does John own that were written by someone called LeGuin"?
2- owns(john, book (Title, author(leguin, GivenName))).
Title = 'Tehanu'
GivenName = ursula
What books does John own?
2- owns(john, Book).
Book = book('Tehanu', author(leguin, ursula))
What books does John own?
2- ovns (john, beok (Title, Author)).
Title = 'Tehanu'
Author = author (leguin, ursula)
Prolog performs a complex matching operation between the structures in the query and those in the clause head.YOUR SCORE IS 4 OUT OF 4
| (1) If sky is blue, everyone likes it. - Write this statement as a prolog clause. _(2) 7 11+4 is 15. - How will prolog respond to this query?
You selected C - Correct!! You selected B - Correct!
© D) likes(sky, everyone) :- blue(sky).
|G) 2 owner(jack, cat(X)) ~ fur(%),spots(X). - What would be the English
meaning for this prolog clause.
4) 2= Nis -(+(5,6),4). and ?-Nis (5+6)-4. - Do these different queries
produce the same result in prolog?
You selected C - Correct!! You selected A-Correct!!
A) jack is a owner of cat and fur and spots.
B) jack is the owner of X or jack is the owner of fur and spots
C) jack is the owner of some cat if that cat has fur and spots.
D)B &C both.(1) dog('Buddy’, likes('Buddy’, toast)). - This statement is
You selected B - Gorrectt!
© A) Rule & Hom Clause
@ B) Fact & Hom Clause
C) Horn Clause with Head and body
© D) Not a Hom clause
(3) Which one from the options would return true/yes for given prolog
program?
boy(john,123).
girl(jane,234).
student(john, 123).
‘You selected B - Correct!
© A) >- ginljane.x).
(2) Which one of the following is not a variable?
You selected D - Correct!
OA)Xyz
© 8) g 234
C) yz
D)B&C both
(4) A prolog query can be made up of only two subgoals.
You selected B - Correct!!
OA)tne