What is Logic Programming?
Logic programming is a programming strategy that uses logic circuits to control how facts and rules are expressed, rather than only mathematical functions. Often used in genetic and evolutionary programming, this approach generally tells a model what goal to accomplish, rather than how to accomplish it. Instead of a carefully structured control flow dictating when to execute and how to evaluate function calls or other instructions, the program’s logic rules are written as logical clauses (predicates).
How does Logic Programming Work?
Each rule contains a head and body with formalized logic, instead of an executable mathematical function. For example,
"X is true (heading): if B1, B2, and B3 are all true. (body)"
Facts (the results) are expressed without a body; for instance, "X is true."
With some languages though, such as Prolog, imperative programming can also be included to tell the model how to solve certain problems. For example, “To solve for X, sum B1, B2 and B3.”
The other two most commonly used logic programming languages, Datalog and Answer Set Programming (ASP), are only declarative and don’t support explicit problem-solving instructions.