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, …
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