Skip to content

Logic Programming

A programming paradigm that expresses relations as logical clauses and obtains answers through inference under a declared semantics and evaluation strategy.

Version
v1 · 2026-10-07 · History
Domain-specific #
13935
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomains
Programming Languages, Computational Logic → Computer Science & Software Engineering
Aliases
Logic Program

Core Idea

Logic programming writes a program as logical clauses and asks what answers follow under stated rules for interpreting and evaluating them. Clauses can include facts with no conditions and rules that derive one relation from others. A Prolog user often poses a goal; a Datalog program can request an output relation. A facts-only Prolog knowledge base is still a program. The exact meaning and search behavior depend on the language and its chosen controls.[1][2][3][4]

How would you explain it like I'm…

Facts, Rules, Questions

You tell the computer some facts, like 'Sam is Max's dad' and 'Max is Lily's dad', and a rule, like 'a dad's dad is a grandpa.' Then you ask, 'Who is Lily's grandpa?' and the computer figures out the answer from what you told it.

Programming With Facts

Most computer programs are lists of steps to follow. In logic programming, you instead write statements that are true: facts (like 'Paris is in France') and rules (like 'if X is in France, X is in Europe'). Then you ask a question, and the computer uses the facts and rules to work out answers. Prolog and Datalog are two such languages. The way the computer searches for answers can matter, so a question might not always get every answer, or might keep going forever in some cases.

Clause-Based Declarative Programming

Logic programming describes relationships as logical clauses: facts (clauses with no conditions) and rules (a conclusion that holds if certain conditions hold). You then pose a goal, as in Prolog, or ask for an output relation, as in Datalog, and an evaluation strategy derives or tests answers. The key idea is that each statement has a logical meaning, while running the program computes answers from it. In Prolog, a rule can also be read as a procedure: to prove the goal, prove its subgoals. In Datalog, facts like edges plus recursive rules can compute all reachable pairs. A program of only facts still counts; recursion and rules are options, not requirements.

 

Logic programming describes relationships as logical clauses and uses a stated interpretation and evaluation strategy to obtain answers. Clauses are facts (empty body) or rules relating a head to conditions; a user poses a goal (Prolog) or requests an output relation (Datalog). The distinctive commitment is that statements have a logical reading while computation derives or tests answers against them. Kowalski's definite clauses illustrate the dual reading: an implication is both a declarative statement and a procedure reducing a goal to subgoals. Datalog, as in Soufflé, realizes the idea bottom-up: edge facts and recursive rules generate a reachability relation. These share a clause-and-inference core but not a single execution order or termination guarantee: pure finite Datalog is constrained, extensions with arithmetic functors may not terminate, and Prolog's control choices affect which answers are reached. Negation-as-failure is weaker than classical negation, so no single consequence relation applies across all logic languages. Recursion and rule bodies are optional; a facts-only program still counts.

Scope of Application

Kowalski's definite-clause factorial program shows clauses with both a logical reading and a way to reduce a goal into subgoals. His program has a base factorial clause, a recursive clause and a necessary Times helper relation. Soufflé's Datalog tutorial shows a different setting: graph edge facts and recursive reachable rules produce a relation of connected vertex pairs.[1][3]

The label covers more than these two examples. Pure finite Datalog has restrictions that practical Soufflé arithmetic extensions can relax, sometimes losing termination. Prolog's depth-first search can also follow an infinite path before reaching an answer; a declarative reading alone does not guarantee full answer enumeration.[3][4]

Clarity

For a claimed logic program, identify its clauses, interpretation, answer target and evaluation strategy. If a query fails, distinguish a missing logical answer from a search path that did not reach an available one. Negation-as-failure is weaker than classical negation, and Prolog's cut can prune search alternatives; these controls must not be silently read as ordinary classical implication.[4][5][6]

Manages Complexity

A small set of clauses can describe many instances of a relation. Soufflé's two reachable rules describe paths of varying lengths without listing each path. Kowalski's factorial clauses describe a family of inputs while a goal selects one computation. This compactness helps when the clauses and their semantics are clear. It can also hide operational cost or nontermination, so the evaluation regime must be stated.[1][3][4]

Abstract Reasoning

Given a goal or output relation, first ask what the clauses say. Next ask how the engine seeks the answer. In the Soufflé graph, each edge is reachable and the recursive rule extends reachability through intermediate vertices. In Kowalski's program, the factorial goal is reduced through the recursive clause and Times. If the answer is not produced, check the clauses, the declared semantics and the search behavior separately.[1][3][4]

Knowledge Transfer

The literal pattern transfers between logic languages: represent relations with logical clauses and evaluate a specified target. A Prolog goal and a Datalog output relation realize that pattern differently, and their syntax and termination conditions need separate checks. The live Programming Paradigm entry is the strict parent: it covers families of computational concepts, composition and reasoning across implementations. Logic programming adds logical clauses and inference-based answers; its words “logic” and “rule” do not by themselves make it a cross-domain Prime.[1][3]

Example

Kowalski's Fact relation represents factorial. Its base clause is Fact(0,s(0)), and its recursive clause uses a smaller factorial result and a Times relation. The worked goal Fact(s(s(0)),x) asks for two factorial. Mapped back: the Fact and Times clauses are the logical program; definite-clause implication gives its meaning; the Fact goal is the target; goal reduction is the evaluation. The Times helper is required for the worked computation.[1]

In Soufflé's graph example, edge facts and two reachable rules define transitive reachability, including reachable("a","d"). Mapped back: edge and reachable clauses are the program; Datalog rule meaning defines the relation; .output reachable chooses the answer; rule evaluation derives it. This does not make one search order or pure-Datalog termination guarantee universal to every extended program.[3]

Relationships to Other Abstractions

Local relationship map for Logic ProgrammingParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Logic ProgrammingDOMAINDomain-specific abstraction: Programming Paradigm — is a kind ofProgrammingParadigmDOMAIN

Current abstraction Logic Programming Domain-specific

Parents (1) — outgoing typed relations

  • Logic Programming is a kind of Programming Paradigm Domain-specific

    Logical clauses, answer targets, semantics and inference-based evaluation organize program composition and reasoning across Prolog and Datalog implementations, making logic programming a strict programming paradigm.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Logic Programming sits in a sparse region of the domain-specific corpus (93rd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (3155 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

Not to Be Confused With

A facts-only program: it remains a valid logic program when the facts are logical clauses available to queries. An imperative algorithm with the same result: output alone does not decide the program form. All declarative programming: some declarative programs use other organizing structures. A guarantee of complete search: Prolog control and depth-first execution can change what the user actually sees. Classical negation: negation-as-failure has a different interpretation.[2][4][5]

References

[1] Robert A. Kowalski, “Predicate Logic as Programming Language,” Proceedings of IFIP Congress 1974 (1974), pp. 569–574, especially the definite-clause procedural/declarative discussion and factorial Fact example. https://www.doc.ic.ac.uk/~rak/papers/IFIP74.pdf registry ↩a ↩b ↩c ↩d ↩e ↩f

[2] Patrick Blackburn, Johan Bos and Kristina Striegnitz, “Facts, Rules, and Queries,” Learn Prolog Now!, Chapter 1, SWI-Prolog-hosted edition, facts-only first program. https://lpn.swi-prolog.org/lpnpage.php?pageid=lpn-htmlse1&pagetype=html registry ↩a ↩b

[3] Soufflé development team, “Tutorial,” Soufflé: A Datalog Synthesis Tool for Static Analysis, “Introduction to Datalog,” “Transitive closure,” and the paragraph on arithmetic functors. https://souffle-lang.github.io/tutorial registry ↩a ↩b ↩c ↩d ↩e ↩f ↩g

[4] SWI-Prolog, “Glossary of Terms,” SWI-Prolog Reference Manual, entries for classes of logic programs, weak versus strong negation, SLD-resolution, and Prolog's leftmost, top-to-bottom, depth-first search and possible infinite proof paths. https://www.swi-prolog.org/pldoc/man?section=glossary registry ↩a ↩b ↩c ↩d ↩e ↩f

[5] SWI-Prolog, “Control Predicates,” SWI-Prolog Reference Manual, cut operator and choice-point behavior. https://www.swi-prolog.org/pldoc/man?section=control registry ↩a ↩b

[6] SWI-Prolog, “Constraint Logic Programming,” SWI-Prolog Reference Manual, §8 note about cut and declarative semantics. https://www.swi-prolog.org/pldoc/man?section=clp registry ↩