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

PPTX
EX-6-Implement Matrix Multiplication with Hadoop Map Reduce.pptx
PPT
Microprocessor 80386
PPT
4 greedy methodnew
PDF
Little o and little omega
PPTX
Chomsky classification of Language
PPTX
Bayesian classification
PPTX
AI: Logic in AI
PPT
Pattern matching
EX-6-Implement Matrix Multiplication with Hadoop Map Reduce.pptx
Microprocessor 80386
4 greedy methodnew
Little o and little omega
Chomsky classification of Language
Bayesian classification
AI: Logic in AI
Pattern matching

What's hot (20)

PPT
Alpaydin - Chapter 2
PDF
8 query processing and optimization
PPTX
Dynamic Programming
PPTX
Job sequencing with deadline
PDF
Introduction to Pandas and Time Series Analysis [PyCon DE]
PDF
I. Hill climbing algorithm II. Steepest hill climbing algorithm
PPTX
NAMED ENTITY RECOGNITION
ODP
NAIVE BAYES CLASSIFIER
PDF
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
PDF
Ch 7 Knowledge Representation.pdf
PDF
Ontologies
DOCX
Artificial Intelligence
PPT
Flynns classification
PDF
Machine learning
PPTX
Random forest
PPT
Ontology engineering
PDF
COMPILER DESIGN- Syntax Directed Translation
PPTX
AI-State Space Representation.pptx
PDF
Computer graphics lab report with code in cpp
PPTX
Unification and Lifting
Alpaydin - Chapter 2
8 query processing and optimization
Dynamic Programming
Job sequencing with deadline
Introduction to Pandas and Time Series Analysis [PyCon DE]
I. Hill climbing algorithm II. Steepest hill climbing algorithm
NAMED ENTITY RECOGNITION
NAIVE BAYES CLASSIFIER
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Ch 7 Knowledge Representation.pdf
Ontologies
Artificial Intelligence
Flynns classification
Machine learning
Random forest
Ontology engineering
COMPILER DESIGN- Syntax Directed Translation
AI-State Space Representation.pptx
Computer graphics lab report with code in cpp
Unification and Lifting
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)

PPT
Nag software For Finance
PPTX
sCode optimization
PPTX
algorithms and data structure Time complexity
PDF
Python functional programming
PPTX
Functional Programming.pptx
PDF
Become Jythonic in FDMEE (KSCOPE15)
PDF
Data Science decoded- author: Rohit Dubey
PDF
Algorithm Analysis.pdf
PDF
Reproducible AI using MLflow and PyTorch
PDF
LLM Cheatsheet and it's brief introduction
PPTX
Towards better software quality assurance by providing intelligent support
PPTX
Improving Code Quality Through Effective Review Process
PDF
EclipseCon Eu 2015 - Breathe life into your Designer!
PPTX
Basic of python for data analysis
PPTX
Design and analysis of algorithm lec 1.pptx
PPTX
Designing function families and bundles with java's behaviors parameterisatio...
PPTX
Natural Laws of Software Performance
PPT
Cs 568 Spring 10 Lecture 5 Estimation
ODP
Gatling
Nag software For Finance
sCode optimization
algorithms and data structure Time complexity
Python functional programming
Functional Programming.pptx
Become Jythonic in FDMEE (KSCOPE15)
Data Science decoded- author: Rohit Dubey
Algorithm Analysis.pdf
Reproducible AI using MLflow and PyTorch
LLM Cheatsheet and it's brief introduction
Towards better software quality assurance by providing intelligent support
Improving Code Quality Through Effective Review Process
EclipseCon Eu 2015 - Breathe life into your Designer!
Basic of python for data analysis
Design and analysis of algorithm lec 1.pptx
Designing function families and bundles with java's behaviors parameterisatio...
Natural Laws of Software Performance
Cs 568 Spring 10 Lecture 5 Estimation
Gatling

Recently uploaded (20)

PPTX
Odoo Consulting Services by CandidRoot Solutions
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
PPTX
Dynamic Solutions Project Pitch Presentation
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
How a Careem Clone App Allows You to Compete with Large Mobility Brands
PDF
A Practical Breakdown of Automation in Project Management
PDF
Emergency Mustering solutions – A Brief overview
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
PDF
Become an Agentblazer Champion Challenge Kickoff
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Best Mobile App Development Company in Lucknow - Code Crafter Web Solutions
PPTX
Services offered by Dynamic Solutions in Pakistan
PPTX
Benefits of DCCM for Genesys Contact Center
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
PDF
Convert Thunderbird to Outlook into bulk
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
DOCX
The Five Best AI Cover Tools in 2025.docx
PDF
Build Multi-agent using Agent Development Kit
PDF
The Future of Smart Factories Why Embedded Analytics Leads the Way
Odoo Consulting Services by CandidRoot Solutions
Materi-Enum-and-Record-Data-Type (1).pptx
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
Dynamic Solutions Project Pitch Presentation
PTS Company Brochure 2025 (1).pdf.......
How a Careem Clone App Allows You to Compete with Large Mobility Brands
A Practical Breakdown of Automation in Project Management
Emergency Mustering solutions – A Brief overview
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Become an Agentblazer Champion Challenge Kickoff
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Best Mobile App Development Company in Lucknow - Code Crafter Web Solutions
Services offered by Dynamic Solutions in Pakistan
Benefits of DCCM for Genesys Contact Center
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Convert Thunderbird to Outlook into bulk
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
The Five Best AI Cover Tools in 2025.docx
Build Multi-agent using Agent Development Kit
The Future of Smart Factories Why Embedded Analytics Leads the Way

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