- Prolog stands for
**Programming in logic.**It is used in artificial intelligence programming. - Prolog is a
**declarative**programming language.

**For example:**While implementing the solution for a given problem, instead of specifying the ways to achieve a certain goal in a specific situation, user needs to specify about the situation (rules and facts) and the goal (query). After these stages, Prolog interpreter derives the solution. - Prolog is useful in AI, NLP, databases but useless in other areas such as graphics or numerical algorithms.

- A fact is something that seems to be true.

**For example:**It's raining. - In Prolog, facts are used to form the statements. Facts consist of a specific item or relation between two or more items.

English Statements | Prolog Facts |
---|---|

Dog is barking | barking(dog) |

Jaya likes food if it is delicious. | likes( Jaya, Food):-delicious(Food) |

In the above table, the statement

- Prolog provides the facility for arithmetic operations.
- As per the requirement of the user, arithmetic operations can be divided into some special purpose integer predicates and a series of general predicates for integer, floating point and rational arithmetic.
- The general arithmetic predicates are handled by the expressions.
- An expression is either a function or a simple number.
- Prolog arithmetic is slightly different than other programming languages.

**For example:**

?- X is 2 + 1.

X = 3 ?

yes

Sr. No | Operator | Explanation |
---|---|---|

1 | X+Y | The sum of 'X' and 'Y' |

2 | X-Y | the difference of 'X' and 'Y' |

3 | X*Y | The product of 'X' and 'Y' |

4 | X/Y | The quotient of 'X' and 'Y' |

5 | X^Y | 'X' to the power of 'Y' |

6 | -X | Negation of 'X' |

7 | abs(X) | Absolute value of 'X' |

8 | sqrt(X) | The square root of X |

9 | sin(X) | The sine of X |

10 | cos(X) | The cos of X |

- If there is more than one operator in the arithmetic expression such as A-B*C+D, then the prolog decides an order in which the operator should be applied.
- Prolog gives numerical value for each operator, operators with high precedence like
**'*'**and**'/'**are applied before operators with relatively low precedence values like**'+'**and**'-'**. - Operator with same precedence value ('*' or '/') and ('+' or '-') should be applied from left to right.
- So, the expression A-B*C+D can be written as
**A-(B*C)+D**

Prolog matches expressions in structural way. So,

?- 3 + 2= 5

no

But the following expressions will match because they have same structure.

?- X + Y = 2 + 3

X = 2

Y = 3

?- 2 + Y = X + 3

X = 2

Y = 3

- Lists are the finite sequence of elements.
- Prolog uses […] to build a list.
- The notation [X|Y] represents that the first element is X and second element is Y (X is head and Y is tail).
- Prolog has some special notation for lists:

I) [a] [honda, maruti, renault]

ii) [a,b,c) [pen, pencil, notebook]

iii) [] represents the empty list.

?- [a,b] = [a,X]

X = b

but:

?- [a,b] = [X]

no

[a, b, c, d, e, f, g]

[apple, pear, bananas, breadfruit]

[ ] this is an empty list

[a,b,c] matches with [Head|Tail] resulting in Head=a and Tail=[b,c]

[a] matches with [H|T] resulting in H=a and T=[]

[a,b,c] matches with [a|T] resulting in T=[b,c]

[a,b,c] doesn't match with [b|T]

[] doesn't match with [H|T]

[] match with []. Hence, two empty lists get matched with each other.

Consider the following facts,

bird(type (sparrow) name (steve)))

bird(type (penguin) name (sweety)))

bird(type (penguin)name (jones)))

?- bird(type (penguin)name(X)

So, prolog will try to match the first query, but this query will not match because sparrow doesn't match with penguin. Then, it will try to find next query to match the fact and succeed with X = sweety. Later, if the query or subgoals are failed, it will go to the saved option and look for more solutions. For example: X = jones

- Every organism has a set of rules which describes, how that organism is built, and encoded in the genes of an organism.
- The chromosomes contain hundreds to thousands of genes.
- Features of the organisms depend on the genes and they have several settings. For example: hair color gene may be brown or black.
- The genes and their settings are referred to as a genotype of an organism.
- When two organisms mate, they share their genes, so that the offspring gets half genes from one parent and half genes from the other parent. Hence, this process is called crossover.
- It is possible that gene is mutated in the organism as a completely new feature.
- The genetic algorithm follows the process of nature to solve the problems such as selection, crossover, mutation, and acceptance for evolution.