Describe the following features of Prolog Include examples f

Describe the following features of Prolog. Include examples for each feature.

Predicate

Clause

Fact

Rule

Query

Procedure

Goal

Program

Term

Atom

Variable

Operator

Arity

Solution

Prolog is a general-purpose logic programming language associated with artificial intelligence and computational linguistics. Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations.The language was first conceived by a group around Alain Colmerauer in Marseille, France, in the early 1970s and the first Prolog system was developed in 1972 by Colmerauer with Philippe Rousse. Prolog was one of the first logic programming languages, and remains the most popular among such languages today, with several free and commercial implementations available. The language has been used for theorem proving, expert systems, as well as its original intended field of use, natural language processing. Modern Prolog environments support creating graphical user interfaces, as well as administrative and networked applications. Prolog is well-suited for specific tasks that benefit from rule-based logical queries such as searching databases, voice control systems, and filling templates.

An atom is a general-purpose name with no inherent meaning. It is composed of a sequence of characters that is parsed by the Prolog reader as a single unit. Atoms are usually bare words in Prolog code, written with no special syntax. However, atoms containing spaces or certain other special characters must be surrounded by single quotes. Atoms beginning with a capital letter must also be quoted, to distinguish them from variables. The empty list, written [], is also an atom. Other examples of atoms include x, blue, \'Taco\', and \'some atom\'.

Numbers can be floats or integers. Many Prolog implementations also provide unbounded integers and rational numbers.

Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning with an upper-case letter or underscore. Variables closely resemble variables in logic in that they are placeholders for arbitrary terms. A variable can become instantiated (bound to equal a specific term) via unification. A single underscore (_) denotes an anonymous variable and means \"any term\". Unlike other variables, the underscore does not represent the same value everywhere it occurs within a predicate definition.

Facts

A fact is just what it appears to be --- a fact. A fact in everyday language is often a proposition like ``It is sunny.\'\' or ``It is summer.\'\' In Prolog such facts could be represented as follows:

Queries

A query in Prolog is the action of asking the program about information contained within its data base. Thus, queries usually occur in the interactive mode. After a program is loaded, you will receive the query prompt,

at which time you can ask the run time system about information in the data base. Using the simple data base above, you can ask the program a question such as

and it will respond with the answer

A yes means that the information in the data base is consistent with the subject of the query. Another way to express this is that the program is capable of proving the query true with the available information in the data base. If a fact is not deducible from the data base the system replys with a no, which indicates that based on the information available (the closed world assumption) the fact is not deducible.

If the data base does not contain sufficient information to answer a query, then it answers the query with a no.

Rules

Rules extend the capabilities of a logic program. They are what give Prolog the ability to pursue its decision-making process. The following program contains two rules for temperature. The first rule is read as follows: ``It is hot if it is summer and it is sunny.\'\' The second rule is read as follows: ``It is cold if it is winter and it is snowing.\'\'

The query,

is answered in the affirmative since both \'It is summer\' and \'It is sunny\' are in the data base while a query ``?- \'It is cold.\' \'\' will produce a negative response.

The previous program is an example of propositional logic. Facts and rules may be parameterized to produce programs in predicate logic. The parameters may be variables, atoms, numbers, or terms. Parameterization permits the definition of more complex relationships. The following program contains a number of predicates that describe a family\'s genelogical relationships.

The above program contains the three simple predicates: female; male; and parentof. They are parameterized with what are called `atoms.\' There are other family relationships which could also be written as facts, but this is a tedious process. Assuming traditional marriage and child-bearing practices, we could write a few rules which would relieve the tedium of identifying and listing all the possible family relations. For example, say you wanted to know if johnette had any siblings, the first question you must ask is ``what does it mean to be a sibling?\'\' To be someone\'s sibling you must have the same parent. This last sentence can be written in Prolog as

A translation of the above Prolog rule into English would be ``X is the sibling of Y provided that Z is a parent of X, and Z is a parent of Y.\'\' X, Y, and Z are variables. This rule however, also defines a child to be its own sibling. To correct this we must add that X and Y are not the same. The corrected version is:

The relation brotherof is similar but adds the condition that X must be a male.

From these examples we see how to construct facts, rules and queries and that strings are enclosed in single quotes, variables begin with a capital letter, constants are either enclosed in single quotes or begin with a small letter.

Types

Prolog provides for numbers, atoms, lists, tuples, and patterns. The types of objects that can be passed as arguments are defined in this section.

Simple Types

Simple types are implementation dependent in Prolog however, most implementations provide the simple types summarized in the following table.

The boolean constants are not usually passed as parameters but are propositions. The constant fail is useful in forcing the generation of all solutions. Variables are character strings beginning with a capital letter. Atoms are either quoted character strings or unquoted strings beginning with a small letter.

Composite Types

In Prolog the distinction between programs and data are blurred. Facts and rules are used as data and data is often passed in the arguments to the predicates. Lists are the most common data structure in Prolog. They are much like the array in that they are a sequential list of elements, and much like the stack in that you can only access the list of elements sequentially, that is, from one end only and not in random order. In addition to lists Prolog permits arbitrary patterns as data. The patterns can be used to represent tuples. Prolog does not provide an array type. But arrays may be represented as a list and multidimensional arrays as a list(s) of lists. An alternate representation is to represent an array as a set of facts in a the data base.

TYPE

A list is designated in Prolog by square brackets ([ ]+). An example of a list is

This says that the list contains the elements dog, {\\tt cat, and mouse, in that order. Elements in a Prolog list are ordered, even though there are no indexes. Records or tuples are represented as patterns. Here is an example.

The elements of a tuple are accessed by pattern matching.

Type Predicates

Since Prolog is a weakly typed language, it is important for the user to be able to determine the type of a parameter. The following built in predicates are used to determine the type of a parameter.

The last three are useful in program manipulation (metalogical or meta-programming) and require additional explanation. clause(H,T) is used to check the contents of the data base. functor(T,F,A) and T=..Lare used to manipulate terms. The predicate, functor is used as follows.

T is a term, F is its functor, and A is its arity. For example,

t is the functor of the term t(a,b,c), and 3 is the arity (number of arguments) of the term. The predicate =.. (univ) is used to compose and decompose terms. For example:

Expressions

Arithmetic expressions are evaluated with the built in predicate is which is used as an infix operator in the following form.

For example,

Arithmetic Operators

Prolog provides the standard arithmetic operations as summarized in the following table.

Boolean Predicates

Besides the usual boolean predicates, Prolog provides more general comparison operators which compare terms and predicates to test for unifiability and whether terms are identical.

For example, the following are all true.

Logic programming definition of natural number.

Prolog definition of natural number.

Logic programming definition of inequalities

Prolog definition of inequality.

Logic programming definition of addition/substraction

Prolog definition of addition

This does not define substration. Logic programming definition of multiplication/division

Prolog definition of multiplication.

This does not define substration. Logic programming definition of Exponentiation

Prolog definition of exponentiation is implementation dependent.

Logical Operators

Predicates are functions which return a boolean value. Thus the logical operators are built in to the language. The comma on the right hand side of a rule is logical conjunction. The symbol :- is logical implication. In addition Prolog provides negation and disjunction operators. The logical operators are used in the definition of rules. Thus,

This table summarizes the logical operators.

TYPE VALUES
boolean true, fail
integer integers
real floating point numbers
variable variables
atom character sequences
Describe the following features of Prolog. Include examples for each feature. Predicate Clause Fact Rule Query Procedure Goal Program Term Atom Variable Operato
Describe the following features of Prolog. Include examples for each feature. Predicate Clause Fact Rule Query Procedure Goal Program Term Atom Variable Operato
Describe the following features of Prolog. Include examples for each feature. Predicate Clause Fact Rule Query Procedure Goal Program Term Atom Variable Operato
Describe the following features of Prolog. Include examples for each feature. Predicate Clause Fact Rule Query Procedure Goal Program Term Atom Variable Operato

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site