Relation Algebra, Allegories, and Logic Programming Emilio Jess - - PowerPoint PPT Presentation

relation algebra allegories and logic programming
SMART_READER_LITE
LIVE PREVIEW

Relation Algebra, Allegories, and Logic Programming Emilio Jess - - PowerPoint PPT Presentation

Relation Algebra, Allegories, and Logic Programming Emilio Jess Gallego Arias [joint work with J. Lipton, J. Mario] CRI-Mines ParisTech Deducteam Seminar 17/10/2014 Paris EJGA (CRI-Mines) Allegories and CLP 09/22/2013 1 / 35


slide-1
SLIDE 1

Relation Algebra, Allegories, and Logic Programming

Emilio Jesús Gallego Arias

[joint work with J. Lipton, J. Mariño]

CRI-Mines ParisTech

Deducteam Seminar 17/10/2014 — Paris

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 1 / 35

slide-2
SLIDE 2

Recall (Basic) Logic Programming

Computation ≡ Proof Search

Basics Program (Γ), query (∃

  • x. ϕ), provability relation (⊢).

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 2 / 35

slide-3
SLIDE 3

Recall (Basic) Logic Programming

Computation ≡ Proof Search

Basics Program (Γ), query (∃

  • x. ϕ), provability relation (⊢).

Execution Find a proof of Γ ⊢ ∃

  • x. ϕ.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 2 / 35

slide-4
SLIDE 4

Recall (Basic) Logic Programming

Computation ≡ Proof Search

Basics Program (Γ), query (∃

  • x. ϕ), provability relation (⊢).

Execution Find a proof of Γ ⊢ ∃

  • x. ϕ.

Output Witnesses a for

  • x. Possibly fresh variables in

a!

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 2 / 35

slide-5
SLIDE 5

Recall (Basic) Logic Programming

Computation ≡ Proof Search

Basics Program (Γ), query (∃

  • x. ϕ), provability relation (⊢).

Execution Find a proof of Γ ⊢ ∃

  • x. ϕ.

Output Witnesses a for

  • x. Possibly fresh variables in

a!

Example

add(0, X, X). (∀X) add(X+1, Y, Z+1) <- add(X, Y, Z). (∀XYZ)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 2 / 35

slide-6
SLIDE 6

Recall (Basic) Logic Programming

Computation ≡ Proof Search

Basics Program (Γ), query (∃

  • x. ϕ), provability relation (⊢).

Execution Find a proof of Γ ⊢ ∃

  • x. ϕ.

Output Witnesses a for

  • x. Possibly fresh variables in

a!

Example

add(0, X, X). (∀X) add(X+1, Y, Z+1) <- add(X, Y, Z). (∀XYZ) ?- add(3, X, 4). {X = 1} ? ; no more

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 2 / 35

slide-7
SLIDE 7

Recall (Basic) Logic Programming

Computation ≡ Proof Search

Basics Program (Γ), query (∃

  • x. ϕ), provability relation (⊢).

Execution Find a proof of Γ ⊢ ∃

  • x. ϕ.

Output Witnesses a for

  • x. Possibly fresh variables in

a!

Example

add(0, X, X). (∀X) add(X+1, Y, Z+1) <- add(X, Y, Z). (∀XYZ) ?- add(3, X, 4). {X = 1} ? ; no more ?- add(X, Y, Z). {X = o, Z = Y ?} ; {X = s(o), Z = s(Y) ? } [more]

Constraints: primitive class of formulas solved externally.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 2 / 35

slide-8
SLIDE 8

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-9
SLIDE 9

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-10
SLIDE 10

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

Example

nat(o) ← ⊤ nat(s(X)) ← nat(X)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-11
SLIDE 11

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

Example

nat(o) ← ⊤ ∀ X .nat(s(X)) ← nat(X)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-12
SLIDE 12

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

Example

nat(o) ← ⊤ ∀ X .nat(s(X)) ← nat(X) Point-free means no variables: nat = {o} ∪ s · nat

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-13
SLIDE 13

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

Example

nat(o) ← ⊤ ∀ X .nat(s(X)) ← nat(X) Point-free means no variables: nat = {o, s(o)} ∪ s · s · nat and equational program reasoning

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-14
SLIDE 14

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

Example

nat(o) ← ⊤ ∀ X .nat(s(X)) ← nat(X) Point-free means no variables: nat = {o, s(o), s(s(o))} ∪ s · s · s · nat and equational program reasoning

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-15
SLIDE 15

Combinatorial Logic Programming

What is our goal?

To reason about logic programming equationally. (“Point-free style”) proof search

Example

nat(o) ← ⊤ ∀ X .nat(s(X)) ← nat(X) Point-free means no variables: nat = {o, s(o), s(s(o))} ∪ s · s · s · nat and equational program reasoning and proof search: s(s(o)) ∩ nat

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 3 / 35

slide-16
SLIDE 16

An Existential Problem

Why this is hard?

Point-free programming is well studied, what is the problem here?

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 4 / 35

slide-17
SLIDE 17

An Existential Problem

Why this is hard?

Point-free programming is well studied, what is the problem here? Existential variables have global scope in LP .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 4 / 35

slide-18
SLIDE 18

An Existential Problem

Why this is hard?

Point-free programming is well studied, what is the problem here? Existential variables have global scope in LP .

p(s(Y)). %% p(X) :- ∃ Y, X = s(Y) ? p(X).

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 4 / 35

slide-19
SLIDE 19

An Existential Problem

Why this is hard?

Point-free programming is well studied, what is the problem here? Existential variables have global scope in LP .

p(s(Y)). %% p(X) :- ∃ Y, X = s(Y) ? p(X). { X = s(_X13) }

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 4 / 35

slide-20
SLIDE 20

An Existential Problem

Why this is hard?

Point-free programming is well studied, what is the problem here? Existential variables have global scope in LP .

p(s(Y)). %% p(X) :- ∃ Y, X = s(Y) ? p(X). { X = s(_X13) }

Two proof witnesses for p may not be equal, given it has the “power” to generate a fresh variable every time it has to be proved.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 4 / 35

slide-21
SLIDE 21

An Existential Problem

Why this is hard?

Point-free programming is well studied, what is the problem here? Existential variables have global scope in LP .

p(s(Y)). %% p(X) :- ∃ Y, X = s(Y) ? p(X). { X = s(_X13) }

Two proof witnesses for p may not be equal, given it has the “power” to generate a fresh variable every time it has to be proved. Quantifiers capture this, but use variables! Also, operational reasoning involves tricky renaming apart, etc. . .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 4 / 35

slide-22
SLIDE 22

An Existential Problem

Why this is hard?

Point-free programming is well studied, what is the problem here? Existential variables have global scope in LP .

p(s(Y)). %% p(X) :- ∃ Y, X = s(Y) ? p(X). { X = s(_X13) }

Two proof witnesses for p may not be equal, given it has the “power” to generate a fresh variable every time it has to be proved. Quantifiers capture this, but use variables! Also, operational reasoning involves tricky renaming apart, etc. . .

Use an algebraic theory of logic and quantification!

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 4 / 35

slide-23
SLIDE 23

Relation Algebra to the Rescue!

Distributive Relation Algebras

Operations ∩, ∪, (·)◦, ·; · satisfying the intended laws of binary relations. Introduced by Peirce-Schröder in the 19th century, and further developed by Tarski and his students in mid 20th century.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 5 / 35

slide-24
SLIDE 24

Relation Algebra to the Rescue!

Distributive Relation Algebras

Operations ∩, ∪, (·)◦, ·; · satisfying the intended laws of binary relations. Introduced by Peirce-Schröder in the 19th century, and further developed by Tarski and his students in mid 20th century.

Relations and Logic

∩ as ∧ and ∪ as ∨; limited to formulas with at most 3 variables!

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 5 / 35

slide-25
SLIDE 25

Relation Algebra to the Rescue!

Distributive Relation Algebras

Operations ∩, ∪, (·)◦, ·; · satisfying the intended laws of binary relations. Introduced by Peirce-Schröder in the 19th century, and further developed by Tarski and his students in mid 20th century.

Relations and Logic

∩ as ∧ and ∪ as ∨; limited to formulas with at most 3 variables!

Extended Relation Algebras

QRA: add (quasi) projections hd, tl; no limit on variables. Freyd-Maddux-Tarski: QRA capture set theory (“equipollent”).

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 5 / 35

slide-26
SLIDE 26

Relation Algebra to the Rescue!

Distributive Relation Algebras

Operations ∩, ∪, (·)◦, ·; · satisfying the intended laws of binary relations. Introduced by Peirce-Schröder in the 19th century, and further developed by Tarski and his students in mid 20th century.

Relations and Logic

∩ as ∧ and ∪ as ∨; limited to formulas with at most 3 variables!

Extended Relation Algebras

QRA: add (quasi) projections hd, tl; no limit on variables. Freyd-Maddux-Tarski: QRA capture set theory (“equipollent”).

Allegories

Due to Freyd. We use it as a typed RA, better for our purposes.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 5 / 35

slide-27
SLIDE 27

The Plan

Compile, interpret and execute CLP to a QRA: Semantics (set of true instances):

QRAΣ. Σ-allegories.

Translation, logical meta-aspects and variables formalized at the relational level.

Program to theory between ground terms. Program to allegory. Sharing and memory is captured.

Execution: Two notions of rewriting. Executable semantics. Many extensions and optimizations possible declaratively: partial evaluation, abstract interpretation, different search strategies. . .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 6 / 35

slide-28
SLIDE 28

The Plan

Compile, interpret and execute CLP to a QRA: Semantics (set of true instances):

QRAΣ. Σ-allegories.

Translation, logical meta-aspects and variables formalized at the relational level.

Program to theory between ground terms. Program to allegory. Sharing and memory is captured.

Execution: Two notions of rewriting. Executable semantics. Many extensions and optimizations possible declaratively: partial evaluation, abstract interpretation, different search strategies. . .

Logic Without Variables + Logic Programming

Formula = Relation Proof = Equational Derivation

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 6 / 35

slide-29
SLIDE 29

The Plan

Compile, interpret and execute CLP to a QRA: Semantics (set of true instances):

QRAΣ. Σ-allegories.

Translation, logical meta-aspects and variables formalized at the relational level.

Program to theory between ground terms. Program to allegory. Sharing and memory is captured.

Execution: Two notions of rewriting. Executable semantics. Many extensions and optimizations possible declaratively: partial evaluation, abstract interpretation, different search strategies. . .

Logic Without Variables + Logic Programming

Program = Formula = Relation Computation = Proof Search = Equational Derivation

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 6 / 35

slide-30
SLIDE 30

The Plan

Compile, interpret and execute CLP to a QRA: Semantics (set of true instances):

QRAΣ. Σ-allegories.

Translation, logical meta-aspects and variables formalized at the relational level.

Program to theory between ground terms. Program to allegory. Sharing and memory is captured.

Execution: Two notions of rewriting. Executable semantics. Many extensions and optimizations possible declaratively: partial evaluation, abstract interpretation, different search strategies. . .

Logic Without Variables + Logic Programming

Program = Relation Computation = Equational Derivation

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 6 / 35

slide-31
SLIDE 31

The Relational Theory

Assume a signature Σ ≡ {C, F, CP, P} and Constr. Dom. D.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 7 / 35

slide-32
SLIDE 32

The Relational Theory

Assume a signature Σ ≡ {C, F, CP, P} and Constr. Dom. D.

Generate the relational language:

RC = {(a, a) | a ∈ CΣ} RF = {Rf | f ∈ FΣ, } RCP = {r | r ∈ CPΣ} RP = {p | p ∈ PΣ} Ratom ::= RC | RF | RCP | RP | id | di | 1 | 0 | hd | tl RΣ ::= Ratom | RΣ◦ | RΣ ∪ RΣ | RΣ ∩ RΣ | RΣRΣ

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 7 / 35

slide-33
SLIDE 33

The Relational Theory

Assume a signature Σ ≡ {C, F, CP, P} and Constr. Dom. D.

Generate the relational language:

RC = {(a, a) | a ∈ CΣ} RF = {Rf | f ∈ FΣ, } RCP = {r | r ∈ CPΣ} RP = {p | p ∈ PΣ} Ratom ::= RC | RF | RCP | RP | id | di | 1 | 0 | hd | tl RΣ ::= Ratom | RΣ◦ | RΣ ∪ RΣ | RΣ ∩ RΣ | RΣRΣ

Interpretation

· : RΣ → P(D† × D†), where D† = ∪nDn.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 7 / 35

slide-34
SLIDE 34

The Relational Theory

Assume a signature Σ ≡ {C, F, CP, P} and Constr. Dom. D.

Generate the relational language:

RC = {(a, a) | a ∈ CΣ} RF = {Rf | f ∈ FΣ, } RCP = {r | r ∈ CPΣ} RP = {p | p ∈ PΣ} Ratom ::= RC | RF | RCP | RP | id | di | 1 | 0 | hd | tl RΣ ::= Ratom | RΣ◦ | RΣ ∪ RΣ | RΣ ∩ RΣ | RΣRΣ

Interpretation

· : RΣ → P(D† × D†), where D† = ∪nDn.

Example

≤ = {(m, n u, m, n u′) | m ≤ n; m, n ∈ R, u, u′ ∈ D†}

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 7 / 35

slide-35
SLIDE 35

The Relational Theory

Assume a signature Σ ≡ {C, F, CP, P} and Constr. Dom. D.

Generate the relational language:

RC = {(a, a) | a ∈ CΣ} RF = {Rf | f ∈ FΣ, } RCP = {r | r ∈ CPΣ} RP = {p | p ∈ PΣ} Ratom ::= RC | RF | RCP | RP | id | di | 1 | 0 | hd | tl RΣ ::= Ratom | RΣ◦ | RΣ ∪ RΣ | RΣ ∩ RΣ | RΣRΣ

Interpretation

· : RΣ → P(D† × D†), where D† = ∪nDn.

Example

≤ = {(m, n u, m, n u′) | m ≤ n; m, n ∈ R, u, u′ ∈ D†} add = {(m, n, o u, m, n, o u′) | m + n = o; m, n, o ∈ N, u, u′ ∈ D†}

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 7 / 35

slide-36
SLIDE 36

Translation Overview: Helpers

Projections and Permutations

Pi is the relation projecting the i-th component of a vector; given a permutation π, Wπ is the associated relation.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 8 / 35

slide-37
SLIDE 37

Translation Overview: Helpers

Projections and Permutations

Pi is the relation projecting the i-th component of a vector; given a permutation π, Wπ is the associated relation.

Partial Identity and Existential Quantification

The quasi-identity relation Qi is such that ( u, v) ∈ Qi if the all but i-th component of u and v agree.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 8 / 35

slide-38
SLIDE 38

Translation Overview: Helpers

Projections and Permutations

Pi is the relation projecting the i-th component of a vector; given a permutation π, Wπ is the associated relation.

Partial Identity and Existential Quantification

The quasi-identity relation Qi is such that ( u, v) ∈ Qi if the all but i-th component of u and v agree. Wrapping a relation R in QiRQi has the logical effect of existentially quantifying i! Qi; R · · · S

i−private forR···S

; Qi

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 8 / 35

slide-39
SLIDE 39

Translation Overview: Helpers

Projections and Permutations

Pi is the relation projecting the i-th component of a vector; given a permutation π, Wπ is the associated relation.

Partial Identity and Existential Quantification

The quasi-identity relation Qi is such that ( u, v) ∈ Qi if the all but i-th component of u and v agree. Wrapping a relation R in QiRQi has the logical effect of existentially quantifying i! Qi; R · · · S

i−private forR···S

; Qi We’ll also use a variation of Qi, In that “hides” all the elements greater than n.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 8 / 35

slide-40
SLIDE 40

Translation Overview [1/3]: Terms

Key Idea

A term t[ x] ∈ TΣ(X ) is translated to a relation between all its ground instances and instantiations for x:

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 9 / 35

slide-41
SLIDE 41

Translation Overview [1/3]: Terms

Key Idea

A term t[ x] ∈ TΣ(X ) is translated to a relation between all its ground instances and instantiations for x: (b, a u) ∈ K(t[ x])D† ⇐ ⇒ b = tD[ a/ x]

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 9 / 35

slide-42
SLIDE 42

Translation Overview [1/3]: Terms

Key Idea

A term t[ x] ∈ TΣ(X ) is translated to a relation between all its ground instances and instantiations for x: (b, a u) ∈ K(t[ x])D† ⇐ ⇒ b = tD[ a/ x]

Formally:

K(t) : TΣ(X ) → RΣ =      (c, c)1 if t ≡ c P◦

i

if t ≡ xi

  • i≤n f r

i K(ti)

if t ≡ f(t1, . . . , tn)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 9 / 35

slide-43
SLIDE 43

Translation Overview [1/3]: Terms

Key Idea

A term t[ x] ∈ TΣ(X ) is translated to a relation between all its ground instances and instantiations for x: (b, a u) ∈ K(t[ x])D† ⇐ ⇒ b = tD[ a/ x]

Formally:

K(t) : TΣ(X ) → RΣ =      (c, c)1 if t ≡ c P◦

i

if t ≡ xi

  • i≤n f r

i K(ti)

if t ≡ f(t1, . . . , tn)

Example

K(f(x1, g(x2, a, h(x1)))) = f 2

1 ; P◦ 1 ∩ f 2 1 ; (g3 1; P◦ 2 ∩ g2 1; (a, a); 1 ∩ g3 3; h; P◦ 1)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 9 / 35

slide-44
SLIDE 44

Translation Overview [2/3]: Constraints

Key Idea

A constraint ϕ[ x] ∈ LD is translated to the set of all its ground solutions, encoded as a coreflexive relation:

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 10 / 35

slide-45
SLIDE 45

Translation Overview [2/3]: Constraints

Key Idea

A constraint ϕ[ x] ∈ LD is translated to the set of all its ground solutions, encoded as a coreflexive relation:

( a u, a u′) ∈ ˙ K(ϕ[ x])D† ⇐ ⇒ D | = ϕ[ a/ x]

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 10 / 35

slide-46
SLIDE 46

Translation Overview [2/3]: Constraints

Key Idea

A constraint ϕ[ x] ∈ LD is translated to the set of all its ground solutions, encoded as a coreflexive relation:

( a u, a u′) ∈ ˙ K(ϕ[ x])D† ⇐ ⇒ D | = ϕ[ a/ x]

Formally:

˙ K(t) : LD → RΣ =      K(

  • t)◦; p; K(
  • t)

if ϕ ≡ p(

  • t)

˙ K(ϕ) ∩ ˙ K(θ) if ϕ ≡ ϕ ∧ θ Qi; ˙ K(ϕ); Qi if ϕ ≡ ∃xi. ϕ

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 10 / 35

slide-47
SLIDE 47

Translation Overview [2/3]: Constraints

Key Idea

A constraint ϕ[ x] ∈ LD is translated to the set of all its ground solutions, encoded as a coreflexive relation:

( a u, a u′) ∈ ˙ K(ϕ[ x])D† ⇐ ⇒ D | = ϕ[ a/ x]

Formally:

˙ K(t) : LD → RΣ =      K(

  • t)◦; p; K(
  • t)

if ϕ ≡ p(

  • t)

˙ K(ϕ) ∩ ˙ K(θ) if ϕ ≡ ϕ ∧ θ Qi; ˙ K(ϕ); Qi if ϕ ≡ ∃xi. ϕ

Example

˙ K(∃x1x2.s(x1) ≤ x2) = Q1Q2; (P◦

1; s◦; P1 ∩ P◦ 2; P2); ≤; (P1; s; P◦ 1 ∩ P2; P◦ 2); Q1Q2

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 10 / 35

slide-48
SLIDE 48

Translation Overview [3/3]: Predicates

Key Idea

Defined predicates p are translated to equations p ⊜ R.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 11 / 35

slide-49
SLIDE 49

Translation Overview [3/3]: Predicates

Key Idea

Defined predicates p are translated to equations p ⊜ R.

Theorem (Adequacy)

( a u, a u′) ∈ pD† ⇐ ⇒ p( a) ∈ T ω

P

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 11 / 35

slide-50
SLIDE 50

Translation Overview [3/3]: Predicates

Key Idea

Defined predicates p are translated to equations p ⊜ R.

Theorem (Adequacy)

( a u, a u′) ∈ pD† ⇐ ⇒ p( a) ∈ T ω

P

The Procedure

1 Purify clause’ heads, canonical renaming, Clark completion. 2 The Relational Step!

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 11 / 35

slide-51
SLIDE 51

Translation Overview [3/3]: Predicates

Key Idea

Defined predicates p are translated to equations p ⊜ R.

Theorem (Adequacy)

( a u, a u′) ∈ pD† ⇐ ⇒ p( a) ∈ T ω

P

The Procedure

1 Purify clause’ heads, canonical renaming, Clark completion. 2 The Relational Step!

add(x1, x2, x3) ← x1 = o, x2 = x3. add(x1, x2, x3) ← x1 = s(x4), x3 = s(x5), add(x4, x2, x5).

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 11 / 35

slide-52
SLIDE 52

Translation Overview [3/3]: Predicates

Key Idea

Defined predicates p are translated to equations p ⊜ R.

Theorem (Adequacy)

( a u, a u′) ∈ pD† ⇐ ⇒ p( a) ∈ T ω

P

The Procedure

1 Purify clause’ heads, canonical renaming, Clark completion. 2 The Relational Step!

add(x1, x2, x3) ← x1 = o, x2 = x3. add(x1, x2, x3) ← x1 = s(x4), x3 = s(x5), add(x4, x2, x5). add = ˙ K(x1 = o ∧ x2 = x3) ∪ I3; ˙ K(x1 = s(x4) ∧ x3 = s(x5)); W; add; W ◦; I3

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 11 / 35

slide-53
SLIDE 53

Program Execution

Relations and Computation

r ∧ (s ∨ t) ↔ r ∧ s ∨ r ∧ t R ∩ (S ∪ T) = (R ∩ S) ∪ (R ∩ T)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 12 / 35

slide-54
SLIDE 54

Program Execution

Relations and Computation

r ∧ (s ∨ t) ↔ r ∧ s ∨ r ∧ t R ∩ (S ∪ T) = (R ∩ S) ∪ (R ∩ T) Computation rule R ∩ (S ∪ T) → (R ∩ S) ∪ (R ∩ T)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 12 / 35

slide-55
SLIDE 55

Program Execution

Relations and Computation

r ∧ (s ∨ t) ↔ r ∧ s ∨ r ∧ t R ∩ (S ∪ T) = (R ∩ S) ∪ (R ∩ T) Computation rule R ∩ (S ∪ T) → (R ∩ S) ∪ (R ∩ T) Cut rule S ∪ T ⊇ S S ∪ T → S

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 12 / 35

slide-56
SLIDE 56

Program Execution

Relations and Computation

r ∧ (s ∨ t) ↔ r ∧ s ∨ r ∧ t R ∩ (S ∪ T) = (R ∩ S) ∪ (R ∩ T) Computation rule R ∩ (S ∪ T) → (R ∩ S) ∪ (R ∩ T) Cut rule S ∪ T ⊇ S S ∪ T → S

Queries

For executing a query, we just intersect and rewrite, for instance for add(o, o, o): ˙ K(x1 = x2 = x3 = o) ∩ add

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 12 / 35

slide-57
SLIDE 57

Rewriting and the Modular Law

Some Sample Rules

0 ∪ R

P

− → R 0 ∩ R

P

− → 0 (R ∪ S) ∩ T

P

− → (R ∩ T) ∪ (S ∩ T)

Meta Rules

Calls to the constraint solver are modeled by meta-rewriting rules: ˙ K(ψ1) ∩ ˙ K(ψ2) → ˙ K(ψ1 ∧ ψ2)

Procedure Call: The Modular Law

˙ K(ψ) ∩ Im(R)

P

− → Im(Im( ˙ K(ψ)) ∩ R) ∩ ˙ K(ψ)

We hide variables in ψ that may be in conflict with variables in R, but we need to “unhide” them later.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 13 / 35

slide-58
SLIDE 58

Example Execution

Query: add(o,s(o),X) 1 I3 ˙ K(o, s(o), x3)I3 ∩ add →

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 14 / 35

slide-59
SLIDE 59

Example Execution

Query: add(o,s(o),X) 1 I3 ˙ K(o, s(o), x3)I3 ∩ add → 2 I3 ˙ K(o, s(o), x3)I3 ∩ ( ˙ K(o, x2, x2) ∪ (I3[ ˙ K(s(x4), x2, s(x5), x4, x5) ∩ W add W ◦]I3)) →

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 14 / 35

slide-60
SLIDE 60

Example Execution

Query: add(o,s(o),X) 1 I3 ˙ K(o, s(o), x3)I3 ∩ add → 2 I3 ˙ K(o, s(o), x3)I3 ∩ ( ˙ K(o, x2, x2) ∪ (I3[ ˙ K(s(x4), x2, s(x5), x4, x5) ∩ W add W ◦]I3)) → 3 I3[ ˙ K(o, s(o), x3) ∩ ˙ K(o, x2, x2)]I3 ∪ I3( ˙ K(o, s(o), x3) ∩ ˙ K(s(x4), x2, s(x5), x4, x5)∩ W add W ◦)I3 →

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 14 / 35

slide-61
SLIDE 61

Example Execution

Query: add(o,s(o),X) 1 I3 ˙ K(o, s(o), x3)I3 ∩ add → 2 I3 ˙ K(o, s(o), x3)I3 ∩ ( ˙ K(o, x2, x2) ∪ (I3[ ˙ K(s(x4), x2, s(x5), x4, x5) ∩ W add W ◦]I3)) → 3 I3[ ˙ K(o, s(o), x3) ∩ ˙ K(o, x2, x2)]I3 ∪ I3( ˙ K(o, s(o), x3) ∩ ˙ K(s(x4), x2, s(x5), x4, x5)∩ W add W ◦)I3 → 4 ˙ K(o, s(o), s(o)) ∪ I3[0 ∩ W add W ◦]I3 →

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 14 / 35

slide-62
SLIDE 62

Example Execution

Query: add(o,s(o),X) 1 I3 ˙ K(o, s(o), x3)I3 ∩ add → 2 I3 ˙ K(o, s(o), x3)I3 ∩ ( ˙ K(o, x2, x2) ∪ (I3[ ˙ K(s(x4), x2, s(x5), x4, x5) ∩ W add W ◦]I3)) → 3 I3[ ˙ K(o, s(o), x3) ∩ ˙ K(o, x2, x2)]I3 ∪ I3( ˙ K(o, s(o), x3) ∩ ˙ K(s(x4), x2, s(x5), x4, x5)∩ W add W ◦)I3 → 4 ˙ K(o, s(o), s(o)) ∪ I3[0 ∩ W add W ◦]I3 → 5 ˙ K(o, s(o), s(o))

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 14 / 35

slide-63
SLIDE 63

Why move to Categories?

An old thought (2004)

“We need types to run fast and allocate memory for the relations.” Just a implementor’s intuition.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 15 / 35

slide-64
SLIDE 64

Why move to Categories?

An old thought (2004)

“We need types to run fast and allocate memory for the relations.” Just a implementor’s intuition.

Problems of the Pure Relational Approach

Terms and substitution are complex. Duplicity of relational terms

  • everywhere. 6 months of research just for unification.

Difficult to implement. A† = TΣ ∪ T ∗

Σ ∪ (T ∗ Σ )∗ ∪ . . . is a hell of a

data type. Renaming apart is difficult to model and understand. Crucial information is missing the number of variables currently in use. Combinatorial approach: bad for performance. Efficiency is difficult due to duplicity.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 15 / 35

slide-65
SLIDE 65

Allegories versus RA

What is the domain for the relations? Signature? How are variables represented?

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 16 / 35

slide-66
SLIDE 66

Allegories versus RA

What is the domain for the relations?

QRA A single domain TΣ ∪ T ∗

Σ ∪ (T ∗ Σ )∗ ∪ . . . .

Allegory Types represent fixed-length sequences of terms.

Signature? How are variables represented?

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 16 / 35

slide-67
SLIDE 67

Allegories versus RA

What is the domain for the relations?

QRA A single domain TΣ ∪ T ∗

Σ ∪ (T ∗ Σ )∗ ∪ . . . .

Allegory Types represent fixed-length sequences of terms.

Signature?

QRA New relations for every constant and term former. Allegory Freely adjoined arrows.

How are variables represented?

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 16 / 35

slide-68
SLIDE 68

Allegories versus RA

What is the domain for the relations?

QRA A single domain TΣ ∪ T ∗

Σ ∪ (T ∗ Σ )∗ ∪ . . . .

Allegory Types represent fixed-length sequences of terms.

Signature?

QRA New relations for every constant and term former. Allegory Freely adjoined arrows.

How are variables represented?

QRA Untyped projections. Allegory We use categorical projections. In essence, we replace typed projections πN

i : N → 1 for untyped

quasiprojections Pi : A† ↔ A†. A small change with big implications.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 16 / 35

slide-69
SLIDE 69

Categories of Syntax (Lawvere Categories)

Defining the Category

For a signature Σ, we define a Lawvere Category C: Objects are the natural numbers. Terminal object 0, the rest of the

  • bjects are powers of 1, 1x1x1 = 2x1 = 1x2 = 3.

For every constant a ∈ TΣ, we freely adjoin an arrow a : 0 → 1. For every function symbol f ∈ TΣ with arity α(f) = N, we freely adjoin an arrow f : N → 1.

Example

For instance, for Σ = ({o}, {s/1, +/2}), C has all the terminal and product arrows plus o : 0 → 1, s : 1 → 1 and + : 2 → 1.

Initial Model

The initial model is a functor C → Set which preserves finite products and pullbacks. It maps the object 1 to TΣ.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 17 / 35

slide-70
SLIDE 70

Regular Categories, Tabular Relations

Regular Category

Category with products, pullbacks and certain exactness conditions.

Categories of Relations

f : C → A and g : C → B is a monic pair iff f, g : C → A × B is monic, informally, a subset of A × B, thus, (f, g) represent a relation from A to B: C A

f B g

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 18 / 35

slide-71
SLIDE 71

Allegories

Allegories and Distributive Allegories

An (distributive) allegory is a category with added structure, such that if f, g : A → B are arrows, (f ∪ g) f ∩ g : A → B and f ◦ : B → A are arrows and obey the appropriate relational laws. Typed version of relational algebras.

Tabular Allegories

An allegory is tabular if for each morphism R there is a pair of maps f, g, such that R = f ◦; g. We say that (f, g) tabulate R. Regular categories are categories of maps for tabular allegories, thus they generate them. Diagrammatically: C A ✛ R

f

B g

C A ✛ R

✲ ✛

f B g

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 19 / 35

slide-72
SLIDE 72

Regular Lawvere Categories

Pullbacks in Syntax Categories

In C, arrows are freely added. No way of equalizing constants a, b : 0 → 1. C is not a regular category, it lacks pullbacks.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 20 / 35

slide-73
SLIDE 73

Regular Lawvere Categories

Pullbacks in Syntax Categories

In C, arrows are freely added. No way of equalizing constants a, b : 0 → 1. C is not a regular category, it lacks pullbacks.

Regular Completion of C

Adjoin an initial object ⊥ Freely adjoin the corresponding initial arrows ?A : ⊥ → A for every

  • bject A. Apply the quotient ?A; f =?B for any arrow f : A → B.

Now every arrow can be made equal to another, ⊥; a = ⊥; b.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 20 / 35

slide-74
SLIDE 74

Regular Lawvere Categories: Examples

Renaming Apart

In the case of a pullback, every term feeds from a different set of variables, so unification module renaming apart is guaranteed. 2 ✛ id 2 1 π1

❄ ✛

π1 2 id

2 ✛

π1, π2

3 1 π1

❄ ✛

π1 2 π1, π3

So each clause will be translated to feed from the same set of variables.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 21 / 35

slide-75
SLIDE 75

Σ-Allegories

Σ-Allegories

Σ-Allegories are distributive allegories generated from a Regular Lawvere Category for the signature Σ and thus partially tabular. They are the target of our translation.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 22 / 35

slide-76
SLIDE 76

Term Translation

For a sequence of terms x = t[ y], K(

  • t[

y]) is the coreflexive relation: | y| | x| ✛ K(

  • t[

y]) ✲

K

y

(

  • t

) | x| K

y

(

  • t

)

Registers

If we look at a completed clause: p( x′) ← x = t[ y], p1(w1( x)), . . . , pn(wn( x)). it is clear that x = x1, . . . , xn plays the role of parameter registers. Names are eliminated by using t1, . . . , tn.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 23 / 35

slide-77
SLIDE 77

Encoding terms and registers

Correspondence of concepts:

Arrows (tabulations, f, g) Arrays of terms Projections (πi) Pointers Domain of tabulations Free (heap) variables (Yi) Target of tabulations Registers (Xi) Composition of tabulations (f; g) Substitution Intersection Term Unification

Example (Term Storage in Registers)

X1 = f(Y1, Y3) f1 = π1, π3; f X2 = g(Y2, a) f2 = π2, !2; a; g 3 2 ◦ f1, f2◦; f1, f2

f1, f2

2

f1, f2

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 24 / 35

slide-78
SLIDE 78

The Relational Step

Step 1: Local Storage

We previously translated the clause: p( x′) ← x = t[ y], p1(w1( x)), . . . , pn(wn( x)). to p = K(

  • t) ∩ W1; p1; W ◦

1 ∩ · · · ∩ Wn; pn; W ◦ n

but now the number of arguments of | x|, | x′| may not be the same.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 25 / 35

slide-79
SLIDE 79

The Relational Step

Step 1: Local Storage

We previously translated the clause: p( x′) ← x = t[ y], p1(w1( x)), . . . , pn(wn( x)). to p = K(

  • t) ∩ W1; p1; W ◦

1 ∩ · · · ∩ Wn; pn; W ◦ n

but now the number of arguments of | x|, | x′| may not be the same.

Step 2: Environments

We introduce environment creation (and its reciprocal, destruction) relations IMN = π1, . . . , πm◦ : M → N. Now the clause is translated to: IMN; (K(

  • t) ∩ W1; p1; W ◦

1 ∩ · · · ∩ Wn; pn; W ◦ n ); I◦ MN

M are parameters, N − M is the number of local variables.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 25 / 35

slide-80
SLIDE 80

Environment Management

Environments: IMN

We introduce an environment creation (and its reciprocal, destruction) relation IMN = π1, . . . , πm◦ : M → N. (π2

1)◦ : 1 → 2 is the canonical “new”

variable creation relation. 3 2 ✛ I23

✲ ✛

  • π

1

, π

2

  • 3

i d

3

Example (Compile time optimization)

Let two registers in R = π1; f, π1; g : 1 → 2. Compute R◦; R; I23. 2 2 ✛ R; R◦; I23

✲ ✛

  • π

1

; f , π

1

; g

  • 3
  • π

1

; f , π

1

; g , π

2

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 26 / 35

slide-81
SLIDE 81

Intersection and Procedure Call

Coreflexive Arrows

If R, S are coreflexive then R ∩ S = R; S. This is highly convenient, and we may eliminate ∩ and simplify our machine.

Procedure Call

The previous translation is semantically correct translation, but Wi; INK; pi; I◦

NK; W ◦ i : N → N is not in general a coreflexive relation, so

we cannot apply ∩ elimination. We fix this using a correflexive version: (idM−α(pi) × pi)N → N. Then, if Ai = N − α(pi) the final translation is: p = IMN; (K(

  • t); W1; (idA1 × p1); W ◦

1 ; . . . ; Wn; (idAn × pn); W ◦ n ); I◦ MN

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 27 / 35

slide-82
SLIDE 82

Example: Partial Evaluation

Translation of add

add(x1, x2, x3) ← x1 = o, x2 = y1, x3 = y1. add(x1, x2, x3) ← x1 = s(y1), x2 = y2, x3 = s(y3), x4 = y1, x5 = y3, add(x4, x2, x5).

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 28 / 35

slide-83
SLIDE 83

Example: Partial Evaluation

Translation of add

add(x1, x2, x3) ← x1 = o, x2 = y1, x3 = y1. add(x1, x2, x3) ← x1 = s(y1), x2 = y2, x3 = s(y3), x4 = y1, x5 = y3, add(x4, x2, x5). add =

  • , π1, π1◦; o, π1, π1

∪ I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 28 / 35

slide-84
SLIDE 84

Example: Partial Evaluation

Translation of add

add(x1, x2, x3) ← x1 = o, x2 = y1, x3 = y1. add(x1, x2, x3) ← x1 = s(y1), x2 = y2, x3 = s(y3), x4 = y1, x5 = y3, add(x4, x2, x5). add =

  • , π1, π1◦; o, π1, π1

∪ I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

Unfold

Execute add without a query! add =

  • , π1, π1◦; o, π1, π1

  • s, π1, π1s◦; os, π1, π1s

∪ I35; π1ss, π2, π3ss, π1, π3; W; (id2 × add); W ◦; I◦

35

  • etc. . .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 28 / 35

slide-85
SLIDE 85

Composition of tabular relations: the core

M N A

f B

h g

C i

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 29 / 35

slide-86
SLIDE 86

Composition of tabular relations: the core

P M

N

A

f B

h g

C i

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 29 / 35

slide-87
SLIDE 87

Composition of tabular relations: the core

D P

  • M

u

N v

✲ ✲

A

f B

h g

C i

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 29 / 35

slide-88
SLIDE 88

Composition of tabular relations: the core

D P

  • M

u

N v

✲ ✲

A

f B

h g

C i

D A

u ; f C v ; i

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 29 / 35

slide-89
SLIDE 89

Composition of tabular relations: the core

D P

  • M

u

N v

✲ ✲

A

f B

h g

C i

D A

u ; f C v ; i

Composition captures unification, parameter passing, renaming apart, variable allocation and (a form of) garbage collection.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 29 / 35

slide-90
SLIDE 90

The Pullback Algorithm

Definition (Arrow Normalization)

We write →!

R for the associated normalizing relation based on →R:

h; f, g →R h; f, h; g f, g; π1 →R f f, g; π2 →R g f; !N →R !M f : M → N

Definition (Starting Diagram)

For a pullback problem, build the pre-starting diagram P: N × N′ π1; f ✲ π2; g

✲ M

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 30 / 35

slide-91
SLIDE 91

The Pullback Algorithm

The starting diagram is: N + N′ id = π1, . . . , πN+N′

✲ N + N′

f ′

g′

✲ M

f ′ = f1, . . . , fM, g′ = g1, . . . , gM, S = {f1 ≈ g1, . . . , fM ≈ gM}. Initial state (S | π1, . . . , πN+N′). Proceed iteratively: !M; a ≈ !M; b ⇒ Fail !M; a ≈ h; f ⇒ Fail g; f ≈ g′; f ′ ⇒ Fail πi ≈ πj ⇒ (S′ | S(j, πi, h)) πi ≈ g; f ⇒ (S′ | S(i, g; f, h)) !M; a ≈ πi ⇒ (S′ | S(i, !M; a, h)) !M; a ≈ !M; a ⇒ (S′ | h) g; f ≈ g′; f ⇒ ({g1 ≈ g′

1} ∪ · · · ∪ {gn ≈ g′ n} ∪ S′ | h)

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 31 / 35

slide-92
SLIDE 92

Specification of the machine

Diagram Rewriting

Basic diagrams: (f | g), R1 ∪ · · · ∪ Rn and (f | g, [R]). (f | g); (f ′ | g′)

(h,h′)

= = ⇒ (h; f | h′; g′) (f | gK, gN); (idK × pN) = ⇒ (f | gK, [gN; p1]) ∪ . . . ∪ (f | gK, [gN; pn]) (f | g, [(g′ | g′)]) = ⇒ (f | g, g) (f | g, [E]) = ⇒ (h; f | h; g, [E′]) iff E = ⇒ E′ R ∪ S = ⇒ R′ ∪ S iff R = ⇒ R′ 0 ∪ S = ⇒ S

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 32 / 35

slide-93
SLIDE 93

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-94
SLIDE 94

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-95
SLIDE 95

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-96
SLIDE 96

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-97
SLIDE 97

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-98
SLIDE 98

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π2, π3s, π1, π3); W; (id2 × add); W ◦; I◦

35

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-99
SLIDE 99

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π2, π3s, π1, π3); W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, π1, π2, π3); (id2 × add); W ◦; I◦

35

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-100
SLIDE 100

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π2, π3s, π1, π3); W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, π1, π2, π3); (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, [π1, π2, π3; o, π1, π1]; W ◦; I◦

35 ∪ . . .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-101
SLIDE 101

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π2, π3s, π1, π3); W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, π1, π2, π3); (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, [π1, π2, π3; o, π1, π1]; W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1s, [o, π1, π1]; W ◦; I◦

35 ∪ . . .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-102
SLIDE 102

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π2, π3s, π1, π3); W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, π1, π2, π3); (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, [π1, π2, π3; o, π1, π1]; W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1s, [o, π1, π1]; W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1s, o, π1, π1); W ◦; I◦

35 ∪ . . .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-103
SLIDE 103

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π2, π3s, π1, π3); W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, π1, π2, π3); (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, [π1, π2, π3; o, π1, π1]; W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1s, [o, π1, π1]; W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1s, o, π1, π1); W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1, π1s, o, π1); I◦

35 ∪ . . .

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-104
SLIDE 104

The Machine: An Example

A query add(s(X), Y, Z) is translated to π1s, π2, π3; add:

π1s, π2, π3; add ⇒ (π1s, π2, π3; o, π1, π1) ∪ . . . ⇒ 0 ∪ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ π1s, π2, π3; I35; π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3 | π1s, π2, π3, π4, π5); π1s, π2, π3s, π1, π3; W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π2, π3s, π1, π3); W; (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, π1, π2, π3); (id2 × add); W ◦; I◦

35

⇒ (π1s, π2, π3s | π1s, π3s, [π1, π2, π3; o, π1, π1]; W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1s, [o, π1, π1]; W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1s, o, π1, π1); W ◦; I◦

35 ∪ . . .

⇒ (os, π1, π1s | os, π1, π1s, o, π1); I◦

35 ∪ . . .

  • s, π1, π1s ∪ . . .

then os, π1, π1s is translated back to the answer X = o, Z = s(Y).

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 33 / 35

slide-105
SLIDE 105

Future work

Not in this talk:

Extensions: Monads, types, functions. Diagrams. Relational Unification.

Future Work:

Beyond logic logic programming? Other applications? Higher-order types. Coalgebraic derivations [Komendantskaya-Power2011] Full formalization down to the instruction level. Research algebraic optimization. [R; (S ∪ T) = R; S ∪ R; T] New Coq formalization and compiler: at 50%.

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 34 / 35

slide-106
SLIDE 106

The End

Merci pour votre attention. Questions?

EJGA (CRI-Mines) Allegories and CLP 09/22/2013 35 / 35