SLIDE 1
How to write and prove programs with constraints and linear logic? - - PowerPoint PPT Presentation
How to write and prove programs with constraints and linear logic? - - PowerPoint PPT Presentation
How to write and prove programs with constraints and linear logic? Thierry Martinez Contraintes Project-Team INRIA Junior Seminar, 18 October 2011 Contraintes project-team Topic Formal semantics for programming languages Methods Logic
SLIDE 2
SLIDE 3
“Contraintes” project-team
Topic Formal semantics for programming modeling languages Methods Logic and constraints Applications
▸ Solving/optimization of combinatorial problems ▸ Systems Biology
SLIDE 4
Sudoku
We probably all know the rules of the Sudoku...
0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
SLIDE 5
Sudoku
We probably all know the rules of the Sudoku...
0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
▸ for every line i and every column j,
the case (i,j) should have a value 1 ⩽ X(i,j) ⩽ 9.
SLIDE 6
Sudoku
We probably all know the rules of the Sudoku...
0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
▸ for every line i and every column j,
the case (i,j) should have a value 1 ⩽ X(i,j) ⩽ 9.
▸ for every line i
and every pair (j,k) of distinct columns, we should have X(i,j) ≠ X(i,k).
SLIDE 7
Sudoku
We probably all know the rules of the Sudoku...
0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
▸ for every line i and every column j,
the case (i,j) should have a value 1 ⩽ X(i,j) ⩽ 9.
▸ for every line i
and every pair (j,k) of distinct columns, we should have X(i,j) ≠ X(i,k).
▸ for every column i
and every pair (j,k) of distinct lines, we should have X(j,i) ≠ X(k,i).
SLIDE 8
Sudoku
We probably all know the rules of the Sudoku...
0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
▸ for every line i and every column j,
the case (i,j) should have a value 1 ⩽ X(i,j) ⩽ 9.
▸ for every line i
and every pair (j,k) of distinct columns, we should have X(i,j) ≠ X(i,k).
▸ for every column i
and every pair (j,k) of distinct lines, we should have X(j,i) ≠ X(k,i).
▸ for every 3 × 3-block (i,j)
and every distinct cases (m,n) and (m′,n′) in this block, we should have X3×(i,j)+(m,n) ≠ X3×(i,j)+(m′,n′).
SLIDE 9
Sudoku
We probably all know the rules of the Sudoku... Logical formulas
▸ ∀i j ∈ {0...8},1 ⩽ X(i,j) ⩽ 9 ▸ ∀i j k ∈ {0...8},j ≠ k ⇒ X(i,j) ≠ X(i,k) ▸ ∀i j k ∈ {0...8},j ≠ k ⇒ X(j,i) ≠ X(k,i) ▸ ∀i j m n m′ n′ ∈ {0...2},(m,n) ≠ (m′,n′) ⇒
X3×(i,j)+(m,n) ≠ X3×(i,j)+(m′,n′)
SLIDE 10
Constraints
▸ Constraints = atomic formulas, X(1,1) ≠ X(1,2) ▸ Model = conjunction of constraints
⋀constraints ⇒ solution
▸ Constraints formalized as relations:
“X(1,1) ≠ X(1,2)” = {(X(i,j))0⩽i⩽8,0⩽j⩽8 ∣ X(1,1) ≠ X(1,2)}
▸ The set of solutions is the intersection
⋂{relations} = {set of solutions}
▸ Explicit representation is intractable
SLIDE 11
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 x
SLIDE 12
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 x 2 3 5 8 9 1 2 3 4 5 6 7 8 9 2 3 5 8 9 Domain: x
SLIDE 13
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 x 2 3 5 8 9 1 4 6 7 2 3 5 8 9 2 3 5 8 9 Domain: x
SLIDE 14
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 x 1 4 6 7 2 3 5 8 9 9 6 8 7 4 Domain: x
SLIDE 15
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 x 1 2 3 4 5 6 7 8 9 9 6 8 7 4 Domain: x
SLIDE 16
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 1 1 2 3 4 5 6 7 8 9 Domain: x
SLIDE 17
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1
SLIDE 18
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 2 3 5 6 7 8 9 1 4
c1 c2 c3 c4 c5 c6 c7 c8 c9
There exists x ∈ 1,...,9 such that cx = 1. x
SLIDE 19
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 5 9 7 2 1 2 3 7 8 9 1 4 5 6
c1 c2 c3 c4 c5 c6 c7 c8 c9
There exists x ∈ 1,...,9 such that cx = 1. x
SLIDE 20
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 8 1 5 2 3 1 4 5 6 7 8 9
c1 c2 c3 c4 c5 c6 c7 c8 c9
There exists x ∈ 1,...,9 such that cx = 1. x
SLIDE 21
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 1 5 3 2 1 3 4 5 6 7 8 9 1
c1 c2 c3 c4 c5 c6 c7 c8 c9
There exists x ∈ 1,...,9 such that cx = 1. x
SLIDE 22
Domain and propagation
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 3 1 2 7 2 8 7 2 9 3 8 7 7 2 7
SLIDE 23
Memory paradigm shift
RAM model Addresses/ Variables Values x vx y vy z vz t vt ⋮
▸ Imperative paradigm:
assigns many, reads many
▸ Functional paradigm:
assigns once, reads many
SLIDE 24
Memory paradigm shift
RAM model Constraint memory model (Partial information) Addresses/ Variables Values x vx y vy z vz t vt ⋮ There exist x, y, z, t. . . such that
increasing knowledge
SLIDE 25
Memory paradigm shift
RAM model Constraint memory model (Partial information) Addresses/ Variables Values x vx y vy z vz t vt ⋮ There exist x, y, z, t. . . such that x ∈ {1,...,15}
increasing knowledge
SLIDE 26
Memory paradigm shift
RAM model Constraint memory model (Partial information) Addresses/ Variables Values x vx y vy z vz t vt ⋮ There exist x, y, z, t. . . such that x ∈ {1,...,15} and y ∈ {5,...,50}
increasing knowledge
SLIDE 27
Memory paradigm shift
RAM model Constraint memory model (Partial information) Addresses/ Variables Values x vx y vy z vz t vt ⋮ There exist x, y, z, t. . . such that x ∈ {1,...,15} and y ∈ {5,...,50} and y ⩽ x
increasing knowledge
SLIDE 28
Memory paradigm shift
RAM model Constraint memory model (Partial information) Addresses/ Variables Values x vx y vy z vz t vt ⋮ There exist x, y, z, t. . . such that x ∈ {1 / 5,...,15} and y ∈ {5,...,50} and y ⩽ x
increasing knowledge
SLIDE 29
Memory paradigm shift
RAM model Constraint memory model (Partial information) Addresses/ Variables Values x vx y vy z vz t vt ⋮ There exist x, y, z, t. . . such that x ∈ {1 / 5,...,15} and y ∈ {5,...,50
15} and
y ⩽ x
increasing knowledge
SLIDE 30
Memory paradigm shift
RAM model Constraint memory model (Partial information) Addresses/ Variables Values x vx y vy z vz t vt ⋮ There exist x, y, z, t. . . such that x ∈ {1 / 5,...,15} and y ∈ {5,...,50
15} and
y ⩽ x and z ∈ Q ∩ [5,9] and more...
increasing knowledge
SLIDE 31
Propagation power
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 3 1 2 7 2 8 7 2 9 3 8 7 7 2 7 x y z 4 6 1 2 3 5 7 8 9 x 4 6 1 2 3 5 7 8 9 y 1 3 4 6 2 5 7 8 9 z
SLIDE 32
Propagation power
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 3 1 2 7 2 8 7 2 9 3 8 7 7 2 7 x y z 4 6 1 2 3 5 7 8 9 x 4 6 1 2 3 5 7 8 9 y 1 3 2 4 5 6 7 8 9 z
SLIDE 33
Propagation power
9 6 8 7 4 7 2 1 5 3 9 7 1 9 5 2 7 2 3 1 2 8 8 5 3 9 5 3 2 1 3 1 2 7 2 8 7 2 9 3 8 7 7 2 7 4 9 6 8 5 8 4 9 6 5 6 3 1 4 3 4 6 8 8 1 4 5 3 9 6 6 5 4 1 4 6 9 5 1 4 6
SLIDE 34
Flow-network algorithm
source x1 x2 ⋮ ⋮ xn v1 v2 ⋮ ⋮ vn target
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Residual network of Ford-Fulkerson: reduced domain
SLIDE 35
Concurrent programming framework
Constraint Model Variable domains Dedicated Propagators acting concurrently Symbolic Constraints
(Graph theory)
Placement Constraints
(Discrete Geometry theory)
Scheduling Constraints
(Formal Language theory)
SLIDE 36
NP-completeness
9 6 8 3 2 1 3 6 1 2 2 1 6 3 9 6 2 8 3 1 7 3 7 1 9 6 2 8 1 2 4 7 5 3 9 6 6 3 2 8 1 7 3 6 1 5 2 1 2 7 6 3 Propagators are polynomial. Finding a solution is NP-complete.
SLIDE 37
Propagation and search
X(1,1) =? propagation 1 3 5 X(1,2) =? propagation
Andorra Principle
Do the deterministic bits first.
SLIDE 38
Conjunction and disjunction
▸ In constraint programming, “and” between constraint ▸ “or” to express choices: in Sudoku,
X(1,1) = 1 ∨ X(1,1) = 2 ∨ ⋅⋅⋅ ∨ X(1,1) = 9
SLIDE 39
Logic programming: logic as a programming language
▸ Abstracting programming traits: concurrency, non
determinism...
▸ Every computation is the search for a proof
Programs = Logical formulas Execution = Proof search
SLIDE 40
What is a proof for a conjunction?
⋮ A ⋮ B A ∧ B
SLIDE 41
What is a proof for a disjunction?
⋮ A A ∨ B ⋮ B A ∨ B A ∨ B A B
SLIDE 42
The logical implication as synchronization mechanism
⋮ A ⋮ A ⇒ B B
SLIDE 43
Logic operators as programming constructs
▸ “and”, ∧: parallel composition ▸ “or”, ∨: non-deterministic choice ▸ “implies”, ⇒: synchronization between parallel tasks (wait) ▸ “exists”, ∃: introducing local variables ▸ elementary formulas: constraints, for adding knowledge about
variables To implement propagators, need to update domains (imperative features).
SLIDE 44
The Linear Concurrent Constraint Programming project
▸ Linear logic (Girard, 87): logic where formulas are resources ▸ Linear implication A ⊸ B is a process which transforms and
consumes A to produce B
▸ Synchronization mechanism relying on linear implication
updates the knowledge by removing some hypotheses
SLIDE 45
Linear logic as a concurrent programming language
▸ Constraints = messages, with partial knowledge ▸ Logic variables = communication channel ▸ Existential operator (∃) = channel locality ▸ Universal operator (∀) = generic synchronization
(∀x(a(x) ⊸ ...))
SLIDE 46
Semantics of programming languages
Program Mathematical model interpretation Observation Property execution proof
SLIDE 47
Semantics of programming languages
Program Mathematical model Logical formula interpretation Observation Property execution proof
SLIDE 48
Semantics of programming languages
interpretation Logical formula Observation Property execution proof
SLIDE 49
Semantics of programming languages
interpretation Logical formula Observable property execution proof
SLIDE 50
Semantics of programming languages
interpretation Logical formula Observable property execution = proof search
SLIDE 51
Warehouse bin-packing
Box placements in containers:
▸ variables = box positions ▸ constraints = weight distribution, gravity. . .
Industrial partnerships with PSA, Fiat...
SLIDE 52
Optimizing energy in underground trains timetable
Reduce energy consumption by slight timetable shifting:
▸ variables = time shift ▸ constraints = energy limit
Industrial partnership with General Electrics
SLIDE 53
Analysis of large graphs of reaction networks in Systems Biology
Model analysis for conservation laws, dead-locks, comparisons between models.
▸ variables = molecules / vertices ▸ constraints = graph structure
Industrial partnership with Dassault Systme
SLIDE 54
Thesis
The design and the implementation of LCC Design Selection of the right logical fragment of linear logic for modular programming, re-use of code, imperative traits... Implementation The LCC compiler (and a compiler for a modular extension of Prolog), with efficient algorithms for proof search Output Compiler for a new programming language for concurrent, imperative and constraint programming. Mono-paradigm: semantics driven by proof theory.
SLIDE 55