Q1: (a) How to define the list in PROLOG Language; also differentiate between facts and patterns? [3]
Answer:
PROLOG Language:
Basically prolog language is based on predicate logics which use to said as it is closed to the world of assumptions and predictions, it use to cover up knowledge and data base control in the language it does not support any distinction between input and output usually PROLOG, since they add the possibility to have a structure that does not have a predefined number of such elements.
Welcome to the Prolog book. This book can serve as a textbook or tutorial for anyone who wants to learn the Prolog programming language. No prior programming experience is required. Some basic knowledge of logic can come in handy. For those new to the subject, a short introduction to logic is given, but this is not required reading.
The first chapters of the book (under Basics) describe the central syntax and features of the language. The next section, Programming, explores additional concepts that are useful when programming in Prolog. The chapters under Basics and Programming are meant to be read in order.
list in PROLOG Language:
According to the List it is basically a structure of the form [t1;t2;::::::::::::::::;tn] where every ti is a prolog term. The first term t1 is called the head of the list. The remaining part of the list, [t2; : : : ; tn] is called the tail. The empty list is denoted by [].
Difference between facts and patterns
In Prolog such facts could be represented as follows:
'It is sunny today '.
'It is summer'.
A fact is analogous to a base case in a proof. It is a piece of information that is known and is a special case of a rule. Facts are also known as unconditional Horn Clauses. The general case of a Horn clause is:
P if Q1 and Q2 . . . and Qnwhere a fact is simply P with no conditional statements Q1, Q2 . . . .
Facts are used to represent unchanging information about objects and their relationships.
Only facts in the PROLOG database can be used for problem solving.
Patterns:
Consider the following sentence : 'All men are mortal' We can express this thing in Prolog by :
mortal(X) :- human(X).
The clause can be read as 'X is mortal if X is human'.
(b): Why this symbol “|” is used in PROLOG language? [3]
Answer:
The following vertical bar ‘|’ is used in prolog language to separate the head and tail of a list.
Example:
[1 | [2, 3] ]
[1, 2, 3 | [ ] ]
(c): Write down the two types of Constant that can be defined in PROLOG language with example? [4]
Answer:
There are two types of constants in Prolog
· atoms
· numbers.
Atoms:
Well there are four types of atom
a) Alphanumeric atoms - alphabetic character sequence starting with a lower case letter. Examples: apple a1 apple_cart
b) An atom is a general-purpose name with no inherent meaning. Examples of atoms include
x
, blue
, 'Taco'
, and 'some atom'
.c) Quoted atoms - sequence of characters surrounded by single quotes. Examples: ‘Apple’ ‘hello world’
d) Symbolic atoms - sequence of symbolic characters. Examples: & < > * - + >>
e) Special atoms. Examples: ! ; [ ] {}
Numbers
Well the numbers include integers and floating point numbers. Examples: 0 1 9821 -10 1.3 -1.3E102.
Q2: Write down the drawbacks of PROLOG language. [5]
Answer:
Welcome to the Prolog book. This book can serve as a textbook or tutorial for anyone who wants to learn the Prolog programming language. No prior programming experience is required. Some basic knowledge of logic can come in handy. For those new to the subject, a short introduction to logic is given, but this is not required reading.
The first chapters of the book (under Basics) describe the central syntax and features of the language. The next section, Programming, explores additional concepts that are useful when programming in Prolog. The chapters under Basics and Programming are meant to be read in order.
The section Built-in Predicates deals with the functions available in many Prolog compilers. These and other chapters can be read in any order.
Prolog is a logical and a declarative programming language. The name itself, Prolog, is short for PROgramming in LOGic. Prolog's heritage includes the research on theorem provers and other automated deduction systems developed in the 1960s and 1970s.
Programming in Prolog is very different from programming in a traditional procedural language like Pascal where as prolog is the major example of a fourth generation programming language supporting the declarative programming paradigm.
Prolog consists of a series of rules and facts. A program is run by presenting some query and seeing if this can be proved against these known rules and facts. A programming language is a formal language for some form of problem solving. It is to be distinguished from design languages such as hardware description languages, and other descriptive languages such as document description languages (e.g. SGML and HTML) or grammars.
Well Prolog is a declarative programming language where we only specify what we need rather than how to do it. It has a simple concise syntax with built-in tree formation and backtracking which generates readable code which is easy to maintain.
No comments:
Post a Comment