# Prolog Syntax

The syntax of Prolog is as follows:

### Symbols

Using the following truth-functional symbols, the Prolog expressions are comprised. These symbols have the same interpretation as in the predicate calculus.

EnglishPredicate CalculusProlog
If-->:-
Not~Not
OrV;
and^,

### Variable

Variable is a string. The string can be a combination of lower case or upper case letters. The string can also contain underscore characters that begin with an underscore or an upper-case letter. Rules for forming names and predicate calculus are the same.

For example:

### Facts

A fact is like a predicate expression. It is used to provide a declarative statement about the problem. In a Prolog expression, when a variable occurs, it is assumed to be universally quantified. Facts are specified in the form of the head. Head is known as the clause head. It will take in the same way as the goal entered at the prompt by the user.

For example:

### Queries

In Prolog, the query is the action of asking the program about the information which is available within its database. When a Prolog program is loaded, we will get the query prompt,

After this, we can ask about the information to the run time system. Using the above simple database, we can ask a question to the program like

and it will give the answer

The system responds to the query with yes if the database information is consistent to answer the query. Using the available database information, we can also check that the program is capable of proving the query true. No indicates that the fact is not deducible based on the available information.

The system answers no to the query if the database does not have sufficient information.

### Rules

Rules extend the logic program capabilities. Rules are used to provide the decision-making process in Prolog. Rules are specified in the form:

:- is known as the clause neck. It is read as 'if'. The body of the clause is specified by t1, t2, t3,…, tk. It contains one or more components, and it can be separated using the commas. A rule will read as 'head is true if t1, t2, t3,…., tk are all true'.

In the following program, first two lines indicate the facts and last two lines indicate the rules:

The above rules mean that 'large_animal(A) is true if dog(A) is true, and large(A) is true, etc.'

The last line means that 'large_animal(C) is true if cat(C) is true, and large(C) is true.