Cover Material, Copyright, and License
Preface
- Who This Book Is For
- How To Read This Book
- Open Source Example Programs and Manuscript Files
- Acknowledgments
Setting Up Your Prolog Development Environment
- Installing SWI-Prolog
- Editor Support
- The SWI-Prolog Interactive Top Level
- Installing Packs (Libraries)
- Cloning the Book’s GitHub Repository
- Project Organization and Best Practices
Prolog Tutorial
- Facts, Rules, and Queries
- Unification and Pattern Matching
- Backtracking and Search
- Lists and Recursive Data Structures
- Arithmetic and Comparison
- Input and Output
- Modules and Code Organization
- Definite Clause Grammars (DCGs) — A First Look
- Common SWI-Prolog Built-in Predicates
Search Algorithms in Prolog
- Loading Graph Data from a File
- Depth-First and Breadth-First Search
- Iterative Deepening
- A* Heuristic Search
- State-Space Search and Puzzle Solving
- Constraint-Based Search: The N-Queens Problem
Natural Language Processing with Definite Clause Grammars
- DCG Fundamentals
- Tokenizing and Preprocessing Text
- Parsing Natural Language Sentences
- Semantic Analysis with DCGs
- Named Entity Recognition
- Text Categorization
- Text Summarization
Reasoning and Inference
- Propositional and First-Order Logic in Prolog
- Forward and Backward Chaining
- Generating and Visualizing Proof Trees
- Non-Monotonic Reasoning and Defaults
- Case Study: A Medical Diagnosis Reasoner
Expert Systems and Rule-Based AI
- What Is an Expert System?
- Building an Expert System Shell in Prolog
- Knowledge Acquisition and Rule Representation
- Explanation Facilities
- Case Study: A Wine Selection Advisor
- Case Study: A Fault Diagnosis System
Explainable AI and Computational Law with s(CASP)
- What is s(CASP)?
- Implementing Compliance Rules
- Running the Compliance Check
- Key Design Decisions
Constraint Logic Programming
- Introduction to CLP
- CLP(FD): Constraints over Finite Domains
- Solving Sudoku with CLP(FD)
- The N-Queens Problem
- Scheduling and Resource Allocation
- CLP(R) and CLP(Q): Constraints over Reals and Rationals
- CLP(B): Boolean Constraints
Probabilistic Logic Programming
- Why Probabilistic Reasoning?
- ProbLog and Probabilistic Facts
- Learning Probabilities from Data
- Bayesian Networks in Prolog
- Practical Applications
Probability
- Words of Warning
- Glossary of Terms
- A SWI-Prolog Library to Explore Probability
- Walking Through the Bayesian Code
- The Correlation Module
- Frequentists vs. Bayesians
- Experimenting with Frequentist Methods
- Prolog-Specific Design Decisions
- Wrap Up
Anomaly Detection
- The Gaussian Approach
- The Training Pipeline
- Module Structure
- Loading and Subsampling
- Preprocessing
- Data Splitting
- Computing Statistics
- The Gaussian PDF
- Epsilon Search
- Putting It Together
- Evaluation
- Running the Example
- Prolog-Specific Design Decisions
- Wrap Up
Knowledge Graphs and Knowledge Representation
- Representing Knowledge in Prolog
- Building a Knowledge Graph
- Multi-Hop Reasoning Over Knowledge Graphs
- Generating RDF and Neo4j Cypher Data from Prolog
- Integrating with DBpedia and Wikidata
Semantic Web Tools
- Loading and Querying RDF Data
- Querying Remote SPARQL Endpoints
- RDFS and OWL Reasoning
- Practical Applications
Web Clients in Prolog
- HTTP GET and POST Requests
- Working with JSON
- Web Scraping
- Practical Applications
Client-Side Prolog with WebAssembly
- Architecture of a WASM Prolog Application
- Recommender System Logic
- JavaScript Integration
- Running the Application Locally
- Key Design Decisions
LLM Integration
- Calling LLM APIs from Prolog
- Structured Output from LLMs
- Combining LLMs with Prolog Reasoning
Cache Engine
- Design Overview
- Implementation
- Usage Examples
- Key Design Decisions
- Practical Applications
LLM Logic Guardrails
- The Neuro-Symbolic Guardrail Pattern
- Prolog Guardrail Rules
- Python Verification Harness
- Running the Verification Script
- Key Design Decisions
Daily Use REPL: Gemini with Search and Cache
- Design Overview
- Keyword Extraction
- Cache Context Builder
- Gemini API Integration
- The REPL Loop
- Running the REPL
- Wrap Up
The Janus Python Bridge
- Setting Up Janus
- Calling Python from Prolog
- Hybrid AI Pipelines
- Calling Prolog from Python
- Practical Applications
Building AI Agents with Prolog
- What Is an AI Agent?
- A Simple Reactive Agent
- Goal-Directed Agents
- Tool-Using Agents with LLM Integration
- Multi-Agent Communication
- Case Study: A Research Assistant Agent
Agent Behavior Trees
- Behavior Tree Node Types
- Implementing the BT Engine in Prolog
- Defining a Robot Agent
- Simulating the Agent
- Key Design Decisions
Meta-Interpreters: Prolog Reasoning About Prolog
- The Vanilla Meta-Interpreter
- Adding Proof Trees
- Bounded Reasoning
- Reasoning with Uncertainty
- Custom Search Strategies
- Debugging and Tracing Meta-Interpreters
- Summary
Planning and Scheduling
- Classical Planning in Prolog
- The Blocks World
- Planning with Constraints
- Partial-Order Planning
- Practical Job Scheduling Applications
Inductive Logic Programming with Popper
- How Popper Works
- The Grandparent Problem Setup
- Python Orchestrator
- Running the Learning Algorithm
- Key Design Decisions
Examples Using Scryer Prolog (The Modern Wave)
- Why Scryer Prolog?
- Installing Scryer Prolog
- Differences from SWI-Prolog
- DCG Processing of Large Text with Scryer
- Constraint Logic Programming in Scryer
- Porting SWI-Prolog Code to Scryer
Book Wrap Up
- Summary of What We Covered
- Where to Go from Here
- The Future of Prolog in AI

