SlideShare a Scribd company logo
11
Most read
13
Most read
19
Most read
Logic Programming in Python
Pierre Carbonnelle
FOSDEM 2014
No if’s, no loops, just the plain mathematical definition !
Logic programming
(Prolog, SQL)
Functional
(Lisp, ..)
Imperative / OO
(C, Smalltalk)
Logic programming
(Prolog, SQL)
Functional
(Lisp, ..)
Imperative / OO
(C, Smalltalk)
Python
Python + pyDatalog
Why Logic Programming in Python ?
Be productive
Be Readable
Use AI
Easy to learn
Batteries included
Query 11 SQL databases
The anatomy of a prolog program
Fact
Clause
Query
The anatomy of a pyDatalog program
The anatomy of a pyDatalog program
Sample 1
Could be
written in SQL
too !
Sample 1
 Loop
 Calculation
 Test
 Input/output polymorphism !
Shorter
programs !
Sample 1
Batteries
included
 Would need an equation solver
Sample 2
• f[X]=2*X is equivalent to (f[X]==Y) <= (Y==2*x)
• Functions return only 1 value per key (aka dict())
• Functions can appear in expressions
• Resolution starts with the latest clause, and stops on first answer
• Support for aggregate functions : sum, min, max, …
Sample 3 Familiar tuple
notation
Memoized
 Faster
 Avoid infinite loop
Sample 4
Prefixed function
to query
Python classes
or SQL databases
Other pyDatalog features
• Runs on PyPy, Python 2, Python 3
• Accepts predicate definition written in Python
• For I/O, performance, …
• Thread-safe
• For use in multi-threaded web framework
• Multi-model : Switch from one Logic model (= set of clauses)
to another
Applications
Core technology Benefit Applications
The SLG resolution algorithm
determines the sequence of steps
to resolve a query.
Spreadsheet-programming : faster
iterations, fewer bugs, more
readable.
Rule-based expert systems for
pricing, tax calculation, access
right, robot control, intelligent
agent.
Input/output polymorphism. Maximise code reuse : shorter
program, simpler database query
language.
Cross-database queries, data
integration.
Intermediate results are memoized. Avoid re-calculation. Avoid infinite
loop.
Recursive algorithm on tree or
graph structures, natural language
processing, code analysis
Roadmap : Equation solver
Roadmap : Transactions
• Assert facts within transactions, with possible roll-back
• Use logic clauses to validate data operations
• Use logic clauses to define triggers (condition => action)
• Memoize results across queries within the same transaction
• Translate Datalog queries into SQL for server-side processing
Feedback, Help welcome !!
Roadmap : Performance
• Rewrite critical sections in C
• Exploit multi-threading in resolution engine
Feedback, Help welcome !!
Why Logic Programming in Python ?
Easy to learn
Batteries included
Query 11 SQL databases
Be productive
Be Readable
Use AI

More Related Content

PPT
Backtracking Algorithm.ppt
PPT
Regular Grammar
PDF
Automata theory
PPTX
Asymptotic Notation
PDF
First Order Logic resolution
PPTX
Asymptotic Notations
PPTX
Heuristic search
Backtracking Algorithm.ppt
Regular Grammar
Automata theory
Asymptotic Notation
First Order Logic resolution
Asymptotic Notations
Heuristic search

What's hot (20)

PPTX
Compiler design syntax analysis
PPTX
Divide and conquer - Quick sort
PDF
A* Search Algorithm
PPT
2.5 backpropagation
PPTX
Activation functions
PDF
Curves and fractals b spline and bezier
PPTX
Church Turing Thesis
PPTX
String Matching (Naive,Rabin-Karp,KMP)
PPTX
ML_Unit_1_Part_B
PPTX
Lecture 14 run time environment
PDF
Time and Space Complexity
PDF
Python-List comprehension
PPTX
04 Multi-layer Feedforward Networks
PPTX
Regular expressions
PDF
Artificial Neural Networks Lect5: Multi-Layer Perceptron & Backpropagation
PPT
Primitive Recursive Functions
PPT
Finite automata
PDF
Asymptotic Notation
PPTX
Raster animation
PDF
Daa notes 1
Compiler design syntax analysis
Divide and conquer - Quick sort
A* Search Algorithm
2.5 backpropagation
Activation functions
Curves and fractals b spline and bezier
Church Turing Thesis
String Matching (Naive,Rabin-Karp,KMP)
ML_Unit_1_Part_B
Lecture 14 run time environment
Time and Space Complexity
Python-List comprehension
04 Multi-layer Feedforward Networks
Regular expressions
Artificial Neural Networks Lect5: Multi-Layer Perceptron & Backpropagation
Primitive Recursive Functions
Finite automata
Asymptotic Notation
Raster animation
Daa notes 1
Ad

Viewers also liked (20)

PDF
Logic programming (1)
PDF
Logic Programming and ILP
PPT
Knowledge Representation in Artificial intelligence
PPTX
Prolog Programming : Basics
DOC
Le langage Prolog
PDF
Construire un moteur d'inférence
PPT
Logic Programming and Prolog
PPTX
Knowledge representation in AI
PPTX
Functional programming ideas in python
PDF
Fantastic DSL in Python
PDF
Intelligence Artificielle: résolution de problèmes en Prolog ou Prolog pour l...
PPT
Prolog programming
PDF
20 examples on Domain-Specific Modeling Languages
DOC
اجابات البرولوج
PPS
Presentation of GetTogether on Functional Programming
PDF
Intelligence Artificielle : Introduction à l'intelligence artificielle
PPTX
Forward Backward Chaining
PPT
Artificial intelligence Prolog Language
PPTX
Introduction on Prolog - Programming in Logic
PPTX
Introduction to Prolog
Logic programming (1)
Logic Programming and ILP
Knowledge Representation in Artificial intelligence
Prolog Programming : Basics
Le langage Prolog
Construire un moteur d'inférence
Logic Programming and Prolog
Knowledge representation in AI
Functional programming ideas in python
Fantastic DSL in Python
Intelligence Artificielle: résolution de problèmes en Prolog ou Prolog pour l...
Prolog programming
20 examples on Domain-Specific Modeling Languages
اجابات البرولوج
Presentation of GetTogether on Functional Programming
Intelligence Artificielle : Introduction à l'intelligence artificielle
Forward Backward Chaining
Artificial intelligence Prolog Language
Introduction on Prolog - Programming in Logic
Introduction to Prolog
Ad

Similar to Logic programming in python (20)

PPTX
logic for Advanced Programming Practice.pptx
PPT
Logical Programming Paradigm for programming Languages.
PPTX
app4.pptx
PPTX
Logical programming languages and functional programming languages
PDF
practical file 11.pdf
PPTX
Introduction to Artificial Intelligence...pptx
PPTX
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
PDF
Python Course At Sparse Matrix Solutions
PPTX
Python ppt
PDF
PDF
CPSC 125 Ch 1 Sec 5
DOCX
An Introduction to Computer Science with Java, Python an.docx
PPTX
Introduction To Programming with Python Lecture 2
PPTX
Introduction to Python for Data Science and Machine Learning
PDF
ICS1019.pdf
PDF
Python-content-1.pdf
PPTX
ProLog (Artificial Intelligence) Introduction
PDF
Do we need a logic of quantum computation?
PPTX
Deductive databases
PPTX
Python Programming Basics
logic for Advanced Programming Practice.pptx
Logical Programming Paradigm for programming Languages.
app4.pptx
Logical programming languages and functional programming languages
practical file 11.pdf
Introduction to Artificial Intelligence...pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
Python Course At Sparse Matrix Solutions
Python ppt
CPSC 125 Ch 1 Sec 5
An Introduction to Computer Science with Java, Python an.docx
Introduction To Programming with Python Lecture 2
Introduction to Python for Data Science and Machine Learning
ICS1019.pdf
Python-content-1.pdf
ProLog (Artificial Intelligence) Introduction
Do we need a logic of quantum computation?
Deductive databases
Python Programming Basics

Recently uploaded (20)

PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
medical staffing services at VALiNTRY
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Transform Your Business with a Software ERP System
PDF
top salesforce developer skills in 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPT
Introduction Database Management System for Course Database
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ManageIQ - Sprint 268 Review - Slide Deck
How to Migrate SBCGlobal Email to Yahoo Easily
medical staffing services at VALiNTRY
Upgrade and Innovation Strategies for SAP ERP Customers
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Understanding Forklifts - TECH EHS Solution
Transform Your Business with a Software ERP System
top salesforce developer skills in 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Odoo POS Development Services by CandidRoot Solutions
Odoo Companies in India – Driving Business Transformation.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction Database Management System for Course Database
PTS Company Brochure 2025 (1).pdf.......
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf

Logic programming in python

  • 1. Logic Programming in Python Pierre Carbonnelle FOSDEM 2014
  • 2. No if’s, no loops, just the plain mathematical definition !
  • 3. Logic programming (Prolog, SQL) Functional (Lisp, ..) Imperative / OO (C, Smalltalk)
  • 4. Logic programming (Prolog, SQL) Functional (Lisp, ..) Imperative / OO (C, Smalltalk) Python Python + pyDatalog
  • 5. Why Logic Programming in Python ? Be productive Be Readable Use AI Easy to learn Batteries included Query 11 SQL databases
  • 6. The anatomy of a prolog program Fact Clause Query
  • 7. The anatomy of a pyDatalog program
  • 8. The anatomy of a pyDatalog program
  • 10. Sample 1  Loop  Calculation  Test  Input/output polymorphism ! Shorter programs !
  • 11. Sample 1 Batteries included  Would need an equation solver
  • 12. Sample 2 • f[X]=2*X is equivalent to (f[X]==Y) <= (Y==2*x) • Functions return only 1 value per key (aka dict()) • Functions can appear in expressions • Resolution starts with the latest clause, and stops on first answer • Support for aggregate functions : sum, min, max, …
  • 13. Sample 3 Familiar tuple notation Memoized  Faster  Avoid infinite loop
  • 14. Sample 4 Prefixed function to query Python classes or SQL databases
  • 15. Other pyDatalog features • Runs on PyPy, Python 2, Python 3 • Accepts predicate definition written in Python • For I/O, performance, … • Thread-safe • For use in multi-threaded web framework • Multi-model : Switch from one Logic model (= set of clauses) to another
  • 16. Applications Core technology Benefit Applications The SLG resolution algorithm determines the sequence of steps to resolve a query. Spreadsheet-programming : faster iterations, fewer bugs, more readable. Rule-based expert systems for pricing, tax calculation, access right, robot control, intelligent agent. Input/output polymorphism. Maximise code reuse : shorter program, simpler database query language. Cross-database queries, data integration. Intermediate results are memoized. Avoid re-calculation. Avoid infinite loop. Recursive algorithm on tree or graph structures, natural language processing, code analysis
  • 18. Roadmap : Transactions • Assert facts within transactions, with possible roll-back • Use logic clauses to validate data operations • Use logic clauses to define triggers (condition => action) • Memoize results across queries within the same transaction • Translate Datalog queries into SQL for server-side processing Feedback, Help welcome !!
  • 19. Roadmap : Performance • Rewrite critical sections in C • Exploit multi-threading in resolution engine Feedback, Help welcome !!
  • 20. Why Logic Programming in Python ? Easy to learn Batteries included Query 11 SQL databases Be productive Be Readable Use AI