Proof Relevant ATP for Type Inference? Katya Komentdantskaya (joint - - PowerPoint PPT Presentation

proof relevant atp for type inference
SMART_READER_LITE
LIVE PREVIEW

Proof Relevant ATP for Type Inference? Katya Komentdantskaya (joint - - PowerPoint PPT Presentation

Proof Relevant ATP for Type Inference? Katya Komentdantskaya (joint work with Peng Fu and Tom Schrijvers) Heriot-Watt University, Edinburgh Dagstuhl, 30th March 2016 A common pattern in typed language development 2 / 15 A common pattern in


slide-1
SLIDE 1

Proof Relevant ATP for Type Inference?

Katya Komentdantskaya (joint work with Peng Fu and Tom Schrijvers)

Heriot-Watt University, Edinburgh

Dagstuhl, 30th March 2016

slide-2
SLIDE 2

A common pattern in typed language development

2 / 15

slide-3
SLIDE 3

A common pattern in typed language development

◮ Some talks highlighted the problem already: if a proof is delivered by an

ATP , it comes with no proof term. (It is a different “citizen" from lemmas whose proof terms are constructed interactively. )

◮ Do we need a better picture?

2 / 15

slide-4
SLIDE 4

Personal experience, 2014-2015

3 / 15

slide-5
SLIDE 5

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

4 / 15

slide-6
SLIDE 6

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

Consider 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 → ∅

4 / 15

slide-7
SLIDE 7

Problems...

Ok, we have some grounds for interfacing FP (type class resolution) and LP (SLD-resolution). BUT:

5 / 15

slide-8
SLIDE 8

Problems...

Ok, we have some grounds for interfacing FP (type class resolution) and LP (SLD-resolution). BUT:

◮ This syntactic correspondence is too shallow and fragile a

ground for a long-term and sustainable methodology

5 / 15

slide-9
SLIDE 9

Problems...

Ok, we have some grounds for interfacing FP (type class resolution) and LP (SLD-resolution). BUT:

◮ This syntactic correspondence is too shallow and fragile a

ground for a long-term and sustainable methodology

◮ Gives a lot of trust to ATP

, the latter is used as a black-box

  • racle, that certifies inference without constructing and

passing back a proof evidence

5 / 15

slide-10
SLIDE 10

Problems...

Ok, we have some grounds for interfacing FP (type class resolution) and LP (SLD-resolution). BUT:

◮ This syntactic correspondence is too shallow and fragile a

ground for a long-term and sustainable methodology

◮ Gives a lot of trust to ATP

, the latter is used as a black-box

  • racle, that certifies inference without constructing and

passing back a proof evidence

◮ This approach lacks a conceptual understanding of relation

between Types, Computation, and Proof

5 / 15

slide-11
SLIDE 11

Problems...

Ok, we have some grounds for interfacing FP (type class resolution) and LP (SLD-resolution). BUT:

◮ This syntactic correspondence is too shallow and fragile a

ground for a long-term and sustainable methodology

◮ Gives a lot of trust to ATP

, the latter is used as a black-box

  • racle, that certifies inference without constructing and

passing back a proof evidence

◮ This approach lacks a conceptual understanding of relation

between Types, Computation, and Proof

◮ ... it is bound to cause practical and theoretical problems

(with runnable proofs, corecursion, soundness, ...)

5 / 15

slide-12
SLIDE 12

Problem: In type inference, proofs ARE programs!

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 test :: Eq (Int, Int) => Bool test = eq (1,2) (1,2) {- eval: test ==> True -}

We need to construct an evidence of Eq (Int, Int) for

  • test. In this example and generally, it needs to be run as a

function by Haskell NB: Type Inhabitation problem!

6 / 15

slide-13
SLIDE 13

In Haskell, proofs ARE type inhabitants

data Eq x where EqD :: (x -> x -> Bool) -> Eq x eq :: Eq x -> (x -> x -> Bool) eq (EqD e) = e k1 :: Eq x -> Eq y -> Eq (x, y) k1 d1 d2 = EqD q where q (x1, y1) (x2, y2) = eq d1 x1 x2 && eq d2 y1 y2 k2 :: Eq Int k2 = EqD primtiveIntEq test :: Eq (Int, Int) -> Bool test d = eq d (1,2) (1,2) {- eval: test (k1 k2 k2) ==> True -}

How do we obtain (k1 k2 k2) for test? SLD-resolution alone is not sufficent

7 / 15

slide-14
SLIDE 14

Solution: Make resolution proof relevant: Horn formulas as types, proofs as terms

Definition (Basic syntax)

Term t ::= x | K | t t′ Atomic Formula A, B, C, D ::= P t1 ... tn Horn Formula H ::= B1, ..., Bn ⇒ A Proof/Evidence e ::= κ | e e′ Axiom Environment Φ ::= · | Φ, (κ : H)

Definition (Resolution)

Φ ⊢ e : A

Φ ⊢ e1 : σB1 · · · Φ ⊢ en : σBn Φ ⊢ κ e1 · · · en : σA if (κ : B1, ..., Bn ⇒ A) ∈ Φ

8 / 15

slide-15
SLIDE 15

Solution: make resolution proof relevant: Horn formulas as types, proofs as terms

Consider the following logic program Φ (clause names are constant terms) κ1 : (Eq x, Eq y) ⇒ Eq(x, y) κ2 : Eq Int Resolve the query ? Eq (Int, Int).

◮ We have the following reduction:

Φ ⊢ Eq (Int, Int) →κ1 Eq Int, Eq Int →κ2 Eq Int →κ2 ∅

9 / 15

slide-16
SLIDE 16

Solution: make resolution proof relevant: Horn formulas as types, proofs as terms

Consider the following logic program Φ (clause names are constant terms) κ1 : (Eq x, Eq y) ⇒ Eq(x, y) κ2 : Eq Int Resolve the query ? Eq (Int, Int).

◮ We have the following reduction:

Φ ⊢ Eq (Int, Int) →κ1 Eq Int, Eq Int →κ2 Eq Int →κ2 ∅

◮ Corresponding derivation:

Φ ⊢ κ2 : Eq x, Eq y ⇒ Eq (x, y) Φ ⊢ κ1 : Eq Int Φ ⊢ κ2 κ1 : Eq y ⇒ Eq (Int, y) Φ ⊢ κ1 : Eq Int Φ ⊢ κ2 κ1 κ1 : Eq(Int, Int)

9 / 15

slide-17
SLIDE 17

So far...

◮ We have started to build a “house" on solid grounds:

NB: automated proof construction = type inhabitation.

10 / 15

slide-18
SLIDE 18

So far...

◮ We have started to build a “house" on solid grounds:

NB: automated proof construction = type inhabitation. Is it a suitable home for real-world Haskell type inference? By adding rules for fixpoint at term level, we were able to extend Haskell type class ability to handle nontermination

  • coinductively. [FLOPS16]

10 / 15

slide-19
SLIDE 19

Our method is now a coherent “building" that unifies

foundations (type theory), implementation (evidence construction), applications (type class inference) [FLOPS16]

11 / 15

slide-20
SLIDE 20

So far:

Proof-relevant (or Curry-Howard) Resolution:

  • 1. Retains operational semantics of first-order resolution

(Operationally, it is still an ATP we started with!);

  • 2. (Co)Recursive (with fixpoint terms inhabiting [coinductive]

formulas with infinite proofs)

  • 3. Coherently unifies type theory, automated proving, type

inference

  • 4. Based on solid principles: Curry-Howard approach to logic,

computation, and proof.

12 / 15

slide-21
SLIDE 21

Computation, programming, proof

Bringing three classic themes back together:

Automated inference (type level) Corresponding func- tion (term-level) Proof Principle terminating resolution

13 / 15

slide-22
SLIDE 22

Computation, programming, proof

Bringing three classic themes back together:

Automated inference (type level) Corresponding func- tion (term-level) Proof Principle terminating resolution proof evidence construc- tion

13 / 15

slide-23
SLIDE 23

Computation, programming, proof

Bringing three classic themes back together:

Automated inference (type level) Corresponding func- tion (term-level) Proof Principle terminating resolution proof evidence construc- tion inductive proofs

13 / 15

slide-24
SLIDE 24

Computation, programming, proof

Bringing three classic themes back together:

Automated inference (type level) Corresponding func- tion (term-level) Proof Principle terminating resolution proof evidence construc- tion inductive proofs non-terminating resolu- tion

13 / 15

slide-25
SLIDE 25

Computation, programming, proof

Bringing three classic themes back together:

Automated inference (type level) Corresponding func- tion (term-level) Proof Principle terminating resolution proof evidence construc- tion inductive proofs non-terminating resolu- tion corecursive evidence construction

13 / 15

slide-26
SLIDE 26

Computation, programming, proof

Bringing three classic themes back together:

Automated inference (type level) Corresponding func- tion (term-level) Proof Principle terminating resolution proof evidence construc- tion inductive proofs non-terminating resolu- tion corecursive evidence construction coinductive proofs

13 / 15

slide-27
SLIDE 27

Is it wrong to Dream of...

change of methodology for all ATP in Type inference? From this:

14 / 15

slide-28
SLIDE 28

Is it wrong to Dream of...

modular methods of building ATPs for Type inference?

15 / 15

slide-29
SLIDE 29

Is it wrong to Dream of...

modular methods of building ATPs for Type inference?

◮ We have built a

similar prover for TRS (first-order terms as types, reductions as proofs).

◮ How far can we go? ◮ Is it (un)thinkable to

ask about Curry-Howard foundations for (e.g.) SMT-solvers for Type inference?

15 / 15