Origins: the 1977 Symposium on Logic and Data Bases
Deductive databases have the advantage of making inference (deduction) of additional facts based on relations (facts and rules) already present in the database.
data representation: relations (based on Horn clauses)
query language: Datalog
Datalog
Datalog VS Prolog
recursion is allowed
negation is allowed, but only for facts
clause order does not matter
not cut !/0 operator to control search
function symbols not allowed - cannot construct complex terms (e.g.person(name(elisabeth), age(inf), ...) has to be expressed as person(elisabeth, inf, ...))
queries are made on finite sets of values, so termination is guaranteed
union U(x,y) :- P(x,y). ; U(x,y) :- Q(x,y,_). (logical OR)
difference D(x,y) :- P(x,y), not Q(x,y,_).
projection Px(x) :- P(x,_).
selection S(x,y) :- Q(x,y,_), x > 10.
product PR(x,y,z,v,w) :- P(x,y), Q(z,v,w).
join J(x,y,z) :- P(x,y), Q(y,z,_).
...
Datalog
Datalog systems - few examples
logicblox.com - a commercial implementation of Datalog used for web-based retail planning and optimization
datomic.com - a transactional database with a flexible data model, elastic scaling, and rich queries
... and many more systems with Datalog components
roadmap
Efficiency in computations
Datalog
CLP and numeric computaitons
Assertions and program verification
Natural language and parsing with DCGs
CLP and numeric computaitons
Constraint satisfaction problems
In the fields of artificial intelligence and operations research there is a need in answering questions in different domains that specify a number of constraints for an answer:
route planning with time or price budget
diet meal preparation accounting for calories intake
solving chess problems (e.g. N-queens)
map coloring
Constraint satisfaction problems are typically solved using a form of search.
CLP and numeric computaitons
Constraint Logic Programming (CLP)
CLP is an extension of logic programming that includes constraint satisfaction in the computations:
CLP = Prolog + Solver(for a given domain)
Some domains:
finite (CLPFD) - e.g. the familty tree
rational numbers (CLP(Q))
real numbers (CLP(R))
CLP and numeric computaitons
CLP(R) in Ciao 1/2
As a language extension CLP functionality is available as a library that defines special operators: .=./2 (equals), .<./2 (less than), etc.
programming language and its specification are based on same formal representation
nowadays a number of mature analysis techniques and tools exist for logic programs analysis and verification
for several high-level languages (C/C++, Java) their intermediate representation (produced by the compiler) can be straightforwardly translated to Horn clauses
Assertions and program verification
Example: factorial (1/2)
Consider the factorial function in XC, a dialect of C for microcontroller programming:
Properties of interest: energy consumption estimates.
Assertions and program verification
Example: factorial (2/2)
ISA (instruction set architecture) instructions for the XC program and respective Horn clause representation with a specification
Assertions and program verification
Some HC-based verification tools
for Java, XC, C and C++ the Ciao preprocessor - CiaoPP - offers abstract interpretation-based analyses over several domains: types, variable instantiation, bounds on computational and energy costs etc
JayHorn is a software model checking tool for Java that tries to find a proof that certain bad states in a Java program are never reachable.
roadmap
Efficiency in computations
Datalog
CLP and numeric computaitons
Assertions and program verification
Natural language and parsing with DCGs
Natural language and parsing with DCGs
IBM Watson
POETS & POETRY: He was a bank clerk in the Yukon before he published
“Songs of a Sourdough” in 1907
"We required a language in which we could conveniently express pattern matching rules over the parse trees and other annotations"
lemma(1, "he"). partOfSpeech(1,pronoun). subject(2,1).
lemma(2, "publish"). partOfSpeech(2,verb). object(2,3).
lemma(3, "Songs of a Sourdough"). partOfSpeech(3,noun). ...
Notice how we still need to provide the two list arguments in the query ?-s([a,cat,eats,a,fish],[]).
roadmap
Efficiency in computations
Datalog
CLP and numeric computaitons
Assertions and program verification
Natural language and parsing with DCGs
---
### Tail recursion
The basic skeleton is: `<head> :- <deterministic computation> <recursive_call>.`
Known as _tail recursion_.
Particular case of _last call optimization_.
It also consumes less memory.
We have done it: `ancestor/2`