This course uses the logic programming language named Prolog.
Logic programming consists of the declaration of a series of facts and rules of deduction. The execution of a program consists in proving a theorem. The program responds whether the theorem can be proved or not from the statements made beforehand.
The logic programming is different from the procedural programming (C, JAVA, etc), the calculations are in the form of logical proofs. We talk about declarative programming: the program describes a situation corresponding to a problem to be solved. Declarative programming is not incompatible with object.
The formulas expressed in Prolog are restricted to Horn clauses and first order logic. A Horn clause is a clause with at most one positive literal.
Rules, facts and goals
A program is therefore a set of facts and rules, all in the form of Horn clauses. The Prolog interpreter uses this knowledge base to serve goals.
Writing in Prolog
A program is a list of facts and rules. We group together the rules that have the same leading predicate and the facts that relate to the same predicate. The order of declaration of the rules can have an impact on the goals.
A constant (‘roger’) covers the whole program while a variable exists only in the clause where it is. So the nephew variable X of nephew(X, Y) is not the same as that one of grand_child_of(X, Y). On the other hand, it is the same as in the conjunction that is associated with it.
Once the programs are loaded and thus the facts and rules base is established, it is possible to ask questions. This is called demonstration or question resolution. A question is asked by replacing, in a rule or fact, a constant or variable by a ‘?’. To know all the rules of a type one writes the name of the rule containing variables followed by a ‘?’ : human (H)? serves to know all the humans of the base.