Introduction to Logic Programming & Prolog

Prolog (Programmation en Logique) is a declarative, logic programming language.

1.1 What is Prolog?

Prolog (Programmation en Logique) is a declarative, logic programming language. Instead of telling the computer *how* to compute, you describe *what is true* — facts and rules — and ask queries. Prolog's engine finds answers by unification and backtracking search.

parent(tom, bob).
parent(bob, ann).
grandparent(X, Z) :- parent(X, Y), parent(Y, Z).

?- grandparent(tom, Who).
Who = ann.

1.2 Key characteristics

Declarative: programs are logical statements (Horn clauses).

Relational: predicates are relations, often usable in multiple directions (append/3 concatenates *and* splits lists).

Unification: powerful two-way pattern matching.

Automatic backtracking: built-in search for all solutions.

Homoiconic: programs are terms → metaprogramming is natural.

Dynamically typed, garbage collected.

1.3 History

Alain Colmerauer & Philippe Roussel create Prolog in Marseille; Robert Kowalski provides the procedural interpretation of Horn clauses

David H.D. Warren's DEC-10 Prolog compiler ("Edinburgh syntax")

Japan's Fifth Generation Computer Systems project adopts logic programming Warren Abstract Machine (WAM)

SWI-Prolog started by Jan Wielemaker; CLP(R) ISO standard (ISO/IEC 13211-1) CLP(FD) libraries, tabling (XSB), CHR IBM Watson uses Prolog for parsing/NLP

Scryer Prolog (Rust, ISO-focused), Trealla, Tau (JS), Janus Python bridge, renewed interest via LLM + symbolic AI

1.4 Where is Prolog used?

AI: expert systems, planning, knowledge representation, NLP (IBM Watson).

Static analysis & program verification (type checkers, theorem provers).

Scheduling, configuration, and constraint solving (airline crew rostering, timetabling).

Databases & rule engines (Datalog derivatives, TerminusDB).

Legal reasoning, bioinformatics, education (teaching logic).

Microsoft Windows NT's networking configuration used an embedded Prolog interpreter.

1.5 Programming mindset shift

variables are memory cells variables are unknowns (logical variables), bound once functions return values predicates succeed/fail, outputs via arguments multiple clauses + unification