Towards Coinductive Theory Exploration Katya Komendantskaya (joint - - PowerPoint PPT Presentation
Towards Coinductive Theory Exploration Katya Komendantskaya (joint - - PowerPoint PPT Presentation
Towards Coinductive Theory Exploration Katya Komendantskaya (joint work with Yue Li, Henning Basold, John Power et al.) Workshop WAIT18, 29 June 2018 Outline Problem statement Solution Technical details FOL, Coinductively Any theory
Outline
Problem statement Solution Technical details
FOL, Coinductively
◮ Any theory expressed in FOL may be seen inductively or
coinductively,
◮ Depending on the chosen semantics
For example...
Given a theory in Horn Clause syntax:
G ::= ⊤ | A | G ∧G | G ∨G | ∃Var G D ::= A | G ⊃ D | D ∧D | ∀Var D
Given a theory in Horn Clause syntax:
G ::= ⊤ | A | G ∧G | G ∨G | ∃Var G D ::= A | G ⊃ D | D ∧D | ∀Var D
Coinductive models of theories in Horn Clause logic
◮ Take the sets of (finite and/or infinite) ground terms ◮ The coinductive model is the largest set of such terms such that it
satisfies the given theory
◮ (The Inductive model is the smallest such set) ◮ Usually these models are given by fixed point (Knaster-Tarski)
construction
Given a theory in Horn Clause syntax:
G ::= ⊤ | A | G ∧G | G ∨G | ∃Var G D ::= A | G ⊃ D | D ∧D | ∀Var D
Coinductive models of theories in Horn Clause logic
◮ Take the sets of (finite and/or infinite) ground terms ◮ The coinductive model is the largest set of such terms such that it
satisfies the given theory
◮ (The Inductive model is the smallest such set) ◮ Usually these models are given by fixed point (Knaster-Tarski)
construction least fixed point greatest fixed point finite terms Least Herbrand models Greatest Herbrand models finite and infi- nite terms Least Complete Herbrand models Greatest Complete Herbrand models
Example 1
◮ Both inductive and coinductive semantics may suit
Example
κ1 : ∀x,nat x ⊃ nat (s x) κ2 : nat 0
least fixed point greatest fixed point finite terms {nat 0,nat(s 0),...} {nat 0,nat(s 0),...} finite and infinite terms {nat 0,nat(s 0),...} {nat 0,nat(s 0),...,sω}
Example 2
◮ ... only coinductive semantics may suit
Example
κ1 : ∀x,streamZ x ⊃ streamZ (scons 0 x)
least fixed point greatest fixed point finite terms / / finite and infinite terms / {streamZ(scons 0(scons 0 ...))}
Example 3
◮ Either semantics may work well for certain fragment of the
theory
Example
κ1 : ∀x,nat x ⊃ nat (s x) κ2 : nat 0 κ3 : ∀x,nat x ∧streamN y ⊃ streamN (scons x y)
least fixed point greatest fixed point finite terms {nat 0,nat(s 0),...} {nat 0,nat(s 0),...} finite and infinite terms {nat 0,nat(s 0),...} {nat 0,nat(s 0),...,sω, streamN(scons 0(scons 0 ...)), streamN(scons 0(scons 1 ...)), streamN(scons 1(scons 0 ...)), streamN(scons 1(scons 1 ...)), ...}
Operational semantics:
◮ State of the art is automated invariant discovery by means of
loop detection
Example
∀x,streamZ x ⊃ streamZ (scons 0 x) Resolution-based search: streamZ x x/(scons 0 x′) streamZ x′
◮ Terminate the loop with x = (scons 0 x). ◮ It is the coinductive invariant.
Operational semantics:
◮ State of the art is automated invariant discovery by means of
loop detection
Example
∀x,streamZ x ⊃ streamZ (scons 0 x) Resolution-based search: streamZ x x/(scons 0 x′) streamZ x′
◮ Terminate the loop with x = (scons 0 x). ◮ It is the coinductive invariant.
Recall:
least fixed point greatest fixed point finite terms / / finite and infinite terms / {streamZ(scons 0(scons 0 ...))}
However, loop detection
◮ ... is not a very satisfactory solution
Why unsatisfactory?
1 it fails too often
Example
∀x,from (s x) y ⊃ from x (scons x y) Resolution-based search: from 0 x x/(scons 0 x′) from (s 0) x′
◮ No unifier exists, ◮ loop detection fails to find coinductive invariant
Why unsatisfactory?
1 it fails too often
Example
∀x,from (s x) y ⊃ from x (scons x y) Resolution-based search: from 0 x x/(scons 0 x′) from (s 0) x′
◮ No unifier exists, ◮ loop detection fails to find coinductive invariant
least fixed point greatest fixed point finite terms / / finite and infinite terms / {from 0(scons 0(scons (s0) ...))}
Why unsatisfactory?
2 it is a bad indicator for coinductive meaning of the theory (Works well with existential, but not universal coinductive models )
Universal Coinductive Models
Example
κ1 : ∀x,p(f x) ⊃ p x
least fixed point greatest fixed point finite terms / {p a,p(f a),p(f f a),...} finite and infinite terms / {p a,p(f a),p(f f a),... p f ω }
Universal Coinductive Models
Example
κ1 : ∀x,p(f x) ⊃ p x
least fixed point greatest fixed point finite terms / {p a,p(f a),p(f f a),...} finite and infinite terms / {p a,p(f a),p(f f a),... p f ω }
Invariant search: p x → p(f x) → p(f f x) → ...
◮ The answer is: x = f x. ◮ However, f ω is not all that there is in the model!
Universal Coinductive Models
Example
κ1 : ∀x,p(f x) ⊃ p x
least fixed point greatest fixed point finite terms / {p a,p(f a),p(f f a),...} finite and infinite terms / {p a,p(f a),p(f f a),... p f ω }
Invariant search: p x → p(f x) → p(f f x) → ...
◮ The answer is: x = f x. ◮ However, f ω is not all that there is in the model!
p a → p(f a) → p(f f a) → ...
◮ fails to find a loop
Outline
Problem statement Solution Technical details
Solution?
◮ Recast the problem of invariant search as a problem of
coinductive theory exploration
Example 1
Example
∀x,streamZ x ⊃ streamZ (scons 0 x) Resolution-based search: streamZ x x/(scons 0 x′) streamZ x′
◮
✭✭✭✭✭✭✭✭✭✭✭✭✭✭✭✭✭✭ ✭
Terminate the loop with x = (scons 0 x).
◮
✭✭✭✭✭✭✭✭✭✭✭✭✭ ✭
It is the coinductive invariant.
◮ Find and prove streamZ(zstream) ◮ for zstream = fixλ x.scons 0 x
Example 2
Example
κ1 : ∀x,p(f x) ⊃ p x p a → p(f a) → ...
◮ ✭✭✭✭✭✭✭✭
✭
fails to find a loop
◮ Find and prove ∀ x, p x ◮ Get p a as a corollary
Outline
Problem statement Solution Technical details
Uniform proofs [Miller et al.]
◮ give proof-theoretic interpretation to goal-oriented proof
search
◮ Uniform: – one rule applies at every stage of the proof ◮ Proven to be a fragment of intuitionistic logic
Uniform proofs [Miller et al.]
◮ give proof-theoretic interpretation to goal-oriented proof
search
◮ Uniform: – one rule applies at every stage of the proof ◮ Proven to be a fragment of intuitionistic logic
FOHH and HOHH
G ::= ⊤ | A | G ∧G | G ∨G | ∃Var G | D ⊃ G | ∀Var G D ::= A | G ⊃ D | D ∧D | ∀Var D
FOHC and HOHC
G ::= ⊤ | A | G ∧G | G ∨G | ∃Var G D ::= A | G ⊃ D | D ∧D | ∀Var D
Logical rules
Σ;P − → ⊤ ⊤R Σ;P − → G1 Σ;P − → G2 Σ;P − → G1 ∧G2 ∧R Σ;P − → G1 Σ;P − → G1 ∨G2 ∨R Σ;P − → G2 Σ;P − → G1 ∨G2 ∨R Σ;P,D − → G Σ;P − → D ⊃ G ⊃R c : τ,Σ;P − → G [x := c] Σ;P − → ∀τx G ∀R Σ;P − → G [x := N] Σ;P − → ∃τx G ∃R
Backchaining (resolution) rules
. . . Σ;P
D
− → A Σ;P − → A Decide Σ;P
D
− → A Σ;P − → G Σ;P G⊃D − → A ⊃ L Σ;P
D[x:=N]
− → A Σ, / 0 ⊢ N : τ Σ;P ∀τx D − → A ∀L
COFIX rule for uniform proofs
Σ;P,M − → M Σ;P M cofix
COFIX rule for uniform proofs
Σ;P,M − → M Σ;P M cofix the guarding modality M must be discharged to get M (this can be done if M is resolved (= pattern matched) against a clause in P). The successful proof ends with Σ;P,M − → M.
Lucky case: trivial coinductive invariant
Example
κ1 : ∀x,p x ⊃ p x Find invariant for: p a − → p a − → ...?
Lucky case: trivial coinductive invariant
Example
κ1 : ∀x,p x ⊃ p x Find invariant for: p a − → p a − → ...?
least fixed point greatest fixed point finite terms / {p a} finite and infinite terms / {p a}
Lucky case: trivial coinductive invariant
Example
κ1 : ∀x,p x ⊃ p x Find invariant for: p a − → p a − → ...?
Initial
P;p a
p a
− → p a
Initial
P;p a
p a
− → p a
⊃ L
P;p a
p a⊃p a
− → p a
∀L
P;p a
∀x,p x⊃p x
− → p a
DECIDE
P;p a − → p a
COFIX
P p a
Lucky case: trivial coinductive invariant
Example
κ1 : ∀x,p x ⊃ p x Find invariant for: p a − → p a − → ...?
Initial
P;p a
p a
− → p a
Initial
P;p a
p a
− → p a
⊃ L
P;p a
p a⊃p a
− → p a
∀L
P;p a
∀x,p x⊃p x
− → p a
DECIDE
P;p a − → p a
COFIX
P p a
QUIZ: which logic does this coinductive hypothesis and prove live in?
Not so lucky case: universal coinductive invariant
Example
κ1 : ∀x,p(f x) ⊃ p x Find invariant for: p(a) − → p(f a) − → p(f f a) − → ...?
Not so lucky case: universal coinductive invariant
Example
κ1 : ∀x,p(f x) ⊃ p x Find invariant for: p(a) − → p(f a) − → p(f f a) − → ...?
Initial
P;p a
p a
− → p(a)
???
P;p a − → p(f a)
⊃ L
P;p a
p(f a)⊃p a
− → p a
∀L
P;p a
∀x,p(f x)⊃p x
− → p a
DECIDE
P;p a − → p a
COFIX
P p a
Not so lucky case: universal coinductive invariant
Example
κ1 : ∀x,p(f x) ⊃ p x Find invariant for: p a − → p(f a) − → ...?
Initial
P;∀x,p x
p a
− → p a
Initial
P;∀x,p x
p (f a)
− → p (f a)
∀L
P;∀x,p x
∀x,p x
− → p (f a)
DECIDE
P;∀x,p x − → p (f a)
⊃ L
P;∀x,p x
p (f a)⊃p a
− → p a
∀L
P;∀x,p x
∀x,p(f (x))⊃p x
− → p a
DECIDE
P;∀x,p x − → p a
∀R
P;∀x,p x − → ∀x,p x
co-fix
P ∀x,p x
Not so lucky case: universal coinductive invariant
Example
κ1 : ∀x,p(f x) ⊃ p x Find invariant for: p a − → p(f a) − → ...?
Initial
P;∀x,p x
p a
− → p a
Initial
P;∀x,p x
p (f a)
− → p (f a)
∀L
P;∀x,p x
∀x,p x
− → p (f a)
DECIDE
P;∀x,p x − → p (f a)
⊃ L
P;∀x,p x
p (f a)⊃p a
− → p a
∀L
P;∀x,p x
∀x,p(f (x))⊃p x
− → p a
DECIDE
P;∀x,p x − → p a
∀R
P;∀x,p x − → ∀x,p x
co-fix
P ∀x,p x
Finally, get (p a) as a corollary. ... QUIZ!
Unlucky case: implicative coinductive invariant
Example
κ1 : ∀x,p(f x)∧q x ⊃ p x κ2 : q(a); κ3 : ∀x,q x ⊃ q(f x) Find invariant for: p a
apply κ1
− → p(f a)∧q a
apply κ2
− → p(f a)
apply κ1
− → p(f f a)∧q(f a)
apply κ3
− → p(f f a)∧q a − → ...?
Unlucky case: implicative coinductive invariant
Example
κ1 : ∀x,p(f x)∧q x ⊃ p x κ2 : q(a); κ3 : ∀x,q x ⊃ q(f x) Find invariant for: p a
apply κ1
− → p(f a)∧q a
apply κ2
− → p(f a)
apply κ1
− → p(f f a)∧q(f a)
apply κ3
− → p(f f a)∧q a − → ...?
least fixed point greatest fixed point finite terms {q a,q(f a), q(f f a),...} {p a,p (f a),p(f f a),... q a,q(f a), q(f f a),...} finite and infinite terms {q a,q(f a), q(f f a),...} {p a,p (f a),p(f f a),... p(f ω),q a,q(f a), q(f f a), ...q f ω }
Unlucky case: implicative coinductive invariant
Example
κ1 : ∀x,p(f x)∧q x ⊃ p x κ2 : q(a); κ3 : ∀x,q x ⊃ q(f x) Find invariant for: p a
apply κ1
− → p(f a)∧q a
apply κ2
− → p(f a)
apply κ1
− → p(f f a)∧q(f a)
apply κ3
− → p(f f a)∧q a − → ...?
least fixed point greatest fixed point finite terms {q a,q(f a), q(f f a),...} {p a,p (f a),p(f f a),... q a,q(f a), q(f f a),...} finite and infinite terms {q a,q(f a), q(f f a),...} {p a,p (f a),p(f f a),... p(f ω),q a,q(f a), q(f f a), ...q f ω }
The only working coinductive invariant is ∀x,q x ⊃ p x, QUIZ!!!
Final example
◮ frStr = fix λ f x.scons x (f (s x)) = fix λ f x.[ x,(f (s x))] INIT
P;CH
from C [C,frStr(s C)]
− → from C [C,frStr(s C)]
INIT
P;CH
from (s C) (frStr(s C))
− → from(s C) (frStr(s C))
∀L
P;CH CH − → from (s C)(frStr(s C))
DECIDE
P;CH − → from (s C) (frStr(s C))
⊃ L
P;CH
from (s C) (frStr(s C))⊃from C [C,frStr(s C)]
− → from C [C,frStr(s C)]
∀L
P;CH
∀x y,from(s x) y⊃from x [x,y]
− → from C [C,frStr(s C)]
DECIDE
P;CH − → from C [C,frStr(s C)]
fixβ-conversion
P;CH − → from C(frStr C)
∀R
P;CH − → ∀x,from x, (frStr x)
cofix
P − → ∀x,from x (frStr x)
Final example
◮ frStr = fix λ f x.scons x (f (s x)) = fix λ f x.[ x,(f (s x))] INIT
P;CH
from C [C,frStr(s C)]
− → from C [C,frStr(s C)]
INIT
P;CH
from (s C) (frStr(s C))
− → from(s C) (frStr(s C))
∀L
P;CH CH − → from (s C)(frStr(s C))
DECIDE
P;CH − → from (s C) (frStr(s C))
⊃ L
P;CH
from (s C) (frStr(s C))⊃from C [C,frStr(s C)]
− → from C [C,frStr(s C)]
∀L
P;CH
∀x y,from(s x) y⊃from x [x,y]
− → from C [C,frStr(s C)]
DECIDE
P;CH − → from C [C,frStr(s C)]
fixβ-conversion
P;CH − → from C(frStr C)
∀R
P;CH − → ∀x,from x, (frStr x)
cofix
P − → ∀x,from x (frStr x)
◮ get from 0 (frStr 0) as a corollary
QUIZ!!!
Current progress:
Analysis of coinductive properties of theories based on the language in which their coinductive invariants are expressed:
Current progress:
Analysis of coinductive properties of theories based on the language in which their coinductive invariants are expressed:
Miller and Nadathur:
HOHH: Higher-order Hereditary Harrop Logic FOHH: First-order Hereditary Harrop Logic HOHH: Higher-order Horn Clause Logic FOHC: First-order Horn clause logic
Current progress:
Analysis of coinductive properties of theories based on the language in which their coinductive invariants are expressed:
co-HOHH: Coinductive Higher-order Hereditary Harrop Logic co-FOHH: Coinductive First-order Hereditary Harrop Logic co-HOHC: Coinductive Higher-order Horn Clause Logic co-FOHC: Coinductive First-order Horn clause logic
Coinductive Theory exploration
Universal Implicative shape with fixpoint terms 2018, Work in progress Universal implicative shape, no fixpoint terms [Fu et al., 2016] Atomic formula with fixpoint terms Loop detection [Guptaet al.,2007 ] Trivial shape E.g. p a [Lammel& Peyton Jones, 2005 ]
Coinductive Theory exploration
Universal Implicative shape with fixpoint terms 2018, Work in progress Universal implicative shape, no fixpoint terms [Fu et al., 2016] Atomic formula with fixpoint terms Loop detection [Guptaet al.,2007 ] Trivial shape E.g. p a [Lammel& Peyton Jones, 2005 ]
- QUIZ: where CoHipster’s lemmas would live?