# Basic elements of Prolog

Prolog is a logic programming language that is primarily used for artificial intelligence and computational linguistics applications. It is based on a formal system called first-order logic.

## 1. Facts:

In Prolog, facts are statements about the world that are assumed to be true. Facts consist of predicates and arguments. Predicates represent relationships or properties, and arguments provide the specific details.

Facts are declared using the syntax:

``````predicate(argument1, argument2, ...).
``````

For example:

``````parent(sanjay, maya).
``````

## 2. Rules:

Rules in Prolog define relationships or conditions based on other facts or rules. They are used to derive new information or make logical inferences. Rules consist of a head (the conclusion) and a body (the condition). The head specifies the result or conclusion, while the body contains the conditions or requirements for the rule to be true.

Rules are declared using the syntax:

``````head :- condition1, condition2, ...
``````

For example:

``````ancestor(X, Y) :- parent(X, Y).
``````

## 3. Queries:

In Prolog, you can ask queries to the system to retrieve information or test relationships. Queries are entered in the form of goals, which are logical statements that you want to prove or find solutions for. You can ask queries using the syntax:

``````?- goal.
``````

For example:

``````?- ancestor(sanjay, maya).
``````

## 4. Variables:

Variables are used in Prolog to represent unknown values or placeholders. They start with an uppercase letter or an underscore (_) and can be used to instantiate values during the execution of a query or rule. Variables allow Prolog to find solutions and perform unification, which is the process of matching values. For example:

``````?- parent(X, maya).
``````

Here, X is a variable, and Prolog will attempt to find a value for X that satisfies the query.

## 5. Logical Operators:

Prolog provides logical operators to combine conditions and goals.

The main logical operators in Prolog are:

• Conjunction (,): Represents logical AND. It requires both conditions to be true.
• Disjunction (;): Represents logical OR. It satisfies the goal if either condition is true.
• Negation (not or +): Represents logical NOT. It negates a condition, making it false.