Horn clause logic: the knowns and the unknowns Ekaterina - - PowerPoint PPT Presentation

horn clause logic the knowns and the unknowns
SMART_READER_LITE
LIVE PREVIEW

Horn clause logic: the knowns and the unknowns Ekaterina - - PowerPoint PPT Presentation

Horn clause logic: the knowns and the unknowns Ekaterina Komendantskaya School of Mathematical and Computer Sciences, Heriot-Watt University ALCOP17, 11 April 2017 Outline Motivation Outline Motivation The knowns: Inductive and


slide-1
SLIDE 1

Horn clause logic: the knowns and the unknowns

Ekaterina Komendantskaya

School of Mathematical and Computer Sciences, Heriot-Watt University

ALCOP’17, 11 April 2017

slide-2
SLIDE 2

Outline

Motivation

slide-3
SLIDE 3

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP

slide-4
SLIDE 4

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP

slide-5
SLIDE 5

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution

slide-6
SLIDE 6

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value

slide-7
SLIDE 7

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value New “unknowns”: the future work

slide-8
SLIDE 8

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value New “unknowns”: the future work

slide-9
SLIDE 9

The Semantic triangle [Lambek and Scott]

Some Logic Categorical Semantics Operational Semantics Type-theoretic Semantics

slide-10
SLIDE 10

This talk:

Horn Clause Logic ? ? ?

slide-11
SLIDE 11

This talk:

Horn Clause Logic ? ? ?

  • ◮ Horn clause logic is a fragment of predicate logic, in which all

formulae are written in clausal form.

slide-12
SLIDE 12

This talk:

Horn Clause Logic ? ? ?

  • ◮ Horn clause logic is a fragment of predicate logic, in which all

formulae are written in clausal form.

◮ Turing complete if taken as a programming language.

slide-13
SLIDE 13

This talk:

Horn Clause Logic ? ? ?

  • ◮ Horn clause logic is a fragment of predicate logic, in which all

formulae are written in clausal form.

◮ Turing complete if taken as a programming language. ◮ Logician A. Horn first pointed out its significance in 1951.

slide-14
SLIDE 14

Syntax of Horn-clause Logic

First-order signature Σ and terms, term-trees

◮ function symbols with arity; ◮ variables.

Example

◮ stream – arity 1 ◮ scons – arity 2

Term-trees are trees over Σ∪V , subject to branching ≈ arity:

stream scons x y

slide-15
SLIDE 15

Sets of terms:

Term(Σ) Set of finite term trees over Σ Term∞(Σ) Set of infinite term trees over Σ Termω(Σ) Set of finite and infinite term trees over Σ

slide-16
SLIDE 16

Sets of terms:

Term(Σ) Set of finite term trees over Σ Term∞(Σ) Set of infinite term trees over Σ Termω(Σ) Set of finite and infinite term trees over Σ GTerm(Σ), GTerm∞(Σ), GTermω(Σ) will denote sets of ground (variable free) terms.

slide-17
SLIDE 17

Syntax of Horn-clause Logic

Horn Clauses

Given A,B1,...,Bn ∈ Term(Σ),

◮ a definite clause A ← B1,...,Bk ◮ a goal clause ← B1,...,Bk

Universal quantification is assumed.

A (definite) logic program is a finite set of definite clauses

... Gives us a Turing-complete programming language.

slide-18
SLIDE 18

Example: lists of natural numbers

Example

nat(0) ← nat(s(x)) ← nat(x) list(nil) ← list(cons(x,y)) ← nat(x), list(y)

slide-19
SLIDE 19

Why Horn clause Logic?

Well-defined model-theoretic properties:

◮ clean denotational (least and greatest) fixed point semantics.

(Fixpoint construction for a monotone functor ´ a la Knaster-Tarski.)

slide-20
SLIDE 20

Why Horn clause Logic?

Well-defined model-theoretic properties:

◮ clean denotational (least and greatest) fixed point semantics.

(Fixpoint construction for a monotone functor ´ a la Knaster-Tarski.)

Sweet spot between expressivity and automation:

◮ It is long known to yield efficient proofs by resolution

◮ logic of choice for first implementations of Prolog in 70s and

80s;

◮ and many resolution-based provers in the 90s.

◮ SLD-resolution is not just sound but also complete relative to

the least fixed point semantics.

slide-21
SLIDE 21

Logic Programming...

SLD resolution = Unification + Search

Given a logic program P, and terms t1,...,ti,...,tn we define

◮ SLD-reduction: P ⊢ [t1,...,ti,...,tn]

[σ(t1),...,σ(B0),...,σ(Bm),...,σ(tn)] if A ← B1,...,Bm ∈ P, and ti ∼σ A.

slide-22
SLIDE 22

SLD-resolution

Program NatList:

Example

1.nat(0) ← 2.nat(s(x)) ← nat(x) 3.list(nil) ← 4.list(cons(x,y)) ← nat(x), list(y) list(cons(x,y))

slide-23
SLIDE 23

SLD-resolution

Example

1.nat(0) ← 2.nat(s(x)) ← nat(x) 3.list(nil) ← 4.list(cons(x,y)) ← nat(x), list(y) list(cons(x,y)) nat(x),list(y)

slide-24
SLIDE 24

SLD-resolution

Example

1.nat(0) ← 2.nat(s(x)) ← nat(x) 3.list(nil) ← 4.list(cons(x,y)) ← nat(x), list(y) list(cons(x,y)) nat(x),list(y) list(y)

slide-25
SLIDE 25

SLD-resolution

Example

1.nat(0) ← 2.nat(s(x)) ← nat(x) 3.list(nil) ← 4.list(cons(x,y)) ← nat(x), list(y) list(cons(x,y)) nat(x),list(y) list(y) / The answer is “Yes”, NatList ⊢ list(cons(x,y)) if x/0, y/nil, but we can get more substitutions by backtracking. SLD-refutation = finite successful SLD-derivation.

slide-26
SLIDE 26

Why Horn clause Logic?

In 2000s, emerged as a unifying language of ATP:

◮ allows elegant extensions to constraint LP and other enriched

variants;

◮ a neat connection to Hoare Logic was discovered in 1987; ◮ in 2000s, Horn constraints have been shown to relate to Craig

interpolation, which is one of the main techniques used to construct and refine abstractions in verification, and to synthesise inductive loop invariants;

◮ from 2010 onwards, increasingly used in SMT-solvers, model

checkers, abstract interpretation (Bjorner, Rybalchenko);

◮ higher-order Horn clauses are used in model checkers of

functional languages (Ong, Kobayashi)

slide-27
SLIDE 27

Why Horn clause logic?

Neat connection to intuitionistic logic.

◮ In 1989, Girard suggested to use the cut rule to model

resolution for Horn formulas.

◮ In the 1990s, Miller et. al. use cut-free sequent calculus to

represent proofs in Horn clause logic.

◮ Interactive theorem prover Twelf (by Pfenning et al.)

pioneered implementation of proof search for Horn clause logic on top of a dependently typed system called LF (Harper & Licata).

◮ In 2016, Fu&Komendantskaya gave a Horn clause-as-types

(proofs as terms in STLC) interpretation to a fragment of Horn clause logic.

slide-28
SLIDE 28

Why Horn clause Logic?

Applications in Programming languages, via type inference

◮ Type classes in Haskell (Jones, 90s, ext. 2000s) ◮ GADTs in Haskell (Stuckey, Schrijvers, et al. late 90s

  • nwards)

◮ Type Classes in Coq and SSReflect (Ziliani, Gonthier et al.

2014)

◮ Class inference in Java (Ancona et al, 2000s)

slide-29
SLIDE 29

Relation of type classes to Horn Clause logic

class Eq x where eq :: Eq x => x -> x -> Bool instance (Eq x, Eq y) => Eq (x, y) where eq (x1, y1) (x2, y2) = eq x1 x2 && eq y1 y2 instance Eq Int where eq x y = primtiveIntEq x y

slide-30
SLIDE 30

Relation of type classes to Horn Clause logic

class Eq x where eq :: Eq x => x -> x -> Bool instance (Eq x, Eq y) => Eq (x, y) where eq (x1, y1) (x2, y2) = eq x1 x2 && eq y1 y2 instance Eq Int where eq x y = primtiveIntEq x y This translates into the following logic program: Eq (x),Eq (y) ⇒ Eq(x,y) ⇒ Eq (Int)

slide-31
SLIDE 31

Relation of type classes to Horn Clause logic

class Eq x where eq :: Eq x => x -> x -> Bool instance (Eq x, Eq y) => Eq (x, y) where eq (x1, y1) (x2, y2) = eq x1 x2 && eq y1 y2 instance Eq Int where eq x y = primtiveIntEq x y This translates into the following logic program: Eq (x),Eq (y) ⇒ Eq(x,y) ⇒ Eq (Int) Resolve the query ? Eq (Int,Int).

◮ We have the following reduction by SLD-resolution:

Φ ⊢ Eq (Int,Int) → Eq (Int),Eq (Int) → Eq (Int) → /

slide-32
SLIDE 32

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value New “unknowns”: the future work

slide-33
SLIDE 33

Inductive semantics of LP, 70s

Horn Clause Logic Least Herbrand models Big Step semantics SLD-resolution ?

slide-34
SLIDE 34

Inductive Semantics of LP

Definition (Big step rule)

P | = σ(B1),...,P | = σ(Bn) P | = σ(A) , for some grounding substitution σ, and A ← B1,...Bn ∈ P.

Definition

The least Herbrand model for P is the smallest set MP ⊆ GTerm(Σ) closed forward under the rules.

Example

Taking the logic program Nat, we obtain the set MNat = {nat(0), nat(s(0)),nat(s(s(0))),...}.

slide-35
SLIDE 35

Least Herbrand models as a least fixed point construction

Definition

The function TP : P(GTerm(Σ)) → P(GTerm(Σ)) is defined by TP(A) = A∪{θ(t) ∈ GTerm(Σ) | t ← t1,...,tn ∈ P and each θ(ti) ∈ A }.

Definition

The least Herbrand model for P ∈ LP(Σ) is the smallest set MP ∈ P(GTerm(Σ)) such that

◮ if a clause A ←∈ P then θ(A) ∈ MP for every substitution θ

such that θ(A) ∈ GTerm(Σ), and

◮ TP(MP) = MP.

slide-36
SLIDE 36

Soundness and Completeness

[70s: Apt, van Emden, Kowalski]

Theorem (Soundness and Completeness of Derivations)

  • Soundness. Given a logic program P, and an atom A, if there is

an SLD-refutation for P and ← A, then there is a grounding substitution θ, such that θ(A) ∈ MP.

  • Completeness. Given a logic program P, and an atom A ∈ MP,

there is an SLD-refutation for A.

slide-37
SLIDE 37

CoInductive semantics

Horn Clause Logic Greatest Herbrand models Big Step semantics ??? ?

slide-38
SLIDE 38

CoInductive Semantics of LP

Definition (Big step rule)

P | = σ(B1),...,P | = σ(Bn) P | = σ(A) , for some grounding substitution σ, and A ← B1,...Bn ∈ P.

Definition

The greatest complete Herbrand model for P is the largest set Mω

P ⊆ GTermω(Σ) closed backward under the rules.

Example

Nat will now be given by the set:

{nat(0),nat(s(0)),nat(s(s(0))),...}{nat(s(s(...)))}.

slide-39
SLIDE 39

Coinductive programs

Some programs have only one natural interpretation:

Example

1.bit(0) ← 2.bit(1) ← 3.stream(scons(x,y)) ← bit(x), stream(y) MStream = {bit(0),bit(1)} Mω

Stream = {bit(0),bit(1),stream(scons(0,scons(0, ...)),

stream(scons(1,scons(0, ...)),...}

slide-40
SLIDE 40

Coinductive programs

Some programs have only one natural interpretation:

Example

1.bit(0) ← 2.bit(1) ← 3.stream(scons(x,y)) ← bit(x), stream(y) MStream = {bit(0),bit(1)} Mω

Stream = {bit(0),bit(1),stream(scons(0,scons(0, ...)),

stream(scons(1,scons(0, ...)),...} ... now the coinductive semantics does not match with the actual SLD-refutations...

slide-41
SLIDE 41

CoInductive semantics, the 80s

Horn Clause Logic Greatest Herbrand models Big Step semantics SLD-computations at infinity ?

slide-42
SLIDE 42

“ SLD Computations at infinity” [80s, van Emden&Abdallah, Lloyd]

Definition

An infinite term t is SLD-computable at infinity with respect to a program P if there exist a finite term t′ and an infinite fair SLD-derivation G0 = (? ← t′),G1,G2,...Gk ... with mgus θ1,θ2,...θk ... such that d(t,θk ...θ1(t′)) → 0 as k → ∞.

An SLD-derivation is fair if either it is finite, or it is infinite and, for every atom B appearing in some goal in the derivation, (a further instantiated version of) B is chosen within a finite number of steps.

slide-43
SLIDE 43

Example

Program Stream:

Example

1.bit(0) ← 2.bit(1) ← 3.stream(scons(x,y)) ← bit(x), stream(y) stream(scons(x,y)) bit(x),stream(y) stream(y) bit(x1),stream(y1) stream(y1) . . . So far, we have computed that x → 0, y → scons(x1,y1), and x1 → 0. At infinity, the term scons(0,scons(0,...)) is computed.

slide-44
SLIDE 44

Computations at infinity as globally productive computations

Program definition For query ? ← p(x), computes the answer: Models p(x) ← p(x) id {p(a),p(f (a),p(f (f (a)),... p(f ω))} p(x) ← p(f(x)) id {p(a),p(f (a),p(f (f (a)),... p(f ω))} p(f(x)) ← p(x) {x → f(f...)} {p(f ω)}

slide-45
SLIDE 45

Computations at infinity are sound

Defining CP = {t ∈ GTerm∞(Σ) | there exists a term t′ such that t is SLD-computable at infinity with respect to P by t′}.

Theorem (Van Emden&Abdallah, Lloyd, 80s)

Given a P ∈ LP(Σ), CP ⊆ Mω

P .

slide-46
SLIDE 46

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value New “unknowns”: the future work

slide-47
SLIDE 47

Coalgebraic operational semantics, K&Power, 2010-14

Horn Clause Logic Coalgebraic Semantics Small Step semantics SLD-resolution ?

slide-48
SLIDE 48

Fibrational Coalgebraic Semantics of CoALP in 3 ideas

Idea 1: Logic programs as coalgebras Definition

For a functor F, a coalgebra is a pair (U,c) consisting of a set U and a function c : U → F(U).

  • 1. Let At be the set of all atoms appearing in a program P.

Then P can be identified with a Pf Pf -coalgebra (At,p), where p : At − → Pf (Pf (At)) sends an atom A to the set of bodies of those clauses in P with head A.

Example

T ← Q,R T ← S p(T) = {{Q,R},{S}}

slide-49
SLIDE 49

Fibrational Coalgebraic Semantics of CoALP in 3 ideas

Idea 2: Derivations as Comonads

In general, if U : H-coalg − → C has a right adjoint G, the composite functor UG : C − → C possesses the canonical structure

  • f a comonad C(H), called the cofree comonad on H. One can

form a coalgebra for a comonad C(H).

slide-50
SLIDE 50

Fibrational Coalgebraic Semantics of CoALP in 3 ideas

Idea 2: Derivations as Comonads

In general, if U : H-coalg − → C has a right adjoint G, the composite functor UG : C − → C possesses the canonical structure

  • f a comonad C(H), called the cofree comonad on H. One can

form a coalgebra for a comonad C(H).

◮ Taking p : At −

→ Pf Pf (At), the corresponding C(Pf Pf )-coalgebra where C(Pf Pf ) is the cofree comonad on Pf Pf is given as follows: C(Pf Pf )(At) is given by a limit of the form ... − → At ×Pf Pf (At ×Pf Pf (At)) − → At ×Pf Pf (At) − → At. This gives a “tree-like” structure: &V -trees.

slide-51
SLIDE 51

Example

Example

T ← Q,R T ← S Q ← S ← R T Q R S R This models and-or parallel trees known in LP [AMAST 2010]

slide-52
SLIDE 52

Fibrational Coalgebraic Semantics of CoALP in 3 ideas

Idea 3: Add Lawvere Theories to model first-order signature

A Lawvere theory consists of a small category L with strictly associative finite products, and a strict finite-product preserving identity-on-objects functor I : Nop → L.

◮ Take Lawvere Theory LΣ to model the terms over Σ

◮ ob(LΣ) is N. ◮ For each n ∈ Nat, let x1,...,xn be a specified list of distinct

variables.

◮ ob(LΣ)(n,m) is the set of m-tuples (t1,...,tm) of terms

generated by the function symbols in Σ and variables x1,...,xn.

◮ composition in LΣ is first-order substitution.

slide-53
SLIDE 53

Fibrational Coalgebraic Semantics of CoALP in 3 ideas

Idea 3: Add Lawvere Theories to model first-order signature

A Lawvere theory consists of a small category L with strictly associative finite products, and a strict finite-product preserving identity-on-objects functor I : Nop → L.

◮ Take Lawvere Theory LΣ to model the terms over Σ

◮ ob(LΣ) is N. ◮ For each n ∈ Nat, let x1,...,xn be a specified list of distinct

variables.

◮ ob(LΣ)(n,m) is the set of m-tuples (t1,...,tm) of terms

generated by the function symbols in Σ and variables x1,...,xn.

◮ composition in LΣ is first-order substitution.

◮ take the functor At : L op Σ → Set that sends a natural number

n to the set of all atomic formulae generated by Σ and n vars.

slide-54
SLIDE 54

Fibrational Coalgebraic Semantics of CoALP in 3 ideas

Idea 3: Add Lawvere Theories to model first-order signature

A Lawvere theory consists of a small category L with strictly associative finite products, and a strict finite-product preserving identity-on-objects functor I : Nop → L.

◮ Take Lawvere Theory LΣ to model the terms over Σ

◮ ob(LΣ) is N. ◮ For each n ∈ Nat, let x1,...,xn be a specified list of distinct

variables.

◮ ob(LΣ)(n,m) is the set of m-tuples (t1,...,tm) of terms

generated by the function symbols in Σ and variables x1,...,xn.

◮ composition in LΣ is first-order substitution.

◮ take the functor At : L op Σ → Set that sends a natural number

n to the set of all atomic formulae generated by Σ and n vars.

◮ model a program P by the [L op Σ ,Pf Pf ]-coalgebra

p : At − → Pf Pf At on the category [L op

Σ ,Set].

slide-55
SLIDE 55

Final remarks

Actually, some modifications are needed:

◮ we need to extend Set to Poset, ◮ natural transformations to lax natural transformations, and ◮ replace the outer instance of Pf by Pc - the countable

powerset functor (as recursion generates countability).

slide-56
SLIDE 56

Final remarks

Actually, some modifications are needed:

◮ we need to extend Set to Poset, ◮ natural transformations to lax natural transformations, and ◮ replace the outer instance of Pf by Pc - the countable

powerset functor (as recursion generates countability). Then p : At − → PcPf At gives a Lax(L op

Σ ,PcPf )-coalgebra

structure on At.

slide-57
SLIDE 57

Examples

Program Stream: “fibers” given by term arities. Take the fiber of

  • 1. &V -trees:
slide-58
SLIDE 58

Examples

Program Stream: “fibers” given by term arities. Take the fiber of

  • 1. &V -trees:

stream(x)

slide-59
SLIDE 59

Examples

Program Stream: “fibers” given by term arities. Take the fiber of

  • 1. &V -trees:

stream(x) stream(scons(x,x)) bit(x) stream(x)

slide-60
SLIDE 60

Examples

Program Stream: “fibers” given by term arities. Take the fiber of

  • 1. &V -trees:

stream(x) stream(scons(x,x)) bit(x) stream(x) stream(scons(0,scons(x,x))) bit(0) stream(scons(x,x)) bit(x) stream(x)

slide-61
SLIDE 61

Examples

Program p(x) ← p(f (x)): “fibers” given by term arities. Take the fiber of 1. &V -trees:

slide-62
SLIDE 62

Examples

Program p(x) ← p(f (x)): “fibers” given by term arities. Take the fiber of 1. &V -trees: p(x) p(f(x)) p(f(f(x))) ... p(f(x)) p(f(f(x))) p(f(f(f(x)))) ... ...

slide-63
SLIDE 63

Examples

Program p(f (x)) ← p(x): “fibers” given by term arities. Take the fiber of 1. &V -trees:

slide-64
SLIDE 64

Examples

Program p(f (x)) ← p(x): “fibers” given by term arities. Take the fiber of 1. &V -trees: p(x) p(f(x)) p(x) p(f(f(x))) p(f(x)) p(x) ... Whatever it is, it is no longer SLD-resolution!

slide-65
SLIDE 65

Coalgebraic operational semantics, K & Power, 2010-14

Horn Clause Logic Coalgebraic Semantics Small Step semantics ??? ?

slide-66
SLIDE 66

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value New “unknowns”: the future work

slide-67
SLIDE 67

Coalgebraic operational semantics, K&Power, 2010-2014

Horn Clause Logic Coalgebraic Semantics Small Step semantics Structural Resolution ?

slide-68
SLIDE 68

S-resolution reductions

matchers

t ≺σ t′ denotes a matcher of t and t′, i.e. σ(t) = t′

◮ SLD-reduction: P ⊢ [t1,...,ti,...,tn]

[σ(t1),...,σ(B0),...,σ(Bm),...,σ(tn)] if A ← B1,...,Bm ∈ P, and ti ∼σ A.

◮ Term-Matching (Rewriting) reduction:

P ⊢ [t1,...,ti,...,tn] → [t1,...,σ(B0),...,σ(Bm),...,tn] if A ← B1,...,Bm ∈ P, and A ≺σ ti.

slide-69
SLIDE 69

S-resolution reductions

matchers

t ≺σ t′ denotes a matcher of t and t′, i.e. σ(t) = t′

◮ SLD-reduction: P ⊢ [t1,...,ti,...,tn]

[σ(t1),...,σ(B0),...,σ(Bm),...,σ(tn)] if A ← B1,...,Bm ∈ P, and ti ∼σ A.

◮ Term-Matching (Rewriting) reduction:

P ⊢ [t1,...,ti,...,tn] → [t1,...,σ(B0),...,σ(Bm),...,tn] if A ← B1,...,Bm ∈ P, and A ≺σ ti.

◮ Substitutional reduction:

P ⊢ [t1,...,ti,...,tn] ֒ → [σ(t1),...,σ(ti),...,σ(tn)] if A ← B1,...,Bm ∈ P, and ti ∼σ A.

◮ S-resolution reduction: P ⊢ [t] →µ ◦ ֒

→1 [t′]. Then, (P,) is a reduction system that models SLD-reductions for P, and (P,→µ ◦ ֒ →1) is a reduction system that models S-resolution reductions for P.

slide-70
SLIDE 70

Example

1.bit(0) ← 2.bit(1) ← 3.stream(scons(x,y)) ← bit(x), stream(y)

  • 1. SLD-resolution reduction:

[stream(x)] [bit(x′),stream(y)] [stream(y)] [bit(x′′),stream(y′)] ...

  • 2. Term-matching reduction: [stream(x)]
  • 3. S-resolution reduction:

[stream(x)] ֒ →1 [stream(scons(x′,y))] →µ [bit(x′),stream(y)] ֒ →1 [bit(0),stream(y)] →µ [stream(y)] ֒ →1 [stream(scons(x′′,y′))] →µ [bit(x′′),stream(y′)]... Note how term-matching (≈ pattern-matching) behaves for this coinductive program!

slide-71
SLIDE 71

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value New “unknowns”: the future work

slide-72
SLIDE 72

Is S-resolution really interesting?

◮ Inductively sound and complete (relative to least Herbrand

models)

◮ Coinductively sound and complete (relative to

SLD-computations at infinity)

◮ Coinductively sound (relative to greatest Herbrand models)

Relating S-resolution to the Coalgebraic semantics is subtle

◮ first theorems appeared in JLC’16 paper by K&Power; ◮ coalgebraic semantics is further refined in CMCS’16 paper to

allow for closer correspondence;

slide-73
SLIDE 73

What did it teach us?

◮ First ever notion of observational productivity for LP ◮ ...

slide-74
SLIDE 74

Productivity for LP

Observational productivity of a program P is a conjunction of two properties of P:

  • 1. universal observability: termination of all rewriting derivations,

and

  • 2. existential liveness: existence of at least one non-terminating

S-resolution or SLD-resolution derivation. Program definition For query ? ← p(x), com- putes the answer: p(x) ← p(x) id p(x) ← p(f(x)) id p(f(x)) ← p(x) {x → f(f...)} Implementation of the productivity checker is available at https://github.com/coalp

slide-75
SLIDE 75

What did it teach us?

◮ First Ever notion of productivity for LP ◮ Connection of LP to term-rewriting ◮ ...

Given a Horn clause A ← B1,...,Bn get a rewriting rule: A − → κ(B1,...,Bn). Get one-to-one correspondence between rewriting reductions in LP and rewriting in TRS.

slide-76
SLIDE 76

What did it teach us?

◮ First Ever notion of productivity for LP ◮ Connection of LP to term-rewriting via rewriting reductions ◮ Arising natural type-theoretic semantics

slide-77
SLIDE 77

Type Theoretic semantics, Fu and K, 2015-2016

Horn Clause Logic Coalgebraic Semantics Small Step semantics Structural Resolution Horn clauses as Types terms as proofs by rewriting reductions

slide-78
SLIDE 78

Type System for S-resolution

Horn Formulas as Types

Proof evidence as Terms Term t ::= x | K(t1,...,tn) Atomic Formula A,B,C,D ::= P(t1,...,tn) Formula F ::= A | F ⇒ F ′ | ∀x.F Horn Formula/Horn Clause H ::= ∀x.A1,...,An ⇒ B Proof Evidence p,e ::= κ | a | e e′ | λa.e Axioms/Logic Programs Φ ::= · | κ : H,Φ | a : F,Φ

slide-79
SLIDE 79

Type System for S-resolution

Horn Formulas as Types

Proof evidence as Terms Term t ::= x | K(t1,...,tn) Atomic Formula A,B,C,D ::= P(t1,...,tn) Formula F ::= A | F ⇒ F ′ | ∀x.F Horn Formula/Horn Clause H ::= ∀x.A1,...,An ⇒ B Proof Evidence p,e ::= κ | a | e e′ | λa.e Axioms/Logic Programs Φ ::= · | κ : H,Φ | a : F,Φ

Note: finite formulas only

slide-80
SLIDE 80

Simply Typed λ calculus

(κ : H) ∈ Φ Φ ⊢ κ : H Axiom (a : F) ∈ Φ Φ ⊢ a : F Var Φ ⊢ e1 : F1 ⇒ F2 Φ ⊢ e2 : F1 Φ ⊢ e1 e2 : F2 App Φ ⊢ e : ∀x.F Φ ⊢ e : [t/x]F Inst Φ ⊢ e : F Φ ⊢ e : ∀x.F Gen Φ,a : F1 ⊢ e : F2 Φ ⊢ λa.e : F1 ⇒ F2 Abs

The cut rule that models Horn clause resolution is admissible (We can use rules Abs and App to emulate Cut rule): Φ ⊢ e1 : A ⇒ D Φ ⊢ e2 : B,D ⇒ C Φ ⊢ λa.λb.(e2 b) (e1 a) : A,B ⇒ C Cut

slide-81
SLIDE 81

Soundness of SLD and term-matching reductions

◮ If P ⊢ {A} n /

0 , then there exists a proof e : ∀x. ⇒ γA.

◮ If P ⊢ {A} →n /

0 , then there exists a proof e : ∀x. ⇒ A.

Example

κ1 : nat(0) ← κ2 : nat(s(x)) ← nat(x) κ3 : list(nil) ← κ4 : list(cons(x,y)) ← nat(x), list(y)

{list(cons(x,y))} {nat(x),list(y)} {list(y)} / yields a proof (λa.(κ4 a) κ1) κ3 : list(cons(0,nil)) (β-reducible to κ4κ3κ1 : list(cons(0,nil))).

slide-82
SLIDE 82

Type Theoretic semantics, Fu and K, 2015-2016

Horn Clause Logic Coalgebraic Semantics Small Step semantics Structural Resolution (rewriting fragment) Horn clauses as Types terms as proofs by rewriting reductions

slide-83
SLIDE 83

What did it teach us?

◮ First Ever notion of productivity for LP ◮ Connection of LP to term-rewriting via rewriting reductions ◮ Arising natural type-theoretic semantics ◮ Coinduction in LP as an instance of the fixpoint rule

slide-84
SLIDE 84

If we add a fixpoint rule

Φ,(α : A ⇒ B) ⊢ e : A ⇒ B HNF(e) Φ ⊢ να.e : A ⇒ B (Nu)

slide-85
SLIDE 85

If we add a fixpoint rule

Φ,(α : A ⇒ B) ⊢ e : A ⇒ B HNF(e) Φ ⊢ να.e : A ⇒ B (Nu) We can (coinductively) prove p(a) from a program: κ : p(x) ⇒ p(x) :

P;α : p(a) ⊢ α : p(a)

CUT

P;α : p(a) ⊢ κα : p(a)

NU

P ⊢ να.κα : p(a)

slide-86
SLIDE 86

If we add a fixpoint rule

Φ,(α : A ⇒ B) ⊢ e : A ⇒ B HNF(e) Φ ⊢ να.e : A ⇒ B (Nu) We can (coinductively) prove p(a) from a program: κ : p(x) ⇒ p(x) :

P;α : p(a) ⊢ α : p(a)

CUT

P;α : p(a) ⊢ κα : p(a)

NU

P ⊢ να.κα : p(a)

Note: still finite formulas only

slide-87
SLIDE 87

Coinductive Type Theoretic semantics, Fu and K, 2015-2016

Horn Clause Logic Coalgebraic Semantics Small Step semantics Nonterminating Rewriting reductions Horn clauses as Types terms as proofs by fixpoint rule

slide-88
SLIDE 88

Applications in Type inference

◮ Rewriting reductions for Horn clauses are used for type class

inference in Haskell (Fu&K&Schrijvers);

◮ We were able to extend the coinductive proof principle to

extend state-of-the-art in Haskell type class inference with non-terminating resolution.

◮ Work on “Proof relevant resolution” or “Certified Resolution”

(Fu & K, 2016)

slide-89
SLIDE 89

Coinductive Type Theoretic semantics, Farka, K, Hammond, 2016

Horn Clause Logic Greatest Herbrand Models Big Step semantics Nonterminating Rewriting reductions Horn clauses as Types terms as proofs by fixpoint rule

slide-90
SLIDE 90

Outline

Motivation The “knowns”: Inductive and Coinductive Big Step Semantics for LP The “known unknown”: Small Step (Co)algebraic Semantics for LP The “unknown unknown”: Structural resolution Structural resolution: impact and scientific value New “unknowns”: the future work

slide-91
SLIDE 91

Small-step categorical semantics for looping derivations?

Horn Clause Logic Categorical semantics? Small Step semantics Nonterminating Rewriting reductions Horn clauses as Types terms as proofs by fixpoint rule

slide-92
SLIDE 92

Small-step categorical semantics for looping derivations?

Horn Clause Logic Categorical semantics? Small Step semantics Nonterminating Rewriting reductions Horn clauses as Types terms as proofs by fixpoint rule

  • ◮ Rewriting reductions give only universal fragment of Horn

clause logic

◮ Infinite computations result in computation of finite terms

(non-productive computations)

slide-93
SLIDE 93

Type theoretic semantics for full fragment of S-resolution?

Horn Clause Logic Nonterminating S-resolution reductions?

  • Note: existential fragment and infinite terms (productive

computations)

slide-94
SLIDE 94

Type theoretic semantics for full fragment of S-resolution?

Horn Clause Logic ?? Nonterminating S-resolution reductions Horn clauses as Types? terms as proofs by fixpoint rule

  • Note: existential fragment and infinite terms (productive

computations)

slide-95
SLIDE 95

Small-step categorical semantics for looping S-resolution?

Horn Clause Logic Categorical semantics? Small Step semantics Nonterminating S-resolution reductions Horn clauses as Types? terms as proofs by fixpoint rule

slide-96
SLIDE 96

Patterns and copatterns?

Horn Clause Logic Inductive- Coinductive semantics? Big Step semantics Pattern- Copattern resolution Horn clauses as Types? terms as proofs by fixpoint rule

slide-97
SLIDE 97

Your own game?

Horn Clause Logic some categorical semantics? some new proof system? new system for Horn clauses as Types

slide-98
SLIDE 98

Your own game?

Horn Clause Logic some categorical semantics? some new proof system? new system for Horn clauses as Types

  • ◮ Horn clause logic is a researcher’s treasure chest

◮ Coinduction in Horn clause logic is still not well understood

(!!!)

◮ Impact of this research is high, due to continuing development

  • f Horn clause logic in Automated Theorem Proving and

Programming Language implementations

slide-99
SLIDE 99

Thank you!